Search in sources :

Example 1 with BusyPane

use of jgnash.uifx.control.BusyPane in project jgnash by ccavanaugh.

the class MainView method start.

public void start(final Stage stage, @Nullable final File dataFile, final char[] password, @Nullable final String host, final int port) throws Exception {
    ThemeManager.restoreLastUsedTheme();
    primaryStage = stage;
    busyPane = new BusyPane();
    try {
        final FXMLLoader fxmlLoader = new FXMLLoader(MenuBarController.class.getResource("MainMenuBar.fxml"), resources);
        menuBar = fxmlLoader.load();
    } catch (final Exception e) {
        logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
    final ToolBar mainToolBar = FXMLLoader.load(Objects.requireNonNull(MainToolBarController.class.getResource("MainToolBar.fxml")), resources);
    tabViewPane = new TabViewPane();
    final VBox top = new VBox();
    top.getChildren().addAll(menuBar, mainToolBar);
    top.setFillWidth(true);
    statusBar = new StatusBar();
    final BorderPane borderPane = new BorderPane();
    borderPane.setTop(top);
    borderPane.setCenter(tabViewPane);
    borderPane.setBottom(statusBar);
    final StackPane stackPane = new StackPane();
    stackPane.getChildren().addAll(borderPane, busyPane);
    final Scene scene = new Scene(stackPane, 640, 480);
    ThemeManager.applyStyleSheets(scene);
    scene.getRoot().styleProperty().bind(ThemeManager.styleProperty());
    stage.setTitle(TITLE);
    stage.getIcons().add(StaticUIMethods.getApplicationIcon());
    stage.setScene(scene);
    stage.setResizable(true);
    // enforce a min width to prevent it from disappearing with a bad click and drag
    stage.setMinWidth(640);
    stage.setMinHeight(480);
    installHandlers();
    MessageBus.getInstance().registerListener(this, MessageChannel.SYSTEM);
    StageUtils.addBoundsListener(stage, MainView.class);
    stage.show();
    Engine.addLogHandler(statusBarLogHandler);
    EngineFactory.addLogHandler(statusBarLogHandler);
    UpdateFactory.addLogHandler(statusBarLogHandler);
    // listen to my own logger
    logger.addHandler(statusBarLogHandler);
    stage.toFront();
    stage.requestFocus();
    if (host != null) {
        // connect to a remote server instead of loading a local file
        new Thread(() -> {
            try {
                Thread.sleep(BootEngineTask.FORCED_DELAY);
                backgroundExecutor.execute(() -> JavaFXUtils.runLater(() -> BootEngineTask.initiateBoot(null, password, true, host, port)));
            } catch (InterruptedException e) {
                logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
                Thread.currentThread().interrupt();
            }
        }).start();
    } else if (dataFile != null) {
        // Load the specified file, this overrides the last open file
        new Thread(() -> {
            try {
                Thread.sleep(BootEngineTask.FORCED_DELAY);
                backgroundExecutor.execute(() -> JavaFXUtils.runLater(() -> BootEngineTask.initiateBoot(dataFile.getAbsolutePath(), password, false, null, 0)));
            } catch (InterruptedException e) {
                logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
                Thread.currentThread().interrupt();
            }
        }).start();
    } else if (Options.openLastProperty().get()) {
        // Load the last open file if enabled
        new Thread(() -> {
            try {
                Thread.sleep(BootEngineTask.FORCED_DELAY);
                backgroundExecutor.execute(() -> JavaFXUtils.runLater(BootEngineTask::openLast));
            } catch (InterruptedException e) {
                logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
                Thread.currentThread().interrupt();
            }
        }).start();
    }
    loadPlugins();
    checkForLatestRelease();
}
Also used : BorderPane(javafx.scene.layout.BorderPane) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader) StatusBar(jgnash.uifx.control.StatusBar) TabViewPane(jgnash.uifx.control.TabViewPane) BusyPane(jgnash.uifx.control.BusyPane) BootEngineTask(jgnash.uifx.tasks.BootEngineTask) ToolBar(javafx.scene.control.ToolBar) VBox(javafx.scene.layout.VBox) StackPane(javafx.scene.layout.StackPane)

Example 2 with BusyPane

