1 19 20 package org.netbeans.core; 21 22 import java.awt.EventQueue ; 23 import java.awt.Frame ; 24 import java.awt.Toolkit ; 25 import java.awt.event.ComponentAdapter ; 26 import java.awt.event.ComponentEvent ; 27 import java.io.IOException ; 28 import java.lang.reflect.Method ; 29 import java.util.logging.Level ; 30 import java.util.logging.Logger ; 31 import javax.swing.SwingUtilities ; 32 import javax.swing.Timer ; 33 import org.netbeans.TopSecurityManager; 34 import org.netbeans.core.startup.InstalledFileLocatorImpl; 35 import org.netbeans.core.startup.Main; 36 import org.netbeans.core.startup.ModuleSystem; 37 import org.netbeans.core.startup.Splash; 38 import org.netbeans.core.startup.StartLog; 39 import org.openide.awt.StatusDisplayer; 40 import org.openide.util.Lookup; 41 import org.openide.util.NbBundle; 42 import org.openide.windows.WindowManager; 43 44 48 public class NonGui extends NbTopManager 49 implements Runnable , org.netbeans.core.startup.RunLevel { 50 private static int count; 51 52 public NonGui () { 53 assert count++ == 0 : "Only one instance allowed"; } 55 56 57 public boolean isInteractive (int il) { 58 return true; 59 } 60 61 63 public void run () { 64 try { 67 LoaderPoolNode.load(); 68 } catch (IOException ioe) { 69 Logger.getLogger(NonGui.class.getName()).log(Level.WARNING, null, ioe); 70 } 71 StartLog.logProgress ("LoaderPool loaded"); Splash.getInstance().increment(10); 73 74 LoaderPoolNode.installationFinished (); 75 StartLog.logProgress ("LoaderPool notified"); Splash.getInstance().increment(10); 77 78 java.net.ProxySelector.setDefault (new NbProxySelector ()); 80 81 84 initializeMainWindow (); 85 StartLog.logProgress ("Main window initialized"); Splash.getInstance().increment(1); 87 88 91 SecurityManager secman = new TopSecurityManager(); 93 94 System.setSecurityManager(secman); 95 TopSecurityManager.makeSwingUseSpecialClipboard(Lookup.getDefault().lookup(org.openide.util.datatransfer.ExClipboard.class)); 96 97 java.net.Authenticator.setDefault (new NbAuthenticator ()); 99 100 StartLog.logProgress ("Security managers installed"); Splash.getInstance().increment(1); 102 103 104 InstalledFileLocatorImpl.discardCache(); 105 } 106 107 108 110 protected void initializeMainWindow () { 111 if (!org.netbeans.core.startup.CLIOptions.isGui ()) { 112 return; 113 } 114 115 StartLog.logStart ("Main window initialization"); 117 try { 124 org.openide.util.Mutex.EVENT.writeAccess (new Runnable () { 125 public void run() { 126 Thread.currentThread().setContextClassLoader(Main.getModuleSystem().getManager().getClassLoader()); 127 Toolkit.getDefaultToolkit().getSystemEventQueue().push(new EventQueue ()); 128 } 129 }); 130 } catch (Exception e) { 131 e.printStackTrace(); 132 } 133 134 StatusDisplayer.getDefault().setStatusText (NbBundle.getMessage (NonGui.class, "MSG_MainWindowInit")); 137 138 Timer timerInit = new Timer (0, new java.awt.event.ActionListener () { 143 public void actionPerformed(java.awt.event.ActionEvent ev) { } 144 }); 145 timerInit.setRepeats(false); 146 timerInit.start(); 147 Splash.getInstance().increment(10); 148 StartLog.logProgress ("Timer initialized"); 150 ShortcutsFolder.initShortcuts(); 153 Splash.getInstance().increment(1); 154 StartLog.logProgress ("Shortcuts initialized"); 156 157 StatusDisplayer.getDefault().setStatusText (NbBundle.getMessage (NonGui.class, "MSG_WindowShowInit")); 160 161 164 SwingUtilities.invokeLater(new Runnable () { 166 167 public void run() { 168 StartLog.logProgress("Window system initialization"); 169 if (System.getProperty("netbeans.warmup.skip") == 170 null && 171 System.getProperty("netbeans.close") == 172 null) { 173 final Frame mainWindow = WindowManager.getDefault().getMainWindow(); 174 175 mainWindow.addComponentListener(new ComponentAdapter () { 176 177 public void componentShown(ComponentEvent evt) { 178 mainWindow.removeComponentListener(this); 179 WarmUpSupport.warmUp(); 180 } 181 }); 182 } 183 NbTopManager.WindowSystem windowSystem = (NbTopManager.WindowSystem) Lookup.getDefault().lookup(NbTopManager.WindowSystem.class); 184 185 if (windowSystem != null) { 186 windowSystem.load(); 187 StartLog.logProgress("Window system loaded"); 188 if (StartLog.willLog()) { 189 waitForMainWindowPaint(); 190 } 191 windowSystem.show(); 192 } else { 193 Logger.getLogger(NonGui.class.getName()).log(Level.WARNING, 194 null, 195 new NullPointerException ("\n\n\nWindowSystem is not supplied!!!\\n\n")); 196 } 197 StartLog.logProgress("Window system shown"); 198 if (!StartLog.willLog()) { 199 maybeDie(null); 200 } 201 } 202 }); 203 StartLog.logEnd ("Main window initialization"); } 205 206 private static void waitForMainWindowPaint() { 207 Runnable r = new Runnable () { 210 public void run() { 211 try { 212 Class clz = Class.forName("org.netbeans.performance.test.guitracker.LoggingRepaintManager"); Method m = clz.getMethod("measureStartup", new Class [] {}); Object o = m.invoke(null); 215 endOfStartupMeasuring(o); 216 } catch (ClassNotFoundException e) { 217 StartLog.logProgress(e.toString()); 218 } catch (NoSuchMethodException e) { 219 StartLog.logProgress(e.toString()); 220 } catch (IllegalAccessException e) { 223 StartLog.logProgress(e.toString()); 224 } catch (java.lang.reflect.InvocationTargetException e) { 225 StartLog.logProgress(e.toString()); 226 } 227 } 228 }; 229 new Thread (r).start(); 230 } 231 private static void endOfStartupMeasuring(Object o) { 232 StartLog.logProgress("Startup memory and time measured"); maybeDie(o); 234 } 235 236 private static void maybeDie(Object o) { 237 if (System.getProperty("netbeans.kill") != null) { 239 org.netbeans.TopSecurityManager.exit(5); 240 } 241 242 if (System.getProperty("netbeans.close") != null) { 244 if (Boolean.getBoolean("netbeans.warm.close")) { 245 new WarmUpSupport().run(); } 249 if(o!=null) StartLog.logMeasuredStartupTime(((Long )o).longValue()); 250 org.openide.LifecycleManager.getDefault().exit(); 251 } 252 } 253 254 256 static void doExit (int code) { 257 TopSecurityManager.exit(code); 258 } 259 260 261 public ModuleSystem getModuleSystem() { 262 return Main.getModuleSystem (); 263 } 264 265 } 266 | Popular Tags |