KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > planetamessenger > mos > forms > JMOSProfileManagerDlg


1 /*
2     =========================================================================
3     Package forms - Implements the user interface MOS module
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: JMOSProfileManagerDlg.java,v 1.23 2007/02/23 21:54:23 popolony2k Exp $
32  * $Author: popolony2k $
33  * $Name: $
34  * $Revision: 1.23 $
35  * $State: Exp $
36  *
37  */

38
39 package org.planetamessenger.mos.forms;
40
41 import org.planetamessenger.mos.engine.*;
42 import org.planetamessenger.mos.ui.*;
43
44
45 public class JMOSProfileManagerDlg extends javax.swing.JDialog JavaDoc implements javax.swing.event.TreeSelectionListener JavaDoc {
46
47   private JProfileTree profileTree;
48   private javax.swing.JButton JavaDoc cancelBtn;
49   private javax.swing.JButton JavaDoc okBtn;
50   private javax.swing.JButton JavaDoc removeProfileBtn;
51   private javax.swing.JButton JavaDoc selectProfileBtn;
52   private javax.swing.JButton JavaDoc newProfileBtn;
53   private javax.swing.JButton JavaDoc changeLookAndFeelBtn;
54   private javax.swing.JLabel JavaDoc profileLabel;
55   private javax.swing.JScrollPane JavaDoc profileTreePane;
56
57   
58
59   /**
60    * Create the ProfileManager dialog object.
61    * @param parent The Dialog Parent window;
62    * @param modal Flag for modal style;
63    */

64   public JMOSProfileManagerDlg( java.awt.Frame JavaDoc parent, boolean modal ) {
65   
66     super( parent, modal );
67
68     initComponents();
69   }
70   
71   /**
72    * Perform a window (and childs) refresh.
73    * This method should be called after look
74    * and feel and language switch.<br>
75    */

76   void windowRefresh() {
77
78     javax.swing.SwingUtilities.updateComponentTreeUI( this );
79   }
80
81   /**
82    * Initializes all components from this
83    * window.
84    */

85   private void initComponents() {
86
87     java.awt.GridBagConstraints JavaDoc constraints = new java.awt.GridBagConstraints JavaDoc();
88
89
90     profileLabel = new javax.swing.JLabel JavaDoc();
91     profileTree = new JProfileTree( JSharedObjects.getLanguageManager().getStringEx( "PROFILES" ) );
92     newProfileBtn = new javax.swing.JButton JavaDoc();
93     selectProfileBtn = new javax.swing.JButton JavaDoc();
94     removeProfileBtn = new javax.swing.JButton JavaDoc();
95     okBtn = new javax.swing.JButton JavaDoc();
96     cancelBtn = new javax.swing.JButton JavaDoc();
97     changeLookAndFeelBtn = new javax.swing.JButton JavaDoc();
98     profileTreePane = new javax.swing.JScrollPane JavaDoc( profileTree );
99
100     getContentPane().setLayout( new java.awt.GridBagLayout JavaDoc() );
101
102     setTitle( JSharedObjects.getLanguageManager().getStringEx( "PROFILE_MANAGER" ) );
103     setName( "JMOSProfileManagerDlg" );
104
105     addWindowListener( new java.awt.event.WindowAdapter JavaDoc() {
106
107       public void windowClosing( java.awt.event.WindowEvent JavaDoc evt ) {
108         closeDialog( evt );
109       }
110     } );
111
112     constraints.gridx = 0;
113     constraints.gridy = 0;
114     constraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
115     constraints.gridheight = 1;
116     constraints.weightx = 1.0;
117     constraints.weighty = 0.0;
118     constraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
119     constraints.insets = new java.awt.Insets JavaDoc( 2, 2, 2, 2 );
120    
121     profileLabel.setFont( JSystemFonts.FONT );
122     profileLabel.setText( JSharedObjects.getLanguageManager().getStringEx( "SELECTED_A_PROFILE" ) );
123     getContentPane().add( profileLabel, constraints );
124
125     constraints.gridy++;
126     constraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
127     constraints.gridheight = 9; // Number of buttons
128
constraints.fill = java.awt.GridBagConstraints.BOTH;
129     constraints.weightx = 1.0;
130     constraints.weighty = 1.0;
131     
132     profileTree.addTreeSelectionListener( this );
133     getContentPane().add( profileTreePane, constraints );
134
135     constraints.gridx++;
136     constraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
137     constraints.gridheight = 1;
138     constraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
139     constraints.weightx = 0.0;
140     constraints.weighty = 1.0;
141     
142     newProfileBtn.setFont( JSystemFonts.FONT );
143     newProfileBtn.setText( JSharedObjects.getLanguageManager().getStringEx( "NEW_PROFILE" ) );
144     newProfileBtn.setName("newProfileBtn");
145     newProfileBtn.setIcon( JSharedObjects.getResources().getIcon( JResources.NEW_ICON ) );
146     getContentPane().add( newProfileBtn, constraints );
147     
148     constraints.gridy = java.awt.GridBagConstraints.RELATIVE;
149     
150     changeLookAndFeelBtn.setEnabled( false );
151     changeLookAndFeelBtn.setFont( JSystemFonts.FONT );
152     // TODO: Change Look and Feel icon
153
changeLookAndFeelBtn.setIcon( JSharedObjects.getResources().getIcon( JResources.RELOAD_ICON ) );
154     changeLookAndFeelBtn.setText( JSharedObjects.getLanguageManager().getStringEx( "CHANGE_LOOK_AND_FEEL" ) );
155     getContentPane().add( changeLookAndFeelBtn, constraints );
156
157     selectProfileBtn.setEnabled( false );
158     selectProfileBtn.setFont( JSystemFonts.FONT );
159     selectProfileBtn.setIcon( JSharedObjects.getResources().getIcon( JResources.APPLY_BUTTON_ICON ) );
160     selectProfileBtn.setText( JSharedObjects.getLanguageManager().getStringEx( "ACTIVATE_PROFILE" ) );
161     getContentPane().add( selectProfileBtn, constraints );
162     
163     removeProfileBtn.setEnabled( false );
164     removeProfileBtn.setFont( JSystemFonts.FONT );
165     removeProfileBtn.setIcon( JSharedObjects.getResources().getIcon( JResources.REMOVE_FILE_ICON ) );
166     removeProfileBtn.setText( JSharedObjects.getLanguageManager().getStringEx( "REMOVE_PROFILE" ) );
167     getContentPane().add( removeProfileBtn, constraints );
168
169     okBtn.setFont( JSystemFonts.FONT );
170     okBtn.setText( JSharedObjects.getLanguageManager().getStringEx( "OK" ) );
171     okBtn.setIcon( JSharedObjects.getResources().getIcon( JResources.OK_BUTTON_ICON ) );
172     getContentPane().add( okBtn, constraints );
173
174     cancelBtn.setFont( JSystemFonts.FONT );
175     cancelBtn.setText( JSharedObjects.getLanguageManager().getStringEx( "CANCEL" ) );
176     cancelBtn.setIcon( JSharedObjects.getResources().getIcon( JResources.CLOSE_BUTTON_ICON ) );
177     getContentPane().add( cancelBtn, constraints );
178
179     setSize( JSharedObjects.getConfiguration().getProfileWindowSize() );
180     setLocation( JSharedObjects.getConfiguration().getProfileWindowLocation() );
181     setResizable( true );
182     //pack();
183

184     // Change Look and feel button action event
185
changeLookAndFeelBtn.addActionListener( new java.awt.event.ActionListener JavaDoc() {
186                                          
187                                               public void actionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
188                                           
189                                                 changeLookAndFeelButtonActionPerformed( evt );
190                                               }
191                                             } );
192
193     // New profile button action event
194
newProfileBtn.addActionListener( new java.awt.event.ActionListener JavaDoc() {
195                                          
196                                        public void actionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
197                                           
198                                          newProfileButtonActionPerformed( evt );
199                                        }
200                                      } );
201                                      
202     // Remove profile button action event
203
removeProfileBtn.addActionListener( new java.awt.event.ActionListener JavaDoc() {
204                                          
205                                           public void actionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
206                                           
207                                             removeProfileButtonActionPerformed( evt );
208                                           }
209                                         } );
210
211     // Select profile button action event
212
selectProfileBtn.addActionListener( new java.awt.event.ActionListener JavaDoc() {
213                                          
214                                           public void actionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
215                                           
216                                             selectProfileButtonActionPerformed( evt );
217                                           }
218                                         } );
219                                         
220     // Ok button action event
221
okBtn.addActionListener( new java.awt.event.ActionListener JavaDoc() {
222                                          
223                                public void actionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
224                                          
225                                  okButtonActionPerformed( evt );
226                                }
227                              } );
228                                  
229     // Cancel button action event
230
cancelBtn.addActionListener( new java.awt.event.ActionListener JavaDoc() {
231                                          
232                                    public void actionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
233                                           
234                                      cancelButtonActionPerformed( evt );
235                                    }
236                                  } );
237   }
238
239   /**
240    * Implements the onClick event of change Look And Feel button.
241    * @param evt The button event object;
242    */

243   private void changeLookAndFeelButtonActionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
244
245     System.err.println( "JMOSProfileManagerDlg.changeLookAndFeelButtonActionPerformed() - Triggered" );
246     
247     javax.swing.tree.TreePath JavaDoc selectedPath = profileTree.getSelectionPath();
248     
249     if( selectedPath != null )
250       profileTree.startEditingAtPath( selectedPath );
251   }
252   
253   /**
254    * Implements the onClick event of
255    * New Profile button.
256    * @param evt The button event object;
257    */

258   private void newProfileButtonActionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
259
260     System.err.println( "JMOSProfileManagerDlg.newProfileButtonActionPerformed() - Triggered" );
261     
262     profileTree.addProfile( JSharedObjects.getLanguageManager().getStringEx( "NEW_PROFILE" ) );
263   }
264
265   /**
266    * Implements the onClick event of
267    * Remove Profile button.
268    * @param evt The button event object;
269    */

270   private void removeProfileButtonActionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
271     
272     System.err.println( "JMOSProfileManagerDlg.removeProfileButtonActionPerformed() - Triggered" );
273     
274     JProfileTreeItem selectedProfile = profileTree.getSelectedItem();
275
276     if( selectedProfile != null ) {
277       if( selectedProfile.getItemType() == JProfileTreeItem.TYPE_PROFILE ) {
278         profileTree.removeSelectedItem();
279         return;
280       }
281     }
282
283     javax.swing.JOptionPane.showMessageDialog( this, JSharedObjects.getLanguageManager().getStringEx( "PLEASE_SELECT_PROFILE_WARNING" ), JSharedObjects.getLanguageManager().getStringEx( "INFORMATION" ), javax.swing.JOptionPane.INFORMATION_MESSAGE );
284   }
285
286   /**
287    * Implements the onClick event of
288    * Select Profile button.
289    * @param evt The button event object;
290    */

