Search in sources :

Example 21 with ListView

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

the class TerraListViewSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    ListView listView = (ListView) component;
    listView.getListViewListeners().add(this);
    listView.getListViewItemListeners().add(this);
    listView.getListViewItemStateListeners().add(this);
    listView.getListViewSelectionListeners().add(this);
}
Also used : ListView(org.apache.pivot.wtk.ListView)

Example 22 with ListView

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

the class TerraListViewSkin method mouseDown.

@Override
public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
    boolean consumed = super.mouseDown(component, button, x, y);
    ListView listView = (ListView) getComponent();
    int itemIndex = getItemAt(y);
    if (itemIndex != -1 && !listView.isItemDisabled(itemIndex)) {
        if (!listView.getCheckmarksEnabled() || listView.isCheckmarkDisabled(itemIndex) || !getCheckboxBounds(itemIndex).contains(x, y)) {
            ListView.SelectMode selectMode = listView.getSelectMode();
            if (button == Mouse.Button.LEFT) {
                Keyboard.Modifier commandModifier = Platform.getCommandModifier();
                if (Keyboard.isPressed(Keyboard.Modifier.SHIFT) && selectMode == ListView.SelectMode.MULTI) {
                    Filter<?> disabledItemFilter = listView.getDisabledItemFilter();
                    if (disabledItemFilter == null) {
                        // Select the range
                        ArrayList<Span> selectedRanges = new ArrayList<>();
                        int startIndex = listView.getFirstSelectedIndex();
                        int endIndex = listView.getLastSelectedIndex();
                        Span selectedRange = (itemIndex > startIndex) ? new Span(startIndex, itemIndex) : new Span(itemIndex, endIndex);
                        selectedRanges.add(selectedRange);
                        listView.setSelectedRanges(selectedRanges);
                    }
                } else if (Keyboard.isPressed(commandModifier) && selectMode == ListView.SelectMode.MULTI) {
                    // Toggle the item's selection state
                    if (listView.isItemSelected(itemIndex)) {
                        listView.removeSelectedIndex(itemIndex);
                    } else {
                        listView.addSelectedIndex(itemIndex);
                    }
                } else if (Keyboard.isPressed(commandModifier) && selectMode == ListView.SelectMode.SINGLE) {
                    // Toggle the item's selection state
                    if (listView.isItemSelected(itemIndex)) {
                        listView.setSelectedIndex(-1);
                    } else {
                        listView.setSelectedIndex(itemIndex);
                    }
                } else {
                    if (selectMode != ListView.SelectMode.NONE) {
                        if (listView.isItemSelected(itemIndex)) {
                            selectIndex = itemIndex;
                        } else {
                            listView.setSelectedIndex(itemIndex);
                        }
                    }
                }
            }
        }
    }
    listView.requestFocus();
    return consumed;
}
Also used : ListView(org.apache.pivot.wtk.ListView) Modifier(org.apache.pivot.wtk.Keyboard.Modifier) Keyboard(org.apache.pivot.wtk.Keyboard) ArrayList(org.apache.pivot.collections.ArrayList) SelectMode(org.apache.pivot.wtk.ListView.SelectMode) Span(org.apache.pivot.wtk.Span)

Example 23 with ListView

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

the class TerraListViewSkin method mouseMove.

@Override
public boolean mouseMove(Component component, int x, int y) {
    boolean consumed = super.mouseMove(component, x, y);
    ListView listView = (ListView) getComponent();
    int previousHighlightIndex = this.highlightIndex;
    highlightIndex = getItemAt(y);
    if (previousHighlightIndex != highlightIndex && listView.getSelectMode() != ListView.SelectMode.NONE && showHighlight) {
        if (previousHighlightIndex != -1) {
            repaintComponent(getItemBounds(previousHighlightIndex));
        }
        if (highlightIndex != -1) {
            repaintComponent(getItemBounds(highlightIndex));
        }
    }
    return consumed;
}
Also used : ListView(org.apache.pivot.wtk.ListView)

Example 24 with ListView

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

the class TerraListViewSkin method keyReleased.

/**
 * {@link KeyCode#SPACE SPACE} Toggles check mark selection when select mode
 * is {@link SelectMode#SINGLE}
 */
@Override
public boolean keyReleased(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
    boolean consumed = super.keyReleased(component, keyCode, keyLocation);
    ListView listView = (ListView) getComponent();
    switch(keyCode) {
        case Keyboard.KeyCode.SPACE:
            {
                if (listView.getCheckmarksEnabled() && listView.getSelectMode() == ListView.SelectMode.SINGLE) {
                    int selectedIndex = listView.getSelectedIndex();
                    if (!listView.isCheckmarkDisabled(selectedIndex)) {
                        listView.setItemChecked(selectedIndex, !listView.isItemChecked(selectedIndex));
                        consumed = true;
                    }
                }
                break;
            }
        default:
            {
                break;
            }
    }
    return consumed;
}
Also used : ListView(org.apache.pivot.wtk.ListView)

