List of usage examples for java.awt.geom Point2D getX
public abstract double getX();
From source file:org.opensha.commons.data.function.EvenlyDiscretizedFunc.java
/** * Calls set( x value, y value ). An IllegalArgumentException is thrown * if the x value is not an x-axis point. *//*from w w w. ja v a 2 s . c o m*/ public void set(Point2D point) { set(point.getX(), point.getY()); }
From source file:org.jfree.chart.demo.MouseListenerDemo4.java
public void chartMouseClicked(ChartMouseEvent chartmouseevent) { int i = chartmouseevent.getTrigger().getX(); int j = chartmouseevent.getTrigger().getY(); System.out.println("x = " + i + ", y = " + j); Point2D point2d = chartPanel.translateScreenToJava2D(new Point(i, j)); XYPlot xyplot = (XYPlot) chart.getPlot(); ChartRenderingInfo chartrenderinginfo = chartPanel.getChartRenderingInfo(); java.awt.geom.Rectangle2D rectangle2d = chartrenderinginfo.getPlotInfo().getDataArea(); ValueAxis valueaxis = xyplot.getDomainAxis(); org.jfree.ui.RectangleEdge rectangleedge = xyplot.getDomainAxisEdge(); ValueAxis valueaxis1 = xyplot.getRangeAxis(); org.jfree.ui.RectangleEdge rectangleedge1 = xyplot.getRangeAxisEdge(); double d = valueaxis.java2DToValue(point2d.getX(), rectangle2d, rectangleedge); double d1 = valueaxis1.java2DToValue(point2d.getY(), rectangle2d, rectangleedge1); System.out.println("Chart: x = " + d + ", y = " + d1); }
From source file:util.ModSpringLayout.java
protected void moveNodes() { synchronized (getSize()) { try {//from ww w . j a v a 2s. c o m for (V v : getGraph().getVertices()) { if (isLocked(v)) { continue; } SpringVertexData vd = springVertexData.get(v); if (vd == null) { continue; } Point2D xyd = transform(v); vd.dx += vd.repulsiondx + vd.edgedx; vd.dy += vd.repulsiondy + vd.edgedy; // keeps nodes from moving any faster than 5 per time unit xyd.setLocation(xyd.getX() + Math.max(-5, Math.min(5, vd.dx)), xyd.getY() + Math.max(-5, Math.min(5, vd.dy))); Dimension d = getSize(); int width = d.width; int height = d.height; if (xyd.getX() < 0) { xyd.setLocation(0, xyd.getY()); } else if (xyd.getX() > width) { xyd.setLocation(width, xyd.getY()); } if (xyd.getY() < 0) { xyd.setLocation(xyd.getX(), 0); } else if (xyd.getY() > height) { xyd.setLocation(xyd.getX(), height); } } } catch (ConcurrentModificationException cme) { moveNodes(); } } }
From source file:Visualizer.SpringLayoutWeighted.java
protected void moveNodes() { synchronized (getSize()) { try {//from w w w .j a va2 s . c o m for (Functionality.Node v : getGraph().getVertices()) { if (isLocked(v)) continue; SpringVertexData vd = springVertexData.get(v); if (vd == null) continue; Point2D xyd = transform(v); vd.dx += vd.repulsiondx + vd.edgedx; vd.dy += vd.repulsiondy + vd.edgedy; // keeps nodes from moving any faster than 5 per time unit xyd.setLocation(xyd.getX() + Math.max(-5, Math.min(5, vd.dx)), xyd.getY() + Math.max(-5, Math.min(5, vd.dy))); Dimension d = getSize(); int width = d.width; int height = d.height; if (xyd.getX() < 0) { xyd.setLocation(0, xyd.getY()); } else if (xyd.getX() > width) { xyd.setLocation(width, xyd.getY()); } if (xyd.getY() < 0) { xyd.setLocation(xyd.getX(), 0); } else if (xyd.getY() > height) { xyd.setLocation(xyd.getX(), height); } } } catch (ConcurrentModificationException cme) { moveNodes(); } } }
From source file:com.google.code.facebook.graph.sna.applet.VertexCollapseDemoWithLayouts.java
public VertexCollapseDemoWithLayouts() { // create a simple graph for the demo graph = TestGraphs.getOneComponentGraph(); collapsedGraph = graph;//from w ww. ja va2 s. c om 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); } }); 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); collapsedGraph = g; 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); } }); Class[] combos = getCombos(); final JComboBox jcb = new JComboBox(combos); // use a renderer to shorten the layout name presentation jcb.setRenderer(new DefaultListCellRenderer() { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String valueString = value.toString(); valueString = valueString.substring(valueString.lastIndexOf('.') + 1); return super.getListCellRendererComponent(list, valueString, index, isSelected, cellHasFocus); } }); jcb.addActionListener(new LayoutChooser(jcb, vv)); jcb.setSelectedItem(FRLayout.class); 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); controls.add(jcb); content.add(controls, BorderLayout.SOUTH); }
From source file:net.sf.fspdfs.chartthemes.spring.ScaledDialValueIndicator.java
/** * Draws the background to the specified graphics device. If the dial * frame specifies a window, the clipping region will already have been * set to this window before this method is called. * * @param g2 the graphics device (<code>null</code> not permitted). * @param plot the plot (ignored here). * @param frame the dial frame (ignored here). * @param view the view rectangle (<code>null</code> not permitted). *//*from ww w. ja v a 2 s . c om*/ public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { // work out the anchor point Rectangle2D f = DialPlot.rectangleByRadius(frame, getRadius(), this.getRadius()); Arc2D arc = new Arc2D.Double(f, this.getAngle(), 0.0, Arc2D.OPEN); Point2D pt = arc.getStartPoint(); // calculate the bounds of the template value FontMetrics fm = g2.getFontMetrics(this.getFont()); String s = this.getNumberFormat().format(this.getTemplateValue()); Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm); // align this rectangle to the frameAnchor Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(tb.getWidth(), tb.getHeight()), pt.getX(), pt.getY(), this.getFrameAnchor()); // add the insets Rectangle2D fb = this.getInsets().createOutsetRectangle(bounds); // draw the background g2.setPaint(this.getBackgroundPaint()); g2.fill(fb); // draw the border g2.setStroke(this.getOutlineStroke()); g2.setPaint(this.getOutlinePaint()); g2.draw(fb); // now find the text anchor point String valueStr = this.getNumberFormat() .format(ChartThemesUtilities.getScaledValue(plot.getValue(this.getDatasetIndex()), scale)); Point2D pt2 = RectangleAnchor.coordinates(bounds, this.getValueAnchor()); g2.setPaint(this.getPaint()); g2.setFont(this.getFont()); TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.getTextAnchor()); }
From source file:com.jakemadethis.graphite.visualization.renderers.HyperedgeLabelRenderer.java
public void labelEdge(RenderContext<V, E> rc, Layout<V, E> layout, E e, String label) { if (label == null || label.length() == 0) return;//w ww. jav a 2 s. c o m Graph<V, E> g = layout.getGraph(); EdgeLayout<E> edgeLayout = EdgeLayout$.MODULE$.apply(layout); Hypergraph<V, E> hg = g; if (!drawPredicate.evaluate(Context.<Hypergraph<V, E>, E>getInstance(hg, e))) return; if (!rc.getEdgeIncludePredicate().evaluate(Context.<Graph<V, E>, E>getInstance(g, e))) return; Point2D edgePos = edgeLayout.getEdgeLocation(e); edgePos = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, edgePos); GraphicsDecorator gd = rc.getGraphicsContext(); Component component = prepareRenderer(rc, rc.getEdgeLabelRenderer(), label, rc.getPickedEdgeState().isPicked(e), e); Dimension d = component.getPreferredSize(); AffineTransform old = gd.getTransform(); AffineTransform xform = new AffineTransform(old); xform.translate(edgePos.getX(), edgePos.getY()); gd.setTransform(xform); gd.setStroke(new BasicStroke(1)); Rectangle rect = new Rectangle(-10, -10, 20, 20); gd.setPaint(Color.WHITE); gd.fill(rect); gd.setPaint(Color.GRAY); gd.draw(rect); xform.translate(-d.width / 2, -d.height / 2); gd.setTransform(xform); gd.draw(component, rc.getRendererPane(), 0, 0, d.width, d.height, true); gd.setTransform(old); }
From source file:net.sf.jasperreports.chartthemes.spring.ScaledDialValueIndicator.java
/** * Draws the background to the specified graphics device. If the dial * frame specifies a window, the clipping region will already have been * set to this window before this method is called. * * @param g2 the graphics device (<code>null</code> not permitted). * @param plot the plot (ignored here). * @param frame the dial frame (ignored here). * @param view the view rectangle (<code>null</code> not permitted). *//* w w w.j a va 2s. com*/ @Override public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { // work out the anchor point Rectangle2D f = DialPlot.rectangleByRadius(frame, getRadius(), this.getRadius()); Arc2D arc = new Arc2D.Double(f, this.getAngle(), 0.0, Arc2D.OPEN); Point2D pt = arc.getStartPoint(); // calculate the bounds of the template value FontMetrics fm = g2.getFontMetrics(this.getFont()); String s = this.getNumberFormat().format(this.getTemplateValue()); Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm); // align this rectangle to the frameAnchor Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(tb.getWidth(), tb.getHeight()), pt.getX(), pt.getY(), this.getFrameAnchor()); // add the insets Rectangle2D fb = this.getInsets().createOutsetRectangle(bounds); // draw the background g2.setPaint(this.getBackgroundPaint()); g2.fill(fb); // draw the border g2.setStroke(this.getOutlineStroke()); g2.setPaint(this.getOutlinePaint()); g2.draw(fb); // now find the text anchor point String valueStr = this.getNumberFormat() .format(ChartThemesUtilities.getScaledValue(plot.getValue(this.getDatasetIndex()), scale)); Point2D pt2 = RectangleAnchor.coordinates(bounds, this.getValueAnchor()); g2.setPaint(this.getPaint()); g2.setFont(this.getFont()); TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.getTextAnchor()); }
From source file:com.wasteofplastic.beaconz.BeaconObj.java
/** * Checks if a beacon base is clear of blocks and above the blocks all the way to the sky * @return true if clear, false if not//w ww. j av a 2 s.com */ public boolean isClear() { Block beacon = getBeaconzWorld().getBlockAt((int) location.getX(), y, (int) location.getY()); //getLogger().info("DEBUG: block y = " + beacon.getY() + " " + beacon.getLocation()); for (BlockFace face : FACES) { Block block = beacon.getRelative(face); //getLogger().info("DEBUG: highest block at " + block.getX() + "," + block.getZ() + " y = " + getHighestBlockYAt(block.getX(), block.getZ())); if (block.getY() != getHighestBlockYAt(block.getX(), block.getZ())) { return false; } } // Check all the defense blocks too for (Point2D point : getRegister().getDefensesAtBeacon(this)) { beacon = getBeaconzWorld().getBlockAt((int) point.getX(), y, (int) point.getY()); if (beacon.getY() != getHighestBlockYAt((int) point.getX(), (int) point.getY())) { return false; } } return true; }
From source file:org.opensha.commons.data.function.EvenlyDiscretizedFunc.java
/** Returns the index of this DataPoint based on it's x any y value * both the x-value and y-values in list should match with that of point * returns -1 if there is no such value in the list * *//* w w w.j av a 2 s . c om*/ public int getIndex(Point2D point) { int index = getXIndex(point.getX()); if (index < 0) return -1; double y = this.getY(index); if (y != point.getY()) return -1; return index; }