KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > multiview > ui > SectionNodePanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.multiview.ui;
21
22 import org.netbeans.modules.xml.multiview.SectionNode;
23 import org.netbeans.modules.xml.multiview.Utils;
24 import org.openide.nodes.Node;
25
26 import javax.swing.*;
27 import javax.swing.border.Border JavaDoc;
28 import javax.swing.border.CompoundBorder JavaDoc;
29 import javax.swing.border.EmptyBorder JavaDoc;
30 import java.awt.*;
31 import java.beans.PropertyChangeListener JavaDoc;
32 import java.beans.PropertyChangeEvent JavaDoc;
33
34 /**
35  * @author pfiala
36  * <p/>
37  * The SectionNodePanel shows data of related SectionNode object
38  * which contains all information about the section
39  */

40 public class SectionNodePanel extends SectionPanel {
41
42     public SectionNodePanel(final SectionNode node) {
43         super(node.getSectionNodeView(), node, node.getDisplayName(), node);
44         if (node.getKey() instanceof SectionView) {
45             // the section corresponding to the top level node is always expanded
46
setInnerViewMode();
47         } else if (node.isExpanded()) {
48             setExpandedViewMode();
49         }
50         node.addPropertyChangeListener(new PropertyChangeListener JavaDoc() {
51             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
52                 if (Node.PROP_DISPLAY_NAME.equals(evt.getPropertyName())) {
53                     setTitle(node.getDisplayName());
54                 }
55             }
56         });
57     }
58
59     /**
60      * The expanded viev mode shows only title bar and border around inner panel,
61      * The inner panel is always visible and the section cannot be collapsed
62      */

63     protected void setExpandedViewMode() {
64         getTitleButton().setVisible(true);
65         getFoldButton().setVisible(false);
66         getHeaderSeparator().setVisible(false);
67         Border JavaDoc emptyBorder = new EmptyBorder JavaDoc(0, 4, 4, 4);
68         Border JavaDoc lineBorder;
69         lineBorder = new JTextField().getBorder();
70
71         setBorder(new CompoundBorder JavaDoc(emptyBorder, new CompoundBorder JavaDoc(lineBorder, emptyBorder)));
72         openInnerPanel();
73         getFillerLine().setVisible(false);
74         getFillerEnd().setVisible(false);
75     }
76
77     /**
78      * The inner view mode shows only inner panel.
79      * The inner panel is always visible and the section cannot be collapsed
80      */

81     protected void setInnerViewMode() {
82         getTitleButton().setVisible(false);
83         getFoldButton().setVisible(false);
84         getHeaderSeparator().setVisible(false);
85         openInnerPanel();
86         getFillerLine().setVisible(false);
87         getFillerEnd().setVisible(false);
88     }
89
90     /**
91      * Creation of inner panel using related SectionNode object
92      *
93      * @return newly created inner panel
94      */

95     protected SectionInnerPanel createInnerpanel() {
96         SectionInnerPanel innerPanel = ((SectionNode) getNode()).createInnerPanel();
97         if (innerPanel == null) {
98             // This case arises only if the inner panel has not been implemented yet.
99
// Then we show empty panel.
100
innerPanel = new BoxPanel(((SectionNode) getNode()).getSectionNodeView());
101         }
102         return innerPanel;
103     }
104
105     protected void openInnerPanel() {
106         super.openInnerPanel();
107         Node[] childNodes = ((SectionNode) getNode()).getChildren().getNodes();
108         if (childNodes != null && childNodes.length > 0) {
109             final SectionNodePanel panel = ((SectionNode) childNodes[0]).getSectionNodePanel();
110             panel.getFoldButton().setSelected(true);
111             panel.openInnerPanel();
112         }
113     }
114
115     protected void closeInnerPanel() {
116         if (getFoldButton().isVisible()) {
117             if (getSectionView().getActivePanel() == this) {
118                 Container parent = getParent();
119                 while (parent != null) {
120                     if (parent instanceof SectionPanel) {
121                         final SectionPanel sectionPanel = (SectionPanel) parent;
122                         Utils.runInAwtDispatchThread(new Runnable JavaDoc() {
123                             public void run() {
124                                 sectionPanel.setActive(true);
125                             }
126                         });
127                         break;
128                     } else {
129                         parent = parent.getParent();
130                     }
131                 }
132             }
133             super.closeInnerPanel();
134         }
135     }
136
137     /**
138      * Method of NodeSectionPanel interface
139      */

140     public void open() {
141         Node parentNode = getNode().getParentNode();
142         if (parentNode instanceof SectionNode) {
143             ((SectionNode) parentNode).getSectionNodePanel().open();
144         }
145         if (getInnerPanel() == null) {
146             super.open();
147         }
148     }
149 }
150
Popular Tags