Java Code Examples for javafx.scene.paint.Color#getOpacity()

The following examples show how to use javafx.scene.paint.Color#getOpacity() . 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: Helper.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
public static final List<Color> createColorPalette(final Color FROM_COLOR, final Color TO_COLOR, final int NO_OF_COLORS) {
    int    steps        = clamp(1, 12, NO_OF_COLORS) - 1;
    double step         = 1.0 / steps;
    double deltaRed     = (TO_COLOR.getRed()     - FROM_COLOR.getRed())     * step;
    double deltaGreen   = (TO_COLOR.getGreen()   - FROM_COLOR.getGreen())   * step;
    double deltaBlue    = (TO_COLOR.getBlue()    - FROM_COLOR.getBlue())    * step;
    double deltaOpacity = (TO_COLOR.getOpacity() - FROM_COLOR.getOpacity()) * step;

    List<Color> palette      = new ArrayList<>(NO_OF_COLORS);
    Color       currentColor = FROM_COLOR;
    palette.add(currentColor);
    for (int i = 0 ; i < steps ; i++) {
        double red     = clamp(0d, 1d, (currentColor.getRed()     + deltaRed));
        double green   = clamp(0d, 1d, (currentColor.getGreen()   + deltaGreen));
        double blue    = clamp(0d, 1d, (currentColor.getBlue()    + deltaBlue));
        double opacity = clamp(0d, 1d, (currentColor.getOpacity() + deltaOpacity));
        currentColor   = Color.color(red, green, blue, opacity);
        palette.add(currentColor);
    }
    return palette;
}
 
Example 2
Source File: Helper.java    From OEE-Designer with MIT License 6 votes vote down vote up
public static final List<Color> createColorPalette(final Color FROM_COLOR, final Color TO_COLOR,
		final int NO_OF_COLORS) {
	int steps = clamp(1, 12, NO_OF_COLORS) - 1;
	double step = 1.0 / steps;
	double deltaRed = (TO_COLOR.getRed() - FROM_COLOR.getRed()) * step;
	double deltaGreen = (TO_COLOR.getGreen() - FROM_COLOR.getGreen()) * step;
	double deltaBlue = (TO_COLOR.getBlue() - FROM_COLOR.getBlue()) * step;
	double deltaOpacity = (TO_COLOR.getOpacity() - FROM_COLOR.getOpacity()) * step;

	List<Color> palette = new ArrayList<>(NO_OF_COLORS);
	Color currentColor = FROM_COLOR;
	palette.add(currentColor);
	for (int i = 0; i < steps; i++) {
		double red = clamp(0d, 1d, (currentColor.getRed() + deltaRed));
		double green = clamp(0d, 1d, (currentColor.getGreen() + deltaGreen));
		double blue = clamp(0d, 1d, (currentColor.getBlue() + deltaBlue));
		double opacity = clamp(0d, 1d, (currentColor.getOpacity() + deltaOpacity));
		currentColor = Color.color(red, green, blue, opacity);
		palette.add(currentColor);
	}
	return palette;
}
 
Example 3
Source File: Helper.java    From charts with Apache License 2.0 6 votes vote down vote up
public static final List<Color> createColorPalette(final Color FROM_COLOR, final Color TO_COLOR, final int NO_OF_COLORS) {
    int    steps        = clamp(1, 50, NO_OF_COLORS) - 1;
    double step         = 1.0 / steps;
    double deltaRed     = (TO_COLOR.getRed()     - FROM_COLOR.getRed())     * step;
    double deltaGreen   = (TO_COLOR.getGreen()   - FROM_COLOR.getGreen())   * step;
    double deltaBlue    = (TO_COLOR.getBlue()    - FROM_COLOR.getBlue())    * step;
    double deltaOpacity = (TO_COLOR.getOpacity() - FROM_COLOR.getOpacity()) * step;

    List<Color> palette      = new ArrayList<>(NO_OF_COLORS);
    Color       currentColor = FROM_COLOR;
    palette.add(currentColor);
    for (int i = 0 ; i < steps ; i++) {
        double red     = clamp(0d, 1d, (currentColor.getRed()     + deltaRed));
        double green   = clamp(0d, 1d, (currentColor.getGreen()   + deltaGreen));
        double blue    = clamp(0d, 1d, (currentColor.getBlue()    + deltaBlue));
        double opacity = clamp(0d, 1d, (currentColor.getOpacity() + deltaOpacity));
        currentColor   = Color.color(red, green, blue, opacity);
        palette.add(currentColor);
    }
    return palette;
}
 
