javafx.scene.shape.Arc Java Examples

The following examples show how to use javafx.scene.shape.Arc. 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: IndicatorSkin.java    From Medusa with Apache License 2.0 6 votes vote down vote up
private void drawSections() {
    if (sections.isEmpty()) return;
    sectionLayer.getChildren().clear();

    double    centerX     = width * 0.5;
    double    centerY     = height * 0.85;
    double    barRadius   = height * 0.54210526;
    double    barWidth    = width * 0.28472222;
    List<Arc> sectionBars = new ArrayList<>(sections.size());
    for (Section section : sections) {
        Arc sectionBar = new Arc(centerX, centerY, barRadius, barRadius, angleRange * 0.5 + 90 - (section.getStart() * angleStep), -((section.getStop() - section.getStart()) - minValue) * angleStep);
        sectionBar.setType(ArcType.OPEN);
        sectionBar.setStroke(section.getColor());
        sectionBar.setStrokeWidth(barWidth);
        sectionBar.setStrokeLineCap(StrokeLineCap.BUTT);
        sectionBar.setFill(null);
        Tooltip sectionTooltip = new Tooltip(new StringBuilder(section.getText()).append("\n").append(String.format(Locale.US, "%.2f", section.getStart())).append(" - ").append(String.format(Locale.US, "%.2f", section.getStop())).toString());
        sectionTooltip.setTextAlignment(TextAlignment.CENTER);
        Tooltip.install(sectionBar, sectionTooltip);
        sectionBars.add(sectionBar);
    }
    sectionLayer.getChildren().addAll(sectionBars);
}
 
Example #2
Source File: TileKpiSkin.java    From Medusa with Apache License 2.0 6 votes vote down vote up
public TileKpiSkin(Gauge gauge) {
    super(gauge);
    if (gauge.isAutoScale()) gauge.calcAutoScale();
    angleRange           = Helper.clamp(90.0, 180.0, gauge.getAngleRange());
    oldValue             = gauge.getValue();
    minValue             = gauge.getMinValue();
    threshold            = gauge.getThreshold();
    thresholdColor       = gauge.getThresholdColor();
    range                = gauge.getRange();
    angleStep            = angleRange / range;
    formatString         = new StringBuilder("%.").append(Integer.toString(gauge.getDecimals())).append("f").toString();
    locale               = gauge.getLocale();
    sectionsVisible      = gauge.getSectionsVisible();
    highlightSections    = gauge.isHighlightSections();
    sections             = gauge.getSections();
    sectionMap           = new HashMap<>(sections.size());
    currentValueListener = o -> rotateNeedle(gauge.getCurrentValue());
    for(Section section : sections) { sectionMap.put(section, new Arc()); }

    initGraphics();
    registerListeners();

    rotateNeedle(gauge.getCurrentValue());
}
 
Example #3
Source File: FanPane.java    From Intro-to-Java-Programming with MIT License 6 votes vote down vote up
/** Add four arcs to a pane and place them in a stack pane */
private void getBlades() {
	double angle = 0;
	for (int i = 0; i < 4; i++) {
		arc = new Arc(); 
		arc.centerXProperty().bind(widthProperty().divide(2));
		arc.centerYProperty().bind(heightProperty().divide(2));
		arc.radiusXProperty().bind(circle.radiusProperty().multiply(.90));
		arc.radiusYProperty().bind(circle.radiusProperty().multiply(.90));
		arc.setStartAngle(angle + 90);
		arc.setLength(50);
		arc.setFill(Color.BLACK);
		arc.setType(ArcType.ROUND);
		paneForBlades.getChildren().add(arc);
		angle += 90;
	}
}
 
