Search in sources :

Example 1 with NamedWidgetColors

use of org.csstudio.display.builder.model.persist.NamedWidgetColors in project org.csstudio.display.builder by kasemir.

the class WidgetColorPopOverController method initialize.

/*
     * -------------------------------------------------------------------------
     */
@Override
public void initialize(URL location, ResourceBundle resources) {
    updateButton(okButton, ButtonType.OK);
    updateButton(cancelButton, ButtonType.CANCEL);
    updateButton(defaultButton, new ButtonType(Messages.WidgetColorPopOver_DefaultButton, ButtonData.LEFT));
    okButton.setText(ButtonType.OK.getText());
    ButtonBar.setButtonData(okButton, ButtonType.OK.getButtonData());
    root.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
        if (event.getCode() == KeyCode.ENTER)
            okPressed(null);
    });
    picker.valueProperty().addListener((observable, oldColor, newColor) -> {
        if (!updating) {
            setColor(JFXUtil.convert(newColor));
        }
    });
    defaultButton.disableProperty().bind(Bindings.createBooleanBinding(() -> getColor().equals(defaultColor), colorProperty()));
    okButton.disableProperty().bind(Bindings.createBooleanBinding(() -> getColor().equals(originalColor), colorProperty()));
    SpinnerValueFactory<Integer> redSpinnerValueFactory = new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 255);
    TextFormatter<Integer> redSpinnerFormatter = new TextFormatter<>(redSpinnerValueFactory.getConverter(), redSpinnerValueFactory.getValue());
    redSpinnerValueFactory.valueProperty().bindBidirectional(redSpinnerFormatter.valueProperty());
    redSpinner.getEditor().setTextFormatter(redSpinnerFormatter);
    redSpinner.setValueFactory(redSpinnerValueFactory);
    redSpinner.valueProperty().addListener(this::updateFromSpinner);
    redSpinner.focusedProperty().addListener((s, ov, nv) -> {
        if (nv) {
            Platform.runLater(() -> redSpinner.getEditor().selectAll());
        }
    });
    SpinnerValueFactory<Integer> greenSpinnerValueFactory = new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 255);
    TextFormatter<Integer> greenSpinnerFormatter = new TextFormatter<>(greenSpinnerValueFactory.getConverter(), greenSpinnerValueFactory.getValue());
    greenSpinnerValueFactory.valueProperty().bindBidirectional(greenSpinnerFormatter.valueProperty());
    greenSpinner.getEditor().setTextFormatter(greenSpinnerFormatter);
    greenSpinner.setValueFactory(greenSpinnerValueFactory);
    greenSpinner.valueProperty().addListener(this::updateFromSpinner);
    greenSpinner.focusedProperty().addListener((s, ov, nv) -> {
        if (nv) {
            Platform.runLater(() -> greenSpinner.getEditor().selectAll());
        }
    });
    SpinnerValueFactory<Integer> blueSpinnerValueFactory = new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 255);
    TextFormatter<Integer> blueSpinnerFormatter = new TextFormatter<>(blueSpinnerValueFactory.getConverter(), blueSpinnerValueFactory.getValue());
    blueSpinnerValueFactory.valueProperty().bindBidirectional(blueSpinnerFormatter.valueProperty());
    blueSpinner.getEditor().setTextFormatter(blueSpinnerFormatter);
    blueSpinner.setValueFactory(blueSpinnerValueFactory);
    blueSpinner.valueProperty().addListener(this::updateFromSpinner);
    blueSpinner.focusedProperty().addListener((s, ov, nv) -> {
        if (nv) {
            Platform.runLater(() -> blueSpinner.getEditor().selectAll());
        }
    });
    SpinnerValueFactory<Integer> alphaSpinnerValueFactory = new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 255);
    TextFormatter<Integer> alphaSpinnerFormatter = new TextFormatter<>(alphaSpinnerValueFactory.getConverter(), alphaSpinnerValueFactory.getValue());
    alphaSpinnerValueFactory.valueProperty().bindBidirectional(alphaSpinnerFormatter.valueProperty());
    alphaSpinner.getEditor().setTextFormatter(alphaSpinnerFormatter);
    alphaSpinner.setValueFactory(alphaSpinnerValueFactory);
    alphaSpinner.valueProperty().addListener(this::updateFromSpinner);
    alphaSpinner.focusedProperty().addListener((s, ov, nv) -> {
        if (nv) {
            Platform.runLater(() -> alphaSpinner.getEditor().selectAll());
        }
    });
    redSlider.valueProperty().addListener(this::updateFromSlider);
    greenSlider.valueProperty().addListener(this::updateFromSlider);
    blueSlider.valueProperty().addListener(this::updateFromSlider);
    alphaSlider.valueProperty().addListener(this::updateFromSlider);
    colorProperty().addListener((observable, oldColor, newColor) -> {
        updating = true;
        Color jfxColor = JFXUtil.convert(getColor());
        picker.setValue(jfxColor);
        currentColorCircle.setFill(jfxColor);
        redSlider.setValue(getRed());
        redSpinner.getValueFactory().setValue(getRed());
        greenSlider.setValue(getGreen());
        greenSpinner.getValueFactory().setValue(getGreen());
        blueSlider.setValue(getBlue());
        blueSpinner.getValueFactory().setValue(getBlue());
        alphaSlider.setValue(getAlpha());
        alphaSpinner.getValueFactory().setValue(getAlpha());
        updating = false;
    });
    colorNames.setCellFactory(view -> new NamedWidgetColorCell());
    colorNames.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            setColor(newValue);
        }
    });
    // Get colors on background thread
    ModelThreadPool.getExecutor().execute(() -> {
        final NamedWidgetColors colors = WidgetColorService.getColors();
        final Collection<NamedWidgetColor> values = colors.getColors();
        values.parallelStream().forEach(nc -> namedColors.put(JFXUtil.convert(nc), nc));
        Platform.runLater(() -> {
            values.stream().forEach(nc -> {
                colorNames.getItems().addAll(nc);
            });
            namesLoaded.set(true);
        });
    });
    // Add the 24 Visually Unique colors to the user's palette.
    // They are useful to create plot tracks.
    // See: http://phrogz.net/tmp/24colors.html
    picker.getCustomColors().add(Color.rgb(255, 0, 0));
    picker.getCustomColors().add(Color.rgb(255, 255, 0));
    picker.getCustomColors().add(Color.rgb(0, 234, 255));
    picker.getCustomColors().add(Color.rgb(170, 0, 255));
    picker.getCustomColors().add(Color.rgb(255, 127, 0));
    picker.getCustomColors().add(Color.rgb(191, 255, 0));
    picker.getCustomColors().add(Color.rgb(0, 149, 255));
    picker.getCustomColors().add(Color.rgb(255, 0, 170));
    picker.getCustomColors().add(Color.rgb(255, 212, 0));
    picker.getCustomColors().add(Color.rgb(106, 255, 0));
    picker.getCustomColors().add(Color.rgb(0, 64, 255));
    picker.getCustomColors().add(Color.rgb(237, 185, 185));
    picker.getCustomColors().add(Color.rgb(185, 215, 237));
    picker.getCustomColors().add(Color.rgb(231, 233, 185));
    picker.getCustomColors().add(Color.rgb(220, 185, 237));
    picker.getCustomColors().add(Color.rgb(185, 237, 224));
    picker.getCustomColors().add(Color.rgb(143, 35, 35));
    picker.getCustomColors().add(Color.rgb(35, 98, 143));
    picker.getCustomColors().add(Color.rgb(143, 106, 35));
    picker.getCustomColors().add(Color.rgb(107, 35, 143));
    picker.getCustomColors().add(Color.rgb(79, 143, 35));
    picker.getCustomColors().add(Color.rgb(0, 0, 0));
    picker.getCustomColors().add(Color.rgb(115, 115, 115));
    picker.getCustomColors().add(Color.rgb(204, 204, 204));
}
Also used : TextFormatter(javafx.scene.control.TextFormatter) NamedWidgetColor(org.csstudio.display.builder.model.properties.NamedWidgetColor) NamedWidgetColor(org.csstudio.display.builder.model.properties.NamedWidgetColor) WidgetColor(org.csstudio.display.builder.model.properties.WidgetColor) Color(javafx.scene.paint.Color) NamedWidgetColors(org.csstudio.display.builder.model.persist.NamedWidgetColors) ButtonType(javafx.scene.control.ButtonType)

Aggregations

ButtonType (javafx.scene.control.ButtonType)1 TextFormatter (javafx.scene.control.TextFormatter)1 Color (javafx.scene.paint.Color)1 NamedWidgetColors (org.csstudio.display.builder.model.persist.NamedWidgetColors)1 NamedWidgetColor (org.csstudio.display.builder.model.properties.NamedWidgetColor)1 WidgetColor (org.csstudio.display.builder.model.properties.WidgetColor)1