KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > config > ui > AbstractDesignEditor


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 package org.netbeans.modules.j2ee.sun.share.config.ui;
20
21 import java.io.*;
22 import java.util.*;
23 import java.awt.*;
24 import java.beans.*;
25 import java.text.MessageFormat JavaDoc;
26 import javax.swing.border.LineBorder JavaDoc;
27 import javax.swing.event.ChangeListener JavaDoc;
28 import javax.swing.event.ListSelectionEvent JavaDoc;
29 import javax.swing.event.ListSelectionListener JavaDoc;
30 import javax.swing.*;
31 import javax.swing.table.TableColumn JavaDoc;
32 import javax.swing.undo.CannotRedoException JavaDoc;
33 import javax.swing.undo.CannotUndoException JavaDoc;
34
35 import org.openide.*;
36 import org.openide.nodes.*;
37 import org.openide.explorer.*;
38 import org.openide.explorer.propertysheet.*;
39 import org.openide.explorer.view.BeanTreeView;
40 import org.openide.windows.*;
41 import org.openide.util.HelpCtx;
42 import org.openide.util.SharedClassObject;
43 import org.openide.util.Utilities;
44
45
46 /**
47  * The ComponentPanel three pane editor. This is basically a container that implements the ExplorerManager
48  * interface. It coordinates the selection of a node in the structure pane and the display of a panel by the a PanelView
49  * in the content pane and the nodes properties in the properties pane. It will populate the tree view in the structure pane
50  * from the root node of the supplied PanelView.
51  *
52  **/

