KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > browser > detail > ElementValueDetailPane


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

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 JavaDoc;
15 import javax.swing.tree.TreePath JavaDoc;
16 import java.awt.*;
17 import java.util.HashMap JavaDoc;
18
19 /**
20  * Container for the classes defined in the <tt>elementvalue</tt> subpackage
21  * and switches between the contained panes as required.
22  *
23  * @author <a HREF="mailto:vitor.carreira@gmail.com">Vitor Carreira</a>
24  * @version $Revision: 1.1 $ $Date: 2004/12/28 13:04:31 $
25  */

26 public class ElementValueDetailPane extends AbstractDetailPane {
27
28     private static final String JavaDoc SCREEN_UNKNOWN = "Unknown";
29     private static final String JavaDoc SCREEN_CONST_VALUE = "Const";
30     private static final String JavaDoc SCREEN_CLASS_VALUE = "Class";
31     private static final String JavaDoc SCREEN_ENUM_VALUE = "Enum";
32
33
34     private HashMap JavaDoc elementTypeToDetailPane;
35
36     // Visual components
37

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 JavaDoc treePath) {
56         ElementValue eve = (ElementValue)
57                 ((BrowserTreeNode)treePath.getLastPathComponent()).getElement();
58
59         String JavaDoc 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 JavaDoc();
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 JavaDoc 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 JavaDoc createTitledBorder(String JavaDoc title) {
114         Border JavaDoc simpleBorder = BorderFactory.createEtchedBorder();
115         Border JavaDoc titledBorder = BorderFactory.createTitledBorder(simpleBorder, title);
116
117         return titledBorder;
118     }
119 }
120
121
Popular Tags