1 19 20 package org.netbeans.modules.form.wizard; 21 22 import java.util.*; 23 import java.beans.EventSetDescriptor ; 24 import javax.swing.tree.*; 25 import javax.swing.event.*; 26 27 import org.openide.awt.Mnemonics; 28 import org.openide.util.NbBundle; 29 import org.netbeans.modules.form.*; 30 31 32 37 38 class ConnectionPanel1 extends javax.swing.JPanel { 39 40 private ConnectionWizardPanel1 wizardPanel; 41 42 43 ConnectionPanel1(ConnectionWizardPanel1 wizardPanel) { 44 this.wizardPanel = wizardPanel; 45 46 initComponents(); 47 48 RADComponent source = wizardPanel.getSourceComponent(); 49 50 java.util.ResourceBundle bundle = NbBundle.getBundle(ConnectionPanel1.class); 51 52 setName(bundle.getString("CTL_CW_Step1_Title")); sourceComponentName.setText(source.getName()); 54 55 eventNameCombo.setEnabled(wizardPanel.getSelectedEvent() != null); 56 57 eventNameCombo.addActionListener(new java.awt.event.ActionListener () { 58 public void actionPerformed(java.awt.event.ActionEvent e) { 59 ConnectionPanel1.this.wizardPanel.fireStateChanged(); 60 } 61 }); 62 63 eventNameCombo.getEditor().addActionListener(new java.awt.event.ActionListener () { 64 public void actionPerformed(java.awt.event.ActionEvent e) { 65 ConnectionPanel1.this.wizardPanel.fireStateChanged(); 66 } 67 }); 68 69 final Vector eventNodes = new Vector(); 71 TreeNode rootNode = new TreeNode() { 72 public TreeNode getChildAt(int childIndex) { 73 return(TreeNode) eventNodes.elementAt(childIndex); 74 } 75 public int getChildCount() { 76 return eventNodes.size(); 77 } 78 public TreeNode getParent() { 79 return null; 80 } 81 public int getIndex(TreeNode node) { 82 return eventNodes.indexOf(node); 83 } 84 public boolean getAllowsChildren() { 85 return true; 86 } 87 public boolean isLeaf() { 88 return false; 89 } 90 public Enumeration children() { 91 return eventNodes.elements(); 92 } 93 }; 94 95 EventSetDescriptor lastEventSetDesc = null; 96 TreeNode eventSetNode = null; 97 List eventSetEvents = null; 98 99 Event[] events = source.getAllEvents(); 100 for (int i=0; i < events.length; i++) { 101 Event event = events[i]; 102 EventSetDescriptor eventSetDesc = event.getEventSetDescriptor(); 103 104 if (eventSetDesc != lastEventSetDesc) { 105 eventSetEvents = new ArrayList(); 106 eventSetNode = new EventSetNode(eventSetDesc.getName(), 107 eventSetEvents); 108 eventNodes.add(eventSetNode); 109 lastEventSetDesc = eventSetDesc; 110 } 111 112 eventSetEvents.add(new EventNode(eventSetNode, event)); 113 } 114 115 DefaultTreeSelectionModel treeSelectionModel = new DefaultTreeSelectionModel(); 116 treeSelectionModel.addTreeSelectionListener(new TreeSelectionListener() { 117 public void valueChanged(TreeSelectionEvent evt) { 118 TreePath[] paths = eventSelectTree.getSelectionPaths(); 119 if ((paths != null) &&(paths.length == 1)) { 120 TreeNode node =(TreeNode) paths[0].getLastPathComponent(); 121 if ((node != null) &&(node instanceof EventNode)) { 122 setSelectedEvent(((EventNode)node).getEvent()); 123 return; 124 } 125 } 126 setSelectedEvent(null); 127 } 128 }); 129 130 treeSelectionModel.setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION); 131 eventSelectTree.setModel(new DefaultTreeModel(rootNode)); 132 eventSelectTree.setSelectionModel(treeSelectionModel); 133 134 Mnemonics.setLocalizedText(sourceNameLabel, bundle.getString("CTL_CW_SourceComponent")); sourceComponentName.setToolTipText( 137 bundle.getString("CTL_CW_SourceComponent_Hint")); Mnemonics.setLocalizedText(eventSelectLabel, bundle.getString("CTL_CW_Event")); eventSelectTree.setToolTipText(bundle.getString("CTL_CW_Event_Hint")); 140 sourcePanel.setToolTipText(bundle.getString("CTL_CW_Event_Hint")); 141 eventHandlerPanel.setBorder(new javax.swing.border.CompoundBorder ( 142 new javax.swing.border.TitledBorder ( 143 new javax.swing.border.EtchedBorder (), 144 bundle.getString("CTL_CW_EventHandlerMethod")), new javax.swing.border.EmptyBorder (new java.awt.Insets (5, 5, 5, 5)))); 146 Mnemonics.setLocalizedText(eventNameLabel, bundle.getString("CTL_CW_MethodName")); 148 eventSelectTree.getAccessibleContext().setAccessibleDescription( 149 bundle.getString("ACSD_CW_EventTree")); eventNameCombo.getAccessibleContext().setAccessibleDescription( 151 bundle.getString("ACSD_CW_MethodName")); sourceComponentName.getAccessibleContext().setAccessibleDescription( 153 bundle.getString("ACSD_CW_SourceComponent")); getAccessibleContext().setAccessibleDescription( 155 bundle.getString("ACSD_CW_ConnectionPanel1")); putClientProperty("WizardPanel_contentSelectedIndex", new Integer (0)); } 158 159 public java.awt.Dimension getPreferredSize() { 160 return new java.awt.Dimension (450, 300); 161 } 162 163 String getEventName() { 164 return (String ) eventNameCombo.getEditor().getItem(); 165 } 166 167 private void setSelectedEvent(Event event) { 168 eventNameCombo.removeAllItems(); 169 170 if (event != null) { 171 eventNameCombo.setEnabled(true); 172 173 FormEvents formEvents = wizardPanel.getSourceComponent() 174 .getFormModel().getFormEvents(); 175 String defaultName = formEvents.findFreeHandlerName( 176 event, wizardPanel.getSourceComponent()); 177 178 eventNameCombo.addItem(defaultName); 179 180 if (event.hasEventHandlers()) { 181 String [] handlers = event.getEventHandlers(); 182 for (int i=0; i < handlers.length; i++) 183 eventNameCombo.addItem(handlers[i]); 184 } 185 186 eventNameCombo.setSelectedIndex(0); 187 } 188 else eventNameCombo.setEnabled(false); 189 190 wizardPanel.setSelectedEvent(event); 191 } 192 193 198 private void initComponents() { sourcePanel = new javax.swing.JPanel (); 200 sourceInfoPanel = new javax.swing.JPanel (); 201 sourceNamePanel = new javax.swing.JPanel (); 202 sourceNameLabel = new javax.swing.JLabel (); 203 sourceComponentName = new javax.swing.JTextField (); 204 eventSelectLabelPanel = new javax.swing.JPanel (); 205 eventSelectLabel = new javax.swing.JLabel (); 206 eventSelectScroll = new javax.swing.JScrollPane (); 207 eventSelectTree = new javax.swing.JTree (); 208 eventHandlerPanel = new javax.swing.JPanel (); 209 eventNameLabel = new javax.swing.JLabel (); 210 eventNameCombo = new javax.swing.JComboBox (); 211 212 setLayout(new java.awt.BorderLayout (0, 11)); 213 214 sourcePanel.setLayout(new java.awt.BorderLayout ()); 215 216 sourceInfoPanel.setLayout(new java.awt.GridLayout (2, 1)); 217 218 sourceNamePanel.setLayout(new java.awt.FlowLayout (java.awt.FlowLayout.LEFT, 0, 0)); 219 220 sourceNameLabel.setLabelFor(sourceComponentName); 221 sourceNameLabel.setText("Source Component:"); 222 sourceNameLabel.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (0, 0, 0, 6))); 223 sourceNamePanel.add(sourceNameLabel); 224 225 sourceComponentName.setEditable(false); 226 sourceComponentName.setText("jTextField1"); 227 sourceNamePanel.add(sourceComponentName); 228 229 sourceInfoPanel.add(sourceNamePanel); 230 231 eventSelectLabelPanel.setLayout(new java.awt.FlowLayout (java.awt.FlowLayout.LEFT, 0, 3)); 232 233 eventSelectLabel.setLabelFor(eventSelectTree); 234 eventSelectLabel.setText("Events"); 235 eventSelectLabelPanel.add(eventSelectLabel); 236 237 sourceInfoPanel.add(eventSelectLabelPanel); 238 239 sourcePanel.add(sourceInfoPanel, java.awt.BorderLayout.NORTH); 240 241 eventSelectScroll.setMaximumSize(new java.awt.Dimension (32767, 100)); 242 eventSelectTree.setRootVisible(false); 243 eventSelectTree.setShowsRootHandles(true); 244 eventSelectScroll.setViewportView(eventSelectTree); 245 246 sourcePanel.add(eventSelectScroll, java.awt.BorderLayout.CENTER); 247 248 add(sourcePanel, java.awt.BorderLayout.CENTER); 249 250 eventHandlerPanel.setLayout(new java.awt.BorderLayout (8, 0)); 251 252 eventHandlerPanel.setBorder(new javax.swing.border.TitledBorder ("Event Handler Method")); 253 eventNameLabel.setLabelFor(eventNameCombo); 254 eventNameLabel.setText("Method Name:"); 255 eventHandlerPanel.add(eventNameLabel, java.awt.BorderLayout.WEST); 256 257 eventNameCombo.setEditable(true); 258 eventHandlerPanel.add(eventNameCombo, java.awt.BorderLayout.CENTER); 259 260 add(eventHandlerPanel, java.awt.BorderLayout.SOUTH); 261 262 } 264 private javax.swing.JTree eventSelectTree; 266 private javax.swing.JLabel eventNameLabel; 267 private javax.swing.JPanel sourcePanel; 268 private javax.swing.JScrollPane eventSelectScroll; 269 private javax.swing.JLabel eventSelectLabel; 270 private javax.swing.JPanel sourceNamePanel; 271 private javax.swing.JPanel sourceInfoPanel; 272 private javax.swing.JPanel eventHandlerPanel; 273 private javax.swing.JLabel sourceNameLabel; 274 private javax.swing.JTextField sourceComponentName; 275 private javax.swing.JComboBox eventNameCombo; 276 private javax.swing.JPanel eventSelectLabelPanel; 277 279 282 static class EventSetNode implements TreeNode { 283 private String eventSetName; 284 private List subNodes; 285 286 public EventSetNode(String eventSetName, List subNodes) { 287 this.eventSetName = eventSetName; 288 this.subNodes = subNodes; 289 } 290 291 public TreeNode getChildAt(int childIndex) { 292 return (TreeNode) subNodes.get(childIndex); 293 } 294 public int getChildCount() { 295 return subNodes.size(); 296 } 297 public TreeNode getParent() { 298 return null; 299 } 300 public int getIndex(TreeNode node) { 301 return subNodes.indexOf(node); 302 } 303 public boolean getAllowsChildren() { 304 return true; 305 } 306 public boolean isLeaf() { 307 return false; 308 } 309 public Enumeration children() { 310 return Collections.enumeration(subNodes); 311 } 312 public String toString() { 313 return eventSetName; 314 } 315 } 316 317 static class EventNode implements TreeNode { 318 private TreeNode parent; 319 private Event event; 320 public EventNode(TreeNode parent, Event event) { 321 this.parent = parent; 322 this.event = event; 323 } 324 public TreeNode getChildAt(int childIndex) { 325 return null; 326 } 327 public int getChildCount() { 328 return 0; 329 } 330 public TreeNode getParent() { 331 return parent; 332 } 333 public int getIndex(TreeNode node) { 334 return -1; 335 } 336 public boolean getAllowsChildren() { 337 return false; 338 } 339 public boolean isLeaf() { 340 return true; 341 } 342 public Enumeration children() { 343 return null; 344 } 345 public String toString() { 346 if (!event.hasEventHandlers()) 347 return event.getName(); 348 String [] handlers = event.getEventHandlers(); 349 if (handlers.length == 1) 350 return event.getName() + " ["+ handlers[0] +"]"; return event.getName() + " [...]"; } 353 Event getEvent() { 354 return event; 355 } 356 } 357 } 358 | Popular Tags |