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:edu.uci.ics.jung.visualization.picking.ShapePickSupport.java

/**
 * Retrieves the shape template for <code>e</code> and
 * transforms it according to the positions of its endpoints
 * in <code>layout</code>./*from  www.jav  a2s  .  c  o  m*/
 * @param layout the <code>Layout</code> which specifies
 * <code>e</code>'s endpoints' positions
 * @param e the edge whose shape is to be returned
 * @return
 */
private Shape getTransformedEdgeShape(Layout<V, E> layout, E e) {
    Pair<V> pair = layout.getGraph().getEndpoints(e);
    V v1 = pair.getFirst();
    V v2 = pair.getSecond();
    boolean isLoop = v1.equals(v2);
    Point2D p1 = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v1));
    Point2D p2 = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v2));
    if (p1 == null || p2 == null)
        return null;
    float x1 = (float) p1.getX();
    float y1 = (float) p1.getY();
    float x2 = (float) p2.getX();
    float y2 = (float) p2.getY();

    // translate the edge to the starting vertex
    AffineTransform xform = AffineTransform.getTranslateInstance(x1, y1);

    Shape edgeShape = vv.getRenderContext().getEdgeShapeTransformer()
            .transform(Context.<Graph<V, E>, E>getInstance(vv.getGraphLayout().getGraph(), e));
    if (isLoop) {
        // make the loops proportional to the size of the vertex
        Shape s2 = vv.getRenderContext().getVertexShapeTransformer().transform(v2);
        Rectangle2D s2Bounds = s2.getBounds2D();
        xform.scale(s2Bounds.getWidth(), s2Bounds.getHeight());
        // move the loop so that the nadir is centered in the vertex
        xform.translate(0, -edgeShape.getBounds2D().getHeight() / 2);
    } else {
        float dx = x2 - x1;
        float dy = y2 - y1;
        // rotate the edge to the angle between the vertices
        double theta = Math.atan2(dy, dx);
        xform.rotate(theta);
        // stretch the edge to span the distance between the vertices
        float dist = (float) Math.sqrt(dx * dx + dy * dy);
        xform.scale(dist, 1.0f);
    }

    // transform the edge to its location and dimensions
    edgeShape = xform.createTransformedShape(edgeShape);
    return edgeShape;
}

From source file:org.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java

/**
 * Method for calculating the minimum bounding rectangle for the given
 * tree layout//from w w w .j  a  v  a2s . c  om
 * @param treeLayout
 *          the layout to calculate MBR for
 * @param rectangle
 *          the rectangle up to now (should be null initially)
 * @return
 *          the MBR
 */
private Rectangle2D.Double calculateBounds(VisualTreeNode treeLayout, Rectangle2D.Double rectangle) {
    Point2D position = treeLayout.getPosition();
    if (rectangle == null) {
        rectangle = new Rectangle2D.Double(position.getX(), position.getY(), 0.0, 0.0);
    } else {
        if (position.getX() < rectangle.getMinX()) {
            double xDiff = rectangle.getMinX() - position.getX();
            rectangle.x -= xDiff;
            rectangle.width += xDiff;
        } else if (position.getX() > rectangle.getMaxX()) {
            double xDiff = position.getX() - rectangle.getMaxX();
            rectangle.width += xDiff;
        }

        if (position.getY() < rectangle.getMinY()) {
            double yDiff = rectangle.getMinY() - position.getY();
            rectangle.y -= yDiff;
            rectangle.height += yDiff;
        } else if (position.getY() > rectangle.getMaxY()) {
            double yDiff = position.getY() - rectangle.getMaxY();
            rectangle.height += yDiff;
        }
    }

    for (VisualTreeNode childNode : treeLayout.getChildNodes()) {
        rectangle = this.calculateBounds(childNode, rectangle);
    }

    return rectangle;
}

From source file:pt.lsts.neptus.plugins.sunfish.awareness.SituationAwareness.java

