1 19 20 package org.netbeans.bluej.options; 21 22 import java.beans.PropertyChangeListener ; 23 import java.beans.PropertyChangeSupport ; 24 import java.io.File ; 25 import java.io.FileInputStream ; 26 import java.io.FileNotFoundException ; 27 import java.io.IOException ; 28 import java.util.Properties ; 29 import java.util.prefs.Preferences ; 30 import org.openide.util.NbPreferences; 31 import org.openide.util.Utilities; 32 33 37 public class BlueJSettings { 38 public static final String PROP_HOME = "home"; 40 private static final BlueJSettings INSTANCE = new BlueJSettings(); 41 42 private PropertyChangeSupport support = new PropertyChangeSupport (this); 43 44 protected final Preferences getPreferences() { 45 return NbPreferences.forModule(BlueJSettings.class); 46 } 47 48 protected final String putProperty(String key, String value) { 49 String retval = getProperty(key); 50 if (value != null) { 51 getPreferences().put(key, value); 52 } else { 53 getPreferences().remove(key); 54 } 55 support.firePropertyChange(key, retval, value); 56 return retval; 57 } 58 59 public void addPropertyChangeListener(PropertyChangeListener listener) { 60 support.addPropertyChangeListener(listener); 61 } 62 63 public void removePropertyChangeListener(PropertyChangeListener listener) { 64 support.removePropertyChangeListener(listener); 65 } 66 67 protected final String getProperty(String key) { 68 return getPreferences().get(key, null); 69 } 70 71 public static BlueJSettings getDefault() { 72 return INSTANCE; 73 } 74 75 public File getHome() { 76 String s = getProperty(PROP_HOME); 77 return s != null ? new File (s) : null; 78 } 79 80 public void setHome(File home) { 81 putProperty(PROP_HOME, home == null ? null : home.getAbsolutePath()); 82 } 83 84 92 public String getUserLibrariesAsClassPath() { 93 File userDir = new File (System.getProperty("user.home")); File bluejHome = null; 95 if (Utilities.isWindows()) { 96 bluejHome = new File (userDir, "bluej"); } else if (Utilities.getOperatingSystem() == Utilities.OS_MAC) { 98 bluejHome = new File (userDir, "Library/Preferences/org.bluej"); } else { 100 bluejHome = new File (userDir, ".bluej"); } 102 File prop = new File (bluejHome, "bluej.properties"); String path = ""; 104 if (prop.exists()) { 105 FileInputStream str = null; 106 try { 107 str = new FileInputStream (prop); 108 Properties properties = new Properties (); 109 properties.load(str); 110 int index = 1; 111 while (true) { 112 String propKey = "bluej.userlibrary." + index + ".location"; String value = properties.getProperty(propKey); 114 if (value != null) { 115 path = path + (path.length() == 0 ? "" : ":") + value; } else { 117 break; 119 } 120 index = index + 1; 121 } 122 } catch (FileNotFoundException ex) { 123 ex.printStackTrace(); 124 } catch (IOException ex) { 125 ex.printStackTrace(); 126 } 127 128 } 129 return path; 130 } 131 132 } 133 | Popular Tags |