author | xdono |
Wed, 02 Jul 2008 12:55:45 -0700 | |
changeset 715 | f16baef3a20e |
parent 438 | 2ae294e4518c |
child 1299 | 027d966d5658 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
715 | 2 |
* Copyright 2002-2008 Sun Microsystems, Inc. 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 |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
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 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package javax.swing.plaf.synth; |
|
27 |
||
28 |
||
29 |
import java.awt.*; |
|
30 |
import java.awt.event.*; |
|
31 |
import java.beans.*; |
|
32 |
import java.util.*; |
|
33 |
import javax.swing.*; |
|
34 |
import javax.swing.event.*; |
|
35 |
import javax.swing.plaf.*; |
|
36 |
import javax.swing.plaf.basic.*; |
|
37 |
import sun.swing.plaf.synth.SynthUI; |
|
38 |
||
39 |
||
40 |
/** |
|
41 |
* Synth's SplitPaneUI. |
|
42 |
* |
|
43 |
* @author Scott Violet |
|
44 |
*/ |
|
45 |
class SynthSplitPaneUI extends BasicSplitPaneUI implements |
|
46 |
PropertyChangeListener, SynthUI { |
|
47 |
/** |
|
48 |
* Keys to use for forward focus traversal when the JComponent is |
|
49 |
* managing focus. |
|
50 |
*/ |
|
51 |
private static Set managingFocusForwardTraversalKeys; |
|
52 |
||
53 |
/** |
|
54 |
* Keys to use for backward focus traversal when the JComponent is |
|
55 |
* managing focus. |
|
56 |
*/ |
|
57 |
private static Set managingFocusBackwardTraversalKeys; |
|
58 |
||
59 |
/** |
|
60 |
* Style for the JSplitPane. |
|
61 |
*/ |
|
62 |
private SynthStyle style; |
|
63 |
/** |
|
64 |
* Style for the divider. |
|
65 |
*/ |
|
66 |
private SynthStyle dividerStyle; |
|
67 |
||
68 |
||
69 |
/** |
|
70 |
* Creates a new SynthSplitPaneUI instance |
|
71 |
*/ |
|
72 |
public static ComponentUI createUI(JComponent x) { |
|
73 |
return new SynthSplitPaneUI(); |
|
74 |
} |
|
75 |
||
76 |
/** |
|
77 |
* Installs the UI defaults. |
|
78 |
*/ |
|
79 |
protected void installDefaults() { |
|
80 |
updateStyle(splitPane); |
|
81 |
||
82 |
setOrientation(splitPane.getOrientation()); |
|
83 |
setContinuousLayout(splitPane.isContinuousLayout()); |
|
84 |
||
85 |
resetLayoutManager(); |
|
86 |
||
87 |
/* Install the nonContinuousLayoutDivider here to avoid having to |
|
88 |
add/remove everything later. */ |
|
89 |
if(nonContinuousLayoutDivider == null) { |
|
90 |
setNonContinuousLayoutDivider( |
|
91 |
createDefaultNonContinuousLayoutDivider(), |
|
92 |
true); |
|
93 |
} else { |
|
94 |
setNonContinuousLayoutDivider(nonContinuousLayoutDivider, true); |
|
95 |
} |
|
96 |
||
97 |
// focus forward traversal key |
|
98 |
if (managingFocusForwardTraversalKeys==null) { |
|
99 |
managingFocusForwardTraversalKeys = new HashSet(); |
|
100 |
managingFocusForwardTraversalKeys.add( |
|
101 |
KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0)); |
|
102 |
} |
|
103 |
splitPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, |
|
104 |
managingFocusForwardTraversalKeys); |
|
105 |
// focus backward traversal key |
|
106 |
if (managingFocusBackwardTraversalKeys==null) { |
|
107 |
managingFocusBackwardTraversalKeys = new HashSet(); |
|
108 |
managingFocusBackwardTraversalKeys.add( |
|
109 |
KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK)); |
|
110 |
} |
|
111 |
splitPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, |
|
112 |
managingFocusBackwardTraversalKeys); |
|
113 |
} |
|
114 |
||
115 |
private void updateStyle(JSplitPane splitPane) { |
|
116 |
SynthContext context = getContext(splitPane, Region.SPLIT_PANE_DIVIDER, |
|
117 |
ENABLED); |
|
118 |
SynthStyle oldDividerStyle = dividerStyle; |
|
119 |
dividerStyle = SynthLookAndFeel.updateStyle(context, this); |
|
120 |
context.dispose(); |
|
121 |
||
122 |
context = getContext(splitPane, ENABLED); |
|
123 |
SynthStyle oldStyle = style; |
|
124 |
||
125 |
style = SynthLookAndFeel.updateStyle(context, this); |
|
126 |
||
127 |
if (style != oldStyle) { |
|
128 |
Object value = style.get(context, "SplitPane.size"); |
|
129 |
if (value == null) { |
|
438
2ae294e4518c
6613529: Avoid duplicate object creation within JDK packages
dav
parents:
2
diff
changeset
|
130 |
value = Integer.valueOf(6); |
2 | 131 |
} |
132 |
LookAndFeel.installProperty(splitPane, "dividerSize", value); |
|
133 |
||
134 |
value = style.get(context, "SplitPane.oneTouchExpandable"); |
|
135 |
if (value != null) { |
|
136 |
LookAndFeel.installProperty(splitPane, "oneTouchExpandable", value); |
|
137 |
} |
|
138 |
||
139 |
if (divider != null) { |
|
140 |
splitPane.remove(divider); |
|
141 |
divider.setDividerSize(splitPane.getDividerSize()); |
|
142 |
} |
|
143 |
if (oldStyle != null) { |
|
144 |
uninstallKeyboardActions(); |
|
145 |
installKeyboardActions(); |
|
146 |
} |
|
147 |
} |
|
148 |
if (style != oldStyle || dividerStyle != oldDividerStyle) { |
|
149 |
// Only way to force BasicSplitPaneDivider to reread the |
|
150 |
// necessary properties. |
|
151 |
if (divider != null) { |
|
152 |
splitPane.remove(divider); |
|
153 |
} |
|
154 |
divider = createDefaultDivider(); |
|
155 |
divider.setBasicSplitPaneUI(this); |
|
156 |
splitPane.add(divider, JSplitPane.DIVIDER); |
|
157 |
} |
|
158 |
context.dispose(); |
|
159 |
} |
|
160 |
||
161 |
/** |
|
162 |
* Installs the event listeners for the UI. |
|
163 |
*/ |
|
164 |
protected void installListeners() { |
|
165 |
super.installListeners(); |
|
166 |
splitPane.addPropertyChangeListener(this); |
|
167 |
} |
|
168 |
||
169 |
/** |
|
170 |
* Uninstalls the UI defaults. |
|
171 |
*/ |
|
172 |
protected void uninstallDefaults() { |
|
173 |
SynthContext context = getContext(splitPane, ENABLED); |
|
174 |
||
175 |
style.uninstallDefaults(context); |
|
176 |
context.dispose(); |
|
177 |
style = null; |
|
178 |
||
179 |
context = getContext(splitPane, Region.SPLIT_PANE_DIVIDER, ENABLED); |
|
180 |
dividerStyle.uninstallDefaults(context); |
|
181 |
context.dispose(); |
|
182 |
dividerStyle = null; |
|
183 |
||
184 |
super.uninstallDefaults(); |
|
185 |
} |
|
186 |
||
187 |
||
188 |
/** |
|
189 |
* Uninstalls the event listeners for the UI. |
|
190 |
*/ |
|
191 |
protected void uninstallListeners() { |
|
192 |
super.uninstallListeners(); |
|
193 |
splitPane.removePropertyChangeListener(this); |
|
194 |
} |
|
195 |
||
196 |
||
197 |
public SynthContext getContext(JComponent c) { |
|
198 |
return getContext(c, getComponentState(c)); |
|
199 |
} |
|
200 |
||
201 |
private SynthContext getContext(JComponent c, int state) { |
|
202 |
return SynthContext.getContext(SynthContext.class, c, |
|
203 |
SynthLookAndFeel.getRegion(c), style, state); |
|
204 |
} |
|
205 |
||
206 |
private Region getRegion(JComponent c) { |
|
207 |
return SynthLookAndFeel.getRegion(c); |
|
208 |
} |
|
209 |
||
210 |
private int getComponentState(JComponent c) { |
|
211 |
return SynthLookAndFeel.getComponentState(c); |
|
212 |
} |
|
213 |
||
214 |
SynthContext getContext(JComponent c, Region region) { |
|
215 |
return getContext(c, region, getComponentState(c, region)); |
|
216 |
} |
|
217 |
||
218 |
private SynthContext getContext(JComponent c, Region region, int state) { |
|
219 |
if (region == Region.SPLIT_PANE_DIVIDER) { |
|
220 |
return SynthContext.getContext(SynthContext.class, c, region, |
|
221 |
dividerStyle, state); |
|
222 |
} |
|
223 |
return SynthContext.getContext(SynthContext.class, c, region, |
|
224 |
style, state); |
|
225 |
} |
|
226 |
||
227 |
private int getComponentState(JComponent c, Region subregion) { |
|
228 |
int state = SynthLookAndFeel.getComponentState(c); |
|
229 |
||
230 |
if (divider.isMouseOver()) { |
|
231 |
state |= MOUSE_OVER; |
|
232 |
} |
|
233 |
return state; |
|
234 |
} |
|
235 |
||
236 |
||
237 |
public void propertyChange(PropertyChangeEvent e) { |
|
238 |
if (SynthLookAndFeel.shouldUpdateStyle(e)) { |
|
239 |
updateStyle((JSplitPane)e.getSource()); |
|
240 |
} |
|
241 |
} |
|
242 |
||
243 |
/** |
|
244 |
* Creates the default divider. |
|
245 |
*/ |
|
246 |
public BasicSplitPaneDivider createDefaultDivider() { |
|
247 |
SynthSplitPaneDivider divider = new SynthSplitPaneDivider(this); |
|
248 |
||
249 |
divider.setDividerSize(splitPane.getDividerSize()); |
|
250 |
return divider; |
|
251 |
} |
|
252 |
||
253 |
protected Component createDefaultNonContinuousLayoutDivider() { |
|
254 |
return new Canvas() { |
|
255 |
public void paint(Graphics g) { |
|
256 |
paintDragDivider(g, 0, 0, getWidth(), getHeight()); |
|
257 |
} |
|
258 |
}; |
|
259 |
} |
|
260 |
||
261 |
public void update(Graphics g, JComponent c) { |
|
262 |
SynthContext context = getContext(c); |
|
263 |
||
264 |
SynthLookAndFeel.update(context, g); |
|
265 |
context.getPainter().paintSplitPaneBackground(context, |
|
266 |
g, 0, 0, c.getWidth(), c.getHeight()); |
|
267 |
paint(context, g); |
|
268 |
context.dispose(); |
|
269 |
} |
|
270 |
||
271 |
public void paint(Graphics g, JComponent c) { |
|
272 |
SynthContext context = getContext(c); |
|
273 |
||
274 |
paint(context, g); |
|
275 |
context.dispose(); |
|
276 |
} |
|
277 |
||
278 |
protected void paint(SynthContext context, Graphics g) { |
|
279 |
// This is done to update package private variables in |
|
280 |
// BasicSplitPaneUI |
|
281 |
super.paint(g, splitPane); |
|
282 |
} |
|
283 |
||
284 |
||
285 |
public void paintBorder(SynthContext context, Graphics g, int x, |
|
286 |
int y, int w, int h) { |
|
287 |
context.getPainter().paintSplitPaneBorder(context, g, x, y, w, h); |
|
288 |
} |
|
289 |
||
290 |
private void paintDragDivider(Graphics g, int x, int y, int w, int h) { |
|
291 |
SynthContext context = getContext(splitPane,Region.SPLIT_PANE_DIVIDER); |
|
292 |
context.setComponentState(((context.getComponentState() | MOUSE_OVER) ^ |
|
293 |
MOUSE_OVER) | PRESSED); |
|
294 |
Shape oldClip = g.getClip(); |
|
295 |
g.clipRect(x, y, w, h); |
|
296 |
context.getPainter().paintSplitPaneDragDivider(context, g, x, y, w, h, |
|
297 |
splitPane.getOrientation()); |
|
298 |
g.setClip(oldClip); |
|
299 |
context.dispose(); |
|
300 |
} |
|
301 |
||
302 |
public void finishedPaintingChildren(JSplitPane jc, Graphics g) { |
|
303 |
if(jc == splitPane && getLastDragLocation() != -1 && |
|
304 |
!isContinuousLayout() && !draggingHW) { |
|
305 |
if(jc.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) { |
|
306 |
paintDragDivider(g, getLastDragLocation(), 0, dividerSize - 1, |
|
307 |
splitPane.getHeight() - 1); |
|
308 |
} else { |
|
309 |
paintDragDivider(g, 0, getLastDragLocation(), |
|
310 |
splitPane.getWidth() - 1, dividerSize - 1); |
|
311 |
} |
|
312 |
} |
|
313 |
} |
|
314 |
} |