KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob.monitor.view;
5
6 import java.awt.BorderLayout JavaDoc;
7 import java.awt.Component JavaDoc;
8 import java.util.Observable JavaDoc;
9 import java.util.Observer JavaDoc;
10
11 import javax.swing.JLabel JavaDoc;
12 import javax.swing.JPanel JavaDoc;
13 import javax.swing.JScrollPane JavaDoc;
14 import javax.swing.JTable JavaDoc;
15 import javax.swing.table.TableCellRenderer JavaDoc;
16
17 import org.oddjob.monitor.model.PropertyModel;
18
19 /**
20  * The Tab Panel for properties.
21  *
22  * @author Rob Gordonl.
23  */

24 public class PropertyPanel extends JPanel JavaDoc
25 implements Observer JavaDoc {
26     private static final long serialVersionUID = 0;
27     
28     private PropertyTableModel tableModel;
29     
30     /**
31      * Constructor.
32      *
33      * @param propertyModel
34      */

35     public PropertyPanel(PropertyModel propertyModel) {
36         propertyModel.addObserver(this);
37
38         tableModel = new PropertyTableModel();
39         JTable JavaDoc propTable = new JTable JavaDoc(tableModel);
40         
41         propTable.getColumnModel().getColumn(0).setCellRenderer(new PropertyRenderer());
42         propTable.getColumnModel().getColumn(1).setCellRenderer(new PropertyRenderer());
43         JScrollPane JavaDoc formScroll = new JScrollPane JavaDoc();
44         formScroll.setViewportView(propTable);
45         
46         setLayout(new BorderLayout JavaDoc());
47         add(formScroll, BorderLayout.CENTER);
48     }
49     
50     /**
51      * This custom renderer just sets the tool tip text
52      * to be the full text of the property.
53      *
54      */

55     class PropertyRenderer extends JLabel JavaDoc
56     implements TableCellRenderer JavaDoc {
57         private static final long serialVersionUID = 0;
58
59         /*
60          * (non-Javadoc)
61          * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
62          */

63         public Component JavaDoc getTableCellRendererComponent(
64                 JTable JavaDoc table, Object JavaDoc value,
65                 boolean isSelected, boolean hasFocus,
66                 int row, int column) {
67             String JavaDoc text = (String JavaDoc) value;
68             setText(text);
69             setToolTipText(text);
70             return this;
71         }
72     }
73     
74     /**
75      * Update from the PropertyModel.
76      *
77      * @param o The PropertyModel.
78      * @param arg Ignored.
79      */

80     public void update(Observable JavaDoc o, Object JavaDoc arg) {
81         PropertyModel propertyModel = (PropertyModel) o;
82         tableModel.update(propertyModel.getProperties());
83     }
84 }
85
Popular Tags