1 19 20 package org.netbeans.modules.j2ee.oc4j.ui.wizards; 21 22 import java.io.File ; 23 import java.util.HashSet ; 24 import java.util.Iterator ; 25 import java.util.Set ; 26 import javax.swing.JFileChooser ; 27 import javax.swing.event.ChangeEvent ; 28 import javax.swing.event.ChangeListener ; 29 import javax.swing.event.DocumentEvent ; 30 import javax.swing.event.DocumentListener ; 31 import org.netbeans.modules.j2ee.oc4j.OC4JDeploymentFactory; 32 import org.openide.util.NbBundle; 33 import org.openide.util.NbPreferences; 34 35 38 public class AddServerLocationVisualPanel extends javax.swing.JPanel { 39 private final Set <ChangeListener > listeners = new HashSet <ChangeListener >(); 40 private static JFileChooser chooser = null; 41 42 43 public AddServerLocationVisualPanel() { 44 initComponents(); 45 setName(NbBundle.getMessage(AddServerLocationVisualPanel.class, "TITLE_ServerLocation")); 46 oc4jHomeTextField.getDocument().addDocumentListener(new DocumentListener () { 47 public void changedUpdate(DocumentEvent e) { 48 fireChangeEvent(); 49 } 50 public void insertUpdate(DocumentEvent e) { 51 fireChangeEvent(); 52 } 53 public void removeUpdate(DocumentEvent e) { 54 fireChangeEvent(); 55 } 56 }); 57 58 initData(); 59 } 60 61 private void initData() { 62 String 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 getOC4JHomeLocation() { 69 return oc4jHomeTextField.getText(); 70 } 71 72 public void addChangeListener(ChangeListener l) { 73 synchronized (listeners) { 74 listeners.add(l); 75 } 76 } 77 78 public void removeChangeListener(ChangeListener l ) { 79 synchronized (listeners) { 80 listeners.remove(l); 81 } 82 } 83 84 private void fireChangeEvent() { 85 Iterator it; 86 synchronized (listeners) { 87 it = new HashSet <ChangeListener >(listeners).iterator(); 88 } 89 ChangeEvent ev = new ChangeEvent (this); 90 while (it.hasNext()) { 91 ((ChangeListener )it.next()).stateChanged (ev); 92 } 93 } 94 95 private String browseOC4JHomeLocation(){ 96 String oc4jLocation = null; 97 JFileChooser chooser = getJFileChooser(); 98 int returnValue = chooser.showDialog(this, NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooseButton")); 100 if(returnValue == JFileChooser.APPROVE_OPTION){ 101 oc4jLocation = chooser.getSelectedFile().getAbsolutePath(); 102 } 103 return oc4jLocation; 104 } 105 106 private JFileChooser getJFileChooser(){ 107 108 if (chooser == null) { 109 chooser = new JFileChooser (); 110 chooser.setDialogTitle(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); chooser.setDialogType(JFileChooser.CUSTOM_DIALOG); 112 113 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 114 chooser.setApproveButtonMnemonic("Choose_Button_Mnemonic".charAt(0)); chooser.setMultiSelectionEnabled(false); 116 chooser.addChoosableFileFilter(new DirFilter()); 117 chooser.setAcceptAllFileFilterUsed(false); 118 chooser.setApproveButtonToolTipText(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); 120 chooser.getAccessibleContext().setAccessibleName(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); chooser.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); } 123 124 File currentLocation = new File (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 gridBagConstraints; 137 138 oc4jHomeLbl = new javax.swing.JLabel (); 139 oc4jHomeTextField = new javax.swing.JTextField (); 140 jButton1 = new javax.swing.JButton (); 141 jPanel1 = new javax.swing.JPanel (); 142 143 setLayout(new java.awt.GridBagLayout ()); 144 145 oc4jHomeLbl.setLabelFor(oc4jHomeTextField); 146 org.openide.awt.Mnemonics.setLocalizedText(oc4jHomeLbl, NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_InstallLocation")); 147 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (); 158 gridBagConstraints.gridy = 1; 159 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 160 gridBagConstraints.weightx = 1.0; 161 gridBagConstraints.insets = new java.awt.Insets (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 () { 166 public void actionPerformed(java.awt.event.ActionEvent evt) { 167 jButton1ActionPerformed(evt); 168 } 169 }); 170 171 gridBagConstraints = new java.awt.GridBagConstraints (); 172 gridBagConstraints.gridy = 1; 173 gridBagConstraints.insets = new java.awt.Insets (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 (); 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 evt) { 190 String newLoc = browseOC4JHomeLocation(); 191 if ((newLoc!=null)&&(!newLoc.equals(""))) 192 oc4jHomeTextField.setText(newLoc); 193 } 194 195 private static class DirFilter extends javax.swing.filechooser.FileFilter { 196 197 public boolean accept(File f) { 198 if(!f.exists() || !f.canRead() || !f.isDirectory() ) { 199 return false; 200 }else{ 201 return true; 202 } 203 } 204 205 public String getDescription() { 206 return NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_DirType"); 207 } 208 209 } 210 211 private javax.swing.JButton jButton1; 213 private javax.swing.JLabel oc4jHomeLbl; 214 private javax.swing.JPanel jPanel1; 215 private javax.swing.JTextField oc4jHomeTextField; 216 } | Popular Tags |