Source Code Cross Referenced for CleverPHL.java in  » Testing » jacareto » jacareto » cleverphl » 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 » Testing » jacareto » jacareto.cleverphl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Jacareto Copyright (c) 2002-2005
003:         * Applied Computer Science Research Group, Darmstadt University of
004:         * Technology, Institute of Mathematics & Computer Science,
005:         * Ludwigsburg University of Education, and Computer Based
006:         * Learning Research Group, Aachen University. All rights reserved.
007:         *
008:         * Jacareto is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public
010:         * License as published by the Free Software Foundation; either
011:         * version 2 of the License, or (at your option) any later version.
012:         *
013:         * Jacareto is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
016:         * General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public
019:         * License along with Jacareto; if not, write to the Free
020:         * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021:         *
022:         */
023:
024:        package jacareto.cleverphl;
025:
026:        import jacareto.cleverphl.gui.CleverPHLConfirmDialog;
027:        import jacareto.cleverphl.gui.CleverPHLFrame;
028:        import jacareto.cleverphl.gui.CleverPHLMainFrame;
029:        import jacareto.cleverphl.gui.ComponentsFrame;
030:        import jacareto.cleverphl.gui.ConceptualModelFrame;
031:        import jacareto.cleverphl.gui.DataSetFrame;
032:        import jacareto.cleverphl.gui.DrawingFrame;
033:        import jacareto.cleverphl.gui.HelpFrame;
034:        import jacareto.cleverphl.gui.InteractionModelFrame;
035:        import jacareto.cleverphl.gui.MessageFrame;
036:        import jacareto.cleverphl.gui.SplashScreen;
037:        import jacareto.cleverphl.gui.TestReportFrame;
038:        import jacareto.cleverphl.gui.TrackEditorFrame;
039:        import jacareto.cleverphl.session.Session;
040:        import jacareto.cleverphl.session.SessionList;
041:        import jacareto.cleverphl.session.SessionLoader;
042:        import jacareto.replay.mediaplayer.DefaultMediaPlayerFactory;
043:        import jacareto.starter.StarterList;
044:        import jacareto.system.Customization;
045:        import jacareto.system.Environment;
046:        import jacareto.system.EnvironmentMember;
047:        import jacareto.system.Files;
048:        import jacareto.system.Language;
049:        import jacareto.system.Modules;
050:        import jacareto.toolkit.CommandLine;
051:        import jacareto.toolkit.CommandLineException;
052:        import jacareto.toolkit.EnhancedHashtable;
053:        import jacareto.toolkit.HashtableException;
054:        import jacareto.toolkit.JacaretoSystemClassLoader;
055:        import jacareto.toolkit.ResourceLoader;
056:        import jacareto.toolkit.StringToolkit;
057:        import jacareto.toolkit.log4j.LogOutputStream;
058:        import jacareto.track.block.BlockType;
059:
060:        import org.apache.log4j.Level;
061:        import org.apache.log4j.Logger;
062:
063:        import java.awt.Window;
064:
065:        import java.io.File;
066:        import java.io.FileFilter;
067:        import java.io.IOException;
068:        import java.io.PrintStream;
069:
070:        import java.util.Enumeration;
071:        import java.util.Iterator;
072:
073:        import javax.swing.ImageIcon;
074:        import javax.swing.UIManager;
075:
076:        /**
077:         * The main class of CleverPHL.
078:         *
079:         * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
080:         * @version 1.25
081:         */
082:        public class CleverPHL extends EnvironmentMember {
083:            /** The version of CleverPHL. */
084:            public final static String VERSION = "0.7.12";
085:
086:            /** The build number. */
087:            public final static int BUILD = 2;
088:
089:            /** The language. */
090:            private static String languageString;
091:
092:            /** Starting in safe mode. */
093:            private static boolean isSafeMode;
094:
095:            /** The main frame. */
096:            private CleverPHLMainFrame mainFrame;
097:
098:            /** The message frame. */
099:            private MessageFrame messageFrame;
100:
101:            /** The components frame. */
102:            private ComponentsFrame componentsFrame;
103:
104:            /** The data set frame . */
105:            private DataSetFrame dataSetFrame;
106:
107:            /** The interaction-model frame */
108:            private InteractionModelFrame interactionModelFrame;
109:
110:            /** The conceptual-model frame */
111:            private ConceptualModelFrame conceptualModelFrame;
112:
113:            /** The Test Report Frame */
114:            private TestReportFrame testReportFrame;
115:
116:            /** The frame with the drawing tools. */
117:            private DrawingFrame drawingFrame;
118:
119:            /** The TrackEditorFrame */
120:            private TrackEditorFrame trackEditorFrame;
121:
122:            /** The help frame. */
123:            private HelpFrame helpFrame;
124:
125:            /** The splash screen. */
126:            private SplashScreen splashScreen;
127:
128:            /** The clipboard. */
129:            private ClipBoard clipBoard;
130:
131:            /** The session loader. */
132:            private SessionLoader sessionLoader;
133:
134:            /** The insert test into tree frame */
135:
136:            //private InsertTestIntoTreeFrame insertTestsIntoTreeFrame;
137:            /** Array with all windows. */
138:            private Window[] windows;
139:
140:            /** Stores the visibility state when all windows are hidden. */
141:            private boolean[] visibilityState;
142:
143:            /** The modules. */
144:            private Modules modules;
145:
146:            /** The session list. */
147:            private SessionList sessionList;
148:
149:            /** The Jacareto system class loader. */
150:            private JacaretoSystemClassLoader systemClassLoader;
151:
152:            /**
153:             * The output stream which replaces the default <code>System.err</code> and pipes to the
154:             * logger.
155:             */
156:            private LogOutputStream errStream;
157:
158:            /**
159:             * The output stream which replaces the default <code>System.out</code> and pipes to the
160:             * logger.
161:             */
162:            private LogOutputStream outStream;
163:
164:            /**
165:             * Creates a new instance of CleverPHL with a defined look&amp;feel.
166:             *
167:             * @param env the environment
168:             * @param lookandfeel the look and feel, as string
169:             */
170:            public CleverPHL(Environment env, String lookandfeel) {
171:                super (env);
172:
173:                boolean lookAndFeelSet = false;
174:
175:                if (StringToolkit.isDefined(lookandfeel)) {
176:                    try {
177:                        UIManager.setLookAndFeel(lookandfeel);
178:                        lookAndFeelSet = true;
179:                    } catch (Exception ex) {
180:                        env.getLogger().error(
181:                                env.getLanguage().getString(
182:                                        "CleverPHL.Msg.LFFailed")
183:                                        + ": " + lookandfeel);
184:                    }
185:                }
186:
187:                if (!lookAndFeelSet) {
188:                    try {
189:                        UIManager.setLookAndFeel(UIManager
190:                                .getSystemLookAndFeelClassName());
191:                    } catch (Exception ex) {
192:                        env.getLogger().debug(
193:                                env.getLanguage().getString(
194:                                        "CleverPHL.Msg.SystemLFFailed"));
195:                    }
196:                }
197:
198:                sessionLoader = new SessionLoader(this );
199:                sessionList = new SessionList(env);
200:
201:                modules = new Modules(env, env.getFiles().getDir("MODULES_DIR")
202:                        .getAbsolutePath());
203:                env.setModules(modules);
204:                clipBoard = new ClipBoard(this );
205:
206:                // working directory
207:                if (!env.getCustomization().containsKey("CleverPHL.WorkingDir")) {
208:                    env.getCustomization().put("CleverPHL.WorkingDir",
209:                            System.getProperty("user.home"));
210:                }
211:            }
212:
213:            /**
214:             * Creates a new instance of CleverPHL with the system's look and feel.
215:             *
216:             * @param env the environment
217:             */
218:            public CleverPHL(Environment env) {
219:                this (env, null);
220:            }
221:
222:            /**
223:             * Returns the working directory.
224:             *
225:             * @return the directory
226:             */
227:            public File getWorkingDir() {
228:                return new File(env.getCustomization()
229:                        .getString("CleverPHL.WorkingDir",
230:                                System.getProperty("user.home")));
231:            }
232:
233:            /**
234:             * Sets the working directory
235:             *
236:             * @param workingDir new working dir
237:             */
238:            public void setWorkingDir(File workingDir) {
239:                env.getCustomization().put("CleverPHL.WorkingDir",
240:                        workingDir.getAbsolutePath());
241:            }
242:
243:            /**
244:             * Returns the main frame.
245:             *
246:             * @return DOCUMENT ME!
247:             */
248:            public CleverPHLMainFrame getMainFrame() {
249:                return mainFrame;
250:            }
251:
252:            /**
253:             * Returns the message frame.
254:             *
255:             * @return DOCUMENT ME!
256:             */
257:            public MessageFrame getMessageFrame() {
258:                return messageFrame;
259:            }
260:
261:            /**
262:             * Returns the TrackEditorFrame
263:             *
264:             * @return {@link TrackEditorFrame}
265:             */
266:            public TrackEditorFrame getTrackEditorFrame() {
267:                return this .trackEditorFrame;
268:            }
269:
270:            /**
271:             * Returns the components frame.
272:             *
273:             * @return {@link ComponentsFrame}
274:             */
275:            public ComponentsFrame getComponentsFrame() {
276:                return componentsFrame;
277:            }
278:
279:            /**
280:             * Returns the help frame.
281:             *
282:             * @return {@link ComponentsFrame}
283:             */
284:            public HelpFrame getHelpFrame() {
285:                return helpFrame;
286:            }
287:
288:            /**
289:             * Returns the data set frame.
290:             *
291:             * @return DOCUMENT ME!
292:             */
293:            public DataSetFrame getDataSetFrame() {
294:                return dataSetFrame;
295:            }
296:
297:            /**
298:             * Returns the interaction-model frame.
299:             *
300:             * @return DOCUMENT ME!
301:             */
302:            public InteractionModelFrame getInteractionModelFrame() {
303:                return interactionModelFrame;
304:            }
305:
306:            /**
307:             * Returns the test report frame.
308:             *
309:             * @return DOCUMENT ME!
310:             */
311:            public TestReportFrame getTestReportFrame() {
312:                return testReportFrame;
313:            }
314:
315:            /**
316:             * Returns the window with the drawing tools.
317:             *
318:             * @return the drawing frame
319:             */
320:            public DrawingFrame getDrawingFrame() {
321:                return drawingFrame;
322:            }
323:
324:            /**
325:             * Return the conceptual-model frame.
326:             *
327:             * @return DOCUMENT ME!
328:             */
329:            public ConceptualModelFrame getConceptualModelFrame() {
330:                return conceptualModelFrame;
331:            }
332:
333:            /**
334:             * Returns the splash screen.
335:             *
336:             * @return the splash screen
337:             */
338:            public SplashScreen getSplashScreen() {
339:                if (splashScreen == null) {
340:                    splashScreen = new SplashScreen(this );
341:                }
342:
343:                return splashScreen;
344:            }
345:
346:            /**
347:             * Returns the clipboard.
348:             *
349:             * @return the clipboard
350:             */
351:            public ClipBoard getClipBoard() {
352:                return clipBoard;
353:            }
354:
355:            /**
356:             * Returns the session loader.
357:             *
358:             * @return the instance which loads sessions!
359:             */
360:            public SessionLoader getSessionLoader() {
361:                return sessionLoader;
362:            }
363:
364:            /**
365:             * Returns the Jacareto system class loader.
366:             *
367:             * @return DOCUMENT ME!
368:             */
369:            public JacaretoSystemClassLoader getJacaretoSystemClassLoader() {
370:                return systemClassLoader;
371:            }
372:
373:            /**
374:             * DOCUMENT ME!
375:             *
376:             * @return the insert test into tree frame.
377:             */
378:
379:            /*public InsertTestIntoTreeFrame getInsertTestsIntoTreeFrame()
380:            {
381:               return insertTestsIntoTreeFrame;
382:            } */
383:
384:            /**
385:             * Returns the modules.
386:             *
387:             * @return DOCUMENT ME!
388:             */
389:            public Modules getModules() {
390:                return modules;
391:            }
392:
393:            /**
394:             * Exits the program in a regular way.
395:             */
396:            public void exit() {
397:                Language language = getLanguage();
398:                Iterator i = getSessionList().iterator();
399:
400:                while (i.hasNext()) {
401:                    Session session = (Session) i.next();
402:
403:                    if (session.isSessionUnsaved()) {
404:                        CleverPHLConfirmDialog confirmDialog = new CleverPHLConfirmDialog(
405:                                this ,
406:                                getMainFrame(),
407:                                language
408:                                        .getString("CleverPHL.Menu.ExitProgram.UnsavedSession"),
409:                                language
410:                                        .getString("CleverPHL.Menu.ExitProgram.Msg.UnsavedSession"),
411:                                language.getString("General.Yes"), language
412:                                        .getString("General.No"));
413:
414:                        if (confirmDialog.getValue() == CleverPHLConfirmDialog.YES) {
415:                            Iterator i2 = getSessionList().iterator();
416:
417:                            while (i2.hasNext()) {
418:                                ((Session) i2.next()).setStoreOnExit(false);
419:                            }
420:
421:                            break;
422:                        } else {
423:                            return;
424:                        }
425:                    }
426:                }
427:
428:                storeSessionNames();
429:
430:                // store the customization
431:                try {
432:                    getCustomization().write(
433:                            getFiles().getAbsolutePath("CLEVERPHL_USER_DIR")
434:                                    + File.separator
435:                                    + getCustomization().getString(
436:                                            "CleverPHL.UserCustomization",
437:                                            "customization.xml"));
438:                } catch (IOException ioex) {
439:                    getLogger().error(
440:                            getLanguage().getString(
441:                                    "CleverPHL.Error.WriteCustomization"));
442:                }
443:
444:                System.exit(0);
445:            }
446:
447:            /**
448:             * Stores the names of the loaded sessions in the customization before exit.
449:             */
450:            private void storeSessionNames() {
451:                // store the names of the opened sessions
452:                Iterator i3 = getSessionList().iterator();
453:                EnhancedHashtable sessionTable = new EnhancedHashtable();
454:                int position = 0;
455:
456:                while (i3.hasNext()) {
457:                    sessionTable.put(new Integer(position), ((Session) i3
458:                            .next()).getName());
459:                    position++;
460:                }
461:
462:                getCustomization().put("Sessions.OpenedSessions", sessionTable);
463:
464:                if (getSessionList().size() > 0) {
465:                    getCustomization().put("Sessions.ActiveSession",
466:                            getSessionList().getActual().getName());
467:                } else {
468:                    getCustomization().put("Sessions.ActiveSession", "");
469:                }
470:            }
471:
472:            /**
473:             * Loads all sessions of the last CleverPHL usage.
474:             */
475:            private void loadLastSessions() {
476:                String progressText = getLanguage().getString(
477:                        "CleverPHL.SplashScreen.ProgressText.LoadingSession");
478:                EnhancedHashtable sessionTable = getCustomization().getMap(
479:                        "Sessions.OpenedSessions", new EnhancedHashtable());
480:                String[] sessionNames = new String[sessionTable.size()];
481:                Enumeration keys = sessionTable.keys();
482:
483:                while (keys.hasMoreElements()) {
484:                    Object position = keys.nextElement();
485:                    int pos = Integer.valueOf(position.toString()).intValue();
486:                    sessionNames[pos] = (String) sessionTable.get(position);
487:                }
488:
489:                for (int i = 0; i < sessionNames.length; i++) {
490:                    try {
491:                        getSplashScreen().setProgressText(
492:                                progressText + " " + sessionNames[i] + "...");
493:                        sessionLoader.loadSession(sessionNames[i]);
494:                    } catch (Exception ignored) {
495:                        // When a session cannot be loaded, it hasn't been saved.
496:                        // In this case, loading the session is not possible.
497:                    }
498:                }
499:
500:                String lastActiveSession = getCustomization().getString(
501:                        "Sessions.ActiveSession", null);
502:
503:                if (StringToolkit.isDefined(lastActiveSession)
504:                        && sessionList.contains(lastActiveSession)) {
505:                    sessionList.setActual(lastActiveSession);
506:                } else if (sessionList.size() > 0) {
507:                    sessionList.setActual(0);
508:                }
509:            }
510:
511:            /**
512:             * The main method.
513:             *
514:             * @param args the command line arguments
515:             */
516:            public static void main(String[] args) {
517:                languageString = null;
518:
519:                testClasspath();
520:
521:                CommandLine commandLine = new CommandLine();
522:
523:                try {
524:                    commandLine.addValidArgument("l", 1);
525:                    commandLine.addValidArgument("h", 0);
526:                    commandLine.addValidArgument("lf", 1);
527:                    commandLine.addValidArgument("safemode", 0);
528:                    commandLine.readArguments(args);
529:                } catch (CommandLineException c) {
530:                    System.out.print("\nError: ");
531:                    System.out.println(c.getMessage());
532:                    printHelp();
533:                    System.exit(-1);
534:                }
535:
536:                if (commandLine.hasArgument("h")) {
537:                    printHelp();
538:                    System.exit(1);
539:                }
540:
541:                if (commandLine.hasArgument("l")) {
542:                    languageString = commandLine.getValue("l", 0);
543:                }
544:
545:                String lookAndFeel = null;
546:
547:                if (commandLine.hasArgument("lf")) {
548:                    lookAndFeel = commandLine.getValue("lf", 0);
549:                }
550:
551:                isSafeMode = commandLine.hasArgument("safemode");
552:
553:                CleverPHL cleverPHL = new CleverPHL(createEnv(), lookAndFeel);
554:
555:                cleverPHL.getSplashScreen().showSplashScreen();
556:
557:                cleverPHL.createStarterFile();
558:                cleverPHL.buildGUI();
559:                cleverPHL.start();
560:            }
561:
562:            /**
563:             * Builds the main frame of CleverPHL with all its subcomponents.
564:             */
565:            public void buildGUI() {
566:                getSplashScreen()
567:                        .setProgressText(
568:                                getLanguage()
569:                                        .getString(
570:                                                "CleverPHL.SplashScreen.ProgressText.BuildingGUI")
571:                                        + "...");
572:
573:                // create the frames
574:                mainFrame = new CleverPHLMainFrame(this );
575:                messageFrame = new MessageFrame(this );
576:                componentsFrame = new ComponentsFrame(this );
577:                dataSetFrame = new DataSetFrame(this );
578:                interactionModelFrame = new InteractionModelFrame(this );
579:                conceptualModelFrame = new ConceptualModelFrame(this );
580:                testReportFrame = new TestReportFrame(this );
581:                drawingFrame = new DrawingFrame(this );
582:                trackEditorFrame = new TrackEditorFrame(this );
583:
584:                getSplashScreen()
585:                        .setProgressText(
586:                                getLanguage()
587:                                        .getString(
588:                                                "CleverPHL.SplashScreen.ProgressText.LoadingHelp")
589:                                        + "...");
590:                helpFrame = new HelpFrame(this );
591:
592:                windows = new Window[10];
593:                visibilityState = new boolean[10];
594:
595:                windows[0] = mainFrame;
596:                windows[1] = messageFrame;
597:                windows[2] = componentsFrame;
598:                windows[3] = dataSetFrame;
599:                windows[4] = interactionModelFrame;
600:                windows[5] = conceptualModelFrame;
601:                windows[6] = testReportFrame;
602:                windows[7] = drawingFrame;
603:                windows[8] = trackEditorFrame;
604:                windows[9] = helpFrame;
605:            }
606:
607:            /**
608:             * Returns the session list.
609:             *
610:             * @return the session list
611:             */
612:            public SessionList getSessionList() {
613:                return sessionList;
614:            }
615:
616:            /**
617:             * Starts CleverPHL. The GUI must be built before with the method {@link #buildGUI()}.
618:             */
619:            public void start() {
620:                Customization customization = getCustomization();
621:
622:                getSplashScreen()
623:                        .setProgressText(
624:                                getLanguage()
625:                                        .getString(
626:                                                "CleverPHL.SplashScreen.ProgressText.ConfiguringLogger")
627:                                        + "...");
628:                getLogger().setAdditivity(false);
629:
630:                try {
631:                    if (customization.getBoolean("Log.SystemOut", false)) {
632:                        outStream = new LogOutputStream(getLogger(), Level
633:                                .toLevel(customization.getString(
634:                                        "Log.SystemOutLevel", "INFO")));
635:                        System.setOut(new PrintStream(outStream));
636:                    }
637:
638:                    if (customization.getBoolean("Log.SystemErr", false)) {
639:                        errStream = new LogOutputStream(getLogger(), Level
640:                                .toLevel(customization.getString(
641:                                        "Log.SystemErrLevel", "ERROR")));
642:                        System.setErr(new PrintStream(errStream));
643:                    }
644:                } catch (SecurityException ignored) {
645:                    ;
646:                }
647:
648:                if (!isSafeMode) {
649:                    loadLastSessions();
650:                }
651:
652:                getSplashScreen().close();
653:
654:                setVisibilityFromCustomization();
655:                mainFrame.setVisible(true);
656:            }
657:
658:            /**
659:             * Hides all visible windows.
660:             */
661:            public void hideAllWindows() {
662:                for (int i = 0; i < windows.length; i++) {
663:                    visibilityState[i] = windows[i].isVisible();
664:                    windows[i].setVisible(false);
665:                }
666:            }
667:
668:            /**
669:             * Restores the visibility state of the windows before they have been hidden.
670:             */
671:            public void restoreVisibility() {
672:                for (int i = 0; i < windows.length; i++) {
673:                    windows[i].setVisible(visibilityState[i]);
674:                }
675:            }
676:
677:            /**
678:             * Loads the visibility states from customization
679:             */
680:            public void setVisibilityFromCustomization() {
681:                for (int i = 0; i < windows.length; i++) {
682:                    if (windows[i] instanceof  CleverPHLFrame) {
683:                        ((CleverPHLFrame) windows[i])
684:                                .restoreVisibilityFromCustomization();
685:                    }
686:                }
687:            }
688:
689:            /**
690:             * Creates the env with the logger, the language and the customization object. If an error
691:             * occurs, this method exits the whole system.
692:             *
693:             * @return the new env
694:             */
695:            private static Environment createEnv() {
696:                Files files = createDirs();
697:
698:                String log4jProperties = files.getDir("CUSTOMIZATION_DIR")
699:                        .getAbsolutePath()
700:                        + File.separator
701:                        + "log4j"
702:                        + File.separator
703:                        + "cleverphl.properties";
704:                org.apache.log4j.PropertyConfigurator
705:                        .configure(log4jProperties);
706:
707:                Logger logger = null;
708:
709:                try {
710:                    logger = Logger.getLogger("CleverPHL");
711:                } catch (VerifyError v) {
712:                    System.err.println("VerifyError    : " + v.getMessage());
713:                    System.err.println("Properties File: " + log4jProperties);
714:                    System.exit(1);
715:                }
716:
717:                Customization customization = null;
718:                Language language = null;
719:
720:                String defaultCustomizationFilename = files.getDir(
721:                        "CUSTOMIZATION_DIR").getAbsolutePath()
722:                        + File.separator + "cleverphl.xml";
723:
724:                try {
725:                    // load the default customization
726:                    customization = new Customization(
727:                            defaultCustomizationFilename);
728:                    customization.put("CleverPHL.Version", VERSION);
729:                    customization.put("CleverPHL.Build", BUILD);
730:
731:                    // overwrite it with the user customization if version and build are the same
732:                    if (!isSafeMode) {
733:                        String userCustomizationFilename = files
734:                                .getAbsolutePath("CLEVERPHL_USER_DIR")
735:                                + File.separator
736:                                + customization.getString(
737:                                        "CleverPHL.UserCustomization",
738:                                        "customization.xml");
739:
740:                        if (new File(userCustomizationFilename).exists()) {
741:                            Customization userCustomization = new Customization(
742:                                    userCustomizationFilename);
743:                            String oldVersion = userCustomization.getString(
744:                                    "CleverPHL.Version", null);
745:                            int oldBuild = userCustomization.getInt(
746:                                    "CleverPHL.Build", 0);
747:
748:                            if (StringToolkit.isDefined(oldVersion)
749:                                    && StringToolkit.areEqual(VERSION,
750:                                            oldVersion) && (BUILD == oldBuild)) {
751:                                customization.read(userCustomizationFilename);
752:                            }
753:                        }
754:                    }
755:                } catch (IOException i) {
756:                    logger.fatal("Cannot read customization file: "
757:                            + defaultCustomizationFilename);
758:                }
759:
760:                try {
761:                    if (languageString == null) {
762:                        languageString = customization.getString(
763:                                "Language.Default", "en");
764:                    }
765:
766:                    language = new Language(customization, files.getDir(
767:                            "LANGUAGE_DIR").getAbsolutePath(), languageString,
768:                            logger);
769:                } catch (IOException i) {
770:                    logger.fatal("Cannot read language file!", i);
771:                    System.exit(-1);
772:                } catch (HashtableException h) {
773:                    logger
774:                            .fatal(
775:                                    "Error: Cannot find the entry for the chosen language ("
776:                                            + languageString
777:                                            + ") in the language map!", h);
778:                    System.exit(-1);
779:                }
780:
781:                return (new Environment(customization, logger, language, files));
782:            }
783:
784:            /**
785:             * Creates the directories if they do not already exist.
786:             *
787:             * @return DOCUMENT ME!
788:             */
789:            private static Files createDirs() {
790:                String userDir = System.getProperty("user.home")
791:                        + File.separator + "cleverphl_data";
792:
793:                if (!(new File(userDir)).exists()) {
794:                    System.out.println("Creating directories for your data...");
795:                    System.out.println("Path: " + userDir);
796:                }
797:
798:                Files files = new Files();
799:                files.addDir("CLEVERPHL_USER_DIR", new File(userDir));
800:                files.addDir("CLEVERPHL_STARTERS_DIR", new File(userDir
801:                        + File.separator + "starters"));
802:                files.addDir("CLEVERPHL_SESSIONS_DIR", new File(userDir
803:                        + File.separator + "sessions"));
804:
805:                // Add the session directories
806:                File sessionDir = files.getDir("CLEVERPHL_SESSIONS_DIR");
807:                File[] dirs = sessionDir.listFiles(new FileFilter() {
808:                    public boolean accept(File file) {
809:                        return file.isDirectory();
810:                    }
811:                });
812:
813:                if (dirs != null) {
814:                    for (int i = 0; i < dirs.length; i++) {
815:                        files.addDir("CLEVERPHL_SESSIONS_DIR."
816:                                + dirs[i].getName(), dirs[i]);
817:                    }
818:                }
819:
820:                return files;
821:            }
822:
823:            /**
824:             * Creates the default starter file.
825:             */
826:            public void createStarterFile() {
827:                String targetFilename = files.getDir("CLEVERPHL_STARTERS_DIR")
828:                        + File.separator
829:                        + customization.getString(
830:                                "CleverPHL.SessionStarterFile", "default.xml");
831:
832:                if (!new File(targetFilename).exists()) {
833:                    getSplashScreen()
834:                            .setProgressText(
835:                                    getLanguage()
836:                                            .getString(
837:                                                    "CleverPHL.SplashScreen.ProgressText.CreatingDefaultStarterFile")
838:                                            + "...");
839:
840:                    StarterList tmpList = new StarterList(env, env.getFiles()
841:                            .getDir("JACARETO_HOME").getAbsolutePath()
842:                            + File.separator
843:                            + customization.getString("CleverPHL.StarterFile",
844:                                    null));
845:                    tmpList.saveStarters(files.getDir("CLEVERPHL_STARTERS_DIR")
846:                            + File.separator
847:                            + customization.getString(
848:                                    "CleverPHL.SessionStarterFile",
849:                                    "default.xml"));
850:                }
851:            }
852:
853:            /**
854:             * Tests the existence of media files in the CLASSPATH. In most cases, this method will only
855:             * find errors when developing with Jacareto.
856:             */
857:            private static void testClasspath() {
858:                boolean errorFound = false;
859:
860:                try {
861:                    ImageIcon icon = ResourceLoader
862:                            .getImageIcon("CleverPHLLogo.gif");
863:                } catch (NullPointerException npex) {
864:                    System.err.println("\nERROR: Cannot find image files.");
865:                    System.err
866:                            .println("Please add the directory \"resources\" to your CLASSPATH variable.");
867:                    errorFound = true;
868:                }
869:
870:                try {
871:                    DefaultMediaPlayerFactory.getInstance().createPlayer(
872:                            BlockType.AUDIO, "replaysounds/mousepressed.wav");
873:                } catch (NullPointerException npex) {
874:                    System.err.println("\nERROR: Cannot find media files.");
875:                    System.err
876:                            .println("Please add the directory \"media\" to your CLASSPATH variable.");
877:                    errorFound = true;
878:                }
879:
880:                if (errorFound) {
881:                    System.err.println("\n");
882:                    System.exit(0);
883:                }
884:            }
885:
886:            /**
887:             * Prints the command line help.
888:             */
889:            private static void printHelp() {
890:                System.out.println();
891:                System.out.println("This is the syntax of starting CleverPHL:");
892:                System.out.println();
893:                System.out
894:                        .println("   java jacareto.cleverphl.CleverPHL [-h][-l lang][-lf lookandfeel][-safemode]");
895:                System.out.println();
896:                System.out.println("Options:");
897:                System.out.println();
898:                System.out.println("-h: ");
899:                System.out.println("   Prints this help.");
900:                System.out.println("-l lang");
901:                System.out.println("   Selects a language. Example: -l en");
902:                System.out.println("-lf lookandfeel");
903:                System.out
904:                        .println("   Starts CleverPHL with the specified look&feel.");
905:                System.out.println("-safemode");
906:                System.out.println("   Starts CleverPHL in safe mode");
907:                System.out
908:                        .println("   (without loading stored customization and sessions).");
909:                System.out.println();
910:            }
911:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.