use of javafx.util.converter.DoubleStringConverter in project blue by kunstmusik.
the class ParameterLineView method editPoints.
private void editPoints() {
TableView<LinePoint> table = new TableView<>();
TableColumn<LinePoint, Double> xCol = new TableColumn<>("x");
TableColumn<LinePoint, Double> yCol = new TableColumn<>("y");
table.getColumns().setAll(xCol, yCol);
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
table.setItems(getSelectedLine().getObservableList());
table.setEditable(true);
xCol.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<LinePoint, Double>, ObservableValue<Double>>() {
@Override
public ObservableValue<Double> call(TableColumn.CellDataFeatures<LinePoint, Double> param) {
return new ReadOnlyObjectWrapper<>(param.getValue().getX() * getDuration() + getStartTime());
}
});
xCol.setCellFactory(TextFieldTableCell.forTableColumn(new DoubleStringConverter()));
xCol.setOnEditCommit(te -> {
LinePoint lp = te.getRowValue();
ObservableList<LinePoint> lpList = getSelectedLine().getObservableList();
if (getSelectedLine().getLinePoint(0) == lp || getSelectedLine().getLinePoint(getSelectedLine().size() - 1) == lp) {
return;
}
int index = lpList.indexOf(lp);
double v = (te.getNewValue() - getStartTime()) / getDuration();
lp.setX(Utils.clamp(lpList.get(index - 1).getX(), v, lpList.get(index + 1).getX()));
});
xCol.setEditable(true);
yCol.setCellValueFactory(new PropertyValueFactory<>("y"));
yCol.setCellFactory(TextFieldTableCell.forTableColumn(new DoubleStringConverter()));
yCol.setOnEditCommit(te -> {
te.getRowValue().setY(Utils.clamp(getSelectedLine().getMin(), te.getNewValue(), getSelectedLine().getMax()));
});
yCol.setEditable(true);
Dialog<ButtonType> d = new Dialog<>();
d.initOwner(getScene().getWindow());
d.initModality(Modality.APPLICATION_MODAL);
d.getDialogPane().setContent(new ScrollPane(table));
d.getDialogPane().getStylesheets().add(BlueFX.getBlueFxCss());
d.getDialogPane().getButtonTypes().setAll(ButtonType.OK);
d.setTitle("Edit Points");
TableModelListener tml = tme -> {
repaint();
};
getSelectedLine().addTableModelListener(tml);
Optional<ButtonType> res = d.showAndWait();
getSelectedLine().removeTableModelListener(tml);
}
use of javafx.util.converter.DoubleStringConverter in project blue by kunstmusik.
the class LineView method editPoints.
private void editPoints() {
TableView<LinePoint> table = new TableView<>();
TableColumn<LinePoint, Double> xCol = new TableColumn<>("x");
TableColumn<LinePoint, Double> yCol = new TableColumn<>("y");
table.getColumns().setAll(xCol, yCol);
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
table.setItems(getSelectedLine().getObservableList());
table.setEditable(true);
xCol.setCellValueFactory(new PropertyValueFactory<LinePoint, Double>("x"));
xCol.setCellFactory(TextFieldTableCell.forTableColumn(new DoubleStringConverter()));
xCol.setOnEditCommit(te -> {
LinePoint lp = te.getRowValue();
if (getSelectedLine().getLinePoint(0) == lp || getSelectedLine().getLinePoint(getSelectedLine().size() - 1) == lp) {
return;
}
lp.setX(Utils.clamp(0.0, te.getNewValue(), 1.0));
});
xCol.setEditable(true);
yCol.setCellValueFactory(new PropertyValueFactory<LinePoint, Double>("y"));
yCol.setCellFactory(TextFieldTableCell.forTableColumn(new DoubleStringConverter()));
yCol.setOnEditCommit(te -> {
te.getRowValue().setY(Utils.clamp(getSelectedLine().getMin(), te.getNewValue(), getSelectedLine().getMax()));
});
yCol.setEditable(true);
Dialog<ButtonType> d = new Dialog<>();
d.initOwner(getScene().getWindow());
d.initModality(Modality.APPLICATION_MODAL);
d.getDialogPane().setContent(new ScrollPane(table));
d.getDialogPane().getStylesheets().add(BlueFX.getBlueFxCss());
d.getDialogPane().getButtonTypes().setAll(ButtonType.OK);
d.setTitle("Edit Points");
TableModelListener tml = tme -> {
repaint();
};
getSelectedLine().addTableModelListener(tml);
Optional<ButtonType> res = d.showAndWait();
getSelectedLine().removeTableModelListener(tml);
}
Aggregations