Search in sources :

Example 1 with Point

use of org.csstudio.display.builder.model.properties.Point in project org.csstudio.display.builder by kasemir.

the class PointsTable method create.

/**
 * @return Top-level {@link Node}
 */
public Node create() {
    // Layout:
    // 
    // | table |  [Add]
    // | table |  [Remove]
    // | table |
    // | table |
    // Create table with editable columns for type Double (supported as Number)
    final TableColumn<Point, Number> x_col = new TableColumn<>(Messages.PointsTable_X);
    x_col.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Point, Number>, ObservableValue<Number>>() {

        @Override
        public ObservableValue<Number> call(CellDataFeatures<Point, Number> param) {
            return new SimpleDoubleProperty(param.getValue().getX());
        }
    });
    x_col.setCellFactory(TextFieldTableCell.<Point, Number>forTableColumn(new NumberStringConverter()));
    x_col.setOnEditCommit(event -> {
        final int row = event.getTablePosition().getRow();
        points.setX(row, event.getNewValue().doubleValue());
    });
    final TableColumn<Point, Number> y_col = new TableColumn<>(Messages.PointsTable_Y);
    y_col.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Point, Number>, ObservableValue<Number>>() {

        @Override
        public ObservableValue<Number> call(CellDataFeatures<Point, Number> param) {
            return new SimpleDoubleProperty(param.getValue().getY());
        }
    });
    y_col.setCellFactory(TextFieldTableCell.<Point, Number>forTableColumn(new NumberStringConverter()));
    y_col.setOnEditCommit(event -> {
        final int row = event.getTablePosition().getRow();
        points.setY(row, event.getNewValue().doubleValue());
    });
    final ObservableList<Point> data = new PointsAdapter(points);
    final TableView<Point> table = new TableView<>(data);
    table.getColumns().add(x_col);
    table.getColumns().add(y_col);
    table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    table.setPlaceholder(new Label(Messages.PointsTable_Empty));
    table.setEditable(true);
    // Buttons
    final Button add = new Button(Messages.Add, JFXUtil.getIcon("add.png"));
    add.setMaxWidth(Double.MAX_VALUE);
    add.setOnAction(event -> data.add(new Point(0, 0)));
    final Button remove = new Button(Messages.Remove, JFXUtil.getIcon("delete.png"));
    remove.setMaxWidth(Double.MAX_VALUE);
    remove.setOnAction(event -> {
        final int sel = table.getSelectionModel().getSelectedIndex();
        if (sel >= 0)
            data.remove(sel);
    });
    final Button up = new Button(Messages.MoveUp, JFXUtil.getIcon("up.png"));
    up.setMaxWidth(Double.MAX_VALUE);
    up.setOnAction(event -> TableHelper.move_item_up(table, data));
    final Button down = new Button(Messages.MoveDown, JFXUtil.getIcon("down.png"));
    down.setMaxWidth(Double.MAX_VALUE);
    down.setOnAction(event -> TableHelper.move_item_down(table, data));
    final VBox buttons = new VBox(10, add, remove, up, down);
    final HBox content = new HBox(10, table, buttons);
    HBox.setHgrow(table, Priority.ALWAYS);
    return content;
}
Also used : HBox(javafx.scene.layout.HBox) CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) ObservableValue(javafx.beans.value.ObservableValue) Label(javafx.scene.control.Label) Point(org.csstudio.display.builder.model.properties.Point) TableColumn(javafx.scene.control.TableColumn) Point(org.csstudio.display.builder.model.properties.Point) NumberStringConverter(javafx.util.converter.NumberStringConverter) Button(javafx.scene.control.Button) VBox(javafx.scene.layout.VBox) TableView(javafx.scene.control.TableView)

Aggregations

SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)1 ObservableValue (javafx.beans.value.ObservableValue)1 Button (javafx.scene.control.Button)1 Label (javafx.scene.control.Label)1 TableColumn (javafx.scene.control.TableColumn)1 CellDataFeatures (javafx.scene.control.TableColumn.CellDataFeatures)1 TableView (javafx.scene.control.TableView)1 HBox (javafx.scene.layout.HBox)1 VBox (javafx.scene.layout.VBox)1 NumberStringConverter (javafx.util.converter.NumberStringConverter)1 Point (org.csstudio.display.builder.model.properties.Point)1