Search in sources :

Example 16 with ListChangeListener

use of javafx.collections.ListChangeListener in project org.csstudio.display.builder by kasemir.

the class RulesDialog method createContent.

private SplitPane createContent() {
    final Node rules = createRulesTable();
    final HBox pvs = createPVsTable();
    final HBox exprs = createExpressionsTable();
    // Display PVs of currently selected rule
    rules_table.getSelectionModel().selectedItemProperty().addListener((prop, old, selected) -> {
        selected_rule_item = selected;
        if (selected == null) {
            pvs.setDisable(true);
            exprs.setDisable(true);
            btn_remove_rule.setDisable(true);
            btn_dup_rule.setDisable(true);
            btn_move_rule_up.setDisable(true);
            btn_move_rule_down.setDisable(true);
            btn_show_script.setDisable(true);
            propComboBox.setDisable(true);
            propComboBox.getSelectionModel().select(null);
            valExpBox.setDisable(true);
            pv_items.clear();
            expression_items.clear();
        } else {
            pvs.setDisable(false);
            exprs.setDisable(false);
            final TableViewSelectionModel<RuleItem> model = rules_table.getSelectionModel();
            btn_remove_rule.setDisable(false);
            btn_dup_rule.setDisable(false);
            btn_move_rule_up.setDisable(model.getSelectedIndex() == 0);
            btn_move_rule_down.setDisable(model.getSelectedIndex() == rule_items.size() - 1);
            btn_show_script.setDisable(false);
            propComboBox.setDisable(false);
            propComboBox.getSelectionModel().select(getPropLongString(selected));
            valExpBox.setDisable(false);
            valExpBox.selectedProperty().set(selected.prop_as_expr.get());
            pv_items.setAll(selected.pvs);
            expression_items.setAll(selected.expressions);
            fixupPVs(0);
        }
    });
    // Update PVs of selected rule from PVs table
    final ListChangeListener<PVTableItem> pll = change -> {
        final RuleItem selected = rules_table.getSelectionModel().getSelectedItem();
        if (selected != null)
            selected.pvs = new ArrayList<>(change.getList());
    };
    pv_items.addListener(pll);
    // Update buttons for currently selected PV
    pvs_table.getSelectionModel().selectedItemProperty().addListener((prop, old, selected) -> {
        if (selected == null) {
            btn_rm_pv.setDisable(true);
            btn_move_pv_up.setDisable(true);
            btn_move_pv_down.setDisable(true);
        } else {
            final TableViewSelectionModel<PVTableItem> model = pvs_table.getSelectionModel();
            btn_rm_pv.setDisable(false);
            btn_move_pv_up.setDisable(model.getSelectedIndex() == 0);
            btn_move_pv_down.setDisable(model.getSelectedIndex() == pv_items.size() - 1);
        }
    });
    // Update Expressions of selected rule from Expressions table
    final ListChangeListener<ExprItem<?>> ell = change -> {
        final RuleItem selected = rules_table.getSelectionModel().getSelectedItem();
        if (selected != null)
            selected.expressions = new ArrayList<>(change.getList());
    };
    expression_items.addListener(ell);
    // Update buttons for currently selected expression
    expressions_table.getSelectionModel().selectedItemProperty().addListener((prop, old, selected) -> {
        if (selected == null) {
            btn_rm_exp.setDisable(true);
            btn_move_exp_up.setDisable(true);
            btn_move_exp_down.setDisable(true);
        } else {
            final TableViewSelectionModel<ExprItem<?>> model = expressions_table.getSelectionModel();
            btn_rm_exp.setDisable(false);
            btn_move_exp_up.setDisable(model.getSelectedIndex() == 0);
            btn_move_exp_down.setDisable(model.getSelectedIndex() == expression_items.size() - 1);
        }
    });
    // What is the property id option we are using?
    final Label propLabel = new Label("Property ID:");
    // Show each property with current value
    final ObservableList<String> prop_id_opts = FXCollections.observableArrayList();
    for (PropInfo pi : propinfo_ls) {
        // Property _value_ can be long, ex. points of a polyline
        // Truncate the value that's shown in the combo box
        // to prevent combo from using all screen width.
        String prop_opt = pi.toString();
        if (prop_opt.length() > MAX_PROP_LENGTH)
            prop_opt = prop_opt.substring(0, MAX_PROP_LENGTH) + "...";
        prop_id_opts.add(prop_opt);
    }
    propComboBox = new ComboBox<String>(prop_id_opts);
    propComboBox.setDisable(true);
    propComboBox.getSelectionModel().selectedIndexProperty().addListener((p, o, index) -> {
        // Select property info based on index within combo.
        final int idx = index.intValue();
        if (idx >= 0) {
            final PropInfo prop = propinfo_ls.get(idx);
            if (selected_rule_item.tryUpdatePropID(undo, prop.getPropID()))
                expression_items.setAll(selected_rule_item.expressions);
        }
    });
    propComboBox.setMinHeight(27);
    propComboBox.setMaxWidth(Double.MAX_VALUE);
    HBox.setHgrow(propComboBox, Priority.ALWAYS);
    // TODO: change this to actually manipulate expression objects in the rule
    valExpBox = new CheckBox("Value as Expression");
    valExpBox.setDisable(true);
    valExpBox.selectedProperty().addListener((ov, old_val, new_val) -> {
        if (!selected_rule_item.tryTogglePropAsExpr(undo, new_val))
            logger.log(Level.FINE, "Did not update rule property as expression flag to " + new_val);
        else
            expression_items.setAll(selected_rule_item.expressions);
    });
    final Region spring = new Region();
    HBox.setHgrow(spring, Priority.ALWAYS);
    final HBox props = new HBox(10, propLabel, propComboBox, spring, valExpBox);
    props.setAlignment(Pos.CENTER);
    pvs.setPadding(new Insets(0, 10, 0, 0));
    exprs.setPadding(new Insets(0, 0, 0, 10));
    HBox.setHgrow(pvs, Priority.ALWAYS);
    HBox.setHgrow(exprs, Priority.ALWAYS);
    final Preferences pref = Preferences.userNodeForPackage(RulesDialog.class);
    final double prefRSPDividerPosition = pref.getDouble("rule.content.divider.position", 0.5);
    ruleSplitPane = new SplitPane(pvs, exprs);
    ruleSplitPane.setOrientation(Orientation.HORIZONTAL);
    ruleSplitPane.setDividerPositions(prefRSPDividerPosition);
    ruleSplitPane.setStyle("-fx-background-insets: 0, 0;");
    VBox.setVgrow(ruleSplitPane, Priority.ALWAYS);
    final VBox subitems = new VBox(10, props, ruleSplitPane);
    final VBox rulebox = new VBox(10, rules);
    rulebox.setPadding(new Insets(0, 10, 0, 0));
    subitems.setPadding(new Insets(0, 0, 0, 10));
    VBox.setVgrow(rules, Priority.ALWAYS);
    HBox.setHgrow(subitems, Priority.ALWAYS);
    final double prefWidth = pref.getDouble("content.width", -1);
    final double prefHeight = pref.getDouble("content.height", -1);
    final double prefDividerPosition = pref.getDouble("content.divider.position", 0.3);
    final SplitPane splitPane = new SplitPane(rulebox, subitems);
    splitPane.setOrientation(Orientation.HORIZONTAL);
    splitPane.setDividerPositions(prefDividerPosition);
    if (prefWidth > 0 && prefHeight > 0)
        splitPane.setPrefSize(prefWidth, prefHeight);
    // Select the first rule
    if (!rules_table.getItems().isEmpty()) {
        Platform.runLater(() -> {
            rules_table.getSelectionModel().select(0);
            rules_table.requestFocus();
        });
    } else
        Platform.runLater(() -> btn_add_rule.requestFocus());
    return splitPane;
}
Also used : Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) UndoableActionManager(org.csstudio.display.builder.util.undo.UndoableActionManager) ScriptPV(org.csstudio.display.builder.model.properties.ScriptPV) LineNumberTableCellFactory(org.csstudio.javafx.LineNumberTableCellFactory) VBox(javafx.scene.layout.VBox) AutoCompletedTableCell(org.csstudio.display.builder.representation.javafx.PVTableItem.AutoCompletedTableCell) RuleInfo(org.csstudio.display.builder.model.rules.RuleInfo) TableHelper(org.csstudio.javafx.TableHelper) ListChangeListener(javafx.collections.ListChangeListener) ComboBox(javafx.scene.control.ComboBox) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) TableView(javafx.scene.control.TableView) ModelThreadPool(org.csstudio.display.builder.model.util.ModelThreadPool) Pane(javafx.scene.layout.Pane) Orientation(javafx.geometry.Orientation) HBox(javafx.scene.layout.HBox) PVTableItem(org.csstudio.display.builder.representation.javafx.PVTableItem) SplitPane(javafx.scene.control.SplitPane) TextField(javafx.scene.control.TextField) Language(org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog.Language) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) Collectors(java.util.stream.Collectors) CommonWidgetProperties(org.csstudio.display.builder.model.properties.CommonWidgetProperties) Platform(javafx.application.Platform) Priority(javafx.scene.layout.Priority) List(java.util.List) BooleanProperty(javafx.beans.property.BooleanProperty) Region(javafx.scene.layout.Region) CheckBoxTableCell(javafx.scene.control.cell.CheckBoxTableCell) AutocompleteMenu(org.csstudio.display.builder.representation.javafx.AutocompleteMenu) JFXUtil(org.csstudio.display.builder.representation.javafx.JFXUtil) ObservableList(javafx.collections.ObservableList) DefaultStringConverter(javafx.util.converter.DefaultStringConverter) ExprInfoString(org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoString) StringProperty(javafx.beans.property.StringProperty) ExpressionInfo(org.csstudio.display.builder.model.rules.RuleInfo.ExpressionInfo) TableViewSelectionModel(javafx.scene.control.TableView.TableViewSelectionModel) SyntaxHighlightedMultiLineInputDialog(org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog) ExprInfoValue(org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoValue) Plugin.logger(org.csstudio.display.builder.editor.Plugin.logger) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) ButtonType(javafx.scene.control.ButtonType) JFXBaseRepresentation(org.csstudio.display.builder.representation.javafx.widgets.JFXBaseRepresentation) FXCollections(javafx.collections.FXCollections) BackingStoreException(java.util.prefs.BackingStoreException) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TableColumn(javafx.scene.control.TableColumn) RulesWidgetProperty(org.csstudio.display.builder.model.properties.RulesWidgetProperty) Messages(org.csstudio.display.builder.representation.javafx.Messages) TableCell(javafx.scene.control.TableCell) Insets(javafx.geometry.Insets) Tooltip(javafx.scene.control.Tooltip) Dialog(javafx.scene.control.Dialog) Label(javafx.scene.control.Label) Node(javafx.scene.Node) CheckBox(javafx.scene.control.CheckBox) Preferences(java.util.prefs.Preferences) TimeUnit(java.util.concurrent.TimeUnit) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ScriptsDialog(org.csstudio.display.builder.representation.javafx.ScriptsDialog) DialogHelper(org.csstudio.javafx.DialogHelper) Widget(org.csstudio.display.builder.model.Widget) ChangeListener(javafx.beans.value.ChangeListener) PropInfo(org.csstudio.display.builder.model.rules.RuleInfo.PropInfo) HBox(javafx.scene.layout.HBox) Insets(javafx.geometry.Insets) Node(javafx.scene.Node) Label(javafx.scene.control.Label) PropInfo(org.csstudio.display.builder.model.rules.RuleInfo.PropInfo) ExprInfoString(org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoString) SplitPane(javafx.scene.control.SplitPane) PVTableItem(org.csstudio.display.builder.representation.javafx.PVTableItem) Preferences(java.util.prefs.Preferences) CheckBox(javafx.scene.control.CheckBox) Region(javafx.scene.layout.Region) VBox(javafx.scene.layout.VBox)