291   private void selectProfileButtonActionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
292
293     System.err.println( "JMOSProfileManagerDlg.selectProfileButtonActionPerformed() - Triggered" );
294
295     JProfileTreeItem selectedProfile = profileTree.getSelectedItem();
296
297
298     if( selectedProfile != null ) {
299       if( selectedProfile.getItemType() == JProfileTreeItem.TYPE_PROFILE ) {
300         profileTree.setDefaultProfile();
301
302         // TODO: Don't need to restart the application
303
if( JSharedObjects.getProfileManager().getDefaultProfile() != JSharedObjects.getProfileManager().getProfileId() )
304           javax.swing.JOptionPane.showMessageDialog( this, JSharedObjects.getLanguageManager().getStringEx( "PROFILE_ACTIVATION_WARNING" ), JSharedObjects.getLanguageManager().getStringEx( "INFORMATION" ), javax.swing.JOptionPane.INFORMATION_MESSAGE );
305         
306         selectProfileBtn.setEnabled( false );
307         
308         return;
309       }
310     }
311
312     javax.swing.JOptionPane.showMessageDialog( this, JSharedObjects.getLanguageManager().getStringEx( "PLEASE_SELECT_PROFILE_WARNING" ), JSharedObjects.getLanguageManager().getStringEx( "INFORMATION" ), javax.swing.JOptionPane.INFORMATION_MESSAGE );
313   }
314
315   /**
316    * Implements the onClick event of
317    * Ok button.
318    * @param evt The button event object;
319    */

