KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > palette > ChooseCategoryWizardPanel


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
20 package org.netbeans.modules.form.palette;
21
22 import javax.swing.*;
23 import javax.swing.event.*;
24 import java.beans.*;
25
26 import org.openide.WizardDescriptor;
27 import org.openide.explorer.*;
28
29 /**
30  * The third panel in the wizard for adding new components to the palette.
31  * Lets the user choose the palette category where to add the selected
32  * components.
33  *
34  * @author Tomas Pavek
35  */

36
37 class ChooseCategoryWizardPanel implements WizardDescriptor.FinishablePanel {
38
39     private CategorySelector categorySelector;
40
41     private EventListenerList listenerList;
42
43     // ----------
44
// WizardDescriptor.Panel implementation
45

46     public java.awt.Component JavaDoc getComponent() {
47         if (categorySelector == null) { // create the UI component for the wizard step
48
categorySelector = new CategorySelector();
49
50             // wizard API: set the caption and index of this panel
51
categorySelector.setName(PaletteUtils.getBundleString("CTL_SelectCategory_Caption")); // NOI18N
52
categorySelector.putClientProperty("WizardPanel_contentSelectedIndex", // NOI18N
53
new Integer JavaDoc(2));
54
55             categorySelector.getExplorerManager().addPropertyChangeListener(
56                 new PropertyChangeListener() {
57                     public void propertyChange(PropertyChangeEvent ev) {
58                         if (ExplorerManager.PROP_SELECTED_NODES.equals(ev.getPropertyName()))
59                             fireStateChanged();
60                     }
61                 });
62         }
63
64         return categorySelector;
65     }
66
67     public org.openide.util.HelpCtx getHelp() {
68         // PENDING
69
return new org.openide.util.HelpCtx("beans.adding"); // NOI18N
70
}
71
72     public boolean isValid() {
73         return categorySelector != null
74                && categorySelector.getSelectedCategory() != null;
75     }
76
77     public void readSettings(Object JavaDoc settings) {
78     }
79
80     public void storeSettings(Object JavaDoc settings) {
81         if (categorySelector != null)
82             ((AddToPaletteWizard)settings).setSelectedCategory(categorySelector.getSelectedCategory());
83     }
84
85     public void addChangeListener(ChangeListener listener) {
86         if (listenerList == null)
87             listenerList = new EventListenerList();
88         listenerList.add(ChangeListener.class, listener);
89     }
90
91     public void removeChangeListener(ChangeListener listener) {
92         if (listenerList != null)
93             listenerList.remove(ChangeListener.class, listener);
94     }
95
96     // WizardDescriptor.FinishablePanel implementation
97
public boolean isFinishPanel() {
98         return true;
99     }
100
101     // -----
102

103     void fireStateChanged() {
104         if (listenerList == null)
105             return;
106
107         ChangeEvent e = null;
108         Object JavaDoc[] listeners = listenerList.getListenerList();
109         for (int i=listeners.length-2; i >= 0; i-=2) {
110             if (listeners[i] == ChangeListener.class) {
111                 if (e == null)
112                     e = new ChangeEvent(this);
113                 ((ChangeListener)listeners[i+1]).stateChanged(e);
114             }
115         }
116     }
117 }
118
Popular Tags