Example 4
Source File: HeatMap.java    From charts with Apache License 2.0 6 votes vote down vote up
/**
 * Recreates the heatmap based on the current monochrome map.
 * Using this approach makes it easy to change the used color
 * mapping.
 */
private void updateHeatMap() {
    monochrome.snapshot(SNAPSHOT_PARAMETERS, monochromeImage);

    int width  = monochromeImage.widthProperty().intValue();
    int height = monochromeImage.heightProperty().intValue();
    heatMap    = new WritableImage(width, height);

    Color       colorFromMonoChromeImage;
    double      brightness;
    Color       mappedColor;
    PixelWriter pixelWriter = heatMap.getPixelWriter();
    PixelReader pixelReader = monochromeImage.getPixelReader();
    for (int y = 0 ; y < height ; y++) {
        for (int x = 0 ; x < width ; x++) {
            colorFromMonoChromeImage = pixelReader.getColor(x, y);
            brightness               = colorFromMonoChromeImage.getOpacity();
            mappedColor              = Helper.getColorAt(mappingGradient, brightness);
            pixelWriter.setColor(x, y, fadeColors ? Color.color(mappedColor.getRed(), mappedColor.getGreen(), mappedColor.getBlue(), brightness) : mappedColor);
        }
    }
    setImage(heatMap);
}
 
Example 5
Source File: JavaFXUtil.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public static java.awt.Color convertColorToAWT(Color col) {
  int r = (int) (col.getRed() * 255);
  int g = (int) (col.getGreen() * 255);
  int b = (int) (col.getBlue() * 255);
  int a = (int) (col.getOpacity() * 255);

  return new java.awt.Color(r, g, b, a);
}
 
Example 6
Source File: FxColorUtil.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public static java.awt.Color fxColorToAWT(final Color color) {
  final int r = (int) (color.getRed() * 255d);
  final int g = (int) (color.getGreen() * 255d);
  final int b = (int) (color.getBlue() * 255d);
  final int opacity = (int) (color.getOpacity() * 255d);
  return new java.awt.Color(r, g, b, opacity);
}
 
Example 7
Source File: UiUtils.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a color from {@link Color} to {@link ColorRGBA}.
 *
 * @param color the color
 * @return the jme color
 */
@FxThread
public static @Nullable ColorRGBA from(@Nullable final Color color) {
    if (color == null) return null;
    return new ColorRGBA((float) color.getRed(), (float) color.getGreen(),
            (float) color.getBlue(), (float) color.getOpacity());
}
 
Example 8
Source File: Helper.java    From charts with Apache License 2.0 5 votes vote down vote up
public static final Color interpolateColor(final Color COLOR1, final Color COLOR2, final double FRACTION, final double TARGET_OPACITY) {
    double fraction       = clamp(0, 1, FRACTION);
    double targetOpacity  = TARGET_OPACITY < 0 ? TARGET_OPACITY : clamp(0, 1, FRACTION);

    final double RED1     = COLOR1.getRed();
    final double GREEN1   = COLOR1.getGreen();
    final double BLUE1    = COLOR1.getBlue();
    final double OPACITY1 = COLOR1.getOpacity();

    final double RED2     = COLOR2.getRed();
    final double GREEN2   = COLOR2.getGreen();
    final double BLUE2    = COLOR2.getBlue();
    final double OPACITY2 = COLOR2.getOpacity();

    final double DELTA_RED     = RED2 - RED1;
    final double DELTA_GREEN   = GREEN2 - GREEN1;
    final double DELTA_BLUE    = BLUE2 - BLUE1;
    final double DELTA_OPACITY = OPACITY2 - OPACITY1;

    double red     = RED1 + (DELTA_RED * fraction);
    double green   = GREEN1 + (DELTA_GREEN * fraction);
    double blue    = BLUE1 + (DELTA_BLUE * fraction);
    double opacity = targetOpacity < 0 ? OPACITY1 + (DELTA_OPACITY * fraction) : targetOpacity;

    red     = clamp(0, 1, red);
    green   = clamp(0, 1, green);
    blue    = clamp(0, 1, blue);
    opacity = clamp(0, 1, opacity);

    return Color.color(red, green, blue, opacity);
}
 
