use of javafx.collections.ObservableList in project org.csstudio.display.builder by kasemir.
the class RulesDialog method createContent.
private SplitPane createContent() {
final Node rules = createRulesTable();
final HBox pvs = createPVsTable();
final HBox exprs = createExpressionsTable();
// Display PVs of currently selected rule
rules_table.getSelectionModel().selectedItemProperty().addListener((prop, old, selected) -> {
selected_rule_item = selected;
if (selected == null) {
pvs.setDisable(true);
exprs.setDisable(true);
btn_remove_rule.setDisable(true);
btn_dup_rule.setDisable(true);
btn_move_rule_up.setDisable(true);
btn_move_rule_down.setDisable(true);
btn_show_script.setDisable(true);
propComboBox.setDisable(true);
propComboBox.getSelectionModel().select(null);
valExpBox.setDisable(true);
pv_items.clear();
expression_items.clear();
} else {
pvs.setDisable(false);
exprs.setDisable(false);
final TableViewSelectionModel<RuleItem> model = rules_table.getSelectionModel();
btn_remove_rule.setDisable(false);
btn_dup_rule.setDisable(false);
btn_move_rule_up.setDisable(model.getSelectedIndex() == 0);
btn_move_rule_down.setDisable(model.getSelectedIndex() == rule_items.size() - 1);
btn_show_script.setDisable(false);
propComboBox.setDisable(false);
propComboBox.getSelectionModel().select(getPropLongString(selected));
valExpBox.setDisable(false);
valExpBox.selectedProperty().set(selected.prop_as_expr.get());
pv_items.setAll(selected.pvs);
expression_items.setAll(selected.expressions);
fixupPVs(0);
}
});
// Update PVs of selected rule from PVs table
final ListChangeListener<PVTableItem> pll = change -> {
final RuleItem selected = rules_table.getSelectionModel().getSelectedItem();
if (selected != null)
selected.pvs = new ArrayList<>(change.getList());
};
pv_items.addListener(pll);
// Update buttons for currently selected PV
pvs_table.getSelectionModel().selectedItemProperty().addListener((prop, old, selected) -> {
if (selected == null) {
btn_rm_pv.setDisable(true);
btn_move_pv_up.setDisable(true);
btn_move_pv_down.setDisable(true);
} else {
final TableViewSelectionModel<PVTableItem> model = pvs_table.getSelectionModel();
btn_rm_pv.setDisable(false);
btn_move_pv_up.setDisable(model.getSelectedIndex() == 0);
btn_move_pv_down.setDisable(model.getSelectedIndex() == pv_items.size() - 1);
}
});
// Update Expressions of selected rule from Expressions table
final ListChangeListener<ExprItem<?>> ell = change -> {
final RuleItem selected = rules_table.getSelectionModel().getSelectedItem();
if (selected != null)
selected.expressions = new ArrayList<>(change.getList());
};
expression_items.addListener(ell);
// Update buttons for currently selected expression
expressions_table.getSelectionModel().selectedItemProperty().addListener((prop, old, selected) -> {
if (selected == null) {
btn_rm_exp.setDisable(true);
btn_move_exp_up.setDisable(true);
btn_move_exp_down.setDisable(true);
} else {
final TableViewSelectionModel<ExprItem<?>> model = expressions_table.getSelectionModel();
btn_rm_exp.setDisable(false);
btn_move_exp_up.setDisable(model.getSelectedIndex() == 0);
btn_move_exp_down.setDisable(model.getSelectedIndex() == expression_items.size() - 1);
}
});
// What is the property id option we are using?
final Label propLabel = new Label("Property ID:");
// Show each property with current value
final ObservableList<String> prop_id_opts = FXCollections.observableArrayList();
for (PropInfo pi : propinfo_ls) {
// Property _value_ can be long, ex. points of a polyline
// Truncate the value that's shown in the combo box
// to prevent combo from using all screen width.
String prop_opt = pi.toString();
if (prop_opt.length() > MAX_PROP_LENGTH)
prop_opt = prop_opt.substring(0, MAX_PROP_LENGTH) + "...";
prop_id_opts.add(prop_opt);
}
propComboBox = new ComboBox<String>(prop_id_opts);
propComboBox.setDisable(true);
propComboBox.getSelectionModel().selectedIndexProperty().addListener((p, o, index) -> {
// Select property info based on index within combo.
final int idx = index.intValue();
if (idx >= 0) {
final PropInfo prop = propinfo_ls.get(idx);
if (selected_rule_item.tryUpdatePropID(undo, prop.getPropID()))
expression_items.setAll(selected_rule_item.expressions);
}
});
propComboBox.setMinHeight(27);
propComboBox.setMaxWidth(Double.MAX_VALUE);
HBox.setHgrow(propComboBox, Priority.ALWAYS);
// TODO: change this to actually manipulate expression objects in the rule
valExpBox = new CheckBox("Value as Expression");
valExpBox.setDisable(true);
valExpBox.selectedProperty().addListener((ov, old_val, new_val) -> {
if (!selected_rule_item.tryTogglePropAsExpr(undo, new_val))
logger.log(Level.FINE, "Did not update rule property as expression flag to " + new_val);
else
expression_items.setAll(selected_rule_item.expressions);
});
final Region spring = new Region();
HBox.setHgrow(spring, Priority.ALWAYS);
final HBox props = new HBox(10, propLabel, propComboBox, spring, valExpBox);
props.setAlignment(Pos.CENTER);
pvs.setPadding(new Insets(0, 10, 0, 0));
exprs.setPadding(new Insets(0, 0, 0, 10));
HBox.setHgrow(pvs, Priority.ALWAYS);
HBox.setHgrow(exprs, Priority.ALWAYS);
final Preferences pref = Preferences.userNodeForPackage(RulesDialog.class);
final double prefRSPDividerPosition = pref.getDouble("rule.content.divider.position", 0.5);
ruleSplitPane = new SplitPane(pvs, exprs);
ruleSplitPane.setOrientation(Orientation.HORIZONTAL);
ruleSplitPane.setDividerPositions(prefRSPDividerPosition);
ruleSplitPane.setStyle("-fx-background-insets: 0, 0;");
VBox.setVgrow(ruleSplitPane, Priority.ALWAYS);
final VBox subitems = new VBox(10, props, ruleSplitPane);
final VBox rulebox = new VBox(10, rules);
rulebox.setPadding(new Insets(0, 10, 0, 0));
subitems.setPadding(new Insets(0, 0, 0, 10));
VBox.setVgrow(rules, Priority.ALWAYS);
HBox.setHgrow(subitems, Priority.ALWAYS);
final double prefWidth = pref.getDouble("content.width", -1);
final double prefHeight = pref.getDouble("content.height", -1);
final double prefDividerPosition = pref.getDouble("content.divider.position", 0.3);
final SplitPane splitPane = new SplitPane(rulebox, subitems);
splitPane.setOrientation(Orientation.HORIZONTAL);
splitPane.setDividerPositions(prefDividerPosition);
if (prefWidth > 0 && prefHeight > 0)
splitPane.setPrefSize(prefWidth, prefHeight);
// Select the first rule
if (!rules_table.getItems().isEmpty()) {
Platform.runLater(() -> {
rules_table.getSelectionModel().select(0);
rules_table.requestFocus();
});
} else
Platform.runLater(() -> btn_add_rule.requestFocus());
return splitPane;
}
use of javafx.collections.ObservableList in project bisq-desktop by bisq-network.
the class SpreadViewModel method update.
private void update(ObservableList<OfferBookListItem> offerBookListItems) {
Map<String, List<Offer>> offersByCurrencyMap = new HashMap<>();
for (OfferBookListItem offerBookListItem : offerBookListItems) {
Offer offer = offerBookListItem.getOffer();
String currencyCode = offer.getCurrencyCode();
if (!offersByCurrencyMap.containsKey(currencyCode))
offersByCurrencyMap.put(currencyCode, new ArrayList<>());
offersByCurrencyMap.get(currencyCode).add(offer);
}
spreadItems.clear();
Coin totalAmount = null;
for (String currencyCode : offersByCurrencyMap.keySet()) {
List<Offer> offers = offersByCurrencyMap.get(currencyCode);
final boolean isFiatCurrency = CurrencyUtil.isFiatCurrency(currencyCode);
List<Offer> buyOffers = offers.stream().filter(e -> e.getDirection().equals(OfferPayload.Direction.BUY)).sorted((o1, o2) -> {
long a = o1.getPrice() != null ? o1.getPrice().getValue() : 0;
long b = o2.getPrice() != null ? o2.getPrice().getValue() : 0;
if (a != b) {
if (isFiatCurrency) {
return a < b ? 1 : -1;
} else {
return a < b ? -1 : 1;
}
}
return 0;
}).collect(Collectors.toList());
List<Offer> sellOffers = offers.stream().filter(e -> e.getDirection().equals(OfferPayload.Direction.SELL)).sorted((o1, o2) -> {
long a = o1.getPrice() != null ? o1.getPrice().getValue() : 0;
long b = o2.getPrice() != null ? o2.getPrice().getValue() : 0;
if (a != b) {
if (isFiatCurrency) {
return a > b ? 1 : -1;
} else {
return a > b ? -1 : 1;
}
}
return 0;
}).collect(Collectors.toList());
Price spread = null;
String percentage = "";
Price bestSellOfferPrice = sellOffers.isEmpty() ? null : sellOffers.get(0).getPrice();
Price bestBuyOfferPrice = buyOffers.isEmpty() ? null : buyOffers.get(0).getPrice();
if (bestBuyOfferPrice != null && bestSellOfferPrice != null) {
MarketPrice marketPrice = priceFeedService.getMarketPrice(currencyCode);
// happens again
try {
if (isFiatCurrency)
spread = bestSellOfferPrice.subtract(bestBuyOfferPrice);
else
spread = bestBuyOfferPrice.subtract(bestSellOfferPrice);
if (spread != null && marketPrice != null && marketPrice.isPriceAvailable()) {
double marketPriceAsDouble = marketPrice.getPrice();
final double precision = isFiatCurrency ? Math.pow(10, Fiat.SMALLEST_UNIT_EXPONENT) : Math.pow(10, Altcoin.SMALLEST_UNIT_EXPONENT);
BigDecimal marketPriceAsBigDecimal = BigDecimal.valueOf(marketPriceAsDouble).multiply(BigDecimal.valueOf(precision));
// We multiply with 10000 because we use precision of 2 at % (100.00%)
double result = BigDecimal.valueOf(spread.getValue()).multiply(BigDecimal.valueOf(10000)).divide(marketPriceAsBigDecimal, RoundingMode.HALF_UP).doubleValue() / 10000;
percentage = formatter.formatPercentagePrice(result);
}
} catch (Throwable t) {
try {
// Don't translate msg. It is just for rare error cases and can be removed probably later if
// that error never gets reported again.
String msg = "An error occurred at the spread calculation.\n" + "Error msg: " + t.toString() + "\n" + "Details of offer data: \n" + "bestSellOfferPrice: " + bestSellOfferPrice.getValue() + "\n" + "bestBuyOfferPrice: " + bestBuyOfferPrice.getValue() + "\n" + "sellOffer getCurrencyCode: " + sellOffers.get(0).getCurrencyCode() + "\n" + "buyOffer getCurrencyCode: " + buyOffers.get(0).getCurrencyCode() + "\n\n" + "Please copy and paste this data and send it to the developers so they can investigate the issue.";
new Popup<>().error(msg).show();
log.error(t.toString());
t.printStackTrace();
} catch (Throwable t2) {
log.error(t2.toString());
t2.printStackTrace();
}
}
}
totalAmount = Coin.valueOf(offers.stream().mapToLong(offer -> offer.getAmount().getValue()).sum());
spreadItems.add(new SpreadItem(currencyCode, buyOffers.size(), sellOffers.size(), offers.size(), spread, percentage, totalAmount));
}
maxPlacesForAmount.set(formatAmount(totalAmount, false).length());
}
use of javafx.collections.ObservableList 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();
}
use of javafx.collections.ObservableList in project drbookings by DrBookings.
the class EarningsPerDayChartViewController method doChart.
protected void doChart(final List<? extends BookingEntry> allElements) {
categories.clear();
mapSeries.clear();
chart.getData().clear();
for (int i = 0; i < allElements.size(); i++) {
final BookingEntry db = allElements.get(i);
bin.add(db);
if (bin.stream().map(e -> e.getDate()).collect(Collectors.toSet()).size() >= getBinSize()) {
flushBin();
}
}
flushBin();
final ObservableList<String> c = FXCollections.observableArrayList(categories);
Collections.sort(c);
xAxis.setCategories(c);
xAxis.setAutoRanging(true);
}
use of javafx.collections.ObservableList in project drbookings by DrBookings.
the class MoneyMonitor method calculateDateToEarnings.
private void calculateDateToEarnings(final ObservableList<? extends RoomBean> list) {
final List<BookingEntry> selectedBookings = list.stream().flatMap(r -> r.getFilteredBookingEntries().stream()).collect(Collectors.toList());
dayToNetEarnings.clear();
for (final BookingEntry rb : selectedBookings) {
fillDayMap(rb);
fillMonthYearMap(rb);
}
setTotalNetEarnings(dayToNetEarnings.values().stream().mapToDouble(d -> d.doubleValue()).sum());
}
Aggregations