53
54 public abstract class AbstractDesignEditor extends TopComponent implements PanelFocusCookie, ExplorerManager.Provider {
55     
56     
57     /** The default width of the AbstractComponentEditor */
58     public static final int DEFAULT_WIDTH = 400;
59     /** The default height of the AbstractComponentEditor */
60     public static final int DEFAULT_HEIGHT = 400;
61     
62     protected static EmptyInspectorNode emptyInspectorNode;
63     
64     /** Default icon base for control panel. */
65     private static final String JavaDoc EMPTY_INSPECTOR_ICON_BASE =
66     "/org/netbeans/modules/form/resources/emptyInspector"; // NOI18N
67

68     
69     private ExplorerManager manager = null;
70     
71     protected JComponent structureView;
72     protected JComponent propertiesView;
73     protected JComponent contentView;
74     
75     
76     /** The icon for ComponentInspector */
77     protected static String JavaDoc iconURL = "/org/netbeans/modules/form/resources/inspector.gif"; // NOI18N
78

79     protected static final long serialVersionUID =1L;
80     
81     
82     protected AbstractDesignEditor(){
83     }
84     /**
85      * Creates a new instance of ComponentPanel
86      * @param panel The PanelView which will provide the node tree for the structure view
87      * and the set of panels the nodes map to.
88      */

89     public AbstractDesignEditor(PanelView panel){
90         contentView = panel;
91         contentView.setPreferredSize(new Dimension(DEFAULT_WIDTH,DEFAULT_HEIGHT));
92         initComponents();
93         setRootContext(panel.getRoot());
94     }
95     
96     
97     /**
98      * Creates a new instance of ComponentPanel
99      * @param panel The PanelView which will provide the node tree for the structure view
100      * and the set of panels the nodes map to.
101      * @param structure The JComponent that will be used in the structure pane. Should follow the
102      * ExplorerManager protocol. Will usually be some subclass of BeanTreeView.
103      */

104     
105     public AbstractDesignEditor(PanelView panel, JComponent structure){
106         contentView = panel;
107         contentView.setPreferredSize(new Dimension(DEFAULT_WIDTH,DEFAULT_HEIGHT));
108         structureView = structure;
109         initComponents();
110         setRootContext(panel.getRoot());
111     }
112     
113     
114     /**
115      * Sets the root context for the ExplorerManager
116      * @param node The new root context.
117      */

118     public void setRootContext(Node node) {
119         getExplorerManager().setRootContext(node);
120     }
121     
122     protected void initComponents() {
123         ExplorerManager manager = getExplorerManager();
124         emptyInspectorNode = new EmptyInspectorNode();
125         manager.setRootContext(emptyInspectorNode);
126         
127         setIcon(Utilities.loadImage(iconURL));
128         setName("CTL_ComponentPanelTitle");
129         
130         // Force winsys to not show tab when this comp is alone
131
putClientProperty("TabPolicy", "HideWhenAlone");
132         setToolTipText("HINT_ComponentPanel");
133         manager.addPropertyChangeListener(new NodeSelectedListener());
134         setLayout(new BorderLayout());
135     }
136     
137     
138  
139     /**
140      * Used to get the JComponent used for the content pane. Usually a subclass of PanelView.
141      * @return the JComponent
142      */

143     public JComponent getContentView(){
144         return contentView;
145     }
146     
147     /**
148      * Used to get the JComponent used for the structure pane. Usually a container for the structure component or the structure component itself.
149      * @return the JComponent
150      */

151     public JComponent getStructureView(){
152         if (structureView ==null){
153             structureView = createStructureComponent();
154         }
155         return structureView;
156     }
157     /**
158      * Used to create an instance of the JComponent used for the structure component. Usually a subclass of BeanTreeView.
159      * @return the JComponent
160      */

161     abstract public JComponent createStructureComponent() ;
162     
163     /**
164      * Used to get the JComponent used for the properties pane. Usually a subclass of PropertySheetView.
165      * @return the JComponent
166      */

167     
168     public JComponent getPropertiesView(){
169         if (propertiesView == null){
170             propertiesView = createPropertiesComponent();
171             propertiesView.addPropertyChangeListener(new PropertiesDisplayListener());
172         }
173         return propertiesView;
174     }
175     
176     /**
177      * Used to create an instance of the JComponent used for the properties component. Usually a subclass of PropertySheetView.
178      * @return JComponent
179      */

180     abstract public JComponent createPropertiesComponent();
181     /**
182      * A parent TopComponent can use this method to notify the ComponentPanel and it PanelView children that it was opened
183      * and lets them do any needed initialization as a result. Default implementation just delegates to the PanelView.
184      */

185     public void open(){
186         if (contentView!=null)
187             ((PanelView)contentView).open();
188     }
189     /**
190      * A parent TopComponent can use this method to notify the ComponentPanel and it PanelView children it is about to close.
191      * and lets them determine if they are ready. Default implementation just delegates to the PanelView.
192      * @return boolean True if the ComponentPanel is ready to close, false otherwise.
193      */

194     public boolean canClose(){
195         if (contentView!=null)
196             return ((PanelView)contentView).canClose();
197         else
198             return true;
199     }
200     
201     /**
202      * This method supports the PanelFocusCookie. It allows an external source set the focus on a ComponentPanel.
203      * See the JavaDoc for PanelFocusCookie for more information.
204      * Default implementation just delegates to the single PanelView.
205      * @param panelViewNameHint String used as a hint for the appropriate PanelView if there is more than one.
206      * @param panelNameHint String used as a hint for the appropiate panel in the PanelView
207      * @param focusObject Object that can be used to identify the object that should have the focus.
208      * @return true if the ComponentPanel was able to focus on the object.
209      */

210     public boolean setFocusOn(String JavaDoc panelViewNameHint, String JavaDoc panelNameHint, Object JavaDoc focusObject){
211         if (contentView!=null)
212             return ((PanelView)contentView).setFocusOn( panelViewNameHint, panelNameHint, focusObject);
213         else
214             return false;
215     }
216     
217     /**
218      * returns the HelpCtx for this component.
219      * @return the HelpCtx
220      */

221     public HelpCtx getHelpCtx() {
222         return new HelpCtx("ComponentPanel"); // NOI18N
223
}
224     
225     /**
226      * returns the preferred size for this component.
227      * @return the Dimension
228      */

229     
230     public Dimension getPreferredSize() {
231         return new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT);
232     }
233
234     public ExplorerManager getExplorerManager() {
235         if (manager == null) {
236             manager = new ExplorerManager();
237         }
238         return manager;
239     }
240     
241     class NodeSelectedListener implements PropertyChangeListener {
242         public void propertyChange(PropertyChangeEvent evt) {
243             if (!ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName()))
244                 return;
245             Node[] selectedNodes = getExplorerManager().getSelectedNodes();
246         }
247     }
248     
249     class PropertiesDisplayListener implements PropertyChangeListener {
250         public void propertyChange(PropertyChangeEvent evt) {
251             if (PropertySheet.PROPERTY_DISPLAY_WRITABLE_ONLY.equals(
252             evt.getPropertyName())) {
253                 //
254
//
255
}
256         }
257     }
258     static class EmptyInspectorNode extends AbstractNode {
259         public EmptyInspectorNode() {
260             super(Children.LEAF);
261             setIconBase(EMPTY_INSPECTOR_ICON_BASE);
262         }
263         
264         public boolean canRename() {
265             return false;
266         }
267     }
268     
269     
270 }
271
Popular Tags