javafx.scene.paint.LinearGradient Java Examples

The following examples show how to use javafx.scene.paint.LinearGradient. 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: ModernSkin.java    From Medusa with Apache License 2.0 6 votes vote down vote up
public void handleMouseEvent(final MouseEvent EVENT) {
    if (gauge.isDisabled()) return;
    final EventType TYPE = EVENT.getEventType();
    if (MouseEvent.MOUSE_PRESSED.equals(TYPE)) {
        gauge.fireEvent(gauge.BTN_PRESSED_EVENT);
        centerKnob.setFill(new LinearGradient(0.5 * size, 0.2708333333333333 * size,
                                              0.5 * size, 0.7291666666666666 * size,
                                              false, CycleMethod.NO_CYCLE,
                                              new Stop(0.0, Color.rgb(31, 31, 31)),
                                              new Stop(1.0, Color.rgb(69, 70, 73))));
        valueText.setTranslateY(size * 0.501);
        subTitleText.setTranslateY(size * 0.3525);
        unitText.setTranslateY(size * 0.6675);
    } else if (MouseEvent.MOUSE_RELEASED.equals(TYPE)) {
        gauge.fireEvent(gauge.BTN_RELEASED_EVENT);
        centerKnob.setFill(new LinearGradient(0.5 * size, 0.2708333333333333 * size,
                                              0.5 * size, 0.7291666666666666 * size,
                                              false, CycleMethod.NO_CYCLE,
                                              new Stop(0.0, Color.rgb(69, 70, 73)),
                                              new Stop(1.0, Color.rgb(31, 31, 31))));
        valueText.setTranslateY(size * 0.5);
        subTitleText.setTranslateY(size * 0.35);
        unitText.setTranslateY(size * 0.67);
    }
}
 
Example #2
Source File: SparkLineTileSkin.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
private void setupGradient() {
    double loFactor = (low - minValue) / tile.getRange();
    double hiFactor = (high - minValue) / tile.getRange();
    Stop   loStop   = new Stop(loFactor, gradientLookup.getColorAt(loFactor));
    Stop   hiStop   = new Stop(hiFactor, gradientLookup.getColorAt(hiFactor));

    List<Stop> stopsInBetween = gradientLookup.getStopsBetween(loFactor, hiFactor);

    double     range  = hiFactor - loFactor;
    double     factor = 1.0 / range;
    List<Stop> stops  = new ArrayList<>();
    stops.add(new Stop(0, loStop.getColor()));
    for (Stop stop : stopsInBetween) {
        stops.add(new Stop((stop.getOffset() - loFactor) * factor, stop.getColor()));
    }
    stops.add(new Stop(1, hiStop.getColor()));

    gradient = new LinearGradient(0, graphBounds.getY() + graphBounds.getHeight(), 0, graphBounds.getY(), false, CycleMethod.NO_CYCLE, stops);
}
 
Example #3
Source File: GaugeSparkLineTileSkin.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
private void setupGradient() {
    double loFactor = (low - minValue) / tile.getRange();
    double hiFactor = (high - minValue) / tile.getRange();
    Stop   loStop   = new Stop(loFactor, gradientLookup.getColorAt(loFactor));
    Stop   hiStop   = new Stop(hiFactor, gradientLookup.getColorAt(hiFactor));

    List<Stop> stopsInBetween = gradientLookup.getStopsBetween(loFactor, hiFactor);

    double     range  = hiFactor - loFactor;
    double     factor = 1.0 / range;
    List<Stop> stops  = new ArrayList<>();
    stops.add(new Stop(0, loStop.getColor()));
    for (Stop stop : stopsInBetween) {
        stops.add(new Stop((stop.getOffset() - loFactor) * factor, stop.getColor()));
    }
    stops.add(new Stop(1, hiStop.getColor()));

    gradient = new LinearGradient(0, graphBounds.getY() + graphBounds.getHeight(), 0, graphBounds.getY(), false, CycleMethod.NO_CYCLE, stops);
}
 
