source: trunk/gli/src/org/greenstone/gatherer/util/ExclusiveListSelectionListener.java@ 4293

Last change on this file since 4293 was 4293, checked in by jmt12, 21 years ago

Initial revision

  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 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 */
37
38
39
40
41
42
43/* GPL_HEADER */
44package org.greenstone.gatherer.util;
45/**************************************************************************************
46 * Title: Gatherer
47 * Description: The Gatherer: a tool for gathering and enriching a digital collection.
48 * Company: The University of Waikato
49 * Written: 16/05/02
50 * Revised: 04/10/02 - Commented
51 **************************************************************************************/
52import javax.swing.JList;
53import javax.swing.event.ListSelectionEvent;
54import javax.swing.event.ListSelectionListener;
55/** This listener is used to ensure that in a group of JList or similar components, only one list actually has elements selected.
56 * @author John Thompson
57 * @version 2.3
58 */
59public class ExclusiveListSelectionListener
60 implements ListSelectionListener {
61 /** A flag set to show that we are already dealing with a list selection change, and to ignore further ones until the flag becomes unset again. */
62 private boolean ignore = false;
63 /** An array of JList components, containing each JList thats registered with this listener. */
64 private JList lists[] = null;
65 /** Method to register a new JList with this listener.
66 * @param list The new <strong>JList</strong> to register.
67 */
68 public void add(JList list) {
69 list.addListSelectionListener(this);
70 if(lists == null) {
71 lists = new JList[1];
72 lists[0] = list;
73 }
74 else {
75 JList temp[] = new JList[lists.length + 1];
76 System.arraycopy(lists, 0, temp, 0, lists.length);
77 temp[lists.length] = list;
78 lists = temp;
79 }
80 }
81 /** Any implementation of ListSelectionListener must include this method so we can be informed when the selection changes. In this case we want to clear the selections of all other registered JLists other than the caller.
82 * @param event A <strong>ListSelectionEvent</strong> containing informaiton about the event.
83 */
84 public void valueChanged(ListSelectionEvent event) {
85 if(!ignore) {
86 ignore = true;
87 JList source = (JList)event.getSource();
88 for(int i = 0; i < lists.length; i++) {
89 if(lists[i] != source) {
90 lists[i].clearSelection();
91 }
92 }
93 ignore = false;
94 }
95 }
96}
Note: See TracBrowser for help on using the repository browser.