@Override
        public void verifyText(VerifyEvent e) {
          // If the edit mask is already full, don't let the user type
          // any new characters
          if (editMaskParser.isComplete()
              && // should eventually be .isFull() to account for optional characters
              e.start == e.end
              && e.text.length() > 0) {
            e.doit = false;
            return;
          }

          oldSelection = selection;
          Point selectionRange = text.getSelection();
          selection = selectionRange.x;

          if (!updating) {
            replacedSelectedText = false;
            if (selectionRange.y - selectionRange.x > 0 && e.text.length() > 0) {
              replacedSelectedText = true;
            }
            // If the machine is loaded down (ie: spyware, malware), we might
            // get another keystroke before asyncExec can process, so we use
            // greedyExec instead.
            SWTUtil.greedyExec(Display.getCurrent(), updateTextField);
            //				Display.getCurrent().asyncExec(updateTextField);
          }
        }
Пример #2
0
  @Test
  public void testSelectionAfterInsertText() {
    text.setText("foobar");
    text.setSelection(3);

    text.insert("xxx");

    assertEquals(new Point(6, 6), text.getSelection());
  }
Пример #3
0
 @Test
 public void testInitialValuesForSingleText() {
   assertEquals("", text.getText());
   assertEquals("", text.getMessage());
   assertEquals(Text.LIMIT, text.getTextLimit());
   assertEquals(0, text.getSelectionCount());
   assertEquals(new Point(0, 0), text.getSelection());
   assertEquals((char) 0, text.getEchoChar());
 }
Пример #4
0
  @Test
  public void testSelection() {
    // test select all
    text.setText("abc");
    text.selectAll();
    assertEquals(new Point(0, 3), text.getSelection());
    assertEquals("abc", text.getSelectionText());

    // test clearSelection
    text.setText("abc");
    text.clearSelection();
    assertEquals(new Point(0, 0), text.getSelection());
    assertEquals("", text.getSelectionText());

    // test setSelection
    text.setText("abc");
    text.setSelection(1);
    assertEquals(new Point(1, 1), text.getSelection());
    assertEquals(0, text.getSelectionCount());
    assertEquals("", text.getSelectionText());
    text.setSelection(1000);
    assertEquals(new Point(3, 3), text.getSelection());
    assertEquals(0, text.getSelectionCount());
    assertEquals("", text.getSelectionText());
    Point saveSelection = text.getSelection();
    text.setSelection(-1);
    assertEquals(saveSelection, text.getSelection());
    assertEquals(0, text.getSelectionCount());
    assertEquals("", text.getSelectionText());
    text.setText("abcdefg");
    text.setSelection(new Point(5, 2));
    assertEquals(new Point(2, 5), text.getSelection());

    // test selection when changing text
    text.setText("abcefg");
    text.setSelection(1, 2);
    text.setText("gfecba");
    assertEquals(new Point(0, 0), text.getSelection());
    // ... even setting the same text again will clear the selection
    text.setText("abcefg");
    text.setSelection(1, 2);
    text.setText(text.getText());
    assertEquals(new Point(0, 0), text.getSelection());
  }
Пример #5
0
 @Test
 public void testGetCaretPosition() {
   Text text = new Text(shell, SWT.SINGLE);
   text.setText("Sample text");
   assertEquals(0, text.getCaretPosition());
   text.setSelection(5);
   assertEquals(5, text.getCaretPosition());
   text.setSelection(3, 8);
   assertEquals(3, text.getCaretPosition());
   text.setSelection(8, 5);
   assertEquals(5, text.getCaretPosition());
   text.setText("New text");
   assertEquals(0, text.getCaretPosition());
   text.setSelection(3, 8);
   text.clearSelection();
   assertEquals(new Point(8, 8), text.getSelection());
   assertEquals(8, text.getCaretPosition());
 }
Пример #6
0
  // Separating out the call to append text to a widget so we can work on its
  // behavior.
  // We'd like this to not scroll if the cursor is not at the bottom of the
  // window
  // and SWT's append method always scrolls.
  private void appendTextToWidget(Text widget, String text) {
    // If set this to true we just use standard append
    // and always scroll.
    boolean kUseAppend = false;

    if (kUseAppend) {
      widget.append(text);
    } else {
      // A more sophisticated routine for inserting text
      // at the end of the widget without scrolling unless
      // current selection is already at the end.
      Point currentSelection = widget.getSelection();
      int length = widget.getCharCount();

      if (currentSelection.x == length) widget.append(text);
      else {
        // The calls to setRedraw are needed because there's a bug
        // on SWT in Windows where setSelection() calls scroll caret
        // always
        // which it really shouldn't. So we need to suppress that
        // behavior by
        // turning redraw on and off. However that incurs the cost of
        // redrawing the
        // entire widget in the setRedraw(true) call which shouldn't be
        // needed.
        // Because of this we only use this code if the selection isn't
        // at the end
        // of the widget.
        widget.setRedraw(false);
        widget.setSelection(length, length);
        widget.insert(text);
        widget.setSelection(currentSelection);
        widget.setRedraw(true);

        if (currentSelection.x == length) widget.showSelection();
      }
    }
  }
Пример #7
0
 public Point getSelection() {
   checkWidget();
   return text.getSelection();
 }
 public Point getSelection() {
   return fText.getSelection();
 }
Пример #9
0
  public boolean isScrolledToBottom() {
    Point currentSelection = m_Text.getSelection();
    int length = m_Text.getCharCount();

    return (currentSelection.x == length);
  }