javafx.scene.effect.Blend Java Examples

The following examples show how to use javafx.scene.effect.Blend. 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: GameToken.java    From metastone with GNU General Public License v2.0 6 votes vote down vote up
private void createTargetButton() {
	target = (StackPane) lookup("#targetAnchor");
	Image image = IconFactory.getTargetIcon();
	ImageView targetIcon = new ImageView(image);
	targetIcon.setClip(new ImageView(image));
	ColorAdjust monochrome = new ColorAdjust();
	monochrome.setSaturation(-1.0);

	Blend red = new Blend(BlendMode.MULTIPLY, monochrome,
			new ColorInput(0, 0, targetIcon.getImage().getWidth(), targetIcon.getImage().getHeight(), Color.RED));

	Blend green = new Blend(BlendMode.MULTIPLY, monochrome,
			new ColorInput(0, 0, targetIcon.getImage().getWidth(), targetIcon.getImage().getHeight(), new Color(0, 1, 0, 0.5)));

	targetButton = targetIcon;

	targetIcon.effectProperty().bind(Bindings.when(targetButton.hoverProperty()).then((Effect) green).otherwise((Effect) red));
	targetButton.setId("target_button");
	hideTargetMarker();
	target.getChildren().add(targetButton);
}
 
Example #2
Source File: MvcLogoExample.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
private static Effect createShadowEffect() {
	DropShadow outerShadow = new DropShadow();
	outerShadow.setRadius(3);
	outerShadow.setSpread(0.2);
	outerShadow.setOffsetX(3);
	outerShadow.setOffsetY(3);
	outerShadow.setColor(new Color(0.3, 0.3, 0.3, 1));

	Distant light = new Distant();
	light.setAzimuth(-135.0f);

	Lighting l = new Lighting();
	l.setLight(light);
	l.setSurfaceScale(3.0f);

	Blend effects = new Blend(BlendMode.MULTIPLY);
	effects.setTopInput(l);
	effects.setBottomInput(outerShadow);

	return effects;
}
 
Example #3
Source File: GeometryNodeSnippet.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
protected static Effect createShadowEffect() {
	final DropShadow outerShadow = new DropShadow();
	outerShadow.setRadius(3);
	outerShadow.setSpread(0.2);
	outerShadow.setOffsetX(3);
	outerShadow.setOffsetY(3);
	outerShadow.setColor(new Color(0.3, 0.3, 0.3, 1));

	final Distant light = new Distant();
	light.setAzimuth(-135.0f);

	final Lighting l = new Lighting();
	l.setLight(light);
	l.setSurfaceScale(3.0f);

	final Blend effects = new Blend(BlendMode.MULTIPLY);
	effects.setTopInput(l);
	effects.setBottomInput(outerShadow);

	return effects;
}
 
Example #4
Source File: BlendEffect.java    From Learn-Java-12-Programming with MIT License 5 votes vote down vote up
static Node[] setEffectOnGroup(BlendMode bm1, BlendMode bm2){
    Node txt1 = new Text(bm1.name());
    Node txt2 = new Text(bm2.name());

    Blend blnd1 = new Blend();
    blnd1.setMode(bm1);

    Node c1 = createCircle();
    Node s1 = createSquare();
    Node g1 = new Group(s1, c1);
    g1.setEffect(blnd1);

    Node c2 = createCircle();
    Node s2 = createSquare();
    Node g2 = new Group(c2, s2);
    g2.setEffect(blnd1);

    Blend blnd2 = new Blend();
    blnd2.setMode(bm2);

    Node c3 = createCircle();
    Node s3 = createSquare();
    Node g3 = new Group(s3, c3);
    g3.setEffect(blnd2);

    Node c4 = createCircle();
    Node s4 = createSquare();
    Node g4 = new Group(c4, s4);
    g4.setEffect(blnd2);

    Node[] arr = {txt1, g1, g2, txt2, g3, g4 };
    return arr;
}
 
Example #5
Source File: ImageUtil.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieve an overlay image.
 *
 * @param overlayType
 *            The overlay type.
 * @param side
 *            The side of the eye.
 * @param color
 *            The overlay color.
 *
 * @return The overlay image.
 */
