下面列出了javafx.scene.shape.Rectangle#getArcHeight ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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() + ">.");
}
}
public static String convertRectangle(final Rectangle RECTANGLE) {
final StringBuilder fxPath = new StringBuilder();
final Bounds bounds = RECTANGLE.getBoundsInLocal();
if (Double.compare(RECTANGLE.getArcWidth(), 0.0) == 0 && Double.compare(RECTANGLE.getArcHeight(), 0.0) == 0) {
fxPath.append("M ").append(bounds.getMinX()).append(" ").append(bounds.getMinY()).append(" ")
.append("H ").append(bounds.getMaxX()).append(" ")
.append("V ").append(bounds.getMaxY()).append(" ")
.append("H ").append(bounds.getMinX()).append(" ")
.append("V ").append(bounds.getMinY()).append(" ")
.append("Z");
} else {
double x = bounds.getMinX();
double y = bounds.getMinY();
double width = bounds.getWidth();
double height = bounds.getHeight();
double arcWidth = RECTANGLE.getArcWidth();
double arcHeight = RECTANGLE.getArcHeight();
double r = x + width;
double b = y + height;
fxPath.append("M ").append(x + arcWidth).append(" ").append(y).append(" ")
.append("L ").append(r - arcWidth).append(" ").append(y).append(" ")
.append("Q ").append(r).append(" ").append(y).append(" ").append(r).append(" ").append(y + arcHeight).append(" ")
.append("L ").append(r).append(" ").append(y + height - arcHeight).append(" ")
.append("Q ").append(r).append(" ").append(b).append(" ").append(r - arcWidth).append(" ").append(b).append(" ")
.append("L ").append(x + arcWidth).append(" ").append(b).append(" ")
.append("Q ").append(x).append(" ").append(b).append(" ").append(x).append(" ").append(b - arcHeight).append(" ")
.append("L ").append(x).append(" ").append(y + arcHeight).append(" ")
.append("Q ").append(x).append(" ").append(y).append(" ").append(x + arcWidth).append(" ").append(y).append(" ")
.append("Z");
}
return fxPath.toString();
}
/**
* Converts the given JavaFX {@link Rectangle} to a
* {@link org.eclipse.gef.geometry.planar.RoundedRectangle}.
*
* @param rect
* The JavaFX {@link Rectangle} to convert.
* @return The newly created
* {@link org.eclipse.gef.geometry.planar.RoundedRectangle} that
* describes the given {@link Rectangle}.
*/
public static org.eclipse.gef.geometry.planar.RoundedRectangle toRoundedRectangle(
Rectangle rect) {
return new org.eclipse.gef.geometry.planar.RoundedRectangle(
rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight(),
rect.getArcWidth(), rect.getArcHeight());
}