Search in sources :

Example 16 with Component

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

the class Pivot811 method startup.

@Override
public void startup(final Display displayArgument, Map<String, String> properties) throws Exception {
    this.display = displayArgument;
    Frame listFrame = new Frame();
    listFrame.setTitle("List Frame");
    listFrame.setPreferredSize(400, 300);
    listFrame.setLocation(20, 20);
    listFrame.getStyles().put(Style.padding, Insets.NONE);
    BoxPane boxPane = new BoxPane();
    boxPane.getStyles().put(Style.fill, true);
    boxPane.setOrientation(Orientation.VERTICAL);
    listFrame.setContent(boxPane);
    Label infoLabel = new Label("Double click on a list item to open a detail frame");
    boxPane.add(infoLabel);
    ScrollPane scrollPane = new ScrollPane();
    scrollPane.setHorizontalScrollBarPolicy(ScrollBarPolicy.FILL);
    scrollPane.setVerticalScrollBarPolicy(ScrollBarPolicy.FILL_TO_CAPACITY);
    // workaround for pivot-738,
    scrollPane.setRepaintAllViewport(true);
    // needed only in in some cases
    boxPane.add(scrollPane);
    final ListView listView = new ListView();
    List<String> listData = new ArrayList<>();
    for (int i = 0; i < 50; ++i) {
        listData.add("List Item " + i);
    }
    listView.setListData(listData);
    scrollPane.setView(listView);
    listView.getListViewSelectionListeners().add(new ListViewSelectionListener() {

        @Override
        public void selectedItemChanged(ListView listViewArgument, Object previousSelectedItem) {
            System.out.println("selectedItemChanged : " + listViewArgument.getSelectedItem());
        }
    });
    listView.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener() {

        @Override
        public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
            System.out.println("mouseClick : " + count);
            if (count == 2) {
                System.out.println("double click, now open a detail frame");
                Frame detailFrame = new Frame();
                detailFrame.setTitle("Detail Frame");
                detailFrame.setPreferredSize(400, 300);
                int selectedIndex = listView.getSelectedIndex();
                detailFrame.setLocation(80 + (selectedIndex * 10), 80 + (selectedIndex * 10));
                detailFrame.getStyles().put(Style.padding, Insets.NONE);
                BoxPane boxPaneLocal = new BoxPane();
                boxPaneLocal.getStyles().put(Style.fill, true);
                boxPaneLocal.setOrientation(Orientation.VERTICAL);
                detailFrame.setContent(boxPaneLocal);
                String selectedItem = listView.getSelectedItem().toString();
                Label label = new Label("Selected Item is \"" + selectedItem + "\"");
                boxPaneLocal.add(label);
                // spacer
                boxPaneLocal.add(new Label(""));
                boxPaneLocal.add(new Label("Click inside the text input to focus it"));
                TextInput textInput = new TextInput();
                textInput.setText("Focusable component");
                // workaround for pivot-811:
                boxPaneLocal.add(textInput);
                // add a focusable element
                // inside the frame
                detailFrame.open(displayArgument);
                // workaround for pivot-811: force the focus on the first
                // focusable element inside the frame
                detailFrame.requestFocus();
            // textInput.requestFocus(); // or use this ...
            }
            return true;
        }
    });
    listFrame.open(displayArgument);
    listView.setSelectedIndex(0);
    listView.requestFocus();
}
Also used : Frame(org.apache.pivot.wtk.Frame) Label(org.apache.pivot.wtk.Label) ArrayList(org.apache.pivot.collections.ArrayList) ListView(org.apache.pivot.wtk.ListView) Mouse(org.apache.pivot.wtk.Mouse) BoxPane(org.apache.pivot.wtk.BoxPane) ScrollPane(org.apache.pivot.wtk.ScrollPane) ComponentMouseButtonListener(org.apache.pivot.wtk.ComponentMouseButtonListener) ListViewSelectionListener(org.apache.pivot.wtk.ListViewSelectionListener) Component(org.apache.pivot.wtk.Component) TextInput(org.apache.pivot.wtk.TextInput)

Example 17 with Component

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

the class LeakTestWindow method initialize.