Example #4
Source File: ThermoDemo.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
Thermo(Color color)
{
    setFill(color);

    fill.setArcHeight(3);
    fill.setArcWidth(3);
    fill.setManaged(false);
    border.setFill(new LinearGradient(.3, 0, .7, 0, true, CycleMethod.NO_CYCLE,
                                    new Stop(0, Color.LIGHTGRAY),
                                    new Stop(.3, Color.WHITESMOKE),
                                    new Stop(1, Color.LIGHTGRAY)));
    border.setStroke(Color.BLACK);
    arc.setLargeArcFlag(true);

    getChildren().add(border);
    getChildren().add(fill);
    getChildren().add(ellipse);
    setBorder(new Border(
            new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT)));
}
 
Example #5
Source File: SectionSkin.java    From Medusa with Apache License 2.0 6 votes vote down vote up
private void createNeedle() {
    double needleWidth  = size * 0.04;
    double needleHeight = size * 0.4675;
    needle.getElements().clear();
    needle.getElements().add(new MoveTo(0.3125 * needleWidth, 0.015957446808510637 * needleHeight));
    needle.getElements().add(new CubicCurveTo(0.3125 * needleWidth, 0.005319148936170213 * needleHeight,
                                              0.4375 * needleWidth, 0.0,
                                              0.5 * needleWidth, 0.0));
    needle.getElements().add(new CubicCurveTo(0.5625 * needleWidth, 0.0,
                                              0.6875 * needleWidth, 0.005319148936170213 * needleHeight,
                                              0.6875 * needleWidth, 0.015957446808510637 * needleHeight));
    needle.getElements().add(new CubicCurveTo(0.6875 * needleWidth, 0.015957446808510637 * needleHeight,
                                              needleWidth, 0.9946808510638298 * needleHeight,
                                              needleWidth, 0.9946808510638298 * needleHeight));
    needle.getElements().add(new LineTo(0.0, 0.9946808510638298 * needleHeight));
    needle.getElements().add(new CubicCurveTo(0.0, 0.9946808510638298 * needleHeight,
                                              0.3125 * needleWidth, 0.015957446808510637 * needleHeight,
                                              0.3125 * needleWidth, 0.015957446808510637 * needleHeight));
    needle.getElements().add(new ClosePath());
    needle.setFill(new LinearGradient(needle.getLayoutBounds().getMinX(), 0,
                                      needle.getLayoutBounds().getMaxX(), 0,
                                      false, CycleMethod.NO_CYCLE,
                                      new Stop(0.0, gauge.getNeedleColor().darker()),
                                      new Stop(0.5, gauge.getNeedleColor()),
                                      new Stop(1.0, gauge.getNeedleColor().darker())));
}
 
Example #6
Source File: SectionSkin.java    From Medusa with Apache License 2.0 6 votes vote down vote up
@Override protected void redraw() {
    sectionsVisible = gauge.getSectionsVisible();
    drawSections();
    needle.setFill(new LinearGradient(needle.getLayoutBounds().getMinX(), 0,
                                      needle.getLayoutBounds().getMaxX(), 0,
                                      false, CycleMethod.NO_CYCLE,
                                      new Stop(0.0, gauge.getNeedleColor().darker()),
                                      new Stop(0.5, gauge.getNeedleColor()),
                                      new Stop(1.0, gauge.getNeedleColor().darker())));
    titleText.setFill(gauge.getTitleColor());
    valueText.setFill(gauge.getValueColor());
    mask.setFill(gauge.getBackgroundPaint());
    knob.setFill(gauge.getKnobColor());
    titleText.setText(gauge.getTitle());
    resizeText();
}
 