Example 9
Source File: JFXUtil.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** Convert JFX color into model color
 *  @param color {@link Color}
 *  @return {@link WidgetColor}
 */
public static WidgetColor convert(final Color color)
{
    return new WidgetColor((int) (color.getRed() * 255),
                           (int) (color.getGreen() * 255),
                           (int) (color.getBlue() * 255),
                           (int) (color.getOpacity() * 255));
}
 
Example 10
Source File: FxmlColor.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static int compareColor(Color o1, Color o2) {
    double diff = o2.getHue() - o1.getHue();
    if (diff > 0) {
        return 1;
    } else if (diff < 0) {
        return -1;
    } else {
        diff = o2.getSaturation() - o1.getSaturation();
        if (diff > 0) {
            return 1;
        } else if (diff < 0) {
            return -1;
        } else {
            diff = o2.getBrightness() - o1.getBrightness();
            if (diff > 0) {
                return 1;
            } else if (diff < 0) {
                return -1;
            } else {
                diff = o2.getOpacity() - o1.getOpacity();
                if (diff > 0) {
                    return 1;
                } else if (diff < 0) {
                    return -1;
                } else {
                    return 0;
                }
            }
        }
    }
}
 
Example 11
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static java.awt.Color toAwtColor(Color color) {
    java.awt.Color newColor = new java.awt.Color((int) (color.getRed() * 255),
            (int) (color.getGreen() * 255),
            (int) (color.getBlue() * 255),
            (int) (color.getOpacity() * 255));
    return newColor;
}
 
Example 12
Source File: Crosshair.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void drawOverlays(final GraphicsContext g)
{

	final Color color = this.color.get();
	if (color != null && color.getOpacity() > 0 && isVisible.get())
	{
		g.setStroke(color);
		g.setLineWidth(strokeWidth);
		g.strokeLine(0, h / 2, w, h / 2);
		g.strokeLine(w / 2, 0, w / 2, h);
	}

}
 
Example 13
Source File: SerializableColor.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
public SerializableColor(Color color) {
    if (color != null) {
        r = color.getRed();
        g = color.getGreen();
        b = color.getBlue();
        a = color.getOpacity();
    }
}
 
Example 14
Source File: ThemeStage.java    From oim-fx with MIT License 5 votes vote down vote up
public void setColor(Color color) {
	double opacity = color.getOpacity();
	opacity = opacity * 100D;
	slider.setValue(opacity);
	colorPicker.setValue(color);
	super.setBackgroundColor(color);
}
 
Example 15
Source File: FxmlColor.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static String rgb2css(Color color) {
    return "rgba(" + (int) (color.getRed() * 255) + ","
            + (int) (color.getGreen() * 255) + ","
            + (int) (color.getBlue() * 255) + ","
            + color.getOpacity() + ")";
}
 
