1 13 package com.tonbeller.wcf.table; 14 15 import java.text.DecimalFormat ; 16 import java.util.Date ; 17 import java.util.Random ; 18 19 22 23 public class TestModel extends AbstractTableModel { 24 String [] columnTitles = { "String", "Date", "Double", "Integer", "Click Me", "Image 1", "Image 2" }; 25 TableRow[] rows; 26 Random rnd = new Random (1234527L); 27 String title = "Test Table model"; 28 29 public TestModel() { 30 int N = 20; 31 rows = new TableRow[N]; 32 DecimalFormat df = new DecimalFormat ("00"); 33 for (int i = 0; i < N; i++) { 34 DefaultCell h1 = new DefaultCell("/", new Integer (rnd.nextInt(1000)), null); 35 DefaultCell h2 = new DefaultCell("/", null, nextImg()); 36 DefaultCell h3 = new DefaultCell("/", "Text " + rnd.nextInt(100), nextImg()); 37 String s = "2002-02-" + df.format(i + 1); 38 Object [] values = new Object [] { 39 "Hello World: " + i, 40 java.sql.Date.valueOf(s), 41 new Double ((double)rnd.nextInt(10000) / (double)rnd.nextInt(100) ), 42 new Integer (rnd.nextInt(1000)), 43 h1, h2, h3 44 }; 45 rows[i] = new DefaultTableRow(values); 46 } 47 } 48 49 public String nextImg() { 50 if (rnd.nextBoolean()) 51 return "wcf/table/sort-ac.png"; 52 return "wcf/table/sort-dn.png"; 53 } 54 55 public int getRowCount() { 56 return rows.length; 57 } 58 public TableRow getRow(int rowIndex) { 59 return rows[rowIndex]; 60 } 61 public int getColumnCount() { 62 return columnTitles.length; 63 } 64 public String getColumnTitle(int columnIndex) { 65 return columnTitles[columnIndex]; 66 } 67 public String getTitle() { 68 return title; 69 } 70 public void setTitle(String string) { 71 title = string; 72 } 73 74 } | Popular Tags |