Search in sources :

Example 41 with Preferences

use of java.util.prefs.Preferences in project jgnash by ccavanaugh.

the class ImportAccountsAction method showAndWait.

public static void showAndWait() {
    final ResourceBundle resources = ResourceUtils.getBundle();
    final FileChooser fileChooser = configureFileChooser();
    fileChooser.setTitle(resources.getString("Title.SelFile"));
    final File file = fileChooser.showOpenDialog(MainView.getPrimaryStage());
    if (file != null) {
        Preferences pref = Preferences.userNodeForPackage(ImportAccountsAction.class);
        pref.put(LAST_DIR, file.getParentFile().getAbsolutePath());
        final ImportTask importTask = new ImportTask(Paths.get(FileUtils.stripFileExtension(file.getAbsolutePath()) + ".xml"));
        new Thread(importTask).start();
        MainView.getInstance().setBusy(importTask);
    }
}
Also used : FileChooser(javafx.stage.FileChooser) ResourceBundle(java.util.ResourceBundle) Preferences(java.util.prefs.Preferences) File(java.io.File)

Example 42 with Preferences

use of java.util.prefs.Preferences in project jgnash by ccavanaugh.

the class ImportOfxAction method showAndWait.

public static void showAndWait() {
    final ResourceBundle resources = ResourceUtils.getBundle();
    final FileChooser fileChooser = configureFileChooser();
    fileChooser.setTitle(resources.getString("Title.SelFile"));
    final File file = fileChooser.showOpenDialog(MainView.getPrimaryStage());
    if (file != null) {
        Preferences pref = Preferences.userNodeForPackage(ImportOfxAction.class);
        pref.put(LAST_DIR, file.getParentFile().getAbsolutePath());
        new Thread(new ImportTask(file)).start();
    }
}
Also used : FileChooser(javafx.stage.FileChooser) ResourceBundle(java.util.ResourceBundle) Preferences(java.util.prefs.Preferences) File(java.io.File)

Example 43 with Preferences

use of java.util.prefs.Preferences in project jgnash by ccavanaugh.

the class ImportQifAction method configureFileChooser.

private static FileChooser configureFileChooser() {
    final Preferences pref = Preferences.userNodeForPackage(ImportQifAction.class);
    final FileChooser fileChooser = new FileChooser();
    fileChooser.setInitialDirectory(new File(pref.get(LAST_DIR, System.getProperty("user.home"))));
    fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Qif Files (*.qif)", "*.qif"));
    return fileChooser;
}
Also used : FileChooser(javafx.stage.FileChooser) Preferences(java.util.prefs.Preferences) File(java.io.File)

Example 44 with Preferences

use of java.util.prefs.Preferences 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());
}
Also used : Pos(javafx.geometry.Pos) Engine(jgnash.engine.Engine) BigDecimal(java.math.BigDecimal) Budget(jgnash.engine.budget.Budget) MessageProperty(jgnash.engine.message.MessageProperty) DefaultDaemonThreadFactory(jgnash.util.DefaultDaemonThreadFactory) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) TreeTableCell(javafx.scene.control.TreeTableCell) BudgetPeriodDescriptor(jgnash.engine.budget.BudgetPeriodDescriptor) TableView(javafx.scene.control.TableView) NullTableViewSelectionModel(jgnash.uifx.control.NullTableViewSelectionModel) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) MessageListener(jgnash.engine.message.MessageListener) HBox(javafx.scene.layout.HBox) NotNull(jgnash.util.NotNull) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Spinner(javafx.scene.control.Spinner) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) JavaFXUtils(jgnash.uifx.util.JavaFXUtils) AccountGroup(jgnash.engine.AccountGroup) Objects(java.util.Objects) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) BudgetGoal(jgnash.engine.budget.BudgetGoal) List(java.util.List) LocalDate(java.time.LocalDate) Optional(java.util.Optional) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) ObservableList(javafx.collections.ObservableList) Message(jgnash.engine.message.Message) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) BudgetPeriodResults(jgnash.engine.budget.BudgetPeriodResults) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) TreeItem(javafx.scene.control.TreeItem) EngineFactory(jgnash.engine.EngineFactory) FXCollections(javafx.collections.FXCollections) DoubleProperty(javafx.beans.property.DoubleProperty) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Bindings(javafx.beans.binding.Bindings) IntegerProperty(javafx.beans.property.IntegerProperty) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TableColumn(javafx.scene.control.TableColumn) TableCell(javafx.scene.control.TableCell) TreeTableView(javafx.scene.control.TreeTableView) ResourceBundle(java.util.ResourceBundle) ThemeManager(jgnash.uifx.skin.ThemeManager) GridPane(javafx.scene.layout.GridPane) Label(javafx.scene.control.Label) Comparators(jgnash.engine.Comparators) FXMLUtils(jgnash.uifx.util.FXMLUtils) BudgetResultsModel(jgnash.engine.budget.BudgetResultsModel) CheckBox(javafx.scene.control.CheckBox) MainView(jgnash.uifx.views.main.MainView) Preferences(java.util.prefs.Preferences) TimeUnit(java.util.concurrent.TimeUnit) TreeTableColumn(javafx.scene.control.TreeTableColumn) CommodityFormat(jgnash.text.CommodityFormat) StageUtils(jgnash.uifx.util.StageUtils) Stage(javafx.stage.Stage) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) StyleClass(jgnash.uifx.skin.StyleClass) SpinnerValueFactory(javafx.scene.control.SpinnerValueFactory) Account(jgnash.engine.Account) ChangeListener(javafx.beans.value.ChangeListener) ScrollBar(javafx.scene.control.ScrollBar) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Preferences(java.util.prefs.Preferences) DefaultDaemonThreadFactory(jgnash.util.DefaultDaemonThreadFactory) SpinnerValueFactory(javafx.scene.control.SpinnerValueFactory) FXML(javafx.fxml.FXML)

