1 19 20 package org.netbeans.bluej.welcome; 21 22 import java.awt.Component ; 23 import java.awt.Cursor ; 24 import java.net.MalformedURLException ; 25 import java.net.URL ; 26 import javax.swing.JComponent ; 27 import javax.swing.JFrame ; 28 import javax.swing.SwingUtilities ; 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 38 44 final class BusinessLogic { 45 46 private static final int THREE_SECONDS = 3 * 1000; 47 48 52 static void perform(int opcode, JComponent client) { 53 switch (opcode) { 54 case 1: 55 showURL("HTML_NEWS", client); break; 57 case 2: 58 showURL("HTML_QUICKSTART", client); break; 60 case 3: 61 showURL("HTML_modules", client); break; 63 case 4: 64 showURL("HTML_Collab", client); break; 66 case 5: 67 showURL("HTML_Profiler", client); break; 69 case 6: 70 showURL("HTML_J2ME", client); break; 72 case 101: 73 showURL("HTML_JAVA", client); break; 75 case 102: 76 showURL("HTML_SUN", client); break; 78 case 103: 79 showURL("HTML_NB", client); break; 81 default: 82 assert false : "Unexpected operation code: " + opcode; } 84 } 85 86 private static void showURL(String bundleKey, JComponent client) { 87 try { 88 start(client); 89 URL url = new URL (NbBundle.getMessage(BusinessLogic.class, bundleKey)); 90 if (url.getProtocol().equalsIgnoreCase("nbinst")) { url = externalizeURL(url); 92 } 93 HtmlBrowser.URLDisplayer.getDefault().showURL(url); 94 } catch (java.net.MalformedURLException ex) { 95 ErrorManager.getDefault().notify(ex); 96 } finally { 97 } 100 } 101 102 114 118 private static void start(final JComponent client) { 119 Component root = SwingUtilities.getRoot(client); 120 final Component glasspane = (root instanceof JFrame ) ? ((JFrame )root).getGlassPane() : null; 121 122 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 () { 129 public void run() { 130 done(client); 131 } 132 }, THREE_SECONDS); 133 } 134 135 138 private static void done(JComponent client) { 139 Component root = SwingUtilities.getRoot(client); 140 final Component glasspane = (root instanceof JFrame ) ? ((JFrame )root).getGlassPane() : null; 141 if (glasspane!=null) { 142 glasspane.setCursor(Cursor.getDefaultCursor()); 143 glasspane.setVisible(false); 144 } 145 } 146 147 private static URL externalizeURL(URL url) { 148 FileObject fo = URLMapper.findFileObject(url); 149 if (fo == null) { 150 try { 151 return new URL ("http://www.netbeans.org"); } catch (MalformedURLException ex) { 153 return null; 155 } 156 } else { 157 return URLMapper.findURL(fo,URLMapper.EXTERNAL); 158 } 159 } 160 161 } 162 | Popular Tags |