Example 17 with ListChangeListener

use of javafx.collections.ListChangeListener in project org.csstudio.display.builder by kasemir.

the class ScriptsDialog method createContent.

private SplitPane createContent() {
    final Region scripts = createScriptsTable();
    final Region pvs = createPVsTable();
    // Display PVs of currently selected script
    scripts_table.getSelectionModel().selectedItemProperty().addListener((prop, old, selected) -> {
        selected_script_item = selected;
        if (selected == null) {
            btn_script_remove.setDisable(true);
            btn_edit.setDisable(true);
            pvs.setDisable(true);
            pv_items.clear();
        } else {
            btn_script_remove.setDisable(false);
            btn_edit.setDisable(false);
            pvs.setDisable(false);
            btn_check_connections.setSelected(selected.check_connections);
            pv_items.setAll(selected.pvs);
            fixupPVs(0);
            if (ScriptInfo.isEmbedded(selected.getScriptInfo().getPath())) {
                scripts_table.setEditable(false);
                btn_edit.setText(Messages.Edit);
                btn_edit.setGraphic(JFXUtil.getIcon("edit.png"));
                if (ScriptInfo.isJython(selected.getScriptInfo().getPath())) {
                    convertToFileMenuItem.setDisable(false);
                    convertToEmbeddedPythonMenuItem.setDisable(true);
                    convertToEmbeddedJavaScriptMenuItem.setDisable(false);
                } else if (ScriptInfo.isJavaScript(selected.getScriptInfo().getPath())) {
                    convertToFileMenuItem.setDisable(false);
                    convertToEmbeddedPythonMenuItem.setDisable(false);
                    convertToEmbeddedJavaScriptMenuItem.setDisable(true);
                } else {
                    convertToFileMenuItem.setDisable(true);
                    convertToEmbeddedPythonMenuItem.setDisable(true);
                    convertToEmbeddedJavaScriptMenuItem.setDisable(true);
                }
            } else {
                scripts_table.setEditable(true);
                btn_edit.setText(Messages.Select);
                btn_edit.setGraphic(JFXUtil.getIcon("select-file.png"));
                convertToFileMenuItem.setDisable(true);
                convertToEmbeddedPythonMenuItem.setDisable(false);
                convertToEmbeddedJavaScriptMenuItem.setDisable(false);
            }
        }
    });
    // Update PVs of selected script from PVs table
    final ListChangeListener<PVTableItem> ll = change -> {
        final ScriptItem selected = scripts_table.getSelectionModel().getSelectedItem();
        if (selected != null)
            selected.pvs = new ArrayList<>(change.getList());
    };
    pv_items.addListener(ll);
    // Update buttons for currently selected PV
    pvs_table.getSelectionModel().selectedItemProperty().addListener((prop, old, selected) -> {
        if (selected == null) {
            btn_pv_remove.setDisable(true);
            btn_pv_up.setDisable(true);
            btn_py_down.setDisable(true);
        } else {
            final TableViewSelectionModel<PVTableItem> model = pvs_table.getSelectionModel();
            btn_pv_remove.setDisable(false);
            btn_pv_up.setDisable(model.getSelectedIndex() == 0);
            btn_py_down.setDisable(model.getSelectedIndex() == pv_items.size() - 1);
        }
    });
    scripts.setPadding(new Insets(0, 10, 0, 0));
    pvs.setPadding(new Insets(0, 0, 0, 10));
    final Preferences pref = Preferences.userNodeForPackage(ScriptsDialog.class);
    double prefWidth = pref.getDouble("content.width", -1);
    double prefHeight = pref.getDouble("content.height", -1);
    double prefDividerPosition = pref.getDouble("content.divider.position", 0.5);
    final SplitPane splitPane = new SplitPane(scripts, pvs);
    splitPane.setDividerPositions(prefDividerPosition);
    if (prefWidth > 0 && prefHeight > 0)
        splitPane.setPrefSize(prefWidth, prefHeight);
    // Select the first script
    if (!scripts_table.getItems().isEmpty()) {
        Platform.runLater(() -> {
            scripts_table.getSelectionModel().select(0);
            scripts_table.requestFocus();
        });
    } else
        Platform.runLater(() -> addMenuButton.requestFocus());
    return splitPane;
}
Also used : Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) ScriptPV(org.csstudio.display.builder.model.properties.ScriptPV) LineNumberTableCellFactory(org.csstudio.javafx.LineNumberTableCellFactory) VBox(javafx.scene.layout.VBox) AutoCompletedTableCell(org.csstudio.display.builder.representation.javafx.PVTableItem.AutoCompletedTableCell) TableHelper(org.csstudio.javafx.TableHelper) ListChangeListener(javafx.collections.ListChangeListener) TableView(javafx.scene.control.TableView) ModelThreadPool(org.csstudio.display.builder.model.util.ModelThreadPool) HBox(javafx.scene.layout.HBox) SplitPane(javafx.scene.control.SplitPane) TextField(javafx.scene.control.TextField) MenuItem(javafx.scene.control.MenuItem) Language(org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog.Language) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) Collectors(java.util.stream.Collectors) Platform(javafx.application.Platform) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) Priority(javafx.scene.layout.Priority) List(java.util.List) Region(javafx.scene.layout.Region) CheckBoxTableCell(javafx.scene.control.cell.CheckBoxTableCell) MenuButton(javafx.scene.control.MenuButton) ObservableList(javafx.collections.ObservableList) DefaultStringConverter(javafx.util.converter.DefaultStringConverter) StringProperty(javafx.beans.property.StringProperty) TableViewSelectionModel(javafx.scene.control.TableView.TableViewSelectionModel) SyntaxHighlightedMultiLineInputDialog(org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) ButtonType(javafx.scene.control.ButtonType) JFXBaseRepresentation(org.csstudio.display.builder.representation.javafx.widgets.JFXBaseRepresentation) FXCollections(javafx.collections.FXCollections) BackingStoreException(java.util.prefs.BackingStoreException) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) Bindings(javafx.beans.binding.Bindings) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TableColumn(javafx.scene.control.TableColumn) TableCell(javafx.scene.control.TableCell) Insets(javafx.geometry.Insets) Tooltip(javafx.scene.control.Tooltip) ScriptInfo(org.csstudio.display.builder.model.properties.ScriptInfo) Dialog(javafx.scene.control.Dialog) Label(javafx.scene.control.Label) SplitMenuButton(javafx.scene.control.SplitMenuButton) Node(javafx.scene.Node) CheckBox(javafx.scene.control.CheckBox) Preferences(java.util.prefs.Preferences) ToolkitRepresentation.logger(org.csstudio.display.builder.representation.ToolkitRepresentation.logger) TimeUnit(java.util.concurrent.TimeUnit) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ImageView(javafx.scene.image.ImageView) DialogHelper(org.csstudio.javafx.DialogHelper) Widget(org.csstudio.display.builder.model.Widget) ChangeListener(javafx.beans.value.ChangeListener) Insets(javafx.geometry.Insets) Region(javafx.scene.layout.Region) SplitPane(javafx.scene.control.SplitPane) Preferences(java.util.prefs.Preferences)

