List of usage examples for java.awt.geom Point2D getY
public abstract double getY();
From source file:org.jfree.chart.demo.ScatterPlotDemo3.java
/** * Callback method for receiving notification of a mouse click on a chart. * * @param event information about the event. *///from www .j av a2 s.c om public void chartMouseClicked(ChartMouseEvent event) { int x = event.getTrigger().getX(); int y = event.getTrigger().getY(); // the following translation takes account of the fact that the chart image may // have been scaled up or down to fit the panel... Point2D p = chartPanel.translateScreenToJava2D(new Point(x, y)); // now convert the Java2D coordinate to axis coordinates... XYPlot plot = chartPanel.getChart().getXYPlot(); Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); double xx = plot.getDomainAxis().java2DToValue(p.getX(), dataArea, plot.getDomainAxisEdge()); double yy = plot.getRangeAxis().java2DToValue(p.getY(), dataArea, plot.getRangeAxisEdge()); // just for fun, lets convert the axis coordinates back to component coordinates... double xxx = plot.getDomainAxis().valueToJava2D(xx, dataArea, plot.getDomainAxisEdge()); double yyy = plot.getRangeAxis().valueToJava2D(yy, dataArea, plot.getRangeAxisEdge()); Point2D p2 = chartPanel.translateJava2DToScreen(new Point2D.Double(xxx, yyy)); System.out .println("Mouse coordinates are (" + x + ", " + y + "), in data space = (" + xx + ", " + yy + ")."); System.out.println("--> (" + p2.getX() + ", " + p2.getY() + ")"); }
From source file:org.jfree.experimental.chart.annotations.XYTitleAnnotation.java
/** * Draws the annotation. This method is called by the drawing code in the * {@link XYPlot} class, you don't normally need to call this method * directly./*from w w w .j a v a2 s. c o m*/ * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info if supplied, this info object will be populated with * entity information. */ public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { PlotOrientation orientation = plot.getOrientation(); AxisLocation domainAxisLocation = plot.getDomainAxisLocation(); AxisLocation rangeAxisLocation = plot.getRangeAxisLocation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(domainAxisLocation, orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(rangeAxisLocation, orientation); Range xRange = domainAxis.getRange(); Range yRange = rangeAxis.getRange(); double anchorX = 0.0; double anchorY = 0.0; if (this.coordinateType == XYCoordinateType.RELATIVE) { anchorX = xRange.getLowerBound() + (this.x * xRange.getLength()); anchorY = yRange.getLowerBound() + (this.y * yRange.getLength()); } else { anchorX = domainAxis.valueToJava2D(this.x, dataArea, domainEdge); anchorY = rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge); } float j2DX = (float) domainAxis.valueToJava2D(anchorX, dataArea, domainEdge); float j2DY = (float) rangeAxis.valueToJava2D(anchorY, dataArea, rangeEdge); float xx = 0.0f; float yy = 0.0f; if (orientation == PlotOrientation.HORIZONTAL) { xx = j2DY; yy = j2DX; } else if (orientation == PlotOrientation.VERTICAL) { xx = j2DX; yy = j2DY; } double maxW = dataArea.getWidth(); double maxH = dataArea.getHeight(); if (this.coordinateType == XYCoordinateType.RELATIVE) { if (this.maxWidth > 0.0) { maxW = maxW * this.maxWidth; } if (this.maxHeight > 0.0) { maxH = maxH * this.maxHeight; } } if (this.coordinateType == XYCoordinateType.DATA) { maxW = this.maxWidth; maxH = this.maxHeight; } RectangleConstraint rc = new RectangleConstraint(new Range(0, maxW), new Range(0, maxH)); Size2D size = this.title.arrange(g2, rc); Rectangle2D titleRect = new Rectangle2D.Double(0, 0, size.width, size.height); Point2D anchorPoint = RectangleAnchor.coordinates(titleRect, this.anchor); xx = xx - (float) anchorPoint.getX(); yy = yy - (float) anchorPoint.getY(); titleRect.setRect(xx, yy, titleRect.getWidth(), titleRect.getHeight()); BlockParams p = new BlockParams(); if (info != null) { if (info.getOwner().getEntityCollection() != null) { p.setGenerateEntities(true); } } Object result = this.title.draw(g2, titleRect, p); if (result instanceof EntityBlockResult) { EntityBlockResult ebr = (EntityBlockResult) result; info.getOwner().getEntityCollection().addAll(ebr.getEntityCollection()); } String toolTip = getToolTipText(); String url = getURL(); if (toolTip != null || url != null) { addEntity(info, new Rectangle2D.Float(xx, yy, (float) size.width, (float) size.height), rendererIndex, toolTip, url); } }
From source file:Visualizer.FRWeightedLayout.java
protected void calcAttraction(Functionality.Edge e) { Pair<Functionality.Node> endpoints = getGraph().getEndpoints(e); Functionality.Node v1 = endpoints.getFirst(); Functionality.Node v2 = endpoints.getSecond(); boolean v1_locked = isLocked(v1); boolean v2_locked = isLocked(v2); if (v1_locked && v2_locked) { // both locked, do nothing return;//from w ww . j a v a 2 s .c om } Point2D p1 = transform(v1); Point2D p2 = transform(v2); if (p1 == null || p2 == null) return; double xDelta = p1.getX() - p2.getX(); double yDelta = p1.getY() - p2.getY(); double deltaLength = Math.max(EPSILON, Math.sqrt((xDelta * xDelta) + (yDelta * yDelta))); double force = (deltaLength * deltaLength) / attraction_constant; if (DataModule.displayedGraph.edgeIsDotted(v1, v1)) { force = force / 2.5; } if (DataModule.displayedGraph.edgeIsNormal(v1, v2)) { force = force / 1.7; } if (Double.isNaN(force)) { throw new IllegalArgumentException( "Unexpected mathematical result in FRWeightedLayout:calcPositions [force]"); } double dx = (xDelta / deltaLength) * force; double dy = (yDelta / deltaLength) * force; if (v1_locked == false) { FRVertexData fvd1 = getFRData(v1); fvd1.offset(-dx, -dy); } if (v2_locked == false) { FRVertexData fvd2 = getFRData(v2); fvd2.offset(dx, dy); } }
From source file:net.panthema.BispanningGame.MyEditingGraphMousePlugin.java
/** * If the mouse is pressed in an empty area, create a new vertex there. If * the mouse is pressed on an existing vertex, prepare to create an edge * from that vertex to another//w w w . ja va 2 s .co m */ @SuppressWarnings("unchecked") public void mousePressed(MouseEvent e) { if (checkModifiers(e)) { final VisualizationViewer<V, E> vv = (VisualizationViewer<V, E>) e.getSource(); final Point2D p = e.getPoint(); GraphElementAccessor<V, E> pickSupport = vv.getPickSupport(); if (pickSupport != null) { Graph<V, E> graph = vv.getModel().getGraphLayout().getGraph(); final V vertex = pickSupport.getVertex(vv.getModel().getGraphLayout(), p.getX(), p.getY()); if (vertex != null) { // get ready to make an edge startVertex = vertex; down = e.getPoint(); transformEdgeShape(down, down); vv.addPostRenderPaintable(edgePaintable); } else { // make a new vertex V newVertex = vertexFactory.create(); Layout<V, E> layout = vv.getModel().getGraphLayout(); graph.addVertex(newVertex); layout.setLocation(newVertex, vv.getRenderContext().getMultiLayerTransformer().inverseTransform(e.getPoint())); if (graph instanceof MyGraph) ((MyGraph) graph).graphChanged(); } } vv.repaint(); } }
From source file:org.jfree.experimental.chart.plot.dial.StandardDialFrame.java
/** * Returns the shape for the window for this dial. Some dial layers will * request that their drawing be clipped within this window. * * @param frame the reference frame (<code>null</code> not permitted). * * @return The shape of the dial's window. *///from w w w . j a va 2s. com public Shape getWindow(Rectangle2D frame) { Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame, this.innerRadius, this.innerRadius); Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame, this.outerRadius, this.outerRadius); Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle, this.extent, Arc2D.OPEN); Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle + this.extent, -this.extent, Arc2D.OPEN); GeneralPath p = new GeneralPath(); Point2D point1 = inner.getStartPoint(); p.moveTo((float) point1.getX(), (float) point1.getY()); p.append(inner, true); p.append(outer, true); p.closePath(); return p; }
From source file:StrokeChooserPanel.java
/** * Draws a line using the sample stroke. * * @param g the graphics device./*w ww.j a v a 2s .c o m*/ */ public void paintComponent(final Graphics g) { final Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); final Dimension size = getSize(); final Insets insets = getInsets(); final double xx = insets.left; final double yy = insets.top; final double ww = size.getWidth() - insets.left - insets.right; final double hh = size.getHeight() - insets.top - insets.bottom; // calculate point one final Point2D one = new Point2D.Double(xx + 6, yy + hh / 2); // calculate point two final Point2D two = new Point2D.Double(xx + ww - 6, yy + hh / 2); // draw a circle at point one final Ellipse2D circle1 = new Ellipse2D.Double(one.getX() - 5, one.getY() - 5, 10, 10); final Ellipse2D circle2 = new Ellipse2D.Double(two.getX() - 6, two.getY() - 5, 10, 10); // draw a circle at point two g2.draw(circle1); g2.fill(circle1); g2.draw(circle2); g2.fill(circle2); // draw a line connecting the points final Line2D line = new Line2D.Double(one, two); if (this.stroke != null) { g2.setStroke(this.stroke); g2.draw(line); } }
From source file:org.jfree.experimental.chart.plot.dial.StandardDialFrame.java
protected Shape getOuterWindow(Rectangle2D frame) { double radiusMargin = 0.02; double angleMargin = 1.5; Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame, this.innerRadius - radiusMargin, this.innerRadius - radiusMargin); Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame, this.outerRadius + radiusMargin, this.outerRadius + radiusMargin); Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle - angleMargin, this.extent + 2 * angleMargin, Arc2D.OPEN);//w w w. j a v a 2 s .c o m Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle + angleMargin + this.extent, -this.extent - 2 * angleMargin, Arc2D.OPEN); GeneralPath p = new GeneralPath(); Point2D point1 = inner.getStartPoint(); p.moveTo((float) point1.getX(), (float) point1.getY()); p.append(inner, true); p.append(outer, true); p.closePath(); return p; }
From source file:lu.lippmann.cdb.graph.mouse.CadralEditingGraphMousePlugin.java
/** * When we are editing the graph : publish an event to select the node if * we right click on an existing node (to edit its properties) *//* ww w. j av a 2s.c o m*/ @SuppressWarnings("unchecked") @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == 3) { //right click final VisualizationViewer<CNode, CEdge> vv = (VisualizationViewer<CNode, CEdge>) e.getSource(); final Point2D p = e.getPoint(); final Layout<CNode, CEdge> layout = vv.getModel().getGraphLayout(); final GraphElementAccessor<CNode, CEdge> pickSupport = vv.getPickSupport(); if (pickSupport != null) { final CNode vertex = pickSupport.getVertex(layout, p.getX(), p.getY()); if (vertex != null) { commandDispatcher.dispatch(new SelectNodeCommand(vertex, 2)); } else { final CEdge edge = pickSupport.getEdge(layout, p.getX(), p.getY()); if (edge != null) { commandDispatcher.dispatch(new SelectEdgeCommand(edge, 2)); } } } } }
From source file:lu.lippmann.cdb.graph.mouse.CadralEditingGraphMousePlugin.java
/** * {@inheritDoc}//w w w . ja v a 2 s . c o m */ @Override public void mousePressed(MouseEvent e) { if (e.getButton() != 3) { //not with left click @SuppressWarnings("unchecked") final VisualizationViewer<CNode, CEdge> vv = (VisualizationViewer<CNode, CEdge>) e.getSource(); final Point2D p = e.getPoint(); final Layout<CNode, CEdge> layout = vv.getModel().getGraphLayout(); final GraphElementAccessor<CNode, CEdge> pickSupport = vv.getPickSupport(); if (pickSupport != null) { final CNode vertex = pickSupport.getVertex(layout, p.getX(), p.getY()); if (vertex == null) { return; } else { //set fields for mouseReleased startVertex = vertex; down = e.getPoint(); vv.addPostRenderPaintable(edgePaintable); vv.addPostRenderPaintable(arrowPaintable); edgeIsDirected = EdgeType.DIRECTED; } } } }
From source file:ru.jcorp.smartstreets.gui.map.bundle.GraphPopupMousePlugin.java
@Override protected void handlePopup(MouseEvent e) { // noinspection unchecked final VisualizationViewer<GraphNode, GraphLink> viewer = (VisualizationViewer<GraphNode, GraphLink>) e .getSource();// w w w . j a v a2 s . com final Layout<GraphNode, GraphLink> layout = viewer.getGraphLayout(); final Graph<GraphNode, GraphLink> graph = layout.getGraph(); final Point2D p = e.getPoint(); final SmartStreetsApp app = SmartStreetsApp.getInstance(); GraphElementAccessor<GraphNode, GraphLink> pickSupport = viewer.getPickSupport(); if (pickSupport != null) { popup.removeAll(); final GraphNode vertex = pickSupport.getVertex(layout, p.getX(), p.getY()); final GraphLink edge = pickSupport.getEdge(layout, p.getX(), p.getY()); final PickedState<GraphNode> pickedVertexState = viewer.getPickedVertexState(); final PickedState<GraphLink> pickedEdgeState = viewer.getPickedEdgeState(); if (vertex != null) { popup.add(new JMenuItem(new AbstractAction(app.getMessage("edit.setSource")) { @Override public void actionPerformed(ActionEvent e) { SmartMapNode mapNode = vertex.getMapNode(); editor.setSourceNode(mapNode); } })); popup.add(new JMenuItem(new AbstractAction(app.getMessage("edit.setDest")) { @Override public void actionPerformed(ActionEvent e) { SmartMapNode mapNode = vertex.getMapNode(); editor.setDestNode(mapNode); } })); popup.add(new JMenuItem(new AbstractAction(app.getMessage("edit.properties")) { @Override public void actionPerformed(ActionEvent e) { SmartMapNode mapNode = vertex.getMapNode(); NodeEditor nodeEditor = new NodeEditor(mapNode); nodeEditor.setLocationRelativeTo(editor); nodeEditor.setVisible(true); editor.clearPathSheduled(); viewer.repaint(); } })); popup.add(new AbstractAction(app.getMessage("graph.deleteVertex")) { @Override public void actionPerformed(ActionEvent e) { editor.clearPathSheduled(); pickedVertexState.pick(vertex, false); graph.removeVertex(vertex); editor.getMapContext().removeNode(vertex.getMapNode()); viewer.repaint(); } }); } else if (edge != null) { popup.add(new JMenuItem(new AbstractAction(app.getMessage("edit.properties")) { @Override public void actionPerformed(ActionEvent e) { SmartMapLine mapLine = edge.getMapLine(); LineEditor lineEditor = new LineEditor(mapLine, edge.getRoadSign()); lineEditor.setLocationRelativeTo(editor); lineEditor.setVisible(true); editor.clearPathSheduled(); viewer.repaint(); } })); popup.add(new AbstractAction(app.getMessage("graph.deleteEdge")) { @Override public void actionPerformed(ActionEvent e) { editor.clearPathSheduled(); pickedEdgeState.pick(edge, false); graph.removeEdge(edge); graph.removeEdge(edge.getNeighbor()); editor.getMapContext().removeLine(edge.getMapLine()); viewer.repaint(); } }); } else { popup.add(new AbstractAction(app.getMessage("graph.createVertex")) { @Override public void actionPerformed(ActionEvent e) { editor.clearPathSheduled(); GraphNode newVertex = vertexFactory.create(); graph.addVertex(newVertex); layout.setLocation(newVertex, viewer.getRenderContext().getMultiLayerTransformer().inverseTransform(p)); viewer.repaint(); } }); } if (popup.getComponentCount() > 0) { popup.show(viewer, e.getX(), e.getY()); } } }