KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > planetamessenger > mos > ui > JAccountsTableModel


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

38
39 package org.planetamessenger.mos.ui;
40
41 import javax.swing.*;
42 import java.util.*;
43 import org.planetamessenger.plugin.*;
44 import org.planetamessenger.mos.engine.*;
45
46
47 public class JAccountsTableModel extends javax.swing.table.DefaultTableModel JavaDoc implements java.awt.event.ItemListener JavaDoc {
48   
49   JAccountsTable tableOwner = null;
50
51   
52   /**
53    * Constructs a accounts table
54    * model.
55    * @param owner The table owner;
56    */

57   public JAccountsTableModel( JAccountsTable owner ) {
58     
59     super();
60     
61     tableOwner = owner;
62   }
63
64   /**
65    * Add a table row based on
66    * parameter plugin.
67    * @param plugin The plugin to add;
68    */

69   public void addRow( JPlugin plugin ) {
70
71     Vector<JComponent> vColumns = new Vector<JComponent>();
72     JPluginComboBox statusCombo = new JPluginComboBox( plugin );
73     JStatusComboItem statusItem = null;
74     JPluginCheckBox autoConnectCheck = new JPluginCheckBox( plugin, JPluginCheckBox.AUTO_CONNECT );
75     JPluginCheckBox connectionCheck = new JPluginCheckBox( plugin, JPluginCheckBox.RECONNECT );
76     JLabel accountLabel = new JLabel( plugin.getPluginProperties().getName() );
77     JUserInfo userInfo = JSharedObjects.getProfileManager().getUserInfo( plugin.getPluginProperties().getPluginId() );
78
79
80     // Status combo initialization
81
statusCombo.setFont( JSystemFonts.FONT );
82     statusCombo.addItemListener( this );
83     
84     if( plugin.getAllPluginStatus().containsValue( new JPlanetaMessengerStatus( JPlugin.STATUS_ONLINE ) ) ) {
85       statusItem = new JStatusComboItem( JSharedObjects.getLanguageManager().getStringEx( "ONLINE" ), JPlugin.STATUS_ONLINE );
86
87       statusCombo.addItem( statusItem );
88       
89       if( userInfo.getLoginStatus() == statusItem.getStatus() )
90         statusCombo.setSelectedItem( statusItem );
91     }
92     
93     if( plugin.getAllPluginStatus().containsValue( new JPlanetaMessengerStatus( JPlugin.STATUS_FREE_CHAT ) ) ) {
94       statusItem = new JStatusComboItem( JSharedObjects.getLanguageManager().getStringEx( "FREE_FOR_CHAT" ), JPlugin.STATUS_FREE_CHAT );
95
96       statusCombo.addItem( statusItem );
97       
98       if( userInfo.getLoginStatus() == statusItem.getStatus() )
99         statusCombo.setSelectedItem( statusItem );
100     }
101     
102     if( plugin.getAllPluginStatus().containsValue( new JPlanetaMessengerStatus( JPlugin.STATUS_INVISIBLE ) ) ) {
103       statusItem = new JStatusComboItem( JSharedObjects.getLanguageManager().getStringEx( "INVISIBLE" ), JPlugin.STATUS_INVISIBLE );
104       
105       statusCombo.addItem( statusItem );
106       
107       if( userInfo.getLoginStatus() == statusItem.getStatus() )
108         statusCombo.setSelectedItem( statusItem );
109     }
110     
111     if( plugin.getAllPluginStatus().containsValue( new JPlanetaMessengerStatus( JPlugin.STATUS_AWAY ) ) ) {
112       statusItem = new JStatusComboItem( JSharedObjects.getLanguageManager().getStringEx( "AWAY" ), JPlugin.STATUS_AWAY );
113
114       statusCombo.addItem( statusItem );
115       
116       if( userInfo.getLoginStatus() == statusItem.getStatus() )
117         statusCombo.setSelectedItem( statusItem );
118     }
119     
120     if( plugin.getAllPluginStatus().containsValue( new JPlanetaMessengerStatus( JPlugin.STATUS_BUSY ) ) ) {
121       statusItem = new JStatusComboItem( JSharedObjects.getLanguageManager().getStringEx( "BUSY" ), JPlugin.STATUS_BUSY );
122
123       statusCombo.addItem( statusItem );
124       
125       if( userInfo.getLoginStatus() == statusItem.getStatus() )
126         statusCombo.setSelectedItem( statusItem );
127     }
128     
129     if( plugin.getAllPluginStatus().containsValue( new JPlanetaMessengerStatus( JPlugin.STATUS_IDLE ) ) ) {
130       statusItem = new JStatusComboItem( JSharedObjects.getLanguageManager().getStringEx( "IDLE" ), JPlugin.STATUS_IDLE );
131
132       statusCombo.addItem( statusItem );
133       
134       if( userInfo.getLoginStatus() == statusItem.getStatus() )
135         statusCombo.setSelectedItem( statusItem );
136     }
137     
138     if( plugin.getAllPluginStatus().containsValue( new JPlanetaMessengerStatus( JPlugin.STATUS_DND ) ) ) {
139       statusItem = new JStatusComboItem( JSharedObjects.getLanguageManager().getStringEx( "DO_NOT_DISTURB" ), JPlugin.STATUS_DND );
140
141       statusCombo.addItem( statusItem );
142       
143       if( userInfo.getLoginStatus() == statusItem.getStatus() )
144         statusCombo.setSelectedItem( statusItem );
145     }
146     
147     if( plugin.getAllPluginStatus().containsValue( new JPlanetaMessengerStatus( JPlugin.STATUS_ON_PHONE ) ) ) {
148       statusItem = new JStatusComboItem( JSharedObjects.getLanguageManager().getStringEx( "ON_PHONE" ), JPlugin.STATUS_ON_PHONE );
149
150       statusCombo.addItem( statusItem );
151       
152       if( userInfo.getLoginStatus() == statusItem.getStatus() )
153         statusCombo.setSelectedItem( statusItem );
154     }
155     
156     if( plugin.getAllPluginStatus().containsValue( new JPlanetaMessengerStatus( JPlugin.STATUS_ON_LUNCH ) ) ) {
157       statusItem = new JStatusComboItem( JSharedObjects.getLanguageManager().getStringEx( "ON_LUNCH" ), JPlugin.STATUS_ON_LUNCH );
158
159       statusCombo.addItem( statusItem );
160       
161       if( userInfo.getLoginStatus() == statusItem.getStatus() )
162         statusCombo.setSelectedItem( statusItem );
163     }
164     
165     if( plugin.getAllPluginStatus().containsValue( new JPlanetaMessengerStatus( JPlugin.STATUS_NOT_AT_HOME ) ) ) {
166       statusItem = new JStatusComboItem( JSharedObjects.getLanguageManager().getStringEx( "NOT_AT_HOME" ), JPlugin.STATUS_NOT_AT_HOME );
167
168       statusCombo.addItem( statusItem );
169       
170       if( userInfo.getLoginStatus() == statusItem.getStatus() )
171         statusCombo.setSelectedItem( statusItem );
172     }
173     
174     if( plugin.getAllPluginStatus().containsValue( new JPlanetaMessengerStatus( JPlugin.STATUS_NOT_IN_OFFICE ) ) ) {
175       statusItem = new JStatusComboItem( JSharedObjects.getLanguageManager().getStringEx( "NOT_IN_OFFICE" ), JPlugin.STATUS_NOT_IN_OFFICE );
176
177       statusCombo.addItem( statusItem );
178       
179       if( userInfo.getLoginStatus() == statusItem.getStatus() )
180         statusCombo.setSelectedItem( statusItem );
181     }
182     
183     if( plugin.getAllPluginStatus().containsValue( new JPlanetaMessengerStatus( JPlugin.STATUS_NOT_AT_DESK ) ) ) {
184       statusItem = new JStatusComboItem( JSharedObjects.getLanguageManager().getStringEx( "NOT_AT_DESK" ), JPlugin.STATUS_NOT_AT_DESK );
185
186       statusCombo.addItem( statusItem );
187       
188       if( userInfo.getLoginStatus() == statusItem.getStatus() )
189         statusCombo.setSelectedItem( statusItem );
190     }
191     
192     if( plugin.getAllPluginStatus().containsValue( new JPlanetaMessengerStatus( JPlugin.STATUS_ON_VACATION ) ) ) {
193       statusItem = new JStatusComboItem( JSharedObjects.getLanguageManager().getStringEx( "ON_VACATION" ), JPlugin.STATUS_ON_VACATION );
194
195       statusCombo.addItem( statusItem );
196       
197       if( userInfo.getLoginStatus() == statusItem.getStatus() )
198         statusCombo.setSelectedItem( statusItem );
199     }
200     
201     // AutoConnection CheckBox initialization
202
autoConnectCheck.addItemListener( this );
203     autoConnectCheck.setToolTipText( JSharedObjects.getLanguageManager().getStringEx( "ENABLE_DISABLE_AUTO_LOGIN" ) );
204     
205     // Connection CheckBox initialization
206
connectionCheck.getModel().setSelected( plugin.isConnected() );
207     connectionCheck.addItemListener( this );
208     connectionCheck.setToolTipText( JSharedObjects.getLanguageManager().getStringEx( "RECONNECT_PLUGIN" ) );
209
210     // Account Label initialization
211
accountLabel.setFont( JSystemFonts.FONT );
212     accountLabel.setToolTipText( plugin.getPluginProperties().getName() );
213       
214     if( userInfo != null ) {
215       if( userInfo.getAutoConnect() == 0 )
216         autoConnectCheck.getModel().setSelected( false );
217       else
218         autoConnectCheck.getModel().setSelected( true );
219     }
220     else
221       autoConnectCheck.getModel().setSelected( false );
222
223     /*
224      * #Becarefull 001. If you change columns order in JAccountsTable class
225      * don't forget change here.
226      */

227     vColumns.add( statusCombo );
228     vColumns.add( connectionCheck );
229     vColumns.add( autoConnectCheck );
230     vColumns.add( accountLabel );
231     
232     this.addRow( vColumns );
233   }
234
235   /**
236    * Remove a table row based from
237    * parameter plugin.
238    * @param plugin The plugin to remove;
239    */

240   public void removeRow( JPlugin plugin ) {
241
242     JPluginComboBox statusCombo;
243     java.util.Vector JavaDoc vData = this.getDataVector();
244
245     
246     // Search for plugin in table model
247
for( int nCount = 0; nCount < vData.size(); nCount++ ) {
248       
249       statusCombo = ( ( JPluginComboBox ) ( ( java.util.Vector JavaDoc ) vData.get( nCount ) ).get( JAccountsTable.STATUS_INDEX ) );
250       
251       if( statusCombo.getPlugin().getPluginProperties().getPluginId() == plugin.getPluginProperties().getPluginId() ) {
252         super.removeRow( nCount );
253         break;
254       }
255     }
256   }
257
258   /**
259    * Change the plugin status in plugin status
260    * table.
261    * @param plugin The plugin that status will be
262    * changed;
263    * @param nNewStatus The new plugin status;
264    */

265   public void changeStatus( JPlugin plugin, int nNewStatus ) {
266    
267     java.util.Vector JavaDoc vData = this.getDataVector();
268     JPluginComboBox statusCombo = null;
269     
270     
271     // Search for plugin in table model
272
for( int nCount = 0; nCount < vData.size(); nCount++ ) {
273       
274       statusCombo = ( ( JPluginComboBox ) ( ( java.util.Vector JavaDoc ) vData.get( nCount ) ).get( JAccountsTable.STATUS_INDEX ) );
275       
276       if( statusCombo.getPlugin().getPluginProperties().getPluginId() == plugin.getPluginProperties().getPluginId() ) {
277       
278         JStatusComboItem statusItem = null;
279       
280         // Search for status to select
281
for( int nItemCount = 0; nItemCount < statusCombo.getItemCount(); nItemCount++ ) {
282           statusItem = ( JStatusComboItem ) statusCombo.getItemAt( nItemCount );
283           
284           if( statusItem.getStatus() == nNewStatus )
285             statusCombo.setSelectedItem( statusItem );
286         }
287         
288         break;
289       }
290     }
291   }
292
293   /**
294    * Change the plugin connection status in plugin connection status
295    * table.
296    * @param plugin The plugin that status will be changed;
297    * @param nStatus The new plugin connection status.
298    * The valid values:
299    * Connecting - JPluginEngineListener.CONNECTING;
300    * Connected - JPluginEngineListener.CONNECTED;
301    * attempting connection - JPluginEngineListener.CONNECTING
302    *
303    */

304   public void changeConnectionStatus( JPlugin plugin, int nStatus ) {
305
306     Vector vData = ( Vector ) this.getDataVector().clone();
307     JPluginCheckBox connectionCheck = null;
308     JPluginCheckBox autoConnectCheck = null;
309     JPluginComboBox statusCombo = null;
310
311     
312     // Search for plugin in table model
313
for( int nCount = 0; nCount < vData.size(); nCount++ ) {
314
315       statusCombo = ( ( JPluginComboBox ) ( ( Vector ) vData.get( nCount ) ).get( JAccountsTable.STATUS_INDEX ) );
316       connectionCheck = ( ( JPluginCheckBox ) ( ( Vector ) vData.get( nCount ) ).get( JAccountsTable.CONNECTION_INDEX ) );
317       autoConnectCheck = ( ( JPluginCheckBox ) ( ( Vector ) vData.get( nCount ) ).get( JAccountsTable.AUTOCONNECT_INDEX ) );
318
319       if( connectionCheck.getPlugin().getPluginProperties().getPluginId() == plugin.getPluginProperties().getPluginId() ) {
320         
321         if( nStatus != org.planetamessenger.plugin.JPluginEngineListener.CONNECTING ) {
322
323           if( nStatus == org.planetamessenger.plugin.JPluginEngineListener.DISCONNECTED )
324             connectionCheck.getModel().setSelected( false );
325           else {
326             connectionCheck.setEnabled( true );
327             connectionCheck.getModel().setSelected( true );
328             connectionCheck.addItemListener( this );
329           }
330           
331           autoConnectCheck.setEnabled( true );
332           statusCombo.setEnabled( true );
333         
334           if( nStatus == org.planetamessenger.plugin.JPluginEngineListener.DISCONNECTED ) {
335             
336             /**
337              * Need to check if the same listener is
338              * already added to this checkBox.
339              */

340             boolean bExist = false;
341             
342             for( int nItems = 0; nItems < connectionCheck.getListeners( java.awt.event.ItemListener JavaDoc.class ).length; nItems++ )
343               if( connectionCheck.getListeners( java.awt.event.ItemListener JavaDoc.class )[nItems] == this ) {
344                 bExist = true;
345                 break;
346               }
347            
348             connectionCheck.setEnabled( true );
349             
350             if( !bExist )
351               connectionCheck.addItemListener( this );
352           }
353         }
354         else {
355           EventObject evt = new EventObject( tableOwner );
356
357           connectionCheck.removeItemListener( this );
358           connectionCheck.setEnabled( false );
359           statusCombo.setEnabled( false );
360           autoConnectCheck.setEnabled( false );
361         }
362         
363         break;
364       }
365     }
366   }
367
368   /**
369    * Overrides the default getColumnClass.
370    * @param see JDK docs;
371    */

372   public java.lang.Class JavaDoc getColumnClass( int nColumnIndex ) {
373    
374     return getValueAt( 0, nColumnIndex ).getClass();
375   }
376   
377   // Listeners implementation
378
/**
379    * Implements the java.awt.event.ItemListener
380    * event handler;
381    * This method change the plugin status in
382    * PM database;
383    * @param see jdk docs;
384    */

385   public void itemStateChanged( java.awt.event.ItemEvent JavaDoc itemEvent ) {
386    
387     // Process CheckBoxes events only
388
if( ( tableOwner.getSelectedRow() >= 0 ) && ( itemEvent.getSource() instanceof JPluginCheckBox ) ) {
389       short nAutoConnect;
390       int nPluginId = ( ( JPluginCheckBox ) itemEvent.getSource() ).getPlugin().getPluginProperties().getPluginId();
391       JUserInfo userInfo = JSharedObjects.getProfileManager().getUserInfo( nPluginId );
392       JPluginCheckBox check = ( JPluginCheckBox ) itemEvent.getSource();
393
394
395       // Autoconnect check
396
if( check.getType() == JPluginCheckBox.AUTO_CONNECT ) {
397         if( check.isSelected() )
398           nAutoConnect = 1;
399         else
400           nAutoConnect = 0;
401
402         // Update the autoconnect status in PlanetaMessenger.org database
403
if( userInfo.getAutoConnect() != nAutoConnect ) {
404           userInfo.setAutoconnect( nAutoConnect );
405           org.planetamessenger.mos.engine.JSharedObjects.getProfileManager().userAdd( nPluginId, userInfo );
406         }
407       }
408       else { // Reconnect check
409
if( !check.getPlugin().isConnected() && check.isSelected() ) {
410           try {
411             check.getPlugin().fireOnLogin();
412           } catch( java.lang.Exception JavaDoc ex ) {
413             System.err.println( "JAccountsTableModel.itemStateChanged() - " + ex );
414           }
415         }
416         else // Logout
417
if( !check.isSelected() ) {
418             try {
419               check.getPlugin().fireOnLogout();
420             } catch( java.lang.Exception JavaDoc ex ) {
421               System.err.println( "JAccountsTableModel.itemStateChanged() - " + ex );
422             }
423           }
424       }
425       
426       return;
427     }
428
429     // Process ComboBoxes events only
430
if( ( tableOwner.getSelectedRow() >= 0 ) && ( itemEvent.getStateChange() != java.awt.event.ItemEvent.DESELECTED ) ) {
431       JStatusComboItem item = ( JStatusComboItem ) itemEvent.getItem();
432       JPlugin plugin = ( ( JPluginComboBox ) itemEvent.getSource() ).getPlugin();
433       int nPluginId = plugin.getPluginProperties().getPluginId();
434       JUserInfo userInfo = JSharedObjects.getProfileManager().getUserInfo( nPluginId );
435     
436       if( nPluginId == -1 )
437         return;
438       
439       // Throws plugin event onPluginStatusChanged() only if plugin is connected
440
if( plugin.isConnected() )
441         try {
442           plugin.fireOnPluginStatusChanged( item.getStatus() );
443         } catch( java.lang.Exception JavaDoc e ) {
444           System.err.println( "JAccountsTableModel.itemStateChanged() - " + e );
445         }
446
447       userInfo.setLoginStatus( item.getStatus() );
448       org.planetamessenger.mos.engine.JSharedObjects.getProfileManager().userAdd( nPluginId, userInfo );
449     }
450   }
451   
452   /**
453    * Update the language for entire table model.
454    */

455   void updateLanguage() {
456
457     java.util.Vector JavaDoc vData = ( java.util.Vector JavaDoc ) this.getDataVector().clone();
458     JPluginCheckBox connectionCheck = null;
459     JPluginCheckBox autoConnectCheck = null;
460     JPluginComboBox statusCombo = null;
461     JStatusComboItem statusItem = null;
462
463     
464     // Search for plugin in table model
465
for( int nCount = 0; nCount < vData.size(); nCount++ ) {
466
467       statusCombo = ( ( JPluginComboBox ) ( ( java.util.Vector JavaDoc ) vData.get( nCount ) ).get( JAccountsTable.STATUS_INDEX ) );
468       connectionCheck = ( ( JPluginCheckBox ) ( ( java.util.Vector JavaDoc ) vData.get( nCount ) ).get( JAccountsTable.CONNECTION_INDEX ) );
469       autoConnectCheck = ( ( JPluginCheckBox ) ( ( java.util.Vector JavaDoc ) vData.get( nCount ) ).get( JAccountsTable.AUTOCONNECT_INDEX ) );
470
471       // Update all status combo items
472
for( int nItemCount = 0; nItemCount < statusCombo.getItemCount(); nItemCount++ ) {
473         statusItem = ( JStatusComboItem ) statusCombo.getItemAt( nItemCount );
474
475         switch( statusItem.getStatus() ) {
476           case JPlugin.STATUS_ONLINE : statusItem.strTitle = JSharedObjects.getLanguageManager().getStringEx( "ONLINE" ); break;
477           case JPlugin.STATUS_FREE_CHAT : statusItem.strTitle = JSharedObjects.getLanguageManager().getStringEx( "FREE_FOR_CHAT" ); break;
478           case JPlugin.STATUS_INVISIBLE : statusItem.strTitle = JSharedObjects.getLanguageManager().getStringEx( "INVISIBLE" ); break;
479           case JPlugin.STATUS_AWAY : statusItem.strTitle = JSharedObjects.getLanguageManager().getStringEx( "AWAY" ); break;
480           case JPlugin.STATUS_BUSY : statusItem.strTitle = JSharedObjects.getLanguageManager().getStringEx( "BUSY" ); break;
481           case JPlugin.STATUS_IDLE : statusItem.strTitle = JSharedObjects.getLanguageManager().getStringEx( "IDLE" ); break;
482           case JPlugin.STATUS_DND : statusItem.strTitle = JSharedObjects.getLanguageManager().getStringEx( "DO_NOT_DISTURB" ); break;
483           case JPlugin.STATUS_ON_PHONE : statusItem.strTitle = JSharedObjects.getLanguageManager().getStringEx( "ON_PHONE" ); break;
484           case JPlugin.STATUS_ON_LUNCH : statusItem.strTitle = JSharedObjects.getLanguageManager().getStringEx( "ON_LUNCH" ); break;
485           case JPlugin.STATUS_NOT_AT_HOME : statusItem.strTitle = JSharedObjects.getLanguageManager().getStringEx( "NOT_AT_HOME" ); break;
486           case JPlugin.STATUS_NOT_IN_OFFICE : statusItem.strTitle = JSharedObjects.getLanguageManager().getStringEx( "NOT_IN_OFFICE" ); break;
487           case JPlugin.STATUS_NOT_AT_DESK : statusItem.strTitle = JSharedObjects.getLanguageManager().getStringEx( "NOT_AT_DESK" ); break;
488           case JPlugin.STATUS_ON_VACATION : statusItem.strTitle = JSharedObjects.getLanguageManager().getStringEx( "ON_VACATION" ); break;
489         }
490       }
491
492       autoConnectCheck.setToolTipText( JSharedObjects.getLanguageManager().getStringEx( "ENABLE_DISABLE_AUTO_LOGIN" ) );
493       
494       if( !connectionCheck.isEnabled() )
495         connectionCheck.setToolTipText( JSharedObjects.getLanguageManager().getStringEx( "CONNECTING" ) );
496       else
497         connectionCheck.setToolTipText( JSharedObjects.getLanguageManager().getStringEx( "RECONNECT_PLUGIN" ) );
498     }
499   }
500
501   /**
502     *=========================================================================
503     * JPluginCheckBox class implementation
504     * This is a new CheckBox based class, used to store the plugin into a table
505     * checkBox
506     *=========================================================================
507     */

508   
509   class JPluginCheckBox extends javax.swing.JCheckBox JavaDoc implements java.awt.event.ItemListener JavaDoc {
510
511     final static int RECONNECT = 0;
512     final static int AUTO_CONNECT = 1;
513
514     JPlugin plugin = null;
515     int nType = -1;
516     private boolean bEnabled = true;
517     private boolean bStarting = false;
518     
519
520     /**
521      * Constructor. Initializaes all class
522      * data;
523      * @param plugin The plugin's label;
524      */

525     JPluginCheckBox( JPlugin plugin, int nType ) {
526       
527       super();
528       this.plugin = plugin;
529       this.nType = nType;
530       
531       if( nType == RECONNECT )
532         addItemListener( this );
533     }
534
535     /**
536      * Returns the plugin's object;
537      */

538     JPlugin getPlugin() {
539       
540       return plugin;
541     }
542
543     /**
544      * Returns the object type.
545      */

546     int getType() {
547       
548       return nType;
549     }
550     
551     /**
552      * Override the setEnabled method
553      * to do specific task.
554      * @parm bEnabled The enabled status
555      * of component.
556      */

557     public void setEnabled( boolean bEnabled ) {
558       
559       if( nType == RECONNECT ) {
560         if( bEnabled ) {
561           
562           if( bStarting ) {
563             tableOwner.stopUpdateUI();
564             bStarting = false;
565           }
566           
567           setIcon( null );
568           setToolTipText( JSharedObjects.getLanguageManager().getStringEx( "RECONNECT_PLUGIN" ) );
569         }
570         else {
571           setToolTipText( JSharedObjects.getLanguageManager().getStringEx( "CONNECTING" ) );
572           tableOwner.startUpdateUI();
573           bStarting = true;
574           setIcon( org.planetamessenger.mos.engine.JSharedObjects.getResources().getIcon( org.planetamessenger.mos.engine.JResources.LOADING_ICON ) );
575         }
576
577         this.bEnabled = bEnabled;
578       }
579       else
580         super.setEnabled( bEnabled );
581     }
582  
583     /**
584      * Override the default isEnabled
585      * to check specific enabled status
586      * of component.
587      */

588     public boolean isEnabled() {
589       
590       if( nType == RECONNECT )
591         return bEnabled;
592       else
593         return super.isEnabled();
594     }
595     
596     /**
597      * Implement the itemStateChanged for component
598      * to ajust icon update in JDK1.4 and higher.
599      * Probably the model used in JDK1.3 (works fine) was
600      * changed in JDK1.4 (and higher) causing some not welcome
601      * effects.
602      */

603     public void itemStateChanged( java.awt.event.ItemEvent JavaDoc itemEvent ) {
604       
605       if( !bEnabled && getModel().isPressed() && ( nType == RECONNECT ) ) {
606         removeItemListener( this );
607         getModel().setPressed( false );
608         addItemListener( this );
609       }
610     }
611   } // JPluginCheckBox class
612

613   
614   
615   /**
616     *=========================================================================
617     * JPluginComboBox class implementation
618     * This is a new ComboBox based class, used to store the plugin into a table
619     * checkBox
620     *=========================================================================
621     */

622   
623   class JPluginComboBox extends javax.swing.JComboBox JavaDoc {
624     
625     JPlugin plugin;
626     
627
628     /**
629      * Constructor. Initializaes all class
630      * data;
631      * @param plugin The plugin's label;
632      */

633     JPluginComboBox( JPlugin plugin ) {
634       
635       super();
636       this.plugin = plugin;
637     }
638
639     /**
640      * Returns the plugin's object;
641      */

642     JPlugin getPlugin() {
643       
644       return plugin;
645     }
646     
647   } // JPluginComboBox class
648

649   
650   /**
651     *=========================================================================
652     * JStatusComboItem class implementation
653     * This is a JPluginCOmboBox item class.
654     * checkBox
655     *=========================================================================
656     */

657   
658   class JStatusComboItem {
659
660     private java.lang.String JavaDoc strTitle;
661     private int nStatus;
662     
663     
664
665     /**
666      * Constructor. Initializes all
667      * class data.
668      * @param strTitle The item title;
669      * @param nStatus The status managed
670      * by this item;
671      */

672     public JStatusComboItem( java.lang.String JavaDoc strTitle, int nStatus ) {
673       
674       this.strTitle = strTitle;
675       this.nStatus = nStatus;
676     }
677
678     /**
679      * Return the item status
680      * field.
681      */

682     int getStatus() {
683       
684       return nStatus;
685     }
686
687     /**
688      * Overrides the default toString
689      * implementation.
690      */

691     public java.lang.String JavaDoc toString() {
692       
693       return strTitle;
694     }
695     
696   } // JStatusComboItem class
697

698 }
699
700 // JAccountsTableModel Class
701
Popular Tags