javafx.scene.paint.Paint Java Examples

The following examples show how to use javafx.scene.paint.Paint. 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: FXPaintUtils.java    From gef with Eclipse Public License 2.0 7 votes vote down vote up
/**
 * Creates a rectangular {@link Image} to visualize the given {@link Paint}.
 *
 * @param width
 *            The width of the resulting {@link Image}.
 * @param height
 *            The height of the resulting {@link Image}.
 * @param paint
 *            The {@link Paint} to use for filling the {@link Image}.
 * @return The resulting (filled) {@link Image}.
 */
public static ImageData getPaintImageData(int width, int height, Paint paint) {
	// use JavaFX canvas to render a rectangle with the given paint
	Canvas canvas = new Canvas(width, height);
	GraphicsContext graphicsContext = canvas.getGraphicsContext2D();
	graphicsContext.setFill(paint);
	graphicsContext.fillRect(0, 0, width, height);
	graphicsContext.setStroke(Color.BLACK);
	graphicsContext.strokeRect(0, 0, width, height);
	// handle transparent color separately (we want to differentiate it from
	// transparent fill)
	if (paint instanceof Color && ((Color) paint).getOpacity() == 0) {
		// draw a red line from bottom-left to top-right to indicate a
		// transparent fill color
		graphicsContext.setStroke(Color.RED);
		graphicsContext.strokeLine(0, height - 1, width, 1);
	}
	WritableImage snapshot = canvas.snapshot(new SnapshotParameters(), null);
	return SWTFXUtils.fromFXImage(snapshot, null);
}
 
Example #2
Source File: SVGIcon.java    From ikonli with Apache License 2.0 6 votes vote down vote up
@Override
public ObjectProperty<Paint> iconColorProperty() {
    if (iconColor == null) {
        iconColor = new StyleableObjectProperty<Paint>(Color.BLACK) {
            @Override
            public CssMetaData getCssMetaData() {
                return StyleableProperties.ICON_COLOR;
            }

            @Override
            public Object getBean() {
                return SVGIcon.this;
            }

            @Override
            public String getName() {
                return "iconColor";
            }
        };
        iconColor.addListener(iconColorChangeListener);
    }
    return iconColor;
}
 
Example #3
Source File: StateTransitionEdgeViewer.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
private void drawLabel(StateTransitionEdge pEdge, GraphicsContext pGraphics)
{
	adjustLabelFont(pEdge);
	Rectangle2D labelBounds = getLabelBounds(pEdge);
	double x = labelBounds.getMinX();
	double y = labelBounds.getMinY();
	
	Paint oldFill = pGraphics.getFill();
	Font oldFont = pGraphics.getFont();
	pGraphics.translate(x, y);
	pGraphics.setFill(Color.BLACK);
	pGraphics.setFont(aFont);
	pGraphics.setTextAlign(TextAlignment.CENTER);
	pGraphics.fillText(pEdge.getMiddleLabel(), labelBounds.getWidth()/2, 0);
	pGraphics.setFill(oldFill);
	pGraphics.setFont(oldFont);
	pGraphics.translate(-x, -y);        
}
 
Example #4
Source File: IconToggleButton.java    From oim-fx with MIT License 6 votes vote down vote up
public IconToggleButton(String text, Font font, Paint paint, Image normalImage, Image hoverImage, Image selectedImage) {
	this(text);
	this.normalImage = normalImage;
	this.hoverImage = hoverImage;
	this.selectedImage = selectedImage;
	if (null != font) {
		this.setFont(font);
	}
	if (null != paint) {
		this.setTextFill(paint);
	}
	initEvent();
	updateImage();
	VBox redVBox=new VBox();
	redVBox.setAlignment(Pos.TOP_RIGHT);
	redVBox.getChildren().add(redImageView);
	
	stackPane.getChildren().add(imageView);
	stackPane.getChildren().add(redVBox);
	
	this.getStyleClass().add(DEFAULT_STYLE_CLASS);
}
 
