Search in sources :

Example 71 with Preferences

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

the class AttachmentPanel method attachmentAction.

private void attachmentAction() {
    final Preferences pref = Preferences.userNodeForPackage(AbstractBankTransactionPanel.class);
    final String baseFile = EngineFactory.getActiveDatabase();
    final String[] fileSuffixes = ImageIO.getReaderFileSuffixes();
    StringBuilder description = new StringBuilder(rb.getString("Title.ImageFiles")).append(" (");
    for (int i = 0; i < fileSuffixes.length; i++) {
        description.append("*.");
        description.append(fileSuffixes[i]);
        if (i < fileSuffixes.length - 1) {
            description.append(", ");
        }
    }
    description.append(")");
    FileFilter fileFilter = new FileNameExtensionFilter(description.toString(), fileSuffixes);
    final JFileChooser chooser = new JFileChooser(pref.get(LAST_DIR, null));
    chooser.addChoosableFileFilter(fileFilter);
    chooser.setFileFilter(fileFilter);
    chooser.setMultiSelectionEnabled(false);
    chooser.setAcceptAllFileFilterUsed(false);
    if (attachment != null) {
        chooser.setSelectedFile(attachment.toFile());
    }
    if (chooser.showOpenDialog(UIApplication.getFrame()) == JFileChooser.APPROVE_OPTION) {
        pref.put(LAST_DIR, chooser.getCurrentDirectory().getAbsolutePath());
        File selectedFile = chooser.getSelectedFile();
        if (selectedFile != null) {
            boolean result = true;
            final Path attachmentDirectory = AttachmentUtils.getAttachmentDirectory(Paths.get(baseFile));
            if (baseFile.startsWith(EngineFactory.REMOTE_PREFIX)) {
                // working remotely
                moveAttachment = true;
            } else if (attachmentDirectory != null && !attachmentDirectory.toString().equals(selectedFile.getParent())) {
                String message = ResourceUtils.getString("Message.Warn.MoveFile", selectedFile.toString(), attachmentDirectory.toString());
                result = YesNoDialog.showYesNoDialog(UIApplication.getFrame(), new JLabel(message), rb.getString("Title.MoveFile"));
                if (result) {
                    moveAttachment = true;
                    Path newPath = Paths.get(AttachmentUtils.getAttachmentDirectory(Paths.get(baseFile)) + FileUtils.separator + selectedFile.getName());
                    if (newPath.toFile().exists()) {
                        message = ResourceUtils.getString("Message.Warn.SameFile", selectedFile.toString(), attachmentDirectory.toString());
                        StaticUIMethods.displayWarning(message);
                        moveAttachment = false;
                        result = false;
                    }
                }
            }
            if (result) {
                attachment = selectedFile.toPath();
            }
        }
    }
}
Also used : Path(java.nio.file.Path) JFileChooser(javax.swing.JFileChooser) JLabel(javax.swing.JLabel) Preferences(java.util.prefs.Preferences) FileFilter(javax.swing.filechooser.FileFilter) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File)

Example 72 with Preferences

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

the class RegisterFactory method setOddColor.

public static void setOddColor(final Color color) {
    Preferences p = Preferences.userNodeForPackage(RegisterFactory.class);
    p.putInt(ODD_COLOR, color.getRGB());
    oddBackgroundColor = color;
}
Also used : Preferences(java.util.prefs.Preferences)

Example 73 with Preferences

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

the class RegisterFactory method setConfirmTransactionDeleteEnabled.

/**
     * Sets if confirm on transaction delete is enabled.
     * 
     * @param enabled true if deletion confirmation is required
     */
public static void setConfirmTransactionDeleteEnabled(final boolean enabled) {
    confirmTransactionDelete = enabled;
    Preferences p = Preferences.userNodeForPackage(RegisterFactory.class);
    p.putBoolean(CONFIRM_ON_DELETE, confirmTransactionDelete);
}
Also used : Preferences(java.util.prefs.Preferences)

Example 74 with Preferences

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

the class RegisterFactory method setSortingEnabled.

/**
     * Sets the availability of sortable registers.
     * 
     * @param enabled true if sorting it enabled
     */
public static void setSortingEnabled(final boolean enabled) {
    sortable = enabled;
    Preferences p = Preferences.userNodeForPackage(RegisterFactory.class);
    p.putBoolean(SORTABLE, sortable);
}
Also used : Preferences(java.util.prefs.Preferences)

Example 75 with Preferences

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

the class RegisterPanel method restoreLastTabUsed.

private void restoreLastTabUsed() {
    if (RegisterFactory.isRestoreLastTransactionTabEnabled()) {
        Preferences tabPreferences = Preferences.userRoot().node(NODE_REG_TAB);
        String id = getAccount().getUuid();
        final int index = tabPreferences.getInt(id, tabbedPane.getSelectedIndex());
        EventQueue.invokeLater(() -> tabbedPane.setSelectedIndex(index));
    }
}
Also used : Preferences(java.util.prefs.Preferences)

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