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