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:com.att.aro.ui.view.diagnostictab.GraphPanel.java

@Override
public void chartMouseClicked(ChartMouseEvent chartmouseevent) {
    Point2D point = chartmouseevent.getTrigger().getPoint();
    Rectangle2D plotArea = getChartPanel().getScreenDataArea();

    XYPlot plot = (XYPlot) getAdvancedGraph().getPlot();
    final double lastChartX = new Double(
            plot.getDomainAxis().java2DToValue(point.getX(), plotArea, plot.getDomainAxisEdge()));

    // setCrossHair(lastChartX);

    // SwingUtilities.invokeLater(new Runnable() {
    // @Override/*ww  w.j a va  2  s .co m*/
    // public void run() {
    // setCrossHair(lastChartX);
    // }
    // });

    for (GraphPanelListener gpl : listeners) {
        gpl.graphPanelClicked(lastChartX);

        /* New added @Tinbit */
        ChartEntity entity = chartmouseevent.getEntity();

        if (entity instanceof XYItemEntity) {
            XYItemEntity xyItem = (XYItemEntity) entity;

            XYDataset xyDataset = xyItem.getDataset();
            int seriesIndex = xyItem.getSeriesIndex();
            int itemIndex = xyItem.getItem();

            double xDataValue = xyDataset.getXValue(seriesIndex, itemIndex);
            double yDataValue = xyDataset.getYValue(seriesIndex, itemIndex);

            Map<Integer, VideoEvent> veSegment = vcPlot.getChunk(xDataValue);
            int indexKey = 0;
            if (vcPlot.isDataItemPoint(xDataValue, yDataValue)) {

                if (veSegment != null) {

                    for (int key : veSegment.keySet()) {
                        // String value="Chunk "+(key+1)+" at
                        // "+String.format("%.2f",
                        // veSegment.get(key).getDLTimeStamp())+"S";
                        chunkInfo.put(key, veSegment.get(key));
                        // chunkInfo.add(value);
                    }
                    indexKey = (int) veSegment.keySet().toArray()[0];
                }

                launchSliderDialog(indexKey);

            } else if (vcPlot.getBufferTimePlot().isDataItemStallPoint(xDataValue, yDataValue) != null) {
                VideoEvent segmentToPlay = vcPlot.getBufferTimePlot().isDataItemStallPoint(xDataValue,
                        yDataValue);
                veSegment = vcPlot.getSegmentToPlayLocation(segmentToPlay);
                if (veSegment != null) {
                    for (int key : veSegment.keySet()) {
                        chunkInfo.put(key, veSegment.get(key));
                    }
                    indexKey = (int) veSegment.keySet().toArray()[0];
                }
                launchSliderDialog(indexKey);
            }
        }
    }
}

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

/**
 * Draws a radar plot polygon.//  www. j  a  v a  2  s  .  c o m
 *
 * @param g2 the graphics device.
 * @param plotArea the area we are plotting in (already adjusted).
 * @param centre the centre point of the radar axes
 * @param info chart rendering info.
 * @param series the series within the dataset we are plotting
 * @param catCount the number of categories per radar plot
 * @param headH the data point height
 * @param headW the data point width
 */
protected void drawRadarPoly(Graphics2D g2, Rectangle2D plotArea, Point2D centre, PlotRenderingInfo info,
        int series, int catCount, double headH, double headW) {

    Polygon polygon = new Polygon();

    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    // plot the data...
    for (int cat = 0; cat < catCount; cat++) {

        Number dataValue = getPlotValue(series, cat);

        if (dataValue != null) {
            double value = dataValue.doubleValue();

            if (value >= 0) { // draw the polygon series...

                // Finds our starting angle from the centre for this axis

                double angle = getStartAngle()
                        + (getDirection().getFactor() * cat * 360 / (catCount > 2 ? catCount : 3));

                // The following angle calc will ensure there isn't a top
                // vertical axis - this may be useful if you don't want any
                // given criteria to 'appear' move important than the
                // others..
                //  + (getDirection().getFactor()
                //        * (cat + 0.5) * 360 / catCount);

                // find the point at the appropriate distance end point
                // along the axis/angle identified above and add it to the
                // polygon

                Point2D point = getWebPoint(plotArea, angle, value / this.maxValue);
                polygon.addPoint((int) point.getX(), (int) point.getY());

                // put an elipse at the point being plotted..

                Paint paint = getSeriesPaint(series);
                Paint outlinePaint = getSeriesOutlinePaint(series);
                Stroke outlineStroke = getSeriesOutlineStroke(series);

                Ellipse2D head = new Ellipse2D.Double(point.getX() - headW / 2, point.getY() - headH / 2, headW,
                        headH);
                g2.setPaint(paint);
                g2.fill(head);
                g2.setStroke(outlineStroke);
                g2.setPaint(outlinePaint);
                g2.draw(head);

                if (entities != null) {
                    int row = 0;
                    int col = 0;
                    if (this.dataExtractOrder == TableOrder.BY_ROW) {
                        row = series;
                        col = cat;
                    } else {
                        row = cat;
                        col = series;
                    }
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(this.dataset, row, col);
                    }

                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset, row, col);
                    }

                    Shape area = new Rectangle((int) (point.getX() - headW), (int) (point.getY() - headH),
                            (int) (headW * 2), (int) (headH * 2));
                    CategoryItemEntity entity = new CategoryItemEntity(area, tip, url, this.dataset,
                            this.dataset.getRowKey(row), this.dataset.getColumnKey(col));
                    entities.add(entity);
                }

            }
        }
    }
    // Plot the polygon

    Paint paint = getSeriesPaint(series);
    g2.setPaint(paint);
    g2.setStroke(getSeriesOutlineStroke(series));
    g2.draw(polygon);

    // Lastly, fill the web polygon if this is required

    if (this.webFilled) {
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
        g2.fill(polygon);
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
    }
}

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

