source: other-projects/FileTransfer-WebSocketPair/testGXTWithGreenstone/src/org/greenstone/gatherer/cdm/DynamicListModel.java@ 33053

Last change on this file since 33053 was 33053, checked in by ak19, 5 years ago

I still had some stuff of Nathan Kelly's (FileTransfer-WebSocketPair) sitting on my USB. Had already commited the Themes folder at the time, 2 years back. Not sure if he wanted this additional folder commited. But I didn't want to delete it and decided it will be better off on SVN. When we use his project, if we find we didn't need this test folder, we can remove it from svn then.

File size: 3.8 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer.cdm;
38
39/**************************************************************************************
40 * Title: Gatherer
41 * Description: The Gatherer: a tool for gathering and enriching a digital collection.
42 * Company: The University of Waikato
43 * Written: 20/05/02
44 * Revised: 03/10/02 - Commented
45 **************************************************************************************/
46import javax.swing.ComboBoxModel;
47import javax.swing.DefaultListModel;
48
49/** This class extends the functionality of the DefaultListModel to include simple methods for refreshing the contents of this model if one of its elements changes.
50 * @author John Thompson, Greenstone Digital Library, University of Waikato
51 * @version 2.3
52 */
53public class DynamicListModel
54 extends DefaultListModel
55 implements ComboBoxModel {
56
57 private boolean auto_order = false;
58
59 private Object object = null;
60
61 public void addElement(Object element) {
62 if(auto_order) {
63 // Insert the object in its alphabetically correct place.
64 int position = 0;
65 boolean found = false;
66 while(!found && position < size()) {
67 ///ystem.err.print("Compare " + element.toString() + " to " + get(position).toString() + ": ");
68 int order = element.toString().compareTo(get(position).toString());
69 if(order < 0) {
70 add(position, element);
71 found = true;
72 ///ystem.err.println("Greater than. Insert");
73 }
74 else if(order == 0) {
75 found = true;
76 ///ystem.err.println("Equal. End.");
77 }
78 else {
79 position++;
80 ///ystem.err.println("Less than. Carry on.");
81 }
82 }
83 if(!found) {
84 super.addElement(element);
85 ///ystem.err.println("Out of elements. Insert");
86 }
87 }
88 else {
89 super.addElement(element);
90 }
91 }
92
93 /* private DynamicListModel shallowCopy() {
94 DynamicListModel copy = new DynamicListModel();
95 copy.setAutoOrder(auto_order);
96 for(int i = 0; i < size(); i++) {
97 copy.addElement(get(i));
98 }
99 return copy;
100 } */
101
102 public Object getSelectedItem() {
103 ///ystem.err.println("Get item: " + object);
104 return object;
105 }
106 /** Notify all controls that are based on this list model that its contents have changed, and they should repaint themselves. */
107 public void refresh() {
108 fireContentsChanged(this, 0, size());
109 }
110
111 public void setAutoOrder(boolean auto_order) {
112 this.auto_order = auto_order;
113 }
114
115 public void setSelectedItem(Object object) {
116 ///ystem.err.println("Set item: " + object);
117 this.object = object;
118 }
119}
Note: See TracBrowser for help on using the repository browser.