Search in sources :

Example 1 with GradientPickerStop

use of com.fxexperience.javafx.scene.control.gradientpicker.GradientPickerStop in project fxexperience2 by EricCanull.

the class ColorPickerControl method initialize.

/**
     * Private
     */
private void initialize() {
    final FXMLLoader loader = new FXMLLoader();
    //NOI18N
    loader.setLocation(ColorPickerControl.class.getResource("/fxml/FXMLColorPicker.fxml"));
    loader.setController(this);
    loader.setRoot(this);
    try {
        loader.load();
    } catch (IOException ex) {
        Logger.getLogger(ColorPickerControl.class.getName()).log(Level.SEVERE, null, ex);
    }
    assert hue_slider != null;
    assert picker_region != null;
    assert hue_textfield != null;
    assert saturation_textfield != null;
    assert brightness_textfield != null;
    assert alpha_textfield != null;
    assert red_textfield != null;
    assert green_textfield != null;
    assert blue_textfield != null;
    assert alpha_slider != null;
    // Make the grad for hue slider
    hue_slider.setStyle(makeHueSliderCSS());
    // Investigate why height + width listeners do not work
    // Indeed, the picker_handle_stackpane bounds may still be null at this point
    // UPDATE BELOW TO BE CALLED ONCE ONLY AT DISPLAY TIME
    picker_region.boundsInParentProperty().addListener((ov, oldb, newb) -> {
        picker_scrollpane.setHvalue(0.5);
        picker_scrollpane.setVvalue(0.5);
        // Init time only
        final Paint paint = paintPickerController.getPaintProperty();
        if (paint instanceof Color) {
            updateUI((Color) paint);
        } else if (paint instanceof LinearGradient || paint instanceof RadialGradient) {
            final GradientPicker gradientPicker = paintPickerController.getGradientPicker();
            final GradientPickerStop gradientPickerStop = gradientPicker.getSelectedStop();
            // Update the color preview with the color of the selected stop
            if (gradientPickerStop != null) {
                updateUI(gradientPickerStop.getColor());
            }
        }
    });
    final ChangeListener<Boolean> onHSBFocusedChange = (ov, oldValue, newValue) -> {
        if (newValue == false) {
            // Update UI
            final Color color = updateUI_OnHSBChange();
            // Update model
            setPaintProperty(color);
        }
    };
    final ChangeListener<Boolean> onRGBFocusedChange = (ov, oldValue, newValue) -> {
        if (newValue == false) {
            // Update UI
            final Color color = updateUI_OnRGBChange();
            // Update model
            setPaintProperty(color);
        }
    };
    final ChangeListener<Boolean> onHexaFocusedChange = (ov, oldValue, newValue) -> {
        if (newValue == false) {
            try {
                // Update UI
                final Color color = updateUI_OnHexaChange();
                // Update model
                setPaintProperty(color);
            } catch (IllegalArgumentException iae) {
                handleHexaException();
            }
        }
    };
    // TextField ON FOCUS LOST event handler
    hue_textfield.focusedProperty().addListener(onHSBFocusedChange);
    saturation_textfield.focusedProperty().addListener(onHSBFocusedChange);
    brightness_textfield.focusedProperty().addListener(onHSBFocusedChange);
    alpha_textfield.focusedProperty().addListener(onHSBFocusedChange);
    red_textfield.focusedProperty().addListener(onRGBFocusedChange);
    green_textfield.focusedProperty().addListener(onRGBFocusedChange);
    blue_textfield.focusedProperty().addListener(onRGBFocusedChange);
    hexa_textfield.focusedProperty().addListener(onHexaFocusedChange);
    // Slider ON VALUE CHANGE event handler
    hue_slider.valueProperty().addListener((ov, oldValue, newValue) -> {
        if (updating == true) {
            return;
        }
        double hue = newValue.doubleValue();
        // retrieve HSB TextFields values
        double saturation = Double.valueOf(saturation_textfield.getText()) / 100.0;
        double brightness = Double.valueOf(brightness_textfield.getText()) / 100.0;
        double alpha = Double.valueOf(alpha_textfield.getText());
        // Update UI
        final Color color = updateUI(hue, saturation, brightness, alpha);
        // Update model
        setPaintProperty(color);
    });
    alpha_slider.valueProperty().addListener((ov, oldValue, newValue) -> {
        if (updating == true) {
            return;
        }
        double alpha = newValue.doubleValue();
        // retrieve HSB TextFields values
        double hue = Double.valueOf(hue_textfield.getText());
        double saturation = Double.valueOf(saturation_textfield.getText()) / 100.0;
        double brightness = Double.valueOf(brightness_textfield.getText()) / 100.0;
        // Update UI
        final Color color = updateUI(hue, saturation, brightness, alpha);
        // Update model
        setPaintProperty(color);
    });
    final ChangeListener<Boolean> liveUpdateListener = (ov, oldValue, newValue) -> paintPickerController.setLiveUpdate(newValue);
    picker_region.pressedProperty().addListener(liveUpdateListener);
    hue_slider.pressedProperty().addListener(liveUpdateListener);
    alpha_slider.pressedProperty().addListener(liveUpdateListener);
}
Also used : Color(javafx.scene.paint.Color) TextField(javafx.scene.control.TextField) Mode(com.fxexperience.javafx.scene.control.paintpicker.PaintPicker.Mode) MouseEvent(javafx.scene.input.MouseEvent) IOException(java.io.IOException) StackPane(javafx.scene.layout.StackPane) LinearGradient(javafx.scene.paint.LinearGradient) GradientPickerStop(com.fxexperience.javafx.scene.control.gradientpicker.GradientPickerStop) Logger(java.util.logging.Logger) VBox(javafx.scene.layout.VBox) Level(java.util.logging.Level) FXML(javafx.fxml.FXML) PaintPickerController(com.fxexperience.javafx.scene.control.paintpicker.PaintPickerController) ActionEvent(javafx.event.ActionEvent) ScrollPane(javafx.scene.control.ScrollPane) Slider(javafx.scene.control.Slider) Region(javafx.scene.layout.Region) Paint(javafx.scene.paint.Paint) FXMLLoader(javafx.fxml.FXMLLoader) RadialGradient(javafx.scene.paint.RadialGradient) GradientPicker(com.fxexperience.javafx.scene.control.gradientpicker.GradientPicker) ChangeListener(javafx.beans.value.ChangeListener) Circle(javafx.scene.shape.Circle) Bounds(javafx.geometry.Bounds) Color(javafx.scene.paint.Color) RadialGradient(javafx.scene.paint.RadialGradient) IOException(java.io.IOException) Paint(javafx.scene.paint.Paint) FXMLLoader(javafx.fxml.FXMLLoader) GradientPickerStop(com.fxexperience.javafx.scene.control.gradientpicker.GradientPickerStop) GradientPicker(com.fxexperience.javafx.scene.control.gradientpicker.GradientPicker) LinearGradient(javafx.scene.paint.LinearGradient)

