001: /*
002: * Copyright (C) 2005 Jeff Tassin
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.jeta.swingbuilder.main;
020:
021: import com.jeta.open.registry.JETARegistry;
022: import com.jeta.swingbuilder.app.UserPropertiesStore;
023: import com.jeta.swingbuilder.common.ComponentNames;
024: import com.jeta.swingbuilder.gui.main.MainFrame;
025: import com.jeta.swingbuilder.gui.main.MainFrameController;
026: import com.jeta.swingbuilder.gui.main.Splash;
027: import com.jeta.swingbuilder.gui.utils.FormDesignerUtils;
028: import com.jeta.swingbuilder.interfaces.app.ObjectStore;
029:
030: /**
031: * This is the main launcher class for the application.
032: *
033: * @author Jeff Tassin
034: */
035: public class AbeilleForms {
036:
037: private Splash m_splash;
038:
039: public AbeilleForms() {
040: }
041:
042: /**
043: * Launches the application and displays the frame window
044: *
045: * @param args
046: * command line arguments
047: */
048: public void launch(String[] args) {
049: launch(args, true);
050: }
051:
052: /**
053: * Launches the application and optionally displays the frame window. This
054: * method is needed for command line utilities that depend on the designer
055: * platform but don't show the main frame window.
056: *
057: * @param args
058: * command line arguments
059: * @param showFrame
060: * true if the main frame is displayed. False otherwise.
061: */
062: public void launch(String[] args, boolean showFrame) {
063: try {
064: /** for Mac OS X menu bar integration */
065: System.setProperty("apple.laf.useScreenMenuBar", "true");
066: System.setProperty(
067: "com.apple.mrj.application.apple.menu.about.name",
068: "Abeille Forms Designer");
069:
070: if (!FormDesignerUtils.isDebug()) {
071: System
072: .setOut(new java.io.PrintStream(
073: new EmptyStream()));
074: }
075:
076: } catch (Exception e) {
077: e.printStackTrace();
078: }
079:
080: if (showFrame)
081: m_splash = new Splash();
082:
083: try {
084: FormsInitializer ji = new FormsInitializer();
085: ji.initialize(args);
086: launchComponents(showFrame);
087: } catch (Exception e) {
088: e.printStackTrace();
089: System.exit(0);
090: }
091: }
092:
093: /**
094: * Launched base components needed by the rest of the application
095: *
096: * @throws ClassNotFoundException
097: * @throws InstantiationException
098: * @throws IllegalAccessException
099: */
100: private void launchComponents(boolean showFrame)
101: throws ClassNotFoundException, InstantiationException,
102: IllegalAccessException {
103: UserPropertiesStore ups = new UserPropertiesStore();
104: ups.startup();
105:
106: if (showFrame) {
107: MainFrameController.setDefaultLookAndFeel();
108: m_splash.dispose();
109: }
110:
111: MainFrame mframe = new MainFrame();
112: if (showFrame)
113: mframe.show();
114: }
115:
116: public static void shutdown() {
117: try {
118: try {
119: Object obj = JETARegistry
120: .lookup(UserPropertiesStore.COMPONENT_ID);
121: if (obj instanceof UserPropertiesStore) {
122: UserPropertiesStore userstore = (UserPropertiesStore) obj;
123: userstore.shutdown();
124: }
125:
126: // save the main application state
127: ObjectStore os = (ObjectStore) JETARegistry
128: .lookup(ComponentNames.APPLICATION_STATE_STORE);
129: os.flush();
130: } catch (Exception e) {
131: }
132: } catch (Exception e) {
133: e.printStackTrace();
134: }
135: System.exit(0);
136: }
137:
138: /**
139: * Trap all system.out
140: */
141: private class EmptyStream extends java.io.OutputStream {
142: public void write(byte[] b) throws java.io.IOException {
143: // ignore
144: }
145:
146: public void write(int ival) throws java.io.IOException {
147: // ignore
148: }
149: }
150:
151: }
|