Search in sources :

Example 51 with Preferences

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

the class JTextFieldEx method setSelectOnFocus.

public static void setSelectOnFocus(final boolean select) {
    Preferences p = Preferences.userNodeForPackage(JTextFieldEx.class);
    p.putBoolean(SELECT_ON_FOCUS, select);
    JTextFieldEx.select = select;
}
Also used : Preferences(java.util.prefs.Preferences)

Example 52 with Preferences

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

the class RemoteConnectionDialog method initComponents.

private void initComponents() {
    Preferences preferences = Preferences.userNodeForPackage(RemoteConnectionDialog.class);
    setPort(preferences.getInt(LAST_PORT, JpaNetworkServer.DEFAULT_PORT));
    setHost(preferences.get(LAST_HOST, "localhost"));
    cancelButton = new JButton(rb.getString("Button.Cancel"));
    okButton = new JButton(rb.getString("Button.Ok"));
    cancelButton.addActionListener(this);
    okButton.addActionListener(this);
}
Also used : JButton(javax.swing.JButton) Preferences(java.util.prefs.Preferences)

Example 53 with Preferences

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

the class DynamicJasperReportPanel method saveAction.

private void saveAction() {
    Preferences p = Preferences.userNodeForPackage(DynamicJasperReportPanel.class);
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setMultiSelectionEnabled(false);
    saveContributors.forEach(fileChooser::addChoosableFileFilter);
    // restore the last save format
    if (p.get(LAST_CONTRIBUTOR, null) != null) {
        String last = p.get(LAST_CONTRIBUTOR, null);
        for (JRSaveContributor saveContributor : saveContributors) {
            if (saveContributor.getDescription().equals(last)) {
                fileChooser.setFileFilter(saveContributor);
                break;
            }
        }
    } else if (!saveContributors.isEmpty()) {
        fileChooser.setFileFilter(saveContributors.get(0));
    }
    if (p.get(LAST_DIRECTORY, null) != null) {
        fileChooser.setCurrentDirectory(new File(p.get(LAST_DIRECTORY, null)));
    }
    int retValue = fileChooser.showSaveDialog(this);
    if (retValue == JFileChooser.APPROVE_OPTION) {
        FileFilter fileFilter = fileChooser.getFileFilter();
        File file = fileChooser.getSelectedFile();
        p.put(LAST_DIRECTORY, file.getParent());
        JRSaveContributor contributor = null;
        if (fileFilter instanceof JRSaveContributor) {
            // save format chosen from the list
            contributor = (JRSaveContributor) fileFilter;
        } else {
            for (JRSaveContributor saveContributor : saveContributors) {
                // need to determine the best match
                if (saveContributor.accept(file)) {
                    contributor = saveContributor;
                    break;
                }
            }
            if (contributor == null) {
                JOptionPane.showMessageDialog(this, resourceBundle.getString("error.saving"));
            }
        }
        if (contributor != null) {
            p.put(LAST_CONTRIBUTOR, contributor.getDescription());
            try {
                if (contributor instanceof JRSingleSheetXlsSaveContributor) {
                    LOG.info("Formatting for xls file");
                    JasperPrint print = report.createJasperPrint(true);
                    contributor.save(print, file);
                } else if (contributor instanceof JRCsvSaveContributor) {
                    LOG.info("Formatting for csv file");
                    JasperPrint print = report.createJasperPrint(true);
                    contributor.save(print, file);
                } else {
                    contributor.save(jasperPrint, file);
                }
            } catch (final JRException ex) {
                LOG.log(Level.SEVERE, ex.getMessage(), ex);
                JOptionPane.showMessageDialog(this, resourceBundle.getString("error.saving"));
            }
        }
    }
}
Also used : JRSingleSheetXlsSaveContributor(net.sf.jasperreports.view.save.JRSingleSheetXlsSaveContributor) JFileChooser(javax.swing.JFileChooser) JRException(net.sf.jasperreports.engine.JRException) JasperPrint(net.sf.jasperreports.engine.JasperPrint) JRSaveContributor(net.sf.jasperreports.view.JRSaveContributor) Preferences(java.util.prefs.Preferences) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) JasperPrint(net.sf.jasperreports.engine.JasperPrint) JRCsvSaveContributor(net.sf.jasperreports.view.save.JRCsvSaveContributor)

