Search in sources :

Example 11 with ListButton

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

the class TerraListButtonSkin method getPreferredHeight.

@Override
public int getPreferredHeight(int width) {
    ListButton listButton = (ListButton) getComponent();
    Button.DataRenderer dataRenderer = listButton.getDataRenderer();
    dataRenderer.render(listButton.getButtonData(), listButton, false);
    int preferredHeight = dataRenderer.getPreferredHeight(-1) + padding.getHeight() + 2;
    return preferredHeight;
}
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 12 with ListButton

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

the class Pivot714 method getWindow.

public Window getWindow(final Window ownerArgument) {
    this.owner = ownerArgument;
    final BXMLSerializer bxmlSerializer = new BXMLSerializer();
    try {
        result = (Dialog) bxmlSerializer.readObject(Pivot714.class.getResource("pivot_714.bxml"));
    } catch (IOException e) {
        e.printStackTrace();
    } catch (SerializationException e) {
        e.printStackTrace();
    }
    final ListButton motif = (ListButton) bxmlSerializer.getNamespace().get("motif");
    ArrayList<String> al = new ArrayList<>();
    al.add("One");
    al.add("Two");
    motif.setListData(al);
    CalendarButton cbDate = (CalendarButton) bxmlSerializer.getNamespace().get("date");
    dcl = (new DialogCloseListener() {

        @Override
        public void dialogClosed(Dialog dialog, boolean modal) {
        // empty block
        }
    });
    cbDate.getCalendarButtonSelectionListeners().add(new CalendarButtonSelectionListener() {

        @Override
        public void selectedDateChanged(CalendarButton calendarButton, CalendarDate previousSelectedDate) {
        // empty block
        }
    });
    return result;
}
Also used : SerializationException(org.apache.pivot.serialization.SerializationException) ArrayList(org.apache.pivot.collections.ArrayList) CalendarButtonSelectionListener(org.apache.pivot.wtk.CalendarButtonSelectionListener) IOException(java.io.IOException) ListButton(org.apache.pivot.wtk.ListButton) CalendarDate(org.apache.pivot.util.CalendarDate) CalendarButton(org.apache.pivot.wtk.CalendarButton) Dialog(org.apache.pivot.wtk.Dialog) DialogCloseListener(org.apache.pivot.wtk.DialogCloseListener) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 13 with ListButton

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

the class Pivot694 method initializeFields.

private void initializeFields(BXMLSerializer serializer) {
    System.out.println("initializeFields: start");
    // TODO: for release 2.1 ... maybe generalizing some test here
    // pushButtons =
    // (ButtonGroup)serializer.getNamespace().get("pushButtons");
    // toggleButtons =
    // (ButtonGroup)serializer.getNamespace().get("toggleButtons");
    // radioButtons =
    // (ButtonGroup)serializer.getNamespace().get("radioButtons");
    // checkButtons =
    // (ButtonGroup)serializer.getNamespace().get("checkButtons");
    // checkTriButtons =
    // (ButtonGroup)serializer.getNamespace().get("checkTriButtons");
    calendarButton1 = (CalendarButton) serializer.getNamespace().get("calendarButton1");
    calendarButton2 = (CalendarButton) serializer.getNamespace().get("calendarButton2");
    spinner1 = (Spinner) serializer.getNamespace().get("spinner1");
    spinner2 = (Spinner) serializer.getNamespace().get("spinner2");
    listView1 = (ListView) serializer.getNamespace().get("listView1");
    listView2 = (ListView) serializer.getNamespace().get("listView2");
    tableView1 = (TableView) serializer.getNamespace().get("tableView1");
    tableView2 = (TableView) serializer.getNamespace().get("tableView2");
    treeView1 = (TreeView) serializer.getNamespace().get("treeView1");
    treeView2 = (TreeView) serializer.getNamespace().get("treeView2");
    listButton1 = (ListButton) serializer.getNamespace().get("listButton1");
    listButton2 = (ListButton) serializer.getNamespace().get("listButton2");
    clearSelectionButton = (PushButton) serializer.getNamespace().get("clearSelectionButton");
    clearSelectionButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            System.out.println("Clearing selection from " + button.getName() + " at " + new Date());
            // TODO: for release 2.1 ... maybe generalizing some test here
            // pushButtons.clearSelection();
            // toggleButtons.clearSelection();
            // radioButtons.clearSelection();
            // checkButtons.clearSelection();
            // checkTriButtons.clearSelection();
            calendarButton1.clearSelection();
            calendarButton2.clearSelection();
            spinner1.clearSelection();
            spinner2.clearSelection();
            listButton1.clearSelection();
            listButton2.clearSelection();
            listView1.clearSelection();
            listView2.clearSelection();
            tableView1.clearSelection();
            tableView2.clearSelection();
            treeView1.clearSelection();
            treeView2.clearSelection();
        }
    });
    clearButton = (PushButton) serializer.getNamespace().get("clearButton");
    clearButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            System.out.println("Clearing data from " + button.getName() + " at " + new Date());
            // TODO: verify for release 2.1 if implement a method to empty
            // components inside ...
            // pushButtons.remove(button);
            // toggleButtons.remove(button);
            // radioButtons.remove(button);
            // checkButtons.remove(button);
            // checkTriButtons.remove(button);
            // force clear of elements data ...
            clearComponent(calendarButton1);
            clearComponent(calendarButton2);
            clearComponent(spinner1);
            clearComponent(spinner2);
            clearComponent(listButton1);
            clearComponent(listButton2);
            clearComponent(listView1);
            clearComponent(listView2);
            clearComponent(tableView1);
            clearComponent(tableView2);
            clearComponent(treeView1);
            clearComponent(treeView2);
        // TODO: put (in bxml) the two tableView in a SplitPane, and see
        // some strange moving mouse over ...
        // TODO: add clear/clearSelection methods even to some type of
        // buttons (all types in the first row displayed) ...
        }
    });
    System.out.println("initializeFields: end");
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) CalendarButton(org.apache.pivot.wtk.CalendarButton) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) ListButton(org.apache.pivot.wtk.ListButton) Date(java.util.Date)

