Exemplo n.º 1
0
  public static void changeFrameAppContext(Frame frame, AppContext newAppContext) {
    // Fixed #4754451: Applet can have methods running on main
    // thread event queue.
    //
    // The cause of this bug is that the frame of the applet
    // is created in main thread group. Thus, when certain
    // AWT/Swing events are generated, the events will be
    // dispatched through the wrong event dispatch thread.
    //
    // To fix this, we rearrange the AppContext with the frame,
    // so the proper event queue will be looked up.
    //
    // Swing also maintains a Frame list for the AppContext,
    // so we will have to rearrange it as well.

    // Check if frame's AppContext has already been set properly
    AppContext oldAppContext = SunToolkit.targetToAppContext(frame);

    if (oldAppContext == newAppContext) return;

    // Synchronization on Window.class is needed for locking the
    // critical section of the window list in AppContext.
    synchronized (Window.class) {
      WeakReference<Window> weakRef = null;
      // Remove frame from the Window list in wrong AppContext
      {
        // Lookup current frame's AppContext
        @SuppressWarnings("unchecked")
        Vector<WeakReference<Window>> windowList =
            (Vector<WeakReference<Window>>) oldAppContext.get(Window.class);
        if (windowList != null) {
          for (WeakReference<Window> ref : windowList) {
            if (ref.get() == frame) {
              weakRef = ref;
              break;
            }
          }
          // Remove frame from wrong AppContext
          if (weakRef != null) windowList.remove(weakRef);
        }
      }

      // Put the frame into the applet's AppContext map
      SunToolkit.insertTargetMapping(frame, newAppContext);

      // Insert frame into the Window list in the applet's AppContext map
      {
        @SuppressWarnings("unchecked")
        Vector<WeakReference<Window>> windowList =
            (Vector<WeakReference<Window>>) newAppContext.get(Window.class);
        if (windowList == null) {
          windowList = new Vector<WeakReference<Window>>();
          newAppContext.put(Window.class, windowList);
        }
        // use the same weakRef here as it is used elsewhere
        windowList.add(weakRef);
      }
    }
  }
 private static synchronized AnimationController getAnimationController() {
   AppContext appContext = AppContext.getAppContext();
   Object obj = appContext.get(ANIMATION_CONTROLLER_KEY);
   if (obj == null) {
     obj = new AnimationController();
     appContext.put(ANIMATION_CONTROLLER_KEY, obj);
   }
   return (AnimationController) obj;
 }
Exemplo n.º 3
0
 // ********************************
 //          Create PLAF
 // ********************************
 public static ComponentUI createUI(JComponent c) {
   AppContext appContext = AppContext.getAppContext();
   BasicButtonUI buttonUI = (BasicButtonUI) appContext.get(BASIC_BUTTON_UI_KEY);
   if (buttonUI == null) {
     buttonUI = new BasicButtonUI();
     appContext.put(BASIC_BUTTON_UI_KEY, buttonUI);
   }
   return buttonUI;
 }
Exemplo n.º 4
0
 // ********************************
 //          Create PLAF
 // ********************************
 public static ComponentUI createUI(JComponent c) {
   AppContext appContext = AppContext.getAppContext();
   MetalButtonUI metalButtonUI = (MetalButtonUI) appContext.get(METAL_BUTTON_UI_KEY);
   if (metalButtonUI == null) {
     metalButtonUI = new MetalButtonUI();
     appContext.put(METAL_BUTTON_UI_KEY, metalButtonUI);
   }
   return metalButtonUI;
 }
Exemplo n.º 5
0
 // ********************************
 //          Create PLAF
 // ********************************
 public static ComponentUI createUI(JComponent c) {
   AppContext appContext = AppContext.getAppContext();
   WindowsCheckBoxUI windowsCheckBoxUI =
       (WindowsCheckBoxUI) appContext.get(WINDOWS_CHECK_BOX_UI_KEY);
   if (windowsCheckBoxUI == null) {
     windowsCheckBoxUI = new WindowsCheckBoxUI();
     appContext.put(WINDOWS_CHECK_BOX_UI_KEY, windowsCheckBoxUI);
   }
   return windowsCheckBoxUI;
 }
 /**
  * Fetch the default layout queue.
  *
  * @return the default layout queue
  */
 public static LayoutQueue getDefaultQueue() {
   AppContext ac = AppContext.getAppContext();
   synchronized (DEFAULT_QUEUE) {
     LayoutQueue defaultQueue = (LayoutQueue) ac.get(DEFAULT_QUEUE);
     if (defaultQueue == null) {
       defaultQueue = new LayoutQueue();
       ac.put(DEFAULT_QUEUE, defaultQueue);
     }
     return defaultQueue;
   }
 }
