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.generic.core.*; 23 import de.gulden.framework.amoda.model.core.*; 24 import de.gulden.framework.amoda.model.core.WorkspaceProvider; 25 import de.gulden.framework.amoda.model.document.*; 26 import de.gulden.framework.amoda.model.document.ClipboardHandler; 27 import de.gulden.framework.amoda.model.document.Document; 28 import de.gulden.framework.amoda.model.document.DocumentHandler; 29 import de.gulden.util.Toolbox; 30 import de.gulden.util.xml.XMLToolbox; 31 import java.awt.*; 32 import java.io.*; 33 import java.lang.*; 34 import java.net.*; 35 import java.util.*; 36 import javax.swing.*; 37 import org.w3c.dom.*; 38 39 45 public abstract class GUIApplication extends CommandLineApplication implements WorkspaceProvider, ClipboardHandler, DocumentHandler { 46 47 51 protected boolean modeMultiDocuments; 52 53 protected boolean modeMultiViews; 54 55 protected JDialog aboutDialog; 56 57 protected JWindow aboutSplashWindow; 58 59 protected JDialog helpDialog; 60 61 62 66 public Workspace getWorkspace() { 67 return ((GUIApplicationEnvironment)getEnvironment()).getWorkspace(); 68 } 69 70 public JComponent createGUIComponent(DocumentView view) { 71 throw new AbstractMethodError ("createDefaultView is not implemented by subclass"); 73 } 74 75 public void cutSelection(DocumentSelection sel) { 76 } 78 79 public void copySelection(DocumentSelection sel) { 80 } 82 83 public void pasteSelection(DocumentSelection sel) { 84 } 86 87 public DocumentHandler getDocumentHandler() { 88 return this; } 90 91 public ClipboardHandler getClipboardHandler() { 92 return this; } 94 95 public void destroy() { 96 ((GUIApplicationEnvironment)getGenericApplicationEnvironment()).getFrame().dispose(); 97 System.exit(0); 98 } 99 100 public void start() { 101 getRecentFilesList().init(this); 103 ((GUIApplicationEnvironment)getEnvironment()).getFrame().setVisible(true); 105 startWorkspace(); 107 if (aboutSplashWindow!=null) { 108 aboutSplashWindow.dispose(); 109 } 110 super.start(); 111 } 112 113 public void about() { 114 if (((GUIApplicationEnvironment)getEnvironment()).getFrame().isVisible()) { if (aboutDialog==null) { 116 aboutDialog=createAboutDialog(); 117 } 118 de.gulden.util.Toolbox.centerOnScreen(aboutDialog); 119 aboutDialog.setVisible(true); 120 } else { 121 aboutSplash(); } 123 } 124 125 public void aboutSplash() { 126 JWindow window=new JWindow(((GUIApplicationEnvironment)getEnvironment()).getFrame()); 127 JComponent aboutComponent=createAboutComponent(); 128 window.getContentPane().add(aboutComponent); 129 window.pack(); 130 Dimension size=window.getSize(); 131 size.width=500; 132 window.setSize(size); 133 de.gulden.util.Toolbox.centerOnScreen(window); 134 this.aboutSplashWindow=window; 135 window.setVisible(true); 136 } 137 138 public Document newDocument() { 139 return null; 141 } 142 143 public Document openDocument(File file) { 144 return null; 146 } 147 148 public void saveDocument(Document doc) { 149 } 151 152 public Workspace createWorkspace() { 153 GUIWorkspace workspace=new GUIWorkspace(); 155 workspace.setEnvironment((de.gulden.framework.amoda.generic.core.GenericApplicationEnvironment)getEnvironment()); 156 return workspace; 157 } 158 159 public Document openDocument(URL url) { 160 String protocol=url.getProtocol(); 161 if (protocol.equals("file")) { 162 return openDocument(new java.io.File (url.getPath())); 163 } else { 164 error("URLs other than file:// are not supported."); 165 return null; 166 } 167 } 168 169 public void saveDocumentAs(Document doc, File file) { 170 } 172 173 public void closeDocument(Document doc) { 174 if (confirm("Really close this document and all its views?")) { 175 Collection views=getWorkspace().getViews(doc); 176 views=(Collection)views; for (Iterator it=views.iterator();it.hasNext();) { 178 DocumentView view=(DocumentView)it.next(); 179 getWorkspace().removeView(view); 180 } 181 } 182 } 183 184 public void loadDocument(File file) { 185 openDocumentOnWorkspace(openDocument(file)); 186 } 187 188 public void loadDocument(URL url) { 189 openDocumentOnWorkspace(openDocument(url)); 190 } 191 192 public void storeDocument(Document document, File file) { 193 } 195 196 public void storeDocument(Document document, URL url) { 197 } 199 200 public void help() { 201 if (helpDialog==null) { 202 helpDialog=createHelpDialog(); 203 } 204 de.gulden.util.Toolbox.centerOnScreen(helpDialog); 205 helpDialog.setVisible(true); 206 } 207 208 protected JDialog createOptionsDialog() { 209 return null; 211 } 212 213 protected JDialog createAboutDialog() { 214 de.gulden.framework.amoda.environment.gui.component.JDialogCloseable dialog=new de.gulden.framework.amoda.environment.gui.component.JDialogCloseable(((GUIApplicationEnvironment)getEnvironment()).getFrame(),"About",false); 215 JTabbedPane tabbedPane=new JTabbedPane(); 216 tabbedPane.setFont(((GUIApplicationEnvironment)getEnvironment()).getFont(GUIApplicationEnvironment.FONT_MENU)); 217 218 JComponent comp=createAboutComponent(); 219 tabbedPane.add("About",comp); 220 221 dialog.getContentPane().add(tabbedPane); 223 224 String licenseText=createLicenseText(); 225 if (licenseText!=null) { 226 JTextArea textArea=new JTextArea(licenseText); 227 JScrollPane scrollPane=new JScrollPane(textArea); 228 comp=new de.gulden.framework.amoda.environment.gui.component.PresentationPanel(getImage("SecurityModern13.png"),scrollPane); 229 tabbedPane.add("License",comp); 230 } 231 232 de.gulden.util.swing.MapTableModel tableModel=new de.gulden.util.swing.MapTableModel(System.getProperties()); 233 JTable table=new JTable(tableModel); 234 JScrollPane scrollPane=new JScrollPane(table); 235 comp=new de.gulden.framework.amoda.environment.gui.component.PresentationPanel(getImage("ManagementModern02.png"),scrollPane); 236 tabbedPane.add("System",comp); 237 238 dialog.pack(); Dimension size=dialog.getSize(); 240 size.height = 400; 242 dialog.setSize(size); 243 return dialog; 244 } 245 246 protected JComponent createAboutComponent() { 247 String aboutHTML=createAboutHTML(); 248 return new de.gulden.framework.amoda.environment.gui.component.PresentationPanel(getImage("SetupModern24.png"), "<html>"+aboutHTML+"</html>"); 249 } 250 251 protected ApplicationEnvironment createApplicationEnvironment() { 252 de.gulden.framework.amoda.model.core.ApplicationEnvironmentFactory factory=new GUIApplicationEnvironmentFactory(getArgs()); return factory.createApplicationEnvironment(); 255 } 256 257 protected String createAboutHTML() { 258 StringBuffer html=new StringBuffer (); 259 html.append("<h2>"+de.gulden.framework.amoda.generic.metadata.GenericMetadata.findTitle(this)+"</h2>"); 260 String subtitle=getMetadata().get("subtitle"); 261 if (!Toolbox.empty(subtitle)) { 262 html.append("<h3>"+subtitle+"</h3>"); 263 } 264 String description=getMetadata().get("description"); 265 if (!Toolbox.empty(description)) { 266 html.append("<h4>"+description+"</h4>"); 267 } 268 String licenseMessage=getMetadata().get("license-message"); 269 if (!Toolbox.empty(subtitle)) { 270 html.append("<h4>"+licenseMessage+"</h4>"); 271 } 272 html.append("<table>"); 273 for (Iterator it=getMetadata().getEntries().iterator();it.hasNext();) { 274 de.gulden.framework.amoda.model.metadata.MetadataEntry entry=(de.gulden.framework.amoda.model.metadata.MetadataEntry)it.next(); 275 String name=entry.getName(); 276 String value=entry.getString(); 277 if (!(name.equals("license-message") 278 ||name.equals("license-text") 279 ||name.equals("description") 280 ||name.equals("title"))) { 281 html.append("<tr><td><i>"+Toolbox.capitalize(entry.getName())+"</i></td><td><b>"+entry.getString()+"</b></td></tr>"); 282 } 283 } 284 html.append("</table>"); 285 return html.toString(); 286 } 287 288 protected String createLicenseText() { 289 String license=getMetadata().get("license-text"); 290 if (!Toolbox.empty(license)) { 291 return license; 292 } else { 293 return null; 294 } 295 } 296 297 protected void startWorkspace() { 298 de.gulden.framework.amoda.model.document.Document doc=getInitialDocument(); 300 if (doc!=null) { 301 openDocumentOnWorkspace(doc); 302 } 303 } 304 305 protected Document getInitialDocument() { 306 if (getOptions().getBoolean("open-most-recent-file-on-startup")) { 307 Document doc=null; 308 de.gulden.framework.amoda.generic.core.GenericRecentFilesList rfl=(de.gulden.framework.amoda.generic.core.GenericRecentFilesList)getRecentFilesList(); 309 if (rfl!=null) { 310 if (rfl.size()>0) { 311 Object o=rfl.get(0); 312 if (o instanceof java.io.File ) { 313 doc=openDocument((java.io.File )o); 314 } else if (o instanceof java.net.URL ) { 315 doc=openDocument((java.net.URL )o); 316 } 317 } 318 } 319 if (doc!=null) { 320 return doc; 321 } 322 } 323 return getDocumentHandler().newDocument(); 325 } 326 327 protected RecentFilesList createRecentFilesList() { 328 return new GUIRecentFilesList(); 329 } 330 331 protected void openDocumentOnWorkspace(Document document) { 332 if (document!=null) { 333 de.gulden.framework.amoda.model.document.DocumentView view=document.createDefaultView(); 334 getWorkspace().addView(view); 335 } 336 } 337 338 protected JDialog createHelpDialog() { 339 de.gulden.framework.amoda.environment.gui.component.JDialogCloseable dialog=new de.gulden.framework.amoda.environment.gui.component.JDialogCloseable(((GUIApplicationEnvironment)getEnvironment()).getFrame(),"Help",false); 340 JPanel panel = new de.gulden.framework.amoda.environment.gui.component.PresentationPanel(getImage("SecurityModern13.png"), "<html><body>"+createHelpHTML()+"</body></html>"); 341 dialog.getContentPane().add(panel); 342 347 dialog.setSize(800,800); 348 return dialog; 349 } 350 351 protected String createUsageHTML() { 352 StringBuffer sb=new StringBuffer (); 353 357 String usageLine = getUsageLine(); 358 if (usageLine!=null) { 359 sb.append("<h4>Usage:</h4><code>"+de.gulden.util.xml.XMLToolbox.xmlEscape(usageLine)+"</code></p>"); 360 } 361 return sb.toString(); 362 } 363 364 protected String createHelpHTML() { 365 StringBuffer sb=new StringBuffer (); 366 sb.append(createAboutHTML()); 367 sb.append(createUsageHTML()); 368 Collection allOptions = getOptions().getAll(de.gulden.framework.amoda.model.option.OptionEntry.class, true).values(); 369 if (!allOptions.isEmpty()) { 370 sb.append("<h4>options are:</h4><table>"); 371 for (Iterator it=allOptions.iterator();it.hasNext();) { 372 de.gulden.framework.amoda.generic.option.GenericOptionEntry o=(de.gulden.framework.amoda.generic.option.GenericOptionEntry)it.next(); 373 if (!(o.isSystem())) { 374 String name = "-" + o.getId(); 375 String shortcut = o.getShortcut(); 376 if (shortcut != null) { 377 name = "-" + shortcut + " or " + name; 378 } 379 String description=de.gulden.util.Toolbox.noNull(o.getMetadata().get("description")); 380 Class typeClass = o.getType(); 381 if (typeClass == null) { 382 typeClass = String .class; 383 } 384 String type="<i>"+de.gulden.util.Toolbox.unqualify(typeClass.getName()).toLowerCase()+"</i>"; 385 String defaultValue=o.getValue(o.STATE_DEFAULT).getString(); 386 if (defaultValue!=null) { 387 description+=" (default: "+defaultValue+")"; 388 } 389 String row="<tr><td valign='top' nowrap>"+ name +"</td><td valign='top'>"+type+"</td><td>"+description+"</td></tr>"; 390 sb.append(row); 391 } 392 } 393 sb.append("</table>"); 394 } 395 return sb.toString(); 396 } 397 398 void internalSetGenericApplicationEnvironment(GenericApplicationEnvironment env) { 399 this.genericApplicationEnvironment = env; } 401 402 } | Popular Tags |