Search in sources :

Example 11 with Orientation

use of org.apache.pivot.wtk.Orientation in project pivot by apache.

the class NumberRulerSkin method getPreferredHeight.

@Override
public int getPreferredHeight(int width) {
    NumberRuler ruler = (NumberRuler) getComponent();
    Orientation orientation = ruler.getOrientation();
    // Give a little extra height if showing numbers
    return (orientation == Orientation.HORIZONTAL) ? ((showMajorNumbers || showMinorNumbers) ? ((int) Math.ceil(charHeight) + MAJOR_SIZE + 5) : MAJOR_SIZE * 2) : 0;
}
Also used : NumberRuler(org.apache.pivot.wtk.NumberRuler) Orientation(org.apache.pivot.wtk.Orientation)

Example 12 with Orientation

use of org.apache.pivot.wtk.Orientation in project pivot by apache.

the class NumberRulerSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    NumberRuler ruler = (NumberRuler) getComponent();
    Orientation orientation = ruler.getOrientation();
    if (orientation == Orientation.VERTICAL) {
        int textSize = ruler.getTextSize();
        FontRenderContext fontRenderContext = Platform.getFontRenderContext();
        char[] digits = new char[textSize];
        Arrays.fill(digits, '0');
        String text = new String(digits);
        Rectangle2D stringBounds = font.getStringBounds(text, fontRenderContext);
        return (int) Math.ceil(stringBounds.getWidth()) + padding;
    }
    return 0;
}
Also used : NumberRuler(org.apache.pivot.wtk.NumberRuler) Rectangle2D(java.awt.geom.Rectangle2D) FontRenderContext(java.awt.font.FontRenderContext) Orientation(org.apache.pivot.wtk.Orientation)

Example 13 with Orientation

use of org.apache.pivot.wtk.Orientation in project pivot by apache.

the class FillPaneSkin method layout.

@Override
public void layout() {
    FillPane fillPane = (FillPane) getComponent();
    // n is the number of 'visible' components
    // len is the total number of components
    int n = 0;
    int len = fillPane.getLength();
    for (int i = 0; i < len; i++) {
        Component component = fillPane.get(i);
        if (component.isVisible()) {
            n++;
        }
    }
    int width = getWidth();
    int height = getHeight();
    if (width <= 0) {
        width = getPreferredWidth(-1);
    }
    if (height <= 0) {
        height = getPreferredHeight(-1);
    }
    Orientation orientation = fillPane.getOrientation();
    if (orientation == Orientation.HORIZONTAL) {
        // Determine the starting x-coordinate
        int x = padding.left;
        int totalWidth = width - padding.getWidth();
        if (n > 1) {
            totalWidth -= spacing * (n - 1);
        }
        int dividedWidth = n == 0 ? 0 : totalWidth / n;
        int leftoverWidth = totalWidth - (dividedWidth * n);
        // Lay out the components
        for (int i = 0, j = 0; i < len; i++) {
            Component component = fillPane.get(i);
            if (component.isVisible()) {
                int componentWidth = dividedWidth;
                if (j == n - 1) {
                    componentWidth += leftoverWidth;
                }
                int componentHeight = Math.max(height - padding.getHeight(), 0);
                int y = padding.top;
                // Set the component's size and position
                component.setSize(componentWidth, componentHeight);
                component.setLocation(x, y);
                // Increment the x-coordinate
                x += componentWidth + spacing;
                j++;
            }
        }
    } else {
        // Determine the starting y-coordinate
        int y = padding.top;
        int totalHeight = height - padding.getHeight();
        if (n > 1) {
            totalHeight -= spacing * (n - 1);
        }
        int dividedHeight = n == 0 ? 0 : totalHeight / n;
        int leftoverHeight = totalHeight - (dividedHeight * n);
        // Lay out the components
        for (int i = 0, j = 0; i < len; i++) {
            Component component = fillPane.get(i);
            if (component.isVisible()) {
                int componentHeight = dividedHeight;
                if (j == n - 1) {
                    componentHeight += leftoverHeight;
                }
                int componentWidth = Math.max(width - padding.getWidth(), 0);
                int x = padding.left;
                // Set the component's size and position
                component.setSize(componentWidth, componentHeight);
                component.setLocation(x, y);
                // Increment the y-coordinate
                y += componentHeight + spacing;
                j++;
            }
        }
    }
}
Also used : FillPane(org.apache.pivot.wtk.FillPane) Component(org.apache.pivot.wtk.Component) Orientation(org.apache.pivot.wtk.Orientation)

Example 14 with Orientation

use of org.apache.pivot.wtk.Orientation in project pivot by apache.

the class FillPaneSkin method getPreferredHeight.

