KickJava   Java API By Example, From Geeks To Geeks.

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


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.Error;
23 import org.openide.explorer.ExplorerManager;
24 import org.openide.explorer.ExplorerUtils;
25 import org.openide.explorer.view.ChoiceView;
26 import org.openide.explorer.view.NodeListModel;
27 import org.openide.util.Lookup;
28
29 import javax.swing.*;
30 import java.awt.*;
31 import java.beans.PropertyVetoException JavaDoc;
32
33 /**
34  * The ComponentPanel three pane editor. This is basically a container that implements the ExplorerManager
35  * interface. It coordinates the selection of a node in the structure pane and the display of a panel by the a PanelView
36  * in the content pane and the nodes properties in the properties pane. It will populate the tree view in the structure pane
37  * from the root node of the supplied PanelView.
38  *
39  **/

40
41 public class ToolBarDesignEditor extends AbstractDesignEditor {
42     
43     protected JComponent designPanel;
44     private ErrorPanel errorPanel;
45     private Object JavaDoc lastActive;
46
47     /**
48      * Creates a new instance of ToolBarDesignEditor
49      * @param panel The PanelView which will provide the node tree for the structure view
50      * and the set of panels the nodes map to.
51      */

52     public ToolBarDesignEditor(){
53         super();
54         createDesignPanel();
55         add(java.awt.BorderLayout.CENTER,designPanel);
56         add(java.awt.BorderLayout.SOUTH,createErrorPanel());
57     }
58     
59     /**
60      * Creates a new instance of ToolBarDesignEditor
61      * @param panel The PanelView which will provide the node tree for the structure view
62      * and the set of panels the nodes map to.
63      */

64     public ToolBarDesignEditor(PanelView panel){
65         super(panel);
66         createDesignPanel();
67         designPanel.add(panel,BorderLayout.CENTER);
68         add(java.awt.BorderLayout.CENTER,designPanel);
69         add(java.awt.BorderLayout.SOUTH,createErrorPanel());
70         panel.attachErrorPanel(errorPanel);
71     }
72     
73     public JComponent createDesignPanel(){
74         designPanel = new JPanel(new BorderLayout());
75         return designPanel;
76     }
77     
78     public void setContentView(PanelView panel) {
79         if (getContentView()!=null) {
80             designPanel.remove(getContentView());
81         }
82         designPanel.add(panel,BorderLayout.CENTER);
83         panel.attachErrorPanel(errorPanel);
84         super.setContentView(panel);
85     }
86     
87     public ErrorPanel getErrorPanel() {
88         return errorPanel;
89     }
90     
91     public Error JavaDoc getError() {
92         return(errorPanel==null?null:errorPanel.getError());
93     }
94     
95     private ErrorPanel createErrorPanel() {
96         errorPanel = new ErrorPanel(this);
97         return errorPanel;
98     }
99     
100     /**
101      * Used to create an instance of the JComponent used for the structure component. Usually a subclass of BeanTreeView.
102      * @return the JComponent
103      */

104     
105     public JComponent createStructureComponent() {
106         JToolBar toolbar = new ToolBarView(getExplorerManager(),getContentView().getRoot(), helpAction);
107         return toolbar;
108     }
109  
110     private static class ToolBarView extends JToolBar implements ExplorerManager.Provider, Lookup.Provider {
111         private ExplorerManager manager;
112         private Lookup lookup;
113         private javax.swing.Action JavaDoc helpAction;
114         ToolBarView(final ExplorerManager manager, org.openide.nodes.Node root, javax.swing.Action JavaDoc helpAction) {
115             super();
116             this.manager=manager;
117             this.helpAction=helpAction;
118             // same as before...
119

120             setLayout(new java.awt.GridBagLayout JavaDoc());
121             ActionMap map = getActionMap();
122             // ...and initialization of lookup variable
123
lookup = ExplorerUtils.createLookup (manager, map);
124
125             ChoiceView cView = new ChoiceView();
126             ((NodeListModel)(cView.getModel())).setNode(root);
127             setFloatable(false);
128             ((NodeListModel)(cView.getModel())).setDepth(5);
129             
130             java.awt.GridBagConstraints JavaDoc gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
131             gridBagConstraints.gridx = 0;
132             gridBagConstraints.gridy = 0;
133             gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 2, 4, 0);
134             add(cView,gridBagConstraints);
135             
136             gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
137             gridBagConstraints.gridx = 1;
138             gridBagConstraints.gridy = 0;
139             gridBagConstraints.weightx = 1.0;
140             JPanel filler = new JPanel();
141             add(filler,gridBagConstraints);
142             
143             javax.swing.JButton JavaDoc helpButton = new javax.swing.JButton JavaDoc(helpAction);
144             helpButton.setText("");
145             helpButton.setContentAreaFilled(false);
146             helpButton.setFocusPainted(false);
147             helpButton.setBorderPainted(false);
148             gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
149             gridBagConstraints.gridx = 2;
150             gridBagConstraints.gridy = 0;
151             //gridBagConstraints.weightx = 1.0;
152
add(helpButton,gridBagConstraints);
153         }
154         // ...method as before and getLookup
155
public ExplorerManager getExplorerManager() {
156             return manager;
157         }
158         
159         public Lookup getLookup() {
160             return lookup;
161         }
162         // ...methods as before, but replace componentActivated and
163
// componentDeactivated with e.g.:
164

165         public void addNotify() {
166             //System.out.println("addNotify()");
167
super.addNotify();
168             ExplorerUtils.activateActions(manager, true);
169         }
170         public void removeNotify() {
171             //System.out.println("removeNotify()");
172
ExplorerUtils.activateActions(manager, false);
173             //super.removeNotify();
174
}
175     }
176     
177     public Object JavaDoc getLastActive() {
178         return lastActive;
179     }
180     
181     public void setLastActive(Object JavaDoc lastActive) {
182         this.lastActive=lastActive;
183     }
184 }
185
Popular Tags