Example 25 with ListView

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

the class TerraListViewSkin method keyPressed.

/**
 * {@link KeyCode#UP UP} Selects the previous enabled list item when select
 * mode is not {@link SelectMode#NONE}<br> {@link KeyCode#DOWN DOWN} Selects
 * the next enabled list item when select mode is not
 * {@link SelectMode#NONE}<p> {@link Modifier#SHIFT SHIFT} +
 * {@link KeyCode#UP UP} Increases the selection size by including the
 * previous enabled list item when select mode is {@link SelectMode#MULTI}
 * <br> {@link Modifier#SHIFT SHIFT} + {@link KeyCode#DOWN DOWN} Increases
 * the selection size by including the next enabled list item when select
 * mode is {@link SelectMode#MULTI}
 */
@Override
public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
    boolean consumed = super.keyPressed(component, keyCode, keyLocation);
    ListView listView = (ListView) getComponent();
    ListView.SelectMode selectMode = listView.getSelectMode();
    switch(keyCode) {
        case Keyboard.KeyCode.UP:
            {
                if (selectMode != ListView.SelectMode.NONE) {
                    int index = listView.getFirstSelectedIndex();
                    int count = listView.getListData().getLength();
                    do {
                        index--;
                    } while (index >= 0 && listView.isItemDisabled(index));
                    if (index >= 0) {
                        if (Keyboard.isPressed(Keyboard.Modifier.SHIFT) && listView.getSelectMode() == ListView.SelectMode.MULTI) {
                            listView.addSelectedIndex(index);
                        } else {
                            listView.setSelectedIndex(index);
                        }
                    } else if (!Keyboard.isPressed(Keyboard.Modifier.SHIFT) && listView.getSelectMode() == ListView.SelectMode.MULTI && count == listView.getSelectedItems().getLength()) {
                        index = listView.getLastSelectedIndex();
                        do {
                            index--;
                        } while (index >= 0 && listView.isItemDisabled(index));
                        listView.setSelectedIndex(Math.max(0, index));
                    }
                    consumed = true;
                }
                break;
            }
        case Keyboard.KeyCode.DOWN:
            {
                if (selectMode != ListView.SelectMode.NONE) {
                    int index = listView.getLastSelectedIndex();
                    int count = listView.getListData().getLength();
                    do {
                        index++;
                    } while (index < count && listView.isItemDisabled(index));
                    if (index < count) {
                        if (Keyboard.isPressed(Keyboard.Modifier.SHIFT) && listView.getSelectMode() == ListView.SelectMode.MULTI) {
                            listView.addSelectedIndex(index);
                        } else {
                            listView.setSelectedIndex(index);
                        }
                    } else if (!Keyboard.isPressed(Keyboard.Modifier.SHIFT) && listView.getSelectMode() == ListView.SelectMode.MULTI && count == listView.getSelectedItems().getLength()) {
                        index = 0;
                        do {
                            index++;
                        } while (index < count && listView.isItemDisabled(index));
                        listView.setSelectedIndex(Math.min(count - 1, index));
                    }
                    consumed = true;
                }
                break;
            }
        default:
            {
                break;
            }
    }
    // Clear the highlight
    if (highlightIndex != -1 && listView.getSelectMode() != ListView.SelectMode.NONE && showHighlight && consumed) {
        repaintComponent(getItemBounds(highlightIndex));
    }
    highlightIndex = -1;
    return consumed;
}
Also used : ListView(org.apache.pivot.wtk.ListView) SelectMode(org.apache.pivot.wtk.ListView.SelectMode)

Aggregations

ListView (org.apache.pivot.wtk.ListView)28 ArrayList (org.apache.pivot.collections.ArrayList)10 Button (org.apache.pivot.wtk.Button)10 List (org.apache.pivot.collections.List)8 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)7 PushButton (org.apache.pivot.wtk.PushButton)6 Span (org.apache.pivot.wtk.Span)6 ListViewSelectionListener (org.apache.pivot.wtk.ListViewSelectionListener)4 Sheet (org.apache.pivot.wtk.Sheet)4 SheetCloseListener (org.apache.pivot.wtk.SheetCloseListener)4 File (java.io.File)3 Bounds (org.apache.pivot.wtk.Bounds)3 BoxPane (org.apache.pivot.wtk.BoxPane)3 Component (org.apache.pivot.wtk.Component)3 FileBrowserSheet (org.apache.pivot.wtk.FileBrowserSheet)3 Frame (org.apache.pivot.wtk.Frame)3 Color (java.awt.Color)2 IOException (java.io.IOException)2 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)2 Sequence (org.apache.pivot.collections.Sequence)2