KickJava   Java API By Example, From Geeks To Geeks.

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


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: JPluginPreferencesManager.java,v 1.14 2007/01/28 17:39:20 popolony2k Exp $
32  * $Author: popolony2k $
33  * $Name: $
34  * $Revision: 1.14 $
35  * $State: Exp $
36  *
37  */

38
39 package org.planetamessenger.mos.engine;
40
41 import java.util.*;
42 import java.awt.*;
43 import javax.swing.*;
44 import org.planetamessenger.mos.forms.*;
45 import org.planetamessenger.plugin.*;
46 import com.jgoodies.forms.builder.*;
47 import com.jgoodies.forms.layout.*;
48 import com.jgoodies.forms.debug.*;
49
50
51
52 public class JPluginPreferencesManager implements JPreferencesListener {
53
54   private HashMap<Integer JavaDoc, JPluginPreferencesContainer> hPropertyPages = null;
55   private JScrollPane scrollPane = null;
56   private FormLayout layout = null;
57   private JLabel panelLabel = null;
58   private JPanel panelInfo = null;
59   private JDataField selectedItem = null;
60
61
62   /**
63    * Constructor. Initialize all preferences class data.
64    */

65   public JPluginPreferencesManager() {
66     
67     hPropertyPages = new HashMap<Integer JavaDoc, JPluginPreferencesContainer>();
68     scrollPane = new JScrollPane();
69     layout = new FormLayout( "fill:pref:grow", "fill:15dlu, fill:pref:grow" );
70     panelLabel = new JLabel();
71     panelInfo = JSharedObjects.getKernelManager().getUserInterfaceManager().createGradientPanel();
72     
73     panelLabel.setOpaque( false );
74     panelLabel.setForeground( Color.WHITE );
75     panelLabel.setFont( JSystemFonts.FONT );
76     panelInfo.setOpaque( true );
77     panelInfo.setBackground( Color.DARK_GRAY );
78     panelInfo.add( panelLabel );
79   }
80
81   /**
82    * Destroy the JPluginPreferencesManager object.
83    */

84   public void destroy() {
85
86     scrollPane.removeAll();
87     hPropertyPages.clear();
88     hPropertyPages = null;
89   }
90   
91   /**
92    * Add a preference container to Preferences manager.
93    * @param nPluginId The plugin id of container to add;
94    * @param container The new container to add;
95    */

96   public boolean add( int nPluginId, JPluginPreferencesContainer container ) {
97     
98     if( container != null ) {
99       hPropertyPages.put( new Integer JavaDoc( nPluginId ), container );
100       return true;
101     }
102     
103     return false;
104   }
105   
106   /**
107    * Remove a preference container from Preferences manager.
108    * @param nPluginId The plugin id of container to remove;
109    */

110   public void remove( int nPluginId ) {
111     
112     hPropertyPages.remove( new Integer JavaDoc( nPluginId ) );
113   }
114   
115   /**
116    * Return the preferences JScrollPane component used
117    * by manager to view preferences configuration options.
118    */

119   public JScrollPane getPreferencesScrollPane() {
120     
121     return scrollPane;
122   }
123   
124   /**
125    * Remove all components from manager scrollPane object.
126    */

127   public void clearScrollPane() {
128     
129     scrollPane.getViewport().removeAll();
130   }
131
132   /**
133    * Fire the onShow event to the plugin.
134    * @param nPluginId The plugin id of plugin owner of this event;
135    * @param field The selected field on manager window;
136    */

137   public void fireOnShow( int nPluginId, JDataField field ) {
138
139     JPluginPreferencesContainer prefs = hPropertyPages.get( new Integer JavaDoc( nPluginId ) );
140
141     if( prefs != null ) {
142
143       CellConstraints cellConst = new CellConstraints();
144       PanelBuilder builder = new PanelBuilder( layout );
145
146       selectedItem = field;
147       panelLabel.setText( "<html><b>" + ( ( ( Integer JavaDoc ) selectedItem.getObject() ).intValue() < 0 ? JSharedObjects.getLanguageManager().getStringEx( selectedItem.getKeyName() ) : selectedItem.toString() ) + "</b></html>" );
148       prefs.onShow();
149
150       builder.setDefaultDialogBorder();
151       builder.add( panelInfo, cellConst.xy( 1, 1 ) );
152       builder.add( prefs, cellConst.xy( 1, 2 ) );
153
154       clearScrollPane();
155       scrollPane.getViewport().add( builder.getPanel() );
156       scrollPane.updateUI();
157     }
158     else {
159       clearScrollPane();
160       scrollPane.updateUI();
161     }
162   }
163
164   /**
165    * Fire the onApply of plugin.
166    */

167   public boolean fireOnApply() {
168     
169     Iterator<JPluginPreferencesContainer> itItem = hPropertyPages.values().iterator();
170     boolean bRet = true;
171
172     while( itItem.hasNext() ) {
173       JPluginPreferencesContainer preferencesContainer = itItem.next();
174
175       try {
176         bRet = preferencesContainer.onApply();
177       } catch( Exception JavaDoc e ) {
178         System.err.println( "JPluginPreferencesManager.fireOnApply() - " + e );
179         bRet = false;
180       }
181     }
182     
183     return bRet;
184   }
185
186   /**
187    * Fire the onCancel event of plugin.
188    */

189   public void fireOnCancel() {
190
191     Iterator<JPluginPreferencesContainer> itItem = hPropertyPages.values().iterator();
192
193     while( itItem.hasNext() ) {
194       JPluginPreferencesContainer preferencesContainer = itItem.next();
195
196       try {
197         preferencesContainer.onCancel();
198       } catch( Exception JavaDoc e ) {
199         System.err.println( "JPluginPreferencesManager.fireOnCancel() - " + e );
200       }
201     }
202   }
203
204   /**
205    * Called by plugin manager when LAF is changed
206    * by user;
207    */

208   public void fireOnLookAndFeelChanged() {
209     
210     Iterator<JPluginPreferencesContainer> itItem = hPropertyPages.values().iterator();
211
212     while( itItem.hasNext() ) {
213       JPluginPreferencesContainer preferencesContainer = itItem.next();
214
215       try {
216         preferencesContainer.onLookAndFeelChanged();
217       } catch( Exception JavaDoc e ) {
218         System.err.println( "JPluginPreferencesManager.fireOnLookAndFeelChanged() - " + e );
219       }
220     }
221   }
222
223   /**
224    * Called by plugin manager when LAF is changed
225    * by user;
226    */

227   public void fireOnLanguageChanged( String JavaDoc strCountryCode ) {
228     
229     Iterator<JPluginPreferencesContainer> itItem = hPropertyPages.values().iterator();
230
231     if( selectedItem != null )
232       panelLabel.setText( "<html><b>" + ( ( ( Integer JavaDoc ) selectedItem.getObject() ).intValue() < 0 ? JSharedObjects.getLanguageManager().getStringEx( selectedItem.getKeyName() ) : selectedItem.toString() ) + "</b></html>" );
233
234     while( itItem.hasNext() ) {
235       JPluginPreferencesContainer preferencesContainer = itItem.next();
236
237       try {
238         preferencesContainer.onLanguageChanged( strCountryCode );
239       } catch( Exception JavaDoc e ) {
240         System.err.println( "JPluginPreferencesManager.fireOnLanguageChanged() - " + e );
241       }
242     }
243   }
244   
245   // Preferences listener implementations
246
/**
247    * Implements the EnableApplyPreferenceManager.
248    * Enable/Disable the Apply button of preference manager;
249    * @param bEnabled The new enabled status for button;
250    */

251   public void EnableApplyPreferencesManager( boolean bEnabled ) {
252
253     JMOSPreferencesDlg preferencesDlg = JSharedObjects.getMainWindow().getPreferencesDialog();
254     
255     if( preferencesDlg != null )
256       preferencesDlg.EnableApply( bEnabled );
257   }
258 }
259
260 // JPluginPreferencesManager class
261
Popular Tags