Search in sources :

Example 11 with ListChangeListener

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);
    };
}
Also used : Binding(com.canoo.platform.core.functional.Binding) Subscription(com.canoo.platform.core.functional.Subscription) IdentityHashMap(java.util.IdentityHashMap) ListChangeListener(javafx.collections.ListChangeListener) ObservableList(com.canoo.platform.remoting.ObservableList) Assert(com.canoo.dp.impl.platform.core.Assert) JavaFXListBinder(com.canoo.platform.remoting.client.javafx.binding.JavaFXListBinder) API(org.apiguardian.api.API) ListChangeEvent(com.canoo.platform.remoting.ListChangeEvent) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) INTERNAL(org.apiguardian.api.API.Status.INTERNAL) Subscription(com.canoo.platform.core.functional.Subscription)

Example 12 with ListChangeListener

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);
        }
    }
}
Also used : Parent(javafx.scene.Parent) ScrollPane(javafx.scene.control.ScrollPane) ListChangeListener(javafx.collections.ListChangeListener) Stage(javafx.stage.Stage) PseudoClass(javafx.css.PseudoClass) Node(javafx.scene.Node) Control(javafx.scene.control.Control) Pane(javafx.scene.layout.Pane) Control(javafx.scene.control.Control) Parent(javafx.scene.Parent) ScrollPane(javafx.scene.control.ScrollPane) Node(javafx.scene.Node) ScrollPane(javafx.scene.control.ScrollPane) Pane(javafx.scene.layout.Pane) ListChangeListener(javafx.collections.ListChangeListener)

Example 13 with ListChangeListener

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();
}
Also used : Clock(io.bitsquare.common.Clock) OpenOffer(io.bitsquare.trade.offer.OpenOffer) PriceFeedService(io.bitsquare.btc.pricefeed.PriceFeedService) Popup(io.bitsquare.gui.main.overlays.popups.Popup) Transaction(org.bitcoinj.core.Transaction) MarketPrice(io.bitsquare.btc.pricefeed.MarketPrice) Coin(org.bitcoinj.core.Coin) Inject(com.google.inject.Inject) ViewModel(io.bitsquare.gui.common.model.ViewModel) LoggerFactory(org.slf4j.LoggerFactory) TradeCurrency(io.bitsquare.locale.TradeCurrency) Security(java.security.Security) TimeoutException(java.util.concurrent.TimeoutException) DisputeManager(io.bitsquare.arbitration.DisputeManager) BalanceWithConfirmationTextField(io.bitsquare.gui.components.BalanceWithConfirmationTextField) Trade(io.bitsquare.trade.Trade) GUIUtil(io.bitsquare.gui.util.GUIUtil) DevFlags(io.bitsquare.app.DevFlags) PaymentAccount(io.bitsquare.payment.PaymentAccount) NotificationCenter(io.bitsquare.gui.main.overlays.notifications.NotificationCenter) ListChangeListener(javafx.collections.ListChangeListener) Navigation(io.bitsquare.gui.Navigation) TradeWalletService(io.bitsquare.btc.TradeWalletService) BlockStoreException(org.bitcoinj.store.BlockStoreException) MonadicBinding(org.fxmisc.easybind.monadic.MonadicBinding) AddressEntry(io.bitsquare.btc.AddressEntry) WalletPasswordWindow(io.bitsquare.gui.main.overlays.windows.WalletPasswordWindow) FilterManager(io.bitsquare.filter.FilterManager) Subscription(org.fxmisc.easybind.Subscription) Collectors(java.util.stream.Collectors) PrivateNotificationManager(io.bitsquare.alert.PrivateNotificationManager) ConnectionListener(io.bitsquare.p2p.network.ConnectionListener) Preferences(io.bitsquare.user.Preferences) CryptoCurrencyAccount(io.bitsquare.payment.CryptoCurrencyAccount) Dispute(io.bitsquare.arbitration.Dispute) BalanceTextField(io.bitsquare.gui.components.BalanceTextField) Address(org.bitcoinj.core.Address) Ping(io.bitsquare.p2p.peers.keepalive.messages.Ping) ObservableList(javafx.collections.ObservableList) CurrencyUtil(io.bitsquare.locale.CurrencyUtil) io.bitsquare.common.crypto(io.bitsquare.common.crypto) PrivateNotification(io.bitsquare.alert.PrivateNotification) Version(io.bitsquare.app.Version) P2PServiceListener(io.bitsquare.p2p.P2PServiceListener) java.util(java.util) P2PService(io.bitsquare.p2p.P2PService) SetChangeListener(javafx.collections.SetChangeListener) FXCollections(javafx.collections.FXCollections) BitsquareApp(io.bitsquare.app.BitsquareApp) AddBitcoinNodesWindow(io.bitsquare.gui.main.overlays.windows.AddBitcoinNodesWindow) Connection(io.bitsquare.p2p.network.Connection) Timer(io.bitsquare.common.Timer) BalanceListener(io.bitsquare.btc.listeners.BalanceListener) OKPayAccount(io.bitsquare.payment.OKPayAccount) TradeManager(io.bitsquare.trade.TradeManager) User(io.bitsquare.user.User) WalletService(io.bitsquare.btc.WalletService) TacWindow(io.bitsquare.gui.main.overlays.windows.TacWindow) Alert(io.bitsquare.alert.Alert) DisplayAlertMessageWindow(io.bitsquare.gui.main.overlays.windows.DisplayAlertMessageWindow) Nullable(javax.annotation.Nullable) Log(io.bitsquare.app.Log) BSFormatter(io.bitsquare.gui.util.BSFormatter) javafx.beans.property(javafx.beans.property) Logger(org.slf4j.Logger) UserThread(io.bitsquare.common.UserThread) TxIdTextField(io.bitsquare.gui.components.TxIdTextField) Wallet(org.bitcoinj.core.Wallet) TimeUnit(java.util.concurrent.TimeUnit) EasyBind(org.fxmisc.easybind.EasyBind) OpenOfferManager(io.bitsquare.trade.offer.OpenOfferManager) ArbitratorManager(io.bitsquare.arbitration.ArbitratorManager) CloseConnectionReason(io.bitsquare.p2p.network.CloseConnectionReason) ChangeListener(javafx.beans.value.ChangeListener) AlertManager(io.bitsquare.alert.AlertManager) BalanceListener(io.bitsquare.btc.listeners.BalanceListener) PaymentAccount(io.bitsquare.payment.PaymentAccount) OpenOffer(io.bitsquare.trade.offer.OpenOffer) UserThread(io.bitsquare.common.UserThread) BitsquareApp(io.bitsquare.app.BitsquareApp) Trade(io.bitsquare.trade.Trade) Coin(org.bitcoinj.core.Coin) Transaction(org.bitcoinj.core.Transaction) Ping(io.bitsquare.p2p.peers.keepalive.messages.Ping) Popup(io.bitsquare.gui.main.overlays.popups.Popup) Dispute(io.bitsquare.arbitration.Dispute) Ping(io.bitsquare.p2p.peers.keepalive.messages.Ping)

