1 7 8 package org.gjt.jclasslib.browser.detail; 9 10 import org.gjt.jclasslib.browser.AbstractDetailPane; 11 import org.gjt.jclasslib.browser.BrowserServices; 12 import org.gjt.jclasslib.browser.detail.attributes.*; 13 import org.gjt.jclasslib.structures.AttributeInfo; 14 import org.gjt.jclasslib.structures.attributes.*; 15 16 import javax.swing.*; 17 import javax.swing.border.Border ; 18 import javax.swing.tree.TreePath ; 19 import java.awt.*; 20 import java.util.HashMap ; 21 22 30 public class AttributeDetailPane extends AbstractDetailPane { 31 32 private static final String SCREEN_UNKNOWN = "Unknown"; 33 private static final String SCREEN_CONSTANT_VALUE = "ConstantValue"; 34 private static final String SCREEN_CODE = "Code"; 35 private static final String SCREEN_EXCEPTIONS = "Exceptions"; 36 private static final String SCREEN_INNER_CLASSES = "InnerClasses"; 37 private static final String SCREEN_SOURCE_FILE = "SourceFile"; 38 private static final String SCREEN_LINE_NUMBER_TABLE = "LineNumberTable"; 39 private static final String SCREEN_LOCAL_VARIABLE_TABLE = "LocalVariableTable"; 40 private static final String SCREEN_ENCLOSING_METHOD = "EnclosingMethod"; 41 private static final String SCREEN_SIGNATURE = "Signature"; 42 private static final String SCREEN_LOCAL_VARIABLE_TYPE_TABLE = "LocalVariableTypeTable"; 43 private static final String SCREEN_RUNTIME_ANNOTATIONS = "RuntimeAnnotations"; 44 private static final String SCREEN_ANNOTATION_DEFAULT = "AnnotationDefault"; 45 46 private HashMap attributeTypeToDetailPane; 47 48 50 private JPanel specificInfoPane; 51 private GenericAttributeDetailPane genericInfoPane; 52 53 58 public AttributeDetailPane(BrowserServices services) { 59 super(services); 60 } 61 62 protected void setupComponent() { 63 64 buildGenericInfoPane(); 65 buildSpecificInfoPane(); 66 67 setLayout(new BorderLayout()); 68 69 add(genericInfoPane, BorderLayout.NORTH); 70 add(specificInfoPane, BorderLayout.CENTER); 71 72 } 73 74 public void show(TreePath treePath) { 75 76 AttributeInfo attribute = findAttribute(treePath); 77 78 String paneName = null; 79 if (attribute instanceof ConstantValueAttribute) { 80 paneName = SCREEN_CONSTANT_VALUE; 81 } else if (attribute instanceof CodeAttribute) { 82 paneName = SCREEN_CODE; 83 } else if (attribute instanceof ExceptionsAttribute) { 84 paneName = SCREEN_EXCEPTIONS; 85 } else if (attribute instanceof InnerClassesAttribute) { 86 paneName = SCREEN_INNER_CLASSES; 87 } else if (attribute instanceof SourceFileAttribute) { 88 paneName = SCREEN_SOURCE_FILE; 89 } else if (attribute instanceof LineNumberTableAttribute) { 90 paneName = SCREEN_LINE_NUMBER_TABLE; 91 } else if (attribute instanceof LocalVariableTableAttribute) { 92 paneName = SCREEN_LOCAL_VARIABLE_TABLE; 93 } else if (attribute instanceof EnclosingMethodAttribute) { 94 paneName = SCREEN_ENCLOSING_METHOD; 95 } else if (attribute instanceof SignatureAttribute) { 96 paneName = SCREEN_SIGNATURE; 97 } else if (attribute instanceof LocalVariableTypeTableAttribute) { 98 paneName = SCREEN_LOCAL_VARIABLE_TYPE_TABLE; 99 } else if (attribute instanceof RuntimeAnnotationsAttribute) { 100 paneName = SCREEN_RUNTIME_ANNOTATIONS; 101 } else if (attribute instanceof AnnotationDefaultAttribute) { 102 paneName = SCREEN_ANNOTATION_DEFAULT; 103 } 104 105 CardLayout layout = (CardLayout)specificInfoPane.getLayout(); 106 if (paneName == null) { 107 layout.show(specificInfoPane, SCREEN_UNKNOWN); 108 } else { 109 AbstractDetailPane pane = (AbstractDetailPane)attributeTypeToDetailPane.get(paneName); 110 pane.show(treePath); 111 layout.show(specificInfoPane, paneName); 112 } 113 114 genericInfoPane.show(treePath); 115 } 116 117 123 public CodeAttributeDetailPane getCodeAttributeDetailPane() { 124 return (CodeAttributeDetailPane)attributeTypeToDetailPane.get(SCREEN_CODE); 125 } 126 127 private void buildGenericInfoPane() { 128 129 genericInfoPane = new GenericAttributeDetailPane(services); 130 genericInfoPane.setBorder(createTitledBorder("Generic info:")); 131 } 132 133 private void buildSpecificInfoPane() { 134 135 specificInfoPane = new JPanel(); 136 specificInfoPane.setBorder(createTitledBorder("Specific info:")); 137 138 specificInfoPane.setLayout(new CardLayout()); 139 attributeTypeToDetailPane = new HashMap (); 140 JPanel pane; 141 142 pane = new JPanel(); 143 specificInfoPane.add(pane, SCREEN_UNKNOWN); 144 145 addScreen(new ConstantValueAttributeDetailPane(services), 146 SCREEN_CONSTANT_VALUE); 147 148 addScreen(new CodeAttributeDetailPane(services), 149 SCREEN_CODE); 150 151 addScreen(new ExceptionsAttributeDetailPane(services), 152 SCREEN_EXCEPTIONS); 153 154 addScreen(new InnerClassesAttributeDetailPane(services), 155 SCREEN_INNER_CLASSES); 156 157 addScreen(new SourceFileAttributeDetailPane(services), 158 SCREEN_SOURCE_FILE); 159 160 addScreen(new LineNumberTableAttributeDetailPane(services), 161 SCREEN_LINE_NUMBER_TABLE); 162 163 addScreen(new LocalVariableTableAttributeDetailPane(services), 164 SCREEN_LOCAL_VARIABLE_TABLE); 165 166 addScreen(new EnclosingMethodAttributeDetailPane(services), 167 SCREEN_ENCLOSING_METHOD); 168 169 addScreen(new SignatureAttributeDetailPane(services), 170 SCREEN_SIGNATURE); 171 172 addScreen(new LocalVariableTypeTableAttributeDetailPane(services), 173 SCREEN_LOCAL_VARIABLE_TYPE_TABLE); 174 175 addScreen(new RuntimeAnnotationsAttributeDetailPane(services), 176 SCREEN_RUNTIME_ANNOTATIONS); 177 178 addScreen(new AnnotationDefaultAttributeDetailPane(services), 179 SCREEN_ANNOTATION_DEFAULT); 180 } 181 182 private void addScreen(AbstractDetailPane detailPane, String name) { 183 184 if (detailPane instanceof FixedListDetailPane) { 185 specificInfoPane.add(((FixedListDetailPane)detailPane).getScrollPane(), name); 186 } else { 187 specificInfoPane.add(detailPane, name); 188 } 189 attributeTypeToDetailPane.put(name, detailPane); 190 } 191 192 private Border createTitledBorder(String title) { 193 Border simpleBorder = BorderFactory.createEtchedBorder(); 194 Border titledBorder = BorderFactory.createTitledBorder(simpleBorder, title); 195 196 return titledBorder; 197 } 198 } 199 200 | Popular Tags |