Example 54 with Preferences

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

the class DialogUtils method addBoundsListener.

/**
     * Listens to a JDialog to save and restore windows bounds automatically.
     * <p>
     * {@code setVisible(false)} and {@code dispose()} must not be used
     * to close the window.  Instead, dispatch a window closing event.
     * <PRE>
     * dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
     * </PRE>
     * and the dialog must be set to dispose on close
     * <PRE>
     * setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
     * </PRE>
     *
     * @param w        {@code Window} to listen to
     * @param prefNode String identifier to preference node to save and restore from
     * @param key      the key to save and restore from
     */
private static void addBoundsListener(final Window w, final String prefNode, final String key) {
    String bounds = Preferences.userRoot().node(prefNode).get(key, null);
    if (bounds != null) {
        if (w instanceof JDialog) {
            if (((JDialog) w).isResizable()) {
                w.setBounds(decodeRectangle(bounds));
            } else {
                w.setLocation(decodeRectangle(bounds).getLocation());
            }
        } else {
            w.setBounds(decodeRectangle(bounds));
        }
        Window owner = w.getOwner();
        if (owner != null) {
            w.setLocationRelativeTo(owner);
        }
    }
    /* listen for a window closing event and deal with it */
    w.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent evt) {
            // save position and size
            Preferences p = Preferences.userRoot().node(prefNode);
            p.put(key, encodeRectangle(w.getBounds()));
            // make GC easy
            w.removeWindowListener(this);
        }
    });
    if (w instanceof JDialog) {
        addEscapeListener((JDialog) w);
    }
}
Also used : Window(java.awt.Window) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) Preferences(java.util.prefs.Preferences) JDialog(javax.swing.JDialog)

Example 55 with Preferences

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

the class EngineFactory method bootClientEngine.

public static synchronized Engine bootClientEngine(final String host, final int port, final char[] password, final String engineName) throws Exception {
    if (engineMap.get(engineName) != null) {
        throw new RuntimeException("A stale engine was found in the map");
    }
    final Preferences pref = Preferences.userNodeForPackage(EngineFactory.class);
    Engine engine = null;
    // start the client message bus
    if (MessageBus.getInstance(engineName).setRemote(host, port + JpaNetworkServer.MESSAGE_SERVER_INCREMENT, password)) {
        pref.putInt(LAST_PORT, port);
        pref.put(LAST_HOST, host);
        pref.putBoolean(LAST_REMOTE, true);
        final MessageBus messageBus = MessageBus.getInstance(engineName);
        // after starting the remote message bus, it should receive the path on the server
        final String remoteDataBasePath = messageBus.getRemoteDataBasePath();
        final DataStoreType dataStoreType = messageBus.getRemoteDataStoreType();
        if (remoteDataBasePath == null || remoteDataBasePath.isEmpty() || dataStoreType == null) {
            throw new Exception("Invalid connection wih the message bus");
        }
        logger.log(Level.INFO, "Remote path was {0}", remoteDataBasePath);
        logger.log(Level.INFO, "Remote data store was {0}", dataStoreType.name());
        logger.log(Level.INFO, "Engine name was {0}", engineName);
        DataStore dataStore = dataStoreType.getDataStore();
        // connect to the remote server
        engine = dataStore.getClientEngine(host, port, password, remoteDataBasePath);
        if (engine != null) {
            logger.info(ResourceUtils.getString("Message.EngineStart"));
            engineMap.put(engineName, engine);
            dataStoreMap.put(engineName, dataStore);
            // remember if the user used a password for the last session
            pref.putBoolean(USED_PASSWORD, password.length > 0);
            final Message message = new Message(MessageChannel.SYSTEM, ChannelEvent.FILE_LOAD_SUCCESS, engine);
            MessageBus.getInstance(engineName).fireEvent(message);
        }
    }
    return engine;
}
Also used : MessageBus(jgnash.engine.message.MessageBus) Message(jgnash.engine.message.Message) BinaryXStreamDataStore(jgnash.engine.xstream.BinaryXStreamDataStore) XMLDataStore(jgnash.engine.xstream.XMLDataStore) Preferences(java.util.prefs.Preferences) IOException(java.io.IOException)

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