Java Code Examples for org.eclipse.swt.custom.StyledText#addListener()
The following examples show how to use
org.eclipse.swt.custom.StyledText#addListener() .
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: DocumentManager.java From ContentAssist with MIT License | 6 votes |
/** * Registers a document manager with an editor. * @param doc the document to be managed * @param st the styled text of the editor * @param dm the document manager */ public static void register(IDocument doc, StyledText st, DocumentManager dm) { if (doc != null) { doc.addDocumentListener(dm); DocumentUndoManagerRegistry.connect(doc); IDocumentUndoManager undoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(doc); if (undoManager != null) { undoManager.addDocumentUndoListener(dm); } } if (st != null) { st.addListener(SWT.KeyDown, dm); st.addListener(SWT.MouseDown, dm); st.addListener(SWT.MouseDoubleClick, dm); } }
Example 2
Source File: IRCStyleChatDisplay.java From saros with GNU General Public License v2.0 | 6 votes |
private void addHyperLinkListener(final StyledText text) { text.addListener( SWT.MouseDown, new Listener() { @Override public void handleEvent(Event event) { try { int offset = text.getOffsetAtLocation(new Point(event.x, event.y)); StyleRange style = text.getStyleRangeAtOffset(offset); if (style != null && style.underline && style.underlineStyle == SWT.UNDERLINE_LINK) { String url = (String) style.data; SWTUtils.openInternalBrowser(url, url); } } catch (IllegalArgumentException e) { // no character under event.x, event.y } } }); }
Example 3
Source File: ChatLine.java From saros with GNU General Public License v2.0 | 6 votes |
private void addHyperLinkListener(final StyledText text) { text.addListener( SWT.MouseDown, new Listener() { @Override public void handleEvent(Event event) { try { int offset = text.getOffsetAtLocation(new Point(event.x, event.y)); StyleRange style = text.getStyleRangeAtOffset(offset); if (style != null && style.underline && style.underlineStyle == SWT.UNDERLINE_LINK) { String url = (String) style.data; SWTUtils.openInternalBrowser(url, url); } } catch (IllegalArgumentException e) { // no character under event.x, event.y } } }); }
Example 4
Source File: StyledTextActionHandler.java From statecharts with Eclipse Public License 1.0 | 5 votes |
/** * 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: OperatorWithControlPanel.java From Rel with Apache License 2.0 | 5 votes |
@Override protected Control obtainControlPanel(Visualiser parent) { Composite controlPanel = new Composite(parent, SWT.NONE); controlPanel.setLayout(new FillLayout()); operatorLabel = new StyledText(controlPanel, SWT.MULTI); operatorLabel.setEditable(false); operatorLabel.setBackground(BackgroundColor); if (!getModel().getRev().isReadOnly()) operatorLabel.addListener(SWT.MouseUp, e -> { if (operatorLabel.getBounds().contains(e.x, e.y)) openDetails(); }); return controlPanel; }
Example 6
Source File: AbstractDialogKeyVerify.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * New single line styled text. * * @param parent the parent * @param tip the tip * @return the styled text */ protected StyledText newSingleLineStyledText(Composite parent, String tip) { StyledText w = new StyledText(parent, SWT.SINGLE | SWT.BORDER); w.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); w.setToolTipText(tip); w.addListener(SWT.KeyUp, this); w.addVerifyKeyListener(this); w.addListener(SWT.MouseUp, this); // for paste operation return w; }
Example 7
Source File: TextAreaSwtParameter.java From BiglyBT with GNU General Public License v2.0 | 4 votes |
public TextAreaSwtParameter( Composite composite, UITextAreaImpl _ui_text_area) { super( null ); setPluginParameter(_ui_text_area); ui_text_area = _ui_text_area; text_area = new StyledText(composite,SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); setMainControl(text_area); if (doGridData(composite)) { GridData gd = new GridData(); gd.horizontalSpan = 2; Integer hhint = (Integer)ui_text_area.getProperty( UIComponent.PT_HEIGHT_HINT ); if ( hhint != null ){ gd.heightHint = hhint; } else { gd.heightHint = 150; } gd.widthHint = 10; gd.verticalAlignment = SWT.FILL; gd.grabExcessVerticalSpace = true; gd.grabExcessHorizontalSpace = true; gd.horizontalAlignment = SWT.FILL; text_area.setLayoutData(gd); } ClipboardCopy.addCopyToClipMenu(text_area, () -> text_area.getText().trim()); text_area.addListener(SWT.KeyDown, event -> { int key = event.character; if (key <= 26 && key > 0) { key += 'a' - 1; } if (key == 'a' && event.stateMask == SWT.MOD1) { event.doit = false; text_area.selectAll(); } }); text_area.setText("" + ui_text_area.getText()); ui_text_area.addPropertyChangeListener(this); }
Example 8
Source File: XdsConsoleViewer.java From xds-ide with Eclipse Public License 1.0 | 4 votes |
public XdsConsoleViewer(Composite parent, TextConsole console) { super(parent, console); StyledText styledText = getTextWidget(); styledText.setDoubleClickEnabled(false); styledText.addListener(SWT.MouseDoubleClick, mouseDoubleClickListener); }
Example 9
Source File: ProblemView.java From tlaplus with MIT License | 4 votes |
/** * Fill data * @param specLoaded */ private void fillData(Spec specLoaded) { if (specLoaded == null) { hide(); return; } else { // retrieve the markers associated with the loaded spec IMarker[] markers = TLAMarkerHelper.getProblemMarkers(specLoaded.getProject(), null); if (markers == null || markers.length == 0) { hide(); } // sort the markers List<IMarker> markersList = new ArrayList<IMarker>(Arrays.asList(markers)); Collections.sort(markersList, new MarkerComparator()); // Bug fix: 2 June 2010. It takes forever if // there are a large number of markers, which // can easily happen if you remove a definition // that's used hundreds of times. int iterations = Math.min(markers.length, 20); for (int j = 0; j < iterations; j++) { final IMarker problem = markersList.get(j); // listener Listener listener = new Listener() { // goto marker on click public void handleEvent(Event event) { TLAMarkerHelper.gotoMarker(problem, ((event.stateMask & SWT.MOD1) != 0)); } }; // contents of the item Composite problemItem = new Composite(bar, SWT.LINE_SOLID); problemItem.setLayout(new RowLayout(SWT.VERTICAL)); problemItem.addListener(SWT.MouseDown, listener); String[] lines = problem.getAttribute(IMarker.MESSAGE, "").split("\n"); for (int i = 0; i < lines.length; i++) { StyledText styledText = new StyledText(problemItem, SWT.INHERIT_DEFAULT); styledText.setEditable(false); styledText.setCursor(styledText.getDisplay().getSystemCursor(SWT.CURSOR_HAND)); styledText.setText(lines[i]); styledText.addListener(SWT.MouseDown, listener); if (isErrorLine(lines[i], problem)) { StyleRange range = new StyleRange(); range.underline = true; range.foreground = styledText.getDisplay().getSystemColor(SWT.COLOR_RED); range.start = 0; range.length = lines[i].length(); styledText.setStyleRange(range); } } ExpandItem item = new ExpandItem(bar, SWT.NONE, 0); item.setExpanded(true); String markerType = TLAMarkerHelper.getType(problem); item.setText(AdapterFactory.getMarkerTypeAsText(markerType) + " " + AdapterFactory.getSeverityAsText(problem.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR))); item.setHeight(problemItem.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item.setControl(problemItem); item.addListener(SWT.MouseDown, listener); } } return ; }
Example 10
Source File: TmfRawEventViewer.java From tracecompass with Eclipse Public License 2.0 | 4 votes |
/** * 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(); } }); }
Example 11
Source File: StyledTextXtextAdapter.java From statecharts with Eclipse Public License 1.0 | 4 votes |
public void adapt(StyledText styledText, boolean decorate) { this.styledText = styledText; // perform initialization of fake resource context updateFakeResourceContext(); // connect Xtext document to fake resource initXtextDocument(getFakeResourceContext()); // connect xtext document to xtext source viewer this.sourceviewer = createXtextSourceViewer(); this.decorationSupport = createSourceViewerDecorationSupport(); configureSourceViewerDecorationSupport(getDecorationSupport()); // install semantic highlighting support installHighlightingHelper(); this.validationJob = createValidationJob(); getXtextDocument().setValidationJob(getValidationJob()); styledText.setData(StyledTextXtextAdapter.class.getCanonicalName(), this); final IContentAssistant contentAssistant = getXtextSourceviewer().getContentAssistant(); final CompletionProposalAdapter completionProposalAdapter = new CompletionProposalAdapter(styledText, contentAssistant, KeyStroke.getInstance(SWT.CTRL, SWT.SPACE), null); if ((styledText.getStyle() & SWT.SINGLE) != 0) { // The regular key down event is too late (after popup is closed). // when using the StyledText.VerifyKey event (3005), we get the // event early enough! styledText.addListener(3005, new Listener() { @Override public void handleEvent(Event event) { if (event.character == SWT.CR && !completionProposalAdapter.isProposalPopupOpen()) { Event selectionEvent = new Event(); selectionEvent.type = SWT.DefaultSelection; selectionEvent.widget = event.widget; for (Listener l : event.widget.getListeners(SWT.DefaultSelection)) { l.handleEvent(selectionEvent); } } } }); } // Register focus tracker for evaluating the active focus control in // core expression IFocusService service = (IFocusService) PlatformUI.getWorkbench().getService(IFocusService.class); service.addFocusTracker(styledText, StyledText.class.getCanonicalName()); if (decorate) { // add JDT Style code completion hint decoration this.decoration = createContentAssistDecoration(styledText); } initSelectionProvider(); }
Example 12
Source File: SearchQuick.java From Rel with Apache License 2.0 | 4 votes |
public SearchQuick(FilterSorter filterSorter, Composite contentPanel) { super(contentPanel, SWT.NONE); this.filterSorter = filterSorter; GridLayout layout = new GridLayout(2, false); layout.horizontalSpacing = 0; layout.verticalSpacing = 0; layout.marginWidth = 0; layout.marginHeight = 0; setLayout(layout); findText = new StyledText(this, SWT.BORDER | SWT.SINGLE); findText.addListener(SWT.Traverse, event -> { if (event.detail == SWT.TRAVERSE_RETURN) { fireUpdate(); } }); findText.addListener(SWT.Modify, event -> { if (findText.getText().trim().length() > 0) { findText.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_RED)); findText.setBackground(SWTResourceManager.getColor(255, 225, 225)); } }); findText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); ToolBar toolBar = new ToolBar(this, SWT.NONE); ToolItem wholeWord = new ToolItem(toolBar, SWT.PUSH); wholeWord.addListener(SWT.Selection, e -> { wholeWordSearch = !wholeWordSearch; wholeWord.setText(wholeWordSearch ? "Whole word" : "Any match"); layout(); fireUpdateIfSearch(); }); wholeWord.setText("Any match"); ToolItem caseSensitive = new ToolItem(toolBar, SWT.PUSH); caseSensitive.addListener(SWT.Selection, e -> { caseSensitiveSearch = !caseSensitiveSearch; caseSensitive.setText(caseSensitiveSearch ? "Case sensitive" : "Case insensitive"); layout(); fireUpdateIfSearch(); }); caseSensitive.setText("Case insensitive"); ToolItem regex = new ToolItem(toolBar, SWT.CHECK); regex.addListener(SWT.Selection, e -> { regexSearch = regex.getSelection(); wholeWord.setEnabled(!regexSearch); caseSensitive.setEnabled(!regexSearch); fireUpdateIfSearch(); }); regex.setText("Regex"); ToolItem clear = new ToolItem(toolBar, SWT.PUSH); clear.addListener(SWT.Selection, e -> { if (findText.getText().trim().length() == 0) return; findText.setText(""); fireUpdate(); }); clear.setText("Clear"); toolBar.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); }