Search in sources :

Example 6 with DefaultStringConverter

use of javafx.util.converter.DefaultStringConverter in project org.csstudio.display.builder by kasemir.

the class ScriptsDialog method createScriptsTable.

/**
 * @return Node for UI elements that edit the scripts
 */
private Region createScriptsTable() {
    scripts_icon_col = new TableColumn<>();
    scripts_icon_col.setCellValueFactory(cdf -> new SimpleObjectProperty<ImageView>(getScriptImage(cdf.getValue())) {

        {
            bind(Bindings.createObjectBinding(() -> getScriptImage(cdf.getValue()), cdf.getValue().fileProperty()));
        }
    });
    scripts_icon_col.setCellFactory(col -> new TableCell<ScriptItem, ImageView>() {

        /* Instance initializer. */
        {
            setAlignment(Pos.CENTER_LEFT);
        }

        @Override
        protected void updateItem(final ImageView item, final boolean empty) {
            super.updateItem(item, empty);
            super.setGraphic(item);
        }
    });
    scripts_icon_col.setEditable(false);
    scripts_icon_col.setSortable(false);
    scripts_icon_col.setMaxWidth(25);
    scripts_icon_col.setMinWidth(25);
    // Create table with editable script 'file' column
    scripts_name_col = new TableColumn<>(Messages.ScriptsDialog_ColScript);
    scripts_name_col.setCellValueFactory(new PropertyValueFactory<ScriptItem, String>("file"));
    scripts_name_col.setCellFactory(col -> new TextFieldTableCell<ScriptItem, 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 startEdit() {
            super.startEdit();
            ((TextField) getGraphic()).focusedProperty().addListener(focusedListener);
        }

        @Override
        public void commitEdit(final String newValue) {
            ((TextField) getGraphic()).focusedProperty().removeListener(focusedListener);
            super.commitEdit(newValue);
            Platform.runLater(() -> btn_pv_add.requestFocus());
        }
    });
    scripts_name_col.setOnEditCommit(event -> {
        final int row = event.getTablePosition().getRow();
        script_items.get(row).file.set(event.getNewValue());
        fixupScripts(row);
    });
    scripts_table = new TableView<>(script_items);
    scripts_table.getColumns().add(scripts_icon_col);
    scripts_table.getColumns().add(scripts_name_col);
    scripts_table.setEditable(true);
    scripts_table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    scripts_table.setTooltip(new Tooltip(Messages.ScriptsDialog_ScriptsTT));
    scripts_table.setPlaceholder(new Label(Messages.ScriptsDialog_NoScripts));
    // Buttons
    addMenuButton = new MenuButton(Messages.Add, JFXUtil.getIcon("add.png"), new MenuItem(Messages.AddPythonFile, JFXUtil.getIcon("file-python.png")) {

        {
            setOnAction(e -> addPythonFile());
        }
    }, new MenuItem(Messages.AddJavaScriptFile, JFXUtil.getIcon("file-javascript.png")) {

        {
            setOnAction(e -> addJavaScriptFile());
        }
    }, new SeparatorMenuItem(), new MenuItem(Messages.AddEmbeddedPython, JFXUtil.getIcon("python.png")) {

        {
            setOnAction(e -> addEmbeddedJython());
        }
    }, new MenuItem(Messages.AddEmbeddedJavaScript, JFXUtil.getIcon("javascript.png")) {

        {
            setOnAction(e -> addEmbeddedJavaScript());
        }
    });
    addMenuButton.setMaxWidth(Double.MAX_VALUE);
    addMenuButton.setAlignment(Pos.CENTER_LEFT);
    btn_script_remove = new Button(Messages.Remove, JFXUtil.getIcon("delete.png"));
    btn_script_remove.setMaxWidth(Double.MAX_VALUE);
    btn_script_remove.setAlignment(Pos.CENTER_LEFT);
    btn_script_remove.setDisable(true);
    btn_script_remove.setOnAction(event -> {
        final int sel = scripts_table.getSelectionModel().getSelectedIndex();
        if (sel >= 0) {
            script_items.remove(sel);
            fixupScripts(sel);
        }
    });
    btn_edit = new SplitMenuButton(convertToFileMenuItem, new SeparatorMenuItem(), convertToEmbeddedPythonMenuItem, convertToEmbeddedJavaScriptMenuItem);
    btn_edit.setText(Messages.Select);
    btn_edit.setGraphic(JFXUtil.getIcon("select-file.png"));
    btn_edit.setMaxWidth(Double.MAX_VALUE);
    btn_edit.setMinWidth(120);
    btn_edit.setAlignment(Pos.CENTER_LEFT);
    btn_edit.setDisable(true);
    btn_edit.setOnAction(e -> editOrSelect());
    final VBox buttons = new VBox(10, addMenuButton, btn_script_remove, btn_edit);
    final HBox content = new HBox(10, scripts_table, buttons);
    HBox.setHgrow(scripts_table, Priority.ALWAYS);
    HBox.setHgrow(buttons, Priority.NEVER);
    return content;
}
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) HBox(javafx.scene.layout.HBox) SplitMenuButton(javafx.scene.control.SplitMenuButton) Label(javafx.scene.control.Label) MenuButton(javafx.scene.control.MenuButton) SplitMenuButton(javafx.scene.control.SplitMenuButton) Button(javafx.scene.control.Button) MenuButton(javafx.scene.control.MenuButton) SplitMenuButton(javafx.scene.control.SplitMenuButton) TextField(javafx.scene.control.TextField) ImageView(javafx.scene.image.ImageView) Tooltip(javafx.scene.control.Tooltip) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) DefaultStringConverter(javafx.util.converter.DefaultStringConverter) VBox(javafx.scene.layout.VBox)

