KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > monitor > view > PropertyTableModel


1 package org.oddjob.monitor.view;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5 import java.util.Map JavaDoc;
6
7 import javax.swing.event.TableModelEvent JavaDoc;
8 import javax.swing.table.AbstractTableModel JavaDoc;
9
10 /**
11  * Model for a table to display properties.
12  *
13  * @author Rob Gordon
14  */

15
16 public class PropertyTableModel extends AbstractTableModel JavaDoc {
17     private static final long serialVersionUID = 20051109;
18     
19     /** The keys */
20     private List JavaDoc keys = new ArrayList JavaDoc();
21     
22     /** The props. */
23     private List JavaDoc values = new ArrayList JavaDoc();
24         
25     private final String JavaDoc colNames[] = { "Name", "Value" };
26
27     public void update(Map JavaDoc props) {
28         keys = new ArrayList JavaDoc(props.keySet());
29         values = new ArrayList JavaDoc(props.values());
30         fireTableChanged(new TableModelEvent JavaDoc(this));
31     }
32
33     /**
34      * @see javax.swing.table.TableModel#getRowCount()
35      */

36     public int getRowCount() {
37         return keys.size();
38     }
39
40     /**
41      * @see javax.swing.table.TableModel#getColumnCount()
42      */

43     public int getColumnCount() {
44         return 2;
45     }
46
47     /**
48      * @see javax.swing.table.TableModel#getColumnName(int)
49      */

50     public String JavaDoc getColumnName(int columnIndex) {
51         return colNames[columnIndex];
52     }
53
54     /**
55      * @see javax.swing.table.TableModel#getValueAt(int, int)
56      */

57     public Object JavaDoc getValueAt(int rowIndex, int columnIndex) {
58         if (columnIndex == 0) {
59             return keys.get(rowIndex);
60         }
61         else {
62             return values.get(rowIndex);
63         }
64     }
65 }
66
Popular Tags