Example usage for java.awt.geom Point2D getX

List of usage examples for java.awt.geom Point2D getX

Introduction

In this page you can find the example usage for java.awt.geom Point2D getX.

Prototype

public abstract double getX();

Source Link

Document

Returns the X coordinate of this Point2D in double precision.

Usage

From source file:net.sf.maltcms.chromaui.charts.FastHeatMapPlot.java

/**
 * Multiplies the range on the domain axis by the specified factor.
 *
 * @param factor the zoom factor./*  ww  w  .  j  a v a  2 s . c o  m*/
 * @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
 */
@Override
public void zoomDomainAxes(double factor, PlotRenderingInfo info, Point2D source, boolean useAnchor) {

    if (useAnchor) {
        // get the source coordinate - this plot has always a VERTICAL
        // orientation
        double sourceX = source.getX();
        double anchorX = this.domainAxis.java2DToValue(sourceX, info.getDataArea(), RectangleEdge.BOTTOM);
        this.domainAxis.resizeRange2(factor, anchorX);
    } else {
        this.domainAxis.resizeRange(factor);
    }
}

From source file:tufts.vue.RichTextBox.java

public void setBoxLocation(Point2D p) {
    setBoxLocation((float) p.getX(), (float) p.getY());
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.LinkAndBrushChartPanel.java

@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 {/* ww  w.  j av  a2s  . c  o m*/
            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());
        }
    }

}

From source file:Hexagon.java

public Hexagon(Point2D center, int size) {
    super();/*from  w  ww.  j  a v a  2s  . c o m*/
    this.center = center;
    this.size = size;

    /**
      * MATH:
      *   With the hexagon points={TOP, UPPER-RIGHT, LOWER-RIGHT, BOTTOM, LOWER-LEFT, UPPER-RIGHT}
      *   size = length of each actual segment of the hexagon
      *   width = bounding rectangle width
      *   height = bounding rectangle height
      *   each inner angle is 120 degrees
      *   outside angles are 30-60-90 triangles with 30 near TOP and BOTTOM and 60 near sides
      *   hOffset = height difference between 'size' edge and bounding rectangle corners
      *   wOffset = width difference between TOP/BOTTOM points and bounding rectangle corners
      */

    double thirtyDegrees = Math.toRadians(30);
    hOffset = Math.sin(thirtyDegrees) * size;
    wOffset = Math.cos(thirtyDegrees) * size;

    height = (2 * hOffset) + size;
    width = (2 * wOffset);

    double left = center.getX() - (width / 2);
    double right = center.getX() + (width / 2);
    double top = center.getY() - (height / 2);
    double bottom = center.getY() + (height / 2);
    boundingBox = new Rectangle2D.Double(left, top, width, height);

    boundingCorners = new HashMap<BoundingCorner, Point2D>();
    boundingCorners.put(BoundingCorner.TopRight, new Point2D.Double(right, top));
    boundingCorners.put(BoundingCorner.TopLeft, new Point2D.Double(left, top));
    boundingCorners.put(BoundingCorner.BottomRight, new Point2D.Double(right, bottom));
    boundingCorners.put(BoundingCorner.BottomLeft, new Point2D.Double(left, bottom));

    corners = new HashMap<Corner, Point2D>();
    corners.put(Corner.Top, new Point2D.Double(center.getX(), top));
    corners.put(Corner.UpperRight, new Point2D.Double(right, (top + hOffset)));
    corners.put(Corner.LowerRight, new Point2D.Double(right, (bottom - hOffset)));
    corners.put(Corner.Bottom, new Point2D.Double(center.getX(), bottom));
    corners.put(Corner.LowerLeft, new Point2D.Double(left, (bottom - hOffset)));
    corners.put(Corner.UpperLeft, new Point2D.Double(left, (top + hOffset)));

    for (Corner corner : Corner.values()) {
        Point2D p2d = corners.get(corner);
        addPoint((int) p2d.getX(), (int) p2d.getY());
    }
}

From source file:genlab.gui.jfreechart.EnhancedSpiderWebPlot.java

/**
 * Returns the location for a label//from ww  w. ja v  a2  s. c  o  m
 *
 * @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);
}

From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java

/**
 * Translates a Java2D point on the chart to a screen location.
 *
 * @param java2DPoint  the Java2D point.
 *
 * @return the screen location./* w w w.  j av  a2 s. c  om*/
 */
public Point translateJava2DToScreen(Point2D java2DPoint) {
    Insets insets = getInsets();
    int x = (int) (java2DPoint.getX() + insets.left);
    int y = (int) (java2DPoint.getY() + insets.top);
    return new Point(x, y);
}

From source file:lcmc.common.ui.ResourceGraph.java