Example #7
Source File: Overlay1Controller.java    From examples-javafx-repos1 with Apache License 2.0 6 votes vote down vote up
private void createTopHighlightBorder() {
    Stop[] stops = new Stop[] {
            new Stop(0, Color.WHITE),
            new Stop(.3, Color.LIGHTGRAY),
            new Stop(1, Color.TRANSPARENT)
    };
    LinearGradient lg1 = new LinearGradient(0, 0, 0, 1, true, CycleMethod.NO_CYCLE, stops);

    topHighlightBorder =
            new Border(new BorderStroke(
                    lg1, null, null, null,
                    BorderStrokeStyle.SOLID, BorderStrokeStyle.NONE, BorderStrokeStyle.NONE, BorderStrokeStyle.NONE,
                    CornerRadii.EMPTY,
                    new BorderWidths( 8.0d ),
                    null
            ));
}
 
Example #8
Source File: ThermometerRepresentation.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
Thermo(Color color)
{
    setFill(color);

    fill.setArcHeight(6);
    fill.setArcWidth(6);
    fill.setManaged(false);
    border.setFill(new LinearGradient(.3, 0, .7, 0, true, CycleMethod.NO_CYCLE,
            new Stop(0, Color.LIGHTGRAY),
            new Stop(.3, Color.WHITESMOKE),
            new Stop(1, Color.LIGHTGRAY)));
    border.setStroke(Color.BLACK);
    arc.setLargeArcFlag(true);
    rightcorner.setY(0);

    getChildren().add(border);
    getChildren().add(fill);
    getChildren().add(ellipse);
    setBorder(new Border(
            new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT)));
}
 
Example #9
Source File: ScatterChartPane.java    From constellation with Apache License 2.0 6 votes vote down vote up
public ScatterChartPane(final ScatterPlotPane parent) {
    this.scatterPlot = parent;

    final LinearGradient gradient = new LinearGradient(0.0, 0.0, 0.0, 0.75, true, CycleMethod.NO_CYCLE,
            new Stop[]{new Stop(0, Color.LIGHTGRAY), new Stop(1, Color.GRAY.darker())});
    this.selection = new Rectangle(0, 0, 0, 0);
    selection.setFill(Color.WHITE);
    selection.setStroke(Color.BLACK);
    selection.setOpacity(0.4);
    selection.setMouseTransparent(true);
    selection.setStroke(Color.SILVER);
    selection.setStrokeWidth(2d);
    selection.setFill(gradient);
    selection.setSmooth(true);
    selection.setArcWidth(5.0);
    selection.setArcHeight(5.0);

    this.tooltip = new Tooltip();

    this.currentData = Collections.synchronizedSet(new HashSet<>());
    this.currentSelectedData = new HashSet<>();

    this.getChildren().addAll(selection);
    this.setId("scatter-chart-pane");
    this.setPadding(new Insets(5));
}
 
Example #10
Source File: ConversationBubble.java    From constellation with Apache License 2.0 6 votes vote down vote up
public final void setColor(final Color color) {
    Color bottomColor = color.darker();
    Color topColor = color.brighter();

    Stop[] stops = new Stop[]{
        new Stop(0, topColor),
        new Stop(1, bottomColor)
    };
    LinearGradient gradient = new LinearGradient(0, 0, 0, 1, true, CycleMethod.NO_CYCLE, stops);

    bubbleGraphic.setStroke(color);
    bubbleGraphic.setFill(gradient);

    tail.setFill(bottomColor);
    tail.setStroke(color);
    tailTop.setStroke(bottomColor); // Erase the border of the buble where the tail joins
}
 
Example #11
Source File: FXSimpleLinearGradientPicker.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Changes the currently selected gradient to the given value.
 *
 * @param simpleLinearGradient
 *            The new simple {@link LinearGradient} to select.
 */
