KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > plaf > metal > MetalMenuBarUI


1 /*
2  * @(#)MetalMenuBarUI.java 1.5 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.swing.plaf.metal;
9
10 import java.awt.*;
11 import javax.swing.*;
12 import javax.swing.plaf.ComponentUI JavaDoc;
13 import javax.swing.plaf.UIResource JavaDoc;
14 import javax.swing.plaf.basic.*;
15
16 /**
17  * Metal implementation of <code>MenuBarUI</code>. This class is responsible
18  * for providing the metal look and feel for <code>JMenuBar</code>s.
19  *
20  * @version 1.5 12/19/03
21  * @see javax.swing.plaf.MenuBarUI
22  * @since 1.5
23  */

24 public class MetalMenuBarUI extends BasicMenuBarUI {
25     /**
26      * Creates the <code>ComponentUI</code> implementation for the passed
27      * in component.
28      *
29      * @param x JComponent to create the ComponentUI implementation for
30      * @return ComponentUI implementation for <code>x</code>
31      * @throws NullPointerException if <code>x</code> is null
32      */

33     public static ComponentUI JavaDoc createUI(JComponent x) {
34         if (x == null) {
35             throw new NullPointerException JavaDoc("Must pass in a non-null component");
36         }
37     return new MetalMenuBarUI JavaDoc();
38     }
39
40     /**
41      * Configures the specified component appropriate for the metal look and
42      * feel.
43      *
44      * @param c the component where this UI delegate is being installed
45      * @throws NullPointerException if <code>c</code> is null.
46      */

47     public void installUI(JComponent c) {
48         super.installUI(c);
49         MetalToolBarUI.register(c);
50     }
51
52     /**
53      * Reverses configuration which was done on the specified component during
54      * <code>installUI</code>.
55      *
56      * @param c the component where this UI delegate is being installed
57      * @throws NullPointerException if <code>c</code> is null.
58      */

59     public void uninstallUI(JComponent c) {
60         super.uninstallUI(c);
61         MetalToolBarUI.unregister(c);
62     }
63
64     /**
65      * If necessary paints the background of the component, then
66      * invokes <code>paint</code>.
67      *
68      * @param g Graphics to paint to
69      * @param c JComponent painting on
70      * @throws NullPointerException if <code>g</code> or <code>c</code> is
71      * null
72      * @see javax.swing.plaf.ComponentUI#update
73      * @see javax.swing.plaf.ComponentUI#paint
74      * @since 1.5
75      */

76     public void update(Graphics g, JComponent c) {
77         boolean isOpaque = c.isOpaque();
78         if (isOpaque && (c.getBackground() instanceof UIResource JavaDoc) &&
79                         UIManager.get("MenuBar.gradient") != null) {
80             if (MetalToolBarUI.doesMenuBarBorderToolBar((JMenuBar)c)) {
81                 JToolBar tb = (JToolBar)MetalToolBarUI.
82                      findRegisteredComponentOfType(c, JToolBar.class);
83                 if (tb.isOpaque() &&tb.getBackground() instanceof UIResource JavaDoc) {
84                     MetalUtils.drawGradient(c, g, "MenuBar.gradient", 0, 0,
85                                             c.getWidth(), c.getHeight() +
86                                             tb.getHeight(), true);
87                     paint(g, c);
88                     return;
89                 }
90             }
91             MetalUtils.drawGradient(c, g, "MenuBar.gradient", 0, 0,
92                                     c.getWidth(), c.getHeight(),true);
93             paint(g, c);
94         }
95         else {
96             super.update(g, c);
97         }
98     }
99 }
100
Popular Tags