Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/mitre/cvw/CVWPreferences.java


1   /*
2    * Copyright (c) 1996-2000. The MITRE Corporation (http://www.mitre.org/).
3    * All rights reserved.
4    * CVW comes with ABSOLUTELY NO WARRANTY. See license for details.
5    */
6   
7   package org.mitre.cvw;
8   
9   import java.io.*;
10  import java.awt.Color;
11  import java.awt.Rectangle;
12  import java.awt.Point;
13  import java.util.StringTokenizer;
14  import java.util.Properties;
15  import java.util.Vector;
16  import java.util.Hashtable;
17  import java.util.LinkedList;
18  
19  /**
20   * This class processes all user preferences whether stored locally on the
21   * user's workstation or on the CVW server. 
22   * Note that the preferences stored on the CVW server are instance vars, whereas
23   * the preferences stored locally are part of a java.util.Properties instance.
24   * @version 1.0
25   * @author Deb Ercolini
26   */
27  public class CVWPreferences extends Object {
28  
29     public static final int NOCOLOR = 0;
30     public static final int RED = 1;
31     public static final int GREEN = 2;
32     public static final int BLUE = 3;
33     public static final int PURPLE = 4;
34     public static final int ORANGE = 5;
35     public static final int YELLOW = 6;
36     public static final int MAGENTA = 7;
37     public static final int CYAN = 8;
38  
39  /* 9/3/97 dage - grabbed color values directly from awt/Color.java
40   */
41  /**
42   * Returns the java.awt.Color given an integer
43   * @param value the color desired
44   * @return the java.awt.Color
45   */
46     public static Color getSystemColor(int value) {
47       switch (value) {
48    case NOCOLOR:
49      return Color.black;
50    case RED:
51      return Color.red;
52    case GREEN:
53      return Color.green;
54    case BLUE:
55      return Color.blue;
56    case PURPLE:
57      return Color.magenta.darker();
58    case ORANGE:
59      //return Color.orange.darker();
60      // orange --> new Color(255, 200, 0);
61      return new Color(200, 100, 0);
62    case YELLOW:
63      //return Color.yellow.darker();
64      // yellow --> new Color(255, 255, 0);
65      return new Color(200, 200, 0);
66    case MAGENTA:
67      return Color.magenta;
68    case CYAN:
69      return Color.cyan.darker().darker();
70    default:
71      return Color.black;
72       }
73    }
74    
75  /**
76   * Returns the default window size/location of either the audio or
77   * video tool.  Missed named.
78   * @param either "Audio" or "Video"
79   * @return 
80   */
81    public static Rectangle getDefaultSize(String toolType) {
82       if (toolType.equals("Audio"))
83    return getAudioDefaultSize();
84       if (toolType.equals("Video"))
85    return getVideoDefaultSize();
86       return null;
87     }
88  
89  /**
90   * Returns the default audio tool size.
91   * @return the default audio tool size/location
92   */
93    public static Rectangle getAudioDefaultSize() {
94       return new Rectangle(300, 300, 300, 320); //x,y,w,h
95     }
96  
97  /**
98   * Returns the default video tool size.
99   * @return the default video tool size/location
100  */
101   public static Rectangle getVideoDefaultSize() {
102      return new Rectangle(200, 200, 300, 280); //x,y.w,h
103    }
104 
105 /**
106  * Returns the default Proxy window size.
107  * @return the default proxy window size/location
108  */
109   public static Rectangle getProxyDefaultSize() {
110         return new Rectangle(250,200,540,450);
111       }
112 
113    String idleMsg = "Real Life Intrusion";
114    boolean timeStamp = true;
115    boolean localTimeZone = true;  //stored locally
116    String prefVersion = "4";   //set this whenever the cvw.rc format changes
117    int videoMaxBandwidth = 128;   //eventually set by server.
118    static Hashtable rangeTable;
119 
120 //highlighting
121    int highlightName = NOCOLOR;
122    int highlightComm = NOCOLOR;
123    int highlightPubComm = NOCOLOR;
124    LinkedList hilightObjects;    //key is objNum as String, value is color as Integer
125 
126 /* 8/12/98 dage - deleted the instance vars ... now using a Properties object
127  */
128   String prefFile=null;
129   NPDocServer plugin=null;
130   
131   Properties prefProps;
132 
133 /**
134  * Constructor
135  */
136   CVWPreferences() {
137     Rectangle r = CVWCoordinator.getInstance().getBounds();
138     prefProps = new Properties();
139     prefProps.setProperty("cvw.main.geometry", getStringFromRect(r));
140     getProxySize();
141     getCarrySize();
142     getMapSize();
143     getOnlineSize();
144     if (rangeTable == null)
145       initRangeTable();
146      hilightObjects = new LinkedList();
147    }
148  
149 /* 4/22/98 dage - dont read the prefs from file upon create, but specifically call it out
150  * 8/12/98 dage - upgrade prefs from ver3 (text file) to ver4 Properties
151  */
152 /**
153  * Initialized the current user's system preferences by reading it from a file.
154  * If an old version is detected, it is read in, converted to java.util.Properties, 
155  * the old file is deleted and then a new format is written.
156  * @see #readV3PrefFromFile
157  */
158  public void init() {
159     plugin = NPDocServer.getInstance();
160 
161     if (plugin == null) return;
162 
163     String sysDir = plugin.getOldUserDir();
164     if (sysDir == null) {
165       // Memory allocation didn't happen, so NULL was returned..
166       //throw new CheckoutDirectoryException();
167       return;
168     }
169     //initPrefProps();
170     prefFile = new String(sysDir + System.getProperty("file.separator") + "cvw.rc");
171     boolean oldVerExists = false;
172     if(plugin.fileExists(prefFile)) {
173     System.err.println("old pref file exists ... upgrading" + prefFile);
174       CVWCoordinator jcvw = CVWCoordinator.getInstance();
175       oldVerExists = true;
176       if (readV3PrefFromFile())
177          jcvw.displayPrvSysMsg("Errors incountered when upgrading your preference file.");
178     else {
179         jcvw.displayPrvSysMsg("Successfully upgraded your preference file.");
180         clearPrefFile();
181        }
182      }
183   sysDir = plugin.getUserDir();
184     prefFile = new String(sysDir + System.getProperty("file.separator") + ".cvwprefs");
185   if (oldVerExists) System.err.println("new" + prefFile);
186     if (oldVerExists) 
187       writePrefsToFile();
188     else
189       readPrefProperties();
190       
191    }
192 
193 /****  hi light accessor methods *****/
194    public HiLightObject getHiLightObject(int index) {
195       if (index < 0 || index >= hilightObjects.size())
196   return null;
197       else 
198   return (HiLightObject)hilightObjects.get(index);
199     }
200 
201    public Color getHiLightColorForUser(String objNum) {
202       for (int i = 0; i < hilightObjects.size(); i++) {
203   HiLightObject hiLight = (HiLightObject)hilightObjects.get(i);
204   if (hiLight.objNum.equals(objNum)) 
205     return getSystemColor(hiLight.color);
206        }
207    return null;
208      }
209 
210 /****  video accessor methods *****/
211 /**
212  * Returns the video encoding string as needed by the video tool.
213  * @return the video encoding string as needed by the video tool
214  */
215   public String getVideoEncodingString() {
216       String videoEncoding = getVideoEncoding();
217       if (videoEncoding.equals("NV")) return "nv -A nv";
218       return videoEncoding.toLowerCase();
219    }
220 /**
221  * Returns the video encoding value.
222  * @return the video encoding value
223  */
224   public String getVideoEncoding() {
225       return prefProps.getProperty("cvw.video.encoding", "H.261");
226    }
227 /**
228  * Returns the video TTL Multicast value.
229  * @return the video TTL Multicast 
230  */
231   public String getVideoTTLMulticast() {
232       return prefProps.getProperty("cvw.video.TTL.multicast", "16");
233    }
234 /**
235  * Returns the video TTL Unicast value.
236  * @return the video TTL Unicast 
237  */
238   public String getVideoTTLUnicast() {
239       return prefProps.getProperty("cvw.video.TTL.unicast", "16");
240    }
241 /**
242  * Returns the video FrameRate value.
243  * @return the video framerate
244  */
245   public String getVideoFrameRate() {
246       return prefProps.getProperty("cvw.video.framerate", "8");
247    }
248 /**
249  * Returns the video Bandwidth value.
250  * @return the video bandwidth
251  */
252   public String getVideoBandwidth() {
253       return prefProps.getProperty("cvw.video.bandwidth", "32");
254     }
255 /**
256  * Returns the video max bandwidth value.
257  * @return the video max bandwidth
258  */
259   public int getVideoMaxBandwidth() {
260       return videoMaxBandwidth;
261     }
262    
263 /**
264  * Sets the video encoding value
265  * @param the video encoding value
266  */
267   public void setVideoEncoding(String enc) {
268       prefProps.setProperty("cvw.video.encoding", enc);
269    }
270 /**
271  * Sets the video ttl multicast value
272  * @param the video ttl multicast value
273  */
274   public void setVideoTTLMulticast(String ttl) {
275       prefProps.setProperty("cvw.video.TTL.multicast", ttl);
276    }
277 /**
278  * Sets the video ttl unicast value
279  * @param the video ttl unicast value
280  */
281   public void setVideoTTLUnicast(String ttl) {
282       prefProps.setProperty("cvw.video.TTL.unicast", ttl);
283    }
284 /**
285  * Sets the video frame rate value
286  * @param enc the video frame rate
287  */
288   public void setVideoFrameRate(String enc) {
289       prefProps.setProperty("cvw.video.framerate", enc);
290    }
291 /**
292  * Sets the video bandwidth value
293  * @param w the video bandwidth 
294  */
295   public void setVideoBandwidth(String w) {
296       prefProps.setProperty("cvw.video.bandwidth", w);
297    }
298 /**
299  * Sets the max video bandwidth value
300  * @param max the max video bandwidth
301  */
302   public void setVideoMaxBandwidth(String max) {
303       try {
304       Integer i = new Integer(max);
305       videoMaxBandwidth = i.intValue();
306       //System.err.println("Setting new max bandwidth: " + videoMaxBandwidth);
307       } catch (NumberFormatException ne) {
308       System.err.println("problem with video max bandwidth: " + max); }
309     }
310 
311 /****  audio accessor methods *****/
312 /**
313  * Gets the audio encoding value.
314  * @return the audio encoding value 
315  */
316   public String getAudioEncoding() {
317       return prefProps.getProperty("cvw.audio.encoding", "GSM");
318    }
319 /**
320  * Gets the audio encoding value as needed by the audio tool.
321  * @return the audio encoding value as needed by the audio tool 
322  */
323   public String getAudioEncodingString() {
324       return getAudioEncoding().toLowerCase();
325    }
326 /**
327  * Gets the audio multicast ttl volume value.
328  * @return the audio multicast ttl
329  */
330   public String getAudioTTLMulticast() {
331       return prefProps.getProperty("cvw.audio.TTL.multicast", "16");
332    }
333 /**
334  * Gets the audio unicast ttl value.
335  * @return the audio unicast ttl volume
336  */
337   public String getAudioTTLUnicast() {
338       return prefProps.getProperty("cvw.audio.TTL.unicast", "16");
339    }
340 /**
341  * Gets the audio microphone volume value.
342  * @return the audio microphone volume
343  */
344   public String getAudioMicVol() {
345       return prefProps.getProperty("cvw.audio.micVol", "32");
346    }
347 /**
348  * Gets the audio speaker volume value.
349  * @return the audio speaker volume
350  */
351   public String getAudioSpeakerVol() {
352       return prefProps.getProperty("cvw.audio.speakerVol", "180");
353    }
354 
355 /**
356  * Sets the audio speaker volume value.
357  * @param enc the audio speaker volume
358  */
359   public void setAudioEncoding(String enc) {
360       prefProps.setProperty("cvw.audio.encoding", enc);
361    }
362 /**
363  * Sets the audio ttl multicast value.
364  * @param ttl audio multicast ttl 
365  */
366   public void setAudioTTLMulticast(String ttl) {
367       prefProps.setProperty("cvw.audio.TTL.multicast", ttl);
368    }
369 /**
370  * Sets the audio ttl unicast value.
371  * @param ttl the audio unicast ttl
372  */
373   public void setAudioTTLUnicast(String ttl) {
374       prefProps.setProperty("cvw.audio.TTL.unicast", ttl);
375    }
376 /**
377  * Sets the audio microphone volume value.
378  * @param vol the audio microphone volume
379  */
380   public void setAudioMicVol(String vol) {
381       prefProps.setProperty("cvw.audio.micVol", vol);
382    }
383 /**
384  * Sets the audio speaker volume value.
385  * @param vol the audio speaker volume
386  */
387   public void setAudioSpeakerVol(String vol) {
388       prefProps.setProperty("cvw.audio.speakerVol", vol);
389    }
390 
391 /**
392  * Returns whether to use RTP for audio
393  * @return whether to use RTP for audio
394  */
395   public boolean useAudioRTP() {
396     return getPropBooleanValue("cvw.audio.rtp", "true");
397    }
398 /**
399  * Sets whether the rtp should be used for audio
400  * @param b whether to use rtp for audio
401  */
402   public void setAudioRTP(boolean b) {
403     setPropBooleanValue("cvw.audio.rtp", b);
404    }
405 
406 /****  misc accessor methods *****/
407 /**
408  * Returns whether to use local time zone
409  * @return whether local time zone is to be used
410  */
411   public boolean useLocalTimeZone() {
412     return getPropBooleanValue("cvw.timezone.local", "true");
413    }
414 /**
415  * Sets whether to use local time zone
416  * @param b whether to use local time zone
417  */
418   public void setLocalTimeZone(boolean b) {
419     setPropBooleanValue("cvw.timezone.local", b);
420    }
421 
422 /****  emacs accessor methods *****/
423 /**
424  * Returns whether to use emacs commands in cmd entry area
425  * @return whether emacs commands in cmd entry area should be used
426  */
427   public boolean useEmacsCmds() {
428     return getPropBooleanValue("cvw.emacs", "false");
429    }
430 /**
431  * Sets whether to use emacs commands in cmd entry area
432  * @param b whether to use emacs commands in cmd entry area
433  */
434   public void setEmacsCmds(boolean b) {
435     setPropBooleanValue("cvw.emacs", b);
436    }
437 
438 /****  xcvw text accessor methods *****/
439 /****  hidden preference *****/
440 /**
441  * Returns whether to use emacs commands in cmd entry area
442  * @return whether emacs commands in cmd entry area should be used
443  */
444   public boolean getTextOrderPref() {
445     return getPropBooleanValue("cvw.moo.text", "false");
446    }
447 
448 /****  audio speaker accessor methods *****/
449 /**
450  * Returns whether to speakers rather than headsets
451  * @return true if use speakers, false if headsets
452  */
453   public boolean useAudioSpeakers() {
454     return getPropBooleanValue("cvw.audio.speakers", "true");
455    }
456 
457 /**
458  * Returns sets either speakers or headset
459  */
460   public void setAudioSpeakers(String type) {
461     boolean b = true;
462     if (type != null && type.equals("Headset"))
463       b = false;
464     setPropBooleanValue("cvw.audio.speakers", b);
465    }
466 
467 /****  av geometry accessor methods *****/
468 /**
469  * Returns the size location of an av tool given the type.
470  * @param toolType either &quot;Audio&quot; or &quot;Video&quot;
471  * @return the size & location of the av tool
472  */
473   public Rectangle getAVSize(String toolType) {
474      if (toolType.equals("Audio"))
475         return getAudioSize();
476      if (toolType.equals("Video"))
477         return getVideoSize();
478      return null;
479    }
480 /**
481  * Returns the size location of the video tool.
482  * @return the size & location of the video tool
483  */
484   public Rectangle getVideoSize() {
485     return getRectFromProps("cvw.video.geometry", getVideoDefaultSize());
486   //return videoGeometry;
487    }
488 /**
489  * Returns the size location of the audio tool.
490  * @return the size & location of the audio tool
491  */
492   public Rectangle getAudioSize() {
493     return getRectFromProps("cvw.audio.geometry", getAudioDefaultSize());
494   //return audioGeometry;
495    }
496 
497 /**
498  * Sets the size & location of an av tool given the type.
499  * @param toolType either &quot;Audio&quot; or &quot;Video&quot;
500  * @param newSize the size and location of the tool
501  */
502   public void setAVSize(String toolType, Rectangle newSize) {
503      prefProps.setProperty("cvw."+toolType.toLowerCase()+".geometry",
504              getStringFromRect(newSize)); 
505    }
506    
507   /* 8/12/98 dage - accessor methods for the execution of vic/vat
508    */
509 /**
510  * Gets the geometry of the video window as a string.  Specifically built for
511  * the vic video tool.
512  * @return a geometry string
513  */
514   public String getVideoGeometry() {
515       Rectangle videoGeometry = getVideoSize();
516       String geo = videoGeometry.width + "x" + videoGeometry.height;
517       geo = geo +  "+" +  videoGeometry.x + "+" + videoGeometry.y;
518       return geo;
519    }
520 /**
521  * Gets the geometry of the audio window as a string.  Specifically built for
522  * the vat video tool.
523  * @return a geometry string
524  */
525   public String getAudioGeometry() {
526       Rectangle audioGeometry = getAudioSize();
527       String geo = audioGeometry.width + "x" + audioGeometry.height;
528       geo = geo + "+" + audioGeometry.x + "+" + audioGeometry.y;
529       return geo;
530    }
531    
532 /****  default command accessor methods *****/
533 /**
534  * Returns which default command to use for main window
535  * @return which default command to use for main window
536  */
537   public int getMainDefaultCmd() {
538     String val = prefProps.getProperty("cvw.defaultCmd");
539     if (val == null) return CVWCommand.SAY;
540     try {
541   return Integer.parseInt(val);
542     } catch (Exception e) {
543   return CVWCommand.SAY;
544     }
545    }
546 /**
547  * Sets the default cvw command  for main window
548  * @param i the default cvw command for main window
549  */
550   public void setMainDefaultCmd(int i) {
551     prefProps.setProperty("cvw.defaultCmd", String.valueOf(i));
552    }
553 
554 /**
555  * Returns which default command to use for proxy window
556  * @return which default command to use for proxy window
557  */
558   public int getProxyDefaultCmd() {
559     String val = prefProps.getProperty("cvw.proxy.defaultCmd");
560     if (val == null) return CVWCommand.SAY;
561     try {
562   return Integer.parseInt(val);
563     } catch (Exception e) {
564   return CVWCommand.SAY;
565     }
566    }
567 /**
568  * Sets the default cvw command  for proxy window
569  * @param i the default cvw command  for proxy window
570  */
571   public void setProxyDefaultCmd(int i) {
572     prefProps.setProperty("cvw.proxy.defaultCmd", String.valueOf(i));
573    }
574 
575 /****  window geometry accessor methods *****/   
576 /**
577  * Returns the preferred size and location of the map window, if none, 
578  * then a default size and location.
579  * @return the preferred size and location of the map window
580  */
581   public Rectangle getMapSize() {
582     Point jcvwLoc = CVWCoordinator.getJCVWXY();
583     return getRectFromProps("cvw.map.geometry",
584       new Rectangle(jcvwLoc.x - 100, jcvwLoc.y - 100, 250, 300));
585    }
586 /**
587  * Sets the preferred size and location of the map window.
588  * @param newSize the new size and location of the map window
589  */
590   public void setMapSize(Rectangle newSize) {
591   String s = getStringFromRect(newSize);
592     prefProps.setProperty("cvw.map.geometry", s);
593    }
594 
595 /**
596  * Returns the preferred size and location of the carry folder window, if none, 
597  * then a default size and location.
598  * @return the preferred size and location of the carry folder window
599  */
600   public Rectangle getCarrySize() {
601      return getRectFromProps("cvw.carry.geometry", 
602              new Rectangle(250, 200, 500, 262));
603    }
604 /**
605  * Sets the preferred size and location of the carry folder window.
606  * @param newSize the new size and location of the carry folder window
607  */
608   public void setCarrySize(Rectangle newSize) {
609     String s = getStringFromRect(newSize);
610     prefProps.setProperty("cvw.carry.geometry", s);
611    }
612 
613 /**
614  * Returns the preferred size and location of the proxy window, if none, 
615  * then a default size and location.
616  * @return the preferred size and location of the proxy window
617  */
618   public Rectangle getProxySize() {
619      return getRectFromProps("cvw.proxy.geometry", getProxyDefaultSize());
620    }
621 /**
622  * Sets the preferred size and location of the proxy window.
623  * @param newSize the new size and location of the proxy window
624  */
625   public void setProxySize(Rectangle newSize) {
626     String s = getStringFromRect(newSize);
627     prefProps.setProperty("cvw.proxy.geometry", s);
628    }
629 
630 /**
631  * Returns the preferred size and location of the main window, if none,
632  * then a default size and location.
633  * @return the preferred size and location of the main window
634  */
635   public Rectangle getMainSize() {
636      return getRectFromProps("cvw.main.geometry", new Rectangle(0, 0, 540, 450));
637    }
638 /**
639  * Sets the preferred size and location of the main window.
640  * @param newSize the new size and location of the main window
641  */
642   public void setMainSize(Rectangle newSize) {
643     String s = getStringFromRect(newSize);
644     prefProps.setProperty("cvw.main.geometry", s);
645    }
646 
647 /**
648  * Returns whether the main window should shrink/grow when panels are hidden/shown
649  * @return whether the main window should shrink/grow
650  */
651   public boolean getChangeMainSize() {
652     return getPropBooleanValue("cvw.main.changeSize", "true");
653    }
654 /**
655  * Sets whether the main window should shrink/grow when panels are hidden/shown
656  * @param b whether the main window should shrink/grow
657  */
658   public void setChangeMainSize(boolean b) {
659     setPropBooleanValue("cvw.main.changeSize", b);
660    }
661 
662 /**
663  * Returns the preferred size and location of the online users window, if none,
664  * then a default size and location.
665  * @return the preferred size and location of the online users window
666  */
667   public Rectangle getOnlineSize() {
668      Point jcvwLoc = CVWCoordinator.getJCVWXY();
669      return getRectFromProps("cvw.online.geometry", 
670            new Rectangle(jcvwLoc.x - 50,jcvwLoc.y - 50,500,290));
671    }
672 /**
673  * Sets the preferred size and location of the online users window.
674  * @param newSize the new size and location of the online users window
675  */
676   public void setOnlineSize(Rectangle newSize) {
677     String s = getStringFromRect(newSize);
678     prefProps.setProperty("cvw.online.geometry", s);
679    }
680 
681 /****  window visibile accessor methods *****/   
682 /**
683  * Returns whether the audio tool should be opened on connect.
684  * @return <code>true</code> if audio tool should be opened on connect
685  */
686   public boolean getAudioShow() {
687     return getPropBooleanValue("cvw.audio.show", "false");
688    }
689 /**
690  * Sets whether the audio tool should be opened on connect.
691  * @param b <code>true</code> if audio tool should be opened on connect
692  */
693   public void setAudioShow(boolean b) {
694     setPropBooleanValue("cvw.audio.show", b);
695    }
696 
697 /**
698  * Returns whether the video tool should be opened on connect.
699  * @return <code>true</code> if video tool should be opened on connect
700  */
701   public boolean getVideoShow() {
702     return getPropBooleanValue("cvw.video.show", "false");
703    }
704 /**
705  * Sets whether the video tool should be opened on connect.
706  * @param b <code>true</code> if video tool should be opened on connect
707  */
708   public void setVideoShow(boolean b) {
709     setPropBooleanValue("cvw.video.show", b);
710    }
711 
712 /**
713  * Returns whether the proxy window should be opened on connect.
714  * @return <code>true</code> if proxy window should be opened on connect
715  */
716   public boolean getProxyShow() {
717     return getPropBooleanValue("cvw.proxy.show", "false");
718    }
719 /**
720  * Sets whether the proxy window should be opened on connect.
721  * @param b <code>true</code> if proxy window should be opened on connect
722  */
723   public void setProxyShow(boolean b) {
724     setPropBooleanValue("cvw.proxy.show", b);
725    }
726 
727 /**
728  * Returns whether the proxy window should be opened on connect.
729  * @return <code>true</code> if proxy window should be opened on connect
730  */
731   public boolean getMapShow() {
732     return getPropBooleanValue("cvw.map.show", "false");
733    }
734 /**
735  * Sets whether the map window should be opened on connect.
736  * @param b <code>true</code> if map window should be opened on connect
737  */
738   public void setMapShow(boolean b) {
739     setPropBooleanValue("cvw.map.show", b);
740    }
741    
742 /**
743  * Returns whether the online users window should be opened on connect.
744  * @return <code>true</code> if online users window should be opened on connect
745  */
746   public boolean getOnlineShow() {
747     return getPropBooleanValue("cvw.online.show", "false");
748    }
749 /**
750  * Sets whether the online users window should be opened on connect.
751  * @param b <code>true</code> if online users window should be opened on connect
752  */
753   public void setOnlineShow(boolean b) {
754     setPropBooleanValue("cvw.online.show", b);
755    }
756 
757 /**
758  * Returns whether the carry folder window should be opened on connect.
759  * @return <code>true</code> if carry folder window should be opened on connect
760  */
761   public boolean getCarryShow() {
762     return getPropBooleanValue("cvw.carry.show", "false");
763    }
764 /**
765  * Sets whether the carry folder window should be opened on connect.
766  * @param b <code>true</code> if carry folder window should be opened on connect
767  */
768   public void setCarryShow(boolean b) {
769     setPropBooleanValue("cvw.carry.show", b);
770    }
771 
772 /**
773  * Returns whether the users panel should be visible on connect.
774  * @return <code>true</code> if users panel should be visible on connect
775  */
776   public boolean getUsersShow() {
777     return getPropBooleanValue("cvw.users.show", "true");
778    }
779 /**
780  * Sets whether the users panel should be visible on connect.
781  * @param b <code>true</code> if users panel should be visible on connect
782  */
783   public void setUsersShow(boolean b) {
784     setPropBooleanValue("cvw.users.show", b);
785    }
786    
787 /**
788  * Returns whether the toolbar panel should be visible on connect.
789  * @return <code>true</code> if toolbar panel should be visible on connect
790  */
791   public boolean getToolbarShow() {
792     return getPropBooleanValue("cvw.toolbar.show", "true");
793    }
794 /**
795  * Sets whether the toolbar panel should be visible on connect.
796  * @param b <code>true</code> if toolbar panel should be visible on connect
797  */
798   public void setToolbarShow(boolean b) {
799     setPropBooleanValue("cvw.toolbar.show", b);
800    }
801    
802 /**
803  * Returns whether the status bar should be visible on connect.
804  * @return <code>true</code> if status bar should be visible on connect
805  */
806   public boolean getStatusBarShow() {
807     return getPropBooleanValue("cvw.statusbar.show", "true");
808    }
809 /**
810  * Sets whether the status bar should be visible on connect.
811  * @param b <code>true</code> if status bar should be visible on connect
812  */
813   public void setStatusBarShow(boolean b) {
814     setPropBooleanValue("cvw.statusbar.show", b);
815    }
816 
817 /**
818  * Returns whether the room contents panel should be visible on connect.
819  * @return <code>true</code> if room contents panel should be visible on connect
820  */
821   public boolean getContentsShow() {
822     return getPropBooleanValue("cvw.contents.show", "true");
823    }
824 /**
825  * Sets whether the room contents panel should be visible on connect.
826  * @param b <code>true</code> if room contents panel should be visible on connect
827  */
828   public void setContentsShow(boolean b) {
829     setPropBooleanValue("cvw.contents.show", b);
830    }
831    
832 /**
833  * Converts the boolean value of a property value which is a string representation.
834  * @param prop the property key
835  * @param def the default boolean string
836  * @return the converted boolean 
837  */
838   private boolean getPropBooleanValue(String prop, String def) {
839   return (new Boolean(prefProps.getProperty(prop, def))).booleanValue();
840    }
841 /**
842  * Sets the property value to the converted boolean string
843  * @param prop the property key
844  * @param b the boolean value to be converted
845  */
846   private void setPropBooleanValue(String prop, boolean b) {
847   prefProps.setProperty(prop, (new Boolean(b)).toString());
848    }
849 
850 /****  proxy window visibile accessor methods *****/   
851 /**
852  * Returns whether the users panel of the proxy window should be visible on connect.
853  * @return <code>true</code> if users panel of the proxy window should be visible 
854  */
855   public boolean getProxyUsersShow() {
856     return getPropBooleanValue("cvw.proxy.users.show", "true");
857    }
858 /**
859  * Sets whether the users panel of the proxy window should be visible on connect.
860  * @param b <code>true</code> if users panel of the proxy window should be visible 
861  */
862   public void setProxyUsersShow(boolean b) {
863     setPropBooleanValue("cvw.proxy.users.show", b);
864    }
865    
866 /**
867  * Returns whether the toolbar panel of the proxy window should be visible on connect.
868  * @return <code>true</code> if toolbar panel of the proxy window should be visible 
869  */
870   public boolean getProxyToolbarShow() {
871     return getPropBooleanValue("cvw.proxy.toolbar.show", "true");
872    }
873 /**
874  * Sets whether the toolbar panel of the proxy window should be visible on connect.
875  * @param b <code>true</code> if toolbar panel of the proxy window should be visible 
876  */
877   public void setProxyToolbarShow(boolean b) {
878     setPropBooleanValue("cvw.proxy.toolbar.show", b);
879    }
880    
881 /**
882  * Returns whether the status bar of the proxy window should be visible on connect.
883  * @return <code>true</code> if status bar of the proxy window should be visible 
884  */
885   public boolean getProxyStatusBarShow() {
886     return getPropBooleanValue("cvw.proxy.statusbar.show", "true");
887    }
888 /**
889  * Sets whether the status bar of the proxy window should be visible on connect.
890  * @param b <code>true</code> if status bar of the proxy window should be visible 
891  */
892   public void setProxyStatusBarShow(boolean b) {
893     setPropBooleanValue("cvw.proxy.statusbar.show", b);
894    }
895    
896 /****  window geometry support methods *****/   
897 /**
898  * Converts a string representing a rectangle to an instance of a rectangle.
899  * The stored format is <code>x.y.w.h</code>
900  * @param prop the property key to look up
901  * @param defaultR the default rectangle incase the property doesnt exist
902  * @return the rectangle store in property values
903  * @see #getStringFromRect
904  */
905   public Rectangle getRectFromProps(String prop, Rectangle defaultR) {
906      String geo = (String)prefProps.getProperty(prop);
907      if (geo == null) {
908        prefProps.setProperty(prop, getStringFromRect(defaultR));
909        return defaultR;
910       }
911      StringTokenizer st = new StringTokenizer(geo, ".");
912      int rx, ry, rw, rh;
913      try {
914        if (st.countTokens() == 4) {
915          rx = Integer.parseInt(st.nextToken());
916          ry = Integer.parseInt(st.nextToken());
917          rw = Integer.parseInt(st.nextToken());
918          rh = Integer.parseInt(st.nextToken());
919          return new Rectangle(rx, ry, rw, rh);
920         }
921      } catch (Exception e) {
922        prefProps.setProperty(prop, getStringFromRect(defaultR));
923      }
924      return defaultR;
925     }
926    
927 /**
928  * Converts a java.awt.Rectangle to a string representation.
929  * The stored format is <code>x.y.w.h</code>
930  * @param r the rectangle to be converted
931  * @return the string with format <code>x.y.w.h</code>
932  */
933    public String getStringFromRect(Rectangle r) {
934       return r.x + "." + r.y + "." + r.width + "." + r.height;
935     }
936 
937 /**
938  * Initializes a hashtable to store the min and max values, mostly for
939  * av tool values.
940  */
941  public void initRangeTable() {
942    rangeTable = new Hashtable(9);
943    Vector v = new Vector(2);
944    v.addElement(new Integer(10));
945    v.addElement(new Integer(videoMaxBandwidth));
946    rangeTable.put("Video Bandwidth", v);
947    
948    v = new Vector(2);
949    v.addElement(new Integer(1));
950    v.addElement(new Integer(30));
951    rangeTable.put("Video Frame Rate", v);
952    
953    v = new Vector(2);
954    v.addElement(new Integer(0));
955    v.addElement(new Integer(260));
956    rangeTable.put("Audio Speaker Volume", v);
957 
958    
959    v = new Vector(2);
960    v.addElement(new Integer(0));
961    v.addElement(new Integer(260));
962    rangeTable.put("Audio Mic Volume", v);
963 
964    
965    v = new Vector(2);
966    v.addElement(new Integer(0));
967    v.addElement(new Integer(127));
968    rangeTable.put("Audio Multicast TTL", v);
969 
970    
971    v = new Vector(2);
972    v.addElement(new Integer(0));
973    v.addElement(new Integer(127));
974    rangeTable.put("Audio Unicast TTL", v);
975 
976    v = new Vector(2);
977    v.addElement(new Integer(0));
978    v.addElement(new Integer(127));
979    rangeTable.put("Video Multicast TTL", v);
980 
981    v = new Vector(2);
982    v.addElement(new Integer(0));
983    v.addElement(new Integer(127));
984    rangeTable.put("Video Unicast TTL", v);
985   }
986 
987 /**
988  * Returns the minimum value given a field name.
989  * @param fieldName the name of the min value desired
990  * @return  the minimum value
991  */
992  public int getMinValue(String fieldName) {
993   Vector v = (Vector) rangeTable.get(fieldName);
994   int min = 0;
995   if (v == null)
996     return min;
997   min = ((Integer)v.elementAt(0)).intValue();
998   return min;
999   }
1000  
1001/**
1002 * Returns the maximum value given a field name.
1003 * @param fieldName the name of the max value desired
1004 * @return  the maximum value
1005 */
1006 public int getMaxValue(String fieldName) {
1007   if (fieldName.equals("Video Bandwidth"))
1008      return videoMaxBandwidth;
1009   Vector v = (Vector) rangeTable.get(fieldName);
1010   int max = 0;
1011   if (v == null)
1012    return max;
1013   max = ((Integer)v.elementAt(1)).intValue();
1014   return max;
1015  }
1016
1017/**
1018 * Checks to see if the given value falls in the numeric range for the
1019 * specified field.
1020 * @param value the value entered by the user
1021 * @param fieldName the name of the field to be checked
1022 * @return <code>true</code> if the value is valid
1023 */
1024 public boolean validRange(int value, String fieldName) {
1025   int min = getMinValue(fieldName);
1026   int max = getMaxValue(fieldName);
1027   //System.err.println(fieldName + " " + min + " " + max);
1028   if (value >= min && value <= max)
1029     return true;
1030   else
1031     return false;
1032  }
1033
1034/* 9/3/97 dage - tried using clone but had to catch exceptions ... how 
1035 *   stupid is that ... it should be a nop to do a copy .. where is smalltalk
1036 *   when you need it
1037 */
1038/**
1039 * Copies the current instance and returns a copy.  
1040 * Note that the preferences stored on the CVW server are instance vars, whereas
1041 * the preferences stored locally are part of a java.util.Properties instance.
1042 * @return  a copy of this CVWPreferences
1043 */
1044  public CVWPreferences copy() {
1045     CVWPreferences newPrefs = new CVWPreferences();
1046     newPrefs.highlightName = this.highlightName;
1047     newPrefs.highlightComm = this.highlightComm;
1048     newPrefs.highlightPubComm = this.highlightPubComm;
1049     
1050     newPrefs.videoMaxBandwidth = this.videoMaxBandwidth;
1051
1052     newPrefs.idleMsg = this.idleMsg;
1053     newPrefs.timeStamp = this.timeStamp;
1054     newPrefs.prefProps = this.prefProps;
1055
1056     newPrefs.hilightObjects = new LinkedList();
1057     for(int i = 0; i < this.hilightObjects.size(); i++) {
1058  HiLightObject obj = (HiLightObject)this.hilightObjects.get(i);
1059  newPrefs.hilightObjects.add(new HiLightObject(obj.objNum, obj.color));
1060      }
1061     
1062     return newPrefs;
1063   }
1064
1065/* 9/2/97 dage - check for null incase all parameters are not sent
1066 * 5/22/98 dage - added prvComm parameter
1067 */
1068/**
1069 * Invoked when the CVW server sends the preferences of the user stored on the server
1070 * <br> MCP receive cvw-preferences
1071 * @param hiName 0 if no name highlighted, otherwise color value 1 - 8
1072 * @param hiComm 0 if no private comms highlighted, otherwise color value 1 - 8
1073 * @param hiPubComm 0 if no public comms highlighted, otherwise color value 1 - 8
1074 * @param hiObjs  list of object number to watch CURRENTLY NOT USED 
1075 * @param hiObjColors list of object numbers to watch CURRENTLY NOT USED 
1076 * @param tStamp 1 if time stamping feature is on, 0 if off
1077 * @param iMsg the idle message of the user
1078 */
1079  public void update(String hiName, String hiComm, String hiPubComm, String hiObjs, String hiObjColors, String tStamp, String iMsg) {
1080    if (hiName != null) 
1081      try { highlightName = Integer.parseInt(hiName); }
1082      catch (NumberFormatException ne) { /* shouldnt happen */ };
1083    if (hiComm != null) 
1084      try { highlightComm = Integer.parseInt(hiComm); }
1085      catch (NumberFormatException ne) { /* shouldnt happen */ };
1086    if (hiPubComm != null) 
1087      try { highlightPubComm = Integer.parseInt(hiPubComm); }
1088      catch (NumberFormatException ne) { /* shouldnt happen */ };
1089    if (tStamp != null) 
1090      timeStamp = (tStamp.equals("1"));
1091    if (iMsg != null) 
1092      idleMsg = iMsg;
1093    StringTokenizer st = new StringTokenizer(hiObjs);
1094    StringTokenizer colorSt = new StringTokenizer(hiObjColors);
1095    int count = st.countTokens();
1096    if (colorSt.countTokens() < count) //shouldnt happen but just in case
1097  count = colorSt.countTokens();
1098    hilightObjects = new LinkedList();
1099    for (int i = 0; i < count; i++) {
1100  HiLightObject hilight = new HiLightObject(st.nextToken(), colorSt.nextToken());
1101  hilightObjects.add(hilight);
1102      }
1103  //will need to process highlight objects
1104    }
1105
1106/**
1107 * Saves the new preferences for the user.
1108 * @param newPrefs the new CVWPreferences
1109 * 
1110 * @see #saveServerPrefs
1111 * @see #saveLocalPrefs
1112 */
1113  public void savePrefs(CVWPreferences newPrefs) { 
1114    saveServerPrefs(newPrefs);
1115    saveLocalPrefs(newPrefs);
1116  }
1117
1118/**
1119 * Sends the new preference values to the CVW server.
1120 * <br> MCP send cvw-preferences-set
1121 * @param newPrefs the new preference values
1122 */
1123  public void saveServerPrefs(CVWPreferences newPrefs) { 
1124     String parms = "";
1125     if (!this.idleMsg.equals(newPrefs.idleMsg)) {
1126   this.idleMsg = newPrefs.idleMsg;
1127  parms = parms + "idle_default_msg: \"" + this.idleMsg + "\" ";
1128      }
1129     if (this.timeStamp != newPrefs.timeStamp) {
1130   this.timeStamp = newPrefs.timeStamp;
1131  String value = "0";
1132  if (this.timeStamp) value = "1";
1133  parms = parms + "time_stamp: " + value + " ";
1134      }
1135     if (this.highlightName != newPrefs.highlightName) {
1136   this.highlightName = newPrefs.highlightName;
1137  parms = parms + "highlight_name: " + this.highlightName + " ";
1138      }
1139     if (this.highlightComm != newPrefs.highlightComm) {
1140   this.highlightComm = newPrefs.highlightComm;
1141  //parms = parms + "highlight_comm: " + this.highlightComm + " ";
1142  parms = parms + "highlight_private_comm: " + this.highlightComm + " ";
1143      }
1144     if (this.highlightPubComm != newPrefs.highlightPubComm) {
1145        this.highlightPubComm = newPrefs.highlightPubComm;
1146        parms = parms + "highlight_public_comm: " + this.highlightPubComm + " ";
1147      }
1148
1149    // 4/30/99 dage - process highlightObjs
1150  String newParmStr = getHiParmString(newPrefs.hilightObjects);
1151  String oldParmStr = getHiParmString(hilightObjects);
1152  if (! newParmStr.equals(oldParmStr))  {
1153    hilightObjects = newPrefs.hilightObjects;
1154          parms += newParmStr;
1155     }
1156
1157     if (parms.trim().length() > 0) 
1158        CVWServerComm.sendMCPCmdToServer("#$#cvw-preferences-set", parms);
1159
1160   }
1161
1162   private String getHiParmString(LinkedList hiObjs) {
1163       HiLightObject hiObj;
1164  String objNums = "";
1165  String colors = "";
1166  for (int i = 0; i < hiObjs.size(); i++) {
1167     hiObj = (HiLightObject)hiObjs.get(i);
1168     objNums += hiObj.objNum + " ";
1169     colors += hiObj.color + " ";
1170         }
1171  return "highlight_objects: \"" + objNums.trim() + 
1172    "\" highlight_objects_colors: \"" + colors.trim() + "\" ";
1173     }
1174
1175  public void debugHiLightObjs() {
1176    int size = hilightObjects.size();
1177    System.err.println("hi light object size:" + size);
1178    for (int i = 0; i < size; i++) {
1179  HiLightObject obj = (HiLightObject)hilightObjects.get(i);
1180  System.err.println(obj.color + " " + obj.objNum);
1181     }
1182   }
1183
1184/**
1185 * Saves the user preferences to the local workstation and points to the new 
1186 * properties as the user preferences.
1187 * @param newPrefs the new instance of CVWPreferences
1188 * @see #writePrefsToFile
1189 */
1190  public void saveLocalPrefs(CVWPreferences newPrefs) { 
1191     this.prefProps = newPrefs.prefProps;
1192     this.writePrefsToFile();
1193   }
1194
1195
1196/**
1197 * Reads the local preferences using the standared load properties method.
1198 */
1199   public void readPrefProperties() {
1200    try {
1201      prefProps.load(new BufferedInputStream(new FileInputStream(prefFile)));
1202    } catch (Exception e) {
1203      System.err.println("Error in loading preferences: " + e);
1204      // not sure we want this message
1205      if (e.getMessage().indexOf("cannot find") < 0) { // access denied is a FileNotFound exception
1206          System.err.println("Potential access denied in loading preferences: " + e.getMessage());
1207      } else {
1208        String masterPref = plugin.getSystemDir("master.cvwprefs");
1209  if (CVWCoordinator.DEBUG) System.err.println("try to copy master pref" + masterPref);
1210      try {
1211    if ((new File(masterPref)).exists()) {
1212      prefProps.load(new BufferedInputStream(new FileInputStream(masterPref)));
1213      writePrefsToFile();  //write it as the pref file
1214     }
1215    else
1216      if (CVWCoordinator.DEBUG) System.err.println("no master prefs file exists");
1217      } catch (Exception ex) {
1218          if (CVWCoordinator.DEBUG) System.err.println("Error in loading preferences: " + ex);
1219  }
1220      }
1221      //        CVWCoordinator.getInstance().displayError(msg, "Preference File Error", false);
1222    }
1223   }
1224   
1225/* 8/12/98 dage - comment out storing values read in into instance vars
1226 */
1227/**
1228 * Reads the older version (Version 3) of the property file and converts it to the
1229 * new format using java.util.Properties.
1230 * @return  <code>false</code> if the conversion was not successful
1231 */
1232  public boolean readV3PrefFromFile() {
1233    String line;
1234    int entries,rc;
1235
1236      if (plugin == null) {
1237  if (CVWCoordinator.DEBUG) System.err.println("plugin not found, cannot read pref file, using defaults");
1238  return false;
1239       }
1240
1241    if(!plugin.fileExists(prefFile)) return false; // No database file at all
1242    if (!this.plugin.openFile(prefFile,0,false))
1243      return false; // Couldn't open database file
1244 
1245    try {
1246      line=plugin.readFileln();
1247      if(line == null) { // Couldn't read the contents; remove & replace
1248  clearPrefFile();
1249        return true;
1250      }
1251    } catch (Exception e) {
1252      // Couldn't read the db file, so close it.
1253      clearPrefFile();
1254      // Return
1255      return true;
1256    }
1257
1258     int value;
1259    //first read line is above
1260    if (!line.equals("3")) { //wrong version
1261        clearPrefFile();
1262        return true;
1263     }
1264     
1265     prefProps.setProperty("cvw.pref.version", "4");
1266
1267// 1/14/98 dage - rather than catching the number exeption after each parseInt
1268//    catch at bottom.
1269    try {
1270     line=plugin.readFileln(); if(line == null) throw new IOException();
1271     prefProps.setProperty("cvw.video.encoding", line);
1272     line=plugin.readFileln(); if(line == null) throw new IOException();
1273        //if (CVWCoordinator.DEBUG) System.err.println("vid bandwidth" + line);
1274        value = Integer.parseInt(line);
1275        prefProps.setProperty("cvw.video.bandwidth", line);
1276    line=plugin.readFileln(); if(line == null) throw new IOException();
1277        //if (CVWCoordinator.DEBUG) System.err.println("vid frame rate" + line);
1278        value = Integer.parseInt(line);
1279        prefProps.setProperty("cvw.video.framerate", line);
1280     line=plugin.readFileln(); if(line == null) throw new IOException();
1281        //if (CVWCoordinator.DEBUG) System.err.println("vid ttl" + line);
1282        value = Integer.parseInt(line);
1283        prefProps.setProperty("cvw.video.TTL.multicast", line);
1284
1285     line=plugin.readFileln(); if(line == null) throw new IOException();
1286       prefProps.setProperty("cvw.audio.encoding", line);
1287     line=plugin.readFileln(); if(line == null) throw new IOException();
1288        //if (CVWCoordinator.DEBUG) System.err.println("aud spkr vol" + line);
1289        value = Integer.parseInt(line);
1290        prefProps.setProperty("cvw.audio.speakerVol", line);
1291     line=plugin.readFileln(); if(line == null) throw new IOException();
1292        //if (CVWCoordinator.DEBUG) System.err.println("aud mike vol" + line);
1293        value = Integer.parseInt(line);
1294        prefProps.setProperty("cvw.audio.micVol", line);
1295     line=plugin.readFileln(); if(line == null) throw new IOException();
1296  //if (CVWCoordinator.DEBUG) System.err.println("aud ttl" + line);
1297  value = Integer.parseInt(line);
1298        prefProps.setProperty("cvw.audio.TTL.multicast", line);
1299    line=plugin.readFileln(); if(line == null) throw new Exception("no size stated");
1300  //if (CVWCoordinator.DEBUG) System.err.println("size " + line);
1301  StringTokenizer st = new StringTokenizer(line);
1302    int x, y, w, h;
1303  if (st.countTokens() == 4) {
1304    x = Integer.parseInt(st.nextToken());
1305    y = Integer.parseInt(st.nextToken());
1306    w = Integer.parseInt(st.nextToken());
1307    h = Integer.parseInt(st.nextToken());
1308    CVWCoordinator.getInstance().setBounds(x, y, w, h);
1309    prefProps.setProperty("cvw.main.geometry", line.replace(' ', '.'));
1310  } 
1311
1312     int rx, ry, rw, rh;
1313     line=plugin.readFileln(); if(line == null) throw new Exception("no vid size stated");
1314        //if (CVWCoordinator.DEBUG) System.err.println("size " + line);
1315        st = new StringTokenizer(line);
1316        if (st.countTokens() == 4) {
1317          rx = Integer.parseInt(st.nextToken());
1318          ry = Integer.parseInt(st.nextToken());
1319          rw = Integer.parseInt(st.nextToken());
1320          rh = Integer.parseInt(st.nextToken());
1321        prefProps.setProperty("cvw.video.geometry", line.replace(' ', '.'));
1322    }
1323
1324     line=plugin.readFileln(); if(line == null) throw new Exception("no aud size stated");
1325        //if (CVWCoordinator.DEBUG) System.err.println("size " + line);
1326        st = new StringTokenizer(line);
1327        if (st.countTokens() == 4) {
1328          rx = Integer.parseInt(st.nextToken());
1329          ry = Integer.parseInt(st.nextToken());
1330          rw = Integer.parseInt(st.nextToken());
1331          rh = Integer.parseInt(st.nextToken());
1332         prefProps.setProperty("cvw.audio.geometry", line.replace(' ', '.'));
1333       }
1334
1335     line=plugin.readFileln(); if(line == null) throw new Exception("no carry size ");
1336        //if (CVWCoordinator.DEBUG) System.err.println("carry " + line);
1337        st = new StringTokenizer(line);
1338        if (st.countTokens() == 4) {