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

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

Removed all occurrences of classes explicitly importing other classes in the same package.

  • 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 /** Determine if a certain row should be shown in the table by checking it against all the current filters.
87 * @param model The <strong>TableModel</strong> the row is from.
88 * @param row The row number as an <i>int</i>
89 * @return <i>true</i> if the rows data matches all autofilters set and should be displayed, <i>false</i> otherwise.
90 */
91 public boolean filter(TableModel model, int row) {
92 boolean result = true;
93 for(int i = 0; result && i < filters.length; i++) {
94 if(filters[i] != null && filters[i].active()) {
95 ArrayList values = (ArrayList) model.getValueAt(row, i);
96 result = result && filters[i].filter(values);
97 }
98 }
99 return result;
100 }
101 /** Retrieve the autofilter associated with a certain column.
102 * @param column The column number as an <i>int</i>.
103 * @return The <strong>Autofilter</strong> assigned to that column.
104 */
105 public Autofilter getFilter(int column) {
106 Autofilter filter = filters[column];
107 if(filter == null) {
108 filter = new Autofilter();
109 filters[column] = filter;
110 }
111 return filter;
112 }
113 /** Determine if a certain column is filtered.
114 * @param column The column number as an <i>int</i>.
115 * @return <i>true</i> if there is an active autofilter assigned to this column, <i>false</i> otherwise.
116 */
117 public boolean isFiltered(int column) {
118 boolean result = false;
119 if(filters[column] != null) {
120 result = filters[column].active();
121 }
122 return result;
123 }
124 /** Remove a TableModelFilterListener from the TableModelFilter.
125 * @param listener The <strong>TableModelFilterListener</strong> to remove.
126 */
127 public synchronized void removeTableModelFilterListener(TableModelFilterListener listener) {
128 listeners.removeElement(listener);
129 }
130 /** Called whenever the filters assigned changes significantly, thus prompting a reload of the table model data. */
131 public void fireFilterChanged() {
132 ///ystem.err.println("Filter Changed!");
133 Vector tmp;
134 synchronized(this) {
135 tmp = (Vector) listeners.clone();
136 }
137
138 TableModelFilterEvent event = new TableModelFilterEvent (this);
139 for (Enumeration enum = tmp.elements();
140 enum.hasMoreElements(); ) {
141 ((TableModelFilterListener)enum.nextElement()).filterChanged(event);
142 }
143 }
144}
Note: See TracBrowser for help on using the repository browser.