00001 package org.hfbk.vis;
00002
00003 import java.io.BufferedReader;
00004 import java.io.File;
00005 import java.io.FileReader;
00006 import java.lang.reflect.Field;
00007 import java.util.HashMap;
00008 import java.util.prefs.BackingStoreException;
00009 import java.util.prefs.Preferences;
00010
00059 public class Prefs implements Cloneable{
00060 static HashMap<String,String> help=new HashMap<String,String>();
00061
00062
00063 public boolean log, osk, udp, map, verbose, sound, debug;
00064 public String
00065 version,
00066 user="anonymous",
00067 baseURL="",
00068 baseURLs="http://vis.hfbk.org/vis/;http://hirnsohle.de/vis/;http://127.0.0.1//vis/",
00069 sources="google,wikipedia,mix,googleNews,googleImages,flickr,commonImages,ebayImages,youtube,blaster,spider",
00070 language="en,es,de,fr",
00071 routes="function poti1(value){client.timescale=value/0x3FF*4;} function poti3(value){client.mouseViewpoint.tfov=value/0x3FF*4;} function poti4(value){var q=(1-value/0x3FF)*3; glutil.backgroundcolor.set(q,q,q);}",
00072 suffixesImage="jpeg|jpg|gif|png",
00073 suffixesAudio="mp3|wav|aiff",
00074 suffixesVideo="mpeg|mpg|avi|mov|rm|wmv|asf|rm|swf",
00075 init="",
00076 screenshotdir=".",
00077 watchdir="",
00078 font="Sans Serif";
00079 public int
00080 maxTextLength=10000,
00081 logCount = 1000,
00082 logUpdate = 60000,
00083 timeout=30000,
00084 servertimeout=2000,
00085 automate=0,
00086 detail=3,
00087 thumbpixels=300000;
00088 public boolean autoFocus=true, direct=true, update=true, screenshotupload=false;
00089
00090 static{
00091 help.put("log", "log queries to the vis server");
00092 help.put("osk", "use the onscreen keyboard");
00093 help.put("udp", "use udp for external communication");
00094 help.put("map", "use the birds eye view");
00095 help.put("verbose", "output debug messages");
00096 help.put("sound", "use sound");
00097 help.put("debug", "use 3d debugging geometries");
00098
00099 help.put("user", "your name for logging");
00100 help.put("baseURL","vis/server currently in use");
00101 help.put("baseURLs","vis/servers to use");
00102 help.put("sources","sources to show in source popup menu");
00103 help.put("language","preferred language in two chars coding");
00104 help.put("routes","javascript functions called on\nkeystrokes or external input");
00105 help.put("suffixesImage","filetypes to be displayed as images");
00106 help.put("suffixesAudio","filetypes to be played as audio");
00107 help.put("suffixesVideo","filetypes to be played as video panels");
00108 help.put("init","javascript executed on start and reset");
00109 help.put("screenshotdir","directory to store your screenshots in");
00110 help.put("watchdir","directory to always show in space");
00111 help.put("font","preferred fancy font to use");
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 help.put("maxTextLength","size limit for text panels");
00127 help.put("logCount", "number of log entries to fetch");
00128 help.put("logUpdate", "time in mS until next log update");
00129 help.put("timeout", "general query timeout");
00130 help.put("servertimeout","timeout in mS for startup server check");
00131 help.put("automate","percentage of log following");
00132 help.put("detail","geometry detail level (1-4)");
00133 help.put("thumbpixels","max thumbnail pixels");
00134
00135 help.put("autoFocus","put the caret to source field on typing if enabled");
00136 help.put("direct","use direct connections to sources");
00137 help.put("update","load source definitions from vis server");
00138 help.put("screenshotupload","automatically upload / contribute screenshots to vis server");
00139 }
00140
00141 static Preferences prefsnode = Preferences.userNodeForPackage(VisClient.class);
00142
00143 static public Prefs current=new Prefs(true);
00144 static public Prefs defaults=new Prefs(false);
00145
00146
00147 static void addShutdownHook(){
00148 Runtime.getRuntime().addShutdownHook(
00149 new Thread() {
00150 public void run() {
00151 current.save();
00152 }
00153 }
00154 );
00155 }
00156
00157 public Prefs(boolean loadFromUser) {
00158 if (loadFromUser) load();
00159 }
00160
00164 void load() {
00165 try {
00166 for (Field f : getClass().getFields()) {
00167 String name=f.getName();
00168 Object value = f.get(this);
00169 Class type=f.getType();
00170
00171 if (type == Boolean.TYPE)
00172 f.set(this, prefsnode.getBoolean(name, (Boolean)value));
00173 else if (type == Integer.TYPE)
00174 f.set(this, prefsnode.getInt(name, (Integer)value));
00175 else if (type == String.class)
00176 f.set(this, prefsnode.get(name, (String)value));
00177 }
00178 } catch (Exception e) {
00179 throw new RuntimeException("Prefs:",e);
00180 }
00181 version=getVersion();
00182 }
00183
00187 void save() {
00188 try {
00189 for (Field f : getClass().getFields()) {
00190 String name=f.getName();
00191 Object value = f.get(this);
00192 Class type=f.getType();
00193
00194 if (type == Boolean.TYPE)
00195 prefsnode.putBoolean(name, (Boolean)value);
00196 else if (type == Integer.TYPE)
00197 prefsnode.putInt(name, (Integer)value);
00198 else if (type == String.class)
00199 prefsnode.put(name, (value!=null ? (String)value : ""));
00200 }
00201 prefsnode.flush();
00202 System.out.println("Prefs saved.");
00203 } catch (Exception e) {
00204 throw new RuntimeException(e);
00205 }
00206 }
00207
00214 public static void main(String[] args) {
00215 if (args.length>0 && args[0].equals("--remove")) {
00216 try {
00217 prefsnode.removeNode();
00218 } catch (BackingStoreException e) { throw new RuntimeException (e); }
00219 System.out.println("User Settings cleared.");
00220 }else{
00221 current.load();
00222 addShutdownHook();
00223 new PrefsDialog();
00224 }
00225 }
00226
00227 public Prefs clone() {
00228 try {
00229 return (Prefs)super.clone();
00230 } catch (CloneNotSupportedException e) {
00231 throw new RuntimeException (e);
00232 }
00233 }
00234
00239 public void parse(String[] args) throws Exception {
00240 for (int i = 0; i < args.length; i += 2) {
00241 String key = args[i], value = args[i + 1];
00242 Field f=getClass().getField(key);
00243 if (f.getType()==Integer.TYPE)
00244 f.setInt(this, Integer.parseInt(value));
00245 else if (f.getType()==Boolean.TYPE)
00246 f.setBoolean(this, Boolean.parseBoolean(value));
00247 else if (f.getType()==String.class)
00248 f.set(this, value);
00249 }
00250 }
00251
00252 static String getVersion(){
00253 try {
00254 File svn=new File(".svn/entries");
00255 if (svn.exists()){
00256 BufferedReader r= new BufferedReader(new FileReader(svn));
00257 r.readLine();r.readLine();r.readLine();
00258 return r.readLine();
00259 }else
00260 return new BufferedReader(new FileReader("version.txt")).readLine();
00261
00262 } catch (Exception e) { System.out.println("Cannot read version file!"); }
00263 return "Unknown";
00264 }
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281 }