Example #5
Source File: FontIcon.java    From ikonli with Apache License 2.0 6 votes vote down vote up
@Override
public ObjectProperty<Paint> iconColorProperty() {
    if (iconColor == null) {
        iconColor = new StyleableObjectProperty<>(Color.BLACK) {
            @Override
            public CssMetaData getCssMetaData() {
                return StyleableProperties.ICON_COLOR;
            }

            @Override
            public Object getBean() {
                return FontIcon.this;
            }

            @Override
            public String getName() {
                return "iconColor";
            }
        };
        iconColor.addListener((v, o, n) -> FontIcon.this.setFill(n));
    }
    return iconColor;
}
 
Example #6
Source File: DemoUtil.java    From RadialFx with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void addColorControl(final String title,
    final ObjectProperty<Paint> paintProperty) {
final ColorPicker colorPicker = ColorPickerBuilder.create()
	.value((Color) paintProperty.get()).build();

paintProperty.bind(colorPicker.valueProperty());
final VBox box = new VBox();
final Text titleText = new Text(title);

titleText.textProperty().bind(new StringBinding() {
    {
	super.bind(colorPicker.valueProperty());
    }

    @Override
    protected String computeValue() {
	return title + " : " + colorPicker.getValue().toString();
    }

});
box.getChildren().addAll(titleText, colorPicker);
getChildren().add(box);
   }
 
Example #7
Source File: FXUtilities.java    From megan-ce with GNU General Public License v3.0 5 votes vote down vote up
/**
 * changes opacity, if paint is a color
 *
 * @param paint
 * @param opacity
 * @return paint
 */
public static Paint changeOpacity(Paint paint, double opacity) {
    if (paint instanceof Color) {
        Color color = (Color) paint;
        return new Color(color.getRed(), color.getGreen(), color.getBlue(), opacity);
    } else
        return paint;
}
 
Example #8
Source File: DashPatternStyle.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
private static ImagePattern createDefaultHatch(final Paint color, final double strokeWidth,
        final boolean isHorizontal, final double[] pattern) {
    final Integer hash = computeHash(color, strokeWidth, isHorizontal, pattern);

    return DashPatternStyle.dashHashMap.computeIfAbsent(hash, t -> {
        // need to recompute hatch pattern image
        final double dashPatternLength = getPatternLength(pattern);
        final double width = isHorizontal ? dashPatternLength : strokeWidth;
        final double height = isHorizontal ? strokeWidth : dashPatternLength;
        final double middle = (int) (strokeWidth / 2.0);

        final Pane pane = new Pane();
        pane.setPrefSize(width, height);
        final Line fw = isHorizontal ? new Line(0, middle, dashPatternLength, middle)
                : new Line(middle, 0, middle, dashPatternLength);

        fw.setSmooth(false);
        fw.setStroke(color);
        if (pattern == null) {
            fw.getStrokeDashArray().setAll(dashPatternLength);
        } else {
            fw.getStrokeDashArray().setAll(DoubleStream.of(pattern).boxed().collect(Collectors.toList()));
        }
        fw.setStrokeWidth(strokeWidth);

        pane.getChildren().addAll(fw);
        pane.setStyle("-fx-background-color: rgba(0, 0, 0, 0.0)");
        final Scene scene = new Scene(pane);
        scene.setFill(Color.TRANSPARENT);

        final Image hatch = pane.snapshot(null, null);

        return new ImagePattern(hatch, width, 0, width, height, false);

    });
}
 
Example #9
Source File: SimpleGauge.java    From Enzo with Apache License 2.0 5 votes vote down vote up
public final ObjectProperty<Paint> sectionFill2Property() {
    if (null == sectionFill2) {
        sectionFill2 = new StyleableObjectProperty<Paint>(DEFAULT_SECTION_FILL_2) {
            @Override public CssMetaData getCssMetaData() { return StyleableProperties.SECTION_FILL_2; }
            @Override public Object getBean() { return this; }
            @Override public String getName() { return "sectionFill2"; }
        };
    }
    return sectionFill2;
}
 