Example #4
Source File: FanPane.java    From Intro-to-Java-Programming with MIT License 6 votes vote down vote up
/** Add four arcs to a pane and place them in a stack pane */
private void getBlades() {
	double angle = 0;
	for (int i = 0; i < 4; i++) {
		arc = new Arc(); 
		arc.centerXProperty().bind(widthProperty().divide(2));
		arc.centerYProperty().bind(heightProperty().divide(2));
		arc.radiusXProperty().bind(circle.radiusProperty().multiply(.90));
		arc.radiusYProperty().bind(circle.radiusProperty().multiply(.90));
		arc.setStartAngle(angle + 90);
		arc.setLength(50);
		arc.setFill(Color.BLACK);
		arc.setType(ArcType.ROUND);
		paneForBlades.getChildren().add(arc);
		angle += 90;
	}
}
 
Example #5
Source File: GaugeTileSkin.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
@Override protected void handleEvents(final String EVENT_TYPE) {
    super.handleEvents(EVENT_TYPE);

    if ("VISIBILITY".equals(EVENT_TYPE)) {
        Helper.enableNode(titleText, !tile.getTitle().isEmpty());
        Helper.enableNode(valueText, tile.isValueVisible());
        Helper.enableNode(sectionPane, tile.getSectionsVisible());
        Helper.enableNode(thresholdRect, tile.isThresholdVisible());
        Helper.enableNode(thresholdText, tile.isThresholdVisible());
        Helper.enableNode(unitFlow, !tile.getUnit().isEmpty());
        sectionsVisible = tile.getSectionsVisible();
    } else if ("SECTION".equals(EVENT_TYPE)) {
        sections = tile.getSections();
        sectionMap.clear();
        for(Section section : sections) { sectionMap.put(section, new Arc()); }
    } else if ("ALERT".equals(EVENT_TYPE)) {
        Helper.enableNode(valueText, tile.isValueVisible() && !tile.isAlert());
        Helper.enableNode(unitText, tile.isValueVisible() && !tile.isAlert());
        Helper.enableNode(alertIcon, tile.isAlert());
        alertTooltip.setText(tile.getAlertMessage());
    }
}
 
Example #6
Source File: ArcSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public ArcSample() {
    super(180,90);
    // Simple red filled arc
    Arc arc1 = new Arc(45,60,45,45,40,100);
    arc1.setFill(Color.RED);
    // Blue stroked arc
    Arc arc2 = new Arc(155,60,45,45,40,100);
    arc2.setStroke(Color.DODGERBLUE);
    arc2.setFill(null);
    // Create a group to show all the arcs);
    getChildren().add(new Group(arc1,arc2));
    // REMOVE ME
    setControls(
            new SimplePropertySheet.PropDesc("Arc 1 Fill", arc1.fillProperty()),
            new SimplePropertySheet.PropDesc("Arc 1 Start Angle", arc1.startAngleProperty(), 0d, 360d),
            new SimplePropertySheet.PropDesc("Arc 1 Length", arc1.lengthProperty(), 0d, 360d),
            new SimplePropertySheet.PropDesc("Arc 2 Stroke", arc2.strokeProperty()),
            new SimplePropertySheet.PropDesc("Arc 2 Stroke Width", arc2.strokeWidthProperty(), 1d, 5d),
            new SimplePropertySheet.PropDesc("Arc 2 Radius X", arc2.radiusXProperty(), 0d, 50d),
            new SimplePropertySheet.PropDesc("Arc 2 Radius Y", arc2.radiusYProperty(), 0d, 50d)
    );
    // END REMOVE ME
}
 
Example #7
Source File: ArcSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public ArcSample() {
    super(180,90);
    // Simple red filled arc
    Arc arc1 = new Arc(45,60,45,45,40,100);
    arc1.setFill(Color.RED);
    // Blue stroked arc
    Arc arc2 = new Arc(155,60,45,45,40,100);
    arc2.setStroke(Color.DODGERBLUE);
    arc2.setFill(null);
    // Create a group to show all the arcs);
    getChildren().add(new Group(arc1,arc2));
    // REMOVE ME
    setControls(
            new SimplePropertySheet.PropDesc("Arc 1 Fill", arc1.fillProperty()),
            new SimplePropertySheet.PropDesc("Arc 1 Start Angle", arc1.startAngleProperty(), 0d, 360d),
            new SimplePropertySheet.PropDesc("Arc 1 Length", arc1.lengthProperty(), 0d, 360d),
            new SimplePropertySheet.PropDesc("Arc 2 Stroke", arc2.strokeProperty()),
            new SimplePropertySheet.PropDesc("Arc 2 Stroke Width", arc2.strokeWidthProperty(), 1d, 5d),
            new SimplePropertySheet.PropDesc("Arc 2 Radius X", arc2.radiusXProperty(), 0d, 50d),
            new SimplePropertySheet.PropDesc("Arc 2 Radius Y", arc2.radiusYProperty(), 0d, 50d)
    );
    // END REMOVE ME
}
 
