KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > websphere6 > ui > wizard > ServerPropertiesPanel


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.websphere6.ui.wizard;
20
21 import java.util.*;
22 import java.awt.*;
23 import java.awt.event.*;
24 import javax.swing.*;
25 import javax.swing.event.*;
26
27 import org.openide.*;
28 import org.openide.awt.Mnemonics;
29 import org.openide.util.*;
30 import org.netbeans.modules.j2ee.websphere6.ui.Instance;
31 import org.netbeans.modules.j2ee.websphere6.ui.Customizer;
32 import org.netbeans.modules.j2ee.websphere6.ui.InstancesModel;
33 import org.netbeans.modules.j2ee.websphere6.ui.ServerProperties;
34 /**
35  * The second panel of the custom wizard used for registering an instance of
36  * the server. Here user should choose among the the existing local instances,
37  * or enter the host/port/username/password conbination for a remote one
38  *
39  * @author Kirill Sorokin
40  */

41 public class ServerPropertiesPanel extends JPanel
42         implements WizardDescriptor.Panel {
43     /**
44      * Since the WizardDescriptor does not expose the property name for the
45      * error message label, we have to keep it here also
46      */

47     private final static String JavaDoc PROP_ERROR_MESSAGE =
48             "WizardPanel_errorMessage"; // NOI18N
49

50     /**
51      * The parent wizard descriptor handle
52      */

53     private transient WizardDescriptor wizardDescriptor;
54     
55     /**
56      * The parent instantiaing iterator handle
57      */

58     private transient WSInstantiatingIterator instantiatingIterator;
59     
60     
61     public class WizardServerProperties extends ServerProperties{
62         public WizardServerProperties(JComboBox serverCombobox,
63                 JComboBox localInstancesCombobox,
64                 JTextField domainPathField,
65                 JTextField hostField,
66                 JTextField portField) {
67             super(serverCombobox,localInstancesCombobox,domainPathField,hostField,portField);
68         }
69         public WizardServerProperties() {
70             super();
71         }
72         
73         public class WizardServerTypeActionListener extends ServerTypeActionListener{
74             public void actionPerformed(ActionEvent e) {
75                 super.actionPerformed(e);
76                 isValid();
77             }
78         }
79     }
80     
81     private WizardServerProperties wizardServerProperties=new WizardServerProperties();
82     
83     /**
84      * Returns wizardServerProperties;
85      */

86     public WizardServerProperties getWizardServerProperties(){
87         return wizardServerProperties;
88     }
89     
90     
91     /**
92      * Creates a new instance of the ServerPropertiesPanel. It initializes all
93      * the GUI components that appear on the panel.
94      *
95      * @param steps the names of the steps in the wizard
96      * @param index index of this panel in the wizard
97      * @param listener a listener that will propagate the chage event higher in
98      * the hierarchy
99      * @param instantiatingIterator the parent instantiating iterator
100      */

101     
102     public ServerPropertiesPanel(String JavaDoc[] steps, int index,
103             ChangeListener listener,
104             WSInstantiatingIterator instantiatingIterator) {
105         // save the instantiating iterator
106
this.instantiatingIterator = instantiatingIterator;
107         
108         // set the required properties, so that the panel appear correct in
109
// the steps
110
putClientProperty("WizardPanel_contentData", steps); // NOI18N
111
putClientProperty("WizardPanel_contentSelectedIndex",
112                 new Integer JavaDoc(index)); // NOI18N
113

114         // register the supplied listener
115
addChangeListener(listener);
116         
117         // set the panel's name
118
setName(steps[index]);
119         
120         // init the GUI
121
init();
122     }
123     
124     /**
125      * Returns the named help article associated with this panel
126      *
127      * @return the associated help article
128      */

129     public HelpCtx getHelp() {
130         return new HelpCtx("j2eeplugins_registering_app_" + // NOI18N
131
"server_websphere"); // NOI18N
132
}
133     
134     /**
135      * Gets the panel's AWT Component object, in our case it coincides with this
136      * object
137      *
138      * @return this
139      */

140     public Component getComponent() {
141         return this;
142     }
143     
144     /**
145      * Checks whether the data input is valid
146      *
147      * @return true if the entered installation directory is valid, false
148      * otherwise
149      */

150     public boolean isValid() {
151         // clear the error message
152
wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, ""); // NOI18N
153

154         // if the server instance is local, then check the profile root
155
// directory for validity
156
if (serverTypeCombo.getSelectedItem().equals(NbBundle.getMessage(
157                 Customizer.class,
158                 "TXT_ServerTypeLocal"))) { // NOI18N
159
if (!wizardServerProperties.isValidDomainRoot(domainPathField.getText())) {
160                 wizardDescriptor.putProperty(PROP_ERROR_MESSAGE,
161                         NbBundle.getMessage(ServerPropertiesPanel.class,
162                         "ERR_INVALID_DOMAIN_ROOT")); // NOI18N
163
return false;
164             }
165         }
166         
167         // check the host field (not empty)
168
if (hostField.getText().trim().equals("")) {
169             wizardDescriptor.putProperty(PROP_ERROR_MESSAGE,
170                     NbBundle.getMessage(ServerPropertiesPanel.class,
171                     "ERR_INVALID_HOST")); // NOI18N
172
}
173         
174         // check the port field (not empty and a positive integer)
175
//if (!portField.getValue().toString().trim().matches("[0-9]+")) {
176
if (!portField.getText().trim().matches("[0-9]+")) {
177             wizardDescriptor.putProperty(PROP_ERROR_MESSAGE,
178                     NbBundle.getMessage(ServerPropertiesPanel.class,
179                     "ERR_INVALID_PORT")); // NOI18N
180
}
181         if (portField.getText().trim().matches("[0-9]+") &&
182                 new java.lang.Integer JavaDoc(portField.getText().trim()).intValue()>65535) {
183             wizardDescriptor.putProperty(PROP_ERROR_MESSAGE,
184                     NbBundle.getMessage(ServerPropertiesPanel.class,
185                     "ERR_INVALID_PORT")); // NOI18N
186
}
187         
188         // no checks for username & password as they may be intentionally blank
189

190         // save the data to the parent instantiating iterator
191
instantiatingIterator.setDomainRoot(domainPathField.getText());
192         instantiatingIterator.setHost(hostField.getText());
193         //instantiatingIterator.setPort(portField.getValue().toString());
194
instantiatingIterator.setPort(portField.getText());
195         instantiatingIterator.setUsername(usernameField.getText());
196         instantiatingIterator.setPassword(new String JavaDoc(
197                 passwordField.getPassword()));
198         instantiatingIterator.setIsLocal(serverTypeCombo.getSelectedItem().
199                 equals(NbBundle.getMessage(Customizer.class,
200                 "TXT_ServerTypeLocal")) ? "true" : "false"); // NOI18N
201
instantiatingIterator.setServerName(((Instance) localInstancesCombo.
202                 getSelectedItem()).getName());
203         instantiatingIterator.setConfigXmlPath(((Instance) localInstancesCombo.
204                 getSelectedItem()).getConfigXmlPath());
205         instantiatingIterator.setAdminPort(((Instance) localInstancesCombo.
206                 getSelectedItem()).getAdminPort());
207         instantiatingIterator.setDefaultHostPort(((Instance) localInstancesCombo.
208                 getSelectedItem()).getDefaultHostPort());
209         
210         // everything seems ok
211
return true;
212     }
213     
214     
215     ////////////////////////////////////////////////////////////////////////////
216
// JPanel section
217
////////////////////////////////////////////////////////////////////////////
218
private JLabel domainPathLabel;
219     private JLabel hostLabel;
220     private JLabel portLabel;
221     private JLabel userNameLabel;
222     private JLabel passwordLabel;
223     private JPasswordField passwordField;
224     private JTextField domainPathField;
225     private JTextField hostField;
226     private JTextField portField;
227     private JTextField usernameField;
228     private JPanel formattingPanel;
229     private JComboBox serverTypeCombo;
230     private JComboBox localInstancesCombo;
231     private JLabel localInstanceLabel;
232     private JLabel serverTypeLabel;
233     private JTextArea remoteWarningLabel;
234     
235     
236     /**
237      * Inits the GUI components
238      */

