src/java.desktop/share/classes/javax/swing/plaf/metal/MetalToolBarUI.java

Print this page




  71     protected ContainerListener contListener;
  72 
  73     /**
  74      * This protected field is implementation specific. Do not access directly
  75      * or override. Use the create method instead.
  76      *
  77      * @see #createRolloverListener
  78      */
  79     protected PropertyChangeListener rolloverListener;
  80 
  81     private static Border nonRolloverBorder;
  82 
  83     /**
  84      * Last menubar the toolbar touched.  This is only useful for ocean.
  85      */
  86     private JMenuBar lastMenuBar;
  87 
  88     /**
  89      * Registers the specified component.
  90      */
  91     synchronized static void register(JComponent c) {
  92         if (c == null) {
  93             // Exception is thrown as convenience for callers that are
  94             // typed to throw an NPE.
  95             throw new NullPointerException("JComponent must be non-null");
  96         }
  97         components.add(new WeakReference<JComponent>(c));
  98     }
  99 
 100     /**
 101      * Unregisters the specified component.
 102      */
 103     synchronized static void unregister(JComponent c) {
 104         for (int counter = components.size() - 1; counter >= 0; counter--) {
 105             // Search for the component, removing any flushed references
 106             // along the way.
 107             JComponent target = components.get(counter).get();
 108 
 109             if (target == c || target == null) {
 110                 components.remove(counter);
 111             }
 112         }
 113     }
 114 
 115     /**
 116      * Finds a previously registered component of class <code>target</code>
 117      * that shares the JRootPane ancestor of <code>from</code>.
 118      */
 119     synchronized static Object findRegisteredComponentOfType(JComponent from,
 120                                                              Class<?> target) {
 121         JRootPane rp = SwingUtilities.getRootPane(from);
 122         if (rp != null) {
 123             for (int counter = components.size() - 1; counter >= 0; counter--){
 124                 Object component = ((WeakReference)components.get(counter)).
 125                                    get();
 126 
 127                 if (component == null) {
 128                     // WeakReference has gone away, remove the WeakReference
 129                     components.remove(counter);
 130                 }
 131                 else if (target.isInstance(component) && SwingUtilities.
 132                          getRootPane((Component)component) == rp) {
 133                     return component;
 134                 }
 135             }
 136         }
 137         return null;
 138     }
 139 




  71     protected ContainerListener contListener;
  72 
  73     /**
  74      * This protected field is implementation specific. Do not access directly
  75      * or override. Use the create method instead.
  76      *
  77      * @see #createRolloverListener
  78      */
  79     protected PropertyChangeListener rolloverListener;
  80 
  81     private static Border nonRolloverBorder;
  82 
  83     /**
  84      * Last menubar the toolbar touched.  This is only useful for ocean.
  85      */
  86     private JMenuBar lastMenuBar;
  87 
  88     /**
  89      * Registers the specified component.
  90      */
  91     static synchronized void register(JComponent c) {
  92         if (c == null) {
  93             // Exception is thrown as convenience for callers that are
  94             // typed to throw an NPE.
  95             throw new NullPointerException("JComponent must be non-null");
  96         }
  97         components.add(new WeakReference<JComponent>(c));
  98     }
  99 
 100     /**
 101      * Unregisters the specified component.
 102      */
 103     static synchronized void unregister(JComponent c) {
 104         for (int counter = components.size() - 1; counter >= 0; counter--) {
 105             // Search for the component, removing any flushed references
 106             // along the way.
 107             JComponent target = components.get(counter).get();
 108 
 109             if (target == c || target == null) {
 110                 components.remove(counter);
 111             }
 112         }
 113     }
 114 
 115     /**
 116      * Finds a previously registered component of class <code>target</code>
 117      * that shares the JRootPane ancestor of <code>from</code>.
 118      */
 119     static synchronized Object findRegisteredComponentOfType(JComponent from,
 120                                                              Class<?> target) {
 121         JRootPane rp = SwingUtilities.getRootPane(from);
 122         if (rp != null) {
 123             for (int counter = components.size() - 1; counter >= 0; counter--){
 124                 Object component = ((WeakReference)components.get(counter)).
 125                                    get();
 126 
 127                 if (component == null) {
 128                     // WeakReference has gone away, remove the WeakReference
 129                     components.remove(counter);
 130                 }
 131                 else if (target.isInstance(component) && SwingUtilities.
 132                          getRootPane((Component)component) == rp) {
 133                     return component;
 134                 }
 135             }
 136         }
 137         return null;
 138     }
 139