javafx.scene.paint.Color#getOpacity ( )源码实例Demo

下面列出了javafx.scene.paint.Color#getOpacity ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: OEE-Designer   文件: Helper.java
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;
}
 
源代码2 项目: charts   文件: HeatMap.java
/**
 * 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);
}
 
源代码3 项目: charts   文件: Helper.java
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;
}
 
源代码4 项目: tilesfx   文件: Helper.java
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;
}
 
源代码5 项目: mzmine3   文件: FxColorUtil.java
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);
}
 
源代码6 项目: oim-fx   文件: ThemeStage.java
public void setColor(Color color) {
	double opacity = color.getOpacity();
	opacity = opacity * 100D;
	slider.setValue(opacity);
	colorPicker.setValue(color);
	super.setBackgroundColor(color);
}
 
源代码7 项目: Quelea   文件: SerializableColor.java
public SerializableColor(Color color) {
    if (color != null) {
        r = color.getRed();
        g = color.getGreen();
        b = color.getBlue();
        a = color.getOpacity();
    }
}
 
源代码8 项目: paintera   文件: Crosshair.java
@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);
	}

}
 
源代码9 项目: MyBox   文件: FxmlImageManufacture.java
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;
}
 
源代码10 项目: MyBox   文件: FxmlColor.java
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;
                }
            }
        }
    }
}
 
源代码11 项目: phoebus   文件: JFXUtil.java
/** 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));
}
 
源代码12 项目: charts   文件: Helper.java
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);
}
 
源代码13 项目: jmonkeybuilder   文件: UiUtils.java
/**
 * 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());
}
 
源代码14 项目: old-mzmine3   文件: JavaFXUtil.java
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);
}
 
源代码15 项目: MyBox   文件: FxmlColor.java
public static String rgb2css(Color color) {
    return "rgba(" + (int) (color.getRed() * 255) + ","
            + (int) (color.getGreen() * 255) + ","
            + (int) (color.getBlue() * 255) + ","
            + color.getOpacity() + ")";
}
 
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);
}
 
源代码17 项目: arma-dialog-creator   文件: SVColorArray.java
/** Set the color from a JavaFX Color instance */
public SVColorArray(@NotNull Color newValue) {
	this(newValue.getRed(), newValue.getGreen(), newValue.getBlue(), newValue.getOpacity());
}
 
源代码18 项目: arma-dialog-creator   文件: SVColorInt.java
/** Set the color from a JavaFX Color instance */
public SVColorInt(@NotNull Color newValue) {
	this(newValue.getRed(), newValue.getGreen(), newValue.getBlue(), newValue.getOpacity());
}
 
源代码19 项目: arma-dialog-creator   文件: SVColorIntArray.java
/** Set the color from a JavaFX Color instance */
public SVColorIntArray(@NotNull Color newValue) {
	this(newValue.getRed(), newValue.getGreen(), newValue.getBlue(), newValue.getOpacity());
}
 
源代码20 项目: chart-fx   文件: ColorGradientAxis.java
/**
 * 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));
}