private static Image getOverlayImage(final int overlayType, final RightLeft side, final Color color) {
	URL imageUrl = ClassLoader.getSystemResource("overlay/" + getOverlayFileName(overlayType, side));

	Image image = new Image(imageUrl.toExternalForm());

	Canvas canvas = new Canvas(OVERLAY_SIZE, OVERLAY_SIZE);
	Color colorNoAlpha = new Color(color.getRed(), color.getGreen(), color.getBlue(), 1);

	Blend effect = new Blend(
			BlendMode.SRC_ATOP,
			null,
			new ColorInput(
					0,
					0,
					OVERLAY_SIZE,
					OVERLAY_SIZE,
					colorNoAlpha));

	// Type 2 is not changed in color.
	if (overlayType != 2) {
		canvas.getGraphicsContext2D().setEffect(effect);
	}
	canvas.getGraphicsContext2D().setGlobalAlpha(color.getOpacity());
	canvas.getGraphicsContext2D().drawImage(image, 0, 0, OVERLAY_SIZE, OVERLAY_SIZE);
	SnapshotParameters parameters = new SnapshotParameters();
	parameters.setFill(Color.TRANSPARENT);

	return canvas.snapshot(parameters, null);
}
 
Example #6
Source File: DigitFactory.java    From metastone with GNU General Public License v2.0 5 votes vote down vote up
private static void applyFontColor(ImageView image, Color color) {
	ColorAdjust monochrome = new ColorAdjust();
	monochrome.setSaturation(-1.0);
	Effect colorInput = new ColorInput(0, 0, image.getImage().getWidth(), image.getImage().getHeight(), color);
	Blend blend = new Blend(BlendMode.MULTIPLY, new ImageInput(image.getImage()), colorInput);
	image.setClip(new ImageView(image.getImage()));
	image.setEffect(blend);
	image.setCache(true);
}
 
Example #7
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 #8
Source File: BlendEffect.java    From Learn-Java-12-Programming with MIT License 5 votes vote down vote up
static Node[] setEffectOnSquare(BlendMode bm1, BlendMode bm2){

        Node txt1 = new Text(bm1.name());
        Node txt2 = new Text(bm2.name());

        Blend blnd1 = new Blend();
        blnd1.setMode(bm1);

        Node c1 = createCircle();
        Node s1 = createSquare();
        s1.setEffect(blnd1);

        Node c2 = createCircle();
        Node s2 = createSquare();
        s2.setEffect(blnd1);

        Blend blnd2 = new Blend();
        blnd2.setMode(bm2);

        Node c3 = createCircle();
        Node s3 = createSquare();
        s3.setEffect(blnd2);

        Node c4 = createCircle();
        Node s4 = createSquare();
        s4.setEffect(blnd2);

        Node[] arr = {txt1, new Group(s1, c1), new Group(c2, s2), txt2, new Group(s3, c3), new Group(c4, s4) };
        return arr;
    }
 
Example #9
Source File: BlendEffect.java    From Learn-Java-12-Programming with MIT License 5 votes vote down vote up
static Node[] setEffectOnCircle(BlendMode bm1, BlendMode bm2){
    Node txt1 = new Text(bm1.name());
    Node txt2 = new Text(bm2.name());

    Blend blnd1 = new Blend();
    blnd1.setMode(bm1);

    Node c1 = createCircle();
    Node s1 = createSquare();
    c1.setEffect(blnd1);

    Node c2 = createCircle();
    Node s2 = createSquare();
    c2.setEffect(blnd1);

    Blend blnd2 = new Blend();
    blnd2.setMode(bm2);

    Node c3 = createCircle();
    Node s3 = createSquare();
    c3.setEffect(blnd2);

    Node c4 = createCircle();
    Node s4 = createSquare();
    c4.setEffect(blnd2);

    Node[] arr = {txt1, new Group(s1, c1), new Group(c2, s2), txt2, new Group(s3, c3), new Group(c4, s4) };
    return arr;
}
 
Example #10
Source File: BlendEffect.java    From Learn-Java-12-Programming with MIT License 5 votes vote down vote up
@Override
public void run(){
    try {
        for(String effect: effects){
            for(int i = 0; i < 11; i++){
                double opacity = Math.round(i * 0.1 * 10.0) / 10.0;
                System.out.println(effect + " = " + opacity);
                String[] e = effect.split(",");
                txt1.setText("The blend mode opacity: " + opacity);
                txt2.setText(e[0]);
                txt3.setText(e[1]);

                Blend b1 = new Blend();
                BlendMode bm1 = Enum.valueOf(BlendMode.class, e[0]);
                b1.setMode(bm1);
                b1.setOpacity(opacity);
                g1.setEffect(b1);

                Blend b2 = new Blend();
                BlendMode bm2 = Enum.valueOf(BlendMode.class, e[1]);
                b2.setMode(bm2);
                b2.setOpacity(opacity);
                g2.setEffect(b2);

                TimeUnit.SECONDS.sleep(1);
                if(pause){
                    while(true){
                        TimeUnit.SECONDS.sleep(1);
                        if(!pause){
                            break;
                        }
                    }
                }
            }
        }
        Platform.exit();
    } catch (Exception ex){
        ex.printStackTrace();
    }
}
 
