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;
}
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;
}
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);
}
}
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);
}
}
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;
}
}));
}
Aggregations