Java Code Examples for java.awt.geom.Point2D#getY()

The following examples show how to use java.awt.geom.Point2D#getY() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XYPlot.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Multiplies the range on the domain axis/axes by the specified factor.
 *
 * @param factor  the zoom factor.
 * @param info  the plot rendering info.
 * @param source  the source point (in Java2D space).
 * @param useAnchor  use source point as zoom anchor?
 * 
 * @see #zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean)
 * 
 * @since 1.0.7
 */
public void zoomDomainAxes(double factor, PlotRenderingInfo info,
                           Point2D source, boolean useAnchor) {
            
    // perform the zoom on each domain axis
    for (int i = 0; i < this.domainAxes.size(); i++) {
        ValueAxis domainAxis = (ValueAxis) this.domainAxes.get(i);
        if (domainAxis != null) {
            if (useAnchor) {
                // get the relevant source coordinate given the plot 
                // orientation
                double sourceX = source.getX();
                if (this.orientation == PlotOrientation.HORIZONTAL) {
                    sourceX = source.getY();
                }
                double anchorX = domainAxis.java2DToValue(sourceX, 
                        info.getDataArea(), getDomainAxisEdge());
                domainAxis.resizeRange(factor, anchorX);
            }
            else {
                domainAxis.resizeRange(factor);
            }
        }
    }
}
 
Example 2
Source File: BalloonManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D)g;
    
    g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
    
    Composite oldC = g2d.getComposite();
    Shape s = getMask( getWidth(), getHeight() );

    g2d.setComposite( AlphaComposite.getInstance( AlphaComposite.SRC_OVER, 0.25f*currentAlpha ) );
    g2d.setColor( Color.black );
    g2d.fill( getShadowMask(s) );
    
    g2d.setColor( UIManager.getColor( "ToolTip.background" ) ); //NOI18N
    g2d.setComposite( AlphaComposite.getInstance( AlphaComposite.SRC_OVER, currentAlpha ) );
    Point2D p1 = s.getBounds().getLocation();
    Point2D p2 = new Point2D.Double(p1.getX(), p1.getY()+s.getBounds().getHeight());
    if( isMouseOverEffect )
        g2d.setPaint( new GradientPaint( p2, getMouseOverGradientStartColor(), p1, getMouseOverGradientFinishColor() ) );
    else
        g2d.setPaint( new GradientPaint( p2, getDefaultGradientStartColor(), p1, getDefaultGradientFinishColor() ) );
    g2d.fill(s);
    g2d.setColor( Color.black );
    g2d.draw(s);
    g2d.setComposite( oldC );
}
 
Example 3
Source File: MagicWandInteractor.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
Point getPixelPos(GeoCoding geocoding, int width, int height, MouseEvent event) {
    final Point2D mp = toModelPoint(event);
    final Point2D ip;
    if (geocoding != null) {
        AffineTransform transform = Product.findImageToModelTransform(geocoding);
        try {
            ip = transform.inverseTransform(mp, null);
        } catch (NoninvertibleTransformException e) {
            Dialogs.showError(DIALOG_TITLE, "A geographic transformation problem occurred:\n" + e.getMessage());
            return null;
        }
    } else {
        ip = mp;
    }

    final int pixelX = (int) ip.getX();
    final int pixelY = (int) ip.getY();
    if (pixelX < 0 || pixelY < 0 || pixelX >= width || pixelY >= height) {
        return null;
    }

    return new Point(pixelX, pixelY);
}
 
Example 4
Source File: DialPointer.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Draws the pointer.
 *
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view.
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
    Rectangle2D view) {

    g2.setPaint(this.paint);
    g2.setStroke(this.stroke);
    Rectangle2D arcRect = DialPlot.rectangleByRadius(frame,
            this.radius, this.radius);

    double value = plot.getValue(this.datasetIndex);
    DialScale scale = plot.getScaleForDataset(this.datasetIndex);
    double angle = scale.valueToAngle(value);

    Arc2D arc = new Arc2D.Double(arcRect, angle, 0, Arc2D.OPEN);
    Point2D pt = arc.getEndPoint();

    Line2D line = new Line2D.Double(frame.getCenterX(),
            frame.getCenterY(), pt.getX(), pt.getY());
    g2.draw(line);
}
 
