KickJava   Java API By Example, From Geeks To Geeks.

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


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

38
39 package org.planetamessenger.mos.forms;
40
41 import org.planetamessenger.mos.engine.*;
42
43
44
45 class JMOSAddInviteDlg extends javax.swing.JDialog JavaDoc {
46
47   private static int WINDOW_WIDTH = 250;
48   private static int WINDOW_HEIGHT = 160;
49
50   private javax.swing.JTextField JavaDoc userIdText = null;
51   private javax.swing.JButton JavaDoc addButton = null;
52   private javax.swing.JButton JavaDoc cancelButton = null;
53   private javax.swing.JLabel JavaDoc userIdLabel = null;
54   private javax.swing.JLabel JavaDoc protocolLabel = null;
55   private javax.swing.JComboBox JavaDoc protocolCombo = null;
56
57
58
59   /**
60    * Constructor. Initializes all class
61    * data.
62    * @param parent The parent frame owner
63    * of this dialog;
64    * @param modal Modal dialog flag;
65    */

66   public JMOSAddInviteDlg( java.awt.Frame JavaDoc parent, boolean modal ) {
67     
68     super( parent, modal );
69     initComponents();
70   }
71
72   /**
73    * Initializes all components from this
74    * window.
75    */

76   private void initComponents() {
77
78     java.awt.GridBagConstraints JavaDoc constraints = new java.awt.GridBagConstraints JavaDoc();
79     javax.swing.Box JavaDoc btnsPanel = javax.swing.Box.createHorizontalBox();
80     
81     
82     addButton = new javax.swing.JButton JavaDoc();
83     cancelButton = new javax.swing.JButton JavaDoc();
84     userIdText = new javax.swing.JTextField JavaDoc();
85     userIdLabel = new javax.swing.JLabel JavaDoc();
86     protocolLabel = new javax.swing.JLabel JavaDoc();
87     protocolCombo = new javax.swing.JComboBox JavaDoc();
88
89
90     setDefaultCloseOperation( javax.swing.JFrame.DO_NOTHING_ON_CLOSE );
91     getContentPane().setLayout( new java.awt.GridBagLayout JavaDoc() );
92     setTitle( JSharedObjects.getLanguageManager().getStringEx( "ADD_INVITE_USER" ) );
93
94     constraints.gridx = 0;
95     constraints.gridy = 0;
96     constraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
97     constraints.gridheight = 1;
98     constraints.weightx = 0.001;
99     constraints.weighty = 0.001;
100     constraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
101     constraints.insets = new java.awt.Insets JavaDoc( 1, 1, 1, 1 );
102     //constraints.anchor = java.awt.GridBagConstraints.WEST;
103

104     // Protocol label initializations
105
protocolLabel.setFont( JSystemFonts.FONT );
106     protocolLabel.setText( JSharedObjects.getLanguageManager().getStringEx( "SELECT_NETWORK" ) );
107     protocolLabel.setPreferredSize( new java.awt.Dimension JavaDoc( 120, 17 ) );
108     getContentPane().add( protocolLabel, constraints );
109
110     constraints.gridy++;
111     constraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
112
113     // Protocol Combo initializations
114
protocolCombo.setPreferredSize( new java.awt.Dimension JavaDoc( 120, 21 ) );
115     protocolCombo.setModel( new javax.swing.DefaultComboBoxModel JavaDoc() );
116     protocolCombo.setFont( JSystemFonts.FONT );
117     fillProtocolCombo();
118     getContentPane().add( protocolCombo, constraints );
119     
120     // Userid Label initializations
121
constraints.gridy++;
122     userIdLabel.setFont( JSystemFonts.FONT );
123     userIdLabel.setText( JSharedObjects.getLanguageManager().getStringEx( "USER" ) );
124     userIdLabel.setPreferredSize( new java.awt.Dimension JavaDoc( 120, 17 ) );
125     getContentPane().add( userIdLabel, constraints );
126     
127     // TextField initializations
128
constraints.gridy++;
129     userIdText.addKeyListener( new java.awt.event.KeyAdapter JavaDoc() {
130       public void keyReleased( java.awt.event.KeyEvent JavaDoc keyEvt ) {
131         if( userIdText.getText().length() > 0 )
132           addButton.setEnabled( true );
133         else
134           addButton.setEnabled( false );
135       }
136     } );
137     userIdText.setFont( JSystemFonts.FONT );
138     userIdText.setText( "" );
139     userIdText.setPreferredSize( new java.awt.Dimension JavaDoc( 110, 21 ) );
140     getContentPane().add( userIdText, constraints );
141
142     // Ok Button
143
addButton.setFont( JSystemFonts.FONT );
144     addButton.setIcon( JSharedObjects.getResources().getIcon( JResources.OK_BUTTON_ICON ) );
145     addButton.setText( JSharedObjects.getLanguageManager().getStringEx( "ADD" ) );
146     addButton.setEnabled( false );
147     addButton.setPreferredSize( new java.awt.Dimension JavaDoc( JResources.DEFAULT_BUTTON_WIDTH, JResources.DEFAULT_BUTTON_HEIGHT ) );
148     addButton.setMinimumSize( addButton.getPreferredSize() );
149
150     // Close button
151
cancelButton.setFont( JSystemFonts.FONT );
152     cancelButton.setIcon( JSharedObjects.getResources().getIcon( JResources.CLOSE_BUTTON_ICON ) );
153     cancelButton.setText( JSharedObjects.getLanguageManager().getStringEx( "CANCEL" ) );
154     cancelButton.setPreferredSize( new java.awt.Dimension JavaDoc( JResources.DEFAULT_BUTTON_WIDTH, JResources.DEFAULT_BUTTON_HEIGHT ) );
155     cancelButton.setMinimumSize( cancelButton.getPreferredSize() );
156
157     btnsPanel.add( javax.swing.Box.createHorizontalGlue() );
158     btnsPanel.add( cancelButton );
159     btnsPanel.add( addButton );
160     
161     constraints.gridy++;
162     constraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
163     constraints.gridheight = java.awt.GridBagConstraints.RELATIVE;
164     constraints.fill = java.awt.GridBagConstraints.CENTER;
165     constraints.weighty = 0.01;
166     
167     getContentPane().add( btnsPanel, constraints );
168
169     setResizable( true );
170     java.awt.Dimension JavaDoc screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
171     setSize( new java.awt.Dimension JavaDoc( WINDOW_WIDTH, WINDOW_HEIGHT ) );
172     setLocation( ( screenSize.width - getSize().width ) / 2, ( screenSize.height - getSize().height ) / 2 );
173     
174     // Ok button action event
175
addButton.addActionListener( new java.awt.event.ActionListener JavaDoc() {
176                                          
177                                       public void actionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
178                                         addButtonActionPerformed( evt );
179                                       }
180                                     }
181                                  );
182                                  
183     // Cancel button action event
184
cancelButton.addActionListener( new java.awt.event.ActionListener JavaDoc() {
185                                          
186                                           public void actionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
187                                             cancelButtonActionPerformed( evt );
188                                           }
189                                         }
190                                   );
191   }
192
193   /**
194    * Implements the onClick event of
195    * Add button.
196    * @param evt The button event object;
197    */

