Search in sources :

Example 6 with Orientation

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

the class RulerSkin method paint.

@Override
public void paint(Graphics2D graphics) {
    int width = getWidth();
    int height = getHeight();
    int top = markerInsets.top;
    int left = markerInsets.left;
    int bottom = height - markerInsets.bottom;
    int right = width - markerInsets.right;
    Ruler ruler = (Ruler) getComponent();
    graphics.setColor(backgroundColor);
    graphics.fillRect(0, 0, width, height);
    graphics.setColor(color);
    GraphicsUtilities.drawBorders(graphics, borders, 0, 0, height - 1, width - 1);
    height -= markerInsets.getHeight();
    width -= markerInsets.getWidth();
    FontRenderContext fontRenderContext = showMajorNumbers || showMinorNumbers ? GraphicsUtilities.prepareForText(graphics, font, color) : null;
    Orientation orientation = ruler.getOrientation();
    switch(orientation) {
        case HORIZONTAL:
            {
                int start = flip ? bottom - 1 : top;
                int end2 = flip ? (start - (MAJOR_SIZE - 1)) : (MAJOR_SIZE - 1);
                int end3 = flip ? (start - (MINOR_SIZE - 1)) : (MINOR_SIZE - 1);
                int end4 = flip ? (start - (REGULAR_SIZE - 1)) : (REGULAR_SIZE - 1);
                for (int i = 0, n = right / markerSpacing + 1; i < n; i++) {
                    int x = i * markerSpacing + left;
                    if (majorDivision != 0 && i % majorDivision == 0) {
                        graphics.drawLine(x, start, x, end2);
                        // Don't show any numbers at 0 -- make a style for this?
                        if (showMajorNumbers && i > 0) {
                            showNumber(graphics, fontRenderContext, i, x, end2);
                        }
                    } else if (minorDivision != 0 && i % minorDivision == 0) {
                        graphics.drawLine(x, start, x, end3);
                        if (showMinorNumbers && i > 0) {
                            // Show the minor numbers at the same y point as the major
                            showNumber(graphics, fontRenderContext, i, x, end2);
                        }
                    } else {
                        graphics.drawLine(x, start, x, end4);
                    }
                }
                break;
            }
        case VERTICAL:
            {
                int start = flip ? right - 1 : left;
                int end2 = flip ? (start - (MAJOR_SIZE - 1)) : (MAJOR_SIZE - 1);
                int end3 = flip ? (start - (MINOR_SIZE - 1)) : (MINOR_SIZE - 1);
                int end4 = flip ? (start - (REGULAR_SIZE - 1)) : (REGULAR_SIZE - 1);
                for (int i = 0, n = bottom / markerSpacing + 1; i < n; i++) {
                    int y = i * markerSpacing + top;
                    if (majorDivision != 0 && i % majorDivision == 0) {
                        graphics.drawLine(start, y, end2, y);
                        // Don't show any numbers at 0 -- make a style for this?
                        if (showMajorNumbers && i > 0) {
                            showNumber(graphics, fontRenderContext, i, end2, y);
                        }
                    } else if (minorDivision != 0 && i % minorDivision == 0) {
                        graphics.drawLine(start, y, end3, y);
                        if (showMinorNumbers && i > 0) {
                            showNumber(graphics, fontRenderContext, i, end3, y);
                        }
                    } else {
                        graphics.drawLine(start, y, end4, y);
                    }
                }
                break;
            }
        default:
            {
                break;
            }
    }
}
Also used : FontRenderContext(java.awt.font.FontRenderContext) Ruler(org.apache.pivot.wtk.Ruler) Orientation(org.apache.pivot.wtk.Orientation)

Example 7 with Orientation

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

the class RulerSkin method getPreferredWidth.

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

Example 8 with Orientation

use of org.apache.pivot.wtk.Orientation 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 9 with Orientation

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

the class BoxPaneSkin method layout.

