KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > planetamessenger > mos > engine > JConfiguration


1 /*
2     =========================================================================
3     Package engine - Implements the engine package.
4
5     This module is developed and maintained by PlanetaMessenger.org.
6     Specs, New and updated versions can be found in
7     http://www.planetamessenger.org
8     If you want contact the Team please send a email to Project Manager
9     Leidson Campos Alves Ferreira at leidson@planetamessenger.org
10
11     Copyright (C) since 2001 by PlanetaMessenger.org
12
13     This program is free software; you can redistribute it and/or modify
14     it under the terms of the GNU General Public License as published by
15     the Free Software Foundation; either version 2 of the License, or
16     (at your option) any later version.
17
18     This program is distributed in the hope that it will be useful,
19     but WITHOUT ANY WARRANTY; without even the implied warranty of
20     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21     GNU General Public License for more details.
22
23     You should have received a copy of the GNU General Public License
24     along with this program; if not, write to the Free Software
25     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
27     =========================================================================
28 */

29 /**
30  *
31  * $Id: JConfiguration.java,v 1.22 2007/01/28 17:39:20 popolony2k Exp $
32  * $Author: popolony2k $
33  * $Name: $
34  * $Revision: 1.22 $
35  * $State: Exp $
36  *
37  */

38
39 package org.planetamessenger.mos.engine;
40
41 import org.planetamessenger.io.*;
42
43
44 public class JConfiguration {
45
46   public static final int SHARE_CONFIG = 0;
47   public static final int NOSHARE_CONFIG = 1;
48   
49   private static final String JavaDoc SYSTEM_VERSION = "Pentarou 0.3";
50   private static final String JavaDoc PROPERTY_FILE_TITLE = "PlanetaMessenger configuration file";
51   
52   private final int PROP_MAIN_WINDOW = 0;
53   private final int PROP_PROFILE_WINDOW = 1;
54   private final int PROP_PREFERENCES_WINDOW = 2;
55   private final int PM_DEFAULT_WIDTH = 195;
56   private final int PM_DEFAULT_HEIGHT = 365;
57   private final int PROF_DEFAULT_WIDTH = 500;
58   private final int PROF_DEFAULT_HEIGHT = 411;
59   private final int PREF_DEFAULT_WIDTH = 698;
60   private final int PREF_DEFAULT_HEIGHT = 571;
61   private final int PREF_DEFAULT_SPLIT_POS = 167;
62   private final int MAX_REQUIRED_DIR = 7;
63
64   private final String JavaDoc PM_DEFAULT_STATUS = "visible";
65   private final String JavaDoc PROPERTY_DIR = ".planetamessenger";
66   private final String JavaDoc PROPERTY_FILE = ".properties";
67   private final String JavaDoc PM_HOME = "planetamessenger.home";
68   private final String JavaDoc PM_VERSION = "planetamessenger.version";
69   private final String JavaDoc MAIN_WINDOW_X = "mainwindow.x";
70   private final String JavaDoc MAIN_WINDOW_Y = "mainwindow.y";
71   private final String JavaDoc MAIN_WINDOW_W = "mainwindow.width";
72   private final String JavaDoc MAIN_WINDOW_H = "mainwindow.height";
73   private final String JavaDoc MAIN_WINDOW_S = "mainwindow.status";
74   private final String JavaDoc PROFILE_WINDOW_X = "profilewindow.x";
75   private final String JavaDoc PROFILE_WINDOW_Y = "profilewindow.y";
76   private final String JavaDoc PROFILE_WINDOW_W = "profilewindow.width";
77   private final String JavaDoc PROFILE_WINDOW_H = "profilewindow.height";
78   private final String JavaDoc PREFERENCES_WINDOW_X = "preferenceswindow.x";
79   private final String JavaDoc PREFERENCES_WINDOW_Y = "preferenceswindow.y";
80   private final String JavaDoc PREFERENCES_WINDOW_W = "preferenceswindow.width";
81   private final String JavaDoc PREFERENCES_WINDOW_H = "preferenceswindow.height";
82   private final String JavaDoc PREFERENCES_WINDOW_SPLIT_POS = "preferenceswindow.split.position";
83
84
85   static int nMode;
86   String JavaDoc strPath;
87   String JavaDoc strMainWindowStatus;
88   java.awt.Dimension JavaDoc dmMainWindow;
89   java.awt.Point JavaDoc ptMainWindow;
90   java.awt.Dimension JavaDoc dmProfileWindow;
91   java.awt.Point JavaDoc ptProfileWindow;
92   java.awt.Dimension JavaDoc dmPreferencesWindow;
93   java.awt.Point JavaDoc ptPreferencesWindow;
94   int nPreferencesSplitPosition;
95
96
97   /*
98    * Static data initialization.
99    */

100   static {
101     nMode = SHARE_CONFIG;
102   }
103
104   
105   /**
106    * Initializes all configuration
107    * class data.
108    */

109   public JConfiguration() {
110
111     java.awt.Dimension JavaDoc screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
112     java.util.Properties JavaDoc properties = new java.util.Properties JavaDoc();
113     String JavaDoc strHomeDir = ( nMode == SHARE_CONFIG ? JClassPath.getCurrentDirectory() + JClassPath.getFileSeparator() + ".." : JClassPath.getUserHomeDirectory() );
114     String JavaDoc strCurrentDir = strHomeDir + JClassPath.getFileSeparator();
115     String JavaDoc strPMDir = strCurrentDir + PROPERTY_DIR;
116     java.io.File JavaDoc dir = new java.io.File JavaDoc( strPMDir );
117     java.io.File JavaDoc propertyFile = new java.io.File JavaDoc( strPMDir + JClassPath.getFileSeparator() + PROPERTY_FILE );
118     boolean bAutoConfig = true;
119
120
121     dmMainWindow = new java.awt.Dimension JavaDoc( PM_DEFAULT_WIDTH, PM_DEFAULT_HEIGHT );
122     ptMainWindow = new java.awt.Point JavaDoc( 0, 0 );
123     dmProfileWindow = new java.awt.Dimension JavaDoc( PROF_DEFAULT_WIDTH, PROF_DEFAULT_HEIGHT );
124     ptProfileWindow = new java.awt.Point JavaDoc( ( ( screenSize.width - PROF_DEFAULT_WIDTH ) / 2 ), ( ( screenSize.height - PROF_DEFAULT_HEIGHT ) / 2 ) );
125     dmPreferencesWindow = new java.awt.Dimension JavaDoc( PREF_DEFAULT_WIDTH, PREF_DEFAULT_HEIGHT );
126     ptPreferencesWindow = new java.awt.Point JavaDoc( ( ( screenSize.width - PREF_DEFAULT_WIDTH ) / 2 ), ( ( screenSize.height - PREF_DEFAULT_HEIGHT ) / 2 ) );
127
128     while( true ) {
129       if( !dir.exists() || !propertyFile.exists() || !bAutoConfig ) {
130         int nDlgResult;
131         boolean bHomeIsOk = false;
132
133
134         do {
135
136           // Automatic config has failed ????
137
if( !bAutoConfig ) {
138             javax.swing.JFileChooser JavaDoc dlg = new javax.swing.JFileChooser JavaDoc();
139
140
141             dlg.setDialogTitle( "PlanetaMessenger home directory" );
142             dlg.setMultiSelectionEnabled( false );
143             dlg.setFileSelectionMode( javax.swing.JFileChooser.DIRECTORIES_ONLY );
144
145             javax.swing.JOptionPane.showMessageDialog( null, "Please to continue you must select the home directory where PlanetaMessenger was installed", "Information", javax.swing.JOptionPane.INFORMATION_MESSAGE );
146             nDlgResult = dlg.showOpenDialog( null );
147
148             if( dlg.getSelectedFile() != null )
149               strCurrentDir = dlg.getSelectedFile().getPath() + JClassPath.getFileSeparator();
150             else
151               strCurrentDir = null;
152           }
153           else
154             nDlgResult = javax.swing.JFileChooser.APPROVE_OPTION;
155
156           if( strCurrentDir != null ) {
157             // Verify if the selected dir is the HOME of PM
158
java.lang.String JavaDoc[] strDirs;
159             java.io.File JavaDoc dirList = new java.io.File JavaDoc( strCurrentDir );
160
161
162             strDirs = dirList.list();
163
164             if( strDirs != null ) {
165               if( strDirs.length >= MAX_REQUIRED_DIR ) {
166
167                 int nDirFound = 0;
168
169                 for( int nCount = 0; nCount < strDirs.length; nCount++ ) {
170                   /*
171                    * Don't forget !!! The number of directories required @see MAX_REQUIRED_DIR
172                    * MUST be increased if you add a new required directory to this list.
173                    */

174                   if( ( strDirs[nCount].compareToIgnoreCase( "lib" ) == 0 ) ||
175                       ( strDirs[nCount].compareToIgnoreCase( "bin" ) == 0 ) ||
176                       ( strDirs[nCount].compareToIgnoreCase( "plugins" ) == 0 ) ||
177                       ( strDirs[nCount].compareToIgnoreCase( "resources" ) == 0 ) ||
178                       ( strDirs[nCount].compareToIgnoreCase( "plaf" ) == 0 ) ||
179                       ( strDirs[nCount].compareToIgnoreCase( "languages" ) == 0 ) ||
180                       ( strDirs[nCount].compareToIgnoreCase( "db" ) == 0 ) )
181                     nDirFound++;
182                 }
183
184                 if( nDirFound == MAX_REQUIRED_DIR ) {
185                   dir.mkdir();
186                   strPath = strCurrentDir;
187                   // General settings
188
properties.setProperty( PM_HOME, strPath );
189                   properties.setProperty( PM_VERSION, SYSTEM_VERSION );
190
191                   // Main window setup
192
properties.setProperty( MAIN_WINDOW_X, "0" );
193                   properties.setProperty( MAIN_WINDOW_Y, "0" );
194                   properties.setProperty( MAIN_WINDOW_W, Integer.toString( PM_DEFAULT_WIDTH ) );
195                   properties.setProperty( MAIN_WINDOW_H, Integer.toString( PM_DEFAULT_HEIGHT ) );
196                   properties.setProperty( MAIN_WINDOW_S, PM_DEFAULT_STATUS );
197                   strMainWindowStatus = PM_DEFAULT_STATUS;
198
199                   // Profile window setup
200
properties.setProperty( PROFILE_WINDOW_X, Integer.toString( ptProfileWindow.x ) );
201                   properties.setProperty( PROFILE_WINDOW_Y, Integer.toString( ptProfileWindow.y ) );
202                   properties.setProperty( PROFILE_WINDOW_W, Integer.toString( PROF_DEFAULT_WIDTH ) );
203                   properties.setProperty( PROFILE_WINDOW_H, Integer.toString( PROF_DEFAULT_HEIGHT ) );
204
205                   // Preferences window setup
206
nPreferencesSplitPosition = PREF_DEFAULT_SPLIT_POS;
207                   properties.setProperty( PREFERENCES_WINDOW_X, Integer.toString( ptPreferencesWindow.x ) );
208                   properties.setProperty( PREFERENCES_WINDOW_Y, Integer.toString( ptPreferencesWindow.y ) );
209                   properties.setProperty( PREFERENCES_WINDOW_W, Integer.toString( PREF_DEFAULT_WIDTH ) );
210                   properties.setProperty( PREFERENCES_WINDOW_H, Integer.toString( PREF_DEFAULT_HEIGHT ) );
211                   properties.setProperty( PREFERENCES_WINDOW_SPLIT_POS, Integer.toString( nPreferencesSplitPosition ) );
212
213                   try {
214                     java.io.FileOutputStream JavaDoc out = new java.io.FileOutputStream JavaDoc( dir.getPath() + JClassPath.getFileSeparator() + PROPERTY_FILE );
215
216                     properties.store( out, PROPERTY_FILE_TITLE );
217                     nDlgResult = javax.swing.JFileChooser.APPROVE_OPTION;
218                     bHomeIsOk = true;
219                   } catch( java.io.IOException JavaDoc e ) {
220                     System.err.println( "JConfiguration.JConfiguration() - Exception " + e );
221                   }
222                 }else{
223                   System.err.println("JConfiguration.JConfiguration() - Expected number of directories ("+MAX_REQUIRED_DIR+") was not found.");
224                 }
225               }
226             }
227           }
228
229           if( !bHomeIsOk && nDlgResult == javax.swing.JFileChooser.APPROVE_OPTION ) {
230             javax.swing.JOptionPane.showMessageDialog( null, "Unable to continue ! You MUST select the home directory that PlanetaMessenger is installed", "Error", javax.swing.JOptionPane.ERROR_MESSAGE );
231             nDlgResult = javax.swing.JFileChooser.CANCEL_OPTION;
232           }
233           else
234             if( !bHomeIsOk ) {
235               javax.swing.JOptionPane.showMessageDialog( null, "The PlanetaMessenger Home directory could not be found. Shutting down.", "Error", javax.swing.JOptionPane.ERROR_MESSAGE );
236               System.err.println( "JConfiguration.JConfiguration() - Fatal, the PM Home directory cannot be configured" );
237               System.exit( 0 );
238             }
239
240           bAutoConfig = false;
241
242         } while( nDlgResult != javax.swing.JFileChooser.APPROVE_OPTION );
243         
244         return;
245       }
246       else {
247         try {
248           java.io.FileInputStream JavaDoc in = new java.io.FileInputStream JavaDoc( dir.getPath() + JClassPath.getFileSeparator() + PROPERTY_FILE );
249           String JavaDoc strVersion;
250
251           properties.load( in );
252           strPath = properties.getProperty( PM_HOME );
253
254           try {
255             // Main window setup
256
ptMainWindow.x = Integer.parseInt( properties.getProperty( MAIN_WINDOW_X, "0" ) );
257             ptMainWindow.y = Integer.parseInt( properties.getProperty( MAIN_WINDOW_Y, "0" ) );
258             dmMainWindow.width = Integer.parseInt( properties.getProperty( MAIN_WINDOW_W, Integer.toString( PM_DEFAULT_WIDTH ) ) );
259             dmMainWindow.height = Integer.parseInt( properties.getProperty( MAIN_WINDOW_H, Integer.toString( PM_DEFAULT_HEIGHT ) ) );
260
261             // Profile window setup
262
screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
263
264             ptProfileWindow.x = Integer.parseInt( properties.getProperty( PROFILE_WINDOW_X, Integer.toString( ( screenSize.width - PROF_DEFAULT_WIDTH ) / 2 ) ) );
265             ptProfileWindow.y = Integer.parseInt( properties.getProperty( PROFILE_WINDOW_Y, Integer.toString( ( screenSize.height - PROF_DEFAULT_HEIGHT ) / 2 ) ) );
266             dmProfileWindow.width = Integer.parseInt( properties.getProperty( PROFILE_WINDOW_W ) );
267             dmProfileWindow.height = Integer.parseInt( properties.getProperty( PROFILE_WINDOW_H ) );
268
269             // Preferences window setup
270
ptPreferencesWindow.x = Integer.parseInt( properties.getProperty( PREFERENCES_WINDOW_X, Integer.toString( ( screenSize.width - PREF_DEFAULT_WIDTH ) / 2 ) ) );
271             ptPreferencesWindow.y = Integer.parseInt( properties.getProperty( PREFERENCES_WINDOW_Y, Integer.toString( ( screenSize.height - PREF_DEFAULT_HEIGHT ) / 2 ) ) );
272             dmPreferencesWindow.width = Integer.parseInt( properties.getProperty( PREFERENCES_WINDOW_W ) );
273             dmPreferencesWindow.height = Integer.parseInt( properties.getProperty( PREFERENCES_WINDOW_H ) );
274             nPreferencesSplitPosition = Integer.parseInt( properties.getProperty( PREFERENCES_WINDOW_SPLIT_POS ) );
275
276           } catch( NumberFormatException JavaDoc e ) {
277             System.err.println( "JConfiguration.JConfiguration() - " + e );
278           }
279
280           strMainWindowStatus = properties.getProperty( MAIN_WINDOW_S, PM_DEFAULT_STATUS );
281           strVersion = properties.getProperty( PM_VERSION );
282
283           /*
284            * If is the same release, we'll delete property file
285            * and recreate the property file again.
286            */

287           if( strVersion.compareTo( SYSTEM_VERSION ) != 0 ) {
288             propertyFile.delete();
289             propertyFile = null;
290             dir = null;
291             dir = new java.io.File JavaDoc( strPMDir );
292             propertyFile = new java.io.File JavaDoc( strPMDir + JClassPath.getFileSeparator() + PROPERTY_FILE );
293             bAutoConfig = false;
294             properties.clear();
295             
296             continue;
297           }
298         } catch( java.io.IOException JavaDoc e ) {
299           System.err.println( "JConfiguration.JConfiguration() - Exception " + e );
300           propertyFile = null;
301           dir = null;
302           dir = new java.io.File JavaDoc( strPMDir );
303           propertyFile = new java.io.File JavaDoc( strPMDir + JClassPath.getFileSeparator() + PROPERTY_FILE );
304           bAutoConfig = false;
305           properties.clear();
306         }
307         
308         break;
309       }
310     }
311   }
312
313   /**
314    * Set the operation mode for config system.
315    * @param nMode The new mode for configuration
316    * scheme. The possible values are:<br>
317    * SHARE_CONFIG - All users share the same<br>
318    * .properties file in PlanetaMessenger's bin<br>
319    * directory;<br>
320    * NOSHARE_CONFIG - Each user has your own
321    * .properties file in home (eg. UNIX $HOME)<br>
322    * directory;
323    */

324   static public void setMode( int nMode ) {
325     
326     JConfiguration.nMode = nMode;
327   }
328
329   /**
330    * Gets the Plugins path.
331    */

332   public java.lang.String JavaDoc getPluginsPath() {
333     
334     return strPath + "plugins" + JClassPath.getFileSeparator();
335   }
336
337   /**
338    * Gets the Library path.
339    */

340   public java.lang.String JavaDoc getLibPath() {
341     
342     return strPath + "lib" + JClassPath.getFileSeparator();
343   }
344
345   /**
346    * Gets the Plugin Dependent Libraries path.
347    */

348   public java.lang.String JavaDoc getDepLibPath() {
349     
350     return getPluginsPath() + "deplib" + JClassPath.getFileSeparator();
351   }
352
353   /**
354    * Gets the resources path.
355    */

356   public java.lang.String JavaDoc getResourcesPath() {
357     
358     return strPath + "resources" + JClassPath.getFileSeparator();
359   }
360
361   /**
362    * Get the Look and Feel path.
363    */

364   public java.lang.String JavaDoc getLookAndFeelPath() {
365     
366     return strPath + "plaf" + JClassPath.getFileSeparator();
367   }
368   
369   /**
370    * Get the Languages path.
371    */

372   public java.lang.String JavaDoc getLanguagesPath() {
373     
374     return strPath + "languages" + JClassPath.getFileSeparator();
375   }
376   
377   /**
378    * Get the bin path.
379    */

380   public java.lang.String JavaDoc getBinPath() {
381    
382     return strPath + "bin" + JClassPath.getFileSeparator();
383   }
384
385   /**
386    * Gets the database name.
387    */

388   public java.lang.String JavaDoc getDatabaseName() {
389     
390     return strPath + "db" + JClassPath.getFileSeparator() + "planetamessenger";
391   }
392
393   /**
394    * Returns the main window location.
395    */

396   public java.awt.Point JavaDoc getMainWindowLocation() {
397     
398     return ptMainWindow;
399   }
400
401   /**
402    * Returns the main window size.
403    */

404   public java.awt.Dimension JavaDoc getMainWindowSize() {
405     
406     return dmMainWindow;
407   }
408
409   /**
410    * Returns the Main window status.
411    */

412   public boolean getMainWindowStatus() {
413     
414     if( strMainWindowStatus.compareTo( PM_DEFAULT_STATUS ) == 0 )
415       return true;
416     else
417       return false;
418   }
419
420   /**
421    * Set the main window location
422    * and size, storing in the property
423    * file and memory;
424    * @param ptWindow Main window position;
425    * @param dmWndow MainWindow size;
426    * @param bWindowStatus The window status flag:
427    * true - Visible;
428    * false - Hidden;
429    */

430   public void setMainWindowProperties( java.awt.Point JavaDoc ptWindow, java.awt.Dimension JavaDoc dmWindow, boolean bWindowStatus ) {
431    
432     setWindowProperties( ptWindow, dmWindow, bWindowStatus, PROP_MAIN_WINDOW );
433   }
434
435   /**
436    * Returns the profile window location.
437    */

438   public java.awt.Point JavaDoc getProfileWindowLocation() {
439     
440     return ptProfileWindow;
441   }
442
443   /**
444    * Returns the profile window size.
445    */

446   public java.awt.Dimension JavaDoc getProfileWindowSize() {
447     
448     return dmProfileWindow;
449   }
450
451   /**
452    * Set the profile window location
453    * and size, storing in the property
454    * file and memory;
455    * @param ptWindow window position;
456    * @param ptDimentsion window size;
457    */

458   public void setProfileWindowProperties( java.awt.Point JavaDoc ptWindow, java.awt.Dimension JavaDoc dmWindow ) {
459
460     setWindowProperties( ptWindow, dmWindow, true, PROP_PROFILE_WINDOW );
461   }
462
463   /**
464    * Returns the preferences window location.
465    */

466   public java.awt.Point JavaDoc getPreferencesWindowLocation() {
467     
468     return ptPreferencesWindow;
469   }
470
471   /**
472    * Returns the protocol window size.
473    */

474   public java.awt.Dimension JavaDoc getPreferencesWindowSize() {
475    
476     return dmPreferencesWindow;
477   }
478
479   /**
480    * Return the preferences window splitter position.
481    */

482   public int getPreferencesSplitPosition() {
483     
484     return nPreferencesSplitPosition;
485   }
486
487   /**
488    * Set the profile window location
489    * and size, storing in the property
490    * file and memory;
491    * @param ptWindow window position;
492    * @param dmDimentsion window size;
493    */

494   public void setPreferencesWindowProperties( java.awt.Point JavaDoc ptWindow, java.awt.Dimension JavaDoc dmWindow ) {
495
496     setWindowProperties( ptWindow, dmWindow, true, PROP_PREFERENCES_WINDOW );
497   }
498   
499   /**
500    * Set the preferences window split position.
501    * @param nPreferencesSplitPosition The new preferences window position;
502    */

503   public void setPreferencesSplitPosition( int nPreferencesSplitPosition ) {
504     
505     this.nPreferencesSplitPosition = nPreferencesSplitPosition;
506   }
507   
508   // private methods
509
/**
510    * Set the main window location
511    * and size, storing in the property
512    * file and memory;
513    * @param ptWindow Window position;
514    * @param dmWndow Window size;
515    * @param bWindowStatus The window status flag:
516    * true - Visible;
517    * false - Hidden;
518    * @param nWindowType Type of window;
519    */

520   private void setWindowProperties( java.awt.Point JavaDoc ptWindow, java.awt.Dimension JavaDoc dmWindow, boolean bWindowStatus, int nWindowType ) {
521
522     // Only save if a default profile was defined
523
if( JSharedObjects.getProfileManager().getDefaultProfile() == -1 )
524       return;
525
526     try {
527       String JavaDoc strPropNameX;
528       String JavaDoc strPropNameY;
529       String JavaDoc strPropNameW;
530       String JavaDoc strPropNameH;
531       int nDefPropW;
532       int nDefPropH;
533       java.util.Properties JavaDoc properties = new java.util.Properties JavaDoc();
534       String JavaDoc strHomeDir = ( nMode == SHARE_CONFIG ? JClassPath.getCurrentDirectory() + JClassPath.getFileSeparator() + ".." : JClassPath.getUserHomeDirectory() );
535       String JavaDoc strPropFile = strHomeDir + JClassPath.getFileSeparator() + PROPERTY_DIR + JClassPath.getFileSeparator() + PROPERTY_FILE;
536       java.io.FileInputStream JavaDoc in = new java.io.FileInputStream JavaDoc( strPropFile );
537       java.io.FileOutputStream JavaDoc out;
538       
539       properties.load( in );
540       in.close();
541       
542       switch( nWindowType ) {
543         
544         case PROP_MAIN_WINDOW : {
545           strPropNameX = MAIN_WINDOW_X;
546           strPropNameY = MAIN_WINDOW_Y;
547           strPropNameW = MAIN_WINDOW_W;
548           strPropNameH = MAIN_WINDOW_H;
549           nDefPropW = PM_DEFAULT_WIDTH;
550           nDefPropH = PM_DEFAULT_WIDTH;
551           ptMainWindow = ptWindow;
552           dmMainWindow = dmWindow;
553           
554           if( bWindowStatus )
555             strMainWindowStatus = PM_DEFAULT_STATUS;
556           else
557             strMainWindowStatus = "hidden";
558
559           properties.setProperty( MAIN_WINDOW_S, ( ( dmWindow.width == 0 || dmWindow.height == 0 ) ? PM_DEFAULT_STATUS : strMainWindowStatus ) );
560         } break;
561         
562         case PROP_PROFILE_WINDOW : {
563           strPropNameX = PROFILE_WINDOW_X;
564           strPropNameY = PROFILE_WINDOW_Y;
565           strPropNameW = PROFILE_WINDOW_W;
566           strPropNameH = PROFILE_WINDOW_H;
567           nDefPropW = PROF_DEFAULT_WIDTH;
568           nDefPropH = PROF_DEFAULT_WIDTH;
569           ptProfileWindow = ptWindow;
570           dmProfileWindow = dmWindow;
571         } break;
572         
573         case PROP_PREFERENCES_WINDOW : {
574           strPropNameX = PREFERENCES_WINDOW_X;
575           strPropNameY = PREFERENCES_WINDOW_Y;
576           strPropNameW = PREFERENCES_WINDOW_W;
577           strPropNameH = PREFERENCES_WINDOW_H;
578           nDefPropW = PREF_DEFAULT_WIDTH;
579           nDefPropH = PREF_DEFAULT_WIDTH;
580           ptPreferencesWindow = ptWindow;
581           dmPreferencesWindow = dmWindow;
582           properties.setProperty( PREFERENCES_WINDOW_SPLIT_POS, Integer.toString( nPreferencesSplitPosition ) );
583         } break;
584         
585         default : return;
586       }
587       
588       out = new java.io.FileOutputStream JavaDoc( strPropFile );
589       properties.setProperty( strPropNameX, Integer.toString( ptWindow.x ) );
590       properties.setProperty( strPropNameY, Integer.toString( ptWindow.y ) );
591       properties.setProperty( strPropNameW, Integer.toString( ( dmWindow.width == 0 ? nDefPropW : dmWindow.width ) ) );
592       properties.setProperty( strPropNameH, Integer.toString( ( dmWindow.height == 0 ? nDefPropH : dmWindow.height ) ) );
593
594       properties.store( out, "PlanetaMessenger configuration file" );
595       out.close();
596       
597     } catch( java.io.IOException JavaDoc e ) {
598       System.err.println( "JConfiguration.setWindowProperties() - " + e );
599     }
600   }
601 }
602 // JConfiguration class
Popular Tags