Example 7 with DefaultStringConverter

use of javafx.util.converter.DefaultStringConverter in project DeskChan by DeskChan.

the class OptionsDialog method initCommandsTab1.

/**
 * Creating 'Commands' tab. *
 */
private static void initCommandsTab1() {
    TableView<CommandItem> commandsTable = new TableView<>();
    BorderPane commandTab = new BorderPane();
    commandTab.setCenter(commandsTable);
    commandsTable.setEditable(true);
    commandsTable.setPlaceholder(new Label(Main.getString("commands.empty")));
    // commandsTable.prefHeightProperty().bind(commandTab.heightProperty());
    // Events column
    TableColumn eventCol = new TableColumn(Main.getString("events"));
    eventCol.setCellValueFactory(new PropertyValueFactory<CommandItem, String>("event"));
    List events = CommandsProxy.getEventsList();
    Collections.sort(events);
    eventCol.setCellFactory(ComboBoxTableCell.forTableColumn(new DefaultStringConverter(), FXCollections.observableArrayList(events)));
    eventCol.setOnEditCommit(ev -> {
        TableColumn.CellEditEvent<CommandItem, String> event = (TableColumn.CellEditEvent<CommandItem, String>) ev;
        CommandItem item = event.getTableView().getItems().get(event.getTablePosition().getRow());
        item.setEvent(event.getNewValue());
    });
    eventCol.setMinWidth(120);
    // Commands column
    TableColumn commandCol = new TableColumn(Main.getString("commands"));
    commandCol.setCellValueFactory(new PropertyValueFactory<CommandItem, String>("command"));
    List commands = CommandsProxy.getCommandsList();
    Collections.sort(commands);
    commandCol.setCellFactory(ComboBoxTableCell.forTableColumn(new DefaultStringConverter(), FXCollections.observableArrayList(commands)));
    commandCol.setOnEditCommit(ev -> {
        TableColumn.CellEditEvent<CommandItem, String> event = (TableColumn.CellEditEvent<CommandItem, String>) ev;
        CommandItem item = event.getTableView().getItems().get(event.getTablePosition().getRow());
        item.setCommand(event.getNewValue());
    });
    commandCol.setMinWidth(120);
    // Rules column
    TableColumn ruleCol = new TableColumn(Main.getString("rules"));
    ruleCol.setCellValueFactory(new PropertyValueFactory<CommandItem, String>("rule"));
    ruleCol.setCellFactory(TooltippedTableCell.<CommandItem>forTableColumn());
    ruleCol.setOnEditCommit(ev -> {
        TableColumn.CellEditEvent<CommandItem, String> event = (TableColumn.CellEditEvent<CommandItem, String>) ev;
        CommandItem item = event.getTableView().getItems().get(event.getTablePosition().getRow());
        item.setRule(event.getNewValue());
    });
    ruleCol.setMinWidth(120);
    // Parameters column
    TableColumn msgCol = new TableColumn(Main.getString("parameters"));
    msgCol.setCellValueFactory(new PropertyValueFactory<CommandItem, String>("msgData"));
    msgCol.setCellFactory(TooltippedTableCell.<CommandItem>forTableColumn());
    msgCol.setOnEditCommit(ev -> {
        TableColumn.CellEditEvent<CommandItem, String> event = (TableColumn.CellEditEvent<CommandItem, String>) ev;
        CommandItem item = event.getTableView().getItems().get(event.getTablePosition().getRow());
        item.setMsgData(event.getNewValue());
    });
    msgCol.setMinWidth(120);
    final TreeItem<CommandItem> root = new TreeItem<>();
    // Filling list of commands
    ObservableList<CommandItem> list = FXCollections.observableArrayList();
    for (Map<String, Object> entry : CommandsProxy.getLinksList()) {
        list.add(new CommandItem(entry));
    }
    commandsTable.setItems(list);
    // Setting columns
    commandsTable.getColumns().addAll(eventCol, ruleCol, commandCol, msgCol);
    // 'Delete' button
    Button deleteButton = new Button(Main.getString("delete"));
    deleteButton.setOnAction(event -> {
        if (commandsTable.getSelectionModel().getSelectedIndex() >= 0)
            commandsTable.getItems().remove(commandsTable.getSelectionModel().getSelectedIndex());
    });
    // 'Reset' button
    Button resetButton = new Button(Main.getString("reset"));
    resetButton.setOnAction(event -> {
        CommandsProxy.reset();
        ObservableList<CommandItem> l = FXCollections.observableArrayList();
        for (Map<String, Object> entry : CommandsProxy.getLinksList()) {
            l.add(new CommandItem(entry));
        }
        commandsTable.setItems(l);
    });
    // 'Save' button
    Button saveButton = new Button(Main.getString("save"));
    saveButton.setOnAction(event -> {
        ArrayList<Map<String, Object>> push = new ArrayList<>();
        for (CommandItem item : commandsTable.getItems()) {
            push.add(item.toMap());
        }
        CommandsProxy.setLinks(push);
        CommandsProxy.save();
    });
    // 'Load' button
    Button loadButton = new Button(Main.getString("load"));
    loadButton.setOnAction(event -> {
        CommandsProxy.load();
        ObservableList<CommandItem> l = FXCollections.observableArrayList();
        for (Map<String, Object> entry : CommandsProxy.getLinksList()) {
            l.add(new CommandItem(entry));
        }
        commandsTable.setItems(l);
    });
    // 'Add' button
    Button addButton = new Button(Main.getString("add"));
    addButton.setOnAction(event -> {
        CommandItem item = new CommandItem(CommandsProxy.getEventsList().get(0), CommandsProxy.getCommandsList().get(0), "", "");
        commandsTable.getItems().add(item);
    });
    // Adding buttons to form
    HBox buttons = new HBox(addButton, deleteButton, loadButton, saveButton, resetButton);
    commandTab.setBottom(buttons);
    buttons.setId("controls-bottom-buttons");
    new ControlsPanel(Main.getPluginProxy().getId(), Main.getString("commands"), "commands", ControlsPanel.PanelType.TAB, commandTab).set();
}
Also used : DefaultStringConverter(javafx.util.converter.DefaultStringConverter) ObservableList(javafx.collections.ObservableList) JSONObject(org.json.JSONObject)