Example 2 with GradientPickerStop

use of com.fxexperience.javafx.scene.control.gradientpicker.GradientPickerStop in project fxexperience2 by EricCanull.

the class ColorPickerControl method handleHexaException.

private void handleHexaException() {
    paintPickerController.getDelegate().handleError("log.warning.color.creation.error.hexadecimal", hexa_textfield.getText().trim());
    // Update UI to previous value
    final Color color;
    switch(paintPickerController.getMode()) {
        case COLOR:
            assert paintPickerController.getPaintProperty() instanceof Color;
            color = (Color) paintPickerController.getPaintProperty();
            break;
        case LINEAR:
        case RADIAL:
            final GradientPicker gradientPicker = paintPickerController.getGradientPicker();
            if (gradientPicker.getGradientStops().isEmpty() == false) {
                final GradientPickerStop stop = paintPickerController.getGradientPicker().getSelectedStop();
                assert stop != null;
                color = stop.getColor();
            } else {
                color = Color.BLACK;
            }
            break;
        default:
            color = null;
            assert false;
    }
    assert color != null;
    updateUI(color);
    hexa_textfield.selectAll();
}
Also used : GradientPicker(com.fxexperience.javafx.scene.control.gradientpicker.GradientPicker) Color(javafx.scene.paint.Color) GradientPickerStop(com.fxexperience.javafx.scene.control.gradientpicker.GradientPickerStop)

Example 3 with GradientPickerStop

use of com.fxexperience.javafx.scene.control.gradientpicker.GradientPickerStop in project fxexperience2 by EricCanull.

the class ColorPickerControl method setPaintProperty.

/**
     * When updating the color picker, we may update :
     * - either the color of the paint picker itself (Color mode)
     * - or the color of the selected stop (LinearGradient or RadialGradient mode)
     *
     * @param color
     */
private void setPaintProperty(Color color) {
    final Mode mode = paintPickerController.getMode();
    final Paint paint;
    switch(mode) {
        case COLOR:
            paint = color;
            break;
        case LINEAR:
        case RADIAL:
            final GradientPicker gradientPicker = paintPickerController.getGradientPicker();
            final GradientPickerStop gradientPickerStop = gradientPicker.getSelectedStop();
            // Set the color of the selected stop
            if (gradientPickerStop != null) {
                gradientPickerStop.setColor(color);
            }
            // Update gradient preview
            paint = gradientPicker.getValue(mode);
            gradientPicker.updatePreview(paint);
            break;
        default:
            paint = null;
            break;
    }
    paintPickerController.setPaintProperty(paint);
}
Also used : GradientPicker(com.fxexperience.javafx.scene.control.gradientpicker.GradientPicker) Mode(com.fxexperience.javafx.scene.control.paintpicker.PaintPicker.Mode) Paint(javafx.scene.paint.Paint) GradientPickerStop(com.fxexperience.javafx.scene.control.gradientpicker.GradientPickerStop)

Aggregations

GradientPicker (com.fxexperience.javafx.scene.control.gradientpicker.GradientPicker)3 GradientPickerStop (com.fxexperience.javafx.scene.control.gradientpicker.GradientPickerStop)3 Mode (com.fxexperience.javafx.scene.control.paintpicker.PaintPicker.Mode)2 Color (javafx.scene.paint.Color)2 Paint (javafx.scene.paint.Paint)2 PaintPickerController (com.fxexperience.javafx.scene.control.paintpicker.PaintPickerController)1 IOException (java.io.IOException)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 ChangeListener (javafx.beans.value.ChangeListener)1 ActionEvent (javafx.event.ActionEvent)1 FXML (javafx.fxml.FXML)1 FXMLLoader (javafx.fxml.FXMLLoader)1 Bounds (javafx.geometry.Bounds)1 ScrollPane (javafx.scene.control.ScrollPane)1 Slider (javafx.scene.control.Slider)1 TextField (javafx.scene.control.TextField)1 MouseEvent (javafx.scene.input.MouseEvent)1 Region (javafx.scene.layout.Region)1 StackPane (javafx.scene.layout.StackPane)1