List of usage examples for com.google.gwt.user.client.ui TextArea getCursorPos
@Override
public int getCursorPos()
From source file:ch.heftix.mailxel.client.OrgTextArea.java
License:Open Source License
public OrgTextArea() { KeyboardListener kl = new KeyboardListener() { Duration sinceEscapePressed = null; public void onKeyDown(Widget sender, char keyCode, int modifiers) { if (keyCode == KeyboardListener.KEY_ESCAPE) { sinceEscapePressed = new Duration(); }/* w w w . ja v a 2s .co m*/ } public void onKeyUp(Widget sender, char keyCode, int modifiers) { } public void onKeyPress(Widget sender, char keyCode, int modifiers) { if ('q' == keyCode) { // System.out.println(sinceEscapePressed.elapsedMillis()); if (null != sinceEscapePressed && (sinceEscapePressed.elapsedMillis() < 300)) { // format region TextArea ta = (TextArea) sender; String text = ta.getText(); int pos = ta.getCursorPos(); int len = ta.getSelectionLength(); String replacement = om.prefixSelection(text, "> ", pos, len); ta.setText(replacement); cancelKey(); } } } }; addKeyboardListener(kl); }
From source file:nl.mpi.tg.eg.experiment.client.view.TimedStimulusView.java
License:Open Source License
public StimulusFreeText addStimulusFreeText(final Stimulus stimulus, final String postName, final String validationRegex, final String keyCodeChallenge, final String validationChallenge, final String allowedCharCodes, final SingleShotEventListner enterKeyListner, final int hotKey, final String styleName, final int dataChannel, final String textValue) { final int inputLengthLimit = 1000; // this coud be a parameter from the configuraiton file, however the validationRegex can also limit the input length. // perhaps consider removing allowedCharCodes and doing a regex test on each key? final Label errorLabel = new Label(validationChallenge); errorLabel.setStylePrimaryName("metadataErrorMessage"); errorLabel.setVisible(false);/*w w w .j a va 2s. c o m*/ getActivePanel().add(errorLabel); final Duration duration = new Duration(); final StringBuilder responseTimes = new StringBuilder(); final TextArea textBox = new TextArea(); if (textValue != null) { textBox.setText(textValue); } if (hotKey == KeyCodes.KEY_ENTER) { textBox.setVisibleLines(1); textBox.getElement().getStyle().setProperty("minHeight", "26px"); } if (styleName != null) { textBox.addStyleName(styleName); } textBox.setStylePrimaryName("metadataOK"); getActivePanel().add(textBox); textBox.setFocus(true); textBox.addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { final char charCode = event.getCharCode(); if (charCode > -1 && charCode == hotKey) { event.getNativeEvent().preventDefault(); enterKeyListner.eventFired(); errorLabel.setVisible(false); } else if (charCode == 0) { // firefox needs these events to be handled by allowing the event to pass return; } else if (textBox.getText().length() > inputLengthLimit) { event.getNativeEvent().preventDefault(); // todo: update this to give a sensible message errorLabel.setText( keyCodeChallenge.replace("<keycode>", "" + inputLengthLimit) + validationChallenge); errorLabel.setVisible(true); } else if (allowedCharCodes != null) { if (0 > allowedCharCodes.indexOf(charCode)) { event.getNativeEvent().preventDefault(); final char invertedCaseCode = (Character.isLowerCase(charCode)) ? Character.toUpperCase(charCode) : Character.toLowerCase(charCode); if (0 > allowedCharCodes.indexOf(invertedCaseCode)) { // if the key is not allowed, then show a message // final String messageString = "The key '<keycode>' is not allowed. " + validationChallenge; errorLabel.setText( keyCodeChallenge.replace("<keycode>", "" + charCode) + validationChallenge); errorLabel.setVisible(true); } else { responseTimes.append(duration.elapsedMillis()); responseTimes.append(","); // if the case is not allowed, then modify the case to what is final int cursorPos = textBox.getCursorPos(); String pretext = textBox.getText().substring(0, cursorPos); String posttext = textBox.getText().substring(textBox.getCursorPos()); textBox.setText(pretext + invertedCaseCode + posttext); textBox.setCursorPos(cursorPos + 1); errorLabel.setVisible(false); } } else { responseTimes.append(duration.elapsedMillis()); responseTimes.append(","); errorLabel.setVisible(false); } } else { responseTimes.append(duration.elapsedMillis()); responseTimes.append(","); errorLabel.setVisible(false); } } }); final StimulusFreeText stimulusFreeText = new StimulusFreeText() { @Override public Stimulus getStimulus() { return stimulus; } @Override public String getValue() { return textBox.getValue(); } @Override public String getResponseTimes() { return responseTimes.substring(0, responseTimes.length() - 1); } @Override public boolean isValid() { if ((getValue().length() <= inputLengthLimit + 2) && (validationRegex == null || getValue().matches(validationRegex))) { textBox.setStylePrimaryName("metadataOK"); errorLabel.setVisible(false); return true; } else { textBox.setStylePrimaryName("metadataError"); errorLabel.setText(validationChallenge); errorLabel.setVisible(true); textBox.setFocus(true); return false; } } @Override public String getPostName() { return postName; } @Override public int getDataChannel() { return dataChannel; } @Override public void setFocus(boolean wantsFocus) { textBox.setFocus(wantsFocus); } }; return stimulusFreeText; }
From source file:scrum.client.test.WidgetsTesterWidget.java
License:Open Source License
private void textTextarea() { final TextArea ta = new TextArea(); Button btn = new Button("check", new ClickHandler() { @Override/*from w w w.j a va 2 s . c o m*/ public void onClick(ClickEvent event) { int cursorPos = ta.getCursorPos(); Gwt.confirm("cursorPos: " + cursorPos); } }); addTest("Textarea", Gwt.createFlowPanel(ta, btn)); }
From source file:us.softoption.infrastructure.TGWTUtilities.java
License:Open Source License
static public void writeOverJournalSelection(TextArea journal, String message) { int current = journal.getCursorPos(); //if there isn't one it's dot which is the old one int selLength = journal.getSelectionLength(); int messageLength = message.length(); String text = journal.getText(); text = text.substring(0, current) + message + text.substring(current + selLength); journal.setText(text);/* w w w. ja va 2s .co m*/ journal.setCursorPos(current + messageLength); journal.setSelectionRange(current + messageLength, 0); journal.setFocus(true); }
From source file:us.softoption.infrastructure.TGWTUtilities.java
License:Open Source License
static public void writeToJournal(TextArea journal, String message, boolean highlight) { int oldCaretPos = journal.getCursorPos(); int oldSelLength = journal.getSelectionLength(); int newCaretPos = oldCaretPos + oldSelLength; int messageLength = message.length(); String text = journal.getText(); String before = text.substring(0, oldCaretPos); String after = text.substring(oldCaretPos + oldSelLength); text = before + message + after; // we con't want to include the original selection journal.setText(text);/*w ww .j a v a2s. c om*/ if (messageLength > 0) { // before aaa<sel>bbb // after aaa<new>Ibbb or // after aaa<new>bbb with new selected // journal.setSelectionRange(newCaretPos,messageLength); new Nov 11 // journal.setSelectionRange(newCaretPos,0); // journal.setCursorPos(newCaretPos); //leave existing selection and do everything after; if (highlight) { newCaretPos = oldCaretPos; journal.setCursorPos(newCaretPos); journal.setSelectionRange(newCaretPos, messageLength); journal.setFocus(true); } else { newCaretPos = oldCaretPos + messageLength; journal.setCursorPos(newCaretPos); journal.setSelectionRange(newCaretPos, 0); } } }