1 11 package org.eclipse.jface.fieldassist; 12 13 import org.eclipse.swt.graphics.Point; 14 import org.eclipse.swt.graphics.Rectangle; 15 import org.eclipse.swt.widgets.Control; 16 import org.eclipse.swt.widgets.Text; 17 18 25 public class TextContentAdapter implements IControlContentAdapter { 26 27 32 public String getControlContents(Control control) { 33 return ((Text) control).getText(); 34 } 35 36 42 public void setControlContents(Control control, String text, 43 int cursorPosition) { 44 ((Text) control).setText(text); 45 ((Text) control).setSelection(cursorPosition, cursorPosition); 46 } 47 48 54 public void insertControlContents(Control control, String text, 55 int cursorPosition) { 56 Point selection = ((Text) control).getSelection(); 57 ((Text) control).insert(text); 58 if (cursorPosition < text.length()) { 61 ((Text) control).setSelection(selection.x + cursorPosition, 62 selection.x + cursorPosition); 63 } 64 } 65 66 71 public int getCursorPosition(Control control) { 72 return ((Text) control).getCaretPosition(); 73 } 74 75 80 public Rectangle getInsertionBounds(Control control) { 81 Text text = (Text) control; 82 Point caretOrigin = text.getCaretLocation(); 83 return new Rectangle(caretOrigin.x, caretOrigin.y, 1, text 84 .getLineHeight()); 85 } 86 87 93 public void setCursorPosition(Control control, int position) { 94 ((Text) control).setSelection(new Point(position, position)); 95 } 96 } 97 | Popular Tags |