下面列出了javafx.scene.shape.Shape#setFill ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public LoadingCircle() {
Circle circle = new Circle(20);
circle.setFill(null);
circle.setStroke(Color.WHITE);
circle.setStrokeWidth(2);
Rectangle rect = new Rectangle(20, 20);
Shape shape = Shape.subtract(circle, rect);
shape.setFill(Color.WHITE);
getChildren().add(shape);
animation = new RotateTransition(Duration.seconds(2.5), this);
animation.setByAngle(-360);
animation.setInterpolator(Interpolator.LINEAR);
animation.setCycleCount(Animation.INDEFINITE);
animation.play();
}
public TriCircle() {
Shape shape1 = Shape.subtract(new Circle(5), new Circle(2));
shape1.setFill(Color.WHITE);
Shape shape2 = Shape.subtract(new Circle(5), new Circle(2));
shape2.setFill(Color.WHITE);
shape2.setTranslateX(5);
Shape shape3 = Shape.subtract(new Circle(5), new Circle(2));
shape3.setFill(Color.WHITE);
shape3.setTranslateX(2.5);
shape3.setTranslateY(-5);
getChildren().addAll(shape1, shape2, shape3);
setEffect(new GaussianBlur(2));
}
/**
* Returns the dot arrow shape decoration corresponding to the
* <i>arrowType</i> parameter.
*
* @param arrowType
* The arrow type for which the dot edge decoration should be
* determined.
*
* @param arrowSize
* The size of the arrow shape decoration.
*
* @param penwidth
* The (pen)width of the shape's drawn lines.
*
* @param color
* The color to use for the arrow shape decoration outline.
*
* @param fillColor
* The color to use for the arrow shape decoration background.
*
* @return The dot arrow shape decoration.
*/
static Node get(ArrowType arrowType, double arrowSize, Double penwidth,
String color, String fillColor) {
// The first arrow shape specified should occur closest to the node.
double offset = 0.0;
Group group = new Group();
for (AbstractArrowShape arrowShape : arrowType.getArrowShapes()) {
Shape currentShape = get(arrowShape, arrowSize, penwidth, color,
fillColor);
if (currentShape == null) {
// represent the "none" arrow shape with a transparent box with
// the corresponding size
currentShape = new Box(arrowSize);
currentShape.setFill(Color.TRANSPARENT);
currentShape.setTranslateX(offset);
} else {
if (currentShape instanceof Circle) {
// translate a circle-based shape specially because of its
// middle-point-based translation
currentShape.setTranslateX(offset
+ currentShape.getLayoutBounds().getWidth() / 2);
} else {
currentShape.setTranslateX(offset);
}
}
offset += NodeUtils.getShapeBounds(currentShape).getWidth()
- currentShape.getStrokeWidth();
group.getChildren().add(currentShape);
}
return group;
}
protected void applyShapeProperties(Shape p)
{
p.setFill(fill);
p.setStroke(strokeColor);
p.setStrokeDashOffset(dashOffset);
p.setStrokeLineCap(lineCap);
p.setStrokeLineJoin(lineJoin);
p.setStrokeMiterLimit(miterLimit);
p.setStrokeType(strokeType);
p.setStrokeWidth(strokeWidth);
}
private static void updateShapeAppearance( Shape shape, boolean selected ) {
if ( shape == null ) return;
shape.setFill(selected ? Color.LIGHTGREEN : Color.LIGHTBLUE);
shape.setStroke(Color.DARKGRAY);
shape.setStrokeWidth(2.5);
DropShadow shadow = new DropShadow();
shadow.setOffsetY(3.0);
shadow.setOffsetX(3.0);
shadow.setColor(Color.GRAY);
shape.setEffect(shadow);
}
private Shape makeGrid() {
Shape shape = new Rectangle((COLUMNS + 1) * TILE_SIZE, (ROWS + 1) * TILE_SIZE);
for (int y = 0; y < ROWS; y++) {
for (int x = 0; x < COLUMNS; x++) {
Circle circle = new Circle(TILE_SIZE / 2);
circle.setCenterX(TILE_SIZE / 2);
circle.setCenterY(TILE_SIZE / 2);
circle.setTranslateX(x * (TILE_SIZE + 5) + TILE_SIZE / 4);
circle.setTranslateY(y * (TILE_SIZE + 5) + TILE_SIZE / 4);
shape = Shape.subtract(shape, circle);
}
}
Light.Distant light = new Light.Distant();
light.setAzimuth(45.0);
light.setElevation(30.0);
Lighting lighting = new Lighting();
lighting.setLight(light);
lighting.setSurfaceScale(5.0);
shape.setFill(Color.BLUE);
shape.setEffect(lighting);
return shape;
}
private void createBackgroundTextures() {
final int tileSize = 600;
// TODO: remove this duplication
Group backgroundGroup = new Group();
Scene offScreenBackgroundScene = new Scene(backgroundGroup, tileSize, tileSize);
Shape emptySpace = new Rectangle(0, 0, tileSize, tileSize);
emptySpace.setFill(EnvironmentView.BACKGROUND_COLOR);
backgroundGroup.getChildren().add(emptySpace);
Group infraredBackgroundGroup = new Group();
Scene offScreenInfraredBackgroundScene = new Scene(infraredBackgroundGroup, tileSize, tileSize);
Shape infraredEmptySpace = new Rectangle(0, 0, tileSize, tileSize);
infraredEmptySpace.setFill(EnvironmentView.INFRARED_BACKGROUND_COLOR);
infraredBackgroundGroup.getChildren().add(infraredEmptySpace);
for (int i = 0; i < 5; i++) {
int x = getRandomCoordinate(tileSize);
int y = getRandomCoordinate(tileSize);
backgroundGroup.getChildren().add(createSpeckle(x, y, NORMAL_SPECKLE_RADIUS));
infraredBackgroundGroup.getChildren().add(createSpeckle(x, y, INFRARED_SPECKLE_RADIUS));
}
backgroundTexture = new WritableImage(tileSize, tileSize);
offScreenBackgroundScene.snapshot(backgroundTexture);
infraredBackgroundTexture = new WritableImage(tileSize, tileSize);
offScreenInfraredBackgroundScene.snapshot(infraredBackgroundTexture);
}
@Override
public void interpolate(Connection connection) {
// compute new curve (this can lead to another refreshGeometry() call
// which is not executed)
ICurve newGeometry = computeCurve(connection);
// XXX: we can only deal with geometry nodes so far
@SuppressWarnings("unchecked")
final GeometryNode<ICurve> curveNode = (GeometryNode<ICurve>) connection
.getCurve();
if (curveNode instanceof GeometryNode
&& !newGeometry.equals(curveNode.getGeometry())) {
// TODO: we need to prevent positions are re-calculated as a
// result of the changed geometry. -> the static anchors should not
// update their positions because of layout bounds changes.
// System.out.println("New geometry: " + newGeometry);
curveNode.setGeometry(newGeometry);
}
Node startDecoration = connection.getStartDecoration();
if (startDecoration != null) {
arrangeStartDecoration(startDecoration, newGeometry,
newGeometry.getP1());
}
Node endDecoration = connection.getEndDecoration();
if (endDecoration != null) {
arrangeEndDecoration(endDecoration, newGeometry,
newGeometry.getP2());
}
if (!newGeometry.getBounds().isEmpty()
&& (startDecoration != null || endDecoration != null)) {
// XXX Use scene coordinates, as the clip node does not provide a
// parent.
// union curve node's children's bounds-in-parent
org.eclipse.gef.geometry.planar.Rectangle unionBoundsInCurveNode = new org.eclipse.gef.geometry.planar.Rectangle();
ObservableList<Node> childrenUnmodifiable = curveNode
.getChildrenUnmodifiable();
for (Node child : childrenUnmodifiable) {
Bounds boundsInParent = child.getBoundsInParent();
org.eclipse.gef.geometry.planar.Rectangle rectangle = FX2Geometry
.toRectangle(boundsInParent);
unionBoundsInCurveNode.union(rectangle);
}
// convert unioned bounds to scene coordinates
Bounds visualBounds = curveNode.localToScene(
Geometry2FX.toFXBounds(unionBoundsInCurveNode));
// create clip
Shape clip = new Rectangle(visualBounds.getMinX(),
visualBounds.getMinY(), visualBounds.getWidth(),
visualBounds.getHeight());
clip.setFill(Color.RED);
// can only clip Shape decorations
if (startDecoration != null && startDecoration instanceof Shape) {
clip = clipAtDecoration(curveNode.getGeometricShape(), clip,
(Shape) startDecoration);
}
// can only clip Shape decorations
if (endDecoration != null && endDecoration instanceof Shape) {
clip = clipAtDecoration(curveNode.getGeometricShape(), clip,
(Shape) endDecoration);
}
// XXX: All CAG operations deliver result shapes that reflect areas
// in scene coordinates.
AffineTransform sceneToLocalTx = NodeUtils
.getSceneToLocalTx(curveNode);
clip.getTransforms().add(Geometry2FX.toFXAffine(sceneToLocalTx));
// set clip
curveNode.setClip(clip);
} else {
curveNode.setClip(null);
}
}
private void addFill(Shape organShape, boolean infraredOn, double alpha) {
if (infraredOn)
organShape.setFill(new Color(1, 0, 0, alpha));
else
organShape.setFill(new Color(baseColor.getRed(), baseColor.getGreen(), baseColor.getBlue(), alpha));
}
private Shape createSpeckle(int x, int y, double radius) {
Shape result = new Circle(radius);
result.setFill(SPECKLE_COLOR);
result.getTransforms().add(new Translate(x, y));
return result;
}