Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class DockingSplitPane extends JSplitPane implements DockingConstants {

private boolean constantPercent;

private boolean percentPending;

/**
* Creates a new {@code DockingSplitPane} for the specified
* {@code DockingPort} with the understanding that the resulting
Expand Down Expand Up @@ -132,6 +134,9 @@ public void setBounds(int x, int y, int w, int h) {
if (constantPercent) {
setResizeWeight(percent);
super.setDividerLocation((int) (percent * getSplitSize()));
} else if (percentPending && getSplitSize() > 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if setDividerLocation(int) is called while a percentage is pending, setBounds() will still override it with the old percentage, no?
should an int location clear percentPending?

percentPending = false;
super.setDividerLocation(percent);
}
}

Expand Down Expand Up @@ -193,6 +198,10 @@ public void setDividerLocation(double percent) {
if (splitSize > 0) {
super.setDividerLocation((int) (percent * splitSize));
}
} else if (valid && splitSize <= 0) {
// JSplitPane would compute a location from the zero size and lose the percentage,
// so setBounds() applies it once the size is known
percentPending = true;
} else {
super.setDividerLocation(percent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ private static void layoutTree(Component component) {
}
}

// Proportion of the split after importing a stored 0.3 layout into a sized port. There is no
// Proportion of the split after importing a stored layout into a sized port. There is no
// peer, so validate() does nothing: size the port and run doLayout() on the whole tree instead.
private static float importStoredProportion(boolean constantPercent) throws Exception {
private static float importStoredProportion(boolean constantPercent, float percent) throws Exception {
DefaultDockingPort source = createSplitPort(DockingConstants.WEST_REGION);
LayoutNode layout = source.exportLayout();
getSplitNode(layout).setPercentage(.3f);
getSplitNode(layout).setPercentage(percent);
LayoutNode restored = roundTripThroughXml(layout);

// The flag is read when the split panes are created, so set it before the import
Expand Down Expand Up @@ -132,18 +132,14 @@ void testOrientationSurvivesXmlAndImport() throws Exception {

@Test
void testProportionIsRestoredWithConstantPercent() throws Exception {
assertEquals(.3f, importStoredProportion(true), DELTA);
assertEquals(.3f, importStoredProportion(true, .3f), DELTA);
}

// Known bug (https://github.com/opencollab/flexdock/issues/33):
// without constant percent the stored proportion is lost on import (the split comes
// back at 0.5). Expected to fail until it is fixed; then the assertion below holds,
// assertThrows fails and the wrapper is to be removed.
// Below 1/3 the unsized split used to come back at 0.5, from 1/3 at Swing's preferred sizes
@Test
void testProportionIsRestoredWithoutConstantPercentKnownBug() throws Exception {
float restored = importStoredProportion(false);

assertThrows(AssertionError.class, () -> assertEquals(.3f, restored, DELTA));
void testProportionIsRestoredWithoutConstantPercent() throws Exception {
assertEquals(.3f, importStoredProportion(false, .3f), DELTA);
assertEquals(.7f, importStoredProportion(false, .7f), DELTA);
}

}
2 changes: 2 additions & 0 deletions release-notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Fixes:
* DockingSplitPane: track the divider percentage from the first drag
* DockingSplitPane: apply the percentage consistently in setDividerLocation()
* DockingSplitPane: keep the percentage set before the size is known
* DockingSplitPane: apply the percentage set before the size is known also
without constant percent, so imported layouts keep their split proportions
* DockingManager: use stub managers when flexdock-view or flexdock-perspective
is missing, instead of overflowing the stack
* UIFactory: create a custom theme under a look and feel without a theme mapping
Expand Down
Loading