@Override
public void paintInteraction(Graphics2D g, StateRenderer2D source) {
    super.paintInteraction(g, source);
    g.setStroke(new BasicStroke(1f));
    paint(g, source);// w  w w .j  a v  a  2  s .  c  om
    AssetPosition pivot = intercepted;
    if (pivot != null) {
        Point2D pt = source.getScreenPosition(pivot.getLoc());
        g.setColor(Color.white);
        g.draw(new Ellipse2D.Double(pt.getX() - 6, pt.getY() - 6, 12, 12));
        if (assetProperties.containsKey(pivot.getAssetName()))
            pivot.putExtra("Description", assetProperties.get(pivot.getAssetName()).description);
        if (assetProperties.containsKey(pivot.getAssetName()))
            pivot.putExtra("Friendly name", assetProperties.get(pivot.getAssetName()).friendly);

        lbl.setOpaque(true);
        lbl.setBackground(new Color(255, 255, 255, 128));
        lbl.setText(pivot.getHtml());
        Dimension d = lbl.getPreferredSize();
        lbl.setSize(d);
        Graphics copy = g.create();
        copy.translate(10, 10);
        lbl.paint(copy);
    }

    for (AssetTrack t : assets.values()) {
        AssetPosition prev = t.getLatest();
        AssetPosition pred = t.getPrediction();

        if (prev != null && pred != null) {
            if (prev.getTimestamp() < oldestTimestampSelection
                    || prev.getTimestamp() > newestTimestampSelection)
                continue;
            g.setColor(new Color(t.getColor().getRed(), t.getColor().getGreen(), t.getColor().getBlue(), 128));
            Point2D pt1 = source.getScreenPosition(prev.getLoc());
            Point2D pt2 = source.getScreenPosition(pred.getLoc());
            if (pt1.distance(pt2) < 1000)
                g.draw(new Line2D.Double(pt1, pt2));
        }
    }
}

From source file:extern.NpairsBoxAndWhiskerRenderer.java

/**
 * Draws a dot to represent an outlier.//from   w w  w.ja va 2  s  . co m
 *
 * @param point  the location.
 * @param oRadius  the radius.
 * @param g2  the graphics device.
 */
private void drawEllipse(Point2D point, double oRadius, Graphics2D g2) {
    Ellipse2D dot = new Ellipse2D.Double(point.getX() + oRadius / 2, point.getY(), oRadius, oRadius);
    g2.draw(dot);
}

From source file:org.bigwiv.blastgraph.gui.graphvisualization.EWLayout.java

protected synchronized void calcPositions(V v) {
    VertexData fvd = getData(v);//  www . j a va 2 s. c  om
    if (fvd == null)
        return;
    Point2D xyd = transform(v);
    double deltaLength = Math.max(EPSILON, fvd.norm());

    double newXDisp = fvd.getX() / deltaLength * Math.min(deltaLength, temperature);

    if (Double.isNaN(newXDisp)) {
        throw new IllegalArgumentException("Unexpected mathematical result in FRLayout:calcPositions [xdisp]");
    }

    double newYDisp = fvd.getY() / deltaLength * Math.min(deltaLength, temperature);
    xyd.setLocation(xyd.getX() + newXDisp, xyd.getY() + newYDisp);

    double borderWidth = getSize().getWidth() / 50.0;
    double newXPos = xyd.getX();
    if (newXPos < borderWidth) {
        newXPos = borderWidth + Math.random() * borderWidth * 2.0;
    } else if (newXPos > (getSize().getWidth() - borderWidth)) {
        newXPos = getSize().getWidth() - borderWidth - Math.random() * borderWidth * 2.0;
    }

    double newYPos = xyd.getY();
    if (newYPos < borderWidth) {
        newYPos = borderWidth + Math.random() * borderWidth * 2.0;
    } else if (newYPos > (getSize().getHeight() - borderWidth)) {
        newYPos = getSize().getHeight() - borderWidth - Math.random() * borderWidth * 2.0;
    }

    xyd.setLocation(newXPos, newYPos);
}

From source file:Visualizer.FRWeightedLayout.java

