Search in sources :

Example 6 with Sheet

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

the class TerraSheetSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    Sheet sheet = (Sheet) component;
    sheet.getSheetStateListeners().add(this);
    // Attach the drop-shadow decorator
    if (!themeIsFlat()) {
        dropShadowDecorator = new DropShadowDecorator();
        sheet.getDecorators().add(dropShadowDecorator);
    }
    sheet.add(resizeHandle);
}
Also used : DropShadowDecorator(org.apache.pivot.wtk.effects.DropShadowDecorator) Sheet(org.apache.pivot.wtk.Sheet)

Example 7 with Sheet

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

the class TerraSheetSkin method alignToOwner.

public void alignToOwner() {
    Sheet sheet = (Sheet) getComponent();
    Window owner = sheet.getOwner();
    if (owner != null) {
        Bounds clientArea = owner.getClientArea();
        Point location = owner.mapPointToAncestor(owner.getDisplay(), clientArea.x, clientArea.y);
        int x = location.x;
        int y = location.y;
        switch(slideSource) {
            case NORTH:
                x = location.x + (clientArea.width - getWidth()) / 2;
                y = location.y;
                break;
            case SOUTH:
                x = location.x + (clientArea.width - getWidth()) / 2;
                y = location.y + (clientArea.height - getHeight());
                break;
            case WEST:
                x = location.x;
                y = location.y + (clientArea.height - getHeight()) / 2;
                break;
            case EAST:
                x = location.x + (clientArea.width - getWidth());
                y = location.y + (clientArea.height - getHeight()) / 2;
                break;
            default:
                throw new IllegalStateException("slideSource is null or an unexpected value");
        }
        sheet.setLocation(x, y);
    }
}
Also used : Window(org.apache.pivot.wtk.Window) Bounds(org.apache.pivot.wtk.Bounds) Point(org.apache.pivot.wtk.Point) Sheet(org.apache.pivot.wtk.Sheet) Point(org.apache.pivot.wtk.Point)

Example 8 with Sheet

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

the class ExpensesWindow method addExpense.

private void addExpense() {
    expenseSheet.clear();
    expenseSheet.open(this, new SheetCloseListener() {

        @Override
        public void sheetClosed(Sheet sheet) {
            if (sheet.getResult()) {
                // Get the expense data from the sheet
                final HashMap<String, Object> expense = new HashMap<>();
                expenseSheet.store(expense);
                // POST expense to server and then add to table
                Expenses expensesApplicationLocal = getExpensesApplication();
                PostQuery addExpenseQuery = new PostQuery(expensesApplicationLocal.getHostname(), expensesApplicationLocal.getPort(), "/pivot-tutorials/expenses", expensesApplicationLocal.isSecure());
                addExpenseQuery.setValue(expense);
                activityIndicatorBoxPane.setVisible(true);
                activityIndicator.setActive(true);
                addExpenseQuery.execute(new TaskAdapter<>(new TaskListener<URL>() {

                    @Override
                    public void taskExecuted(Task<URL> task) {
                        activityIndicatorBoxPane.setVisible(false);
                        activityIndicator.setActive(false);
                        URL location = task.getResult();
                        String file = location.getFile();
                        int id = Integer.parseInt(file.substring(file.lastIndexOf('/') + 1));
                        expense.put("id", id);
                        @SuppressWarnings("unchecked") List<Object> expenses = (List<Object>) expenseTableView.getTableData();
                        expenses.add(expense);
                    }

                    @Override
                    public void executeFailed(Task<URL> task) {
                        activityIndicatorBoxPane.setVisible(false);
                        activityIndicator.setActive(false);
                        Prompt.prompt(MessageType.ERROR, task.getFault().getMessage(), ExpensesWindow.this);
                    }
                }));
            }
        }
    });
}
Also used : HashMap(org.apache.pivot.collections.HashMap) SheetCloseListener(org.apache.pivot.wtk.SheetCloseListener) URL(java.net.URL) TaskAdapter(org.apache.pivot.wtk.TaskAdapter) PostQuery(org.apache.pivot.web.PostQuery) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List) Sheet(org.apache.pivot.wtk.Sheet)

Example 9 with Sheet

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

the class ExpensesWindow method updateSelectedExpense.

