Search in sources :

Example 1 with SplitPane

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);
    }
}
Also used : SplitPane(org.apache.pivot.wtk.SplitPane) Orientation(org.apache.pivot.wtk.Orientation)

Example 2 with SplitPane

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;
}
Also used : SplitPane(org.apache.pivot.wtk.SplitPane) Component(org.apache.pivot.wtk.Component)

Example 3 with SplitPane

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;
}
Also used : SplitPane(org.apache.pivot.wtk.SplitPane) Component(org.apache.pivot.wtk.Component)

Example 4 with SplitPane

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));
        }
    }
}
Also used : SplitPane(org.apache.pivot.wtk.SplitPane) Component(org.apache.pivot.wtk.Component)

Example 5 with SplitPane

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;
}
Also used : SplitPane(org.apache.pivot.wtk.SplitPane) Component(org.apache.pivot.wtk.Component)

Aggregations

SplitPane (org.apache.pivot.wtk.SplitPane)8 Component (org.apache.pivot.wtk.Component)5 Cursor (org.apache.pivot.wtk.Cursor)1 Dimensions (org.apache.pivot.wtk.Dimensions)1 Orientation (org.apache.pivot.wtk.Orientation)1