Example #8
Source File: PieSkin.java    From WorkbenchFX with Apache License 2.0 6 votes vote down vote up
@Override
public void initializeParts() {
  double center = ARTBOARD_HEIGHT * 0.5;
  border = new Circle(center, center, center);
  border.getStyleClass().add("border");

  pieSlice = new Arc(center, center, center - 1, center - 1, 90, 0);
  pieSlice.getStyleClass().add("pieSlice");
  pieSlice.setType(ArcType.ROUND);

  valueField = new TextField();
  valueField.relocate(ARTBOARD_HEIGHT + 5, 2);
  valueField.setPrefWidth(ARTBOARD_WIDTH - ARTBOARD_HEIGHT - 5);
  valueField.getStyleClass().add("valueField");

  // always needed
  drawingPane = new Pane();
  drawingPane.setMaxSize(ARTBOARD_WIDTH, ARTBOARD_HEIGHT);
  drawingPane.setMinSize(ARTBOARD_WIDTH, ARTBOARD_HEIGHT);
  drawingPane.setPrefSize(ARTBOARD_WIDTH, ARTBOARD_HEIGHT);
}
 
Example #9
Source File: CenterArc.java    From CrazyAlpha with GNU General Public License v2.0 6 votes vote down vote up
public CenterArc() {
    fillColor = Color.color(Math.random(), Math.random(), Math.random());
    strokeColor = Color.YELLOW;
    width = 120;
    height = 120;
    x = (Game.getInstance().getRender().getWidth() - width) / 2;
    y = (Game.getInstance().getRender().getHeight() - height) / 2;
    for (int i = 0; i < 4; i++) {
        Arc arc = new Arc(x, y, width, height, i * 90, 30);
        arc.setType(ArcType.ROUND);
        shapes.add(arc);
    }
    effect = new GaussianBlur();

    start();
}
 
Example #10
Source File: TimerControlTileSkin.java    From OEE-Designer with MIT License 6 votes vote down vote up
@Override protected void handleEvents(final String EVENT_TYPE) {
    super.handleEvents(EVENT_TYPE);

    if ("VISIBILITY".equals(EVENT_TYPE)) {
        Helper.enableNode(titleText, !tile.getTitle().isEmpty());
        Helper.enableNode(text, tile.isTextVisible());
        Helper.enableNode(dateText, tile.isDateVisible());
        Helper.enableNode(second, tile.isSecondsVisible());
        Helper.enableNode(sectionsPane, tile.getSectionsVisible());
    } else if ("SECTION".equals(EVENT_TYPE)) {
        sectionMap.clear();
        for (TimeSection section : tile.getTimeSections()) { sectionMap.put(section, new Arc()); }
        sectionsPane.getChildren().setAll(sectionMap.values());
        resize();
        redraw();
    }
}
 
Example #11
Source File: RotationHandler.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
/**
 * The constructor by default.
 * @param border The selection border.
 */
