List of usage examples for java.awt.geom Point2D getX
public abstract double getX();
From source file:edu.uci.ics.jung.algorithms.layout.AggregateLayout.java
/** * Returns the location of the vertex. The location is specified first * by the sublayouts, and then by the base layout if no sublayouts operate * on this vertex.//from ww w. jav a2 s.co m * @return the location of the vertex * @see org.apache.commons.collections15.Transformer#transform(java.lang.Object) */ public Point2D transform(V v) { boolean wasInSublayout = false; for (Layout<V, E> layout : layouts.keySet()) { if (layout.getGraph().getVertices().contains(v)) { wasInSublayout = true; Point2D center = layouts.get(layout); // transform by the layout itself, but offset to the // center of the sublayout Dimension d = layout.getSize(); AffineTransform at = AffineTransform.getTranslateInstance(center.getX() - d.width / 2, center.getY() - d.height / 2); return at.transform(layout.transform(v), null); } } if (wasInSublayout == false) { return delegate.transform(v); } return null; }
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) *///from ww w. j ava2 s. 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:org.apache.fontbox.cff.CharStringRenderer.java
private void rlineTo(Number dx, Number dy) { Point2D point = path.getCurrentPoint(); path.lineTo((float) (point.getX() + dx.doubleValue()), (float) (point.getY() + dy.doubleValue())); }
From source file:edu.uci.ics.jung.algorithms.layout.AggregateLayout.java
/** * @param v/*from ww w. ja v a 2 s .co m*/ * @param location * @see edu.uci.ics.jung.algorithms.layout.Layout#setLocation(java.lang.Object, java.awt.geom.Point2D) */ public void setLocation(V v, Point2D location) { boolean wasInSublayout = false; for (Layout<V, E> layout : layouts.keySet()) { if (layout.getGraph().getVertices().contains(v)) { Point2D center = layouts.get(layout); // transform by the layout itself, but offset to the // center of the sublayout Dimension d = layout.getSize(); AffineTransform at = AffineTransform.getTranslateInstance(-center.getX() + d.width / 2, -center.getY() + d.height / 2); Point2D localLocation = at.transform(location, null); layout.setLocation(v, localLocation); wasInSublayout = true; } } if (wasInSublayout == false && getGraph().getVertices().contains(v)) { delegate.setLocation(v, location); } }
From source file:lu.lippmann.cdb.graph.mouse.CadralEditingGraphMousePlugin.java
/** * {@inheritDoc}// w ww . j a va 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:org.jcurl.demo.tactics.BroomPromptSwingBean.java
private void syncM2V(final Point2D s) { if (s == null) { x.setValue(0);// w w w .ja v a 2 s.c om y.setValue(0); } else { x.setValue(s.getX()); y.setValue(s.getY()); } x.setEnabled(s != null); y.setEnabled(s != null); }
From source file:Visualizer.SpringLayoutWeighted.java
protected void calculateRepulsion() { try {/*from ww w . j a v a 2s. c o m*/ for (Functionality.Node v : getGraph().getVertices()) { if (isLocked(v)) continue; SpringVertexData svd = springVertexData.get(v); if (svd == null) continue; double dx = 0, dy = 0; for (Functionality.Node v2 : getGraph().getVertices()) { if (v == v2) continue; Point2D p = transform(v); Point2D p2 = transform(v2); if (p == null || p2 == null) continue; double vx = p.getX() - p2.getX(); double vy = p.getY() - p2.getY(); double distanceSq = p.distanceSq(p2); if (distanceSq == 0) { dx += Math.random(); dy += Math.random(); } else if (distanceSq < repulsion_range_sq) { double factor = 1; dx += factor * vx / distanceSq; dy += factor * vy / distanceSq; } } double dlen = dx * dx + dy * dy; if (dlen > 0) { dlen = Math.sqrt(dlen) / 2; svd.repulsiondx += dx / dlen; svd.repulsiondy += dy / dlen; } } } catch (ConcurrentModificationException cme) { calculateRepulsion(); } }
From source file:org.apache.fontbox.cff.CharStringRenderer.java
private void rrcurveTo(Number dx1, Number dy1, Number dx2, Number dy2, Number dx3, Number dy3) { Point2D point = path.getCurrentPoint(); float x1 = (float) point.getX() + dx1.floatValue(); float y1 = (float) point.getY() + dy1.floatValue(); float x2 = x1 + dx2.floatValue(); float y2 = y1 + dy2.floatValue(); float x3 = x2 + dx3.floatValue(); float y3 = y2 + dy3.floatValue(); path.curveTo(x1, y1, x2, y2, x3, y3); }
From source file:org.apache.fop.render.pcl.PCLPainter.java
/** * Sets the current cursor position. The coordinates are transformed to the absolute position * on the logical PCL page and then passed on to the PCLGenerator. * @param x the x coordinate (in millipoints) * @param y the y coordinate (in millipoints) *//* ww w .j a v a2 s.c o m*/ void setCursorPos(int x, int y) throws IOException { Point2D transPoint = transformedPoint(x, y); gen.setCursorPos(transPoint.getX(), transPoint.getY()); }
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 ww. j a v a 2s . c o m*/ 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()); } } }