/** Returns position adjusted to scrollbar. */
protected Point2D posWithScrollbar(final Point2D oldPos) {
    final double newX = oldPos.getX() + scrollPane.getHorizontalScrollBar().getValue();
    final double newY = oldPos.getY() + scrollPane.getVerticalScrollBar().getValue();
    return new Point2D.Double(newX, newY);
}

From source file:lcmc.common.ui.ResourceGraph.java

protected final void showPopup(final JPopupMenu popup, final Point2D p) {
    final int posX = (int) p.getX();
    final int posY = (int) p.getY();
    swingUtils.invokeAndWait(new Runnable() {
        @Override/*w  w  w  . j a  va2 s .com*/
        public void run() {
            if (visualizationViewer.isShowing() && visualizationViewer.isDisplayable()) {
                popup.show(visualizationViewer, posX, posY);
                popup.repaint();
            }
        }
    });
}

From source file:lcmc.common.ui.ResourceGraph.java

/**
 * Scales the graph, so that all vertices can be seen. The graph can
 * get smaller but not bigger.// w  w  w  . ja  v  a2  s . c o  m
 */
public void scale() {
    final Point2D max = getLastPosition();
    final float maxXPos = (float) max.getX();
    final float maxYPos = (float) max.getY();
    if (maxXPos <= 0 || maxYPos <= 0) {
        return;
    }
    final Float vvX = new Float(getLayout().getSize().getWidth());
    final Float vvY = new Float(getLayout().getSize().getHeight());
    if (maxXPos > vvX || maxYPos > vvY) {
        final float x = maxXPos > vvX ? maxXPos : vvX;
        final float y = maxYPos > vvY ? maxYPos : vvY;
        getLayout().setSize(new Dimension((int) x, (int) y));
        visualizationViewer.setGraphLayout(getLayout());
    }
    if (changed) {
        somethingChangedReset();
    }
    visualizationViewer.repaint();
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java

private void placeStructures(Vector<AnnotationObject> annotations, boolean init) {

    // get starting point
    double y = thePlot.getRangeAxis().getRange().getUpperBound();
    double cur_x = thePlot.getDomainAxis().getRange().getLowerBound();

    double all_width = 0.;
    for (AnnotationObject a : annotations) {
        if (a.hasAnnotations())
            all_width += screenToDataX(rectangles_complete.get(a).width);
    }//  ww w.  ja  v a 2  s .com

    double min_pp_x = annotations.firstElement().getPeakPoint().getX();
    double max_pp_x = annotations.lastElement().getPeakPoint().getX();
    double center_pp_x = (max_pp_x + min_pp_x) / 2;

    cur_x = Math.max(cur_x, center_pp_x - all_width / 2);

    // place annotations
    for (AnnotationObject a : annotations) {
        Point2D pp = a.getPeakPoint();
        if (a.hasAnnotations()) {
            double cur_width = screenToDataX(rectangles_complete.get(a).width);
            double x = cur_x + cur_width / 2.;
            theDocument.getAnchor(a).setLocation(x, y);
            theDocument.getControlPoints().put(a,
                    theDocument.computeControlPoint(new Point2D.Double(x, y), pp));

            cur_x += cur_width;
        } else {
            theDocument.getAnchor(a).setLocation(pp.getX(), pp.getY());
            theDocument.getControlPoints().put(a, theDocument.computeControlPoint(pp, pp));
        }
    }

    // refine control points
    for (int i = 0; i < annotations.size(); i++) {
        AnnotationObject ai = annotations.get(i);
        Point2D aai = theDocument.getAnchor(ai);
        Point2D cpi = theDocument.getControlPoint(ai);

        if (aai.getX() < cpi.getX()) {
            for (int l = i + 1; l < annotations.size(); l++) {
                AnnotationObject al = annotations.get(l);
                Point2D aal = theDocument.getAnchor(al);
                Point2D cpl = theDocument.getControlPoint(al);

                if (aal.getX() > cpi.getX())
                    break;
                if (cpl.getY() < cpi.getY()) {
                    cpl.setLocation(cpl.getX(), cpi.getY());
                    ai = al;
                    aai = aal;
                    cpi = cpl;
                } else
                    break;
            }
        } else {
            for (int l = i - 1; l >= 0; l--) {
                AnnotationObject al = annotations.get(l);
                Point2D aal = theDocument.getAnchor(al);
                Point2D cpl = theDocument.getControlPoint(al);

                if (aal.getX() < cpi.getX())
                    break;
                if (cpl.getY() < cpi.getY()) {
                    cpl.setLocation(cpl.getX(), cpi.getY());
                    ai = al;
                    aai = aal;
                    cpi = cpl;
                } else
                    break;
            }
        }
    }

    // fire events
    if (init)
        theDocument.fireDocumentInit();
    else
        theDocument.fireDocumentChanged();
}