List of usage examples for java.awt.geom Point2D getY
public abstract double getY();
From source file:com.newatlanta.bluedragon.CustomClusteredXYBarRenderer.java
private void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, Rectangle2D bar, boolean negative) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); if (generator == null) return;/*w w w . ja va2 s . c om*/ String label = generator.generateLabel(dataset, series, item); if (label == null) { return; // nothing to do } Font labelFont = getItemLabelFont(series, item); g2.setFont(labelFont); Paint paint = getItemLabelPaint(series, item); g2.setPaint(paint); // find out where to place the label... ItemLabelPosition position = null; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, orientation); TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); }
From source file:com.google.code.facebook.graph.sna.applet.VertexCollapseDemo.java
public VertexCollapseDemo() { // create a simple graph for the demo graph = TestGraphs.getOneComponentGraph(); collapser = new GraphCollapser(graph); layout = new FRLayout(graph); Dimension preferredSize = new Dimension(400, 400); final VisualizationModel visualizationModel = new DefaultVisualizationModel(layout, preferredSize); vv = new VisualizationViewer(visualizationModel, preferredSize); vv.getRenderContext().setVertexShapeTransformer(new ClusterVertexShapeFunction()); final PredicatedParallelEdgeIndexFunction eif = PredicatedParallelEdgeIndexFunction.getInstance(); final Set exclusions = new HashSet(); eif.setPredicate(new Predicate() { public boolean evaluate(Object e) { return exclusions.contains(e); }//ww w. j av a 2 s . co m }); vv.getRenderContext().setParallelEdgeIndexFunction(eif); vv.setBackground(Color.white); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller() { /* (non-Javadoc) * @see edu.uci.ics.jung.visualization.decorators.DefaultToolTipFunction#getToolTipText(java.lang.Object) */ @Override public String transform(Object v) { if (v instanceof Graph) { return ((Graph) v).getVertices().toString(); } return super.transform(v); } }); /** * the regular graph mouse for the normal view */ final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); Container content = getContentPane(); GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv); content.add(gzsp); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton collapse = new JButton("Collapse"); collapse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = new HashSet(vv.getPickedVertexState().getPicked()); if (picked.size() > 1) { Graph inGraph = layout.getGraph(); Graph clusterGraph = collapser.getClusterGraph(inGraph, picked); Graph g = collapser.collapse(layout.getGraph(), clusterGraph); double sumx = 0; double sumy = 0; for (Object v : picked) { Point2D p = (Point2D) layout.transform(v); sumx += p.getX(); sumy += p.getY(); } Point2D cp = new Point2D.Double(sumx / picked.size(), sumy / picked.size()); vv.getRenderContext().getParallelEdgeIndexFunction().reset(); layout.setGraph(g); layout.setLocation(clusterGraph, cp); vv.getPickedVertexState().clear(); vv.repaint(); } } }); JButton compressEdges = new JButton("Compress Edges"); compressEdges.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = vv.getPickedVertexState().getPicked(); if (picked.size() == 2) { Pair pair = new Pair(picked); Graph graph = layout.getGraph(); Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst())); edges.retainAll(graph.getIncidentEdges(pair.getSecond())); exclusions.addAll(edges); vv.repaint(); } } }); JButton expandEdges = new JButton("Expand Edges"); expandEdges.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = vv.getPickedVertexState().getPicked(); if (picked.size() == 2) { Pair pair = new Pair(picked); Graph graph = layout.getGraph(); Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst())); edges.retainAll(graph.getIncidentEdges(pair.getSecond())); exclusions.removeAll(edges); vv.repaint(); } } }); JButton expand = new JButton("Expand"); expand.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = new HashSet(vv.getPickedVertexState().getPicked()); for (Object v : picked) { if (v instanceof Graph) { Graph g = collapser.expand(layout.getGraph(), (Graph) v); vv.getRenderContext().getParallelEdgeIndexFunction().reset(); layout.setGraph(g); } vv.getPickedVertexState().clear(); vv.repaint(); } } }); JButton reset = new JButton("Reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { layout.setGraph(graph); exclusions.clear(); vv.repaint(); } }); JButton help = new JButton("Help"); help.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog((JComponent) e.getSource(), instructions, "Help", JOptionPane.PLAIN_MESSAGE); } }); JPanel controls = new JPanel(); JPanel zoomControls = new JPanel(new GridLayout(2, 1)); zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom")); zoomControls.add(plus); zoomControls.add(minus); controls.add(zoomControls); JPanel collapseControls = new JPanel(new GridLayout(3, 1)); collapseControls.setBorder(BorderFactory.createTitledBorder("Picked")); collapseControls.add(collapse); collapseControls.add(expand); collapseControls.add(compressEdges); collapseControls.add(expandEdges); collapseControls.add(reset); controls.add(collapseControls); controls.add(modeBox); controls.add(help); content.add(controls, BorderLayout.SOUTH); }
From source file:com.projity.pm.graphic.network.NetworkRenderer.java
protected void updateLinkConnections(GraphicNode node, double[] linkPoints) { GeneralPath shape = getShape(node); if (shape == null) return;//from w w w . j a v a 2 s. com Point2D center = getCenter(node); linkPoints[0] = center.getX(); linkPoints[1] = center.getX(); linkPoints[2] = center.getY(); linkPoints[3] = center.getY(); double x0 = 0.0, y0 = 0.0, x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0, x, y; for (PathIterator j = shape.getPathIterator(null); !j.isDone(); j.next()) { int segmentType = j.currentSegment(segment); switch (segmentType) { case PathIterator.SEG_MOVETO: x0 = segment[0]; y0 = segment[1]; x2 = x0; y2 = y0; break; case PathIterator.SEG_LINETO: x2 = segment[0]; y2 = segment[1]; case PathIterator.SEG_CLOSE: if (segmentType == PathIterator.SEG_CLOSE) { x2 = x0; y2 = y0; } //works only convex shapes double lambda; if (y2 != y1) { x = (center.getY() - y1) * (x2 - x1) / (y2 - y1) + x1; lambda = (x2 == x1) ? 0 : (x - x1) / (x2 - x1); if (x1 == x2 || (lambda >= 0 && lambda <= 1)) { if (x < linkPoints[0]) linkPoints[0] = x; if (x > linkPoints[1]) linkPoints[1] = x; } } if (x2 != x1) { y = (center.getX() - x1) * (y2 - y1) / (x2 - x1) + y1; lambda = (y2 == x1) ? 0 : (y - y1) / (y2 - y1); if (y1 == y2 || (lambda >= 0 && lambda <= 1)) { if (y < linkPoints[2]) linkPoints[2] = y; if (y > linkPoints[3]) linkPoints[3] = y; } } break; } x1 = x2; y1 = y2; } }
From source file:org.bigwiv.blastgraph.gui.graphvisualization.EWLayout.java
protected void calcAttraction(E e) { ValueEdge edge = (ValueEdge) e;//from w ww . j a v a 2s . com double evalue = edge.getExpectValue(); double ew; // edge weight if (evalue <= 0) { ew = 1; } else { ew = (Math.log10(maxEvalue) - Math.log10(evalue)) / (Math.log10(maxEvalue) - Math.log10(minEvalue)); } Pair<V> endpoints = getGraph().getEndpoints(e); V v1 = endpoints.getFirst(); V v2 = endpoints.getSecond(); boolean v1_locked = isLocked(v1); boolean v2_locked = isLocked(v2); if (v1_locked && v2_locked) { // both locked, do nothing return; } 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))); // force by edge weight double force = (deltaLength * deltaLength) * ew / attraction_constant; if (Double.isNaN(force)) { throw new IllegalArgumentException("Unexpected mathematical result in FRLayout:calcPositions [force]"); } double dx = (xDelta / deltaLength) * force; double dy = (yDelta / deltaLength) * force; if (v1_locked == false) { VertexData fvd1 = getData(v1); fvd1.offset(-dx, -dy); } if (v2_locked == false) { VertexData fvd2 = getData(v2); fvd2.offset(dx, dy); } }
From source file:edu.uci.ics.jung.algorithms.layout.SpringLayout.java
protected void relaxEdges() { try {/*from w w w . jav a 2s.c om*/ 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.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) *//*from w ww . j av a 2 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: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()); }// w w w .j a v a 2 s . c o m polygon.closePath(); return polygon; }
From source file:net.sf.mzmine.chartbasics.ChartLogics.java
/** * Translates mouse coordinates to chart coordinates (xy-axis) * //from www .j a v a 2s .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 www .ja v a2 s. c om*/ 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:lu.lippmann.cdb.graph.mouse.CadralGraphMouse.java
/** * {@inheritDoc}//from w w w . j a va 2 s.co m */ @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); }