KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > oc4j > ui > wizards > AddServerLocationVisualPanel


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.j2ee.oc4j.ui.wizards;
21
22 import java.io.File JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.Set JavaDoc;
26 import javax.swing.JFileChooser JavaDoc;
27 import javax.swing.event.ChangeEvent JavaDoc;
28 import javax.swing.event.ChangeListener JavaDoc;
29 import javax.swing.event.DocumentEvent JavaDoc;
30 import javax.swing.event.DocumentListener JavaDoc;
31 import org.netbeans.modules.j2ee.oc4j.OC4JDeploymentFactory;
32 import org.openide.util.NbBundle;
33 import org.openide.util.NbPreferences;
34
35 /**
36  * @author pblaha
37  */

38 public class AddServerLocationVisualPanel extends javax.swing.JPanel JavaDoc {
39     private final Set JavaDoc <ChangeListener JavaDoc> listeners = new HashSet JavaDoc<ChangeListener JavaDoc>();
40     private static JFileChooser JavaDoc chooser = null;
41
42     /** Creates new form AddServerLocationVisualPanel */
43     public AddServerLocationVisualPanel() {
44         initComponents();
45         setName(NbBundle.getMessage(AddServerLocationVisualPanel.class, "TITLE_ServerLocation"));
46         oc4jHomeTextField.getDocument().addDocumentListener(new DocumentListener JavaDoc() {
47             public void changedUpdate(DocumentEvent JavaDoc e) {
48                 fireChangeEvent();
49             }
50             public void insertUpdate(DocumentEvent JavaDoc e) {
51                 fireChangeEvent();
52             }
53             public void removeUpdate(DocumentEvent JavaDoc e) {
54                 fireChangeEvent();
55             }
56         });
57         
58         initData();
59     }
60     
61     private void initData() {
62         String JavaDoc root = NbPreferences.forModule(OC4JDeploymentFactory.class).get(OC4JDeploymentFactory.PROP_SERVER_ROOT, "");
63         
64         if (root.length() != 0)
65             oc4jHomeTextField.setText(root);
66     }
67     
68     public String JavaDoc getOC4JHomeLocation() {
69         return oc4jHomeTextField.getText();
70     }
71     
72     public void addChangeListener(ChangeListener JavaDoc l) {
73         synchronized (listeners) {
74             listeners.add(l);
75         }
76     }
77     
78     public void removeChangeListener(ChangeListener JavaDoc l ) {
79         synchronized (listeners) {
80             listeners.remove(l);
81         }
82     }
83
84     private void fireChangeEvent() {
85         Iterator JavaDoc it;
86         synchronized (listeners) {
87             it = new HashSet JavaDoc<ChangeListener JavaDoc>(listeners).iterator();
88         }
89         ChangeEvent JavaDoc ev = new ChangeEvent JavaDoc(this);
90         while (it.hasNext()) {
91             ((ChangeListener JavaDoc)it.next()).stateChanged (ev);
92         }
93     }
94     
95     private String JavaDoc browseOC4JHomeLocation(){
96         String JavaDoc oc4jLocation = null;
97         JFileChooser JavaDoc chooser = getJFileChooser();
98         int returnValue = chooser.showDialog(this, NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooseButton")); //NOI18N
99

100         if(returnValue == JFileChooser.APPROVE_OPTION){
101             oc4jLocation = chooser.getSelectedFile().getAbsolutePath();
102         }
103         return oc4jLocation;
104     }
105     
106     private JFileChooser JavaDoc getJFileChooser(){
107         
108         if (chooser == null) {
109             chooser = new JFileChooser JavaDoc();
110             chooser.setDialogTitle(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N
111
chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
112
113             chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
114             chooser.setApproveButtonMnemonic("Choose_Button_Mnemonic".charAt(0)); //NOI18N
115
chooser.setMultiSelectionEnabled(false);
116             chooser.addChoosableFileFilter(new DirFilter());
117             chooser.setAcceptAllFileFilterUsed(false);
118             chooser.setApproveButtonToolTipText(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N
119

120             chooser.getAccessibleContext().setAccessibleName(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N
121
chooser.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N
122
}
123
124         // set the current directory
125
File JavaDoc currentLocation = new File JavaDoc(oc4jHomeTextField.getText());
126         if (currentLocation.exists() && currentLocation.isDirectory()) {
127             chooser.setCurrentDirectory(currentLocation.getParentFile());
128             chooser.setSelectedFile(currentLocation);
129         }
130         
131         
132         return chooser;
133     }
134     
135     private void initComponents() {
136         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
137
138         oc4jHomeLbl = new javax.swing.JLabel JavaDoc();
139         oc4jHomeTextField = new javax.swing.JTextField JavaDoc();
140         jButton1 = new javax.swing.JButton JavaDoc();
141         jPanel1 = new javax.swing.JPanel JavaDoc();
142
143         setLayout(new java.awt.GridBagLayout JavaDoc());
144
145         oc4jHomeLbl.setLabelFor(oc4jHomeTextField);
146         org.openide.awt.Mnemonics.setLocalizedText(oc4jHomeLbl, NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_InstallLocation"));
147         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
148         gridBagConstraints.gridx = 0;
149         gridBagConstraints.gridy = 1;
150         add(oc4jHomeLbl, gridBagConstraints);
151         oc4jHomeTextField.setColumns(15);
152         oc4jHomeTextField.getAccessibleContext().setAccessibleDescription(
153                 NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_InstallLocation"));
154         oc4jHomeTextField.getAccessibleContext().setAccessibleName(
155                 NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_InstallLocation"));
156
157         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
158         gridBagConstraints.gridy = 1;
159         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
160         gridBagConstraints.weightx = 1.0;
161         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
162         add(oc4jHomeTextField, gridBagConstraints);
163
164         org.openide.awt.Mnemonics.setLocalizedText(jButton1, NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_BrowseButton"));
165         jButton1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
166             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
167                 jButton1ActionPerformed(evt);
168             }
169         });
170
171         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
172         gridBagConstraints.gridy = 1;
173         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
174         add(jButton1, gridBagConstraints);
175         jButton1.getAccessibleContext().setAccessibleName(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_BrowseButton"));
176         jButton1.getAccessibleContext().setAccessibleDescription("ACSD_Browse_Button_InstallLoc");
177
178         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
179         gridBagConstraints.gridx = 0;
180         gridBagConstraints.gridwidth = 3;
181         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
182         gridBagConstraints.weightx = 1.0;
183         gridBagConstraints.weighty = 1.0;
184         add(jPanel1, gridBagConstraints);
185         jPanel1.getAccessibleContext().setAccessibleName("TITLE_AddServerLocationPanel");
186         jPanel1.getAccessibleContext().setAccessibleDescription("AddServerLocationPanel_Desc");
187     }
188
189     private void jButton1ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
190         String JavaDoc newLoc = browseOC4JHomeLocation();
191         if ((newLoc!=null)&&(!newLoc.equals("")))
192         oc4jHomeTextField.setText(newLoc);
193     }
194
195     private static class DirFilter extends javax.swing.filechooser.FileFilter JavaDoc {
196         
197         public boolean accept(File JavaDoc f) {
198             if(!f.exists() || !f.canRead() || !f.isDirectory() ) {
199                 return false;
200             }else{
201                 return true;
202             }
203         }
204         
205         public String JavaDoc getDescription() {
206             return NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_DirType");
207         }
208         
209     }
210     
211     // Variables declaration - do not modify
212
private javax.swing.JButton JavaDoc jButton1;
213     private javax.swing.JLabel JavaDoc oc4jHomeLbl;
214     private javax.swing.JPanel JavaDoc jPanel1;
215     private javax.swing.JTextField JavaDoc oc4jHomeTextField;
216     // End of variables declaration
217
}
Popular Tags