/** * Returns whether the given annotation type should be skipped by the drawing routine of the header. * * @param annotationType the annotation type * @return <code>true</code> if annotation of the given type should be skipped * @since 3.0 */ private boolean skipInHeader(Object annotationType) { return !contains(annotationType, fAllowedHeaderAnnotationTypes, fConfiguredHeaderAnnotationTypes); }
@Override public int toDocumentLineNumber(int y_coordinate) { if (fTextViewer == null || y_coordinate == -1) return -1; int[] lineNumbers= toLineNumbers(y_coordinate, true); if (lineNumbers[0] == -1) lineNumbers= toLineNumbers(y_coordinate, false); int bestLine= findBestMatchingLineNumber(lineNumbers); if (bestLine == -1 && lineNumbers.length > 0) return lineNumbers[0]; return bestLine; }
/** * Handles mouse moves. * * @param event the mouse move event */ private void handleMouseMove(MouseEvent event) { if (fTextViewer != null) { int[] lines= toLineNumbers(event.y, true); Position p= getAnnotationPosition(lines); Cursor cursor= (p != null ? fHitDetectionCursor : null); if (cursor != fLastCursor) { fCanvas.setCursor(cursor); fLastCursor= cursor; } } }
Object annotationType= iterator.next(); if (skip(annotationType)) continue; int startLine= textWidget.getLineAtOffset(startOffset); yy= computeY(startLine, infos); int yy2= computeY(startLine + numberOfLines - 1, infos); hh= Math.max(yy2 - yy, ANNOTATION_HEIGHT); } else { stroke= getStrokeColor(annotationType, style[t] == FilterIterator.TEMPORARY); fill= fUseSaturatedColors ? stroke : getFillColor(annotationType, style[t] == FilterIterator.TEMPORARY); areColorsComputed= true;
/** * Returns a color based on the color configured for the given annotation type and the given scale factor. * * @param annotationType the annotation type * @param scale the scale factor * @return the computed color */ private Color getColor(Object annotationType, double scale) { Color base= findColor(annotationType); if (base == null) return null; RGB baseRGB= base.getRGB(); RGB background= fCanvas.getBackground().getRGB(); boolean darkBase= isDark(baseRGB); boolean darkBackground= isDark(background); if (darkBase && darkBackground) background= new RGB(255, 255, 255); else if (!darkBase && !darkBackground) background= new RGB(0, 0, 0); return fSharedTextColors.getColor(interpolate(baseRGB, background, scale)); }
/** * Handles mouse clicks. * * @param event the mouse button down event */ private void handleMouseDown(MouseEvent event) { if (fTextViewer != null) { int[] lines= toLineNumbers(event.y, true); if (lines[0] == -1) lines= toLineNumbers(event.y, false); Position p= getAnnotationPosition(lines); if (p == null && event.button == 1) { try { p= new Position(fTextViewer.getDocument().getLineInformation(lines[0]).getOffset(), 0); } catch (BadLocationException e) { // do nothing } } if (p != null) { fTextViewer.revealRange(p.getOffset(), p.getLength()); fTextViewer.setSelectedRange(p.getOffset(), p.getLength()); } fTextViewer.getTextWidget().setFocus(); } fLastMouseButtonActivityLine= toDocumentLineNumber(event.y); }
outer: for (int i= fAnnotationsSortedByLayer.size() -1; i >= 0; i--) { Object annotationType= fAnnotationsSortedByLayer.get(i); if (skipInHeader(annotationType) || skip(annotationType)) continue; color= findColor(colorType);
doubleBufferPaint(event.gc); }); handleDispose(); fTextViewer= null; }); fCanvas.addMouseMoveListener(event -> handleMouseMove(event)); fCanvas.addMouseWheelListener(e -> handleMouseScrolled(e));
/** * Double buffer drawing. * * @param dest the GC to draw into */ private void doubleBufferPaint(GC dest) { Point size= fCanvas.getSize(); if (size.x <= 0 || size.y <= 0) return; if (fBuffer != null) { Rectangle r= fBuffer.getBounds(); if (r.width != size.x || r.height != size.y) { fBuffer.dispose(); fBuffer= null; } } if (fBuffer == null) fBuffer= new Image(fCanvas.getDisplay(), size.x, size.y); GC gc= new GC(fBuffer); try { gc.setBackground(fCanvas.getBackground()); gc.fillRectangle(0, 0, size.x, size.y); cacheAnnotations(); doPaint(gc); } finally { gc.dispose(); } dest.drawImage(fBuffer, 0, 0); }
/** * Returns the stroke color for the given annotation type and characteristics. * * @param annotationType the annotation type * @param temporary <code>true</code> if for temporary annotations * @return the stroke color */ private Color getStrokeColor(Object annotationType, boolean temporary) { return getColor(annotationType, temporary && fIsTemporaryAnnotationDiscolored ? 0.5 : 0.2); }
protected IOverviewRuler createOverviewRuler(ISharedTextColors sharedColors) { IOverviewRuler ruler= new OverviewRuler(getAnnotationAccess(), VERTICAL_RULER_WIDTH, sharedColors); Iterator e= fAnnotationPreferences.getAnnotationPreferences().iterator(); while (e.hasNext()) { AnnotationPreference preference= (AnnotationPreference) e.next(); if (preference.contributesToHeader()) ruler.addHeaderAnnotationType(preference.getAnnotationType()); } return ruler; }
/** * Redraws the overview ruler. */ private void redraw() { if (fTextViewer == null || fModel == null) return; if (fCanvas != null && !fCanvas.isDisposed()) { if (VerticalRuler.AVOID_NEW_GC) { fCanvas.redraw(); } else { GC gc= new GC(fCanvas); doubleBufferPaint(gc); gc.dispose(); } } }
/** * Returns the line which corresponds best to one of * the underlying annotations at the given y-coordinate. * * @param lineNumbers the line numbers * @return the best matching line or <code>-1</code> if no such line can be found */ private int findBestMatchingLineNumber(int[] lineNumbers) { if (lineNumbers == null || lineNumbers.length < 1) return -1; try { Position pos= getAnnotationPosition(lineNumbers); if (pos == null) return -1; return fTextViewer.getDocument().getLineOfOffset(pos.getOffset()); } catch (BadLocationException ex) { return -1; } }
int y0= computeY(lines[0], infos); if (y_coordinate < y0 || y0 + ANNOTATION_HEIGHT < y_coordinate) { lines[0]= -1;
if (skip(annotationType)) continue; int startLine= textWidget.getLineAtOffset(startOffset); yy= computeY(startLine, infos); int yy2= computeY(startLine + numberOfLines - 1, infos); hh= Math.max(yy2 - yy, ANNOTATION_HEIGHT); } else { stroke= getStrokeColor(annotationType, element == FilterIterator.TEMPORARY); fill= fUseSaturatedColors ? stroke : getFillColor(annotationType, element == FilterIterator.TEMPORARY); areColorsComputed= true;
/** * Returns a color based on the color configured for the given annotation type and the given scale factor. * * @param annotationType the annotation type * @param scale the scale factor * @return the computed color */ private Color getColor(Object annotationType, double scale) { Color base= findColor(annotationType); if (base == null) return null; RGB baseRGB= base.getRGB(); RGB background= fCanvas.getBackground().getRGB(); boolean darkBase= isDark(baseRGB); boolean darkBackground= isDark(background); if (darkBase && darkBackground) background= new RGB(255, 255, 255); else if (!darkBase && !darkBackground) background= new RGB(0, 0, 0); return fSharedTextColors.getColor(interpolate(baseRGB, background, scale)); }
/** * Handles mouse clicks. * * @param event the mouse button down event */ private void handleMouseDown(MouseEvent event) { if (fTextViewer != null) { int[] lines= toLineNumbers(event.y, true); if (lines[0] == -1) lines= toLineNumbers(event.y, false); Position p= getAnnotationPosition(lines); if (p == null && event.button == 1) { try { p= new Position(fTextViewer.getDocument().getLineInformation(lines[0]).getOffset(), 0); } catch (BadLocationException e) { // do nothing } } if (p != null) { fTextViewer.revealRange(p.getOffset(), p.getLength()); fTextViewer.setSelectedRange(p.getOffset(), p.getLength()); } fTextViewer.getTextWidget().setFocus(); } fLastMouseButtonActivityLine= toDocumentLineNumber(event.y); }
outer: for (int i= fAnnotationsSortedByLayer.size() -1; i >= 0; i--) { Object annotationType= fAnnotationsSortedByLayer.get(i); if (skipInHeader(annotationType) || skip(annotationType)) continue; color= findColor(colorType);
/** * Double buffer drawing. * * @param dest the GC to draw into */ private void doubleBufferPaint(GC dest) { Point size= fCanvas.getSize(); if (size.x <= 0 || size.y <= 0) return; if (fBuffer != null) { Rectangle r= fBuffer.getBounds(); if (r.width != size.x || r.height != size.y) { fBuffer.dispose(); fBuffer= null; } } if (fBuffer == null) fBuffer= new Image(fCanvas.getDisplay(), size.x, size.y); GC gc= new GC(fBuffer); try { gc.setBackground(fCanvas.getBackground()); gc.fillRectangle(0, 0, size.x, size.y); cacheAnnotations(); doPaint(gc); } finally { gc.dispose(); } dest.drawImage(fBuffer, 0, 0); }
/** * Returns the fill color for the given annotation type and characteristics. * * @param annotationType the annotation type * @param temporary <code>true</code> if for temporary annotations * @return the fill color */ private Color getFillColor(Object annotationType, boolean temporary) { return getColor(annotationType, temporary && fIsTemporaryAnnotationDiscolored ? 0.9 : 0.75); }