239     private void init() {
240         // we use the GridBagLayout so we need the GridBagConstraints to
241
// properly place the components
242
GridBagConstraints gridBagConstraints;
243         getAccessibleContext().setAccessibleDescription(
244                 java.util.ResourceBundle.getBundle(
245                 "org/netbeans/modules/j2ee/websphere6/ui/Bundle").
246                 getString("MSG_ServerPropertiesPanelDescription"));
247         // initialize the components
248
domainPathLabel = new JLabel();
249         domainPathField = new JTextField();
250         hostLabel = new JLabel();
251         hostField = new JTextField();
252         portLabel = new JLabel();
253         portField = new JTextField();
254         userNameLabel = new JLabel();
255         usernameField = new JTextField();
256         passwordLabel = new JLabel();
257         passwordField = new JPasswordField();
258         formattingPanel = new JPanel();
259         serverTypeLabel = new JLabel();
260         serverTypeCombo = new JComboBox(new Object JavaDoc[] {NbBundle.getMessage(
261                 Customizer.class, "TXT_ServerTypeLocal")/*,
262         //NbBundle.getMessage(Customizer.class,
263                 "TXT_ServerTypeRemote")*/
});// NOI18N
264
localInstanceLabel = new JLabel();
265         localInstancesCombo = new JComboBox(new InstancesModel(
266                 wizardServerProperties.getServerInstances(
267                 instantiatingIterator.getServerRoot())));
268         remoteWarningLabel = new JTextArea(NbBundle.getMessage(
269                 ServerPropertiesPanel.class,
270                 "LBL_remoteIncompatibilityWarning")); // NOI18N
271

272         // set the desired layout
273
setLayout(new GridBagLayout());
274         
275         
276         
277         // add server type field label
278
serverTypeLabel.setText(NbBundle.getMessage(
279                 Customizer.class, "LBL_LocalRemote")); // NOI18N
280
gridBagConstraints = new GridBagConstraints();
281         gridBagConstraints.gridx = 0;
282         gridBagConstraints.gridy = 0;
283         gridBagConstraints.anchor = GridBagConstraints.EAST;
284         gridBagConstraints.insets = new Insets(0, 0, 5, 0);
285         add(serverTypeLabel, gridBagConstraints);
286         
287         // add server type combobox
288
serverTypeCombo.addActionListener(wizardServerProperties.getServerTypeActionListener());
289         gridBagConstraints = new GridBagConstraints();
290         gridBagConstraints.gridx = 1;
291         gridBagConstraints.gridy = 0;
292         gridBagConstraints.anchor = GridBagConstraints.WEST;
293         gridBagConstraints.insets = new Insets(0, 10, 5, 0);
294         serverTypeCombo.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("TTL_AccessMethod"));
295         serverTypeCombo.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("MSG_AccessMethodDescription"));
296         add(serverTypeCombo, gridBagConstraints);
297         
298         // add local instances field label
299
localInstanceLabel.setText(NbBundle.getMessage(
300                 Customizer.class, "LBL_LocalInstances")); // NOI18N
301
gridBagConstraints = new GridBagConstraints();
302         gridBagConstraints.gridx = 0;
303         gridBagConstraints.gridy = 1;
304         gridBagConstraints.anchor = GridBagConstraints.EAST;
305         gridBagConstraints.insets = new Insets(0, 0, 5, 0);
306         add(localInstanceLabel, gridBagConstraints);
307         
308         // add local instances combobox
309
localInstancesCombo.addActionListener(
310                 wizardServerProperties.getInstanceSelectionListener());
311         
312         gridBagConstraints = new GridBagConstraints();
313         gridBagConstraints.gridx = 1;
314         gridBagConstraints.gridy = 1;
315         gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
316         gridBagConstraints.insets = new Insets(0, 10, 5, 0);
317         localInstancesCombo.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("TTL_LocalInstances"));
318         localInstancesCombo.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("MSG_LocalInstances"));
319         add(localInstancesCombo, gridBagConstraints);
320         
321         // add domain path field label
322
domainPathLabel.setText(NbBundle.getMessage(
323                 Customizer.class, "LBL_ProfilePath")); // NOI18N
324
gridBagConstraints = new GridBagConstraints();
325         gridBagConstraints.gridx = 0;
326         gridBagConstraints.gridy = 2;
327         gridBagConstraints.anchor = GridBagConstraints.EAST;
328         gridBagConstraints.insets = new Insets(0, 0, 5, 0);
329         add(domainPathLabel, gridBagConstraints);
330         
331         // add domain path field
332
domainPathField.setText(""); // NOI18N
333
domainPathField.setEditable(false);
334         gridBagConstraints = new GridBagConstraints();
335         gridBagConstraints.gridx = 1;
336         gridBagConstraints.gridy = 2;
337         gridBagConstraints.weightx = 1.0;
338         gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
339         gridBagConstraints.insets = new Insets(0, 10, 5, 0);
340         domainPathField.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("TTL_ProfilePath"));
341         domainPathField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("MSG_ProfilePath"));
342         add(domainPathField, gridBagConstraints);
343         
344         // add host field label
345
hostLabel.setText(NbBundle.getMessage(Customizer.class,
346                 "LBL_Host")); // NOI18N
347
gridBagConstraints = new GridBagConstraints();
348         gridBagConstraints.gridx = 0;
349         gridBagConstraints.gridy = 3;
350         gridBagConstraints.anchor = GridBagConstraints.EAST;
351         gridBagConstraints.insets = new Insets(0, 0, 5, 0);
352         add(hostLabel, gridBagConstraints);
353         
354         // add host field
355
hostField.setText(""); // NOI18N
356
hostField.addKeyListener(new KeyListener());
357         gridBagConstraints = new GridBagConstraints();
358         gridBagConstraints.gridx = 1;
359         gridBagConstraints.gridy = 3;
360         gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
361         gridBagConstraints.insets = new Insets(0, 10, 5, 0);
362         hostField.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("TTL_Host"));
363         hostField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("MSG_Host"));
364         add(hostField, gridBagConstraints);
365         hostField.setEditable(false);
366         
367         // add port field label
368
portLabel.setText(NbBundle.getMessage(Customizer.class,
369                 "LBL_Port")); // NOI18N
370
gridBagConstraints = new GridBagConstraints();
371         gridBagConstraints.gridx = 0;
372         gridBagConstraints.gridy = 4;
373         gridBagConstraints.anchor = GridBagConstraints.EAST;
374         gridBagConstraints.insets = new Insets(0, 0, 5, 0);
375         add(portLabel, gridBagConstraints);
376         
377         // add port field
378