Example 5
Source File: StandardGlyphVector.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * !!! not used currently, but might be by getPixelbounds?
 */
public void pixellate(FontRenderContext renderFRC, Point2D loc, Point pxResult) {
    if (renderFRC == null) {
        renderFRC = frc;
    }

    // it is a total pain that you have to copy the transform.

    AffineTransform at = renderFRC.getTransform();
    at.transform(loc, loc);
    pxResult.x = (int)loc.getX(); // but must not behave oddly around zero
    pxResult.y = (int)loc.getY();
    loc.setLocation(pxResult.x, pxResult.y);
    try {
        at.inverseTransform(loc, loc);
    }
    catch (NoninvertibleTransformException e) {
        throw new IllegalArgumentException("must be able to invert frc transform");
    }
}
 
Example 6
Source File: GroundContainer.java    From stendhal with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Calculates whether the click was close enough to a zone border to trigger
 * a zone change.
 *
 * @param point click point in world coordinates
 * @return Direction of the zone to change to, <code>null</code> if no zone change should happen
 */
public Direction calculateZoneChangeDirection(Point2D point) {
	StaticGameLayers layers = StendhalClient.get().getStaticGameLayers();
	double x = point.getX();
	double y = point.getY();
	double width = layers.getWidth();
	double height = layers.getHeight();
	if (x < 0.333) {
		return Direction.LEFT;
	}
	if (x > width - 0.333) {
		return Direction.RIGHT;
	}
	if (y < 0.333) {
		return Direction.UP;
	}
	if (y > height - 0.4) {
		return Direction.DOWN;
	}
	return null;
}
 
Example 7
Source File: StandardGlyphVector.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * !!! not used currently, but might be by getPixelbounds?
 */
public void pixellate(FontRenderContext renderFRC, Point2D loc, Point pxResult) {
    if (renderFRC == null) {
        renderFRC = frc;
    }

    // it is a total pain that you have to copy the transform.

    AffineTransform at = renderFRC.getTransform();
    at.transform(loc, loc);
    pxResult.x = (int)loc.getX(); // but must not behave oddly around zero
    pxResult.y = (int)loc.getY();
    loc.setLocation(pxResult.x, pxResult.y);
    try {
        at.inverseTransform(loc, loc);
    }
    catch (NoninvertibleTransformException e) {
        throw new IllegalArgumentException("must be able to invert frc transform");
    }
}
 
Example 8
Source File: XYPlot.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Multiplies the range on the range axis/axes by the specified factor.
 *
 * @param factor  the zoom factor.
 * @param info  the plot rendering info.
 * @param source  the source point.
 * @param useAnchor  a flag that controls whether or not the source point
 *         is used for the zoom anchor.
 *
 * @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean)
 *
 * @since 1.0.7
 */
@Override
public void zoomRangeAxes(double factor, PlotRenderingInfo info,
                          Point2D source, boolean useAnchor) {

    // perform the zoom on each range axis
    for (ValueAxis yAxis : this.rangeAxes.values()) {
        if (yAxis == null) {
            continue;
        }
        if (useAnchor) {
            // get the relevant source coordinate given the plot orientation
            double sourceY = source.getY();
            if (this.orientation == PlotOrientation.HORIZONTAL) {
                sourceY = source.getX();
            }
            double anchorY = yAxis.java2DToValue(sourceY,
                    info.getDataArea(), getRangeAxisEdge());
            yAxis.resizeRange2(factor, anchorY);
        } else {
            yAxis.resizeRange(factor);
        }
    }
}
 
Example 9
Source File: StandardGlyphVector.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void setGlyphPosition(int ix, Point2D pos) {
    initPositions();

    int ix2 = ix << 1;
    positions[ix2] = (float)pos.getX();
    positions[ix2 + 1] = (float)pos.getY();

    clearCaches(ix);
    addFlags(FLAG_HAS_POSITION_ADJUSTMENTS);
}
 
