Search in sources :

Example 11 with Checkbox

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

the class TerraCheckboxSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    Checkbox checkbox = (Checkbox) getComponent();
    Button.DataRenderer dataRenderer = checkbox.getDataRenderer();
    dataRenderer.render(checkbox.getButtonData(), checkbox, false);
    int preferredWidth = CHECKBOX_SIZE;
    int preferredHeight = CHECKBOX_SIZE;
    Object buttonData = checkbox.getButtonData();
    if (buttonData != null) {
        dataRenderer.render(buttonData, checkbox, false);
        preferredWidth += dataRenderer.getPreferredWidth(-1) + spacing * 2;
        preferredHeight = Math.max(preferredHeight, dataRenderer.getPreferredHeight(-1));
    }
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : Button(org.apache.pivot.wtk.Button) Checkbox(org.apache.pivot.wtk.Checkbox) Dimensions(org.apache.pivot.wtk.Dimensions) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint)

Example 12 with Checkbox

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

the class TerraCheckboxSkin method paint.

@Override
public void paint(Graphics2D graphics) {
    Checkbox checkbox = (Checkbox) getComponent();
    int width = getWidth();
    int height = getHeight();
    // Paint the button
    int offset = (height - CHECKBOX_SIZE) / 2;
    graphics.translate(0, offset);
    paintButton(graphics, checkbox.isEnabled(), checkbox.getState());
    graphics.translate(0, -offset);
    // Paint the content
    Button.DataRenderer dataRenderer = checkbox.getDataRenderer();
    Object buttonData = checkbox.getButtonData();
    dataRenderer.render(buttonData, checkbox, false);
    dataRenderer.setSize(Math.max(width - (CHECKBOX_SIZE + spacing * 2), 0), height);
    Graphics2D contentGraphics = (Graphics2D) graphics.create();
    contentGraphics.translate(CHECKBOX_SIZE + spacing, 0);
    contentGraphics.clipRect(0, 0, dataRenderer.getWidth(), dataRenderer.getHeight());
    dataRenderer.paint(contentGraphics);
    contentGraphics.dispose();
    // Paint the focus state
    if (checkbox.isFocused()) {
        if (buttonData == null) {
            Color focusColor = ColorUtilities.setTransparencyInColor(buttonSelectionColor, ALPHA);
            graphics.setColor(focusColor);
            graphics.fillRect(0, 0, CHECKBOX_SIZE, CHECKBOX_SIZE);
        } else {
            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(buttonBorderColor);
            GraphicsUtilities.setAntialiasingOn(graphics);
            Rectangle2D focusRectangle = new Rectangle2D.Double(CHECKBOX_SIZE + 1, 0.5, dataRenderer.getWidth() + spacing * 2 - 2, dataRenderer.getHeight() - 1);
            graphics.draw(focusRectangle);
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Button(org.apache.pivot.wtk.Button) Checkbox(org.apache.pivot.wtk.Checkbox) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D)

Example 13 with Checkbox

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

the class RepeatableListButtons method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    colorListButton = (ListButton) namespace.get("colorListButton");
    checkboxBoxPane = (BoxPane) namespace.get("checkboxBoxPane");
    ButtonStateListener buttonStateListener = new ButtonStateListener() {

        @Override
        public void stateChanged(Button button, State previousState) {
            if (button.isSelected()) {
                selectedCount++;
            } else {
                selectedCount--;
            }
            applyColorAction.setEnabled(selectedCount > 0);
        }
    };
    ArrayList<String> numbers = new ArrayList<>("One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten");
    for (String number : numbers) {
        Checkbox checkbox = new Checkbox(number);
        checkbox.getButtonStateListeners().add(buttonStateListener);
        checkboxBoxPane.add(checkbox);
    }
}
Also used : Button(org.apache.pivot.wtk.Button) ListButton(org.apache.pivot.wtk.ListButton) State(org.apache.pivot.wtk.Button.State) Checkbox(org.apache.pivot.wtk.Checkbox) ArrayList(org.apache.pivot.collections.ArrayList) ButtonStateListener(org.apache.pivot.wtk.ButtonStateListener)

Aggregations

Checkbox (org.apache.pivot.wtk.Checkbox)13 Button (org.apache.pivot.wtk.Button)9 GradientPaint (java.awt.GradientPaint)5 Paint (java.awt.Paint)5 ListButton (org.apache.pivot.wtk.ListButton)3 PushButton (org.apache.pivot.wtk.PushButton)3 BoxPane (org.apache.pivot.wtk.BoxPane)2 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)2 ButtonStateListener (org.apache.pivot.wtk.ButtonStateListener)2 Frame (org.apache.pivot.wtk.Frame)2 ListView (org.apache.pivot.wtk.ListView)2 Sheet (org.apache.pivot.wtk.Sheet)2 SheetCloseListener (org.apache.pivot.wtk.SheetCloseListener)2 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1 File (java.io.File)1 URL (java.net.URL)1 FileObject (org.apache.commons.vfs2.FileObject)1