1 13 package com.tonbeller.wcf.table; 14 15 import java.util.Arrays ; 16 import java.util.Comparator ; 17 18 21 22 class SortedTableModel extends TableModelDecorator { 23 TableRow[] data = null; 24 25 public SortedTableModel() { 26 } 27 28 public SortedTableModel(TableModel model) { 29 super(model); 30 } 31 32 33 public int getRowCount() { 34 if (data == null) 35 return super.getRowCount(); 36 return data.length; 37 } 38 39 public TableRow getRow(int index) { 40 if (data == null) 41 return super.getRow(index); 42 return data[index]; 43 } 44 45 public void unSort() { 46 data = null; 47 } 48 49 public void sort(Comparator compare) { 50 int N = super.getRowCount(); 51 data = new TableRow[N]; 52 for (int i = 0; i < N; i++) 53 data[i] = super.getRow(i); 54 Arrays.sort(data, compare); 55 } 56 57 public void tableModelChanged(TableModelChangeEvent event) { 58 data = null; 59 } 60 61 } 62 | Popular Tags |