Example 18 with ListChangeListener

use of javafx.collections.ListChangeListener in project Board-Instrumentation-Framework by intel.

the class GaugeSkin method registerListeners.

private void registerListeners() {
    getSkinnable().widthProperty().addListener(observable -> handleControlPropertyChanged("RESIZE"));
    getSkinnable().heightProperty().addListener(observable -> handleControlPropertyChanged("RESIZE"));
    getSkinnable().minMeasuredValueProperty().addListener(observable -> handleControlPropertyChanged("MIN_MEASURED_VALUE"));
    getSkinnable().minMeasuredValueVisibleProperty().addListener(observable -> handleControlPropertyChanged("MIN_MEASURED_VALUE_VISIBLE"));
    getSkinnable().maxMeasuredValueProperty().addListener(observable -> handleControlPropertyChanged("MAX_MEASURED_VALUE"));
    getSkinnable().maxMeasuredValueVisibleProperty().addListener(observable -> handleControlPropertyChanged("MAX_MEASURED_VALUE_VISIBLE"));
    getSkinnable().tickLabelOrientationProperty().addListener(observable -> handleControlPropertyChanged("RESIZE"));
    getSkinnable().needleTypeProperty().addListener(observable -> handleControlPropertyChanged("NEEDLE_TYPE"));
    getSkinnable().needleColorProperty().addListener(observable -> handleControlPropertyChanged("NEEDLE_COLOR"));
    getSkinnable().animatedProperty().addListener(observable -> handleControlPropertyChanged("ANIMATED"));
    getSkinnable().thresholdProperty().addListener(observable -> handleControlPropertyChanged("THRESHOLD"));
    getSkinnable().thresholdVisibleProperty().addListener(observable -> handleControlPropertyChanged("THRESHOLD_VISIBLE"));
    getSkinnable().angleRangeProperty().addListener(observable -> handleControlPropertyChanged("ANGLE_RANGE"));
    getSkinnable().numberFormatProperty().addListener(observable -> handleControlPropertyChanged("RECALC"));
    getSkinnable().plainValueProperty().addListener(observable -> handleControlPropertyChanged("PLAIN_VALUE"));
    getSkinnable().histogramEnabledProperty().addListener(observable -> handleControlPropertyChanged("HISTOGRAM"));
    getSkinnable().dropShadowEnabledProperty().addListener(observable -> handleControlPropertyChanged("DROP_SHADOW"));
    getSkinnable().interactiveProperty().addListener(observable -> handleControlPropertyChanged("INTERACTIVE"));
    getSkinnable().getSections().addListener((ListChangeListener<Section>) change -> handleControlPropertyChanged("CANVAS_REFRESH"));
    getSkinnable().getAreas().addListener((ListChangeListener<Section>) change -> handleControlPropertyChanged("CANVAS_REFRESH"));
    getSkinnable().getMarkers().addListener((MapChangeListener<Marker, Rotate>) change -> handleControlPropertyChanged("MARKER"));
    getSkinnable().markersVisibleProperty().addListener(observable -> handleControlPropertyChanged("MARKER"));
    getSkinnable().sectionsVisibleProperty().addListener(observable -> handleControlPropertyChanged("CANVAS_REFRESH"));
    getSkinnable().areasVisibleProperty().addListener(observable -> handleControlPropertyChanged("CANVAS_REFRESH"));
    getSkinnable().customKnobClickHandlerProperty().addListener(observable -> handleControlPropertyChanged("CUSTOM_KNOB_CLICK_HANDLER"));
    getSkinnable().valueProperty().addListener((OV, OLD_VALUE, NEW_VALUE) -> {
        withinSpeedLimit = !(Instant.now().minusMillis((long) getSkinnable().getAnimationDuration()).isBefore(lastCall));
        lastCall = Instant.now();
        oldValue = OLD_VALUE.doubleValue();
        rotateNeedle();
    });
    getSkinnable().minValueProperty().addListener((OV, OLD_VALUE, NEW_VALUE) -> {
        angleStep = getSkinnable().getAngleRange() / (getSkinnable().getMaxValue() - NEW_VALUE.doubleValue());
        needleRotate.setAngle((180 - getSkinnable().getStartAngle()) + (getSkinnable().getValue() - NEW_VALUE.doubleValue()) * angleStep);
        if (getSkinnable().getValue() < NEW_VALUE.doubleValue()) {
            getSkinnable().setValue(NEW_VALUE.doubleValue());
            oldValue = NEW_VALUE.doubleValue();
        }
    });
    getSkinnable().maxValueProperty().addListener((OV, OLD_VALUE, NEW_VALUE) -> {
        angleStep = getSkinnable().getAngleRange() / (NEW_VALUE.doubleValue() - getSkinnable().getMinValue());
        needleRotate.setAngle((180 - getSkinnable().getStartAngle()) + (getSkinnable().getValue() - getSkinnable().getMinValue()) * angleStep);
        if (getSkinnable().getValue() > NEW_VALUE.doubleValue()) {
            getSkinnable().setValue(NEW_VALUE.doubleValue());
            oldValue = NEW_VALUE.doubleValue();
        }
    });
    getSkinnable().limitProperty().addListener(observable -> handleControlPropertyChanged("LIMIT"));
    needleRotate.angleProperty().addListener(observable -> handleControlPropertyChanged("ANGLE"));
    if (null == getSkinnable().getCustomKnobClickHandler()) {
        knob.setOnMousePressed(event -> {
            timeline.stop();
            needleRotate.setAngle(180 - getSkinnable().getStartAngle() + (getSkinnable().getValue() - getSkinnable().getMinValue()) * angleStep);
            getSkinnable().setInteractive(!getSkinnable().isInteractive());
        });
    } else {
        knob.setOnMousePressed(getSkinnable().getCustomKnobClickHandler());
    }
    minMeasuredValue.setOnMousePressed(mouseEventHandler);
    minMeasuredValue.setOnMouseReleased(mouseEventHandler);
    maxMeasuredValue.setOnMousePressed(mouseEventHandler);
    maxMeasuredValue.setOnMouseReleased(mouseEventHandler);
    threshold.setOnMousePressed(mouseEventHandler);
    threshold.setOnMouseDragged(mouseEventHandler);
    threshold.setOnMouseReleased(mouseEventHandler);
    for (Marker marker : getSkinnable().getMarkers().keySet()) {
        marker.setOnMousePressed(mouseEventHandler);
        marker.setOnMouseDragged(mouseEventHandler);
        marker.setOnMouseReleased(mouseEventHandler);
    }
}
Also used : EventHandler(javafx.event.EventHandler) CacheHint(javafx.scene.CacheHint) Rotate(javafx.scene.transform.Rotate) ArcTo(javafx.scene.shape.ArcTo) BlendMode(javafx.scene.effect.BlendMode) ListChangeListener(javafx.collections.ListChangeListener) Locale(java.util.Locale) Point2D(javafx.geometry.Point2D) Pane(javafx.scene.layout.Pane) GraphicsContext(javafx.scene.canvas.GraphicsContext) MapChangeListener(javafx.collections.MapChangeListener) Blend(javafx.scene.effect.Blend) Font(javafx.scene.text.Font) Timeline(javafx.animation.Timeline) Canvas(javafx.scene.canvas.Canvas) Group(javafx.scene.Group) Instant(java.time.Instant) ArcType(javafx.scene.shape.ArcType) Text(javafx.scene.text.Text) Marker(eu.hansolo.enzo.common.Marker) Duration(javafx.util.Duration) List(java.util.List) Region(javafx.scene.layout.Region) Interpolator(javafx.animation.Interpolator) PauseTransition(javafx.animation.PauseTransition) TouchEvent(javafx.scene.input.TouchEvent) StrokeLineCap(javafx.scene.shape.StrokeLineCap) ObservableList(javafx.collections.ObservableList) Path(javafx.scene.shape.Path) FontWeight(javafx.scene.text.FontWeight) IntStream(java.util.stream.IntStream) SkinBase(javafx.scene.control.SkinBase) Gauge(eu.hansolo.enzo.gauge.Gauge) CubicCurve(javafx.scene.shape.CubicCurve) PathTransition(javafx.animation.PathTransition) MouseEvent(javafx.scene.input.MouseEvent) FXCollections(javafx.collections.FXCollections) Skin(javafx.scene.control.Skin) ArrayList(java.util.ArrayList) FadeTransition(javafx.animation.FadeTransition) ValueEvent(eu.hansolo.enzo.common.ValueEvent) VPos(javafx.geometry.VPos) BlurType(javafx.scene.effect.BlurType) TextAlignment(javafx.scene.text.TextAlignment) KeyValue(javafx.animation.KeyValue) InnerShadow(javafx.scene.effect.InnerShadow) Color(javafx.scene.paint.Color) KeyFrame(javafx.animation.KeyFrame) Section(eu.hansolo.enzo.common.Section) Node(javafx.scene.Node) DropShadow(javafx.scene.effect.DropShadow) Fonts(eu.hansolo.enzo.fonts.Fonts) EventType(javafx.event.EventType) ParallelTransition(javafx.animation.ParallelTransition) SequentialTransition(javafx.animation.SequentialTransition) Arc(javafx.scene.shape.Arc) FillRule(javafx.scene.shape.FillRule) Shape(javafx.scene.shape.Shape) Rotate(javafx.scene.transform.Rotate) Marker(eu.hansolo.enzo.common.Marker) Section(eu.hansolo.enzo.common.Section)

