1 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 ; 26 import javax.swing.border.LineBorder ; 27 import javax.swing.event.ChangeListener ; 28 import javax.swing.event.ListSelectionEvent ; 29 import javax.swing.event.ListSelectionListener ; 30 import javax.swing.*; 31 import javax.swing.table.TableColumn ; 32 import javax.swing.undo.CannotRedoException ; 33 import javax.swing.undo.CannotUndoException ; 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 53 54 public abstract class AbstractDesignEditor extends TopComponent implements PanelFocusCookie, ExplorerManager.Provider { 55 56 57 58 public static final int DEFAULT_WIDTH = 400; 59 60 public static final int DEFAULT_HEIGHT = 400; 61 62 protected static EmptyInspectorNode emptyInspectorNode; 63 64 65 private static final String EMPTY_INSPECTOR_ICON_BASE = 66 "/org/netbeans/modules/form/resources/emptyInspector"; 68 69 private ExplorerManager manager = null; 70 71 protected JComponent structureView; 72 protected JComponent propertiesView; 73 protected JComponent contentView; 74 75 76 77 protected static String iconURL = "/org/netbeans/modules/form/resources/inspector.gif"; 79 protected static final long serialVersionUID =1L; 80 81 82 protected AbstractDesignEditor(){ 83 } 84 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 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 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 putClientProperty("TabPolicy", "HideWhenAlone"); 132 setToolTipText("HINT_ComponentPanel"); 133 manager.addPropertyChangeListener(new NodeSelectedListener()); 134 setLayout(new BorderLayout()); 135 } 136 137 138 139 143 public JComponent getContentView(){ 144 return contentView; 145 } 146 147 151 public JComponent getStructureView(){ 152 if (structureView ==null){ 153 structureView = createStructureComponent(); 154 } 155 return structureView; 156 } 157 161 abstract public JComponent createStructureComponent() ; 162 163 167 168 public JComponent getPropertiesView(){ 169 if (propertiesView == null){ 170 propertiesView = createPropertiesComponent(); 171 propertiesView.addPropertyChangeListener(new PropertiesDisplayListener()); 172 } 173 return propertiesView; 174 } 175 176 180 abstract public JComponent createPropertiesComponent(); 181 185 public void open(){ 186 if (contentView!=null) 187 ((PanelView)contentView).open(); 188 } 189 194 public boolean canClose(){ 195 if (contentView!=null) 196 return ((PanelView)contentView).canClose(); 197 else 198 return true; 199 } 200 201 210 public boolean setFocusOn(String panelViewNameHint, String panelNameHint, Object focusObject){ 211 if (contentView!=null) 212 return ((PanelView)contentView).setFocusOn( panelViewNameHint, panelNameHint, focusObject); 213 else 214 return false; 215 } 216 217 221 public HelpCtx getHelpCtx() { 222 return new HelpCtx("ComponentPanel"); } 224 225 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 } 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 |