Example 10
Source File: SpiderWebPlot.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the location for a label
 *
 * @param labelBounds the label bounds.
 * @param ascent the ascent (height of font).
 * @param plotArea the plot area
 * @param startAngle the start angle for the pie series.
 *
 * @return The location for a label.
 */
protected Point2D calculateLabelLocation(Rectangle2D labelBounds,
                                         double ascent,
                                         Rectangle2D plotArea,
                                         double startAngle)
{
    Arc2D arc1 = new Arc2D.Double(plotArea, startAngle, 0, Arc2D.OPEN);
    Point2D point1 = arc1.getEndPoint();

    double deltaX = -(point1.getX() - plotArea.getCenterX())
                    * this.axisLabelGap;
    double deltaY = -(point1.getY() - plotArea.getCenterY())
                    * this.axisLabelGap;

    double labelX = point1.getX() - deltaX;
    double labelY = point1.getY() - deltaY;

    if (labelX < plotArea.getCenterX()) {
        labelX -= labelBounds.getWidth();
    }

    if (labelX == plotArea.getCenterX()) {
        labelX -= labelBounds.getWidth() / 2;
    }

    if (labelY > plotArea.getCenterY()) {
        labelY += ascent;
    }

    return new Point2D.Double(labelX, labelY);
}
 
Example 11
Source File: VisualGraphTranslatingGraphMousePlugin.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void mouseDragged(MouseEvent e) {
	GraphViewer<V, E> viewer = getGraphViewer(e);
	boolean accepted = checkModifiers(e);
	if (!accepted) {
		return;
	}

	if (!isHandlingEvent) {
		return;
	}

	panning = true;

	RenderContext<V, E> context = viewer.getRenderContext();
	MultiLayerTransformer multiLayerTransformer = context.getMultiLayerTransformer();
	MutableTransformer layoutTransformer = multiLayerTransformer.getTransformer(Layer.LAYOUT);
	viewer.setCursor(cursor);
	Point2D downPoint = multiLayerTransformer.inverseTransform(down);
	Point2D p = multiLayerTransformer.inverseTransform(e.getPoint());
	float dx = (float) (p.getX() - downPoint.getX());
	float dy = (float) (p.getY() - downPoint.getY());

	layoutTransformer.translate(dx, dy);
	down.x = e.getX();
	down.y = e.getY();
	e.consume();
	viewer.repaint();
}
 
Example 12
Source File: GLPanel.java    From depan with Apache License 2.0 5 votes vote down vote up
@Override
public void setPosition(
    NodeRenderingProperty nodeProp, Point2D position) {
  if (null == position) {
    return;
  }
  nodeProp.targetPositionX = (float) position.getX();
  nodeProp.targetPositionY = (float) position.getY();
}
 
Example 13
Source File: FruchtermanReingoldLayout.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void layoutCirculary(Collection<GraphNode<I>> nodes, GraphNode<I> masterNode) {
    Point masterPoint = new Point();
    NodeWidget master = getWidget(masterNode);
    masterPoint.setLocation(master.locX, master.locY);
    double r;
    double theta;
    double thetaStep = Math.PI / 5;
    r = 150;
    theta = 0;
    Iterator<GraphNode<I>> it = nodes.iterator();
    NodeWidget nw = getWidget(it.next());
    while (true) {
        AffineTransform tr = AffineTransform.getRotateInstance(theta);
        Point2D d2point = tr.transform(new Point2D.Double(0, r), null);
        Point point = new Point((int)d2point.getX() + masterPoint.x, (int)d2point.getY() + masterPoint.y);
        if (isThereFreeSpace(point, nw)) {
            nw.locX = point.getX();
            nw.locY = point.getY();
            nw.dispX = 0;
            nw.dispY = 0;
            if (it.hasNext()) {
                nw = getWidget(it.next());
            } else {
                return;
            }
        }
        theta = theta + thetaStep;
        if (theta > (Math.PI * 2 - Math.PI / 10)) {
            r = r + 90;
            theta = theta - Math.PI * 2;
            thetaStep = thetaStep * 3 / 4; 
        }
    }
    
}
 
