KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > jboss4 > ide > ui > 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 package org.netbeans.modules.j2ee.jboss4.ide.ui;
20
21 import java.io.File JavaDoc;
22 import java.util.HashSet JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Set JavaDoc;
25 import javax.swing.JFileChooser JavaDoc;
26 import javax.swing.event.ChangeEvent JavaDoc;
27 import javax.swing.event.ChangeListener JavaDoc;
28 import javax.swing.event.DocumentEvent JavaDoc;
29 import javax.swing.event.DocumentListener JavaDoc;
30 import org.openide.util.NbBundle;
31
32 /**
33  *
34  * @author Ivan Sidorkin
35  */

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

95         if(returnValue == JFileChooser.APPROVE_OPTION){
96             insLocation = chooser.getSelectedFile().getAbsolutePath();
97         }
98         return insLocation;
99     }
100     
101     private JFileChooser JavaDoc getJFileChooser(){
102         //JFileChooser chooser = new JFileChooser();
103

104         if (chooser == null) {
105         
106             chooser = new JFileChooser JavaDoc();
107
108             chooser.setDialogTitle(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N
109
chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
110
111             chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
112             chooser.setApproveButtonMnemonic("Choose_Button_Mnemonic".charAt(0)); //NOI18N
113
chooser.setMultiSelectionEnabled(false);
114             chooser.addChoosableFileFilter(new dirFilter());
115             chooser.setAcceptAllFileFilterUsed(false);
116             chooser.setApproveButtonToolTipText(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N
117

118             chooser.getAccessibleContext().setAccessibleName(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N
119
chooser.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N
120
}
121
122         // set the current directory
123
File JavaDoc currentLocation = new File JavaDoc(locationTextField.getText());
124         if (currentLocation.exists() && currentLocation.isDirectory()) {
125             chooser.setCurrentDirectory(currentLocation.getParentFile());
126             chooser.setSelectedFile(currentLocation);
127         }
128         
129         
130         return chooser;
131     }
132     
133     
134     private void initComponents() {
135         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
136
137         jPanel2 = new javax.swing.JPanel JavaDoc();
138 // jTextArea1 = new javax.swing.JTextArea();
139
jLabel1 = new javax.swing.JLabel JavaDoc();
140         locationTextField = new javax.swing.JTextField JavaDoc();
141         jButton1 = new javax.swing.JButton JavaDoc();
142         jPanel1 = new javax.swing.JPanel JavaDoc();
143
144         setLayout(new java.awt.GridBagLayout JavaDoc());
145
146 // jTextArea1.setBackground(java.awt.Color.lightGray);
147
// jTextArea1.setEditable(false);
148
// jTextArea1.setLineWrap(true);
149
// //jTextArea1.setText(org.openide.util.NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_InstallLocationInfo"));
150
// jTextArea1.setText(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_InstallLocationInfo"));
151
// jTextArea1.setWrapStyleWord(true);
152
// jTextArea1.setFocusable(false);
153
// jTextArea1.setOpaque(false);
154
// gridBagConstraints = new java.awt.GridBagConstraints();
155
// gridBagConstraints.gridwidth = 3;
156
// gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
157
// gridBagConstraints.weightx = 1.0;
158
// gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
159
// add(jTextArea1, gridBagConstraints);
160

161         jLabel1.setLabelFor(locationTextField);
162         org.openide.awt.Mnemonics.setLocalizedText(jLabel1, NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_InstallLocation"));
163         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
164         gridBagConstraints.gridx = 0;
165         gridBagConstraints.gridy = 1;
166         add(jLabel1, gridBagConstraints);
167         locationTextField.setColumns(15);
168         locationTextField.getAccessibleContext().setAccessibleDescription(
169                 NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_InstallLocation"));
170         locationTextField.getAccessibleContext().setAccessibleName(
171                 NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_InstallLocation"));
172
173         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
174         gridBagConstraints.gridy = 1;
175         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
176         gridBagConstraints.weightx = 1.0;
177         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
178         add(locationTextField, gridBagConstraints);
179
180         org.openide.awt.Mnemonics.setLocalizedText(jButton1, NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_BrowseButton"));
181         jButton1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
182             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
183                 jButton1ActionPerformed(evt);
184             }
185         });
186
187         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
188         gridBagConstraints.gridy = 1;
189         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
190         add(jButton1, gridBagConstraints);
191         jButton1.getAccessibleContext().setAccessibleName(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_BrowseButton"));
192         jButton1.getAccessibleContext().setAccessibleDescription("ACSD_Browse_Button_InstallLoc");
193
194         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
195         gridBagConstraints.gridx = 0;
196         gridBagConstraints.gridwidth = 3;
197         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
198         gridBagConstraints.weightx = 1.0;
199         gridBagConstraints.weighty = 1.0;
200         add(jPanel1, gridBagConstraints);
201         jPanel1.getAccessibleContext().setAccessibleName("TITLE_AddServerLocationPanel");
202        // jPanel1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(AddServerLocationVisualPanel.class, "TITLE_AddServerLocationPanel"));
203
jPanel1.getAccessibleContext().setAccessibleDescription("AddServerLocationPanel_Desc");
204
205         if (JBPluginProperties.getInstance().getInstallLocation()!=null){
206             locationTextField.setText(JBPluginProperties.getInstance().getInstallLocation());
207         }
208         
209     }
210
211
212     private void jButton1ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
213         String JavaDoc newLoc = browseInstallLocation();
214         if ((newLoc!=null)&&(!newLoc.equals("")))
215         locationTextField.setText(newLoc);
216     }
217
218     private static class dirFilter extends javax.swing.filechooser.FileFilter JavaDoc {
219         
220         public boolean accept(File JavaDoc f) {
221             if(!f.exists() || !f.canRead() || !f.isDirectory() ) {
222                 return false;
223             }else{
224                 return true;
225             }
226         }
227         
228         public String JavaDoc getDescription() {
229             return NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_DirType");
230         }
231         
232     }
233     
234     // Variables declaration - do not modify
235
private javax.swing.JButton JavaDoc jButton1;
236     private javax.swing.JLabel JavaDoc jLabel1;
237     private javax.swing.JPanel JavaDoc jPanel1;
238     private javax.swing.JPanel JavaDoc jPanel2;
239     private javax.swing.JTextArea JavaDoc jTextArea1;
240     private javax.swing.JTextField JavaDoc locationTextField;
241     // End of variables declaration
242

243 }
244
Popular Tags