Search in sources :

Example 11 with ArrayList

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

the class ShutdownTest method shutdown.

@Override
public boolean shutdown(boolean optional) {
    System.out.println("shutdown()");
    if (alert == null) {
        ArrayList<String> options = new ArrayList<>();
        options.add("Yes");
        options.add("No");
        alert = new Alert(MessageType.QUESTION, "Cancel shutdown?", options);
        alert.setModal(false);
        alert.open(display, new DialogCloseListener() {

            @Override
            public void dialogClosed(Dialog dialog, boolean modal) {
                if (!(dialog instanceof Alert)) {
                    return;
                }
                Alert alertLocal = (Alert) dialog;
                if (alertLocal.getResult()) {
                    if (alertLocal.getSelectedOptionIndex() == 1) {
                        cancelShutdown = false;
                        DesktopApplicationContext.exit();
                    }
                }
                ShutdownTest.this.alert = null;
            }
        });
    }
    return cancelShutdown;
}
Also used : Dialog(org.apache.pivot.wtk.Dialog) ArrayList(org.apache.pivot.collections.ArrayList) Alert(org.apache.pivot.wtk.Alert) DialogCloseListener(org.apache.pivot.wtk.DialogCloseListener)

Example 12 with ArrayList

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

the class TerraTableViewSkin method layout.

@Override
public void layout() {
    columnWidths = getColumnWidths((TableView) getComponent(), getWidth());
    TableView tableView = (TableView) getComponent();
    TableView.ColumnSequence columns = tableView.getColumns();
    if (variableRowHeight) {
        @SuppressWarnings("unchecked") List<Object> tableData = (List<Object>) tableView.getTableData();
        int n = tableData.getLength();
        rowBoundaries = new ArrayList<>(n);
        int rowY = 0;
        for (int i = 0; i < n; i++) {
            Object rowData = tableData.get(i);
            int rowHeight = 0;
            for (int columnIndex = 0, columnCount = columns.getLength(); columnIndex < columnCount; columnIndex++) {
                TableView.Column column = columns.get(columnIndex);
                TableView.CellRenderer cellRenderer = column.getCellRenderer();
                int columnWidth = columnWidths.get(columnIndex).intValue();
                cellRenderer.render(rowData, i, columnIndex, tableView, column.getName(), false, false, false);
                rowHeight = Math.max(rowHeight, cellRenderer.getPreferredHeight(columnWidth));
            }
            rowY += rowHeight;
            rowBoundaries.add(Integer.valueOf(rowY));
            rowY++;
        }
    } else {
        fixedRowHeight = calculateFixedRowHeight(tableView);
    }
    if (validateSelection) {
        // Ensure that the selection is visible
        Sequence<Span> selectedRanges = tableView.getSelectedRanges();
        if (selectedRanges.getLength() > 0) {
            int rangeStart = selectedRanges.get(0).start;
            int rangeEnd = selectedRanges.get(selectedRanges.getLength() - 1).end;
            Bounds selectionBounds = getRowBounds(rangeStart);
            selectionBounds = selectionBounds.union(getRowBounds(rangeEnd));
            Bounds visibleSelectionBounds = tableView.getVisibleArea(selectionBounds);
            if (visibleSelectionBounds != null && visibleSelectionBounds.height < selectionBounds.height) {
                tableView.scrollAreaToVisible(selectionBounds);
            }
        }
    }
    validateSelection = false;
}
Also used : Bounds(org.apache.pivot.wtk.Bounds) Span(org.apache.pivot.wtk.Span) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List) TableView(org.apache.pivot.wtk.TableView)

Example 13 with ArrayList

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

the class TerraTableViewSkin method getBaseline.

@Override
public int getBaseline(int width, int height) {
    TableView tableView = (TableView) getComponent();
    @SuppressWarnings("unchecked") List<Object> tableData = (List<Object>) tableView.getTableData();
    int baseline = -1;
    TableView.ColumnSequence columns = tableView.getColumns();
    ArrayList<Integer> columnWidthsLocal = getColumnWidths(tableView, width);
    if (variableRowHeight) {
        int rowHeight = getVariableRowHeight(0, columnWidthsLocal);
        Object rowData = tableData.get(0);
        for (int i = 0, n = columns.getLength(); i < n; i++) {
            TableView.Column column = columns.get(i);
            TableView.CellRenderer cellRenderer = column.getCellRenderer();
            cellRenderer.render(rowData, 0, i, tableView, column.getName(), false, false, false);
            baseline = Math.max(baseline, cellRenderer.getBaseline(columnWidthsLocal.get(i).intValue(), rowHeight));
        }
    } else {
        int rowHeight = calculateFixedRowHeight(tableView);
        for (int i = 0, n = columns.getLength(); i < n; i++) {
            TableView.Column column = columns.get(i);
            TableView.CellRenderer cellRenderer = column.getCellRenderer();
            cellRenderer.render(null, -1, i, tableView, column.getName(), false, false, false);
            baseline = Math.max(baseline, cellRenderer.getBaseline(columnWidthsLocal.get(i).intValue(), rowHeight));
        }
    }
    return baseline;
}
Also used : ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List) TableView(org.apache.pivot.wtk.TableView)