Example 19 with ListChangeListener

use of javafx.collections.ListChangeListener in project Board-Instrumentation-Framework by intel.

the class RadialBargraphSkin method registerListeners.

private void registerListeners() {
    getSkinnable().widthProperty().addListener(observable -> handleControlPropertyChanged("RESIZE"));
    getSkinnable().heightProperty().addListener(observable -> handleControlPropertyChanged("RESIZE"));
    getSkinnable().valueProperty().addListener(observable -> handleControlPropertyChanged("VALUE"));
    getSkinnable().minValueProperty().addListener(observable -> handleControlPropertyChanged("RECALC"));
    getSkinnable().maxValueProperty().addListener(observable -> handleControlPropertyChanged("RECALC"));
    getSkinnable().minMeasuredValueProperty().addListener(observable -> handleControlPropertyChanged("MIN_MEASURED_VALUE"));
    getSkinnable().minMeasuredValueVisibleProperty().addListener(observable -> handleControlPropertyChanged("MIN_MEASURED_VALUE_VISIBLE"));
    getSkinnable().maxMeasuredValueProperty().addListener(observable -> handleControlPropertyChanged("MAX_MEASURED_VALUE"));
    getSkinnable().maxMeasuredValueVisibleProperty().addListener(observable -> handleControlPropertyChanged("MAX_MEASURED_VALUE_VISIBLE"));
    getSkinnable().barColorProperty().addListener(observable -> handleControlPropertyChanged("BAR_COLOR"));
    getSkinnable().animatedProperty().addListener(observable -> handleControlPropertyChanged("ANIMATED"));
    getSkinnable().thresholdProperty().addListener(observable -> handleControlPropertyChanged("THRESHOLD"));
    getSkinnable().thresholdVisibleProperty().addListener(observable -> handleControlPropertyChanged("THRESHOLD_VISIBLE"));
    getSkinnable().angleRangeProperty().addListener(observable -> handleControlPropertyChanged("ANGLE_RANGE"));
    getSkinnable().numberFormatProperty().addListener(observable -> handleControlPropertyChanged("RECALC"));
    getSkinnable().plainValueProperty().addListener(observable -> handleControlPropertyChanged("PLAIN_VALUE"));
    getSkinnable().interactiveProperty().addListener(observable -> handleControlPropertyChanged("INTERACTIVE"));
    getSkinnable().getSections().addListener((ListChangeListener<Section>) change -> handleControlPropertyChanged("CANVAS_REFRESH"));
    getSkinnable().getMarkers().addListener((MapChangeListener<Marker, Rotate>) change -> handleControlPropertyChanged("MARKER"));
    getSkinnable().barGradientProperty().addListener((ListChangeListener<Stop>) change -> handleControlPropertyChanged("BAR_GRADIENT"));
    getSkinnable().barGradientEnabledProperty().addListener(observable -> handleControlPropertyChanged("BAR_COLOR"));
    angle.addListener(observable -> handleControlPropertyChanged("ANGLE"));
    knob.setOnMousePressed(event -> getSkinnable().setInteractive(!getSkinnable().isInteractive()));
    minMeasuredValue.setOnMousePressed(mouseEventHandler);
    minMeasuredValue.setOnMouseReleased(mouseEventHandler);
    minMeasuredValue.setOnTouchPressed(touchEventHandler);
    minMeasuredValue.setOnTouchReleased(touchEventHandler);
    maxMeasuredValue.setOnMousePressed(mouseEventHandler);
    maxMeasuredValue.setOnMouseReleased(mouseEventHandler);
    maxMeasuredValue.setOnTouchPressed(touchEventHandler);
    maxMeasuredValue.setOnTouchReleased(touchEventHandler);
    threshold.setOnMousePressed(mouseEventHandler);
    threshold.setOnMouseDragged(mouseEventHandler);
    threshold.setOnMouseReleased(mouseEventHandler);
    threshold.setOnTouchPressed(touchEventHandler);
    threshold.setOnTouchMoved(touchEventHandler);
    threshold.setOnTouchReleased(touchEventHandler);
    for (Marker marker : getSkinnable().getMarkers().keySet()) {
        marker.setOnMousePressed(mouseEventHandler);
        marker.setOnMouseDragged(mouseEventHandler);
        marker.setOnMouseReleased(mouseEventHandler);
        marker.setOnTouchPressed(touchEventHandler);
        marker.setOnTouchMoved(touchEventHandler);
        marker.setOnTouchReleased(touchEventHandler);
    }
}
Also used : EventHandler(javafx.event.EventHandler) CacheHint(javafx.scene.CacheHint) Rotate(javafx.scene.transform.Rotate) CycleMethod(javafx.scene.paint.CycleMethod) BlendMode(javafx.scene.effect.BlendMode) ListChangeListener(javafx.collections.ListChangeListener) ConicalGradient(eu.hansolo.enzo.common.ConicalGradient) Locale(java.util.Locale) Point2D(javafx.geometry.Point2D) Pane(javafx.scene.layout.Pane) RadialBargraph(eu.hansolo.enzo.gauge.RadialBargraph) Stop(javafx.scene.paint.Stop) GraphicsContext(javafx.scene.canvas.GraphicsContext) MapChangeListener(javafx.collections.MapChangeListener) Blend(javafx.scene.effect.Blend) Font(javafx.scene.text.Font) Timeline(javafx.animation.Timeline) Canvas(javafx.scene.canvas.Canvas) Instant(java.time.Instant) ArcType(javafx.scene.shape.ArcType) Text(javafx.scene.text.Text) Marker(eu.hansolo.enzo.common.Marker) Duration(javafx.util.Duration) List(java.util.List) Region(javafx.scene.layout.Region) Interpolator(javafx.animation.Interpolator) PauseTransition(javafx.animation.PauseTransition) TouchEvent(javafx.scene.input.TouchEvent) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) StrokeLineCap(javafx.scene.shape.StrokeLineCap) IntStream(java.util.stream.IntStream) SkinBase(javafx.scene.control.SkinBase) MouseEvent(javafx.scene.input.MouseEvent) DoubleProperty(javafx.beans.property.DoubleProperty) Skin(javafx.scene.control.Skin) ArrayList(java.util.ArrayList) FadeTransition(javafx.animation.FadeTransition) ValueEvent(eu.hansolo.enzo.common.ValueEvent) VPos(javafx.geometry.VPos) RadialGradient(javafx.scene.paint.RadialGradient) StrokeType(javafx.scene.shape.StrokeType) BlurType(javafx.scene.effect.BlurType) KeyValue(javafx.animation.KeyValue) LinkedList(java.util.LinkedList) InnerShadow(javafx.scene.effect.InnerShadow) Color(javafx.scene.paint.Color) KeyFrame(javafx.animation.KeyFrame) Section(eu.hansolo.enzo.common.Section) Node(javafx.scene.Node) ImagePattern(javafx.scene.paint.ImagePattern) DropShadow(javafx.scene.effect.DropShadow) Fonts(eu.hansolo.enzo.fonts.Fonts) EventType(javafx.event.EventType) ParallelTransition(javafx.animation.ParallelTransition) SequentialTransition(javafx.animation.SequentialTransition) Arc(javafx.scene.shape.Arc) Image(javafx.scene.image.Image) Rotate(javafx.scene.transform.Rotate) Stop(javafx.scene.paint.Stop) Marker(eu.hansolo.enzo.common.Marker) Section(eu.hansolo.enzo.common.Section)

