KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > gumby > swing > widgets > JTablePeer


1 package org.sapia.gumby.swing.widgets;
2
3 import java.util.Vector JavaDoc;
4
5 import javax.swing.JTable JavaDoc;
6 import javax.swing.table.DefaultTableModel JavaDoc;
7
8 import org.sapia.util.xml.confix.ConfigurationException;
9 import org.sapia.util.xml.confix.ObjectCreationCallback;
10
11 /**
12  * @author Yanick Duchesne
13  *
14  * <dl>
15  * <dt><b>Copyright: </b>
16  * <dd>Copyright &#169; 2002-2005 <a HREF="http://www.sapia-oss.org">Sapia Open
17  * Source Software </a>. All Rights Reserved.</dd>
18  * </dt>
19  * <dt><b>License: </b>
20  * <dd>Read the license.txt file of the jar or visit the <a
21  * HREF="http://www.sapia-oss.org/license.html">license page </a> at the Sapia
22  * OSS web site</dd>
23  * </dt>
24  * </dl>
25  */

26 public class JTablePeer extends JTable JavaDoc implements ObjectCreationCallback {
27
28   static final long serialVersionUID = 1L;
29
30   private Vector JavaDoc _rows = new Vector JavaDoc();
31   private Vector JavaDoc _headers = new Vector JavaDoc();
32
33   public Row createTr() {
34     return new Row(this);
35   }
36
37   protected void addRow(Vector JavaDoc cols) {
38     _rows.add(cols);
39   }
40
41   public void addTh(String JavaDoc value) {
42     _headers.add(value);
43   }
44
45   /**
46    * @see org.sapia.util.xml.confix.ObjectCreationCallback#onCreate()
47    */

48   public Object JavaDoc onCreate() throws ConfigurationException {
49     DefaultTableModel JavaDoc model = new DefaultTableModel JavaDoc(_rows, _headers);
50     super.setModel(model);
51     return this;
52   }
53
54   public static final class Header implements ObjectCreationCallback {
55     private JTablePeer _owner;
56     private String JavaDoc _value;
57
58     public Header(JTablePeer owner) {
59       _owner = owner;
60     }
61
62     public void setValue(String JavaDoc value) {
63       _value = value;
64     }
65
66     public Object JavaDoc onCreate() throws ConfigurationException {
67       _owner.addTh(_value == null ? "" : _value);
68       return this;
69     }
70   }
71
72   public static final class Row implements ObjectCreationCallback {
73     private Vector JavaDoc _cols = new Vector JavaDoc();
74     private JTablePeer _owner;
75
76     Row(JTablePeer owner) {
77       _owner = owner;
78     }
79
80     public void addTd(Object JavaDoc colValue) {
81       _cols.add(colValue);
82     }
83
84     public Object JavaDoc onCreate() throws ConfigurationException {
85       _owner.addRow(_cols);
86       return this;
87     }
88   }
89
90 }
91
Popular Tags