Java Code Examples for org.eclipse.swt.custom.StyledText#getText()

The following examples show how to use org.eclipse.swt.custom.StyledText#getText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractHighlightingTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void testHighlighting(StyledText styledText, String text, int fontStyle, int foregroundR, int foregroundG, int foregroundB,
		int backgroundR, int backgroundG, int backgroundB) {
	Color expectedForegroundColor = new Color(null, foregroundR, foregroundG, foregroundB);
	Color expectedBackgroundColor = new Color(null, backgroundR, backgroundG, backgroundB);

	String content = styledText.getText();
	int offset = getStartPosition(content, text);
	assertNotEquals("Cannot locate '" + text + "' in " + content, -1, offset);

	for (int i = 0; i < text.length(); i++) {
		int currentPosition = offset + i;
		String character = styledText.getTextRange(currentPosition, 1);
		StyleRange styleRange = styledText.getStyleRangeAtOffset(currentPosition);
		if (isRelevant(character)) {
			assertFontStyle(styleRange, character, fontStyle);
			assertForegroundColor(styleRange, character, expectedForegroundColor);
			assertBackgroundColor(styleRange, character, expectedBackgroundColor);
		}
	}
}
 
Example 2
Source File: AbstractDialogKeyVerifyJavaNames.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Java name space names verify key checks for java identifier and periods.
 *
 * @param event the event
 * @return true, if successful
 */
@Override
public boolean verifyKeyChecks(VerifyEvent event) {
  if (event.keyCode == SWT.CR || event.keyCode == SWT.TAB)
    return true;
  if (Character.isJavaIdentifierPart(event.character))
    return true;
  StyledText w = (StyledText) event.widget;
  String text = w.getText();
  int len = text.length();
  if (event.character == '.') {
    if (len == 0)
      return false;
    return true;
  }
  return false;
}
 
Example 3
Source File: HsMultiCellEditorControl.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 当一个文本段初次获取焦点时,实时进行拼写检查,<div style='color:red'>该方法与{@link tgtTextRealTimeSpellCheck} 类似</div>
 */
private static void tgtTextFirstRealTimeSpellCheck(final String tgtLang, HsMultiCellEditor targetEditor){
	final StyledTextCellEditor tgtEditor = targetEditor.getCellEditor();
	final StyledText text = tgtEditor.getSegmentViewer().getTextWidget();
	if (tgtLang == null) {
		return;
	}
	String tgtText = text.getText();
	if (tgtText == null || "".equals(tgtText.trim())) {
		return;
	}
	List<SingleWord> errorWordList = new LinkedList<SingleWord>();
	errorWordList = spellTrigger.getErrorWords(tgtText, tgtLang);
	if (errorWordList != null && errorWordList.size() > 0) {
		targetEditor.highLightedErrorWord(tgtText, errorWordList);
	}else {
		targetEditor.refreshErrorWordsStyle(null);
	}
}
 
Example 4
Source File: HsMultiCellEditor.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public void highlightedTerms(List<String> terms) {
	if (!isValid()) {
		return;
	}
	StyledText styledText = cellEditor.viewer.getTextWidget();
	String text = styledText.getText();
	char[] source = text.toCharArray();
	List<StyleRange> ranges = new ArrayList<StyleRange>();
	TextStyle style = new TextStyle(cellEditor.getSegmentViewer().getTextWidget().getFont(), null,
			ColorConfigBean.getInstance().getHighlightedTermColor());
	for (String term : terms) {
		ranges.addAll(calculateTermsStyleRange(source, term.toCharArray(), style));
	}
	for (StyleRange range : ranges) {
		styledText.setStyleRange(range);
	}
}
 
Example 5
Source File: HsMultiCellEditorControl.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 当一个文本段初次获取焦点时,实时进行拼写检查,<div style='color:red'>该方法与{@link tgtTextRealTimeSpellCheck} 类似</div>
 */
private static void tgtTextFirstRealTimeSpellCheck(final String tgtLang, HsMultiCellEditor targetEditor) {
	final StyledTextCellEditor tgtEditor = targetEditor.getCellEditor();
	final StyledText text = tgtEditor.getSegmentViewer().getTextWidget();
	if (tgtLang == null) {
		return;
	}
	String tgtText = text.getText();
	if (tgtText == null || "".equals(tgtText.trim())) {
		return;
	}
	List<SingleWord> errorWordList = new LinkedList<SingleWord>();
	errorWordList = spellTrigger.getErrorWords(tgtText, tgtLang);
	if (errorWordList != null && errorWordList.size() > 0) {
		targetEditor.highLightedErrorWord(tgtText, errorWordList);
	} else {
		targetEditor.refreshErrorWordsStyle(null);
	}
}
 
