public void dragOver( DropTargetEvent e ) { styledText.setFocus(); Point location = xParent.getDisplay().map( null, styledText, e.x, e.y ); location.x = Math.max( 0, location.x ); location.y = Math.max( 0, location.y ); try { int offset = styledText.getOffsetAtLocation( new Point( location.x, location.y ) ); styledText.setCaretOffset( offset ); } catch ( IllegalArgumentException ex ) { int maxOffset = styledText.getCharCount(); Point maxLocation = styledText.getLocationAtOffset( maxOffset ); if ( location.y >= maxLocation.y ) { if ( location.x >= maxLocation.x ) { styledText.setCaretOffset( maxOffset ); } else { int offset = styledText.getOffsetAtLocation( new Point( location.x, maxLocation.y ) ); styledText.setCaretOffset( offset ); } } else { styledText.setCaretOffset( maxOffset ); } } }
int offset = text.getOffsetAtLocation( new Point( e.x, e.y ) ); StyleRange style = text.getStyleRangeAtOffset( offset ); if ( style != null && style.underline && style.underlineStyle == SWT.UNDERLINE_LINK ) {
private Optional<StyleRange> getSelectedStyleRange(final int x, final int y) { try { final int offset = styledText.getOffsetAtLocation(new Point(x, y)); final StyleRange style = styledText.getStyleRangeAtOffset(offset); return Optional.fromNullable(style); } catch (final IllegalArgumentException e) { return absent(); } }
@Override public void handleEvent(Event event) { if (links.size() == 0) { return; } try { int ofs = styled_text.getOffsetAtLocation(new Point(event.x, event.y)); for (int i = 0; i < links.size(); i++) { linkInfo linkInfo = (linkInfo)links.get(i); if (ofs >= linkInfo.ofsStart && ofs <= linkInfo.ofsEnd) { Utils.launch(linkInfo.url); break; } } } catch (Exception e) { } } });
public void mouseMove(MouseEvent event) { String toolTipText = ""; //$NON-NLS-1$ try { int offset = styledText.getOffsetAtLocation(new Point(event.x, event.y)); toolTipText = getFullURI(offset); } catch (Exception e) { // Do nothing. } styledText.setToolTipText(toolTipText); if ((toolTipText != null) && (toolTipText.length() > 0)) { fullFileNameField.setText(toolTipText); } } }
@Override public void mouseMove(MouseEvent e) { int offset = -1; try { Point p = new Point(e.x, e.y); offset = getTextWidget().getOffsetAtLocation(p); } catch (IllegalArgumentException ex) { // out of the document range } updateLinks(offset); }
public void mouseMove(MouseEvent e) { int offset = -1; try { Point p = new Point(e.x, e.y); offset = getTextWidget().getOffsetAtLocation(p); } catch (IllegalArgumentException ex) { // out of the document range } updateLinks(offset); }
private boolean isLocationSelected(Point point) { // FIXME: https://bugs.eclipse.org/bugs/show_bug.cgi?id=260922 if (isBlockSelectionModeEnabled()) return false; int offset= st.getOffsetAtLocation(point); Point p= st.getLocationAtOffset(offset); if (p.x > point.x) offset--; return offset >= fSelection.x && offset < fSelection.y; }
public int getOffset(StructuredTextEditor textEditor, Point location) { StyledText text = textEditor.getTextViewer().getTextWidget(); return text.getOffsetAtLocation(location); }
@Override public void handleEvent(Event event) { int offset = ftux_bottom.getOffsetAtLocation(new Point (event.x, event.y)); StyleRange style = ftux_bottom.getStyleRangeAtOffset(offset); if ( style != null ){ String url = (String)style.data; try{ Utils.launch( new URL( url )); }catch( Throwable e ){ Debug.out( e ); } } } });
@Override public void mouseDoubleClick(MouseEvent e) { StyledText widget = getTextWidget(); if (widget != null) { int offset = -1; try { Point p = new Point(e.x, e.y); offset = widget.getOffsetAtLocation(p); FileLink link = getFileLink(offset); if (link != null) { link.linkActivated(); } } catch (IllegalArgumentException ex) { } } }
public static void mouseDown(ActionContext actionContext){ Event event = (Event) actionContext.get("event"); StyledText consoleText = (StyledText) event.widget; if(event.button == 1){ Point p = new Point(event.x, event.y); try{ int offset = -1; StyleRange range = null; try{ offset = consoleText.getOffsetAtLocation(p); range = consoleText.getStyleRangeAtOffset(offset); }catch(Exception e){ } if(range != null && range.underline == true){ Thing thing = (Thing) range.data; if(thing != null){ XWorkerUtils.ideOpenThing(thing); } } }catch(Exception e){ e.printStackTrace(); } } } }
/** * Get style range at x/y coordinates * * @param x * @param y * @return style range, will be null when no style range exists at given * coordinates */ private StyleRange getStyleRange(final int x, final int y) { final StyledText t = getTextWidget(); final int offset; try { offset = t.getOffsetAtLocation(new Point(x, y)); } catch (IllegalArgumentException e) { return null; } if (offset < t.getCharCount()) return t.getStyleRangeAtOffset(offset); else return null; } }
@Override public void mouseMove(MouseEvent e) { if (mIsActive) { // try to get the position inside the text int offset; // Workaround: It is possible check that is text under the cursor ? try { offset = textWidget.getOffsetAtLocation(new Point(e.x, e.y)); } catch (IllegalArgumentException e2) { return; } Map<Integer, AnnotationFS> view = getView(getAnnotationMode()); mCandidate = view.get(offset); if (mCandidate != null) { textWidget.setSelectionRange(mCandidate.getBegin(), mCandidate.getEnd() - mCandidate.getBegin()); } } }
private int computeOffsetAtLocation(ITextViewer textViewer, int x, int y) { StyledText styledText= textViewer.getTextWidget(); IDocument document= textViewer.getDocument(); if (document == null) return -1; try { int widgetOffset= styledText.getOffsetAtLocation(new Point(x, y)); Point p= styledText.getLocationAtOffset(widgetOffset); if (p.x > x) widgetOffset--; if (textViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension= (ITextViewerExtension5) textViewer; return extension.widgetOffset2ModelOffset(widgetOffset); } IRegion visibleRegion= textViewer.getVisibleRegion(); return widgetOffset + visibleRegion.getOffset(); } catch (IllegalArgumentException e) { return -1; } } }
private int computeOffsetAtLocation(ITextViewer textViewer, int x, int y) { StyledText styledText= textViewer.getTextWidget(); IDocument document= textViewer.getDocument(); if (document == null) return -1; try { int widgetOffset= styledText.getOffsetAtLocation(new Point(x, y)); Point p= styledText.getLocationAtOffset(widgetOffset); if (p.x > x) widgetOffset--; if (textViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension= (ITextViewerExtension5) textViewer; return extension.widgetOffset2ModelOffset(widgetOffset); } IRegion visibleRegion= textViewer.getVisibleRegion(); return widgetOffset + visibleRegion.getOffset(); } catch (IllegalArgumentException e) { return -1; } } }
private int computeOffsetAtLocation(ITextViewer textViewer, int x, int y) { StyledText styledText= textViewer.getTextWidget(); IDocument document= textViewer.getDocument(); if (document == null) return -1; try { int widgetOffset= styledText.getOffsetAtLocation(new Point(x, y)); Point p= styledText.getLocationAtOffset(widgetOffset); if (p.x > x) widgetOffset--; if (textViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension= (ITextViewerExtension5) textViewer; return extension.widgetOffset2ModelOffset(widgetOffset); } IRegion visibleRegion= textViewer.getVisibleRegion(); return widgetOffset + visibleRegion.getOffset(); } catch (IllegalArgumentException e) { return -1; } } }
void updateErrorToolTip(StyledTextComp wText, int x, int y) { StyledText canvas = wText.getStyledText(); String errorText = (String) canvas.getData("lastErrorMessage"); // if there's no errors, bail out if (errorText == null) { canvas.setToolTipText(null); return; } // shield against SWT anomalies try { // if there are errors, see if the user hovers over the error line int line = canvas.getLineAtOffset(canvas.getOffsetAtLocation(new Point(1, y))); if (line == (Integer) canvas.getData("lastErrorLine")) { canvas.setToolTipText(errorText); return; } } catch (IllegalArgumentException ignored) { } // in case something went wrong or the line was not correct, no tooltip canvas.setToolTipText(null); }
/** * Returns the document relative offset from the text widget relative point * * @param document the document * @param textWidget the text widget * @param point the point for which to get the offset * @return the offset * @throws BadLocationException if the document is accessed with an invalid line */ private int getOffset(IDocument document, StyledText textWidget, Point point) throws BadLocationException { int widgetCaret= fViewer.getTextWidget().getCaretOffset(); if (fViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 ext= (ITextViewerExtension5) fViewer; try { return ext.widgetOffset2ModelOffset(textWidget.getOffsetAtLocation(point)); } catch (IllegalArgumentException e) { int docLineIndex= ext.widgetLine2ModelLine(textWidget.getLineIndex(point.y)); String lineDelimiter= document.getLineDelimiter(docLineIndex); int delimLength= lineDelimiter == null ? 0 : lineDelimiter.length(); return document.getLineOffset(docLineIndex) + document.getLineLength(docLineIndex) - delimLength; } } IRegion visible= fViewer.getVisibleRegion(); return widgetCaret + visible.getOffset(); } }
StyledText consoleText = (StyledText) event.widget; try{ int offset = consoleText.getOffsetAtLocation(p); StyleRange range = consoleText.getStyleRangeAtOffset(offset);