KickJava   Java API By Example, From Geeks To Geeks.

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


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

38
39 package org.planetamessenger.mos.ui;
40
41 import org.planetamessenger.mos.forms.*;
42 import org.planetamessenger.mos.engine.*;
43 import org.planetamessenger.plugin.*;
44 import java.util.*;
45 import java.awt.*;
46 import javax.swing.*;
47 import javax.swing.border.*;
48
49
50 public class JContactList extends JList implements JContactListInterface, java.awt.event.MouseListener JavaDoc, java.awt.event.ActionListener JavaDoc {
51
52   ArrayList<JMenuListener> menuListener = null;
53   JContactListModel listModel = null;
54   JPopupMenu popMenu = null;
55   JMenuItem messageItem = null;
56   JMenuItem contactDetailsItem = null;
57   JMenuItem updateNameItem = null;
58   JMenuItem removeContactItem = null;
59   JMenuItem renameContactItem = null;
60   JMenuItem blockUnblockItem = null;
61   JMenuItem addContactToListItem = null;
62
63
64   /**
65    * Constructor. Initializes all JList
66    * data members.
67    */

68   public JContactList() {
69
70     super();
71     
72     addMouseListener( this );
73
74     menuListener = new ArrayList<JMenuListener>();
75     listModel = new JContactListModel();
76     setModel( listModel );
77     getSelectionModel().setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
78
79     JContactListItem onlineItem = new JContactListItem( -1, JSharedObjects.getLanguageManager().getStringEx( "ONLINE" ), JSharedObjects.getLanguageManager().getStringEx( "ONLINE" ) );
80     JContactListItem offlineItem = new JContactListItem( -2, JSharedObjects.getLanguageManager().getStringEx( "OFFLINE" ), JSharedObjects.getLanguageManager().getStringEx( "OFFLINE" ) );
81
82     onlineItem.setStatus( org.planetamessenger.plugin.JPlugin.STATUS_ONLINE );
83     offlineItem.setStatus( org.planetamessenger.plugin.JPlugin.STATUS_OFFLINE );
84     
85     addItem( onlineItem );
86     addItem( offlineItem );
87
88     popMenu = new JPopupMenu();
89     
90     messageItem = new JMenuItem();
91     messageItem.setName( "message" );
92     messageItem.setFont( JSystemFonts.FONT );
93     messageItem.setIcon( JSharedObjects.getResources().getIcon( JResources.MESSAGE_ICON ) );
94     messageItem.addActionListener( this );
95     popMenu.add( messageItem );
96     
97     contactDetailsItem = new JMenuItem();
98     contactDetailsItem.setName( "contact_details" );
99     contactDetailsItem.setFont( JSystemFonts.FONT );
100     contactDetailsItem.setIcon( JSharedObjects.getResources().getIcon( JResources.USER_DETAIL_ICON ) );
101     contactDetailsItem.addActionListener( this );
102     popMenu.add( contactDetailsItem );
103     
104     popMenu.addSeparator();
105
106     updateNameItem = new JMenuItem();
107     updateNameItem.setName( "update_contact_name" );
108     updateNameItem.setFont( JSystemFonts.FONT );
109     updateNameItem.setIcon( JSharedObjects.getResources().getIcon( JResources.UPDATE_NAME_ICON ) );
110     updateNameItem.addActionListener( this );
111     popMenu.add( updateNameItem );
112     
113     blockUnblockItem = new JMenuItem();
114     blockUnblockItem.setName( "block_unblock_contact" );
115     blockUnblockItem.setFont( JSystemFonts.FONT );
116     blockUnblockItem.addActionListener( this );
117     popMenu.add( blockUnblockItem );
118     
119     addContactToListItem = new JMenuItem();
120     addContactToListItem.setName( "add_contact" );
121     addContactToListItem.setFont( JSystemFonts.FONT );
122     addContactToListItem.setIcon( JSharedObjects.getResources().getIcon( JResources.ADD_INVITE_ICON ) );
123     addContactToListItem.addActionListener( this );
124     popMenu.add( addContactToListItem );
125     
126     removeContactItem = new JMenuItem();
127     removeContactItem.setName( "remove_contact" );
128     removeContactItem.setFont( JSystemFonts.FONT );
129     removeContactItem.setIcon( JSharedObjects.getResources().getIcon( JResources.REMOVE_ICON ) );
130     removeContactItem.addActionListener( this );
131     popMenu.add( removeContactItem );
132     
133     renameContactItem = new JMenuItem();
134     renameContactItem.setName( "rename_contact" );
135     renameContactItem.setFont( JSystemFonts.FONT );
136     renameContactItem.setIcon( JSharedObjects.getResources().getIcon( JResources.RENAME_ICON ) );
137     renameContactItem.addActionListener( this );
138     popMenu.add( renameContactItem );
139     
140     updateLanguage();
141     setCellRenderer( new JListCellRenderer() );
142     setToolTipText( "JContactList" ); // After set this on JDK1.3 getToolTipText() works fine
143
}
144
145   /**
146    * Update the language for all contact list items.
147    */

148   public void updateLanguage() {
149     
150     messageItem.setText( JSharedObjects.getLanguageManager().getStringEx( "NEW_MESSAGE" ) );
151     contactDetailsItem.setText( JSharedObjects.getLanguageManager().getStringEx( "CONTACT_DETAILS" ) );
152     updateNameItem.setText( JSharedObjects.getLanguageManager().getStringEx( "UPDATE_SCREEN_NAME" ) );
153     removeContactItem.setText( JSharedObjects.getLanguageManager().getStringEx( "REMOVE_CONTACT" ) );
154     renameContactItem.setText( JSharedObjects.getLanguageManager().getStringEx( "RENAME_CONTACT" ) );
155     addContactToListItem.setText( JSharedObjects.getLanguageManager().getStringEx( "ADD_TO_CONTACT_LIST" ) );
156     updateUI();
157   }
158
159   /**
160    * Override the updateUI method to perform
161    * correct update to table component,
162    * updating all components into table.
163    */

164   public void updateUI() {
165
166     super.updateUI();
167
168     if( popMenu != null ) {
169       javax.swing.SwingUtilities.updateComponentTreeUI( popMenu );
170       popMenu.invalidate();
171       popMenu.validate();
172       popMenu.repaint();
173     }
174   }
175
176   /**
177    * Override the getToolTipText JList method
178    * to return a item ToolTip.
179    * evt The mouse event with event information
180    * about mouse status;
181    */

182   public String JavaDoc getToolTipText( java.awt.event.MouseEvent JavaDoc evt ) {
183
184     int nIndex = locationToIndex( evt.getPoint() );
185
186     if( nIndex >= 0 ) {
187       JContactListItem item = ( JContactListItem ) getModel().getElementAt( nIndex );
188       JPlugin plugin = ( JPlugin ) JSharedObjects.getPluginEngine().get( item.getPluginId() );
189
190       if( plugin != null )
191         return "<html><b>" + plugin.toString() +
192                 "</b><br><br><i><b>" +
193                 JSharedObjects.getLanguageManager().getStringEx( "USER" ) + "</b></i> " +
194                 item.getUserId() + "<br><i><b>" +
195                 JSharedObjects.getLanguageManager().getStringEx( "NICK_NAME" ) + "</b></i> " +
196                 item.getNickName() + "</html>";
197       else
198         return null;
199     }
200
201     return null;
202   }
203
204   /**
205    * Overrides the default implementation
206    * for mouse processing event.
207    * Added here for PopupMenu processing.
208    * @param e The Mouse event generated;
209    */

210   public void processMouseEvent( java.awt.event.MouseEvent JavaDoc e ) {
211
212     try {
213       if( e.isPopupTrigger() ) {
214
215         JContactListItem item = ( ( JContactListItem ) getSelectedValue() );
216
217
218         if( item == null )
219           return;
220
221         if( ( item.getPluginId() == -1 ) || ( item.getPluginId() == -2 ) )
222           return;
223
224         JPlugin plugin = ( JPlugin ) JSharedObjects.getPluginEngine().get( item.getPluginId() );
225         int nPosX = e.getX();
226         int nPosY = e.getY();
227
228         // Retrieve item from contact list database (because this item has the updated status of contact in system)
229
item = ( JContactListItem ) JSharedObjects.getContactListManager().getContactList( plugin ).get( item.getUserId() );
230
231         if( fireIsNewTabEnabled( item ) ) {
232           messageItem.setVisible( true );
233           messageItem.setText( JSharedObjects.getLanguageManager().getStringEx( "NEW_TAB" ) );
234         }
235         else {
236           if( fireIsNewMessageEnabled( item ) ) {
237             messageItem.setVisible( true );
238             messageItem.setText( JSharedObjects.getLanguageManager().getStringEx( "NEW_MESSAGE" ) );
239           }
240           else {
241             messageItem.setVisible( false );
242           }
243         }
244         
245         // Is a NOT_IN_LIST contact ??
246
if( item.getContactFlag() == JContactListItem.CONTACT_NOT_IN_LIST )
247           addContactToListItem.setVisible( true );
248         else
249           addContactToListItem.setVisible( false );
250         
251         // Plugin support Update screen name capability ?
252
updateNameItem.setVisible( plugin.getPluginCapabilities().getBool( JPluginCapabilities.CAPABILITY_UPDATE_SCREEN_NAME ) );
253
254         // Block/Unblock capability ?
255
blockUnblockItem.setVisible( plugin.getPluginCapabilities().getBool( JPluginCapabilities.CAPABILITY_BLOCK_CONTACT ) );
256
257         if( blockUnblockItem.isVisible() )
258           
259           blockUnblockItem.setEnabled( plugin.isConnected() );
260         
261           if( item.getBlocked() ) {
262             blockUnblockItem.setText( JSharedObjects.getLanguageManager().getStringEx( "UNBLOCK_CONTACT" ) );
263             blockUnblockItem.setIcon( JSharedObjects.getResources().getIcon( JResources.UNBLOCK_16_ICON ) );
264           }
265           else {
266             blockUnblockItem.setText( JSharedObjects.getLanguageManager().getStringEx( "BLOCK_CONTACT" ) );
267             blockUnblockItem.setIcon( JSharedObjects.getResources().getIcon( JResources.BLOCK_16_ICON ) );
268           }
269
270         if( nPosX > ( this.getPreferredScrollableViewportSize().width / 2 ) )
271           nPosX = e.getX() - popMenu.getSize().width;
272
273         popMenu.show( this, nPosX, nPosY );
274       }
275       else {
276         super.processMouseEvent( e );
277       }
278     } catch( java.lang.Exception JavaDoc ex ) {
279       System.err.println( "JContactList.processMenuEvent() - " + ex );
280     }
281
282   }
283
284   /**
285    * Add a Menu listener for this JList component.
286    * @param menuListener - The listener to add;
287    */

288   public void addMenuListener( JMenuListener menuListener ) {
289   
290     this.menuListener.add( menuListener );
291   }
292   
293   /**
294    * Remove a Menu listener of this JList component.
295    * @param menuListener - The listener to remove;
296    */

297   public void removeMenuListener( JMenuListener menuListener ) {
298   
299     this.menuListener.remove( menuListener );
300   }
301   
302  /**
303   * Performs a object cleanup.
304   */

305  public void destroy() {
306  
307    menuListener.clear();
308  }
309
310  /**
311   * Adds a item to this JList.
312   * @param item The Item to add;
313   */

314   public boolean addItem( JContactListItem item ) {
315     
316     if( listModel.contains( item ) ) {
317       /*
318        * If item is already in list, update all item object.
319        */

320       JContactListItem tmpItem = getItem( item.getPluginId(), item.getUserId() );
321       tmpItem.copy( item );
322       return false;
323     }
324     
325     listModel.addElement( item );
326     
327     return true;
328   }
329
330   /**
331    * Returns the item specified by
332    * parameter.
333    * @param nPluginId The Plugin id;
334    * @param strItemId The id of Item;
335    */

336   public JContactListItem getItem( int nPluginId, java.lang.String JavaDoc strItemId ) {
337     
338     JContactListItem item = new JContactListItem( nPluginId, strItemId, "" );
339     int nItemIndex = listModel.indexOf( item );
340     
341     
342     if( nItemIndex != -1 )
343       return ( JContactListItem ) listModel.get( nItemIndex );
344     else
345       return null;
346   }
347
348   /**
349    * Removes a item of this JList.
350    * @param item The Item to remove;
351    */

352   public boolean removeItem( JContactListItem item ) {
353
354     if( !listModel.contains( item ) )
355       return false;
356
357     listModel.removeElement( item );
358
359     return true;
360   }
361
362   /**
363    * Removes all plugin specific items.
364    * @param nPluginId The plugin id that whose
365    * plugins will be removed;
366    */

367   public boolean removePluginItems( int nPluginId ) {
368     
369     int nCountItems = listModel.size();
370     HashMap<JContactListItem, JContactListItem> hItems = new HashMap<JContactListItem, JContactListItem>();
371     Iterator<JContactListItem> itItems;
372     JContactListItem item;
373         
374     
375     for( int nCount = 0; nCount < nCountItems; nCount++ ) {
376     
377       item = ( JContactListItem ) listModel.get( nCount );
378       
379       if( item.getPluginId() == nPluginId )
380         hItems.put( item, item );
381     }
382     
383     itItems = hItems.values().iterator();
384     
385     while( itItems.hasNext() ) {
386       item = itItems.next();
387       listModel.removeElement( item );
388     }
389
390     hItems.clear();
391     
392     return true;
393   }
394
395   /**
396    * Set all items of specified plugin to
397    * a status specified by parameter.
398    * @param nPluginId The plugin id to set the new status
399    * for users;
400    * @nNewStatus The new status to set;
401    */

402   public boolean setAllItemsStatus( int nPluginId, int nNewStatus ) {
403   
404     JContactListItem item;
405     int nCountItems = listModel.getSize();
406     boolean bChanged = false;
407
408
409     for( int nCount = 0; nCount < nCountItems; nCount++ ) {
410
411       item = ( JContactListItem ) listModel.get( nCount );
412
413       if( item.getPluginId() == nPluginId ) {
414         item.setStatus( nNewStatus );
415         bChanged = true;
416       }
417     }
418
419     if( bChanged ) {
420       listModel.sort();
421       listModel.update();
422     }
423
424     return true;
425   }
426
427   /**
428    * Removes the selected item from this JList.
429    */

430   public boolean removeSelectedItem() {
431
432     int nSelectedIndex = getSelectedIndex();
433         
434
435     if( nSelectedIndex == -1 )
436       return false;
437     
438     remove( nSelectedIndex );
439     
440     return true;
441   }
442
443   /**
444    * Sets a new status of a JList item.
445    * @param item The Item key to set the status;
446    * @param nNewStatus The new item status;
447    */

448   public boolean setItemStatus( JContactListItem item, int nNewStatus ) {
449
450     int nItemPos = listModel.indexOf( item );
451     int nStatus;
452
453
454     if( nItemPos == -1 )
455       return false;
456
457     JContactListItem itemTmp = ( JContactListItem ) listModel.get( nItemPos );
458
459     nStatus = itemTmp.getStatus();
460     itemTmp.setStatus( nNewStatus );
461
462     if( nStatus != nNewStatus )
463       if( ( ( nStatus > JPlugin.STATUS_OFFLINE ) &&
464             ( nNewStatus == JPlugin.STATUS_OFFLINE ) ) ||
465           ( ( nStatus == JPlugin.STATUS_OFFLINE ) &&
466             ( nNewStatus > JPlugin.STATUS_OFFLINE ) ) ||
467           ( ( nStatus >= JPlugin.STATUS_URL ) ) ||
468           ( ( nNewStatus >= JPlugin.STATUS_URL ) ) ) {
469         listModel.sort();
470       }
471       else
472         listModel.update();
473     else
474       listModel.update();
475     
476     return true;
477   }
478
479   /**
480    * restore the last status of a JList item.
481    * @param item The Item key to set the status;
482    */

483   public void restoreItemStatus( JContactListItem item ) {
484
485     int nItemPos = listModel.indexOf( item );
486
487
488     if( nItemPos == -1 )
489       return;
490
491     JContactListItem item2 = ( JContactListItem ) listModel.get( nItemPos );
492     
493     item2.restoreRealStatus();
494     listModel.sort();
495   }
496   
497   // Mouse event handlers
498
/**
499    * Implements the mouseClicked event handler
500    * for this JList class.
501    * @param mouseEvent The Mouse event generated;
502    */

503   public void mouseClicked( java.awt.event.MouseEvent JavaDoc mouseEvent ) {
504
505     try {
506       if( mouseEvent.getClickCount() == 2 ) {
507
508         JContactListItem item = ( JContactListItem ) getSelectedValue();
509
510         if( item == null )
511           return;
512
513         if( ( item.getPluginId() != -1 ) && ( item.getPluginId() != -2 ) )
514           fireOnMessage( item );
515       }
516     } catch( java.lang.Exception JavaDoc ex ) {
517       System.err.println( "JContactList.mouseClicked() - " + ex );
518     }
519   }
520   
521   /**
522    * Implements the mouseEntered event handler
523    * for this JList class.
524    * @param mouseEvent The Mouse event generated;
525    * Do nothing in this implementation
526    */

527   public void mouseEntered( java.awt.event.MouseEvent JavaDoc mouseEvent ) {
528     
529   }
530   
531   /**
532    * Implements the mouseExited event handler
533    * for this JList class.
534    * @param mouseEvent The Mouse event generated;
535    * Do nothing in this implementation
536    */

537   public void mouseExited( java.awt.event.MouseEvent JavaDoc mouseEvent ) {
538     
539   }
540   
541   /**
542    * Implements the mousePressed event handler
543    * for this JList class.
544    * @param mouseEvent The Mouse event generated;
545    * Do nothing in this implementation
546    */

547   public void mousePressed( java.awt.event.MouseEvent JavaDoc mouseEvent ) {
548     
549   }
550   
551   /**
552    * Implements the mouseReleased event handler
553    * for this JList class.
554    * @param mouseEvent The Mouse event generated;
555    * Do nothing in this implementation
556    */

557   public void mouseReleased( java.awt.event.MouseEvent JavaDoc mouseEvent ) {
558     
559   }
560
561   /**
562    * Implements the actionPerformed event handler
563    * for the popup menu items;
564    * @param actionEvent The event generated;
565    */

566   public void actionPerformed( java.awt.event.ActionEvent JavaDoc actionEvent ) {
567
568     try {
569       JContactListItem item = ( JContactListItem ) getSelectedValue();
570       JMenuItem menuItem = ( JMenuItem ) actionEvent.getSource();
571
572       System.err.println( "JContactList.actionPerformed() - Triggered for item[" + item.getUserId() + "]" );
573
574       // Message processing
575
if( menuItem.getName().compareTo( "message" ) == 0 ) {
576         fireOnMessage( item );
577         return;
578       }
579       
580       // User details processing
581
if( menuItem.getName().compareTo( "contact_details" ) == 0 ) {
582         JMOSContactDetails contactDetailDlg = new JMOSContactDetails( item );
583
584         contactDetailDlg.setVisible( true );
585         return;
586       }
587       
588       // Remove contact processing
589
if( menuItem.getName().compareTo( "remove_contact" ) == 0 ) {
590
591         int nRet = JOptionPane.showConfirmDialog( null, JSharedObjects.getLanguageManager().getStringEx( "REMOVE_CONTACT_WARNING" ) + " " + item.getNickName() + JSharedObjects.getLanguageManager().getStringEx( "QUESTION_SYMBOL" ), JSharedObjects.getLanguageManager().getStringEx( "REMOVE_CONTACT" ), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE );
592
593         // Trigger the plugin onRemoveUserFromContactList event
594
if( nRet == JOptionPane.YES_OPTION )
595           ( ( JPlugin ) JSharedObjects.getPluginEngine().get( item.getPluginId() ) ).fireOnRemoveUserFromContactList( item.getUserId() );
596
597         return;
598       }
599
600       // Update screen name
601
if( menuItem.getName().compareTo( "update_contact_name" ) == 0 ) {
602         ( ( JPlugin ) JSharedObjects.getPluginEngine().get( item.getPluginId() ) ).fireOnBuddyDetails( item.getUserId() );
603         return;
604       }
605
606       // Contact rename processing
607
if( menuItem.getName().compareTo( "rename_contact" ) == 0 ) {
608
609         java.lang.Object JavaDoc objNickName = JOptionPane.showInputDialog( null, JSharedObjects.getLanguageManager().getStringEx( "NICK_NAME" ), JSharedObjects.getLanguageManager().getStringEx( "RENAME_CONTACT" ), JOptionPane.PLAIN_MESSAGE, null, null, item.getNickName() );
610
611         if( ( objNickName == null ? "" : objNickName.toString() ).compareTo( "" ) != 0 ) {
612           JSharedObjects.getContactListManager().updateScreenName( ( ( JPlugin ) JSharedObjects.getPluginEngine().get( item.getPluginId() ) ), item.getUserId(), objNickName.toString() );
613           item.setNickName( objNickName.toString() );
614           listModel.update();
615         }
616
617         return;
618       }
619       
620       // Add user to list processing
621
if( menuItem.getName().compareTo( "add_contact" ) == 0 ) {
622         ( ( JPlugin ) JSharedObjects.getPluginEngine().get( item.getPluginId() ) ).fireOnAddUserToContactList( item.getUserId() );
623         return;
624       }
625       
626       // Block/Unblock contact processing
627
if( menuItem.getName().compareTo( "block_unblock_contact" ) == 0 ) {
628         
629         JContactListItem[] aContactList = new JContactListItem[1];
630         JPlugin plugin = JSharedObjects.getPluginEngine().get( item.getPluginId() );
631
632         aContactList[0] = ( JContactListItem ) JSharedObjects.getContactListManager().getContactList( plugin ).get( item.getUserId() );
633         
634         if( aContactList[0] != null ) {
635           aContactList[0].setBlocked( !aContactList[0].getBlocked() );
636           plugin.fireOnChangePrivacy( aContactList );
637         }
638         
639         return;
640       }
641     } catch( java.lang.Exception JavaDoc ex ) {
642       System.err.println( "JContactist.actionPerformed() - " + ex );
643     }
644   }
645
646   /**
647    * Fire the OnMessage event.
648    * @param item The contact item of this event;
649    */

650   private void fireOnMessage( JContactListItem item ) {
651    
652     ArrayList<JMenuListener> clone;
653     
654     synchronized( this ) {
655       clone = ( ArrayList<JMenuListener> ) menuListener.clone();
656     }
657     
658     if( clone.size() > 0 ) {
659       for( int nCount = 0; nCount < clone.size(); nCount++ )
660         ( ( JMenuListener ) clone.get( nCount ) ).onMessage( item );
661     }
662   }
663   
664   /**
665    * Fire the OnNewTab event.
666    * @param item The contact item of this event;
667    */

668   private void fireOnNewTab( JContactListItem item ) {
669    
670     ArrayList<JMenuListener> clone;
671     
672     synchronized( this ) {
673       clone = ( ArrayList<JMenuListener> ) menuListener.clone();
674     }
675     
676     if( clone.size() > 0 ) {
677       for( int nCount = 0; nCount < clone.size(); nCount++ )
678         ( ( JMenuListener ) clone.get( nCount ) ).onNewTab( item );
679     }
680   }
681   
682   /**
683    * Fire the isNewTabEnabled event.
684    * @param item The contact item of this event;
685    */

686   private boolean fireIsNewTabEnabled( JContactListItem item ) {
687    
688     ArrayList<JMenuListener> clone;
689     boolean bRet = true;
690     
691     synchronized( this ) {
692       clone = ( ArrayList<JMenuListener> ) menuListener.clone();
693     }
694     
695     if( clone.size() > 0 ) {
696       for( int nCount = 0; nCount < clone.size(); nCount++ )
697         bRet = ( bRet && ( ( JMenuListener ) clone.get( nCount ) ).isNewTabEnabled( item ) );
698     }
699     
700     return bRet;
701   }
702
703   /**
704    * Fire the isNewMessageEnabled event.
705    * @param item The contact item of this event;
706    */

707   private boolean fireIsNewMessageEnabled( JContactListItem item ) {
708    
709     ArrayList<JMenuListener> clone;
710     boolean bRet = true;
711     
712     synchronized( this ) {
713       clone = ( ArrayList<JMenuListener> ) menuListener.clone();
714     }
715     
716     if( clone.size() > 0 ) {
717       for( int nCount = 0; nCount < clone.size(); nCount++ )
718         bRet = ( bRet && ( ( JMenuListener ) clone.get( nCount ) ).isNewMessageEnabled( item ) );
719     }
720     
721     return bRet;
722   }
723  
724   /*
725    *=========================================================================
726    * JListCellRenderer class implementation
727    * This is a new cell renderer implementation for the contact list,
728    * that will manage the entire redrawing for labels, icons, system labels, ...
729    *=========================================================================
730    */

731   class JListCellRenderer extends javax.swing.JLabel JavaDoc implements javax.swing.ListCellRenderer JavaDoc {
732   
733     boolean bSystemLabel = false;
734     
735
736     /**
737      * Creates a ListCellRenderer.
738      */

739     public JListCellRenderer() {
740     
741       setOpaque( true );
742     }
743  
744     /**
745      * This is the only method defined by ListCellRenderer.
746      * We just reconfigure the JLabel each time we're called.
747      * This method will replace the default renderer
748      * for the item contact list component.
749      * @param See the java documentation for javax.swing.ListCellRenderer;
750      */

751     public Component getListCellRendererComponent( javax.swing.JList JavaDoc list, Object JavaDoc value, int index, boolean isSelected, boolean cellHasFocus ) {
752  
753       try {
754         JContactListItem item = ( JContactListItem ) value;
755         ImageIcon icon = JSharedObjects.getResources().getIcon( item.getStatus() );
756         Icon thisIcon = getIcon();
757         Dimension dmItemSize = new Dimension( list.getParent().getSize().width, icon.getIconHeight() );
758         boolean bEnabledItem = !item.getBlocked();
759
760
761         setText( item.getNickName() );
762
763         if( !list.isEnabled() )
764           bEnabledItem = false;
765
766         setEnabled( bEnabledItem );
767
768         if( ( thisIcon != null ? !thisIcon.equals( icon ) : true ) )
769           setIcon( icon );
770
771         if( isSelected && item.getPluginId() != -1 && item.getPluginId() != -2 ) {
772           setHorizontalAlignment( JLabel.LEADING );
773           setBackground( list.getSelectionBackground() );
774           setForeground( list.getSelectionForeground() );
775           setBorder( new EtchedBorder() );
776           bSystemLabel = false;
777         }
778         else {
779           if( item.getPluginId() == -1 || item.getPluginId() == -2 ) {
780             setHorizontalAlignment( JLabel.CENTER );
781             bSystemLabel = true;
782           }
783           else {
784             setHorizontalAlignment( JLabel.LEADING );
785             bSystemLabel = false;
786           }
787
788           setBackground( list.getBackground() );
789           setForeground( list.getForeground() );
790           setPreferredSize( dmItemSize );
791           setBorder( null );
792         }
793       } catch( java.lang.Exception JavaDoc e ) {
794         System.err.println( "JContactList.getListCellRendererComponent() - " + e );
795       }
796     
797       setFont( list.getFont() );
798     
799       return this;
800     }
801
802     /**
803      * We will override the default paint
804      * implementation to perform any
805      * customized extra drawing in this
806      * Label component.
807      * @param g The Graphics device that will
808      * be used in drawing operations;
809      */

810     public void paint( java.awt.Graphics JavaDoc g ) {
811
812       if( bSystemLabel ) {
813         java.awt.Dimension JavaDoc dmSize = getSize();
814         int //nCenterX = ( dmSize.width / 2 ) - ( g.getFontMetrics().stringWidth( getText() ) / 2 ), // This formula center the label in component
815
nCenterX = 10,
816                                nCenterY = ( dmSize.height / 2 ) + ( g.getFontMetrics().getHeight() / 2 );
817
818         g.draw3DRect( 0, ( int )( dmSize.getHeight() / 2 ), nCenterX - 2, 1, true );
819         g.draw3DRect( ( int )( nCenterX + g.getFontMetrics().stringWidth( getText() ) ), ( int )( dmSize.getHeight() / 2 ), ( int ) ( dmSize.getWidth() - nCenterX - g.getFontMetrics().stringWidth( getText() ) - 2 ), 1, true );
820         g.setFont( getFont() );
821         g.setColor( this.getForeground() );
822         g.drawString( getText(), nCenterX, nCenterY - 2 );
823       }
824       else
825         super.paint( g );
826     }
827     
828   } // JListCellRenderer class
829
}
830
831 // JContactList class
Popular Tags