Example #11
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static Image addArcFx(Image image, int arc, Color bgColor) {
        try {
            if (image == null || arc <= 0) {
                return null;
            }
            Group group = new Group();
            double imageWidth = image.getWidth(), imageHeight = image.getHeight();
            Scene scene = new Scene(group);

            ImageView view = new ImageView(image);
            view.setPreserveRatio(true);
            view.setFitWidth(imageWidth);
            view.setFitHeight(imageHeight);

            Rectangle clip = new Rectangle(imageWidth, imageHeight);
            clip.setArcWidth(arc);
            clip.setArcHeight(arc);
            view.setClip(clip);

            group.getChildren().add(view);

            Blend blend = new Blend(BlendMode.SRC_OVER);
            blend.setBottomInput(new ColorInput(0, 0, imageWidth, imageHeight, bgColor));
            group.setEffect(blend);

            SnapshotParameters parameters = new SnapshotParameters();
            parameters.setFill(Color.TRANSPARENT);
            WritableImage newImage = group.snapshot(parameters, null);
            return newImage;

        } catch (Exception e) {
//            logger.error(e.toString());
            return null;
        }

    }
 
Example #12
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static Image addTextFx(Image image, String textString,
        Font font, Color color, int x, int y, float transparent, int shadow) {
    try {
        Group group = new Group();

        Text text = new Text(x, y, textString);
        text.setFill(color);
        text.setFont(font);
        if (shadow > 0) {
            DropShadow dropShadow = new DropShadow();
            dropShadow.setOffsetX(shadow);
            dropShadow.setOffsetY(shadow);
            text.setEffect(dropShadow);
        }

        group.getChildren().add(text);

        Blend blend = new Blend(BlendMode.SRC_OVER);
        blend.setBottomInput(new ImageInput(image));
        blend.setOpacity(1.0 - transparent);
        group.setEffect(blend);

        SnapshotParameters parameters = new SnapshotParameters();
        parameters.setFill(Color.TRANSPARENT);
        WritableImage newImage = group.snapshot(parameters, null);
        return newImage;
    } catch (Exception e) {
        logger.error(e.toString());
        return null;
    }
}
 
Example #13
Source File: BuildEntry_Controller.java    From Path-of-Leveling with MIT License 5 votes vote down vote up
public void initDisabledBuild(){
    isDisabledInLauncher = true;
    BoxBlur b = new BoxBlur();
    b.setWidth(5.0);
    b.setHeight(5.0);
    b.setIterations(1);
    Blend bl = new Blend();
    bl.setMode(BlendMode.SRC_OVER);
    bl.setOpacity(1.0);
    bl.setTopInput(b);
    disabledPanel.setEffect(b);
    //disabledPanel.setVisible(true);
    nonValidPanel.setVisible(true);
}
 
Example #14
Source File: VertexTypeNodeProvider.java    From constellation with Apache License 2.0 4 votes vote down vote up
public VertexTypeNodeProvider() {
    schemaLabel = new Label(SeparatorConstants.HYPHEN);
    schemaLabel.setPadding(new Insets(5));
    treeView = new TreeView<>();
    vertexTypes = new ArrayList<>();
    detailsView = new HBox();
    detailsView.setPadding(new Insets(5));
    backgroundIcons = new HashMap<>();
    foregroundIcons = new HashMap<>();
    startsWithRb = new RadioButton("Starts with");
    filterText = new TextField();

    // A shiny cell factory so the tree nodes show the correct text and graphic.
    treeView.setCellFactory(p -> new TreeCell<SchemaVertexType>() {
        @Override
        protected void updateItem(final SchemaVertexType item, boolean empty) {
            super.updateItem(item, empty);
            if (!empty && item != null) {
                setText(item.getName());
                if (item.getForegroundIcon() != null) {
                    // Background icon, sized, clipped, colored.
                    final Color color = item.getColor().getJavaFXColor();

                    if (!backgroundIcons.containsKey(item)) {
                        backgroundIcons.put(item, item.getBackgroundIcon().buildImage());
                    }
                    final ImageView bg = new ImageView(backgroundIcons.get(item));
                    bg.setFitWidth(SMALL_ICON_IMAGE_SIZE);
                    bg.setPreserveRatio(true);
                    bg.setSmooth(true);
                    final ImageView clip = new ImageView(bg.getImage());
                    clip.setFitWidth(SMALL_ICON_IMAGE_SIZE);
                    clip.setPreserveRatio(true);
                    clip.setSmooth(true);
                    bg.setClip(clip);
                    final ColorAdjust adjust = new ColorAdjust();
                    adjust.setSaturation(-1);
                    final ColorInput ci = new ColorInput(0, 0, SMALL_ICON_IMAGE_SIZE, SMALL_ICON_IMAGE_SIZE, color);
                    final Blend blend = new Blend(BlendMode.MULTIPLY, adjust, ci);
                    bg.setEffect(blend);

                    // Foreground icon, sized.
                    if (!foregroundIcons.containsKey(item)) {
                        foregroundIcons.put(item, item.getForegroundIcon().buildImage());
                    }
                    final ImageView fg = new ImageView(foregroundIcons.get(item));
                    fg.setFitWidth(SMALL_ICON_IMAGE_SIZE);
                    fg.setPreserveRatio(true);
                    fg.setSmooth(true);
                    fg.setCache(true);

                    // Combine foreground and background icons.
                    final Group iconGroup = new Group(bg, fg);

                    setGraphic(iconGroup);
                }
            } else {
                setGraphic(null);
                setText(null);
            }
        }
    });
}
 
