1 2 23 package org.enhydra.tool.codegen.wizard; 24 25 27 import org.enhydra.tool.codegen.ProjectOptionSet; 28 import org.enhydra.tool.codegen.GeneratorOption; 29 import org.enhydra.tool.codegen.GeneratorException; 30 import org.enhydra.tool.codegen.ValidationException; 31 import org.enhydra.tool.common.ExtensionFilter; 32 import org.enhydra.tool.common.FileUtil; 33 import org.enhydra.tool.common.SwingUtil; 34 35 37 import javax.swing.*; 38 import javax.swing.border.*; 39 import javax.swing.event.*; 40 import java.awt.*; 41 import java.awt.event.ActionEvent ; 42 import java.awt.event.ActionListener ; 43 import java.awt.event.ItemEvent ; 44 import java.awt.event.ItemListener ; 45 import java.beans.*; 46 import java.io.File ; 47 import java.util.ResourceBundle ; 48 49 55 public class ProjectOptionPanel2 extends CodeGenPanel { 56 57 59 private final String TXT_TYPE = "txt"; 61 64 67 transient public JPanel panelCopyright; 68 69 72 transient public JButton buttonSet; 73 74 77 transient public JTextField textCopyrightFile; 78 79 82 transient public JTextArea textCopyright; 83 84 87 transient public JRadioButton radioFile; 88 89 92 transient public JRadioButton radioText; 93 94 97 transient public JRadioButton radioNone; 98 99 102 transient public ButtonGroup radioGroup; 103 104 106 transient private JScrollPane scroll; 107 transient private JPanel panelFiller; 108 transient private GridBagLayout layoutMain; 109 transient private GridBagLayout layoutDest; 110 transient private LocalRadioListener radioListener; 111 transient private LocalButtonListener buttonListener; 112 113 117 public ProjectOptionPanel2 () { 118 try { 119 jbInit (); 120 pmInit (); 121 } catch (Exception ex) { 122 ex.printStackTrace (); 123 } 124 } 125 126 133 public void readOptionSet () throws GeneratorException { 134 GeneratorOption option = null; 135 136 138 option = getOptionSet ().lookup (ProjectOptionSet.COPYRIGHT); 139 140 textCopyright.setText (option.getValue ()); 141 142 144 option = getOptionSet ().lookup (ProjectOptionSet.COPYRIGHTFILE); 145 146 if (FileUtil.isFile (option.getValue ())) { 147 textCopyrightFile.setText (option.getValue ()); 148 } else { 149 textCopyrightFile.setText (new String ()); 150 } 151 152 if (textCopyright.getText ().trim ().length () > 0) { 153 radioText.setSelected (true); 154 } else if (textCopyrightFile.getText ().trim ().length () > 0) { 155 radioFile.setSelected (true); 156 } else { 157 radioNone.setSelected (true); 158 } 159 } 160 161 168 public void writeOptionSet () throws GeneratorException { 169 String value = new String (); 170 171 173 value = textCopyright.getText ().trim (); 174 175 getOptionSet ().lookup (ProjectOptionSet.COPYRIGHT).setValue (value); 176 177 179 value = textCopyrightFile.getText (); 180 181 getOptionSet ().lookup (ProjectOptionSet.COPYRIGHTFILE).setValue (value); 182 } 183 184 192 public void validateOptionSet () throws ValidationException { 193 String value = new String (); 194 195 if (textCopyrightFile.getText ().trim ().length () > 0) { 196 File file = new File (textCopyrightFile.getText ()); 197 198 if ((!file.exists ()) || (!file.isFile ())) { 199 throw new ValidationException (res.getString ("Copyright_file_is_not")); 200 } 201 } 202 } 203 204 210 public String getPageTitle () { 211 return res.getString ("Copyright"); 212 } 213 214 221 public String getInstructions () { 222 StringBuffer buf = new StringBuffer (); 223 224 buf.append (res.getString ("InstructCopy1")); 225 buf.append (res.getString ("InstructCopy2")); 226 buf.append (res.getString ("InstructCopy3")); 227 buf.append (res.getString ("InstructCopy4")); 228 229 return buf.toString (); 230 } 231 232 236 242 private void jbInit () throws Exception { 243 panelCopyright = 244 (JPanel) Beans.instantiate (getClass ().getClassLoader (), 245 JPanel.class.getName ()); 246 layoutDest = 247 (GridBagLayout) Beans.instantiate (getClass ().getClassLoader (), 248 GridBagLayout.class.getName ()); 249 buttonSet = 250 (JButton) Beans.instantiate (getClass ().getClassLoader (), 251 JButton.class.getName ()); 252 textCopyrightFile = 253 (JTextField) Beans.instantiate (getClass ().getClassLoader (), 254 JTextField.class.getName ()); 255 layoutMain = 256 (GridBagLayout) Beans.instantiate (getClass ().getClassLoader (), 257 GridBagLayout.class.getName ()); 258 panelFiller = 259 (JPanel) Beans.instantiate (getClass ().getClassLoader (), 260 JPanel.class.getName ()); 261 textCopyright = 262 (JTextArea) Beans.instantiate (getClass ().getClassLoader (), 263 JTextArea.class.getName ()); 264 radioFile = 265 (JRadioButton) Beans.instantiate (getClass ().getClassLoader (), 266 JRadioButton.class.getName ()); 267 radioText = 268 (JRadioButton) Beans.instantiate (getClass ().getClassLoader (), 269 JRadioButton.class.getName ()); 270 radioNone = 271 (JRadioButton) Beans.instantiate (getClass ().getClassLoader (), 272 JRadioButton.class.getName ()); 273 scroll = new JScrollPane (textCopyright); 274 275 buttonSet.setText (res.getString ("Set_")); 276 panelCopyright.setLayout (layoutDest); 277 radioFile.setText (res.getString ("Choose_file")); 278 radioText.setText (res.getString ("Enter_copyright_text")); 279 radioNone.setText (res.getString ("No_copyright")); 280 panelCopyright.add (textCopyrightFile, 281 new GridBagConstraints (0, 2, 2, 1, 0.1, 0.1, 282 GridBagConstraints.WEST, 283 GridBagConstraints.HORIZONTAL, 284 new Insets (0, 5, 5, 5), 285 0, 0)); 286 panelCopyright.add (scroll, 287 new GridBagConstraints (0, 3, 4, 1, 0.1, 0.1, 288 GridBagConstraints.CENTER, 289 GridBagConstraints.BOTH, 290 new Insets (5, 5, 5, 5), 291 0, 50)); 292 panelCopyright.add (radioFile, 293 new GridBagConstraints (0, 0, 1, 1, 0.0, 0.0, 294 GridBagConstraints.CENTER, 295 GridBagConstraints.HORIZONTAL, 296 new Insets (5, 5, 5, 5), 297 0, 0)); 298 panelCopyright.add (radioText, 299 new GridBagConstraints (1, 0, 1, 1, 0.0, 0.0, 300 GridBagConstraints.CENTER, 301 GridBagConstraints.NONE, 302 new Insets (5, 5, 5, 5), 303 0, 0)); 304 panelCopyright.add (buttonSet, 305 new GridBagConstraints (2, 1, 2, 2, 0.0, 0.0, 306 GridBagConstraints.EAST, 307 GridBagConstraints.NONE, 308 new Insets (5, 5, 5, 5), 309 0, 0)); 310 panelCopyright.add (radioNone, 311 new GridBagConstraints (2, 0, 1, 1, 0.0, 0.0, 312 GridBagConstraints.EAST, 313 GridBagConstraints.NONE, 314 new Insets (5, 5, 5, 5), 315 0, 0)); 316 this.setLayout (layoutMain); 317 this.add (panelCopyright, 318 new GridBagConstraints (0, 1, 2, 1, 0.1, 0.1, 319 GridBagConstraints.CENTER, 320 GridBagConstraints.BOTH, 321 new Insets (5, 5, 5, 5), 0, 0)); 322 this.add (panelFiller, 323 new GridBagConstraints (0, 2, 2, 1, 0.4, 0.4, 324 GridBagConstraints.CENTER, 325 GridBagConstraints.BOTH, 326 new Insets (0, 0, 0, 0), 0, 0)); 327 } 328 329 333 private void pmInit () { 334 radioGroup = new ButtonGroup (); 335 336 radioGroup.add (radioFile); 337 radioGroup.add (radioText); 338 radioGroup.add (radioNone); 339 radioNone.setSelected (true); 340 341 radioListener = new LocalRadioListener (); 342 343 radioText.addItemListener (radioListener); 344 radioFile.addItemListener (radioListener); 345 radioNone.addItemListener (radioListener); 346 347 buttonListener = new LocalButtonListener (); 348 349 buttonSet.addActionListener (buttonListener); 350 refreshControls (); 351 } 352 353 357 private void refreshControls () { 358 if (radioNone.isSelected ()) { 359 textCopyright.setText (new String ()); 360 textCopyright.setEnabled (false); 361 textCopyrightFile.setText (new String ()); 362 textCopyrightFile.setEnabled (false); 363 buttonSet.setEnabled (false); 364 } else if (radioText.isSelected ()) { 365 textCopyright.setEnabled (true); 366 textCopyrightFile.setText (new String ()); 367 textCopyrightFile.setEnabled (false); 368 buttonSet.setEnabled (false); 369 } else { 370 textCopyright.setText (new String ()); 371 textCopyright.setEnabled (false); 372 textCopyrightFile.setEnabled (true); 373 buttonSet.setEnabled (true); 374 } 375 376 if (textCopyright.isEnabled ()) { 377 textCopyright.setForeground (SystemColor.textText); 378 textCopyright.setBackground (SystemColor.textHighlightText); 379 } else { 380 textCopyright.setForeground (SystemColor.inactiveCaptionText); 381 textCopyright.setBackground (SystemColor.controlLtHighlight); 382 } 383 384 if (textCopyrightFile.isEnabled ()) { 385 textCopyrightFile.setForeground (SystemColor.textText); 386 textCopyrightFile.setBackground (SystemColor.textHighlightText); 387 } else { 388 textCopyrightFile.setForeground (SystemColor.inactiveCaptionText); 389 textCopyrightFile.setBackground (SystemColor.controlLtHighlight); 390 } 391 } 392 393 397 private void browseForFile () { 398 File file = null; 399 ExtensionFilter filter = null; 400 401 filter = new ExtensionFilter (); 402 403 filter.addExtension (TXT_TYPE); 404 filter.setDescriptionTitle (res.getString ("Copyright_text")); 405 406 file = 407 SwingUtil.getFileChoice (this, textCopyrightFile.getText (), 408 filter, 409 res.getString ("Choose_copyright_file")); 410 411 if (file != null) { 412 textCopyrightFile.setText (file.getAbsolutePath ()); 413 } 414 } 415 416 419 private class LocalRadioListener implements ItemListener { 420 public void itemStateChanged (ItemEvent e) { 421 if (e.getStateChange () == ItemEvent.SELECTED) { 422 refreshControls (); 423 } 424 } 425 426 } 427 428 431 private class LocalButtonListener implements ActionListener { 432 public void actionPerformed (ActionEvent event) { 433 browseForFile (); 434 } 435 436 } 437 438 } 439 440 | Popular Tags |