1 26 27 package org.objectweb.util.browser.core.panel; 28 29 30 import java.lang.reflect.Field ; 31 import javax.swing.JButton ; 32 import javax.swing.JLabel ; 33 import javax.swing.BoxLayout ; 34 import java.awt.Dimension ; 35 import java.awt.event.ActionListener ; 36 import java.awt.event.ActionEvent ; 37 import java.awt.Color ; 38 import javax.swing.Box ; 39 40 48 public class FieldGUI extends Box { 49 50 protected Object object_; 51 protected Field field_; 52 53 public FieldGUI(Field field, Object object) { 54 super(BoxLayout.X_AXIS); 55 field_ = field; 56 object_ = object; 57 setBackground(Color.white); 58 add(Box.createHorizontalGlue()); 59 Class type = field_.getType(); 60 int lastIndex = type.getName().lastIndexOf('.'); 61 JLabel label = null; 62 if (lastIndex != -1) 63 label = new JLabel (field.getName() + " : " + type.getName().substring(lastIndex + 1)); 64 else 65 label = new JLabel (field.getName() + " : " + type.getName()); 66 label.setPreferredSize(new Dimension (350, 20)); 67 add(label); 68 add(Box.createHorizontalStrut(10)); 69 JButton value = new JButton ("Value"); 70 value.setPreferredSize(new Dimension (80, 20)); 71 value.addActionListener(new ValueAction()); 72 add(value); 73 add(Box.createHorizontalGlue()); 74 } 75 76 protected class ValueAction implements ActionListener { 77 public void actionPerformed(ActionEvent e) { 78 try { 79 System.out.println(field_.get(object_).toString()); 80 } catch (java.lang.IllegalAccessException ex) { 81 ex.printStackTrace(); 82 } catch (java.lang.IllegalArgumentException ex) { 83 ex.printStackTrace(); 84 } 85 } 86 } 87 } 88 | Popular Tags |