source: trunk/gli/src/org/greenstone/gatherer/gui/metaaudit/Filter.java@ 4366

Last change on this file since 4366 was 4366, checked in by kjdon, 21 years ago

re-tabbed the code for java

  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 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.gui.metaaudit;
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: 03/09/02
50 * Revised: 04/10/02 - Commented
51 **************************************************************************************/
52import de.qfs.lib.gui.TableModelFilter;
53import de.qfs.lib.gui.TableModelFilterEvent;
54import de.qfs.lib.gui.TableModelFilterListener;
55import java.util.ArrayList;
56import java.util.Enumeration;
57import java.util.Vector;
58import javax.swing.table.TableModel;
59import org.greenstone.gatherer.gui.metaaudit.Autofilter;
60/** This class essentially manages the autofilters applied to the metaaudit table.
61 * @author John Thompson
62 * @version 2.3
63 */
64public class Filter
65 implements TableModelFilter {
66 /** An array of autofilters. */
67 private Autofilter filters[];
68 /** The registered TableModelFilterListeners. */
69 private Vector listeners = new Vector ();
70 /** Constructor.
71 * @param columns The number of columns this Filter will be expected to filter, as an <i>int</i>.
72 */
73 public Filter(int columns) {
74 filters = new Autofilter[columns];
75 }
76 /** Add a TableModelFilterListener to the TableModelFilter.
77 * @param listener The <strong>TableModelFilterListener</strong> to add, if it isn't already registered.
78 */
79 public synchronized void addTableModelFilterListener(TableModelFilterListener listener) {
80 if (!listeners.contains(listener)) {
81 listeners.addElement(listener);
82 }
83 }
84 /** Remove a filter from a column.
85 * @param column The column number to remove the filter from, as an <i>int</i>.
86 */
87 public void clearFilter(int column) {
88 if(filters[column] != null) {
89 filters[column].setActive(false);
90 }
91 }
92 /** Determine if a certain row should be shown in the table by checking it against all the current filters.
93 * @param model The <strong>TableModel</strong> the row is from.
94 * @param row The row number as an <i>int</i>
95 * @return <i>true</i> if the rows data matches all autofilters set and should be displayed, <i>false</i> otherwise.
96 */
97 public boolean filter(TableModel model, int row) {
98 boolean result = true;
99 for(int i = 0; result && i < filters.length; i++) {
100 if(filters[i] != null && filters[i].active()) {
101 ArrayList values = (ArrayList) model.getValueAt(row, i);
102 result = result && filters[i].filter(values);
103 }
104 }
105 return result;
106 }
107 /** Retrieve the autofilter associated with a certain column.
108 * @param column The column number as an <i>int</i>.
109 * @return The <strong>Autofilter</strong> assigned to that column.
110 */
111 public Autofilter getFilter(int column) {
112 Autofilter filter = filters[column];
113 if(filter == null) {
114 filter = new Autofilter();
115 filters[column] = filter;
116 }
117 return filter;
118 }
119 /** Determine if a certain column is filtered.
120 * @param column The column number as an <i>int</i>.
121 * @return <i>true</i> if there is an active autofilter assigned to this column, <i>false</i> otherwise.
122 */
123 public boolean isFiltered(int column) {
124 boolean result = false;
125 if(filters[column] != null) {
126 result = filters[column].active();
127 }
128 return result;
129 }
130 /** Remove a TableModelFilterListener from the TableModelFilter.
131 * @param listener The <strong>TableModelFilterListener</strong> to remove.
132 */
133 public synchronized void removeTableModelFilterListener(TableModelFilterListener listener) {
134 listeners.removeElement(listener);
135 }
136 /** Called whenever the filters assigned changes significantly, thus prompting a reload of the table model data. */
137 public void fireFilterChanged() {
138 ///ystem.err.println("Filter Changed!");
139 Vector tmp;
140 synchronized(this) {
141 tmp = (Vector) listeners.clone();
142 }
143
144 TableModelFilterEvent event = new TableModelFilterEvent (this);
145 for (Enumeration enum = tmp.elements();
146 enum.hasMoreElements(); ) {
147 ((TableModelFilterListener)enum.nextElement()).filterChanged(event);
148 }
149 }
150}
Note: See TracBrowser for help on using the repository browser.