Search in sources :

Example 21 with Span

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

the class TerraListViewSkin method selectedRangesChanged.

@Override
public void selectedRangesChanged(ListView listView, Sequence<Span> previousSelectedRanges) {
    if (previousSelectedRanges != null && previousSelectedRanges != listView.getSelectedRanges()) {
        if (listView.isValid()) {
            // Repaint the area occupied by the previous selection
            if (previousSelectedRanges.getLength() > 0) {
                int rangeStart = previousSelectedRanges.get(0).start;
                int rangeEnd = previousSelectedRanges.get(previousSelectedRanges.getLength() - 1).end;
                Bounds previousSelectionBounds = getItemBounds(rangeStart);
                previousSelectionBounds = previousSelectionBounds.union(getItemBounds(rangeEnd));
                repaintComponent(previousSelectionBounds);
            }
            // Repaint the area occupied by the current selection
            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));
                repaintComponent(selectionBounds);
                // Ensure that the selection is visible
                Bounds visibleSelectionBounds = listView.getVisibleArea(selectionBounds);
                if (visibleSelectionBounds != null && visibleSelectionBounds.height < selectionBounds.height) {
                    // Repainting the entire component is a workaround for PIVOT-490
                    repaintComponent();
                    listView.scrollAreaToVisible(selectionBounds);
                }
            }
        } else {
            validateSelection = true;
        }
    }
}
Also used : Bounds(org.apache.pivot.wtk.Bounds) Span(org.apache.pivot.wtk.Span)

Example 22 with Span

use of org.apache.pivot.wtk.Span 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 23 with Span

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

the class ComponentInspectorSkin method addSpanControl.

private static Component addSpanControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
    Span span = (Span) dictionary.get(key);
    BoxPane boxPane = new BoxPane(Orientation.VERTICAL);
    section.add(boxPane);
    Form.setLabel(boxPane, key);
    FlowPane flowPane = new FlowPane();
    flowPane.getStyles().put(Style.alignToBaseline, true);
    flowPane.getStyles().put(Style.horizontalSpacing, 5);
    boxPane.add(flowPane);
    TextInput textInput = new TextInput();
    textInput.setTextSize(10);
    textInput.setMaximumLength(10);
    textInput.setValidator(new IntValidator());
    textInput.setText(span == null ? "" : String.valueOf(span.start));
    flowPane.add(textInput);
    textInput.getComponentStateListeners().add(new ComponentStateListener() {

        @Override
        public void focusedChanged(Component component, Component obverseComponent) {
            if (!component.isFocused()) {
                TextInput textInputLocal = (TextInput) component;
                Span spanLocal = (Span) dictionary.get(key);
                try {
                    int start = Integer.parseInt(textInputLocal.getText());
                    dictionary.put(key, new Span(start, spanLocal == null ? start : spanLocal.end));
                } catch (Exception exception) {
                    displayErrorMessage(exception, component.getWindow());
                    textInputLocal.setText(spanLocal == null ? "" : String.valueOf(spanLocal.start));
                }
            }
        }
    });
    Label label = new Label("start");
    label.getStyles().put(Style.font, "{italic:true}");
    flowPane.add(label);
    flowPane = new FlowPane();
    flowPane.getStyles().put(Style.alignToBaseline, true);
    flowPane.getStyles().put(Style.horizontalSpacing, 5);
    boxPane.add(flowPane);
    textInput = new TextInput();
    textInput.setTextSize(10);
    textInput.setMaximumLength(10);
    textInput.setValidator(new IntValidator());
    textInput.setText(span == null ? "" : String.valueOf(span.end));
    flowPane.add(textInput);
    textInput.getComponentStateListeners().add(new ComponentStateListener() {

        @Override
        public void focusedChanged(Component component, Component obverseComponent) {
            if (!component.isFocused()) {
                TextInput textInputLocal = (TextInput) component;
                Span spanLocal = (Span) dictionary.get(key);
                try {
                    int end = Integer.parseInt(textInputLocal.getText());
                    dictionary.put(key, new Span(spanLocal == null ? end : spanLocal.start, end));
                } catch (Exception exception) {
                    displayErrorMessage(exception, component.getWindow());
                    textInputLocal.setText(spanLocal == null ? "" : String.valueOf(spanLocal.end));
                }
            }
        }
    });
    label = new Label("end");
    label.getStyles().put(Style.font, "{italic:true}");
    flowPane.add(label);
    return boxPane;
}
Also used : IntValidator(org.apache.pivot.wtk.validation.IntValidator) BoxPane(org.apache.pivot.wtk.BoxPane) Label(org.apache.pivot.wtk.Label) FlowPane(org.apache.pivot.wtk.FlowPane) TextInput(org.apache.pivot.wtk.TextInput) Component(org.apache.pivot.wtk.Component) Span(org.apache.pivot.wtk.Span) ComponentStateListener(org.apache.pivot.wtk.ComponentStateListener)

Example 24 with Span

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

the class ComponentInspectorSkin method updateSpanControl.

private void updateSpanControl(Dictionary<String, Object> dictionary, String key) {
    BoxPane boxPane = (BoxPane) controls.get(key);
    if (boxPane != null) {
        Span span = (Span) dictionary.get(key);
        TextInput startTextInput = (TextInput) ((FlowPane) boxPane.get(0)).get(0);
        TextInput endTextInput = (TextInput) ((FlowPane) boxPane.get(1)).get(0);
        startTextInput.setText(span == null ? "" : String.valueOf(span.start));
        endTextInput.setText(span == null ? "" : String.valueOf(span.end));
    }
}
Also used : BoxPane(org.apache.pivot.wtk.BoxPane) TextInput(org.apache.pivot.wtk.TextInput) Span(org.apache.pivot.wtk.Span)

