Example usage for java.util.prefs Preferences getInt

List of usage examples for java.util.prefs Preferences getInt

Introduction

In this page you can find the example usage for java.util.prefs Preferences getInt.

Prototype

public abstract int getInt(String key, int def);

Source Link

Document

Returns the int value represented by the string associated with the specified key in this preference node.

Usage

From source file:hr.fer.zemris.vhdllab.platform.ui.command.WelcomeCommand.java

@Override
protected void doExecuteCommand() {
    Preferences pref = Preferences.userNodeForPackage(WelcomeCommand.class);
    int count = pref.getInt(PREF_WELCOME_DIALOG_SHOW_COUNT, 0);

    if (count < 10) {
        showWelcomeDialog();//  ww  w  . j  ava2s. co  m
        showUpdateJavaDialog();

        pref.putInt(PREF_WELCOME_DIALOG_SHOW_COUNT, count + 1);
    }
}

From source file:de.fhg.igd.mapviewer.server.wms.WMSTileConfiguration.java

/**
 * @see WMSConfiguration#loadProperties(Preferences)
 *//*from   w  w w.  j  av a 2 s.c  o m*/
@Override
protected void loadProperties(Preferences node) {
    super.loadProperties(node);

    setZoomLevels(node.getInt(ZOOM_LEVELS, DEFAULT_ZOOM_LEVELS));
    setMinTileSize(node.getInt(MIN_TILE_SIZE, DEFAULT_MIN_TILE_SIZE));
    setMinMapSize(node.getInt(MIN_MAP_SIZE, DEFAULT_MIN_MAP_SIZE));
}

From source file:PreferencesTest.java

public PreferencesFrame() {
    // get position, size, title from preferences

    Preferences root = Preferences.userRoot();
    final Preferences node = root.node("/com/horstmann/corejava");
    int left = node.getInt("left", 0);
    int top = node.getInt("top", 0);
    int width = node.getInt("width", DEFAULT_WIDTH);
    int height = node.getInt("height", DEFAULT_HEIGHT);
    setBounds(left, top, width, height);

    // if no title given, ask user

    String title = node.get("title", "");
    if (title.equals(""))
        title = JOptionPane.showInputDialog("Please supply a frame title:");
    if (title == null)
        title = "";
    setTitle(title);/*from  w w w .j  ava  2s  .  com*/

    // set up file chooser that shows XML files

    final JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File("."));

    // accept all files ending with .xml
    chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
        public boolean accept(File f) {
            return f.getName().toLowerCase().endsWith(".xml") || f.isDirectory();
        }

        public String getDescription() {
            return "XML files";
        }
    });

    // set up menus
    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);
    JMenu menu = new JMenu("File");
    menuBar.add(menu);

    JMenuItem exportItem = new JMenuItem("Export preferences");
    menu.add(exportItem);
    exportItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            if (chooser.showSaveDialog(PreferencesFrame.this) == JFileChooser.APPROVE_OPTION) {
                try {
                    OutputStream out = new FileOutputStream(chooser.getSelectedFile());
                    node.exportSubtree(out);
                    out.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    });

    JMenuItem importItem = new JMenuItem("Import preferences");
    menu.add(importItem);
    importItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            if (chooser.showOpenDialog(PreferencesFrame.this) == JFileChooser.APPROVE_OPTION) {
                try {
                    InputStream in = new FileInputStream(chooser.getSelectedFile());
                    Preferences.importPreferences(in);
                    in.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    });

    JMenuItem exitItem = new JMenuItem("Exit");
    menu.add(exitItem);
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            node.putInt("left", getX());
            node.putInt("top", getY());
            node.putInt("width", getWidth());
            node.putInt("height", getHeight());
            node.put("title", getTitle());
            System.exit(0);
        }
    });
}

From source file:de.fhg.igd.mapviewer.server.tiles.CustomTileMapServerConfiguration.java

/**
 * Load the configuration's properties/*  ww w .jav  a  2s .c  om*/
 * 
 * @param node the preference node
 */
protected void loadProperties(Preferences node) {
    setUrlPattern(node.get(URL_PATTERN, null));
    setZoomLevel(node.getInt(ZOOM_LEVELS, DEFAULT_ZOOM_LEVELS));
    setAttributionText(node.get(ATTRIBUTION, null));
}

