Search in sources :

Example 1 with ChangeListener

use of javafx.beans.value.ChangeListener in project JFoenix by jfoenixadmin.

the class GenericEditableTreeTableCell method createEditorNode.

private void createEditorNode() {
    EventHandler<KeyEvent> keyEventsHandler = new EventHandler<KeyEvent>() {

        @Override
        public void handle(KeyEvent t) {
            if (t.getCode() == KeyCode.ENTER) {
                commitHelper(false);
            } else if (t.getCode() == KeyCode.ESCAPE) {
                cancelEdit();
            } else if (t.getCode() == KeyCode.TAB) {
                commitHelper(false);
                TreeTableColumn nextColumn = getNextColumn(!t.isShiftDown());
                if (nextColumn != null) {
                    getTreeTableView().edit(getIndex(), nextColumn);
                }
            }
        }
    };
    ChangeListener<Boolean> focusChangeListener = new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
            //of stopping the double commit.
            if (!newValue && editorNode != null) {
                commitHelper(true);
            }
        }
    };
    DoubleBinding minWidthBinding = Bindings.createDoubleBinding(() -> {
        return this.getWidth() - this.getGraphicTextGap() * 2 - this.getBaselineOffset();
    }, this.widthProperty(), this.graphicTextGapProperty());
    editorNode = builder.createNode(getValue(), minWidthBinding, keyEventsHandler, focusChangeListener);
}
Also used : KeyEvent(javafx.scene.input.KeyEvent) JFXTreeTableColumn(com.jfoenix.controls.JFXTreeTableColumn) TreeTableColumn(javafx.scene.control.TreeTableColumn) DoubleBinding(javafx.beans.binding.DoubleBinding) ObservableValue(javafx.beans.value.ObservableValue) EventHandler(javafx.event.EventHandler) ChangeListener(javafx.beans.value.ChangeListener)

Example 2 with ChangeListener

use of javafx.beans.value.ChangeListener in project fxexperience2 by EricCanull.

the class GradientPicker method initialize.

/**
     * Private
     */
