Search in sources :

Example 6 with Platform

use of javafx.application.Platform in project jgnash by ccavanaugh.

the class IncomeExpensePayeePieChartDialogController method initialize.

@FXML
public void initialize() {
    // Respect animation preference
    debitPieChart.animatedProperty().set(Options.animationsEnabledProperty().get());
    creditPieChart.animatedProperty().set(Options.animationsEnabledProperty().get());
    creditPieChart.getStylesheets().addAll(CHART_CSS);
    debitPieChart.getStylesheets().addAll(CHART_CSS);
    creditPieChart.centerTitleProperty().set(resources.getString("Column.Credit"));
    debitPieChart.centerTitleProperty().set(resources.getString("Column.Debit"));
    accountComboBox.setPredicate(AccountComboBox.getShowAllPredicate());
    if (preferences.get(LAST_ACCOUNT, null) != null) {
        final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
        Objects.requireNonNull(engine);
        final Account account = engine.getAccountByUuid(preferences.get(LAST_ACCOUNT, null));
        if (account != null) {
            accountComboBox.setValue(account);
        }
    }
    startDatePicker.setValue(endDatePicker.getValue().minusYears(1));
    final ChangeListener<Object> listener = (observable, oldValue, newValue) -> {
        if (newValue != null) {
            updateCharts();
            preferences.put(LAST_ACCOUNT, accountComboBox.getValue().getUuid());
        }
    };
    accountComboBox.valueProperty().addListener(listener);
    startDatePicker.valueProperty().addListener(listener);
    endDatePicker.valueProperty().addListener(listener);
    creditPieChart.setLegendSide(Side.BOTTOM);
    debitPieChart.setLegendSide(Side.BOTTOM);
    // Load in the first aux payee text field
    insertAuxPayeeTextField();
    restoreFilters();
    // Expand the titled pane if filters are being used
    Platform.runLater(() -> {
        if (getPayeeTextFields().size() > 1) {
            titledPane.setExpanded(true);
        }
    });
    // Push the initial load to the end of the platform thread for better startup and nicer visual effect
    Platform.runLater(this::updateCharts);
}
Also used : DoughnutChart(jgnash.uifx.control.DoughnutChart) Scene(javafx.scene.Scene) Engine(jgnash.engine.Engine) TextInputControl(javafx.scene.control.TextInputControl) Transaction(jgnash.engine.Transaction) EngineFactory(jgnash.engine.EngineFactory) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) VBox(javafx.scene.layout.VBox) Side(javafx.geometry.Side) AccountComboBox(jgnash.uifx.control.AccountComboBox) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) EncodeDecode(jgnash.util.EncodeDecode) BigDecimal(java.math.BigDecimal) ResourceBundle(java.util.ResourceBundle) Map(java.util.Map) Tooltip(javafx.scene.control.Tooltip) GridPane(javafx.scene.layout.GridPane) CurrencyNode(jgnash.engine.CurrencyNode) ObjectProperty(javafx.beans.property.ObjectProperty) TextField(javafx.scene.control.TextField) InjectFXML(jgnash.uifx.util.InjectFXML) TitledPane(javafx.scene.control.TitledPane) NotNull(jgnash.util.NotNull) Comparators(jgnash.engine.Comparators) Predicate(java.util.function.Predicate) Collectors(java.util.stream.Collectors) Preferences(java.util.prefs.Preferences) Objects(java.util.Objects) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) PieChart(javafx.scene.chart.PieChart) List(java.util.List) CommodityFormat(jgnash.text.CommodityFormat) Stage(javafx.stage.Stage) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) LocalDate(java.time.LocalDate) Account(jgnash.engine.Account) ObservableList(javafx.collections.ObservableList) PayeePredicate(jgnash.util.function.PayeePredicate) ChangeListener(javafx.beans.value.ChangeListener) Collections(java.util.Collections) DatePickerEx(jgnash.uifx.control.DatePickerEx) CollectionUtils(jgnash.util.CollectionUtils) Options(jgnash.uifx.Options) Account(jgnash.engine.Account) Engine(jgnash.engine.Engine) InjectFXML(jgnash.uifx.util.InjectFXML) FXML(javafx.fxml.FXML)

Example 7 with Platform

use of javafx.application.Platform in project jgnash by ccavanaugh.

the class IncomeExpensePieChartDialogController method initialize.

