1 18 19 package de.gulden.framework.amoda.environment.gui.component; 20 21 import de.gulden.framework.amoda.environment.gui.GUIApplicationEnvironment; 22 import de.gulden.framework.amoda.model.core.*; 23 import de.gulden.framework.amoda.model.interaction.*; 24 import de.gulden.framework.amoda.model.behaviour.event.*; 25 import de.gulden.framework.amoda.model.option.Option; 26 import de.gulden.framework.amoda.generic.core.*; 27 import de.gulden.framework.amoda.generic.interaction.GenericDialog; 28 import de.gulden.framework.amoda.generic.option.GenericOptions; 29 import java.awt.*; 30 import java.awt.event.*; 31 import javax.swing.*; 32 import java.util.*; 33 34 40 public class CommandLineWrapperFrame extends GUIFrameAbstract implements ApplicationListener, MessagePerformer, ActionListener { 41 42 46 protected JComponent extendedPanel; 47 48 protected boolean extendedOpen; 49 50 protected JButton extendedButton; 51 52 protected String extendedLabelOpen; 53 54 protected String extendedLabelClosed; 55 56 protected boolean guiMessages; 57 58 private JPanel basePanel; 59 60 private JPanel buttonExtendPanel; 61 62 private JPanel buttonPanel; 63 64 private JPanel buttonsStartStopCloseOkPanel; 65 66 private JMenu fileMenu; 67 68 private JMenuBar menuBar; 69 70 private JPanel menuPanel; 71 72 private JEditorPane outputEditorPane; 73 74 private JPanel outputPanel; 75 76 private JScrollPane outputScrollPane; 77 78 private JPanel padPanel; 79 80 81 85 public CommandLineWrapperFrame(GUIApplicationEnvironment environment) { 86 super(environment); 87 environment.setFrame(this); 88 GenericApplication application = environment.getGenericApplication(); 89 initComponents(); 90 application.addApplicationListener(this); 91 92 FeatureGroup fg = application.getFeatureGroup("commandline-wrapper"); 93 Feature extended = fg.getFeature("extend"); 94 Feature options = fg.getFeature("options"); 95 Feature about = fg.getFeature("about"); 96 Feature help = fg.getFeature("help"); 97 Feature start = fg.getFeature("start"); 98 Feature stop = fg.getFeature("stop"); 99 Feature close = fg.getFeature("close"); 100 Feature ok = fg.getFeature("ok"); 101 102 this.extendedOpen = application.getOptions().getBoolean("extended-on-open"); 103 this.guiMessages = application.getOptions().getBoolean("gui-messages"); 104 105 if (extended.isEnabled()) { 106 this.extendedLabelOpen = extended.getOptions().getString("label-open"); 107 this.extendedLabelClosed = extended.getOptions().getString("label-closed"); 108 this.extendedButton = environment.createButtonFromFeature(extended); 109 updateExtendedButtonLabel(); 110 buttonExtendPanel.add(this.extendedButton); 111 } else if (options.isEnabled()) { 112 buttonExtendPanel.add(environment.createButtonFromFeature(options)); 113 } 114 115 Dimension s = buttonExtendPanel.getPreferredSize(); 116 padPanel.setPreferredSize(s); 117 118 120 fileMenu.setFont(menuBar.getFont()); 121 122 if (options.isEnabled()) { 123 JMenu optionsMenu = new JMenu("Edit"); 124 optionsMenu.setFont(menuBar.getFont()); 125 optionsMenu.add(this.environment.createMenuItemFromFeature(options)); 126 menuBar.add(optionsMenu); 127 } 128 129 if (about.isEnabled()||help.isEnabled()) { 130 JMenu helpMenu = new JMenu("Help"); 131 helpMenu.setFont(menuBar.getFont()); 132 if (about.isEnabled()) { 133 helpMenu.add(this.environment.createMenuItemFromFeature(about)); 134 } 135 if (help.isEnabled()) { 136 helpMenu.add(this.environment.createMenuItemFromFeature(help)); 137 } 138 menuBar.add(helpMenu); 139 } 140 141 142 148 149 for (Iterator it = application.getFeatures().iterator(); it.hasNext(); ) { 150 GenericFeature f = (GenericFeature)it.next(); 151 if ((!(f instanceof FeatureGroup))&&(!(f instanceof InteractionMember))&&(!f.isSystem())&&f.isEnabled()) { 152 JButton button = environment.createButtonFromFeature(f); 153 JMenuItem menuitem = environment.createMenuItemFromFeature(f); 154 addUpdaterInFront(button); 155 addUpdaterInFront(menuitem); 156 buttonsStartStopCloseOkPanel.add(button); 157 if (f.getId().equals("exit")) { 158 fileMenu.addSeparator(); 159 } else if (f.getId().equals("default")) { 160 button.requestFocus(); 161 getRootPane().setDefaultButton(button); 162 } 163 fileMenu.add(menuitem); 164 } 165 } 166 167 168 180 181 182 updateExtendedPanel(); 183 } 184 185 186 190 public void setSize(int width, int height) { 191 if (isExtended()) { 192 height += extendedPanel.getPreferredSize().height; 193 } 194 super.setSize(width, height); 195 } 196 197 public void setExtended(boolean open) { 198 this.extendedOpen = open; 199 updateExtendedPanel(); 200 } 201 202 public boolean isExtended() { 203 return this.extendedOpen; 204 } 205 206 public void doMessage(Message message) { 207 if ( (!guiMessages) || (message instanceof LogMessage) || (((GenericFeature)message).isSystem()) ) { 208 try { 209 int offset = outputEditorPane.getDocument().getEndPosition().getOffset()-1; 210 String txt = message.getText(); 211 if (!txt.endsWith("\n")) { 212 txt += "\n"; 213 } 214 if (offset == 0) { 215 txt = txt + "\n"; } 217 outputEditorPane.getDocument().insertString(offset, txt, null); 218 int endOffset = outputEditorPane.getDocument().getEndPosition().getOffset(); 219 outputEditorPane.getCaret().setDot(endOffset); 220 outputScrollPane.updateUI(); 221 } catch (Exception e) { 222 this.environment.getGenericApplication().error(e); 223 } 224 } else { this.environment.internalDoMessage(message); 226 } 227 } 228 229 public void moduleLoaded(ApplicationEvent event) { 230 updateExtendedPanel(); } 232 233 public void pluginInstalled(ApplicationEvent event) { 234 } 236 237 public void pluginUninstalled(ApplicationEvent event) { 238 } 240 241 245 public void actionPerformed(ActionEvent e) { 246 ((GenericOptions)environment.getGenericApplication().getOptions()).shiftAllValues(Option.STATE_EDIT, Option.STATE_CURRENT); 247 } 248 249 protected void updateExtendedPanel() { 250 updateExtendedButtonLabel(); 251 Dimension currentSize = this.getSize(); 252 int heightWithoutExtended = currentSize.height; 253 if (this.extendedPanel != null) { 254 Dimension size = extendedPanel.getSize(); 255 heightWithoutExtended -= size.height; 256 this.menuPanel.remove(this.extendedPanel); 257 } 258 if (this.extendedOpen) { this.extendedPanel = this.environment.createOptionsEditor((GenericOptions)this.environment.getGenericApplication().getOptions()); 260 GridBagConstraints gc = new GridBagConstraints(); 261 gc.gridwidth = GridBagConstraints.REMAINDER; 262 gc.weightx = 1.0; 263 gc.fill = GridBagConstraints.BOTH; 264 this.menuPanel.add(this.extendedPanel, gc); 265 Dimension preferredSize = extendedPanel.getPreferredSize(); 266 super.setSize(currentSize.width, heightWithoutExtended + preferredSize.height); 267 } else { this.extendedPanel = null; 269 super.setSize(currentSize.width, heightWithoutExtended); 270 } 271 this.validate(); 272 } 273 274 protected void updateExtendedButtonLabel() { 275 if (this.extendedButton!=null) { 276 this.extendedButton.setText(this.extendedOpen ? this.extendedLabelOpen : this.extendedLabelClosed); 277 this.extendedButton.validate(); 278 } 279 } 280 281 private void addUpdaterInFront(AbstractButton b) { 282 295 b.addActionListener(this); 297 } 298 299 private void initComponents() { 300 java.awt.GridBagConstraints gridBagConstraints; 302 303 basePanel = new javax.swing.JPanel (); 304 outputPanel = new javax.swing.JPanel (); 305 outputScrollPane = new javax.swing.JScrollPane (); 306 outputEditorPane = new javax.swing.JEditorPane (); 307 menuPanel = new javax.swing.JPanel (); 308 buttonPanel = new javax.swing.JPanel (); 309 padPanel = new javax.swing.JPanel (); 310 buttonsStartStopCloseOkPanel = new javax.swing.JPanel (); 311 buttonExtendPanel = new javax.swing.JPanel (); 312 menuBar = new javax.swing.JMenuBar (); 313 fileMenu = new javax.swing.JMenu (); 314 315 addWindowListener(new java.awt.event.WindowAdapter () { 316 public void windowClosing(java.awt.event.WindowEvent evt) { 317 exitForm(evt); 318 } 319 }); 320 321 basePanel.setLayout(new java.awt.BorderLayout (0, 3)); 322 323 outputPanel.setLayout(new java.awt.BorderLayout ()); 324 325 outputEditorPane.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.background")); 326 outputEditorPane.setFont(new java.awt.Font ("DialogInput", 0, 12)); 327 outputScrollPane.setViewportView(outputEditorPane); 328 329 outputPanel.add(outputScrollPane, java.awt.BorderLayout.CENTER); 330 331 basePanel.add(outputPanel, java.awt.BorderLayout.CENTER); 332 333 menuPanel.setLayout(new java.awt.GridBagLayout ()); 334 335 buttonPanel.setLayout(new java.awt.GridBagLayout ()); 336 337 padPanel.setLayout(null); 338 339 buttonPanel.add(padPanel, new java.awt.GridBagConstraints ()); 340 341 gridBagConstraints = new java.awt.GridBagConstraints (); 342 gridBagConstraints.weightx = 1.0; 343 buttonPanel.add(buttonsStartStopCloseOkPanel, gridBagConstraints); 344 345 buttonPanel.add(buttonExtendPanel, new java.awt.GridBagConstraints ()); 346 347 gridBagConstraints = new java.awt.GridBagConstraints (); 348 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 349 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 350 gridBagConstraints.weightx = 1.0; 351 menuPanel.add(buttonPanel, gridBagConstraints); 352 353 basePanel.add(menuPanel, java.awt.BorderLayout.SOUTH); 354 355 getContentPane().add(basePanel, java.awt.BorderLayout.CENTER); 356 357 fileMenu.setText("File"); 358 menuBar.add(fileMenu); 359 360 setJMenuBar(menuBar); 361 362 pack(); 363 } 364 365 private void exitForm(WindowEvent evt) { 366 environment.getExitCommand().perform(); 368 } 369 370 } | Popular Tags |