Search in sources :

Example 1 with Container

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

the class ScaleDecorator method repaint.

public void repaint(final Component component, int x, int y, int width, int height) {
    Container parent = component.getParent();
    if (parent != null) {
        int tx = getTranslatedX(component);
        int ty = getTranslatedY(component);
        int xUpdated = (int) ((x * scaleX) + component.getX() + tx);
        int yUpdated = (int) ((y * scaleY) + component.getY() + ty);
        int widthUpdated = (int) Math.ceil(width * scaleX);
        int heightUpdated = (int) Math.ceil(height * scaleY);
        parent.repaint(xUpdated, yUpdated, widthUpdated, heightUpdated);
    }
}
Also used : Container(org.apache.pivot.wtk.Container)

Example 2 with Container

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

the class SheetSlideDirectionWindow method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    // Populate the ListButton with values from the enum
    listButton.setListData(new ArrayList<>(SheetPlacement.values()));
    listButton = null;
    // Populate the form with data from the Sheet's styles
    form.load(sheet.getStyles());
    // Common ButtonPressListener to be applied to all four of
    // the PushButtons representing a slide direction
    ButtonPressListener openSheetButtonPressListener = new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            StyleDictionary sheetStyles = sheet.getStyles();
            form.store(sheetStyles);
            button.store(sheetStyles);
            form.load(sheetStyles);
            sheet.load(sheetStyles);
            sheet.open(button.getWindow());
        }
    };
    // Apply the common ButtonPressListener to the PushButtons
    for (Iterator<Component> it = tablePane.iterator(); it.hasNext(); ) {
        Component component = it.next();
        if (component instanceof PushButton) {
            PushButton button = (PushButton) component;
            button.getButtonPressListeners().add(openSheetButtonPressListener);
            button.setTooltipText("Press me!");
        }
    }
    tablePane = null;
    // Mouse handler to enable users to quickly close the sheet
    final ContainerMouseListener displayMouseHandler = new ContainerMouseListener() {

        @Override
        public boolean mouseDown(Container container, Mouse.Button button, int x, int y) {
            Display display = (Display) container;
            Component component = display.getComponentAt(x, y);
            // Close the sheet by clicking away from it.
            // This allows resizing etc to work without requiring
            // a close button or similar on the sheet.
            boolean consumed = (component != sheet);
            if (consumed) {
                sheet.close();
            }
            return consumed;
        }
    };
    // Add/remove the mouse handler based on the Sheet's state
    sheet.getWindowStateListeners().add(new WindowStateListener() {

        @Override
        public void windowOpened(Window window) {
            window.getDisplay().getContainerMouseListeners().add(displayMouseHandler);
        }

        @Override
        public void windowClosed(Window window, Display display, Window owner) {
            display.getContainerMouseListeners().remove(displayMouseHandler);
        }
    });
}
Also used : Window(org.apache.pivot.wtk.Window) WindowStateListener(org.apache.pivot.wtk.WindowStateListener) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) Container(org.apache.pivot.wtk.Container) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) ListButton(org.apache.pivot.wtk.ListButton) ContainerMouseListener(org.apache.pivot.wtk.ContainerMouseListener) Component(org.apache.pivot.wtk.Component) PushButton(org.apache.pivot.wtk.PushButton) Display(org.apache.pivot.wtk.Display)

Example 3 with Container

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

the class TerraDialogSkin method windowOpened.

@Override
public void windowOpened(Window window) {
    super.windowOpened(window);
    Display display = window.getDisplay();
    display.getContainerMouseListeners().add(displayMouseListener);
    display.reenterMouse();
    if (!window.requestFocus()) {
        Component.clearFocus();
    }
    // Center the dialog over its owner
    Container ancestor = window.getOwner();
    if (ancestor == null) {
        ancestor = window.getDisplay();
    }
    Dimensions size = window.getPreferredSize();
    int deltaWidth = ancestor.getWidth() - size.width;
    int deltaHeight = ancestor.getHeight() - size.height;
    int x = Math.max(0, Math.round(ancestor.getX() + 0.5f * deltaWidth));
    int y = Math.max(0, Math.round(ancestor.getY() + GOLDEN_SECTION * deltaHeight));
    window.setLocation(x, y);
}
Also used : Container(org.apache.pivot.wtk.Container) Dimensions(org.apache.pivot.wtk.Dimensions) Display(org.apache.pivot.wtk.Display)

Example 4 with Container

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