Example 14
Source File: clsUtility.java    From mil-sym-java with Apache License 2.0 5 votes vote down vote up
protected static Rectangle2D getMBR(ArrayList<Point2D> clipBounds)
{
    Rectangle2D rect=null;
    try
    {
        int j=0;
        Point2D pt=null;
        double xmax=clipBounds.get(0).getX(),xmin=xmax,ymax=clipBounds.get(0).getY(),ymin=ymax;
        for(j=0;j<clipBounds.size();j++)
        {
            pt=clipBounds.get(j);
            if(pt.getX()<xmin)
                xmin=pt.getX();
            if(pt.getX()>xmax)
                xmax=pt.getX();
            if(pt.getY()<=ymin)
                ymin=pt.getY();
            if(pt.getY()>ymax)
                ymax=pt.getY();
        }
        rect=new Rectangle2D.Double(xmin, ymin, xmax-xmin, ymax-ymin);
    }
    catch (Exception exc) {
        ErrorLogger.LogException(_className, "AddBoundaryPointsForLines",
                new RendererException("Failed inside AddBoundaryPointsForLines", exc));
    }
    return rect;
}
 
Example 15
Source File: SHAPERECORD.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
public static double[][] approximateCubic(double[] cubicControlPointCoords) {
    if (cubicControlPointCoords.length < 8) {
        throw new IllegalArgumentException("Must have at least 8 coordinates");
    }

    //extract point objects from source array
    Point2D p0 = new Point2D.Double(cubicControlPointCoords[0], cubicControlPointCoords[1]);
    Point2D p1 = new Point2D.Double(cubicControlPointCoords[2], cubicControlPointCoords[3]);
    Point2D p2 = new Point2D.Double(cubicControlPointCoords[4], cubicControlPointCoords[5]);
    Point2D p3 = new Point2D.Double(cubicControlPointCoords[6], cubicControlPointCoords[7]);

    //calculates the useful base points
    Point2D pa = getPointOnSegment(p0, p1, 3.0 / 4.0);
    Point2D pb = getPointOnSegment(p3, p2, 3.0 / 4.0);

    //get 1/16 of the [P3, P0] segment
    double dx = (p3.getX() - p0.getX()) / 16.0;
    double dy = (p3.getY() - p0.getY()) / 16.0;

    //calculates control point 1
    Point2D pc1 = getPointOnSegment(p0, p1, 3.0 / 8.0);

    //calculates control point 2
    Point2D pc2 = getPointOnSegment(pa, pb, 3.0 / 8.0);
    pc2 = movePoint(pc2, -dx, -dy);

    //calculates control point 3
    Point2D pc3 = getPointOnSegment(pb, pa, 3.0 / 8.0);
    pc3 = movePoint(pc3, dx, dy);

    //calculates control point 4
    Point2D pc4 = getPointOnSegment(p3, p2, 3.0 / 8.0);

    //calculates the 3 anchor points
    Point2D pa1 = getMidPoint(pc1, pc2);
    Point2D pa2 = getMidPoint(pa, pb);
    Point2D pa3 = getMidPoint(pc3, pc4);

    //return the points for the four quadratic curves
    return new double[][]{
        {pc1.getX(), pc1.getY(), pa1.getX(), pa1.getY()},
        {pc2.getX(), pc2.getY(), pa2.getX(), pa2.getY()},
        {pc3.getX(), pc3.getY(), pa3.getX(), pa3.getY()},
        {pc4.getX(), pc4.getY(), p3.getX(), p3.getY()}};
}
 
Example 16
Source File: clsClipQuad.java    From mil-sym-java with Apache License 2.0 4 votes vote down vote up
/**
 * @deprecated
 * @param polygon
 * @param clipBounds
 * @return 
 */
