1 19 package org.netbeans.modules.j2ee.jboss4.ide.ui; 20 21 import java.io.File ; 22 import java.util.HashSet ; 23 import java.util.Iterator ; 24 import java.util.Set ; 25 import javax.swing.JFileChooser ; 26 import javax.swing.event.ChangeEvent ; 27 import javax.swing.event.ChangeListener ; 28 import javax.swing.event.DocumentEvent ; 29 import javax.swing.event.DocumentListener ; 30 import org.openide.util.NbBundle; 31 32 36 public class AddServerLocationVisualPanel extends javax.swing.JPanel { 37 private final Set listeners = new HashSet (); 38 private static JFileChooser chooser = null; 39 40 41 42 43 public AddServerLocationVisualPanel() { 44 initComponents(); 45 setName(NbBundle.getMessage(AddServerLocationVisualPanel.class, "TITLE_ServerLocation")); 46 locationTextField.getDocument().addDocumentListener(new DocumentListener () { 47 public void changedUpdate(DocumentEvent e) { 48 locationChanged(); 49 } 50 public void insertUpdate(DocumentEvent e) { 51 locationChanged(); 52 } 53 public void removeUpdate(DocumentEvent e) { 54 locationChanged(); 55 } 56 }); 57 } 58 59 public String getInstallLocation() { 60 return locationTextField.getText(); 61 } 62 63 public void addChangeListener(ChangeListener l) { 64 synchronized (listeners) { 65 listeners.add(l); 66 } 67 } 68 69 public void removeChangeListener(ChangeListener l ) { 70 synchronized (listeners) { 71 listeners.remove(l); 72 } 73 } 74 75 private void fireChangeEvent() { 76 Iterator it; 77 synchronized (listeners) { 78 it = new HashSet (listeners).iterator(); 79 } 80 ChangeEvent ev = new ChangeEvent (this); 81 while (it.hasNext()) { 82 ((ChangeListener )it.next()).stateChanged (ev); 83 } 84 } 85 86 private void locationChanged() { 87 fireChangeEvent(); 88 } 89 90 private String browseInstallLocation(){ 91 String insLocation = null; 92 JFileChooser chooser = getJFileChooser(); 93 int returnValue = chooser.showDialog(this, NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooseButton")); 95 if(returnValue == JFileChooser.APPROVE_OPTION){ 96 insLocation = chooser.getSelectedFile().getAbsolutePath(); 97 } 98 return insLocation; 99 } 100 101 private JFileChooser getJFileChooser(){ 102 104 if (chooser == null) { 105 106 chooser = new JFileChooser (); 107 108 chooser.setDialogTitle(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); chooser.setDialogType(JFileChooser.CUSTOM_DIALOG); 110 111 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 112 chooser.setApproveButtonMnemonic("Choose_Button_Mnemonic".charAt(0)); chooser.setMultiSelectionEnabled(false); 114 chooser.addChoosableFileFilter(new dirFilter()); 115 chooser.setAcceptAllFileFilterUsed(false); 116 chooser.setApproveButtonToolTipText(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); 118 chooser.getAccessibleContext().setAccessibleName(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); chooser.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); } 121 122 File currentLocation = new File (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 gridBagConstraints; 136 137 jPanel2 = new javax.swing.JPanel (); 138 jLabel1 = new javax.swing.JLabel (); 140 locationTextField = new javax.swing.JTextField (); 141 jButton1 = new javax.swing.JButton (); 142 jPanel1 = new javax.swing.JPanel (); 143 144 setLayout(new java.awt.GridBagLayout ()); 145 146 161 jLabel1.setLabelFor(locationTextField); 162 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_InstallLocation")); 163 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (); 174 gridBagConstraints.gridy = 1; 175 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 176 gridBagConstraints.weightx = 1.0; 177 gridBagConstraints.insets = new java.awt.Insets (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 () { 182 public void actionPerformed(java.awt.event.ActionEvent evt) { 183 jButton1ActionPerformed(evt); 184 } 185 }); 186 187 gridBagConstraints = new java.awt.GridBagConstraints (); 188 gridBagConstraints.gridy = 1; 189 gridBagConstraints.insets = new java.awt.Insets (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 (); 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().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 evt) { 213 String newLoc = browseInstallLocation(); 214 if ((newLoc!=null)&&(!newLoc.equals(""))) 215 locationTextField.setText(newLoc); 216 } 217 218 private static class dirFilter extends javax.swing.filechooser.FileFilter { 219 220 public boolean accept(File f) { 221 if(!f.exists() || !f.canRead() || !f.isDirectory() ) { 222 return false; 223 }else{ 224 return true; 225 } 226 } 227 228 public String getDescription() { 229 return NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_DirType"); 230 } 231 232 } 233 234 private javax.swing.JButton jButton1; 236 private javax.swing.JLabel jLabel1; 237 private javax.swing.JPanel jPanel1; 238 private javax.swing.JPanel jPanel2; 239 private javax.swing.JTextArea jTextArea1; 240 private javax.swing.JTextField locationTextField; 241 243 } 244 | Popular Tags |