KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > bluej > welcome > BusinessLogic


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.bluej.welcome;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.Cursor JavaDoc;
24 import java.net.MalformedURLException JavaDoc;
25 import java.net.URL JavaDoc;
26 import javax.swing.JComponent JavaDoc;
27 import javax.swing.JFrame JavaDoc;
28 import javax.swing.SwingUtilities JavaDoc;
29 import org.openide.ErrorManager;
30 import org.openide.awt.HtmlBrowser;
31 import org.openide.filesystems.FileObject;
32 import org.openide.filesystems.URLMapper;
33 import org.openide.util.HelpCtx;
34 import org.openide.util.Lookup;
35 import org.openide.util.NbBundle;
36 //import org.netbeans.api.javahelp.Help;
37

38 /**
39  * Handles welcome screen buttons. It should be loaded
40  * into memory only if a button pressed saving few ms.
41  *
42  * @author Petr Kuzel
43  */

44 final class BusinessLogic {
45     
46     private static final int THREE_SECONDS = 3 * 1000;
47     
48     /**
49      *
50      * @param opcode 1-6 for button set. 101 top log, 102 bottom logo
51      */

52     static void perform(int opcode, JComponent JavaDoc client) {
53         switch (opcode) {
54             case 1:
55                 showURL("HTML_NEWS", client); // NOI18N
56
break;
57             case 2:
58                 showURL("HTML_QUICKSTART", client); // NOI18N
59
break;
60             case 3:
61                 showURL("HTML_modules", client); // NOI18N
62
break;
63             case 4:
64                 showURL("HTML_Collab", client); // NOI18N
65
break;
66             case 5:
67                 showURL("HTML_Profiler", client); // NOI18N
68
break;
69             case 6:
70                 showURL("HTML_J2ME", client); // NOI18N
71
break;
72             case 101:
73                 showURL("HTML_JAVA", client); // NOI18N
74
break;
75             case 102:
76                 showURL("HTML_SUN", client); // NOI18N
77
break;
78             case 103:
79                 showURL("HTML_NB", client); // NOI18N
80
break;
81             default:
82                 assert false : "Unexpected operation code: " + opcode; // NOI18N
83
}
84     }
85     
86     private static void showURL(String JavaDoc bundleKey, JComponent JavaDoc client) {
87         try {
88             start(client);
89             URL JavaDoc url = new URL JavaDoc(NbBundle.getMessage(BusinessLogic.class, bundleKey));
90             if (url.getProtocol().equalsIgnoreCase("nbinst")) { // NOI18N
91
url = externalizeURL(url);
92             }
93             HtmlBrowser.URLDisplayer.getDefault().showURL(url);
94         } catch (java.net.MalformedURLException JavaDoc ex) {
95             ErrorManager.getDefault().notify(ex);
96         } finally {
97             // waiting for #63987
98
// done(client);
99
}
100     }
101
102 // private static void showHelp(String id, JComponent client) {
103
// Help help = (Help) Lookup.getDefault().lookup(Help.class);
104
// if (help != null) {
105
// try {
106
// start(client);
107
// help.showHelp(new HelpCtx(id));
108
// } finally {
109
// done(client);
110
// }
111
// }
112
// }
113

114     /**
115      * Enables glass pane for max 3sec. It disallows
116      * user to select same slow action by accident two times.
117      */

118     private static void start(final JComponent JavaDoc client) {
119             Component JavaDoc root = SwingUtilities.getRoot(client);
120             final Component JavaDoc glasspane = (root instanceof JFrame JavaDoc) ? ((JFrame JavaDoc)root).getGlassPane() : null;
121             
122             // do the timeouting waiting cursor
123
if (glasspane != null) {
124                 glasspane.setVisible(true);
125                 glasspane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
126             }
127             
128             org.openide.util.RequestProcessor.getDefault().post(new Runnable JavaDoc() {
129                 public void run() {
130                     done(client);
131                 }
132             }, THREE_SECONDS);
133     }
134     
135     /**
136      * Hides the glass pane.
137      */

138     private static void done(JComponent JavaDoc client) {
139         Component JavaDoc root = SwingUtilities.getRoot(client);
140         final Component JavaDoc glasspane = (root instanceof JFrame JavaDoc) ? ((JFrame JavaDoc)root).getGlassPane() : null;
141         if (glasspane!=null) {
142             glasspane.setCursor(Cursor.getDefaultCursor());
143             glasspane.setVisible(false);
144         }
145     }
146     
147     private static URL JavaDoc externalizeURL(URL JavaDoc url) {
148         FileObject fo = URLMapper.findFileObject(url);
149         if (fo == null) {
150             try {
151                 return new URL JavaDoc("http://www.netbeans.org"); // NOI18N
152
} catch (MalformedURLException JavaDoc ex) {
153                 // ignore
154
return null;
155             }
156         } else {
157             return URLMapper.findURL(fo,URLMapper.EXTERNAL);
158         }
159     }
160     
161 }
162
Popular Tags