Example 8 with DefaultStringConverter

use of javafx.util.converter.DefaultStringConverter in project DeskChan by DeskChan.

the class OptionsDialog method initCommandsTab2.

/**
 * Creating 'Commands' tab. *
 */
private void initCommandsTab2() {
    TreeTableView<CommandItem> commandsTable = new TreeTableView<>();
    commandsTable.setShowRoot(false);
    BorderPane commandTab = new BorderPane();
    commandTab.setCenter(commandsTable);
    commandsTable.setEditable(true);
    commandsTable.setPlaceholder(new Label(Main.getString("commands.empty")));
    // commandsTable.prefHeightProperty().bind(commandTab.heightProperty());
    // Events column
    TreeTableColumn eventCol = new TreeTableColumn(Main.getString("events"));
    eventCol.setCellValueFactory(new PropertyValueFactory<CommandItem, String>("event"));
    List events = CommandsProxy.getEventsList();
    Collections.sort(events);
    eventCol.setCellFactory(ComboBoxTableCell.forTableColumn(new DefaultStringConverter(), FXCollections.observableArrayList(events)));
    eventCol.setOnEditCommit(ev -> {
        TableColumn.CellEditEvent<CommandItem, String> event = (TableColumn.CellEditEvent<CommandItem, String>) ev;
        CommandItem item = event.getTableView().getItems().get(event.getTablePosition().getRow());
        item.setEvent(event.getNewValue());
    });
    eventCol.setMinWidth(120);
    // Commands column
    TreeTableColumn commandCol = new TreeTableColumn(Main.getString("commands"));
    commandCol.setCellValueFactory(new PropertyValueFactory<CommandItem, String>("command"));
    List commands = CommandsProxy.getCommandsList();
    Collections.sort(commands);
    commandCol.setCellFactory(ComboBoxTableCell.forTableColumn(new DefaultStringConverter(), FXCollections.observableArrayList(commands)));
    commandCol.setOnEditCommit(ev -> {
        TableColumn.CellEditEvent<CommandItem, String> event = (TableColumn.CellEditEvent<CommandItem, String>) ev;
        CommandItem item = event.getTableView().getItems().get(event.getTablePosition().getRow());
        item.setCommand(event.getNewValue());
    });
    commandCol.setMinWidth(120);
    // Rules column
    TreeTableColumn ruleCol = new TreeTableColumn(Main.getString("rules"));
    ruleCol.setCellValueFactory(new PropertyValueFactory<CommandItem, String>("rule"));
    ruleCol.setCellFactory(TooltippedTableCell.<CommandItem>forTableColumn());
    ruleCol.setOnEditCommit(ev -> {
        TableColumn.CellEditEvent<CommandItem, String> event = (TableColumn.CellEditEvent<CommandItem, String>) ev;
        CommandItem item = event.getTableView().getItems().get(event.getTablePosition().getRow());
        item.setRule(event.getNewValue());
    });
    ruleCol.setMinWidth(120);
    // Parameters column
    TreeTableColumn msgCol = new TreeTableColumn(Main.getString("parameters"));
    msgCol.setCellValueFactory(new PropertyValueFactory<CommandItem, String>("msgData"));
    msgCol.setCellFactory(TooltippedTableCell.<CommandItem>forTableColumn());
    msgCol.setOnEditCommit(ev -> {
        TableColumn.CellEditEvent<CommandItem, String> event = (TableColumn.CellEditEvent<CommandItem, String>) ev;
        CommandItem item = event.getTableView().getItems().get(event.getTablePosition().getRow());
        item.setMsgData(event.getNewValue());
    });
    msgCol.setMinWidth(120);
    final TreeItem<CommandItem> root = new TreeItem<>();
    fillTreeTable(root);
    // Setting columns
    commandsTable.getColumns().addAll(eventCol, ruleCol, commandCol, msgCol);
    // 'Delete' button
    Button deleteButton = new Button(Main.getString("delete"));
    deleteButton.setOnAction(event -> {
        TreeItem item = commandsTable.getSelectionModel().getSelectedItem();
        if (item == null)
            return;
        item.getParent().getChildren().remove(item);
    });
    // 'Reset' button
    Button resetButton = new Button(Main.getString("reset"));
    resetButton.setOnAction(event -> {
        CommandsProxy.reset();
        fillTreeTable(root);
    });
    // 'Save' button
    Button saveButton = new Button(Main.getString("save"));
    saveButton.setOnAction(e -> {
        ArrayList<Map<String, Object>> push = new ArrayList<>();
        for (TreeItem<CommandItem> event : root.getChildren()) for (TreeItem<CommandItem> command : event.getChildren()) for (TreeItem<CommandItem> item : event.getChildren()) push.add(item.getValue().toMap());
        CommandsProxy.setLinks(push);
        CommandsProxy.save();
    });
    // 'Load' button
    Button loadButton = new Button(Main.getString("load"));
    loadButton.setOnAction(event -> {
        CommandsProxy.load();
        fillTreeTable(root);
    });
    // 'Add' button
    Button addButton = new Button(Main.getString("add"));
    addButton.setOnAction(event -> {
        new ControlsPanel(Main.getPluginProxy().getId(), Main.getString("add"), "add", ControlsPanel.PanelType.WINDOW, commandTab).show();
    });
    // Adding buttons to form
    HBox buttons = new HBox(addButton, deleteButton, loadButton, saveButton, resetButton);
    buttons.setId("controls-bottom-buttons");
    commandTab.setBottom(buttons);
    new ControlsPanel(Main.getPluginProxy().getId(), Main.getString("commands"), "commands", ControlsPanel.PanelType.TAB, commandTab).set();
}
Also used : DefaultStringConverter(javafx.util.converter.DefaultStringConverter) ObservableList(javafx.collections.ObservableList)