Example 6
Source File: HsMultiCellEditor.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public void highlightedTerms(List<String> terms) {
	if (!isValid()) {
		return;
	}
	StyledText styledText = cellEditor.viewer.getTextWidget();
	String text = styledText.getText();
	char[] source = text.toCharArray();
	List<StyleRange> ranges = new ArrayList<StyleRange>();
	TextStyle style = new TextStyle(cellEditor.getSegmentViewer().getTextWidget().getFont(), null,
			ColorConfigBean.getInstance().getHighlightedTermColor());
	for (String term : terms) {
		if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
			term = term.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n");
			term = term.replaceAll("\\t", Constants.TAB_CHARACTER + "\u200B");
			term = term.replaceAll(" ", Constants.SPACE_CHARACTER + "\u200B");
		}
		ranges.addAll(calculateTermsStyleRange(source, term.toCharArray(), style));
	}
	for (StyleRange range : ranges) {
		styledText.setStyleRange(range);
	}
}
 
Example 7
Source File: XLIFFEditorActionHandler.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public void runWithEvent(Event event) {
	if (viewer != null && !viewer.getTextWidget().isDisposed()) {
		StyledTextCellEditor editor = HsMultiActiveCellEditor.getFocusCellEditor();
		boolean isSrc = false;
		if (editor != null && editor.getCellType().equals(NatTableConstant.SOURCE)) {
			isSrc = true;
		}
		StyledText styledText = viewer.getTextWidget();
		String text = styledText.getText();
		String selectionText = styledText.getSelectionText();
		// 当选择源文时,要判断是否是删除所有源文
		if (isSrc) {
			if (selectionText != null && text != null && text.equals(selectionText)) {
				MessageDialog.openInformation(viewer.getTextWidget().getShell(),
						Messages.getString("editor.XLIFFEditorActionHandler.msgTitle"),
						Messages.getString("editor.XLIFFEditorActionHandler.msg"));
				return;
			}
		}
		viewer.doOperation(ITextOperationTarget.DELETE);
		updateActionsEnableState();
		return;
	}
	if (deleteAction != null) {
		deleteAction.runWithEvent(event);
		return;
	}
}
 
Example 8
Source File: ContentAssistant.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param cp
 * @param styledText
 * @param c
 * @param keyCode
 * @return
 */
private boolean isAutoActivationLocation(ICommonContentAssistProcessor cp, StyledText styledText, char c,
		int keyCode)
{

	int offset = styledText.getCaretOffset();
	Point selection = styledText.getSelection();
	if (offset >= selection.x && offset <= selection.y)
	{
		offset = selection.x;
	}

	// Are we at beginning of file?
	if (offset == 0)
	{
		return true;
	}

	String line = styledText.getText(offset - 1, offset - 1);

	if (line.length() > 0)
	{
		return cp.isValidActivationCharacter(line.charAt(0), keyCode)
				|| cp.isValidAutoActivationLocation(c, keyCode, fContentAssistSubjectControlAdapter.getDocument(),
						offset);
	}
	else
	{
		return false;
	}
}
 
Example 9
Source File: GamlEditorDragAndDropHandler.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param sb
 * @param file
 * @return
 */
private int addDropImport(final StringBuilder sb, final IFile file) {
	final String name = obtainRelativePath(file);
	sb.append(Strings.LN).append("import ").append('"').append(name).append('"').append(Strings.LN);
	final StyledText st = getStyledText();
	final String text = st.getText();
	final int startOfGlobal = text.indexOf("global");
	final int startOfModel = text.indexOf("\nmodel");
	if (startOfGlobal == -1 && startOfModel == -1) { return -1; }
	final int endOfModel = text.indexOf("\n", startOfModel + 1);
	return endOfModel + 1;
}
 
Example 10
Source File: SpringConfigurationStyledText.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
private void addUndoList(ExtendedModifyEvent event) {
	if(fromUndoRedo ){
		return;
	}
	StyledText st = (StyledText) event.widget;
	String currText = st.getText();
	String newText = currText.substring(event.start, event.start
			+ event.length);
	if (undoStack.size() == MAX_STACK_SIZE) {
		undoStack.remove(undoStack.size() - 1);
	}
	undoStack.add(0, new UndoRedoModel(newText, event.start, event.length,
			event.replacedText));

}
 
Example 11
Source File: ExecuteQueryAction.java    From mat-calcite-plugin with Apache License 2.0 5 votes vote down vote up
private String getSelectedQuery() {
	StyledText queryString = pane.getQueryString();
	String query = queryString.getSelectionText();

	if ("".equals(query)) //$NON-NLS-1$
	{
		query = queryString.getText();
	}

	// Temporary workaround for https://issues.apache.org/jira/browse/CALCITE-459
	query = query + queryString.getLineDelimiter();

	return query;
}
 
Example 12
Source File: XLIFFEditorActionHandler.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void runWithEvent(Event event) {
	if (viewer != null && !viewer.getTextWidget().isDisposed()) {
		StyledTextCellEditor editor = HsMultiActiveCellEditor.getFocusCellEditor();
		boolean isSrc = false;
		if (editor != null && editor.getCellType().equals(NatTableConstant.SOURCE)) {
			isSrc = true;
		}
		StyledText styledText = viewer.getTextWidget();
		String text = styledText.getText();
		String selectionText = styledText.getSelectionText();
		// 当选择源文时,要判断是否是删除所有源文
		if (isSrc) {
			if (selectionText != null && text != null && text.equals(selectionText)) {
				MessageDialog.openInformation(viewer.getTextWidget().getShell(),
						Messages.getString("editor.XLIFFEditorActionHandler.msgTitle"),
						Messages.getString("editor.XLIFFEditorActionHandler.msg"));
				return;
			}
		}
		viewer.doOperation(ITextOperationTarget.DELETE);
		updateActionsEnableState();
		return;
	}
	if (deleteAction != null) {
		deleteAction.runWithEvent(event);
		return;
	}
}
 
