Package pivot.wtk

Examples of pivot.wtk.ListView$ItemRenderer


        listView.setDragSource(new DragSource() {
            private LocalManifest content = null;

            public boolean beginDrag(Component component, int x, int y) {
                ListView listView = (ListView)component;
                FileList fileList = (FileList)listView.getListData();

                if (fileList.getLength() > 0) {
                    content = new LocalManifest();
                    content.putFileList(fileList);
                }

                return (content != null);
            }

            public void endDrag(Component component, DropAction dropAction) {
                content = null;
            }

            public boolean isNative() {
                return true;
            }

            public LocalManifest getContent() {
                return content;
            }

            public Visual getRepresentation() {
                return null;
            }

            public Point getOffset() {
                return null;
            }

            public int getSupportedDropActions() {
                return DropAction.COPY.getMask();
            }
        });

        listView.setDropTarget(new DropTarget() {
            public DropAction dragEnter(Component component, Manifest dragContent,
                int supportedDropActions, DropAction userDropAction) {
                DropAction dropAction = null;

                if (dragContent.containsFileList()
                    && DropAction.COPY.isSelected(supportedDropActions)) {
                    dropAction = DropAction.COPY;
                }

                return dropAction;
            }

            public void dragExit(Component component) {
            }

            public DropAction dragMove(Component component, Manifest dragContent,
                int supportedDropActions, int x, int y, DropAction userDropAction) {
                return (dragContent.containsFileList() ? DropAction.COPY : null);
            }

            public DropAction userDropActionChange(Component component, Manifest dragContent,
                int supportedDropActions, int x, int y, DropAction userDropAction) {
                return (dragContent.containsFileList() ? DropAction.COPY : null);
            }

            public DropAction drop(Component component, Manifest dragContent,
                int supportedDropActions, int x, int y, DropAction userDropAction) {
                DropAction dropAction = null;

                if (dragContent.containsFileList()) {
                    try {
                        listView.setListData(dragContent.getFileList());
                        dropAction = DropAction.COPY;
                    } catch(IOException exception) {
                        System.err.println(exception);
                    }
                }
View Full Code Here


            (Component)wtkxSerializer.readObject("pivot/tutorials/lists/list_views.wtkx");

        final Label selectionLabel =
            (Label)wtkxSerializer.getObjectByName("selectionLabel");

        ListView listView = (ListView)wtkxSerializer.getObjectByName("listView");
        listView.getListViewSelectionListeners().add(new ListViewSelectionListener() {
            public void selectedRangeAdded(ListView listView, int rangeStart, int rangeEnd) {
                updateSelection(listView);
            }

            public void selectedRangeRemoved(ListView listView, int rangeStart, int rangeEnd) {
                updateSelection(listView);
            }

            public void selectedRangesChanged(ListView listView, Sequence<Span> previousSelectedRanges) {
                updateSelection(listView);
            }

            private void updateSelection(ListView listView) {
                String selectionText = "";

                Sequence<Span> selectedRanges = listView.getSelectedRanges();
                for (int i = 0, n = selectedRanges.getLength(); i < n; i++) {
                    Span selectedRange = selectedRanges.get(i);

                    for (int j = selectedRange.getStart();
                        j <= selectedRange.getEnd();
                        j++) {
                        if (selectionText.length() > 0) {
                            selectionText += ", ";
                        }

                        String text = (String)listView.getListData().get(j);
                        selectionText += text;
                    }
                }

                selectionLabel.setText(selectionText);
View Full Code Here

                // Update the image
                menuImageView.setImage(image);
            }
        };

        ListView iconListView = (ListView)wtkxSerializer.getObjectByName("lists.iconListView");
        iconListView.setItemDisabled(3, true);
        iconListView.setItemDisabled(4, true);

        ListView checkedListView = (ListView)wtkxSerializer.getObjectByName("lists.checkedListView");
        checkedListView.setItemChecked(0, true);
        checkedListView.setItemChecked(2, true);
        checkedListView.setItemChecked(3, true);

        menuImageView = (ImageView)wtkxSerializer.getObjectByName("menus.imageView");
        menuImageView.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener() {
            public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
                if (button == Mouse.Button.RIGHT) {
View Full Code Here

    }

    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);
    }
View Full Code Here

        listView.getListViewItemStateListeners().add(this);
        listView.getListViewSelectionListeners().add(this);
    }

    public void uninstall() {
        ListView listView = (ListView)getComponent();
        listView.getListViewListeners().remove(this);
        listView.getListViewItemListeners().remove(this);
        listView.getListViewItemStateListeners().remove(this);
        listView.getListViewSelectionListeners().remove(this);

        super.uninstall();
    }
View Full Code Here

    @SuppressWarnings("unchecked")
    public int getPreferredWidth(int height) {
        int preferredWidth = 0;

        ListView listView = (ListView)getComponent();
        List<Object> listData = (List<Object>)listView.getListData();

        ListView.ItemRenderer renderer = listView.getItemRenderer();

        for (Object item : listData) {
            renderer.render(item, listView, false, false, false, false);
            preferredWidth = Math.max(preferredWidth, renderer.getPreferredWidth(-1));
        }

        if (listView.getCheckmarksEnabled()) {
          preferredWidth += CHECKBOX.getWidth() + (checkboxPadding.left
          + checkboxPadding.right);
        }

        return preferredWidth;
View Full Code Here

    @SuppressWarnings("unchecked")
    public int getPreferredHeight(int width) {
        int preferredHeight = 0;

        ListView listView = (ListView)getComponent();
        List<Object> listData = (List<Object>)listView.getListData();
        preferredHeight = listData.getLength() * getItemHeight();

        return preferredHeight;
    }
View Full Code Here

        // No-op
    }

    @SuppressWarnings("unchecked")
    public void paint(Graphics2D graphics) {
        ListView listView = (ListView)getComponent();
        List<Object> listData = (List<Object>)listView.getListData();
        ListView.ItemRenderer renderer = listView.getItemRenderer();

        int width = getWidth();
        int height = getHeight();
        int itemHeight = getItemHeight();

        // Paint the background
        graphics.setPaint(backgroundColor);
        graphics.fillRect(0, 0, width, height);

        // Paint the list contents
        int itemStart = 0;
        int itemEnd = listData.getLength() - 1;

        // Ensure that we only paint items that are visible
        Rectangle clipBounds = graphics.getClipBounds();
        if (clipBounds != null) {
            itemStart = Math.max(itemStart, (int)Math.floor(clipBounds.y
                / (double)itemHeight));
            itemEnd = Math.min(itemEnd, (int)Math.ceil((clipBounds.y
                + clipBounds.height) / (double)itemHeight) - 1);
        }

        for (int itemIndex = itemStart; itemIndex <= itemEnd; itemIndex++) {
            Object item = listData.get(itemIndex);
            boolean highlighted = (itemIndex == highlightedIndex
                && listView.getSelectMode() != ListView.SelectMode.NONE);
            boolean selected = listView.isItemSelected(itemIndex);
            boolean disabled = listView.isItemDisabled(itemIndex);

            Color itemBackgroundColor = null;

            if (selected) {
                itemBackgroundColor = (listView.isFocused())
                    ? this.selectionBackgroundColor : inactiveSelectionBackgroundColor;
            } else {
                if (highlighted && showHighlight && !disabled) {
                    itemBackgroundColor = highlightBackgroundColor;
                }
            }

            if (itemBackgroundColor != null) {
                graphics.setPaint(itemBackgroundColor);
                graphics.fillRect(0, itemIndex * itemHeight, width, itemHeight);
            }

            int itemX = 0;
            int itemY = itemIndex * itemHeight;

            boolean checked = false;
            if (listView.getCheckmarksEnabled()) {
                checked = listView.isItemChecked(itemIndex);

                int checkboxY = (itemHeight - CHECKBOX.getHeight()) / 2;
              Graphics2D checkboxGraphics = (Graphics2D)graphics.create(checkboxPadding.left,
              itemY + checkboxY, CHECKBOX.getWidth(), CHECKBOX.getHeight());

View Full Code Here

    public int getItemAt(int y) {
        if (y < 0) {
            throw new IllegalArgumentException("y is negative");
        }

        ListView listView = (ListView)getComponent();

        int index = (y / getItemHeight());
        List<Object> listData = (List<Object>)listView.getListData();

        if (index >= listData.getLength()) {
            index = -1;
        }
View Full Code Here

    }

    public int getItemIndent() {
        int itemIndent = 0;

        ListView listView = (ListView)getComponent();
        if (listView.getCheckmarksEnabled()) {
            itemIndent = CHECKBOX.getWidth() + checkboxPadding.left + checkboxPadding.right;
        }

        return itemIndent;
    }
View Full Code Here

TOP

Related Classes of pivot.wtk.ListView$ItemRenderer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.