KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > planetamessenger > mos > forms > preferences > JYesNoPanel


1 /*
2     =========================================================================
3     Package preferences - Preferences management panels.
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: JYesNoPanel.java,v 1.6 2007/01/28 17:39:20 popolony2k Exp $
32  * $Author: popolony2k $
33  * $Name: $
34  * $Revision: 1.6 $
35  * $State: Exp $
36  *
37  */

38
39 package org.planetamessenger.mos.forms.preferences;
40
41 import java.awt.*;
42 import java.awt.event.*;
43 import javax.swing.*;
44 import javax.swing.tree.*;
45 import javax.swing.event.*;
46 import javax.swing.text.*;
47 import javax.swing.text.html.*;
48 import java.util.*;
49 import javax.swing.event.*;
50 import javax.swing.border.*;
51 import com.jgoodies.forms.builder.*;
52 import com.jgoodies.forms.layout.*;
53 import com.jgoodies.forms.debug.*;
54 import org.planetamessenger.mos.engine.*;
55 import org.planetamessenger.mos.ui.*;
56 import org.planetamessenger.plugin.*;
57 import org.planetamessenger.ui.*;
58
59
60 public class JYesNoPanel extends JPluginPreferencesContainer {
61
62   public static final int YES_BUTTON = 0;
63   public static final int NO_BUTTON = 1;
64   
65   private FormLayout layout = null;
66   private PanelBuilder builder = null;
67   private String JavaDoc strCaption = null;
68   private JLabel caption = null;
69   private JButton yesButton = null;
70   private JButton noButton = null;
71   private ArrayList<ActionListener> listener = null;
72   
73   
74   /**
75    * Constructor. Initialize all class data.
76    * @param strCaption The caption for this panel;
77    */

78   public JYesNoPanel( String JavaDoc strCaption ) {
79
80     super();
81
82     CellConstraints cellConst = new CellConstraints();
83     Box btnsPanel = Box.createHorizontalBox();
84     
85     
86     this.listener = new ArrayList<ActionListener>();
87     this.yesButton = new JButton();
88     this.noButton = new JButton();
89     this.caption = new JLabel();
90     this.layout = new FormLayout( "center:250dlu", "center:pref, center:pref" );
91     this.builder = new PanelBuilder( layout );
92     this.strCaption = strCaption;
93     
94     caption.setOpaque( false );
95     caption.setFont( JSystemFonts.FONT );
96     
97     yesButton.setPreferredSize( new Dimension( JResources.DEFAULT_BUTTON_WIDTH, JResources.DEFAULT_BUTTON_HEIGHT ) );
98     yesButton.setMinimumSize( yesButton.getPreferredSize() );
99     yesButton.setIcon( JSharedObjects.getResources().getIcon( JResources.OK_BUTTON_ICON ) );
100     yesButton.addActionListener( new ActionListener() {
101                                        public void actionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
102                                          fireOnButtonAction( YES_BUTTON );
103                                        }
104                                      } );
105
106     noButton.setPreferredSize( new Dimension( JResources.DEFAULT_BUTTON_WIDTH, JResources.DEFAULT_BUTTON_HEIGHT ) );
107     noButton.setMinimumSize( noButton.getPreferredSize() );
108     noButton.setIcon( JSharedObjects.getResources().getIcon( JResources.CLOSE_BUTTON_ICON ) );
109     noButton.addActionListener( new ActionListener() {
110                                       public void actionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
111                                         fireOnButtonAction( NO_BUTTON );
112                                       }
113                                     } );
114     
115     btnsPanel.add( javax.swing.Box.createHorizontalGlue() );
116     btnsPanel.add( noButton );
117     btnsPanel.add( yesButton );
118     
119     builder.setDefaultDialogBorder();
120     builder.add( caption, cellConst.xy( 1, 1 ) );
121     builder.add( btnsPanel, cellConst.xy( 1, 2 ) );
122   }
123   
124   /**
125    * Dispatch the event through button event listeners.
126    * @param nButton The button owner of this event.
127    * Values:
128    * YES_BUTTON - The Yes button was pressed;
129    * NO_BUTTON - The No button was pressed;
130    */

131   private void fireOnButtonAction( int nButton ) {
132     
133     ArrayList<ActionListener> cloneListener = ( ArrayList<ActionListener> ) listener.clone();
134     JButton button = ( nButton == YES_BUTTON ? yesButton : noButton );
135     ActionEvent evt = new ActionEvent( button, nButton, button.toString() );
136     
137     for( int nCount = 0; nCount < cloneListener.size(); nCount++ )
138       cloneListener.get( nCount ).actionPerformed( evt );
139   }
140   
141   /**
142    * Add a event listener to ok button of Yes No Panel.
143    * @param listener The event listener to add;
144    */

145   public void addEventListener( ActionListener listener ) {
146     
147     this.listener.add( listener );
148   }
149   
150   /**
151    * Remove a event listener to ok button of Yes No Panel.
152    * @param listener The event listener to remove;
153    */

154   public void removeEventListener( ActionListener listener ) {
155     
156     this.listener.remove( listener );
157   }
158
159   /**
160    * Initialize the component's panel to show on
161    * preferences window.
162    */

163   public void onShow() {
164
165     if( getComponentCount() == 0 )
166       add( builder.getPanel() );
167   }
168
169   /**
170    * Called when Apply/Ok button is triggered.
171    * Store the new configuration to PM database.
172    */

173   public boolean onApply() {
174
175     return true;
176   }
177   
178   /**
179    * Called when cancel button is triggered.
180    */

181   public void onCancel() {
182
183   }
184   
185   /**
186    * Called by plugin manager when LAF is changed
187    * by user;
188    */

189   public void onLookAndFeelChanged() {
190
191     javax.swing.SwingUtilities.updateComponentTreeUI( this );
192   }
193   
194   /**
195    * Called by plugin manager when LAF is changed
196    * by user;
197    */

198   public void onLanguageChanged( String JavaDoc strCountryCode ) {
199
200     caption.setText( JSharedObjects.getLanguageManager().getStringEx( strCaption ) );
201     yesButton.setText( JSharedObjects.getLanguageManager().getStringEx( "YES" ) );
202     noButton.setText( JSharedObjects.getLanguageManager().getStringEx( "NO" ) );
203   }
204 }
205
206 // JYesNoPanel class
207
Popular Tags