Search in sources :

Example 1 with Border

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

the class BorderSkin method getBaseline.

@Override
public int getBaseline(int width, int height) {
    int baseline = -1;
    Border border = (Border) getComponent();
    // Delegate baseline calculation to the content component
    Component content = border.getContent();
    if (content != null) {
        int clientWidth = Math.max(width - paddingThicknessWidth(), 0);
        int clientHeight = Math.max(height - paddingThicknessHeight(), 0);
        baseline = content.getBaseline(clientWidth, clientHeight);
    }
    // Include top padding value and top border thickness
    if (baseline != -1) {
        baseline += (padding.top + topThickness);
    }
    return baseline;
}
Also used : Component(org.apache.pivot.wtk.Component) Border(org.apache.pivot.wtk.Border) Paint(java.awt.Paint)

Example 2 with Border

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

the class BorderSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    Border border = (Border) component;
    border.getBorderListeners().add(this);
}
Also used : Border(org.apache.pivot.wtk.Border)

Example 3 with Border

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

the class BorderSkin method layout.

@Override
public void layout() {
    int width = getWidth();
    int height = getHeight();
    Border border = (Border) getComponent();
    Component content = border.getContent();
    if (content != null) {
        content.setLocation(padding.left + thickness, padding.top + topThickness);
        int contentWidth = Math.max(width - paddingThicknessWidth(), 0);
        int contentHeight = Math.max(height - paddingThicknessHeight(), 0);
        content.setSize(contentWidth, contentHeight);
    }
}
Also used : Component(org.apache.pivot.wtk.Component) Border(org.apache.pivot.wtk.Border) Paint(java.awt.Paint)

Example 4 with Border

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

the class BorderSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    int preferredWidth = 0;
    int preferredHeight = 0;
    Border border = (Border) getComponent();
    String title = border.getTitle();
    if (title != null && title.length() > 0) {
        FontRenderContext fontRenderContext = Platform.getFontRenderContext();
        Rectangle2D headingBounds = font.getStringBounds(title, fontRenderContext);
        preferredWidth = (int) Math.ceil(headingBounds.getWidth());
    }
    Component content = border.getContent();
    if (content != null) {
        Dimensions preferredSize = content.getPreferredSize();
        preferredWidth = Math.max(preferredWidth, preferredSize.width);
        preferredHeight += preferredSize.height;
    }
    preferredWidth += paddingThicknessWidth();
    preferredHeight += paddingThicknessHeight();
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Dimensions(org.apache.pivot.wtk.Dimensions) FontRenderContext(java.awt.font.FontRenderContext) Component(org.apache.pivot.wtk.Component) Border(org.apache.pivot.wtk.Border) Paint(java.awt.Paint)

Example 5 with Border

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

the class BorderSkin method paint.

@Override
public void paint(Graphics2D graphics) {
    Border border = (Border) getComponent();
    String title = border.getTitle();
    // TODO Java2D doesn't support variable corner radii; we'll need to
    // "fake" this by drawing multiple arcs
    int cornerRadius = cornerRadii.topLeft;
    int width = getWidth();
    int height = getHeight();
    int strokeX = thickness / 2;
    int strokeY = topThickness / 2;
    int strokeWidth = Math.max(width - thickness, 0);
    int strokeHeight = Math.max(height - (int) Math.ceil((topThickness + thickness) * 0.5), 0);
    // Draw the background
    Paint backgroundPaint = getBackgroundPaint();
    if (backgroundPaint != null) {
        graphics.setPaint(backgroundPaint);
        if (cornerRadius > 0) {
            GraphicsUtilities.setAntialiasingOn(graphics);
            graphics.fillRoundRect(strokeX, strokeY, strokeWidth, strokeHeight, cornerRadius, cornerRadius);
            GraphicsUtilities.setAntialiasingOff(graphics);
        } else {
            graphics.fillRect(strokeX, strokeY, strokeWidth, strokeHeight);
        }
    }
    // Draw the title
    if (title != null) {
        FontRenderContext fontRenderContext = GraphicsUtilities.prepareForText(graphics, font, titleColor);
        // Note that we add one pixel to the string bounds for spacing
        Rectangle2D titleBounds = font.getStringBounds(title, fontRenderContext);
        titleBounds = new Rectangle2D.Double(padding.left + thickness, (topThickness - titleBounds.getHeight()) / 2, titleBounds.getWidth() + 1, titleBounds.getHeight());
        graphics.drawString(title, (int) titleBounds.getX(), (int) (titleBounds.getY() + titleAscent));
        Area titleClip = new Area(graphics.getClip());
        titleClip.subtract(new Area(titleBounds));
        graphics.clip(titleClip);
    }
    // Draw the border
    if (thickness > 0 && !themeIsFlat()) {
        graphics.setPaint(color);
        if (cornerRadius > 0) {
            GraphicsUtilities.setAntialiasingOn(graphics);
            graphics.setStroke(new BasicStroke(thickness));
            graphics.draw(new RoundRectangle2D.Double(0.5 * thickness, 0.5 * topThickness, strokeWidth, strokeHeight, cornerRadius, cornerRadius));
            GraphicsUtilities.setAntialiasingOff(graphics);
        } else {
            int y = (topThickness - thickness) / 2;
            GraphicsUtilities.drawRect(graphics, 0, y, width, Math.max(height - y, 0), thickness);
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Area(java.awt.geom.Area) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Rectangle2D(java.awt.geom.Rectangle2D) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Paint(java.awt.Paint) FontRenderContext(java.awt.font.FontRenderContext) Border(org.apache.pivot.wtk.Border) Paint(java.awt.Paint)

Aggregations

Border (org.apache.pivot.wtk.Border)13 Paint (java.awt.Paint)6 Component (org.apache.pivot.wtk.Component)6 BoxPane (org.apache.pivot.wtk.BoxPane)4 Window (org.apache.pivot.wtk.Window)4 FontRenderContext (java.awt.font.FontRenderContext)3 Rectangle2D (java.awt.geom.Rectangle2D)3 RoundRectangle2D (java.awt.geom.RoundRectangle2D)3 Button (org.apache.pivot.wtk.Button)2 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)2 Label (org.apache.pivot.wtk.Label)2 PushButton (org.apache.pivot.wtk.PushButton)2 Theme (org.apache.pivot.wtk.Theme)2 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 Area (java.awt.geom.Area)1 ComponentMouseButtonListener (org.apache.pivot.wtk.ComponentMouseButtonListener)1 Dimensions (org.apache.pivot.wtk.Dimensions)1 Button (org.apache.pivot.wtk.Mouse.Button)1 StackPane (org.apache.pivot.wtk.StackPane)1