Example #10
Source File: Hexagon.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
public void drawContour(GraphicsContext gc) {
    gc.save();
    gc.setStroke(getStroke());
    gc.setLineWidth(getStrokeWidth());
    gc.setFill(getFill());
    if (map == null) {
        drawHexagon(gc, Direction.values());
        gc.restore();
    }

    final List<Direction> list = new ArrayList<>();
    for (final Direction direction : Direction.values()) {
        final Hexagon neighbour = getNeighbour(direction);
        if (neighbour == null) {
            continue;
        }
        final Paint stroke = neighbour.getStroke();
        // if (stroke != null && !stroke.equals(this.getStroke())) {
        // list.add(direction);
        // }

        // TODO: find work-around for colour smoothing operation on image scaling
        if (stroke != null && !myColourCompare(stroke, getStroke(), 0.2)) {
            list.add(direction);
        }
    }

    drawHexagon(gc, list.toArray(new Direction[list.size()]));

    gc.restore();
}
 
Example #11
Source File: SimpleGauge.java    From Enzo with Apache License 2.0 5 votes vote down vote up
public final ObjectProperty<Paint> titleTextColorProperty() {
    if (null == titleTextColor) {
        titleTextColor = new StyleableObjectProperty<Paint>(DEFAULT_TITLE_TEXT_COLOR) {
            @Override public CssMetaData getCssMetaData() { return StyleableProperties.TITLE_TEXT_COLOR; }
            @Override public Object getBean() { return this; }
            @Override public String getName() { return "titleTextColor"; }
        };
    }
    return titleTextColor;
}
 
Example #12
Source File: Grid.java    From charts with Apache License 2.0 5 votes vote down vote up
public ObjectProperty<Paint> majorVGridLinePaintProperty() {
    if (null == majorVGridLinePaint) {
        majorVGridLinePaint = new ObjectPropertyBase<Paint>(_majorVGridLinePaint) {
            @Override protected void invalidated() { drawGrid(); }
            @Override public Object getBean() { return Grid.this; }
            @Override public String getName() { return "majorVGridLinePaint"; }
        };
        _majorVGridLinePaint = null;
    }
    return majorVGridLinePaint;
}
 
Example #13
Source File: XYZPane.java    From charts with Apache License 2.0 5 votes vote down vote up
public void setChartBackground(final Paint PAINT) {
    if (null == chartBackground) {
        _chartBackground = PAINT;
        redraw();
    } else {
        chartBackground.set(PAINT);
    }
}
 
Example #14
Source File: StaticProgressIndicatorSkin.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
IndeterminateSpinner(TxConfidenceIndicator control, StaticProgressIndicatorSkin s,
                     boolean spinEnabled, Paint fillOverride) {
    this.control = control;
    this.skin = s;
    this.fillOverride = fillOverride;

    setNodeOrientation(NodeOrientation.LEFT_TO_RIGHT);
    getStyleClass().setAll("spinner");

    pathsG = new IndicatorPaths(this);
    getChildren().add(pathsG);

    rebuild();
}
 
Example #15
Source File: Clock.java    From Medusa with Apache License 2.0 5 votes vote down vote up
/**
 * Defines the Paint object that will be used to fill the foreground of the clock.
 * This could be used to visualize glass effects etc. and is only rarely used.
 * @param PAINT
 */
public void setForegroundPaint(final Paint PAINT) {
    if (null == foregroundPaint) {
        _foregroundPaint = PAINT;
        fireUpdateEvent(REDRAW_EVENT);
    } else {
        foregroundPaint.set(PAINT);
    }
}
 
Example #16
Source File: JavaFXCompatibility.java    From RichTextFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Java 8:  javafx.scene.text.Text.impl_selectionFillProperty()
 * Java 9+: javafx.scene.text.Text.selectionFillProperty()
 */
@SuppressWarnings("unchecked")
static ObjectProperty<Paint> Text_selectionFillProperty(Text text) {
    try {
        if (mText_selectionFillProperty == null) {
            mText_selectionFillProperty = Text.class.getMethod(
                    isJava9orLater ? "selectionFillProperty" : "impl_selectionFillProperty");
        }
        return (ObjectProperty<Paint>) mText_selectionFillProperty.invoke(text);
    } catch(NoSuchMethodException | SecurityException | IllegalAccessException |
            IllegalArgumentException | InvocationTargetException e) {
        e.printStackTrace();
        throw new Error(e);
    }
}
 