379         //portField.setModel(new SpinnerNumberModel(0,0,65535,1));
380
//portField.setValue(new Integer(8880)); // NOI18N
381
portField.setText("8880");// NOI18N
382
portField.addKeyListener(new KeyListener());
383         portField.setPreferredSize(new Dimension(50, 20));
384         portField.setFont(hostField.getFont());
385         gridBagConstraints = new GridBagConstraints();
386         gridBagConstraints.gridx = 1;
387         gridBagConstraints.gridy = 4;
388         gridBagConstraints.anchor = GridBagConstraints.WEST;
389         gridBagConstraints.insets = new Insets(0, 10, 5, 0);
390         portField.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("TTL_Port"));
391         portField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("MSG_Port"));
392         add(portField, gridBagConstraints);
393         portField.setEditable(false);
394         
395         // add username field label
396
userNameLabel.setText(NbBundle.getMessage(Customizer.class,
397                 "LBL_Username")); // NOI18N
398
gridBagConstraints = new GridBagConstraints();
399         gridBagConstraints.gridx = 0;
400         gridBagConstraints.gridy = 5;
401         gridBagConstraints.anchor = GridBagConstraints.EAST;
402         gridBagConstraints.insets = new Insets(0, 0, 5, 0);
403         add(userNameLabel, gridBagConstraints);
404         
405         // add username field
406
usernameField.setText(""); // NOI18N
407
usernameField.addKeyListener(new KeyListener());
408         usernameField.setPreferredSize(new Dimension(100, 20));
409         gridBagConstraints = new GridBagConstraints();
410         gridBagConstraints.gridx = 1;
411         gridBagConstraints.gridy = 5;
412         gridBagConstraints.anchor = GridBagConstraints.WEST;
413         gridBagConstraints.insets = new Insets(0, 10, 5, 0);
414         usernameField.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("TTL_Username"));
415         usernameField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("MSG_Username"));
416         add(usernameField, gridBagConstraints);
417         
418         // add password field label
419
passwordLabel.setText(NbBundle.getMessage(Customizer.class,
420                 "LBL_Password")); // NOI18N
421
gridBagConstraints = new GridBagConstraints();
422         gridBagConstraints.gridx = 0;
423         gridBagConstraints.gridy = 6;
424         gridBagConstraints.anchor = GridBagConstraints.EAST;
425         gridBagConstraints.insets = new Insets(0, 0, 5, 0);
426         add(passwordLabel, gridBagConstraints);
427         
428         // add password field
429
passwordField.setPreferredSize(new Dimension(100, 20));
430         passwordField.addKeyListener(new KeyListener());
431         gridBagConstraints = new GridBagConstraints();
432         gridBagConstraints.gridx = 1;
433         gridBagConstraints.gridy = 6;
434         gridBagConstraints.anchor = GridBagConstraints.WEST;
435         gridBagConstraints.insets = new Insets(0, 10, 5, 0);
436         passwordField.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("TTL_Password"));
437         passwordField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle").getString("MSG_Password"));
438         add(passwordField, gridBagConstraints);
439         
440         // remote warning label
441
remoteWarningLabel.setEditable(false);
442         remoteWarningLabel.setWrapStyleWord(true);
443         remoteWarningLabel.setLineWrap(true);
444         remoteWarningLabel.setOpaque(false);
445         remoteWarningLabel.getAccessibleContext().setAccessibleName(
446                 java.util.ResourceBundle.getBundle(
447                 "org/netbeans/modules/j2ee/websphere6/ui/wizard/Bundle").
448                 getString("TTL_RemoteWarningA11Name"));
449         remoteWarningLabel.getAccessibleContext().setAccessibleDescription(
450                 java.util.ResourceBundle.getBundle(
451                 "org/netbeans/modules/j2ee/websphere6/ui/wizard/Bundle").
452                 getString("MSG_RemoteWarningA11Description"));
453         
454         gridBagConstraints = new GridBagConstraints();
455         gridBagConstraints.gridx = 0;
456         gridBagConstraints.gridy = 7;
457         gridBagConstraints.gridwidth = 2;
458         gridBagConstraints.fill = GridBagConstraints.BOTH;
459         gridBagConstraints.anchor = GridBagConstraints.NORTH;
460         gridBagConstraints.weighty = 1.0;
461         gridBagConstraints.insets = new Insets(10, 0, 5, 0);
462         add(remoteWarningLabel, gridBagConstraints);
463         
464         setMnemonics(domainPathLabel);
465         domainPathLabel.setLabelFor(domainPathField);
466         setMnemonics(serverTypeLabel);
467         serverTypeLabel.setLabelFor(serverTypeCombo);
468         setMnemonics(localInstanceLabel);
469         localInstanceLabel.setLabelFor(localInstancesCombo);
470         setMnemonics(hostLabel);
471         hostLabel.setLabelFor(hostField);
472         setMnemonics(portLabel);
473         portLabel.setLabelFor(portField);
474         setMnemonics(userNameLabel);
475         userNameLabel.setLabelFor(usernameField);
476         setMnemonics(passwordLabel);
477         passwordLabel.setLabelFor(passwordField);
478         
479         wizardServerProperties.setVariables(serverTypeCombo,localInstancesCombo,
480                 domainPathField,hostField,portField,instantiatingIterator);
481     }
482     
483     
484     private void setMnemonics(JLabel label) {
485         String JavaDoc name = label.getText();
486         int index = Mnemonics.findMnemonicAmpersand(name);
487         if(index < 0) {
488             Mnemonics.setLocalizedText(label,name);
489             label.setDisplayedMnemonic(name.charAt(0));
490         } else {
491             Mnemonics.setLocalizedText(label,name.substring(0,index) + name.substring(index+1));
492             label.setDisplayedMnemonic(name.charAt(index+1));
493         }
494     }
495     ////////////////////////////////////////////////////////////////////////////
496
// Settings section
497
////////////////////////////////////////////////////////////////////////////
498
/**
499      * Reads the supplied setting. The only one that can arrive this way is the
500      * WizardDescriptor, thus we only convert the incoming object and save
501      *
502      * @param object the incoming setting (WizardDescriptor)
503      */

