1 7 package org.gjt.jclasslib.browser.detail; 8 9 import org.gjt.jclasslib.browser.*; 10 import org.gjt.jclasslib.browser.detail.elementvalues.*; 11 import org.gjt.jclasslib.structures.elementvalues.*; 12 13 import javax.swing.*; 14 import javax.swing.border.Border ; 15 import javax.swing.tree.TreePath ; 16 import java.awt.*; 17 import java.util.HashMap ; 18 19 26 public class ElementValueDetailPane extends AbstractDetailPane { 27 28 private static final String SCREEN_UNKNOWN = "Unknown"; 29 private static final String SCREEN_CONST_VALUE = "Const"; 30 private static final String SCREEN_CLASS_VALUE = "Class"; 31 private static final String SCREEN_ENUM_VALUE = "Enum"; 32 33 34 private HashMap elementTypeToDetailPane; 35 36 38 private JPanel specificInfoPane; 39 private GenericElementValueDetailPane genericInfoPane; 40 41 public ElementValueDetailPane(BrowserServices services) { 42 super(services); 43 } 44 45 protected void setupComponent() { 46 buildGenericInfoPane(); 47 buildSpecificInfoPane(); 48 49 setLayout(new BorderLayout()); 50 51 add(genericInfoPane, BorderLayout.NORTH); 52 add(specificInfoPane, BorderLayout.CENTER); 53 } 54 55 public void show(TreePath treePath) { 56 ElementValue eve = (ElementValue) 57 ((BrowserTreeNode)treePath.getLastPathComponent()).getElement(); 58 59 String paneName = null; 60 if (eve instanceof ConstElementValue) { 61 paneName = SCREEN_CONST_VALUE; 62 } else if (eve instanceof ClassElementValue) { 63 paneName = SCREEN_CLASS_VALUE; 64 } else if (eve instanceof EnumElementValue) { 65 paneName = SCREEN_ENUM_VALUE; 66 } 67 68 CardLayout layout = (CardLayout)specificInfoPane.getLayout(); 69 if (paneName == null) { 70 layout.show(specificInfoPane, SCREEN_UNKNOWN); 71 } else { 72 AbstractDetailPane pane = (AbstractDetailPane)elementTypeToDetailPane.get(paneName); 73 pane.show(treePath); 74 layout.show(specificInfoPane, paneName); 75 } 76 genericInfoPane.show(treePath); 77 } 78 79 80 private void buildGenericInfoPane() { 81 genericInfoPane = new GenericElementValueDetailPane(services); 82 genericInfoPane.setBorder(createTitledBorder("Generic info:")); 83 } 84 85 private void buildSpecificInfoPane() { 86 specificInfoPane = new JPanel(); 87 specificInfoPane.setBorder(createTitledBorder("Specific info:")); 88 89 specificInfoPane.setLayout(new CardLayout()); 90 elementTypeToDetailPane = new HashMap (); 91 JPanel pane; 92 93 pane = new JPanel(); 94 specificInfoPane.add(pane, SCREEN_UNKNOWN); 95 96 addScreen(new ConstElementValueEntryDetailPane(services), 97 SCREEN_CONST_VALUE); 98 addScreen(new ClassElementValueEntryDetailPane(services), 99 SCREEN_CLASS_VALUE); 100 addScreen(new EnumElementValueEntryDetailPane(services), 101 SCREEN_ENUM_VALUE); 102 } 103 104 private void addScreen(AbstractDetailPane detailPane, String name) { 105 if (detailPane instanceof FixedListDetailPane) { 106 specificInfoPane.add(((FixedListDetailPane)detailPane).getScrollPane(), name); 107 } else { 108 specificInfoPane.add(detailPane, name); 109 } 110 elementTypeToDetailPane.put(name, detailPane); 111 } 112 113 private Border createTitledBorder(String title) { 114 Border simpleBorder = BorderFactory.createEtchedBorder(); 115 Border titledBorder = BorderFactory.createTitledBorder(simpleBorder, title); 116 117 return titledBorder; 118 } 119 } 120 121 | Popular Tags |