private void replaceText() { int start = text.getSelectionRange().x; text.replaceTextRange( start, text.getSelectionCount(), replaceText.getText() ); text.setSelection( start, start + replaceText.getText().length() ); } }
private void remove (int start, int end) { if ( start == end ) return; // Nothing to remove // Delete the text from the control edit.replaceTextRange(start, end-start, ""); }
@Override public void replaceText(AccessibleEditableTextEvent e) { StyledText st = StyledText.this; st.replaceTextRange(e.start, e.end - e.start, e.string); e.result = ACC.OK; } @Override
@Override public void replaceText(AccessibleEditableTextEvent e) { StyledText st = StyledText.this; st.replaceTextRange(e.start, e.end - e.start, e.string); e.result = ACC.OK; } @Override
@Override public void replaceText(AccessibleEditableTextEvent e) { StyledText st = StyledText.this; st.replaceTextRange(e.start, e.end - e.start, e.string); e.result = ACC.OK; } @Override
@Override public void replaceText(AccessibleEditableTextEvent e) { StyledText st = StyledText.this; st.replaceTextRange(e.start, e.end - e.start, e.string); e.result = ACC.OK; } @Override
public void replaceText(AccessibleEditableTextEvent e) { StyledText st = StyledText.this; st.replaceTextRange(e.start, e.end - e.start, e.string); e.result = ACC.OK; } public void pasteText(AccessibleEditableTextEvent e) {
public void undo() { try{ if (undoStack.size() > 0) { isUndo = true; RedoUndoEntity lastEdit = (RedoUndoEntity) undoStack.remove(0); int editLength = lastEdit.length; int startReplaceIndex = lastEdit.start; styledText.replaceTextRange(startReplaceIndex, editLength, lastEdit.replacedText); styledText.setCaretOffset(lastEdit.start); } }catch(Exception e){ e.printStackTrace(); } }
public void redo() { try{ if (redoStack.size() > 0) { isRedo = true; RedoUndoEntity lastEdit = (RedoUndoEntity) redoStack.remove(0); int editLength = lastEdit.length; int startReplaceIndex = lastEdit.start; styledText.replaceTextRange(startReplaceIndex, editLength, lastEdit.replacedText); styledText.setCaretOffset(lastEdit.start + lastEdit.replacedText.length()); } }catch(Exception e){ e.printStackTrace(); } }
private void placeText (String text) { Point pt = edit.getSelection(); edit.replaceTextRange(pt.x, pt.y-pt.x, text); edit.setCaretOffset(pt.x+text.length()); }
void replaceTextRange(TextChangingEvent event) { fTextChanging = true; int start = event.start; int length = event.replaceCharCount; String text = event.newText; if (event.newLineCount > 0 || event.replaceLineCount > 0) { Rectangle clientArea = fMinimapTextWidget.getClientArea(); fMinimapTextWidget.setRedraw(false); fMinimapTextWidget.replaceTextRange(start, length, text); fMinimapTextWidget.redraw(0, fTopIndexY, clientArea.width, clientArea.height, false); fMinimapTextWidget.setRedraw(true); } else { fMinimapTextWidget.replaceTextRange(start, length, text); } fTextChanging = false; }
/** * Appends a string to the text at the end of the widget. * * @param string the string to be appended * @see #replaceTextRange(int,int,String) * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ public void append(String string) { checkWidget(); if (string == null) { SWT.error(SWT.ERROR_NULL_ARGUMENT); } int lastChar = Math.max(getCharCount(), 0); replaceTextRange(lastChar, 0, string); } /**
/** * Appends a string to the text at the end of the widget. * * @param string the string to be appended * @see #replaceTextRange(int,int,String) * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ public void append(String string) { checkWidget(); if (string == null) { SWT.error(SWT.ERROR_NULL_ARGUMENT); } int lastChar = Math.max(getCharCount(), 0); replaceTextRange(lastChar, 0, string); } /**
/** * Appends a string to the text at the end of the widget. * * @param string the string to be appended * @see #replaceTextRange(int,int,String) * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ public void append(String string) { checkWidget(); if (string == null) { SWT.error(SWT.ERROR_NULL_ARGUMENT); } int lastChar = Math.max(getCharCount(), 0); replaceTextRange(lastChar, 0, string); } /**
/** * Appends a string to the text at the end of the widget. * * @param string the string to be appended * @see #replaceTextRange(int,int,String) * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ public void append(String string) { checkWidget(); if (string == null) { SWT.error(SWT.ERROR_NULL_ARGUMENT); } int lastChar = Math.max(getCharCount(), 0); replaceTextRange(lastChar, 0, string); } /**
private void setStatusAdapter(StatusAdapter adapter) { populateList(text, adapter.getStatus(), 0, new int[] { 0 }); if (!isMulti()) { Long timestamp = (Long) adapter .getProperty(IStatusAdapterConstants.TIMESTAMP_PROPERTY); if (timestamp != null) { String date = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG) .format(new Date(timestamp.longValue())); text.append(NLS.bind(ProgressMessages.JobInfo_Error, (new Object[] { "", date }))); //$NON-NLS-1$ } } int delimiterLength = getLineSeparator().length(); text.replaceTextRange(text.getText().length() - delimiterLength, delimiterLength, ""); //$NON-NLS-1$ adjustHeight(text); }
void addImage(Image image) { int offset = styledText.getCaretOffset(); styledText.replaceTextRange(offset, 0, "\uFFFC"); //$NON-NLS-1$ StyleRange style = new StyleRange(); Rectangle rect = image.getBounds(); style.metrics = new GlyphMetrics(rect.height, 0, rect.width); style.data = image; int[] ranges = {offset, 1}; StyleRange[] styles = {style}; styledText.setStyleRanges(0,0, ranges, styles); }
/** * Inserts a string. The old selection is replaced with the new text. * * @param string the string * @see #replaceTextRange(int,int,String) * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when string is null</li> * </ul> */ public void insert(String string) { checkWidget(); if (string == null) { SWT.error(SWT.ERROR_NULL_ARGUMENT); } if (blockSelection) { insertBlockSelectionText(string, false); } else { Point sel = getSelectionRange(); replaceTextRange(sel.x, sel.y, string); } } int insertBlockSelectionText(String text, boolean fillWithSpaces) {
@Override public void dragFinished(DragSourceEvent event) { try { if (event.detail == DND.DROP_MOVE && validateEditorInputState()) { Point newSelection= st.getSelection(); int length= fSelection.y - fSelection.x; int delta= 0; if (newSelection.x < fSelection.x) delta= length; st.replaceTextRange(fSelection.x + delta, length, ""); //$NON-NLS-1$ if (fTextDragAndDropToken == null) { // Move in same editor - end compound change IRewriteTarget target= getAdapter(IRewriteTarget.class); if (target != null) target.endCompoundChange(); } } } finally { fTextDragAndDropToken= null; } } });
void addControl(Control control) { int offset = styledText.getCaretOffset(); styledText.replaceTextRange(offset, 0, "\uFFFC"); //$NON-NLS-1$ StyleRange style = new StyleRange(); Point size = control.computeSize(SWT.DEFAULT, SWT.DEFAULT); int ascent = 2 * size.y / 3; int descent = size.y - ascent; style.metrics = new GlyphMetrics(ascent + MARGIN, descent + MARGIN, size.x + 2 * MARGIN); style.data = control; int[] ranges = {offset, 1}; StyleRange[] styles = {style}; styledText.setStyleRanges(0,0, ranges, styles); control.setSize(size); }