use of javafx.beans.value.ObservableValue in project bisq-desktop by bisq-network.
the class OfferBookView method getVolumeColumn.
private AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem> getVolumeColumn() {
AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem> column = new AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem>("") {
{
setMinWidth(125);
}
};
column.getStyleClass().add("number-column");
column.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
column.setCellFactory(new Callback<TableColumn<OfferBookListItem, OfferBookListItem>, TableCell<OfferBookListItem, OfferBookListItem>>() {
@Override
public TableCell<OfferBookListItem, OfferBookListItem> call(TableColumn<OfferBookListItem, OfferBookListItem> column) {
return new TableCell<OfferBookListItem, OfferBookListItem>() {
private OfferBookListItem offerBookListItem;
final ChangeListener<Number> listener = new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
if (offerBookListItem != null && offerBookListItem.getOffer().getVolume() != null) {
setGraphic(new ColoredDecimalPlacesWithZerosText(model.getVolume(offerBookListItem), model.getNumberOfDecimalsForVolume(offerBookListItem)));
model.priceFeedService.updateCounterProperty().removeListener(listener);
}
}
};
@Override
public void updateItem(final OfferBookListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
if (item.getOffer().getPrice() == null) {
this.offerBookListItem = item;
model.priceFeedService.updateCounterProperty().addListener(listener);
setText(Res.get("shared.na"));
setGraphic(null);
} else {
setText("");
setGraphic(new ColoredDecimalPlacesWithZerosText(model.getVolume(item), model.getNumberOfDecimalsForVolume(item)));
}
} else {
if (listener != null)
model.priceFeedService.updateCounterProperty().removeListener(listener);
this.offerBookListItem = null;
setText("");
setGraphic(null);
}
}
};
}
});
return column;
}
use of javafx.beans.value.ObservableValue in project bisq-desktop by bisq-network.
the class OfferBookChartView method getOfferTable.
private Tuple4<TableView<OfferListItem>, VBox, Button, Label> getOfferTable(OfferPayload.Direction direction) {
TableView<OfferListItem> tableView = new TableView<>();
tableView.setMinHeight(initialOfferTableViewHeight);
tableView.setPrefHeight(121);
tableView.setMinWidth(480);
tableView.getStyleClass().add("offer-table");
// price
TableColumn<OfferListItem, OfferListItem> priceColumn = new TableColumn<>();
priceColumn.textProperty().bind(priceColumnLabel);
priceColumn.setMinWidth(115);
priceColumn.setMaxWidth(115);
priceColumn.setSortable(false);
priceColumn.getStyleClass().add("number-column");
priceColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
priceColumn.setCellFactory(new Callback<TableColumn<OfferListItem, OfferListItem>, TableCell<OfferListItem, OfferListItem>>() {
@Override
public TableCell<OfferListItem, OfferListItem> call(TableColumn<OfferListItem, OfferListItem> column) {
return new TableCell<OfferListItem, OfferListItem>() {
private Offer offer;
final ChangeListener<Number> listener = new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
if (offer != null && offer.getPrice() != null) {
setText("");
setGraphic(new ColoredDecimalPlacesWithZerosText(model.getPrice(offer), model.getZeroDecimalsForPrice(offer)));
model.priceFeedService.updateCounterProperty().removeListener(listener);
}
}
};
@Override
public void updateItem(final OfferListItem offerListItem, boolean empty) {
super.updateItem(offerListItem, empty);
if (offerListItem != null && !empty) {
final Offer offer = offerListItem.offer;
if (offer.getPrice() == null) {
this.offer = offer;
model.priceFeedService.updateCounterProperty().addListener(listener);
setText(Res.get("shared.na"));
} else {
setGraphic(new ColoredDecimalPlacesWithZerosText(model.getPrice(offer), model.getZeroDecimalsForPrice(offer)));
}
} else {
if (listener != null)
model.priceFeedService.updateCounterProperty().removeListener(listener);
this.offer = null;
setText("");
setGraphic(null);
}
}
};
}
});
// volume
TableColumn<OfferListItem, OfferListItem> volumeColumn = new TableColumn<>();
volumeColumn.setMinWidth(115);
volumeColumn.setSortable(false);
volumeColumn.textProperty().bind(volumeColumnLabel);
volumeColumn.getStyleClass().add("number-column");
volumeColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
volumeColumn.setCellFactory(new Callback<TableColumn<OfferListItem, OfferListItem>, TableCell<OfferListItem, OfferListItem>>() {
@Override
public TableCell<OfferListItem, OfferListItem> call(TableColumn<OfferListItem, OfferListItem> column) {
return new TableCell<OfferListItem, OfferListItem>() {
private Offer offer;
final ChangeListener<Number> listener = new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
if (offer != null && offer.getPrice() != null) {
setText("");
setGraphic(new ColoredDecimalPlacesWithZerosText(model.getVolume(offer), model.getMaxNumberOfPriceZeroDecimalsToColorize(offer)));
model.priceFeedService.updateCounterProperty().removeListener(listener);
}
}
};
@Override
public void updateItem(final OfferListItem offerListItem, boolean empty) {
super.updateItem(offerListItem, empty);
if (offerListItem != null && !empty) {
this.offer = offerListItem.offer;
if (offer.getPrice() == null) {
this.offer = offerListItem.offer;
model.priceFeedService.updateCounterProperty().addListener(listener);
setText(Res.get("shared.na"));
} else {
setText("");
setGraphic(new ColoredDecimalPlacesWithZerosText(model.getVolume(offer), model.getMaxNumberOfPriceZeroDecimalsToColorize(offer)));
}
} else {
if (listener != null)
model.priceFeedService.updateCounterProperty().removeListener(listener);
this.offer = null;
setText("");
setGraphic(null);
}
}
};
}
});
// amount
TableColumn<OfferListItem, OfferListItem> amountColumn = new AutoTooltipTableColumn<>(Res.get("shared.amountWithCur", Res.getBaseCurrencyCode()));
amountColumn.setMinWidth(115);
amountColumn.setSortable(false);
amountColumn.getStyleClass().add("number-column");
amountColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
amountColumn.setCellFactory(new Callback<TableColumn<OfferListItem, OfferListItem>, TableCell<OfferListItem, OfferListItem>>() {
@Override
public TableCell<OfferListItem, OfferListItem> call(TableColumn<OfferListItem, OfferListItem> column) {
return new TableCell<OfferListItem, OfferListItem>() {
@Override
public void updateItem(final OfferListItem offerListItem, boolean empty) {
super.updateItem(offerListItem, empty);
if (offerListItem != null && !empty) {
setGraphic(new ColoredDecimalPlacesWithZerosText(formatter.formatCoin(offerListItem.offer.getAmount(), 4), GUIUtil.AMOUNT_DECIMALS_WITH_ZEROS));
} else {
setGraphic(null);
}
}
};
}
});
tableView.getColumns().add(volumeColumn);
tableView.getColumns().add(amountColumn);
tableView.getColumns().add(priceColumn);
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
Label placeholder = new AutoTooltipLabel(Res.get("table.placeholder.noItems", Res.get("shared.multipleOffers")));
placeholder.setWrapText(true);
tableView.setPlaceholder(placeholder);
Label titleLabel = new AutoTooltipLabel();
titleLabel.getStyleClass().add("table-title");
UserThread.execute(() -> titleLabel.prefWidthProperty().bind(tableView.widthProperty()));
boolean isSellOffer = direction == OfferPayload.Direction.SELL;
Button button = new AutoTooltipButton();
ImageView iconView = new ImageView();
iconView.setId(isSellOffer ? "image-buy-white" : "image-sell-white");
button.setGraphic(iconView);
button.setGraphicTextGap(10);
button.setText(isSellOffer ? Res.get("market.offerBook.buy") : Res.get("market.offerBook.sell"));
button.setMinHeight(40);
button.setId(isSellOffer ? "buy-button-big" : "sell-button-big");
button.setOnAction(e -> {
if (isSellOffer) {
model.preferences.setBuyScreenCurrencyCode(model.getCurrencyCode());
// noinspection unchecked
navigation.navigateTo(MainView.class, BuyOfferView.class);
} else {
model.preferences.setSellScreenCurrencyCode(model.getCurrencyCode());
// noinspection unchecked
navigation.navigateTo(MainView.class, SellOfferView.class);
}
});
VBox vBox = new VBox();
vBox.setSpacing(10);
vBox.setFillWidth(true);
vBox.setMinHeight(190);
vBox.setVgrow(tableView, Priority.ALWAYS);
vBox.getChildren().addAll(titleLabel, tableView, button);
button.prefWidthProperty().bind(vBox.widthProperty());
return new Tuple4<>(tableView, vBox, button, titleLabel);
}
use of javafx.beans.value.ObservableValue 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;
}
use of javafx.beans.value.ObservableValue 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.beans.value.ObservableValue in project assembly64fx by freabemania.
the class SearchController method init.
public void init(Artifact searchEntry) throws Exception {
localDb = LocalDBService.getInstance();
userService = UserService.getInstance();
searchService = SearchService.getInstance();
mappingService = CategoryMappingService.getInstance();
// populate years
table.setPlaceholder(new Label(""));
yearInput.getItems().add(ALL);
IntStream.range(1980, Calendar.getInstance().get(Calendar.YEAR) + 1).forEach(item -> yearInput.getItems().add(String.valueOf(item)));
yearInput.getSelectionModel().selectFirst();
// populate ratings
ratingInput.getItems().add(ALL);
IntStream.range(1, 10).forEach(item -> ratingInput.getItems().add(String.valueOf(item)));
ratingInput.getSelectionModel().selectFirst();
categoryInput.getItems().add(ALL);
List<CategoryMapping> l = new ArrayList<CategoryMapping>(mappingService.values());
Collections.sort(l, (i1, i2) -> i1.getDescription().toLowerCase().compareTo(i2.getDescription().toLowerCase()));
l.stream().forEach(item -> categoryInput.getItems().add(item.getDescription()));
if (searchEntry != null) {
try {
CategoryMapping categoryMappingByName = mappingService.getCategoryMappingByName(searchEntry.getDatabaseId());
categoryInput.getSelectionModel().select(categoryMappingByName.getDescription());
} catch (Exception e) {
categoryInput.getSelectionModel().selectFirst();
}
} else {
categoryInput.getSelectionModel().selectFirst();
}
name.setCellValueFactory(new PropertyValueFactory<SearchResultItem, String>("name"));
group.setCellValueFactory(new PropertyValueFactory<SearchResultItem, String>("group"));
year.setCellValueFactory(new PropertyValueFactory<SearchResultItem, Integer>("year"));
handle.setCellValueFactory(new PropertyValueFactory<SearchResultItem, String>("handle"));
event.setCellValueFactory(new PropertyValueFactory<SearchResultItem, String>("event"));
group.setCellValueFactory(new PropertyValueFactory<SearchResultItem, String>("group"));
rating.setCellValueFactory(new PropertyValueFactory<SearchResultItem, Integer>("rating"));
category.setCellValueFactory(new PropertyValueFactory<SearchResultItem, String>("categoryName"));
updated.setCellValueFactory(new PropertyValueFactory<SearchResultItem, String>("updated"));
EventHandler<MouseEvent> mouseEventHandle = (MouseEvent event) -> {
handleMouseClicked(event);
};
table.setOnKeyTyped(event -> {
if (event.getCharacter().length() > 0 && event.getCharacter().charAt(0) == ENTER_KEY) {
openFiles();
}
});
table.addEventHandler(MouseEvent.MOUSE_PRESSED, mouseEventHandle);
table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
registerSearchOnEnter(nameInput);
registerSearchOnEnter(groupInput);
registerSearchOnEnter(handleInput);
registerSearchOnEnter(eventInput);
registerChoice(yearInput);
registerChoice(categoryInput);
registerChoice(ratingInput);
checkCheckbox(t64, T64SEARCH);
checkCheckbox(d64, D64SEARCH);
checkCheckbox(d71, T71SEARCH);
checkCheckbox(d81, T81SEARCH);
checkCheckbox(prg, PRGSEARCH);
checkCheckbox(tap, TAPSEARCH);
checkCheckbox(crt, CRTSEARCH);
checkCheckbox(bin, BINSEARCH);
checkCheckbox(sid, SIDSEARCH);
checkCheckbox(g64, G64SEARCH);
searchPeriod.setItems(FXCollections.observableArrayList(SEARCH_PERIOD.ALL, SEARCH_PERIOD.ONE_DAY, SEARCH_PERIOD.TWO_DAYS, SEARCH_PERIOD.FOUR_DAYS, SEARCH_PERIOD.ONE_WEEK, SEARCH_PERIOD.TWO_WEEKS, SEARCH_PERIOD.THREE_WEEKS, SEARCH_PERIOD.ONE_MONTH, SEARCH_PERIOD.TWO_MONTHS));
searchPeriod.getSelectionModel().select(0);
try {
searchPeriod.getSelectionModel().selectedItemProperty().addListener((ObservableValue<? extends SEARCH_PERIOD> observable, SEARCH_PERIOD oldValue, SEARCH_PERIOD newValue) -> performSearch());
} catch (Exception e) {
logger.error("Unable to install listener", e);
}
registerCheckboxChangeForSearch(t64, T64SEARCH);
registerCheckboxChangeForSearch(d64, D64SEARCH);
registerCheckboxChangeForSearch(d71, T71SEARCH);
registerCheckboxChangeForSearch(d81, T81SEARCH);
registerCheckboxChangeForSearch(prg, PRGSEARCH);
registerCheckboxChangeForSearch(tap, TAPSEARCH);
registerCheckboxChangeForSearch(crt, CRTSEARCH);
registerCheckboxChangeForSearch(bin, BINSEARCH);
registerCheckboxChangeForSearch(sid, SIDSEARCH);
registerCheckboxChangeForSearch(g64, G64SEARCH);
searchFromStartOfString.selectedProperty().addListener(new ChangeListener<Boolean>() {
public void changed(ObservableValue<? extends Boolean> ov, Boolean oldVal, Boolean newVal) {
ExecutorUtil.executeAsyncWithRetry(() -> {
localDb.addLocalDBSetting("search_from_start", String.valueOf(newVal));
return null;
});
}
});
String val = localDb.getLocalDBSetting("search_from_start");
if (val != null) {
searchFromStartOfString.setSelected(Boolean.valueOf(val));
} else {
searchFromStartOfString.setSelected(true);
}
if (!userService.isLocationSelectedAndExisting()) {
downloadFolderImage.setVisible(false);
}
}
Aggregations