Source Code Cross Referenced for JSmoothApplication.java in  » Installer » jsmooth » net » charabia » jsmoothgen » application » swtgui » 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 » Installer » jsmooth » net.charabia.jsmoothgen.application.swtgui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on Nov 19, 2003
003:         */
004:        package net.charabia.jsmoothgen.application.swtgui;
005:
006:        import java.io.File;
007:        import java.io.IOException;
008:        import java.util.Iterator;
009:        import java.util.List;
010:        import java.util.Vector;
011:
012:        import net.charabia.jsmoothgen.application.ExeCompiler;
013:        import net.charabia.jsmoothgen.application.JSmoothModelBean;
014:        import net.charabia.jsmoothgen.application.JSmoothModelPersistency;
015:        import net.charabia.jsmoothgen.application.JavaPropertyPair;
016:        import net.charabia.jsmoothgen.application.swtgui.resources.JSmoothResources;
017:        import net.charabia.jsmoothgen.skeleton.SkeletonBean;
018:        import net.charabia.jsmoothgen.skeleton.SkeletonList;
019:        import net.charabia.jsmoothgen.skeleton.SkeletonProperty;
020:
021:        import org.eclipse.swt.SWT;
022:        import org.eclipse.swt.custom.StackLayout;
023:        import org.eclipse.swt.events.SelectionAdapter;
024:        import org.eclipse.swt.events.SelectionEvent;
025:        import org.eclipse.swt.graphics.Point;
026:        import org.eclipse.swt.graphics.Rectangle;
027:        import org.eclipse.swt.layout.GridData;
028:        import org.eclipse.swt.layout.GridLayout;
029:        import org.eclipse.swt.widgets.Composite;
030:        import org.eclipse.swt.widgets.Control;
031:        import org.eclipse.swt.widgets.Display;
032:        import org.eclipse.swt.widgets.Label;
033:        import org.eclipse.swt.widgets.Layout;
034:        import org.eclipse.swt.widgets.Menu;
035:        import org.eclipse.swt.widgets.MenuItem;
036:        import org.eclipse.swt.widgets.Shell;
037:        import org.eclipse.swt.widgets.Text;
038:        import org.eclipse.swt.widgets.ToolBar;
039:        import org.eclipse.swt.widgets.ToolItem;
040:
041:        /**
042:         * @author Dumon
043:         */
044:        public final class JSmoothApplication {
045:            public final JSmoothAction ACTION_OPEN = new OpenAction(
046:                    JSmoothApplication.this );
047:            public final JSmoothAction ACTION_EXIT = new ExitAction(
048:                    JSmoothApplication.this );
049:            public final JSmoothAction ACTION_SAVE = new SaveProjectAction(
050:                    JSmoothApplication.this );
051:            public final JSmoothAction ACTION_SAVE_AS = new SaveAsProjectAction(
052:                    JSmoothApplication.this );
053:            public final JSmoothAction ACTION_NEW = new NewAction(
054:                    JSmoothApplication.this );
055:            public final JSmoothAction ACTION_COMPILE = new CompileAction(
056:                    JSmoothApplication.this );
057:            public final JSmoothAction ACTION_RUNEXE = new RunexeAction(
058:                    JSmoothApplication.this );
059:            public final JSmoothAction ACTION_CONSOLE_CLEAR = new ClearConsoleAction(
060:                    JSmoothApplication.this );
061:
062:            private Shell shell;
063:            private Display display;
064:
065:            // Separators
066:            private Label menusep;
067:            private Label switchersep;
068:
069:            // The layout of the page area composite
070:            private StackLayout stack;
071:
072:            // JSmooth Pages
073:            public final JSmoothPage PAGE_SKELETON = new SkeletonPage(
074:                    JSmoothApplication.this );
075:            public final JSmoothPage PAGE_EXECUTABLE = new ExecutablePage(
076:                    JSmoothApplication.this );
077:            public final JSmoothPage PAGE_WELCOME = new WelcomePage(
078:                    JSmoothApplication.this );
079:            public final JSmoothPage PAGE_APPLICATION = new JavaAppPage(
080:                    JSmoothApplication.this );
081:            public final JSmoothPage PAGE_JVM_OPTIONS = new JVMOptionsPage(
082:                    JSmoothApplication.this );
083:            public final JSmoothPage[] PAGES = new JSmoothPage[] {
084:                    PAGE_WELCOME, PAGE_SKELETON, PAGE_APPLICATION,
085:                    PAGE_JVM_OPTIONS, PAGE_EXECUTABLE };
086:
087:            // Page area
088:            private Composite pagearea;
089:
090:            private Menu mainmenu;
091:            private ToolBar switcher;
092:            private Composite consolearea;
093:            private Text console;
094:            private static final int DIM_CONSOLE_HEIGHT = 150;
095:
096:            // JSmooth related fields
097:            private boolean dirty = false;
098:            private JSmoothModelBean jsmodel;
099:            private File projectfile;
100:            private ExeCompiler compiler;
101:            private SkeletonList skeletonList;
102:
103:            // Cached list of skeleton names
104:            private List skeletonNames;
105:
106:            public JSmoothApplication(Display display) {
107:                new JSmoothResources(this .display = display);
108:
109:                // FIXME: Hardcoded skeletons dir.
110:                this .skeletonList = new SkeletonList(new File("skeletons"));
111:            }
112:
113:            public void newProject() {
114:                // Create a new empty JSmoothModelBean
115:                jsmodel = new JSmoothModelBean();
116:                jsmodel.setSkeletonName(getInitialSkeletonName());
117:                setSkeletonProperties(getInititalSkeletonProperties());
118:                jsmodel.setExecutableName("");
119:                jsmodel.setArguments("");
120:                jsmodel.setBundledJVMPath("");
121:                jsmodel.setClassPath(new String[0]);
122:                jsmodel.setCurrentDirectory("");
123:                jsmodel.setIconLocation("");
124:                jsmodel.setJarLocation("");
125:                jsmodel.setJavaProperties(new JavaPropertyPair[0]);
126:                jsmodel.setJVMSearchPath(new String[0]);
127:                jsmodel.setMainClassName("");
128:                jsmodel.setMaximumVersion("");
129:                jsmodel.setMinimumVersion("");
130:                jsmodel.setNoJvmMessage("");
131:                jsmodel.setNoJvmURL("");
132:
133:                projectfile = null;
134:                compiler = new ExeCompiler();
135:                compiler.addListener(new SWTCompileListener());
136:
137:                for (int i = 0; i < PAGES.length; i++) {
138:                    PAGES[i].load();
139:                }
140:
141:                getShell().setText(getProjectName());
142:            }
143:
144:            public String getProjectName() {
145:                if (projectfile == null) {
146:                    return "";
147:                }
148:                return projectfile.getName();
149:            }
150:
151:            public void setSkeletonProperty(SkeletonProperty property) {
152:                System.out.println("[DEBUG] Setting property \""
153:                        + property.getIdName() + "\" to value \""
154:                        + property.getValue() + "\"");
155:                JSmoothModelBean.Property[] modelProps = jsmodel
156:                        .getSkeletonProperties();
157:                for (int i = 0; i < modelProps.length; i++) {
158:                    if (property.getIdName().equals(modelProps[i].Key)) {
159:                        modelProps[i].setValue(property.getValue());
160:                    }
161:                }
162:            }
163:
164:            public void setSkeletonProperties(SkeletonProperty[] props) {
165:                // Transfer the SkeletonProperty data to JSmoothModelBean.Property
166:                JSmoothModelBean.Property[] modelProps = new JSmoothModelBean.Property[props.length];
167:                String sysoutProps = "";
168:                for (int i = 0; i < props.length; i++) {
169:                    modelProps[i] = new JSmoothModelBean.Property();
170:                    System.out.println("[DEBUG] Setting property \""
171:                            + props[i].getIdName() + "\" to value \""
172:                            + props[i].getValue() + "\"");
173:                    modelProps[i].Key = props[i].getIdName();
174:                    modelProps[i].setValue(props[i].getValue());
175:                }
176:                jsmodel.setSkeletonProperties(modelProps);
177:            }
178:
179:            public SkeletonProperty[] getInititalSkeletonProperties() {
180:                SkeletonBean skeleton = skeletonList.getSkeleton(jsmodel
181:                        .getSkeletonName());
182:                return skeleton.getSkeletonProperties();
183:            }
184:
185:            public SkeletonProperty[] getSkeletonProperties() {
186:                SkeletonBean skeleton = skeletonList.getSkeleton(jsmodel
187:                        .getSkeletonName());
188:                SkeletonProperty[] skeletonProps = skeleton
189:                        .getSkeletonProperties();
190:                JSmoothModelBean.Property[] modelProps = jsmodel
191:                        .getSkeletonProperties();
192:                for (int i = 0; i < skeletonProps.length; i++) {
193:                    if (skeletonProps[i].getIdName().equals(modelProps[i].Key)) {
194:                        skeletonProps[i].setValue(modelProps[i].getValue());
195:                    }
196:                }
197:                return skeletonProps;
198:            }
199:
200:            /**
201:             * Creates the "Page Switcher" toolbar manager and its control. The "Page
202:             * Switcher" lies on the left of the JSmooth window, and is a vertical
203:             * toolbar, with toggle items. On item selection, the window contents change.
204:             */
205:            private void createSwitcherControl(Shell shell) {
206:                switcher = new ToolBar(shell, SWT.FLAT | SWT.NO_FOCUS
207:                        | SWT.VERTICAL);
208:                PAGE_WELCOME.createToolItem(switcher);
209:                PAGE_SKELETON.createToolItem(switcher);
210:                PAGE_APPLICATION.createToolItem(switcher);
211:                PAGE_EXECUTABLE.createToolItem(switcher);
212:                // PAGE_JVM_OPTIONS.createToolItem(switcher);
213:            }
214:
215:            private void createMainMenu(Shell shell) {
216:                mainmenu = new Menu(shell, SWT.BAR);
217:
218:                /* ==== FILE ACTIONS ==== */
219:
220:                MenuItem topItem = new MenuItem(mainmenu, SWT.CASCADE);
221:                topItem.setText("File");
222:                Menu menu = new Menu(shell, SWT.DROP_DOWN);
223:                topItem.setMenu(menu);
224:
225:                MenuItem item = new MenuItem(menu, SWT.NULL);
226:                item.setText("New");
227:                item.addSelectionListener(new SelectionAdapter() {
228:                    public void widgetSelected(SelectionEvent e) {
229:                        ACTION_NEW.run();
230:                    }
231:                });
232:
233:                item = new MenuItem(menu, SWT.NULL);
234:                item.setText("Open...");
235:                item.addSelectionListener(new SelectionAdapter() {
236:                    public void widgetSelected(SelectionEvent e) {
237:                        ACTION_OPEN.run();
238:                    }
239:                });
240:
241:                item = new MenuItem(menu, SWT.NULL);
242:                item.setText("Save");
243:                item.addSelectionListener(new SelectionAdapter() {
244:                    public void widgetSelected(SelectionEvent e) {
245:                        ACTION_SAVE.run();
246:                    }
247:                });
248:
249:                item = new MenuItem(menu, SWT.NULL);
250:                item.setText("Save As...");
251:                item.addSelectionListener(new SelectionAdapter() {
252:                    public void widgetSelected(SelectionEvent e) {
253:                        ACTION_SAVE_AS.run();
254:                    }
255:                });
256:
257:                item = new MenuItem(menu, SWT.SEPARATOR);
258:
259:                item = new MenuItem(menu, SWT.NULL);
260:                item.setText("Exit");
261:                item.addSelectionListener(new SelectionAdapter() {
262:                    public void widgetSelected(SelectionEvent e) {
263:                        ACTION_EXIT.run();
264:                    }
265:                });
266:
267:                /* ==== PROJECT ACTIONS ==== */
268:
269:                topItem = new MenuItem(mainmenu, SWT.CASCADE);
270:                topItem.setText("Project");
271:                menu = new Menu(shell, SWT.DROP_DOWN);
272:                topItem.setMenu(menu);
273:
274:                item = new MenuItem(menu, SWT.NULL);
275:                item.setText("Compile");
276:                item.addSelectionListener(new SelectionAdapter() {
277:                    public void widgetSelected(SelectionEvent e) {
278:                        ACTION_COMPILE.run();
279:                    }
280:                });
281:
282:                item = new MenuItem(menu, SWT.NULL);
283:                item.setText("Run .exe");
284:                item.addSelectionListener(new SelectionAdapter() {
285:                    public void widgetSelected(SelectionEvent e) {
286:                        ACTION_RUNEXE.run();
287:                    }
288:                });
289:
290:                /* ==== CONSOLE ACTIONS ==== */
291:
292:                topItem = new MenuItem(mainmenu, SWT.CASCADE);
293:                topItem.setText("Console");
294:                menu = new Menu(shell, SWT.DROP_DOWN);
295:                topItem.setMenu(menu);
296:
297:                item = new MenuItem(menu, SWT.NULL);
298:                item.setText("Clear");
299:                item.addSelectionListener(new SelectionAdapter() {
300:                    public void widgetSelected(SelectionEvent e) {
301:                        ACTION_CONSOLE_CLEAR.run();
302:                    }
303:                });
304:
305:                shell.setMenuBar(mainmenu);
306:            }
307:
308:            private void createPages(Shell shell) {
309:                pagearea = new Composite(shell, SWT.NONE);
310:                stack = new StackLayout();
311:                pagearea.setLayout(stack);
312:                for (int i = 0; i < PAGES.length; i++) {
313:                    PAGES[i].createControl(pagearea);
314:                }
315:            }
316:
317:            public void showPage(JSmoothPage page) {
318:                stack.topControl = page.getControl();
319:                if (pagearea != null)
320:                    pagearea.layout();
321:                ToolItem item = page.getToolItem();
322:                if (!item.getSelection())
323:                    item.setSelection(true);
324:            }
325:
326:            public static void main(String[] args) {
327:                new JSmoothApplication(Display.getDefault()).run();
328:            }
329:
330:            public void run() {
331:                if (shell == null)
332:                    createControls();
333:
334:                // open the window
335:                shell.open();
336:
337:                newProject();
338:                showPage(PAGE_WELCOME);
339:
340:                try {
341:                    while (shell != null && !shell.isDisposed()) {
342:                        if (!display.readAndDispatch()) {
343:                            display.sleep();
344:                        }
345:                    }
346:                    display.update();
347:                } finally {
348:                    display.dispose();
349:                }
350:            }
351:
352:            private void createControls() {
353:                // Create the shell
354:                shell = new Shell(display, SWT.TITLE | SWT.CLOSE | SWT.MIN
355:                        | SWT.RESIZE);
356:
357:                // The application's menu bar
358:                createMainMenu(shell);
359:
360:                // Horizontal separator label.
361:                // Separes the menu bar from the rest.
362:                menusep = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
363:
364:                createConsole(shell);
365:
366:                // The page switcher toolbar
367:                createSwitcherControl(shell);
368:
369:                // Vertical separator label.
370:                // Separes the switcher toolbar from the rest.
371:                switchersep = new Label(shell, SWT.SEPARATOR | SWT.VERTICAL);
372:
373:                createPages(shell);
374:
375:                // The JSmooth layout
376:                // NOTE: it should be set *after* creating the controls
377:                shell.setLayout(new JSmoothLayout());
378:
379:                // Initialize the bounds of the shell to that appropriate for the contents
380:                initializeBounds();
381:            }
382:
383:            private void createConsole(Shell shell) {
384:                consolearea = new Composite(shell, SWT.NULL);
385:                GridLayout gridlayout = new GridLayout();
386:                consolearea.setLayout(gridlayout);
387:
388:                console = new Text(consolearea, SWT.MULTI | SWT.H_SCROLL
389:                        | SWT.V_SCROLL | SWT.READ_ONLY | SWT.BORDER);
390:                console.setBackground(shell.getDisplay().getSystemColor(
391:                        SWT.COLOR_WHITE));
392:                console.setForeground(shell.getDisplay().getSystemColor(
393:                        SWT.COLOR_BLUE));
394:                GridData gridata = new GridData(GridData.FILL_BOTH);
395:                console.setLayoutData(gridata);
396:
397:                /* ==== CONSOLE MENU ==== */
398:
399:                Menu menu = new Menu(shell, SWT.NULL);
400:
401:                MenuItem item = new MenuItem(menu, SWT.NULL);
402:                item.setText("Clear");
403:                item.addSelectionListener(new SelectionAdapter() {
404:                    public void widgetSelected(SelectionEvent e) {
405:                        ACTION_CONSOLE_CLEAR.run();
406:                    }
407:                });
408:
409:                item = new MenuItem(menu, SWT.NULL);
410:                item.setText("Copy");
411:                item.addSelectionListener(new SelectionAdapter() {
412:                    public void widgetSelected(SelectionEvent e) {
413:                        console.copy();
414:                    }
415:                });
416:
417:                item = new MenuItem(menu, SWT.NULL);
418:                item.setText("Copy All");
419:                item.addSelectionListener(new SelectionAdapter() {
420:                    public void widgetSelected(SelectionEvent e) {
421:                        console.selectAll();
422:                        console.copy();
423:                    }
424:                });
425:
426:                console.setMenu(menu);
427:            }
428:
429:            private void initializeBounds() {
430:                Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
431:                Point location = getInitialLocation(size);
432:                shell.setBounds(location.x, location.y, size.x, size.y);
433:            }
434:
435:            private Point getInitialLocation(Point size) {
436:                Rectangle screen = display.getClientArea();
437:                int x = Math.max(0, screen.x + (screen.width - size.x) / 2);
438:                int y = Math.max(0, screen.y + (screen.height - size.y) / 3);
439:                return new Point(x, y);
440:            }
441:
442:            public Shell getShell() {
443:                return shell;
444:            }
445:
446:            private void fillSkeletonList(List list) {
447:                Iterator i = skeletonList.getIteratorNoDebugName();
448:                while (i.hasNext()) {
449:                    list.add((String) i.next());
450:                }
451:            }
452:
453:            public List getSkeletonList(boolean flush) {
454:                // True at the first call to this method
455:                if (skeletonNames == null)
456:                    fillSkeletonList(skeletonNames = new Vector());
457:                if (flush) {
458:                    skeletonNames.clear();
459:                    fillSkeletonList(skeletonNames);
460:                }
461:
462:                // From the "cache"
463:                return skeletonNames;
464:            }
465:
466:            public String[] getAllSkeletonNames() {
467:                return (String[]) getSkeletonList(false).toArray(new String[0]);
468:            }
469:
470:            public String getInitialSkeletonName() {
471:                // We want to return the "Window Wrapper" skeleton.
472:                // Due to the fact that we cannot identify the skeletons :(,
473:                // we'll have to make a hard guess.
474:                // It seems like the "Window Wrapper" is the second in the
475:                // list. In case it is not , we catch the exception,
476:                // and return the first skeleton in the list.
477:                String[] skelNames = getAllSkeletonNames();
478:                try {
479:                    return skelNames[1];
480:                } catch (ArrayIndexOutOfBoundsException e) {
481:                    return skelNames[0];
482:                }
483:            }
484:
485:            public JSmoothModelBean getModelBean() {
486:                return jsmodel;
487:            }
488:
489:            public boolean saveProjectAs(String projectfile) {
490:                System.out.println("[DEBUG] Saving project to file: "
491:                        + projectfile);
492:                this .projectfile = new File(projectfile);
493:                try {
494:                    JSmoothModelPersistency.save(this .projectfile, jsmodel);
495:                } catch (IOException e) {
496:                    System.out.println("[ERROR] Failed saving project : "
497:                            + e.getMessage());
498:                    return false;
499:                }
500:                getShell().setText(getProjectName());
501:                return true;
502:            }
503:
504:            public boolean saveProject() {
505:                return saveProjectAs(projectfile.getAbsolutePath());
506:            }
507:
508:            public File getProjectFile() {
509:                return projectfile;
510:            }
511:
512:            public boolean hasProjectFile() {
513:                return projectfile != null;
514:            }
515:
516:            public void exit() {
517:                getShell().close();
518:            }
519:
520:            public boolean openProject(String projectfile) {
521:                System.out.println("[DEBUG] Opening project : " + projectfile);
522:                File file = new File(projectfile);
523:                JSmoothModelBean jsmodel = null;
524:                try {
525:                    jsmodel = JSmoothModelPersistency.load(file);
526:                } catch (IOException e) {
527:                    System.out.println("[ERROR] Failed opening project : "
528:                            + e.getMessage());
529:                    return false;
530:                }
531:
532:                this .projectfile = file;
533:                this .jsmodel = jsmodel;
534:
535:                for (int i = 0; i < PAGES.length; i++) {
536:                    PAGES[i].load();
537:                }
538:
539:                getShell().setText(getProjectName());
540:                return true;
541:            }
542:
543:            public boolean compileProject() {
544:                consoleMessage("=== Compilation ===");
545:                File basedir = projectfile.getParentFile();
546:                jsmodel.normalizePaths(basedir);
547:                String skeletonName = jsmodel.getSkeletonName();
548:                SkeletonBean skeletonBean = skeletonList
549:                        .getSkeleton(skeletonName);
550:                File skeletonRoot = skeletonList.getDirectory(skeletonBean);
551:
552:                // NOTE: We assume the exe name is always relative
553:                File exename = new File(jsmodel.getExecutableName());
554:                if (!exename.isAbsolute()) {
555:                    exename = new File(basedir, jsmodel.getExecutableName());
556:                }
557:
558:                boolean success = false;
559:                try {
560:                    success = compiler.compile(skeletonRoot, skeletonBean,
561:                            basedir, jsmodel, exename);
562:                } catch (Exception e) {
563:                    // Do nothing, bellow we the errors anyway (see bellow).
564:                }
565:
566:                consoleMessages((String[]) compiler.getErrors().toArray(
567:                        new String[0]));
568:                compiler.cleanErrors();
569:
570:                return success;
571:            }
572:
573:            public void consoleMessage(String msg) {
574:                if (console.getText().length() != 0)
575:                    console.append("\r\n"); // New line ?
576:                console.append(msg);
577:            }
578:
579:            public void consoleMessages(String[] msg) {
580:                for (int i = 0; i < msg.length; i++) {
581:                    consoleMessage(msg[i]);
582:                }
583:            }
584:
585:            public void clearConsole() {
586:                console.setText("");
587:            }
588:
589:            public void consoleSection(String title) {
590:                StringBuffer buffer = new StringBuffer(
591:                        "-------------------------------------------------------------------------------------");
592:                if (title == null) {
593:                    consoleMessage(buffer.toString());
594:                    return;
595:                }
596:                buffer.replace(0, title.length() + 1, title + " ");
597:                consoleMessage(buffer.toString());
598:            }
599:
600:            /**
601:             * Special layout for the JSmooth Window.
602:             */
603:            class JSmoothLayout extends Layout {
604:                protected Point computeSize(Composite composite, int wHint,
605:                        int hHint, boolean flushCache) {
606:                    if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) {
607:                        return new Point(wHint, hHint);
608:                    }
609:
610:                    Point result = new Point(0, 0);
611:                    Control[] ctrls = composite.getChildren();
612:                    Point p = null;
613:                    for (int i = 0; i < ctrls.length; i++) {
614:                        Control w = ctrls[i];
615:                        if (menusep == w) {
616:                            p = w.computeSize(wHint, hHint, flushCache);
617:                            result.y += p.y;
618:                        } else if (switcher == w) {
619:                            p = w.computeSize(wHint, hHint, flushCache);
620:                            result.x += p.x;
621:                            result.y += p.y;
622:                        } else if (switchersep == w) {
623:                            p = w.computeSize(wHint, hHint, flushCache);
624:                            result.x += p.x;
625:                        } else if (consolearea == w) {
626:                            p = w.computeSize(wHint, hHint, flushCache);
627:                            result.y += DIM_CONSOLE_HEIGHT;
628:                        } else if (pagearea == w) {
629:                            p = w.computeSize(wHint, hHint, flushCache);
630:                            result.x += p.x;
631:                            result.y = p.y + DIM_CONSOLE_HEIGHT;
632:                        }
633:                    }
634:
635:                    if (wHint != SWT.DEFAULT)
636:                        result.x = wHint;
637:                    if (hHint != SWT.DEFAULT)
638:                        result.y = hHint;
639:
640:                    return result;
641:                }
642:
643:                protected void layout(Composite cmp, boolean flushCache) {
644:                    if (flushCache) {
645:                        for (int i = 0; i < PAGES.length; i++) {
646:                            ((Composite) PAGES[i].getControl()).layout();
647:                        }
648:                    }
649:
650:                    Rectangle clientarea = cmp.getClientArea();
651:                    Control[] wgs = cmp.getChildren();
652:                    Point p = null;
653:                    for (int i = 0; i < wgs.length; i++) {
654:                        Control w = wgs[i];
655:                        if (menusep == w) {
656:                            p = w.computeSize(SWT.DEFAULT, SWT.DEFAULT,
657:                                    flushCache);
658:                            w.setBounds(clientarea.x, clientarea.y,
659:                                    clientarea.width, p.y);
660:                            clientarea.y += p.y;
661:                            clientarea.height += p.y;
662:                        } else if (switcher == w) {
663:                            p = w.computeSize(SWT.DEFAULT, SWT.DEFAULT,
664:                                    flushCache);
665:                            w.setBounds(clientarea.x, clientarea.y, p.x, p.y);
666:                            clientarea.x += p.x;
667:                            clientarea.width -= p.x;
668:                        } else if (switchersep == w) {
669:                            p = w.computeSize(SWT.DEFAULT, SWT.DEFAULT,
670:                                    flushCache);
671:                            w.setBounds(clientarea.x, clientarea.y, p.x,
672:                                    clientarea.height);
673:                            clientarea.x += p.x;
674:                            clientarea.width -= p.x;
675:                        } else if (consolearea == w) {
676:                            p = w.computeSize(SWT.DEFAULT, DIM_CONSOLE_HEIGHT,
677:                                    flushCache);
678:                            w
679:                                    .setBounds(clientarea.x, clientarea.height
680:                                            - DIM_CONSOLE_HEIGHT,
681:                                            clientarea.width, p.y);
682:                            clientarea.height -= DIM_CONSOLE_HEIGHT;
683:                        } else if (pagearea == w) {
684:                            w.setBounds(clientarea.x, clientarea.y,
685:                                    clientarea.width, clientarea.height);
686:                        }
687:                    }
688:
689:                    // Resize to fit all child controls
690:                    if (flushCache)
691:                        cmp.setSize(cmp.computeSize(SWT.DEFAULT, SWT.DEFAULT));
692:                }
693:            }
694:
695:            class SWTCompileListener implements  ExeCompiler.StepListener {
696:                public void setNewState(int percent, String state) {
697:                    consoleMessage(state);
698:                }
699:
700:                public void failed() {
701:                    consoleMessage("Compile failed.");
702:                }
703:
704:                public void complete() {
705:                    consoleMessage("Compile successfull.");
706:                }
707:            }
708:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.