KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > table > TestModel


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.wcf.table;
14
15 import java.text.DecimalFormat JavaDoc;
16 import java.util.Date JavaDoc;
17 import java.util.Random JavaDoc;
18
19 /**
20  * a table model for testing
21  */

22
23 public class TestModel extends AbstractTableModel {
24   String JavaDoc[] columnTitles = { "String", "Date", "Double", "Integer", "Click Me", "Image 1", "Image 2" };
25   TableRow[] rows;
26   Random JavaDoc rnd = new Random JavaDoc(1234527L);
27   String JavaDoc title = "Test Table model";
28
29   public TestModel() {
30     int N = 20;
31     rows = new TableRow[N];
32     DecimalFormat JavaDoc df = new DecimalFormat JavaDoc("00");
33     for (int i = 0; i < N; i++) {
34       DefaultCell h1 = new DefaultCell("/", new Integer JavaDoc(rnd.nextInt(1000)), null);
35       DefaultCell h2 = new DefaultCell("/", null, nextImg());
36       DefaultCell h3 = new DefaultCell("/", "Text " + rnd.nextInt(100), nextImg());
37       String JavaDoc s = "2002-02-" + df.format(i + 1);
38       Object JavaDoc[] values = new Object JavaDoc[] {
39         "Hello World: " + i,
40         java.sql.Date.valueOf(s),
41         new Double JavaDoc((double)rnd.nextInt(10000) / (double)rnd.nextInt(100) ),
42         new Integer JavaDoc(rnd.nextInt(1000)),
43         h1, h2, h3
44       };
45       rows[i] = new DefaultTableRow(values);
46     }
47   }
48
49   public String JavaDoc 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 JavaDoc getColumnTitle(int columnIndex) {
65     return columnTitles[columnIndex];
66   }
67   public String JavaDoc getTitle() {
68     return title;
69   }
70   public void setTitle(String JavaDoc string) {
71     title = string;
72   }
73
74 }
Popular Tags