KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > panoptes > view > swing > tables > ContextTableModel


1 /*
2  * Created on Sep 4, 2003
3  *
4  */

5 package net.sf.panoptes.view.swing.tables;
6
7 import java.util.ArrayList JavaDoc;
8
9 import javax.swing.table.AbstractTableModel JavaDoc;
10
11 import net.sf.panoptes.model.node.NodeSupport;
12
13 /**
14  *
15  *
16  * @author Dag Liodden
17  * @version 0.1
18  */

19 public class ContextTableModel extends AbstractTableModel JavaDoc {
20
21     private ArrayList JavaDoc contextKeys = new ArrayList JavaDoc();
22     private NodeSupport.Context context = null;
23
24     public ContextTableModel() {
25     }
26
27     public void setContext(NodeSupport.Context context) {
28         this.context = context;
29         contextKeys = new ArrayList JavaDoc(context.keySet());
30         fireTableDataChanged();
31     }
32
33     public int getColumnCount() {
34         return 3;
35     }
36
37     public int getRowCount() {
38         return contextKeys.size();
39     }
40
41     public String JavaDoc getColumnName(int columnIndex) {
42         switch (columnIndex) {
43             case 0 :
44                 return "Name";
45             case 1 :
46                 return "Value";
47             case 2 :
48                 return "Class";
49             default :
50                 return "Uknown column";
51         }
52
53     }
54
55     public Object JavaDoc getValueAt(int rowIndex, int columnIndex) {
56         Object JavaDoc key = contextKeys.get(rowIndex);
57         switch (columnIndex) {
58             case 0 :
59                 return key;
60             case 1 :
61                 return context.get(key);
62             case 2 :
63                 Object JavaDoc value = context.get(key);
64                 return value == null ? "" : value.getClass().getName();
65             default :
66                 return "Unknown column";
67         }
68     }
69 }
70
71
Popular Tags