public void setSimpleLinearGradient(LinearGradient simpleLinearGradient) {
	if (!isSimpleLinearGradient(simpleLinearGradient)) {
		throw new IllegalArgumentException("Given value '"
				+ simpleLinearGradient + "' is no simple linear gradient");
	}

	this.simpleLinearGradient.set(simpleLinearGradient);
	// a simple linear gradient contains two stops
	List<Stop> stops = simpleLinearGradient.getStops();
	if (!color1Picker.getColor().equals(stops.get(0).getColor())) {
		color1Picker.setColor(stops.get(0).getColor());
	}
	if (!color2Picker.getColor().equals(stops.get(1).getColor())) {
		color2Picker.setColor(stops.get(1).getColor());
	}
}
 
Example #12
Source File: BaseLEDRepresentation.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private Paint computeEditColors()
{
    final Color[] save_colors = colors;
    final List<Stop> stops = new ArrayList<>(2 * save_colors.length);
    final double offset = 1.0 / save_colors.length;

    for (int i = 0; i < save_colors.length; ++i)
    {
        stops.add(new Stop(i * offset, save_colors[i]));
        stops.add(new Stop((i + 1) * offset, save_colors[i]));
    }

    return new LinearGradient(0, 0, 1, 1, true, CycleMethod.NO_CYCLE, stops);
}
 
Example #13
Source File: RadialPercentageTileSkin.java    From OEE-Designer with MIT License 5 votes vote down vote up
@Override protected void redraw() {
    super.redraw();
    locale           = tile.getLocale();
    formatString     = new StringBuilder("%.").append(Integer.toString(tile.getDecimals())).append("f").toString();
    sectionsVisible  = tile.getSectionsVisible();

    barBackground.setStroke(tile.getBarBackgroundColor());

    LinearGradient gradient = new LinearGradient(0, 0, 1, 1, true, CycleMethod.NO_CYCLE, tile.getGradientStops());

    bar.setStroke(tile.isFillWithGradient() ? gradient : tile.getBarColor());
    proportionBar.setStroke(tile.isFillWithGradient() ? gradient : tile.getBarColor());
    percentageValueText.setFill(tile.getValueColor());
    percentageUnitText.setFill(tile.getUnitColor());
    descriptionText.setFill(tile.getDescriptionColor());
    unitText.setFill(tile.getUnitColor());
    titleText.setFill(tile.getTitleColor());
    text.setFill(tile.getTextColor());
    separator.setStroke(tile.getBackgroundColor());

    titleText.setText(tile.getTitle());
    descriptionText.setText(tile.getDescription());
    text.setText(tile.getText());
    unitText.setText(tile.getUnit());

    referenceValue = tile.getReferenceValue() < maxValue ? maxValue : tile.getReferenceValue();

    resizeStaticText();
    resizeDynamicText();
}
 
Example #14
Source File: ThermometerRepresentation.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
public void setFill(Color color)
{
    ellipse.setFill(
            new RadialGradient(0, 0, 0.3, 0.1, 0.4, true, CycleMethod.NO_CYCLE,
                    new Stop(0, color.interpolate(Color.WHITESMOKE, 0.8)),
                    new Stop(1, color)));
    fill.setFill(new LinearGradient(0, 0, .8, 0, true, CycleMethod.NO_CYCLE,
            new Stop(0, color),
            new Stop(.3, color.interpolate(Color.WHITESMOKE, 0.7)),
            new Stop(1, color)));
}
 
Example #15
Source File: TestViewBorderedShape.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
@Test
void testFillGradientMidPt() {
	assumeTrue(model.isFillable());
	model.setFillingStyle(FillingStyle.GRAD);
	WaitForAsyncUtils.waitForFxEvents();
	final LinearGradient grad1 = (LinearGradient) border.getFill();
	model.setGradMidPt(0.6352);
	WaitForAsyncUtils.waitForFxEvents();
	assertNotEquals(grad1, border.getFill());
}
 
