Search in sources :

Example 21 with ListButton

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

the class TerraListButtonSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    ListButton listButton = (ListButton) getComponent();
    Button.DataRenderer dataRenderer = listButton.getDataRenderer();
    // Determine the preferred width of the current button data
    dataRenderer.render(listButton.getButtonData(), listButton, false);
    int preferredWidth = dataRenderer.getPreferredWidth(-1);
    // The preferred width of the button is the max. width of the rendered
    // content plus padding and the trigger width
    List<?> listData = listButton.getListData();
    for (Object item : listData) {
        dataRenderer.render(item, listButton, false);
        preferredWidth = Math.max(preferredWidth, dataRenderer.getPreferredWidth(-1));
    }
    preferredWidth += TRIGGER_WIDTH + padding.getWidth() + 2;
    return preferredWidth;
}
Also used : ListButton(org.apache.pivot.wtk.ListButton) Button(org.apache.pivot.wtk.Button) ListButton(org.apache.pivot.wtk.ListButton) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Example 22 with ListButton

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

the class ComponentInspectorSkin method addEnumControl.

private Component addEnumControl(final Dictionary<String, Object> dictionary, final String key, Class<? extends Enum<?>> type, Form.Section section) {
    Enum<?> value = (Enum<?>) dictionary.get(key);
    ArrayList<Object> listData = new ArrayList<>();
    listData.add(null);
    Enum<?>[] enumConstants = type.getEnumConstants();
    for (int i = 0; i < enumConstants.length; i++) {
        listData.add(enumConstants[i]);
    }
    ListButton listButton = new ListButton();
    listButton.setListData(listData);
    listButton.setSelectedItem(value);
    section.add(listButton);
    Form.setLabel(listButton, key);
    listButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener() {

        private boolean updating = false;

        @Override
        public void selectedIndexChanged(ListButton listButtonArgument, int previousSelectedIndex) {
            if (!updating) {
                updating = true;
                try {
                    dictionary.put(key, listButtonArgument.getSelectedItem());
                } catch (Exception exception) {
                    displayErrorMessage(exception, listButtonArgument.getWindow());
                    listButtonArgument.setSelectedIndex(previousSelectedIndex);
                } finally {
                    updating = false;
                }
            }
        }
    });
    return listButton;
}
Also used : ListButton(org.apache.pivot.wtk.ListButton) ListButtonSelectionListener(org.apache.pivot.wtk.ListButtonSelectionListener) ArrayList(org.apache.pivot.collections.ArrayList) Point(org.apache.pivot.wtk.Point)

Example 23 with ListButton

use of org.apache.pivot.wtk.ListButton 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)

Example 24 with ListButton

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

the class ListButtons method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    listButton = (ListButton) namespace.get("listButton");
    imageView = (ImageView) namespace.get("imageView");
    listButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener() {

        @Override
        public void selectedItemChanged(ListButton listButtonArgument, Object previousSelectedItem) {
            Object selectedItem = listButtonArgument.getSelectedItem();
            if (selectedItem != null) {
                // Get the image URL for the selected item
                Image image = Image.loadFromCache(ImageUtils.findByName("/org/apache/pivot/tutorials/" + selectedItem, "image"));
                // Update the image
                imageView.setImage(image);
            }
        }
    });
    listButton.setSelectedIndex(0);
}
Also used : ListButton(org.apache.pivot.wtk.ListButton) ListButtonSelectionListener(org.apache.pivot.wtk.ListButtonSelectionListener) Image(org.apache.pivot.wtk.media.Image)

Example 25 with ListButton

use of org.apache.pivot.wtk.ListButton 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

ListButton (org.apache.pivot.wtk.ListButton)25 Button (org.apache.pivot.wtk.Button)13 Point (org.apache.pivot.wtk.Point)8 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)7 PushButton (org.apache.pivot.wtk.PushButton)7 ArrayList (org.apache.pivot.collections.ArrayList)6 ListButtonSelectionListener (org.apache.pivot.wtk.ListButtonSelectionListener)6 GradientPaint (java.awt.GradientPaint)5 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)5 IOException (java.io.IOException)4 File (java.io.File)3 List (org.apache.pivot.collections.List)3 SerializationException (org.apache.pivot.serialization.SerializationException)3 Component (org.apache.pivot.wtk.Component)3 Container (org.apache.pivot.wtk.Container)3 Display (org.apache.pivot.wtk.Display)3 TableView (org.apache.pivot.wtk.TableView)3 TableViewSortListener (org.apache.pivot.wtk.TableViewSortListener)3 Color (java.awt.Color)2 Sequence (org.apache.pivot.collections.Sequence)2