private void initialize() {
    final FXMLLoader loader = new FXMLLoader();
    //NOI18N
    loader.setLocation(GradientPicker.class.getResource("/fxml/FXMLGradientPicker.fxml"));
    loader.setController(this);
    loader.setRoot(this);
    try {
        loader.load();
    } catch (IOException ex) {
        Logger.getLogger(GradientPicker.class.getName()).log(Level.SEVERE, null, ex);
    }
    assert proportional_checkbox != null;
    assert cycleMethod_choicebox != null;
    assert startX_slider != null;
    assert endX_slider != null;
    assert startY_slider != null;
    assert endY_slider != null;
    assert centerX_slider != null;
    assert centerY_slider != null;
    assert radial_container != null;
    // Add two default stops
    final GradientPickerStop black = addStop(0.0, 1.0, 0.0, Color.BLACK);
    addStop(0.0, 1.0, 1.0, Color.WHITE);
    // Select first default stop
    setSelectedStop(black);
    proportional_checkbox.setSelected(true);
    proportional_checkbox.selectedProperty().addListener((ov, oldValue, newValue) -> {
        final Mode mode = paintPicker.getMode();
        final Paint value = getValue(mode);
        // Update UI
        preview_rect.setFill(value);
        // Update model
        paintPicker.setPaintProperty(value);
    });
    proportional_checkbox.setOnAction((ActionEvent event) -> {
        event.consume();
    });
    cycleMethod_choicebox.setItems(FXCollections.observableArrayList(CycleMethod.values()));
    cycleMethod_choicebox.getSelectionModel().selectFirst();
    cycleMethod_choicebox.getSelectionModel().selectedItemProperty().addListener((ov, oldValue, newValue) -> {
        final Mode mode = paintPicker.getMode();
        final Paint value = getValue(mode);
        // Update UI
        preview_rect.setFill(value);
        // Update model
        paintPicker.setPaintProperty(value);
    });
    cycleMethod_choicebox.addEventHandler(ActionEvent.ACTION, (Event event) -> {
        event.consume();
    });
    final ChangeListener<Number> onValueChange = (ov, oldValue, newValue) -> {
        final Mode mode = paintPicker.getMode();
        final Paint value = getValue(mode);
        // Update UI
        preview_rect.setFill(value);
        // Update model
        paintPicker.setPaintProperty(value);
    };
    startX_slider.valueProperty().addListener(onValueChange);
    startY_slider.valueProperty().addListener(onValueChange);
    endX_slider.valueProperty().addListener(onValueChange);
    endY_slider.valueProperty().addListener(onValueChange);
    centerX_slider.valueProperty().addListener(onValueChange);
    centerY_slider.valueProperty().addListener(onValueChange);
    focusAngleRotator.rotationProperty().addListener(onValueChange);
    focusDistanceSlider.getSlider().valueProperty().addListener(onValueChange);
    radiusSlider.getSlider().valueProperty().addListener(onValueChange);
    radial_container.getChildren().addAll(radiusSlider, focusDistanceSlider, focusAngleRotator);
    radial_container.setVisible(false);
    radial_container.setManaged(false);
    final ChangeListener<Boolean> liveUpdateListener = (ov, oldValue, newValue) -> paintPicker.setLiveUpdate(newValue);
    startX_slider.pressedProperty().addListener(liveUpdateListener);
    startY_slider.pressedProperty().addListener(liveUpdateListener);
    endX_slider.pressedProperty().addListener(liveUpdateListener);
    endY_slider.pressedProperty().addListener(liveUpdateListener);
    centerX_slider.pressedProperty().addListener(liveUpdateListener);
    centerY_slider.pressedProperty().addListener(liveUpdateListener);
    radiusSlider.pressedProperty().addListener(liveUpdateListener);
    focusDistanceSlider.pressedProperty().addListener(liveUpdateListener);
    focusAngleRotator.pressedProperty().addListener(liveUpdateListener);
    slider_container.pressedProperty().addListener(liveUpdateListener);
}
Also used : Mode(com.fxexperience.javafx.scene.control.paintpicker.PaintPicker.Mode) RotatorControl(com.fxexperience.javafx.scene.control.rotator.RotatorControl) MouseEvent(javafx.scene.input.MouseEvent) FXCollections(javafx.collections.FXCollections) StackPane(javafx.scene.layout.StackPane) VBox(javafx.scene.layout.VBox) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) PaintPickerController(com.fxexperience.javafx.scene.control.paintpicker.PaintPickerController) Slider(javafx.scene.control.Slider) FXMLLoader(javafx.fxml.FXMLLoader) Pane(javafx.scene.layout.Pane) HBox(javafx.scene.layout.HBox) Label(javafx.scene.control.Label) Event(javafx.event.Event) CheckBox(javafx.scene.control.CheckBox) Rectangle(javafx.scene.shape.Rectangle) IOException(java.io.IOException) javafx.scene.paint(javafx.scene.paint) Logger(java.util.logging.Logger) ChoiceBox(javafx.scene.control.ChoiceBox) FXML(javafx.fxml.FXML) List(java.util.List) ActionEvent(javafx.event.ActionEvent) SliderControl(com.fxexperience.javafx.scene.control.slider.SliderControl) ChangeListener(javafx.beans.value.ChangeListener) ActionEvent(javafx.event.ActionEvent) Mode(com.fxexperience.javafx.scene.control.paintpicker.PaintPicker.Mode) IOException(java.io.IOException) FXMLLoader(javafx.fxml.FXMLLoader) MouseEvent(javafx.scene.input.MouseEvent) Event(javafx.event.Event) ActionEvent(javafx.event.ActionEvent)

Example 3 with ChangeListener

use of javafx.beans.value.ChangeListener 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 4 with ChangeListener

use of javafx.beans.value.ChangeListener in project azure-tools-for-java by Microsoft.

the class JobViewFxUtil method startFx.

public static Object startFx(Object composite, final String webUrl, Object jobUtils) {
    try {
        Class compositeClass = Class.forName("org.eclipse.swt.widgets.Composite");
        Class[] paramTypes = { compositeClass, int.class };
        Constructor con = FXCanvas.class.getConstructor(paramTypes);
        Object[] parames = { composite, 1 << 16 };
        final FXCanvas canvas = (FXCanvas) con.newInstance(parames);
        Platform.setImplicitExit(false);
        Platform.runLater(new Runnable() {

            @Override
            public void run() {
                final WebView webView = new WebView();
                Scene scene = new Scene(webView);
                canvas.setScene(scene);
                WebEngine webEngine = webView.getEngine();
                webEngine.load(webUrl);
                webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>() {

                    @Override
                    public void changed(ObservableValue<? extends Worker.State> ov, Worker.State oldState, Worker.State newState) {
                        if (newState == Worker.State.SUCCEEDED) {
                            JSObject win = (JSObject) webEngine.executeScript("window");
                            win.setMember("JobUtils", new JobUtilsForEclipse());
                        }
                    }
                });
            }
        });
        return canvas;
    } catch (Exception e) {
        return e;
    }
}
Also used : Constructor(java.lang.reflect.Constructor) ObservableValue(javafx.beans.value.ObservableValue) JSObject(netscape.javascript.JSObject) Scene(javafx.scene.Scene) WebEngine(javafx.scene.web.WebEngine) Worker(javafx.concurrent.Worker) JSObject(netscape.javascript.JSObject) ChangeListener(javafx.beans.value.ChangeListener) FXCanvas(javafx.embed.swt.FXCanvas) WebView(javafx.scene.web.WebView)