private static int AddBoundaryPointsForLines(ArrayList<Point2D> polygon,
        Rectangle2D clipBounds) {
    int result = 0;
    try {
        double ulx = 0, uly = 0, lrx = 0, lry = 0;
        ulx = clipBounds.getMinX();
        uly = clipBounds.getMinY();
        lrx = clipBounds.getMaxX();
        lry = clipBounds.getMaxY();
        //move these inside by 10 pixels so the algoithm will treat them as inside points
        Point2D ul = new Point2D.Double(ulx + 10, uly + 10);
        Point2D lr = new Point2D.Double(lrx - 10, lry - 10);

        Point2D pt0 = polygon.get(0);
        Point2D ptn = polygon.get(polygon.size() - 1);
        Boolean addToFront = false, addToEnd = false;            
        //add a point to the begining of the array
        if (pt0.getY() < uly) //above the top clip
        {
            polygon.add(0, ul);
            addToFront = true;
        } else if (pt0.getX() < ulx) //outside the left clip
        {
            polygon.add(0, ul);
            addToFront = true;
        } else if (pt0.getX() > lrx) //outside the right clip
        {
            polygon.add(0, lr);
            addToFront = true;
        } else if (pt0.getY() > lry) //below the bottom clip
        {
            polygon.add(0, lr);
            addToFront = true;
        }

        //add a point to the end of the array
        if (ptn.getY() < uly) //above the top clip
        {
            polygon.add(ul);
            addToEnd = true;
        } else if (ptn.getX() < ulx) //outside the left clip
        {
            polygon.add(ul);
            addToEnd = true;
        } else if (ptn.getX() > lrx) //outside the right clip
        {
            polygon.add(lr);
            addToEnd = true;
        } else if (ptn.getY() > lry) //below the bottom clip
        {
            polygon.add(lr);
            addToEnd = true;
        }

        if (addToFront == false && addToEnd == false) {
            result = 0;
        }
        if (addToFront == true && addToEnd == false) {
            result = 1;
        }
        if (addToFront == false && addToEnd == true) {
            result = 2;
        }
        if (addToFront == true && addToEnd == true) {
            result = 3;
        }

    } catch (Exception exc) {
        ErrorLogger.LogException(_className, "AddBoundaryPointsForLines",
                new RendererException("Failed inside AddBoundaryPointsForLines", exc));
    }
    return result;
}
 
