javafx.scene.effect.ColorAdjust Java Examples

The following examples show how to use javafx.scene.effect.ColorAdjust. 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: ConfigController.java    From houdoku with MIT License 6 votes vote down vote up
/**
 * Update the page effect/filter preview using the slider values.
 * 
 * <p>This method also updates the labels next to each slider.
 */
@FXML
private void updateEffectPreview() {
    ColorAdjust color_adjust = new ColorAdjust();
    double hue = filterHueSlider.getValue();
    double saturation = filterSaturationSlider.getValue();
    double brightness = filterBrightnessSlider.getValue();

    if (effectColorCheck.isSelected()) {
        filterHueSliderLabel.setText(String.format("%.2f", hue));
        color_adjust.setHue(hue);
        color_adjust.setSaturation(filterSaturationSlider.getValue());

        filterSaturationSliderLabel.setText(String.format("%.2f", saturation));
        color_adjust.setSaturation(saturation);
        color_adjust.setHue(filterHueSlider.getValue());
    }
    if (effectBrightnessCheck.isSelected()) {
        filterBrightnessSliderLabel.setText(String.format("%.2f", brightness));
        color_adjust.setBrightness(brightness);
    }

    effectPreview.setEffect(color_adjust);
}
 
Example #2
Source File: PlayerController.java    From Simple-Media-Player with MIT License 6 votes vote down vote up
private void setIcon(Button button,String path,int size){
    Image icon = new Image(path);
    ImageView imageView = new ImageView(icon);
    imageView.setFitWidth(size);
    imageView.setFitHeight((int)(size * icon.getHeight() / icon.getWidth()));
    button.setGraphic(imageView);
    //设置图标点击时发亮
    ColorAdjust colorAdjust = new ColorAdjust();
    button.setOnMousePressed(event ->  {
        colorAdjust.setBrightness(0.5);
        button.setEffect(colorAdjust);
    });
    button.setOnMouseReleased(event -> {
        colorAdjust.setBrightness(0);
        button.setEffect(colorAdjust);
    });
}
 
Example #3
Source File: FxIconBuilder.java    From FxDock with Apache License 2.0 6 votes vote down vote up
protected Effect setInputEffect(Effect a, Effect b)
{
	// I don't know a better way to chain effects, it's missing in FX
	// https://bugs.openjdk.java.net/browse/JDK-8091895
	// perhaps try Blend:
	// https://community.oracle.com/thread/2337194?tstart=0
	if(b instanceof GaussianBlur)
	{
		((GaussianBlur)b).setInput(a);
	}
	else if(b instanceof ColorAdjust)
	{
		((ColorAdjust)b).setInput(a);
	}
	else
	{
		throw new Error("todo: does " + b + " have setInput()?"); 
	}
	return b;
}
 
Example #4
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 #5
Source File: Transitions.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
private void removeEffect(Node node, int duration) {
    if (node != null) {
        node.setMouseTransparent(false);
        removeEffectTimeLine = new Timeline();
        GaussianBlur blur = (GaussianBlur) node.getEffect();
        if (blur != null) {
            KeyValue kv1 = new KeyValue(blur.radiusProperty(), 0.0);
            KeyFrame kf1 = new KeyFrame(Duration.millis(getDuration(duration)), kv1);
            removeEffectTimeLine.getKeyFrames().add(kf1);

            ColorAdjust darken = (ColorAdjust) blur.getInput();
            KeyValue kv2 = new KeyValue(darken.brightnessProperty(), 0.0);
            KeyFrame kf2 = new KeyFrame(Duration.millis(getDuration(duration)), kv2);
            removeEffectTimeLine.getKeyFrames().add(kf2);
            removeEffectTimeLine.setOnFinished(actionEvent -> {
                node.setEffect(null);
                removeEffectTimeLine = null;
            });
            removeEffectTimeLine.play();
        } else {
            node.setEffect(null);
            removeEffectTimeLine = null;
        }
    }
}
 