private void updateSelectedExpense() {
    Object expense = expenseTableView.getSelectedRow();
    final int id = JSON.getInt(expense, "id");
    expenseSheet.load(expense);
    expenseSheet.open(this, new SheetCloseListener() {

        @Override
        public void sheetClosed(Sheet sheet) {
            if (sheet.getResult()) {
                // Get the expense data from the sheet
                final HashMap<String, Object> expenseLocal = new HashMap<>();
                expenseSheet.store(expenseLocal);
                // PUT expense to server and then update table
                Expenses expensesApplicationLocal = getExpensesApplication();
                PutQuery updateExpenseQuery = new PutQuery(expensesApplicationLocal.getHostname(), expensesApplicationLocal.getPort(), "/pivot-tutorials/expenses/" + JSON.get(expenseLocal, "id"), expensesApplicationLocal.isSecure());
                updateExpenseQuery.setValue(expenseLocal);
                activityIndicatorBoxPane.setVisible(true);
                activityIndicator.setActive(true);
                updateExpenseQuery.execute(new TaskAdapter<>(new TaskListener<Boolean>() {

                    @Override
                    public void taskExecuted(Task<Boolean> task) {
                        activityIndicatorBoxPane.setVisible(false);
                        activityIndicator.setActive(false);
                        // Find matching row and update
                        @SuppressWarnings("unchecked") List<Object> expenses = (List<Object>) expenseTableView.getTableData();
                        for (int i = 0, n = expenses.getLength(); i < n; i++) {
                            if (JSON.get(expenses.get(i), "id").equals(id)) {
                                expenses.update(i, expenseLocal);
                                break;
                            }
                        }
                    }

                    @Override
                    public void executeFailed(Task<Boolean> task) {
                        activityIndicatorBoxPane.setVisible(false);
                        activityIndicator.setActive(false);
                        Prompt.prompt(MessageType.ERROR, task.getFault().getMessage(), ExpensesWindow.this);
                    }
                }));
            }
        }
    });
}
Also used : HashMap(org.apache.pivot.collections.HashMap) SheetCloseListener(org.apache.pivot.wtk.SheetCloseListener) PutQuery(org.apache.pivot.web.PutQuery) TaskAdapter(org.apache.pivot.wtk.TaskAdapter) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List) Sheet(org.apache.pivot.wtk.Sheet)

Example 10 with Sheet

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

the class TabPanes method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    confirmCloseTabPrompt = (Prompt) namespace.get("confirmCloseTabPrompt");
    tabPane = (TabPane) namespace.get("tabPane");
    closeableCheckbox = (Checkbox) namespace.get("closeableCheckbox");
    collapsibleCheckbox = (Checkbox) namespace.get("collapsibleCheckbox");
    horizontalRadioButton = (RadioButton) namespace.get("horizontalRadioButton");
    verticalRadioButton = (RadioButton) namespace.get("verticalRadioButton");
    cornerBoxPane = (BoxPane) namespace.get("cornerBoxPane");
    tabPane.getTabPaneListeners().add(new TabPaneListener() {

        @Override
        public Vote previewRemoveTabs(final TabPane tabPaneArgument, final int index, final int count) {
            Vote vote;
            if (confirmCloseTab) {
                confirmCloseTabPrompt.open(TabPanes.this, new SheetCloseListener() {

                    @Override
                    public void sheetClosed(Sheet sheet) {
                        if (confirmCloseTabPrompt.getResult() && confirmCloseTabPrompt.getSelectedOptionIndex() == 1) {
                            confirmCloseTab = false;
                            int n = tabPaneArgument.getTabs().getLength();
                            if (index < n - 1) {
                                tabPaneArgument.setSelectedIndex(index + 1);
                            } else {
                                tabPaneArgument.setSelectedIndex(index - 1);
                            }
                            tabPaneArgument.getTabs().remove(index, count);
                            confirmCloseTab = true;
                        }
                    }
                });
                vote = Vote.DENY;
            } else {
                vote = Vote.APPROVE;
            }
            return vote;
        }
    });
    ButtonStateListener checkboxStateListener = new ButtonStateListener() {

        @Override
        public void stateChanged(Button button, Button.State previousState) {
            updateTabPane();
        }
    };
    closeableCheckbox.getButtonStateListeners().add(checkboxStateListener);
    collapsibleCheckbox.getButtonStateListeners().add(checkboxStateListener);
    ButtonStateListener radioButtonStateListener = new ButtonStateListener() {

        @Override
        public void stateChanged(Button button, Button.State previousState) {
            if (button.isSelected()) {
                updateTabPane();
            }
        }
    };
    horizontalRadioButton.getButtonStateListeners().add(radioButtonStateListener);
    verticalRadioButton.getButtonStateListeners().add(radioButtonStateListener);
    updateTabPane();
}
Also used : TabPaneListener(org.apache.pivot.wtk.TabPaneListener) TabPane(org.apache.pivot.wtk.TabPane) Vote(org.apache.pivot.util.Vote) RadioButton(org.apache.pivot.wtk.RadioButton) Button(org.apache.pivot.wtk.Button) ButtonStateListener(org.apache.pivot.wtk.ButtonStateListener) SheetCloseListener(org.apache.pivot.wtk.SheetCloseListener) Sheet(org.apache.pivot.wtk.Sheet)

Aggregations

Sheet (org.apache.pivot.wtk.Sheet)22 SheetCloseListener (org.apache.pivot.wtk.SheetCloseListener)11 Button (org.apache.pivot.wtk.Button)9 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)8 PushButton (org.apache.pivot.wtk.PushButton)8 Component (org.apache.pivot.wtk.Component)6 Point (org.apache.pivot.wtk.Point)6 File (java.io.File)5 FileBrowserSheet (org.apache.pivot.wtk.FileBrowserSheet)5 Frame (org.apache.pivot.wtk.Frame)4 ListView (org.apache.pivot.wtk.ListView)4 IOException (java.io.IOException)3 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)3 ArrayList (org.apache.pivot.collections.ArrayList)3 HashMap (org.apache.pivot.collections.HashMap)3 List (org.apache.pivot.collections.List)3 Bounds (org.apache.pivot.wtk.Bounds)3 BoxPane (org.apache.pivot.wtk.BoxPane)3 TaskAdapter (org.apache.pivot.wtk.TaskAdapter)3 Window (org.apache.pivot.wtk.Window)3