Search in sources :

Example 1 with ArrayList

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

the class ComponentStyleInspectorSkin method sourceChanged.

@Override
public void sourceChanged(ComponentInspector componentInspector, Component previousSource) {
    Component source = componentInspector.getSource();
    clearControls();
    if (previousSource != null) {
        previousSource.getComponentStyleListeners().remove(componentStyleHandler);
    }
    if (source != null) {
        source.getComponentStyleListeners().add(componentStyleHandler);
        Component.StyleDictionary styles = source.getStyles();
        ArrayList<String> keys = new ArrayList<>(new Comparator<String>() {

            @Override
            public int compare(String key1, String key2) {
                return key1.compareTo(key2);
            }
        });
        // Filter (exclude read-only) and sort the keys
        for (String key : styles) {
            if (!styles.isReadOnly(key)) {
                keys.add(key);
            }
        }
        // Add the controls
        for (String key : keys) {
            addControl(styles, key, styles.getType(key), stylesSection);
        }
    }
}
Also used : ArrayList(org.apache.pivot.collections.ArrayList) Component(org.apache.pivot.wtk.Component)

Example 2 with ArrayList

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

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

the class SuggestionPopupTest method startup.

@Override
public void startup(final Display display, final Map<String, String> properties) throws Exception {
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    window = (Window) bxmlSerializer.readObject(SuggestionPopupTest.class, "suggestion_popup_test.bxml");
    bxmlSerializer.bind(this);
    textInput.getTextInputContentListeners().add(new TextInputContentListener() {

        @Override
        public void textInserted(final TextInput textInputArgument, final int index, final int count) {
            ArrayList<String> suggestions = new ArrayList<>("One", "Two", "Three", "Four", "Five");
            suggestionPopup.setSuggestionData(suggestions);
            suggestionPopup.open(textInputArgument, new SuggestionPopupCloseListener() {

                @Override
                public void suggestionPopupClosed(final SuggestionPopup suggestionPopupArgument) {
                    if (suggestionPopupArgument.getResult()) {
                        selectedIndexLabel.setText("You selected suggestion number " + suggestionPopupArgument.getSelectedIndex() + ".");
                    } else {
                        selectedIndexLabel.setText("You didn't select anything.");
                    }
                }
            });
        }

        @Override
        public void textRemoved(final TextInput textInputArgument, final int index, final int count) {
            suggestionPopup.close();
        }
    });
    window.open(display);
}
Also used : TextInputContentListener(org.apache.pivot.wtk.TextInputContentListener) SuggestionPopupCloseListener(org.apache.pivot.wtk.SuggestionPopupCloseListener) SuggestionPopup(org.apache.pivot.wtk.SuggestionPopup) ArrayList(org.apache.pivot.collections.ArrayList) TextInput(org.apache.pivot.wtk.TextInput) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 4 with ArrayList

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

the class Window method close.

/**
 * Closes the window and all of its owned windows. If any owned window fails
 * to close, this window will also fail to close.
 */
public void close() {
    if (!isClosed()) {
        closing = true;
        // Close all owned windows (create a copy of the owned window
        // list so owned windows can remove themselves from the list
        // without interrupting the iteration)
        boolean cancel = false;
        for (Window ownedWindow : new ArrayList<>(this.ownedWindows)) {
            ownedWindow.close();
            cancel |= !(ownedWindow.isClosing() || ownedWindow.isClosed());
        }
        // in parallel, forcing them to run in series)
        if (cancel) {
            closing = false;
        } else {
            Vote vote = windowStateListeners.previewWindowClose(this);
            if (vote == Vote.APPROVE) {
                // Remove the window from the display
                Display display = getDisplay();
                display.remove(this);
                // Clear the owner and remove from the owner's owned window list
                Window ownerValue = this.owner;
                this.owner = null;
                if (ownerValue != null) {
                    ownerValue.ownedWindows.remove(this);
                }
                // Notify listeners
                closing = false;
                windowStateListeners.windowClosed(this, display, ownerValue);
            } else {
                if (vote == Vote.DENY) {
                    closing = false;
                }
                windowStateListeners.windowCloseVetoed(this, vote);
            }
        }
    }
}
Also used : Vote(org.apache.pivot.util.Vote) ArrayList(org.apache.pivot.collections.ArrayList)

Example 5 with ArrayList

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

the class TextPaneSkinParagraphView method getPreferredSize.

@Override
public Dimensions getPreferredSize(int breakWidth) {
    // Break the views into multiple rows
    Paragraph paragraph = (Paragraph) getNode();
    ArrayList<Row> rowsLocal = new ArrayList<>();
    int offset = 0;
    ParagraphChildLayouter layouter = new ParagraphChildLayouter();
    Row row = new Row();
    for (TextPaneSkinNodeView nodeView : this) {
        nodeView.layout(Math.max(breakWidth - (row.width + PARAGRAPH_TERMINATOR_WIDTH), 0));
        int nodeViewWidth = nodeView.getWidth();
        if (row.width + nodeViewWidth > breakWidth && row.width > 0) {
            // The view is too big to fit in the remaining space,
            // and it is not the only view in this row
            rowsLocal.add(row);
            layouter.endRow(row);
            row = new Row();
            row.width = 0;
        }
        // Add the view to the row
        RowSegment segment = new RowSegment(nodeView, offset);
        row.rowSegments.add(segment);
        layouter.startSegment(segment);
        offset += nodeView.getCharacterCount();
        row.width += nodeViewWidth;
        // If the view was split into multiple views, add them to their own rows
        nodeView = getNext(nodeView);
        while (nodeView != null) {
            rowsLocal.add(row);
            layouter.endRow(row);
            row = new Row();
            nodeView.layout(breakWidth);
            segment = new RowSegment(nodeView, offset);
            row.rowSegments.add(segment);
            layouter.startSegment(segment);
            offset += nodeView.getCharacterCount();
            row.width = nodeView.getWidth();
            nodeView = getNext(nodeView);
        }
    }
    // Add the last row
    if (row.rowSegments.getLength() > 0) {
        rowsLocal.add(row);
        layouter.endRow(row);
    }
    // calculate paragraph width and adjust for alignment
    layouter.end(paragraph, rowsLocal);
    // Recalculate terminator bounds
    FontRenderContext fontRenderContext = Platform.getFontRenderContext();
    LineMetrics lm = getTextPaneSkin().getFont().getLineMetrics("", 0, 0, fontRenderContext);
    int terminatorHeight = (int) Math.ceil(lm.getHeight());
    int terminatorY;
    if (getCharacterCount() == 1) {
        // The terminator is the only character in this paragraph
        terminatorY = 0;
    } else {
        terminatorY = layouter.rowY - terminatorHeight;
    }
    Bounds terminatorBoundsLocal = new Bounds(layouter.x, terminatorY, PARAGRAPH_TERMINATOR_WIDTH, terminatorHeight);
    // Ensure that the paragraph is visible even when empty
    layouter.paragraphWidth += terminatorBoundsLocal.width;
    int height = Math.max(layouter.rowY, terminatorBoundsLocal.height);
    return new Dimensions(layouter.paragraphWidth, height);
}
Also used : Bounds(org.apache.pivot.wtk.Bounds) ArrayList(org.apache.pivot.collections.ArrayList) Dimensions(org.apache.pivot.wtk.Dimensions) FontRenderContext(java.awt.font.FontRenderContext) LineMetrics(java.awt.font.LineMetrics) Paragraph(org.apache.pivot.wtk.text.Paragraph)

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