Example 13
Source File: GamlEditorDragAndDropHandler.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private String addGlobalIfNecessary(final String fileDeclarations) {
	if (fileDeclarations.contains("import \"")) { return fileDeclarations; }
	final StyledText st = getStyledText();
	final String text = st.getText();
	final int startOfGlobal = text.indexOf("global");
	if (startOfGlobal == -1) { return "global {" + Strings.LN + fileDeclarations + Strings.LN + "}"; }
	return fileDeclarations;
}
 
Example 14
Source File: SearchMinibuffer.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Allow single character operations on an existing search string
 * 
 * @param event
 * @param search - true if we should search after operation
 * @return true if event handled
 */
protected boolean dispatchAltCtrl(VerifyEvent event, boolean search) {
	// allows editing of history/yanked search string
	boolean result = false;
	switch (event.keyCode) {
	case CM_DEL:
		// remove the last character and search
		super.backSpaceChar(event);
		getRX().bsChar();
		if (search) {
			findNext(getSearchString(),true);
		}
		updateStatusLine(getMBString());
		result = true;
		break;
	case CM_ADD:
		StyledText w = getTextWidget(); 
		int catPos = w.getCaretOffset() + (isForward() ? 0 : getMBLength());
		String text = w.getText(catPos, catPos);
		if (w.getLineDelimiter().contains(text)) {
			text = w.getLineDelimiter();
		}
		addIt(text);
		if (search) {
			findNext(getSearchString(),true);
		}
		updateStatusLine(getMBString());
		result = true;
		break;
	}
	if (!result && hasBinding(event)) {
		// exit search and execute the command
		ITextEditor ed = getEditor();					
		leave();
		executeBinding(ed,event);
		result = true;
	}
	return result;
}
 
Example 15
Source File: ParamView.java    From http4e with Apache License 2.0 5 votes vote down vote up
String getParamText(){
   StyledText st = (StyledText) textView.getControl();
   if (CoreMessages.PARAM_DEFAULTS.equals(st.getText())) {
      return CoreConstants.EMPTY_TEXT;
   }
   String txt = st.getText();
   
   return txt;
}
 
Example 16
Source File: UndoRedo.java    From Rel with Apache License 2.0 4 votes vote down vote up
public Capture(StyledText text) {
	this.content = text.getText();
	this.caretOffset = text.getCaretOffset();
	this.topIndex = text.getTopIndex();
}
 
Example 17
Source File: UnTranslatedPropertyTester.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
	boolean enabled = false;
	IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	if (window != null) {
		IWorkbenchPage page = window.getActivePage();
		if (page != null) {
			IEditorPart editor = page.getActiveEditor();
			if (editor != null && editor instanceof XLIFFEditorImplWithNatTable) {
				XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
				if (xliffEditor != null && xliffEditor.getTable() != null) {
					enabled = true;
					XLFHandler handler = xliffEditor.getXLFHandler();
					List<String> selectedRowIds = xliffEditor.getSelectedRowIds();
					if (selectedRowIds != null && selectedRowIds.size() > 0) {
						boolean isLock = true;
						for (String rowId : selectedRowIds) {
							if (!handler.isEmptyTranslation(rowId)) {
								enabled = false;
								break;
							}
							if (!handler.isLocked(rowId)) {
								isLock = false;
							}
						}
						enabled = enabled && !isLock;
						if (!enabled) {
							StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor();
							if (cellEditor != null && !cellEditor.isApprovedOrLocked()) {
								StyledText styledText = cellEditor.getSegmentViewer().getTextWidget();
								if (styledText != null) {
									String text = styledText.getText();
									if (text != null && !text.equals("")) {
										enabled = true;
									}
								}
							}

						}
					}
				}
			}
		}
	}
	return enabled;
}
 
Example 18
Source File: TLCUIHelper.java    From tlaplus with MIT License 3 votes vote down vote up
/**
   * Installs hyperlinks for locations reported by TLC on the {@link StyledText}.
   * This handles both creating the appearance of the hyperlink and storing
   * the module location that should be shown when the link is opened.
   * 
   * When this method is used to create the links, {@link TLCUIHelper#openTLCLocationHyperlink(StyledText, Event, ILaunchConfiguration)}
   * should be used to open the link.
   * 
   * @param styledText
   */
  public static void setTLCLocationHyperlinks(final StyledText styledText)
  {
      final String text = styledText.getText();
      final List<StyleRange> list = setTLCLocationHyperlinks(text);
      for (StyleRange styleRange : list) {
	styledText.setStyleRange(styleRange);
}
  }