Search in sources :

Example 51 with Button

use of org.apache.pivot.wtk.Button 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 52 with Button

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

the class RadioButtons method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    selectButton = (PushButton) namespace.get("selectButton");
    // Get a reference to the button group
    final ButtonGroup numbersGroup = (ButtonGroup) namespace.get("numbers");
    // Add a button press listener
    selectButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            String message = "You selected \"" + numbersGroup.getSelection().getButtonData() + "\".";
            Alert.alert(MessageType.INFO, message, RadioButtons.this);
        }
    });
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) ButtonGroup(org.apache.pivot.wtk.ButtonGroup) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button)

Example 53 with Button

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

the class DataBinding method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    form = (Form) namespace.get("form");
    loadJavaButton = (PushButton) namespace.get("loadJavaButton");
    loadJSONButton = (PushButton) namespace.get("loadJSONButton");
    clearButton = (PushButton) namespace.get("clearButton");
    sourceLabel = (Label) namespace.get("sourceLabel");
    loadJavaButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            form.load(new BeanAdapter(CONTACT));
            sourceLabel.setText("Java");
        }
    });
    loadJSONButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            JSONSerializer serializer = new JSONSerializer();
            try (InputStream inputStream = getClass().getResourceAsStream("contact.json")) {
                form.load(serializer.readObject(inputStream));
                sourceLabel.setText("JSON");
            } catch (Exception exception) {
                System.err.println(exception);
            }
            button.setEnabled(true);
        }
    });
    clearButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            form.clear();
            sourceLabel.setText("");
        }
    });
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) InputStream(java.io.InputStream) BeanAdapter(org.apache.pivot.beans.BeanAdapter) JSONSerializer(org.apache.pivot.json.JSONSerializer)

Example 54 with Button

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

the class BXMLExplorerWindow method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    // hide until we support editing and saving BXML files
    if (!BXMLExplorer.ENABLE_EDITING) {
        paletteTabPane.getTabs().remove(paletteTreeViewScrollPane);
        splitPane.setSplitRatio(0);
        fileMenuSection.remove(fileNewMenuItem);
    }
    fileBrowserSheet.setDisabledFileFilter(new Filter<File>() {

        @Override
        public boolean include(File item) {
            return !(item.isDirectory() || item.getName().endsWith(".bxml"));
        }
    });
    closeButton.setEnabled(false);
    closeButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            int x = tabPane.getSelectedIndex();
            tabPane.getTabs().remove(x, 1);
            if (tabPane.getTabs().getLength() > 0) {
                x = Math.max(x - 1, 0);
                tabPane.setSelectedIndex(x);
            }
            closeButton.setEnabled(tabPane.getTabs().getLength() > 0);
        }
    });
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) File(java.io.File)

Example 55 with Button

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

the class ExpenseSheet method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resource) {
    this.resources = resource;
    dateSpinner = (Spinner) namespace.get("dateSpinner");
    typeListButton = (ListButton) namespace.get("typeListButton");
    amountTextInput = (TextInput) namespace.get("amountTextInput");
    cancelButton = (PushButton) namespace.get("cancelButton");
    okButton = (PushButton) namespace.get("okButton");
    cancelButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            close(false);
        }
    });
    okButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            close(true);
        }
    });
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) ListButton(org.apache.pivot.wtk.ListButton)

Aggregations

Button (org.apache.pivot.wtk.Button)61 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)43 PushButton (org.apache.pivot.wtk.PushButton)40 Component (org.apache.pivot.wtk.Component)15 ListButton (org.apache.pivot.wtk.ListButton)12 IOException (java.io.IOException)11 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)11 File (java.io.File)9 BoxPane (org.apache.pivot.wtk.BoxPane)9 Sheet (org.apache.pivot.wtk.Sheet)9 ListView (org.apache.pivot.wtk.ListView)8 SheetCloseListener (org.apache.pivot.wtk.SheetCloseListener)8 ButtonStateListener (org.apache.pivot.wtk.ButtonStateListener)7 List (org.apache.pivot.collections.List)6 Sequence (org.apache.pivot.collections.Sequence)6 FileBrowserSheet (org.apache.pivot.wtk.FileBrowserSheet)6 Point (org.apache.pivot.wtk.Point)6 Span (org.apache.pivot.wtk.Span)6 GradientPaint (java.awt.GradientPaint)5 SerializationException (org.apache.pivot.serialization.SerializationException)5