use of javafx.beans.value.ChangeListener in project SmartCity-Market by TechnionYP5777.
the class ManageEmployeesTab method initialize.
@Override
public void initialize(URL location, ResourceBundle __) {
userTxt.textProperty().addListener((observable, oldValue, newValue) -> enableFinishBtn());
passTxt.textProperty().addListener((observable, oldValue, newValue) -> enableFinishBtn());
securityAnswerTxt.textProperty().addListener((observable, oldValue, newValue) -> enableFinishBtn());
radioBtnCont.addRadioButtons(Arrays.asList(new RadioButton[] { workerRadioBtn, managerRadioBtn }));
securityCombo.getItems().addAll(SecurityQuestions.getQuestions());
RequiredFieldValidator validator2 = new RequiredFieldValidator();
validator2.setMessage("Input Required");
validator2.setIcon(GlyphsBuilder.create(FontAwesomeIconView.class).glyph(FontAwesomeIcon.WARNING).size("1em").styleClass("error").build());
userTxt.getValidators().add(validator2);
userTxt.focusedProperty().addListener((o, oldVal, newVal) -> {
if (!newVal)
userTxt.validate();
});
RequiredFieldValidator validator3 = new RequiredFieldValidator();
validator3.setMessage("Input Required");
validator3.setIcon(GlyphsBuilder.create(FontAwesomeIconView.class).glyph(FontAwesomeIcon.WARNING).size("1em").styleClass("error").build());
passTxt.getValidators().add(validator3);
passTxt.focusedProperty().addListener((o, oldVal, newVal) -> {
if (!newVal)
passTxt.validate();
});
RequiredFieldValidator validator4 = new RequiredFieldValidator();
validator4.setMessage("Input Required");
validator4.setIcon(GlyphsBuilder.create(FontAwesomeIconView.class).glyph(FontAwesomeIcon.WARNING).size("1em").styleClass("error").build());
securityAnswerTxt.getValidators().add(validator4);
securityAnswerTxt.focusedProperty().addListener((o, oldVal, newVal) -> {
if (!newVal)
securityAnswerTxt.validate();
});
createEmployeesList();
searchEmployee.textProperty().addListener(obs -> {
String filter = searchEmployee.getText();
filteredDataEmployees.setPredicate(filter == null || filter.length() == 0 ? s -> true : s -> s.contains(filter));
});
employeesList.setCellFactory(CheckBoxListCell.forListView(new Callback<String, ObservableValue<Boolean>>() {
@Override
public ObservableValue<Boolean> call(String item) {
BooleanProperty observable = new SimpleBooleanProperty();
observable.set(selectedEmployees.contains(item));
observable.addListener((obs, wasSelected, isNowSelected) -> {
if (isNowSelected)
selectedEmployees.add(item);
else
selectedEmployees.remove(item);
enableRemoveButton();
});
return observable;
}
}));
securityCombo.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> __, String oldValue, String newValue) {
enableFinishBtn();
}
});
enableFinishBtn();
enableRemoveButton();
}
use of javafx.beans.value.ChangeListener in project jmeter by apache.
the class RenderInBrowser method createScene.
private void createScene(final String htmlContent) {
Platform.setImplicitExit(false);
Platform.runLater(new Runnable() {
@Override
public void run() {
WebView view = new WebView();
engine = view.getEngine();
engine.setOnStatusChanged(event -> SwingUtilities.invokeLater(() -> lblStatus.setText(event.getData())));
engine.getLoadWorker().workDoneProperty().addListener((ChangeListener<Number>) (observableValue, oldValue, newValue) -> SwingUtilities.invokeLater(() -> progressBar.setValue(newValue.intValue())));
engine.getLoadWorker().exceptionProperty().addListener(new ChangeListener<Throwable>() {
@Override
public void changed(ObservableValue<? extends Throwable> o, Throwable old, final Throwable value) {
if (engine.getLoadWorker().getState() == State.FAILED) {
SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(resultsScrollPane, (value != null) ? engine.getLocation() + "\n" + value.getMessage() : engine.getLocation() + "\nUnexpected error.", "Loading error...", JOptionPane.ERROR_MESSAGE));
}
}
});
jfxPanel.setScene(new Scene(view));
}
});
}
use of javafx.beans.value.ChangeListener in project bitsquare by bitsquare.
the class OfferBookChartView method getOfferTable.
private Tuple4<TableView<OfferListItem>, VBox, Button, Label> getOfferTable(Offer.Direction direction) {
TableView<OfferListItem> tableView = new TableView<>();
tableView.setMinHeight(109);
tableView.setPrefHeight(121);
//530
tableView.setMinWidth(480);
// price
TableColumn<OfferListItem, OfferListItem> priceColumn = new TableColumn<>();
priceColumn.textProperty().bind(priceColumnLabel);
//130
priceColumn.setMinWidth(115);
//130
priceColumn.setMaxWidth(115);
priceColumn.setSortable(false);
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;
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(formatter.formatPrice(offer.getPrice()));
model.priceFeedService.currenciesUpdateFlagProperty().removeListener(listener);
}
}
};
@Override
public void updateItem(final OfferListItem offerListItem, boolean empty) {
super.updateItem(offerListItem, empty);
if (offerListItem != null && !empty) {
if (offerListItem.offer.getPrice() == null) {
this.offer = offerListItem.offer;
model.priceFeedService.currenciesUpdateFlagProperty().addListener(listener);
setText("N/A");
} else {
setText(formatter.formatPrice(offerListItem.offer.getPrice()));
}
} else {
if (listener != null)
model.priceFeedService.currenciesUpdateFlagProperty().removeListener(listener);
this.offer = null;
setText("");
}
}
};
}
});
// volume
TableColumn<OfferListItem, OfferListItem> volumeColumn = new TableColumn<>();
//125
volumeColumn.setMinWidth(115);
volumeColumn.setSortable(false);
volumeColumn.textProperty().bind(volumeColumnLabel);
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;
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(formatter.formatVolume(offer.getOfferVolume()));
model.priceFeedService.currenciesUpdateFlagProperty().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.currenciesUpdateFlagProperty().addListener(listener);
setText("N/A");
} else {
setText(formatter.formatVolume(offer.getOfferVolume()));
}
} else {
if (listener != null)
model.priceFeedService.currenciesUpdateFlagProperty().removeListener(listener);
this.offer = null;
setText("");
}
}
};
}
});
// amount
TableColumn<OfferListItem, OfferListItem> amountColumn = new TableColumn<>("Amount in BTC");
//125
amountColumn.setMinWidth(115);
amountColumn.setSortable(false);
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)
setText(formatter.formatCoin(offerListItem.offer.getAmount()));
else
setText("");
}
};
}
});
// accumulated
TableColumn<OfferListItem, OfferListItem> accumulatedColumn = new TableColumn<>("Sum in BTC");
//130
accumulatedColumn.setMinWidth(100);
accumulatedColumn.setSortable(false);
accumulatedColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
accumulatedColumn.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)
setText(formatter.formatRoundedDoubleWithPrecision(offerListItem.accumulated, 4));
else
setText("");
}
};
}
});
if (direction == Offer.Direction.BUY) {
tableView.getColumns().add(accumulatedColumn);
tableView.getColumns().add(volumeColumn);
tableView.getColumns().add(amountColumn);
tableView.getColumns().add(priceColumn);
} else {
tableView.getColumns().add(priceColumn);
tableView.getColumns().add(amountColumn);
tableView.getColumns().add(volumeColumn);
tableView.getColumns().add(accumulatedColumn);
}
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
Label placeholder = new Label("Currently there are no offers available");
placeholder.setWrapText(true);
tableView.setPlaceholder(placeholder);
Label titleLabel = new Label();
titleLabel.setStyle("-fx-font-weight: bold; -fx-font-size: 16; -fx-alignment: center");
UserThread.execute(() -> titleLabel.prefWidthProperty().bind(tableView.widthProperty()));
boolean isSellOffer = direction == Offer.Direction.SELL;
Button button = new Button();
ImageView iconView = new ImageView();
iconView.setId(isSellOffer ? "image-buy-white" : "image-sell-white");
button.setGraphic(iconView);
button.setGraphicTextGap(10);
button.setText(isSellOffer ? "I want to buy bitcoin" : "I want to sell bitcoin");
button.setMinHeight(40);
button.setId(isSellOffer ? "buy-button-big" : "sell-button-big");
button.setOnAction(e -> {
if (isSellOffer) {
model.preferences.setBuyScreenCurrencyCode(model.getCurrencyCode());
navigation.navigateTo(MainView.class, BuyOfferView.class);
} else {
model.preferences.setSellScreenCurrencyCode(model.getCurrencyCode());
navigation.navigateTo(MainView.class, SellOfferView.class);
}
});
VBox vBox = new VBox();
vBox.setSpacing(10);
vBox.setFillWidth(true);
vBox.setMinHeight(190);
vBox.getChildren().addAll(titleLabel, tableView, button);
button.prefWidthProperty().bind(vBox.widthProperty());
return new Tuple4<>(tableView, vBox, button, titleLabel);
}
use of javafx.beans.value.ChangeListener in project jgnash by ccavanaugh.
the class BudgetTableController method initialize.
@FXML
private void initialize() {
final Preferences preferences = Preferences.userNodeForPackage(BudgetTableController.class);
runningTotalsButton.selectedProperty().setValue(preferences.getBoolean(RUNNING_TOTALS, false));
rateLimitExecutor = new ScheduledThreadPoolExecutor(1, new DefaultDaemonThreadFactory(), new ThreadPoolExecutor.DiscardPolicy());
tableWidthChangeListener = (observable, oldValue, newValue) -> {
if (newValue != null && !oldValue.equals(newValue)) {
optimizeColumnWidths();
}
};
updateHeights();
yearSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(LocalDate.now().getYear() - YEAR_MARGIN, LocalDate.now().getYear() + YEAR_MARGIN, LocalDate.now().getYear(), 1));
accountTreeView.getStylesheets().addAll(StyleClass.HIDE_VERTICAL_CSS);
accountTreeView.setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
accountTreeView.setShowRoot(false);
accountTreeView.setEditable(true);
accountTreeView.fixedCellSizeProperty().bind(rowHeight);
accountSummaryTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
accountSummaryTable.getStylesheets().addAll(StyleClass.HIDE_VERTICAL_CSS, StyleClass.HIDE_HORIZONTAL_CSS);
accountSummaryTable.setItems(expandedAccountList);
accountSummaryTable.fixedCellSizeProperty().bind(rowHeight);
accountSummaryTable.setSelectionModel(new NullTableViewSelectionModel<>(accountSummaryTable));
accountTypeTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
accountTypeTable.getStylesheets().add(StyleClass.HIDE_HEADER_CSS);
accountTypeTable.setItems(accountGroupList);
accountTypeTable.fixedCellSizeProperty().bind(rowHeight);
accountTypeTable.prefHeightProperty().bind(rowHeight.multiply(Bindings.size(accountGroupList)).add(BORDER_MARGIN));
accountTypeTable.setSelectionModel(new NullTableViewSelectionModel<>(accountTypeTable));
accountGroupPeriodSummaryTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
accountGroupPeriodSummaryTable.getStylesheets().addAll(StyleClass.HIDE_HEADER_CSS, StyleClass.HIDE_HORIZONTAL_CSS, StyleClass.HIDE_VERTICAL_CSS);
accountGroupPeriodSummaryTable.setItems(accountGroupList);
accountGroupPeriodSummaryTable.fixedCellSizeProperty().bind(rowHeight);
accountGroupPeriodSummaryTable.prefHeightProperty().bind(rowHeight.multiply(Bindings.size(accountGroupList)).add(BORDER_MARGIN));
accountGroupPeriodSummaryTable.setSelectionModel(new NullTableViewSelectionModel<>(accountGroupPeriodSummaryTable));
buildAccountTreeTable();
buildAccountTypeTable();
buildAccountSummaryTable();
buildAccountGroupSummaryTable();
accountSummaryTable.maxWidthProperty().bind(minSummaryColumnWidth.multiply(3.0).add(BORDER_MARGIN));
accountGroupPeriodSummaryTable.maxWidthProperty().bind(minSummaryColumnWidth.multiply(3.0).add(BORDER_MARGIN));
accountSummaryTable.minWidthProperty().bind(minSummaryColumnWidth.multiply(3.0).add(BORDER_MARGIN));
accountGroupPeriodSummaryTable.minWidthProperty().bind(minSummaryColumnWidth.multiply(3.0).add(BORDER_MARGIN));
accountTreeView.expandedItemCountProperty().addListener((observable, oldValue, newValue) -> JavaFXUtils.runLater(this::updateExpandedAccountList));
final ChangeListener<Object> budgetChangeListener = (observable, oldValue, newValue) -> handleBudgetChange();
budget.addListener(budgetChangeListener);
yearSpinner.valueProperty().addListener(budgetChangeListener);
runningTotalsButton.selectedProperty().addListener(budgetChangeListener);
visibleColumnCount.addListener(budgetChangeListener);
runningTotalsButton.selectedProperty().addListener((observable, oldValue, newValue) -> preferences.putBoolean(RUNNING_TOTALS, newValue));
/* Setting the tables as un-managed effectively removes these tables from the GridPane. The tables are
redundant if showing the amounts as running balances. */
accountSummaryTable.managedProperty().bind(runningTotalsButton.selectedProperty().not());
accountGroupPeriodSummaryTable.managedProperty().bind(runningTotalsButton.selectedProperty().not());
horizontalScrollBar.setMin(0);
horizontalScrollBar.maxProperty().bind(periodCount.subtract(visibleColumnCount));
horizontalScrollBar.setUnitIncrement(1);
horizontalScrollBar.disableProperty().bind(periodCount.lessThanOrEqualTo(1));
// shift the table right and left with the ScrollBar value
horizontalScrollBar.valueProperty().addListener((observable, oldValue, newValue) -> {
/* must be synchronized to prevent a race condition from multiple events and an out of
* bounds exception */
synchronized (this) {
/* don't try unless columns exist. This can occur if the UI is not large enough to display
* a minimum of one period of information.
*/
if (periodTable.getColumns().size() > 0) {
final int newIndex = (int) Math.round(newValue.doubleValue());
if (newIndex > index) {
while (newIndex > index) {
handleShiftRight();
}
} else if (newIndex < index) {
while (newIndex < index) {
handleShiftLeft();
}
}
}
}
});
ThemeManager.fontScaleProperty().addListener((observable, oldValue, newValue) -> updateHeights());
}
use of javafx.beans.value.ChangeListener in project jgnash by ccavanaugh.
the class AccountBalanceChartController method initialize.
@FXML
public void initialize() {
accountComboBox.setPredicate(AccountComboBox.getShowAllPredicate());
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
periodComboBox.getItems().addAll(ReportPeriod.MONTHLY, ReportPeriod.QUARTERLY, ReportPeriod.YEARLY);
periodComboBox.setValue(ReportPeriod.values()[preferences.getInt(REPORT_PERIOD, ReportPeriod.MONTHLY.ordinal())]);
defaultCurrency = engine.getDefaultCurrency();
numberFormat = CommodityFormat.getFullNumberFormat(defaultCurrency);
barChart.getStylesheets().addAll(CHART_CSS);
barChart.getYAxis().setLabel(defaultCurrency.getSymbol());
barChart.barGapProperty().set(BAR_GAP);
barChart.setCategoryGap(CATEGORY_GAP);
barChart.setLegendVisible(false);
barChart.getXAxis().setLabel(resources.getString("Column.Period"));
barChart.getYAxis().setLabel(resources.getString("Column.Balance") + " : " + defaultCurrency.getSymbol());
// Respect animation preference
barChart.animatedProperty().set(Options.animationsEnabledProperty().get());
startDatePicker.setValue(DateUtils.getFirstDayOfTheMonth(endDatePicker.getValue().minusMonths(12)));
// Force a defaults
includeSubAccounts.setSelected(preferences.getBoolean(SUB_ACCOUNTS, true));
runningBalanceRadioButton.setSelected(preferences.getBoolean(RUNNING_BALANCE, true));
endingBalanceRadioButton.setSelected(preferences.getBoolean(ENDING_BALANCE, false));
invertBalanceCheckBox.setSelected(preferences.getBoolean(INVERT_BALANCES, true));
restoreSelectedAccounts();
accountComboBox.valueProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
defaultCurrency = newValue.getCurrencyNode();
numberFormat = CommodityFormat.getFullNumberFormat(defaultCurrency);
Platform.runLater(AccountBalanceChartController.this::updateChart);
Platform.runLater(AccountBalanceChartController.this::saveSelectedAccounts);
}
});
// Generic listener. No super efficient but reduces listener count
final ChangeListener<Object> listener = (observable, oldValue, newValue) -> {
if (newValue != null) {
Platform.runLater(AccountBalanceChartController.this::updateChart);
preferences.putBoolean(ENDING_BALANCE, endingBalanceRadioButton.isSelected());
preferences.putBoolean(RUNNING_BALANCE, runningBalanceRadioButton.isSelected());
preferences.putBoolean(SUB_ACCOUNTS, includeSubAccounts.isSelected());
preferences.putInt(REPORT_PERIOD, periodComboBox.getValue().ordinal());
preferences.putBoolean(INVERT_BALANCES, invertBalanceCheckBox.isSelected());
}
};
// load the initial aux account combo
addAuxAccountCombo(null);
periodComboBox.valueProperty().addListener(listener);
startDatePicker.valueProperty().addListener(listener);
endDatePicker.valueProperty().addListener(listener);
runningBalanceRadioButton.selectedProperty().addListener(listener);
endingBalanceRadioButton.selectedProperty().addListener(listener);
includeSubAccounts.selectedProperty().addListener(listener);
invertBalanceCheckBox.selectedProperty().addListener(listener);
// Push the initial load to the end of the platform thread for better startup and a nicer visual effect
Platform.runLater(this::updateChart);
}
Aggregations