/** Returns position of the last vertex. */
protected final Point2D getLastPosition() {
    double lastX = 0;
    double lastY = 0;
    final Map<Vertex, Point2D> vl = getVertexLocations();
    for (final Map.Entry<Vertex, Point2D> localtionEntry : vl.entrySet()) {
        final Point2D last = localtionEntry.getValue();
        if (last != null) {
            if (last.getX() > lastX) {
                lastX = last.getX();// ww  w .j ava2  s  .c  o  m
            }
            if (last.getY() > lastY) {
                lastY = last.getY();
            }
        }
    }
    putVertexLocations();
    return new Point2D.Double(lastX, lastY + 40);
}

From source file:com.net2plan.gui.tools.GUINetworkDesign.java

@Override
public void moveNodeTo(final GUINode guiNode, final Point2D toPoint) {
    if (!vs.isNetPlanEditable())
        throw new UnsupportedOperationException("NetPlan is not editable");

    final ITopologyCanvas canvas = topologyPanel.getCanvas();
    final Node node = guiNode.getAssociatedNetPlanNode();

    final Point2D netPlanPoint = canvas.getCanvasPointFromMovement(toPoint);
    if (netPlanPoint == null)
        return;//from   w w w . j  ava 2  s.  c om

    final Point2D jungPoint = canvas.getCanvasPointFromNetPlanPoint(toPoint);

    node.setXYPositionMap(netPlanPoint);

    viewEditTopTables.updateView();

    // Updating GUINodes position having in mind the selected layer.
    final List<GUINode> guiNodes = vs.getCanvasVerticallyStackedGUINodes(node);
    final int selectedLayerVisualizationOrder = vs
            .getCanvasVisualizationOrderRemovingNonVisible(guiNode.getLayer());

    for (GUINode stackedGUINode : guiNodes) {
        final int vlIndex = vs.getCanvasVisualizationOrderRemovingNonVisible(stackedGUINode.getLayer());
        final double interLayerDistanceInNpCoord = canvas.getInterLayerDistanceInNpCoordinates();

        if (vlIndex > selectedLayerVisualizationOrder) {
            final int layerDistance = vlIndex - selectedLayerVisualizationOrder;
            canvas.moveVertexToXYPosition(stackedGUINode, new Point2D.Double(jungPoint.getX(),
                    -(jungPoint.getY() + (layerDistance * interLayerDistanceInNpCoord))));
        } else if (vlIndex == selectedLayerVisualizationOrder) {
            canvas.moveVertexToXYPosition(stackedGUINode,
                    new Point2D.Double(jungPoint.getX(), -(jungPoint.getY())));
        } else {
            final int layerDistance = selectedLayerVisualizationOrder - vlIndex;
            canvas.moveVertexToXYPosition(stackedGUINode, new Point2D.Double(jungPoint.getX(),
                    -(jungPoint.getY() - (layerDistance * interLayerDistanceInNpCoord))));
        }
    }

    canvas.refresh();
}

From source file:org.gumtree.vis.hist2d.Hist2DPanel.java

private void moveMask(Point2D point) {
    if (maskMovePoint != null && getSelectedMask() != null) {
        Rectangle2D frame = getSelectedMask().getRectangleFrame();
        getSelectedMask().setRectangleFrame(new Rectangle2D.Double(
                frame.getMinX() + point.getX() - maskMovePoint.getX(),
                frame.getMinY() + point.getY() - maskMovePoint.getY(), frame.getWidth(), frame.getHeight()));
        maskMovePoint = point;//from   w w w . ja v  a  2 s .co  m
        fireMaskUpdateEvent(getSelectedMask());
    }
}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

