use of javafx.util.converter.DefaultStringConverter in project org.csstudio.display.builder by kasemir.
the class RulesDialog method createRulesTable.
/**
* @return Node for UI elements that edit the rules
*/
private Node createRulesTable() {
// Create table with editable rule 'name' column
final TableColumn<RuleItem, String> name_col = new TableColumn<>(Messages.RulesDialog_ColName);
name_col.setCellValueFactory(new PropertyValueFactory<RuleItem, String>("name"));
name_col.setCellFactory(list -> new TextFieldTableCell<RuleItem, String>(new DefaultStringConverter()) {
private final ChangeListener<? super Boolean> focusedListener = (ob, o, n) -> {
if (!n)
cancelEdit();
};
@Override
public void cancelEdit() {
((TextField) getGraphic()).focusedProperty().removeListener(focusedListener);
super.cancelEdit();
}
@Override
public void commitEdit(final String newValue) {
((TextField) getGraphic()).focusedProperty().removeListener(focusedListener);
super.commitEdit(newValue);
Platform.runLater(() -> btn_add_pv.requestFocus());
}
@Override
public void startEdit() {
super.startEdit();
((TextField) getGraphic()).focusedProperty().addListener(focusedListener);
}
});
name_col.setOnEditCommit(event -> {
final int row = event.getTablePosition().getRow();
rule_items.get(row).name.set(event.getNewValue());
fixupRules(row);
});
rules_table = new TableView<>(rule_items);
rules_table.getColumns().add(name_col);
rules_table.setEditable(true);
rules_table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
rules_table.setTooltip(new Tooltip(Messages.RulesDialog_RulesTT));
rules_table.setPlaceholder(new Label(Messages.RulesDialog_NoRules));
// Buttons
btn_add_rule = new Button(Messages.Add, JFXUtil.getIcon("add.png"));
btn_add_rule.setMaxWidth(Double.MAX_VALUE);
btn_add_rule.setAlignment(Pos.CENTER_LEFT);
btn_add_rule.setOnAction(event -> {
final RuleItem newItem = new RuleItem(attached_widget, selected_rule_item == null ? ((propinfo_ls.size() == 0) ? "" : propinfo_ls.get(0).getPropID()) : selected_rule_item.prop_id.get());
rule_items.add(newItem);
rules_table.getSelectionModel().select(newItem);
final int newRow = rules_table.getSelectionModel().getSelectedIndex();
ModelThreadPool.getTimer().schedule(() -> {
Platform.runLater(() -> rules_table.edit(newRow, name_col));
}, 123, TimeUnit.MILLISECONDS);
});
btn_remove_rule = new Button(Messages.Remove, JFXUtil.getIcon("delete.png"));
btn_remove_rule.setMaxWidth(Double.MAX_VALUE);
btn_remove_rule.setAlignment(Pos.CENTER_LEFT);
btn_remove_rule.setDisable(true);
btn_remove_rule.setOnAction(event -> {
final int sel = rules_table.getSelectionModel().getSelectedIndex();
if (sel >= 0) {
rule_items.remove(sel);
fixupRules(sel);
}
});
btn_move_rule_up = new Button(Messages.MoveUp, JFXUtil.getIcon("up.png"));
btn_move_rule_up.setMaxWidth(Double.MAX_VALUE);
btn_move_rule_up.setAlignment(Pos.CENTER_LEFT);
btn_move_rule_up.setDisable(true);
btn_move_rule_up.setOnAction(event -> TableHelper.move_item_up(rules_table, rule_items));
btn_move_rule_down = new Button(Messages.MoveDown, JFXUtil.getIcon("down.png"));
btn_move_rule_down.setMaxWidth(Double.MAX_VALUE);
btn_move_rule_down.setAlignment(Pos.CENTER_LEFT);
btn_move_rule_down.setDisable(true);
btn_move_rule_down.setOnAction(event -> TableHelper.move_item_down(rules_table, rule_items));
btn_dup_rule = new Button(Messages.Duplicate, JFXUtil.getIcon("file-duplicate.png"));
btn_dup_rule.setMaxWidth(Double.MAX_VALUE);
btn_dup_rule.setAlignment(Pos.CENTER_LEFT);
btn_dup_rule.setDisable(true);
btn_dup_rule.setOnAction(event -> {
if (selected_rule_item != null) {
final RuleItem newItem = RuleItem.forInfo(attached_widget, selected_rule_item.getRuleInfo(), undo);
if (!newItem.nameProperty().get().endsWith(" (duplicate)"))
newItem.nameProperty().set(newItem.nameProperty().get() + " (duplicate)");
rule_items.add(newItem);
rules_table.getSelectionModel().select(newItem);
final int newRow = rules_table.getSelectionModel().getSelectedIndex();
ModelThreadPool.getTimer().schedule(() -> {
Platform.runLater(() -> rules_table.edit(newRow, name_col));
}, 123, TimeUnit.MILLISECONDS);
}
});
btn_show_script = new Button(Messages.RulesDialog_ShowScript, JFXUtil.getIcon("file.png"));
btn_show_script.setMaxWidth(Double.MAX_VALUE);
btn_show_script.setMinWidth(120);
btn_dup_rule.setAlignment(Pos.CENTER_LEFT);
btn_show_script.setDisable(true);
btn_show_script.setOnAction(event -> {
final int sel = rules_table.getSelectionModel().getSelectedIndex();
if (sel >= 0) {
final String content = rule_items.get(sel).getRuleInfo().getTextPy(attached_widget);
final SyntaxHighlightedMultiLineInputDialog dialog = new SyntaxHighlightedMultiLineInputDialog(btn_show_script, content, Language.Python, false);
DialogHelper.positionDialog(dialog, btn_show_script, -200, -300);
dialog.setTextHeight(600);
dialog.show();
}
});
final VBox buttons = new VBox(10, btn_add_rule, btn_remove_rule, btn_move_rule_up, btn_move_rule_down, new Pane(), btn_dup_rule, btn_show_script);
final HBox content = new HBox(10, rules_table, buttons);
HBox.setHgrow(rules_table, Priority.ALWAYS);
HBox.setHgrow(buttons, Priority.NEVER);
return content;
}
use of javafx.util.converter.DefaultStringConverter in project on-track by michaelplazek.
the class CentralTrafficControlController method connectTables.
private void connectTables() {
stopColumn.setCellValueFactory(new PropertyValueFactory<ScheduleRow, String>("stop"));
dwellColumn.setCellValueFactory(new PropertyValueFactory<ScheduleRow, String>("dwell"));
selectedDwellColumn.setCellValueFactory(new PropertyValueFactory<ScheduleRow, String>("dwell"));
selectedStopColumn.setCellValueFactory(new PropertyValueFactory<ScheduleRow, String>("stop"));
selectedTimeColumn.setCellValueFactory(new PropertyValueFactory<ScheduleRow, String>("time"));
trainColumn.setCellValueFactory(new PropertyValueFactory<TrainTracker, String>("id"));
departureColumn.setCellValueFactory(new PropertyValueFactory<TrainTracker, String>("departure"));
dispatchTrainColumn.setCellValueFactory(new PropertyValueFactory<TrainTracker, String>("id"));
dispatchLocationColumn.setCellValueFactory(new PropertyValueFactory<TrainTracker, String>("locationId"));
dispatchAuthorityColumn.setCellValueFactory(new PropertyValueFactory<TrainTracker, String>("authority"));
dispatchSpeedColumn.setCellValueFactory(new PropertyValueFactory<TrainTracker, String>("speed"));
dispatchPassengersColumn.setCellValueFactory(new PropertyValueFactory<TrainTracker, String>("passengers"));
// set dropdown menu for stations
stopColumn.setCellFactory(ComboBoxTableCell.forTableColumn(new DefaultStringConverter(), ctc.getStationList()));
stopColumn.setOnEditCommit((TableColumn.CellEditEvent<ScheduleRow, String> t) -> {
((ScheduleRow) t.getTableView().getItems().get(t.getTablePosition().getRow())).setStop(t.getNewValue());
});
dwellColumn.setCellFactory(TextFieldTableCell.<ScheduleRow>forTableColumn());
dwellColumn.setOnEditCommit((TableColumn.CellEditEvent<ScheduleRow, String> t) -> {
String input = t.getNewValue();
if (checkTimeFormat(input) || input.equals("")) {
((ScheduleRow) t.getTableView().getItems().get(t.getTablePosition().getRow())).setDwell(input);
} else {
AlertWindow alert = new AlertWindow();
alert.setTitle("Error Submitting");
alert.setHeader("Please Use Correct Format");
alert.setContent("Please enter the time in the following format: " + "XX:XX:XX");
alert.show();
}
});
addScheduleTable.setItems(FXCollections.observableArrayList(new ScheduleRow("", "", ""), new ScheduleRow("", "", ""), new ScheduleRow("", "", ""), new ScheduleRow("", "", ""), new ScheduleRow("", "", ""), new ScheduleRow("", "", "")));
}
use of javafx.util.converter.DefaultStringConverter in project MiscellaneousStudy by mikoto2000.
the class EditableTreeViewController method initialize.
@Override
public void initialize(URL location, ResourceBundle resources) {
// ルートの子要素を作成
TreeItem<String> item1 = new TreeItem<String>("Item 1");
TreeItem<String> item2 = new TreeItem<String>("Item 2");
TreeItem<String> item3 = new TreeItem<String>("Item 3");
TreeItem<String> item4 = new TreeItem<String>("Item 4");
// item4 の子要素
TreeItem<String> item41 = new TreeItem<String>("Item 4-1");
TreeItem<String> item42 = new TreeItem<String>("Item 4-2");
TreeItem<String> item43 = new TreeItem<String>("Item 4-3");
// item4 に子要素を追加する
ObservableList<TreeItem<String>> image4tChildren = item4.getChildren();
image4tChildren.add(item41);
image4tChildren.add(item42);
image4tChildren.add(item43);
TreeItem<String> root = new TreeItem<String>("root");
treeView.setRoot(root);
// ルート要素に子要素を追加する
ObservableList<TreeItem<String>> rootChildren = root.getChildren();
rootChildren.add(item1);
rootChildren.add(item2);
rootChildren.add(item3);
rootChildren.add(item4);
// 子を持つノードを開く
root.setExpanded(true);
item4.setExpanded(true);
// 編集可能にする
treeView.setEditable(true);
treeView.setCellFactory((TreeView<String> p) -> {
TextFieldTreeCell<String> cell = new TextFieldTreeCell<String>();
// 編集した文字列を、
// セルが持つデータに反映させるロジックを指定。
// 今回はテキストフィールドに入力した文字列を
// そのままセルが持つデータとして使うので、
// DefaultStringConverter を使用。
cell.setConverter(new DefaultStringConverter());
return cell;
});
}
use of javafx.util.converter.DefaultStringConverter in project on-track by michaelplazek.
the class CentralTrafficControlController method connectOthers.
private void connectOthers() {
TableView.TableViewSelectionModel<ScheduleRow> defaultModel = addScheduleTable.getSelectionModel();
// connect the toggle buttons for mode of operation
mode.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
public void changed(ObservableValue<? extends Toggle> ov, Toggle oldToggle, Toggle newToggle) {
if (mode.getSelectedToggle() != null) {
RadioButton btn = (RadioButton) newToggle.getToggleGroup().getSelectedToggle();
changeMode(btn.getText(), defaultModel);
}
}
});
trainQueueTable.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
if (trainQueueTable.getSelectionModel().getSelectedItem() != null) {
TrainTracker selected = trainQueueTable.getSelectionModel().getSelectedItem();
selectedScheduleTable.setItems(selected.getSchedule().getStops());
}
});
trackSelect.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
if (!newValue.equals("Select track")) {
ctc.setLine(newValue);
ctc.makeStationList();
ctc.makeBlockList();
stopColumn.setCellFactory(ComboBoxTableCell.forTableColumn(new DefaultStringConverter(), ctc.getStationList()));
scheduleBlocks.setDisable(false);
setAuthorityBlocks.setDisable(false);
scheduleBlocks.setItems(ctc.getBlockList());
setAuthorityBlocks.setItems(ctc.getBlockList());
// only show trains that are on the selected line
ctc.getTrainQueueTable().clear();
ctc.getDispatchTable().clear();
selectedScheduleTable.setItems(FXCollections.observableArrayList());
TrainTracker item;
ObservableList<TrainTracker> list = ctc.getTrainList();
for (int i = 0; i < list.size(); i++) {
item = list.get(i);
if (item.getLine().equals(newValue)) {
// first, set the queue table
if (!item.isDispatched()) {
ctc.getTrainQueueTable().add(item);
} else {
// then get the dispatch table
ctc.getDispatchTable().add(item);
}
}
}
// then set the user interface
trainQueueTable.setItems(ctc.getTrainQueueTable());
dispatchTable.setItems(ctc.getDispatchTable());
if (ctc.getBlockList().size() > 0) {
scheduleBlocks.setValue(ctc.getBlockList().get(0));
setAuthorityBlocks.setValue(ctc.getBlockList().get(0));
}
} else {
trackSelect.setValue(oldValue);
}
});
maintenanceActions.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
if (newValue.equals("Select action")) {
maintenanceActions.setValue(oldValue);
} else {
String action = maintenanceActions.getSelectionModel().getSelectedItem();
String line = maintenanceTracks.getSelectionModel().getSelectedItem();
int blockId = extractBlock();
Block block = Track.getListOfTracks().get(line).getBlock(blockId);
if (action.equals("Toggle switch") && !block.isSwitch()) {
submitMaintenance.setDisable(true);
} else {
submitMaintenance.setDisable(false);
}
}
});
maintenanceBlocks.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
String action = maintenanceActions.getSelectionModel().getSelectedItem();
String line = maintenanceTracks.getSelectionModel().getSelectedItem();
int blockId = extractBlock();
Block block = Track.getListOfTracks().get(line).getBlock(blockId);
if (action.equals("Toggle switch") && !block.isSwitch()) {
submitMaintenance.setDisable(true);
} else {
submitMaintenance.setDisable(false);
}
});
maintenanceTracks.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
if (!newValue.equals("Select track")) {
trackMaintenance.setLine(newValue);
trackMaintenance.makeBlockList();
maintenanceBlocks.setItems(trackMaintenance.getBlockList());
if (ctc.getBlockList().size() > 0) {
maintenanceBlocks.setValue(trackMaintenance.getBlockList().get(0));
}
} else {
maintenanceTracks.setValue(oldValue);
}
updateMaintenance();
});
trainStatus.setFill(Paint.valueOf("Grey"));
}
use of javafx.util.converter.DefaultStringConverter in project org.csstudio.display.builder by kasemir.
the class RulesDialog method createExpressionsTable.
/**
* @return Node for UI elements that edit the expressions
*/
private HBox createExpressionsTable() {
// Create table with editable rule 'bool expression' column
final TableColumn<ExprItem<?>, String> bool_exp_col = new TableColumn<>(Messages.RulesDialog_ColBoolExp);
bool_exp_col.setSortable(false);
bool_exp_col.setCellValueFactory(new PropertyValueFactory<ExprItem<?>, String>("boolExp"));
bool_exp_col.setCellFactory(tableColumn -> new TextFieldTableCell<ExprItem<?>, String>(new DefaultStringConverter()) {
private final ChangeListener<? super Boolean> focusedListener = (ob, o, n) -> {
if (!n)
cancelEdit();
};
/* Instance initializer. */
{
setAlignment(Pos.CENTER_LEFT);
}
@Override
public void cancelEdit() {
((TextField) getGraphic()).focusedProperty().removeListener(focusedListener);
super.cancelEdit();
}
@Override
public void commitEdit(final String newValue) {
((TextField) getGraphic()).focusedProperty().removeListener(focusedListener);
super.commitEdit(newValue);
}
@Override
public void startEdit() {
super.startEdit();
((TextField) getGraphic()).focusedProperty().addListener(focusedListener);
}
});
// Create table with editable rule 'value expression' column
final TableColumn<ExprItem<?>, Node> val_exp_col = new TableColumn<>(Messages.RulesDialog_ColValExp);
// This statement requires "val_exp_col" be defined.
bool_exp_col.setOnEditCommit(event -> {
final int row = event.getTablePosition().getRow();
expression_items.get(row).boolExpProperty().set(event.getNewValue());
ModelThreadPool.getTimer().schedule(() -> {
Platform.runLater(() -> val_exp_col.getCellData(row).requestFocus());
}, 123, TimeUnit.MILLISECONDS);
});
val_exp_col.setSortable(false);
val_exp_col.setCellValueFactory(new PropertyValueFactory<ExprItem<?>, Node>("field"));
val_exp_col.setCellFactory(tableColumn -> new TableCell<ExprItem<?>, Node>() {
@Override
protected void updateItem(final Node item, final boolean empty) {
// calling super here is very important - don't skip this!
super.updateItem(item, empty);
setGraphic(item);
}
});
val_exp_col.setOnEditCommit(event -> {
final int row = event.getTablePosition().getRow();
expression_items.get(row).fieldProperty().set(event.getNewValue());
event.consume();
ModelThreadPool.getTimer().schedule(() -> {
Platform.runLater(() -> btn_add_exp.requestFocus());
}, 1230, TimeUnit.MILLISECONDS);
});
expressions_table = new TableView<>(expression_items);
expressions_table.getColumns().add(bool_exp_col);
expressions_table.getColumns().add(val_exp_col);
expressions_table.setEditable(true);
expressions_table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
expressions_table.setTooltip(new Tooltip(Messages.RulesDialog_ExpressionsTT));
expressions_table.setPlaceholder(new Label(Messages.RulesDialog_NoExpressions));
// Buttons
btn_add_exp = new Button(Messages.Add, JFXUtil.getIcon("add.png"));
btn_add_exp.setMaxWidth(Double.MAX_VALUE);
btn_add_exp.setAlignment(Pos.CENTER_LEFT);
btn_add_exp.setOnAction(event -> {
selected_rule_item.addNewExpr(undo);
expression_items.setAll(selected_rule_item.expressions);
expressions_table.getSelectionModel().select(expression_items.size() - 1);
final int newRow = expression_items.size() - 1;
ModelThreadPool.getTimer().schedule(() -> {
Platform.runLater(() -> expressions_table.edit(newRow, bool_exp_col));
}, 123, TimeUnit.MILLISECONDS);
});
btn_rm_exp = new Button(Messages.Remove, JFXUtil.getIcon("delete.png"));
btn_rm_exp.setMaxWidth(Double.MAX_VALUE);
btn_rm_exp.setMinWidth(96);
btn_rm_exp.setAlignment(Pos.CENTER_LEFT);
btn_rm_exp.setDisable(true);
btn_rm_exp.setOnAction(event -> {
final int sel = expressions_table.getSelectionModel().getSelectedIndex();
if (sel >= 0)
expression_items.remove(sel);
});
btn_move_exp_up = new Button(Messages.MoveUp, JFXUtil.getIcon("up.png"));
btn_move_exp_up.setMaxWidth(Double.MAX_VALUE);
btn_move_exp_up.setAlignment(Pos.CENTER_LEFT);
btn_move_exp_up.setDisable(true);
btn_move_exp_up.setOnAction(event -> TableHelper.move_item_up(expressions_table, expression_items));
btn_move_exp_down = new Button(Messages.MoveDown, JFXUtil.getIcon("down.png"));
btn_move_exp_down.setMaxWidth(Double.MAX_VALUE);
btn_move_exp_down.setAlignment(Pos.CENTER_LEFT);
btn_move_exp_down.setDisable(true);
btn_move_exp_down.setOnAction(event -> TableHelper.move_item_down(expressions_table, expression_items));
final VBox buttons = new VBox(10, btn_add_exp, btn_rm_exp, btn_move_exp_up, btn_move_exp_down);
final HBox content = new HBox(10, expressions_table, buttons);
HBox.setHgrow(expressions_table, Priority.ALWAYS);
HBox.setHgrow(buttons, Priority.NEVER);
content.setDisable(true);
return content;
}
Aggregations