Example #16
Source File: SmoothAreaChartTileSkin.java    From OEE-Designer with MIT License 5 votes vote down vote up
@Override protected void redraw() {
    super.redraw();

    smoothing = tile.isSmoothing();

    titleText.setText(tile.getTitle());

    valueText.setText(String.format(locale, formatString, tile.getCurrentValue()));
    unitText.setText(tile.getUnit());

    resizeDynamicText();
    resizeStaticText();

    titleText.setFill(tile.getTitleColor());
    valueText.setFill(tile.getValueColor());
    unitText.setFill(tile.getUnitColor());
    selector.setStroke(tile.getForegroundColor());
    selector.setFill(tile.getBackgroundColor());
    Color fillPathColor1 = Helper.getColorWithOpacity(tile.getBarColor(), 0.7);
    Color fillPathColor2 = Helper.getColorWithOpacity(tile.getBarColor(), 0.1);
    if (tile.isFillWithGradient() && !tile.getGradientStops().isEmpty()) {
        fillPath.setFill(new LinearGradient(0, 0, 0, 1, true, CycleMethod.NO_CYCLE, tile.getGradientStops()));
        strokePath.setStroke(tile.getGradientStops().get(0).getColor());
        if (dataPointsVisible) { drawDataPoints(points, tile.getGradientStops().get(0).getColor()); }
    } else {
        fillPath.setFill(new LinearGradient(0, 0, 0, 1, true, CycleMethod.NO_CYCLE, new Stop(0, fillPathColor1), new Stop(1, fillPathColor2)));
        strokePath.setStroke(tile.getBarColor());
        if (dataPointsVisible) { drawDataPoints(points, tile.getBarColor()); }
    }
    drawChart(points);
}
 
Example #17
Source File: ThermoDemo.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
public void setFill(Color color)
{
    ellipse.setFill(
            new RadialGradient(0, 0, 0.3, 0.1, 0.4, true, CycleMethod.NO_CYCLE,
                    new Stop(0, color.interpolate(Color.WHITESMOKE, 0.8)),
                    new Stop(1, color)));
    fill.setFill(new LinearGradient(0, 0, .8, 0, true, CycleMethod.NO_CYCLE,
                    new Stop(0, color),
                    new Stop(.3, color.interpolate(Color.WHITESMOKE, 0.7)),
                    new Stop(1, color)));
}
 
Example #18
Source File: TestViewBorderedShape.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
@Test
void testFillGradientColor1() {
	assumeTrue(model.isFillable());
	model.setFillingStyle(FillingStyle.GRAD);
	model.setGradColStart(DviPsColors.DANDELION);
	WaitForAsyncUtils.waitForFxEvents();
	final LinearGradient grad = (LinearGradient) border.getFill();
	assertEquals(DviPsColors.DANDELION.toJFX(), grad.getStops().get(0).getColor());
}
 
Example #19
Source File: Helper.java    From charts with Apache License 2.0 5 votes vote down vote up
public static final LinearGradient createColorVariationGradient(final Color COLOR, final int NO_OF_COLORS) {
    List<Color> colorVariations = createColorVariations(COLOR, NO_OF_COLORS);
    List<Stop>  stops = new ArrayList<>(NO_OF_COLORS);
    double step = 1.0 / NO_OF_COLORS;
    for (int i = 0 ; i < NO_OF_COLORS ; i++) {
        stops.add(new Stop(i * step, colorVariations.get(i)));
    }
    return new LinearGradient(0, 0, 1, 0, true, CycleMethod.NO_CYCLE, stops);
}
 
Example #20
Source File: BoolButtonRepresentation.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private Paint computeEditColors()
{
    final Color[] save_colors = state_colors;
    return new LinearGradient(0, 0, 1, 1, true, CycleMethod.NO_CYCLE,
        List.of(new Stop(0.0, save_colors[0]),
                new Stop(0.5, save_colors[0]),
                new Stop(0.5, save_colors[1]),
                new Stop(1.0, save_colors[1])));
}
 
