Source Code Cross Referenced for SimpleBasisAMSInstall.java in  » 6.0-JDK-Modules » j2me » com » sun » jumpimpl » presentation » simplebasis » 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 » 6.0 JDK Modules » j2me » com.sun.jumpimpl.presentation.simplebasis 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright  1990-2006 Sun Microsystems, Inc. All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004:         *
005:         * This program is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU General Public License version
007:         * 2 only, as published by the Free Software Foundation.
008:         *
009:         * This program is distributed in the hope that it will be useful, but
010:         * WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012:         * General Public License version 2 for more details (a copy is
013:         * included at /legal/license.txt).
014:         *
015:         * You should have received a copy of the GNU General Public License
016:         * version 2 along with this work; if not, write to the Free Software
017:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018:         * 02110-1301 USA
019:         *
020:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021:         * Clara, CA 95054 or visit www.sun.com if you need additional
022:         * information or have any questions.
023:         */
024:
025:        package com.sun.jumpimpl.presentation.simplebasis;
026:
027:        import com.sun.jump.common.JUMPApplication;
028:        import com.sun.jump.common.JUMPContent;
029:        import com.sun.jump.module.installer.JUMPInstallerModule;
030:        import com.sun.jump.module.installer.JUMPInstallerModuleFactory;
031:        import com.sun.jumpimpl.module.download.OTADiscovery;
032:        import com.sun.jumpimpl.module.installer.JUMPInstallerTool;
033:        import java.awt.BorderLayout;
034:        import java.awt.Color;
035:        import java.awt.Container;
036:        import java.awt.Dimension;
037:        import java.awt.Font;
038:        import java.awt.FontMetrics;
039:        import java.awt.Graphics;
040:        import java.awt.GridLayout;
041:        import java.awt.event.ActionEvent;
042:        import java.awt.event.ActionListener;
043:        import java.util.HashMap;
044:        import java.util.Iterator;
045:        import java.util.Map;
046:        import java.util.Vector;
047:
048:        public class SimpleBasisAMSInstall {
049:
050:            private String downloadNames[] = null;
051:            private String downloadURIs[] = null;
052:            private SimpleBasisAMS ams = null;
053:
054:            private final int INSTALL_SCREEN = 10;
055:            private final int INSTALL_APPS_LIST_SCREEN = 11;
056:            private final int REMOVE_SCREEN = 12;
057:            private final int REMOVE_APPS_LIST_SCREEN = 13;
058:            private final int STATUS_SCREEN = 14;
059:
060:            private static final Color INSTALL_SCREEN_COLOR = new Color(209,
061:                    191, 217);
062:            private static final Color REMOVE_SCREEN_COLOR = new Color(201,
063:                    158, 119);
064:            private static final Color STATUS_SCREEN_COLOR = new Color(219,
065:                    241, 153);
066:
067:            private static final Color BUTTON_BLUE_COLOR = new Color(86, 135,
068:                    248);
069:            private static final Color BUTTON_YELLOW_COLOR = new Color(229,
070:                    231, 44);
071:            private static final Color BUTTON_RED_COLOR = new Color(188, 85, 68);
072:
073:            private static final int APPS_LIST_SCREEN_ROWS = 7;
074:            private static final int APPS_LIST_SCREEN_COLUMNS = 1;
075:            private static final int APPS_LIST_SCREEN_NUM_ENTRIES = APPS_LIST_SCREEN_ROWS
076:                    * APPS_LIST_SCREEN_COLUMNS;
077:
078:            int installAppsListScreenPageNumber = 0;
079:            int removeAppsListScreenPageNumber = 0;
080:            InstallationStatusScreen installationStatusScreen = null;
081:
082:            private JUMPInstallerTool tool = null;
083:            private Map map = null;
084:
085:            private final Font HEADER_FONT = new Font("Arial", Font.BOLD
086:                    | Font.ITALIC, 24);
087:
088:            private String provisionURL = null;
089:
090:            public SimpleBasisAMSInstall(SimpleBasisAMS ams) {
091:                this .ams = ams;
092:                this .map = ams.map;
093:                tool = new JUMPInstallerTool(parseToolProperties(map));
094:            }
095:
096:            private void trace(String str) {
097:                ams.trace(str);
098:            }
099:
100:            private String[] parseToolProperties(Map map) {
101:
102:                // check if verbose mode is used
103:                provisionURL = System
104:                        .getProperty("jump.installer.provisionURL");
105:                if (provisionURL == null && map != null) {
106:                    provisionURL = (String) map
107:                            .get("jump.installer.provisionURL");
108:                }
109:                String str[] = new String[1];
110:                str[0] = "-ProvisioningServerURL " + provisionURL;
111:                return str;
112:            }
113:
114:            public void pageUp() {
115:                int currentScreen = ams.getCurrentScreen();
116:
117:                if (currentScreen == INSTALL_APPS_LIST_SCREEN) {
118:                    // Determine if there is possibly more icons to display
119:                    // beyond this page
120:                    if (installAppsListScreenPageNumber > 0) {
121:                        installAppsListScreenPageNumber--;
122:                        showInstallAppListScreen();
123:                    }
124:                } else if (currentScreen == REMOVE_APPS_LIST_SCREEN) {
125:                    // Determine if there is possibly more icons to display
126:                    // beyond this page
127:                    if (removeAppsListScreenPageNumber > 0) {
128:                        removeAppsListScreenPageNumber--;
129:                        showRemoveAppListScreen();
130:                    }
131:                }
132:            }
133:
134:            public void pageDown() {
135:                int currentScreen = ams.getCurrentScreen();
136:
137:                if (currentScreen == INSTALL_APPS_LIST_SCREEN) {
138:                    // Find out number of total screen pages
139:                    int totalInstallAppsListScreenPages = ams
140:                            .getTotalScreenPages(
141:                                    installAppsListScreenButtons.length,
142:                                    APPS_LIST_SCREEN_ROWS
143:                                            * APPS_LIST_SCREEN_COLUMNS);
144:
145:                    // Don't scroll beyond the last page
146:                    if (installAppsListScreenPageNumber < (totalInstallAppsListScreenPages - 1)) {
147:                        installAppsListScreenPageNumber++;
148:                        showInstallAppListScreen();
149:                    }
150:                } else if (currentScreen == REMOVE_APPS_LIST_SCREEN) {
151:                    // Find out number of total screen pages
152:                    int totalRemoveAppsListScreenPages = ams
153:                            .getTotalScreenPages(
154:                                    removeAppsListScreenButtons.length,
155:                                    ams.SCREEN_DISPLAY_ICONS);
156:
157:                    // Don't scroll beyond the last page
158:                    if (removeAppsListScreenPageNumber < (totalRemoveAppsListScreenPages - 1)) {
159:                        removeAppsListScreenPageNumber++;
160:                        showRemoveAppListScreen();
161:                    }
162:                }
163:            }
164:
165:            /****************************** DISCOVERY ****************************/
166:
167:            private void discover() {
168:                HashMap applist = new OTADiscovery().discover(provisionURL);
169:
170:                downloadURIs = new String[applist.size()];
171:                downloadNames = new String[applist.size()];
172:
173:                int i = 0;
174:                for (Iterator e = applist.keySet().iterator(); e.hasNext();) {
175:                    String s = (String) e.next();
176:                    downloadURIs[i] = s;
177:                    downloadNames[i] = (String) applist.get(s);
178:                    i++;
179:                }
180:            }
181:
182:            class DiscoveryInstallAllActionListener implements  ActionListener {
183:                /* Because this actionPeformed() will be run within the AWT thread,
184:                 * we need to run the following in a different thread as it is
185:                 * not a good idea to draw within the AWT thread.
186:                 */
187:                public void actionPerformed(ActionEvent e) {
188:                    new Thread() {
189:                        public void run() {
190:                            discover();
191:                            showInstallationStatusScreen();
192:                            for (int i = 0; i < downloadNames.length; i++) {
193:                                try {
194:                                    installationStatusScreen.drawStatusString(
195:                                            "Attemping to install: ",
196:                                            downloadNames[i], "INSTALLING");
197:                                    Thread.sleep(100);
198:                                    JUMPContent content[] = tool.doInstall(
199:                                            downloadNames[i], downloadURIs[i]);
200:                                    if (content == null || content.length == 0) {
201:                                        installationStatusScreen
202:                                                .drawStatusString(
203:                                                        "Completed install: ",
204:                                                        downloadNames[i],
205:                                                        "FAILED");
206:                                    } else {
207:                                        installationStatusScreen
208:                                                .drawStatusString(
209:                                                        "Completed install: ",
210:                                                        downloadNames[i],
211:                                                        "SUCCESS");
212:                                    }
213:                                    Thread.sleep(100);
214:                                } catch (InterruptedException ex) {
215:                                    ex.printStackTrace();
216:                                }
217:                            }
218:                            installationStatusScreen.drawStatusDone(
219:                                    "Install completed.",
220:                                    new ShowInstallScreenActionListener(),
221:                                    new ApplicationsScreenActionListener());
222:                            try {
223:                                Thread.sleep(100);
224:                            } catch (Exception e) {
225:                                e.printStackTrace();
226:                            }
227:                            ams.refreshApplicationsScreen();
228:                        }
229:                    }.start();
230:                }
231:            }
232:
233:            class DiscoveryInstall1ActionListener implements  ActionListener {
234:                public void actionPerformed(ActionEvent e) {
235:                    discover();
236:                    showInstallAppListScreen();
237:                }
238:            }
239:
240:            /****************************** STATUS SCREEN ****************************/
241:
242:            private void showInstallationStatusScreen() {
243:                ams.setCurrentScreen(STATUS_SCREEN);
244:                ams.showScreen(createInstallationStatusScreen());
245:            }
246:
247:            private Container createInstallationStatusScreen() {
248:                installationStatusScreen = new InstallationStatusScreen();
249:                return installationStatusScreen;
250:            }
251:
252:            /*
253:             * This is the status screen seen during installation and removal
254:             */
255:            class InstallationStatusScreen extends Container {
256:                static final int START_X = 5;
257:                static final int START_Y = 5;
258:                int currentX = 0;
259:                int currentY = 0;
260:                String label = null;
261:                String appName = null;
262:                String status = null;
263:                boolean clearFlag = false;
264:                boolean done = false;
265:                Container buttonContainer = null;
266:                Container textContainer = null;
267:                final Color darkGreen = new Color(72, 142, 87);
268:
269:                public InstallationStatusScreen() {
270:                    currentX = START_X;
271:                    currentY = START_Y;
272:                    clearFlag = true;
273:                    removeAll();
274:                    setLayout(new BorderLayout());
275:
276:                    buttonContainer = new Container() {
277:                        public Dimension getPreferredSize() {
278:                            return new Dimension(240, 50);
279:                        }
280:                    };
281:                    buttonContainer.setLayout(new GridLayout(1, 2));
282:
283:                    textContainer = new Container() {
284:                        public void paint(Graphics g) {
285:                            Dimension d = getSize();
286:                            g.setColor(STATUS_SCREEN_COLOR);
287:                            if (clearFlag) {
288:                                g.fillRect(0, 0, d.width, d.height);
289:                                g.setColor(Color.black);
290:                                g.fillRect(0, 0, d.width, d.height / 4);
291:                                g.setColor(Color.white);
292:                                g.setFont(HEADER_FONT);
293:                                FontMetrics fm = getFontMetrics(HEADER_FONT);
294:                                int fheight = (int) fm.getHeight();
295:                                g.drawString("STATUS WINDOW", 5,
296:                                        ((d.height / 4) / 2) + (fheight / 2));
297:                            }
298:                            g.setColor(Color.black);
299:                            g.setFont(new Font("Helvetica", Font.PLAIN, 20));
300:                            if (!done) {
301:                                if (label != null) {
302:                                    g.drawString(label, 5, 120);
303:                                }
304:                                g.setColor(BUTTON_BLUE_COLOR);
305:                                if (appName != null) {
306:                                    g.drawString(appName, 20, 150);
307:                                } else {
308:                                    g.drawString("<untitled>", 20, 150);
309:                                }
310:                                if (status != null) {
311:                                    g.setColor(darkGreen);
312:                                    g.drawString("Status: " + status, 5, 180);
313:                                } else {
314:                                    g.setColor(Color.red);
315:                                    g.drawString("Status: UNKNOWN", 5, 180);
316:                                }
317:                            } else {
318:                                if (label != null) {
319:                                    g.drawString(label, 5, 80);
320:                                }
321:                            }
322:                        }
323:
324:                        public void update(Graphics g) {
325:                            paint(g);
326:                        }
327:                    };
328:                    add(textContainer, BorderLayout.CENTER);
329:                }
330:
331:                private void drawStatusDone(String label,
332:                        ActionListener backAction, ActionListener okAction) {
333:                    this .label = label;
334:                    buttonContainer.add(createButton("Back", backAction));
335:                    buttonContainer.add(createButton("Done", okAction));
336:                    add(buttonContainer, BorderLayout.SOUTH);
337:                    done = true;
338:                    validate();
339:                    repaint();
340:                }
341:
342:                private SimpleBasisAMSImageButton createButton(String label,
343:                        ActionListener action) {
344:                    SimpleBasisAMSImageButton button = new SimpleBasisAMSImageButton();
345:                    if (button == null) {
346:                        return null;
347:                    }
348:                    button.addActionListener(action);
349:                    button.setEnabled(true);
350:                    button.setForeground(BUTTON_BLUE_COLOR);
351:                    button.setTextShadow(true);
352:                    button.setPaintBorders(true);
353:                    button.setLabel(label);
354:                    return button;
355:                }
356:
357:                synchronized public void drawStatusString(String label,
358:                        String appName, String status) {
359:                    this .label = label;
360:                    this .appName = appName;
361:                    this .status = status;
362:                    done = false;
363:                    repaint();
364:                }
365:
366:            }
367:
368:            /****************************** INSTALL SCREEN ****************************/
369:
370:            public void showInstallScreen() {
371:                ams.showScreen(createInstallScreen());
372:                ams.setCurrentScreen(INSTALL_SCREEN);
373:            }
374:
375:            Container createInstallScreen() {
376:                Container showURLContainer = new InstallScreen();
377:                return showURLContainer;
378:            }
379:
380:            class ShowInstallScreenActionListener implements  ActionListener {
381:                public void actionPerformed(ActionEvent e) {
382:                    showInstallScreen();
383:                }
384:            }
385:
386:            class ApplicationsScreenActionListener implements  ActionListener {
387:                public void actionPerformed(ActionEvent e) {
388:                    ams.doApplicationsScreen();
389:                }
390:            }
391:
392:            class ShowInstallApplistScreenActionListener implements 
393:                    ActionListener {
394:                public void actionPerformed(ActionEvent e) {
395:                    showInstallAppListScreen();
396:                }
397:            }
398:
399:            /*
400:             * This is the screen the user sees when selecting the Install command button
401:             */
402:            class InstallScreen extends Container {
403:                private static final String message1 = "Choose All to install all apps.";
404:                private static final String message2 = "Choose One to install from a list of apps.";
405:                private static final String message3 = "Choose Cancel to exit without installing.";
406:
407:                public InstallScreen() {
408:
409:                    setLayout(new BorderLayout());
410:                    Container buttonContainer = new Container();
411:                    if (provisionURL != null) {
412:                        buttonContainer.setLayout(new GridLayout(1, 3));
413:                        buttonContainer.add(createButton("All",
414:                                new DiscoveryInstallAllActionListener()));
415:                        buttonContainer.add(createButton("One",
416:                                new DiscoveryInstall1ActionListener()));
417:                        buttonContainer.add(createButton("Cancel",
418:                                new ApplicationsScreenActionListener()));
419:                    }
420:
421:                    Container textContainer = new Container() {
422:                        public void paint(Graphics g) {
423:                            super .paint(g);
424:                            Dimension d = getSize();
425:                            g.setColor(INSTALL_SCREEN_COLOR);
426:                            g.fillRect(0, 0, d.width, d.height);
427:                            g.setColor(Color.black);
428:                            g.fillRect(0, 0, d.width, d.height / 4);
429:                            g.setColor(Color.white);
430:                            g.setFont(HEADER_FONT);
431:                            FontMetrics fm = getFontMetrics(HEADER_FONT);
432:                            int fheight = (int) fm.getHeight();
433:                            g.drawString("Install Applications", 5,
434:                                    ((d.height / 4) / 2) + (fheight / 2));
435:                            g.setColor(Color.black);
436:                            g.setFont(new Font("Helvetica", Font.PLAIN, 20));
437:                            g.drawString("Discover URL:", 5, 80);
438:                            g.setFont(new Font("Monospaced", Font.PLAIN, 12));
439:                            if (provisionURL != null) {
440:                                g.drawString(provisionURL, 5, 100);
441:                                g
442:                                        .setFont(new Font("Helvetica",
443:                                                Font.PLAIN, 12));
444:                                g.drawString(message1, 5, 140);
445:                                g.drawString(message2, 5, 160);
446:                                g.drawString(message3, 5, 180);
447:                            } else {
448:                                g.drawString("No Provisioning URL provided.",
449:                                        5, 100);
450:                                g
451:                                        .drawString(
452:                                                "The property jump.installer.provisionURL",
453:                                                5, 140);
454:                                g
455:                                        .drawString(
456:                                                "must be provided to the JUMP executive",
457:                                                5, 160);
458:                                g
459:                                        .drawString(
460:                                                "with a valid provisioning server URL.",
461:                                                5, 180);
462:                            }
463:
464:                        }
465:                    };
466:                    textContainer.setBackground(INSTALL_SCREEN_COLOR);
467:                    add(textContainer, BorderLayout.CENTER);
468:                    add(buttonContainer, BorderLayout.SOUTH);
469:                }
470:
471:                private SimpleBasisAMSImageButton createButton(String label,
472:                        ActionListener action) {
473:                    SimpleBasisAMSImageButton button = new SimpleBasisAMSImageButton();
474:                    if (button == null) {
475:                        return null;
476:                    }
477:                    button.addActionListener(action);
478:                    button.setEnabled(true);
479:                    button.setForeground(BUTTON_BLUE_COLOR);
480:                    button.setTextShadow(true);
481:                    button.setPaintBorders(true);
482:                    button.setLabel(label);
483:                    return button;
484:                }
485:            }
486:
487:            private void showInstallAppListScreen() {
488:                Container installAppsListScreen = createInstallAppsListScreen();
489:                ams.showScreen(installAppsListScreen);
490:                ams.setCurrentScreen(INSTALL_APPS_LIST_SCREEN);
491:            }
492:
493:            private SimpleBasisAMSImageButton installAppsListScreenButtons[] = null;
494:
495:            Container createInstallAppsListScreen() {
496:                Container appsListScreen = new Container();
497:                appsListScreen.setLayout(new GridLayout(APPS_LIST_SCREEN_ROWS,
498:                        APPS_LIST_SCREEN_COLUMNS));
499:                installAppsListScreenButtons = new SimpleBasisAMSImageButton[downloadNames.length];
500:                for (int i = 0; i < downloadNames.length; i++) {
501:                    installAppsListScreenButtons[i] = ams.createScreenButton(
502:                            downloadNames[i], new InstallOneActionListener(i),
503:                            BUTTON_YELLOW_COLOR);
504:                }
505:                int firstPositionIndex = installAppsListScreenPageNumber
506:                        * APPS_LIST_SCREEN_NUM_ENTRIES;
507:                for (int i = firstPositionIndex; i < (installAppsListScreenPageNumber
508:                        * APPS_LIST_SCREEN_NUM_ENTRIES + APPS_LIST_SCREEN_NUM_ENTRIES); i++) {
509:                    if (i < installAppsListScreenButtons.length) {
510:                        appsListScreen.add(installAppsListScreenButtons[i]);
511:                    } else {
512:                        appsListScreen.add(ams.createScreenButton(null,
513:                                BUTTON_YELLOW_COLOR));
514:                    }
515:                }
516:                return appsListScreen;
517:            }
518:
519:            class InstallOneActionListener implements  ActionListener {
520:                int index;
521:
522:                public InstallOneActionListener(int i) {
523:                    this .index = i;
524:                }
525:
526:                public void actionPerformed(ActionEvent e) {
527:                    new Thread() {
528:                        public void run() {
529:                            try {
530:                                showInstallationStatusScreen();
531:                                installationStatusScreen.drawStatusString(
532:                                        "Attempting to install: ",
533:                                        downloadNames[index], "INSTALLING");
534:                                Thread.sleep(100);
535:                                JUMPContent content[] = tool.doInstall(
536:                                        downloadNames[index],
537:                                        downloadURIs[index]);
538:                                if (content == null || content.length == 0) {
539:                                    installationStatusScreen.drawStatusString(
540:                                            "Installing Application: ",
541:                                            downloadNames[index],
542:                                            "PROCESSING...");
543:                                } else {
544:                                    installationStatusScreen.drawStatusString(
545:                                            "Installing Application: ",
546:                                            downloadNames[index], "DONE");
547:                                }
548:                                Thread.sleep(100);
549:                            } catch (InterruptedException ex) {
550:                                ex.printStackTrace();
551:                            }
552:                            installationStatusScreen
553:                                    .drawStatusDone(
554:                                            "Finished installing: "
555:                                                    + downloadNames[index],
556:                                            new ShowInstallApplistScreenActionListener(),
557:                                            new ApplicationsScreenActionListener());
558:                            try {
559:                                Thread.sleep(100);
560:                            } catch (Exception e) {
561:                                e.printStackTrace();
562:                            }
563:                            ams.refreshApplicationsScreen();
564:                        }
565:                    }.start();
566:                }
567:            }
568:
569:            /****************************** REMOVE SCREEN ****************************/
570:
571:            public void showRemoveScreen() {
572:                ams.showScreen(createRemoveScreen());
573:                ams.setCurrentScreen(REMOVE_SCREEN);
574:            }
575:
576:            Container createRemoveScreen() {
577:                Container removeContainer = new RemoveScreen();
578:                return removeContainer;
579:            }
580:
581:            /*
582:             * This the screen the user sees after selecting the Remove command button
583:             */
584:            class RemoveScreen extends Container {
585:
586:                public RemoveScreen() {
587:
588:                    setLayout(new BorderLayout());
589:                    Container buttonContainer = new Container();
590:                    buttonContainer.setLayout(new GridLayout(1, 3));
591:                    buttonContainer.add(createButton("All",
592:                            new RemoveAllActionListener()));
593:                    buttonContainer.add(createButton("One",
594:                            new Remove1ScreenActionListener()));
595:                    buttonContainer.add(createButton("Cancel",
596:                            new ApplicationsScreenActionListener()));
597:
598:                    Container textContainer = new Container() {
599:                        public void paint(Graphics g) {
600:                            super .paint(g);
601:                            Dimension d = getSize();
602:                            g.setColor(REMOVE_SCREEN_COLOR);
603:                            g.fillRect(0, 0, d.width, d.height);
604:                            g.setColor(Color.black);
605:                            g.fillRect(0, 0, d.width, d.height / 4);
606:                            g.setColor(Color.white);
607:                            g.setFont(HEADER_FONT);
608:                            FontMetrics fm = getFontMetrics(HEADER_FONT);
609:                            int fheight = (int) fm.getHeight();
610:                            g.drawString("Remove Applications", 5,
611:                                    ((d.height / 4) / 2) + (fheight / 2));
612:                            g.setColor(Color.black);
613:                            g.setFont(new Font("Helvetica", Font.PLAIN, 12));
614:                            g.drawString("Remove Applications Screen:", 5, 110);
615:                            g.drawString("Remove all, Remove 1, or Cancel?", 5,
616:                                    130);
617:                        }
618:                    };
619:                    textContainer.setBackground(REMOVE_SCREEN_COLOR);
620:                    add(textContainer, BorderLayout.CENTER);
621:                    add(buttonContainer, BorderLayout.SOUTH);
622:                }
623:
624:                private SimpleBasisAMSImageButton createButton(String label,
625:                        ActionListener action) {
626:                    SimpleBasisAMSImageButton button = new SimpleBasisAMSImageButton();
627:                    if (button == null) {
628:                        return null;
629:                    }
630:                    button.addActionListener(action);
631:                    button.setEnabled(true);
632:                    button.setForeground(BUTTON_BLUE_COLOR);
633:                    button.setTextShadow(true);
634:                    button.setPaintBorders(true);
635:                    button.setLabel(label);
636:                    return button;
637:                }
638:            }
639:
640:            class Remove1ScreenActionListener implements  ActionListener {
641:                public void actionPerformed(ActionEvent e) {
642:                    showRemoveAppListScreen();
643:                }
644:            }
645:
646:            class ShowRemoveApplistScreenActionListener implements 
647:                    ActionListener {
648:                public void actionPerformed(ActionEvent e) {
649:                    showRemoveAppListScreen();
650:                }
651:            }
652:
653:            class ShowRemoveScreenActionListener implements  ActionListener {
654:                public void actionPerformed(ActionEvent e) {
655:                    showRemoveScreen();
656:                }
657:            }
658:
659:            class RemoveOneActionListener implements  ActionListener {
660:                JUMPApplication app = null;
661:
662:                public RemoveOneActionListener(JUMPApplication app) {
663:                    this .app = app;
664:                }
665:
666:                /* Because this actionPeformed() will be run within the AWT thread,
667:                 * we need to run the following in a different thread as it is
668:                 * not a good idea to draw within the AWT thread.
669:                 */
670:                public void actionPerformed(ActionEvent e) {
671:                    new Thread() {
672:                        public void run() {
673:                            try {
674:                                showInstallationStatusScreen();
675:                                installationStatusScreen.drawStatusString(
676:                                        "Removing Application: ", app
677:                                                .getTitle(), "PROCESSING...");
678:                                Thread.sleep(100);
679:                                if (!ams.isRunningApp(app)) {
680:                                    tool.doUninstall(app);
681:                                    installationStatusScreen.drawStatusString(
682:                                            "Removing Application: ", app
683:                                                    .getTitle(), "DONE");
684:                                } else {
685:                                    installationStatusScreen.drawStatusString(
686:                                            "Removing Application: ", app
687:                                                    .getTitle(),
688:                                            "ERROR - application running");
689:                                }
690:                                Thread.sleep(100);
691:                            } catch (InterruptedException ex) {
692:                                ex.printStackTrace();
693:                            }
694:                            installationStatusScreen
695:                                    .drawStatusDone(
696:                                            "Finished removing application: "
697:                                                    + app.getTitle(),
698:                                            new ShowRemoveApplistScreenActionListener(),
699:                                            new ApplicationsScreenActionListener());
700:                            try {
701:                                Thread.sleep(100);
702:                            } catch (Exception e) {
703:                                e.printStackTrace();
704:                            }
705:                            ams.refreshApplicationsScreen();
706:                        }
707:                    }.start();
708:                }
709:            }
710:
711:            class RemoveAllActionListener implements  ActionListener {
712:                public void actionPerformed(ActionEvent e) {
713:                    /* Because this actionPeformed() will be run within the AWT thread,
714:                     * we need to run the following in a different thread as it is
715:                     * not a good idea to draw within the AWT thread.
716:                     */
717:                    new Thread() {
718:                        public void run() {
719:                            try {
720:                                showInstallationStatusScreen();
721:                                JUMPInstallerModule installers[] = JUMPInstallerModuleFactory
722:                                        .getInstance().getAllInstallers();
723:                                for (int i = 0; i < installers.length; i++) {
724:                                    JUMPContent[] content = installers[i]
725:                                            .getInstalled();
726:                                    while (content != null
727:                                            && content.length > 0) {
728:                                        if (content[0] != null) {
729:                                            JUMPApplication app = (JUMPApplication) content[0];
730:                                            installationStatusScreen
731:                                                    .drawStatusString(
732:                                                            "Removing Application: ",
733:                                                            app.getTitle(),
734:                                                            "PROCESSING...");
735:                                            Thread.sleep(100);
736:                                            if (!ams.isRunningApp(app)) {
737:                                                tool.doUninstall(app);
738:                                                installationStatusScreen
739:                                                        .drawStatusString(
740:                                                                "Removing Application: ",
741:                                                                app.getTitle(),
742:                                                                "DONE");
743:                                            } else {
744:                                                installationStatusScreen
745:                                                        .drawStatusString(
746:                                                                "Removing Application: ",
747:                                                                app.getTitle(),
748:                                                                "ERROR - application running");
749:                                            }
750:                                            Thread.sleep(100);
751:                                        }
752:                                        content = installers[i].getInstalled();
753:                                    }
754:                                }
755:                            } catch (InterruptedException ex) {
756:                                ex.printStackTrace();
757:                            }
758:                            installationStatusScreen.drawStatusDone(
759:                                    "Remove completed.",
760:                                    new ShowRemoveScreenActionListener(),
761:                                    new ApplicationsScreenActionListener());
762:                            try {
763:                                Thread.sleep(100);
764:                            } catch (Exception e) {
765:                                e.printStackTrace();
766:                            }
767:                            ams.refreshApplicationsScreen();
768:                        }
769:                    }.start();
770:                }
771:            }
772:
773:            private void showRemoveAppListScreen() {
774:                Container removeAppsListScreen = createRemoveAppsListScreen();
775:                ams.showScreen(removeAppsListScreen);
776:                ams.setCurrentScreen(REMOVE_APPS_LIST_SCREEN);
777:            }
778:
779:            private SimpleBasisAMSImageButton removeAppsListScreenButtons[] = null;
780:
781:            Container createRemoveAppsListScreen() {
782:                Container removeAppsListScreen = new Container();
783:                removeAppsListScreen.setLayout(new GridLayout(ams.SCREEN_ROWS,
784:                        ams.SCREEN_COLUMNS));
785:
786:                JUMPInstallerModule installers[] = JUMPInstallerModuleFactory
787:                        .getInstance().getAllInstallers();
788:                Vector allApps = new Vector();
789:                for (int i = 0; i < installers.length; i++) {
790:                    JUMPContent[] apps = installers[i].getInstalled();
791:                    for (int j = 0; j < apps.length; j++) {
792:                        allApps.add(apps[j]);
793:                    }
794:                }
795:                JUMPContent content[] = (JUMPContent[]) allApps
796:                        .toArray(new JUMPContent[] {});
797:                removeAppsListScreenButtons = new SimpleBasisAMSImageButton[content.length];
798:                for (int i = 0; i < content.length; i++) {
799:                    JUMPApplication app = (JUMPApplication) content[i];
800:                    removeAppsListScreenButtons[i] = ams.createScreenButton(
801:                            app, new RemoveOneActionListener(app),
802:                            BUTTON_RED_COLOR);
803:                }
804:                int firstPositionIndex = removeAppsListScreenPageNumber
805:                        * ams.SCREEN_DISPLAY_ICONS;
806:                for (int i = firstPositionIndex; i < (removeAppsListScreenPageNumber
807:                        * ams.SCREEN_DISPLAY_ICONS + ams.SCREEN_DISPLAY_ICONS); i++) {
808:                    if (i < removeAppsListScreenButtons.length) {
809:                        removeAppsListScreen
810:                                .add(removeAppsListScreenButtons[i]);
811:                    } else {
812:                        removeAppsListScreen.add(ams.createScreenButton(null,
813:                                BUTTON_RED_COLOR));
814:                    }
815:                }
816:                return removeAppsListScreen;
817:            }
818:
819:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.