KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.Comparator JavaDoc;
15
16 /**
17  * describes a TableColumn via the following properties:
18  * <ul>
19  * <li> sorting properties (ascending/descending)
20  * <li> how the values are compared (Comparator) for sorting
21  * <li> how the values are rendered
22  * </ul>
23  */

24
25 public class TableColumn {
26
27   private boolean descending = false;
28   private boolean sortable = true;
29   private Comparator JavaDoc comparator;
30   private CellRenderer renderer;
31   private int columnIndex;
32   private boolean hidden = false;
33
34   public TableColumn(int columnIndex) {
35     this.columnIndex = columnIndex;
36     comparator = new Comparator JavaDoc() {
37       public int compare(Object JavaDoc o1, Object JavaDoc o2) {
38         if (o1 instanceof Boolean JavaDoc) {
39           boolean b1 = ((Boolean JavaDoc) o1).booleanValue();
40           boolean b2 = ((Boolean JavaDoc) o2).booleanValue();
41           if (b1 == b2)
42             return 0;
43           if (b1)
44             return 1;
45           return -1;
46         }
47         return ((Comparable JavaDoc) o1).compareTo(o2);
48       }
49     };
50     renderer = new DefaultCellRenderer();
51   }
52
53   public void setDescending(boolean newDescending) {
54     descending = newDescending;
55   }
56   public boolean isDescending() {
57     return descending;
58   }
59   public void setComparator(Comparator JavaDoc newComparator) {
60     comparator = newComparator;
61   }
62   public Comparator JavaDoc getComparator() {
63     return comparator;
64   }
65   public void setCellRenderer(CellRenderer newRenderer) {
66     renderer = newRenderer;
67   }
68   public CellRenderer getCellRenderer() {
69     return renderer;
70   }
71   public void setSortable(boolean newSortable) {
72     sortable = newSortable;
73   }
74   public boolean isSortable() {
75     return sortable;
76   }
77
78   /**
79    * the column index for TableRow.getValue() that this TableColumn that
80    * is displayed by this table column.
81    * The following is <em>not</em> true, after the
82    * user has swapped columns:
83    * <pre><code>
84    * TableComponent.getTableColumn(index).getColumnIndex() == index
85    * </code></pre>
86    *
87    * @return
88    */

89   public int getColumnIndex() {
90     return columnIndex;
91   }
92   public void setHidden(boolean newHidden) {
93     hidden = newHidden;
94   }
95   public boolean isHidden() {
96     return hidden;
97   }
98 }
99
Popular Tags