public static String convertPolyline(final Polyline POLYLINE) { final StringBuilder fxPath = new StringBuilder(); final int size = POLYLINE.getPoints().size(); if (size % 2 == 0) { List<Double> coordinates = POLYLINE.getPoints(); for (int i = 0; i < size; i += 2) { fxPath .append(i == 0 ? "M " : "L ") .append(coordinates.get(i)) .append(" ") .append(coordinates.get(i + 1)) .append(" "); } } return fxPath.toString(); }
public static Node createIconContent() { Polyline polyline = new Polyline(new double[]{ 45, 10, 10, 80, 80, 80, }); polyline.setStroke(Color.web("#b9c0c5")); polyline.setStrokeWidth(5); polyline.getStrokeDashArray().addAll(15d,15d); polyline.setFill(null); javafx.scene.effect.InnerShadow effect = new javafx.scene.effect.InnerShadow(); effect.setOffsetX(1); effect.setOffsetY(1); effect.setRadius(3); effect.setColor(Color.rgb(0,0,0,0.6)); polyline.setEffect(effect); return polyline; }
private static void makeNFPPolylineScene(Group group,NoFitPolygon nfp, double biggestValue) { //sceneSize divided by 2 because x and y axis are in the middle double resizeFactor = sceneSizeY/biggestValue/2; Color sligthlyLighterBlack = Color.web("0x201F18"); Polyline[] nfpPolygonList = nfp.toPolylineList(sceneSizeX, sceneSizeY, resizeFactor); for(Polyline polygon : nfpPolygonList){ polygon.setStrokeWidth(4); polygon.setStroke(sligthlyLighterBlack); polygon.setFill(Color.TRANSPARENT); group.getChildren().add(polygon); } }
/** * Draws the shape, uses a polyline along with the width and height to calculate a suitable shape * @param polyline The polyline to draw with */ public void drawShape(Polyline polyline){ double baseX = getX(); double baseY = getY(); double rightHeight = super.getShapeHeight() * 0.6; double rightSmallHeight = (super.getShapeHeight() - rightHeight) / 2; double gapWidth = super.getShapeHeight() * 0.3; double leftHeight = (super.getShapeHeight() - gapWidth) / 2; polyline.getPoints().clear(); polyline.getPoints().addAll( baseX, baseY, baseX + getShapeWidth(), baseY + rightSmallHeight, baseX + getShapeWidth(), baseY + rightHeight + rightSmallHeight, baseX, baseY + super.getShapeHeight(), baseX, baseY + gapWidth + leftHeight, baseX + (getShapeWidth() * 0.2), baseY + leftHeight + (gapWidth / 2), baseX, baseY + leftHeight, baseX, baseY); setComponentShape(polyline); }
/** * Sets attributes on the shape, useful when resizing * @param x The new x coordinate * @param y The new y coordinate * @param width The new width * @param height The new height */ public void setAttrs(double x, double y, double width, double height){ Shape shape = getComponentShape(); Text text = getComponentLabel(); setLayoutX(x); shape.setLayoutX(x); setLayoutY(y); shape.setLayoutY(y); setX(x); setY(y); setShapeWidth(width); setPrefWidth(width); setShapeHeight(height); setPrefHeight(height); text.setWrappingWidth(width); drawShape(((Polyline) shape)); }
/** * Sets up the connector wire * @param from The shape going from * @param to The shape going to * @param type The type of wire * @param rightOrBottom If starting from the right or bottom * @param arrowStart If the arrow should be on from or to * @param offset The offset of the wire to multiply (0-1) */ public ConnectorWire(ComponentStackPane from, ComponentStackPane to, Type type, boolean rightOrBottom, boolean arrowStart, double offset){ super(new Polyline(), new Polyline(), type); this.from = from; this.to = to; this.arrowStart = arrowStart; this.type = type; this.rightOrBottom = rightOrBottom; setReverse(rightOrBottom && arrowStart); this.offset = offset; if(type == Type.HORIZONTAL){ drawHorizontalWire(); } else { drawVerticalLine(); } getArrowhead().getStyleClass().add("cpu-arrowhead"); getLine().getStyleClass().add("cpu-line"); this.getChildren().addAll(getLine(), getArrowhead()); }
/** * Get the JavaFX representation of the way. * * @return The JavaFX representation of the way. */ public Polyline render() { Polyline polyline = new Polyline(); // Don't use antialiasing for performance reasons. polyline.setSmooth(false); polyline.getStyleClass().add("way"); for (Map.Entry<String, String> tag: this.tags().entrySet()) { polyline.getStyleClass().add(tag.getKey()); polyline.getStyleClass().add(tag.getKey() + "-" + tag.getValue()); } if (this.nodes != null) { for (Node node: this.nodes) { polyline.getPoints().add((double) node.x()); polyline.getPoints().add((double) node.y()); } } return polyline; }
public PolylineSample() { super(180,90); // Red stroked not closed triangle Polyline polyline1 = new Polyline(new double[]{ 45, 10, 10, 80, 80, 80, }); polyline1.setFill(Color.TRANSPARENT); polyline1.setStroke(Color.RED); // Blue stroked closed triangle Polyline polyline2 = new Polyline(new double[]{ 135, 10, 100, 80, 170, 80, 135, 10, }); polyline2.setStroke(Color.DODGERBLUE); polyline2.setStrokeWidth(2); polyline2.setFill(null); // Create a group to show all the polylines); getChildren().add(new Group(polyline1, polyline2)); // REMOVE ME setControls( new SimplePropertySheet.PropDesc("Polyline 1 Fill", polyline1.fillProperty()), new SimplePropertySheet.PropDesc("Polyline 1 Stroke", polyline1.strokeProperty()), new SimplePropertySheet.PropDesc("Polyline 2 Stroke", polyline2.strokeProperty()) ); // END REMOVE ME }
public Polyline[] toPolylineList(double xSize, double ySize, double sizeFactor) { Polyline[] polygonList = new Polyline[nfpPolygonsList.size()]; for (int i = 0; i < nfpPolygonsList.size(); i++) { polygonList[i] = new Polyline(); for (Coordinate coord : nfpPolygonsList.get(i)) { polygonList[i].getPoints().add(sizeFactor * coord.getxCoord() + xSize / 2); // yCoord*-1 to invert to normal axis polygonList[i].getPoints().add(-1 * sizeFactor * coord.getyCoord() + ySize / 2); } } return polygonList; }
/** * Draws the shape, sets attributes and sets the text alignment * @param vis The CPU visualisation * @param label The label to use */ public ALU(CPUVisualisation vis, String label){ super(vis, label); drawShape(new Polyline()); setAttributes(); getComponentLabel().setTextAlignment(TextAlignment.RIGHT); }
/** * Sets up a new wire * @param line The poly line to use for the wire * @param arrowHead the poly line to use for the arrowhead * @param type The type of wire */ Wire(Polyline line, Polyline arrowHead, Type type) { this.line = line; this.arrowHead = arrowHead; this.type = type; this.animating = false; this.reverse = false; this.transitions = new LinkedList<>(); this.path = new Path(); setCache(true); setCacheHint(CacheHint.SPEED); }
/** * Sets up a new custom wire * @param xStart The starting x position * @param yStart The starting y position * @param customLines The custom lines for the wire */ public CustomWire(double xStart, double yStart, CustomLine... customLines){ super(new Polyline(), new Polyline(), Type.CUSTOM); drawLine(xStart, yStart, customLines); getArrowhead().getStyleClass().add("cpu-arrowhead"); getLine().getStyleClass().add("cpu-line"); getChildren().addAll(getLine(), getArrowhead()); }
private void createOverlayBottomLineUp() { overlayBottomLineUp = new Polyline(); overlayBottomLineUp.getPoints().addAll( new Double[]{ -10.0d, 4.0d, 0.0d, 0.0d, 10.0d, 4.0d} ); }
public static String shapeToSvgString(final Shape SHAPE) { final StringBuilder fxPath = new StringBuilder(); if (Line.class.equals(SHAPE.getClass())) { fxPath.append(convertLine((Line) SHAPE)); } else if (Arc.class.equals(SHAPE.getClass())) { fxPath.append(convertArc((Arc) SHAPE)); } else if (QuadCurve.class.equals(SHAPE.getClass())) { fxPath.append(convertQuadCurve((QuadCurve) SHAPE)); } else if (CubicCurve.class.equals(SHAPE.getClass())) { fxPath.append(convertCubicCurve((CubicCurve) SHAPE)); } else if (Rectangle.class.equals(SHAPE.getClass())) { fxPath.append(convertRectangle((Rectangle) SHAPE)); } else if (Circle.class.equals(SHAPE.getClass())) { fxPath.append(convertCircle((Circle) SHAPE)); } else if (Ellipse.class.equals(SHAPE.getClass())) { fxPath.append(convertEllipse((Ellipse) SHAPE)); } else if (Text.class.equals(SHAPE.getClass())) { Path path = (Path)(Shape.subtract(SHAPE, new Rectangle(0, 0))); fxPath.append(convertPath(path)); } else if (Path.class.equals(SHAPE.getClass())) { fxPath.append(convertPath((Path) SHAPE)); } else if (Polygon.class.equals(SHAPE.getClass())) { fxPath.append(convertPolygon((Polygon) SHAPE)); } else if (Polyline.class.equals(SHAPE.getClass())) { fxPath.append(convertPolyline((Polyline) SHAPE)); } else if (SVGPath.class.equals(SHAPE.getClass())) { fxPath.append(((SVGPath) SHAPE).getContent()); } return fxPath.toString(); }
public static String convertPolyline(final Polyline POLYLINE) { final StringBuilder fxPath = new StringBuilder(); final int size = POLYLINE.getPoints().size(); if (size % 2 == 0) { List<Double> coordinates = POLYLINE.getPoints(); for (int i = 0 ; i < size ; i += 2) { fxPath.append(i == 0 ? "M " : "L ") .append(coordinates.get(i)).append(" ").append(coordinates.get(i + 1)).append(" "); } } return fxPath.toString(); }
@Override public Group createJFXNode() throws Exception { final Polyline polyline = new Polyline(); polyline.setStrokeLineJoin(StrokeLineJoin.MITER); polyline.setStrokeLineCap(StrokeLineCap.BUTT); return new Group(polyline, new Arrow(), new Arrow()); }
@Test public void testGetPolylineAdjuster() { Adjuster adjuster = Adjuster.getAdjuster(Polyline.class); assertThat(adjuster, is(instanceOf(PolylineAdjuster.class))); assertThat(adjuster.getNodeClass(), is(sameInstance(Polyline.class))); }
@Override // Override the start method in the Application class public void start(Stage primaryStage) { // Create a pane Pane pane = new Pane(); // Create a polyline Polyline polyline = new Polyline(new Double(100.0), new Double(100.0)); polyline.setFill(Color.WHITE); polyline.setStroke(Color.BLACK); pane.getChildren().add(polyline); ObservableList<Double> list = polyline.getPoints(); // Create and register handler pane.setOnKeyPressed(e -> { double x = 0, y = 0; double length = 10; switch (e.getCode()) { case DOWN: x = list.get(list.size() - 2); y = list.get(list.size() - 1) + length; break; case UP: x = list.get(list.size() - 2); y = list.get(list.size() - 1) - length; break; case RIGHT: x = list.get(list.size() - 2) + length; y = list.get(list.size() - 1); break; case LEFT: x = list.get(list.size() - 2) - length; y = list.get(list.size() - 1); break; } list.add(x); list.add(y); }); // Create a scene and place it in the stage Scene scene = new Scene(pane, 200, 200); primaryStage.setTitle("Exercise_15_09"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage pane.requestFocus(); // Pane is focused to receive key input }
public PolylineNode(List<Double> points) { this(new Polyline(), points); }
private PolylineNode(Polyline polyline, List<Double> points) { super(polyline); this.polyline = polyline; polyline.getPoints().addAll(points); }
private void createTimeLine(final Pane field, final Interpolator interpolator) { Circle start = new Circle(10, 10, 3); start.setFill(Color.GREEN); Line finish = new Line(0, 110, 120, 110); finish.setStroke(Color.RED); field.getChildren().add(start); field.getChildren().add(finish); final Polyline pl = new Polyline(); pl.getPoints().addAll(10., 10.); field.getChildren().add(pl); WritableDoubleValue dv = new WritableDoubleValue() { double value = 0; private double x = 10; private static final double Y = 9; public Number getValue() { return value; } public double get() { return value; } public void set(double d) { value = d; pl.getPoints().addAll(++x, Y + d); } public void setValue(Number t) { setValue(t.doubleValue()); } }; KeyFrame kf = new KeyFrame(Duration.millis(1000), new KeyValue(dv, Double.valueOf(100), interpolator)); final Timeline timeline = new Timeline(); timeline.getKeyFrames().add(kf); Platform.runLater(new Runnable() { public void run() { timeline.play(); } }); }
@Override public Class<? extends Node> getNodeClass() { return Polyline.class; }
@Override // Override the start method in the Application class public void start(Stage primaryStage) { // Create two panes Pane pane1 = new Pane(); pane1.setRotate(180); pane1.setPadding(new Insets(72, 0, 0, 75)); Pane pane2 = new Pane(); // Create a polyline Polyline polyline1 = new Polyline(); pane1.getChildren().add(polyline1); ObservableList<Double> list = polyline1.getPoints(); double scaleFactor = 0.0125; for (int x = -100; x <= 100; x++) { list.add(x + 200.0); list.add(scaleFactor * x * x); } // Create two lines Line lineX = new Line(10, 200, 350, 200); //pane.getChildren().addAll(stackPane, lineX); Line lineY = new Line(lineX.getEndX() / 2, 250, lineX.getEndX() / 2, 30); pane2.getChildren().addAll(pane1, lineX, lineY); // Create two polylines Polyline polyline2 = new Polyline(); pane2.getChildren().add(polyline2); ObservableList<Double> list2 = polyline2.getPoints(); list2.addAll(lineY.getEndX() - 10, lineY.getEndY() + 20, lineY.getEndX(), lineY.getEndY(), lineY.getEndX() + 10, lineY. getEndY() + 20); Polyline polyline3 = new Polyline(); pane2.getChildren().add(polyline3); ObservableList<Double> list3 = polyline3.getPoints(); list3.addAll(lineX.getEndX() - 20, lineX.getEndY() - 10, lineX.getEndX(), lineX.getEndY(), lineX.getEndX() - 20, lineX. getEndY() + 10); // Create two text objects Text textX = new Text(lineX.getEndX() - 10, lineX.getEndY() - 20, "X"); Text textY = new Text(lineY.getEndX() + 20, lineY.getEndY() + 10, "Y"); pane2.getChildren().addAll(textX, textY); // Create a scene and place it in the stage Scene scene = new Scene(pane2); primaryStage.setTitle("Exercise_14_18"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage }
@Override // Override the start method in the Application class public void start(Stage primaryStage) { // Create a pane Pane pane = new Pane(); // Create three polylines and set their properties Polyline polyline1 = new Polyline(); pane.getChildren().add(polyline1); polyline1.setStroke(Color.BLACK); ObservableList<Double> list = polyline1.getPoints(); double x1 = 40.0; double y1 = 190.0; double y2 = 20.0; double x3 = 125.0; list.addAll(x1, y1, x1, y2, x3, y2, x3, y1 * .60); Polyline polyline2 = new Polyline(); pane.getChildren().add(polyline2); polyline2.setStroke(Color.BLACK); ObservableList<Double> list2 = polyline2.getPoints(); list2.addAll((x1 + x3) * .5, y1 * .5, x3, y1 * .25, x3 + (x3 - x1) * .5, y1 * .5); Polyline polyline3 = new Polyline(); pane.getChildren().add(polyline3); polyline3.setStroke(Color.BLACK); ObservableList<Double> list3 = polyline3.getPoints(); list3.addAll((x1 + x3) * .6, y1 * .80, x3, y1 * .60, x3 + (x3 - x1) * .3, y1 * .80); // Create a circle and set its properties Circle circle = new Circle(x3, y1 * .25, 15); circle.setFill(Color.WHITE); circle.setStroke(Color.BLACK); pane.getChildren().add(circle); // Create an arc and set its properties Arc arc = new Arc(x1, y1 + 1, 25, 15, 0, 180); arc.setFill(Color.WHITE); arc.setStroke(Color.BLACK); pane.getChildren().add(arc); // Create a scene and place it in the stage Scene scene = new Scene(pane, 200, 200); primaryStage.setTitle("Exercise_14_17"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage }
/** * Gets the line * @return The main line */ public Polyline getLine(){ return line; }
/** * Gets the arrowhead * @return The arrowhead */ Polyline getArrowhead(){ return arrowHead; }
/** * Constructor. * * @param sketchPointsVal The Sketch points list * @param sketchDrawingVal the Sketch displayed polyline */ SketchEvent(final List<Point2D> sketchPointsVal, final Polyline sketchDrawingVal) { super(EVENT_TYPE); sketchPoints = sketchPointsVal; sketchDrawing = sketchDrawingVal; }
/** * Get the Sketch displayed polyline. * * @return the Sketch displayed polyline */ final Polyline getSketchDrawing() { return sketchDrawing; }