Source Code Cross Referenced for UpdaterFrame.java in  » IDE-Netbeans » autoupdate » org » netbeans » updater » 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 » IDE Netbeans » autoupdate » org.netbeans.updater 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.updater;
043:
044:        import java.awt.*;
045:        import java.util.Locale;
046:        import javax.swing.*;
047:        import java.io.*;
048:        import java.beans.PropertyChangeListener;
049:        import java.net.URL;
050:        import java.util.Collection;
051:
052:        import javax.swing.border.LineBorder;
053:
054:        /**
055:         *
056:         * @author  phrebejk, akemr, Jiri Rechtacek
057:         * @version
058:         */
059:        public class UpdaterFrame extends javax.swing.JPanel {
060:
061:            /** Operating system is Windows x */
062:            public static final int OS_WIN = 1;
063:            /** Operating system is Solaris. */
064:            public static final int OS_SOLARIS = 8;
065:            /** Operating system is Linux. */
066:            public static final int OS_LINUX = 16;
067:            /** Operating system is OS/2. */
068:            public static final int OS_OS2 = 1024;
069:            /** Operating system is unknown. */
070:            public static final int OS_OTHER = 65536;
071:
072:            private static final String SPLASH_PATH = "org/netbeans/updater/resources/updatersplash"; // NOI18N
073:
074:            private static UpdaterFrame panel;
075:
076:            private static boolean bigBounds = false;
077:
078:            private static boolean fromIDE = false;
079:
080:            private static Window splashWindow;
081:
082:            /** For external running Updater without GUI */
083:            private static boolean noSplash = false;
084:
085:            public static final String FINISHED = "FINISHED"; // NOI18N
086:            public static final String RUNNING = "RUNNING"; // NOI18N
087:
088:            /** Creates new form UpdaterFrame */
089:            public UpdaterFrame() {
090:                initComponents();
091:
092:                if (addBorder())
093:                    setBorder(new LineBorder(
094:                            stringToColor("UpdaterFrame.LineBorder.Color",
095:                                    new Color(0, 0, 0))));
096:
097:                loadSplash();
098:            }
099:
100:            static final void center(Window c) {
101:                c.pack();
102:
103:                GraphicsConfiguration gconf = GraphicsEnvironment
104:                        .getLocalGraphicsEnvironment().getDefaultScreenDevice()
105:                        .getDefaultConfiguration();
106:                Rectangle bounds = gconf.getBounds();
107:                Dimension dialogSize = c.getSize();
108:
109:                c.setLocation(bounds.x + (bounds.width - dialogSize.width) / 2,
110:                        bounds.y + (bounds.height - dialogSize.height) / 2);
111:            }
112:
113:            static String getMainWindowTitle() {
114:                return Localization.getBrandedString("UpdaterFrame.Form.title");
115:            }
116:
117:            /** This method is called from within the constructor to
118:             * initialize the form.
119:             * WARNING: Do NOT modify this code. The content of this method is
120:             * always regenerated by the FormEditor.
121:             */
122:            // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
123:            private void initComponents() {
124:                java.awt.GridBagConstraints gridBagConstraints;
125:
126:                jLabel3 = new javax.swing.JLabel();
127:                jTextArea1 = new javax.swing.JTextArea();
128:                textLabel = new javax.swing.JLabel();
129:                progressBar = new javax.swing.JProgressBar();
130:
131:                setLayout(new java.awt.GridBagLayout());
132:
133:                setBackground(stringToColor("UpdaterFrame.Background",
134:                        new Color(6, 4, 100)));
135:                setBorder(new javax.swing.border.EmptyBorder(
136:                        new java.awt.Insets(0, 0, 0, 0)));
137:                gridBagConstraints = new java.awt.GridBagConstraints();
138:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
139:                add(jLabel3, gridBagConstraints);
140:
141:                jTextArea1
142:                        .setBackground(stringToColor(
143:                                "UpdaterFrame.TextBackground", new Color(213,
144:                                        204, 187)));
145:                jTextArea1.setEditable(false);
146:                jTextArea1.setForeground(stringToColor(
147:                        "UpdaterFrame.TextForeground", java.awt.Color.white));
148:                jTextArea1.setText(Localization
149:                        .getBrandedString("UpdaterFrame.jTextArea1.text"));
150:                jTextArea1
151:                        .setDisabledTextColor(stringToColor(
152:                                "UpdaterFrame.DisabledTextColor",
153:                                java.awt.Color.white));
154:                jTextArea1.setOpaque(false);
155:                gridBagConstraints = new java.awt.GridBagConstraints();
156:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
157:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
158:                gridBagConstraints.weightx = 1.0;
159:                gridBagConstraints.weighty = 1.0;
160:                gridBagConstraints.insets = new java.awt.Insets(8, 14, 0, 14);
161:                add(jTextArea1, gridBagConstraints);
162:
163:                textLabel.setFont(new java.awt.Font("Dialog", 1, 11));
164:                textLabel.setForeground(stringToColor(
165:                        "UpdaterFrame.TextForeground", java.awt.Color.white));
166:                textLabel.setText(Localization
167:                        .getBrandedString("UpdaterFrame.textLabel.text"));
168:                gridBagConstraints = new java.awt.GridBagConstraints();
169:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
170:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
171:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
172:                gridBagConstraints.insets = new java.awt.Insets(8, 14, 8, 14);
173:                add(textLabel, gridBagConstraints);
174:
175:                progressBar.setPreferredSize(stringToDimension(
176:                        "UpdaterFrame.ProgressBar.PreferredSize",
177:                        new Dimension(300, 20)));
178:                progressBar.setRequestFocusEnabled(false);
179:                gridBagConstraints = new java.awt.GridBagConstraints();
180:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
181:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
182:                gridBagConstraints.weightx = 1.0;
183:                gridBagConstraints.insets = new java.awt.Insets(5, 14, 10, 14);
184:                add(progressBar, gridBagConstraints);
185:
186:            }
187:
188:            // </editor-fold>//GEN-END:initComponents
189:
190:            @Override
191:            protected void paintComponent(Graphics g) {
192:                if (isGradient()) {
193:                    Color outerColor = stringToColor("UpdaterFrame.outerColor",
194:                            new Color(230, 242, 234));
195:                    Color centerColor = stringToColor(
196:                            "UpdaterFrame.centerColor", Color.WHITE);
197:                    int w = getWidth();
198:                    int h = getHeight();
199:
200:                    // paint the background color.
201:                    Graphics2D g2d = (Graphics2D) g;
202:                    g2d.setPaint(new GradientPaint(0, 0, outerColor, w / 2, 0,
203:                            centerColor, true));
204:                    g2d.fillRect(0, 0, w, h);
205:                } else {
206:                    super .paintComponent(g);
207:                }
208:            }
209:
210:            private static void showSplash() {
211:
212:                if ((getOperatingSystem() == OS_WIN)
213:                        || (getOperatingSystem() == OS_SOLARIS)
214:                        || (getOperatingSystem() == OS_OS2)
215:                        || (getOperatingSystem() == OS_LINUX)) {
216:                    // only some systems supports non-frame windows
217:                    splashWindow = new SplashWindow();
218:                } else {
219:                    splashWindow = (Window) new SplashFrame();
220:                }
221:
222:                // show splash
223:                javax.swing.SwingUtilities.invokeLater(new Runnable() {
224:                    public void run() {
225:                        splashWindow.setVisible(true);
226:                        splashWindow.toFront();
227:                    }
228:                });
229:            }
230:
231:            static void disposeSplash() {
232:                if (splashWindow != null)
233:                    splashWindow.dispose();
234:            }
235:
236:            /**
237:             * @param args the command line arguments
238:             */
239:            public static void main(String args[]) {
240:                if (args.length > 0) {
241:                    cli(args);
242:                }
243:
244:                panel = new UpdaterFrame();
245:
246:                if (!noSplash) {
247:                    showSplash();
248:                }
249:
250:                new UpdaterDispatcher().run();
251:            }
252:
253:            public static Thread runFromIDE(Collection<File> files,
254:                    PropertyChangeListener listener, String brandingToken,
255:                    boolean showSplash) {
256:                noSplash = !showSplash;
257:                fromIDE = true;
258:                Localization.setBranding(brandingToken);
259:                panel = new UpdaterFrame();
260:                panel.addPropertyChangeListener(listener);
261:                if (!noSplash) {
262:                    showSplash();
263:                }
264:
265:                ModuleUpdater mu = new ModuleUpdater(files);
266:                mu.start();
267:                return mu;
268:            }
269:
270:            void unpackingIsRunning() {
271:                if (fromIDE) {
272:                    firePropertyChange(RUNNING, null, null);
273:                }
274:            }
275:
276:            void unpackingFinished() {
277:                runningFinished();
278:                /*
279:                ClassRunner runner = new ClassRunner(); 
280:                runner.start();
281:                 */
282:            }
283:
284:            void runningFinished() {
285:                if (fromIDE) {
286:                    firePropertyChange(FINISHED, null, null);
287:                    if (splashWindow != null)
288:                        splashWindow.dispose();
289:                } else
290:                    System.exit(0);
291:            }
292:
293:            /** Tells the Localization class whether we are running from IDE or not
294:             */
295:            boolean isFromIde() {
296:                return fromIDE;
297:            }
298:
299:            // Variables declaration - do not modify//GEN-BEGIN:variables
300:            private javax.swing.JLabel jLabel3;
301:            private javax.swing.JTextArea jTextArea1;
302:            private javax.swing.JProgressBar progressBar;
303:            private javax.swing.JLabel textLabel;
304:
305:            // End of variables declaration//GEN-END:variables
306:
307:            static void setLabel(final String text) {
308:
309:                if (noSplash)
310:                    return;
311:
312:                final javax.swing.JLabel label = panel.textLabel;
313:
314:                javax.swing.SwingUtilities.invokeLater(new Runnable() {
315:                    public void run() {
316:                        label.setText(text);
317:                    }
318:                });
319:
320:            }
321:
322:            static void setProgressRange(final long min, final long max) {
323:
324:                if (noSplash)
325:                    return;
326:
327:                bigBounds = max > 0xFFFF;
328:
329:                final javax.swing.JProgressBar progressBar = panel.progressBar;
330:                final boolean bb = bigBounds;
331:
332:                javax.swing.SwingUtilities.invokeLater(new Runnable() {
333:                    public void run() {
334:                        progressBar.setMinimum(bb ? (int) (min / 1024)
335:                                : (int) min);
336:                        progressBar.setMaximum(bb ? (int) (max / 1024)
337:                                : (int) max);
338:                    }
339:                });
340:
341:            }
342:
343:            static void setProgressValue(final long value) {
344:
345:                if (noSplash)
346:                    return;
347:
348:                final javax.swing.JProgressBar progressBar = panel.progressBar;
349:                final boolean bb = bigBounds;
350:
351:                javax.swing.SwingUtilities.invokeLater(new Runnable() {
352:                    public void run() {
353:                        progressBar.setValue(bb ? (int) (value / 1024)
354:                                : (int) value);
355:                    }
356:                });
357:            }
358:
359:            /** Get the operating system on which the IDE is running.
360:             * @return one of the <code>OS_*</code> constants (such as {@link #OS_WINNT})
361:             */
362:            public static final int getOperatingSystem() {
363:                int operatingSystem = -1;
364:                String osName = System.getProperty("os.name");
365:                if (osName != null && osName.startsWith("Windows")) // NOI18N
366:                    operatingSystem = OS_WIN;
367:                else if ("Solaris".equals(osName)) // NOI18N
368:                    operatingSystem = OS_SOLARIS;
369:                else if (osName.startsWith("SunOS")) // NOI18N
370:                    operatingSystem = OS_SOLARIS;
371:                else if ("Linux".equals(osName)) // NOI18N
372:                    operatingSystem = OS_LINUX;
373:                else if ("OS/2".equals(osName)) // NOI18N
374:                    operatingSystem = OS_OS2;
375:                else
376:                    operatingSystem = OS_OTHER;
377:                return operatingSystem;
378:            }
379:
380:            /** Getter for property fromIDE.
381:             * @return Value of property fromIDE.
382:             */
383:            static boolean isFromIDE() {
384:                return fromIDE;
385:            }
386:
387:            static UpdaterFrame getUpdaterFrame() {
388:                return panel;
389:            }
390:
391:            static private Color stringToColor(String key, Color defcolor) {
392:                try {
393:                    String str = Localization.getBrandedString(key + "_R"); // NOI18N
394:                    int re = Integer.parseInt(str);
395:
396:                    str = Localization.getBrandedString(key + "_G"); // NOI18N
397:                    int gr = Integer.parseInt(str);
398:
399:                    str = Localization.getBrandedString(key + "_B"); // NOI18N
400:                    int bl = Integer.parseInt(str);
401:
402:                    return new Color(re, gr, bl);
403:                } catch (Exception e) {
404:                    return defcolor;
405:                }
406:            }
407:
408:            static private Dimension stringToDimension(String key,
409:                    Dimension defaultSize) {
410:                try {
411:                    String str = Localization.getBrandedString(key + "_X"); // NOI18N
412:                    int x = Integer.parseInt(str);
413:
414:                    str = Localization.getBrandedString(key + "_Y"); // NOI18N
415:                    int y = Integer.parseInt(str);
416:
417:                    return new Dimension(x, y);
418:                } catch (Exception e) {
419:                    return defaultSize;
420:                }
421:            }
422:
423:            static private boolean addBorder() {
424:                return "true".equals(Localization
425:                        .getBrandedString("UpdaterFrame.hasBorder")); // NOI18N
426:            }
427:
428:            static private boolean isGradient() {
429:                return "true".equals(Localization
430:                        .getBrandedString("UpdaterFrame.isGradient")); // NOI18N
431:            }
432:
433:            private void loadSplash() {
434:                URL lookup = Localization.getBrandedResource(SPLASH_PATH,
435:                        ".gif"); // NOI18N
436:                if (lookup != null)
437:                    jLabel3.setIcon(new ImageIcon(lookup));
438:            }
439:
440:            static class SplashFrame extends JFrame {
441:
442:                /** Creates a new SplashFrame */
443:                public SplashFrame() {
444:                    super (getMainWindowTitle());
445:                    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
446:                    setCursor(java.awt.Cursor
447:                            .getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
448:                    // add splash component
449:                    getContentPane().add(panel);
450:                    center(this );
451:                }
452:
453:                @Override
454:                public java.awt.Dimension getPreferredSize() {
455:                    return stringToDimension(
456:                            "UpdaterFrame.Splash.PreferredSize", new Dimension(
457:                                    400, 280));
458:                }
459:            }
460:
461:            static class SplashWindow extends Window {
462:                /** Creates a new SplashWindow */
463:                public SplashWindow() {
464:                    super (new Frame());
465:                    // add splash component
466:                    setLayout(new java.awt.BorderLayout());
467:                    add(panel, java.awt.BorderLayout.CENTER);
468:                    center(this );
469:                }
470:
471:                @Override
472:                public java.awt.Dimension getPreferredSize() {
473:                    return stringToDimension(
474:                            "UpdaterFrame.Splash.PreferredSize", new Dimension(
475:                                    400, 280));
476:                }
477:            }
478:
479:            // copied from core/CLIOptions
480:
481:            private static boolean isOption(String value, String optionName) {
482:                if (value == null)
483:                    return false;
484:
485:                if (value.startsWith("--")) {
486:                    return value.substring(2).equals(optionName);
487:                } else if (value.startsWith("-")) {
488:                    return value.substring(1).equals(optionName);
489:                }
490:                return false;
491:            }
492:
493:            private static int cli(String[] args) {
494:                // let's go through the command line
495:                for (int i = 0; i < args.length; i++) {
496:                    if (args[i] == null) {
497:                        continue;
498:                    }
499:                    if (isOption(args[i], "nosplash")) { // NOI18N
500:                        UpdaterFrame.noSplash = true;
501:                    } else if (isOption(args[i], "locale")) { // NOI18N
502:                        args[i] = null;
503:                        String localeParam = args[++i];
504:                        String language;
505:                        String country = ""; // NOI18N
506:                        String variant = ""; // NOI18N
507:                        int index1 = localeParam.indexOf(":"); // NOI18N
508:                        if (index1 == -1)
509:                            language = localeParam;
510:                        else {
511:                            language = localeParam.substring(0, index1);
512:                            int index2 = localeParam.indexOf(":", index1 + 1); // NOI18N
513:                            if (index2 != -1) {
514:                                country = localeParam.substring(index1 + 1,
515:                                        index2);
516:                                variant = localeParam.substring(index2 + 1);
517:                            } else
518:                                country = localeParam.substring(index1 + 1);
519:                        }
520:                        Locale
521:                                .setDefault(new Locale(language, country,
522:                                        variant));
523:                    } else if (isOption(args[i], "branding")) { // NOI18N
524:                        args[i] = null;
525:                        if (++i == args.length) {
526:                            System.err
527:                                    .println("Option --branding requires one argument.");
528:                            return 2;
529:                        }
530:                        String branding = args[i];
531:                        if (branding.equals("-"))
532:                            branding = null; // NOI18N
533:                        try {
534:                            Localization.setBranding(branding);
535:                        } catch (IllegalArgumentException iae) {
536:                            iae.printStackTrace();
537:                            return 1;
538:                        }
539:                    }
540:                }
541:
542:                return 0;
543:            }
544:
545:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.