15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javax.swing.plaf.metal; 27 28 import java.awt.*; 29 import javax.swing.*; 30 import javax.swing.plaf.ComponentUI; 31 import javax.swing.plaf.UIResource; 32 import javax.swing.plaf.basic.*; 33 34 /** 35 * Metal implementation of <code>MenuBarUI</code>. This class is responsible 36 * for providing the metal look and feel for <code>JMenuBar</code>s. 37 * 38 * @see javax.swing.plaf.MenuBarUI 39 * @since 1.5 40 */ 41 public class MetalMenuBarUI extends BasicMenuBarUI { 42 /** 43 * Creates the <code>ComponentUI</code> implementation for the passed 44 * in component. 45 * 46 * @param x JComponent to create the ComponentUI implementation for 47 * @return ComponentUI implementation for <code>x</code> 48 * @throws NullPointerException if <code>x</code> is null 49 */ 50 public static ComponentUI createUI(JComponent x) { 51 if (x == null) { 52 throw new NullPointerException("Must pass in a non-null component"); 53 } 54 return new MetalMenuBarUI(); 55 } 56 57 /** 58 * Configures the specified component appropriate for the metal look and 59 * feel. 60 * 61 * @param c the component where this UI delegate is being installed 62 * @throws NullPointerException if <code>c</code> is null. 63 */ 64 public void installUI(JComponent c) { 65 super.installUI(c); 66 MetalToolBarUI.register(c); 67 } 68 69 /** 70 * Reverses configuration which was done on the specified component during 71 * <code>installUI</code>. 72 * 73 * @param c the component where this UI delegate is being installed 74 * @throws NullPointerException if <code>c</code> is null. 75 */ 76 public void uninstallUI(JComponent c) { 77 super.uninstallUI(c); 78 MetalToolBarUI.unregister(c); 79 } 80 81 /** 82 * If necessary paints the background of the component, then 83 * invokes <code>paint</code>. 84 * 85 * @param g Graphics to paint to 86 * @param c JComponent painting on 87 * @throws NullPointerException if <code>g</code> or <code>c</code> is 88 * null 89 * @see javax.swing.plaf.ComponentUI#update 90 * @see javax.swing.plaf.ComponentUI#paint 91 * @since 1.5 92 */ 93 public void update(Graphics g, JComponent c) { 94 boolean isOpaque = c.isOpaque(); 95 if (g == null) { 96 throw new NullPointerException("Graphics must be non-null"); 97 } 98 if (isOpaque && (c.getBackground() instanceof UIResource) && 99 UIManager.get("MenuBar.gradient") != null) { 100 if (MetalToolBarUI.doesMenuBarBorderToolBar((JMenuBar)c)) { 101 JToolBar tb = (JToolBar)MetalToolBarUI. 102 findRegisteredComponentOfType(c, JToolBar.class); 103 if (tb.isOpaque() &&tb.getBackground() instanceof UIResource) { 104 MetalUtils.drawGradient(c, g, "MenuBar.gradient", 0, 0, 105 c.getWidth(), c.getHeight() + 106 tb.getHeight(), true); 107 paint(g, c); | 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javax.swing.plaf.metal; 27 28 import java.awt.*; 29 import javax.swing.*; 30 import javax.swing.plaf.ComponentUI; 31 import javax.swing.plaf.UIResource; 32 import javax.swing.plaf.basic.*; 33 34 /** 35 * Metal implementation of {@code MenuBarUI}. This class is responsible 36 * for providing the metal look and feel for {@code JMenuBar}s. 37 * 38 * @see javax.swing.plaf.MenuBarUI 39 * @since 1.5 40 */ 41 public class MetalMenuBarUI extends BasicMenuBarUI { 42 /** 43 * Creates the {@code ComponentUI} implementation for the passed 44 * in component. 45 * 46 * @param x JComponent to create the ComponentUI implementation for 47 * @return ComponentUI implementation for {@code x} 48 * @throws NullPointerException if {@code x} is null 49 */ 50 public static ComponentUI createUI(JComponent x) { 51 if (x == null) { 52 throw new NullPointerException("Must pass in a non-null component"); 53 } 54 return new MetalMenuBarUI(); 55 } 56 57 /** 58 * Configures the specified component appropriate for the metal look and 59 * feel. 60 * 61 * @param c the component where this UI delegate is being installed 62 * @throws NullPointerException if {@code c} is null. 63 */ 64 public void installUI(JComponent c) { 65 super.installUI(c); 66 MetalToolBarUI.register(c); 67 } 68 69 /** 70 * Reverses configuration which was done on the specified component during 71 * {@code installUI}. 72 * 73 * @param c the component where this UI delegate is being installed 74 * @throws NullPointerException if {@code c} is null. 75 */ 76 public void uninstallUI(JComponent c) { 77 super.uninstallUI(c); 78 MetalToolBarUI.unregister(c); 79 } 80 81 /** 82 * If necessary paints the background of the component, then 83 * invokes {@code paint}. 84 * 85 * @param g Graphics to paint to 86 * @param c JComponent painting on 87 * @throws NullPointerException if {@code g} or {@code c} is 88 * null 89 * @see javax.swing.plaf.ComponentUI#update 90 * @see javax.swing.plaf.ComponentUI#paint 91 * @since 1.5 92 */ 93 public void update(Graphics g, JComponent c) { 94 boolean isOpaque = c.isOpaque(); 95 if (g == null) { 96 throw new NullPointerException("Graphics must be non-null"); 97 } 98 if (isOpaque && (c.getBackground() instanceof UIResource) && 99 UIManager.get("MenuBar.gradient") != null) { 100 if (MetalToolBarUI.doesMenuBarBorderToolBar((JMenuBar)c)) { 101 JToolBar tb = (JToolBar)MetalToolBarUI. 102 findRegisteredComponentOfType(c, JToolBar.class); 103 if (tb.isOpaque() &&tb.getBackground() instanceof UIResource) { 104 MetalUtils.drawGradient(c, g, "MenuBar.gradient", 0, 0, 105 c.getWidth(), c.getHeight() + 106 tb.getHeight(), true); 107 paint(g, c); |