Example #21
Source File: RadialPercentageTileSkin.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
@Override protected void redraw() {
    super.redraw();
    locale           = tile.getLocale();
    formatString     = new StringBuilder("%.").append(Integer.toString(tile.getDecimals())).append("f").toString();
    sectionsVisible  = tile.getSectionsVisible();

    barBackground.setStroke(tile.getBarBackgroundColor());

    LinearGradient gradient = new LinearGradient(0, 0, 1, 1, true, CycleMethod.NO_CYCLE, tile.getGradientStops());

    bar.setStroke(tile.isFillWithGradient() ? gradient : tile.getBarColor());
    proportionBar.setStroke(tile.isFillWithGradient() ? gradient : tile.getBarColor());
    percentageValueText.setFill(tile.getValueColor());
    percentageUnitText.setFill(tile.getUnitColor());
    descriptionText.setFill(tile.getDescriptionColor());
    unitText.setFill(tile.getUnitColor());
    titleText.setFill(tile.getTitleColor());
    text.setFill(tile.getTextColor());
    separator.setStroke(tile.getBackgroundColor());

    titleText.setText(tile.getTitle());
    descriptionText.setText(tile.getDescription());
    text.setText(tile.getText());
    unitText.setText(tile.getUnit());

    referenceValue = tile.getReferenceValue() < maxValue ? maxValue : tile.getReferenceValue();

    resizeStaticText();
    resizeDynamicText();
}
 
Example #22
Source File: OverviewPanel.java    From constellation with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method that creates and styles a POV object.
 *
 * The POV object is a styled rectangle that is used to indicate the
 * currently observed time range (aka time extent) on the timeline. It can
 * also be used to quickly interact with the time extent.
 *
 * @return A formatted POV object.
 */
private Rectangle createPOV() {
    final Rectangle rect = new Rectangle(135, 25, 60, 1);

    // Bind the height of the POV to the Height of the histogram:
    rect.yProperty().bind(histogram.heightProperty());
    rect.heightProperty().bind(innerPane.prefHeightProperty());
    rect.setManaged(true);

    // Style the rectangle:
    rect.setStroke(Color.DODGERBLUE);
    rect.setStrokeWidth(2d);
    final LinearGradient gradient
            = new LinearGradient(0.0, 0.0, 0.0, 0.5, true, CycleMethod.NO_CYCLE, new Stop[]{
        new Stop(0, Color.LIGHTBLUE.darker()),
        new Stop(1, Color.TRANSPARENT)
    });
    rect.setFill(gradient);
    rect.setSmooth(true);

    // Round the edges of the rectangle:
    rect.setArcWidth(5.0);
    rect.setArcHeight(5.0);

    // Set the POV mouse event handlers:
    final POVMouseEventHandler handler = new POVMouseEventHandler(rect);
    rect.setOnMouseMoved(handler);
    rect.setOnMousePressed(handler);
    rect.setOnMouseDragged(handler);
    rect.setOnMouseReleased(handler);

    // Make the POV object the top-most object on this panel:
    rect.toFront();

    return rect;
}
 
Example #23
Source File: FuelGauge.java    From medusademo with Apache License 2.0 5 votes vote down vote up
@Override public void init() {
    fuelIcon = new Region();
    fuelIcon.getStyleClass().setAll("fuel-icon");

    gauge = GaugeBuilder.create()
                        .skinType(SkinType.HORIZONTAL)
                        .prefSize(500, 250)
                        .knobColor(Color.rgb(0, 0, 0))
                        .foregroundBaseColor(Color.rgb(249, 249, 249))
                        .animated(true)
                        .shadowsEnabled(true)
                        .valueVisible(false)
                        //.title("FUEL")
                        .needleColor(Color.web("0xEF2F06"))
                        //.needleColor(Color.rgb(255, 10, 1))
                        .needleShape(NeedleShape.ROUND)
                        .needleSize(NeedleSize.THICK)
                        .minorTickMarksVisible(false)
                        .mediumTickMarksVisible(false)
                        //.majorTickMarkType(TickMarkType.TRIANGLE)
                        .sectionsVisible(true)
                        .sections(new Section(0, 0.2, Color.rgb(255, 10, 1)))
                        .minValue(0)
                        .maxValue(1)
                        .angleRange(90)
                        .customTickLabelsEnabled(true)
                        .customTickLabels("E", "", "", "", "", "1/2", "", "", "", "", "F")
                        .build();

    pane = new StackPane(fuelIcon, gauge);
    pane.setPadding(new Insets(10));
    LinearGradient gradient = new LinearGradient(0, 0, 0, pane.getLayoutBounds().getHeight(),
                                                 false, CycleMethod.NO_CYCLE,
                                                 new Stop(0.0, Color.rgb(38, 38, 38)),
                                                 new Stop(1.0, Color.rgb(15, 15, 15)));
    pane.setBackground(new Background(new BackgroundFill(gradient, CornerRadii.EMPTY, Insets.EMPTY)));
}
 
