1 package prefuse.util; 2 3 import java.io.IOException ; 4 import java.util.Properties ; 5 import java.util.logging.FileHandler ; 6 import java.util.logging.Handler ; 7 import java.util.logging.Logger ; 8 import java.util.logging.SimpleFormatter ; 9 10 import prefuse.util.io.IOLib; 11 12 52 public class PrefuseConfig extends Properties { 53 54 private static final Logger s_logger 55 = Logger.getLogger(PrefuseConfig.class.getName()); 56 57 private static final PrefuseConfig s_config = new PrefuseConfig(); 58 59 63 public static PrefuseConfig getConfig() { 64 return s_config; 65 } 66 67 private PrefuseConfig() { 68 setDefaults(); 69 70 String configFile; 71 try { 72 configFile = System.getProperty("prefuse.config"); 73 } catch ( Exception e ) { 74 configFile = null; 76 } 77 if ( configFile == null ) 78 configFile = "prefuse.conf"; 79 try { 80 load(IOLib.streamFromString(configFile)); 81 s_logger.info("Loaded config file: "+configFile); 82 } catch ( Exception e ) { 83 } 85 86 String logdir = getProperty("util.logdir"); 89 String logfile = getProperty("util.logfile"); 90 if ( logdir != null ) { 91 try { 92 Logger logger = Logger.getLogger("prefuse"); 93 logger.setUseParentHandlers(false); 94 Handler fileHandler = new FileHandler (logdir+"/"+logfile); 95 fileHandler.setFormatter(new SimpleFormatter ()); 96 logger.addHandler(fileHandler); 97 } catch ( IOException e ) { 98 e.printStackTrace(); 99 } 100 } 101 } 102 103 108 public static String get(String key) { 109 return s_config.getProperty(key); 110 } 111 112 119 public static int getInt(String key) { 120 String val = s_config.getProperty(key); 121 try { 122 return Integer.parseInt(val); 123 } catch ( NumberFormatException nfe ) { 124 return Integer.MIN_VALUE; 125 } 126 } 127 128 135 public static long getLong(String key) { 136 String val = s_config.getProperty(key); 137 try { 138 return Long.parseLong(val); 139 } catch ( NumberFormatException nfe ) { 140 return Long.MIN_VALUE; 141 } 142 } 143 144 151 public static float getFloat(String key) { 152 String val = s_config.getProperty(key); 153 try { 154 return Float.parseFloat(val); 155 } catch ( NumberFormatException nfe ) { 156 return Float.NaN; 157 } 158 } 159 160 167 public static double getDouble(String key) { 168 String val = s_config.getProperty(key); 169 try { 170 return Double.parseDouble(val); 171 } catch ( NumberFormatException nfe ) { 172 return Double.NaN; 173 } 174 } 175 176 183 public static boolean getBoolean(String key) { 184 String val = s_config.getProperty(key); 185 return "true".equalsIgnoreCase(val); 186 } 187 188 191 private void setDefaults() { 192 setProperty("size.scale2D", "0.5"); 193 setProperty("activity.threadPriority", "6"); 194 setProperty("data.delimiter", "."); 195 setProperty("data.graph.nodeGroup", "nodes"); 196 setProperty("data.graph.edgeGroup", "edges"); 197 setProperty("data.visual.fieldPrefix", "_"); 198 setProperty("data.io.worker.threadPriority", 199 String.valueOf(Thread.NORM_PRIORITY)); 200 201 setProperty("data.filter.optimizeThreshold", "300"); 204 205 setProperty("data.graph.sourceKey", "source"); 207 setProperty("data.graph.targetKey", "target"); 208 setProperty("data.tree.sourceKey", "parent"); 209 setProperty("data.tree.targetKey", "child"); 210 setProperty("visualization.allItems", "_all_"); 211 setProperty("visualization.focusItems", "_focus_"); 212 setProperty("visualization.selectedItems", "_selected_"); 213 setProperty("visualization.searchItems", "_search_"); 214 215 setProperty("util.logfile", "prefuse_log_%g.txt"); 217 } 218 219 } | Popular Tags |