KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2     =========================================================================
3     Package mos - Implements the 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: JMOSPluginPropertiesDlg.java,v 1.10 2007/01/28 17:39:20 popolony2k Exp $
32  * $Author: popolony2k $
33  * $Name: $
34  * $Revision: 1.10 $
35  * $State: Exp $
36  *
37  */

38
39 package org.planetamessenger.mos.forms;
40
41 import org.planetamessenger.mos.engine.*;
42 import org.planetamessenger.plugin.*;
43
44
45 public class JMOSPluginPropertiesDlg extends javax.swing.JDialog JavaDoc {
46
47   private static int WINDOW_WIDTH = 300;
48   private static int WINDOW_HEIGHT = 250;
49
50   private javax.swing.JButton JavaDoc okButton;
51   private javax.swing.JButton JavaDoc cancelButton;
52   private javax.swing.JLabel JavaDoc pluginNameLabel;
53   private javax.swing.JLabel JavaDoc pluginNameContent;
54   private javax.swing.JLabel JavaDoc registeredUserLabel;
55   private javax.swing.JLabel JavaDoc registeredUserContent;
56   private javax.swing.JLabel JavaDoc registeredUserNickLabel;
57   private javax.swing.JTextField JavaDoc registeredUserNickText;
58   private JUserInfo userInfo;
59   JPlugin plugin;
60
61   
62   /**
63    * Constructor. Initializes all class data.
64    * @param parent The parent frame owner of <br>
65    * this dialog;<br>
66    * @param modal Modal dialog flag;<br>
67    * @param nPluginId The PluginId of this property;
68    */

69   public JMOSPluginPropertiesDlg( java.awt.Frame JavaDoc parent, int nPluginId, boolean modal ) {
70     
71     super( parent, modal );
72     plugin = JSharedObjects.getPluginEngine().get( nPluginId );
73     userInfo = org.planetamessenger.mos.engine.JSharedObjects.getProfileManager().getUserInfo( nPluginId );
74     initComponents();
75   }
76
77   /**
78    * Initializes all components from this
79    * window.
80    */

81   private void initComponents() {
82
83     java.awt.GridBagConstraints JavaDoc constraints = new java.awt.GridBagConstraints JavaDoc();
84     javax.swing.Box JavaDoc btnsPanel = javax.swing.Box.createHorizontalBox();
85
86
87     okButton = new javax.swing.JButton JavaDoc();
88     cancelButton = new javax.swing.JButton JavaDoc();
89     pluginNameLabel = new javax.swing.JLabel JavaDoc( JSharedObjects.getLanguageManager().getStringEx( "PLUGIN_NAME" ) );
90     pluginNameContent = new javax.swing.JLabel JavaDoc( "<html><b>" + plugin.getPluginProperties().getName() + "</b></html>" );
91     registeredUserLabel = new javax.swing.JLabel JavaDoc( JSharedObjects.getLanguageManager().getStringEx( "USER" ) );
92     registeredUserContent = new javax.swing.JLabel JavaDoc( "<html><b>" + ( plugin.getUserId() != null ? plugin.getUserId() : JSharedObjects.getLanguageManager().getStringEx( "NONE" ) ) + "</b></html>" );
93     registeredUserNickLabel = new javax.swing.JLabel JavaDoc( JSharedObjects.getLanguageManager().getStringEx( "NICK_NAME" ) );
94     registeredUserNickText = new javax.swing.JTextField JavaDoc( ( plugin.getAliasName() != null ? plugin.getAliasName() : JSharedObjects.getLanguageManager().getStringEx( "NONE" ) ) );
95
96     pluginNameLabel.setFont( JSystemFonts.FONT );
97     pluginNameContent.setFont( JSystemFonts.FONT );
98     registeredUserLabel.setFont( JSystemFonts.FONT );
99     registeredUserContent.setFont( JSystemFonts.FONT );
100     registeredUserNickLabel.setFont( JSystemFonts.FONT );
101
102     setName( "PluginProperties" );
103     setTitle( JSharedObjects.getLanguageManager().getStringEx( "PROPERTIES" ) );
104     setDefaultCloseOperation( javax.swing.WindowConstants.DISPOSE_ON_CLOSE );
105     getContentPane().setLayout( new java.awt.GridBagLayout JavaDoc() );
106     
107     addWindowListener( new java.awt.event.WindowAdapter JavaDoc() {
108       
109       public void windowClosing( java.awt.event.WindowEvent JavaDoc evt ) {
110         closeDialog( evt );
111       }
112     } );
113
114     // Ok button
115
okButton.setFont( JSystemFonts.FONT );
116     okButton.setText( JSharedObjects.getLanguageManager().getStringEx( "OK" ) );
117     okButton.setEnabled( true );
118     okButton.setIcon( JSharedObjects.getResources().getIcon( JResources.OK_BUTTON_ICON ) );
119     okButton.setPreferredSize( new java.awt.Dimension JavaDoc( JResources.DEFAULT_BUTTON_WIDTH, JResources.DEFAULT_BUTTON_HEIGHT ) );
120     okButton.setMinimumSize( okButton.getPreferredSize() );
121     
122     // Ok button action event
123
okButton.addActionListener( new java.awt.event.ActionListener JavaDoc() {
124                                          
125                                       public void actionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
126                                           
127                                         okButtonActionPerformed( evt );
128                                       }
129                                     }
130                                  );
131
132     // Close button
133
cancelButton.setFont( JSystemFonts.FONT );
134     cancelButton.setIcon( JSharedObjects.getResources().getIcon( JResources.CLOSE_BUTTON_ICON ) );
135     cancelButton.setText( JSharedObjects.getLanguageManager().getStringEx( "CANCEL" ) );
136     cancelButton.setPreferredSize( new java.awt.Dimension JavaDoc( JResources.DEFAULT_BUTTON_WIDTH, JResources.DEFAULT_BUTTON_HEIGHT ) );
137     cancelButton.setMinimumSize( cancelButton.getPreferredSize() );
138     
139     // Cancel button action event
140
cancelButton.addActionListener( new java.awt.event.ActionListener JavaDoc() {
141                                          
142                                       public void actionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
143
144                                         closeDialog( null );
145                                       }
146                                     }
147                                  );
148
149
150     // Setup and Add the Plugin name label
151
constraints.gridx = 0;
152     constraints.gridy = 0;
153     constraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
154     constraints.gridheight = 1;
155     constraints.weightx = 0.0001;
156     constraints.weighty = 0.0001;
157     constraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
158     constraints.anchor = java.awt.GridBagConstraints.NORTH;
159     constraints.insets = new java.awt.Insets JavaDoc( 2, 2, 2, 2 );
160     getContentPane().add( pluginNameLabel, constraints );
161
162     // Add Plugin name content label
163
constraints.gridy++;
164     getContentPane().add( pluginNameContent, constraints );
165     
166     // Add Registered user label
167
constraints.gridy++;
168     getContentPane().add( registeredUserLabel, constraints );
169     
170     // Add Registered user content
171
constraints.gridy++;
172     getContentPane().add( registeredUserContent, constraints );
173     
174     // Add Registered user nick label
175
constraints.gridy++;
176     getContentPane().add( registeredUserNickLabel, constraints );
177     
178     // Add Registered user nick text
179
constraints.gridy++;
180     getContentPane().add( registeredUserNickText, constraints );
181
182     // Add ok button
183
btnsPanel.add( javax.swing.Box.createHorizontalGlue() );
184     btnsPanel.add( cancelButton );
185     btnsPanel.add( okButton );
186
187     constraints.gridy++;
188     constraints.gridheight = java.awt.GridBagConstraints.RELATIVE;
189     constraints.anchor = java.awt.GridBagConstraints.SOUTH;
190     constraints.fill = java.awt.GridBagConstraints.CENTER;
191     getContentPane().add( btnsPanel, constraints );
192
193     // Sets the initial dialog position
194
java.awt.Dimension JavaDoc screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
195     setSize( new java.awt.Dimension JavaDoc( WINDOW_WIDTH, WINDOW_HEIGHT ) );
196     setLocation( ( screenSize.width - getSize().width ) / 2, ( screenSize.height - getSize().height ) / 2 );
197     setResizable( true );
198   }
199   
200   /**
201    * Implements the onClick event of Cancel button.<br>
202    * @param evt The button event object;
203    */

204   private void closeDialog( java.awt.event.WindowEvent JavaDoc evt ) {
205
206     setVisible( false );
207     dispose();
208   }
209
210   /**
211    * Implements the onClick event of Ok button.
212    * @param evt The button event object;
213    */

214   private void okButtonActionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
215
216     System.err.println( "JMOSPluginProperties.okButtonActionPerformed() - Triggered" );
217     
218     // Update the plugin properties
219
plugin.setAliasName( registeredUserNickText.getText() );
220     userInfo.setAliasName( registeredUserNickText.getText() );
221     
222     if( JSharedObjects.getProfileManager().userAdd( plugin.getPluginProperties().getPluginId(), userInfo ) ) {
223       plugin.fireOnPluginPropertiesUpdated();
224       closeDialog( null );
225     }
226     else
227       javax.swing.JOptionPane.showMessageDialog( this, JSharedObjects.getLanguageManager().getStringEx( "UPDATE_PROPERTIES_ERROR_WARNING" ), JSharedObjects.getLanguageManager().getStringEx( "ERROR" ), javax.swing.JOptionPane.ERROR_MESSAGE );
228   }
229 }
230
231 // JPluginProperties class
232
Popular Tags