1 8 package com.nightlabs.editor2d.filter; 9 10 import java.beans.PropertyChangeListener ; 11 import java.beans.PropertyChangeSupport ; 12 import java.util.ArrayList ; 13 import java.util.Collection ; 14 import java.util.List ; 15 import java.util.Map ; 16 17 import com.nightlabs.editor2d.DrawComponent; 18 19 22 public class FilterManager 23 { 24 public static final String FILTER_CHANGED = "Filter changed"; 25 26 protected Map filter2FilterName; 27 public String getTypeName(Class clazz) 28 { 29 try { 30 Object o = clazz.newInstance(); 31 if (o instanceof DrawComponent) 32 return ((DrawComponent)o).getTypeName(); 33 } catch (InstantiationException e) { 34 return clazz.getName(); 35 } catch (IllegalAccessException e) { 36 return clazz.getName(); 37 } 38 return clazz.getName(); 39 } 40 41 46 protected List filters; 47 protected List allFilters; 48 public FilterManager() { 49 super(); 50 } 51 52 public void addFilter(Class clazz) 53 { 54 if (clazz == null) 55 throw new IllegalArgumentException ("Param clazz must not be null!"); 56 57 getFilters().add(clazz); 58 getAllFilters().add(clazz); 59 } 60 61 public void addFilters(Collection classes) 62 { 63 if (classes == null) 64 throw new IllegalArgumentException ("Param classes must not be null!"); 65 66 getFilters().addAll(classes); 67 getAllFilters().addAll(classes); 68 } 69 70 public List getFilters() 71 { 72 if (filters == null) 73 filters = new ArrayList (); 74 75 return filters; 76 } 77 78 public List getAllFilters() 79 { 80 if (allFilters == null) 81 allFilters = new ArrayList (); 82 83 return allFilters; 84 } 85 86 public void setFilter(Class clazz) 87 { 88 if (clazz == null) 89 throw new IllegalArgumentException ("Param clazz must not be null!"); 90 91 getFilters().clear(); 92 getFilters().add(clazz); 93 pcs.firePropertyChange(FILTER_CHANGED, null, getFilters()); 94 } 95 96 public void setFilter(Collection classes) 97 { 98 if (classes == null) 99 throw new IllegalArgumentException ("Param classes must not be null!"); 100 101 getFilters().clear(); 102 getFilters().addAll(classes); 103 pcs.firePropertyChange(FILTER_CHANGED, null, getFilters()); 104 } 105 106 public void setAllFiltersAvailable() { 107 setFilter(getAllFilters()); 108 } 109 110 public boolean isAllFilterSet() { 111 if (filters != null && allFilters != null) { 112 if (filters.size() == allFilters.size()) 113 return true; 114 else 115 return false; 116 } 117 return true; 118 } 119 120 protected PropertyChangeSupport pcs = new PropertyChangeSupport (this); 121 public void addPropertyChangeListener(PropertyChangeListener pcl) { 122 pcs.addPropertyChangeListener(pcl); 123 } 124 public void removePropertyChangeListener(PropertyChangeListener pcl) { 125 pcs.removePropertyChangeListener(pcl); 126 } 127 } 128
| Popular Tags
|