javafx.scene.shape.PathElement Java Examples
The following examples show how to use
javafx.scene.shape.PathElement.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ToolGraphics.java From JetUML with GNU General Public License v3.0 | 6 votes |
private static void applyPath(GraphicsContext pGraphics, Path pPath) { pGraphics.beginPath(); for(PathElement element : pPath.getElements()) { if(element instanceof MoveTo) { pGraphics.moveTo(((int)((MoveTo) element).getX()) + 0.5, ((int)((MoveTo) element).getY()) + 0.5); } else if(element instanceof LineTo) { pGraphics.lineTo(((int)((LineTo) element).getX()) + 0.5, ((int)((LineTo) element).getY()) + 0.5); } else if (element instanceof QuadCurveTo) { QuadCurveTo curve = (QuadCurveTo) element; pGraphics.quadraticCurveTo(((int)curve.getControlX())+0.5, ((int)curve.getControlY()) + 0.5, ((int) curve.getX()) + 0.5, ((int) curve.getY()) + 0.5); } } }
Example #2
Source File: Paragraph.java From Open-Lowcode with Eclipse Public License 2.0 | 6 votes |
protected void displaySelection() { logger.finest(" - DisplaySelection - Try to print " + dragstartindex + " - " + dragendindex); if (this.dragstartindex >= 0) if (this.dragendindex >= 0) if (this.dragendindex > this.dragstartindex) { hideSelection(); TextLayout textlayout = (TextLayout) invoke(getTextLayout, textflow); PathElement[] highlight = textlayout.getRange(this.dragstartindex, this.dragendindex, TextLayout.TYPE_TEXT, 0, 0); hightlightpath = new Path(highlight); hightlightpath.setManaged(false); hightlightpath.setFill(Color.web("#222235", 0.2)); hightlightpath.setStrokeWidth(0); if (title) hightlightpath.setTranslateY(6); if (bulletpoint) { hightlightpath.setTranslateY(2); hightlightpath.setTranslateX(5); } textflow.getChildren().add(hightlightpath); textflow.requestLayout(); textflow.requestFocus(); } }
Example #3
Source File: ViewFactory.java From latexdraw with GNU General Public License v3.0 | 6 votes |
@Override public Optional<PathElement> createPathElement(final PathElement elt) { if(elt instanceof LineTo) { return Optional.of(createLineTo(((LineTo) elt).getX(), ((LineTo) elt).getY())); } if(elt instanceof MoveTo) { return Optional.of(createMoveTo(((MoveTo) elt).getX(), ((MoveTo) elt).getY())); } if(elt instanceof ClosePath) { return Optional.of(createClosePath()); } if(elt instanceof CubicCurveTo) { final CubicCurveTo curve = (CubicCurveTo) elt; return Optional.of(createCubicCurveTo(curve.getControlX1(), curve.getControlY1(), curve.getControlX2(), curve.getControlY2(), curve.getX(), curve.getY())); } return Optional.empty(); }
Example #4
Source File: ViewFactory.java From latexdraw with GNU General Public License v3.0 | 6 votes |
@Override public void flushPathElement(final PathElement elt) { if(elt instanceof LineTo) { final LineTo lineTo = (LineTo) elt; lineTo.xProperty().unbind(); lineTo.yProperty().unbind(); }else { if(elt instanceof MoveTo) { final MoveTo moveTo = (MoveTo) elt; moveTo.xProperty().unbind(); moveTo.yProperty().unbind(); }else { if(elt instanceof CubicCurveTo) { final CubicCurveTo cct = (CubicCurveTo) elt; cct.xProperty().unbind(); cct.yProperty().unbind(); cct.controlX1Property().unbind(); cct.controlX2Property().unbind(); cct.controlY1Property().unbind(); cct.controlY2Property().unbind(); } } } }
Example #5
Source File: ViewGrid.java From latexdraw with GNU General Public License v3.0 | 6 votes |
/** * Companion method of updatePathSubGrid */ private final void updatePathSubGridLines(final double posX, final double posY, final double minX, final double maxX, final double minY, final double maxY, final double xStep, final double yStep, final double xSubStep, final double ySubStep, final double tlx, final double tly, final double brx, final double bry) { final ObservableList<PathElement> elements = subgrid.getElements(); final double subGridDiv = model.getSubGridDiv(); for(double k = minX, i = posX; k < maxX; i += xStep, k++) { for(double j = 0d; j <= subGridDiv; j++) { elements.add(pathProducer.createMoveTo(i + xSubStep * j, bry)); elements.add(pathProducer.createLineTo(i + xSubStep * j, tly)); } } for(double k = minY, i = posY; k < maxY; i -= yStep, k++) { for(double j = 0d; j <= subGridDiv; j++) { elements.add(pathProducer.createMoveTo(tlx, i - ySubStep * j)); elements.add(pathProducer.createLineTo(brx, i - ySubStep * j)); } } }
Example #6
Source File: ViewGrid.java From latexdraw with GNU General Public License v3.0 | 6 votes |
private final void updatePathMainGrid(final double unit, final double minX, final double maxX, final double minY, final double maxY, final double posX, final double posY, final double xStep, final double yStep, final double tlx, final double tly, final double brx, final double bry, final double absStep) { if(model.getGridDots() > 0) { updatePathMainGridDots(unit, minX, maxX, minY, maxY, posX, posY, xStep, yStep, tlx, tly, brx, bry, absStep); }else { final ObservableList<PathElement> elements = maingrid.getElements(); for(double k = minX, i = posX; k <= maxX; i += xStep, k++) { elements.add(pathProducer.createMoveTo(i, bry)); elements.add(pathProducer.createLineTo(i, tly)); } for(double k = minY, i = posY; k <= maxY; i -= yStep, k++) { elements.add(pathProducer.createMoveTo(tlx, i)); elements.add(pathProducer.createLineTo(brx, i)); } } }
Example #7
Source File: TextFlowExt.java From RichTextFX with BSD 2-Clause "Simplified" License | 6 votes |
/** * @param from The index of the first character. * @param to The index of the last character. * @return An array with the PathElement objects which define an * underline from the first to the last character. */ PathElement[] getUnderlineShape(int from, int to) { // get a Path for the text underline List<PathElement> result = new ArrayList<>(); PathElement[] shape = rangeShape( from, to ); // The shape is a closed Path for one or more rectangles AROUND the selected text. // shape: [MoveTo origin, LineTo top R, LineTo bottom R, LineTo bottom L, LineTo origin, *] // Extract the bottom left and right coordinates for each rectangle to get the underline path. for ( int ele = 2; ele < shape.length; ele += 5 ) { LineTo bl = (LineTo) shape[ele+1]; LineTo br = (LineTo) shape[ele]; double y = br.getY() - 2.5; result.add( new MoveTo( bl.getX(), y ) ); result.add( new LineTo( br.getX(), y ) ); } return result.toArray(new PathElement[0]); }
Example #8
Source File: TextFlowExt.java From RichTextFX with BSD 2-Clause "Simplified" License | 6 votes |
/** * @param from The index of the first character. * @param to The index of the last character. * @return An array with the PathElement objects which define an * underline from the first to the last character. */ PathElement[] getUnderlineShape(int from, int to) { // get a Path for the text underline PathElement[] shape = textLayout().getRange(from, to, TextLayout.TYPE_UNDERLINE, 0, 0); // The shape is returned as a closed Path (a thin rectangle). // If we use the Path as it is, this causes rendering issues. // Hence we only use the MoveTo and the succeeding LineTo elements for the result // so that simple line segments instead of rectangles are returned. List<PathElement> result = new ArrayList<>(); boolean collect = false; for (PathElement elem : shape) { if (elem instanceof MoveTo) { // There seems to be no API to get the type of the PathElement result.add(elem); collect = true; } else if (elem instanceof LineTo) { if (collect) { result.add(elem); collect = false; } } } return result.toArray(new PathElement[0]); }
Example #9
Source File: ParagraphText.java From RichTextFX with BSD 2-Clause "Simplified" License | 6 votes |
public Bounds getRangeBoundsOnScreen(int from, int to) { layout(); // ensure layout, is a no-op if not dirty PathElement[] rangeShape = getRangeShapeSafely(from, to); Path p = new Path(); p.setManaged(false); p.setLayoutX(getInsets().getLeft()); p.setLayoutY(getInsets().getTop()); getChildren().add(p); p.getElements().setAll(rangeShape); Bounds localBounds = p.getBoundsInLocal(); Bounds rangeBoundsOnScreen = p.localToScreen(localBounds); getChildren().remove(p); return rangeBoundsOnScreen; }
Example #10
Source File: ParagraphOverlayGraphicFactory.java From markdown-writer-fx with BSD 2-Clause "Simplified" License | 6 votes |
protected Rectangle2D getBounds(int start, int end) { PathElement[] shape = getShape(start, end); double minX = 0, minY = 0, maxX = 0, maxY = 0; for (PathElement pathElement : shape) { if (pathElement instanceof MoveTo) { MoveTo moveTo = (MoveTo) pathElement; minX = maxX = moveTo.getX(); minY = maxY = moveTo.getY(); } else if (pathElement instanceof LineTo) { LineTo lineTo = (LineTo) pathElement; double x = lineTo.getX(); double y = lineTo.getY(); minX = Math.min(minX, x); minY = Math.min(minY, y); maxX = Math.max(maxX, x); maxY = Math.max(maxY, y); } } return new Rectangle2D(minX, minY, maxX - minX, maxY - minY); }
Example #11
Source File: ViewPolyPoint.java From latexdraw with GNU General Public License v3.0 | 5 votes |
private void initPath(final Path path) { final ObservableList<PathElement> elts = path.getElements(); final MoveTo moveTo = pathProducer.createMoveTo(0d, 0d); moveTo.xProperty().bind(model.getPtAt(0).xProperty()); moveTo.yProperty().bind(model.getPtAt(0).yProperty()); elts.add(moveTo); IntStream.range(1, model.getNbPoints()).forEach(i -> { final LineTo lineto = pathProducer.createLineTo(0d, 0d); lineto.xProperty().bind(model.getPtAt(i).xProperty()); lineto.yProperty().bind(model.getPtAt(i).yProperty()); elts.add(lineto); }); }
Example #12
Source File: TestViewPlot.java From latexdraw with GNU General Public License v3.0 | 5 votes |
@Test void testOnChangeNbPlotPoints() { final List<PathElement> before = duplicatePath(getCurvePath()); model.setNbPlottedPoints(model.getNbPlottedPoints() + 41); WaitForAsyncUtils.waitForFxEvents(); assertNotEquals(before, getCurvePath()); }
Example #13
Source File: TestViewPlot.java From latexdraw with GNU General Public License v3.0 | 5 votes |
@Test void testOnChangeEquation() { final List<PathElement> before = duplicatePath(getCurvePath()); model.setPlotEquation("x 2 mul"); WaitForAsyncUtils.waitForFxEvents(); assertNotEquals(before, getCurvePath()); }
Example #14
Source File: TestViewPlot.java From latexdraw with GNU General Public License v3.0 | 5 votes |
@Test void testOnChangeDotStyle() { model.setPlotStyle(PlotStyle.DOTS); WaitForAsyncUtils.waitForFxEvents(); final List<PathElement> before = ((Path) ((ViewDot) view.getChildren().get(0)).getChildren().get(1)).getElements(); model.setDotStyle(DotStyle.FDIAMOND); WaitForAsyncUtils.waitForFxEvents(); assertNotEquals(before, ((Path) ((ViewDot) view.getChildren().get(0)).getChildren().get(1)).getElements()); }
Example #15
Source File: TestViewPlot.java From latexdraw with GNU General Public License v3.0 | 5 votes |
@Test void testOnChangePolar() { final List<PathElement> before = duplicatePath(getCurvePath()); model.setPolar(!model.isPolar()); WaitForAsyncUtils.waitForFxEvents(); assertNotEquals(before, getCurvePath()); }
Example #16
Source File: TestViewPlot.java From latexdraw with GNU General Public License v3.0 | 5 votes |
@Test void testOnChangePlotXMin() { final List<PathElement> before = duplicatePath(getCurvePath()); model.setPlotMinX(model.getPlotMinX() - 2d); WaitForAsyncUtils.waitForFxEvents(); assertNotEquals(before, getCurvePath()); }
Example #17
Source File: TestViewPlot.java From latexdraw with GNU General Public License v3.0 | 5 votes |
@Test void testOnChangePlotXMax() { final List<PathElement> before = duplicatePath(getCurvePath()); model.setPlotMaxX(model.getPlotMaxX() + 3d); WaitForAsyncUtils.waitForFxEvents(); assertNotEquals(before, getCurvePath()); }
Example #18
Source File: TestViewPlot.java From latexdraw with GNU General Public License v3.0 | 5 votes |
@Test void testOnChangePlotXScale() { final List<PathElement> before = duplicatePath(getCurvePath()); model.setXScale(model.getXScale() * 1.33); WaitForAsyncUtils.waitForFxEvents(); assertNotEquals(before, getCurvePath()); }
Example #19
Source File: TestViewPlot.java From latexdraw with GNU General Public License v3.0 | 5 votes |
@Test void testOnChangePlotYScale() { final List<PathElement> before = duplicatePath(getCurvePath()); model.setYScale(model.getYScale() * 0.87); WaitForAsyncUtils.waitForFxEvents(); assertNotEquals(before, getCurvePath()); }
Example #20
Source File: JFXToSVG.java From latexdraw with GNU General Public License v3.0 | 5 votes |
private SVGPathSeg createSVGPathSeg(final PathElement elt) { if(elt instanceof LineTo) { return createSVGPathSegLineto((LineTo) elt); } if(elt instanceof MoveTo) { return createSVGPathSegMoveto((MoveTo) elt); } if(elt instanceof ClosePath) { return new SVGPathSegClosePath(); } if(elt instanceof CubicCurveTo) { return createSVGPathSegCurvetoCubic((CubicCurveTo) elt); } return null; }
Example #21
Source File: TestViewShape.java From latexdraw with GNU General Public License v3.0 | 5 votes |
public static void assertPathSameButNotEqual(final List<PathElement> p1, final List<PathElement> p2) { assertEquals(p1.size(), p2.size()); for(int i = 0, size = p2.size(); i < size; i++) { if(p1.get(i) instanceof ClosePath) { assertTrue(p2.get(i) instanceof ClosePath); }else { assertNotEquals(p1.get(i), p2.get(i)); } } }
Example #22
Source File: ViewGrid.java From latexdraw with GNU General Public License v3.0 | 5 votes |
private void updatePathMainGridDots(final double unit, final double minX, final double maxX, final double minY, final double maxY, final double posX, final double posY, final double xStep, final double yStep, final double tlx, final double tly, final double brx, final double bry, final double absStep) { final int gridDots = model.getGridDots(); final double dotStep = unit * Shape.PPC / gridDots; final ObservableList<PathElement> elements = maingrid.getElements(); for(double k = minX, i = posX; k <= maxX; i += xStep, k++) { for(double m = tly, n = minY; n < maxY; n++, m += absStep) { for(double l = 0d, j = m; l < gridDots; l++, j += dotStep) { elements.add(pathProducer.createMoveTo(i, j)); elements.add(pathProducer.createLineTo(i, j)); } } } for(double k = minY, i = posY; k <= maxY; i -= yStep, k++) { for(double m = tlx, n = minX; n < maxX; n++, m += absStep) { for(double l = 0d, j = m; l < gridDots; l++, j += dotStep) { elements.add(pathProducer.createMoveTo(j, i)); elements.add(pathProducer.createLineTo(j, i)); } } } elements.add(pathProducer.createMoveTo(brx, bry)); elements.add(pathProducer.createLineTo(brx, bry)); }
Example #23
Source File: TestViewShape.java From latexdraw with GNU General Public License v3.0 | 5 votes |
protected List<PathElement> duplicatePath(final List<PathElement> path) { return path.stream().map(elt -> { final PathElement dupelt; if(elt instanceof MoveTo) { final MoveTo moveTo = (MoveTo) elt; dupelt = factory.createMoveTo(moveTo.getX(), moveTo.getY()); }else { if(elt instanceof LineTo) { final LineTo lineTo = (LineTo) elt; dupelt = factory.createLineTo(lineTo.getX(), lineTo.getY()); }else { if(elt instanceof ClosePath) { dupelt = factory.createClosePath(); }else { if(elt instanceof CubicCurveTo) { final CubicCurveTo cct = (CubicCurveTo) elt; dupelt = factory.createCubicCurveTo(cct.getControlX1(), cct.getControlY1(), cct.getControlX2(), cct.getControlY2(), cct.getX(), cct.getY()); }else { throw new IllegalArgumentException(); } } } } dupelt.setAbsolute(elt.isAbsolute()); return dupelt; }).collect(Collectors.toList()); }
Example #24
Source File: TestViewPolyline.java From latexdraw with GNU General Public License v3.0 | 5 votes |
@Test public void testMovePointUpdatePathArrow0() { model.setArrowStyle(ArrowStyle.RIGHT_ARROW, 0); WaitForAsyncUtils.waitForFxEvents(); final double tx = ((Translate) view.viewArrows.arrows.get(0).path.getTransforms().get(0)).getX(); final double ty = ((Translate) view.viewArrows.arrows.get(0).path.getTransforms().get(0)).getY(); final List<PathElement> pathArrow = duplicatePath(view.viewArrows.arrows.get(0).path.getElements()); model.getPtAt(0).translate(10d, 11d); WaitForAsyncUtils.waitForFxEvents(); assertEquals(pathArrow, view.viewArrows.arrows.get(0).path.getElements()); assertNotEquals(tx, ((Translate) view.viewArrows.arrows.get(0).path.getTransforms().get(0)).getX()); assertNotEquals(ty, ((Translate) view.viewArrows.arrows.get(0).path.getTransforms().get(0)).getY()); }
Example #25
Source File: ParagraphText.java From RichTextFX with BSD 2-Clause "Simplified" License | 5 votes |
private PathElement[] createRectangle(double topLeftX, double topLeftY, double bottomRightX, double bottomRightY) { return new PathElement[] { new MoveTo(topLeftX, topLeftY), new LineTo(bottomRightX, topLeftY), new LineTo(bottomRightX, bottomRightY), new LineTo(topLeftX, bottomRightY), new LineTo(topLeftX, topLeftY) }; }
Example #26
Source File: TestViewPolyline.java From latexdraw with GNU General Public License v3.0 | 5 votes |
@Test public void testMovePointUpdatePathArrow1() { model.setArrowStyle(ArrowStyle.RIGHT_ARROW, 1); WaitForAsyncUtils.waitForFxEvents(); final double tx = ((Translate) view.viewArrows.arrows.get(1).path.getTransforms().get(0)).getX(); final double ty = ((Translate) view.viewArrows.arrows.get(1).path.getTransforms().get(0)).getY(); final List<PathElement> pathArrow = duplicatePath(view.viewArrows.arrows.get(1).path.getElements()); model.getPtAt(9).translate(10d, 11d); WaitForAsyncUtils.waitForFxEvents(); assertEquals(pathArrow, view.viewArrows.arrows.get(1).path.getElements()); assertNotEquals(tx, ((Translate) view.viewArrows.arrows.get(1).path.getTransforms().get(0)).getX()); assertNotEquals(ty, ((Translate) view.viewArrows.arrows.get(1).path.getTransforms().get(0)).getY()); }
Example #27
Source File: CursorOffsetCalculator.java From graph-editor with Eclipse Public License 1.0 | 5 votes |
/** * Gets the horizontal or vertical offset to the connection for the given cursor position. * * @param cursorSceneX the cursor x-position in the scene * @param cursorSceneY the cursor y-position in the scene * @return an offset to the nearest connection, or {@code null} if the cursor is too far away */ public Point2D getOffset(final double cursorSceneX, final double cursorSceneY) { // Scale factor only relevant if we are zoomed in. final double scaleFactor = backgroundPath.getLocalToSceneTransform().getMxx(); // This will be used as the largest acceptable offset value. final double offsetBound = Math.ceil(backgroundPath.getStrokeWidth() / 2) * scaleFactor; minOffsetX = offsetBound + 1; minOffsetY = offsetBound + 1; currentX = ((MoveTo) path.getElements().get(0)).getX(); currentY = ((MoveTo) path.getElements().get(0)).getY(); for (int i = 1; i < path.getElements().size(); i++) { final PathElement pathElement = path.getElements().get(i); calculateOffset(pathElement, cursorSceneX, cursorSceneY, offsetBound); } if (minOffsetX > offsetBound && minOffsetY > offsetBound) { return null; } else if (Math.abs(minOffsetX) <= Math.abs(minOffsetY)) { return new Point2D(minOffsetX, 0); } else { return new Point2D(0, minOffsetY); } }
Example #28
Source File: TestViewPolyline.java From latexdraw with GNU General Public License v3.0 | 5 votes |
@Test public void testThicknessChangesArrow() { model.setArrowStyle(ArrowStyle.RIGHT_ARROW, 0); WaitForAsyncUtils.waitForFxEvents(); final List<PathElement> pathArrow = duplicatePath(view.viewArrows.arrows.get(0).path.getElements()); model.setThickness(model.getThickness() * 2d); WaitForAsyncUtils.waitForFxEvents(); assertNotEquals(pathArrow, view.viewArrows.arrows.get(0).path.getElements()); }
Example #29
Source File: CrosshairIndicator.java From chart-fx with Apache License 2.0 | 5 votes |
private void updatePath(final MouseEvent event, final Bounds plotAreaBounds) { final ObservableList<PathElement> path = crosshairPath.getElements(); path.clear(); path.add(new MoveTo(plotAreaBounds.getMinX() + 1, event.getY())); path.add(new LineTo(plotAreaBounds.getMaxX(), event.getY())); path.add(new MoveTo(event.getX(), plotAreaBounds.getMinY() + 1)); path.add(new LineTo(event.getX(), plotAreaBounds.getMaxY())); }
Example #30
Source File: ViewGrid.java From latexdraw with GNU General Public License v3.0 | 5 votes |
/** * Companion method of updatePathSubGrid */ private final void updatePathSubGridDots(final double minX, final double maxX, final double minY, final double maxY, final double xSubStep, final double ySubStep, final double tlx, final double tly, final double brx, final double bry, final double unit) { final ObservableList<PathElement> elements = subgrid.getElements(); final double subGridDiv = model.getSubGridDiv(); final double subGridDots = model.getSubGridDots(); final double dotStep = unit * Shape.PPC / (subGridDots * subGridDiv); final double nbX = (maxX - minX) * subGridDiv; final double nbY = (maxY - minY) * subGridDiv; for(double i = 0d, n = tlx; i < nbX; i++, n += xSubStep) { for(double j = 0d, m = tly; j <= nbY; j++, m += ySubStep) { for(double k = 0d; k < subGridDots; k++) { elements.add(pathProducer.createMoveTo(n + k * dotStep, m)); elements.add(pathProducer.createLineTo(n + k * dotStep, m)); } } } for(double j = 0d, n = tly; j < nbY; j++, n += ySubStep) { for(double i = 0d, m = tlx; i <= nbX; i++, m += xSubStep) { for(double k = 0d; k < subGridDots; k++) { elements.add(pathProducer.createMoveTo(m, n + k * dotStep)); elements.add(pathProducer.createLineTo(m, n + k * dotStep)); } } } elements.add(pathProducer.createMoveTo(brx, bry)); elements.add(pathProducer.createLineTo(brx, bry)); }