Example #6
Source File: SpriteView.java    From quantumjava with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void setColor(Color color) {
    this.color = color;
    if (color == null) {
        imageView.setEffect(null);
    } else {
        imageView.setEffect(new ColorAdjust(color.getHue() / 180 - colorOffset, 0.3, 0, 0));
    }
}
 
Example #7
Source File: BytecodeEditorPane.java    From Recaf with MIT License 5 votes vote down vote up
/**
 * Called by the error handler to notify the UI of error status.
 *
 * @param exceptions
 * 		Errors reported.
 */
public void onErrorsReceived(List<LineException> exceptions) {
	if (exceptions == null || exceptions.isEmpty()) {
		ColorAdjust colorAdjust = new ColorAdjust();
		colorAdjust.setBrightness(-0.7);
		colorAdjust.setSaturation(-0.8);
		errorGraphic.setEffect(colorAdjust);
	} else {
		errorGraphic.setEffect(null);
		stackHelper.setErrored();
	}
}
 
Example #8
Source File: SpriteView.java    From training with MIT License 5 votes vote down vote up
public void setColor(Color color) {
    this.color = color;
    if (color == null) {
        imageView.setEffect(null);
    } else {
        imageView.setEffect(new ColorAdjust(color.getHue() / 180 - colorOffset, 0.3, 0, 0));
    }
}
 
Example #9
Source File: JFXColorPickerUI.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
private void refreshHSLCircle() {
    ColorAdjust colorAdjust = new ColorAdjust();
    colorAdjust.setHue(map(currentHue + (currentHue < 127.5 ? 1 : -1) * 127.5, 0, 255, -1, 1));
    slCircleView.setEffect(colorAdjust);
    setColorAtLocation((int) selector.getTranslateX() + selectorSize / 2,
        (int) selector.getTranslateY() + selectorSize / 2);
}
 
Example #10
Source File: IconsListElementSkin.java    From phoenicis with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Updates grayscale of the miniature when the enabled state has been updated
 *
 * @param miniature The miniature
 */
private void updateEnabled(final Region miniature) {
    if (!getControl().isEnabled()) {
        final ColorAdjust grayScale = new ColorAdjust();
        grayScale.setSaturation(-1);

        miniature.setEffect(grayScale);
    } else {
        miniature.setEffect(null);
    }
}
 
Example #11
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 #12
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 #13
Source File: MainController.java    From neural-style-gui with GNU General Public License v3.0 4 votes vote down vote up
private void setupServiceListeners() {
    // handle each Worker.State
    log.log(Level.FINER, "Setting state listener.");
    EventStreams.valuesOf(neuralService.stateProperty()).subscribe(state -> {
        switch (state) {
            case SCHEDULED:
                log.log(Level.FINER, "Neural service: Scheduled.");
                statusLabel.setText(resources.getString("neuralServiceStatusScheduled"));
                startButton.setDisable(true);
                stopButton.setDisable(false);
                progress.setProgress(0);
                break;
            case READY:
                log.log(Level.FINER, "Neural service: Ready.");
                statusLabel.setText(resources.getString("neuralServiceStatusReady"));
                startButton.setDisable(false);
                stopButton.setDisable(true);
                break;
            case RUNNING:
                log.log(Level.FINER, "Neural service: Running.");
                statusLabel.setText(resources.getString("neuralServiceStatusRunning"));
                startButton.setDisable(true);
                stopButton.setDisable(false);
                break;
            case SUCCEEDED:
                log.log(Level.FINER, "Neural service: Succeeded.");
                statusLabel.setText(resources.getString("neuralServiceStatusFinished"));
                startButton.setDisable(false);
                stopButton.setDisable(true);
                progress.setProgress(100);
                break;
            case CANCELLED:
                log.log(Level.FINER, "Neural service: Cancelled.");
                statusLabel.setText(resources.getString("neuralServiceStatusCancelled"));
                startButton.setDisable(false);
                stopButton.setDisable(true);
                break;
            case FAILED:
                log.log(Level.FINER, "Neural service: Failed.");
                statusLabel.setText(resources.getString("neuralServiceStatusFailed"));
                startButton.setDisable(false);
                stopButton.setDisable(true);
                break;
        }
    });

    log.log(Level.FINER, "Setting Image Output Service listener.");
    EventStreams.nonNullValuesOf(imageOutputService.valueProperty()).subscribe(newResults -> {
        log.log(Level.FINER, "Received updated Image Outputs from Service.");
        updateNeuralOutputs(newResults);
        updateImageView();
    });
    EventStreams.valuesOf(NeuralStyleWrapper.workingFolder.valueProperty()).subscribe(newFolder -> {
        log.log(Level.FINE, "New Working Folder, restarting output Service.");
        imageOutputService.cancel();
        outputRoot.getChildren().clear();
        startOutputService();
    });
    startOutputService();

    log.log(Level.FINER, "Setting progress listener.");
    EventStreams.nonNullValuesOf(neuralService.progressProperty())
            .subscribe(value -> progress.setProgress(value.doubleValue()));

    log.log(Level.FINER, "Setting running listener.");
    final ColorAdjust highlighted = new ColorAdjust(0, 0, 0.3, 0);
    EventStreams.nonNullValuesOf(neuralService.runningProperty())
            .subscribe(running -> {
               if (running)
                   statusLabel.setEffect(highlighted);
               else
                   statusLabel.setEffect(null);
            });
}
 
