Search in sources :

Example 6 with Vote

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

the class TextInput method removeText.

private void removeText(int index, int count, boolean addToEditHistory) {
    if (count > 0) {
        Vote vote = textInputContentListeners.previewRemoveText(this, index, count);
        if (vote == Vote.APPROVE) {
            // Add a remove history item
            if (addToEditHistory) {
                editHistory.push(new RemoveTextEdit(index, count));
            }
            // Remove the text
            characters.delete(index, index + count);
            // Update the selection
            int previousSelectionStart = selectionStart;
            int previousSelectionLength = selectionLength;
            selectionStart = index;
            selectionLength = 0;
            // Update the valid flag
            boolean previousTextValid = textValid;
            textValid = (validator == null) ? true : validator.isValid(getText());
            // Fire change events
            textInputContentListeners.textRemoved(this, index, count);
            textInputContentListeners.textChanged(this);
            if (textValid != previousTextValid) {
                textInputListeners.textValidChanged(this);
            }
            if (selectionStart != previousSelectionStart || selectionLength != previousSelectionLength) {
                textInputSelectionListeners.selectionChanged(this, selectionStart, selectionLength);
            }
        } else {
            textInputContentListeners.removeTextVetoed(this, vote);
        }
    }
}
Also used : Vote(org.apache.pivot.util.Vote)

Example 7 with Vote

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

the class TextInput method insertText.

private void insertText(CharSequence text, int index, boolean addToEditHistory) {
    Utils.checkNull(text, "text");
    if (characters.length() + text.length() > maximumLength) {
        throw new IllegalArgumentException("Insertion of text would exceed maximum length.");
    }
    if (text.length() > 0) {
        Vote vote = textInputContentListeners.previewInsertText(this, text, index);
        if (vote == Vote.APPROVE) {
            // Insert the text
            characters.insert(index, text);
            // Add an insert history item
            if (addToEditHistory) {
                editHistory.push(new InsertTextEdit(text, index));
            }
            // Update selection
            int previousSelectionStart = selectionStart;
            int previousSelectionLength = selectionLength;
            selectionStart = index + text.length();
            selectionLength = 0;
            // Update the valid flag
            boolean previousTextValid = textValid;
            textValid = (validator == null) ? true : validator.isValid(getText());
            // Fire change events
            textInputContentListeners.textInserted(this, index, text.length());
            textInputContentListeners.textChanged(this);
            if (textValid != previousTextValid) {
                textInputListeners.textValidChanged(this);
            }
            if (selectionStart != previousSelectionStart || selectionLength != previousSelectionLength) {
                textInputSelectionListeners.selectionChanged(this, selectionStart, selectionLength);
            }
        } else {
            textInputContentListeners.insertTextVetoed(this, vote);
        }
    }
}
Also used : Vote(org.apache.pivot.util.Vote)

Example 8 with Vote

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

the class VoteResultTest method test1.

@Test
public void test1() {
    ArrayList<Vote> votes = new ArrayList<>();
    votes.add(Vote.APPROVE);
    votes.add(Vote.DEFER);
    votes.add(Vote.DENY);
    // These are the expected results as each vote is tallied
    ArrayList<Vote> results = new ArrayList<>();
    results.add(Vote.APPROVE);
    results.add(Vote.DEFER);
    results.add(Vote.DENY);
    VoteResult result = new VoteResult();
    Iterator<Vote> resultIter = results.iterator();
    for (Vote vote : votes) {
        result.tally(vote);
        assertEquals(result.get(), resultIter.next());
    }
}
Also used : Vote(org.apache.pivot.util.Vote) ArrayList(org.apache.pivot.collections.ArrayList) VoteResult(org.apache.pivot.util.VoteResult) Test(org.junit.Test)

Example 9 with Vote

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

the class CardPaneTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    frame = new Frame(new BoxPane());
    frame.getStyles().put(Style.padding, 0);
    frame.setTitle("Component Pane Test");
    frame.setPreferredSize(800, 600);
    frame.setLocation(20, 20);
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    sheet = (Sheet) bxmlSerializer.readObject(CardPaneTest.class, "card_pane_test.bxml");
    cardPane = (CardPane) bxmlSerializer.getNamespace().get("cardPane");
    sizeGroup = (ButtonGroup) bxmlSerializer.getNamespace().get("sizeGroup");
    sizeGroup.getButtonGroupListeners().add(new ButtonGroupListener() {

        @Override
        public void selectionChanged(ButtonGroup buttonGroup, Button previousSelection) {
            final Button selection = buttonGroup.getSelection();
            int selectedIndex = selection == null ? -1 : selection.getParent().indexOf(selection);
            cardPane.getCardPaneListeners().add(new CardPaneListener() {

                @Override
                public Vote previewSelectedIndexChange(CardPane cardPaneArgument, int selectedIndexArgument) {
                    if (selection != null) {
                        selection.getParent().setEnabled(false);
                    }
                    return Vote.APPROVE;
                }

                @Override
                public void selectedIndexChangeVetoed(CardPane cardPaneArgument, Vote reason) {
                    if (selection != null && reason == Vote.DENY) {
                        selection.getParent().setEnabled(true);
                    }
                }

                @Override
                public void selectedIndexChanged(CardPane cardPaneArgument, int previousSelectedIndex) {
                    if (selection != null) {
                        selection.getParent().setEnabled(true);
                    }
                }
            });
            cardPane.setSelectedIndex(selectedIndex);
        }
    });
    frame.open(display);
    ApplicationContext.queueCallback(() -> sheet.open(frame));
}
Also used : Frame(org.apache.pivot.wtk.Frame) CardPane(org.apache.pivot.wtk.CardPane) Vote(org.apache.pivot.util.Vote) BoxPane(org.apache.pivot.wtk.BoxPane) ButtonGroup(org.apache.pivot.wtk.ButtonGroup) Button(org.apache.pivot.wtk.Button) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer) ButtonGroupListener(org.apache.pivot.wtk.ButtonGroupListener) CardPaneListener(org.apache.pivot.wtk.CardPaneListener)

Example 10 with Vote

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

the class TerraTooltipSkin method previewWindowClose.

@Override
public Vote previewWindowClose(final Window window) {
    Vote vote = Vote.APPROVE;
    if (fade) {
        if (closeTransition == null) {
            closeTransition = new FadeWindowTransition(window, closeTransitionDuration, closeTransitionRate, dropShadowDecorator);
            closeTransition.start(new TransitionListener() {

                @Override
                public void transitionCompleted(Transition transition) {
                    window.close();
                }
            });
            vote = Vote.DEFER;
        } else {
            vote = (closeTransition.isRunning()) ? Vote.DEFER : Vote.APPROVE;
        }
    }
    return vote;
}
Also used : Vote(org.apache.pivot.util.Vote) Transition(org.apache.pivot.wtk.effects.Transition) TransitionListener(org.apache.pivot.wtk.effects.TransitionListener)

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