44 |
import java.awt.Insets; |
import java.awt.Insets; |
45 |
import java.awt.LayoutManager; |
import java.awt.LayoutManager; |
46 |
import java.awt.Rectangle; |
import java.awt.Rectangle; |
47 |
|
import java.awt.Point; |
48 |
import java.io.Serializable; |
import java.io.Serializable; |
49 |
import javax.swing.border.Border; |
import javax.swing.border.Border; |
50 |
|
|
198 |
return null; |
return null; |
199 |
} |
} |
200 |
|
|
201 |
|
private static void maybeSetPreferredSize(JComponent src, Dimension dim) |
202 |
|
{ |
203 |
|
Dimension tmp = null; |
204 |
|
if (src != null) |
205 |
|
tmp = src.getPreferredSize(); |
206 |
|
if (tmp != null) |
207 |
|
dim.setSize(tmp); |
208 |
|
} |
209 |
|
|
210 |
|
private static void maybeSetMinimumSize(JComponent src, Dimension dim) |
211 |
|
{ |
212 |
|
Dimension tmp = null; |
213 |
|
if (src != null) |
214 |
|
tmp = src.getMinimumSize(); |
215 |
|
if (tmp != null) |
216 |
|
dim.setSize(tmp); |
217 |
|
} |
218 |
|
|
219 |
public Dimension preferredLayoutSize(Container parent) |
public Dimension preferredLayoutSize(Container parent) |
220 |
{ |
{ |
221 |
if (parent instanceof JScrollPane) |
if (parent != null && parent instanceof JScrollPane) |
222 |
{ |
{ |
223 |
JScrollPane sc = (JScrollPane) parent; |
JScrollPane sc = (JScrollPane) parent; |
224 |
synchronized (sc.getTreeLock ()) |
synchronized (sc.getTreeLock ()) |
236 |
Insets viewportInsets = null; |
Insets viewportInsets = null; |
237 |
|
|
238 |
if (viewportBorder != null) |
if (viewportBorder != null) |
239 |
|
{ |
240 |
viewportInsets = viewportBorder.getBorderInsets(parent); |
viewportInsets = viewportBorder.getBorderInsets(parent); |
241 |
|
if (viewportInsets != null) |
242 |
|
viewportInsetsSize.setSize(viewportInsets.left + viewportInsets.right, |
243 |
|
viewportInsets.top + viewportInsets.bottom); |
244 |
|
} |
245 |
|
|
246 |
if (insets != null) |
if (insets != null) |
247 |
insetsSize.setSize(insets.left + insets.right, |
insetsSize.setSize(insets.left + insets.right, |
248 |
insets.top + insets.bottom); |
insets.top + insets.bottom); |
249 |
|
|
250 |
if (viewport != null) |
if (viewport != null) |
251 |
viewportSize.setSize(viewport.getPreferredSize()); |
{ |
252 |
|
Component view = null; |
253 |
if (colHead != null) |
Scrollable scr = null; |
254 |
columnHeaderSize.setSize(colHead.getPreferredSize()); |
Dimension pref = null; |
255 |
|
|
256 |
if (rowHead != null) |
view = viewport.getView(); |
257 |
rowHeaderSize.setSize(rowHead.getPreferredSize()); |
if (view != null && view instanceof Scrollable) |
258 |
|
scr = (Scrollable) view; |
259 |
if (vsb != null) |
if (scr != null) |
260 |
verticalScrollBarSize.setSize(vsb.getPreferredSize()); |
pref = scr.getPreferredScrollableViewportSize(); |
261 |
|
if (pref == null) |
262 |
if (hsb != null) |
pref = viewport.getPreferredSize(); |
263 |
horizontalScrollBarSize.setSize(hsb.getPreferredSize()); |
if (pref != null) |
264 |
|
viewportSize.setSize(pref); |
265 |
/* |
} |
266 |
System.err.println("widths: [vp=" + viewportSize.width + |
|
267 |
", h=" + columnHeaderSize.width + |
maybeSetPreferredSize(colHead, columnHeaderSize); |
268 |
", sc=" + horizontalScrollBarSize.width + "]"); |
maybeSetPreferredSize(rowHead, rowHeaderSize); |
269 |
|
maybeSetPreferredSize(vsb, verticalScrollBarSize); |
270 |
System.err.println("heights: [vp=" + viewportSize.height + |
maybeSetPreferredSize(hsb, horizontalScrollBarSize); |
|
", h=" + rowHeaderSize.height + |
|
|
", sc=" + verticalScrollBarSize.height + "]"); |
|
|
*/ |
|
271 |
|
|
272 |
return new Dimension(insetsSize.width |
return new Dimension(insetsSize.width |
273 |
+ viewportSize.width |
+ viewportSize.width |
307 |
Insets viewportInsets = null; |
Insets viewportInsets = null; |
308 |
|
|
309 |
if (viewportBorder != null) |
if (viewportBorder != null) |
310 |
|
{ |
311 |
viewportInsets = viewportBorder.getBorderInsets(parent); |
viewportInsets = viewportBorder.getBorderInsets(parent); |
312 |
|
if (viewportInsets != null) |
313 |
|
viewportInsetsSize.setSize(viewportInsets.left + viewportInsets.right, |
314 |
|
viewportInsets.top + viewportInsets.bottom); |
315 |
|
} |
316 |
|
|
317 |
if (insets != null) |
if (insets != null) |
318 |
insetsSize.setSize(insets.left + insets.right, |
insetsSize.setSize(insets.left + insets.right, |
319 |
insets.top + insets.bottom); |
insets.top + insets.bottom); |
320 |
|
|
321 |
if (viewport != null) |
maybeSetMinimumSize(viewport, viewportSize); |
322 |
viewportSize.setSize(viewport.getMinimumSize()); |
maybeSetMinimumSize(colHead, columnHeaderSize); |
323 |
|
maybeSetMinimumSize(rowHead, rowHeaderSize); |
324 |
|
|
325 |
if (colHead != null) |
if (vsbPolicy != VERTICAL_SCROLLBAR_NEVER) |
326 |
columnHeaderSize.setSize(colHead.getMinimumSize()); |
maybeSetMinimumSize(vsb, verticalScrollBarSize); |
|
|
|
|
if (rowHead != null) |
|
|
rowHeaderSize.setSize(rowHead.getMinimumSize()); |
|
327 |
|
|
328 |
if (vsb != null |
if (hsbPolicy != HORIZONTAL_SCROLLBAR_NEVER) |
329 |
&& vsbPolicy != VERTICAL_SCROLLBAR_NEVER) |
maybeSetMinimumSize(hsb, horizontalScrollBarSize); |
|
verticalScrollBarSize.setSize(vsb.getMinimumSize()); |
|
|
|
|
|
if (hsb != null |
|
|
&& hsbPolicy != HORIZONTAL_SCROLLBAR_NEVER) |
|
|
horizontalScrollBarSize.setSize(hsb.getMinimumSize()); |
|
330 |
|
|
331 |
return new Dimension(insetsSize.width |
return new Dimension(insetsSize.width |
332 |
+ viewportSize.width |
+ viewportSize.width |
374 |
JScrollPane sc = (JScrollPane) parent; |
JScrollPane sc = (JScrollPane) parent; |
375 |
synchronized (sc.getTreeLock ()) |
synchronized (sc.getTreeLock ()) |
376 |
{ |
{ |
|
Rectangle scrollPaneBounds = sc.getBounds(); |
|
377 |
JViewport viewport = sc.getViewport(); |
JViewport viewport = sc.getViewport(); |
378 |
Dimension viewportSize = viewport.getSize(); |
Dimension viewSize = viewport.getViewSize(); |
379 |
Dimension viewSize = viewport.getView().getSize(); |
Point viewPos = viewport.getViewPosition(); |
380 |
|
|
381 |
int x1 = 0, x2 = 0, x3 = 0, x4 = 0; |
int x1 = 0, x2 = 0, x3 = 0, x4 = 0; |
382 |
int y1 = 0, y2 = 0, y3 = 0, y4 = 0; |
int y1 = 0, y2 = 0, y3 = 0, y4 = 0; |
383 |
|
|
384 |
|
Rectangle scrollPaneBounds = SwingUtilities.calculateInnerArea(sc, null); |
385 |
|
|
386 |
x1 = scrollPaneBounds.x; |
x1 = scrollPaneBounds.x; |
387 |
y1 = scrollPaneBounds.y; |
y1 = scrollPaneBounds.y; |
388 |
x4 = scrollPaneBounds.x + scrollPaneBounds.width; |
x4 = scrollPaneBounds.x + scrollPaneBounds.width; |
401 |
int vsbPolicy = sc.getVerticalScrollBarPolicy(); |
int vsbPolicy = sc.getVerticalScrollBarPolicy(); |
402 |
int hsbPolicy = sc.getHorizontalScrollBarPolicy(); |
int hsbPolicy = sc.getHorizontalScrollBarPolicy(); |
403 |
|
|
404 |
|
x3 = x4 - vsb.getPreferredSize().width; |
405 |
|
y3 = y4 - hsb.getPreferredSize().height; |
406 |
|
|
407 |
boolean showVsb = |
boolean showVsb = |
408 |
(vsb != null) |
(vsb != null) |
409 |
&& ((vsbPolicy == VERTICAL_SCROLLBAR_ALWAYS) |
&& ((vsbPolicy == VERTICAL_SCROLLBAR_ALWAYS) |
410 |
|| (vsbPolicy == VERTICAL_SCROLLBAR_AS_NEEDED |
|| (vsbPolicy == VERTICAL_SCROLLBAR_AS_NEEDED |
411 |
&& viewSize.height > viewportSize.height)); |
&& viewSize.height > (y3 - y2))); |
412 |
|
|
413 |
boolean showHsb = |
boolean showHsb = |
414 |
(hsb != null) |
(hsb != null) |
415 |
&& ((hsbPolicy == HORIZONTAL_SCROLLBAR_ALWAYS) |
&& ((hsbPolicy == HORIZONTAL_SCROLLBAR_ALWAYS) |
416 |
|| (hsbPolicy == HORIZONTAL_SCROLLBAR_AS_NEEDED |
|| (hsbPolicy == HORIZONTAL_SCROLLBAR_AS_NEEDED |
417 |
&& viewSize.width > viewportSize.width)); |
&& viewSize.width > (x3 - x2))); |
418 |
|
|
419 |
if (showVsb) |
if (!showVsb) |
|
x3 = x4 - vsb.getPreferredSize().width; |
|
|
else |
|
420 |
x3 = x4; |
x3 = x4; |
421 |
|
|
422 |
if (showHsb) |
if (!showHsb) |
|
y3 = y4 - hsb.getPreferredSize().height; |
|
|
else |
|
423 |
y3 = y4; |
y3 = y4; |
424 |
|
|
425 |
// now set the layout |
// now set the layout |
434 |
rowHead.setBounds(new Rectangle(x1, y2, x2-x1, y3-y2)); |
rowHead.setBounds(new Rectangle(x1, y2, x2-x1, y3-y2)); |
435 |
|
|
436 |
if (showVsb) |
if (showVsb) |
437 |
|
{ |
438 |
|
vsb.setVisible(true); |
439 |
vsb.setBounds(new Rectangle(x3, y2, x4-x3, y3-y2)); |
vsb.setBounds(new Rectangle(x3, y2, x4-x3, y3-y2)); |
440 |
|
} |
441 |
|
else if (vsb != null) |
442 |
|
vsb.setVisible(false); |
443 |
|
|
444 |
if (showHsb) |
if (showHsb) |
445 |
|
{ |
446 |
|
hsb.setVisible(true); |
447 |
hsb.setBounds(new Rectangle(x2, y3, x3-x2, y4-y3)); |
hsb.setBounds(new Rectangle(x2, y3, x3-x2, y4-y3)); |
448 |
|
} |
449 |
|
else if (hsb != null) |
450 |
|
hsb.setVisible(false); |
451 |
|
|
452 |
if (upperLeft != null) |
if (upperLeft != null) |
453 |
upperLeft.setBounds(new Rectangle(x1, y1, x2-x1, y2-y1)); |
upperLeft.setBounds(new Rectangle(x1, y1, x2-x1, y2-y1)); |