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);
}
}
}
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);
}
}
}
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());
}
}
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));
}
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;
}
Aggregations