1 18 19 package de.gulden.framework.amoda.environment.gui; 20 21 import de.gulden.framework.amoda.environment.commandline.*; 22 import de.gulden.framework.amoda.environment.gui.component.DefaultButton; 23 import de.gulden.framework.amoda.generic.behaviour.*; 24 import de.gulden.framework.amoda.generic.core.*; 25 import de.gulden.framework.amoda.generic.interaction.*; 26 import de.gulden.framework.amoda.generic.option.*; 27 import de.gulden.framework.amoda.model.behaviour.*; 28 import de.gulden.framework.amoda.model.core.*; 29 import de.gulden.framework.amoda.model.core.WorkspaceProvider; 30 import de.gulden.framework.amoda.model.interaction.*; 31 import de.gulden.framework.amoda.model.interaction.Dialog; 32 import de.gulden.util.Toolbox; 33 import de.gulden.util.xml.XMLToolbox; 34 import java.awt.*; 35 import java.lang.*; 36 import java.util.*; 37 import javax.swing.*; 38 39 45 public class GUIApplicationEnvironment extends CommandLineApplicationEnvironment implements WorkspaceProvider, FontProvider { 46 47 51 public static String FONT_DEFAULT = "default"; 52 53 public static String FONT_MENU = "menu"; 54 55 public static String FONT_BUTTON = "button"; 56 57 public static String FONT_LABEL = "label"; 58 59 protected JFrame frame; 60 61 protected Hashtable fontCache = new Hashtable(); 62 63 protected JMenu windowMenu = null; 64 65 protected JMenu fileMenu = null; 66 67 protected Command exitCommand; 68 69 protected Command openMostRecentFileCommand; 70 71 public static Dimension BUTTON_PREFERRED_SIZE = new Dimension(80,25); 72 73 public CommandLineApplicationEnvironment fallbackCommandLineApplicationEnvironment; 74 75 76 80 public GUIApplicationEnvironment() { 81 } 83 84 85 89 public CommandLineApplicationEnvironment getFallbackCommandLineApplicationEnvironment() { 90 return fallbackCommandLineApplicationEnvironment; 91 } 92 93 public void setFallbackCommandLineApplicationEnvironment(CommandLineApplicationEnvironment commandLineApplicationEnvironment) { 94 this.fallbackCommandLineApplicationEnvironment = commandLineApplicationEnvironment; 95 } 96 97 public void launch(Application application) { 98 if (!(application instanceof GUIApplication)) { de.gulden.framework.amoda.environment.commandline.CommandLineApplicationEnvironmentFactory f = new de.gulden.framework.amoda.environment.commandline.CommandLineApplicationEnvironmentFactory(getFactory().getArgs()); 100 setFallbackCommandLineApplicationEnvironment((CommandLineApplicationEnvironment)f.createApplicationEnvironment()); 101 ((GenericFeature)options.get("gui")).setSystem(false); 103 ((GenericFeature)options.get("environment")).setSystem(true); 105 ((GenericFeature)options.get("font")).setSystem(true); 106 } else { ((GenericFeature)application.getFeature("default")).setSystem(true); 108 } 109 super.launch(application); 110 } 111 112 public void doMessage(Message message) { 113 GenericApplication application = getGenericApplication(); 114 if ((application==null) || !application.isQuiet()) { 115 JFrame frame = getFrame(); 116 if (frame instanceof de.gulden.framework.amoda.environment.gui.component.CommandLineWrapperFrame) { 117 ((de.gulden.framework.amoda.environment.gui.component.CommandLineWrapperFrame)frame).doMessage(message); 118 } else { 119 if ((frame!=null) && (!((de.gulden.framework.amoda.generic.core.GenericFeature)message).isSystem())) { 120 if (message.getType()==Message.STATUS_MESSAGE) { 121 String text=message.getText(); 122 if (!Toolbox.isEmpty(text)) { 123 ((de.gulden.framework.amoda.environment.gui.component.GUIFrame)frame).setStatus(text); 124 } else { 125 ((de.gulden.framework.amoda.environment.gui.component.GUIFrame)frame).resetStatus(); 126 } 127 } else { 128 internalDoMessage(message); 129 } 130 } else { getFallbackCommandLineApplicationEnvironment().doMessage(message); 132 } 133 } 134 135 } 136 } 137 138 public void doQuestion(Question question) { 139 GenericQuestion q=(GenericQuestion)question; 140 JOptionPane p=internalCreateJOptionPane(q); 141 JDialog dialog=p.createDialog(getFrame(),q.getMetadata().get("title","Question")); 142 dialog.setVisible(true); 143 String answerString=(String )p.getValue(); 144 if (answerString==null) { 145 q.setAnswer(Question.CANCEL); return; 147 } 148 for (Iterator it=q.getAnswerOptions().iterator();it.hasNext();) { 150 de.gulden.framework.amoda.model.option.Option o=(de.gulden.framework.amoda.model.option.Option)it.next(); 151 if (answerString.equals(o.toString())) { 152 q.setAnswer(o.getId()); 153 return; 154 } 155 } 156 } 157 158 public void doErrorMessage(ErrorMessage errorMessage) { 159 JFrame frame = getFrame(); 161 if (frame instanceof de.gulden.framework.amoda.model.interaction.ErrorMessagePerformer) { 162 ((de.gulden.framework.amoda.model.interaction.ErrorMessagePerformer)frame).doErrorMessage(errorMessage); } else { doMessage(errorMessage); 165 } 166 if (errorMessage.exitApplication()) { 167 } 169 } 170 171 public void doDialog(Dialog dialog) { 172 GenericDialog d=(GenericDialog)dialog; 173 de.gulden.framework.amoda.generic.option.GenericOptions options=(de.gulden.framework.amoda.generic.option.GenericOptions)d.getOptions(); 174 if (!d.isFileDialog()) { 175 JComponent optionsPanel=createOptionsEditor(options); 176 JDialog jdialog=internalCreateJDialog(d,optionsPanel,FlowLayout.CENTER); 177 jdialog.setVisible(true); 178 for (Iterator it=d.getAll(de.gulden.framework.amoda.model.behaviour.Command.class,false).values().iterator();it.hasNext();) { 181 de.gulden.framework.amoda.generic.behaviour.GenericCommand c=(de.gulden.framework.amoda.generic.behaviour.GenericCommand)it.next(); 182 c.perform(); 183 } 184 } else { JFileChooser fc=new JFileChooser(); 186 191 196 fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); 197 198 for (Iterator it=d.getOptions().getEntries().values().iterator();it.hasNext();) { 200 de.gulden.framework.amoda.generic.option.GenericOptionEntry o=(de.gulden.framework.amoda.generic.option.GenericOptionEntry)it.next(); 201 Class optType=o.getType(); 202 if (o.getType()==String .class) { 203 String suffix=o.getValue().getString(); 204 if (suffix.startsWith("*.")) { 205 suffix=suffix.substring(2); 206 } 207 String description=o.findTitle(); 208 javax.swing.filechooser.FileFilter ff=new de.gulden.util.swing.SuffixFileFilter(suffix,description); 209 fc.addChoosableFileFilter(ff); 210 } 211 } 212 213 de.gulden.framework.amoda.generic.option.GenericOptionEntry resultOption=null; 215 for (Iterator it=d.getOptions().getEntries().values().iterator();(resultOption==null)&&it.hasNext();) { 216 de.gulden.framework.amoda.generic.option.GenericOptionEntry o=(de.gulden.framework.amoda.generic.option.GenericOptionEntry)it.next(); 217 Class optType=o.getType(); 218 if (optType==java.io.File .class) { 219 resultOption=o; 220 } 222 } 223 224 if (resultOption==null) { resultOption=new de.gulden.framework.amoda.generic.option.GenericOptionEntry(); 226 resultOption.setName("file"); 227 resultOption.setType(java.io.File .class); 228 ((de.gulden.framework.amoda.generic.option.GenericOptions)d.getOptions()).add(resultOption); 229 } 230 231 java.io.File file=resultOption.getValue(de.gulden.framework.amoda.model.option.Option.STATE_CURRENT).getFile(); 232 if (file!=null) { 233 fc.setSelectedFile(file); 234 } 235 236 int answer; 237 if (d.isSave()) { 238 answer=fc.showSaveDialog(getFrame()); 239 } else { 240 answer=fc.showOpenDialog(getFrame()); 241 } 242 243 if (answer==JFileChooser.APPROVE_OPTION) { 244 if (resultOption!=null) { 245 java.io.File f=fc.getSelectedFile(); 246 if (!f.isDirectory()) { javax.swing.filechooser.FileFilter ff=fc.getFileFilter(); 248 if (ff instanceof de.gulden.util.swing.SuffixFileFilter) { 249 de.gulden.util.swing.SuffixFileFilter sff=(de.gulden.util.swing.SuffixFileFilter)ff; 250 String suffix=sff.getSuffix(); 251 if (!f.getName().endsWith("."+suffix)) { 252 f=new java.io.File (f.getAbsolutePath()+"."+suffix); 253 } 254 } 255 } 256 ((de.gulden.framework.amoda.generic.data.GenericValue)resultOption.getValue(de.gulden.framework.amoda.model.option.Option.STATE_CURRENT)).set(f); 257 } else { 258 } 260 } else { 261 if (resultOption!=null) { 262 ((de.gulden.framework.amoda.generic.data.GenericValue)resultOption.getValue(de.gulden.framework.amoda.model.option.Option.STATE_CURRENT)).set(null); 263 } else { 264 } 266 } 267 } 268 } 269 270 public void doWizard(Wizard wizard) { 271 } 273 274 public JFrame getFrame() { 275 return frame; 276 } 277 278 public void setFrame(JFrame _frame) { 279 frame = _frame; 280 } 281 282 public JComponent createOptionsEditor(GenericOptions options) { 283 if (options.getParentMember()==null) options.setParentMember(getGenericApplication()); if (options == getGenericApplication().getOptions()) { 285 ((GenericOptionEntry)options.getOptionEntry("gui")).setSystem(true); } 287 de.gulden.framework.amoda.generic.behaviour.GenericCondition cond=new de.gulden.framework.amoda.generic.behaviour.GenericCondition() { 288 public boolean test() { 289 de.gulden.framework.amoda.generic.core.GenericFeature f=((de.gulden.framework.amoda.generic.core.GenericFeature)getObject()); 290 return f.isEnabled()&&(!f.isSystem()); 291 } 292 }; 293 int depth=options.countMaxDepth(cond); 294 if (depth==0) { 295 JLabel label=new JLabel("-empty-",JLabel.CENTER); 296 label.setFont(getDefaultFont()); 297 return label; 298 } else if (depth==1) { JPanel panel=new JPanel(); 300 panel.setLayout(new GridBagLayout()); 301 FeatureGroup fg = getGenericApplication().getFeatureGroup("commandline-wrapper"); 302 Feature optionsFeature = fg.getFeature("options"); 303 boolean showDescriptionLabels = optionsFeature.getOptions().getBoolean("show-descriptions"); 304 for (Iterator it=options.getEntries().values().iterator();it.hasNext();) { 305 GenericOptionEntry entry=(GenericOptionEntry)it.next(); 306 entry.setParent(options); if (cond.test(entry)) { 308 entry.createGUIEditorComponent(panel, this); 309 if (showDescriptionLabels) { 310 String descr = entry.getMetadata().get("description"); 311 JTextArea descrLabel = new JTextArea(); 312 descrLabel.setText(descr); 313 descrLabel.setLineWrap(true); 314 descrLabel.setWrapStyleWord(true); 315 descrLabel.setEditable(false); 316 descrLabel.setOpaque(false); descrLabel.setFont(getFont("menu")); 318 descrLabel.setForeground(new Color(0xff9999cc)); GridBagConstraints gc = new GridBagConstraints(); 320 gc.fill = GridBagConstraints.HORIZONTAL; 321 gc.gridwidth = GridBagConstraints.REMAINDER; 322 gc.gridx = 1; 323 panel.add(descrLabel, gc); 324 gc = new GridBagConstraints(); 326 gc.fill = GridBagConstraints.HORIZONTAL; 327 gc.gridwidth = GridBagConstraints.REMAINDER; 328 panel.add(new JPanel(), gc); 329 } 330 } 331 } 332 return panel; 333 } else if (depth==2) { JPanel panel=new JPanel(); 335 panel.setLayout(new GridBagLayout()); 336 GridBagConstraints gbc=new GridBagConstraints(); 337 gbc.gridwidth=GridBagConstraints.REMAINDER; 338 gbc.fill=GridBagConstraints.HORIZONTAL; 339 for (Iterator it=options.getGroups().values().iterator();it.hasNext();) { 340 GenericOptions g=(GenericOptions)it.next(); 341 if (cond.test(g)&&g.countMaxDepth(cond)>0) { 342 JComponent gPanel=createOptionsEditor(g); javax.swing.border.TitledBorder border=new javax.swing.border.TitledBorder (g.findTitle()); 344 border.setTitleFont(getFont(FONT_MENU)); 345 gPanel.setBorder(border); 346 panel.add(gPanel,gbc); 347 } 348 } 349 return panel; 350 } else { JTabbedPane panel=new JTabbedPane(); 352 panel.setFont(getDefaultFont()); 353 GenericOptions flatEntries=new GenericOptions(); 355 flatEntries.setParent(options.getParent()); 356 Collection flats=options.getEntries().values(); 357 flats = cond.filter(flats); if (flats.size()>0) { 359 flatEntries.addAll(flats); 360 flatEntries.setParent(null); for (Iterator it=flats.iterator();it.hasNext();) { 363 GenericOptionEntry entry=(GenericOptionEntry)it.next(); 364 entry.setParent(options.getParent()); 365 } 366 JComponent gPanel=createOptionsEditor(flatEntries); panel.addTab("General",gPanel); 370 } 371 for (Iterator it=options.getGroups().values().iterator();it.hasNext();) { 373 GenericOptions g=(GenericOptions)it.next(); 374 if (cond.test(g)&&(g.countMaxDepth(cond)>0)) { 375 g=g.flattenHierarchy(2,cond); 376 JComponent gPanel=createOptionsEditor(g); panel.addTab(g.findTitle(),gPanel); 378 } 379 } 380 return panel; 381 } 382 } 383 384 public Font getDefaultFont() { 385 return getFont(FONT_DEFAULT); 386 } 387 388 public Font getFont(String id) { 389 Font f=(Font)fontCache.get(id); 390 if (f==null) { 391 String fontDescription=getGenericApplication().getOptions().getString("font."+id); 392 StringTokenizer st=new StringTokenizer(fontDescription,",",false); 393 String fontName=st.nextToken(); 394 String fontStyleStr=st.nextToken(); String fontSizeStr=st.nextToken(); 396 int fontStyle=Font.PLAIN; 397 if (fontStyleStr!=null) { 398 fontStyleStr=fontStyleStr.toLowerCase(); 399 if (fontStyleStr.indexOf("bold")!=-1) { 400 fontStyle|=Font.BOLD; 401 } 402 if (fontStyleStr.indexOf("italic")!=-1) { 403 fontStyle|=Font.ITALIC; 404 } 405 } 406 int fontSize=12; 407 if (fontStyleStr!=null) { 408 try { 409 fontSize=Integer.parseInt(fontStyleStr); 410 } catch (NumberFormatException nfe) { 411 } 413 } 414 f=new Font(fontName,fontStyle,fontSize); 415 fontCache.put(id,f); 416 } 417 return f; 418 } 419 420 public JMenu getWindowMenu() { 421 return windowMenu; 422 } 423 424 public Command getExitCommand() { 425 return exitCommand; 426 } 427 428 public void createPopupMenuFromFeatureGroup(FeatureGroup featureGroup, JPopupMenu menu) { 429 if (featureGroup.isEnabled()) { 430 if (menu.getSubElements().length>0) { 431 menu.addSeparator(); 432 } 433 Object previousFeature=null; 434 for (Iterator it=featureGroup.getFeatures().iterator();it.hasNext();) { 435 Object f=it.next(); 436 if (f instanceof FeatureGroup) { 437 createPopupMenuFromFeatureGroup((FeatureGroup)f,menu); 438 } else { 439 if (previousFeature instanceof FeatureGroup) { 440 menu.addSeparator(); 441 } 442 menu.add(createMenuItemFromFeature((Feature)f)); 443 } 444 previousFeature=f; 445 } 446 } 447 } 448 449 public JMenu getFileMenu() { 450 return fileMenu; 451 } 452 453 public Command getOpenMostRecentFileCommand() { 454 return openMostRecentFileCommand; 455 } 456 457 public void setOpenMostRecentFileCommand(Command _openMostRecentFileCommand) { 458 openMostRecentFileCommand = _openMostRecentFileCommand; 459 } 460 461 public JButton createButtonFromFeature(Feature feature) { 462 JButton item = new DefaultButton(); 463 initFromFeature(item, feature); 464 return item; 465 } 466 467 public JMenuItem createMenuItemFromFeature(Feature feature) { 468 JMenuItem item = new JMenuItem(); 469 item.setFont(getFrame().getJMenuBar().getFont()); 470 initFromFeature(item, feature); 471 return item; 472 } 473 474 public void doAbout() { 475 if (getFrame().isVisible()) { GUIApplication a = new GUIApplication() {}; 478 a.internalSetGenericApplicationEnvironment(this); a.setMetadata(getGenericApplication().getMetadata()); 480 a.setOptions(getGenericApplication().getOptions()); 481 a.about(); 482 } else { super.doAbout(); 484 } 485 } 486 487 public void doHelp() { 488 if (getFrame().isVisible()) { GUIApplication a = new GUIApplication() {}; 491 a.internalSetGenericApplicationEnvironment(this); a.setMetadata(getGenericApplication().getMetadata()); 493 a.setOptions(getGenericApplication().getOptions()); 494 a.help(); 495 } else { super.doHelp(); 497 } 498 } 499 500 public void internalDoMessage(Message message) { 501 JOptionPane.showMessageDialog(frame,message.getText(),message.getMetadata().get("title","Message"),message.getType()); 502 } 503 504 protected void prepareApplicationWelcome() { 505 super.prepareApplicationWelcome(); 506 de.gulden.framework.amoda.generic.core.GenericApplication application = getGenericApplication(); 507 String lafName = application.getOptions().getString("swing-look-and-feel"); 509 if (!Toolbox.empty(lafName)) { 510 try { 511 javax.swing.UIManager.setLookAndFeel(lafName); 512 } catch (Throwable t) { 513 System.out.println("Warning: Cannot set look-and-feel '"+lafName+"' - ignoring."); 514 } 515 } 516 initDefaultUIFonts(); 517 518 JFrame frame; 519 if (application instanceof GUIApplication) { frame = createGUIFrame(); } else { 522 frame = createCommandLineWrapperFrame(); } 524 java.net.URL url=de.gulden.framework.amoda.generic.metadata.GenericMetadata.findIconResource(getGenericApplication()); 525 if (url!=null) { 526 java.awt.Image icon=frame.getToolkit().getImage(url); 527 frame.setIconImage(icon); 528 } 529 setFrame(frame); 530 } 531 532 protected void prepareApplicationStart() { 533 super.prepareApplicationStart(); 534 de.gulden.framework.amoda.generic.core.GenericApplication application = getGenericApplication(); 536 if (application.getOptions().getBoolean("main-window-maximized")) { 537 getFrame().setLocation(0,0); 540 java.awt.Dimension screenSize=getFrame().getToolkit().getScreenSize(); 541 getFrame().setSize(screenSize.width,screenSize.height); 542 } else { 543 getFrame().setLocation(100,100); 544 getFrame().setSize(getGenericApplication().getOptions().getInt("main-window-width"),getGenericApplication().getOptions().getInt("main-window-height")); 545 } 546 getFrame().setTitle(de.gulden.framework.amoda.generic.metadata.GenericMetadata.findTitle(getGenericApplication())); 547 548 if (application instanceof GUIApplication) { 549 de.gulden.framework.amoda.environment.gui.component.GUIFrame f = (de.gulden.framework.amoda.environment.gui.component.GUIFrame)getFrame(); 550 JMenuBar menubar; 551 JMenu menu; 552 JMenuItem item; 553 Feature feature; 554 menubar=f.getJMenuBar(); 555 for (Iterator it=application.getFeatureGroups().iterator();it.hasNext();) { 556 Object o=it.next(); 557 de.gulden.framework.amoda.generic.core.GenericFeatureGroup g=(de.gulden.framework.amoda.generic.core.GenericFeatureGroup)o; 558 if (g.isEnabled()&&(!g.isSystem())) { 559 menu=new JMenu(g.findTitle()); 560 menu.setFont(menubar.getFont()); 561 createMenuItemsFromFeatureGroup(g,menu); 562 menubar.add(menu); 563 if (g.getId().equals("file-features")) { 565 this.fileMenu=menu; 566 } else if (g.getId().equals("window-features")) { 567 this.windowMenu=menu; 568 } 569 } 570 } 571 f.resetStatus(); 572 } else { getFrame().show(); 574 } 575 } 576 577 protected void initDefaultUIFonts() { 578 Font font; 579 font=getDefaultFont(); 580 UIDefaults defaults=UIManager.getDefaults(); 581 for (Enumeration e=defaults.keys();e.hasMoreElements();) { 582 Object o=e.nextElement(); 583 if (o instanceof String ) { 584 String key=(String )o; 585 if (key.endsWith(".font")) { 586 UIManager.put(key,new javax.swing.plaf.FontUIResource (font)); 587 } 588 } 589 } 590 } 591 592 protected JFrame createGUIFrame() { 593 return new de.gulden.framework.amoda.environment.gui.component.GUIFrame(this); 594 } 595 596 protected JFrame createCommandLineWrapperFrame() { 597 return new de.gulden.framework.amoda.environment.gui.component.CommandLineWrapperFrame(this); 598 } 599 600 protected void launchAfterInit(GenericApplication genericApplication) { 601 if (!genericApplication.getOptions().getBoolean("gui")) { 602 getFallbackCommandLineApplicationEnvironment().launch(genericApplication); 604 } else { 605 super.launchAfterInit(genericApplication); } 607 } 608 609 protected void initFromFeature(AbstractButton item, Feature feature) { 610 String title=de.gulden.framework.amoda.generic.metadata.GenericMetadata.findTitle(feature); 611 if (item instanceof JMenuItem) { 612 title = title.trim(); 613 } 614 item.setText(title); 615 String shortcut=((de.gulden.framework.amoda.generic.core.GenericFeature)feature).getShortcut(); 616 if (shortcut!=null) { 617 StringTokenizer st=new StringTokenizer(shortcut," +-,",false); 618 shortcut="ctrl"; 619 while (st.hasMoreTokens()) { 620 String tok=st.nextToken(); 621 if (st.hasMoreTokens()) { tok=tok.toLowerCase(); 623 } 624 shortcut+=" "+tok; 625 } 626 if (item instanceof JMenuItem) { 627 javax.swing.KeyStroke ks=javax.swing.KeyStroke.getKeyStroke(shortcut); if (ks!=null) { 629 ((JMenuItem)item).setAccelerator(ks); 630 } 631 } 632 } 633 int commandCount=0; 634 for (Iterator it=feature.getAll(GenericCommand.class,false).values().iterator();it.hasNext();) { 635 GenericCommand c=(GenericCommand)it.next(); 636 c.setParent(getGenericApplication()); 637 item.addActionListener((java.awt.event.ActionListener )c); 638 commandCount++; 639 if (((c instanceof de.gulden.framework.amoda.generic.behaviour.CommandApplicationExit)||((c instanceof de.gulden.framework.amoda.generic.behaviour.CommandWrapper) && (((de.gulden.framework.amoda.generic.behaviour.CommandWrapper)c).getWrapped() instanceof de.gulden.framework.amoda.generic.behaviour.CommandApplicationExit)))&&(exitCommand==null)) { 641 exitCommand=c; } 643 } 644 if (commandCount==0) { 645 item.setEnabled(false); 646 } 647 } 648 649 protected void createMenuItemsFromFeatureGroup(FeatureGroup featureGroup, JMenu menu) { 650 if (featureGroup.isEnabled()) { 651 java.awt.Component [] components=menu.getMenuComponents(); 652 if ((components.length>0)&&(components[components.length-1] instanceof javax.swing.MenuElement )) { menu.addSeparator(); 654 } 655 Object previousFeature=null; 656 for (Iterator it=featureGroup.getFeatures().iterator();it.hasNext();) { 657 Object f=it.next(); 658 if (f instanceof FeatureGroup) { 659 createMenuItemsFromFeatureGroup((FeatureGroup)f,menu); 660 } else { 661 if (previousFeature instanceof FeatureGroup) { 662 menu.addSeparator(); 663 } 664 menu.add(createMenuItemFromFeature((Feature)f)); 665 } 666 previousFeature=f; 667 } 668 } 669 } 670 671 protected void launchStart(GenericApplication application) { 672 if ((!(getFrame() instanceof de.gulden.framework.amoda.environment.gui.component.CommandLineWrapperFrame)) || (!application.getFeatureGroup("commandline-wrapper").getFeature("start").isEnabled())) { 674 application.start(); 675 } 676 } 677 678 private JOptionPane internalCreateJOptionPane(GenericQuestion q) { 679 Collection answerOptions=q.getAnswerOptions(); 680 String [] answers=new String [answerOptions.size()]; 682 int i=0; 683 for (Iterator it=answerOptions.iterator();it.hasNext();) { 684 answers[i++]=it.next().toString(); 685 } 686 JOptionPane p=new JOptionPane(); 687 p.setMessageType(q.getType()); 688 p.setMessage(q.getText()); 689 p.setOptions(answers); 690 p.setInitialValue(q.getDefaultAnswer()); 691 return p; 692 } 693 694 private JButton internalCreateOptionButton(GenericOptionEntry option, GenericDialog parentDialog) { 695 JButton button=new DefaultButton(option.findTitle()); 696 button.setFont(getDefaultFont()); 697 if (option.getId().equals(parentDialog.getDefaultAnswer())) { 698 parentDialog.getJDialog().getRootPane().setDefaultButton(button); 699 } 700 for (Iterator it=option.getAll(de.gulden.framework.amoda.generic.behaviour.GenericCommand.class,false).values().iterator();it.hasNext();) { 701 de.gulden.framework.amoda.generic.behaviour.GenericCommand c=(de.gulden.framework.amoda.generic.behaviour.GenericCommand)it.next(); 702 de.gulden.framework.amoda.generic.behaviour.GenericCommand cc=(de.gulden.framework.amoda.generic.behaviour.GenericCommand)c.clone(); 703 cc.setParent(parentDialog); 704 button.addActionListener(cc); } 706 return button; 707 } 708 709 private JDialog internalCreateJDialog(GenericDialog d, JComponent mainComponent, int buttonOrientation) { 710 JDialog dialog=new JDialog(getFrame(),true); 711 d.setJDialog(dialog); 712 String title = d.getTitle(); 713 if (title == null) { 714 title = d.getMetadata().get("title","Dialog"); 715 } 716 dialog.setTitle(title); 717 dialog.getContentPane().setLayout(new BorderLayout()); 718 dialog.getContentPane().add(mainComponent,BorderLayout.CENTER); 719 JPanel buttonsPanel=new JPanel(); 720 buttonsPanel.setLayout(new FlowLayout(buttonOrientation)); 721 Collection answerOptions=d.getAnswerOptions(); 722 for (Iterator it=answerOptions.iterator();it.hasNext();) { 723 de.gulden.framework.amoda.generic.option.GenericOptionEntry answer=(de.gulden.framework.amoda.generic.option.GenericOptionEntry)it.next(); 724 buttonsPanel.add(internalCreateOptionButton(answer,d)); 725 } 726 dialog.getContentPane().add(buttonsPanel,BorderLayout.SOUTH); 727 dialog.pack(); 728 Toolbox.centerComponent(dialog,getFrame()); 729 return dialog; 730 } 731 732 733 737 public static void invoke(Class applicationClass, String [] args) throws Exception { 738 de.gulden.framework.amoda.generic.core.GenericApplicationEnvironment.invoke(applicationClass, args, GUIApplicationEnvironmentFactory.class); 739 } 740 741 } | Popular Tags |