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; 236 JToggleButton b = (JToggleButton)c; 237 Border border = b.getBorder(); 238 super.setBorderToNonRollover(c); 239 if (border instanceof UIResource) { 240 if (nonRolloverBorder == null) { 241 nonRolloverBorder = createNonRolloverToggleBorder(); 242 } 243 b.setBorder(nonRolloverBorder); 244 } 245 } else { 246 super.setBorderToNonRollover(c); 247 } 248 } 249 250 251 /** 252 * Creates a container listener that will be added to the JToolBar. 253 * If this method returns null then it will not be added to the 254 * toolbar. 255 * 256 * @return an instance of a <code>ContainerListener</code> or null 257 */ 258 protected ContainerListener createContainerListener() { 259 return null; 260 } 261 262 /** 263 * Creates a property change listener that will be added to the JToolBar. 264 * If this method returns null then it will not be added to the 265 * toolbar. 266 * 267 * @return an instance of a <code>PropertyChangeListener</code> or null 268 */ 269 protected PropertyChangeListener createRolloverListener() { 270 return null; 271 } 272 273 protected MouseInputListener createDockingListener( ) 274 { 275 return new MetalDockingListener( toolBar ); 276 } 277 278 /** 279 * Sets the offset of the mouse cursor inside the DragWindow. 280 * 281 * @param p the offset 282 */ 283 protected void setDragOffset(Point p) { 284 if (!GraphicsEnvironment.isHeadless()) { 285 if (dragWindow == null) { 286 dragWindow = createDragWindow(toolBar); 287 } 288 dragWindow.setOffset(p); 289 } 290 } 291 292 /** 293 * If necessary paints the background of the component, then invokes 294 * <code>paint</code>. 295 * 296 * @param g Graphics to paint to 297 * @param c JComponent painting on 298 * @throws NullPointerException if <code>g</code> or <code>c</code> is 299 * null 300 * @see javax.swing.plaf.ComponentUI#update 301 * @see javax.swing.plaf.ComponentUI#paint 302 * @since 1.5 303 */ 304 public void update(Graphics g, JComponent c) { 305 if (g == null) { 306 throw new NullPointerException("graphics must be non-null"); 307 } 308 if (c.isOpaque() && (c.getBackground() instanceof UIResource) && 309 ((JToolBar)c).getOrientation() == 310 JToolBar.HORIZONTAL && UIManager.get( 311 "MenuBar.gradient") != null) { 312 JRootPane rp = SwingUtilities.getRootPane(c); 313 JMenuBar mb = (JMenuBar)findRegisteredComponentOfType( 314 c, JMenuBar.class); 315 if (mb != null && mb.isOpaque() && 316 (mb.getBackground() instanceof UIResource)) { 317 Point point = new Point(0, 0); 318 point = SwingUtilities.convertPoint(c, point, rp); | 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} 117 * that shares the JRootPane ancestor of {@code from}. 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; 236 JToggleButton b = (JToggleButton)c; 237 Border border = b.getBorder(); 238 super.setBorderToNonRollover(c); 239 if (border instanceof UIResource) { 240 if (nonRolloverBorder == null) { 241 nonRolloverBorder = createNonRolloverToggleBorder(); 242 } 243 b.setBorder(nonRolloverBorder); 244 } 245 } else { 246 super.setBorderToNonRollover(c); 247 } 248 } 249 250 251 /** 252 * Creates a container listener that will be added to the JToolBar. 253 * If this method returns null then it will not be added to the 254 * toolbar. 255 * 256 * @return an instance of a {@code ContainerListener} or null 257 */ 258 protected ContainerListener createContainerListener() { 259 return null; 260 } 261 262 /** 263 * Creates a property change listener that will be added to the JToolBar. 264 * If this method returns null then it will not be added to the 265 * toolbar. 266 * 267 * @return an instance of a {@code PropertyChangeListener} or null 268 */ 269 protected PropertyChangeListener createRolloverListener() { 270 return null; 271 } 272 273 protected MouseInputListener createDockingListener( ) 274 { 275 return new MetalDockingListener( toolBar ); 276 } 277 278 /** 279 * Sets the offset of the mouse cursor inside the DragWindow. 280 * 281 * @param p the offset 282 */ 283 protected void setDragOffset(Point p) { 284 if (!GraphicsEnvironment.isHeadless()) { 285 if (dragWindow == null) { 286 dragWindow = createDragWindow(toolBar); 287 } 288 dragWindow.setOffset(p); 289 } 290 } 291 292 /** 293 * If necessary paints the background of the component, then invokes 294 * {@code paint}. 295 * 296 * @param g Graphics to paint to 297 * @param c JComponent painting on 298 * @throws NullPointerException if {@code g} or {@code c} is 299 * null 300 * @see javax.swing.plaf.ComponentUI#update 301 * @see javax.swing.plaf.ComponentUI#paint 302 * @since 1.5 303 */ 304 public void update(Graphics g, JComponent c) { 305 if (g == null) { 306 throw new NullPointerException("graphics must be non-null"); 307 } 308 if (c.isOpaque() && (c.getBackground() instanceof UIResource) && 309 ((JToolBar)c).getOrientation() == 310 JToolBar.HORIZONTAL && UIManager.get( 311 "MenuBar.gradient") != null) { 312 JRootPane rp = SwingUtilities.getRootPane(c); 313 JMenuBar mb = (JMenuBar)findRegisteredComponentOfType( 314 c, JMenuBar.class); 315 if (mb != null && mb.isOpaque() && 316 (mb.getBackground() instanceof UIResource)) { 317 Point point = new Point(0, 0); 318 point = SwingUtilities.convertPoint(c, point, rp); |