Example 16
Source File: ColorArrayValueEditor.java    From arma-dialog-creator with MIT License 4 votes vote down vote up
public ArrayEditorPopup(@Nullable Color initialColor) {
	VBox root = new VBox(5);
	root.setPadding(new Insets(10));
	getContent().add(root);

	root.setStyle("-fx-background-color:-fx-background");
	root.setBorder(new Border(
					new BorderStroke(Color.GRAY, BorderStrokeStyle.SOLID,
							CornerRadii.EMPTY, BorderStroke.THIN
					)
			)
	);

	Canvas canvas = new Canvas(128, 32);
	StackPane stackPaneCanvas = new StackPane(canvas);
	stackPaneCanvas.setBorder(root.getBorder());
	stackPaneCanvas.setMaxWidth(canvas.getWidth());
	stackPaneCanvas.setAlignment(Pos.CENTER_LEFT);

	HBox paneHeader = new HBox(5, stackPaneCanvas, tfAsArray);
	root.getChildren().add(paneHeader);
	HBox.setHgrow(tfAsArray, Priority.ALWAYS);

	tfAsArray.setEditable(false);

	GraphicsContext gc = canvas.getGraphicsContext2D();


	ValueListener<Double> valListener = (observer, oldValue, newValue) -> {
		Color c = getCurrentColor();
		if (c != null) {

			if (c.getOpacity() < 1) {
				//draw a grid to show theres transparency
				gc.setGlobalAlpha(1);
				gc.setFill(Color.WHITE);
				Region.paintCheckerboard(
						gc, 0, 0, (int) canvas.getWidth(), (int) canvas.getHeight(), Color.GRAY, Color.WHITE,
						5);
			}

			gc.setGlobalAlpha(c.getOpacity());
			gc.setFill(c);
			gc.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());

			tfAsArray.setText(SVColor.toStringF(c.getRed(), c.getGreen(), c.getBlue(), c.getOpacity()));
		}
	};
	r.getValueObserver().addListener(valListener);
	g.getValueObserver().addListener(valListener);
	b.getValueObserver().addListener(valListener);
	a.getValueObserver().addListener(valListener);

	if (initialColor != null) {
		r.getValueObserver().updateValue(getRounded(initialColor.getRed()));
		g.getValueObserver().updateValue(getRounded(initialColor.getGreen()));
		b.getValueObserver().updateValue(getRounded(initialColor.getBlue()));
		a.getValueObserver().updateValue(getRounded(initialColor.getOpacity()));
	}


	//r
	root.getChildren().add(getColorEditor("r", r));
	//g
	root.getChildren().add(getColorEditor("g", g));
	//b
	root.getChildren().add(getColorEditor("b", b));
	//a
	root.getChildren().add(getColorEditor("a", a));

	//footer
	root.getChildren().add(new Separator(Orientation.HORIZONTAL));
	GenericResponseFooter footer = new GenericResponseFooter(true, true, false,
			null,
			cancelEvent -> {
				cancelled = true;
				ArrayEditorPopup.this.hide();
			},
			okEvent -> {
				if (!hasInvalid()) {
					return;
				}
				cancelled = false;
				ArrayEditorPopup.this.hide();
			}
	);
	ResourceBundle bundle = Lang.ApplicationBundle();
	footer.getBtnOk().setText(bundle.getString("ValueEditors.ColorArrayEditor.use"));
	root.getChildren().add(footer);

	setAutoHide(true);

	setHideOnEscape(true); //when push esc key, hide it

	valListener.valueUpdated(r.getValueObserver(), null, null);
}
 
Example 17
Source File: SVColorArray.java    From arma-dialog-creator with MIT License 4 votes vote down vote up
/** Set the color from a JavaFX Color instance */
public SVColorArray(@NotNull Color newValue) {
	this(newValue.getRed(), newValue.getGreen(), newValue.getBlue(), newValue.getOpacity());
}
 
Example 18
Source File: SVColorInt.java    From arma-dialog-creator with MIT License 4 votes vote down vote up
/** Set the color from a JavaFX Color instance */
public SVColorInt(@NotNull Color newValue) {
	this(newValue.getRed(), newValue.getGreen(), newValue.getBlue(), newValue.getOpacity());
}
 
Example 19
Source File: SVColorIntArray.java    From arma-dialog-creator with MIT License 4 votes vote down vote up
/** Set the color from a JavaFX Color instance */
public SVColorIntArray(@NotNull Color newValue) {
	this(newValue.getRed(), newValue.getGreen(), newValue.getBlue(), newValue.getOpacity());
}
 
Example 20
Source File: ColorGradientAxis.java    From chart-fx with Apache License 2.0 2 votes vote down vote up
/**
 * Return the color for a value as an integer with the color values in its bytes. For use e.g. with an IntBuffer
 * backed PixelBuffer.
 * 
 * @param value z-Value
 * @return integer with one byte each set to alpha, red, green, blue
 */
public int getIntColor(final double value) {
    final Color color = getColor(value);
    return ((byte) (color.getOpacity() * 255) << 24) + ((byte) (color.getRed() * 255) << 16)
            + ((byte) (color.getGreen() * 255) << 8) + ((byte) (color.getBlue() * 255));
}