1 package org.enhydra.kelp.ant.deployer; 2 3 25 26 import org.enhydra.tool.common.DirectoryFilter; 28 import org.enhydra.tool.common.SwingUtil; 29 30 import java.awt.Dimension ; 32 import java.awt.Dialog ; 33 import java.awt.Frame ; 34 import java.awt.GridBagLayout ; 35 import java.awt.GridBagConstraints ; 36 import java.awt.Insets ; 37 import java.awt.Point ; 38 import java.awt.event.ActionEvent ; 39 import java.awt.event.ActionListener ; 40 import java.io.File ; 41 import java.beans.Beans ; 42 import javax.swing.JButton ; 43 import javax.swing.JDialog ; 44 import javax.swing.JPanel ; 45 import javax.swing.JTextField ; 46 import javax.swing.JLabel ; 47 import java.util.ResourceBundle ; 48 49 56 public class AntDeployReplaceEditorDialog extends JDialog { 57 static ResourceBundle res = 58 ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); public static final int ACTION_OK = 0; 60 public static final int ACTION_CANCEL = 1; 61 private static File startFolder = null; 62 private int option = ACTION_CANCEL; 63 private LocalButtonListener buttonListener = null; 64 private JPanel panelMain = new JPanel (); 65 private GridBagLayout layoutMain; 66 private JPanel panelEntry; 67 private GridBagLayout layoutEntry; 68 private JPanel panelButtons; 69 private GridBagLayout layoutButton; 70 private JLabel labelFind; 71 private JTextField textFind; 72 private JButton buttonBrowse; 73 private JLabel labelReplaceWith; 74 private JTextField textReplaceWith; 75 private JButton buttonCancel; 76 private JButton buttonOK; 77 78 86 public AntDeployReplaceEditorDialog(Dialog owner, String title, boolean modal) { 87 super(owner, title, modal); 88 construct(); 89 } 90 91 public AntDeployReplaceEditorDialog(Frame owner, String title, boolean modal) { 92 super(owner, title, modal); 93 construct(); 94 } 95 96 private void construct() { 97 try { 98 jbInit(); 99 pmInit(); 100 pack(); 101 } catch (Exception ex) { 102 ex.printStackTrace(); 103 } 104 } 105 106 110 public AntDeployReplaceEditorDialog() { 111 this(new Frame (), new String (), false); 112 } 113 114 118 public void show() { 119 setResizable(false); 120 Point cPoint; 121 122 invalidate(); 123 doLayout(); 124 pack(); 125 cPoint = SwingUtil.getCenteringPoint(getSize()); 126 setLocation(cPoint); 127 super.show(); 128 } 129 130 134 private void pmInit() { 135 buttonListener = new LocalButtonListener(); 136 buttonBrowse.addActionListener(buttonListener); 137 buttonOK.addActionListener(buttonListener); 138 buttonCancel.addActionListener(buttonListener); 139 textFind.setText(new String ()); 140 textReplaceWith.setText(new String ()); 141 } 142 143 149 private void jbInit() throws Exception { 150 layoutMain = 151 (GridBagLayout ) Beans.instantiate(getClass().getClassLoader(), 152 GridBagLayout .class.getName()); 153 panelEntry = (JPanel ) Beans.instantiate(getClass().getClassLoader(), 154 JPanel .class.getName()); 155 layoutEntry = 156 (GridBagLayout ) Beans.instantiate(getClass().getClassLoader(), 157 GridBagLayout .class.getName()); 158 panelButtons = (JPanel ) Beans.instantiate(getClass().getClassLoader(), 159 JPanel .class.getName()); 160 layoutButton = 161 (GridBagLayout ) Beans.instantiate(getClass().getClassLoader(), 162 GridBagLayout .class.getName()); 163 labelFind = (JLabel ) Beans.instantiate(getClass().getClassLoader(), 164 JLabel .class.getName()); 165 textFind = (JTextField ) Beans.instantiate(getClass().getClassLoader(), 166 JTextField .class.getName()); 167 buttonBrowse = 168 (JButton ) Beans.instantiate(getClass().getClassLoader(), 169 JButton .class.getName()); 170 labelReplaceWith = 171 (JLabel ) Beans.instantiate(getClass().getClassLoader(), 172 JLabel .class.getName()); 173 textReplaceWith = 174 (JTextField ) Beans.instantiate(getClass().getClassLoader(), 175 JTextField .class.getName()); 176 buttonCancel = 177 (JButton ) Beans.instantiate(getClass().getClassLoader(), 178 JButton .class.getName()); 179 buttonOK = (JButton ) Beans.instantiate(getClass().getClassLoader(), 180 JButton .class.getName()); 181 panelMain.setLayout(layoutMain); 182 panelEntry.setLayout(layoutEntry); 183 panelButtons.setLayout(layoutButton); 184 labelFind.setText(res.getString("labelFind_Text")); 185 textFind.setPreferredSize(new Dimension (250, 21)); 186 labelReplaceWith.setText(res.getString("labelReplaceWith_Text")); 187 textReplaceWith.setPreferredSize(new Dimension (250, 21)); 188 buttonBrowse.setText(res.getString("Browse")); 189 buttonCancel.setText(res.getString("Cancel")); 190 buttonOK.setText(res.getString("OK")); 191 getContentPane().add(panelMain); 192 panelMain.add(panelEntry, 193 new GridBagConstraints (0, 0, 1, 1, 0.2, 0.2, 194 GridBagConstraints.CENTER, 195 GridBagConstraints.BOTH, 196 new Insets (0, 0, 0, 0), 0, 0)); 197 panelEntry.add(labelFind, 198 new GridBagConstraints (0, 0, 1, 1, 0.2, 0.2, 199 GridBagConstraints.WEST, 200 GridBagConstraints.HORIZONTAL, 201 new Insets (5, 5, 5, 5), 0, 0)); 202 panelEntry.add(textFind, 203 new GridBagConstraints (0, 1, 1, 1, 0.4, 0.4, 204 GridBagConstraints.WEST, 205 GridBagConstraints.HORIZONTAL, 206 new Insets (5, 5, 5, 5), 200, 207 0)); 208 panelEntry.add(labelReplaceWith, 209 new GridBagConstraints (0, 2, 1, 1, 0.2, 0.2, 210 GridBagConstraints.WEST, 211 GridBagConstraints.HORIZONTAL, 212 new Insets (5, 5, 5, 5), 0, 0)); 213 panelEntry.add(textReplaceWith, 214 new GridBagConstraints (0, 3, 1, 1, 0.4, 0.4, 215 GridBagConstraints.WEST, 216 GridBagConstraints.HORIZONTAL, 217 new Insets (5, 5, 5, 5), 200, 218 0)); 219 panelEntry.add(buttonBrowse, 220 new GridBagConstraints (1, 3, 1, 1, 0.2, 0.2, 221 GridBagConstraints.CENTER, 222 GridBagConstraints.NONE, 223 new Insets (5, 5, 5, 5), 0, 0)); 224 panelMain.add(panelButtons, 225 new GridBagConstraints (0, 1, 1, 1, 0.2, 0.2, 226 GridBagConstraints.CENTER, 227 GridBagConstraints.BOTH, 228 new Insets (5, 5, 5, 0), 0, 0)); 229 panelButtons.add(buttonOK, 230 new GridBagConstraints (0, 0, 1, 1, 0.0, 0.0, 231 GridBagConstraints.CENTER, 232 GridBagConstraints.NONE, 233 new Insets (5, 5, 5, 5), 0, 234 0)); 235 panelButtons.add(buttonCancel, 236 new GridBagConstraints (1, 0, 1, 1, 0.0, 0.0, 237 GridBagConstraints.CENTER, 238 GridBagConstraints.NONE, 239 new Insets (5, 5, 5, 5), 0, 240 0)); 241 } 242 243 247 protected void closeDialog() { 248 setVisible(false); 249 removeAll(); 250 dispose(); 251 } 252 253 259 protected int getOption() { 260 return option; 261 } 262 263 269 protected String getFind() { 270 return textFind.getText(); 271 } 272 273 protected void setFind(String find) { 274 textFind.setText(find); 275 } 276 277 283 protected String getReplaceWith() { 284 return textReplaceWith.getText(); 285 } 286 287 protected void setReplaceWith(String replace) { 288 textReplaceWith.setText(replace); 289 } 290 291 297 private void setOption(int o) { 298 option = o; 299 } 300 301 305 private void browseAction() { 306 File choice; 307 308 if (startFolder == null ||!startFolder.exists()) { 309 startFolder = new File (textReplaceWith.getText()); 310 } 311 choice = 312 SwingUtil.getDirectoryChoice(this, startFolder, 313 res.getString("Select_folder_to_use")); 314 buttonBrowse.requestFocus(); 315 if (choice != null) { 316 textReplaceWith.setText(choice.toString()); 317 startFolder = choice; } 319 } 320 321 class LocalButtonListener implements ActionListener { 322 323 329 public void actionPerformed(ActionEvent event) { 330 Object source = event.getSource(); 331 332 if (source == buttonBrowse) { 333 browseAction(); 334 } else if (source == buttonOK) { 335 setOption(ACTION_OK); 336 closeDialog(); 337 } else if (source == buttonCancel) { 338 setOption(ACTION_CANCEL); 339 closeDialog(); 340 } 341 } 342 343 } 344 } 345 | Popular Tags |