@Override
public void layout() {
    BoxPane boxPane = (BoxPane) getComponent();
    int n = boxPane.getLength();
    int width = getWidth();
    int height = getHeight();
    Orientation orientation = boxPane.getOrientation();
    if (orientation == Orientation.HORIZONTAL) {
        int preferredWidth = getPreferredWidth(fill ? height : -1);
        // Determine the starting x-coordinate
        int x = 0;
        switch(horizontalAlignment) {
            case CENTER:
                {
                    x = (width - preferredWidth) / 2;
                    break;
                }
            case RIGHT:
                {
                    x = width - preferredWidth;
                    break;
                }
            case LEFT:
                {
                    break;
                }
            default:
                {
                    break;
                }
        }
        x += padding.left;
        // Lay out the components
        for (int i = 0; i < n; i++) {
            Component component = boxPane.get(i);
            if (component.isVisible()) {
                int componentWidth = 0;
                int componentHeight = 0;
                int y = 0;
                if (fill) {
                    componentHeight = Math.max(height - padding.getHeight(), 0);
                    componentWidth = component.getPreferredWidth(componentHeight);
                } else {
                    Dimensions preferredComponentSize = component.getPreferredSize();
                    componentWidth = preferredComponentSize.width;
                    componentHeight = preferredComponentSize.height;
                }
                switch(verticalAlignment) {
                    case TOP:
                        {
                            y = padding.top;
                            break;
                        }
                    case CENTER:
                        {
                            y = (height - componentHeight) / 2;
                            break;
                        }
                    case BOTTOM:
                        {
                            y = height - padding.bottom - componentHeight;
                            break;
                        }
                    default:
                        {
                            break;
                        }
                }
                // Set the component's size and position
                component.setSize(componentWidth, componentHeight);
                component.setLocation(x, y);
                // Increment the x-coordinate
                x += componentWidth + spacing;
            }
        }
    } else {
        int preferredHeight = getPreferredHeight(fill ? width : -1);
        // Determine the starting y-coordinate
        int y = 0;
        switch(verticalAlignment) {
            case CENTER:
                {
                    y = (height - preferredHeight) / 2;
                    break;
                }
            case BOTTOM:
                {
                    y = height - preferredHeight;
                    break;
                }
            case TOP:
                break;
            default:
                {
                    break;
                }
        }
        y += padding.top;
        // Lay out the components
        for (int i = 0; i < n; i++) {
            Component component = boxPane.get(i);
            if (component.isVisible()) {
                int componentWidth = 0;
                int componentHeight = 0;
                int x = 0;
                if (fill) {
                    componentWidth = Math.max(width - padding.getWidth(), 0);
                    componentHeight = component.getPreferredHeight(componentWidth);
                } else {
                    Dimensions preferredComponentSize = component.getPreferredSize();
                    componentWidth = preferredComponentSize.width;
                    componentHeight = preferredComponentSize.height;
                }
                switch(horizontalAlignment) {
                    case LEFT:
                        {
                            x = padding.left;
                            break;
                        }
                    case CENTER:
                        {
                            x = (width - componentWidth) / 2;
                            break;
                        }
                    case RIGHT:
                        {
                            x = width - padding.right - componentWidth;
                            break;
                        }
                    default:
                        {
                            break;
                        }
                }
                // Set the component's size and position
                component.setSize(componentWidth, componentHeight);
                component.setLocation(x, y);
                // Increment the y-coordinate
                y += componentHeight + spacing;
            }
        }
    }
}
Also used : BoxPane(org.apache.pivot.wtk.BoxPane) Dimensions(org.apache.pivot.wtk.Dimensions) Orientation(org.apache.pivot.wtk.Orientation) Component(org.apache.pivot.wtk.Component)

Example 10 with Orientation

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

the class NumberRulerSkin method paint.

