List of usage examples for java.awt.geom Point2D getY
public abstract double getY();
From source file:Visualizer.FRWeightedLayout.java
protected synchronized void calcPositions(Functionality.Node v) { FRVertexData fvd = getFRData(v);/*from w ww.j a va 2 s . c om*/ 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 FRWeightedLayout: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:figs.treeVisualization.gui.TimeAxisTree2DPanel.java
/** * Calculate the coordinates of the top and bottom nodes. *//*from ww w .j a va 2 s .c o m*/ private void calculateDateMargins() { Point2D top = null, bottom = null; for (Iterator<Element> i = this.fLeafNodes.iterator(); i.hasNext();) { Element leaf = i.next(); Point2D pt = this.fTreePainter.cladeToJava2D(leaf, this.fLeftTreeArea); if (top == null) { top = pt; } else if (top.getY() > pt.getY()) { top = pt; } if (bottom == null) { bottom = pt; } else if (bottom.getY() < pt.getY()) { bottom = pt; } } this.fTopLeafPt = top; this.fBottomLeafPt = bottom; }
From source file:boundary.GraphPane.java
private Node addThresholdSlider(float min, float max) { HBox hBox = new HBox(); hBox.setPadding(new Insets(15, 12, 15, 12)); hBox.setStyle("-fx-background-color: #66FFFF;"); Label lblThreshold = new Label("Threshold: "); lblThreshold.setPrefSize(100, 20);/*from w ww. j av a 2 s . c om*/ Label lblValue = new Label("Value: "); lblValue.setPrefSize(50, 20); TextField tfValue = new TextField(String.valueOf(min)); Slider thresholdSlider = new Slider(); thresholdSlider.setMin(Math.floor(min)); thresholdSlider.setMax(Math.ceil(max)); thresholdSlider.setMajorTickUnit(Math.ceil((max - min) / 5)); thresholdSlider.setMinorTickCount(1); thresholdSlider.setBlockIncrement(1); thresholdSlider.setSnapToTicks(true); thresholdSlider.setShowTickMarks(true); thresholdSlider.valueProperty().addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { edgePredicate.setThreshold(newValue.floatValue()); vertexPredicate.setThreshold(newValue.floatValue()); vv.repaint(); tfValue.setText(String.format(Locale.US, "%.2f", newValue.floatValue())); } }); tfValue.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { float value; try { value = Float.parseFloat(tfValue.getText()); } catch (Exception ex) { value = 0; } edgePredicate.setThreshold(value); vertexPredicate.setThreshold(value); vv.repaint(); thresholdSlider.setValue(value); } }); Label lblSearch = new Label("Search: "); lblSearch.setPrefSize(70, 20); TextField tf = new TextField(); tf.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { String toFind = tf.getText().toLowerCase(); for (NodeInfo nodeInfo : nodesHighlighted) nodeInfo.setHighlighted(false); if (nodesHighlighted.size() > 0) { nodesHighlighted.clear(); vv.repaint(); } if (toFind.length() > 2) { for (NodeInfo nodeInfo : nodes.values()) { if (nodeInfo.getUserData().toLowerCase().contains((toFind))) { nodeInfo.setHighlighted(true); nodesHighlighted.add(nodeInfo); } } if (nodesHighlighted.size() == 1) { Layout<String, String> layout = vv.getGraphLayout(); Point2D q = layout.transform(nodesHighlighted.get(0).id); Point2D lvc = vv.getRenderContext().getMultiLayerTransformer() .inverseTransform(vv.getCenter()); final double dx = (lvc.getX() - q.getX()) / 10; final double dy = (lvc.getY() - q.getY()) / 10; Runnable animator = new Runnable() { public void run() { for (int i = 0; i < 10; i++) { vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT) .translate(dx, dy); try { Thread.sleep(100); } catch (InterruptedException ex) { } } } }; Thread thread = new Thread(animator); thread.start(); } vv.repaint(); } } }); hBox.getChildren().addAll(lblThreshold, thresholdSlider, lblValue, tfValue, lblSearch, tf); return hBox; }
From source file:pt.lsts.neptus.plugins.sunfish.awareness.SituationAwareness.java
public void paintIcons(Graphics2D g, StateRenderer2D renderer) { for (AssetTrack track : assets.values()) { AssetPosition p = track.getLatest(newestTimestampSelection); if (p == null || hiddenPosTypes.contains(p.getType())) continue; if (p.getTimestamp() < oldestTimestampSelection || p.getTimestamp() > newestTimestampSelection) continue; Point2D pt = renderer.getScreenPosition(p.getLoc()); //TODO paint icon here Image img = getIcon(p);/*from w w w . j a v a2 s. c o m*/ if (img != null) { g.drawImage(img, (int) (pt.getX() - 8), (int) (pt.getY() - 8), (int) (pt.getX() + 8), (int) (pt.getY() + 8), 0, 0, img.getWidth(null), img.getHeight(null), null); } } }
From source file:com.wasteofplastic.beaconz.Register.java
public void saveRegister() { // Save the beacons File beaconzFile = new File(getBeaconzPlugin().getDataFolder(), "beaconz.yml"); YamlConfiguration beaconzYml = new YamlConfiguration(); // Backup the beacons file just in case if (beaconzFile.exists()) { File backup = new File(getBeaconzPlugin().getDataFolder(), "beaconz.old"); beaconzFile.renameTo(backup);/* w ww . j a v a2 s . c o m*/ } int count = 0; for (BeaconObj beacon : beaconRegister.values()) { String owner = "unowned"; if (beacon.getOwnership() != null) { owner = beacon.getOwnership().getName(); } beaconzYml.set("beacon." + count + ".location", beacon.getX() + ":" + beacon.getY() + ":" + beacon.getZ() + ":" + owner); List<String> beaconLinks = new ArrayList<String>(); for (BeaconObj linkedBeacon : beacon.getLinks()) { beaconLinks.add(linkedBeacon.getX() + ":" + linkedBeacon.getZ()); } beaconzYml.set("beacon." + count + ".links", beaconLinks); if (beacon.getId() != null) { beaconzYml.set("beacon." + count + ".id", beacon.getId()); } // Save defense blocks List<String> defenseBlocks = new ArrayList<String>(); for (Point2D point : defenseBlocksInverse.get(beacon)) { defenseBlocks.add((int) point.getX() + ":" + (int) point.getY()); } beaconzYml.set("beacon." + count + ".defenseblocks", defenseBlocks); count++; } try { beaconzYml.save(beaconzFile); } catch (IOException e) { getLogger().severe("Problem saving beacons file!"); e.printStackTrace(); } }
From source file:org.opennms.features.topology.app.internal.jung.TopoFRLayout.java
protected synchronized void calcPositions(V v) { FRVertexData fvd = getFRData(v);/*from w ww . ja v a 2s. com*/ if (fvd == null) return; Point2D xyd = transform(v); double deltaLength = fvd.norm(); if (deltaLength <= 0.005) return; double newXDisp = fvd.getX() * percentage() / deltaLength * Math.min(deltaLength, temperature); if (Double.isNaN(newXDisp)) { throw new IllegalArgumentException("Unexpected mathematical result in FRLayout:calcPositions [xdisp]"); } double newYDisp = fvd.getY() * percentage() / 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:Polygon2D.java
/** * Tests if a specified {@link Point2D} is inside the boundary of this * <code>Polygon</code>.//from w w w. ja va 2 s . c om * @param p a specified <code>Point2D</code> * @return <code>true</code> if this <code>Polygon</code> contains the * specified <code>Point2D</code>; <code>false</code> * otherwise. * @see #contains(double, double) */ public boolean contains(Point2D p) { return contains(p.getX(), p.getY()); }
From source file:org.jcurl.core.base.CurveTransformedTest.java
/** * Test the transformation from a Rock Coordinates (rc) System at wc(3,3.5) * with positive y axis along wc(2,4.2) into World Coordinates (wc). Uses a * Point rc(5,1.3) = wc(8,2.5)./*from w w w . ja v a 2 s .c o m*/ * * @see CurveTransformed#createRc2Wc(AffineTransform, Point2D, Point2D) */ public void testCreateRc2Wc() { final Point2D p0_wc = new Point2D.Double(3, 3.5); final Rock v0_wc = new RockDouble(2, 4.2, 0.3); final AffineTransform at = CurveTransformed.createRc2Wc(null, p0_wc, v0_wc); assertEquals(AffineTransform.TYPE_GENERAL_ROTATION + AffineTransform.TYPE_TRANSLATION, at.getType()); assertEquals(1.0, at.getDeterminant()); assertEquals(0.9028605188239303, at.getScaleX()); assertEquals(at.getScaleX(), at.getScaleY()); assertEquals(0.42993358039234775, at.getShearX()); assertEquals(-at.getShearX(), at.getShearY()); assertEquals(p0_wc.getX(), at.getTranslateX()); assertEquals(p0_wc.getY(), at.getTranslateY()); final Point2D rc = new Point2D.Double(5, 1.3); final Point2D wc = at.transform(rc, null); assertEquals("Point2D.Double[8.073216248629704, 2.524050772509371]", wc.toString()); // angle in rc: double ang = Math.atan2(rc.getY(), rc.getX()); assertEquals(14.574216198038739, rad2deg(ang)); // wc rotation: ang = Math.atan2(at.getShearY(), at.getScaleY()); assertEquals(-25.463345061871614, rad2deg(ang)); final double[] d = new double[6]; at.getMatrix(d); ang = Math.atan2(-d[2], d[3]); assertEquals(-25.463345061871614, rad2deg(ang)); // angle in wc: ang = Math.atan2(wc.getY(), wc.getX()); assertEquals(17.36159358309492, rad2deg(ang)); }
From source file:Hexagon.java
public void attach(Hexagon toTranslate, Direction direction) { double horSize = size + hOffset; /**/*from w w w . jav a2s . c o m*/ * To start with, we need to know toTranslate's position RELATIVE to ours */ Point2D topLeft = getBoundPoint(BoundingCorner.TopLeft); Point2D toTranslateTopLeft = toTranslate.getBoundPoint(BoundingCorner.TopLeft); double deltaX = topLeft.getX() - toTranslateTopLeft.getX(); double deltaY = topLeft.getY() - toTranslateTopLeft.getY(); // that should be enough to line them up exactly... now offset it... switch (direction) { case NorthEast: deltaX += wOffset; deltaY -= horSize; break; case East: deltaX += width; break; case SouthEast: deltaX += wOffset; deltaY += horSize; break; case SouthWest: deltaX -= wOffset; deltaY += horSize; break; case West: deltaX -= width; break; case NorthWest: deltaX -= wOffset; deltaY -= horSize; break; } toTranslate.translate(deltaX, deltaY); }
From source file:pt.lsts.neptus.plugins.wg.WgCtdLayer.java
private boolean paintHistory(Graphics2D g, StateRenderer2D renderer) { boolean paintedToRender = false; Long endMark = dataDateEnd.getTime(); Long timeMark = dataDateStart.getTime(); CtdData dataPoint;//from ww w . j a v a 2 s .c o m // double tempMaxTemp, tempMinTemp; // timeMark = ctdHistory.higherKey(timeMark); // if (timeMark != null) { // dataPoint = ctdHistory.get(timeMark); // tempMaxTemp = dataPoint.temperature; // tempMinTemp = dataPoint.temperature; // } // else { // tempMaxTemp = maxTemp; // tempMinTemp = minTemp; // } Color color; Graphics2D gt; Point2D pt; int width = (renderer.getZoom() > 1) ? (int) (5 * renderer.getZoom()) : 5; if (renderer.getZoom() < 0.002) { timeMark = ctdHistory.higherKey(timeMark); if (timeMark != null && timeMark <= endMark) { dataPoint = ctdHistory.get(timeMark); pt = renderer.getScreenPosition(dataPoint.location); if (isVisibleInRender(pt, renderer)) { gt = (Graphics2D) g.create(); color = genColor(dataPoint.temperature); gt.setColor(color); gt.fillOval((int) pt.getX(), (int) pt.getY(), 10, 10); gt.dispose(); paintedToRender = true; } } } else { try { timeMark = ctdHistory.higherKey(timeMark); // TODO avoid for in case of being too far from location shown on map for (timeMark = ctdHistory.higherKey(timeMark); timeMark != null && timeMark <= endMark; timeMark = ctdHistory.higherKey(timeMark + 1)) { dataPoint = ctdHistory.get(timeMark); pt = renderer.getScreenPosition(dataPoint.location); if (!isVisibleInRender(pt, renderer)) { continue; } // check if it is visible gt = (Graphics2D) g.create(); color = genColor(dataPoint.temperature); gt.setColor(color); gt.fillOval((int) pt.getX(), (int) pt.getY(), width, width); gt.dispose(); paintedToRender = true; } } catch (NullPointerException e) { System.out.println("timeMark"); } } return paintedToRender; }