Source Code Cross Referenced for GUIApplication.java in  » Code-Analyzer » beautyJ » de » gulden » framework » amoda » environment » gui » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Code Analyzer » beautyJ » de.gulden.framework.amoda.environment.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Project: AMODA - Abstract Modeled Application
003:         * Class:   de.gulden.framework.amoda.environment.gui.GUIApplication
004:         * Version: snapshot-beautyj-1.1
005:         *
006:         * Date:    2004-09-29
007:         *
008:         * This is a snapshot version of the AMODA 0.2 development branch,
009:         * it is not released as a seperate version.
010:         * For AMODA, see http://amoda.berlios.de/.
011:         *  
012:         * This is licensed under the GNU Lesser General Public License (LGPL)
013:         * and comes with NO WARRANTY.
014:         *
015:         * Author:  Jens Gulden
016:         * Email:   amoda@jensgulden.de
017:         */
018:
019:        package de.gulden.framework.amoda.environment.gui;
020:
021:        import de.gulden.framework.amoda.environment.commandline.*;
022:        import de.gulden.framework.amoda.generic.core.*;
023:        import de.gulden.framework.amoda.model.core.*;
024:        import de.gulden.framework.amoda.model.core.WorkspaceProvider;
025:        import de.gulden.framework.amoda.model.document.*;
026:        import de.gulden.framework.amoda.model.document.ClipboardHandler;
027:        import de.gulden.framework.amoda.model.document.Document;
028:        import de.gulden.framework.amoda.model.document.DocumentHandler;
029:        import de.gulden.util.Toolbox;
030:        import de.gulden.util.xml.XMLToolbox;
031:        import java.awt.*;
032:        import java.io.*;
033:        import java.lang.*;
034:        import java.net.*;
035:        import java.util.*;
036:        import javax.swing.*;
037:        import org.w3c.dom.*;
038:
039:        /**
040:         * Class GUIApplication.
041:         *  
042:         * @author  Jens Gulden
043:         * @version  snapshot-beautyj-1.1
044:         */
045:        public abstract class GUIApplication extends CommandLineApplication
046:                implements  WorkspaceProvider, ClipboardHandler, DocumentHandler {
047:
048:            // ------------------------------------------------------------------------
049:            // --- fields                                                           ---
050:            // ------------------------------------------------------------------------
051:
052:            protected boolean modeMultiDocuments;
053:
054:            protected boolean modeMultiViews;
055:
056:            protected JDialog aboutDialog;
057:
058:            protected JWindow aboutSplashWindow;
059:
060:            protected JDialog helpDialog;
061:
062:            // ------------------------------------------------------------------------
063:            // --- methods                                                          ---
064:            // ------------------------------------------------------------------------
065:
066:            public Workspace getWorkspace() {
067:                return ((GUIApplicationEnvironment) getEnvironment())
068:                        .getWorkspace();
069:            }
070:
071:            public JComponent createGUIComponent(DocumentView view) {
072:                // to be overwritten by subclass if used
073:                throw new AbstractMethodError(
074:                        "createDefaultView is not implemented by subclass");
075:            }
076:
077:            public void cutSelection(DocumentSelection sel) {
078:                // your code here
079:            }
080:
081:            public void copySelection(DocumentSelection sel) {
082:                // your code here
083:            }
084:
085:            public void pasteSelection(DocumentSelection sel) {
086:                // your code here
087:            }
088:
089:            public DocumentHandler getDocumentHandler() {
090:                return this ; // default is this, may be overwritten
091:            }
092:
093:            public ClipboardHandler getClipboardHandler() {
094:                return this ; // default is this, may be overwritten
095:            }
096:
097:            public void destroy() {
098:                ((GUIApplicationEnvironment) getGenericApplicationEnvironment())
099:                        .getFrame().dispose();
100:                System.exit(0);
101:            }
102:
103:            public void start() {
104:                // init recent files list
105:                getRecentFilesList().init(this );
106:                // open window
107:                ((GUIApplicationEnvironment) getEnvironment()).getFrame()
108:                        .setVisible(true);
109:                // open initial documents or whatever else on the workspace
110:                startWorkspace();
111:                if (aboutSplashWindow != null) {
112:                    aboutSplashWindow.dispose();
113:                }
114:                super .start();
115:            }
116:
117:            public void about() {
118:                if (((GUIApplicationEnvironment) getEnvironment()).getFrame()
119:                        .isVisible()) { // normal mode
120:                    if (aboutDialog == null) {
121:                        aboutDialog = createAboutDialog();
122:                    }
123:                    de.gulden.util.Toolbox.centerOnScreen(aboutDialog);
124:                    aboutDialog.setVisible(true);
125:                } else {
126:                    aboutSplash(); // special mode during init
127:                }
128:            }
129:
130:            public void aboutSplash() {
131:                JWindow window = new JWindow(
132:                        ((GUIApplicationEnvironment) getEnvironment())
133:                                .getFrame());
134:                JComponent aboutComponent = createAboutComponent();
135:                window.getContentPane().add(aboutComponent);
136:                window.pack();
137:                Dimension size = window.getSize();
138:                size.width = 500;
139:                window.setSize(size);
140:                de.gulden.util.Toolbox.centerOnScreen(window);
141:                this .aboutSplashWindow = window;
142:                window.setVisible(true);
143:            }
144:
145:            public Document newDocument() {
146:                // your code here
147:                return null;
148:            }
149:
150:            public Document openDocument(File file) {
151:                // your code here
152:                return null;
153:            }
154:
155:            public void saveDocument(Document doc) {
156:                // your code here
157:            }
158:
159:            public Workspace createWorkspace() {
160:                // may be overwritten by sublcasses
161:                GUIWorkspace workspace = new GUIWorkspace();
162:                workspace
163:                        .setEnvironment((de.gulden.framework.amoda.generic.core.GenericApplicationEnvironment) getEnvironment());
164:                return workspace;
165:            }
166:
167:            public Document openDocument(URL url) {
168:                String protocol = url.getProtocol();
169:                if (protocol.equals("file")) {
170:                    return openDocument(new java.io.File(url.getPath()));
171:                } else {
172:                    error("URLs other than file:// are not supported.");
173:                    return null;
174:                }
175:            }
176:
177:            public void saveDocumentAs(Document doc, File file) {
178:                // your code here
179:            }
180:
181:            public void closeDocument(Document doc) {
182:                if (confirm("Really close this document and all its views?")) {
183:                    Collection views = getWorkspace().getViews(doc);
184:                    views = (Collection) views; // avoid concurrent modification exception
185:                    for (Iterator it = views.iterator(); it.hasNext();) {
186:                        DocumentView view = (DocumentView) it.next();
187:                        getWorkspace().removeView(view);
188:                    }
189:                }
190:            }
191:
192:            public void loadDocument(File file) {
193:                openDocumentOnWorkspace(openDocument(file));
194:            }
195:
196:            public void loadDocument(URL url) {
197:                openDocumentOnWorkspace(openDocument(url));
198:            }
199:
200:            public void storeDocument(Document document, File file) {
201:                // your code here
202:            }
203:
204:            public void storeDocument(Document document, URL url) {
205:                // your code here
206:            }
207:
208:            public void help() {
209:                if (helpDialog == null) {
210:                    helpDialog = createHelpDialog();
211:                }
212:                de.gulden.util.Toolbox.centerOnScreen(helpDialog);
213:                helpDialog.setVisible(true);
214:            }
215:
216:            protected JDialog createOptionsDialog() {
217:                // your code here
218:                return null;
219:            }
220:
221:            protected JDialog createAboutDialog() {
222:                de.gulden.framework.amoda.environment.gui.component.JDialogCloseable dialog = new de.gulden.framework.amoda.environment.gui.component.JDialogCloseable(
223:                        ((GUIApplicationEnvironment) getEnvironment())
224:                                .getFrame(), "About", false);
225:                JTabbedPane tabbedPane = new JTabbedPane();
226:                tabbedPane
227:                        .setFont(((GUIApplicationEnvironment) getEnvironment())
228:                                .getFont(GUIApplicationEnvironment.FONT_MENU));
229:
230:                JComponent comp = createAboutComponent();
231:                tabbedPane.add("About", comp);
232:
233:                // set size now (after filling text will be too late)
234:                dialog.getContentPane().add(tabbedPane);
235:
236:                String licenseText = createLicenseText();
237:                if (licenseText != null) {
238:                    JTextArea textArea = new JTextArea(licenseText);
239:                    JScrollPane scrollPane = new JScrollPane(textArea);
240:                    comp = new de.gulden.framework.amoda.environment.gui.component.PresentationPanel(
241:                            getImage("SecurityModern13.png"), scrollPane);
242:                    tabbedPane.add("License", comp);
243:                }
244:
245:                de.gulden.util.swing.MapTableModel tableModel = new de.gulden.util.swing.MapTableModel(
246:                        System.getProperties());
247:                JTable table = new JTable(tableModel);
248:                JScrollPane scrollPane = new JScrollPane(table);
249:                comp = new de.gulden.framework.amoda.environment.gui.component.PresentationPanel(
250:                        getImage("ManagementModern02.png"), scrollPane);
251:                tabbedPane.add("System", comp);
252:
253:                dialog.pack(); // will lead to extremely over-wide dialog
254:                Dimension size = dialog.getSize();
255:                //size.height-=10; // ******************************************
256:                size.height = 400;
257:                dialog.setSize(size);
258:                return dialog;
259:            }
260:
261:            protected JComponent createAboutComponent() {
262:                String aboutHTML = createAboutHTML();
263:                return new de.gulden.framework.amoda.environment.gui.component.PresentationPanel(
264:                        getImage("SetupModern24.png"), "<html>" + aboutHTML
265:                                + "</html>");
266:            }
267:
268:            protected ApplicationEnvironment createApplicationEnvironment() {
269:                // overwrites CommandlineApplication.createApplicationEnvironment
270:                de.gulden.framework.amoda.model.core.ApplicationEnvironmentFactory factory = new GUIApplicationEnvironmentFactory(
271:                        getArgs());//,getConfigurationResourceURL());
272:                return factory.createApplicationEnvironment();
273:            }
274:
275:            protected String createAboutHTML() {
276:                StringBuffer html = new StringBuffer();
277:                html
278:                        .append("<h2>"
279:                                + de.gulden.framework.amoda.generic.metadata.GenericMetadata
280:                                        .findTitle(this ) + "</h2>");
281:                String subtitle = getMetadata().get("subtitle");
282:                if (!Toolbox.empty(subtitle)) {
283:                    html.append("<h3>" + subtitle + "</h3>");
284:                }
285:                String description = getMetadata().get("description");
286:                if (!Toolbox.empty(description)) {
287:                    html.append("<h4>" + description + "</h4>");
288:                }
289:                String licenseMessage = getMetadata().get("license-message");
290:                if (!Toolbox.empty(subtitle)) {
291:                    html.append("<h4>" + licenseMessage + "</h4>");
292:                }
293:                html.append("<table>");
294:                for (Iterator it = getMetadata().getEntries().iterator(); it
295:                        .hasNext();) {
296:                    de.gulden.framework.amoda.model.metadata.MetadataEntry entry = (de.gulden.framework.amoda.model.metadata.MetadataEntry) it
297:                            .next();
298:                    String name = entry.getName();
299:                    String value = entry.getString();
300:                    if (!(name.equals("license-message")
301:                            || name.equals("license-text")
302:                            || name.equals("description") || name
303:                            .equals("title"))) {
304:                        html.append("<tr><td><i>"
305:                                + Toolbox.capitalize(entry.getName())
306:                                + "</i></td><td><b>" + entry.getString()
307:                                + "</b></td></tr>");
308:                    }
309:                }
310:                html.append("</table>");
311:                return html.toString();
312:            }
313:
314:            protected String createLicenseText() {
315:                String license = getMetadata().get("license-text");
316:                if (!Toolbox.empty(license)) {
317:                    return license;
318:                } else {
319:                    return null;
320:                }
321:            }
322:
323:            protected void startWorkspace() {
324:                // default implementation, opens 1 new blank document
325:                de.gulden.framework.amoda.model.document.Document doc = getInitialDocument();
326:                if (doc != null) {
327:                    openDocumentOnWorkspace(doc);
328:                }
329:            }
330:
331:            protected Document getInitialDocument() {
332:                if (getOptions().getBoolean("open-most-recent-file-on-startup")) {
333:                    Document doc = null;
334:                    de.gulden.framework.amoda.generic.core.GenericRecentFilesList rfl = (de.gulden.framework.amoda.generic.core.GenericRecentFilesList) getRecentFilesList();
335:                    if (rfl != null) {
336:                        if (rfl.size() > 0) {
337:                            Object o = rfl.get(0);
338:                            if (o instanceof  java.io.File) {
339:                                doc = openDocument((java.io.File) o);
340:                            } else if (o instanceof  java.net.URL) {
341:                                doc = openDocument((java.net.URL) o);
342:                            }
343:                        }
344:                    }
345:                    if (doc != null) {
346:                        return doc;
347:                    }
348:                }
349:                //FALLSTHROUGH on all else-branches
350:                return getDocumentHandler().newDocument();
351:            }
352:
353:            protected RecentFilesList createRecentFilesList() {
354:                return new GUIRecentFilesList();
355:            }
356:
357:            protected void openDocumentOnWorkspace(Document document) {
358:                if (document != null) {
359:                    de.gulden.framework.amoda.model.document.DocumentView view = document
360:                            .createDefaultView();
361:                    getWorkspace().addView(view);
362:                }
363:            }
364:
365:            protected JDialog createHelpDialog() {
366:                de.gulden.framework.amoda.environment.gui.component.JDialogCloseable dialog = new de.gulden.framework.amoda.environment.gui.component.JDialogCloseable(
367:                        ((GUIApplicationEnvironment) getEnvironment())
368:                                .getFrame(), "Help", false);
369:                JPanel panel = new de.gulden.framework.amoda.environment.gui.component.PresentationPanel(
370:                        getImage("SecurityModern13.png"), "<html><body>"
371:                                + createHelpHTML() + "</body></html>");
372:                dialog.getContentPane().add(panel);
373:                /*dialog.pack(); // will lead to extremely over-wide dialog
374:                Dimension size=dialog.getSize();
375:                size.height = 800;
376:                size.height = 600;
377:                dialog.setSize(size);*/
378:                dialog.setSize(800, 800);
379:                return dialog;
380:            }
381:
382:            protected String createUsageHTML() {
383:                StringBuffer sb = new StringBuffer();
384:                /*String description = getMetadata().get("description").trim();
385:                if (description.length()!=0) {
386:                    sb.append("<p>"+description+"</p>");
387:                }*/
388:                String usageLine = getUsageLine();
389:                if (usageLine != null) {
390:                    sb.append("<h4>Usage:</h4><code>"
391:                            + de.gulden.util.xml.XMLToolbox
392:                                    .xmlEscape(usageLine) + "</code></p>");
393:                }
394:                return sb.toString();
395:            }
396:
397:            protected String createHelpHTML() {
398:                StringBuffer sb = new StringBuffer();
399:                sb.append(createAboutHTML());
400:                sb.append(createUsageHTML());
401:                Collection allOptions = getOptions()
402:                        .getAll(
403:                                de.gulden.framework.amoda.model.option.OptionEntry.class,
404:                                true).values();
405:                if (!allOptions.isEmpty()) {
406:                    sb.append("<h4>options are:</h4><table>");
407:                    for (Iterator it = allOptions.iterator(); it.hasNext();) {
408:                        de.gulden.framework.amoda.generic.option.GenericOptionEntry o = (de.gulden.framework.amoda.generic.option.GenericOptionEntry) it
409:                                .next();
410:                        if (!(o.isSystem())) {
411:                            String name = "-" + o.getId();
412:                            String shortcut = o.getShortcut();
413:                            if (shortcut != null) {
414:                                name = "-" + shortcut + " or " + name;
415:                            }
416:                            String description = de.gulden.util.Toolbox
417:                                    .noNull(o.getMetadata().get("description"));
418:                            Class typeClass = o.getType();
419:                            if (typeClass == null) {
420:                                typeClass = String.class;
421:                            }
422:                            String type = "<i>"
423:                                    + de.gulden.util.Toolbox.unqualify(
424:                                            typeClass.getName()).toLowerCase()
425:                                    + "</i>";
426:                            String defaultValue = o.getValue(o.STATE_DEFAULT)
427:                                    .getString();
428:                            if (defaultValue != null) {
429:                                description += " (default: " + defaultValue
430:                                        + ")";
431:                            }
432:                            String row = "<tr><td valign='top' nowrap>" + name
433:                                    + "</td><td valign='top'>" + type
434:                                    + "</td><td>" + description + "</td></tr>";
435:                            sb.append(row);
436:                        }
437:                    }
438:                    sb.append("</table>");
439:                }
440:                return sb.toString();
441:            }
442:
443:            void internalSetGenericApplicationEnvironment(
444:                    GenericApplicationEnvironment env) {
445:                this .genericApplicationEnvironment = env; // set without backward-reference (for dummy-instances of GUIApplication)
446:            }
447:
448:        } // end GUIApplication
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.