List of usage examples for java.awt.geom Point2D getX
public abstract double getX();
From source file:util.ModSpringLayout.java
protected void relaxEdges() { try {/*w w w . ja v a 2 s .co m*/ for (E e : getGraph().getEdges()) { Pair<V> endpoints = getGraph().getEndpoints(e); V v1 = endpoints.getFirst(); V v2 = endpoints.getSecond(); Point2D p1 = transform(v1); Point2D p2 = transform(v2); if (p1 == null || p2 == null) { continue; } double vx = p1.getX() - p2.getX(); double vy = p1.getY() - p2.getY(); double len = Math.sqrt(vx * vx + vy * vy); double desiredLen = lengthFunction.transform(e); // round from zero, if needed [zero would be Bad.]. len = (len == 0) ? .0001 : len; double f = force_multiplier * (desiredLen - len) / len; f = f * Math.pow(stretch, (getGraph().degree(v1) + getGraph().degree(v2) - 2)); // the actual movement distance 'dx' is the force multiplied by the // distance to go. double dx = f * vx; double dy = f * vy; SpringVertexData v1D, v2D; v1D = springVertexData.get(v1); v2D = springVertexData.get(v2); v1D.edgedx += dx; v1D.edgedy += dy; v2D.edgedx += -dx; v2D.edgedy += -dy; } } catch (ConcurrentModificationException cme) { relaxEdges(); } }
From source file:org.bigwiv.blastgraph.gui.graphvisualization.EWLayout.java
protected void calcRepulsion(V v1) { VertexData fvd1 = getData(v1);//w w w. ja va 2 s .co m if (fvd1 == null) return; fvd1.setLocation(0, 0); try { for (V v2 : getGraph().getVertices()) { // if (isLocked(v2)) continue; if (v1 != v2) { Point2D p1 = transform(v1); Point2D p2 = transform(v2); if (p1 == null || p2 == null) continue; 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 = (repulsion_constant * repulsion_constant) / deltaLength; if (Double.isNaN(force)) { throw new RuntimeException( "Unexpected mathematical result in FRLayout:calcPositions [repulsion]"); } fvd1.offset((xDelta / deltaLength) * force, (yDelta / deltaLength) * force); } } } catch (ConcurrentModificationException cme) { calcRepulsion(v1); } }
From source file:com.sdk.connector.chart.TimeDomainRenderer.java
@Override public void chartMouseClicked(ChartMouseEvent cme) { ChartEntity chartentity = cme.getEntity(); //JOptionPane.showMessageDialog(null,chartentity.getClass(), "",JOptionPane.CANCEL_OPTION); if (cme.getEntity() instanceof PlotEntity) { if (chartentity != null) { Point2D p = chartPanel.translateScreenToJava2D(cme.getTrigger().getPoint()); final Rectangle2D plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); double chartX = plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge()); double chartY = plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge()); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis((long) chartX); createAnnotation(formatter.format(calendar.getTime()), chartX, chartY); } else {// w ww . ja v a 2s . c o m } } }
From source file:vteaexploration.plotgatetools.gates.PolygonGate.java
@Override public Path2D createPath2DInChartSpace() { Point2D p; Path2D.Double polygon = new Path2D.Double(); ListIterator<Point2D.Double> itr = verticesInChartSpace.listIterator(); p = (Point2D) verticesInChartSpace.get(0); //System.out.println(verticesInChartSpace.size() + " Gate points"); //System.out.println("First Point: " + p); polygon.moveTo(p.getX(), p.getY()); while (itr.hasNext()) { p = (Point2D) itr.next(); //System.out.println("Next Point: " + p); polygon.lineTo(p.getX(), p.getY()); }//from w w w .j a v a2 s . c o m polygon.closePath(); return polygon; }
From source file:ijfx.core.overlay.OverlayStatService.java
public boolean areColinear(Point2D pt1, Point2D pt2, Point2D pt3) { boolean colinear = false; double signedArea = ((pt2.getX() - pt1.getX()) * (pt3.getY() - pt1.getY())) - ((pt3.getX() - pt1.getX()) * (pt2.getY() - pt1.getY())); colinear = (signedArea == 0.0);/*from w w w. j a v a2 s. co m*/ return colinear; }
From source file:net.sf.mzmine.chartbasics.ChartLogics.java
/** * Translates mouse coordinates to chart coordinates (xy-axis) * //from w w w . j a va2 s . c om * @param myChart * @param mouseX * @param mouseY * @return Range as chart coordinates * @throws Exception */ public static Point2D mouseXYToPlotXY(ChartPanel myChart, int mouseX, int mouseY) throws Exception { Point2D p = myChart.translateScreenToJava2D(new Point(mouseX, mouseY)); XYPlot plot = null; // find plot as parent of axis ChartEntity entity = findChartEntity(myChart, mouseX, mouseY); if (entity instanceof AxisEntity) { Axis a = ((AxisEntity) entity).getAxis(); if (a.getPlot() instanceof XYPlot) plot = (XYPlot) a.getPlot(); } ChartRenderingInfo info = myChart.getChartRenderingInfo(); int subplot = info.getPlotInfo().getSubplotIndex(p); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); if (subplot != -1) dataArea = info.getPlotInfo().getSubplotInfo(subplot).getDataArea(); if (plot == null) plot = findXYSubplot(myChart.getChart(), info, p.getX(), p.getY()); // coordinates double cx = 0; double cy = 0; if (plot != null) { // find axis ValueAxis domainAxis = plot.getDomainAxis(); ValueAxis rangeAxis = plot.getRangeAxis(); RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); // parent? if (domainAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) { XYPlot pp = ((XYPlot) plot.getParent()); domainAxis = pp.getDomainAxis(); domainAxisEdge = pp.getDomainAxisEdge(); } if (rangeAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) { XYPlot pp = ((XYPlot) plot.getParent()); rangeAxis = pp.getRangeAxis(); rangeAxisEdge = pp.getRangeAxisEdge(); } if (domainAxis != null) cx = domainAxis.java2DToValue(p.getX(), dataArea, domainAxisEdge); if (rangeAxis != null) cy = rangeAxis.java2DToValue(p.getY(), dataArea, rangeAxisEdge); } else { throw new Exception("no xyplot found"); } return new Point2D.Double(cx, cy); }
From source file:org.jcurl.zui.piccolo.BroomPromptSimple.java
/** adjust position + rotation */ private void setBroom(final Point2D b) { if (b == null) return;/*from ww w .j a va 2 s . com*/ final AffineTransform t = getTransformReference(true); t.setToIdentity(); t.translate(b.getX(), b.getY()); MathVec.rotate(t, b.getX(), b.getY() - IceSize.FAR_HACK_2_TEE); MathVec.rotate(t, 0, 1); invalidateFullBounds(); invalidatePaint(); }
From source file:vnreal.gui.control.MyEditingPopupGraphMousePlugin.java
@SuppressWarnings("unchecked") @Override/* www . j a va2 s . c om*/ protected void createGeneralMenuEntries(final Point point, final N graph, final LayerViewer<V, E> vv) { JMenuItem mi; // creating a node mi = new JMenuItem("Create node"); final int layer = vv.getLayer().getLayer(); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // adding an resource/demand boolean addConstraint = true; V node = vertexFactory.create(); Point2D p2 = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(point); node.setCoordinateX(p2.getX()); node.setCoordinateY(p2.getY()); while (addConstraint) { new AddConstraintDialog(node, layer, GUI.getInstance(), new Dimension(300, 150)); // if a resource/demand has been added if (node.get().size() > 0) { addConstraint = false; @SuppressWarnings("rawtypes") Network net = ToolKit.getScenario().getNetworkStack().getLayer(layer); if ((net instanceof SubstrateNetwork && ((SubstrateNetwork) net).addVertex((SubstrateNode) node)) || (net instanceof VirtualNetwork && ((VirtualNetwork) net).addVertex((VirtualNode) node))) { vv.updateUI(); } else { throw new AssertionError("Adding Node failed."); } } else { String cons = (layer == 0 ? "Resource" : "Demand"); int option = JOptionPane.showConfirmDialog(GUI.getInstance(), "A " + cons + " must be added for the node to be created!", "Create Node", JOptionPane.OK_CANCEL_OPTION); if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) { addConstraint = false; } } } } }); popup.add(mi); popup.addSeparator(); @SuppressWarnings("rawtypes") final MyGraphPanel pnl = GUI.getInstance().getGraphPanel(); if (pnl.getMaximized() == null) { mi = new JMenuItem("Maximize"); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { pnl.setMaximized(vv); } }); } else { mi = new JMenuItem("Restore"); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { pnl.setMaximized(null); } }); } popup.add(mi); if (pnl.getMaximized() != null) { mi = new JMenuItem("Hide"); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { vv.getParent().setVisible(false); } }); popup.add(mi); } popup.addSeparator(); // Copied from MuLaNEO mi = new JMenuItem("Export layer to SVG"); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int layer = vv.getLayer().getLayer(); MyFileChooser fc = new MyFileChooser("Export layer " + layer + " to SVG", MyFileChooserType.MISC, false); fc.addChoosableFileFilter(FileFilters.svgFilter); fc.setSelectedFile(new File("export-layer-" + layer + ".svg")); if (fc.showSaveDialog(GUI.getInstance()) == JFileChooser.APPROVE_OPTION) new SVGExporter().export(vv, fc.getSelectedFile()); } }); popup.add(mi); }
From source file:lu.lippmann.cdb.graph.mouse.CadralGraphMouse.java
/** * {@inheritDoc}//from w ww . j a va 2s. c om */ @Override public void mouseReleased(MouseEvent e) { if (mode.equals(Mode.PICKING)) { @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) { //Check that we moved the selected vertex if (before != null && !layout.transform(vertex).equals(before.get(vertex.getId()))) { boolean needsGroup = (vv.getPickedVertexState().getPicked().size() > 1); if (needsGroup) { graph.startGroupOperation(); } for (CNode picked : vv.getPickedVertexState().getPicked()) { if (before.containsKey(picked.getId())) { graph.moveNodeTo(picked, before.get(picked.getId()), layout.transform(picked)); } } if (needsGroup) { graph.stopGroupOperation(); } } } } } //will call either : // - CadralEditingGraphMousePlugin.mouseReleased(e) // - CadralPickingGraphMousePlugin.mouseReleased(e) //System.out.println("Position : " + e.getPoint()); super.mouseReleased(e); }
From source file:jmeanshift.ChartProof.java
@Override public void chartMouseClicked(ChartMouseEvent cme) { ChartEntity chartentity = cme.getEntity(); if (chartentity != null) { Point2D p = chartPanel.translateScreenToJava2D(cme.getTrigger().getPoint()); final Rectangle2D plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); int i = (int) plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge()); int j = (int) plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge()); series.addOrUpdate(i, j);// w w w . j a va 2 s . c o m data1.add((double) i); data2.add((double) j); } else { } }