@FXML
public void initialize() {
    // Respect animation preference
    pieChart.animatedProperty().set(Options.animationsEnabledProperty().get());
    accountComboBox.valueProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null && newValue.getParent().getAccountType() != AccountType.ROOT) {
            pieChart.setCursor(CustomCursor.getZoomOutCursor());
        } else {
            pieChart.setCursor(Cursor.DEFAULT);
        }
    });
    final Preferences preferences = Preferences.userNodeForPackage(IncomeExpensePieChartDialogController.class).node("IncomeExpensePieChart");
    accountComboBox.setPredicate(new ParentAccountPredicate());
    if (preferences.get(LAST_ACCOUNT, null) != null) {
        final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
        Objects.requireNonNull(engine);
        final Account account = engine.getAccountByUuid(preferences.get(LAST_ACCOUNT, null));
        if (account != null) {
            accountComboBox.setValue(account);
        }
    }
    startDatePicker.setValue(endDatePicker.getValue().minusYears(1));
    final ChangeListener<Object> listener = (observable, oldValue, newValue) -> {
        if (newValue != null) {
            updateChart();
            preferences.put(LAST_ACCOUNT, accountComboBox.getValue().getUuid());
        }
    };
    accountComboBox.valueProperty().addListener(listener);
    startDatePicker.valueProperty().addListener(listener);
    endDatePicker.valueProperty().addListener(listener);
    pieChart.setLegendSide(Side.BOTTOM);
    // zoom out
    pieChart.setOnMouseClicked(event -> {
        if (!nodeFocused && accountComboBox.getValue().getParent().getAccountType() != AccountType.ROOT) {
            accountComboBox.setValue(accountComboBox.getValue().getParent());
        }
    });
    // Push the initial load to the end of the platform thread for better startup and nicer visual effect
    Platform.runLater(this::updateChart);
}
Also used : DoughnutChart(jgnash.uifx.control.DoughnutChart) Scene(javafx.scene.Scene) Engine(jgnash.engine.Engine) EngineFactory(jgnash.engine.EngineFactory) FXCollections(javafx.collections.FXCollections) StackPane(javafx.scene.layout.StackPane) ParentAccountPredicate(jgnash.util.function.ParentAccountPredicate) Side(javafx.geometry.Side) AccountComboBox(jgnash.uifx.control.AccountComboBox) NumberFormat(java.text.NumberFormat) ResourceBundle(java.util.ResourceBundle) AccountType(jgnash.engine.AccountType) Tooltip(javafx.scene.control.Tooltip) CurrencyNode(jgnash.engine.CurrencyNode) ObjectProperty(javafx.beans.property.ObjectProperty) InjectFXML(jgnash.uifx.util.InjectFXML) Preferences(java.util.prefs.Preferences) Objects(java.util.Objects) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) Cursor(javafx.scene.Cursor) PieChart(javafx.scene.chart.PieChart) CommodityFormat(jgnash.text.CommodityFormat) Stage(javafx.stage.Stage) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) LocalDate(java.time.LocalDate) CustomCursor(jgnash.resource.cursor.CustomCursor) Account(jgnash.engine.Account) ObservableList(javafx.collections.ObservableList) ChangeListener(javafx.beans.value.ChangeListener) DatePickerEx(jgnash.uifx.control.DatePickerEx) Options(jgnash.uifx.Options) Account(jgnash.engine.Account) ParentAccountPredicate(jgnash.util.function.ParentAccountPredicate) Preferences(java.util.prefs.Preferences) Engine(jgnash.engine.Engine) InjectFXML(jgnash.uifx.util.InjectFXML) FXML(javafx.fxml.FXML)

Example 8 with Platform

use of javafx.application.Platform in project PayFile by mikehearn.

the class ConnectServerController method connect.

public void connect(ActionEvent event) {
    final String serverName = server.getText().trim();
    HostAndPort hostPort = verifyServerName(serverName);
    if (hostPort == null)
        return;
    connectBtn.setDisable(true);
    maybeSettleLastServer(hostPort).thenRun(() -> {
        titleLabel.setText(String.format("Connecting to %s...", serverName));
        Main.connect(hostPort).handle((client, ex) -> {
            if (ex != null) {
                Platform.runLater(() -> handleConnectError(Throwables.getRootCause(ex), serverName));
                return null;
            }
            Main.client = client;
            return client.queryFiles().whenCompleteAsync((files, ex2) -> {
                if (ex2 != null) {
                    handleQueryFilesError(ex2);
                } else {
                    Settings.setLastServer(hostPort);
                    showUIWithFiles(files);
                }
            }, Platform::runLater);
        });
    });
}
Also used : HostAndPort(com.google.common.net.HostAndPort) Platform(javafx.application.Platform)

Example 9 with Platform

use of javafx.application.Platform in project PayFile by mikehearn.

the class Main method init.