use of jgnash.uifx.control.BusyPane in project jgnash by ccavanaugh.

the class JasperViewerDialogController method initialize.

@FXML
private void initialize() {
    busyPane = new BusyPane();
    stackPane.getChildren().add(busyPane);
    screenResolution = Screen.getPrimary().getDpi();
    saveButton.disableProperty().bind(jasperPrint.isNull());
    printButton.disableProperty().bind(jasperPrint.isNull());
    reportFormatButton.disableProperty().bind(jasperPrint.isNull());
    fontSizeSpinner.disableProperty().bind(jasperPrint.isNull());
    firstButton.disableProperty().bind(jasperPrint.isNull().or(pageCount.isEqualTo(0)).or(pageIndex.isEqualTo(0)));
    previousButton.disableProperty().bind(jasperPrint.isNull().or(pageCount.isEqualTo(0)).or(pageIndex.isEqualTo(0)));
    nextButton.disableProperty().bind(jasperPrint.isNull().or(pageCount.isEqualTo(0)).or(pageIndex.isEqualTo(pageCount.subtract(1))));
    lastButton.disableProperty().bind(jasperPrint.isNull().or(pageCount.isEqualTo(0)).or(pageIndex.isEqualTo(pageCount.subtract(1))));
    fitPageButton.disableProperty().bind(jasperPrint.isNull());
    fitHeightButton.disableProperty().bind(jasperPrint.isNull());
    fitWidthButton.disableProperty().bind(jasperPrint.isNull());
    zoomComboBox.disableProperty().bind(jasperPrint.isNull());
    zoomInButton.disableProperty().bind(jasperPrint.isNull().or(zoomProperty.greaterThanOrEqualTo(DEFAULT_ZOOMS[DEFAULT_ZOOMS.length - 1] / 100)));
    zoomOutButton.disableProperty().bind(jasperPrint.isNull().or(zoomProperty.lessThanOrEqualTo(DEFAULT_ZOOMS[0] / 100)));
    fitPageButton.setSelected(true);
    firstButton.prefHeightProperty().bind(saveButton.heightProperty());
    previousButton.prefHeightProperty().bind(saveButton.heightProperty());
    nextButton.prefHeightProperty().bind(saveButton.heightProperty());
    lastButton.prefHeightProperty().bind(saveButton.heightProperty());
    zoomInButton.prefHeightProperty().bind(saveButton.heightProperty());
    zoomOutButton.prefHeightProperty().bind(saveButton.heightProperty());
    fitHeightButton.prefHeightProperty().bind(saveButton.heightProperty());
    fitWidthButton.prefHeightProperty().bind(saveButton.heightProperty());
    fitPageButton.prefHeightProperty().bind(saveButton.heightProperty());
    fontSizeSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(5, 15, 7));
    report.addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            jasperPrint.set(newValue.createJasperPrint(false));
            fontSizeSpinner.valueFactoryProperty().get().setValue(newValue.getBaseFontSize());
            newValue.refreshCallBackProperty().set(() -> createJasperPrint(newValue));
        } else {
            jasperPrint.set(null);
        }
    });
    jasperPrint.addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            pageCount.set(newValue.getPages().size());
        } else {
            pageCount.set(0);
        }
        Platform.runLater(this::refresh);
    });
    reportControllerPaneProperty.addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            reportControllerPane.getChildren().addAll(newValue);
        }
    });
    fontSizeSpinner.valueProperty().addListener((observable, oldValue, newValue) -> {
        report.get().setBaseFontSize(newValue);
        Platform.runLater(() -> createJasperPrint(report.get()));
    });
    pagePane.setSpacing(PAGE_BORDER);
    pagePane.setPadding(new Insets(PAGE_BORDER));
    pagePane.setAlignment(Pos.CENTER);
    scrollPane.viewportBoundsProperty().addListener((observable, oldValue, newValue) -> {
        if (fitWidthButton.isSelected()) {
            handleFitPageWidthAction();
        }
        scrollPane.setFitToWidth(pagePane.prefWidth(-1) < newValue.getWidth());
        scrollPane.setFitToHeight(pagePane.prefHeight(-1) < newValue.getHeight());
    });
    scrollPane.vvalueProperty().addListener((ObservableValue<? extends Number> observable, Number oldValue, Number newValue) -> {
        final double interval = 1d / (double) pageCount.get();
        double low = pageIndex.get() * interval;
        double hi = low + interval;
        int newPageIndex = pageIndex.get();
        if (hi < newValue.doubleValue() && pageIndex.get() < pageCount.get()) {
            while (hi < newValue.doubleValue()) {
                newPageIndex++;
                hi += interval;
            }
            // increase the page index to match the scroll position
            setPageIndex(newPageIndex);
        } else if (low > newValue.doubleValue() && pageIndex.get() > 0) {
            while (low > newValue.doubleValue()) {
                newPageIndex--;
                low -= interval;
            }
            // decrease the page index to match the scroll position
            setPageIndex(newPageIndex);
        }
    });
    for (int zoom : DEFAULT_ZOOMS) {
        zoomComboBox.getItems().add(zoom + "%");
    }
    zoomComboBox.getSelectionModel().select(DEFAULT_ZOOM_INDEX);
    zoomComboBox.addEventHandler(KeyEvent.KEY_PRESSED, (KeyEvent e) -> {
        if (e.getCode() == KeyCode.ENTER) {
            handleZoomChangedAction();
        }
    });
    setZoomRatio(1);
}
Also used : KeyEvent(javafx.scene.input.KeyEvent) BusyPane(jgnash.uifx.control.BusyPane) Insets(javafx.geometry.Insets) ObservableValue(javafx.beans.value.ObservableValue) JasperPrint(net.sf.jasperreports.engine.JasperPrint) SpinnerValueFactory(javafx.scene.control.SpinnerValueFactory) FXML(javafx.fxml.FXML) InjectFXML(jgnash.uifx.util.InjectFXML)