@Override
public int getPreferredHeight(int width) {
    FillPane fillPane = (FillPane) getComponent();
    int preferredHeight = 0;
    Orientation orientation = fillPane.getOrientation();
    if (orientation == Orientation.HORIZONTAL) {
        // components
        for (int i = 0, n = fillPane.getLength(); i < n; i++) {
            Component component = fillPane.get(i);
            if (component.isVisible()) {
                preferredHeight = Math.max(preferredHeight, component.getPreferredHeight());
            }
        }
    } else {
        int widthUpdated = width;
        // Include padding in constraint
        if (widthUpdated != -1) {
            widthUpdated = Math.max(widthUpdated - padding.getWidth(), 0);
        }
        // Preferred height is the sum of the preferred heights of all
        // components
        int j = 0;
        for (int i = 0, n = fillPane.getLength(); i < n; i++) {
            Component component = fillPane.get(i);
            if (component.isVisible()) {
                preferredHeight += component.getPreferredHeight(widthUpdated);
                j++;
            }
        }
        // Include spacing
        if (j > 1) {
            preferredHeight += spacing * (j - 1);
        }
    }
    // Include top and bottom padding values
    preferredHeight += padding.getHeight();
    return preferredHeight;
}
Also used : FillPane(org.apache.pivot.wtk.FillPane) Orientation(org.apache.pivot.wtk.Orientation) Component(org.apache.pivot.wtk.Component)

Example 15 with Orientation

use of org.apache.pivot.wtk.Orientation in project pivot by apache.

the class RulerSkin method showNumber.

private void showNumber(Graphics2D graphics, FontRenderContext fontRenderContext, int number, int x, int y) {
    String num = Integer.toString(number);
    StringCharacterIterator line;
    GlyphVector glyphVector;
    Rectangle2D textBounds;
    float width, height;
    float fx, fy;
    Ruler ruler = (Ruler) getComponent();
    Orientation orientation = ruler.getOrientation();
    switch(orientation) {
        case HORIZONTAL:
            // Draw the whole number just off the tip of the line given by (x,y)
            line = new StringCharacterIterator(num);
            glyphVector = font.createGlyphVector(fontRenderContext, line);
            textBounds = glyphVector.getLogicalBounds();
            width = (float) textBounds.getWidth();
            height = (float) textBounds.getHeight();
            fx = (float) x - (width / 2.0f);
            if (flip) {
                fy = (float) (y - 2);
            } else {
                fy = (float) (y - 1) + height;
            }
            graphics.drawGlyphVector(glyphVector, fx, fy);
            break;
        case VERTICAL:
            // Draw the number one digit at a time, vertically just off the tip of the line
            if (flip) {
                fx = (float) (x - 1) - charWidth;
            } else {
                fx = (float) (x + 3);
            }
            int numDigits = num.length();
            float heightAdjust = (numDigits % 2 == 1) ? charHeight / 2.0f : 0.0f;
            for (int i = 0; i < numDigits; i++) {
                line = new StringCharacterIterator(num.substring(i, i + 1));
                glyphVector = font.createGlyphVector(fontRenderContext, line);
                int midDigit = (numDigits + 1) / 2;
                if (i <= midDigit) {
                    fy = (float) y + heightAdjust - descent - (float) (midDigit - i - 1) * charHeight;
                } else {
                    fy = (float) y + heightAdjust - descent + (float) (i - midDigit - 1) * charHeight;
                }
                graphics.drawGlyphVector(glyphVector, fx, fy);
            }
            break;
    }
}
Also used : StringCharacterIterator(java.text.StringCharacterIterator) GlyphVector(java.awt.font.GlyphVector) Rectangle2D(java.awt.geom.Rectangle2D) Ruler(org.apache.pivot.wtk.Ruler) Orientation(org.apache.pivot.wtk.Orientation)

Aggregations

Orientation (org.apache.pivot.wtk.Orientation)15 Component (org.apache.pivot.wtk.Component)6 Ruler (org.apache.pivot.wtk.Ruler)4 FontRenderContext (java.awt.font.FontRenderContext)3 Rectangle2D (java.awt.geom.Rectangle2D)3 BoxPane (org.apache.pivot.wtk.BoxPane)3 FillPane (org.apache.pivot.wtk.FillPane)3 NumberRuler (org.apache.pivot.wtk.NumberRuler)3 GlyphVector (java.awt.font.GlyphVector)2 StringCharacterIterator (java.text.StringCharacterIterator)2 Graphics2D (java.awt.Graphics2D)1 Rectangle (java.awt.Rectangle)1 Dimensions (org.apache.pivot.wtk.Dimensions)1 HorizontalAlignment (org.apache.pivot.wtk.HorizontalAlignment)1 SplitPane (org.apache.pivot.wtk.SplitPane)1 VerticalAlignment (org.apache.pivot.wtk.VerticalAlignment)1