View Javadoc

1   /*
2    *  File: JaretStyledText.java 
3    *  Copyright (c) 2004-2007  Peter Kliem (Peter.Kliem@jaret.de)
4    *  A commercial license is available, see http://www.jaret.de.
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of the Common Public License v1.0
8    * which accompanies this distribution, and is available at
9    * http://www.eclipse.org/legal/cpl-v10.html
10   */
11  package org.eclipse.swt.custom;
12  
13  import org.eclipse.swt.SWT;
14  import org.eclipse.swt.widgets.Composite;
15  
16  /**
17   * Extension (HACK!) of the styled text widget to add a method for setting the caret offset without clearing the
18   * selection.
19   * 
20   * @author Peter Kliem
21   * @version $Id: JaretStyledText.java 242 2007-02-11 21:05:07Z olk $
22   */
23  public class JaretStyledText extends StyledText {
24  
25      public JaretStyledText(Composite arg0, int arg1) {
26          super(arg0, arg1);
27      }
28  
29      public void setCaretOffsetJaret(int offset) {
30          checkWidget();
31          int length = getCharCount();
32  
33          if (length > 0 && offset != caretOffset) {
34              if (offset < 0) {
35                  caretOffset = 0;
36              } else if (offset > length) {
37                  caretOffset = length;
38              } else {
39                  if (isLineDelimiter(offset)) {
40                      SWT.error(SWT.ERROR_INVALID_ARGUMENT);
41                  }
42                  caretOffset = offset;
43              }
44          }
45          setCaretLocation();
46      }
47  }