1 package sellwin.utils; 2 3 import java.util.*; 4 import java.io.*; 5 import java.text.*; 6 import java.awt.*; 7 8 12 19 public class Prefs { 20 21 public final static boolean DEBUG=true; 22 23 public final static int ORACLE = 1; 25 public final static int MYSQL = 2; 26 27 public final static int I_TOP = 7; 29 public final static int I_LF = 5; 30 public final static int I_BOTT = 7; 31 public final static int I_RT = 5; 32 33 public final static int FIELD_HEIGHT = 20; 34 35 private static Properties systemProps=null; 36 public final static String CONNECTED="Connected"; 37 public final static String TWO_TIER="2Tier"; 38 public final static String LOCAL="Local"; 39 40 public final static String [] LANGS = { "English", "French", "Spanish", "German" }; 41 public final static String DEF_LANG = "defaultLanguage"; 42 public final static String CONN_MODE = "connectionMode"; 43 public final static String LOCAL_DB= "sellwin"; 44 public final static String LOCAL_DB_ID= "localDBid"; 45 public final static String LOCAL_DB_PSW= "localDBpsw"; 46 public final static String SERVER_NAME= "serverName"; 47 public final static String LAST_ID= "default"; 48 public final static String PREF_BASE= ".sellwinrc"; 49 public final static String SELLWIN_HOME= "sellwin"; 50 public final static String DATA_BASE= "data"; 51 52 public final static NumberFormat wholeMoney = new DecimalFormat("#,###,###,##0"); 53 public final static NumberFormat money = new DecimalFormat("#,###,###,##0.00"); 54 public final static SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yy"); 55 public final static SimpleDateFormat dateTimeFormat = new SimpleDateFormat("MM/dd/yy hh:mm aa"); 56 57 58 62 public static String getDefaultLang() { 63 Properties props = getApplProps(); 64 String lang = (String )(props.getProperty(DEF_LANG)); 65 return lang; 66 } 67 68 73 public static String getDataDir() { 74 Properties props = getApplProps(); 75 String dir = (String )(props.getProperty(LOCAL_DB)); 76 return dir; 77 } 78 79 83 public static String getLastID() { 84 Properties props = getApplProps(); 85 String lastID = (String )(props.getProperty(LAST_ID)); 86 if (lastID == null) 87 return "default"; 88 else 89 return lastID; 90 } 91 96 public static String getServerName() { 97 Properties props = getApplProps(); 98 String serverName = (String )(props.getProperty(SERVER_NAME)); 99 if (serverName == null) 100 return "localhost"; 101 else 102 return serverName; 103 } 104 105 110 public static String getConnectionMode() { 111 Properties props = getApplProps(); 112 String mode = (String )(props.getProperty(CONN_MODE)); 113 return mode; 114 } 115 116 121 public static void saveApplProps(Properties props) { 122 FileOutputStream outStream=null; 123 try { 124 System.out.println("saving props to "+ Prefs.getApplPropsPath()); 125 outStream = new FileOutputStream(Prefs.getApplPropsPath()); 126 props.store(outStream, "SellWin application properties"); 127 } catch (IOException e) { 128 e.printStackTrace(); 129 } finally { 130 try { 131 if (outStream != null) 132 outStream.close(); 133 } catch (Exception f) { 134 f.printStackTrace(); 135 } 136 } 137 } 138 139 143 public static Properties getApplProps() { 144 String appPropsPath = getApplPropsPath(); 145 Properties props = new Properties(); 146 147 FileInputStream inStream=null; 148 try { 149 inStream = new FileInputStream(appPropsPath); 150 props.load(inStream); 151 } catch (FileNotFoundException e) { 152 System.out.println(appPropsPath + " does not exist...creating with default values"); 153 props.setProperty(DEF_LANG, LANGS[0]); 154 props.setProperty(CONN_MODE, LOCAL); 155 props.setProperty(LAST_ID, "trial"); 156 props.setProperty(LOCAL_DB, "sellwin"); 157 props.setProperty(LOCAL_DB_ID, "localid"); 158 props.setProperty(LOCAL_DB_PSW, "localpsw"); 159 props.setProperty(SERVER_NAME, "localhost"); 160 saveApplProps(props); 161 } catch (IOException e) { 162 e.printStackTrace(); 163 } finally { 164 try { 165 if (inStream != null) 166 inStream.close(); 167 } catch (Exception f) { 168 f.printStackTrace(); 169 } 170 } 171 return props; 172 } 173 174 178 public static String getDatabaseHost() { 179 Properties props = System.getProperties(); 180 return props.getProperty("DATABASE_HOST"); 181 } 182 183 187 public static String getDatabasePort() { 188 Properties props = System.getProperties(); 189 return props.getProperty("DATABASE_PORT"); 190 } 191 192 196 public static String getDatabaseType() { 197 Properties props = System.getProperties(); 198 return props.getProperty("DATABASE_TYPE"); 199 } 200 201 205 public static String getDatabaseName() { 206 Properties props = System.getProperties(); 207 return props.getProperty("DATABASE_NAME"); 208 } 209 210 214 public static String getDatabaseID() { 215 Properties props = System.getProperties(); 216 return props.getProperty("DATABASE_ID"); 217 } 218 219 223 public static String getDatabasePassword() { 224 Properties props = System.getProperties(); 225 return props.getProperty("DATABASE_PASSWORD"); 226 } 227 228 232 public static String getServerHost() { 233 Properties props = System.getProperties(); 234 return props.getProperty("SERVER_HOST"); 235 } 236 240 public static String getLocalDB() { 241 Properties props = System.getProperties(); 242 return props.getProperty("LOCAL_DB"); 243 } 244 248 public static String getLocalDBID() { 249 Properties props = System.getProperties(); 250 return props.getProperty("LOCAL_DB_ID"); 251 } 252 256 public static String getLocalDBPSW() { 257 Properties props = System.getProperties(); 258 return props.getProperty("LOCAL_DB_PSW"); 259 } 260 261 265 public static String getHomeDir() { 266 if (systemProps == null) 267 systemProps = System.getProperties(); 268 return systemProps.getProperty("user.home"); 269 } 270 271 275 public static String getFileSep() { 276 if (systemProps == null) 277 systemProps = System.getProperties(); 278 279 return systemProps.getProperty("file.separator"); 280 } 281 282 287 public static String getApplPropsPath() { 288 String homeDir = getHomeDir(); 289 return homeDir + getFileSep() + PREF_BASE; 290 } 291 } 292 293 | Popular Tags |