KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.File JavaDoc;
23 import javax.swing.JFileChooser JavaDoc;
24 import javax.swing.BorderFactory JavaDoc;
25 import javax.swing.event.*;
26 import java.awt.event.*;
27 import java.beans.*;
28
29 import org.openide.WizardDescriptor;
30
31 /**
32  * The first panel in the wizard for adding new components to the palette from
33  * a JAR. In this panel (as the first step) the user chooses the JAR file.
34  * The alternative first steps are ChooseLibraryWizardPanel and
35  * ChooseProjectWizardPanel.
36  *
37  * @author Tomas Pavek
38  */

39
40 class ChooseJARWizardPanel implements WizardDescriptor.Panel {
41
42     private JFileChooser JavaDoc fileChooser;
43     private static String JavaDoc lastDirectoryUsed;
44
45     private AddToPaletteWizard wizard;
46
47     private EventListenerList listenerList;
48
49     // ----------
50
// WizardDescriptor.Panel implementation
51

52     public java.awt.Component JavaDoc getComponent() {
53         if (fileChooser == null) { // create the UI component for the wizard step
54
fileChooser = new JFileChooser JavaDoc(lastDirectoryUsed);
55             fileChooser.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
56
57             // wizard API: set the caption and index of this panel
58
fileChooser.setName(PaletteUtils.getBundleString("CTL_SelectJAR_Caption")); // NOI18N
59
fileChooser.putClientProperty("WizardPanel_contentSelectedIndex", // NOI18N
60
new Integer JavaDoc(0));
61
62             fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
63             fileChooser.setAcceptAllFileFilterUsed(true);
64             fileChooser.setControlButtonsAreShown(false);
65             fileChooser.setMultiSelectionEnabled(true);
66
67             fileChooser.setFileFilter(new javax.swing.filechooser.FileFilter JavaDoc() {
68                 public boolean accept(File JavaDoc f) {
69                     return f.isDirectory()
70                            || f.getName().toLowerCase().endsWith(".jar"); // NOI18N
71
}
72                 public String JavaDoc getDescription() {
73                     return PaletteUtils.getBundleString("CTL_JarArchivesMask"); // NOI18N
74
}
75             });
76
77             fileChooser.addActionListener(new ActionListener() {
78                 public void actionPerformed(ActionEvent ev) {
79                     wizard.stepToNext();
80                 }
81             });
82
83             fileChooser.addPropertyChangeListener(new PropertyChangeListener() {
84                 public void propertyChange(PropertyChangeEvent ev) {
85                     if (JFileChooser.SELECTED_FILES_CHANGED_PROPERTY
86                                         .equals(ev.getPropertyName()))
87                         fireStateChanged();
88                 }
89             });
90         }
91
92         return fileChooser;
93     }
94
95     public org.openide.util.HelpCtx getHelp() {
96         // PENDING
97
return new org.openide.util.HelpCtx("beans.adding"); // NOI18N
98
}
99
100     public boolean isValid() {
101         if (fileChooser != null && fileChooser.getSelectedFiles().length > 0) {
102             lastDirectoryUsed = fileChooser.getCurrentDirectory().getAbsolutePath();
103             return true;
104         }
105         return false;
106     }
107
108     public void readSettings(Object JavaDoc settings) {
109         wizard = (AddToPaletteWizard) settings;
110     }
111
112     public void storeSettings(Object JavaDoc settings) {
113         if (fileChooser != null)
114             ((AddToPaletteWizard)settings).setJARFiles(fileChooser.getSelectedFiles());
115     }
116
117     public void addChangeListener(ChangeListener listener) {
118         if (listenerList == null)
119             listenerList = new EventListenerList();
120         listenerList.add(ChangeListener.class, listener);
121     }
122
123     public void removeChangeListener(ChangeListener listener) {
124         if (listenerList != null)
125             listenerList.remove(ChangeListener.class, listener);
126     }
127
128     // -----
129

130     void fireStateChanged() {
131         if (listenerList == null)
132             return;
133
134         ChangeEvent e = null;
135         Object JavaDoc[] listeners = listenerList.getListenerList();
136         for (int i=listeners.length-2; i >= 0; i-=2) {
137             if (listeners[i] == ChangeListener.class) {
138                 if (e == null)
139                     e = new ChangeEvent(this);
140                 ((ChangeListener)listeners[i+1]).stateChanged(e);
141             }
142         }
143     }
144 }
145
Popular Tags