From source file:de.fhg.igd.mapviewer.server.wms.WMSConfiguration.java

/**
 * Load the configuration's properties// w  ww. j a v a2s .  c o m
 * 
 * @param node the preference node
 */
protected void loadProperties(Preferences node) {
    setBaseUrl(node.get(BASE_URL, null));
    setPreferredEpsg(node.getInt(PREFERRED_EPSG, DEFAULT_PREFERRED_EPSG));
    setLayers(node.get(LAYERS, "")); //$NON-NLS-1$
}

From source file:com.github.fritaly.dualcommander.TabbedPane.java

public void init(Preferences preferences) {
    Validate.notNull(preferences, "The given preferences is null");

    final int tabCount = preferences.getInt("tab.count", 1);

    for (int i = 0; i < tabCount; i++) {
        final File directory = new File(preferences.get(String.format("tab.%d.directory", i), "."));

        if (directory.exists()) {
            // Ensure the directory exists. Create a new tab
            addBrowserTab(directory);//from  w w  w  . j a  v a 2s .c  o  m
        } else {
            logger.warn(String.format("The directory '%s' doesn't exist", directory.getAbsolutePath()));
        }
    }

    // Ensure the tabbed pane has at least one tab
    if (getTabCount() == 0) {
        addBrowserTab();
    }
}

From source file:edu.umich.robot.ViewerApplication.java

public ViewerApplication(String[] args) {
    JPopupMenu.setDefaultLightWeightPopupEnabled(false);
    ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);

    Config config = (args.length > 0) ? ConfigUtil.getDefaultConfig(args) : promptForConfig();
    if (config == null)
        System.exit(1);//from  w  w w .ja  v  a 2  s .c  o m

    setupViewerConfig(config);
    viewer = new Viewer(config);
    viewer.getVisCanvas().getViewManager().setInterfaceMode(3);

    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosed(WindowEvent e) {
            frame.dispose();

            try {
                Thread.sleep(500);
            } catch (InterruptedException ignored) {
            }
            System.exit(0); // No way to shut down april threads
        }
    });
    frame.setLayout(new BorderLayout());

    viewerView = new ViewerView(viewer.getVisCanvas());

    // TODO SoarApril
    // viewer.getVisCanvas().setDrawGround(true);

    frame.add(viewerView, BorderLayout.CENTER);

    Preferences windowPrefs = getWindowPreferences();
    if (windowPrefs.get("x", null) != null) {
        frame.setBounds(windowPrefs.getInt("x", 0), windowPrefs.getInt("y", 0),
                windowPrefs.getInt("width", 800), windowPrefs.getInt("height", 800));
    } else {
        frame.setBounds(windowPrefs.getInt("x", 0), windowPrefs.getInt("y", 0),
                windowPrefs.getInt("width", 600), windowPrefs.getInt("height", 600));
        frame.setLocationRelativeTo(null); // center
    }

    frame.getRootPane().registerKeyboardAction(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            frame.dispose();
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);

    frame.pack();

    frame.setVisible(true);

    String[] splinters = config.getStrings("splinters", new String[0]);
    for (String s : splinters) {
        addViewRobot(s);
        addViewLidars(s);
        addViewWaypoints(s);

        // TODO SoarApril
        addViewTrajectory(s);
    }
}

From source file:com.tag.FramePreferences.java

public int getPreferredExtendedState() {
    Preferences prefs = getPreferences();
    return prefs.getInt(KEY_EXTENDED_STATE, Frame.NORMAL);
}

From source file:com.tag.FramePreferences.java

public Point getPreferredLocation() {
    Preferences prefs = getPreferences();
    int def = 0;/*www .j a  v a  2  s .  c o m*/
    int x = prefs.getInt(KEY_X, def);
    int y = prefs.getInt(KEY_Y, def);
    return new Point(x, y);
}

From source file:com.tag.FramePreferences.java

public Dimension getPreferredSize() {
    Preferences prefs = getPreferences();
    int def = 0;/*  w  ww. j  a va2 s .co m*/
    int width = prefs.getInt(KEY_WIDTH, def);
    int height = prefs.getInt(KEY_HEIGHT, def);
    return new Dimension(width, height);
}