Search in sources :

Example 1 with Revision

use of org.eclipse.jface.text.revisions.Revision in project eclipse.platform.text by eclipse.

the class RevisionPainter method getRequiredWidth.

/**
 * Returns the width in chars required to display information.
 *
 * @return the width in chars required to display information
 * @since 3.3
 */
public int getRequiredWidth() {
    if (fRequiredWidth == -1) {
        if (hasInformation() && (fShowRevision || fShowAuthor)) {
            int revisionWidth = 0;
            int authorWidth = 0;
            for (Revision revision : fRevisionInfo.getRevisions()) {
                revisionWidth = Math.max(revisionWidth, revision.getId().length());
                authorWidth = Math.max(authorWidth, revision.getAuthor().length());
            }
            fRevisionIdChars = revisionWidth + 1;
            if (fShowAuthor && fShowRevision)
                fRequiredWidth = revisionWidth + authorWidth + 2;
            else if (fShowAuthor)
                fRequiredWidth = authorWidth + 1;
            else
                fRequiredWidth = revisionWidth + 1;
        } else {
            fRequiredWidth = 0;
        }
    }
    return fRequiredWidth;
}
Also used : Revision(org.eclipse.jface.text.revisions.Revision) Point(org.eclipse.swt.graphics.Point)

Example 2 with Revision

use of org.eclipse.jface.text.revisions.Revision in project eclipse.platform.text by eclipse.

the class RevisionPainter method onFocusRangeChanged.

/**
 * Handles a changing focus range.
 *
 * @param previousRange the old focus range (<code>null</code> for no focus)
 * @param nextRange the new focus range (<code>null</code> for no focus)
 */
private void onFocusRangeChanged(RevisionRange previousRange, RevisionRange nextRange) {
    if (DEBUG)
        // $NON-NLS-1$ //$NON-NLS-2$
        System.out.println("range: " + previousRange + " > " + nextRange);
    fFocusRange = nextRange;
    Revision revision = nextRange == null ? null : nextRange.getRevision();
    updateFocusRevision(revision);
}
Also used : Revision(org.eclipse.jface.text.revisions.Revision)

Example 3 with Revision

use of org.eclipse.jface.text.revisions.Revision in project eclipse.platform.text by eclipse.

the class RevisionPainter method paintRange.

/**
 * Paints a single change region onto <code>gc</code>.
 *
 * @param range the range to paint
 * @param gc the {@link GC} to paint on
 */
private void paintRange(RevisionRange range, GC gc) {
    ILineRange widgetRange = modelLinesToWidgetLines(range);
    if (widgetRange == null)
        return;
    Revision revision = range.getRevision();
    boolean drawArmedFocus = range == fMouseHandler.fMouseDownRegion;
    boolean drawSelection = !drawArmedFocus && revision == fSelectedRevision;
    boolean drawFocus = !drawSelection && !drawArmedFocus && revision == fFocusRevision;
    Rectangle box = computeBoxBounds(widgetRange);
    gc.setBackground(lookupColor(revision, false));
    if (drawArmedFocus) {
        Color foreground = gc.getForeground();
        Color focusColor = lookupColor(revision, true);
        gc.setForeground(focusColor);
        gc.fillRectangle(box);
        // highlight box
        gc.drawRectangle(box.x, box.y, box.width - 1, box.height - 1);
        // inner highlight box
        gc.drawRectangle(box.x + 1, box.y + 1, box.width - 3, box.height - 3);
        gc.setForeground(foreground);
    } else if (drawFocus || drawSelection) {
        Color foreground = gc.getForeground();
        Color focusColor = lookupColor(revision, true);
        gc.setForeground(focusColor);
        gc.fillRectangle(box);
        // highlight box
        gc.drawRectangle(box.x, box.y, box.width - 1, box.height - 1);
        gc.setForeground(foreground);
    } else {
        gc.fillRectangle(box);
    }
    if ((fShowAuthor || fShowRevision)) {
        int indentation = 1;
        int baselineBias = getBaselineBias(gc, widgetRange.getStartLine());
        if (fShowAuthor && fShowRevision) {
            gc.drawString(revision.getId(), indentation, box.y + baselineBias, true);
            gc.drawString(revision.getAuthor(), fAuthorInset, box.y + baselineBias, true);
        } else if (fShowAuthor) {
            gc.drawString(revision.getAuthor(), indentation, box.y + baselineBias, true);
        } else if (fShowRevision) {
            gc.drawString(revision.getId(), indentation, box.y + baselineBias, true);
        }
    }
}
Also used : Revision(org.eclipse.jface.text.revisions.Revision) ILineRange(org.eclipse.jface.text.source.ILineRange) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point)