Example 3 with BusyPane

use of jgnash.uifx.control.BusyPane in project jgnash by ccavanaugh.

the class ReportViewerDialogController method initialize.

@FXML
private void initialize() {
    busyPane = new BusyPane();
    stackPane.getChildren().add(busyPane);
    saveButton.disableProperty().bind(report.isNull());
    reportFormatButton.disableProperty().bind(report.isNull());
    fontSizeSpinner.disableProperty().bind(report.isNull());
    firstButton.disableProperty().bind(report.isNull().or(pageCount.isEqualTo(0)).or(pageIndex.isEqualTo(0)));
    previousButton.disableProperty().bind(report.isNull().or(pageCount.isEqualTo(0)).or(pageIndex.isEqualTo(0)));
    nextButton.disableProperty().bind(report.isNull().or(pageCount.isEqualTo(0)).or(pageIndex.isEqualTo(pageCount.subtract(1))));
    lastButton.disableProperty().bind(report.isNull().or(pageCount.isEqualTo(0)).or(pageIndex.isEqualTo(pageCount.subtract(1))));
    fitPageButton.disableProperty().bind(report.isNull());
    fitHeightButton.disableProperty().bind(report.isNull());
    fitWidthButton.disableProperty().bind(report.isNull());
    zoomComboBox.disableProperty().bind(report.isNull());
    zoomInButton.disableProperty().bind(report.isNull().or(zoomProperty.greaterThanOrEqualTo(DEFAULT_ZOOMS[DEFAULT_ZOOMS.length - 1] / 100)));
    zoomOutButton.disableProperty().bind(report.isNull().or(zoomProperty.lessThanOrEqualTo(DEFAULT_ZOOMS[0] / 100)));
    fitPageButton.setSelected(true);
    firstButton.prefHeightProperty().bind(saveButton.heightProperty());
    previousButton.prefHeightProperty().bind(saveButton.heightProperty());
    nextButton.prefHeightProperty().bind(saveButton.heightProperty());
    lastButton.prefHeightProperty().bind(saveButton.heightProperty());
    zoomInButton.prefHeightProperty().bind(saveButton.heightProperty());
    zoomOutButton.prefHeightProperty().bind(saveButton.heightProperty());
    fitHeightButton.prefHeightProperty().bind(saveButton.heightProperty());
    fitWidthButton.prefHeightProperty().bind(saveButton.heightProperty());
    fitPageButton.prefHeightProperty().bind(saveButton.heightProperty());
    fontSizeSpinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(5, 15, 7));
    // act when the report property has been set or changed
    report.addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            fontSizeSpinner.valueFactoryProperty().get().setValue((double) newValue.getBaseFontSize());
        }
    });
    reportControllerPaneProperty.addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            reportControllerPane.getChildren().addAll(newValue);
        }
    });
    fontSizeSpinner.valueProperty().addListener((observable, oldValue, newValue) -> {
        report.get().setBaseFontSize(newValue.floatValue());
        if (reportController != null) {
            reportController.refreshReport();
        }
    });
    pagePane.setSpacing(PAGE_BORDER);
    pagePane.setPadding(new Insets(PAGE_BORDER));
    pagePane.setAlignment(Pos.CENTER);
    scrollPane.viewportBoundsProperty().addListener((observable, oldValue, newValue) -> {
        if (fitWidthButton.isSelected()) {
            handleFitPageWidthAction();
        }
        scrollPane.setFitToWidth(pagePane.prefWidth(-1) < newValue.getWidth());
        scrollPane.setFitToHeight(pagePane.prefHeight(-1) < newValue.getHeight());
    });
    scrollPane.vvalueProperty().addListener((ObservableValue<? extends Number> observable, Number oldValue, Number newValue) -> {
        final double interval = 1d / pageCount.get();
        double low = pageIndex.get() * interval;
        double hi = low + interval;
        int newPageIndex = pageIndex.get();
        if (hi < newValue.doubleValue() && pageIndex.get() < pageCount.get()) {
            while (hi < newValue.doubleValue()) {
                newPageIndex++;
                hi += interval;
            }
            // increase the page index to match the scroll position
            setPageIndex(newPageIndex);
        } else if (low > newValue.doubleValue() && pageIndex.get() > 0) {
            while (low > newValue.doubleValue()) {
                newPageIndex--;
                low -= interval;
            }
            // decrease the page index to match the scroll position
            setPageIndex(newPageIndex);
        }
    });
    for (int zoom : DEFAULT_ZOOMS) {
        zoomComboBox.getItems().add(zoom + "%");
    }
    zoomComboBox.getSelectionModel().select(DEFAULT_ZOOM_INDEX);
    zoomComboBox.addEventHandler(KeyEvent.KEY_PRESSED, (KeyEvent e) -> {
        if (e.getCode() == KeyCode.ENTER) {
            handleZoomChangedAction();
        }
    });
    setZoomRatio(1);
    // this ensures the report is properly closed when the dialog is closed
    parent.addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            parent.get().getWindow().setOnCloseRequest(event -> {
                try {
                    report.get().close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            });
        }
    });
}
Also used : KeyEvent(javafx.scene.input.KeyEvent) BusyPane(jgnash.uifx.control.BusyPane) Insets(javafx.geometry.Insets) ObservableValue(javafx.beans.value.ObservableValue) IOException(java.io.IOException) SpinnerValueFactory(javafx.scene.control.SpinnerValueFactory) FXML(javafx.fxml.FXML) InjectFXML(jgnash.uifx.util.InjectFXML)

Aggregations

BusyPane (jgnash.uifx.control.BusyPane)3 ObservableValue (javafx.beans.value.ObservableValue)2 FXML (javafx.fxml.FXML)2 Insets (javafx.geometry.Insets)2 SpinnerValueFactory (javafx.scene.control.SpinnerValueFactory)2 KeyEvent (javafx.scene.input.KeyEvent)2 InjectFXML (jgnash.uifx.util.InjectFXML)2 IOException (java.io.IOException)1 FXMLLoader (javafx.fxml.FXMLLoader)1 Scene (javafx.scene.Scene)1 ToolBar (javafx.scene.control.ToolBar)1 BorderPane (javafx.scene.layout.BorderPane)1 StackPane (javafx.scene.layout.StackPane)1 VBox (javafx.scene.layout.VBox)1 StatusBar (jgnash.uifx.control.StatusBar)1 TabViewPane (jgnash.uifx.control.TabViewPane)1 BootEngineTask (jgnash.uifx.tasks.BootEngineTask)1 JasperPrint (net.sf.jasperreports.engine.JasperPrint)1