protected synchronized void calcPositions(Functionality.Node v) {
    FRVertexData fvd = getFRData(v);//  w  w  w .j av a  2 s . co  m
    if (fvd == null)
        return;
    Point2D xyd = transform(v);
    double deltaLength = Math.max(EPSILON, fvd.norm());

    double newXDisp = fvd.getX() / deltaLength * Math.min(deltaLength, temperature);

    if (Double.isNaN(newXDisp)) {
        throw new IllegalArgumentException(
                "Unexpected mathematical result in FRWeightedLayout:calcPositions [xdisp]");
    }

    double newYDisp = fvd.getY() / deltaLength * Math.min(deltaLength, temperature);
    xyd.setLocation(xyd.getX() + newXDisp, xyd.getY() + newYDisp);

    double borderWidth = getSize().getWidth() / 50.0;
    double newXPos = xyd.getX();
    if (newXPos < borderWidth) {
        newXPos = borderWidth + Math.random() * borderWidth * 2.0;
    } else if (newXPos > (getSize().getWidth() - borderWidth)) {
        newXPos = getSize().getWidth() - borderWidth - Math.random() * borderWidth * 2.0;
    }

    double newYPos = xyd.getY();
    if (newYPos < borderWidth) {
        newYPos = borderWidth + Math.random() * borderWidth * 2.0;
    } else if (newYPos > (getSize().getHeight() - borderWidth)) {
        newYPos = getSize().getHeight() - borderWidth - Math.random() * borderWidth * 2.0;
    }

    xyd.setLocation(newXPos, newYPos);
}

From source file:org.esa.snap.rcp.statistics.ProfilePlotPanel.java

private ChartPanel createChartPanel(JFreeChart chart) {
    profilePlotDisplay = new ChartPanel(chart);

    MaskSelectionToolSupport maskSelectionToolSupport = new MaskSelectionToolSupport(this, profilePlotDisplay,
            "profile_plot_area", "Mask generated from selected profile plot area", Color.RED,
            PlotAreaSelectionTool.AreaType.Y_RANGE) {

        @Override/*from   w  w  w .  ja  v a  2s  . c o m*/
        protected String createMaskExpression(PlotAreaSelectionTool.AreaType areaType, Shape shape) {
            Rectangle2D bounds = shape.getBounds2D();
            return createMaskExpression(bounds.getMinY(), bounds.getMaxY());
        }

        protected String createMaskExpression(double x1, double x2) {
            String bandName = BandArithmetic.createExternalName(getRaster().getName());
            return String.format("%s >= %s && %s <= %s", bandName, x1, bandName, x2);
        }
    };

    profilePlotDisplay.addChartMouseListener(new XYPlotMarker(profilePlotDisplay, new XYPlotMarker.Listener() {
        @Override
        public void pointSelected(XYDataset xyDataset, int seriesIndex, Point2D dataPoint) {
            if (profileData != null) {
                GeoPos[] geoPositions = profileData.getGeoPositions();
                int index = (int) dataPoint.getX();
                if (index >= 0 && index < geoPositions.length) {
                    if (cursorSynchronizer == null) {
                        cursorSynchronizer = new DefaultCursorSynchronizer();
                    }
                    if (!cursorSynchronizer.isEnabled()) {
                        cursorSynchronizer.setEnabled(true);
                    }
                    cursorSynchronizer.updateCursorOverlays(geoPositions[index]);
                }
            }
        }

        @Override
        public void pointDeselected() {
            cursorSynchronizer.setEnabled(false);
        }
    }));
    profilePlotDisplay.setInitialDelay(200);
    profilePlotDisplay.setDismissDelay(1500);
    profilePlotDisplay.setReshowDelay(200);
    profilePlotDisplay.setZoomTriggerDistance(5);
    profilePlotDisplay.getPopupMenu().addSeparator();
    profilePlotDisplay.getPopupMenu().add(maskSelectionToolSupport.createMaskSelectionModeMenuItem());
    profilePlotDisplay.getPopupMenu().add(maskSelectionToolSupport.createDeleteMaskMenuItem());
    profilePlotDisplay.getPopupMenu().addSeparator();
    profilePlotDisplay.getPopupMenu().add(createCopyDataToClipboardMenuItem());

    return profilePlotDisplay;
}

From source file:org.esa.beam.visat.toolviews.stat.ProfilePlotPanel.java