Example #14
Source File: Story.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/** render the application on a stage */
  public StackPane createGUI() {

	SwingUtilities.invokeLater(() -> {
		//Simulation.instance().getJConsole().write(ADDRESS,Color.ORANGE,Color.BLACK);
	});

    // place the address content in a bordered title pane.
    Pane titledContent = new BorderedTitledPane(TITLE, getContent());
    titledContent.getStyleClass().add("titled-address");
    titledContent.setPrefSize(800, 745);

    // make some crumpled paper as a background.
    final Image paper = new Image(PAPER);
    final ImageView paperView = new ImageView(paper);
    ColorAdjust colorAdjust = new ColorAdjust(0, -.2, .2, 0);
    paperView.setEffect(colorAdjust);

    // place the address content over the top of the paper.
    StackPane stackedContent = new StackPane();
    stackedContent.getChildren().addAll(paperView, titledContent);

    // manage the viewport of the paper background, to size it to the content.
    paperView.setViewport(new Rectangle2D(0, 0, titledContent.getPrefWidth(), titledContent.getPrefHeight()));
    stackedContent.layoutBoundsProperty().addListener(new ChangeListener<Bounds>() {
      @Override public void changed(ObservableValue<? extends Bounds> observableValue, Bounds oldValue, Bounds newValue) {
        paperView.setViewport(new Rectangle2D(
          newValue.getMinX(), newValue.getMinY(),
          Math.min(newValue.getWidth(), paper.getWidth()), Math.min(newValue.getHeight(), paper.getHeight())
        ));
      }
    });

    // blend the content into the paper and make it look old.
    titledContent.setMaxWidth(paper.getWidth());
    titledContent.setEffect(new SepiaTone());
    titledContent.setBlendMode(BlendMode.MULTIPLY);

    // configure and display the scene and stage.
    //Scene scene = new Scene(stackedContent);
    //scene.getStylesheets().add(getClass().getResource("/css/gettysburg.css").toExternalForm());

/*
    stage.setTitle(TITLE);
    stage.getIcons().add(new Image(ICON));
    stage.setScene(scene);
    stage.setMinWidth(600); stage.setMinHeight(500);
    stage.show();
*/
    // make the scrollbar in the address scroll pane hide when it is not needed.
    makeScrollFadeable(titledContent.lookup(".address > .scroll-pane"));

    return stackedContent;
  }
 
Example #15
Source File: EnvironmentView.java    From narjillos with MIT License 4 votes vote down vote up
private void darkenWithDistance(Node node, double zoomLevel) {
	double brightnessAdjust = -zoomLevel / 5;
	node.setEffect(new ColorAdjust(0, 0, brightnessAdjust, 0));
}