public RotationHandler(final @NotNull Rectangle border) {
	super();
	final Arc arc = new Arc();
	arc.setCenterX(DEFAULT_SIZE / 2d);
	arc.setRadiusX(DEFAULT_SIZE / 2d);
	arc.setRadiusY(DEFAULT_SIZE / 2d);
	arc.setType(ArcType.OPEN);
	arc.setLength(270d);
	arc.setStroke(DEFAULT_COLOR);
	arc.setStrokeWidth(2.5d);
	arc.setStrokeLineCap(StrokeLineCap.BUTT);
	arc.setFill(new Color(1d, 1d, 1d, 0d));
	getChildren().add(arc);

	final Path arrows = new Path();
	arrows.setStroke(null);
	arrows.setFill(new Color(0d, 0d, 0d, 0.4));
	arrows.getElements().add(new MoveTo(DEFAULT_SIZE + DEFAULT_SIZE / 4d, 0d));
	arrows.getElements().add(new LineTo(DEFAULT_SIZE, DEFAULT_SIZE / 2d));
	arrows.getElements().add(new LineTo(DEFAULT_SIZE - DEFAULT_SIZE / 4d, 0d));
	arrows.getElements().add(new ClosePath());
	getChildren().add(arrows);

	translateXProperty().bind(Bindings.createDoubleBinding(() -> border.getLayoutX() + border.getWidth(), border.xProperty(),
		border.widthProperty(), border.layoutXProperty()));
	translateYProperty().bind(Bindings.createDoubleBinding(() -> border.getLayoutY() + DEFAULT_SIZE, border.yProperty(),
		border.heightProperty(), border.layoutYProperty()));
}
 
Example #12
Source File: TestViewCircleArc.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
@ParameterizedTest
@EnumSource(ArcStyle.class)
void testClipArrowSameDimensions(final ArcStyle style) {
	assumeTrue(style.supportArrow());
	model.setArcStyle(style);
	model.setArrowStyle(ArrowStyle.RIGHT_ARROW, 0);
	model.setArrowStyle(ArrowStyle.RIGHT_DBLE_ARROW, -1);
	WaitForAsyncUtils.waitForFxEvents();
	final Arc clip = (Arc) view.border.getClip();
	assertEquals(clip.getCenterX(), view.border.getCenterX(), 0.0001);
	assertEquals(clip.getCenterY(), view.border.getCenterY(), 0.0001);
	assertEquals(clip.getRadiusX(), view.border.getRadiusX(), 0.0001);
	assertEquals(clip.getRadiusY(), view.border.getRadiusY(), 0.0001);
}
 
Example #13
Source File: Exercise_14_11.java    From Intro-to-Java-Programming with MIT License 5 votes vote down vote up
/** Return a Arc of specified properties */
private Arc getArc(Circle c) {
	Arc a = new Arc(c.getRadius(), c.getRadius() * 1.30, 
		c.getRadius() / 2, c.getRadius() / 4, 0, -180);
	a.setType(ArcType.OPEN);
	a.setFill(Color.WHITE);
	a.setStroke(Color.BLACK);
	return a;
}
 
Example #14
Source File: ViewCircleArc.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
private final void bindArcProperties(final Arc arc) {
	arc.startAngleProperty().bind(Bindings.createDoubleBinding(() -> Math.toDegrees(model.getAngleStart()), model.angleStartProperty()));
	arc.lengthProperty().bind(Bindings.createDoubleBinding(
		() -> model.getAngleEnd() > model.getAngleStart() ? Math.toDegrees(model.getAngleEnd() - model.getAngleStart()) :
			Math.toDegrees(Math.PI * 2d - model.getAngleStart() + model.getAngleEnd()), model.angleStartProperty(), model.angleEndProperty()));
	model.angleStartProperty().addListener(viewArrows.updateArrow);
	model.angleEndProperty().addListener(viewArrows.updateArrow);
	arc.typeProperty().bind(Bindings.createObjectBinding(() -> model.getArcStyle().getJFXStyle(), model.arcStyleProperty()));
}
 
Example #15
Source File: TestViewCircleArc.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
@ParameterizedTest
@MethodSource("getArcsToTest")
void testSetAngleEndMainBorder(final Function<ViewCircleArc, Arc> fct) {
	final Arc arc = fct.apply(view);
	final double length = arc.getLength();
	final double angle = model.getAngleEnd() + Math.PI / 4d;
	model.setAngleEnd(angle);
	WaitForAsyncUtils.waitForFxEvents();
	assertNotEquals(arc.getLength(), length);
	assertEquals(Math.toDegrees(model.getAngleEnd() - model.getAngleStart()), arc.getLength(), 0.0001);
}
 