Example 14 with ListButton

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

the class ListButtonSkin method keyPressed.

/**
 * {@link KeyCode#SPACE SPACE} Repaints the component to reflect the pressed
 * state and opens the popup.<br> {@link KeyCode#UP UP} Selects the previous
 * enabled list item.<br> {@link KeyCode#DOWN DOWN} Selects the next enabled
 * list item.
 *
 * @see #keyReleased(Component, int,
 * org.apache.pivot.wtk.Keyboard.KeyLocation)
 */
@Override
public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
    boolean consumed = false;
    ListButton listButton = (ListButton) getComponent();
    if (keyCode == Keyboard.KeyCode.SPACE) {
        pressed = true;
        repaintComponent();
        if (listViewPopup.isOpen()) {
            listViewPopup.close();
        } else if (!listButton.isRepeatable()) {
            listViewPopup.open(component.getWindow());
        }
    } else if (keyCode == Keyboard.KeyCode.UP) {
        int index = listButton.getSelectedIndex();
        do {
            index--;
        } while (index >= 0 && listButton.isItemDisabled(index));
        if (index >= 0) {
            listButton.setSelectedIndex(index);
            consumed = true;
        }
    } else if (keyCode == Keyboard.KeyCode.DOWN) {
        if (Keyboard.isPressed(Keyboard.Modifier.ALT)) {
            listViewPopup.open(component.getWindow());
            consumed = true;
        } else {
            int index = listButton.getSelectedIndex();
            int count = listButton.getListData().getLength();
            do {
                index++;
            } while (index < count && listView.isItemDisabled(index));
            if (index < count) {
                listButton.setSelectedIndex(index);
                consumed = true;
            }
        }
    } else {
        consumed = super.keyPressed(component, keyCode, keyLocation);
    }
    return consumed;
}
Also used : ListButton(org.apache.pivot.wtk.ListButton)

Example 15 with ListButton

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

the class ListButtonSkin method keyTyped.

/**
 * Select the next enabled list item where the first character of the
 * rendered text matches the typed key (case insensitive).
 */
@Override
public boolean keyTyped(Component component, char character) {
    boolean consumed = super.keyTyped(component, character);
    ListButton listButton = (ListButton) getComponent();
    List<?> listData = listButton.getListData();
    ListView.ItemRenderer itemRenderer = listButton.getItemRenderer();
    char characterUpper = Character.toUpperCase(character);
    for (int i = listButton.getSelectedIndex() + 1, n = listData.getLength(); i < n; i++) {
        if (!listButton.isItemDisabled(i)) {
            String string = itemRenderer.toString(listData.get(i));
            if (string != null && string.length() > 0) {
                char first = Character.toUpperCase(string.charAt(0));
                if (first == characterUpper) {
                    listButton.setSelectedIndex(i);
                    consumed = true;
                    break;
                }
            }
        }
    }
    return consumed;
}
Also used : ListButton(org.apache.pivot.wtk.ListButton) ListView(org.apache.pivot.wtk.ListView)

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