use of javafx.collections.ListChangeListener in project dolphin-platform by canoo.
the class DefaultJavaFXListBinder method to.
@Override
public <T> Binding to(final ObservableList<T> dolphinList, final Function<? super T, ? extends S> converter) {
Assert.requireNonNull(dolphinList, "dolphinList");
Assert.requireNonNull(converter, "converter");
if (boundLists.containsKey(list)) {
throw new UnsupportedOperationException("A JavaFX list can only be bound to one Dolphin Platform list!");
}
boundLists.put(list, list);
final InternalListChangeListener<T> listChangeListener = new InternalListChangeListener<>(converter);
final Subscription subscription = dolphinList.onChanged(listChangeListener);
list.setAll(dolphinList.stream().map(converter).collect(Collectors.toList()));
ListChangeListener<S> readOnlyListener = c -> {
if (!listChangeListener.onChange) {
throw new UnsupportedOperationException("A JavaFX list that is bound to a dolphin list can only be modified by the binding!");
}
};
list.addListener(readOnlyListener);
return () -> {
subscription.unsubscribe();
list.removeListener(readOnlyListener);
boundLists.remove(list);
};
}
use of javafx.collections.ListChangeListener in project JFoenix by jfoenixadmin.
the class JFXResponsiveHandler method scanAllNodes.
/**
* scans all nodes in the scene and apply the css pseduoClass to them.
*
* @param parent stage parent node
* @param pseudoClass css class for certain device
*/
private void scanAllNodes(Parent parent, PseudoClass pseudoClass) {
parent.getChildrenUnmodifiable().addListener(new ListChangeListener<Node>() {
@Override
public void onChanged(javafx.collections.ListChangeListener.Change<? extends Node> c) {
while (c.next()) if (!c.wasPermutated() && !c.wasUpdated())
for (Node addedNode : c.getAddedSubList()) if (addedNode instanceof Parent)
scanAllNodes((Parent) addedNode, pseudoClass);
}
});
for (Node component : parent.getChildrenUnmodifiable()) {
if (component instanceof Pane) {
((Pane) component).getChildren().addListener(new ListChangeListener<Node>() {
@Override
public void onChanged(javafx.collections.ListChangeListener.Change<? extends Node> c) {
while (c.next()) {
if (!c.wasPermutated() && !c.wasUpdated()) {
for (Node addedNode : c.getAddedSubList()) {
if (addedNode instanceof Parent)
scanAllNodes((Parent) addedNode, pseudoClass);
}
}
}
}
});
//if the component is a container, scan its children
scanAllNodes((Pane) component, pseudoClass);
} else if (component instanceof ScrollPane) {
((ScrollPane) component).contentProperty().addListener((o, oldVal, newVal) -> {
scanAllNodes((Parent) newVal, pseudoClass);
});
//if the component is a container, scan its children
if (((ScrollPane) component).getContent() instanceof Parent) {
scanAllNodes((Parent) ((ScrollPane) component).getContent(), pseudoClass);
}
} else if (component instanceof Control) {
//if the component is an instance of IInputControl, add to list
((Control) component).pseudoClassStateChanged(PSEUDO_CLASS_EX_SMALL, pseudoClass == PSEUDO_CLASS_EX_SMALL);
((Control) component).pseudoClassStateChanged(PSEUDO_CLASS_SMALL, pseudoClass == PSEUDO_CLASS_SMALL);
((Control) component).pseudoClassStateChanged(PSEUDO_CLASS_MEDIUM, pseudoClass == PSEUDO_CLASS_MEDIUM);
((Control) component).pseudoClassStateChanged(PSEUDO_CLASS_LARGE, pseudoClass == PSEUDO_CLASS_LARGE);
}
}
}
use of javafx.collections.ListChangeListener in project bitsquare by bitsquare.
the class MainViewModel method onAllServicesInitialized.
private void onAllServicesInitialized() {
Log.traceCall();
clock.start();
// disputeManager
disputeManager.onAllServicesInitialized();
disputeManager.getDisputesAsObservableList().addListener((ListChangeListener<Dispute>) change -> {
change.next();
onDisputesChangeListener(change.getAddedSubList(), change.getRemoved());
});
onDisputesChangeListener(disputeManager.getDisputesAsObservableList(), null);
// tradeManager
tradeManager.onAllServicesInitialized();
tradeManager.getTrades().addListener((ListChangeListener<Trade>) c -> updateBalance());
tradeManager.getTrades().addListener((ListChangeListener<Trade>) change -> onTradesChanged());
onTradesChanged();
// We handle the trade period here as we display a global popup if we reached dispute time
tradesAndUIReady = EasyBind.combine(isSplashScreenRemoved, tradeManager.pendingTradesInitializedProperty(), (a, b) -> a && b);
tradesAndUIReady.subscribe((observable, oldValue, newValue) -> {
if (newValue)
applyTradePeriodState();
});
// walletService
walletService.addBalanceListener(new BalanceListener() {
@Override
public void onBalanceChanged(Coin balance, Transaction tx) {
updateBalance();
}
});
openOfferManager.getOpenOffers().addListener((ListChangeListener<OpenOffer>) c -> updateBalance());
tradeManager.getTrades().addListener((ListChangeListener<Trade>) c -> updateBalance());
openOfferManager.onAllServicesInitialized();
arbitratorManager.onAllServicesInitialized();
alertManager.alertMessageProperty().addListener((observable, oldValue, newValue) -> displayAlertIfPresent(newValue));
privateNotificationManager.privateNotificationProperty().addListener((observable, oldValue, newValue) -> displayPrivateNotification(newValue));
displayAlertIfPresent(alertManager.alertMessageProperty().get());
p2PService.onAllServicesInitialized();
setupBtcNumPeersWatcher();
setupP2PNumPeersWatcher();
updateBalance();
if (DevFlags.DEV_MODE) {
preferences.setShowOwnOffersInOfferBook(true);
if (user.getPaymentAccounts().isEmpty())
setupDevDummyPaymentAccounts();
}
setupMarketPriceFeed();
swapPendingOfferFundingEntries();
fillPriceFeedComboBoxItems();
showAppScreen.set(true);
// We want to test if the client is compiled with the correct crypto provider (BountyCastle)
// and if the unlimited Strength for cryptographic keys is set.
// If users compile themselves they might miss that step and then would get an exception in the trade.
// To avoid that we add here at startup a sample encryption and signing to see if it don't causes an exception.
// See: https://github.com/bitsquare/bitsquare/blob/master/doc/build.md#7-enable-unlimited-strength-for-cryptographic-keys
Thread checkCryptoThread = new Thread() {
@Override
public void run() {
try {
Thread.currentThread().setName("checkCryptoThread");
log.trace("Run crypto test");
// just use any simple dummy msg
io.bitsquare.p2p.peers.keepalive.messages.Ping payload = new Ping(1, 1);
SealedAndSigned sealedAndSigned = Encryption.encryptHybridWithSignature(payload, keyRing.getSignatureKeyPair(), keyRing.getPubKeyRing().getEncryptionPubKey());
DecryptedDataTuple tuple = Encryption.decryptHybridWithSignature(sealedAndSigned, keyRing.getEncryptionKeyPair().getPrivate());
if (tuple.payload instanceof Ping && ((Ping) tuple.payload).nonce == payload.nonce && ((Ping) tuple.payload).lastRoundTripTime == payload.lastRoundTripTime)
log.debug("Crypto test succeeded");
else
throw new CryptoException("Payload not correct after decryption");
} catch (CryptoException e) {
e.printStackTrace();
String msg = "Seems that you use a self compiled binary and have not following the build " + "instructions in https://github.com/bitsquare/bitsquare/blob/master/doc/build.md#7-enable-unlimited-strength-for-cryptographic-keys.\n\n" + "If that is not the case and you use the official Bitsquare binary, " + "please file a bug report to the Github page.\n" + "Error=" + e.getMessage();
log.error(msg);
UserThread.execute(() -> new Popup<>().warning(msg).actionButtonText("Shut down").onAction(BitsquareApp.shutDownHandler::run).closeButtonText("Report bug at Github issues").onClose(() -> GUIUtil.openWebPage("https://github.com/bitsquare/bitsquare/issues")).show());
}
}
};
checkCryptoThread.start();
if (Security.getProvider("BC") == null) {
new Popup<>().warning("There is a problem with the crypto libraries. BountyCastle is not available.").actionButtonText("Shut down").onAction(BitsquareApp.shutDownHandler::run).closeButtonText("Report bug at Github issues").onClose(() -> GUIUtil.openWebPage("https://github.com/bitsquare/bitsquare/issues")).show();
}
String remindPasswordAndBackupKey = "remindPasswordAndBackup";
user.getPaymentAccountsAsObservable().addListener((SetChangeListener<PaymentAccount>) change -> {
if (!walletService.getWallet().isEncrypted() && preferences.showAgain(remindPasswordAndBackupKey) && change.wasAdded()) {
new Popup<>().headLine("Important security recommendation").information("We would like to remind you to consider using password protection for your wallet if you have not already enabled that.\n\n" + "It is also highly recommended to write down the wallet seed words. Those seed words are like a master password for recovering your Bitcoin wallet.\n" + "At the \"Wallet Seed\" section you find more information.\n\n" + "Additionally you can backup the complete application data folder at the \"Backup\" section.\n" + "Please note, that this backup is not encrypted!").dontShowAgainId(remindPasswordAndBackupKey, preferences).show();
}
});
checkIfOpenOffersMatchTradeProtocolVersion();
}
use of javafx.collections.ListChangeListener in project Gargoyle by callakrsos.
the class CaptureScreenController method initialize.
@FXML
public void initialize() {
itemHandler = new CaptureItemHandler(this);
flowItems.getChildren().addAll(itemHandler.getItems());
anchorBoard = new AnchorPane();
//아이템 카운트 수를 핸들링하는 이벤트 리스너
anchorBoard.getChildren().addListener((ListChangeListener) c -> {
if (c.next()) {
if (c.wasAdded()) {
int addedSize = c.getAddedSize();
itemCount.add(addedSize);
} else if (c.wasRemoved()) {
itemCount.subtract(c.getRemovedSize());
}
}
});
spPic.setContent(anchorBoard);
anchorBoard.setOnScroll(ev -> {
if (ev.isControlDown()) {
if (ev.getDeltaY() > 0) {
scaleDeltaX.set(scaleDeltaX.get() + 0.1);
scaleDeltaY.set(scaleDeltaY.get() + 0.1);
scale.setX(scaleDeltaX.get());
scale.setY(scaleDeltaY.get());
scale.setPivotX(ev.getX());
scale.setPivotY(ev.getY());
} else {
double value = scaleDeltaX.get() - 0.1;
double value2 = scaleDeltaY.get() - 0.1;
if (value < 0)
return;
if (value2 < 0)
return;
scaleDeltaX.set(value);
scaleDeltaY.set(value2);
scale.setX(scaleDeltaX.get());
scale.setY(scaleDeltaY.get());
scale.setPivotX(ev.getX());
scale.setPivotY(ev.getY());
}
lblStatus.setText(String.format(STATUS_FORMAT, scaleDeltaX.get(), ev.getX(), ev.getY(), itemCount.get()));
}
});
anchorBoard.setOnMouseMoved(ev -> {
lblStatus.setText(String.format(STATUS_FORMAT, scaleDeltaX.get(), ev.getX(), ev.getY(), itemCount.get()));
});
}
use of javafx.collections.ListChangeListener in project jgnash by ccavanaugh.
the class ImportPageTwoController method initialize.
@FXML
private void initialize() {
textFlow.getChildren().addAll(new Text(TextResource.getString("ImportTwo.txt")));
deleteButton.disableProperty().bind(tableView.getSelectionModel().selectedItemProperty().isNull());
tableView.setTableMenuButtonVisible(false);
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
tableView.setEditable(true);
tableView.getItems().addListener((ListChangeListener<ImportTransaction>) c -> valid.set(tableView.getItems().size() > 0));
buildTableView();
tableViewManager = new TableViewManager<>(tableView, PREF_NODE);
tableViewManager.setColumnWeightFactory(column -> PREF_COLUMN_WEIGHTS[column]);
tableViewManager.setMinimumColumnWidthFactory(column -> MIN_COLUMN_WIDTHS[column]);
updateDescriptor();
}
Aggregations