Search in sources :

Example 31 with PushButton

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

the class TerraPromptSkin method optionInserted.

@Override
public void optionInserted(Prompt prompt, int index) {
    Object option = prompt.getOptions().get(index);
    PushButton optionButton = new PushButton(option);
    optionButton.setStyleName(BUTTON_STYLE_NAME);
    optionButton.getButtonPressListeners().add(optionButtonPressListener);
    optionButtonBoxPane.insert(optionButton, index);
}
Also used : PushButton(org.apache.pivot.wtk.PushButton)

Example 32 with PushButton

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

the class TerraPushButtonSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    int preferredWidth = 0;
    if (height == -1) {
        preferredWidth = getPreferredSize().width;
    } else {
        PushButton pushButton = (PushButton) getComponent();
        Button.DataRenderer dataRenderer = pushButton.getDataRenderer();
        dataRenderer.render(pushButton.getButtonData(), pushButton, false);
        // Include padding in constraint
        int contentHeight = height;
        if (contentHeight != -1) {
            contentHeight = Math.max(contentHeight - paddingHeight(), 0);
        }
        preferredWidth = dataRenderer.getPreferredWidth(contentHeight) + paddingWidth();
        // Adjust for preferred aspect ratio
        if (!Float.isNaN(minimumAspectRatio) && (float) preferredWidth / (float) height < minimumAspectRatio) {
            preferredWidth = (int) (height * minimumAspectRatio);
        }
    }
    return preferredWidth;
}
Also used : PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) PushButton(org.apache.pivot.wtk.PushButton) GradientPaint(java.awt.GradientPaint)

Example 33 with PushButton

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

the class TerraPushButtonSkin method paint.

@Override
public void paint(Graphics2D graphics) {
    PushButton pushButton = (PushButton) getComponent();
    int width = getWidth();
    int height = getHeight();
    Color backgroundColorLocal = null;
    Color bevelColorLocal = null;
    Color borderColorLocal = null;
    if (!toolbar || highlighted || pushButton.isFocused()) {
        if (pushButton.isEnabled()) {
            backgroundColorLocal = this.backgroundColor;
            bevelColorLocal = (pressed || pushButton.isSelected()) ? pressedBevelColor : this.bevelColor;
            borderColorLocal = this.borderColor;
        } else {
            backgroundColorLocal = disabledBackgroundColor;
            bevelColorLocal = disabledBevelColor;
            borderColorLocal = disabledBorderColor;
        }
    }
    // Paint the background
    GraphicsUtilities.setAntialiasingOn(graphics);
    if (backgroundColorLocal != null && bevelColorLocal != null) {
        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);
    Button.DataRenderer dataRenderer = pushButton.getDataRenderer();
    dataRenderer.render(pushButton.getButtonData(), pushButton, highlighted);
    dataRenderer.setSize(Math.max(width - paddingWidth(), 0), Math.max(getHeight() - paddingHeight(), 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);
    // 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 (pushButton.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));
    }
}
Also used : BasicStroke(java.awt.BasicStroke) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) Color(java.awt.Color) RoundRectangle2D(java.awt.geom.RoundRectangle2D) GradientPaint(java.awt.GradientPaint) PushButton(org.apache.pivot.wtk.PushButton) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D)

Example 34 with PushButton

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

the class TerraPushButtonSkin method getPreferredHeight.

@Override
public int getPreferredHeight(int width) {
    int preferredHeight = 0;
    if (width == -1) {
        preferredHeight = getPreferredSize().height;
    } else {
        PushButton pushButton = (PushButton) getComponent();
        Button.DataRenderer dataRenderer = pushButton.getDataRenderer();
        dataRenderer.render(pushButton.getButtonData(), pushButton, false);
        // Include padding in constraint
        int contentWidth = width;
        if (contentWidth != -1) {
            contentWidth = Math.max(contentWidth - paddingWidth(), 0);
        }
        preferredHeight = dataRenderer.getPreferredHeight(contentWidth) + paddingHeight();
        // Adjust for preferred aspect ratio
        if (!Float.isNaN(maximumAspectRatio) && (float) width / (float) preferredHeight > maximumAspectRatio) {
            preferredHeight = (int) (width / maximumAspectRatio);
        }
    }
    return preferredHeight;
}
Also used : PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) PushButton(org.apache.pivot.wtk.PushButton) GradientPaint(java.awt.GradientPaint)

Example 35 with PushButton

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

the class TerraAlertSkin method optionInserted.

@Override
public void optionInserted(Alert alert, int index) {
    Object option = alert.getOptions().get(index);
    PushButton optionButton = new PushButton(option);
    optionButton.setStyleName(BUTTON_STYLE_NAME);
    optionButton.getButtonPressListeners().add(optionButtonPressListener);
    optionButtonBoxPane.insert(optionButton, index);
}
Also used : PushButton(org.apache.pivot.wtk.PushButton)

Aggregations

PushButton (org.apache.pivot.wtk.PushButton)39 Button (org.apache.pivot.wtk.Button)29 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)23 Window (org.apache.pivot.wtk.Window)9 BoxPane (org.apache.pivot.wtk.BoxPane)8 Component (org.apache.pivot.wtk.Component)6 GradientPaint (java.awt.GradientPaint)5 ListButton (org.apache.pivot.wtk.ListButton)5 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)4 Path (org.apache.pivot.collections.Sequence.Tree.Path)3 Checkbox (org.apache.pivot.wtk.Checkbox)3 Frame (org.apache.pivot.wtk.Frame)3 ListView (org.apache.pivot.wtk.ListView)3 Sheet (org.apache.pivot.wtk.Sheet)3 TreeView (org.apache.pivot.wtk.TreeView)3 TreeViewSelectionListener (org.apache.pivot.wtk.TreeViewSelectionListener)3 TreeBranch (org.apache.pivot.wtk.content.TreeBranch)3 File (java.io.File)2 TaskExecutionException (org.apache.pivot.util.concurrent.TaskExecutionException)2 Alert (org.apache.pivot.wtk.Alert)2