Example #15
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static Image addMarginsFx2(Image image, Color color, int MarginWidth,
        boolean addTop, boolean addBottom, boolean addLeft, boolean addRight) {
    try {
        if (image == null || MarginWidth <= 0) {
            return image;
        }
        Group group = new Group();
        double imageWidth = image.getWidth(), imageHeight = image.getHeight();
        double totalWidth = image.getWidth(), totalHeight = image.getHeight();
        ImageView view = new ImageView(image);
        view.setPreserveRatio(true);
        view.setFitWidth(imageWidth);
        view.setFitHeight(imageHeight);
        if (addLeft) {
            view.setX(MarginWidth);
            totalWidth += MarginWidth;
        } else {
            view.setX(0);
        }
        if (addTop) {
            view.setY(MarginWidth);
            totalHeight += MarginWidth;
        } else {
            view.setY(0);
        }
        if (addBottom) {
            totalHeight += MarginWidth;
        }
        if (addRight) {
            totalWidth += MarginWidth;
        }
        group.getChildren().add(view);

        Blend blend = new Blend(BlendMode.SRC_OVER);
        blend.setBottomInput(new ColorInput(0, 0, totalWidth, totalHeight, color));
        group.setEffect(blend);

        SnapshotParameters parameters = new SnapshotParameters();
        parameters.setFill(Color.TRANSPARENT);
        WritableImage newImage = group.snapshot(parameters, null);
        return newImage;

    } catch (Exception e) {
        logger.error(e.toString());
        return image;
    }

}
 
Example #16
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static Image combineSingleColumnFx(List<Image> images) {
    if (images == null || images.isEmpty()) {
        return null;
    }
    try {
        Group group = new Group();

        double x = 0, y = 0, imageWidth, imageHeight;
        double totalWidth = 0, totalHeight = 0;

        for (Image theImage : images) {
            ImageView view = new ImageView(theImage);
            imageWidth = theImage.getWidth();
            imageHeight = theImage.getHeight();

            view.setPreserveRatio(true);
            view.setX(x);
            view.setY(y);
            view.setFitWidth(imageWidth);
            view.setFitHeight(imageHeight);

            group.getChildren().add(view);
            y += imageHeight;

            if (imageWidth > totalWidth) {
                totalWidth = imageWidth;
            }
        }
        totalHeight = y;
        Blend blend = new Blend(BlendMode.SRC_OVER);
        blend.setBottomInput(new ColorInput(0, 0, totalWidth, totalHeight, Color.TRANSPARENT));
        group.setEffect(blend);

        SnapshotParameters parameters = new SnapshotParameters();
        parameters.setFill(Color.TRANSPARENT);
        WritableImage newImage = group.snapshot(parameters, null);
        return newImage;
    } catch (Exception e) {
        logger.error(e.toString());
        return null;
    }
}
 
