Search in sources :

Example 16 with Vote

use of org.apache.pivot.util.Vote 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)

Example 17 with Vote

use of org.apache.pivot.util.Vote in project pivot by apache.

the class Window method open.

/**
 * Opens the window. <p> Note that this method is not a synchronous call, it
 * schedules an event to open the window.
 *
 * @param display The display on which the window will be opened.
 * @param ownerArgument The window's owner, or <tt>null</tt> if the window
 * has no owner.
 */
public void open(Display display, Window ownerArgument) {
    Utils.checkNull(display, "display");
    if (ownerArgument != null) {
        if (!ownerArgument.isOpen()) {
            throw new IllegalArgumentException("owner is not open.");
        }
        if (isOwner(ownerArgument)) {
            throw new IllegalArgumentException("owner is an owned descendant of this window.");
        }
    }
    if (isOpen()) {
        if (getDisplay() != display) {
            throw new IllegalStateException("Window is already open on a different display.");
        }
        if (this.owner != ownerArgument) {
            throw new IllegalStateException("Window is already open with a different owner.");
        }
    }
    if (!isOpen()) {
        opening = true;
        Vote vote = windowStateListeners.previewWindowOpen(this);
        if (vote == Vote.APPROVE) {
            // Set the owner and add to the owner's owned window list
            this.owner = ownerArgument;
            if (ownerArgument != null) {
                ownerArgument.ownedWindows.add(this);
            }
            // Add the window to the display
            display.add(this);
            // Notify listeners
            opening = false;
            windowStateListeners.windowOpened(this);
            moveToFront();
        } else {
            if (vote == Vote.DENY) {
                opening = false;
            }
            windowStateListeners.windowOpenVetoed(this, vote);
        }
    }
}
Also used : Vote(org.apache.pivot.util.Vote)

Example 18 with Vote

use of org.apache.pivot.util.Vote in project pivot by apache.

the class TabPane method setSelectedIndex.

public void setSelectedIndex(int selectedIndex) {
    indexBoundsCheck("selectedIndex", selectedIndex, -1, tabs.getLength() - 1);
    int previousSelectedIndex = this.selectedIndex;
    if (previousSelectedIndex != selectedIndex) {
        Vote vote = tabPaneSelectionListeners.previewSelectedIndexChange(this, selectedIndex);
        if (vote == Vote.APPROVE) {
            this.selectedIndex = selectedIndex;
            tabPaneSelectionListeners.selectedIndexChanged(this, previousSelectedIndex);
        } else {
            tabPaneSelectionListeners.selectedIndexChangeVetoed(this, vote);
        }
    }
}
Also used : Vote(org.apache.pivot.util.Vote)

Example 19 with Vote

use of org.apache.pivot.util.Vote in project pivot by apache.

the class Rollup method setExpanded.

public void setExpanded(boolean expanded) {
    if (expanded != this.expanded) {
        Vote vote = rollupStateListeners.previewExpandedChange(this);
        if (vote == Vote.APPROVE) {
            this.expanded = expanded;
            rollupStateListeners.expandedChanged(this);
        } else {
            rollupStateListeners.expandedChangeVetoed(this, vote);
        }
    }
}
Also used : Vote(org.apache.pivot.util.Vote)

Example 20 with Vote

use of org.apache.pivot.util.Vote in project pivot by apache.

the class Dialog method close.

public void close(boolean resultArgument) {
    if (!isClosed()) {
        closing = true;
        Vote vote = dialogStateListeners.previewDialogClose(this, resultArgument);
        if (vote == Vote.APPROVE) {
            Window owner = getOwner();
            super.close();
            closing = super.isClosing();
            if (isClosed()) {
                this.result = resultArgument;
                // Move the owner to the front
                if (owner != null && owner.isOpen()) {
                    owner.moveToFront();
                }
                // Notify listeners
                dialogStateListeners.dialogClosed(this, modal);
                if (dialogCloseListener != null) {
                    dialogCloseListener.dialogClosed(this, modal);
                    dialogCloseListener = null;
                }
            }
        } else {
            if (vote == Vote.DENY) {
                closing = false;
            }
            dialogStateListeners.dialogCloseVetoed(this, vote);
        }
    }
}
Also used : Vote(org.apache.pivot.util.Vote)

Aggregations

Vote (org.apache.pivot.util.Vote)28 ArrayList (org.apache.pivot.collections.ArrayList)4 Transition (org.apache.pivot.wtk.effects.Transition)4 TransitionListener (org.apache.pivot.wtk.effects.TransitionListener)4 IOException (java.io.IOException)2 Button (org.apache.pivot.wtk.Button)2 Component (org.apache.pivot.wtk.Component)2 Form (org.apache.pivot.wtk.Form)2 Window (org.apache.pivot.wtk.Window)2 Validator (org.apache.pivot.wtk.validation.Validator)2 GradientPaint (java.awt.GradientPaint)1 File (java.io.File)1 FileName (org.apache.commons.vfs2.FileName)1 FileObject (org.apache.commons.vfs2.FileObject)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 FileSystemManager (org.apache.commons.vfs2.FileSystemManager)1 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)1 ImmutablePath (org.apache.pivot.collections.Sequence.Tree.ImmutablePath)1 VoteResult (org.apache.pivot.util.VoteResult)1 Accordion (org.apache.pivot.wtk.Accordion)1