Example 17
Source File: BufferedPaints.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method uses techniques that are nearly identical to those
 * employed in setGradientPaint() above.  The primary difference
 * is that at the native level we use a fragment shader to manually
 * apply the plane equation constants to the current fragment position
 * to calculate the gradient position in the range [0,1] (the native
 * code for GradientPaint does the same, except that it uses OpenGL's
 * automatic texture coordinate generation facilities).
 *
 * One other minor difference worth mentioning is that
 * setGradientPaint() calculates the plane equation constants
 * such that the gradient end points are positioned at 0.25 and 0.75
 * (for reasons discussed in the comments for that method).  In
 * contrast, for LinearGradientPaint we setup the equation constants
 * such that the gradient end points fall at 0.0 and 1.0.  The
 * reason for this difference is that in the fragment shader we
 * have more control over how the gradient values are interpreted
 * (depending on the paint's CycleMethod).
 */
private static void setLinearGradientPaint(RenderQueue rq,
                                           SunGraphics2D sg2d,
                                           LinearGradientPaint paint,
                                           boolean useMask)
{
    boolean linear =
        (paint.getColorSpace() == ColorSpaceType.LINEAR_RGB);
    Color[] colors = paint.getColors();
    int numStops = colors.length;
    Point2D pt1 = paint.getStartPoint();
    Point2D pt2 = paint.getEndPoint();
    AffineTransform at = paint.getTransform();
    at.preConcatenate(sg2d.transform);

    if (!linear && numStops == 2 &&
        paint.getCycleMethod() != CycleMethod.REPEAT)
    {
        // delegate to the optimized two-color gradient codepath
        boolean isCyclic =
            (paint.getCycleMethod() != CycleMethod.NO_CYCLE);
        setGradientPaint(rq, at,
                         colors[0], colors[1],
                         pt1, pt2,
                         isCyclic, useMask);
        return;
    }

    int cycleMethod = paint.getCycleMethod().ordinal();
    float[] fractions = paint.getFractions();
    int[] pixels = convertToIntArgbPrePixels(colors, linear);

    // calculate plane equation constants
    double x = pt1.getX();
    double y = pt1.getY();
    at.translate(x, y);
    // now gradient point 1 is at the origin
    x = pt2.getX() - x;
    y = pt2.getY() - y;
    double len = Math.sqrt(x * x + y * y);
    at.rotate(x, y);
    // now gradient point 2 is on the positive x-axis
    at.scale(len, 1);
    // now gradient point 1 is at (0.0, 0), point 2 is at (1.0, 0)

    float p0, p1, p3;
    try {
        at.invert();
        p0 = (float)at.getScaleX();
        p1 = (float)at.getShearX();
        p3 = (float)at.getTranslateX();
    } catch (java.awt.geom.NoninvertibleTransformException e) {
        p0 = p1 = p3 = 0.0f;
    }

    // assert rq.lock.isHeldByCurrentThread();
    rq.ensureCapacity(20 + 12 + (numStops*4*2));
    RenderBuffer buf = rq.getBuffer();
    buf.putInt(SET_LINEAR_GRADIENT_PAINT);
    buf.putInt(useMask ? 1 : 0);
    buf.putInt(linear  ? 1 : 0);
    buf.putInt(cycleMethod);
    buf.putInt(numStops);
    buf.putFloat(p0);
    buf.putFloat(p1);
    buf.putFloat(p3);
    buf.put(fractions);
    buf.put(pixels);
}
 
Example 18
Source File: CrosshairOverlay.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Draws a crosshair horizontally across the plot.
 *
 * @param g2  the graphics target.
 * @param dataArea  the data area.
 * @param y  the y-value in Java2D space.
 * @param crosshair  the crosshair.
 */
protected void drawHorizontalCrosshair(Graphics2D g2, Rectangle2D dataArea,
        double y, Crosshair crosshair) {

    if (y >= dataArea.getMinY() && y <= dataArea.getMaxY()) {
        Line2D line = new Line2D.Double(dataArea.getMinX(), y,
                dataArea.getMaxX(), y);
        Paint savedPaint = g2.getPaint();
        Stroke savedStroke = g2.getStroke();
        g2.setPaint(crosshair.getPaint());
        g2.setStroke(crosshair.getStroke());
        g2.draw(line);
        if (crosshair.isLabelVisible()) {
            String label = crosshair.getLabelGenerator().generateLabel(
                    crosshair);
            RectangleAnchor anchor = crosshair.getLabelAnchor();
            Point2D pt = calculateLabelPoint(line, anchor, 5, 5);
            float xx = (float) pt.getX();
            float yy = (float) pt.getY();
            TextAnchor alignPt = textAlignPtForLabelAnchorH(anchor);
            Shape hotspot = TextUtilities.calculateRotatedStringBounds(
                    label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER);
            if (!dataArea.contains(hotspot.getBounds2D())) {
                anchor = flipAnchorV(anchor);
                pt = calculateLabelPoint(line, anchor, 5, 5);
                xx = (float) pt.getX();
                yy = (float) pt.getY();
                alignPt = textAlignPtForLabelAnchorH(anchor);
                hotspot = TextUtilities.calculateRotatedStringBounds(
                       label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER);
            }

            g2.setPaint(crosshair.getLabelBackgroundPaint());
            g2.fill(hotspot);
            g2.setPaint(crosshair.getLabelOutlinePaint());
            g2.draw(hotspot);
            TextUtilities.drawAlignedString(label, g2, xx, yy, alignPt);
        }
        g2.setPaint(savedPaint);
        g2.setStroke(savedStroke);
    }
}
 
Example 19
Source File: SHAPERECORD.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
private static Point2D getPointOnSegment(Point2D p0, Point2D p1, double ratio) {
    double x = p0.getX() + ((p1.getX() - p0.getX()) * ratio);
    double y = p0.getY() + ((p1.getY() - p0.getY()) * ratio);
    return new Point2D.Double(x, y);
}
 
Example 20
Source File: LinkAndBrushChartPanel.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void mouseReleased(MouseEvent e) {

	// if we've been panning, we need to reset now that the mouse is
	// released...
	Rectangle2D zoomRectangle = (Rectangle2D) getChartFieldValueByName("zoomRectangle");
	Point2D zoomPoint = (Point2D) getChartFieldValueByName("zoomPoint");
	if (getChartFieldValueByName("panLast") != null) {
		setChartFieldValue(getChartFieldByName("panLast"), null);
		setCursor(Cursor.getDefaultCursor());
	} else if (zoomRectangle != null) {
		boolean hZoom = false;
		boolean vZoom = false;
		if ((PlotOrientation) getChartFieldValueByName("orientation") == PlotOrientation.HORIZONTAL) {
			hZoom = (Boolean) getChartFieldValueByName("rangeZoomable");
			vZoom = (Boolean) getChartFieldValueByName("domainZoomable");
		} else {
			hZoom = (Boolean) getChartFieldValueByName("domainZoomable");
			vZoom = (Boolean) getChartFieldValueByName("rangeZoomable");
		}

		boolean zoomTrigger1 = hZoom
				&& Math.abs(e.getX() - zoomPoint.getX()) >= (Integer) getChartFieldValueByName("zoomTriggerDistance");
		boolean zoomTrigger2 = vZoom
				&& Math.abs(e.getY() - zoomPoint.getY()) >= (Integer) getChartFieldValueByName("zoomTriggerDistance");
		if (zoomTrigger1 || zoomTrigger2) {
			if (hZoom && e.getX() < zoomPoint.getX() || vZoom && e.getY() < zoomPoint.getY()) {
				restoreAutoBounds();
			} else {
				double x, y, w, h;
				Rectangle2D screenDataArea = getScreenDataArea((int) zoomPoint.getX(), (int) zoomPoint.getY());
				double maxX = screenDataArea.getMaxX();
				double maxY = screenDataArea.getMaxY();
				// for mouseReleased event, (horizontalZoom || verticalZoom)
				// will be true, so we can just test for either being false;
				// otherwise both are true
				if (!vZoom) {
					x = zoomPoint.getX();
					y = screenDataArea.getMinY();
					w = Math.min(zoomRectangle.getWidth(), maxX - zoomPoint.getX());
					h = screenDataArea.getHeight();
				} else if (!hZoom) {
					x = screenDataArea.getMinX();
					y = zoomPoint.getY();
					w = screenDataArea.getWidth();
					h = Math.min(zoomRectangle.getHeight(), maxY - zoomPoint.getY());
				} else {
					x = zoomPoint.getX();
					y = zoomPoint.getY();
					w = Math.min(zoomRectangle.getWidth(), maxX - zoomPoint.getX());
					h = Math.min(zoomRectangle.getHeight(), maxY - zoomPoint.getY());
				}
				Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h);
				zoom(zoomArea);
			}
			setChartFieldValue(getChartFieldByName("zoomPoint"), null);
			setChartFieldValue(getChartFieldByName("zoomRectangle"), null);
		} else {
			// erase the zoom rectangle
			Graphics2D g2 = (Graphics2D) getGraphics();
			if ((Boolean) getChartFieldValueByName("useBuffer")) {
				repaint();
			} else {
				drawZoomRectangle(g2, true);
			}
			g2.dispose();
			setChartFieldValue(getChartFieldByName("zoomPoint"), null);
			setChartFieldValue(getChartFieldByName("zoomRectangle"), null);
		}

	}

	else if (e.isPopupTrigger()) {
		if (getChartFieldValueByName("popup") != null) {
			displayPopupMenu(e.getX(), e.getY());
		}
	}

}