Example 9 with DefaultStringConverter

use of javafx.util.converter.DefaultStringConverter in project FXGL by AlmasB.

the class PropertyMapView method makeView.

/**
 * Makes a check box when it is a boolean value and text field when it is string etc.
 */
@SuppressWarnings("unchecked")
private Node makeView(Object value) {
    if (value instanceof BooleanProperty) {
        CheckBox box = new CheckBox();
        box.selectedProperty().bindBidirectional((BooleanProperty) value);
        return box;
    } else if (value instanceof ObjectProperty) {
        ObjectProperty<?> property = (ObjectProperty<?>) value;
        // If object is an enum.
        if (property.get().getClass().isEnum())
            return makeEnumView((ObjectProperty<Enum<?>>) property);
        // If object is something else.
        if (converters.containsKey(property.get().getClass())) {
            PropertyViewChangeListener<?, ?> converter = converters.get(property.get().getClass());
            return converter.makeViewInternal(property);
        } else {
            // If object does not have a converter.
            Text text = new Text();
            text.textProperty().bind(property.asString());
            return text;
        }
    } else {
        TextField textField = new TextField();
        textField.setPrefWidth(150);
        if (value instanceof StringProperty)
            textField.textProperty().bindBidirectional((StringProperty) value, new DefaultStringConverter());
        if (value instanceof IntegerProperty)
            textField.textProperty().bindBidirectional((Property<Integer>) value, new IntegerStringConverter());
        if (value instanceof DoubleProperty)
            textField.textProperty().bindBidirectional((Property<Double>) value, new DoubleStringConverter());
        return textField;
    }
}
Also used : DoubleStringConverter(javafx.util.converter.DoubleStringConverter) IntegerStringConverter(javafx.util.converter.IntegerStringConverter) Text(javafx.scene.text.Text) DefaultStringConverter(javafx.util.converter.DefaultStringConverter) CheckBox(javafx.scene.control.CheckBox) TextField(javafx.scene.control.TextField) Vec2PropertyViewChangeListener(com.almasb.fxgl.ui.property.Vec2PropertyViewChangeListener)

Aggregations

DefaultStringConverter (javafx.util.converter.DefaultStringConverter)9 ObservableList (javafx.collections.ObservableList)5 CheckBox (javafx.scene.control.CheckBox)4 TableView (javafx.scene.control.TableView)4 TextField (javafx.scene.control.TextField)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 TimeUnit (java.util.concurrent.TimeUnit)3 Level (java.util.logging.Level)3 BackingStoreException (java.util.prefs.BackingStoreException)3 Preferences (java.util.prefs.Preferences)3 Collectors (java.util.stream.Collectors)3 Platform (javafx.application.Platform)3 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)3 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)3 StringProperty (javafx.beans.property.StringProperty)3 ChangeListener (javafx.beans.value.ChangeListener)3 FXCollections (javafx.collections.FXCollections)3 ListChangeListener (javafx.collections.ListChangeListener)3 Insets (javafx.geometry.Insets)3