Exemplo n.º 7
0
  /**
   * Constructor for AppContext. This method is <i>not</i> public, nor should it ever be used as
   * such. The proper way to construct an AppContext is through the use of
   * SunToolkit.createNewAppContext. A ThreadGroup is created for the new AppContext, a Thread is
   * created within that ThreadGroup, and that Thread calls SunToolkit.createNewAppContext before
   * calling anything else. That creates both the new AppContext and its EventQueue.
   *
   * @param threadGroup The ThreadGroup for the new AppContext
   * @see sun.awt.SunToolkit
   * @since 1.2
   */
  AppContext(ThreadGroup threadGroup) {
    numAppContexts++;

    this.threadGroup = threadGroup;
    threadGroup2appContext.put(threadGroup, this);

    this.contextClassLoader =
        AccessController.doPrivileged(
            new PrivilegedAction<ClassLoader>() {
              public ClassLoader run() {
                return Thread.currentThread().getContextClassLoader();
              }
            });

    // Initialize push/pop lock and its condition to be used by all the
    // EventQueues within this AppContext
    Lock eventQueuePushPopLock = new ReentrantLock();
    put(EVENT_QUEUE_LOCK_KEY, eventQueuePushPopLock);
    Condition eventQueuePushPopCond = eventQueuePushPopLock.newCondition();
    put(EVENT_QUEUE_COND_KEY, eventQueuePushPopCond);
  }
  /**
   * Returns the default menu selection manager.
   *
   * @return a MenuSelectionManager object
   */
  public static MenuSelectionManager defaultManager() {
    synchronized (MENU_SELECTION_MANAGER_KEY) {
      AppContext context = AppContext.getAppContext();
      MenuSelectionManager msm = (MenuSelectionManager) context.get(MENU_SELECTION_MANAGER_KEY);
      if (msm == null) {
        msm = new MenuSelectionManager();
        context.put(MENU_SELECTION_MANAGER_KEY, msm);
      }

      return msm;
    }
  }
Exemplo n.º 9
0
  /*
   * The method maps the list of the active windows to the window's AppContext,
   * then the method registers ActiveWindowListener, GuiDisposedListener listeners;
   * it executes the initilialization only once per AppContext.
   */
  @SuppressWarnings("unchecked")
  private static void initActiveWindowsTracking(Window w) {
    AppContext appContext = AppContext.getAppContext();
    synchronized (appContext) {
      List<WWindowPeer> l = (List<WWindowPeer>) appContext.get(ACTIVE_WINDOWS_KEY);
      if (l == null) {
        l = new LinkedList<WWindowPeer>();
        appContext.put(ACTIVE_WINDOWS_KEY, l);
        appContext.addPropertyChangeListener(AppContext.GUI_DISPOSED, guiDisposedListener);

        KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
        kfm.addPropertyChangeListener("activeWindow", activeWindowListener);
      }
    }
  }
Exemplo n.º 10
0
    private static Dimension[] getIconSizesMap() {
      AppContext appContext = AppContext.getAppContext();
      Dimension[] iconSizes = (Dimension[]) appContext.get(ICON_SIZE_KEY);

      if (iconSizes == null) {
        iconSizes = new Dimension[7];
        iconSizes[0] = null; // GTK_ICON_SIZE_INVALID
        iconSizes[1] = new Dimension(16, 16); // GTK_ICON_SIZE_MENU
        iconSizes[2] = new Dimension(18, 18); // GTK_ICON_SIZE_SMALL_TOOLBAR
        iconSizes[3] = new Dimension(24, 24); // GTK_ICON_SIZE_LARGE_TOOLBAR
        iconSizes[4] = new Dimension(20, 20); // GTK_ICON_SIZE_BUTTON
        iconSizes[5] = new Dimension(32, 32); // GTK_ICON_SIZE_DND
        iconSizes[6] = new Dimension(48, 48); // GTK_ICON_SIZE_DIALOG
        appContext.put(ICON_SIZE_KEY, iconSizes);
      }
      return iconSizes;
    }