Example #16
Source File: TestViewCircleArc.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
@Test
void testThicknessChangeRadius() {
	final Arc arc = cloneArc(view.border);
	model.setThickness(model.getThickness() * 2d);
	WaitForAsyncUtils.waitForFxEvents();
	assertNotEquals(arc.getRadiusX(), view.border.getRadiusX());
	assertNotEquals(arc.getRadiusY(), view.border.getRadiusY());
}
 
Example #17
Source File: ShapeConverter.java    From Enzo with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #18
Source File: TaskProgressIndicatorSkin.java    From archivo with GNU General Public License v3.0 5 votes vote down vote up
public DeterminateIndicator(ProgressIndicator control, Paint fillOverride) {

            getStyleClass().add("determinate-indicator");

            degProgress = (int) (360 * control.getProgress());

            getChildren().clear();

            // The circular background for the progress pie piece
            indicator = new StackPane();
            indicator.setScaleShape(false);
            indicator.setCenterShape(false);
            indicator.getStyleClass().setAll("indicator");
            indicatorCircle = new Circle();
            indicator.setShape(indicatorCircle);

            // The shape for our progress pie piece
            arcShape = new Arc();
            arcShape.setType(ArcType.ROUND);
            arcShape.setStartAngle(90.0F);

            // Our progress pie piece
            progress = new StackPane();
            progress.getStyleClass().setAll("progress");
            progress.setScaleShape(false);
            progress.setCenterShape(false);
            progress.setShape(arcShape);
            progress.getChildren().clear();
            setFillOverride(fillOverride);

            // The check mark that's drawn at 100%
            tick = new StackPane();
            tick.getStyleClass().setAll("tick");

            getChildren().setAll(indicator, progress, tick);
            updateProgress(control.getProgress());
        }
 
Example #19
Source File: Exercise_14_09.java    From Intro-to-Java-Programming with MIT License 5 votes vote down vote up
/** Add four arcs to a pane and place them in a stack pane */
private void getArcs(StackPane stackPane) {
	double angle = 30; // Start angle
	for (int i = 0; i < 4; i++) {
		Pane pane = new Pane();
		Arc arc = new Arc(100, 100, 80, 80, angle + 90, 35);
		arc.setFill(Color.BLACK);
		arc.setType(ArcType.ROUND);
		pane.getChildren().add(arc);
		stackPane.getChildren().add(pane);
		angle += 90;
	}
}
 
Example #20
Source File: FridayFunSkin.java    From WorkbenchFX with Apache License 2.0 5 votes vote down vote up
@Override
public void initializeParts() {
  double center = ARTBOARD_SIZE * 0.5;
  int width = 15;
  double radius = center - width;

  backgroundCircle = new Circle(center, center, radius);
  backgroundCircle.getStyleClass().add("backgroundCircle");

  bar = new Arc(center, center, radius, radius, 90.0, 0.0);
  bar.getStyleClass().add("bar");
  bar.setType(ArcType.OPEN);

  thumb = new Circle(center, center + center - width, 13);
  thumb.getStyleClass().add("thumb");

  valueDisplay = createCenteredText(center, center, "valueDisplay");

  ticks = createTicks(center, center, 60, 360.0, 6, 33, 0, "tick");

  tickLabels = new ArrayList<>();

  int labelCount = 8;
  for (int i = 0; i < labelCount; i++) {
    double r = 95;
    double nextAngle = i * 360.0 / labelCount;

    Point2D p = pointOnCircle(center, center, r, nextAngle);
    Text tickLabel = createCenteredText(p.getX(), p.getY(), "tickLabel");

    tickLabels.add(tickLabel);
  }
  updateTickLabels();

  drawingPane = new Pane();
  drawingPane.getStyleClass().add("numberRange");
  drawingPane.setMaxSize(ARTBOARD_SIZE, ARTBOARD_SIZE);
  drawingPane.setMinSize(ARTBOARD_SIZE, ARTBOARD_SIZE);
  drawingPane.setPrefSize(ARTBOARD_SIZE, ARTBOARD_SIZE);
}
 
