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

The following examples show how to use org.eclipse.swt.custom.StyledText#addKeyListener() . 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: SpecialCharacters.java    From Rel with Apache License 2.0 6 votes vote down vote up
/**
 * Create the dialog.
 * 
 * @param parent
 * @param style
 */
public SpecialCharacters(Shell parent, StyledText inputText) {
	super(parent, SWT.NONE);
	this.inputText = inputText;
	inputText.addKeyListener(new KeyAdapter() {
		@Override
		public void keyReleased(KeyEvent e) {
			// System.out.println("character = '" + e.character + "' keycode = '" +
			// (char)e.keyCode + "' " + (((e.stateMask & SWT.CTRL) != 0) ? "CTRL" : "") + "
			// " + (((e.stateMask & SWT.SHIFT) != 0) ? "SHIFT" : ""));
			for (SpecialCharacter specialCharacter : specialCharacters) {
				if (specialCharacter.matches(e)) {
					emit(specialCharacter.symbol);
					break;
				}
			}
		}
	});
}
 
Example 2
Source File: RenameRefactoringPopup.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void start() {
	editor.getSite().getWorkbenchWindow().getPartService().addPartListener(this);
	final ISourceViewer viewer = editor.getInternalSourceViewer();
	final StyledText textWidget = viewer.getTextWidget();
	textWidget.addControlListener(this);
	textWidget.addMouseListener(this);
	textWidget.addKeyListener(this);
	editor.getSite().getShell().addControlListener(this);
	viewer.addViewportListener(this);
	popup.addDisposeListener(new DisposeListener() {
		@Override
		public void widgetDisposed(DisposeEvent e) {
			editor.getSite().getWorkbenchWindow().getPartService()
					.removePartListener(PopupVisibilityManager.this);
			if (!textWidget.isDisposed()) {
				textWidget.removeControlListener(PopupVisibilityManager.this);
				textWidget.removeMouseListener(PopupVisibilityManager.this);
				textWidget.removeKeyListener(PopupVisibilityManager.this);
			}
			editor.getSite().getShell().removeControlListener(PopupVisibilityManager.this);
			viewer.removeViewportListener(PopupVisibilityManager.this);
			if (menuImage != null) {
				menuImage.dispose();
				menuImage = null;
			}
			if (menuManager != null) {
				menuManager.dispose();
				menuManager = null;
			}
		}
	});
}
 
Example 3
Source File: RenameInformationPopup.java    From typescript.java with MIT License 5 votes vote down vote up
public void start() {
			fEditor.getSite().getWorkbenchWindow().getPartService().addPartListener(this);
			final ISourceViewer viewer= fEditor.getViewer();
			final StyledText textWidget= viewer.getTextWidget();
			textWidget.addControlListener(this);
			textWidget.addMouseListener(this);
			textWidget.addKeyListener(this);
			fEditor.getSite().getShell().addControlListener(this);
			viewer.addTextListener(this);
			viewer.addViewportListener(this);
			fPopup.addDisposeListener(new DisposeListener() {
				@Override
				public void widgetDisposed(DisposeEvent e) {
					fEditor.getSite().getWorkbenchWindow().getPartService().removePartListener(PopupVisibilityManager.this);
					if (! textWidget.isDisposed()) {
						textWidget.removeControlListener(PopupVisibilityManager.this);
						textWidget.removeMouseListener(PopupVisibilityManager.this);
						textWidget.removeKeyListener(PopupVisibilityManager.this);
					}
					fEditor.getSite().getShell().removeControlListener(PopupVisibilityManager.this);
					viewer.removeTextListener(PopupVisibilityManager.this);
					viewer.removeViewportListener(PopupVisibilityManager.this);
//					if (fMenuImage != null) {
//						fMenuImage.dispose();
//						fMenuImage= null;
//					}
					if (fMenuManager != null) {
						fMenuManager.dispose();
						fMenuManager= null;
					}
					fRenameLinkedMode.cancel();
				}
			});
		}
 
Example 4
Source File: StyledTextActionHandler.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Adapts a <code>StyledText</code> widget to the handler so that the Copy, Cut,
 * Paste and Select All actions are redirected to it when focused.
 *
 * @param textWidget
 *            the <code>StyledText</code> widget
 */
