author | alexsch |
Wed, 25 Sep 2013 17:08:31 +0400 | |
changeset 20168 | 137788883a22 |
parent 7668 | d4a77089c587 |
child 23010 | 6dadb192ad81 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
package javax.swing.plaf.synth; |
|
26 |
||
27 |
import javax.swing.*; |
|
28 |
import java.awt.Graphics; |
|
29 |
import java.beans.PropertyChangeEvent; |
|
30 |
import java.beans.PropertyChangeListener; |
|
31 |
import javax.swing.plaf.*; |
|
32 |
import javax.swing.plaf.basic.*; |
|
33 |
||
34 |
/** |
|
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
35 |
* Provides the Synth L&F UI delegate for |
4394 | 36 |
* {@link javax.swing.JMenuBar}. |
2 | 37 |
* |
38 |
* @author Scott Violet |
|
4394 | 39 |
* @since 1.7 |
2 | 40 |
*/ |
4394 | 41 |
public class SynthMenuBarUI extends BasicMenuBarUI |
42 |
implements PropertyChangeListener, SynthUI { |
|
2 | 43 |
private SynthStyle style; |
44 |
||
4394 | 45 |
/** |
46 |
* Creates a new UI object for the given component. |
|
47 |
* |
|
48 |
* @param x component to create UI object for |
|
49 |
* @return the UI object |
|
50 |
*/ |
|
2 | 51 |
public static ComponentUI createUI(JComponent x) { |
52 |
return new SynthMenuBarUI(); |
|
53 |
} |
|
54 |
||
4394 | 55 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
56 |
* {@inheritDoc} |
4394 | 57 |
*/ |
58 |
@Override |
|
2 | 59 |
protected void installDefaults() { |
60 |
if (menuBar.getLayout() == null || |
|
61 |
menuBar.getLayout() instanceof UIResource) { |
|
4394 | 62 |
menuBar.setLayout(new SynthMenuLayout(menuBar,BoxLayout.LINE_AXIS)); |
2 | 63 |
} |
64 |
updateStyle(menuBar); |
|
65 |
} |
|
66 |
||
4394 | 67 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
68 |
* {@inheritDoc} |
4394 | 69 |
*/ |
70 |
@Override |
|
2 | 71 |
protected void installListeners() { |
72 |
super.installListeners(); |
|
73 |
menuBar.addPropertyChangeListener(this); |
|
74 |
} |
|
75 |
||
76 |
private void updateStyle(JMenuBar c) { |
|
77 |
SynthContext context = getContext(c, ENABLED); |
|
78 |
SynthStyle oldStyle = style; |
|
79 |
style = SynthLookAndFeel.updateStyle(context, this); |
|
80 |
if (style != oldStyle) { |
|
81 |
if (oldStyle != null) { |
|
82 |
uninstallKeyboardActions(); |
|
83 |
installKeyboardActions(); |
|
84 |
} |
|
85 |
} |
|
86 |
context.dispose(); |
|
87 |
} |
|
88 |
||
4394 | 89 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
90 |
* {@inheritDoc} |
4394 | 91 |
*/ |
92 |
@Override |
|
2 | 93 |
protected void uninstallDefaults() { |
94 |
SynthContext context = getContext(menuBar, ENABLED); |
|
95 |
||
96 |
style.uninstallDefaults(context); |
|
97 |
context.dispose(); |
|
98 |
style = null; |
|
99 |
} |
|
100 |
||
4394 | 101 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
102 |
* {@inheritDoc} |
4394 | 103 |
*/ |
104 |
@Override |
|
2 | 105 |
protected void uninstallListeners() { |
106 |
super.uninstallListeners(); |
|
107 |
menuBar.removePropertyChangeListener(this); |
|
108 |
} |
|
109 |
||
4394 | 110 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
111 |
* {@inheritDoc} |
4394 | 112 |
*/ |
113 |
@Override |
|
2 | 114 |
public SynthContext getContext(JComponent c) { |
115 |
return getContext(c, getComponentState(c)); |
|
116 |
} |
|
117 |
||
118 |
private SynthContext getContext(JComponent c, int state) { |
|
119 |
return SynthContext.getContext(SynthContext.class, c, |
|
120 |
SynthLookAndFeel.getRegion(c), style, state); |
|
121 |
} |
|
122 |
||
123 |
private int getComponentState(JComponent c) { |
|
124 |
return SynthLookAndFeel.getComponentState(c); |
|
125 |
} |
|
126 |
||
4394 | 127 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
128 |
* Notifies this UI delegate to repaint the specified component. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
129 |
* This method paints the component background, then calls |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
130 |
* the {@link #paint(SynthContext,Graphics)} method. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
131 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
132 |
* <p>In general, this method does not need to be overridden by subclasses. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
133 |
* All Look and Feel rendering code should reside in the {@code paint} method. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
134 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
135 |
* @param g the {@code Graphics} object used for painting |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
136 |
* @param c the component being painted |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
137 |
* @see #paint(SynthContext,Graphics) |
4394 | 138 |
*/ |
139 |
@Override |
|
2 | 140 |
public void update(Graphics g, JComponent c) { |
141 |
SynthContext context = getContext(c); |
|
142 |
||
143 |
SynthLookAndFeel.update(context, g); |
|
144 |
context.getPainter().paintMenuBarBackground(context, |
|
145 |
g, 0, 0, c.getWidth(), c.getHeight()); |
|
146 |
paint(context, g); |
|
147 |
context.dispose(); |
|
148 |
} |
|
149 |
||
4394 | 150 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
151 |
* Paints the specified component according to the Look and Feel. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
152 |
* <p>This method is not used by Synth Look and Feel. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
153 |
* Painting is handled by the {@link #paint(SynthContext,Graphics)} method. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
154 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
155 |
* @param g the {@code Graphics} object used for painting |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
156 |
* @param c the component being painted |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
157 |
* @see #paint(SynthContext,Graphics) |
4394 | 158 |
*/ |
159 |
@Override |
|
2 | 160 |
public void paint(Graphics g, JComponent c) { |
161 |
SynthContext context = getContext(c); |
|
162 |
||
163 |
paint(context, g); |
|
164 |
context.dispose(); |
|
165 |
} |
|
166 |
||
4394 | 167 |
/** |
168 |
* Paints the specified component. This implementation does nothing. |
|
169 |
* |
|
170 |
* @param context context for the component being painted |
|
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
171 |
* @param g the {@code Graphics} object used for painting |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
172 |
* @see #update(Graphics,JComponent) |
4394 | 173 |
*/ |
2 | 174 |
protected void paint(SynthContext context, Graphics g) { |
175 |
} |
|
176 |
||
4394 | 177 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
178 |
* {@inheritDoc} |
4394 | 179 |
*/ |
180 |
@Override |
|
2 | 181 |
public void paintBorder(SynthContext context, Graphics g, int x, |
182 |
int y, int w, int h) { |
|
183 |
context.getPainter().paintMenuBarBorder(context, g, x, y, w, h); |
|
184 |
} |
|
185 |
||
4394 | 186 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
187 |
* {@inheritDoc} |
4394 | 188 |
*/ |
189 |
@Override |
|
2 | 190 |
public void propertyChange(PropertyChangeEvent e) { |
191 |
if (SynthLookAndFeel.shouldUpdateStyle(e)) { |
|
192 |
updateStyle((JMenuBar)e.getSource()); |
|
193 |
} |
|
194 |
} |
|
195 |
} |