KickJava   Java API By Example, From Geeks To Geeks.

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


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

38
39 package org.planetamessenger.mos.forms;
40
41 import javax.swing.*;
42 import java.awt.*;
43 import java.awt.event.*;
44 import com.jgoodies.forms.builder.*;
45 import com.jgoodies.forms.layout.*;
46 import com.jgoodies.forms.debug.*;
47 import org.planetamessenger.mos.engine.*;
48
49
50 class JMOSMessageDialog extends JDialog {
51
52   private final int DEFAULT_WIDTH = 430;
53   private final int DEFAULT_HEIGHT = 120;
54
55   public static final int NONE_BUTTON = 0;
56   public static final int YES_BUTTON = 1;
57   public static final int NO_BUTTON = 2;
58
59   private JLabel infoLabel;
60   private JButton okButton;
61   private JButton cancelButton;
62   private int nButtonResult;
63   private String JavaDoc strTitle;
64   private String JavaDoc strMessage;
65
66   
67
68   /**
69    * Constructor. Creates and initializes all
70    * JMOSUnregisterUser class data.
71    * @param plugin The selected plugin to do this
72    * operation;
73    * @param parent The parent frame owner of this dialog;
74    * @param strTitle The dialog title;
75    * @param strMessage The dalg message;
76    * @param modal Modal dialog flag;
77    */

78   public JMOSMessageDialog( JDialog parent, String JavaDoc strTitle, String JavaDoc strMessage, boolean modal ) {
79    
80     super( parent, modal );
81     this.nButtonResult = NONE_BUTTON;
82     this.strTitle = strTitle;
83     this.strMessage = strMessage;
84     initComponents();
85   }
86
87   /**
88    * Initializes all components from this
89    * window.
90    */

91   private void initComponents() {
92
93     FormLayout layout = new FormLayout( "center:pref", "center:pref, center:4dlu, center:4dlu, center:pref" );
94     PanelBuilder builder = new PanelBuilder( layout );
95     CellConstraints cellConst = new CellConstraints();
96     Box btnsPanel = Box.createHorizontalBox();
97     
98     
99     okButton = new JButton();
100     cancelButton = new JButton();
101     infoLabel = new JLabel();
102
103     setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE );
104     getContentPane().setLayout( new GridBagLayout() );
105     setTitle( strTitle );
106
107     infoLabel.setFont( JSystemFonts.FONT );
108     infoLabel.setText( strMessage );
109     getContentPane().add( infoLabel );
110
111     cancelButton.setFont( JSystemFonts.FONT );
112     cancelButton.setIcon( JSharedObjects.getResources().getIcon( JResources.CLOSE_BUTTON_ICON ) );
113     cancelButton.setText( JSharedObjects.getLanguageManager().getStringEx( "NO" ) );
114     cancelButton.setPreferredSize( new Dimension( JResources.DEFAULT_BUTTON_WIDTH, JResources.DEFAULT_BUTTON_HEIGHT ) );
115     getContentPane().add( cancelButton );
116
117     okButton.setFont( JSystemFonts.FONT );
118     okButton.setIcon( JSharedObjects.getResources().getIcon( JResources.OK_BUTTON_ICON ) );
119     okButton.setText( JSharedObjects.getLanguageManager().getStringEx( "YES" ) );
120     okButton.setPreferredSize( new Dimension( JResources.DEFAULT_BUTTON_WIDTH, JResources.DEFAULT_BUTTON_HEIGHT ) );
121     getContentPane().add( okButton );
122
123     // Ok button action event
124
okButton.addActionListener( new ActionListener() {
125                                       public void actionPerformed( ActionEvent evt ) {
126                                         okButtonActionPerformed( evt );
127                                       }
128                                     }
129                                  );
130                                  
131     // Cancel button action event
132
cancelButton.addActionListener( new ActionListener() {
133                                           public void actionPerformed( ActionEvent evt ) {
134                                             cancelButtonActionPerformed( evt );
135                                           }
136                                         }
137                                   );
138
139     btnsPanel.add( Box.createHorizontalGlue() );
140     btnsPanel.add( cancelButton );
141     btnsPanel.add( okButton );
142     
143     builder.setDefaultDialogBorder();
144     builder.add( infoLabel, cellConst.xy( 1, 1 ) );
145     builder.add( btnsPanel, cellConst.xy( 1, 4 ) );
146     
147     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
148     setSize( new Dimension( DEFAULT_WIDTH, DEFAULT_HEIGHT ) );
149     setLocation( ( screenSize.width - getSize().width ) / 2, ( screenSize.height - getSize().height ) / 2 );
150
151     getContentPane().add( builder.getPanel() );
152   }
153
154   /**
155    * Implements the onClick event of
156    * Ok button.
157    * @param evt The button event object;
158    */

159   private void okButtonActionPerformed( ActionEvent evt ) {
160
161     nButtonResult = YES_BUTTON;
162     closeDialog( null );
163   }
164
165   /**
166    * Implements the onClick event of
167    * Cancel button.
168    * @param evt The button event object;
169    */

170   private void cancelButtonActionPerformed( ActionEvent evt ) {
171     
172     nButtonResult = NO_BUTTON;
173     closeDialog( null );
174   }
175
176   /**
177    * Implements the closeDialog event handler.
178    * @param evt The close window event object;
179    */

180   private void closeDialog( WindowEvent evt ) {
181
182     setVisible( false );
183     dispose();
184   }
185   
186   /**
187    * Enable/Disable all dialog controls;
188    * @param bStatus The controls state:
189    * true All will be enabled;
190    * false All will be disabled;
191    */

192   public void setEnabled( boolean bStatus ) {
193   
194     okButton.setEnabled( bStatus );
195     cancelButton.setEnabled( bStatus );
196     super.setEnabled( bStatus );
197   }
198
199   /**
200    * Return the result of latest dialog button operation.
201    */

202   public int getButtonResult() {
203     
204     return nButtonResult;
205   }
206 }
207
208 // JMOSMessageDialog class
Popular Tags