1 7 8 package org.gjt.jclasslib.browser.detail; 9 10 import org.gjt.jclasslib.browser.*; 11 import org.gjt.jclasslib.browser.detail.constants.*; 12 import org.gjt.jclasslib.structures.CPInfo; 13 import org.gjt.jclasslib.structures.constants.*; 14 15 import javax.swing.*; 16 import javax.swing.tree.TreePath ; 17 import java.awt.*; 18 import java.util.HashMap ; 19 20 28 public class ConstantPoolDetailPane extends AbstractDetailPane { 29 30 private static final String SCREEN_CONSTANT_UTF8_INFO = "ConstantUtf8Info"; 31 private static final String SCREEN_CONSTANT_UNKNOWN = "ConstantUnknown"; 32 private static final String SCREEN_CONSTANT_CLASS_INFO = "ConstantClassInfo"; 33 private static final String SCREEN_CONSTANT_DOUBLE_INFO = "ConstantDoubleInfo"; 34 private static final String SCREEN_CONSTANT_LONG_INFO = "ConstantLongInfo"; 35 private static final String SCREEN_CONSTANT_FLOAT_INFO = "ConstantFloatInfo"; 36 private static final String SCREEN_CONSTANT_INTEGER_INFO = "ConstantIntegerInfo"; 37 private static final String SCREEN_CONSTANT_NAME_AND_TYPE_INFO = "ConstantNameAndTypeInfo"; 38 private static final String SCREEN_CONSTANT_STRING_INFO = "ConstantStringInfo"; 39 private static final String SCREEN_CONSTANT_REFERENCE = "ConstantReference"; 40 41 private HashMap constantTypeToDetailPane; 42 43 47 public ConstantPoolDetailPane(BrowserServices services) { 48 super(services); 49 } 50 51 protected void setupComponent() { 52 setLayout(new CardLayout()); 53 constantTypeToDetailPane = new HashMap (); 54 JPanel pane; 55 56 pane = new JPanel(); 57 pane.setBackground(Color.blue); 58 add(pane, SCREEN_CONSTANT_UNKNOWN); 59 60 addScreen(new ConstantUtf8InfoDetailPane(services), 61 SCREEN_CONSTANT_UTF8_INFO); 62 63 addScreen(new ConstantClassInfoDetailPane(services), 64 SCREEN_CONSTANT_CLASS_INFO); 65 66 addScreen(new ConstantDoubleInfoDetailPane(services), 67 SCREEN_CONSTANT_DOUBLE_INFO); 68 69 addScreen(new ConstantLongInfoDetailPane(services), 70 SCREEN_CONSTANT_LONG_INFO); 71 72 addScreen(new ConstantFloatInfoDetailPane(services), 73 SCREEN_CONSTANT_FLOAT_INFO); 74 75 addScreen(new ConstantIntegerInfoDetailPane(services), 76 SCREEN_CONSTANT_INTEGER_INFO); 77 78 addScreen(new ConstantNameAndTypeInfoDetailPane(services), 79 SCREEN_CONSTANT_NAME_AND_TYPE_INFO); 80 81 addScreen(new ConstantStringInfoDetailPane(services), 82 SCREEN_CONSTANT_STRING_INFO); 83 84 addScreen(new ConstantReferenceDetailPane(services), 85 SCREEN_CONSTANT_REFERENCE); 86 87 } 88 89 public void show(TreePath treePath) { 90 91 int constantPoolIndex = ((BrowserTreeNode)treePath.getLastPathComponent()).getIndex(); 92 CPInfo constantPoolEntry = services.getClassFile().getConstantPool()[constantPoolIndex]; 93 94 String paneName = null; 95 if (constantPoolEntry instanceof ConstantUtf8Info) { 96 paneName = SCREEN_CONSTANT_UTF8_INFO; 97 } else if (constantPoolEntry instanceof ConstantClassInfo) { 98 paneName = SCREEN_CONSTANT_CLASS_INFO; 99 } else if (constantPoolEntry instanceof ConstantDoubleInfo) { 100 paneName = SCREEN_CONSTANT_DOUBLE_INFO; 101 } else if (constantPoolEntry instanceof ConstantLongInfo) { 102 paneName = SCREEN_CONSTANT_LONG_INFO; 103 } else if (constantPoolEntry instanceof ConstantFloatInfo) { 104 paneName = SCREEN_CONSTANT_FLOAT_INFO; 105 } else if (constantPoolEntry instanceof ConstantIntegerInfo) { 106 paneName = SCREEN_CONSTANT_INTEGER_INFO; 107 } else if (constantPoolEntry instanceof ConstantNameAndTypeInfo) { 108 paneName = SCREEN_CONSTANT_NAME_AND_TYPE_INFO; 109 } else if (constantPoolEntry instanceof ConstantStringInfo) { 110 paneName = SCREEN_CONSTANT_STRING_INFO; 111 } else if (constantPoolEntry instanceof ConstantReference) { 112 paneName = SCREEN_CONSTANT_REFERENCE; 113 } 114 115 116 CardLayout layout = (CardLayout)getLayout(); 117 if (paneName == null) { 118 layout.show(this, SCREEN_CONSTANT_UNKNOWN); 119 } else { 120 AbstractDetailPane pane = (AbstractDetailPane)constantTypeToDetailPane.get(paneName); 121 pane.show(treePath); 122 layout.show(this, paneName); 123 } 124 125 } 126 127 private void addScreen(AbstractDetailPane detailPane, String name) { 128 129 if (detailPane instanceof FixedListDetailPane) { 130 add(((FixedListDetailPane)detailPane).getScrollPane(), name); 131 } else { 132 add(detailPane, name); 133 } 134 constantTypeToDetailPane.put(name, detailPane); 135 } 136 137 } 138 139 | Popular Tags |