Example 45 with Preferences

use of java.util.prefs.Preferences in project jgnash by ccavanaugh.

the class ThemeManager method buildLookAndFeelMenu.

/**
     * Loads the menu with the available look and feels for the application
     * 
     * @return l and f menu
     */
JMenu buildLookAndFeelMenu() {
    String activeLookAndFeelName = UIManager.getLookAndFeel().getName();
    // ButtonGroup buttonGroup = new ButtonGroup();
    JMenu lfMenu = new JMenu();
    lfMenu.setText(rb.getString("Menu.LookAndFeel.Name"));
    lfMenu.add(buildSubstanceMenu());
    List<String> lookAndFeels = new ArrayList<>();
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if (isLookAndFeelAvailable(info.getClassName())) {
            lookAndFeels.add(info.getClassName());
        }
    }
    for (String lookAndFeel : KNOWN) {
        if (isLookAndFeelAvailable(lookAndFeel)) {
            lookAndFeels.add(lookAndFeel);
        }
    }
    Collections.sort(lookAndFeels);
    for (String lookAndFeel : lookAndFeels) {
        try {
            Class<?> lnfClass = Class.forName(lookAndFeel);
            LookAndFeel newLAF = (LookAndFeel) lnfClass.newInstance();
            JRadioButtonMenuItem button = new JRadioButtonMenuItem();
            button.setText(newLAF.getName());
            button.setActionCommand(lookAndFeel);
            button.setName(newLAF.getName());
            button.addActionListener(e -> {
                Preferences pref = Preferences.userNodeForPackage(ThemeManager.class);
                pref.put(LF, e.getActionCommand());
                restartUI();
            });
            lfButtonGroup.add(button);
            lfMenu.add(button);
            if (newLAF.getName().equals(activeLookAndFeelName)) {
                button.setSelected(true);
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
            Logger.getLogger(ThemeManager.class.getName()).log(Level.WARNING, null, e);
        }
    }
    return lfMenu;
}
Also used : LookAndFeelInfo(javax.swing.UIManager.LookAndFeelInfo) ArrayList(java.util.ArrayList) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) LookAndFeel(javax.swing.LookAndFeel) NimbusLookAndFeel(javax.swing.plaf.nimbus.NimbusLookAndFeel) SubstanceLookAndFeel(org.pushingpixels.substance.api.SubstanceLookAndFeel) MetalLookAndFeel(javax.swing.plaf.metal.MetalLookAndFeel) Preferences(java.util.prefs.Preferences) JMenu(javax.swing.JMenu)

Aggregations

Preferences (java.util.prefs.Preferences)291 BackingStoreException (java.util.prefs.BackingStoreException)49 File (java.io.File)45 ResourceBundle (java.util.ResourceBundle)24 FileChooser (javafx.stage.FileChooser)21 ArrayList (java.util.ArrayList)17 FXML (javafx.fxml.FXML)16 IOException (java.io.IOException)14 JFileChooser (javax.swing.JFileChooser)12 List (java.util.List)8 SwingWorker (javax.swing.SwingWorker)8 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)7 Engine (jgnash.engine.Engine)7 AutoCompletePreferences (org.jabref.logic.autocompleter.AutoCompletePreferences)6 FieldContentParserPreferences (org.jabref.logic.bibtex.FieldContentParserPreferences)6 LatexFieldFormatterPreferences (org.jabref.logic.bibtex.LatexFieldFormatterPreferences)6 BibtexKeyPatternPreferences (org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences)6 CleanupPreferences (org.jabref.logic.cleanup.CleanupPreferences)6 ImportFormatPreferences (org.jabref.logic.importer.ImportFormatPreferences)6 JournalAbbreviationPreferences (org.jabref.logic.journals.JournalAbbreviationPreferences)6