1 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 ; 32 33 40 41 public class ToolBarDesignEditor extends AbstractDesignEditor { 42 43 protected JComponent designPanel; 44 private ErrorPanel errorPanel; 45 private Object lastActive; 46 47 52 public ToolBarDesignEditor(){ 53 super(); 54 createDesignPanel(); 55 add(java.awt.BorderLayout.CENTER,designPanel); 56 add(java.awt.BorderLayout.SOUTH,createErrorPanel()); 57 } 58 59 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 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 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 helpAction; 114 ToolBarView(final ExplorerManager manager, org.openide.nodes.Node root, javax.swing.Action helpAction) { 115 super(); 116 this.manager=manager; 117 this.helpAction=helpAction; 118 120 setLayout(new java.awt.GridBagLayout ()); 121 ActionMap map = getActionMap(); 122 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 gridBagConstraints = new java.awt.GridBagConstraints (); 131 gridBagConstraints.gridx = 0; 132 gridBagConstraints.gridy = 0; 133 gridBagConstraints.insets = new java.awt.Insets (0, 2, 4, 0); 134 add(cView,gridBagConstraints); 135 136 gridBagConstraints = new java.awt.GridBagConstraints (); 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 helpButton = new javax.swing.JButton (helpAction); 144 helpButton.setText(""); 145 helpButton.setContentAreaFilled(false); 146 helpButton.setFocusPainted(false); 147 helpButton.setBorderPainted(false); 148 gridBagConstraints = new java.awt.GridBagConstraints (); 149 gridBagConstraints.gridx = 2; 150 gridBagConstraints.gridy = 0; 151 add(helpButton,gridBagConstraints); 153 } 154 public ExplorerManager getExplorerManager() { 156 return manager; 157 } 158 159 public Lookup getLookup() { 160 return lookup; 161 } 162 165 public void addNotify() { 166 super.addNotify(); 168 ExplorerUtils.activateActions(manager, true); 169 } 170 public void removeNotify() { 171 ExplorerUtils.activateActions(manager, false); 173 } 175 } 176 177 public Object getLastActive() { 178 return lastActive; 179 } 180 181 public void setLastActive(Object lastActive) { 182 this.lastActive=lastActive; 183 } 184 } 185 | Popular Tags |