Example #21
Source File: FanPane.java    From Intro-to-Java-Programming with MIT License 5 votes vote down vote up
/** Animate fan blades */
protected void spinFan() {
	ObservableList<Node> list = paneForBlades.getChildren();
	for (int i = 0; i < list.size(); i++) {
		Arc a = (Arc)list.get(i);
		a.setStartAngle(a.getStartAngle() + startAngle);
	}
}
 
Example #22
Source File: StateTransitionEdgeViewer.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean contains(Edge pEdge, Point pPoint)
{
	boolean result = super.contains(pEdge, pPoint);
	if (getShape(pEdge) instanceof Arc)
	{
		Arc arc = (Arc) getShape(pEdge);
		arc.setRadiusX(arc.getRadiusX() + 2 * MAX_DISTANCE);
		arc.setRadiusY(arc.getRadiusY() + 2 * MAX_DISTANCE);
		result = arc.contains(pPoint.getX(), pPoint.getY());
	}
	return result;
}
 
Example #23
Source File: TestViewCircleArc.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
@Test
void testTicknessChangeDbleSep() {
	final Arc arc = cloneArc(view.border);
	model.setHasDbleBord(true);
	model.setDbleBordSep(model.getDbleBordSep() * 2d);
	WaitForAsyncUtils.waitForFxEvents();
	assertNotEquals(arc.getRadiusX(), view.border.getRadiusX());
	assertNotEquals(arc.getRadiusY(), view.border.getRadiusY());
}
 
Example #24
Source File: TestViewCircleArc.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
@ParameterizedTest
@EnumSource(ArcStyle.class)
void testClipArrowSameStartEndNotEmptyClip(final ArcStyle style) {
	assumeTrue(style.supportArrow());
	model.setArcStyle(style);
	model.setAngleStart(0d);
	model.setAngleEnd(0d);
	model.setArrowLength(0d);
	model.setArrowStyle(ArrowStyle.RIGHT_ARROW, 0);
	model.setArrowStyle(ArrowStyle.RIGHT_DBLE_ARROW, -1);
	WaitForAsyncUtils.waitForFxEvents();
	final Arc clip = (Arc) view.border.getClip();
	assertNotEquals(clip.getLength(), 0d);
}
 
Example #25
Source File: Shape2Geometry.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns an {@link IGeometry} that describes the geometric outline of the
 * given {@link Shape}, i.e. excluding the stroke.
 * <p>
 * The conversion is supported for the following {@link Shape}s:
 * <ul>
 * <li>{@link Arc}
 * <li>{@link Circle}
 * <li>{@link CubicCurve}
 * <li>{@link Ellipse}
 * <li>{@link Line}
 * <li>{@link Path}
 * <li>{@link Polygon}
 * <li>{@link Polyline}
 * <li>{@link QuadCurve}
 * <li>{@link Rectangle}
 * </ul>
 * The following {@link Shape}s cannot be converted, yet:
 * <ul>
 * <li>{@link Text}
 * <li>{@link SVGPath}
 * </ul>
 *
 * @param visual
 *            The {@link Shape} for which an {@link IGeometry} is
 *            determined.
 * @return The newly created {@link IGeometry} that best describes the
 *         geometric outline of the given {@link Shape}.
 * @throws IllegalStateException
 *             if the given {@link Shape} is not supported.
 */
