Search in sources :

Example 6 with MenuButton

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

the class TerraMenuButtonSkin method getPreferredHeight.

@Override
public int getPreferredHeight(int width) {
    int preferredHeight = 0;
    if (width == -1) {
        preferredHeight = getPreferredSize().height;
    } else {
        MenuButton menuButton = (MenuButton) getComponent();
        Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
        dataRenderer.render(menuButton.getButtonData(), menuButton, false);
        preferredHeight = dataRenderer.getPreferredHeight(-1) + padding.top + padding.bottom + 2;
        // Adjust for preferred aspect ratio
        if (!Float.isNaN(maximumAspectRatio) && (float) width / (float) preferredHeight > maximumAspectRatio) {
            preferredHeight = (int) (width / maximumAspectRatio);
        }
    }
    return preferredHeight;
}
Also used : MenuButton(org.apache.pivot.wtk.MenuButton) Button(org.apache.pivot.wtk.Button) MenuButton(org.apache.pivot.wtk.MenuButton) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Example 7 with MenuButton

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

the class TerraMenuButtonSkin method paint.

@Override
public void paint(Graphics2D graphics) {
    MenuButton menuButton = (MenuButton) getComponent();
    int width = getWidth();
    int height = getHeight();
    Color colorLocal = null;
    Color backgroundColorLocal = null;
    Color bevelColorLocal = null;
    Color borderColorLocal = null;
    if (!toolbar || highlighted || menuButton.isFocused() || menuPopup.isOpen()) {
        if (menuButton.isEnabled()) {
            colorLocal = this.color;
            backgroundColorLocal = this.backgroundColor;
            bevelColorLocal = (pressed || (menuPopup.isOpen() && !menuPopup.isClosing())) ? pressedBevelColor : this.bevelColor;
            borderColorLocal = this.borderColor;
        } else {
            colorLocal = disabledColor;
            backgroundColorLocal = disabledBackgroundColor;
            bevelColorLocal = disabledBevelColor;
            borderColorLocal = disabledBorderColor;
        }
    }
    // Paint the background
    if (backgroundColorLocal != null && bevelColorLocal != null) {
        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(padding.left + 1, padding.top + 1, Math.max(width - (padding.getWidth() + spacing + TRIGGER_WIDTH + 2), 0), Math.max(height - (padding.getHeight() + 2), 0));
    Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
    dataRenderer.render(menuButton.getButtonData(), menuButton, highlighted);
    dataRenderer.setSize(contentBounds.getSize());
    Graphics2D contentGraphics = (Graphics2D) graphics.create();
    contentGraphics.translate(contentBounds.x, contentBounds.y);
    contentGraphics.clipRect(0, 0, contentBounds.width, contentBounds.height);
    dataRenderer.paint(contentGraphics);
    contentGraphics.dispose();
    GraphicsUtilities.setAntialiasingOn(graphics);
    // Paint the border
    if (borderColorLocal != null && !themeIsFlat()) {
        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 (menuButton.isFocused() && !toolbar) {
        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(colorLocal);
    Bounds triggerBounds = new Bounds(Math.max(width - (padding.right + TRIGGER_WIDTH), 0), 0, // TODO: this calculation doesn't look right \\// (should be + not -?)
    TRIGGER_WIDTH, Math.max(height - (padding.top - padding.bottom), 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) MenuButton(org.apache.pivot.wtk.MenuButton) Button(org.apache.pivot.wtk.Button) Color(java.awt.Color) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Bounds(org.apache.pivot.wtk.Bounds) MenuButton(org.apache.pivot.wtk.MenuButton) GradientPaint(java.awt.GradientPaint) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D)

Example 8 with MenuButton

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

the class TerraMenuButtonSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    int preferredWidth = 0;
    if (height == -1) {
        preferredWidth = getPreferredSize().width;
    } else {
        MenuButton menuButton = (MenuButton) getComponent();
        Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
        dataRenderer.render(menuButton.getButtonData(), menuButton, false);
        preferredWidth = dataRenderer.getPreferredWidth(-1) + TRIGGER_WIDTH + padding.left + padding.right + spacing + 2;
        // Adjust for preferred aspect ratio
        if (!Float.isNaN(minumumAspectRatio) && (float) preferredWidth / (float) height < minumumAspectRatio) {
            preferredWidth = (int) (height * minumumAspectRatio);
        }
    }
    return preferredWidth;
}
Also used : MenuButton(org.apache.pivot.wtk.MenuButton) Button(org.apache.pivot.wtk.Button) MenuButton(org.apache.pivot.wtk.MenuButton) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Example 9 with MenuButton

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

the class TerraMenuButtonSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    MenuButton menuButton = (MenuButton) getComponent();
    Button.DataRenderer dataRenderer = menuButton.getDataRenderer();
    dataRenderer.render(menuButton.getButtonData(), menuButton, false);
    Dimensions contentSize = dataRenderer.getPreferredSize();
    int preferredWidth = contentSize.width + TRIGGER_WIDTH + padding.left + padding.right + 2;
    int preferredHeight = contentSize.height + padding.top + padding.bottom + 2;
    // Adjust for preferred aspect ratio
    float aspectRatio = (float) preferredWidth / (float) preferredHeight;
    if (!Float.isNaN(minumumAspectRatio) && aspectRatio < minumumAspectRatio) {
        preferredWidth = (int) (preferredHeight * minumumAspectRatio);
    }
    if (!Float.isNaN(maximumAspectRatio) && aspectRatio > maximumAspectRatio) {
        preferredHeight = (int) (preferredWidth / maximumAspectRatio);
    }
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : MenuButton(org.apache.pivot.wtk.MenuButton) Button(org.apache.pivot.wtk.Button) MenuButton(org.apache.pivot.wtk.MenuButton) Dimensions(org.apache.pivot.wtk.Dimensions) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Aggregations

MenuButton (org.apache.pivot.wtk.MenuButton)9 GradientPaint (java.awt.GradientPaint)5 Button (org.apache.pivot.wtk.Button)5 Point (org.apache.pivot.wtk.Point)5 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 GeneralPath (java.awt.geom.GeneralPath)1 RoundRectangle2D (java.awt.geom.RoundRectangle2D)1 Vote (org.apache.pivot.util.Vote)1 Bounds (org.apache.pivot.wtk.Bounds)1 Dimensions (org.apache.pivot.wtk.Dimensions)1 Display (org.apache.pivot.wtk.Display)1 Menu (org.apache.pivot.wtk.Menu)1 Window (org.apache.pivot.wtk.Window)1 WindowStateListener (org.apache.pivot.wtk.WindowStateListener)1