private void init(Stage mainWindow) throws IOException {
    this.mainWindow = mainWindow;
    // commented out for now as Modena looks better, but might want to bring this back.
    /* if (System.getProperty("os.name").toLowerCase().contains("mac")) {
            AquaFx.style();
        } */
    // Load the GUI. The Controller class will be automagically created and wired up.
    URL location = getClass().getResource("main.fxml");
    FXMLLoader loader = new FXMLLoader(location);
    mainUI = loader.load();
    controller = loader.getController();
    // Configure the window with a StackPane so we can overlay things on top of the main UI.
    uiStack = new StackPane(mainUI);
    mainWindow.setTitle(APP_NAME);
    final Scene scene = new Scene(uiStack);
    // Add CSS that we need.
    TextFieldValidator.configureScene(scene);
    mainWindow.setScene(scene);
    // Make log output concise.
    BriefLogFormatter.init();
    // Tell bitcoinj to run event handlers on the JavaFX UI thread. This keeps things simple and means
    // we cannot forget to switch threads when adding event handlers. Unfortunately, the DownloadListener
    // we give to the app kit is currently an exception and runs on a library thread. It'll get fixed in
    // a future version. Also note that this doesn't affect the default executor for ListenableFutures.
    // That must be specified each time.
    Threading.USER_THREAD = Platform::runLater;
    // Create the app kit. It won't do any heavyweight initialization until after we start it.
    bitcoin = new WalletAppKit(params, new File("."), filePrefix + APP_NAME) {

        @Override
        protected void addWalletExtensions() throws Exception {
            super.addWalletExtensions();
            wallet().addExtension(new StoredPaymentChannelClientStates(wallet(), peerGroup()));
        }
    };
    if (params == RegTestParams.get()) {
        // You should run a regtest mode bitcoind locally.
        bitcoin.connectToLocalHost();
    } else if (params == MainNetParams.get()) {
        // Checkpoints are block headers that ship inside our app: for a new user, we pick the last header
        // in the checkpoints file and then download the rest from the network. It makes things much faster.
        // Checkpoint files are made using the BuildCheckpoints tool and usually we have to download the
        // last months worth or more (takes a few seconds).
        bitcoin.setCheckpoints(getClass().getResourceAsStream("checkpoints"));
    }
    // Now configure and start the appkit. It won't block for very long.
    bitcoin.setDownloadListener(controller.progressBarUpdater()).setBlockingStartup(false).setUserAgent("PayFile Client", "1.0").startAndWait();
    // Don't make the user wait for confirmations for now, as the intention is they're sending it their own money!
    bitcoin.wallet().allowSpendingUnconfirmedTransactions();
    System.out.println(bitcoin.wallet());
    controller.onBitcoinSetup();
    overlayUI("connect_server.fxml");
    mainUI.setVisible(false);
    mainWindow.show();
}
Also used : Platform(javafx.application.Platform) StoredPaymentChannelClientStates(com.google.bitcoin.protocols.channels.StoredPaymentChannelClientStates) WalletAppKit(com.google.bitcoin.kits.WalletAppKit) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader) File(java.io.File) URL(java.net.URL) StackPane(javafx.scene.layout.StackPane) OptionException(joptsimple.OptionException) IOException(java.io.IOException) BlockStoreException(com.google.bitcoin.store.BlockStoreException)

Example 10 with Platform

use of javafx.application.Platform in project jgnash by ccavanaugh.

the class TestFxPlugin method start.

@Override
public void start(final PluginPlatform pluginPlatform) {
    System.out.println("Starting test plugin");
    if (pluginPlatform != PluginPlatform.Fx) {
        throw new RuntimeException("Invalid platform");
    }
    Platform.runLater(() -> {
        //for API test.  Lookup allows plugins to find nodes within the application scene
        final Node node = MainView.getInstance().lookup("#fileMenu");
        if (node != null) {
            System.out.println("found the file menu");
            // Not really a node, but the skin for the node,
            System.out.println(node.getClass().toString());
        }
        assert MainView.getInstance().lookup("#importMenu") != null;
        // Install a menu item
        final MenuBar menuBar = MainView.getInstance().getMenuBar();
        menuBar.getMenus().stream().filter(menu -> menu.getId().equals("fileMenu")).forEach(menu -> {
            System.out.println("found the file menu");
            menu.getItems().add(new MenuItem("Plugin Menu"));
        });
    });
}
Also used : Platform(javafx.application.Platform) Color(javafx.scene.paint.Color) MenuBar(javafx.scene.control.MenuBar) MenuItem(javafx.scene.control.MenuItem) FxPlugin(jgnash.plugin.FxPlugin) Node(javafx.scene.Node) MainView(jgnash.uifx.views.main.MainView) Rectangle(javafx.scene.shape.Rectangle) Node(javafx.scene.Node) MenuBar(javafx.scene.control.MenuBar) MenuItem(javafx.scene.control.MenuItem)

Aggregations

Platform (javafx.application.Platform)10 Scene (javafx.scene.Scene)6 StackPane (javafx.scene.layout.StackPane)5 Stage (javafx.stage.Stage)5 NumberFormat (java.text.NumberFormat)4 List (java.util.List)4 Objects (java.util.Objects)4 ResourceBundle (java.util.ResourceBundle)4 Preferences (java.util.prefs.Preferences)4 ObjectProperty (javafx.beans.property.ObjectProperty)4 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)4 ChangeListener (javafx.beans.value.ChangeListener)4 FXML (javafx.fxml.FXML)4 Tooltip (javafx.scene.control.Tooltip)4 Account (jgnash.engine.Account)4 CurrencyNode (jgnash.engine.CurrencyNode)4 Engine (jgnash.engine.Engine)4 EngineFactory (jgnash.engine.EngineFactory)4 CommodityFormat (jgnash.text.CommodityFormat)4 Options (jgnash.uifx.Options)4