Search in sources :

Example 36 with ArrayList

use of org.apache.pivot.collections.ArrayList 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 37 with ArrayList

use of org.apache.pivot.collections.ArrayList in project pivot by apache.

the class TerraListViewSkin method layout.

@Override
public void layout() {
    ListView listView = (ListView) getComponent();
    @SuppressWarnings("unchecked") List<Object> listData = (List<Object>) listView.getListData();
    ListView.ItemRenderer itemRenderer = listView.getItemRenderer();
    if (variableItemHeight) {
        int width = getWidth();
        int checkboxHeight = 0;
        if (listView.getCheckmarksEnabled()) {
            checkboxHeight = CHECKBOX.getHeight() + checkboxPadding.getHeight();
        }
        int n = listData.getLength();
        itemBoundaries = new ArrayList<>(n);
        int itemY = 0;
        for (int i = 0; i < n; i++) {
            Object item = listData.get(i);
            int itemWidth = width;
            int itemX = 0;
            Button.State state = Button.State.UNSELECTED;
            if (listView.getCheckmarksEnabled()) {
                if (listView.getAllowTriStateCheckmarks()) {
                    state = listView.getItemCheckmarkState(i);
                } else {
                    state = listView.isItemChecked(i) ? Button.State.SELECTED : Button.State.UNSELECTED;
                }
                itemX = CHECKBOX.getWidth() + checkboxPadding.getWidth();
                itemWidth -= itemX;
            }
            itemRenderer.render(item, i, listView, false, state, false, false);
            int itemHeight = itemRenderer.getPreferredHeight(itemWidth);
            if (listView.getCheckmarksEnabled()) {
                itemHeight = Math.max(itemHeight, checkboxHeight);
            }
            itemY += itemHeight;
            itemBoundaries.add(itemY);
        }
    } else {
        itemRenderer.render(null, -1, listView, false, Button.State.UNSELECTED, false, false);
        fixedItemHeight = itemRenderer.getPreferredHeight(-1);
        if (listView.getCheckmarksEnabled()) {
            fixedItemHeight = Math.max(CHECKBOX.getHeight() + checkboxPadding.getHeight(), fixedItemHeight);
        }
    }
    if (validateSelection) {
        // Ensure that the selection is visible
        Sequence<Span> selectedRanges = listView.getSelectedRanges();
        if (selectedRanges.getLength() > 0) {
            int rangeStart = selectedRanges.get(0).start;
            int rangeEnd = selectedRanges.get(selectedRanges.getLength() - 1).end;
            Bounds selectionBounds = getItemBounds(rangeStart);
            selectionBounds = selectionBounds.union(getItemBounds(rangeEnd));
            Bounds visibleSelectionBounds = listView.getVisibleArea(selectionBounds);
            if (visibleSelectionBounds != null && visibleSelectionBounds.height < selectionBounds.height) {
                listView.scrollAreaToVisible(selectionBounds);
            }
        }
    }
    validateSelection = false;
}
Also used : Bounds(org.apache.pivot.wtk.Bounds) Span(org.apache.pivot.wtk.Span) ListView(org.apache.pivot.wtk.ListView) Button(org.apache.pivot.wtk.Button) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List)

Example 38 with ArrayList

use of org.apache.pivot.collections.ArrayList 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 39 with ArrayList

use of org.apache.pivot.collections.ArrayList in project pivot by apache.

the class ComponentPropertyInspectorSkin method sourceChanged.

