|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.tasklist.core.filter; import java.util.List; import java.util.Set; import java.util.Vector; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.util.TreeSet; import java.util.Iterator; import java.util.Collection; import java.util.Set; import java.util.AbstractCollection; import java.util.SortedSet; import java.util.AbstractSet; import java.util.Collection; import java.util.Comparator; import java.util.TreeSet; import java.util.Iterator; import java.util.LinkedList; /** * Set of filters */ public final class FilterRepository implements List { /** * Property corresponding to the collection of filters in the * repository. The old/new object fired with the property are null. */ public static final String PROP_FILTERS = "propFilters"; /** * Property corresponding to the active filter. */ public static final String PROP_ACTIVE_FILTER = "propActiveFilter"; /** collection of listeners **/ private PropertyChangeSupport pcs = null; /** the set of filters of this repository **/ private LinkedList filters = new LinkedList(); private int active = -1; // index of the active filter /** listener for nested filters **/ private PropertyChangeListener filterChangeListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { fireFiltersChanged(); } }; /** * Constructor, default. */ public FilterRepository() { } public void assign(final FilterRepository rhs) { if (rhs != this) { filters.clear(); Iterator it = rhs.filters.iterator(); while (it.hasNext()) { filters.add(((Filter)it.next()).clone()); } active = rhs.active; fireFiltersChanged(); } } public Object clone() { FilterRepository ret = new FilterRepository(); ret.assign(this); return ret; } // Implementation of java.util.Set /** * Adds a new filter to the collection, if it was not present * already. * @param f the Filter to be added * @return true iff it was not member before and was added */ public boolean add(Object f) { if (filters.add(f)) { ((Filter)f).addPropertyChangeListener(filterChangeListener); fireFiltersChanged(); return true; } else { return false; } } public boolean addAll(Collection c) { boolean ret = filters.addAll(c); if (ret) { hookCollection(c); fireFiltersChanged(); } return ret; } public void add(int param, Object obj) { filters.add(param, obj); ((Filter)obj).addPropertyChangeListener(filterChangeListener); fireFiltersChanged(); } public boolean addAll(int param, java.util.Collection collection) { if (filters.addAll(param, collection)) { hookCollection(collection); fireFiltersChanged(); return true; } else return false; } public void clear() { if (!filters.isEmpty()) { setActive(null); unhookCollection(filters); filters.clear(); fireFiltersChanged(); } } /** * Returns true if this repository contains the specified filter. * @param f filter whose presence is to be tested * @return true if this repository contains the filter */ public boolean contains(Object f) { return filters.contains(f); } /** * Remove the filter specified by parameter from the collection. * * @param filter the Filter to remove * @return true iff the filter was found and removed */ public boolean remove(Object filter) { if (filter == getActive()) setActive(null); if (filters.remove(filter)) { ((Filter)filter).removePropertyChangeListener(filterChangeListener); return true; } else return false; } public boolean isEmpty() { return filters.isEmpty(); } public Iterator iterator() { return filters.iterator(); } /** * Describe |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.