198   private void addButtonActionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
199
200     org.planetamessenger.plugin.JPlugin plugin = ( org.planetamessenger.plugin.JPlugin ) protocolCombo.getModel().getSelectedItem();
201     
202     
203     if( !plugin.isConnected() ) {
204       System.err.println( "JMOSAddInviteDlg.addButtonActionPerformed() - Plugin is not connected. Nothing to do" );
205
206       javax.swing.JOptionPane.showMessageDialog( this,
207                                                  JSharedObjects.getLanguageManager().getStringEx( "DISCONNECTED_PLUGIN_WARNING" ),
208                                                  JSharedObjects.getLanguageManager().getStringEx( "INFORMATION" ), javax.swing.JOptionPane.INFORMATION_MESSAGE );
209       return;
210     }
211
212     try {
213       if( JSharedObjects.getContactListManager().getContactList( plugin ).containsKey( userIdText.getText().trim() ) ) {
214         javax.swing.JOptionPane.showMessageDialog( this, JSharedObjects.getLanguageManager().getStringEx( "USER_ALREADY_IN_CONTACT_LIST_WARNING" ), JSharedObjects.getLanguageManager().getStringEx( "INFORMATION" ), javax.swing.JOptionPane.INFORMATION_MESSAGE );
215       }
216       else {
217         plugin.fireOnAddUserToContactList( userIdText.getText() );
218         closeDialog( null );
219       }
220     } catch( java.lang.Exception JavaDoc ex ) {
221       System.err.println( "JMOSAddInviteDialog.addButtonActionPerformed() - " + ex );
222     }
223   }
224
225   /**
226    * Implements the onClick event of
227    * Cancel button.
228    * @param evt The button event object;
229    */

230   private void cancelButtonActionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
231     
232     closeDialog( null );
233   }
234
235   /**
236    * Implements the closeDialog event
237    * handler.
238    * @param evt The close window event object;
239    */

240   private void closeDialog( java.awt.event.WindowEvent JavaDoc evt ) {
241     
242     setVisible( false );
243     dispose();
244   }
245   
246   /**
247    * Fill the protocolCombo with all
248    * available plugins for this profile.
249    */

250   private void fillProtocolCombo() {
251     
252     // Load all Plugins into ComboBox
253
org.planetamessenger.plugin.JPlugin[] allPlugins = org.planetamessenger.mos.engine.JSharedObjects.getPluginEngine().toArray();
254     
255     if( allPlugins != null )
256       for( int nCount = 0; nCount < allPlugins.length; nCount++ )
257         if( org.planetamessenger.mos.engine.JSharedObjects.getProfileManager().checkForPluginUser( allPlugins[nCount].getPluginProperties().getPluginId() ) )
258           ( ( javax.swing.DefaultComboBoxModel JavaDoc ) protocolCombo.getModel() ).addElement( allPlugins[nCount] );
259   }
260 }
261
262 // JMOSAddInviteDialog Class
Popular Tags