Example 25 with Span

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

the class StockTrackerWindow method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    // Add stocks table view event handlers
    stocksTableView.getTableViewRowListeners().add(new TableViewRowListener() {

        @Override
        public void rowsSorted(TableView tableView) {
            List<?> tableData = stocksTableView.getTableData();
            if (tableData.getLength() > 0) {
                stocksTableView.setSelectedIndex(0);
            }
        }
    });
    stocksTableView.getTableViewSelectionListeners().add(new TableViewSelectionListener() {

        @Override
        public void selectedRangesChanged(TableView tableView, Sequence<Span> previousSelectedRanges) {
            int firstSelectedIndex = stocksTableView.getFirstSelectedIndex();
            removeSymbolsAction.setEnabled(firstSelectedIndex != -1);
            refreshDetail();
        }
    });
    stocksTableView.getTableViewSortListeners().add(new TableViewSortListener() {

        @Override
        public void sortChanged(TableView tableView) {
            @SuppressWarnings("unchecked") List<Object> tableData = (List<Object>) tableView.getTableData();
            tableData.setComparator(new TableViewRowComparator(tableView));
        }
    });
    stocksTableView.getComponentKeyListeners().add(new ComponentKeyListener() {

        @Override
        public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
            if (keyCode == Keyboard.KeyCode.DELETE || keyCode == Keyboard.KeyCode.BACKSPACE) {
                removeSymbolsAction.perform(component);
            } else if (keyCode == Keyboard.KeyCode.A && Keyboard.isPressed(Platform.getCommandModifier())) {
                stocksTableView.selectAll();
            }
            return false;
        }
    });
    // Add symbol text input event handlers
    symbolTextInput.getTextInputContentListeners().add(new TextInputContentListener() {

        @Override
        public void textChanged(TextInput textInput) {
            addSymbolAction.setEnabled(textInput.getCharacterCount() > 0);
        }
    });
    symbolTextInput.getComponentKeyListeners().add(new ComponentKeyListener() {

        @Override
        public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
            if (keyCode == Keyboard.KeyCode.ENTER) {
                if (addSymbolAction.isEnabled()) {
                    addSymbolAction.perform(component);
                }
            }
            return false;
        }
    });
    // Assign actions to add and remove symbol buttons
    addSymbolButton.setAction(addSymbolAction);
    removeSymbolsButton.setAction(removeSymbolsAction);
    // Add a button press listener to open the Yahoo! Finance web page when
    // the link is clicked
    yahooFinanceButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            Desktop desktop = Desktop.getDesktop();
            try {
                desktop.browse(new URL(YAHOO_FINANCE_HOME).toURI());
            } catch (MalformedURLException exception) {
                throw new RuntimeException(exception);
            } catch (URISyntaxException exception) {
                throw new RuntimeException(exception);
            } catch (IOException exception) {
                System.out.println("Unable to open " + YAHOO_FINANCE_HOME + " in default browser.");
            }
        }
    });
}
Also used : MalformedURLException(java.net.MalformedURLException) TableViewSortListener(org.apache.pivot.wtk.TableViewSortListener) URISyntaxException(java.net.URISyntaxException) Span(org.apache.pivot.wtk.Span) URL(java.net.URL) TableViewRowListener(org.apache.pivot.wtk.TableViewRowListener) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) TableViewRowComparator(org.apache.pivot.wtk.content.TableViewRowComparator) TextInputContentListener(org.apache.pivot.wtk.TextInputContentListener) Button(org.apache.pivot.wtk.Button) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List) Component(org.apache.pivot.wtk.Component) TextInput(org.apache.pivot.wtk.TextInput) TableViewSelectionListener(org.apache.pivot.wtk.TableViewSelectionListener) TableView(org.apache.pivot.wtk.TableView) Keyboard(org.apache.pivot.wtk.Keyboard) IOException(java.io.IOException) ComponentKeyListener(org.apache.pivot.wtk.ComponentKeyListener) Desktop(java.awt.Desktop)

Aggregations

Span (org.apache.pivot.wtk.Span)25 ArrayList (org.apache.pivot.collections.ArrayList)11 List (org.apache.pivot.collections.List)10 Button (org.apache.pivot.wtk.Button)7 Keyboard (org.apache.pivot.wtk.Keyboard)7 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)6 Component (org.apache.pivot.wtk.Component)6 ListView (org.apache.pivot.wtk.ListView)6 TableView (org.apache.pivot.wtk.TableView)6 Sequence (org.apache.pivot.collections.Sequence)5 Bounds (org.apache.pivot.wtk.Bounds)5 ComponentKeyListener (org.apache.pivot.wtk.ComponentKeyListener)5 IOException (java.io.IOException)4 PushButton (org.apache.pivot.wtk.PushButton)4 TableViewSelectionListener (org.apache.pivot.wtk.TableViewSelectionListener)4 TableViewSortListener (org.apache.pivot.wtk.TableViewSortListener)4 TextInput (org.apache.pivot.wtk.TextInput)4 TextSpan (org.apache.pivot.wtk.text.TextSpan)4 File (java.io.File)3 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)3