504     public void readSettings(Object JavaDoc object) {
505         this.wizardDescriptor = (WizardDescriptor) object;
506     }
507     
508     /**
509      * Stores the supplied setting. I don't know the purpose of this method
510      * thus we do not implement it
511      */

512     public void storeSettings(Object JavaDoc object) {
513     }
514     
515     ////////////////////////////////////////////////////////////////////////////
516
// Listeners section
517
////////////////////////////////////////////////////////////////////////////
518
/**
519      * The registrered listeners vector
520      */

521     private Vector listeners = new Vector();
522     
523     /**
524      * Removes a registered listener
525      *
526      * @param listener the listener to be removed
527      */

528     public void removeChangeListener(ChangeListener listener) {
529         if (listeners != null) {
530             synchronized (listeners) {
531                 listeners.remove(listener);
532             }
533         }
534     }
535     
536     /**
537      * Adds a listener
538      *
539      * @param listener the listener to be added
540      */

541     public void addChangeListener(ChangeListener listener) {
542         synchronized (listeners) {
543             listeners.add(listener);
544         }
545     }
546     
547     /**
548      * Fires a change event originating from this panel
549      */

550     private void fireChangeEvent() {
551         ChangeEvent event = new ChangeEvent(this);
552         fireChangeEvent(event);
553     }
554     
555     /**
556      * Fires a custom change event
557      *
558      * @param event the event
559      */

560     private void fireChangeEvent(ChangeEvent event) {
561         Vector targetListeners;
562         synchronized (listeners) {
563             targetListeners = (Vector) listeners.clone();
564         }
565         
566         for (int i = 0; i < targetListeners.size(); i++) {
567             ChangeListener listener =
568                     (ChangeListener) targetListeners.elementAt(i);
569             listener.stateChanged(event);
570         }
571     }
572     
573     ////////////////////////////////////////////////////////////////////////////
574
// Inner classes
575
////////////////////////////////////////////////////////////////////////////
576
/**
577      * Simple key listener that delegates the event to its parent's listeners
578      *
579      * @author Kirill Sorokin
580      */

581     public class KeyListener extends KeyAdapter {
582         /**
583          * This method is called when a user presses a key on the keyboard
584          */

585         public void keyTyped(KeyEvent event) {
586             fireChangeEvent();
587         }
588         
589         /**
590          * This method is called when a user releases a key on the keyboard
591          */

592         public void keyReleased(KeyEvent event) {
593             fireChangeEvent();
594         }
595     }
596 }
Popular Tags