KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > plaf > synth > SynthMenuBarUI


1 /*
2  * @(#)SynthMenuBarUI.java 1.10 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 package javax.swing.plaf.synth;
8
9 import javax.swing.*;
10 import javax.swing.event.*;
11 import java.awt.Color JavaDoc;
12 import java.awt.Component JavaDoc;
13 import java.awt.Container JavaDoc;
14 import java.awt.Dimension JavaDoc;
15 import java.awt.Graphics JavaDoc;
16 import java.awt.Insets JavaDoc;
17 import java.awt.Point JavaDoc;
18 import java.awt.Rectangle JavaDoc;
19 import java.awt.event.*;
20 import java.beans.PropertyChangeEvent JavaDoc;
21 import java.beans.PropertyChangeListener JavaDoc;
22
23 import javax.swing.border.*;
24 import javax.swing.plaf.*;
25 import javax.swing.plaf.basic.*;
26 import sun.swing.plaf.synth.SynthUI;
27
28 /**
29  * Synth's MenuBarUI.
30  *
31  * @version 1.10, 12/19/03
32  * @author Scott Violet
33  */

34 class SynthMenuBarUI extends BasicMenuBarUI implements PropertyChangeListener JavaDoc,
35                                   SynthUI {
36     private SynthStyle JavaDoc style;
37
38     public static ComponentUI createUI(JComponent x) {
39     return new SynthMenuBarUI JavaDoc();
40     }
41
42     protected void installDefaults() {
43     if (menuBar.getLayout() == null ||
44         menuBar.getLayout() instanceof UIResource) {
45             menuBar.setLayout(new DefaultMenuLayout JavaDoc(menuBar,BoxLayout.LINE_AXIS));
46         }
47         updateStyle(menuBar);
48     }
49
50     protected void installListeners() {
51         super.installListeners();
52         menuBar.addPropertyChangeListener(this);
53     }
54
55     private void updateStyle(JMenuBar c) {
56         SynthContext JavaDoc context = getContext(c, ENABLED);
57         SynthStyle JavaDoc oldStyle = style;
58         style = SynthLookAndFeel.updateStyle(context, this);
59         if (style != oldStyle) {
60             if (oldStyle != null) {
61                 uninstallKeyboardActions();
62                 installKeyboardActions();
63             }
64         }
65         context.dispose();
66     }
67
68     protected void uninstallDefaults() {
69         SynthContext JavaDoc context = getContext(menuBar, ENABLED);
70
71         style.uninstallDefaults(context);
72         context.dispose();
73         style = null;
74     }
75
76     protected void uninstallListeners() {
77         super.uninstallListeners();
78         menuBar.removePropertyChangeListener(this);
79     }
80
81     public SynthContext JavaDoc getContext(JComponent c) {
82         return getContext(c, getComponentState(c));
83     }
84
85     private SynthContext JavaDoc getContext(JComponent c, int state) {
86         return SynthContext.getContext(SynthContext JavaDoc.class, c,
87                     SynthLookAndFeel.getRegion(c), style, state);
88     }
89
90     private Region JavaDoc getRegion(JComponent c) {
91         return SynthLookAndFeel.getRegion(c);
92     }
93
94     private int getComponentState(JComponent c) {
95         return SynthLookAndFeel.getComponentState(c);
96     }
97
98     public void update(Graphics JavaDoc g, JComponent c) {
99         SynthContext JavaDoc context = getContext(c);
100
101         SynthLookAndFeel.update(context, g);
102         context.getPainter().paintMenuBarBackground(context,
103                           g, 0, 0, c.getWidth(), c.getHeight());
104         paint(context, g);
105         context.dispose();
106     }
107
108     public void paint(Graphics JavaDoc g, JComponent c) {
109         SynthContext JavaDoc context = getContext(c);
110
111         paint(context, g);
112         context.dispose();
113     }
114
115     protected void paint(SynthContext JavaDoc context, Graphics JavaDoc g) {
116     }
117
118     public void paintBorder(SynthContext JavaDoc context, Graphics JavaDoc g, int x,
119                             int y, int w, int h) {
120         context.getPainter().paintMenuBarBorder(context, g, x, y, w, h);
121     }
122
123     public void propertyChange(PropertyChangeEvent JavaDoc e) {
124         if (SynthLookAndFeel.shouldUpdateStyle(e)) {
125             updateStyle((JMenuBar)e.getSource());
126         }
127     }
128 }
129
Popular Tags