private void makeNewMask(MouseEvent e) {
    Point2D screenPoint = translateScreenToJava2D(e.getPoint());
    if (Double.isNaN(maskPoint) || Math.abs(screenPoint.getX() - maskPoint) < minMaskWidth) {
        return;/*from  ww w . j  a v a  2s  . co  m*/
    }
    Graphics2D g2 = (Graphics2D) getGraphics();

    // erase the previous zoom rectangle (if any).  We only need to do
    // this is we are using XOR mode, which we do when we're not using
    // the buffer (if there is a buffer, then at the end of this method we
    // just trigger a repaint)
    if (!isDoubleBuffered()) {
        //          drawZoomRectangle(g2, true);
        ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), getMaskMap(), getSelectedMask(), getChart());
    }

    //       boolean hZoom = false;
    //       boolean vZoom = false;
    //       if (this.orientation == PlotOrientation.HORIZONTAL) {
    //          hZoom = this.rangeZoomable;
    //          vZoom = this.domainZoomable;
    //       }
    //       else {
    //          hZoom = this.domainZoomable;
    //          vZoom = this.rangeZoomable;
    //       }
    Rectangle2D scaledDataArea = getScreenDataArea();
    //             (int) this.maskPoint.getX(), (int) this.maskPoint.getY());
    // Working on the current mask. Only create one new mask per drag-drawing.
    if (currentMaskRectangle == null) {
        boolean isInclusive = (e.getModifiers() & maskingExclusiveMask) == 0;
        currentMaskRectangle = new RangeMask(isInclusive);
        //           currentMaskRectangle.setFillColor(getNextMaskColor(isInclusive));
        //           getMasks().add(currentMaskRectangle);
        addMask(currentMaskRectangle);
    }
    // selected rectangle shouldn't extend outside the data area...
    double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
    // Update the current mask.
    Insets insets = getInsets();
    double startX = ChartMaskingUtilities.translateScreenX((maskPoint - insets.left) / getScaleX(),
            getScreenDataArea(), getChart());
    double endX = ChartMaskingUtilities.translateScreenX((xmax - insets.left) / getScaleX(),
            getScreenDataArea(), getChart());
    updateCurrentDomainMask(startX, endX);
    // Draw the new zoom rectangle...
    if (isDoubleBuffered()) {
        repaint();
    } else {
        // with no buffer, we use XOR to draw the rectangle "over" the
        // chart...
        ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), getMaskMap(), getSelectedMask(), getChart());
    }
    g2.dispose();
}

From source file:com.munch.exchange.ExchangeChartComposite.java

/**
 * Translates a Java2D point on the chart to a screen location.
 *
 * @param java2DPoint  the Java2D point.
 *
 * @return The screen location.//from   w w w.ja  v a  2  s. com
 */
public Point translateJava2DToScreen(Point2D java2DPoint) {
    Rectangle insets = this.getClientArea();
    int x = (int) (java2DPoint.getX() * this.scaleX + insets.x);
    int y = (int) (java2DPoint.getY() * this.scaleY + insets.y);
    return new Point(x, y);
}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

private void changeLegendWidth(Point2D point) {
    if (isInternalLegendEnabled && isInternalLegendSelected && legendPoint != null) {
        Rectangle2D screenArea = getScreenDataArea();
        if (point.getX() < screenArea.getMaxX()) {
            internalLegendSetup.setRect(internalLegendSetup.getX(), internalLegendSetup.getY(),
                    point.getX() - screenArea.getMaxX() + internalLegendSetup.getX(),
                    internalLegendSetup.getHeight());
        }//w  w  w  .  j  a  v  a 2 s .c om
    }
}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

private void changeLegendX(Point2D point) {
    if (isInternalLegendEnabled && isInternalLegendSelected && legendPoint != null) {
        Rectangle2D screenArea = getScreenDataArea();
        if (point.getX() < screenArea.getMaxX()) {
            internalLegendSetup.setRect(
                    screenArea.getMaxX() - point.getX(), internalLegendSetup.getY(), screenArea.getMaxX()
                            - internalLegendSetup.getX() + internalLegendSetup.getWidth() - point.getX(),
                    internalLegendSetup.getHeight());
        }// w  w w  .j a v  a 2  s  .  c  om
    }
}

From source file:lcmc.gui.ResourceGraph.java

/**
 * Scales the graph, so that all vertices can be seen. The graph can
 * get smaller but not bigger.//w  ww .ja  v  a  2s  . co  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));
        vv.setGraphLayout(getLayout());
    }
    if (changed) {
        somethingChangedReset();
    }
    vv.repaint();
}