Java Code Examples for javafx.scene.control.ColorPicker#setOnAction()

The following examples show how to use javafx.scene.control.ColorPicker#setOnAction() . 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: ColorPickerApp.java    From oim-fx with MIT License 6 votes vote down vote up
public Parent createContent() {
    final ColorPicker colorPicker = new ColorPicker(Color.GREEN);
    final Label coloredText = new Label("Colors");
    Font font = new Font(53);
    coloredText.setFont(font);
    final Button coloredButton = new Button("Colored Control");
    Color c = colorPicker.getValue();
    coloredText.setTextFill(c);
    coloredButton.setStyle(createRGBString(c));
    
    colorPicker.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent t) {
            Color newColor = colorPicker.getValue();
            coloredText.setTextFill(newColor);
            coloredButton.setStyle(createRGBString(newColor));
        }
    });
    
    VBox outerVBox = new VBox(coloredText, coloredButton, colorPicker);
    outerVBox.setAlignment(Pos.CENTER);
    outerVBox.setSpacing(20);
    outerVBox.setMaxSize(VBox.USE_PREF_SIZE, VBox.USE_PREF_SIZE);
    
    return outerVBox;
}
 
Example 2
Source File: SimpleColorPickerControl.java    From PreferencesFX with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void initializeParts() {
  super.initializeParts();

  node = new StackPane();
  node.getStyleClass().add("simple-text-control");

  colorPicker = new ColorPicker(initialValue);
  colorPicker.setMaxWidth(Double.MAX_VALUE);
  colorPicker.setOnAction(event -> {
    if (!field.valueProperty().getValue().equals(colorPicker.getValue().toString())) {
      field.valueProperty().setValue(colorPicker.getValue().toString());
    }
  });
  field.valueProperty().setValue(colorPicker.getValue().toString());
  fieldLabel = new Label(field.labelProperty().getValue());
}
 
Example 3
Source File: ColorPickerPreference.java    From Quelea with GNU General Public License v3.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void initializeParts() {
    super.initializeParts();

    node = new StackPane();
    node.getStyleClass().add("simple-text-control");

    colorPicker = new ColorPicker(initialValue);
    colorPicker.setMaxWidth(Double.MAX_VALUE);
    colorPicker.setOnAction(event -> {
        if (!field.valueProperty().getValue().equals(getColorString(colorPicker.getValue())))
            field.valueProperty().setValue(getColorString(colorPicker.getValue()));
    });

    field.valueProperty().setValue(getColorString(colorPicker.getValue()));
}
 
Example 4
Source File: PlotConfigDialog.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private int addTraceContent(final GridPane layout, int row, final Trace<?> trace)
{
    Label label = new Label(trace.getName());
    layout.add(label, 5, row);

    final ColorPicker color = createPicker(trace.getColor());
    color.setOnAction(event ->
    {
        trace.setColor(color.getValue());
        plot.requestUpdate();
    });
    layout.add(color, 6, row);

    final CheckBox visible = new CheckBox(Messages.PlotConfigVisible);
    visible.setSelected(trace.isVisible());
    visible.setOnAction(event ->
    {
        trace.setVisible(visible.isSelected());
        plot.requestUpdate();
    });
    layout.add(visible, 7, row++);

    return row;
}
 
Example 5
Source File: ColorMapDialog.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** @param section Segment of the color map
 *  @return ColorPicker that updates this segment in #color_sections
 */
private ColorPicker createColorPicker(final ColorSection section)
{
    final Color color = section.color;
    final int index = color_sections.indexOf(section);
    if (index < 0)
        throw new IllegalArgumentException("Cannot locate color section " + section);
    final ColorPicker picker = new ColorPicker(color);
    picker.setOnAction(event ->
    {
        color_sections.set(index, new ColorSection(section.value, picker.getValue()));
        updateMapFromSections();
    });
    return picker;
}
 
