1 4 package org.oddjob.monitor.view; 5 6 import java.awt.BorderLayout ; 7 import java.awt.Component ; 8 import java.util.Observable ; 9 import java.util.Observer ; 10 11 import javax.swing.JLabel ; 12 import javax.swing.JPanel ; 13 import javax.swing.JScrollPane ; 14 import javax.swing.JTable ; 15 import javax.swing.table.TableCellRenderer ; 16 17 import org.oddjob.monitor.model.PropertyModel; 18 19 24 public class PropertyPanel extends JPanel 25 implements Observer { 26 private static final long serialVersionUID = 0; 27 28 private PropertyTableModel tableModel; 29 30 35 public PropertyPanel(PropertyModel propertyModel) { 36 propertyModel.addObserver(this); 37 38 tableModel = new PropertyTableModel(); 39 JTable propTable = new JTable (tableModel); 40 41 propTable.getColumnModel().getColumn(0).setCellRenderer(new PropertyRenderer()); 42 propTable.getColumnModel().getColumn(1).setCellRenderer(new PropertyRenderer()); 43 JScrollPane formScroll = new JScrollPane (); 44 formScroll.setViewportView(propTable); 45 46 setLayout(new BorderLayout ()); 47 add(formScroll, BorderLayout.CENTER); 48 } 49 50 55 class PropertyRenderer extends JLabel 56 implements TableCellRenderer { 57 private static final long serialVersionUID = 0; 58 59 63 public Component getTableCellRendererComponent( 64 JTable table, Object value, 65 boolean isSelected, boolean hasFocus, 66 int row, int column) { 67 String text = (String ) value; 68 setText(text); 69 setToolTipText(text); 70 return this; 71 } 72 } 73 74 80 public void update(Observable o, Object arg) { 81 PropertyModel propertyModel = (PropertyModel) o; 82 tableModel.update(propertyModel.getProperties()); 83 } 84 } 85 | Popular Tags |