Example #17
Source File: TilesFXSeries.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
public TilesFXSeries(final Series<X, Y> SERIES, final Paint COLOR) {
    series = SERIES;
    stroke = COLOR;
    fill   = COLOR;
    if (null != COLOR) {
        symbolBackground = new Background(new BackgroundFill(COLOR, new CornerRadii(5), Insets.EMPTY), new BackgroundFill(Color.WHITE, new CornerRadii(5), new Insets(2)));
        legendSymbolFill = COLOR;
    }
}
 
Example #18
Source File: Clock.java    From Medusa with Apache License 2.0 5 votes vote down vote up
public ObjectProperty<Paint> borderPaintProperty() {
    if (null == borderPaint) {
        borderPaint  = new ObjectPropertyBase<Paint>(_borderPaint) {
            @Override protected void invalidated() { fireUpdateEvent(REDRAW_EVENT); }
            @Override public Object getBean() { return Clock.this; }
            @Override public String getName() { return "borderPaint"; }
        };
        _borderPaint = null;
    }
    return borderPaint;
}
 
Example #19
Source File: DotGraphView.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private void addGraphBackground(Paint paint) {
	double margin = 5;
	GraphPart graphPart = (GraphPart) getContentViewer().getRootPart()
			.getContentPartChildren().get(0);
	Group group = graphPart.getVisual();
	Bounds bounds = group.getLayoutBounds();
	group.setEffect(new Blend(BlendMode.SRC_OVER,
			new ColorInput(bounds.getMinX() - margin,
					bounds.getMinY() - margin,
					bounds.getWidth() + 2 * margin,
					bounds.getHeight() + 2 * margin, paint),
			null));
}
 
Example #20
Source File: GridBuilder.java    From charts with Apache License 2.0 4 votes vote down vote up
public final B minorHGridLinePaint(final Paint PAINT) {
    properties.put("minorHGridLinePaint", new SimpleObjectProperty<>(PAINT));
    return (B)this;
}
 
Example #21
Source File: SimpleGauge.java    From Enzo with Apache License 2.0 4 votes vote down vote up
@Override public Paint getInitialValue(SimpleGauge gauge) {
    return gauge.getSectionFill1();
}
 
Example #22
Source File: JFXCheckBox.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
@Override
public StyleableProperty<Paint> getStyleableProperty(JFXCheckBox control) {
    return control.checkedColorProperty();
}
 
Example #23
Source File: RadialMenuItem.java    From RadialFx with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ObjectProperty<Paint> strokeFillProperty() {
return strokeFill;
   }
 
Example #24
Source File: SimpleGauge.java    From Enzo with Apache License 2.0 4 votes vote down vote up
public final void setSectionFill1(Paint value) {
    sectionFill1Property().set(value);
}
 
Example #25
Source File: Gauge.java    From Enzo with Apache License 2.0 4 votes vote down vote up
public final void setSectionFill8(Paint value) {
    sectionFill8Property().set(value);
}
 
Example #26
Source File: StackedFontIcon.java    From ikonli with Apache License 2.0 4 votes vote down vote up
public Paint getIconColor() {
    return iconColorProperty().get();
}
 
Example #27
Source File: SimpleGauge.java    From Enzo with Apache License 2.0 4 votes vote down vote up
public final void setSectionFill3(Paint value) {
    sectionFill3Property().set(value);
}
 
Example #28
Source File: GeometricShape.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
public ObjectProperty<Paint> fillProperty() {
	return fillProperty;
}
 
Example #29
Source File: JFXButton.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
/**
 * @return the ripple color
 */
public final Paint getRipplerFill() {
    return this.ripplerFillProperty().get();
}
 
Example #30
Source File: Gauge.java    From Enzo with Apache License 2.0 4 votes vote down vote up
public final Paint getMarkerFill1() {
    return null == markerFill1 ? DEFAULT_MARKER_FILL_1 : markerFill1.get();
}