Search in sources :

Example 76 with Bounds

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

the class TerraColorChooserButtonSkin method paint.

@Override
public void paint(Graphics2D graphics) {
    ColorChooserButton colorChooserButton = (ColorChooserButton) getComponent();
    int width = getWidth();
    int height = getHeight();
    Color backgroundColorLocal = null;
    Color bevelColorLocal = null;
    Color borderColorLocal = null;
    if (colorChooserButton.isEnabled()) {
        backgroundColorLocal = this.backgroundColor;
        bevelColorLocal = (pressed || (colorChooserPopup.isOpen() && !colorChooserPopup.isClosing())) ? pressedBevelColor : this.bevelColor;
        borderColorLocal = this.borderColor;
    } else {
        backgroundColorLocal = disabledBackgroundColor;
        bevelColorLocal = disabledBevelColor;
        borderColorLocal = disabledBorderColor;
    }
    // Paint the background
    GraphicsUtilities.setAntialiasingOn(graphics);
    if (!themeIsFlat()) {
        graphics.setPaint(new GradientPaint(width / 2f, 0, bevelColorLocal, width / 2f, height / 2f, backgroundColorLocal));
    } else {
        graphics.setPaint(backgroundColorLocal);
    }
    graphics.fill(new RoundRectangle2D.Double(0.5, 0.5, width - 1, height - 1, CORNER_RADIUS, CORNER_RADIUS));
    // Paint the content
    GraphicsUtilities.setAntialiasingOff(graphics);
    Bounds contentBounds = new Bounds(0, 0, Math.max(width - TRIGGER_WIDTH - 1, 0), Math.max(height - 1, 0));
    Button.DataRenderer dataRenderer = colorChooserButton.getDataRenderer();
    dataRenderer.render(colorChooserButton.getButtonData(), colorChooserButton, false);
    dataRenderer.setSize(Math.max(contentBounds.width - (padding.getWidth() + 2) + 1, 0), Math.max(contentBounds.height - (padding.getHeight() + 2) + 1, 0));
    Graphics2D contentGraphics = (Graphics2D) graphics.create();
    contentGraphics.translate(padding.left + 1, padding.top + 1);
    contentGraphics.clipRect(0, 0, dataRenderer.getWidth(), dataRenderer.getHeight());
    dataRenderer.paint(contentGraphics);
    contentGraphics.dispose();
    GraphicsUtilities.setAntialiasingOn(graphics);
    if (!themeIsFlat()) {
        // Paint the border
        if (borderColorLocal != null) {
            graphics.setPaint(borderColorLocal);
            graphics.setStroke(new BasicStroke(1));
            graphics.draw(new RoundRectangle2D.Double(0.5, 0.5, width - 1, height - 1, CORNER_RADIUS, CORNER_RADIUS));
        }
    }
    // Paint the focus state
    if (colorChooserButton.isFocused()) {
        BasicStroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 0.0f, 2.0f }, 0.0f);
        graphics.setStroke(dashStroke);
        graphics.setColor(this.borderColor);
        graphics.draw(new RoundRectangle2D.Double(2.5, 2.5, Math.max(width - 5, 0), Math.max(height - 5, 0), CORNER_RADIUS / 2, CORNER_RADIUS / 2));
    }
    GraphicsUtilities.setAntialiasingOff(graphics);
    // Paint the trigger
    GeneralPath triggerIconShape = new GeneralPath(Path2D.WIND_EVEN_ODD);
    triggerIconShape.moveTo(0, 0);
    triggerIconShape.lineTo(3, 3);
    triggerIconShape.lineTo(6, 0);
    triggerIconShape.closePath();
    Graphics2D triggerGraphics = (Graphics2D) graphics.create();
    triggerGraphics.setStroke(new BasicStroke(0));
    triggerGraphics.setPaint(color);
    Bounds triggerBounds = new Bounds(Math.max(width - (padding.right + TRIGGER_WIDTH), 0), 0, TRIGGER_WIDTH, Math.max(height - padding.getHeight(), 0));
    int tx = triggerBounds.x + (triggerBounds.width - triggerIconShape.getBounds().width) / 2;
    int ty = triggerBounds.y + (triggerBounds.height - triggerIconShape.getBounds().height) / 2;
    triggerGraphics.translate(tx, ty);
    triggerGraphics.draw(triggerIconShape);
    triggerGraphics.fill(triggerIconShape);
    triggerGraphics.dispose();
}
Also used : BasicStroke(java.awt.BasicStroke) GeneralPath(java.awt.geom.GeneralPath) ColorChooserButton(org.apache.pivot.wtk.ColorChooserButton) ColorChooserButton(org.apache.pivot.wtk.ColorChooserButton) Button(org.apache.pivot.wtk.Button) Color(java.awt.Color) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Bounds(org.apache.pivot.wtk.Bounds) GradientPaint(java.awt.GradientPaint) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D)

