use of org.apache.pivot.wtk.SplitPane in project pivot by apache.
the class TerraSplitPaneSkin method setSize.
@Override
public void setSize(int width, int height) {
int previousWidth = getWidth();
int previousHeight = getHeight();
super.setSize(width, height);
SplitPane splitPane = (SplitPane) getComponent();
Orientation orientation = splitPane.getOrientation();
if (splitPane.getResizeMode() == SplitPane.ResizeMode.PRIMARY_REGION && ((previousWidth != width && orientation == Orientation.HORIZONTAL) || (previousHeight != height && orientation == Orientation.VERTICAL))) {
SplitPane.Region primaryRegion = splitPane.getPrimaryRegion();
float splitRatio = splitPane.getSplitRatio();
if (orientation == Orientation.HORIZONTAL) {
int splitLocation = (int) (splitRatio * previousWidth);
if (primaryRegion == SplitPane.Region.BOTTOM_RIGHT) {
// Move the split location to maintain size on the right
splitLocation += (width - previousWidth);
}
splitRatio = (float) limitSplitLocation(splitLocation) / width;
} else {
int splitLocation = (int) (splitRatio * previousHeight);
if (primaryRegion == SplitPane.Region.BOTTOM_RIGHT) {
// Move the split location to maintain size on the bottom
splitLocation += (height - previousHeight);
}
splitRatio = (float) limitSplitLocation(splitLocation) / height;
}
splitPane.setSplitRatio(splitRatio);
}
}
use of org.apache.pivot.wtk.SplitPane in project pivot by apache.
the class TerraSplitPaneSkin method getPreferredWidth.
@Override
public int getPreferredWidth(int height) {
int preferredWidth = splitterThickness;
SplitPane splitPane = (SplitPane) getComponent();
Component topLeft = splitPane.getTopLeft();
if (topLeft != null) {
preferredWidth += topLeft.getPreferredWidth(height);
}
Component bottomRight = splitPane.getBottomRight();
if (bottomRight != null) {
preferredWidth += bottomRight.getPreferredWidth(height);
}
return preferredWidth;
}
use of org.apache.pivot.wtk.SplitPane in project pivot by apache.
the class TerraSplitPaneSkin method limitSplitLocation.
private int limitSplitLocation(int splitLocation) {
SplitPane splitPane = (SplitPane) getComponent();
Component topLeft = splitPane.getTopLeft();
Component bottomRight = splitPane.getBottomRight();
int lower, upper;
if (splitPane.getOrientation() == Orientation.HORIZONTAL) {
lower = 0;
upper = Math.max(getWidth() - splitterThickness, 0);
if (topLeft != null) {
int leftLimit = topLeft.getMinimumWidth();
if (leftLimit >= 0) {
lower = Math.min(leftLimit, upper);
}
}
if (bottomRight != null) {
int rightLimit = bottomRight.getMinimumWidth();
if (rightLimit >= 0) {
upper = Math.max(upper - rightLimit, lower);
}
}
} else {
lower = 0;
upper = Math.max(getHeight() - splitterThickness, 0);
if (topLeft != null) {
int topLimit = topLeft.getMinimumHeight();
if (topLimit >= 0) {
lower = Math.min(topLimit, upper);
}
}
if (bottomRight != null) {
int bottomLimit = bottomRight.getMinimumHeight();
if (bottomLimit >= 0) {
upper = Math.max(upper - bottomLimit, lower);
}
}
}
if (splitLocation < lower) {
return lower;
} else if (splitLocation > upper) {
return upper;
}
return splitLocation;
}
use of org.apache.pivot.wtk.SplitPane in project pivot by apache.
the class TerraSplitPaneSkin method layout.
@Override
public void layout() {
int width = getWidth();
int height = getHeight();
SplitPane splitPane = (SplitPane) getComponent();
float splitRatio = splitPane.getSplitRatio();
Component topLeft = splitPane.getTopLeft();
Component bottomRight = splitPane.getBottomRight();
if (splitPane.getOrientation() == Orientation.HORIZONTAL) {
int splitLocation = limitSplitLocation((int) (splitRatio * width));
int rightStart = splitLocation + splitterThickness;
splitter.setLocation(splitLocation, 0);
splitter.setSize(splitterThickness, height);
if (topLeft != null) {
topLeft.setLocation(0, 0);
topLeft.setSize(splitLocation, height);
}
if (bottomRight != null) {
bottomRight.setLocation(rightStart, 0);
bottomRight.setSize(Math.max(width - rightStart, 0), height);
}
} else {
int splitLocation = limitSplitLocation((int) (splitRatio * height));
int bottomStart = splitLocation + splitterThickness;
splitter.setLocation(0, splitLocation);
splitter.setSize(width, splitterThickness);
if (topLeft != null) {
topLeft.setLocation(0, 0);
topLeft.setSize(width, splitLocation);
}
if (bottomRight != null) {
bottomRight.setLocation(0, bottomStart);
bottomRight.setSize(width, Math.max(height - bottomStart, 0));
}
}
}
use of org.apache.pivot.wtk.SplitPane in project pivot by apache.
the class TerraSplitPaneSkin method getPreferredHeight.
@Override
public int getPreferredHeight(int width) {
int preferredHeight = splitterThickness;
SplitPane splitPane = (SplitPane) getComponent();
Component topLeft = splitPane.getTopLeft();
if (topLeft != null) {
preferredHeight += topLeft.getPreferredHeight(width);
}
Component bottomRight = splitPane.getBottomRight();
if (bottomRight != null) {
preferredHeight += bottomRight.getPreferredHeight(width);
}
return preferredHeight;
}
Aggregations