List of usage examples for java.awt.geom Point2D getY
public abstract double getY();
From source file:com.net2plan.gui.utils.topologyPane.jung.JUNGCanvas.java
/** * Converts a point from the SWING coordinates system into a point from the JUNG coordinates system. * * @param jungLayoutCoord (@code Point2D) on the SWING canvas. * @return (@code Point2D) on the JUNG canvas. *//*from w ww .j a v a2 s . co m*/ @Override public Point2D getCanvasPointFromNetPlanPoint(Point2D npCoord) { Point2D layoutOrViewCoordinates = vv.getRenderContext().getMultiLayerTransformer() .inverseTransform(Layer.LAYOUT, npCoord); layoutOrViewCoordinates.setLocation(layoutOrViewCoordinates.getX(), -layoutOrViewCoordinates.getY()); return layoutOrViewCoordinates; }
From source file:Hexagon.java
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("[Hexagon: "); sb.append(String.format("[Size: %d]", size)); sb.append(String.format("[Height: %2.1f, hOffset: %2.1f]", height, hOffset)); sb.append(String.format("[Width: %2.1f, wOffset: %2.1f]", width, wOffset)); sb.append(String.format("[Center: %2.1fx%2.1f]", center.getX(), center.getY())); sb.append("[Corners: "); for (Corner corner : Corner.values()) { Point2D p2d = corners.get(corner); sb.append(String.format("[%s: %2.1fx%2.1f]", corner, p2d.getX(), p2d.getY())); }//from www . ja v a 2 s.com sb.append("]"); sb.append("[Bounds: "); for (BoundingCorner corner : BoundingCorner.values()) { Point2D p2d = boundingCorners.get(corner); sb.append(String.format("[%s: %2.1fx%2.1f]", corner, p2d.getX(), p2d.getY())); } sb.append("]"); sb.append(String.format("[BoundingBox: %2.1fx%2.1f to %2.1fx%2.1f]", boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMaxX(), boundingBox.getMaxY())); sb.append("]"); return sb.toString(); }
From source file:de.fhg.igd.mapviewer.waypoints.CustomWaypointPainter.java
/** * Find the way-points in a given polygon * /*w w w. j ava 2 s . c o m*/ * @param poly the polygon * @return the way-points in the polygon area */ public Set<W> findWaypoints(final Polygon poly) { Rectangle viewPort = getMapKit().getMainMap().getViewportBounds(); final int zoom = getMapKit().getMainMap().getZoom(); final PixelConverter converter = getMapKit().getMainMap().getTileFactory().getTileProvider().getConverter(); de.fhg.igd.geom.Point2D[] points = new de.fhg.igd.geom.Point2D[poly.npoints]; // create a metamodel polygon for (int i = 0; i < poly.npoints; i++) { int worldX = viewPort.x + poly.xpoints[i]; int worldY = viewPort.y + poly.ypoints[i]; // convert to geo position GeoPosition pos = converter.pixelToGeo(new Point(worldX, worldY), zoom); // convert to common CRS try { pos = GeotoolsConverter.getInstance().convert(pos, SelectableWaypoint.COMMON_EPSG); } catch (IllegalGeoPositionException e) { log.warn("Error converting polygon point for query"); //$NON-NLS-1$ return new HashSet<W>(); } points[i] = new de.fhg.igd.geom.Point2D(pos.getX(), pos.getY()); } final de.fhg.igd.geom.shape.Polygon verifyPolygon = new de.fhg.igd.geom.shape.Polygon(points); // we need a 3D search bounding box for the R-Tree BoundingBox searchBox = verifyPolygon.getBoundingBox(); searchBox.setMinZ(-2.0); searchBox.setMaxZ(2.0); poly.translate(viewPort.x, viewPort.y); try { Set<W> wps = waypoints.query(searchBox, new Verifier<W, BoundingBox>() { @Override public boolean verify(W wp, BoundingBox second) { try { Point2D wpPixel = converter.geoToPixel(wp.getPosition(), zoom); int dx = (int) wpPixel.getX(); int dy = (int) wpPixel.getY(); poly.translate(-dx, -dy); try { Area area = wp.getMarker().getArea(zoom); if (area != null) { return area.containedIn(poly); } else { // something that has not been painted yet may // not be selected return false; } } finally { poly.translate(dx, dy); } } catch (IllegalGeoPositionException e) { log.warn("Could not convert waypoint position to pixel", e); // fall back to simple method return verifyPolygon.contains(wp.getBoundingBox().toExtent()); } } }); if (wps == null) { return new HashSet<W>(); } else { return wps; } } finally { poly.translate(-viewPort.x, -viewPort.y); } }
From source file:com.net2plan.gui.utils.topologyPane.jung.JUNGCanvas.java
@Override public void moveCanvasTo(Point2D destinationPoint) { final MutableTransformer layoutTransformer = vv.getRenderContext().getMultiLayerTransformer() .getTransformer(Layer.LAYOUT); layoutTransformer.translate(destinationPoint.getX(), destinationPoint.getY()); }
From source file:org.apache.fontbox.cff.CharStringRenderer.java
private void rmoveTo(Number dx, Number dy) { Point2D point = referencePoint; if (point == null) { point = path.getCurrentPoint();/* w w w . j av a 2s . c om*/ if (point == null) { point = sidebearingPoint; } } referencePoint = null; path.moveTo((float) (point.getX() + dx.doubleValue()), (float) (point.getY() + dy.doubleValue())); }
From source file:util.ModSpringLayout1.java
protected void moveNodes() { synchronized (getSize()) { try {/* www . ja va2 s. c om*/ for (V v : getGraph().getVertices()) { if (isLocked(v)) { continue; } SpringVertexData vd = getSpringVertexData(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());// setX(0); } else if (xyd.getX() > width) { xyd.setLocation(width, xyd.getY()); //setX(width); } if (xyd.getY() < 0) { xyd.setLocation(xyd.getX(), 0);//setY(0); } else if (xyd.getY() > height) { xyd.setLocation(xyd.getX(), height); //setY(height); } } } catch (ConcurrentModificationException cme) { moveNodes(); } } }
From source file:de.fhg.igd.mapviewer.waypoints.CustomWaypointPainter.java
/** * Find a way-point at a given position// w w w. j a v a 2 s. c o m * * @param point the position * @return the way-point */ public W findWaypoint(Point point) { Rectangle viewPort = getMapKit().getMainMap().getViewportBounds(); final int overlap = getMaxOverlap(); // the overlap is the reason why // the point is used instead of // a GeoPosition final int x = viewPort.x + point.x; final int y = viewPort.y + point.y; final int zoom = getMapKit().getMainMap().getZoom(); final PixelConverter converter = getMapKit().getMainMap().getTileFactory().getTileProvider().getConverter(); final Dimension mapSize = TileProviderUtils .getMapSize(getMapKit().getMainMap().getTileFactory().getTileProvider(), zoom); final int width = mapSize.width * getMapKit().getMainMap().getTileFactory().getTileProvider().getTileWidth(zoom); final int height = mapSize.height * getMapKit().getMainMap().getTileFactory().getTileProvider().getTileHeight(zoom); final GeoPosition topLeft = converter .pixelToGeo(new Point(Math.max(x - overlap, 0), Math.max(y - overlap, 0)), zoom); final GeoPosition bottomRight = converter .pixelToGeo(new Point(Math.min(x + overlap, width), Math.min(y + overlap, height)), zoom); BoundingBox searchBox; try { searchBox = createSearchBB(topLeft, bottomRight); Set<W> wps = waypoints.query(searchBox, new Verifier<W, BoundingBox>() { @Override public boolean verify(W wp, BoundingBox box) { try { Point2D wpPixel = converter.geoToPixel(wp.getPosition(), zoom); int relX = x - (int) wpPixel.getX(); int relY = y - (int) wpPixel.getY(); Area area = wp.getMarker().getArea(zoom); if (area != null && area.contains(relX, relY)) { // match return true; } } catch (IllegalGeoPositionException e) { log.debug("Error converting waypoint position", e); //$NON-NLS-1$ } return false; } }); if (wps == null || wps.isEmpty()) { return null; } else { if (wps.size() == 1) { return wps.iterator().next(); } else { List<W> sorted = new ArrayList<W>(wps); Collections.sort(sorted, new Comparator<W>() { @Override public int compare(W o1, W o2) { double a1 = o1.getMarker().getArea(zoom).getArea(); double a2 = o2.getMarker().getArea(zoom).getArea(); // compare size if (a1 < a2) { return -1; } else if (a2 < a1) { return 1; } else { return 0; } } }); return sorted.get(0); } } } catch (IllegalGeoPositionException e) { return null; } }
From source file:com.wasteofplastic.beaconz.Beaconz.java
/** * Creates the corner-most beaconz so that the map can be theoretically be covered entirely (almost) *//*from www. j av a 2 s .co m*/ private void createCorners() { // Check corners Set<Point2D> corners = new HashSet<Point2D>(); int xMin = Settings.xCenter - (Settings.borderSize / 2) + 2; int xMax = Settings.xCenter + (Settings.borderSize / 2) - 3; int zMin = Settings.zCenter - (Settings.borderSize / 2) + 2; int zMax = Settings.zCenter + (Settings.borderSize / 2) - 3; corners.add(new Point2D.Double(xMin, zMin)); corners.add(new Point2D.Double(xMin, zMax)); corners.add(new Point2D.Double(xMax, zMin)); corners.add(new Point2D.Double(xMax, zMax)); for (Point2D point : corners) { if (!register.isNearBeacon(point, 5)) { Block b = getBeaconzWorld().getHighestBlockAt((int) point.getX(), (int) point.getY()); while (b.getType().equals(Material.AIR) || b.getType().equals(Material.LEAVES) || b.getType().equals(Material.LEAVES_2)) { if (b.getY() == 0) { // Oops, nothing here break; } b = b.getRelative(BlockFace.DOWN); } if (b.getY() > 3) { // Create a beacon //Bukkit.getLogger().info("DEBUG: made beacon at " + b.getLocation()); b.setType(Material.BEACON); // Register the beacon register.addBeacon(null, b.getLocation()); // Add the capstone b.getRelative(BlockFace.UP).setType(Material.OBSIDIAN); // Create the pyramid b = b.getRelative(BlockFace.DOWN); // All diamond blocks for now b.setType(Material.DIAMOND_BLOCK); b.getRelative(BlockFace.SOUTH).setType(Material.DIAMOND_BLOCK); b.getRelative(BlockFace.SOUTH_EAST).setType(Material.DIAMOND_BLOCK); b.getRelative(BlockFace.SOUTH_WEST).setType(Material.DIAMOND_BLOCK); b.getRelative(BlockFace.EAST).setType(Material.DIAMOND_BLOCK); b.getRelative(BlockFace.WEST).setType(Material.DIAMOND_BLOCK); b.getRelative(BlockFace.NORTH).setType(Material.DIAMOND_BLOCK); b.getRelative(BlockFace.NORTH_EAST).setType(Material.DIAMOND_BLOCK); b.getRelative(BlockFace.NORTH_WEST).setType(Material.DIAMOND_BLOCK); } } } }
From source file:edu.uci.ics.jung.algorithms.layout.FRLayout.java
protected synchronized void calcPositions(V v) { FRVertexData fvd = getFRData(v);/*from w w w .ja v a2 s .co m*/ if (fvd == null) return; Point2D xyd = transform(v); double deltaLength = Math.max(EPSILON, fvd.norm()); double newXDisp = fvd.getX() / deltaLength * Math.min(deltaLength, temperature); if (Double.isNaN(newXDisp)) { throw new IllegalArgumentException("Unexpected mathematical result in FRLayout:calcPositions [xdisp]"); } double newYDisp = fvd.getY() / deltaLength * Math.min(deltaLength, temperature); xyd.setLocation(xyd.getX() + newXDisp, xyd.getY() + newYDisp); double borderWidth = getSize().getWidth() / 50.0; double newXPos = xyd.getX(); if (newXPos < borderWidth) { newXPos = borderWidth + Math.random() * borderWidth * 2.0; } else if (newXPos > (getSize().getWidth() - borderWidth)) { newXPos = getSize().getWidth() - borderWidth - Math.random() * borderWidth * 2.0; } double newYPos = xyd.getY(); if (newYPos < borderWidth) { newYPos = borderWidth + Math.random() * borderWidth * 2.0; } else if (newYPos > (getSize().getHeight() - borderWidth)) { newYPos = getSize().getHeight() - borderWidth - Math.random() * borderWidth * 2.0; } xyd.setLocation(newXPos, newYPos); }
From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.graph.CollapsableGraphView.java
public CollapsableGraphView(Graph graph, boolean val) throws HeadlessException { super();/*from w ww . j av a 2s . c o m*/ setGraph(graph); layout = new FRLayout(graph); Dimension preferredSize = new Dimension(400, 400); final VisualizationModel visualizationModel = new DefaultVisualizationModel(layout, preferredSize); VisualizationViewer vv = new VisualizationViewer(visualizationModel, preferredSize); vv.addGraphMouseListener(new CollapsableGraphMouseListener<Number>()); vv.getRenderContext().setVertexShapeTransformer(new ClusterVertexShapeTransformer()); PickedState<Integer> picked_state = vv.getPickedVertexState(); // create decorators vv.getRenderContext().setVertexFillPaintTransformer(IB_TransformerFactory.getDefaultPaintTransformer(vv)); setVisViewer(vv); 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) { VisualizationViewer vv = getVisViewer(); scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { VisualizationViewer vv = getVisViewer(); scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton collapse = new JButton("Collapse"); collapse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Collapsing the graph"); // Pick all port zeros, and their IMMEDIATE links // PickManager.getInstance().pickAllSwitches(vv); VisualizationViewer vv = getVisViewer(); Collection picked = new HashSet(vv.getPickedVertexState().getPicked()); if (picked.size() > 1) { System.out.println("CGV: The number picked is: " + picked.size()); 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(); } // 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) { VisualizationViewer vv = getVisViewer(); 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())); getExclusions().addAll(edges); vv.repaint(); } } }); JButton expandEdges = new JButton("Expand Edges"); expandEdges.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { VisualizationViewer vv = getVisViewer(); 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())); getExclusions().removeAll(edges); vv.repaint(); } } }); JButton expand = new JButton("Expand"); expand.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { VisualizationViewer vv = getVisViewer(); 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) { VisualizationViewer vv = getVisViewer(); Graph g = getGraph(); layout.setGraph(g); getExclusions().clear(); vv.repaint(); } }); JButton help = new JButton("Help"); help.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog((JComponent) e.getSource(), getInstructions(), "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, this)); 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); }