src/share/classes/sun/awt/AppContext.java

Print this page




 292         }
 293 
 294         AppContext appContext = threadAppContext.get();
 295 
 296         if (null == appContext) {
 297             appContext = AccessController.doPrivileged(new PrivilegedAction<AppContext>()
 298             {
 299                 public AppContext run() {
 300                     // Get the current ThreadGroup, and look for it and its
 301                     // parents in the hash from ThreadGroup to AppContext --
 302                     // it should be found, because we use createNewContext()
 303                     // when new AppContext objects are created.
 304                     ThreadGroup currentThreadGroup = Thread.currentThread().getThreadGroup();
 305                     ThreadGroup threadGroup = currentThreadGroup;
 306 
 307                     // Special case: we implicitly create the main app context
 308                     // if no contexts have been created yet. This covers standalone apps
 309                     // and excludes applets because by the time applet starts
 310                     // a number of contexts have already been created by the plugin.
 311                     if (numAppContexts.get() == 0) {
 312                         // This check is not necessary, its purpose is to help
 313                         // Plugin devs to catch all the cases of main AC creation.
 314                         if (System.getProperty("javaplugin.version") == null &&
 315                                 System.getProperty("javawebstart.version") == null) {
 316                             initMainAppContext();




 317                         }
 318                     }
 319 
 320                     AppContext context = threadGroup2appContext.get(threadGroup);
 321                     while (context == null) {
 322                         threadGroup = threadGroup.getParent();
 323                         if (threadGroup == null) {
 324                             return null;
 325                         }
 326                         context = threadGroup2appContext.get(threadGroup);
 327                     }
 328 
 329                     // In case we did anything in the above while loop, we add
 330                     // all the intermediate ThreadGroups to threadGroup2appContext
 331                     // so we won't spin again.
 332                     for (ThreadGroup tg = currentThreadGroup; tg != threadGroup; tg = tg.getParent()) {
 333                         threadGroup2appContext.put(tg, context);
 334                     }
 335 
 336                     // Now we're done, so we cache the latest key/value pair.




 292         }
 293 
 294         AppContext appContext = threadAppContext.get();
 295 
 296         if (null == appContext) {
 297             appContext = AccessController.doPrivileged(new PrivilegedAction<AppContext>()
 298             {
 299                 public AppContext run() {
 300                     // Get the current ThreadGroup, and look for it and its
 301                     // parents in the hash from ThreadGroup to AppContext --
 302                     // it should be found, because we use createNewContext()
 303                     // when new AppContext objects are created.
 304                     ThreadGroup currentThreadGroup = Thread.currentThread().getThreadGroup();
 305                     ThreadGroup threadGroup = currentThreadGroup;
 306 
 307                     // Special case: we implicitly create the main app context
 308                     // if no contexts have been created yet. This covers standalone apps
 309                     // and excludes applets because by the time applet starts
 310                     // a number of contexts have already been created by the plugin.
 311                     if (numAppContexts.get() == 0) {


 312                         if (System.getProperty("javaplugin.version") == null &&
 313                                 System.getProperty("javawebstart.version") == null) {
 314                             initMainAppContext();
 315                         } else if (System.getProperty("javafx.version") != null &&
 316                                 threadGroup.getParent() != null) {
 317                             // Swing inside JavaFX case
 318                             SunToolkit.createNewAppContext();
 319                         }
 320                     }
 321 
 322                     AppContext context = threadGroup2appContext.get(threadGroup);
 323                     while (context == null) {
 324                         threadGroup = threadGroup.getParent();
 325                         if (threadGroup == null) {
 326                             return null;
 327                         }
 328                         context = threadGroup2appContext.get(threadGroup);
 329                     }
 330 
 331                     // In case we did anything in the above while loop, we add
 332                     // all the intermediate ThreadGroups to threadGroup2appContext
 333                     // so we won't spin again.
 334                     for (ThreadGroup tg = currentThreadGroup; tg != threadGroup; tg = tg.getParent()) {
 335                         threadGroup2appContext.put(tg, context);
 336                     }
 337 
 338                     // Now we're done, so we cache the latest key/value pair.