1 7 8 package org.jdesktop.dataset; 9 10 import java.beans.PropertyChangeListener ; 11 import java.beans.PropertyChangeSupport ; 12 import java.util.ArrayList ; 13 import java.util.BitSet ; 14 import java.util.Collections ; 15 import java.util.List ; 16 import org.jdesktop.dataset.NameGenerator; 17 18 22 public class DataSelector { 23 protected static final String DEFAULT_NAME_PREFIX = "DataSelector"; 25 private static final NameGenerator NAMEGEN = new NameGenerator(DEFAULT_NAME_PREFIX); 26 27 private DataTable table; 28 private String name; 29 33 private BitSet indices = new BitSet (0); 34 private PropertyChangeSupport pcs = new PropertyChangeSupport (this); 35 36 37 public DataSelector(DataTable table) { 38 assert table != null; 39 this.table = table; 40 name = NAMEGEN.generateName(this); 41 } 42 43 public DataTable getDataTable() { 44 return table; 45 } 46 47 50 public void setName(String name) { 51 if (this.name != name) { 52 assert name != null && !name.trim().equals(""); 53 String oldName = this.name; 54 this.name = name; 55 pcs.firePropertyChange("name", oldName, name); 56 } 57 } 58 59 public String getName() { 60 return name; 61 } 62 63 public List <Integer > getRowIndices() { 64 List <Integer > results = new ArrayList <Integer >(indices.cardinality()); 65 int n=-1; 66 for(int i=0; i<indices.cardinality(); i++) { 67 n = indices.nextSetBit(n+1); 68 results.add(n); 69 } 70 return Collections.unmodifiableList(results); 71 } 72 73 public void setRowIndices(int[] rowIndices) { 74 List oldIndices = getRowIndices(); 76 indices.clear(); 77 for (int index : rowIndices) { 78 indices.set(index); 79 } 80 pcs.firePropertyChange("rowIndices", oldIndices, getRowIndices()); 85 } 86 87 public void addPropertyChangeListener(PropertyChangeListener listener) { 88 pcs.addPropertyChangeListener(listener); 89 } 90 91 public void addPropertyChangeListener(String property, PropertyChangeListener listener) { 92 pcs.addPropertyChangeListener(property, listener); 93 } 94 95 public void removePropertyChangeListener(PropertyChangeListener listener) { 96 pcs.removePropertyChangeListener(listener); 97 } 98 99 public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { 100 pcs.removePropertyChangeListener(propertyName, listener); 101 } 102 103 } 104 | Popular Tags |