author | peterz |
Thu, 28 Jan 2010 17:06:54 +0300 | |
changeset 4848 | ffcc849b9351 |
parent 4394 | 92a8ec883f5d |
child 4962 | 8e27c99de375 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* Copyright 2002-2006 Sun Microsystems, Inc. All Rights Reserved. |
|
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 |
||
2658 | 28 |
import java.awt.Component; |
29 |
import java.awt.Container; |
|
30 |
import java.awt.Dimension; |
|
31 |
import java.awt.Graphics; |
|
32 |
import java.awt.Insets; |
|
33 |
import java.awt.LayoutManager; |
|
34 |
import java.awt.Rectangle; |
|
35 |
import java.beans.PropertyChangeEvent; |
|
36 |
import java.beans.PropertyChangeListener; |
|
37 |
import javax.swing.Box; |
|
38 |
import javax.swing.Icon; |
|
39 |
import javax.swing.JComponent; |
|
40 |
import javax.swing.JSeparator; |
|
41 |
import javax.swing.JToolBar; |
|
42 |
import javax.swing.plaf.ComponentUI; |
|
2 | 43 |
import javax.swing.plaf.basic.BasicToolBarUI; |
2658 | 44 |
import sun.swing.plaf.synth.SynthIcon; |
2 | 45 |
|
46 |
/** |
|
4394 | 47 |
* Provides the Synth L&F UI delegate for |
48 |
* {@link javax.swing.JToolBar}. |
|
2 | 49 |
* |
4394 | 50 |
* @since 1.7 |
2 | 51 |
*/ |
4394 | 52 |
public class SynthToolBarUI extends BasicToolBarUI |
53 |
implements PropertyChangeListener, SynthUI { |
|
54 |
private Icon handleIcon = null; |
|
55 |
private Rectangle contentRect = new Rectangle(); |
|
2 | 56 |
|
57 |
private SynthStyle style; |
|
58 |
private SynthStyle contentStyle; |
|
59 |
private SynthStyle dragWindowStyle; |
|
60 |
||
4394 | 61 |
/** |
62 |
* Creates a new UI object for the given component. |
|
63 |
* |
|
64 |
* @param c component to create UI object for |
|
65 |
* @return the UI object |
|
66 |
*/ |
|
2 | 67 |
public static ComponentUI createUI(JComponent c) { |
68 |
return new SynthToolBarUI(); |
|
69 |
} |
|
70 |
||
4394 | 71 |
/** |
72 |
* @inheritDoc |
|
73 |
*/ |
|
2658 | 74 |
@Override |
2 | 75 |
protected void installDefaults() { |
76 |
toolBar.setLayout(createLayout()); |
|
77 |
updateStyle(toolBar); |
|
78 |
} |
|
79 |
||
4394 | 80 |
/** |
81 |
* @inheritDoc |
|
82 |
*/ |
|
2658 | 83 |
@Override |
2 | 84 |
protected void installListeners() { |
85 |
super.installListeners(); |
|
86 |
toolBar.addPropertyChangeListener(this); |
|
87 |
} |
|
88 |
||
4394 | 89 |
/** |
90 |
* @inheritDoc |
|
91 |
*/ |
|
2658 | 92 |
@Override |
2 | 93 |
protected void uninstallListeners() { |
94 |
super.uninstallListeners(); |
|
95 |
toolBar.removePropertyChangeListener(this); |
|
96 |
} |
|
97 |
||
98 |
private void updateStyle(JToolBar c) { |
|
2658 | 99 |
SynthContext context = getContext( |
100 |
c, Region.TOOL_BAR_CONTENT, null, ENABLED); |
|
101 |
contentStyle = SynthLookAndFeel.updateStyle(context, this); |
|
102 |
context.dispose(); |
|
103 |
||
104 |
context = getContext(c, Region.TOOL_BAR_DRAG_WINDOW, null, ENABLED); |
|
105 |
dragWindowStyle = SynthLookAndFeel.updateStyle(context, this); |
|
106 |
context.dispose(); |
|
107 |
||
108 |
context = getContext(c, ENABLED); |
|
2 | 109 |
SynthStyle oldStyle = style; |
110 |
||
111 |
style = SynthLookAndFeel.updateStyle(context, this); |
|
112 |
if (oldStyle != style) { |
|
113 |
handleIcon = |
|
114 |
style.getIcon(context, "ToolBar.handleIcon"); |
|
115 |
if (oldStyle != null) { |
|
116 |
uninstallKeyboardActions(); |
|
117 |
installKeyboardActions(); |
|
118 |
} |
|
119 |
} |
|
120 |
context.dispose(); |
|
121 |
} |
|
122 |
||
4394 | 123 |
/** |
124 |
* @inheritDoc |
|
125 |
*/ |
|
2658 | 126 |
@Override |
2 | 127 |
protected void uninstallDefaults() { |
128 |
SynthContext context = getContext(toolBar, ENABLED); |
|
129 |
||
130 |
style.uninstallDefaults(context); |
|
131 |
context.dispose(); |
|
132 |
style = null; |
|
133 |
||
134 |
handleIcon = null; |
|
135 |
||
2658 | 136 |
context = getContext(toolBar, Region.TOOL_BAR_CONTENT, |
137 |
contentStyle, ENABLED); |
|
2 | 138 |
contentStyle.uninstallDefaults(context); |
139 |
context.dispose(); |
|
140 |
contentStyle = null; |
|
141 |
||
2658 | 142 |
context = getContext(toolBar, Region.TOOL_BAR_DRAG_WINDOW, |
143 |
dragWindowStyle, ENABLED); |
|
2 | 144 |
dragWindowStyle.uninstallDefaults(context); |
145 |
context.dispose(); |
|
146 |
dragWindowStyle = null; |
|
147 |
||
148 |
toolBar.setLayout(null); |
|
149 |
} |
|
150 |
||
4394 | 151 |
/** |
152 |
* @inheritDoc |
|
153 |
*/ |
|
2658 | 154 |
@Override |
155 |
protected void installComponents() {} |
|
2 | 156 |
|
4394 | 157 |
/** |
158 |
* @inheritDoc |
|
159 |
*/ |
|
2658 | 160 |
@Override |
161 |
protected void uninstallComponents() {} |
|
2 | 162 |
|
4394 | 163 |
/** |
164 |
* Creates a {@code LayoutManager} to use with the toolbar. |
|
165 |
* |
|
166 |
* @return a {@code LayoutManager} instance |
|
167 |
*/ |
|
2 | 168 |
protected LayoutManager createLayout() { |
169 |
return new SynthToolBarLayoutManager(); |
|
170 |
} |
|
171 |
||
4394 | 172 |
/** |
173 |
* @inheritDoc |
|
174 |
*/ |
|
175 |
@Override |
|
2 | 176 |
public SynthContext getContext(JComponent c) { |
4394 | 177 |
return getContext(c, SynthLookAndFeel.getComponentState(c)); |
2 | 178 |
} |
179 |
||
180 |
private SynthContext getContext(JComponent c, int state) { |
|
181 |
return SynthContext.getContext(SynthContext.class, c, |
|
182 |
SynthLookAndFeel.getRegion(c), style, state); |
|
183 |
} |
|
184 |
||
2658 | 185 |
private SynthContext getContext(JComponent c, Region region, SynthStyle style) { |
186 |
return SynthContext.getContext(SynthContext.class, c, region, |
|
187 |
style, getComponentState(c, region)); |
|
2 | 188 |
} |
189 |
||
2658 | 190 |
private SynthContext getContext(JComponent c, Region region, |
191 |
SynthStyle style, int state) { |
|
2 | 192 |
return SynthContext.getContext(SynthContext.class, c, region, |
2658 | 193 |
style, state); |
2 | 194 |
} |
195 |
||
196 |
private int getComponentState(JComponent c, Region region) { |
|
197 |
return SynthLookAndFeel.getComponentState(c); |
|
198 |
} |
|
199 |
||
4394 | 200 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
201 |
* 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
|
202 |
* 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
|
203 |
* 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
|
204 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
205 |
* <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
|
206 |
* 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
|
207 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
208 |
* @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
|
209 |
* @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
|
210 |
* @see #paint(SynthContext,Graphics) |
4394 | 211 |
*/ |
2658 | 212 |
@Override |
2 | 213 |
public void update(Graphics g, JComponent c) { |
214 |
SynthContext context = getContext(c); |
|
215 |
||
216 |
SynthLookAndFeel.update(context, g); |
|
217 |
context.getPainter().paintToolBarBackground(context, |
|
218 |
g, 0, 0, c.getWidth(), c.getHeight(), |
|
219 |
toolBar.getOrientation()); |
|
220 |
paint(context, g); |
|
221 |
context.dispose(); |
|
222 |
} |
|
223 |
||
4394 | 224 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
225 |
* 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
|
226 |
* <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
|
227 |
* 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
|
228 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
229 |
* @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
|
230 |
* @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
|
231 |
* @see #paint(SynthContext,Graphics) |
4394 | 232 |
*/ |
2658 | 233 |
@Override |
2 | 234 |
public void paint(Graphics g, JComponent c) { |
235 |
SynthContext context = getContext(c); |
|
236 |
||
237 |
paint(context, g); |
|
238 |
context.dispose(); |
|
239 |
} |
|
240 |
||
4394 | 241 |
/** |
242 |
* @inheritDoc |
|
243 |
*/ |
|
244 |
@Override |
|
2 | 245 |
public void paintBorder(SynthContext context, Graphics g, int x, |
246 |
int y, int w, int h) { |
|
247 |
context.getPainter().paintToolBarBorder(context, g, x, y, w, h, |
|
248 |
toolBar.getOrientation()); |
|
249 |
} |
|
250 |
||
251 |
// Overloaded to do nothing so we can share listeners. |
|
4394 | 252 |
/** |
253 |
* @inheritDoc |
|
254 |
*/ |
|
2658 | 255 |
@Override |
2 | 256 |
protected void setBorderToNonRollover(Component c) {} |
257 |
||
258 |
// Overloaded to do nothing so we can share listeners. |
|
4394 | 259 |
/** |
260 |
* @inheritDoc |
|
261 |
*/ |
|
2658 | 262 |
@Override |
2 | 263 |
protected void setBorderToRollover(Component c) {} |
264 |
||
265 |
// Overloaded to do nothing so we can share listeners. |
|
4394 | 266 |
/** |
267 |
* @inheritDoc |
|
268 |
*/ |
|
2658 | 269 |
@Override |
2 | 270 |
protected void setBorderToNormal(Component c) {} |
271 |
||
4394 | 272 |
/** |
273 |
* Paints the toolbar. |
|
274 |
* |
|
275 |
* @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
|
276 |
* @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
|
277 |
* @see #update(Graphics,JComponent) |
4394 | 278 |
*/ |
2 | 279 |
protected void paint(SynthContext context, Graphics g) { |
280 |
if (handleIcon != null && toolBar.isFloatable()) { |
|
281 |
int startX = toolBar.getComponentOrientation().isLeftToRight() ? |
|
282 |
0 : toolBar.getWidth() - |
|
283 |
SynthIcon.getIconWidth(handleIcon, context); |
|
284 |
SynthIcon.paintIcon(handleIcon, context, g, startX, 0, |
|
285 |
SynthIcon.getIconWidth(handleIcon, context), |
|
286 |
SynthIcon.getIconHeight(handleIcon, context)); |
|
287 |
} |
|
288 |
||
2658 | 289 |
SynthContext subcontext = getContext( |
290 |
toolBar, Region.TOOL_BAR_CONTENT, contentStyle); |
|
2 | 291 |
paintContent(subcontext, g, contentRect); |
292 |
subcontext.dispose(); |
|
293 |
} |
|
294 |
||
4394 | 295 |
/** |
296 |
* Paints the toolbar content. |
|
297 |
* |
|
298 |
* @param context context for the component being painted |
|
299 |
* @param g {@code Graphics} object used for painting |
|
300 |
* @param bounds bounding box for the toolbar |
|
301 |
*/ |
|
302 |
protected void paintContent(SynthContext context, Graphics g, |
|
2 | 303 |
Rectangle bounds) { |
304 |
SynthLookAndFeel.updateSubregion(context, g, bounds); |
|
305 |
context.getPainter().paintToolBarContentBackground(context, g, |
|
306 |
bounds.x, bounds.y, bounds.width, bounds.height, |
|
307 |
toolBar.getOrientation()); |
|
308 |
context.getPainter().paintToolBarContentBorder(context, g, |
|
309 |
bounds.x, bounds.y, bounds.width, bounds.height, |
|
310 |
toolBar.getOrientation()); |
|
311 |
} |
|
312 |
||
4394 | 313 |
/** |
314 |
* @inheritDoc |
|
315 |
*/ |
|
2658 | 316 |
@Override |
2 | 317 |
protected void paintDragWindow(Graphics g) { |
318 |
int w = dragWindow.getWidth(); |
|
319 |
int h = dragWindow.getHeight(); |
|
2658 | 320 |
SynthContext context = getContext( |
321 |
toolBar, Region.TOOL_BAR_DRAG_WINDOW, dragWindowStyle); |
|
322 |
SynthLookAndFeel.updateSubregion( |
|
323 |
context, g, new Rectangle(0, 0, w, h)); |
|
2 | 324 |
context.getPainter().paintToolBarDragWindowBackground(context, |
325 |
g, 0, 0, w, h, |
|
326 |
dragWindow.getOrientation()); |
|
327 |
context.getPainter().paintToolBarDragWindowBorder(context, g, 0, 0, w, h, |
|
328 |
dragWindow.getOrientation()); |
|
329 |
context.dispose(); |
|
330 |
} |
|
331 |
||
332 |
// |
|
333 |
// PropertyChangeListener |
|
334 |
// |
|
335 |
||
4394 | 336 |
/** |
337 |
* @inheritDoc |
|
338 |
*/ |
|
339 |
@Override |
|
2 | 340 |
public void propertyChange(PropertyChangeEvent e) { |
341 |
if (SynthLookAndFeel.shouldUpdateStyle(e)) { |
|
342 |
updateStyle((JToolBar)e.getSource()); |
|
343 |
} |
|
344 |
} |
|
345 |
||
346 |
||
347 |
class SynthToolBarLayoutManager implements LayoutManager { |
|
348 |
public void addLayoutComponent(String name, Component comp) {} |
|
349 |
||
350 |
public void removeLayoutComponent(Component comp) {} |
|
351 |
||
352 |
public Dimension minimumLayoutSize(Container parent) { |
|
353 |
JToolBar tb = (JToolBar)parent; |
|
354 |
Insets insets = tb.getInsets(); |
|
355 |
Dimension dim = new Dimension(); |
|
356 |
SynthContext context = getContext(tb); |
|
357 |
||
358 |
if (tb.getOrientation() == JToolBar.HORIZONTAL) { |
|
359 |
dim.width = tb.isFloatable() ? |
|
360 |
SynthIcon.getIconWidth(handleIcon, context) : 0; |
|
361 |
Dimension compDim; |
|
362 |
for (int i = 0; i < tb.getComponentCount(); i++) { |
|
363 |
compDim = tb.getComponent(i).getMinimumSize(); |
|
364 |
dim.width += compDim.width; |
|
365 |
dim.height = Math.max(dim.height, compDim.height); |
|
366 |
} |
|
367 |
} else { |
|
368 |
dim.height = tb.isFloatable() ? |
|
369 |
SynthIcon.getIconHeight(handleIcon, context) : 0; |
|
370 |
Dimension compDim; |
|
371 |
for (int i = 0; i < tb.getComponentCount(); i++) { |
|
372 |
compDim = tb.getComponent(i).getMinimumSize(); |
|
373 |
dim.width = Math.max(dim.width, compDim.width); |
|
374 |
dim.height += compDim.height; |
|
375 |
} |
|
376 |
} |
|
377 |
dim.width += insets.left + insets.right; |
|
378 |
dim.height += insets.top + insets.bottom; |
|
379 |
||
380 |
context.dispose(); |
|
381 |
return dim; |
|
382 |
} |
|
383 |
||
384 |
public Dimension preferredLayoutSize(Container parent) { |
|
385 |
JToolBar tb = (JToolBar)parent; |
|
386 |
Insets insets = tb.getInsets(); |
|
387 |
Dimension dim = new Dimension(); |
|
388 |
SynthContext context = getContext(tb); |
|
389 |
||
390 |
if (tb.getOrientation() == JToolBar.HORIZONTAL) { |
|
391 |
dim.width = tb.isFloatable() ? |
|
392 |
SynthIcon.getIconWidth(handleIcon, context) : 0; |
|
393 |
Dimension compDim; |
|
394 |
for (int i = 0; i < tb.getComponentCount(); i++) { |
|
395 |
compDim = tb.getComponent(i).getPreferredSize(); |
|
396 |
dim.width += compDim.width; |
|
397 |
dim.height = Math.max(dim.height, compDim.height); |
|
398 |
} |
|
399 |
} else { |
|
400 |
dim.height = tb.isFloatable() ? |
|
401 |
SynthIcon.getIconHeight(handleIcon, context) : 0; |
|
402 |
Dimension compDim; |
|
403 |
for (int i = 0; i < tb.getComponentCount(); i++) { |
|
404 |
compDim = tb.getComponent(i).getPreferredSize(); |
|
405 |
dim.width = Math.max(dim.width, compDim.width); |
|
406 |
dim.height += compDim.height; |
|
407 |
} |
|
408 |
} |
|
409 |
dim.width += insets.left + insets.right; |
|
410 |
dim.height += insets.top + insets.bottom; |
|
411 |
||
412 |
context.dispose(); |
|
413 |
return dim; |
|
414 |
} |
|
415 |
||
416 |
public void layoutContainer(Container parent) { |
|
417 |
JToolBar tb = (JToolBar)parent; |
|
418 |
Insets insets = tb.getInsets(); |
|
419 |
boolean ltr = tb.getComponentOrientation().isLeftToRight(); |
|
420 |
SynthContext context = getContext(tb); |
|
421 |
||
422 |
Component c; |
|
423 |
Dimension d; |
|
2658 | 424 |
|
425 |
// JToolBar by default uses a somewhat modified BoxLayout as |
|
426 |
// its layout manager. For compatibility reasons, we want to |
|
427 |
// support Box "glue" as a way to move things around on the |
|
428 |
// toolbar. "glue" is represented in BoxLayout as a Box.Filler |
|
429 |
// with a minimum and preferred size of (0,0). |
|
430 |
// So what we do here is find the number of such glue fillers |
|
431 |
// and figure out how much space should be allocated to them. |
|
432 |
int glueCount = 0; |
|
433 |
for (int i=0; i<tb.getComponentCount(); i++) { |
|
434 |
if (isGlue(tb.getComponent(i))) glueCount++; |
|
435 |
} |
|
436 |
||
2 | 437 |
if (tb.getOrientation() == JToolBar.HORIZONTAL) { |
438 |
int handleWidth = tb.isFloatable() ? |
|
439 |
SynthIcon.getIconWidth(handleIcon, context) : 0; |
|
440 |
||
441 |
// Note: contentRect does not take insets into account |
|
442 |
// since it is used for determining the bounds that are |
|
443 |
// passed to paintToolBarContentBackground(). |
|
444 |
contentRect.x = ltr ? handleWidth : 0; |
|
445 |
contentRect.y = 0; |
|
446 |
contentRect.width = tb.getWidth() - handleWidth; |
|
447 |
contentRect.height = tb.getHeight(); |
|
448 |
||
449 |
// However, we do take the insets into account here for |
|
450 |
// the purposes of laying out the toolbar child components. |
|
451 |
int x = ltr ? |
|
452 |
handleWidth + insets.left : |
|
453 |
tb.getWidth() - handleWidth - insets.right; |
|
454 |
int baseY = insets.top; |
|
455 |
int baseH = tb.getHeight() - insets.top - insets.bottom; |
|
456 |
||
2658 | 457 |
// we need to get the minimum width for laying things out |
458 |
// so that we can calculate how much empty space needs to |
|
459 |
// be distributed among the "glue", if any |
|
460 |
int extraSpacePerGlue = 0; |
|
461 |
if (glueCount > 0) { |
|
462 |
int minWidth = minimumLayoutSize(parent).width; |
|
463 |
extraSpacePerGlue = (tb.getWidth() - minWidth) / glueCount; |
|
464 |
if (extraSpacePerGlue < 0) extraSpacePerGlue = 0; |
|
465 |
} |
|
466 |
||
2 | 467 |
for (int i = 0; i < tb.getComponentCount(); i++) { |
468 |
c = tb.getComponent(i); |
|
469 |
d = c.getPreferredSize(); |
|
470 |
int y, h; |
|
471 |
if (d.height >= baseH || c instanceof JSeparator) { |
|
472 |
// Fill available height |
|
473 |
y = baseY; |
|
474 |
h = baseH; |
|
475 |
} else { |
|
476 |
// Center component vertically in the available space |
|
477 |
y = baseY + (baseH / 2) - (d.height / 2); |
|
478 |
h = d.height; |
|
479 |
} |
|
2658 | 480 |
//if the component is a "glue" component then add to its |
481 |
//width the extraSpacePerGlue it is due |
|
482 |
if (isGlue(c)) d.width += extraSpacePerGlue; |
|
2 | 483 |
c.setBounds(ltr ? x : x - d.width, y, d.width, h); |
484 |
x = ltr ? x + d.width : x - d.width; |
|
485 |
} |
|
486 |
} else { |
|
487 |
int handleHeight = tb.isFloatable() ? |
|
488 |
SynthIcon.getIconHeight(handleIcon, context) : 0; |
|
489 |
||
490 |
// See notes above regarding the use of insets |
|
491 |
contentRect.x = 0; |
|
492 |
contentRect.y = handleHeight; |
|
493 |
contentRect.width = tb.getWidth(); |
|
494 |
contentRect.height = tb.getHeight() - handleHeight; |
|
495 |
||
496 |
int baseX = insets.left; |
|
497 |
int baseW = tb.getWidth() - insets.left - insets.right; |
|
498 |
int y = handleHeight + insets.top; |
|
499 |
||
2658 | 500 |
// we need to get the minimum height for laying things out |
501 |
// so that we can calculate how much empty space needs to |
|
502 |
// be distributed among the "glue", if any |
|
503 |
int extraSpacePerGlue = 0; |
|
504 |
if (glueCount > 0) { |
|
505 |
int minHeight = minimumLayoutSize(parent).height; |
|
506 |
extraSpacePerGlue = (tb.getHeight() - minHeight) / glueCount; |
|
507 |
if (extraSpacePerGlue < 0) extraSpacePerGlue = 0; |
|
508 |
} |
|
509 |
||
2 | 510 |
for (int i = 0; i < tb.getComponentCount(); i++) { |
511 |
c = tb.getComponent(i); |
|
512 |
d = c.getPreferredSize(); |
|
513 |
int x, w; |
|
514 |
if (d.width >= baseW || c instanceof JSeparator) { |
|
515 |
// Fill available width |
|
516 |
x = baseX; |
|
517 |
w = baseW; |
|
518 |
} else { |
|
519 |
// Center component horizontally in the available space |
|
520 |
x = baseX + (baseW / 2) - (d.width / 2); |
|
521 |
w = d.width; |
|
522 |
} |
|
2658 | 523 |
//if the component is a "glue" component then add to its |
524 |
//height the extraSpacePerGlue it is due |
|
525 |
if (isGlue(c)) d.height += extraSpacePerGlue; |
|
2 | 526 |
c.setBounds(x, y, w, d.height); |
527 |
y += d.height; |
|
528 |
} |
|
529 |
} |
|
530 |
context.dispose(); |
|
531 |
} |
|
2658 | 532 |
|
533 |
private boolean isGlue(Component c) { |
|
534 |
if (c instanceof Box.Filler) { |
|
535 |
Box.Filler f = (Box.Filler)c; |
|
536 |
Dimension min = f.getMinimumSize(); |
|
537 |
Dimension pref = f.getPreferredSize(); |
|
538 |
return min.width == 0 && min.height == 0 && |
|
539 |
pref.width == 0 && pref.height == 0; |
|
540 |
} |
|
541 |
return false; |
|
542 |
} |
|
2 | 543 |
} |
544 |
} |