Example 20 with ListChangeListener

use of javafx.collections.ListChangeListener in project Board-Instrumentation-Framework by intel.

the class RadialGauge method registerListeners.

private void registerListeners() {
    sections.addListener((ListChangeListener<Section>) c -> IntStream.range(0, sections.size()).parallel().forEachOrdered(i -> {
        Section section = sections.get(i);
        switch(i) {
            case 0:
                setSectionFill0(section.getColor());
                break;
            case 1:
                setSectionFill1(section.getColor());
                break;
            case 2:
                setSectionFill2(section.getColor());
                break;
            case 3:
                setSectionFill3(section.getColor());
                break;
            case 4:
                setSectionFill4(section.getColor());
                break;
            case 5:
                setSectionFill5(section.getColor());
                break;
            case 6:
                setSectionFill6(section.getColor());
                break;
            case 7:
                setSectionFill7(section.getColor());
                break;
            case 8:
                setSectionFill8(section.getColor());
                break;
            case 9:
                setSectionFill9(section.getColor());
                break;
        }
    }));
    areas.addListener((ListChangeListener<Section>) c -> IntStream.range(0, areas.size()).parallel().forEachOrdered(i -> {
        Section area = areas.get(i);
        switch(i) {
            case 0:
                setAreaFill0(area.getColor());
                break;
            case 1:
                setAreaFill1(area.getColor());
                break;
            case 2:
                setAreaFill2(area.getColor());
                break;
            case 3:
                setAreaFill3(area.getColor());
                break;
            case 4:
                setAreaFill4(area.getColor());
                break;
            case 5:
                setAreaFill4(area.getColor());
                break;
            case 6:
                setAreaFill4(area.getColor());
                break;
            case 7:
                setAreaFill4(area.getColor());
                break;
            case 8:
                setAreaFill4(area.getColor());
                break;
            case 9:
                setAreaFill4(area.getColor());
                break;
        }
    }));
}
Also used : IntStream(java.util.stream.IntStream) Color(javafx.scene.paint.Color) javafx.beans.property(javafx.beans.property) java.util(java.util) Section(eu.hansolo.enzo.common.Section) Control(javafx.scene.control.Control) DecimalFormat(java.text.DecimalFormat) FXCollections(javafx.collections.FXCollections) RadialGaugeSkin(eu.hansolo.enzo.gauge.skin.RadialGaugeSkin) Skin(javafx.scene.control.Skin) AnimationTimer(javafx.animation.AnimationTimer) Duration(javafx.util.Duration) ListChangeListener(javafx.collections.ListChangeListener) javafx.css(javafx.css) Paint(javafx.scene.paint.Paint) ObservableList(javafx.collections.ObservableList) Section(eu.hansolo.enzo.common.Section)

Aggregations

ListChangeListener (javafx.collections.ListChangeListener)24 FXCollections (javafx.collections.FXCollections)15 List (java.util.List)14 ObservableList (javafx.collections.ObservableList)13 ArrayList (java.util.ArrayList)11 Collectors (java.util.stream.Collectors)9 Map (java.util.Map)8 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)8 Color (javafx.scene.paint.Color)8 Platform (javafx.application.Platform)7 Label (javafx.scene.control.Label)7 HashMap (java.util.HashMap)6 TimeUnit (java.util.concurrent.TimeUnit)6 IntegerProperty (javafx.beans.property.IntegerProperty)6 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)6 ChangeListener (javafx.beans.value.ChangeListener)6 Node (javafx.scene.Node)6 Button (javafx.scene.control.Button)6 IntStream (java.util.stream.IntStream)5 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)5