Example #17
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static Image combineImagesColumnFx(List<Image> images,
        Color bgColor, int interval, int Margin) {
    try {
        if (images == null || images.isEmpty()) {
            return null;
        }
        Group group = new Group();

        int x = Margin, y = Margin, width = 0, height = 0;
        for (int i = 0; i < images.size(); ++i) {
            Image image = images.get(i);
            ImageView view = new ImageView(image);
            view.setPreserveRatio(true);
            view.setFitWidth(image.getWidth());
            view.setFitHeight(image.getHeight());
            view.setX(x);
            view.setY(y);
            group.getChildren().add(view);

            x = Margin;
            y += image.getHeight() + interval;

            if (image.getWidth() > width) {
                width = (int) image.getWidth();
            }
        }

        width += 2 * Margin;
        height = y + Margin - interval;
        Blend blend = new Blend(BlendMode.SRC_OVER);
        blend.setBottomInput(new ColorInput(0, 0, width, height, bgColor));
        group.setEffect(blend);

        SnapshotParameters parameters = new SnapshotParameters();
        parameters.setFill(Color.TRANSPARENT);
        WritableImage newImage = group.snapshot(parameters, null);

        return newImage;
    } catch (Exception e) {
        logger.error(e.toString());
        return null;
    }
}
 
Example #18
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static Image indicateSplitFx(Image image,
            List<Integer> rows, List<Integer> cols,
            Color lineColor, int lineWidth, boolean showSize) {
        try {
            if (rows == null || cols == null) {
                return image;
            }
            Group group = new Group();
            int width = (int) image.getWidth();
            int height = (int) image.getHeight();
            int row;
            for (int i = 0; i < rows.size(); ++i) {
                row = rows.get(i);
                if (row <= 0 || row >= height - 1) {
                    continue;
                }
                Line rowLine = new Line(0, row, width, row);
                rowLine.setStroke(lineColor);
                rowLine.setStrokeWidth(lineWidth);
                group.getChildren().add(rowLine);
            }
            int col;
            for (int i = 0; i < cols.size(); ++i) {
                col = cols.get(i);
                if (col <= 0 || col >= width - 1) {
                    continue;
                }
                Line colLine = new Line(col, 0, col, height);
                colLine.setStroke(lineColor);
                colLine.setStrokeWidth(lineWidth);
                group.getChildren().add(colLine);
            }

            if (showSize) {
                for (int i = 0; i < rows.size() - 1; ++i) {
                    int h = rows.get(i + 1) - rows.get(i) + 1;
                    for (int j = 0; j < cols.size() - 1; ++j) {
                        int w = cols.get(j + 1) - cols.get(j) + 1;
                        Text text = new Text();
                        text.setX(cols.get(j) + w / 3);
                        text.setY(rows.get(i) + h / 3);
                        text.setFill(lineColor);
                        text.setText(w + "x" + h);
                        text.setFont(new javafx.scene.text.Font(lineWidth * 3.0));
                        group.getChildren().add(text);
                    }
                }
            }

            Blend blend = new Blend(BlendMode.SRC_OVER);
            blend.setBottomInput(new ImageInput(image));
            group.setEffect(blend);

            SnapshotParameters parameters = new SnapshotParameters();
            parameters.setFill(Color.TRANSPARENT);
            WritableImage newImage = group.snapshot(parameters, null);

            return newImage;
        } catch (Exception e) {
//            logger.error(e.toString());
            return null;
        }
    }
 
Example #19
Source File: MainScene.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public void createBlend() {

		blend = new Blend();
		blend.setMode(BlendMode.MULTIPLY);

		DropShadow ds = new DropShadow();
		ds.setColor(Color.rgb(254, 235, 66, 0.3));
		ds.setOffsetX(5);
		ds.setOffsetY(5);
		ds.setRadius(5);
		ds.setSpread(0.2);

		blend.setBottomInput(ds);

		DropShadow ds1 = new DropShadow();
		ds1.setColor(Color.web("#d68268")); // #d68268 is pinkish orange//f13a00"));
		ds1.setRadius(20);
		ds1.setSpread(0.2);

		Blend blend2 = new Blend();
		blend2.setMode(BlendMode.MULTIPLY);

		InnerShadow is = new InnerShadow();
		is.setColor(Color.web("#feeb42")); // #feeb42 is mid-pale yellow
		is.setRadius(9);
		is.setChoke(0.8);
		blend2.setBottomInput(is);

		InnerShadow is1 = new InnerShadow();
		is1.setColor(Color.web("#278206")); // # f13a00 is bright red // 278206 is dark green
		is1.setRadius(5);
		is1.setChoke(0.4);
		blend2.setTopInput(is1);

		Blend blend1 = new Blend();
		blend1.setMode(BlendMode.MULTIPLY);
		blend1.setBottomInput(ds1);
		blend1.setTopInput(blend2);

		blend.setTopInput(blend1);
	}