Example #24
Source File: SVGIcon.java    From ikonli with Apache License 2.0 5 votes vote down vote up
private static Paint resolvePaintValue(String iconCode, String value) {
    try { return Color.valueOf(value); } catch (IllegalArgumentException e1) {
        try { return LinearGradient.valueOf(value); } catch (IllegalArgumentException e2) {
            try { return RadialGradient.valueOf(value); } catch (IllegalArgumentException e3) {
                throw invalidDescription(iconCode, e3);
            }
        }
    }
}
 
Example #25
Source File: FontIcon.java    From ikonli with Apache License 2.0 5 votes vote down vote up
private static Paint resolvePaintValue(String iconCode, String value) {
    try { return Color.valueOf(value); } catch (IllegalArgumentException e1) {
        try { return LinearGradient.valueOf(value); } catch (IllegalArgumentException e2) {
            try { return RadialGradient.valueOf(value); } catch (IllegalArgumentException e3) {
                throw invalidDescription(iconCode, e3);
            }
        }
    }
}
 
Example #26
Source File: TestViewBorderedShape.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
@Test
void testFillGradient() {
	assumeTrue(model.isFillable());
	model.setFillingStyle(FillingStyle.GRAD);
	WaitForAsyncUtils.waitForFxEvents();
	assertTrue(border.getFill() instanceof LinearGradient);
}
 
Example #27
Source File: NodePart.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates the shape used to display the node's border and background.
 *
 * @return The newly created {@link Shape}.
 */
private Node createDefaultShape() {
	GeometryNode<?> shape = new GeometryNode<>(new org.eclipse.gef.geometry.planar.Rectangle());
	shape.setUserData(DEFAULT_SHAPE_ROLE);
	shape.getStyleClass().add(CSS_CLASS_SHAPE);
	shape.setFill(new LinearGradient(0, 0, 1, 1, true, CycleMethod.REFLECT,
			Arrays.asList(new Stop(0, new Color(1, 1, 1, 1)))));
	shape.setStroke(new Color(0, 0, 0, 1));
	shape.setStrokeType(StrokeType.INSIDE);
	return shape;
}
 
Example #28
Source File: ViewSingleShape.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
private LinearGradient computeGradient() {
	final Point tl = model.getTopLeftPoint();
	final Point br = model.getBottomRightPoint();

	if(tl.equals(br)) {
		return null;
	}

	double angle = model.getGradAngle() % (2d * Math.PI);
	double gradMidPt = model.getGradMidPt();

	if(angle < 0d) {
		angle = 2d * Math.PI + angle;
	}

	if(angle >= Math.PI) {
		gradMidPt = 1d - gradMidPt;
		angle -= Math.PI;
	}

	if(!MathUtils.INST.equalsDouble(angle, 0d)) {
		return computeRotatedGradient(angle, gradMidPt, tl, br);
	}

	final Point pt1 = ShapeFactory.INST.createPoint((tl.getX() + br.getX()) / 2d, tl.getY());
	final Point pt2 = ShapeFactory.INST.createPoint((tl.getX() + br.getX()) / 2d, br.getY());

	if(gradMidPt < 0.5) {
		pt1.setY(pt2.getY() - Point2D.distance(pt2.getX(), pt2.getY(), (tl.getX() + br.getX()) / 2d, br.getY()));
	}

	pt2.setY(tl.getY() + (br.getY() - tl.getY()) * gradMidPt);

	return new LinearGradient(pt1.getX(), pt1.getY(), pt2.getX(), pt2.getY(), false, CycleMethod.NO_CYCLE,
		new Stop(0d, model.getGradColStart().toJFX()), new Stop(1d, model.getGradColEnd().toJFX()));
}
 