@Override
public void paint(Graphics2D graphics) {
    int width = getWidth();
    int height = getHeight();
    int bottom = height - markerInsets.bottom;
    Rectangle clipRect = graphics.getClipBounds();
    NumberRuler ruler = (NumberRuler) getComponent();
    int textSize = ruler.getTextSize();
    graphics.setColor(backgroundColor);
    graphics.fillRect(0, 0, width, height);
    graphics.setColor(color);
    FontRenderContext fontRenderContext = Platform.getFontRenderContext();
    graphics.setFont(font);
    Orientation orientation = ruler.getOrientation();
    Rectangle fullRect = new Rectangle(width, height);
    Rectangle clippedRect = fullRect.intersection(clipRect);
    switch(orientation) {
        case HORIZONTAL:
            {
                int start = bottom - 1;
                int end2 = start - (MAJOR_SIZE - 1);
                int end3 = start - (MINOR_SIZE - 1);
                int end4 = start - (REGULAR_SIZE - 1);
                Rectangle lineRect = new Rectangle(0, height - 1, width - 1, 0);
                Rectangle clippedLineRect = lineRect.intersection(clipRect);
                graphics.drawLine(clippedLineRect.x, clippedLineRect.y, clippedLineRect.x + clippedLineRect.width, clippedLineRect.y);
                for (int i = 0, n = width / markerSpacing + 1; i < n; i++) {
                    int x = i * markerSpacing + markerInsets.left;
                    if (majorDivision != 0 && i % majorDivision == 0) {
                        graphics.drawLine(x, start, x, end2);
                        // Don't show any numbers at 0 -- make a style for this?
                        if (showMajorNumbers && i > 0) {
                            showNumber(graphics, fontRenderContext, i, x, end2);
                        }
                    } else if (minorDivision != 0 && i % minorDivision == 0) {
                        graphics.drawLine(x, start, x, end3);
                        if (showMinorNumbers && i > 0) {
                            // Show the minor numbers at the same y point as the major
                            showNumber(graphics, fontRenderContext, i, x, end2);
                        }
                    } else {
                        graphics.drawLine(x, start, x, end4);
                    }
                }
                break;
            }
        case VERTICAL:
            {
                Rectangle lineRect = new Rectangle(width - 1, 0, 0, height - 1);
                Rectangle clippedLineRect = lineRect.intersection(clipRect);
                graphics.drawLine(clippedLineRect.x, clippedLineRect.y, clippedLineRect.x, clippedLineRect.y + clippedLineRect.height);
                // Optimize drawing by only starting just above the current clip bounds
                // down to the bottom (plus one) of the end of the clip bounds.
                // This is a 100x speed improvement for 500,000 lines.
                int linesAbove = clipRect.y / lineHeight;
                int linesBelow = (height - (clipRect.y + clipRect.height)) / lineHeight;
                int totalLines = height / lineHeight + 1;
                for (int num = 1 + linesAbove, n = totalLines - (linesBelow - 1); num < n; num++) {
                    String numberString = Integer.toString(num);
                    StringCharacterIterator line = new StringCharacterIterator(numberString);
                    int lineY = (num - 1) * lineHeight + markerInsets.top;
                    Graphics2D lineGraphics = (Graphics2D) graphics.create(0, lineY, width, lineHeight);
                    float y = (float) (lineHeight - rowPadding.bottom) - descent;
                    GlyphVector glyphVector = font.createGlyphVector(fontRenderContext, line);
                    Rectangle2D textBounds = glyphVector.getLogicalBounds();
                    float lineWidth = (float) textBounds.getWidth();
                    float x = (float) width - (lineWidth + (float) padding);
                    lineGraphics.drawGlyphVector(glyphVector, x, y);
                }
                break;
            }
        default:
            {
                break;
            }
    }
}
Also used : NumberRuler(org.apache.pivot.wtk.NumberRuler) StringCharacterIterator(java.text.StringCharacterIterator) GlyphVector(java.awt.font.GlyphVector) Rectangle(java.awt.Rectangle) Rectangle2D(java.awt.geom.Rectangle2D) FontRenderContext(java.awt.font.FontRenderContext) Orientation(org.apache.pivot.wtk.Orientation) Graphics2D(java.awt.Graphics2D)

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