Example 5 with ChangeListener

use of javafx.beans.value.ChangeListener in project intellij-plugins by StepicOrg.

the class AuthDialog method makeProgressBarWithListener.

@NotNull
private ProgressBar makeProgressBarWithListener() {
    final ProgressBar progress = new ProgressBar();
    Worker<Void> loadWorker = engine.getLoadWorker();
    progress.progressProperty().bind(loadWorker.progressProperty());
    loadWorker.stateProperty().addListener(new ChangeListener<Worker.State>() {

        @Override
        public void changed(ObservableValue<? extends Worker.State> ov, Worker.State oldState, Worker.State newState) {
            if (newState == Worker.State.CANCELLED) {
                return;
            }
            if (newState == Worker.State.FAILED) {
                Map<String, Object> map = new HashMap<>();
                map.put("url", engine.getLocation());
                String content = Templater.processTemplate("error", map);
                engine.loadContent(content);
                return;
            }
            String location = engine.getLocation();
            if (location != null) {
                if (location.startsWith(Urls.STEPIK_URL + "/#")) {
                    String paramString = location.split("#")[1];
                    String[] params = paramString.split("&");
                    map.clear();
                    Arrays.stream(params).forEach(param -> {
                        String[] entry = param.split("=");
                        String value = "";
                        if (entry.length > 1) {
                            value = entry[1];
                        }
                        map.put(entry[0], value);
                    });
                    hide();
                    return;
                } else if ((Urls.STEPIK_URL + "/?error=access_denied").equals(location)) {
                    map.put("error", "access_denied");
                    hide();
                    return;
                }
            }
            progressBar.setVisible(newState == Worker.State.RUNNING);
            if (newState == Worker.State.SUCCEEDED) {
                AuthDialog.this.setTitle(engine.getTitle());
            }
        }

        private void hide() {
            loadWorker.cancel();
            setVisible(false);
        }
    });
    return progress;
}
Also used : Button(javafx.scene.control.Button) Worker(javafx.concurrent.Worker) Pos(javafx.geometry.Pos) Scene(javafx.scene.Scene) WebEngine(javafx.scene.web.WebEngine) Arrays(java.util.Arrays) AllIcons(com.intellij.icons.AllIcons) HashMap(java.util.HashMap) JFXPanel(javafx.embed.swing.JFXPanel) CookieManager(org.stepik.plugin.auth.webkit.network.CookieManager) Insets(javafx.geometry.Insets) ProgressBar(javafx.scene.control.ProgressBar) CookieHandler(java.net.CookieHandler) Map(java.util.Map) Tooltip(javafx.scene.control.Tooltip) HBox(javafx.scene.layout.HBox) WebView(javafx.scene.web.WebView) WebHistory(javafx.scene.web.WebHistory) BufferedImage(java.awt.image.BufferedImage) Node(javafx.scene.Node) WritableImage(javafx.scene.image.WritableImage) Platform(javafx.application.Platform) java.awt(java.awt) Urls(org.stepik.api.urls.Urls) ImageView(javafx.scene.image.ImageView) SwingFXUtils(javafx.embed.swing.SwingFXUtils) ObservableValue(javafx.beans.value.ObservableValue) Templater(org.stepik.core.templates.Templater) BorderPane(javafx.scene.layout.BorderPane) StepikAuthManager(org.stepik.core.stepik.StepikAuthManager) ChangeListener(javafx.beans.value.ChangeListener) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) Worker(javafx.concurrent.Worker) ProgressBar(javafx.scene.control.ProgressBar) HashMap(java.util.HashMap) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ChangeListener (javafx.beans.value.ChangeListener)25 ObservableValue (javafx.beans.value.ObservableValue)11 ObservableList (javafx.collections.ObservableList)11 FXCollections (javafx.collections.FXCollections)10 FXML (javafx.fxml.FXML)10 ResourceBundle (java.util.ResourceBundle)8 Platform (javafx.application.Platform)8 Stage (javafx.stage.Stage)8 List (java.util.List)7 Scene (javafx.scene.Scene)7 Account (jgnash.engine.Account)7 BigDecimal (java.math.BigDecimal)6 NumberFormat (java.text.NumberFormat)6 Objects (java.util.Objects)6 Preferences (java.util.prefs.Preferences)6 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)6 Tooltip (javafx.scene.control.Tooltip)6 ImageView (javafx.scene.image.ImageView)6 Engine (jgnash.engine.Engine)6 EngineFactory (jgnash.engine.EngineFactory)6