1 26 27 package org.objectweb.util.browser.core.panel; 28 29 30 import javax.swing.JPanel ; 31 import java.awt.Color ; 32 import java.lang.reflect.Method ; 33 import java.lang.reflect.Field ; 34 import javax.swing.BoxLayout ; 35 import javax.swing.Box ; 36 import javax.swing.border.TitledBorder ; 37 38 39 import org.objectweb.util.browser.api.TreeView; 40 import org.objectweb.util.browser.api.Panel; 41 42 48 public class DefaultAssociatedPanel 49 implements Panel { 50 51 57 protected TreeView treeView_; 58 59 protected Object object_; 60 61 protected JPanel panel_; 62 63 69 72 public DefaultAssociatedPanel() { 73 panel_ = new JPanel (); 74 panel_.setBackground(Color.white); 75 panel_.setLayout(new BoxLayout (panel_, BoxLayout.Y_AXIS)); 76 } 77 78 84 protected JPanel addMethods() { 85 JPanel methodsPanel = new JPanel (); 86 methodsPanel.setBackground(Color.white); 87 methodsPanel.setBorder(new TitledBorder (null, " Methods ", TitledBorder.CENTER, TitledBorder.TOP)); 88 Box box = Box.createVerticalBox(); 89 Method [] methods = object_.getClass().getDeclaredMethods(); 90 for (int i = 0; i < methods.length; i++) { 91 box.add(new MethodGUI(methods[i], treeView_)); 92 } 93 methodsPanel.add(box); 94 return methodsPanel; 95 } 96 97 protected JPanel addFields() { 98 JPanel fieldsPanel = new JPanel (); 99 fieldsPanel.setBackground(Color.white); 100 fieldsPanel.setBorder(new TitledBorder (null, " Attributes ", TitledBorder.CENTER, TitledBorder.TOP)); 101 Box box = Box.createVerticalBox(); 102 Field [] fields = object_.getClass().getFields(); 103 for (int i = 0; i < fields.length; i++) { 104 box.add(new FieldGUI(fields[i], object_)); 105 } 106 fieldsPanel.add(box); 107 return fieldsPanel; 108 } 109 110 116 119 public void selected(TreeView treeView) { 120 treeView_ = treeView; 121 object_ = treeView_.getSelectedObject(); 122 if (object_ != null) { 123 panel_.add(addFields()); 124 panel_.add(addMethods()); 125 } 126 } 127 128 132 public JPanel getPanel(){ 133 return panel_; 134 } 135 136 137 140 public void unselected(TreeView treeView) { 141 } 142 143 } 144 | Popular Tags |