@Override
public void initialize(Map<String, Object> arg0, URL arg1, Resources arg2) {
    System.out.println("LeakTestWindow initialize(...)\n");
    button.setAction(new Action() {

        @Override
        public void perform(Component component) {
            dialogTest++;
            System.out.println("Dialog test number " + dialogTest + " at " + new Date());
            TestDialog dialog = TestDialog.create();
            System.out.println("Opening the dialog");
            dialog.open(LeakTestWindow.this);
            // Close the dialog straight away
            System.out.println("Closing the dialog");
            dialog.close();
            System.out.println("End of perform()\n");
        }
    });
}
Also used : Action(org.apache.pivot.wtk.Action) Component(org.apache.pivot.wtk.Component) Date(java.util.Date)

Example 18 with Component

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

the class ScrollPaneSkin method getMaxScrollTop.

/**
 * Gets the maximum legal <tt>scrollTop</tt> value this this skin imposes.
 * This is the largest value possible that still shows as much of the view
 * component as it can.
 *
 * @return The maximum scrollTop value
 */
private int getMaxScrollTop() {
    int maxScrollTop = 0;
    ScrollPane scrollPane = (ScrollPane) getComponent();
    Component view = scrollPane.getView();
    if (view != null) {
        int viewHeight = view.getHeight();
        int columnHeaderHeight = 0;
        int horizontalScrollBarHeight = 0;
        int height = getHeight();
        Component columnHeader = scrollPane.getColumnHeader();
        if (columnHeader != null) {
            columnHeaderHeight = columnHeader.getHeight();
        }
        if (horizontalScrollBar.isVisible()) {
            horizontalScrollBarHeight = horizontalScrollBar.getHeight();
        }
        maxScrollTop = Math.max(viewHeight + columnHeaderHeight + horizontalScrollBarHeight - height, 0);
    }
    return maxScrollTop;
}
Also used : ScrollPane(org.apache.pivot.wtk.ScrollPane) Component(org.apache.pivot.wtk.Component) Paint(java.awt.Paint)

Example 19 with Component

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

the class ScrollPaneSkin method getPreferredHeight.

@Override
public int getPreferredHeight(int width) {
    int preferredHeight = 0;
    ScrollPane scrollPane = (ScrollPane) getComponent();
    Component view = scrollPane.getView();
    if (view != null) {
        int preferredRowHeaderWidth = 0;
        Component rowHeader = scrollPane.getRowHeader();
        if (rowHeader != null) {
            preferredRowHeaderWidth = rowHeader.getPreferredWidth(-1);
        }
        int preferredColumnHeaderHeight = 0;
        Component columnHeader = scrollPane.getColumnHeader();
        if (columnHeader != null) {
            preferredColumnHeaderHeight = columnHeader.getPreferredHeight(-1);
        }
        ScrollBarPolicy horizontalPolicy = scrollPane.getHorizontalScrollBarPolicy();
        if (horizontalPolicy != ScrollBarPolicy.FILL) {
            // Get the unconstrained preferred size of the view
            Dimensions preferredViewSize = view.getPreferredSize();
            if (horizontalPolicy == ScrollBarPolicy.FILL_TO_CAPACITY) {
                if (width < 0) {
                    horizontalPolicy = ScrollBarPolicy.AUTO;
                } else {
                    int preferredWidth = preferredViewSize.width + preferredRowHeaderWidth;
                    if (preferredWidth < width) {
                        horizontalPolicy = ScrollBarPolicy.FILL;
                    } else {
                        horizontalPolicy = ScrollBarPolicy.AUTO;
                    }
                }
            }
            if (horizontalPolicy == ScrollBarPolicy.ALWAYS || horizontalPolicy == ScrollBarPolicy.NEVER || horizontalPolicy == ScrollBarPolicy.AUTO) {
                preferredHeight = preferredViewSize.height + preferredColumnHeaderHeight;
                // height calculation
                if (horizontalPolicy == ScrollBarPolicy.ALWAYS || (horizontalPolicy == ScrollBarPolicy.AUTO && width > 0 && preferredViewSize.width + preferredRowHeaderWidth > width)) {
                    preferredHeight += horizontalScrollBar.getPreferredHeight(-1);
                }
            }
        }
        if (horizontalPolicy == ScrollBarPolicy.FILL) {
            // Preferred height is the sum of the constrained preferred height
            // of the view and the unconstrained preferred height of the column header
            int widthUpdated = width;
            if (widthUpdated >= 0) {
                // Subtract the unconstrained preferred width of the row header
                // from the width constraint
                widthUpdated = Math.max(widthUpdated - preferredRowHeaderWidth, 0);
            }
            preferredHeight = view.getPreferredHeight(widthUpdated) + preferredColumnHeaderHeight;
        }
    }
    return preferredHeight;
}
Also used : ScrollPane(org.apache.pivot.wtk.ScrollPane) ScrollBarPolicy(org.apache.pivot.wtk.ScrollPane.ScrollBarPolicy) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component) Paint(java.awt.Paint)

