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

Last change on this file since 13531 was 8471, checked in by mdewsnip, 20 years ago

Changed the name of a variable from "enum" to "enumeration" to avoid clash with Java 1.5.0.

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