the class TerraFileBrowserSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    final FileBrowser fileBrowser = (FileBrowser) component;
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    try {
        content = (Component) bxmlSerializer.readObject(TerraFileBrowserSkin.class, "terra_file_browser_skin.bxml", true);
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    } catch (SerializationException exception) {
        throw new RuntimeException(exception);
    }
    fileBrowser.add(content);
    bxmlSerializer.bind(this, TerraFileBrowserSkin.class);
    driveListButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener() {

        @Override
        public void selectedItemChanged(ListButton listButton, Object previousSelectedItem) {
            if (previousSelectedItem != null) {
                File drive = (File) listButton.getSelectedItem();
                if (drive != null && drive.canRead()) {
                    if (!selectingDriveFromRootDirectory) {
                        fileBrowser.setRootDirectory(drive);
                    }
                } else {
                    refreshRoots = true;
                    listButton.setSelectedItem(previousSelectedItem);
                }
            }
        }
    });
    pathListButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener() {

        @Override
        public void selectedItemChanged(ListButton listButton, Object previousSelectedItem) {
            File ancestorDirectory = (File) listButton.getSelectedItem();
            if (ancestorDirectory != null) {
                fileBrowser.setRootDirectory(ancestorDirectory);
            }
        }
    });
    goUpButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            File rootDirectory = fileBrowser.getRootDirectory();
            File parentDirectory = rootDirectory.getParentFile();
            fileBrowser.setRootDirectory(parentDirectory);
        }
    });
    newFolderButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
        // TODO
        }
    });
    goHomeButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            fileBrowser.setRootDirectory(HOME_DIRECTORY);
        }
    });
    /**
     * {@link KeyCode#DOWN DOWN} Transfer focus to the file list and select
     * the first item.<br> {@link KeyCode#ESCAPE ESCAPE} Clear the search
     * field.
     */
    searchTextInput.getComponentKeyListeners().add(new ComponentKeyListener() {

        @Override
        public boolean keyPressed(Component componentArgument, int keyCode, Keyboard.KeyLocation keyLocation) {
            boolean consumed = false;
            if (keyCode == Keyboard.KeyCode.ESCAPE) {
                searchTextInput.setText("");
                consumed = true;
            } else if (keyCode == Keyboard.KeyCode.DOWN) {
                if (fileTableView.getTableData().getLength() > 0) {
                    fileTableView.setSelectedIndex(0);
                    fileTableView.requestFocus();
                }
            }
            return consumed;
        }
    });
    searchTextInput.getTextInputContentListeners().add(new TextInputContentListener() {

        @Override
        public void textChanged(TextInput textInput) {
            refreshFileList();
        }
    });
    fileTableView.getTableViewSelectionListeners().add(new TableViewSelectionListener() {

        @Override
        public void selectedRangeAdded(TableView tableView, int rangeStart, int rangeEnd) {
            if (!updatingSelection) {
                updatingSelection = true;
                for (int i = rangeStart; i <= rangeEnd; i++) {
                    @SuppressWarnings("unchecked") List<File> files = (List<File>) fileTableView.getTableData();
                    File file = files.get(i);
                    fileBrowser.addSelectedFile(file);
                }
                updatingSelection = false;
            }
        }

        @Override
        public void selectedRangeRemoved(TableView tableView, int rangeStart, int rangeEnd) {
            if (!updatingSelection) {
                updatingSelection = true;
                for (int i = rangeStart; i <= rangeEnd; i++) {
                    @SuppressWarnings("unchecked") List<File> files = (List<File>) fileTableView.getTableData();
                    File file = files.get(i);
                    fileBrowser.removeSelectedFile(file);
                }
                updatingSelection = false;
            }
        }

        @Override
        public void selectedRangesChanged(TableView tableView, Sequence<Span> previousSelectedRanges) {
            if (!updatingSelection && previousSelectedRanges != null) {
                updatingSelection = true;
                @SuppressWarnings("unchecked") Sequence<File> files = (Sequence<File>) tableView.getSelectedRows();
                for (int i = 0, n = files.getLength(); i < n; i++) {
                    File file = files.get(i);
                    files.update(i, file);
                }
                fileBrowser.setSelectedFiles(files);
                updatingSelection = false;
            }
        }

        @Override
        public void selectedRowChanged(TableView tableView, Object previousSelectedRow) {
        // No-op
        }
    });
    fileTableView.getTableViewSortListeners().add(new TableViewSortListener() {

        @Override
        public void sortChanged(TableView tableView) {
            TableView.SortDictionary sort = fileTableView.getSort();
            if (!sort.isEmpty()) {
                Dictionary.Pair<String, SortDirection> pair = fileTableView.getSort().get(0);
                @SuppressWarnings("unchecked") List<File> files = (List<File>) fileTableView.getTableData();
                files.setComparator(getFileComparator(pair.key, pair.value));
            }
        }
    });
    fileTableView.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener() {

        private int index = -1;

        @Override
        public boolean mouseClick(Component componentArgument, Mouse.Button button, int x, int y, int count) {
            boolean consumed = false;
            if (count == 1) {
                index = fileTableView.getRowAt(y);
            } else if (count == 2) {
                int indexLocal = fileTableView.getRowAt(y);
                if (indexLocal != -1 && indexLocal == this.index && fileTableView.isRowSelected(indexLocal)) {
                    File file = (File) fileTableView.getTableData().get(indexLocal);
                    if (file.isDirectory()) {
                        fileBrowser.setRootDirectory(file);
                        consumed = true;
                    }
                }
            }
            return consumed;
        }
    });
    fileBrowser.setFocusTraversalPolicy(new IndexFocusTraversalPolicy() {

        @Override
        public Component getNextComponent(Container container, Component componentArgument, FocusTraversalDirection direction) {
            Component nextComponent;
            if (componentArgument == null) {
                nextComponent = fileTableView;
            } else {
                nextComponent = super.getNextComponent(container, componentArgument, direction);
            }
            return nextComponent;
        }
    });
    fileTableView.setSort(TableViewFileRenderer.NAME_KEY, SortDirection.ASCENDING);
    fileTableView.getComponentTooltipListeners().add(new ComponentTooltipListener() {

        @Override
        public void tooltipTriggered(Component comp, int x, int y) {
            // Check that we are on the first column.
            if (fileTableView.getColumnAt(x) != 0) {
                return;
            }
            // Gets the underlying file
            int row = fileTableView.getRowAt(y);
            if (row < 0) {
                return;
            }
            File file = (File) fileTableView.getTableData().get(row);
            // Construct and show the tooltip.
            final Tooltip tooltip = new Tooltip();
            String text = null;
            if (file != null) {
                text = file.getName();
            }
            if (text == null || text.isEmpty()) {
                return;
            }
            TextArea toolTipTextArea = new TextArea();
            toolTipTextArea.setText(text);
            toolTipTextArea.getStyles().put(Style.wrapText, true);
            toolTipTextArea.getStyles().put(Style.backgroundColor, null);
            tooltip.setContent(toolTipTextArea);
            Point location = comp.getDisplay().getMouseLocation();
            x = location.x;
            y = location.y;
            // Ensure that the tooltip stays on screen
            Display display = comp.getDisplay();
            int tooltipHeight = tooltip.getPreferredHeight();
            if (y + tooltipHeight > display.getHeight()) {
                y -= tooltipHeight;
            }
            int tooltipXOffset = 16;
            int padding = 15;
            toolTipTextArea.setMaximumWidth(display.getWidth() - (x + tooltipXOffset + padding));
            tooltip.setLocation(x + tooltipXOffset, y);
            tooltip.open(comp.getWindow());
        }
    });
    rootDirectoryChanged(fileBrowser, null);
    selectedFilesChanged(fileBrowser, null);
}
Also used : FocusTraversalDirection(org.apache.pivot.wtk.FocusTraversalDirection) ComponentTooltipListener(org.apache.pivot.wtk.ComponentTooltipListener) TextArea(org.apache.pivot.wtk.TextArea) ListButtonSelectionListener(org.apache.pivot.wtk.ListButtonSelectionListener) TableViewSortListener(org.apache.pivot.wtk.TableViewSortListener) Span(org.apache.pivot.wtk.Span) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) TextInputContentListener(org.apache.pivot.wtk.TextInputContentListener) Container(org.apache.pivot.wtk.Container) PushButton(org.apache.pivot.wtk.PushButton) ListButton(org.apache.pivot.wtk.ListButton) 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) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer) TableView(org.apache.pivot.wtk.TableView) SerializationException(org.apache.pivot.serialization.SerializationException) Keyboard(org.apache.pivot.wtk.Keyboard) Tooltip(org.apache.pivot.wtk.Tooltip) IOException(java.io.IOException) Sequence(org.apache.pivot.collections.Sequence) Point(org.apache.pivot.wtk.Point) Point(org.apache.pivot.wtk.Point) ListButton(org.apache.pivot.wtk.ListButton) ComponentKeyListener(org.apache.pivot.wtk.ComponentKeyListener) Mouse(org.apache.pivot.wtk.Mouse) FileBrowser(org.apache.pivot.wtk.FileBrowser) ComponentMouseButtonListener(org.apache.pivot.wtk.ComponentMouseButtonListener) File(java.io.File) Display(org.apache.pivot.wtk.Display)

