Skip to content
Merged
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) {
Comment thread
danilovesky marked this conversation as resolved.
Resolved
percentPending = false;
super.setDividerLocation(percent);
}
}

Expand Down Expand Up @@ -193,12 +198,23 @@ 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);
}
setResizeWeight(percent);
}

@Override
public void setDividerLocation(int location) {
// an explicit location replaces a percentage that still waits for the size
percentPending = false;
super.setDividerLocation(location);
}

public boolean isConstantPercent() {
return constantPercent;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.flexdock.test.docking;

import org.flexdock.docking.DockingConstants;
import org.flexdock.docking.defaults.DefaultDockingPort;
import org.flexdock.docking.defaults.DockingSplitPane;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class DockingSplitPaneTest {

private static DockingSplitPane createUnsizedSplit() {
return new DockingSplitPane(new DefaultDockingPort(), DockingConstants.WEST_REGION);
}

@Test
void testPercentSetBeforeSizeIsAppliedOnceSized() {
DockingSplitPane split = createUnsizedSplit();

split.setDividerLocation(.3);
split.setBounds(0, 0, 1000, 600);

int expected = (int) ((1000 - split.getDividerSize()) * .3);
assertEquals(expected, split.getDividerLocation());
}

@Test
void testIntLocationReplacesPendingPercent() {
DockingSplitPane split = createUnsizedSplit();

split.setDividerLocation(.3);
split.setDividerLocation(100);
split.setBounds(0, 0, 1000, 600);

assertEquals(100, split.getDividerLocation());
}

}
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);
}

}
7 changes: 4 additions & 3 deletions release-notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ Fixes:
* DefaultDockingPort: clear() also clears the nested docking ports
* DockingStateListener: validate pending layout before capturing docking state
* PlafManager: keep the preferred theme after a look and feel change
* 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: track the divider percentage from the first drag and
apply it consistently in setDividerLocation()
* DockingSplitPane: apply a percentage set before the size is known once it is,
also without constant percent, so imported layouts keep their 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