Example 4 with Revision

use of org.eclipse.jface.text.revisions.Revision in project eclipse.platform.text by eclipse.

the class RevisionPainter method handleRevisionSelected.

/**
 * Handles the selection of a revision id and informs listeners
 *
 * @param id the selected revision id
 */
void handleRevisionSelected(String id) {
    Assert.isLegal(id != null);
    if (fRevisionInfo == null)
        return;
    for (Revision revision : fRevisionInfo.getRevisions()) {
        if (id.equals(revision.getId())) {
            handleRevisionSelected(revision);
            return;
        }
    }
    // clear selection if it does not exist
    handleRevisionSelected((Revision) null);
}
Also used : Revision(org.eclipse.jface.text.revisions.Revision)

Example 5 with Revision

use of org.eclipse.jface.text.revisions.Revision in project eclipse.platform.text by eclipse.

the class RevisionPainter method updateOverviewAnnotations.

/**
 * Shows (or hides) the overview annotations.
 */
private void updateOverviewAnnotations() {
    if (fAnnotationModel == null)
        return;
    Revision revision = fFocusRevision != null ? fFocusRevision : fSelectedRevision;
    Map<Annotation, Position> added = null;
    if (revision != null) {
        added = new HashMap<>();
        for (RevisionRange range : revision.getRegions()) {
            try {
                IRegion charRegion = toCharRegion(range);
                Position position = new Position(charRegion.getOffset(), charRegion.getLength());
                Annotation annotation = new RevisionAnnotation(revision.getId());
                added.put(annotation, position);
            } catch (BadLocationException x) {
            // ignore - document was changed, show no annotations
            }
        }
    }
    if (fAnnotationModel instanceof IAnnotationModelExtension) {
        IAnnotationModelExtension ext = (IAnnotationModelExtension) fAnnotationModel;
        ext.replaceAnnotations(fAnnotations.toArray(new Annotation[fAnnotations.size()]), added);
    } else {
        for (Annotation annotation : fAnnotations) {
            fAnnotationModel.removeAnnotation(annotation);
        }
        if (added != null) {
            for (Entry<Annotation, Position> entry : added.entrySet()) {
                fAnnotationModel.addAnnotation(entry.getKey(), entry.getValue());
            }
        }
    }
    fAnnotations.clear();
    if (added != null)
        fAnnotations.addAll(added.keySet());
}
Also used : Revision(org.eclipse.jface.text.revisions.Revision) Position(org.eclipse.jface.text.Position) RevisionRange(org.eclipse.jface.text.revisions.RevisionRange) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) Annotation(org.eclipse.jface.text.source.Annotation) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

Revision (org.eclipse.jface.text.revisions.Revision)5 Point (org.eclipse.swt.graphics.Point)2 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IRegion (org.eclipse.jface.text.IRegion)1 Position (org.eclipse.jface.text.Position)1 RevisionRange (org.eclipse.jface.text.revisions.RevisionRange)1 Annotation (org.eclipse.jface.text.source.Annotation)1 IAnnotationModelExtension (org.eclipse.jface.text.source.IAnnotationModelExtension)1 ILineRange (org.eclipse.jface.text.source.ILineRange)1 Color (org.eclipse.swt.graphics.Color)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1