001: /*
002: * UILauncher.java Copyright (c) 2006,07 Swaroop Belur
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008:
009: * This program 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
012: * GNU General Public License for more details.
013:
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
017: *
018: */
019:
020: package net.sf.jdec.ui.main;
021:
022: import java.awt.Component;
023: import java.awt.Window;
024: import java.io.IOException;
025: import java.util.ArrayList;
026: import java.util.List;
027:
028: import javax.swing.JFrame;
029:
030: import net.sf.jdec.commonutil.StartupHelper;
031: import net.sf.jdec.io.Writer;
032: import net.sf.jdec.ui.config.UIConfig;
033: import net.sf.jdec.ui.core.DisplayUI;
034: import net.sf.jdec.ui.core.Manager;
035: import net.sf.jdec.ui.core.UIObserver;
036: import net.sf.jdec.ui.util.LogWriter;
037: import net.sf.jdec.ui.util.SplashScreen;
038: import net.sf.jdec.ui.util.UIUtil;
039:
040: /***
041: * TODO: Trim this class for next release
042: * @author sbelur
043: *
044: */
045: public class UILauncher {
046:
047: private static void setUIUtilRef(UIUtil uiutil) {
048: util = uiutil;
049: }
050:
051: private static UIUtil util = null;
052:
053: public static boolean welcomeCreated = false;
054:
055: public static UIUtil getUIutil() {
056: return util;
057: }
058:
059: static String message = "";
060:
061: public static void main(java.lang.String arg[]) {
062: try {
063: //registerShutDownHook();
064: Thread sp = new SplashScreenThread();
065: sp.start();
066: sp.setPriority(Thread.MAX_PRIORITY);
067: while (splash == null) {
068: }
069:
070: UIUtil uiutil = UIUtil.getUIUtil();
071: uiutil.registerDecompilerConfigParams();
072: splash.progress.setValue(10);
073:
074: setUIUtilRef(uiutil);
075: UIObserver observer = UIObserver.getUIObserver();
076: setObserver(observer);
077: uiConfig = UIConfig.getUIConfig();
078: uiConfig.readUserPrefs();
079: splash.progress.setValue(20);
080:
081: Manager manager = Manager.getManager();
082: manager.createAllComponents(observer);
083: splash.progress.setValue(50);
084:
085: manager.regitser();
086: splash.progress.setValue(60);
087:
088: new StartupHelper().start();
089:
090: // Now Display The UI
091: DisplayUI display = new DisplayUI();
092: display.setManager(manager);
093: display.renderComponenets();
094:
095: } catch (IOException ioe) {
096: try {
097: ioe.printStackTrace();
098: LogWriter lg = LogWriter.getInstance();
099: lg
100: .writeLog("[ERROR]: Method: main\n\tClass: UILauncher.class");
101: lg
102: .writeLog("------------------------------------------------");
103: lg.writeLog("Exception Stack Trace");
104: ioe.printStackTrace(lg.getPrintWriter());
105: lg.flush();
106: } catch (Exception e) {
107:
108: }
109:
110: } catch (Exception ep) {
111: ep.printStackTrace();
112:
113: } catch (Throwable t) {
114: t.printStackTrace();
115: }
116:
117: }
118:
119: private static void registerShutDownHook() {
120: Runtime rt = Runtime.getRuntime();
121: rt.addShutdownHook(new Thread(new Runnable() {
122:
123: public void run() {
124:
125: Writer w = null;
126: try {
127: w = Writer.getWriter("log");
128: String cmd = "java.exe -cp .;jdec.jar net.sf.jdec.ui.main.UILauncher";
129: Process p = Runtime.getRuntime().exec(cmd);
130: } catch (IOException e) {
131: if (w != null)
132: e.printStackTrace(w);
133: } finally {
134: System.exit(0);
135: }
136: }
137: }));
138:
139: }
140:
141: private static UIConfig uiConfig;
142:
143: public static UIConfig getUIConfigRef() {
144: return uiConfig;
145:
146: }
147:
148: public static void setMainFrameRef(JFrame main) {
149: mainFrame = main;
150: }
151:
152: public static JFrame getMainFrame() {
153: return mainFrame;
154: }
155:
156: static JFrame mainFrame = null;
157:
158: public static UIObserver observer = null;
159:
160: private static void setObserver(UIObserver observer) {
161: UILauncher.observer = observer;
162: //System.out.println(UILauncher.observer + " Is the Observer Object...");
163: }
164:
165: public static UIObserver getObserver() {
166: return observer;
167: }
168:
169: public static void setTempFrame(JFrame[] temp) {
170: UILauncher.temp = temp;
171: }
172:
173: public static void addTempFrame(JFrame frame) {
174: tempa.add(frame);
175: }
176:
177: public static JFrame[] getTempFrames() {
178: return (JFrame[]) tempa.toArray(new JFrame[tempa.size()]);
179: }
180:
181: private static JFrame[] temp;
182: private static ArrayList tempa = new ArrayList();;
183:
184: public static void addMainFrameRefCopy(JFrame frame) {
185: copies.add(frame);
186: }
187:
188: private static ArrayList copies = new ArrayList();
189:
190: public static ArrayList getAllClones() {
191: return copies;
192: }
193:
194: public static JFrame getOriginalFrame() {
195: return getMainFrame();
196: }
197:
198: static ArrayList childRefs = new ArrayList();
199:
200: public static void addChildRef(Component c) {
201: childRefs.add(c);
202: }
203:
204: public static List getChildRefs() {
205: return childRefs;
206: }
207:
208: public static void closeChildWindows() {
209: int total = childRefs.size();
210: for (int s = 0; s < total; s++) {
211: Component x = (Component) childRefs.get(s);
212: if (x instanceof Window && x != null) //? Is null check needed
213: {
214: Window w = (Window) x;
215: w.setVisible(false);
216: w.setEnabled(false);
217: w = null;
218: x = null;
219:
220: }
221:
222: }
223:
224: }
225:
226: public static volatile boolean showSplash = true;
227: public volatile static SplashScreen splash = null;
228:
229: static class SplashScreenThread extends Thread {
230:
231: public void run() {
232:
233: splash = new SplashScreen();
234: splash.splash();
235: while (showSplash) {
236: try {
237: sleep(1000);
238: } catch (InterruptedException ie) {
239: showSplash = false;
240: }
241: }
242: splash.dispose();
243: splash.setVisible(false);
244: splash = null;
245: }
246:
247: }
248: //Package
249: }
|