Beispiel #1
0
 public void savePosition(Runnable runnable) {
   Position pos = this.getDocument().createPosition(this.getCaretOffset());
   try {
     runnable.run();
   } finally {
     this.moveTo(pos.getOffset());
   }
 }
Beispiel #2
0
  public void doWork(boolean savePosition, Runnable runnable) {
    Position position = null;

    if (savePosition) {
      position = this.getDocument().createPosition(this.getCaretOffset());
    }

    boolean success = false;
    try {
      this.beginWork();
      runnable.run();
      success = true;
    } catch (Exception ex) {
      ex.printStackTrace();
    } finally {
      this.endWork(success);
      if (position != null) {
        this.moveTo(position.getOffset());
      }
    }
  }