Search in sources :

Example 21 with Preferences

use of java.util.prefs.Preferences in project robovm by robovm.

the class OldPreferencesTest method testPutDouble.

public void testPutDouble() {
    Preferences pref = Preferences.userNodeForPackage(Preferences.class);
    try {
        pref.putDouble(null, 3);
        fail();
    } catch (NullPointerException expected) {
    }
    pref.putDouble(longKey, 3);
    try {
        pref.putDouble(longKey + "a", 3);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    pref.putDouble("testPutDoubleKey", 3);
    assertEquals("3.0", pref.get("testPutDoubleKey", null));
    assertEquals(3, pref.getDouble("testPutDoubleKey", 0), 0);
}
Also used : Preferences(java.util.prefs.Preferences)

Example 22 with Preferences

use of java.util.prefs.Preferences in project robovm by robovm.

the class OldPreferencesTest method testPut.

public void testPut() throws BackingStoreException {
    Preferences pref = Preferences.userNodeForPackage(Preferences.class);
    pref.put("", "emptyvalue");
    assertEquals("emptyvalue", pref.get("", null));
    pref.put("testPutkey", "value1");
    assertEquals("value1", pref.get("testPutkey", null));
    pref.put("testPutkey", "value2");
    assertEquals("value2", pref.get("testPutkey", null));
    pref.put("", "emptyvalue");
    assertEquals("emptyvalue", pref.get("", null));
    try {
        pref.put(null, "value");
        fail();
    } catch (NullPointerException expected) {
    }
    try {
        pref.put("key", null);
        fail();
    } catch (NullPointerException expected) {
    }
    pref.put(longKey, longValue);
    try {
        pref.put(longKey + 1, longValue);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    try {
        pref.put(longKey, longValue + 1);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    pref.removeNode();
    try {
        pref.put(longKey, longValue + 1);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    try {
        pref.put(longKey, longValue);
        fail();
    } catch (IllegalStateException expected) {
    }
}
Also used : Preferences(java.util.prefs.Preferences)

Example 23 with Preferences

use of java.util.prefs.Preferences in project scriptographer by scriptographer.

the class Dialog method savePreferences.

public void savePreferences(String name) {
    Preferences prefs = preferences.node(name);
    // Saving the palette position, tab/dock preference.
    DialogGroupInfo groupInfo = getGroupInfo();
    Rectangle bounds = getBounds();
    prefs.put("group", groupInfo.group != null ? groupInfo.group : "");
    prefs.putInt("positionCode", groupInfo.positionCode);
    prefs.put("bounds", bounds.x + " " + bounds.y + " " + bounds.width + " " + bounds.height);
}
Also used : Preferences(java.util.prefs.Preferences)

Example 24 with Preferences

use of java.util.prefs.Preferences in project exhibitor by soabase.

the class TestMonitorRunningInstance method makeMockExhibitor.

private Exhibitor makeMockExhibitor(InstanceConfig config, String us) {
    Preferences preferences = Mockito.mock(Preferences.class);
    ControlPanelValues controlPanelValues = new ControlPanelValues(preferences) {

        @Override
        public boolean isSet(ControlPanelTypes type) throws Exception {
            return true;
        }
    };
    ConfigManager configManager = Mockito.mock(ConfigManager.class);
    Mockito.when(configManager.getConfig()).thenReturn(config);
    Exhibitor mockExhibitor = Mockito.mock(Exhibitor.class, Mockito.RETURNS_MOCKS);
    Mockito.when(mockExhibitor.getConfigManager()).thenReturn(configManager);
    Mockito.when(mockExhibitor.getThisJVMHostname()).thenReturn(us);
    Mockito.when(mockExhibitor.getControlPanelValues()).thenReturn(controlPanelValues);
    return mockExhibitor;
}
Also used : ControlPanelValues(com.netflix.exhibitor.core.controlpanel.ControlPanelValues) ControlPanelTypes(com.netflix.exhibitor.core.controlpanel.ControlPanelTypes) Exhibitor(com.netflix.exhibitor.core.Exhibitor) Preferences(java.util.prefs.Preferences) ConfigManager(com.netflix.exhibitor.core.config.ConfigManager)

Example 25 with Preferences

use of java.util.prefs.Preferences in project antlr4 by antlr.

the class TreeViewer method showInDialog.

protected static JFrame showInDialog(final TreeViewer viewer) {
    final JFrame dialog = new JFrame();
    dialog.setTitle("Parse Tree Inspector");
    final Preferences prefs = Preferences.userNodeForPackage(TreeViewer.class);
    // Make new content panes
    final Container mainPane = new JPanel(new BorderLayout(5, 5));
    final Container contentPane = new JPanel(new BorderLayout(0, 0));
    contentPane.setBackground(Color.white);
    // Wrap viewer in scroll pane
    JScrollPane scrollPane = new JScrollPane(viewer);
    // Make the scrollpane (containing the viewer) the center component
    contentPane.add(scrollPane, BorderLayout.CENTER);
    JPanel wrapper = new JPanel(new FlowLayout());
    // Add button to bottom
    JPanel bottomPanel = new JPanel(new BorderLayout(0, 0));
    contentPane.add(bottomPanel, BorderLayout.SOUTH);
    JButton ok = new JButton("OK");
    ok.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
        }
    });
    wrapper.add(ok);
    // Add an export-to-png button right of the "OK" button
    JButton png = new JButton("Export as PNG");
    png.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            generatePNGFile(viewer, dialog);
        }
    });
    wrapper.add(png);
    bottomPanel.add(wrapper, BorderLayout.SOUTH);
    // Add scale slider
    double lastKnownViewerScale = prefs.getDouble(DIALOG_VIEWER_SCALE_PREFS_KEY, viewer.getScale());
    viewer.setScale(lastKnownViewerScale);
    int sliderValue = (int) ((lastKnownViewerScale - 1.0) * 1000);
    final JSlider scaleSlider = new JSlider(JSlider.HORIZONTAL, -999, 1000, sliderValue);
    scaleSlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            int v = scaleSlider.getValue();
            viewer.setScale(v / 1000.0 + 1.0);
        }
    });
    bottomPanel.add(scaleSlider, BorderLayout.CENTER);
    // Add a JTree representing the parser tree of the input.
    JPanel treePanel = new JPanel(new BorderLayout(5, 5));
    // An "empty" icon that will be used for the JTree's nodes.
    Icon empty = new EmptyIcon();
    UIManager.put("Tree.closedIcon", empty);
    UIManager.put("Tree.openIcon", empty);
    UIManager.put("Tree.leafIcon", empty);
    Tree parseTreeRoot = viewer.getTree().getRoot();
    TreeNodeWrapper nodeRoot = new TreeNodeWrapper(parseTreeRoot, viewer);
    fillTree(nodeRoot, parseTreeRoot, viewer);
    final JTree tree = new JTree(nodeRoot);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            JTree selectedTree = (JTree) e.getSource();
            TreePath path = selectedTree.getSelectionPath();
            if (path != null) {
                TreeNodeWrapper treeNode = (TreeNodeWrapper) path.getLastPathComponent();
                // Set the clicked AST.
                viewer.setTree((Tree) treeNode.getUserObject());
            }
        }
    });
    treePanel.add(new JScrollPane(tree));
    // Create the pane for both the JTree and the AST
    final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treePanel, contentPane);
    mainPane.add(splitPane, BorderLayout.CENTER);
    dialog.setContentPane(mainPane);
    // make viz
    WindowListener exitListener = new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            prefs.putInt(DIALOG_WIDTH_PREFS_KEY, (int) dialog.getSize().getWidth());
            prefs.putInt(DIALOG_HEIGHT_PREFS_KEY, (int) dialog.getSize().getHeight());
            prefs.putDouble(DIALOG_X_PREFS_KEY, dialog.getLocationOnScreen().getX());
            prefs.putDouble(DIALOG_Y_PREFS_KEY, dialog.getLocationOnScreen().getY());
            prefs.putInt(DIALOG_DIVIDER_LOC_PREFS_KEY, splitPane.getDividerLocation());
            prefs.putDouble(DIALOG_VIEWER_SCALE_PREFS_KEY, viewer.getScale());
            dialog.setVisible(false);
            dialog.dispose();
        }
    };
    dialog.addWindowListener(exitListener);
    dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    int width = prefs.getInt(DIALOG_WIDTH_PREFS_KEY, 600);
    int height = prefs.getInt(DIALOG_HEIGHT_PREFS_KEY, 500);
    dialog.setPreferredSize(new Dimension(width, height));
    dialog.pack();
    // After pack(): set the divider at 1/3 (200/600) of the frame.
    int dividerLocation = prefs.getInt(DIALOG_DIVIDER_LOC_PREFS_KEY, 200);
    splitPane.setDividerLocation(dividerLocation);
    if (prefs.getDouble(DIALOG_X_PREFS_KEY, -1) != -1) {
        dialog.setLocation((int) prefs.getDouble(DIALOG_X_PREFS_KEY, 100), (int) prefs.getDouble(DIALOG_Y_PREFS_KEY, 100));
    } else {
        dialog.setLocationRelativeTo(null);
    }
    dialog.setVisible(true);
    return dialog;
}
Also used : ActionEvent(java.awt.event.ActionEvent) WindowAdapter(java.awt.event.WindowAdapter) TreeSelectionListener(javax.swing.event.TreeSelectionListener) Tree(org.antlr.v4.runtime.tree.Tree) ChangeListener(javax.swing.event.ChangeListener) Preferences(java.util.prefs.Preferences) WindowListener(java.awt.event.WindowListener) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) TreePath(javax.swing.tree.TreePath) WindowEvent(java.awt.event.WindowEvent) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Aggregations

Preferences (java.util.prefs.Preferences)241 File (java.io.File)35 BackingStoreException (java.util.prefs.BackingStoreException)34 ResourceBundle (java.util.ResourceBundle)24 FileChooser (javafx.stage.FileChooser)21 FXML (javafx.fxml.FXML)16 IOException (java.io.IOException)13 JFileChooser (javax.swing.JFileChooser)12 ArrayList (java.util.ArrayList)10 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 NbPreferences (org.openide.util.NbPreferences)6