KickJava   Java API By Example, From Geeks To Geeks.

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


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

38
39 package org.planetamessenger.mos.ui;
40
41
42
43 public class JContactListModel extends javax.swing.DefaultListModel JavaDoc {
44
45   /**
46    * Creates a JContactListModel object.
47    */

48   public JContactListModel() {
49     super();
50   }
51
52   /**
53    * Overrides the default addElement to
54    * add a new item with automatic data
55    * sorting.
56    * @param obj - The new data object that
57    * will be added in the model.
58    */

59   public synchronized void addElement( Object JavaDoc obj ) {
60
61     super.addElement( ( org.planetamessenger.plugin.JContactListItem ) obj );
62     sort();
63   }
64
65   /**
66    * Update the model content.
67    */

68   public final synchronized void update() {
69     
70     fireContentsChanged( this, 0, getSize() );
71   }
72
73   /**
74    * Performs the Model list sorting.
75    */

76   final synchronized void sort() {
77     
78     Object JavaDoc[] itemsList = toArray();
79     
80
81     // Checks if is first element
82
if( getSize() == 1 )
83       return;
84
85     java.util.Arrays.sort( itemsList );
86     //clear();
87

88     for( int nCount = 0; nCount < itemsList.length; nCount++ )
89       super.setElementAt( ( org.planetamessenger.plugin.JContactListItem ) itemsList[nCount], nCount );
90       //super.addElement( ( org.planetamessenger.plugin.JContactListItem ) itemsList[nCount] );
91

92     fireContentsChanged( this, 0, getSize() );
93   }
94 }
95
96 // JContactListModel class
Popular Tags