Example 20 with Component

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

the class ScrollPaneSkin method scrollTopChanged.

// ViewportListener methods
@Override
public void scrollTopChanged(Viewport viewport, int previousScrollTop) {
    // NOTE we don't invalidate the component here because we need only
    // reposition the view and row header. Invalidating would yield
    // the correct positioning, but it would do much more work than needed.
    ScrollPane scrollPane = (ScrollPane) viewport;
    Component view = scrollPane.getView();
    Component rowHeader = scrollPane.getRowHeader();
    Component columnHeader = scrollPane.getColumnHeader();
    int columnHeaderHeight = 0;
    if (columnHeader != null) {
        columnHeaderHeight = columnHeader.getHeight();
    }
    int scrollTop = scrollPane.getScrollTop();
    if (view != null && view.isShowing() && isOptimizeScrolling()) {
        Bounds blitArea = view.getVisibleArea();
        int blitX = blitArea.x + view.getX();
        int blitY = blitArea.y + view.getY();
        int blitWidth = blitArea.width;
        int blitHeight = blitArea.height;
        if (rowHeader != null) {
            // Blit the row header as well
            int rowHeaderWidth = rowHeader.getWidth();
            blitX -= rowHeaderWidth;
            blitWidth += rowHeaderWidth;
        }
        int deltaScrollTop = scrollTop - previousScrollTop;
        blitY += Math.max(deltaScrollTop, 0);
        blitHeight -= Math.abs(deltaScrollTop);
        Graphics2D graphics = scrollPane.getGraphics();
        graphics.copyArea(blitX, blitY, blitWidth, blitHeight, 0, -deltaScrollTop);
        scrollPane.setConsumeRepaint(true);
        try {
            view.setLocation(view.getX(), columnHeaderHeight - scrollTop);
            if (rowHeader != null) {
                rowHeader.setLocation(0, columnHeaderHeight - scrollTop);
            }
        } finally {
            scrollPane.setConsumeRepaint(false);
        }
        boolean repaintAllViewport = scrollPane.isRepaintAllViewport();
        if (!repaintAllViewport) {
            scrollPane.repaint(blitX, (columnHeaderHeight + (deltaScrollTop > 0 ? blitHeight : 0)), blitWidth, Math.abs(deltaScrollTop), true);
        } else {
            Bounds viewportBounds = getViewportBounds();
            scrollPane.repaint(viewportBounds.x, viewportBounds.y, viewportBounds.width, viewportBounds.height, true);
        }
    } else {
        if (view != null) {
            view.setLocation(view.getX(), columnHeaderHeight - scrollTop);
        }
        if (rowHeader != null) {
            rowHeader.setLocation(0, columnHeaderHeight - scrollTop);
        }
    }
    if (scrollTop >= 0 && scrollTop <= getMaxScrollTop()) {
        verticalScrollBar.setValue(scrollTop);
    }
}
Also used : ScrollPane(org.apache.pivot.wtk.ScrollPane) Bounds(org.apache.pivot.wtk.Bounds) Component(org.apache.pivot.wtk.Component) Paint(java.awt.Paint) Graphics2D(java.awt.Graphics2D)

Aggregations

Component (org.apache.pivot.wtk.Component)209 Dimensions (org.apache.pivot.wtk.Dimensions)40 Point (org.apache.pivot.wtk.Point)38 GradientPaint (java.awt.GradientPaint)33 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)24 TextInput (org.apache.pivot.wtk.TextInput)21 Label (org.apache.pivot.wtk.Label)20 BoxPane (org.apache.pivot.wtk.BoxPane)18 Paint (java.awt.Paint)17 Button (org.apache.pivot.wtk.Button)15 PushButton (org.apache.pivot.wtk.PushButton)14 ScrollPane (org.apache.pivot.wtk.ScrollPane)14 TablePane (org.apache.pivot.wtk.TablePane)14 Window (org.apache.pivot.wtk.Window)14 IOException (java.io.IOException)13 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)13 Frame (org.apache.pivot.wtk.Frame)13 FlowPane (org.apache.pivot.wtk.FlowPane)12 ComponentStateListener (org.apache.pivot.wtk.ComponentStateListener)11 ComponentMouseButtonListener (org.apache.pivot.wtk.ComponentMouseButtonListener)10