Example 6
Source File: ColorInputPane.java    From constellation with Apache License 2.0 4 votes vote down vote up
public ColorInputPane(final PluginParameter<ColorParameterValue> parameter) {
    final List<String> recentValues = RecentParameterValues.getRecentValues(parameter.getId());
    field = new ColorPicker();
    namedCombo = makeNamedCombo();
    final HBox hbox = new HBox(field, namedCombo);

    field.valueProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            final Color opaque = Color.color(newValue.getRed(), newValue.getGreen(), newValue.getBlue());
            if (!opaque.equals(oldValue)) {
                boolean foundNamedColor = false;
                for (final ConstellationColor c : ConstellationColor.NAMED_COLOR_LIST) {
                    final Color fxc = c.getJavaFXColor();
                    if (opaque.equals(fxc)) {
                        namedCombo.setValue(c);
                        foundNamedColor = true;
                        break;
                    }
                }

                if (!foundNamedColor) {
                    namedCombo.setValue(null);
                }
            }
        }
    });

    final ColorParameterValue pv = parameter.getParameterValue();

    if (recentValues != null) {
        field.setValue(Color.valueOf(recentValues.get(0)));
    }

    field.setValue(pv.get().getJavaFXColor());

    if (parameter.getParameterValue().getGuiInit() != null) {
        parameter.getParameterValue().getGuiInit().init(hbox);
    }

    field.setDisable(!parameter.isEnabled());
    field.setManaged(parameter.isVisible());
    field.setVisible(parameter.isVisible());
    this.setManaged(parameter.isVisible());
    this.setVisible(parameter.isVisible());

    namedCombo.valueProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null && !newValue.equals(oldValue)) {
            field.setValue(newValue.getJavaFXColor());
            parameter.setColorValue(ConstellationColor.fromFXColor(field.getValue()));
        }
    });

    field.setOnAction(event -> {
        parameter.setColorValue(ConstellationColor.fromFXColor(field.getValue()));
    });

    parameter.addListener((PluginParameter<?> pluginParameter, ParameterChange change) -> {
        Platform.runLater(() -> {
            switch (change) {
                case VALUE:
                    // Don't change the value if it isn't necessary.
                    final ConstellationColor param = pluginParameter.getColorValue();
                    if (!param.equals(field.getValue())) {
                        field.setValue(param.getJavaFXColor());
                    }
                    break;
                case ENABLED:
                    field.setDisable(!pluginParameter.isEnabled());
                    break;
                case VISIBLE:
                    field.setManaged(parameter.isVisible());
                    field.setVisible(parameter.isVisible());
                    this.setVisible(parameter.isVisible());
                    this.setManaged(parameter.isVisible());
                    break;
                default:
                    LOGGER.log(Level.FINE, "ignoring parameter change type {0}.", change);
                    break;
            }
        });
    });

    getChildren().add(hbox);
}
 
Example 7
Source File: TopsoilPlotEvolution.java    From ET_Redux with Apache License 2.0 4 votes vote down vote up
@Override
public List<Node> toolbarControlsFactory() {
    List<Node> controls = super.toolbarControlsFactory();

    CheckBox ellipsesCheckBox = new CheckBox("Ellipses");
    ellipsesCheckBox.setSelected(true);
    ellipsesCheckBox.setOnAction(mouseEvent -> {
        plot.setProperty(ELLIPSES, ellipsesCheckBox.isSelected());
    });
    
    ChoiceBox<SigmaPresentationModes> uncertaintyChoiceBox = new ChoiceBox<>(FXCollections.observableArrayList(SigmaPresentationModes.values()));
    uncertaintyChoiceBox.setValue(SigmaPresentationModes.TWO_SIGMA_ABSOLUTE);
    uncertaintyChoiceBox.setConverter(new StringConverter<SigmaPresentationModes>() {
        @Override
        public String toString(SigmaPresentationModes object) {
            return object.getDisplayName();
        }

        @Override
        public SigmaPresentationModes fromString(String string) {
            return null;
        }
    });
    uncertaintyChoiceBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<SigmaPresentationModes>() {
        @Override
        public void changed(ObservableValue observable, SigmaPresentationModes oldValue, SigmaPresentationModes newValue) {
            plot.setProperty(UNCERTAINTY, newValue.getSigmaMultiplier());
        }
    });

    ColorPicker ellipsesColorPicker = new ColorPicker(Color.RED);
    ellipsesColorPicker.setStyle("-fx-font-size: 8px; -fx-font-family: 'Courier New';");
    ellipsesColorPicker.setPrefWidth(100);
    ellipsesColorPicker.setOnAction(mouseEvent -> {
        // to satisfy D3
        plot.setProperty(ELLIPSE_FILL_COLOR, ellipsesColorPicker.getValue().toString().substring(0, 8).replaceAll("0x", "#"));
    });

    CheckBox matrixCheckBox = new CheckBox("Matrix");
    matrixCheckBox.setSelected(true);
    matrixCheckBox.setOnAction(mouseEvent -> {
        plot.setProperty(EVOLUTION_MATRIX, matrixCheckBox.isSelected());
    });

    CheckBox allSelectedCheckBox = new CheckBox("Select All");
    allSelectedCheckBox.setSelected(true);
    allSelectedCheckBox.setOnAction(mouseEvent -> {
        setSelectedAllData(allSelectedCheckBox.isSelected());
    });

    CheckBox regressionUnctEnvelopeCheckBox = new CheckBox("2D Regression Unct");
    regressionUnctEnvelopeCheckBox.setSelected(false);
    regressionUnctEnvelopeCheckBox.setOnAction(mouseEvent -> {
        plot.setProperty(REGRESSION_ENVELOPE, regressionUnctEnvelopeCheckBox.isSelected());
    });

    CheckBox regressionCheckBox = new CheckBox("2D Regression");
    regressionCheckBox.setSelected(false);
    regressionUnctEnvelopeCheckBox.setDisable(true);
    regressionCheckBox.setOnAction(mouseEvent -> {
        boolean isRegression = regressionCheckBox.isSelected();
        plot.setProperty(REGRESSION_LINE, isRegression);
        regressionUnctEnvelopeCheckBox.setDisable(!isRegression);
    });

    controls.add(ellipsesCheckBox);
    controls.add(uncertaintyChoiceBox);
    controls.add(ellipsesColorPicker);
    controls.add(allSelectedCheckBox);
    controls.add(matrixCheckBox);
    controls.add(regressionCheckBox);
    controls.add(regressionUnctEnvelopeCheckBox);

    return controls;
}
 