public static IGeometry toGeometry(Shape visual) {
	if (visual instanceof Arc) {
		return toArc((Arc) visual);
	} else if (visual instanceof Circle) {
		return toEllipse((Circle) visual);
	} else if (visual instanceof CubicCurve) {
		return toCubicCurve((CubicCurve) visual);
	} else if (visual instanceof Ellipse) {
		return toEllipse((Ellipse) visual);
	} else if (visual instanceof Line) {
		return toLine((Line) visual);
	} else if (visual instanceof Path) {
		return toPath((Path) visual);
	} else if (visual instanceof Polygon) {
		return toPolygon((Polygon) visual);
	} else if (visual instanceof Polyline) {
		return toPolyline((Polyline) visual);
	} else if (visual instanceof QuadCurve) {
		QuadCurve quad = (QuadCurve) visual;
		return toQuadraticCurve(quad);
	} else if (visual instanceof Rectangle) {
		Rectangle rect = (Rectangle) visual;
		if (rect.getArcWidth() == 0 && rect.getArcHeight() == 0) {
			// corners are not rounded => normal rectangle is sufficient
			return toRectangle(rect);
		}
		return toRoundedRectangle((Rectangle) visual);
	} else {
		// Text and SVGPath shapes are currently not supported
		throw new IllegalStateException(
				"Cannot compute geometric outline for Shape of type <"
						+ visual.getClass() + ">.");
	}
}
 
Example #26
Source File: Shape2Geometry.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Converts the given JavaFX {@link Arc} to a
 * {@link org.eclipse.gef.geometry.planar.Arc}.
 *
 * @param arc
 *            The JavaFX {@link Arc} to convert.
 * @return The newly created {@link org.eclipse.gef.geometry.planar.Arc}
 *         that describes the given {@link Arc}.
 */
public static org.eclipse.gef.geometry.planar.Arc toArc(Arc arc) {
	return new org.eclipse.gef.geometry.planar.Arc(
			arc.getCenterX() - arc.getRadiusX(),
			arc.getCenterY() - arc.getRadiusY(),
			arc.getRadiusX() + arc.getRadiusX(),
			arc.getRadiusY() + arc.getRadiusY(),
			Angle.fromDeg(arc.getStartAngle()),
			Angle.fromDeg(arc.getLength()));
}
 
Example #27
Source File: DotArrowShapeDecorations.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private static void setSide(Shape shape, String side) {
	if (shape instanceof Polygon) {
		setSide((Polygon) shape, side);
	} else if (shape instanceof Arc) {
		setSide((Arc) shape, side);
	}
}
 
Example #28
Source File: ButtonFXControlAdapterSnippet.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Scene createScene() {
	HBox hbox = new HBox();
	VBox col1 = new VBox();
	VBox col2 = new VBox();
	HBox.setMargin(col1, new Insets(10.0));
	HBox.setMargin(col2, new Insets(10.0));
	hbox.getChildren().addAll(col1, col2);
	HBox.setHgrow(col1, Priority.ALWAYS);
	HBox.setHgrow(col2, Priority.ALWAYS);

	col1.getChildren().addAll(new Button("JavaFX Button 1"),
			shape(new Arc(0, 0, 50, 50, 15, 120) {
				{
					setType(ArcType.ROUND);
				}
			}, 0.52, 0.49, 0.15), createButtonAdapter("SWT Button 1"));

	col2.getChildren().addAll(
			shape(new Rectangle(0, 0, 100, 50), 0.49, 0.36, 0.20),
			createButtonAdapter("SWT Button 2"),
			shape(new Rectangle(0, 0, 100, 100) {
				{
					setArcHeight(20);
					setArcWidth(20);
				}
			}, 0.87, 0.83, 0.49), new Button("JavaFX Button 2"));

	return new Scene(hbox, 400, 300);
}
 
Example #29
Source File: TestViewCircleArc.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
@ParameterizedTest
@MethodSource("styleFunction")
void testTypeArc(final ArcStyle style, final Function<ViewCircleArc, Arc> fct) {
	model.setArcStyle(style);
	WaitForAsyncUtils.waitForFxEvents();
	assertEquals(style.getJFXStyle(), fct.apply(view).getType());
}
 
Example #30
Source File: ViewArrow.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates the view.
 * @param model The arrow. Cannot be null.
 * @throws NullPointerException if the given arrow is null.
 */
ViewArrow(final Arrow model) {
	super();
	setId(ID);
	arrow = Objects.requireNonNull(model);
	path = new Path();
	ellipse = new Ellipse();
	arc = new Arc();
	getChildren().add(path);
	getChildren().add(ellipse);
	getChildren().add(arc);
	enableShape(false, false, false);
}