public void adaptStyledText(StyledText textWidget) {
	if (textWidget == null)
		return;

	styledText = textWidget;
	textWidget.addListener(SWT.Activate, textControlListener);
	textWidget.addListener(SWT.Deactivate, textControlListener);

	textWidget.addKeyListener(keyAdapter);
	textWidget.addMouseListener(mouseAdapter);
}
 
Example 5
Source File: RenameInformationPopup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void start() {
	fEditor.getSite().getWorkbenchWindow().getPartService().addPartListener(this);
	final ISourceViewer viewer= fEditor.getViewer();
	final StyledText textWidget= viewer.getTextWidget();
	textWidget.addControlListener(this);
	textWidget.addMouseListener(this);
	textWidget.addKeyListener(this);
	fEditor.getSite().getShell().addControlListener(this);
	viewer.addTextListener(this);
	viewer.addViewportListener(this);
	fPopup.addDisposeListener(new DisposeListener() {
		public void widgetDisposed(DisposeEvent e) {
			fEditor.getSite().getWorkbenchWindow().getPartService().removePartListener(PopupVisibilityManager.this);
			if (! textWidget.isDisposed()) {
				textWidget.removeControlListener(PopupVisibilityManager.this);
				textWidget.removeMouseListener(PopupVisibilityManager.this);
				textWidget.removeKeyListener(PopupVisibilityManager.this);
			}
			fEditor.getSite().getShell().removeControlListener(PopupVisibilityManager.this);
			viewer.removeTextListener(PopupVisibilityManager.this);
			viewer.removeViewportListener(PopupVisibilityManager.this);
			if (fMenuImage != null) {
				fMenuImage.dispose();
				fMenuImage= null;
			}
			if (fMenuManager != null) {
				fMenuManager.dispose();
				fMenuManager= null;
			}
			fRenameLinkedMode.cancel();
		}
	});
}
 
Example 6
Source File: TypingRunDetector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Adds the selection listener to the text widget underlying the viewer, if
 * not already done.
 */
private void ensureSelectionListenerAdded() {
	if (fSelectionListener == null) {
		fSelectionListener= new SelectionListener();
		StyledText textWidget= fViewer.getTextWidget();
		textWidget.addFocusListener(fSelectionListener);
		textWidget.addKeyListener(fSelectionListener);
		textWidget.addMouseListener(fSelectionListener);
	}
}
 
Example 7
Source File: StyledTextCellEditor.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
protected Control activateCell(final Composite parent, HsMultiCellEditor hsCellEditor) {
	this.hsCellEditor = hsCellEditor;
	StyledText text = createTextControl(parent);
	text.setBounds(hsCellEditor.getEditorBounds());
	// analyzeCellType(); // 分析单元格类型。
	this.cellType = hsCellEditor.getType();
	if (cellType == NatTableConstant.TARGET) {
		this.source = HsMultiActiveCellEditor.getSourceEditor().getOriginalCanonicalValue().toString();
		viewer.setSource(source); // 设置原文本,用来解析内部标记
	}

	editableManager.judgeEditable(); // 判断“可编辑”状态;

	// If we have an initial value, then
	Object originalCanonicalValue = this.hsCellEditor.getOriginalCanonicalValue();
	if (originalCanonicalValue != null) {
		setCanonicalValue(new UpdateDataBean(originalCanonicalValue.toString(), null, null));
	} else {
		setCanonicalValue(new UpdateDataBean());
	}

	// 改变关闭状态标识
	close = false;
	xliffEditor.getTable().addDisposeListener(this);

	// text.forceFocus();

	// 初始化撤销/重做管理器,设置步长为 50。
	viewer.initUndoManager(50);
	// 绑定全局 Edit 菜单
	actionHandler.addTextViewer(viewer);
	text.addKeyListener(movedKeyListener);

	// 移除向上和向下键默认事件处理,将此部分实现放到upAndDownKeyListener监听中
	text.setKeyBinding(SWT.ARROW_DOWN, SWT.NULL);
	text.setKeyBinding(SWT.ARROW_UP, SWT.NULL);
	addMouselistener(text);
	return text;
}
 
