コード例 #1
0
  @Test
  public void newlineIsTyped() throws Exception {
    model.setCaretLocation(TextLocation.origin);
    new CharTypedEvent(0, '\n').dispatch(panel);

    assertEquals("\nSome Text", model.getText());
  }
コード例 #2
0
  @Test
  public void backspaceIsNotTyped() throws Exception {
    model.setCaretLocation(TextLocation.origin);
    new CharTypedEvent(0, '\b').dispatch(panel);

    assertEquals("Some Text", model.getText());
  }
コード例 #3
0
ファイル: TextModel.java プロジェクト: JoshCheek/limelight
 public synchronized void insertChar(char c) {
   if (c == KeyEvent.CHAR_UNDEFINED) return;
   if (selectionActivated) deleteSelection();
   text.insert(getCaretLocation().toIndex(getLines()), c);
   clearCache();
   setCaretLocation(getCaretLocation().moved(getLines(), 1));
 }
コード例 #4
0
  @Test
  public void typingACharWillInsertIt() throws Exception {
    model.setCaretLocation(TextLocation.origin);

    new CharTypedEvent(0, 'Z').dispatch(panel);

    assertEquals("ZSome Text", model.getText());
  }
コード例 #5
0
  @Test
  public void typedCharsWithCommandModifierDoNothing() throws Exception {
    model.setCaretLocation(TextLocation.origin);

    new CharTypedEvent(KeyEvent.COMMAND_MASK, 'A').dispatch(panel);

    assertEquals("Some Text", model.getText());
  }
コード例 #6
0
 private void handleMultipleClicks(MousePressedEvent e) {
   if (e.getClickCount() == 2) {
     inWordSelectionMode = true;
     model.setSelectionLocation(model.findWordsLeftEdge(model.getCaretLocation()));
     model.setCaretLocation(model.findWordsRightEdge(model.getCaretLocation()));
   } else if (e.getClickCount() == 3) {
     model.selectAll();
   }
 }
コード例 #7
0
ファイル: TextModel.java プロジェクト: JoshCheek/limelight
  public synchronized void setText(String newText) {
    if (newText == null) newText = "";

    if (newText.length() == text.length() && newText.equals(getText())) return;

    text = new StringBuffer(newText);
    clearCache();
    setCaretLocation(getEndLocation());
  }
コード例 #8
0
  @Test
  public void typingACharMakesThePanelDirty() throws Exception {
    assertEquals(0, root.dirtyRegions.size());

    model.setCaretLocation(TextLocation.origin);
    new CharTypedEvent(0, 'Z').dispatch(panel);

    assertEquals(1, root.dirtyRegions.size());
    assertEquals(panel.getBounds(), root.dirtyRegions.get(0));
  }
コード例 #9
0
ファイル: TextModel.java プロジェクト: JoshCheek/limelight
 public void deleteEnclosedText(TextLocation start, TextLocation end) {
   ArrayList<TypedLayout> lines = getLines();
   int startIndex = start.toIndex(lines);
   int endIndex = end.toIndex(lines);
   synchronized (this) {
     text.delete(startIndex, endIndex);
     clearCache();
   }
   setCaretLocation(start);
   setSelectionLocation(start);
 }
コード例 #10
0
ファイル: TextModel.java プロジェクト: JoshCheek/limelight
 public void pasteClipboard() {
   String clipboard = getClipboardContents();
   if (clipboard != null && clipboard.length() > 0) {
     int caretIndex = caretLocation.toIndex(getLines());
     synchronized (this) {
       text.insert(caretIndex, clipboard);
       clearCache();
     }
     setCaretLocation(TextLocation.fromIndex(getLines(), caretIndex + clipboard.length()));
   }
 }
コード例 #11
0
ファイル: TextModel.java プロジェクト: JoshCheek/limelight
  public void moveCaretToNewLine(int lineDelta) {
    ArrayList<TypedLayout> lines = getLines();
    int newLineNumber = caretLocation.line + lineDelta;
    if (newLineNumber >= 0 && newLineNumber < lines.size()) {
      TextLocation origin = verticalOrigin != null ? verticalOrigin : caretLocation;
      int desiredX = lines.get(origin.line).getX(origin.index);

      TypedLayout newLine = lines.get(newLineNumber);
      int newIndex = newLine.getIndexAt(desiredX);

      TextLocation newLocation = TextLocation.at(newLineNumber, newIndex);
      setCaretLocation(newLocation);

      verticalOrigin = origin;
    }
  }
コード例 #12
0
  public void processMousePressed(MousePressedEvent e) {
    final Panel panel = e.getRecipient();
    inWordSelectionMode = false;

    TextLocation location = model.getLocationAt(e.getLocation());
    model.startSelection(location);
    model.setCaretLocation(location, XOffsetStrategy.FITTING, YOffsetStrategy.FITTING);
    model.setCaretOn(true);

    handleMultipleClicks(e);

    panel.markAsDirty();
    panel.getStage().getKeyListener().focusOn(panel);

    lastClickTime = System.currentTimeMillis();
  }
コード例 #13
0
  public void processMouseDragged(MouseDraggedEvent e) {
    Point mousePoint = e.getLocation();

    ArrayList<TypedLayout> lines = model.getLines();
    TextLocation tempLocation = model.getLocationAt(mousePoint);

    // TODO MDM - This needs work.  Ideally, the text will scroll smoothly, a pixel at a time,
    // without the mouse moving.  The scoll speed increased as the mouse moves away.
    if (mousePoint.x < 3 && tempLocation.index > 0) tempLocation = tempLocation.moved(lines, -1);
    else if (mousePoint.x > (model.getContainer().getWidth() - 3) && tempLocation.atEnd(lines))
      tempLocation = tempLocation.moved(lines, +1);

    if (inWordSelectionMode) selectWord(tempLocation);
    else model.setCaretLocation(tempLocation, XOffsetStrategy.FITTING, YOffsetStrategy.FITTING);

    e.getRecipient().markAsDirty();
  }
コード例 #14
0
ファイル: TextModel.java プロジェクト: JoshCheek/limelight
 public void sendCaretToEndOfLine() {
   final TextLocation caret = getCaretLocation();
   TypedLayout caretLine = getLines().get(caret.line);
   setCaretLocation(TextLocation.at(caret.line, caretLine.visibleLength()));
 }
コード例 #15
0
ファイル: TextModel.java プロジェクト: JoshCheek/limelight
 public void setCaretLocation(TextLocation location) {
   setCaretLocation(location, getDefaultXOffsetStrategy(), getDefaultYOffsetStrategy());
 }
コード例 #16
0
ファイル: TextModel.java プロジェクト: JoshCheek/limelight
 public void selectAll() {
   startSelection(TextLocation.origin);
   setCaretLocation(getEndLocation());
 }
コード例 #17
0
ファイル: TextModel.java プロジェクト: JoshCheek/limelight
 public void moveCaret(int places) {
   setCaretLocation(getCaretLocation().moved(getLines(), places));
 }
コード例 #18
0
ファイル: TextModel.java プロジェクト: JoshCheek/limelight
 public void sendCaretToStartOfLine() {
   setCaretLocation(TextLocation.at(getCaretLocation().line, 0));
 }