Example #29
Source File: QualityGauge.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
private void updateValue() {
    double value = model.getValue();
    if (value == 0) {
        currentQuality.setFill(Color.TRANSPARENT);
        currentQuality.setStroke(Color.TRANSPARENT);
        currentQualityText.setFill(Color.TRANSPARENT);
        currentQualityText.setText("");
        knob.setFill(Color.web("#cccccc"));
    } else {
        currentQualityRotate.setAngle(279 + ((int) value) * sectionAngle - sectionAngle);
        double radius      = width * 0.45;
        double sinValue    = Math.sin(Math.toRadians(currentQualityRotate.getAngle() + (-sectionAngle * ((int) value + 0.5) + model.getStartAngle() + 270 + sectionAngle)));
        double cosValue    = Math.cos(Math.toRadians(currentQualityRotate.getAngle() + (-sectionAngle * ((int) value + 0.5) + model.getStartAngle() + 270 + sectionAngle)));
        Color sectionColor = model.getSections().get((int) value - 1).getColor().deriveColor(0, 2.5, 1, 1);
        LinearGradient currentQualityFill = new LinearGradient(centerX + radius * sinValue,
                                                               centerY + radius * cosValue,
                                                               centerX, centerY,
                                                               false, CycleMethod.NO_CYCLE,
                                                               new Stop(0.0, sectionColor),
                                                               new Stop(0.22, sectionColor),
                                                               new Stop(0.22, sectionColor.deriveColor(0, 0.7, 1.1, 1)),
                                                               new Stop(1.0, sectionColor.deriveColor(0, 0.7, 1.1, 1)));

        currentQuality.setFill(currentQualityFill);
        currentQuality.setStroke(Color.WHITE);

        sinValue = Math.sin(Math.toRadians(-sectionAngle * ((int) value + 0.5) + model.getStartAngle() + 270 + sectionAngle));
        cosValue = Math.cos(Math.toRadians(-sectionAngle * ((int) value + 0.5) + model.getStartAngle() + 270 + sectionAngle));
        currentQualityText.setFont(Fonts.latoBold(height * 0.14860681));
        currentQualityText.setText(model.getSections().get((int) value - 1).getText());
        currentQualityText.setFill(Color.WHITE);
        currentQualityText.setX(centerX - (currentQualityText.getLayoutBounds().getWidth() * 0.55) + radius * sinValue);
        currentQualityText.setY(centerY + radius * cosValue);

        knob.setFill(sectionColor);
    }
}
 
Example #30
Source File: FXPaintSelectionDialog.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates a {@link Composite} that contains the advanced gradient picker.
 *
 * @param parent
 *            The parent {@link Composite}.
 * @return The {@link Composite} that contains the advanced gradient picker.
 */
protected Control createAdvancedGradientFillControl(Composite parent) {
	advancedGradientPicker = new FXAdvancedLinearGradientPicker(parent, Color.WHITE, Color.GREY, Color.BLACK);
	advancedGradientPicker.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	advancedGradientPicker.advancedLinearGradientProperty().addListener(new ChangeListener<LinearGradient>() {

		@Override
		public void changed(ObservableValue<? extends LinearGradient> observable, LinearGradient oldValue,
				LinearGradient newValue) {
			setPaint(newValue);
		}
	});
	return advancedGradientPicker;
}