1 21 package net.mlw.vlh.swing.support; 22 23 import java.util.LinkedList ; 24 import java.util.List ; 25 26 import javax.swing.table.AbstractTableModel ; 27 28 import net.mlw.vlh.ValueList; 29 import net.mlw.vlh.swing.ValueListTableModel; 30 31 35 public abstract class AbstractValueListTableModel extends AbstractTableModel implements ValueListTableModel 36 { 37 protected List list = new LinkedList (); 38 39 protected int rowCount = 0; 40 41 44 public int getRowCount() 45 { 46 return rowCount; 47 } 48 49 public synchronized int addBean(Object bean) 50 { 51 list.add(bean); 52 return (rowCount = list.size()) - 1; 53 } 54 55 public Object getBean(int row) 56 { 57 if (row == -1 || list.size() < row) 58 { 59 return null; 60 } 61 return list.get(row); 62 } 63 64 public synchronized void setList(List list) 65 { 66 this.list = list; 67 this.rowCount = list.size(); 68 fireTableDataChanged(); 69 } 70 71 public synchronized void setValueList(ValueList valueList) 72 { 73 this.list = valueList.getList(); 74 this.rowCount = list.size(); 75 fireTableDataChanged(); 76 } 77 78 81 public synchronized int trimFromList(int index) 82 { 83 list.remove(index); 84 return (rowCount = list.size()) - 1; 85 } 86 87 90 public boolean contains(Object bean) 91 { 92 return list.contains(bean); 93 } 94 95 public synchronized int removeBean(Object bean) 96 { 97 int index = list.indexOf(bean); 98 if (index >= 0) 99 { 100 list.remove(index); 101 this.rowCount = list.size(); 102 } 103 return index; 104 } 105 } | Popular Tags |