Example 77 with Bounds

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

the class FakeWindowSkin method paint.

@Override
public void paint(Graphics2D graphics) {
    // Call the base class to paint the background
    super.paint(graphics);
    int width = getWidth();
    int height = getHeight();
    int titleBarHeight = titleBarTablePane.getHeight();
    // Draw the title area
    Color titleBarBackgroundColorLocal = this.titleBarBackgroundColor;
    Color titleBarBorderColorLocal = this.titleBarBorderColor;
    Color titleBarBevelColorLocal = this.titleBarBevelColor;
    graphics.setPaint(new GradientPaint(width / 2f, 0, titleBarBevelColorLocal, width / 2f, titleBarHeight + 1, titleBarBackgroundColorLocal));
    graphics.fillRect(0, 0, width, titleBarHeight + 1);
    // Draw the border
    graphics.setPaint(titleBarBorderColorLocal);
    GraphicsUtilities.drawRect(graphics, 0, 0, width, titleBarHeight + 2);
    // Draw the content area
    Bounds contentAreaRectangle = new Bounds(0, titleBarHeight + 2, width, height - (titleBarHeight + 2));
    graphics.setPaint(contentBorderColor);
    GraphicsUtilities.drawRect(graphics, contentAreaRectangle.x, contentAreaRectangle.y, contentAreaRectangle.width, contentAreaRectangle.height);
    // graphics.setPaint(contentBevelColor);
    GraphicsUtilities.drawLine(graphics, contentAreaRectangle.x + 1, contentAreaRectangle.y + 1, contentAreaRectangle.width - 2, Orientation.HORIZONTAL);
}
Also used : Color(java.awt.Color) Bounds(org.apache.pivot.wtk.Bounds) GradientPaint(java.awt.GradientPaint) GradientPaint(java.awt.GradientPaint)

Aggregations

Bounds (org.apache.pivot.wtk.Bounds)77 Point (org.apache.pivot.wtk.Point)21 GradientPaint (java.awt.GradientPaint)15 Color (java.awt.Color)10 Graphics2D (java.awt.Graphics2D)9 Rectangle (java.awt.Rectangle)7 TableView (org.apache.pivot.wtk.TableView)7 BasicStroke (java.awt.BasicStroke)6 GeneralPath (java.awt.geom.GeneralPath)5 Button (org.apache.pivot.wtk.Button)5 Component (org.apache.pivot.wtk.Component)5 Span (org.apache.pivot.wtk.Span)5 TextArea (org.apache.pivot.wtk.TextArea)5 TextPane (org.apache.pivot.wtk.TextPane)5 FontRenderContext (java.awt.font.FontRenderContext)4 LineMetrics (java.awt.font.LineMetrics)4 Area (java.awt.geom.Area)4 RoundRectangle2D (java.awt.geom.RoundRectangle2D)4 ArrayList (org.apache.pivot.collections.ArrayList)4 ScrollPane (org.apache.pivot.wtk.ScrollPane)4