Example 5 with Container

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

the class TableViewRowEditor method beginEdit.

@Override
public void beginEdit(TableView tableViewArgument, int rowIndexArgument, int columnIndexArgument) {
    this.tableView = tableViewArgument;
    this.rowIndex = rowIndexArgument;
    this.columnIndex = columnIndexArgument;
    Container tableViewParent = tableViewArgument.getParent();
    tableViewScrollPane = (tableViewParent instanceof ScrollPane) ? (ScrollPane) tableViewParent : null;
    // Add/create the editor components
    TableView.ColumnSequence tableViewColumns = tableViewArgument.getColumns();
    TablePane.ColumnSequence tablePaneColumns = tablePane.getColumns();
    for (int i = 0, n = tableViewColumns.getLength(); i < n; i++) {
        // Add a new column to the table pane to match the table view column
        TablePane.Column tablePaneColumn = new TablePane.Column();
        tablePaneColumn.setWidth(tableViewArgument.getColumnBounds(i).width);
        tablePaneColumns.add(tablePaneColumn);
        // Determine which component to use as the editor for this column
        String columnName = tableViewColumns.get(i).getName();
        Component editorComponent = null;
        if (columnName != null) {
            editorComponent = cellEditors.get(columnName);
        }
        // Default to a read-only text input editor
        if (editorComponent == null) {
            TextInput editorTextInput = new TextInput();
            editorTextInput.setTextKey(columnName);
            editorTextInput.setEnabled(false);
            editorTextInput.setTextBindType(BindType.LOAD);
            editorComponent = editorTextInput;
        }
        // Add the editor component to the table pane
        editorRow.add(editorComponent);
    }
    // Get the data being edited
    List<?> tableData = tableViewArgument.getTableData();
    Object tableRow = tableData.get(rowIndexArgument);
    // Load the row data into the editor components
    tablePane.load(tableRow);
    // Get the row bounds
    Bounds rowBounds = tableViewArgument.getRowBounds(rowIndexArgument);
    rowImage.bounds = rowBounds;
    // Scroll to make the row as visible as possible
    tableViewArgument.scrollAreaToVisible(rowBounds.x, rowBounds.y, rowBounds.width, rowBounds.height);
    // Constrain the bounds by what is visible through viewport ancestors
    rowBounds = tableViewArgument.getVisibleArea(rowBounds);
    Point location = tableViewArgument.mapPointToAncestor(tableViewArgument.getDisplay(), rowBounds.x, rowBounds.y);
    // Set size and location and match scroll left
    setPreferredWidth(rowBounds.width);
    setLocation(location.x, location.y + (rowBounds.height - getPreferredHeight(-1)) / 2);
    if (tableViewScrollPane != null) {
        scrollPane.setScrollLeft(tableViewScrollPane.getScrollLeft());
    }
    // Open the editor
    open(tableViewArgument.getWindow());
    // Start the transition
    cardPane.setSelectedIndex(EDITOR_CARD_INDEX);
}
Also used : Bounds(org.apache.pivot.wtk.Bounds) Point(org.apache.pivot.wtk.Point) Point(org.apache.pivot.wtk.Point) Container(org.apache.pivot.wtk.Container) ScrollPane(org.apache.pivot.wtk.ScrollPane) Component(org.apache.pivot.wtk.Component) TextInput(org.apache.pivot.wtk.TextInput) TableView(org.apache.pivot.wtk.TableView) TablePane(org.apache.pivot.wtk.TablePane)

Aggregations

Container (org.apache.pivot.wtk.Container)10 Component (org.apache.pivot.wtk.Component)5 Display (org.apache.pivot.wtk.Display)4 Button (org.apache.pivot.wtk.Button)3 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)3 ListButton (org.apache.pivot.wtk.ListButton)3 Point (org.apache.pivot.wtk.Point)3 PushButton (org.apache.pivot.wtk.PushButton)3 TableView (org.apache.pivot.wtk.TableView)3 TextInput (org.apache.pivot.wtk.TextInput)3 IOException (java.io.IOException)2 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)2 ArrayList (org.apache.pivot.collections.ArrayList)2 List (org.apache.pivot.collections.List)2 Sequence (org.apache.pivot.collections.Sequence)2 SerializationException (org.apache.pivot.serialization.SerializationException)2 ComponentKeyListener (org.apache.pivot.wtk.ComponentKeyListener)2 ComponentMouseButtonListener (org.apache.pivot.wtk.ComponentMouseButtonListener)2 ComponentTooltipListener (org.apache.pivot.wtk.ComponentTooltipListener)2 FocusTraversalDirection (org.apache.pivot.wtk.FocusTraversalDirection)2