Example 8
Source File: StyledTextCellEditor.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
protected Control activateCell(final Composite parent, HsMultiCellEditor hsCellEditor) {
	this.hsCellEditor = hsCellEditor;
	StyledText text = createTextControl(parent);
	text.setBounds(hsCellEditor.getEditorBounds());
	// analyzeCellType(); // 分析单元格类型。
	this.cellType = hsCellEditor.getType();
	if (cellType == NatTableConstant.TARGET) {
		this.source = HsMultiActiveCellEditor.getSourceEditor().getOriginalCanonicalValue().toString();
		viewer.setSource(source); // 设置原文本,用来解析内部标记
	}

	editableManager.judgeEditable(); // 判断“可编辑”状态;

	// If we have an initial value, then
	Object originalCanonicalValue = this.hsCellEditor.getOriginalCanonicalValue();
	if (originalCanonicalValue != null) {
		setCanonicalValue(new UpdateDataBean(originalCanonicalValue.toString(), null, null));
	} else {
		setCanonicalValue(new UpdateDataBean());
	}

	// 改变关闭状态标识
	close = false;
	xliffEditor.getTable().addDisposeListener(this);

	text.forceFocus();

	// 初始化撤销/重做管理器,设置步长为 50。
	viewer.initUndoManager(50);
	// 绑定全局 Edit 菜单
	actionHandler.addTextViewer(viewer);
	text.addKeyListener(movedKeyListener);

	// 移除向上和向下键默认事件处理,将此部分实现放到upAndDownKeyListener监听中
	text.setKeyBinding(SWT.ARROW_DOWN, SWT.NULL);
	text.setKeyBinding(SWT.ARROW_UP, SWT.NULL);
	return text;
}
 
Example 9
Source File: EditorListener.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Connects all selection listeners to the given {@linkplain IEditorPart editor part}. If an
 * editor part was already bound it will be unbound and replaced with the given editor part.
 *
 * @see #unbind()
 * @param part the editor part to observe
 * @return <code>true</code> if the selection listeners were successfully installed, <code>false
 *     </code> if the selection listeners could not be installed
 */
public boolean bind(final IEditorPart part) {

  if (this.part != null) unbind();

  final ITextViewer viewer = EditorAPI.getViewer(part);

  if (viewer == null) {
    log.warn(
        "could not attach selection listeners to editor part:"
            + part
            + " , could not retrieve text widget");
    return false;
  }

  this.part = part;
  this.viewer = viewer;

  final StyledText textWidget = viewer.getTextWidget();

  textWidget.addControlListener(controlListener);
  textWidget.addMouseListener(mouseListener);
  textWidget.addKeyListener(keyListener);

  viewer.addTextListener(textListener);
  viewer.getSelectionProvider().addSelectionChangedListener(selectionChangedListener);
  viewer.addViewportListener(viewportListener);

  return true;
}
 
Example 10
Source File: TmfRawEventViewer.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Create the text area and add listeners
 */
private void createTextArea(int style) {
    fScrolledComposite = new ScrolledComposite(this, style);
    fScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    fTextArea = new Composite(fScrolledComposite, SWT.NONE);
    fTextArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    fScrolledComposite.setContent(fTextArea);
    fScrolledComposite.setExpandHorizontal(true);
    fScrolledComposite.setExpandVertical(true);
    fScrolledComposite.setAlwaysShowScrollBars(true);
    fScrolledComposite.setMinSize(fTextArea.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    fScrolledComposite.addControlListener(this);

    GridLayout textAreaGridLayout = new GridLayout();
    textAreaGridLayout.marginHeight = 0;
    textAreaGridLayout.marginWidth = 0;
    fTextArea.setLayout(textAreaGridLayout);

    fStyledText = new StyledText(fTextArea, SWT.READ_ONLY);
    fStyledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    initializeFonts();
    initializeColors();
    PlatformUI.getWorkbench().getThemeManager().addPropertyChangeListener(this);

    fStyledText.addCaretListener(this);
    fStyledText.addMouseMoveListener(this);
    fStyledText.addMouseTrackListener(this);
    fStyledText.addMouseWheelListener(this);
    /* disable mouse scroll of horizontal scroll bar */
    fStyledText.addListener(SWT.MouseWheel, event -> event.doit = false);
    fStyledText.addKeyListener(this);

    fTextArea.setBackground(fStyledText.getBackground());
    fTextArea.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDown(MouseEvent e) {
            fTextArea.setFocus();
        }
    });
}