下面列出了怎么用javafx.scene.effect.ColorAdjust的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* 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);
}
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);
});
}
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;
}
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);
}
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;
}
}
}
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));
}
}
/**
* 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();
}
}
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));
}
}
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);
}
/**
* 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);
}
}
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);
}
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);
}
}
});
}
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);
});
}
/** 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;
}
private void darkenWithDistance(Node node, double zoomLevel) {
double brightnessAdjust = -zoomLevel / 5;
node.setEffect(new ColorAdjust(0, 0, brightnessAdjust, 0));
}