private ChartPanel createChartPanel(JFreeChart chart) {
    profilePlotDisplay = new ChartPanel(chart);

    MaskSelectionToolSupport maskSelectionToolSupport = new MaskSelectionToolSupport(this, profilePlotDisplay,
            "profile_plot_area", "Mask generated from selected profile plot area", Color.RED,
            PlotAreaSelectionTool.AreaType.Y_RANGE) {

        @Override// w w w .ja  v a 2s .c  om
        protected String createMaskExpression(PlotAreaSelectionTool.AreaType areaType, Shape shape) {
            Rectangle2D bounds = shape.getBounds2D();
            return createMaskExpression(bounds.getMinY(), bounds.getMaxY());
        }

        protected String createMaskExpression(double x1, double x2) {
            String bandName = BandArithmetic.createExternalName(getRaster().getName());
            return String.format("%s >= %s && %s <= %s", bandName, x1, bandName, x2);
        }
    };

    profilePlotDisplay.addChartMouseListener(new XYPlotMarker(profilePlotDisplay, new XYPlotMarker.Listener() {
        @Override
        public void pointSelected(XYDataset xyDataset, int seriesIndex, Point2D dataPoint) {
            if (profileData != null) {
                GeoPos[] geoPositions = profileData.getGeoPositions();
                int index = (int) dataPoint.getX();
                if (index >= 0 && index < geoPositions.length) {
                    if (cursorSynchronizer == null) {
                        cursorSynchronizer = new CursorSynchronizer(VisatApp.getApp());
                    }
                    if (!cursorSynchronizer.isEnabled()) {
                        cursorSynchronizer.setEnabled(true);
                    }
                    cursorSynchronizer.updateCursorOverlays(geoPositions[index]);
                }
            }
        }

        @Override
        public void pointDeselected() {
            cursorSynchronizer.setEnabled(false);
        }
    }));
    profilePlotDisplay.setInitialDelay(200);
    profilePlotDisplay.setDismissDelay(1500);
    profilePlotDisplay.setReshowDelay(200);
    profilePlotDisplay.setZoomTriggerDistance(5);
    profilePlotDisplay.getPopupMenu().addSeparator();
    profilePlotDisplay.getPopupMenu().add(maskSelectionToolSupport.createMaskSelectionModeMenuItem());
    profilePlotDisplay.getPopupMenu().add(maskSelectionToolSupport.createDeleteMaskMenuItem());
    profilePlotDisplay.getPopupMenu().addSeparator();
    profilePlotDisplay.getPopupMenu().add(createCopyDataToClipboardMenuItem());

    return profilePlotDisplay;
}

From source file:com.wasteofplastic.beaconz.Register.java

/**
 * Deletes any links that starts/*w  w  w. j  a  v  a2  s . c o m*/
 * @param faction
 * @param point
 * NOTE: THIS ISN'T USED ANYWHERE *****************************
 */
public void deleteBeaconLinks(Team team, Point2D point) {
    Set<Line2D> linkSet = new HashSet<Line2D>();
    if (links.containsKey(team)) {
        linkSet = links.get(team);
    }
    Iterator<Line2D> it = linkSet.iterator();
    while (it.hasNext()) {
        Line2D line = it.next();
        if (line.getP1().equals(point) || line.getP2().equals(point)) {
            // Devisualize - TODO: make async or something
            for (Iterator<Point2D> lineIt = new LineIterator(line); lineIt.hasNext();) {
                Point2D current = lineIt.next();
                Block b = getBeaconzWorld().getBlockAt((int) current.getX(),
                        getBeaconzWorld().getMaxHeight() - 1, (int) current.getY());
                b.setType(Material.AIR);
            }
            it.remove();
            getScorecard().refreshScores(team, "links");
        }
    }
}

From source file:Hexagon.java

public void attach(Hexagon toTranslate, Direction direction) {
    double horSize = size + hOffset;
    /**//from   ww  w .  ja va2  s . c  o  m
      * To start with, we need to know toTranslate's position RELATIVE to ours
      */
    Point2D topLeft = getBoundPoint(BoundingCorner.TopLeft);
    Point2D toTranslateTopLeft = toTranslate.getBoundPoint(BoundingCorner.TopLeft);
    double deltaX = topLeft.getX() - toTranslateTopLeft.getX();
    double deltaY = topLeft.getY() - toTranslateTopLeft.getY();
    // that should be enough to line them up exactly... now offset it...

    switch (direction) {
    case NorthEast:
        deltaX += wOffset;
        deltaY -= horSize;
        break;
    case East:
        deltaX += width;
        break;
    case SouthEast:
        deltaX += wOffset;
        deltaY += horSize;
        break;
    case SouthWest:
        deltaX -= wOffset;
        deltaY += horSize;
        break;
    case West:
        deltaX -= width;
        break;
    case NorthWest:
        deltaX -= wOffset;
        deltaY -= horSize;
        break;
    }
    toTranslate.translate(deltaX, deltaY);
}