Example 8
Source File: TopsoilPlotWetherill.java    From ET_Redux with Apache License 2.0 4 votes vote down vote up
@Override
public List<Node> toolbarControlsFactory() {
    List<Node> controls = super.toolbarControlsFactory();

    CheckBox ellipsesCheckBox = new CheckBox("Ellipses");
    ellipsesCheckBox.setSelected(true);
    ellipsesCheckBox.setOnAction(mouseEvent -> {
        plot.setProperty(ELLIPSES, ellipsesCheckBox.isSelected());
    });
    
    ChoiceBox<SigmaPresentationModes> uncertaintyChoiceBox = new ChoiceBox<>(FXCollections.observableArrayList(SigmaPresentationModes.values()));
    uncertaintyChoiceBox.setValue(SigmaPresentationModes.TWO_SIGMA_ABSOLUTE);
    uncertaintyChoiceBox.setConverter(new StringConverter<SigmaPresentationModes>() {
        @Override
        public String toString(SigmaPresentationModes object) {
            return object.getDisplayName();
        }

        @Override
        public SigmaPresentationModes fromString(String string) {
            return null;
        }
    });
    uncertaintyChoiceBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<SigmaPresentationModes>() {
        @Override
        public void changed(ObservableValue observable, SigmaPresentationModes oldValue, SigmaPresentationModes newValue) {
            plot.setProperty(UNCERTAINTY, newValue.getSigmaMultiplier());
        }
    });

    ColorPicker ellipsesColorPicker = new ColorPicker(Color.RED);
    ellipsesColorPicker.setStyle("-fx-font-size: 8px; -fx-font-family: 'Courier New';");
    ellipsesColorPicker.setPrefWidth(100);
    ellipsesColorPicker.setOnAction(mouseEvent -> {
        // to satisfy D3
        plot.setProperty(ELLIPSE_FILL_COLOR, ellipsesColorPicker.getValue().toString().substring(0, 8).replaceAll("0x", "#"));
    });

    CheckBox concordiaLineCheckBox = new CheckBox("Concordia");
    concordiaLineCheckBox.setSelected(true);
    concordiaLineCheckBox.setOnAction(mouseEvent -> {
        plot.setProperty(CONCORDIA_LINE, concordiaLineCheckBox.isSelected());
    });

    CheckBox allSelectedCheckBox = new CheckBox("Select All");
    allSelectedCheckBox.setSelected(true);
    allSelectedCheckBox.setOnAction(mouseEvent -> {
        setSelectedAllData(allSelectedCheckBox.isSelected());
    });

    CheckBox regressionUnctEnvelopeCheckBox = new CheckBox("2D Regression Unct");
    regressionUnctEnvelopeCheckBox.setSelected(false);
    regressionUnctEnvelopeCheckBox.setOnAction(mouseEvent -> {
        plot.setProperty(REGRESSION_ENVELOPE, regressionUnctEnvelopeCheckBox.isSelected());
    });

    CheckBox regressionCheckBox = new CheckBox("2D Regression");
    regressionCheckBox.setSelected(false);
    regressionUnctEnvelopeCheckBox.setDisable(true);
    regressionCheckBox.setOnAction(mouseEvent -> {
        boolean isRegression = regressionCheckBox.isSelected();
        plot.setProperty(REGRESSION_LINE, isRegression);
        regressionUnctEnvelopeCheckBox.setDisable(!isRegression);
    });

    controls.add(ellipsesCheckBox);
    controls.add(uncertaintyChoiceBox);
    controls.add(ellipsesColorPicker);
    controls.add(allSelectedCheckBox);
    controls.add(concordiaLineCheckBox);
    controls.add(regressionCheckBox);
    controls.add(regressionUnctEnvelopeCheckBox);

    return controls;
}