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