Example 14 with ListChangeListener

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()));
    });
}
Also used : Label(javafx.scene.control.Label) Node(javafx.scene.Node) FXMLController(com.kyj.fx.voeditor.visual.framework.annotation.FXMLController) FXCollections(javafx.collections.FXCollections) DoubleProperty(javafx.beans.property.DoubleProperty) FileInputStream(java.io.FileInputStream) IntegerProperty(javafx.beans.property.IntegerProperty) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) FXML(javafx.fxml.FXML) ScrollPane(javafx.scene.control.ScrollPane) ListChangeListener(javafx.collections.ListChangeListener) FlowPane(javafx.scene.layout.FlowPane) AnchorPane(javafx.scene.layout.AnchorPane) ImageView(javafx.scene.image.ImageView) Map(java.util.Map) FileUtil(com.kyj.fx.voeditor.visual.util.FileUtil) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) Scale(javafx.scene.transform.Scale) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) Point2D(javafx.geometry.Point2D) Image(javafx.scene.image.Image) AnchorPane(javafx.scene.layout.AnchorPane) FXML(javafx.fxml.FXML)

Example 15 with ListChangeListener

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();
}
Also used : Button(javafx.scene.control.Button) Engine(jgnash.engine.Engine) TableViewManager(jgnash.uifx.util.TableViewManager) StackPane(javafx.scene.layout.StackPane) AccountComboBox(jgnash.uifx.control.AccountComboBox) ImportFilter(jgnash.convert.imports.ImportFilter) BigDecimal(java.math.BigDecimal) Nullable(jgnash.util.Nullable) ListChangeListener(javafx.collections.ListChangeListener) Map(java.util.Map) AccountType(jgnash.engine.AccountType) TableView(javafx.scene.control.TableView) GenericImport(jgnash.convert.imports.GenericImport) TransactionType(jgnash.engine.TransactionType) Objects(java.util.Objects) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) Text(javafx.scene.text.Text) List(java.util.List) LocalDate(java.time.LocalDate) BayesImportClassifier(jgnash.convert.imports.BayesImportClassifier) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) ImportBank(jgnash.convert.imports.ImportBank) Transaction(jgnash.engine.Transaction) MouseEvent(javafx.scene.input.MouseEvent) EngineFactory(jgnash.engine.EngineFactory) ResourceUtils(jgnash.util.ResourceUtils) TextResource(jgnash.util.TextResource) FXCollections(javafx.collections.FXCollections) BigDecimalTableCell(jgnash.uifx.control.BigDecimalTableCell) TextFlow(javafx.scene.text.TextFlow) ImportState(jgnash.convert.imports.ImportState) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) TableCell(javafx.scene.control.TableCell) ResourceBundle(java.util.ResourceBundle) Tooltip(javafx.scene.control.Tooltip) FontAwesomeLabel(jgnash.resource.font.FontAwesomeLabel) CurrencyNode(jgnash.engine.CurrencyNode) ImportTransaction(jgnash.convert.imports.ImportTransaction) Label(javafx.scene.control.Label) ShortDateTableCell(jgnash.uifx.control.ShortDateTableCell) TableRow(javafx.scene.control.TableRow) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) AbstractWizardPaneController(jgnash.uifx.control.wizard.AbstractWizardPaneController) Account(jgnash.engine.Account) ContentDisplay(javafx.scene.control.ContentDisplay) Options(jgnash.uifx.Options) Text(javafx.scene.text.Text) ImportTransaction(jgnash.convert.imports.ImportTransaction) FXML(javafx.fxml.FXML)

Aggregations

ListChangeListener (javafx.collections.ListChangeListener)24 FXCollections (javafx.collections.FXCollections)15 List (java.util.List)14 ObservableList (javafx.collections.ObservableList)13 ArrayList (java.util.ArrayList)11 Collectors (java.util.stream.Collectors)9 Map (java.util.Map)8 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)8 Color (javafx.scene.paint.Color)8 Platform (javafx.application.Platform)7 Label (javafx.scene.control.Label)7 HashMap (java.util.HashMap)6 TimeUnit (java.util.concurrent.TimeUnit)6 IntegerProperty (javafx.beans.property.IntegerProperty)6 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)6 ChangeListener (javafx.beans.value.ChangeListener)6 Node (javafx.scene.Node)6 Button (javafx.scene.control.Button)6 IntStream (java.util.stream.IntStream)5 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)5