Package java.util.prefs

Examples of java.util.prefs.Preferences


*/
public class DBBrowserConfig {
   
    public static File getLastDirectory() {
        try {
            Preferences preferences = Preferences.userNodeForPackage(DBBrowserConfig.class);
            if (preferences != null) {
                try {
                    preferences.sync();
                } catch (BackingStoreException e) {
                }
                String path = preferences.get("directory", null);
                if (path != null) {
                    return new File(path);
                }
            }
        } catch (SecurityException e) {
View Full Code Here


        return null;
    }
   
    public static void setLastDirectory(File directory) {
        try {
            Preferences preferences = Preferences.userNodeForPackage(DBBrowserConfig.class);
            if (preferences != null && directory != null) {
                preferences.put("directory", directory.getAbsolutePath());
                try {
                    preferences.flush();
                } catch (BackingStoreException e) {
                }
            }
        } catch (SecurityException e) {
            //
View Full Code Here

        }
    }

    public static void saveWindowSize(String windowName, Window w) {
        try {
            Preferences preferences = Preferences.userNodeForPackage(DBBrowserConfig.class);
            if (preferences != null && w != null) {
                preferences.put("window." + windowName + ".x", w.getLocation().x + "");
                preferences.put("window." + windowName + ".y", w.getLocation().y + "");
                preferences.put("window." + windowName + ".width", w.getSize().width + "");
                preferences.put("window." + windowName + ".height", w.getSize().height + "");
                try {
                    preferences.flush();
                } catch (BackingStoreException e) {
                }
            }
        } catch (SecurityException e) {
            //
View Full Code Here

        }
    }

    public static void loadWindowSize(String windowName, Window window) {
        try {
            Preferences preferences = Preferences.userNodeForPackage(DBBrowserConfig.class);
            if (preferences != null && window != null) {
                try {
                    preferences.sync();
                } catch (BackingStoreException e) {
                }
                int x = preferences.getInt("window." + windowName + ".x", -1);
                int y = preferences.getInt("window." + windowName + ".y", -1);
                int w = preferences.getInt("window." + windowName + ".width", -1);
                int h = preferences.getInt("window." + windowName + ".height", -1);
                if (x >= 0 && w > 0) {
                    window.setSize(w, h);
                    window.setLocation(x, y);
                } else {
                    window.pack();
View Full Code Here

       
    }

    public static void setRecentDBs(List<File> paths) {
        try {
            Preferences preferences = Preferences.userNodeForPackage(DBBrowserConfig.class);
            if (preferences != null && paths != null) {
                int i = 0;
                for (File path : paths) {
                    preferences.put("recent." + i, path.getAbsolutePath());
                    i++;
                }
                try {
                    preferences.flush();
                } catch (BackingStoreException e) {
                }
            }
        } catch (SecurityException e) {
        }
View Full Code Here

    }

    public static List<File> getRecentDBs() {
        LinkedList<File> list = new LinkedList<File>();
        try {
            Preferences preferences = Preferences.userNodeForPackage(DBBrowserConfig.class);
            if (preferences != null) {
                try {
                    preferences.sync();
                } catch (BackingStoreException e) {
                }
                for (int i = 0; i < 5; i++) {
                    String path = preferences.get("recent." + i, null);
                    if (path == null) {
                        break;
                    }
                    list.add(new File(path));
                }
View Full Code Here

      if(comp instanceof JComponent) {
        ((JComponent)comp).setPreferredSize(size);
      }
    }

    Preferences prefs = getPrefs();

    if(comp instanceof JFrame) {
      Toolkit tk = comp.getToolkit();
      if(tk.isFrameStateSupported(Frame.MAXIMIZED_VERT) ||
         tk.isFrameStateSupported(Frame.MAXIMIZED_HORIZ) ||
         tk.isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {
        int state = prefs.getInt(KEY_STATE, Frame.NORMAL);
        ((Frame)comp).setExtendedState(state);
      }
      int x = prefs.getInt(KEY_X, 0);
      int y = prefs.getInt(KEY_Y, 0);
      // System.out.println("attach " + id + " pos=" + x + ", " + y);
      comp.setLocation(x, y);
    }

    if(comp instanceof JSplitPane) {
      JSplitPane split = (JSplitPane)comp;
      int pos = prefs.getInt(KEY_SPLITPOS, defSplit);
      if(pos != -1) {
        // System.out.println("attach " + id + " split=" + pos);
        split.setDividerLocation(pos);
        // Tell components that they may want to redo its layout
        Component parent = split.getParent();
View Full Code Here

    store();
  }

  Preferences getPrefs() {
    Preferences prefsBase = Preferences.userNodeForPackage(getClass());

    String spid  = Activator.getBC().getProperty("org.osgi.provisioning.spid");
    if(spid == null) {
      spid = "default";
    }

    Preferences prefs     = prefsBase.node(NODE_NAME + "/" + spid + "/" + id);
    try {
      prefs.sync(); // Get the latest version of the node.
    } catch (Exception e) {
      errCount++;
      if(errCount < maxErr) {
        Activator.log.warn("Failed to get id=" + id, e);
      }
View Full Code Here

  public void store() {
    Dimension size = comp.getSize();
    try {
      savedSize = new Dimension(size.width, size.height);
      Preferences prefs = getPrefs();


      if(comp instanceof JFrame) {
        Point p =  ((JFrame)comp).getLocationOnScreen();
        // System.out.println(id + ": store pos " + p);
        prefs.put(KEY_X, Integer.toString((int)p.getX()));
        prefs.put(KEY_Y, Integer.toString((int)p.getY()));

        Toolkit tk = Toolkit.getDefaultToolkit();
        if(tk.isFrameStateSupported(Frame.MAXIMIZED_VERT) ||
           tk.isFrameStateSupported(Frame.MAXIMIZED_HORIZ) ||
           tk.isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {
          int state = ((Frame)comp).getExtendedState();
          prefs.put(KEY_STATE, Integer.toString(state));
        }

      }

      // System.out.println(id + ": store " + size);
      prefs.put(KEY_WIDTH, Integer.toString(size.width));
      prefs.put(KEY_HEIGHT, Integer.toString(size.height));

      if(comp instanceof JSplitPane) {
        JSplitPane split = (JSplitPane)comp;
        prefs.put(KEY_SPLITPOS, Integer.toString(split.getDividerLocation()));
        // System.out.println(id + ": store split=" + split.getDividerLocation());
      }

      prefs.flush();
    } catch (Exception e) {
      errCount++;
      if(errCount < maxErr) {
        Activator.log.warn("Failed to store id=" + id + ", size=" + size, e);
      }
View Full Code Here

    if(defSize == null) {
      return null;
    }
    try {

      Preferences prefs = getPrefs();
      int w = prefs.getInt(KEY_WIDTH, defSize.width);
      int h = prefs.getInt(KEY_HEIGHT, defSize.height);

      Dimension size = new Dimension(w, h);
      return size;
    } catch (Exception e) {
      errCount++;
View Full Code Here

TOP

Related Classes of java.util.prefs.Preferences

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.