@Override
public void sourceChanged(ComponentInspector componentInspector, Component previousSource) {
    Component source = componentInspector.getSource();
    clearControls();
    Form.SectionSequence sections = form.getSections();
    sections.remove(0, sections.getLength());
    if (previousSource != null) {
        beanMonitor.getPropertyChangeListeners().remove(propertyChangeListener);
    }
    if (source == null) {
        beanMonitor = null;
    } else {
        beanMonitor = new BeanMonitor(source);
        beanMonitor.getPropertyChangeListeners().add(propertyChangeListener);
        Class<?> sourceType = source.getClass();
        HashMap<Class<?>, List<String>> declaringClassPartitions = new HashMap<>(classComparator);
        // Partition the properties by their declaring class
        BeanAdapter beanAdapter = new BeanAdapter(source);
        for (String propertyName : beanAdapter) {
            if (beanMonitor.isNotifying(propertyName) && !beanAdapter.isReadOnly(propertyName)) {
                Method method = BeanAdapter.getGetterMethod(sourceType, propertyName);
                Class<?> declaringClass = method.getDeclaringClass();
                List<String> propertyNames = declaringClassPartitions.get(declaringClass);
                if (propertyNames == null) {
                    propertyNames = new ArrayList<>(nameComparator);
                    declaringClassPartitions.put(declaringClass, propertyNames);
                }
                propertyNames.add(propertyName);
            }
        }
        // Add the controls
        for (Class<?> declaringClass : declaringClassPartitions) {
            Form.Section section = new Form.Section();
            section.setHeading(declaringClass.getSimpleName());
            sections.add(section);
            List<String> propertyNames = declaringClassPartitions.get(declaringClass);
            for (String propertyName : propertyNames) {
                Class<?> type = beanAdapter.getType(propertyName);
                addControl(beanAdapter, propertyName, type, section);
            }
        }
    }
}
Also used : BeanMonitor(org.apache.pivot.beans.BeanMonitor) Form(org.apache.pivot.wtk.Form) HashMap(org.apache.pivot.collections.HashMap) Method(java.lang.reflect.Method) List(org.apache.pivot.collections.List) ArrayList(org.apache.pivot.collections.ArrayList) BeanAdapter(org.apache.pivot.beans.BeanAdapter) Component(org.apache.pivot.wtk.Component)

Example 40 with ArrayList

use of org.apache.pivot.collections.ArrayList in project pivot by apache.

the class EventLoggerSkin method sourceChanged.

// EventLoggerListener methods
@Override
public void sourceChanged(EventLogger eventLogger, Component previousSource) {
    // Component source = eventLogger.getSource();
    HashMap<Class<?>, ArrayList<Method>> buckets = new HashMap<>();
    for (Method event : eventLogger.getDeclaredEvents()) {
        Class<?> listenerInterface = event.getDeclaringClass();
        ArrayList<Method> bucket = buckets.get(listenerInterface);
        if (bucket == null) {
            bucket = new ArrayList<>();
            buckets.put(listenerInterface, bucket);
        }
        bucket.add(event);
    }
    ArrayList<TreeNode> treeData = new ArrayList<>(treeNodeComparator);
    declaredEventsTreeView.setTreeData(treeData);
    updating = true;
    try {
        for (Class<?> listenerInterface : buckets) {
            TreeBranch treeBranch = new TreeBranch(listenerInterface.getSimpleName());
            treeBranch.setComparator(treeNodeComparator);
            treeData.add(treeBranch);
            for (Method event : buckets.get(listenerInterface)) {
                treeBranch.add(new EventNode(event));
                eventLogger.getIncludeEvents().add(event);
            }
        }
        Sequence.Tree.ItemIterator<TreeNode> iter = Sequence.Tree.depthFirstIterator(treeData);
        while (iter.hasNext()) {
            iter.next();
            declaredEventsTreeView.setNodeChecked(iter.getPath(), true);
        }
    } finally {
        updating = false;
    }
}
Also used : HashMap(org.apache.pivot.collections.HashMap) ArrayList(org.apache.pivot.collections.ArrayList) Method(java.lang.reflect.Method) TreeBranch(org.apache.pivot.wtk.content.TreeBranch) TreeNode(org.apache.pivot.wtk.content.TreeNode)

Aggregations

ArrayList (org.apache.pivot.collections.ArrayList)41 List (org.apache.pivot.collections.List)9 Span (org.apache.pivot.wtk.Span)8 Test (org.junit.Test)6 IOException (java.io.IOException)5 ListView (org.apache.pivot.wtk.ListView)5 Point (org.apache.pivot.wtk.Point)5 TableView (org.apache.pivot.wtk.TableView)5 StringWriter (java.io.StringWriter)4 HashMap (org.apache.pivot.collections.HashMap)4 CSVSerializer (org.apache.pivot.serialization.CSVSerializer)4 SerializationException (org.apache.pivot.serialization.SerializationException)4 Vote (org.apache.pivot.util.Vote)4 Component (org.apache.pivot.wtk.Component)4 Form (org.apache.pivot.wtk.Form)4 File (java.io.File)3 FileObject (org.apache.commons.vfs2.FileObject)3 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)3 Bounds (org.apache.pivot.wtk.Bounds)3 ListButton (org.apache.pivot.wtk.ListButton)3