320   private void okButtonActionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
321     
322     JSharedObjects.getConfiguration().setProfileWindowProperties( this.getLocation(), this.getSize() );
323     closeDialog( null );
324   }
325
326   /**
327    * Implements the onClick event of
328    * Cancel button.
329    * @param evt The button event object;
330    */

331   private void cancelButtonActionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
332     
333     JSharedObjects.getConfiguration().setProfileWindowProperties( this.getLocation(), this.getSize() );
334     JSharedObjects.getLookAndFeelManager().loadDefaultLookAndFeel();
335     closeDialog( null );
336   }
337
338   /**
339    * Implements the closeDialog event
340    * handler.
341    * @param evt The close window event object;
342    */

343   private void closeDialog( java.awt.event.WindowEvent JavaDoc evt ) {
344     
345     setVisible( false );
346     dispose();
347   }
348   
349   /**
350    * Implements the valueChanged of TreeSelectionListener
351    * interface.<br>
352    * Enable/disable the dialog buttons depending of tree
353    * item selected;<br>
354    * @param See Jdk docs;
355    */

356   public void valueChanged( javax.swing.event.TreeSelectionEvent JavaDoc treeSelectionEvent ) {
357
358     javax.swing.tree.TreePath JavaDoc path = treeSelectionEvent.getPath();
359     int nPathCount = path.getPathCount();
360     JProfileMutableTreeNode node = ( JProfileMutableTreeNode ) path.getPathComponent( nPathCount - 1 );
361     JProfileTreeItem item = ( JProfileTreeItem ) node.getUserObject();
362
363
364     switch( item.getItemType() ) {
365
366       case JProfileTreeItem.TYPE_PLUGIN : {
367                                              removeProfileBtn.setEnabled( false );
368                                              selectProfileBtn.setEnabled( false );
369                                              changeLookAndFeelBtn.setEnabled( false );
370                                            } break;
371
372       case JProfileTreeItem.TYPE_PROFILE : {
373                                              removeProfileBtn.setEnabled( true );
374                                              
375                                              if( item.getProfileId() == JSharedObjects.getProfileManager().getDefaultProfile() )
376                                                selectProfileBtn.setEnabled( false );
377                                              else
378                                                selectProfileBtn.setEnabled( true );
379                                              
380                                              changeLookAndFeelBtn.setEnabled( false );
381                                            } break;
382       
383       case JProfileTreeItem.TYPE_LOOKNFEEL : {
384                                                 removeProfileBtn.setEnabled( false );
385                                                 selectProfileBtn.setEnabled( false );
386                                                 changeLookAndFeelBtn.setEnabled( true );
387                                               } break;
388
389       default : {
390                                              removeProfileBtn.setEnabled( false );
391                                              selectProfileBtn.setEnabled( false );
392                                              changeLookAndFeelBtn.setEnabled( false );
393                                            } break;
394     }
395   }
396 }
397 // JMOSProfileManagerDlg class
Popular Tags