Example 14 with ArrayList

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

the class TerraTreeViewSkin method showMixedCheckmarkStateChanged.

@Override
public void showMixedCheckmarkStateChanged(TreeView treeView) {
    if (treeView.getCheckmarksEnabled()) {
        // The check state of all *branch* nodes may have changed, so we
        // need to update the cached check state of all BranchNode
        // instances in our hierarchy
        Sequence<NodeInfo> nodes = new ArrayList<>();
        nodes.add(rootBranchInfo);
        while (nodes.getLength() > 0) {
            NodeInfo nodeInfo = nodes.get(0);
            nodes.remove(0, 1);
            // Only branch nodes can be affected by this event
            if (nodeInfo instanceof BranchInfo) {
                BranchInfo branchInfo = (BranchInfo) nodeInfo;
                // Update the cached entry for this branch
                Path path = branchInfo.getPath();
                branchInfo.setCheckState(treeView.getNodeCheckState(path));
                // Add the branch's children to the queue
                if (branchInfo.children != null) {
                    for (int i = 0, n = branchInfo.children.getLength(); i < n; i++) {
                        nodes.insert(branchInfo.children.get(i), i);
                    }
                }
            }
        }
        repaintComponent();
    }
}
Also used : Path(org.apache.pivot.collections.Sequence.Tree.Path) GeneralPath(java.awt.geom.GeneralPath) ArrayList(org.apache.pivot.collections.ArrayList)

Example 15 with ArrayList

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

the class TerraVFSBrowserSheetSkin method previewSheetClose.

@Override
public Vote previewSheetClose(final Sheet sheet, final boolean result) {
    Vote vote = null;
    if (result && !okButton.isEnabled()) {
        vote = Vote.DENY;
    } else {
        if (result) {
            updatingSelection = true;
            VFSBrowserSheet fileBrowserSheet = (VFSBrowserSheet) sheet;
            VFSBrowserSheet.Mode mode = fileBrowserSheet.getMode();
            FileSystemManager manager = fileBrowserSheet.getManager();
            FileName baseFileName = fileBrowserSheet.getBaseFileName();
            switch(mode) {
                case OPEN:
                case OPEN_MULTIPLE:
                case SAVE_TO:
                    {
                        try {
                            fileBrowserSheet.setSelectedFiles(fileBrowser.getSelectedFiles());
                        } catch (FileSystemException fse) {
                            throw new RuntimeException(fse);
                        }
                        break;
                    }
                case SAVE_AS:
                    {
                        String fileName = saveAsTextInput.getText();
                        // current location and let the chips fall ...
                        try {
                            FileObject selectedFile = manager.resolveFile(fileBrowser.getRootDirectory(), fileName);
                            // !fileName.startsWith(File.separator)) {
                            if (selectedFile.exists() && selectedFile.getType() == FileType.FOLDER) {
                                try {
                                    // TODO: what to do about canonical file representations?
                                    FileObject root = /* selectedFile.getCanonicalFile(); */
                                    selectedFile;
                                    fileBrowserSheet.setRootDirectory(root);
                                    fileBrowser.setRootDirectory(root);
                                    setHostLabel(root);
                                    saveAsTextInput.setText("");
                                } catch (IOException ioe) {
                                    Form.setFlag(saveAsBoxPane, new Form.Flag());
                                }
                                selectedFile = null;
                                vote = Vote.DENY;
                            } else {
                                FileObject root = selectedFile.getParent();
                                if (root != null && root.exists() && root.getType() == FileType.FOLDER) {
                                    try {
                                        // TODO: canonical file again
                                        // fileBrowserSheet.setRootDirectory(root.getCanonicalFile());
                                        fileBrowserSheet.setRootDirectory(root);
                                        setHostLabel(root);
                                        selectedFile = manager.resolveFile(selectedFile.getName().getURI());
                                    } catch (IOException ioe) {
                                        Form.setFlag(saveAsBoxPane, new Form.Flag());
                                        selectedFile = null;
                                        vote = Vote.DENY;
                                    }
                                } else {
                                    // Could be an error message here
                                    // ("Directory does not exist")
                                    Form.setFlag(saveAsBoxPane, new Form.Flag());
                                    selectedFile = null;
                                    vote = Vote.DENY;
                                }
                            }
                            if (selectedFile != null) {
                                fileBrowserSheet.setSelectedFiles(new ArrayList<>(selectedFile));
                            }
                        } catch (FileSystemException fse) {
                            Form.setFlag(saveAsBoxPane, new Form.Flag());
                            vote = Vote.DENY;
                        }
                        break;
                    }
                default:
                    break;
            }
            updatingSelection = false;
        }
        if (vote == null) {
            vote = super.previewSheetClose(sheet, result);
        }
    }
    return vote;
}
Also used : Vote(org.apache.pivot.util.Vote) Form(org.apache.pivot.wtk.Form) FileName(org.apache.commons.vfs2.FileName) ArrayList(org.apache.pivot.collections.ArrayList) IOException(java.io.IOException) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) FileSystemException(org.apache.commons.vfs2.FileSystemException) VFSBrowserSheet(org.apache.pivot.wtk.VFSBrowserSheet) FileObject(org.apache.commons.vfs2.FileObject)

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