100
103
protected int[] sizes = new int[3];
106
* Creates a new instance. This is package private because the reference
107
* implementation has no public constructor either. Still, we need to
108
* call it from BasicVerticalLayoutManager.
110
BasicHorizontalLayoutManager()
112
// Nothing to do here.
103
116
* This method adds the component given to the JSplitPane. The position of
104
117
* the component is given by the constraints object.
128
141
if (place == null)
130
143
else if (place.equals(JSplitPane.TOP) || place.equals(JSplitPane.LEFT))
132
145
else if (place.equals(JSplitPane.BOTTOM)
133
146
|| place.equals(JSplitPane.RIGHT))
136
throw new IllegalArgumentException("Illegal placement in JSplitPane");
149
throw new IllegalArgumentException("Illegal placement in JSplitPane");
137
150
components[i] = component;
139
152
splitPane.revalidate();
251
264
if (container instanceof JSplitPane)
253
JSplitPane split = (JSplitPane) container;
254
distributeExtraSpace();
255
Insets insets = split.getInsets();
256
int width = getInitialLocation(insets);
257
Dimension dims = split.getSize();
258
for (int i = 0; i < components.length; i += 2)
260
if (components[i] == null)
262
setComponentToSize(components[i], sizes[i], width, insets, dims);
265
if (components[1] != null)
267
setComponentToSize(components[1], sizes[1], width, insets, dims);
266
JSplitPane split = (JSplitPane) container;
267
distributeExtraSpace();
268
Insets insets = split.getInsets();
269
Dimension dims = split.getSize();
270
int loc = getInitialLocation(insets);
271
int available = getAvailableSize(dims, insets);
272
sizes[0] = getDividerLocation(split) - loc;
273
sizes[1] = available - sizes[0] - sizes[2];
274
// The size of the divider won't change.
276
// Layout component#1.
277
setComponentToSize(components[0], sizes[0], loc, insets, dims);
280
setComponentToSize(components[2], sizes[2], loc, insets, dims);
281
// Layout component#2.
283
setComponentToSize(components[1], sizes[1], loc, insets, dims);
298
312
if (target instanceof JSplitPane)
300
JSplitPane split = (JSplitPane) target;
301
Insets insets = target.getInsets();
314
JSplitPane split = (JSplitPane) target;
315
Insets insets = target.getInsets();
305
for (int i = 0; i < components.length; i++)
307
if (components[i] == null)
309
Dimension dims = components[i].getMinimumSize();
313
height = Math.max(height, dims.height);
316
return new Dimension(width, height);
319
for (int i = 0; i < components.length; i++)
321
if (components[i] == null)
323
Dimension dims = components[i].getMinimumSize();
327
height = Math.max(height, dims.height);
330
return new Dimension(width, height);
332
346
if (target instanceof JSplitPane)
334
JSplitPane split = (JSplitPane) target;
335
Insets insets = target.getInsets();
348
JSplitPane split = (JSplitPane) target;
349
Insets insets = target.getInsets();
339
for (int i = 0; i < components.length; i++)
341
if (components[i] == null)
343
Dimension dims = components[i].getPreferredSize();
347
if (! (components[i] instanceof BasicSplitPaneDivider))
348
height = Math.max(height, dims.height);
351
return new Dimension(width, height);
353
for (int i = 0; i < components.length; i++)
355
if (components[i] == null)
357
Dimension dims = components[i].getPreferredSize();
361
if (!(components[i] instanceof BasicSplitPaneDivider))
362
height = Math.max(height, dims.height);
365
return new Dimension(width, height);
452
468
void distributeExtraSpace()
454
int availSize = getAvailableSize(splitPane.getSize(),
455
splitPane.getInsets());
456
int[] newSizes = new int[3];
457
double weight = splitPane.getResizeWeight();
459
int oldLen = sizes[0] + sizes[1];
461
// dividers don't change size.
462
availSize -= sizes[2] + oldLen;
464
int rightAlloc = (int) (availSize * (1 - weight));
465
int leftAlloc = availSize - rightAlloc;
467
sizes[0] += leftAlloc;
468
sizes[1] += rightAlloc;
470
// FIXME: This needs to be reimplemented correctly.
564
566
if (container instanceof JSplitPane)
566
JSplitPane split = (JSplitPane) container;
567
Insets insets = container.getInsets();
568
JSplitPane split = (JSplitPane) container;
569
Insets insets = container.getInsets();
571
for (int i = 0; i < components.length; i++)
573
if (components[i] == null)
575
Dimension dims = components[i].getMinimumSize();
578
height += dims.height;
579
width = Math.max(width, dims.width);
582
return new Dimension(width, height);
573
for (int i = 0; i < components.length; i++)
575
if (components[i] == null)
577
Dimension dims = components[i].getMinimumSize();
580
height += dims.height;
581
width = Math.max(width, dims.width);
584
return new Dimension(width, height);
598
600
if (container instanceof JSplitPane)
600
JSplitPane split = (JSplitPane) container;
601
Insets insets = container.getInsets();
602
JSplitPane split = (JSplitPane) container;
603
Insets insets = container.getInsets();
605
for (int i = 0; i < components.length; i++)
607
if (components[i] == null)
609
Dimension dims = components[i].getPreferredSize();
612
height += dims.height;
613
width = Math.max(width, dims.width);
616
return new Dimension(width, height);
607
for (int i = 0; i < components.length; i++)
609
if (components[i] == null)
611
Dimension dims = components[i].getPreferredSize();
614
height += dims.height;
615
width = Math.max(width, dims.width);
618
return new Dimension(width, height);
814
816
if (e.getPropertyName().equals(JSplitPane.DIVIDER_SIZE_PROPERTY))
816
int newSize = splitPane.getDividerSize();
817
int[] tmpSizes = layoutManager.getSizes();
818
dividerSize = tmpSizes[2];
819
int newSpace = newSize - tmpSizes[2];
820
tmpSizes[2] = newSize;
818
int newSize = splitPane.getDividerSize();
819
int[] tmpSizes = layoutManager.getSizes();
820
dividerSize = tmpSizes[2];
821
int newSpace = newSize - tmpSizes[2];
822
tmpSizes[2] = newSize;
822
tmpSizes[0] += newSpace / 2;
823
tmpSizes[1] += newSpace / 2;
824
tmpSizes[0] += newSpace / 2;
825
tmpSizes[1] += newSpace / 2;
825
layoutManager.setSizes(tmpSizes);
827
layoutManager.setSizes(tmpSizes);
827
829
else if (e.getPropertyName().equals(JSplitPane.ORIENTATION_PROPERTY))
829
int max = layoutManager.getAvailableSize(splitPane.getSize(),
830
splitPane.getInsets());
831
int dividerLoc = getDividerLocation(splitPane);
832
double prop = ((double) dividerLoc) / max;
831
int max = layoutManager.getAvailableSize(splitPane.getSize(),
832
splitPane.getInsets());
833
int dividerLoc = getDividerLocation(splitPane);
834
double prop = ((double) dividerLoc) / max;
834
resetLayoutManager();
835
if (prop <= 1 && prop >= 0)
836
splitPane.setDividerLocation(prop);
836
resetLayoutManager();
837
if (prop <= 1 && prop >= 0)
838
splitPane.setDividerLocation(prop);
838
layoutManager.layoutContainer(splitPane);
840
840
// Don't have to deal with continuous_layout - only
841
841
// necessary in dragging modes (and it's checked
842
842
// every time you drag there)
843
843
// Don't have to deal with resize_weight (as there
844
844
// will be no extra space associated with this
845
845
// event - the changes to the weighting will
846
// be taken into account the next time the
846
// be taken into account the next time the
847
847
// sizes change.)
848
// Don't have to deal with divider_location
848
// Don't have to deal with divider_location
849
849
// The method in JSplitPane calls our setDividerLocation
850
850
// so we'll know about those anyway.
851
851
// Don't have to deal with last_divider_location
852
// Although I'm not sure why, it doesn't seem to
852
// Although I'm not sure why, it doesn't seem to
853
853
// have any effect on Sun's JSplitPane.
854
854
// one_touch_expandable changes are dealt with
855
855
// by our divider.
992
994
"SplitPane.foreground");
993
995
LookAndFeel.installBorder(splitPane, "SplitPane.border");
994
996
divider = createDefaultDivider();
997
divider.setBorder(UIManager.getBorder("SplitPaneDivider.border"));
995
998
resetLayoutManager();
996
999
nonContinuousLayoutDivider = createDefaultNonContinuousLayoutDivider();
997
1000
splitPane.add(divider, JSplitPane.DIVIDER);
1012
1015
divider = null;
1013
1016
nonContinuousLayoutDivider = null;
1015
splitPane.setBackground(null);
1016
splitPane.setBorder(null);
1018
if (splitPane.getBackground() instanceof UIResource)
1019
splitPane.setBackground(null);
1020
if (splitPane.getBorder() instanceof UIResource)
1021
splitPane.setBorder(null);
1219
1226
if (nonContinuousLayoutDivider == null)
1221
nonContinuousLayoutDivider = new Canvas();
1222
nonContinuousLayoutDivider.setBackground(Color.DARK_GRAY);
1228
nonContinuousLayoutDivider = new Canvas();
1229
Color c = UIManager.getColor("SplitPaneDivider.draggingColor");
1230
nonContinuousLayoutDivider.setBackground(c);
1224
1232
return nonContinuousLayoutDivider;
1299
1307
public void setDividerLocation(JSplitPane jc, int location)
1301
location = validLocation(location);
1302
Container p = jc.getParent();
1303
Dimension rightPrefSize = jc.getRightComponent().getPreferredSize();
1304
Dimension size = jc.getSize();
1305
// check if the size has been set for the splitpane
1306
if (size.width == 0 && size.height == 0)
1307
size = jc.getPreferredSize();
1309
if (getOrientation() == 0 && location > size.height)
1311
location = size.height;
1314
p.setSize(p.getWidth(), p.getHeight() + rightPrefSize.height);
1318
else if (location > size.width)
1320
location = size.width;
1323
p.setSize(p.getWidth() + rightPrefSize.width, p.getHeight());
1328
setLastDragLocation(getDividerLocation(splitPane));
1329
splitPane.setLastDividerLocation(getDividerLocation(splitPane));
1330
int[] tmpSizes = layoutManager.getSizes();
1331
tmpSizes[0] = location
1332
- layoutManager.getInitialLocation(splitPane.getInsets());
1333
tmpSizes[1] = layoutManager.getAvailableSize(splitPane.getSize(),
1334
splitPane.getInsets())
1336
layoutManager.setSizes(tmpSizes);
1309
dividerLocation = location;
1337
1310
splitPane.revalidate();
1338
1311
splitPane.repaint();
1362
1334
public int getMinimumDividerLocation(JSplitPane jc)
1364
int value = layoutManager.getInitialLocation(jc.getInsets())
1365
- layoutManager.getAvailableSize(jc.getSize(), jc.getInsets())
1366
+ splitPane.getDividerSize();
1367
if (layoutManager.components[1] != null)
1368
value += layoutManager.minimumSizeOfComponent(1);
1336
int value = layoutManager.getInitialLocation(jc.getInsets());
1337
if (layoutManager.components[0] != null)
1338
value += layoutManager.minimumSizeOfComponent(0);
1486
1456
protected void startDragging()
1458
Component left = splitPane.getLeftComponent();
1459
Component right = splitPane.getRightComponent();
1488
1460
dividerSize = divider.getDividerSize();
1489
1461
setLastDragLocation(-1);
1491
if (! splitPane.getLeftComponent().isLightweight()
1492
|| ! splitPane.getRightComponent().isLightweight())
1463
if ((left != null && !left.isLightweight())
1464
|| (right != null && !right.isLightweight()))
1493
1465
draggingHW = true;
1495
1467
if (splitPane.isContinuousLayout())
1496
1468
nonContinuousLayoutDivider.setVisible(false);
1499
nonContinuousLayoutDivider.setVisible(true);
1500
nonContinuousLayoutDivider.setBounds(divider.getBounds());
1471
nonContinuousLayoutDivider.setVisible(true);
1472
nonContinuousLayoutDivider.setBounds(divider.getBounds());
1502
splitPane.revalidate();
1503
splitPane.repaint();
1520
1490
splitPane.setDividerLocation(location);
1523
Point p = nonContinuousLayoutDivider.getLocation();
1524
if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT)
1528
nonContinuousLayoutDivider.setLocation(p);
1493
Point p = nonContinuousLayoutDivider.getLocation();
1494
if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT)
1498
nonContinuousLayoutDivider.setLocation(p);
1530
1500
setLastDragLocation(location);
1531
1501
splitPane.repaint();