Permalink
Browse files

Added test annotation

  • Loading branch information...
1 parent c8ca543 commit 8eef627efbd2e012acc9d20ea04f59bac183ff29 @danlucraft danlucraft committed May 20, 2010
View
BIN lib/org.eclipse.core.jobs_3.4.100.v20090429-1800.jar
Binary file not shown.
View
BIN lib/org.eclipse.core.resources_3.5.1.R35x_v20090826-0451.jar
Binary file not shown.
View
BIN lib/org.eclipse.core.runtime.compatibility_3.2.0.v20090413.jar
Binary file not shown.
View
BIN lib/org.eclipse.core.runtime_3.5.0.v20090525.jar
Binary file not shown.
View
61 projection_attempt.diff
@@ -0,0 +1,61 @@
+diff --git a/src/com/redcareditor/mate/MateText.java b/src/com/redcareditor/mate/MateText.java
+index 209fec9..7159d85 100644
+--- a/src/com/redcareditor/mate/MateText.java
++++ b/src/com/redcareditor/mate/MateText.java
+@@ -11,6 +11,9 @@ import org.eclipse.jface.text.Document;
+ import org.eclipse.jface.text.IDocument;
+ import org.eclipse.jface.text.source.CompositeRuler;
+ import org.eclipse.jface.text.source.SourceViewer;
++import org.eclipse.jface.text.source.OverviewRuler;
++import org.eclipse.jface.text.source.projection.ProjectionViewer;
++import org.eclipse.jface.text.projection.*;
+ import org.eclipse.swt.SWT;
+ import org.eclipse.swt.custom.StyledText;
+ import org.eclipse.swt.graphics.Color;
+@@ -28,6 +31,7 @@ import com.redcareditor.mate.document.swt.SwtMateDocument;
+ import com.redcareditor.mate.undo.MateTextUndoManager;
+ import com.redcareditor.mate.undo.swt.SwtMateTextUndoManager;
+ import com.redcareditor.mate.WhitespaceCharacterPainter;
++import com.redcareditor.mate.SharedTextColors;
+ import com.redcareditor.mate.LineNumberRulerColumn;
+ import com.redcareditor.onig.NullRx;
+ import com.redcareditor.onig.Rx;
+@@ -55,6 +59,8 @@ public class MateText {
+ private CompositeRuler gutter;
+ private LineNumberRulerColumn lineNumbers;
+ private SwtMateDocument mateDocument;
++ private OverviewRuler overviewRuler;
++ private SharedTextColors sharedColors;
+
+ private MateTextUndoManager undoManager;
+ private List<IGrammarListener> grammarListeners;
+@@ -69,16 +75,23 @@ public class MateText {
+
+ public MateText(Composite parent, boolean thisSingleLine) {
+ singleLine = thisSingleLine;
+- document = new Document();
+- gutter = constructRuler();
++ document = new Document();
+ if (singleLine) {
+ viewer = new SourceViewer(parent, null, SWT.FULL_SELECTION | SWT.HORIZONTAL | SWT.VERTICAL | SWT.SINGLE);
++ viewer.setDocument(document);
+ }
+ else {
+- viewer = new SourceViewer(parent, gutter, SWT.FULL_SELECTION | SWT.HORIZONTAL | SWT.VERTICAL);
+- }
+- viewer.setDocument(document);
+-
++ sharedColors = new SharedTextColors();
++ overviewRuler = new OverviewRuler(null, 20, sharedColors);
++ gutter = constructRuler();
++ viewer = new ProjectionViewer(parent, gutter, overviewRuler, true, SWT.FULL_SELECTION | SWT.HORIZONTAL | SWT.VERTICAL);
++ viewer.doOperation(ProjectionViewer.TOGGLE);
++
++ ProjectionDocumentManager manager = new ProjectionDocumentManager();
++ ProjectionDocument projectionDocument = (ProjectionDocument) manager.createSlaveDocument(document);
++ viewer.setDocument(projectionDocument);
++ }
++
+ whitespaceCharacterPainter = new WhitespaceCharacterPainter(viewer);
+ showingInvisibles = false;
+
View
301 src/com/redcareditor/mate/MateText.java
@@ -1,23 +1,28 @@
package com.redcareditor.mate;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import java.util.logging.Logger;
import java.util.logging.Handler;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
-import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.source.CompositeRuler;
-import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.jface.text.*;
+import org.eclipse.jface.text.source.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
-import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.jface.text.presentation.IPresentationReconciler;
+import org.eclipse.jface.text.presentation.PresentationReconciler;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.*;
+import org.eclipse.core.runtime.jobs.*;
import com.redcareditor.mate.colouring.Colourer;
import com.redcareditor.mate.colouring.swt.SwtColourer;
@@ -52,7 +57,9 @@ static public Handler consoleHandler() {
/* components plugged together */
public SourceViewer viewer;
private IDocument document;
- private CompositeRuler gutter;
+ private CompositeRuler compositeRuler;
+ private OverviewRuler overviewRuler;
+ private AnnotationRulerColumn annotationRuler;
private LineNumberRulerColumn lineNumbers;
private SwtMateDocument mateDocument;
@@ -62,22 +69,27 @@ static public Handler consoleHandler() {
private boolean singleLine;
private WhitespaceCharacterPainter whitespaceCharacterPainter;
private boolean showingInvisibles;
-
+
+ public static String ERROR_TYPE = "error.type";
+ public static Image ERROR_IMAGE;
+ public static final RGB ERROR_RGB = new RGB(255, 0, 0);
+
+ // annotation model
+ private AnnotationModel fAnnotationModel = new AnnotationModel();
+ private IAnnotationAccess fAnnotationAccess;
+ private ColorCache cc;
+
public MateText(Composite parent) {
this(parent, false);
}
public MateText(Composite parent, boolean thisSingleLine) {
singleLine = thisSingleLine;
document = new Document();
- gutter = constructRuler();
- if (singleLine) {
- viewer = new SourceViewer(parent, null, SWT.FULL_SELECTION | SWT.HORIZONTAL | SWT.VERTICAL | SWT.SINGLE);
- }
- else {
- viewer = new SourceViewer(parent, gutter, SWT.FULL_SELECTION | SWT.HORIZONTAL | SWT.VERTICAL);
- }
- viewer.setDocument(document);
+ if (singleLine)
+ createSingleLineSourceViewer(parent);
+ else
+ createSourceViewer(parent);
whitespaceCharacterPainter = new WhitespaceCharacterPainter(viewer);
showingInvisibles = false;
@@ -94,10 +106,70 @@ public MateText(Composite parent, boolean thisSingleLine) {
}
logger.addHandler(MateText.consoleHandler());
logger.info("Created MateText");
- }
+ }
+
+ private void createSingleLineSourceViewer(Composite parent) {
+ viewer = new SourceViewer(parent, null, SWT.FULL_SELECTION | SWT.HORIZONTAL | SWT.VERTICAL | SWT.SINGLE);
+ viewer.setDocument(document);
+ }
+
+ private void createSourceViewer(Composite parent) {
+ ERROR_IMAGE = new Image(Display.getDefault(), "/Users/danlucraft/Desktop/little-star.png");
+
+ fAnnotationAccess = new AnnotationMarkerAccess();
+
+ cc = new ColorCache();
+
+ compositeRuler = new CompositeRuler();
+ overviewRuler = new OverviewRuler(fAnnotationAccess, 12, cc);
+ annotationRuler = new AnnotationRulerColumn(fAnnotationModel, 16, fAnnotationAccess);
+ compositeRuler.setModel(fAnnotationModel);
+ overviewRuler.setModel(fAnnotationModel);
+
+ // add what types are show on the different rulers
+ annotationRuler.addAnnotationType(ERROR_TYPE);
+ overviewRuler.addAnnotationType(ERROR_TYPE);
+ overviewRuler.addHeaderAnnotationType(ERROR_TYPE);
+ // set what layer this type is on
+ overviewRuler.setAnnotationTypeLayer(ERROR_TYPE, 3);
+ // set what color is used on the overview ruler for the type
+ overviewRuler.setAnnotationTypeColor(ERROR_TYPE, new Color(Display.getDefault(), ERROR_RGB));
+
+ lineNumbers = new LineNumberRulerColumn();
+ compositeRuler.addDecorator(0, lineNumbers);
+ compositeRuler.addDecorator(0, annotationRuler);
+
+ viewer = new SourceViewer(parent, compositeRuler, SWT.FULL_SELECTION | SWT.HORIZONTAL | SWT.VERTICAL);
+ viewer.setDocument(document, fAnnotationModel);
+
+ // hover manager that shows text when we hover
+ AnnotationHover ah = new AnnotationHover();
+ AnnotationConfiguration ac = new AnnotationConfiguration();
+ AnnotationBarHoverManager fAnnotationHoverManager = new AnnotationBarHoverManager(compositeRuler, viewer, ah, ac);
+ fAnnotationHoverManager.install(annotationRuler.getControl());
+
+ // to paint the annotations
+ AnnotationPainter ap = new AnnotationPainter(viewer, fAnnotationAccess);
+ ap.addAnnotationType(ERROR_TYPE);
+ ap.setAnnotationTypeColor(ERROR_TYPE, new Color(Display.getDefault(), ERROR_RGB));
+
+ // this will draw the squigglies under the text
+ viewer.addPainter(ap);
+
+ viewer.configure(new CodeViewerConfiguration(cc));
+
+ // some misspelled text
+ document.set("Here's some texst so that we have somewhere to show an error");
+
+ // add an annotation
+ ErrorAnnotation errorAnnotation = new ErrorAnnotation(1, "Learn how to spell \"text!\"");
+
+ // lets underline the word "texst"
+ fAnnotationModel.addAnnotation(errorAnnotation, new Position(12, 5));
+ }
public boolean isSingleLine() {
- return singleLine;
+ return singleLine;
}
public void showInvisibles(boolean should) {
@@ -113,27 +185,20 @@ public void showInvisibles(boolean should) {
public boolean isShowingInvisibles() {
return showingInvisibles;
}
-
- private CompositeRuler constructRuler() {
- CompositeRuler ruler = new CompositeRuler(0);
- lineNumbers = new LineNumberRulerColumn();
- ruler.addDecorator(0, lineNumbers);
- return ruler;
- }
public void attachUpdater() {
}
-
- public boolean getWordWrap() {
- return getTextWidget().getWordWrap();
- }
- public void setWordWrap(boolean val) {
- getTextWidget().setWordWrap(val);
- }
+ public boolean getWordWrap() {
+ return getTextWidget().getWordWrap();
+ }
+
+ public void setWordWrap(boolean val) {
+ getTextWidget().setWordWrap(val);
+ }
- public String grammarName() {
+ public String grammarName() {
return parser.grammar.name;
}
@@ -274,4 +339,172 @@ public void redraw() {
// SwtMateTextLocation endLocation = new SwtMateTextLocation(0 + getTextWidget().getCharCount(), getMateDocument());
getTextWidget().redraw();
}
+
+ class AnnotationConfiguration implements IInformationControlCreator {
+ public IInformationControl createInformationControl(Shell shell) {
+ return new DefaultInformationControl(shell);
+ }
+ }
+
+ class ColorCache implements ISharedTextColors {
+ public Color getColor(RGB rgb) {
+ return new Color(Display.getDefault(), rgb);
+ }
+
+ public void dispose() {
+ }
+ }
+
+ // santa's little helper
+ class AnnotationMarkerAccess implements IAnnotationAccess, IAnnotationAccessExtension {
+ public Object getType(Annotation annotation) {
+ return annotation.getType();
+ }
+
+ public boolean isMultiLine(Annotation annotation) {
+ return true;
+ }
+
+ public boolean isTemporary(Annotation annotation) {
+ return !annotation.isPersistent();
+ }
+
+ public String getTypeLabel(Annotation annotation) {
+ if (annotation instanceof ErrorAnnotation)
+ return "Errors";
+
+ return null;
+ }
+
+ public int getLayer(Annotation annotation) {
+ if (annotation instanceof ErrorAnnotation)
+ return ((ErrorAnnotation)annotation).getLayer();
+
+ return 0;
+ }
+
+ public void paint(Annotation annotation, GC gc, Canvas canvas, Rectangle bounds) {
+ ImageUtilities.drawImage(((ErrorAnnotation)annotation).getImage(), gc, canvas, bounds, SWT.CENTER, SWT.TOP);
+ }
+
+ public boolean isPaintable(Annotation annotation) {
+ if (annotation instanceof ErrorAnnotation)
+ return ((ErrorAnnotation)annotation).getImage() != null;
+
+ return false;
+ }
+
+ public boolean isSubtype(Object annotationType, Object potentialSupertype) {
+ if (annotationType.equals(potentialSupertype))
+ return true;
+
+ return false;
+
+ }
+
+ public Object[] getSupertypes(Object annotationType) {
+ return new Object[0];
+ }
+ }
+
+ // source viewer configuration
+ class CodeViewerConfiguration extends SourceViewerConfiguration {
+ private ColorCache manager;
+
+ public CodeViewerConfiguration(ColorCache manager) {
+ this.manager = manager;
+ }
+
+ public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
+ PresentationReconciler reconciler = new PresentationReconciler();
+ return reconciler;
+ }
+
+ public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
+ return new AnnotationHover();
+ }
+ }
+
+ // annotation hover manager
+ class AnnotationHover implements IAnnotationHover, ITextHover {
+ public String getHoverInfo(ISourceViewer sourceViewer, int lineNumber) {
+ Iterator ite = fAnnotationModel.getAnnotationIterator();
+
+ ArrayList all = new ArrayList();
+
+ while (ite.hasNext()) {
+ Annotation a = (Annotation) ite.next();
+ if (a instanceof ErrorAnnotation) {
+ all.add(((ErrorAnnotation)a).getText());
+ }
+ }
+
+ StringBuffer total = new StringBuffer();
+ for (int x = 0; x < all.size(); x++) {
+ String str = (String) all.get(x);
+ total.append(" " + str + (x == (all.size()-1) ? "" : "\n"));
+ }
+
+ return total.toString();
+ }
+
+ public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
+ return null;
+ }
+
+ public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
+ return null;
+ }
+ }
+
+ // one error annotation
+ class ErrorAnnotation extends Annotation {
+ private IMarker marker;
+ private String text;
+ private int line;
+ private Position position;
+
+ public ErrorAnnotation(IMarker marker) {
+ this.marker = marker;
+ }
+
+ public ErrorAnnotation(int line, String text) {
+ super(ERROR_TYPE, true, null);
+ this.marker = null;
+ this.line = line;
+ this.text = text;
+ }
+
+ public IMarker getMarker() {
+ return marker;
+ }
+
+ public int getLine() {
+ return line;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public Image getImage() {
+ return ERROR_IMAGE;
+ }
+
+ public int getLayer() {
+ return 3;
+ }
+
+ public String getType() {
+ return ERROR_TYPE;
+ }
+
+ public Position getPosition() {
+ return position;
+ }
+
+ public void setPosition(Position position) {
+ this.position = position;
+ }
+ }
}
View
110 src/com/redcareditor/mate/SharedTextColors.java
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package com.redcareditor.mate;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+
+import org.eclipse.jface.text.source.ISharedTextColors;
+
+/*
+ * @see org.eclipse.jface.text.source.ISharedTextColors
+ * @since 2.1
+ */
+class SharedTextColors implements ISharedTextColors {
+
+ /** The display table. */
+ private Map fDisplayTable;
+
+ /** Creates an returns a shared color manager. */
+ public SharedTextColors() {
+ super();
+ }
+
+ /*
+ * @see ISharedTextColors#getColor(RGB)
+ */
+ public Color getColor(RGB rgb) {
+ if (rgb == null)
+ return null;
+
+ if (fDisplayTable == null)
+ fDisplayTable= new HashMap(2);
+
+ final Display display= Display.getCurrent();
+
+ Map colorTable= (Map) fDisplayTable.get(display);
+ if (colorTable == null) {
+ colorTable= new HashMap(10);
+ fDisplayTable.put(display, colorTable);
+ display.disposeExec(new Runnable() {
+ public void run() {
+ dispose(display);
+ }
+ });
+ }
+
+ Color color= (Color) colorTable.get(rgb);
+ if (color == null) {
+ color= new Color(display, rgb);
+ colorTable.put(rgb, color);
+ }
+
+ return color;
+ }
+
+ /*
+ * @see ISharedTextColors#dispose()
+ */
+ public void dispose() {
+ if (fDisplayTable == null)
+ return;
+
+ Iterator iter= fDisplayTable.values().iterator();
+ while (iter.hasNext())
+ dispose((Map)iter.next());
+ fDisplayTable= null;
+ }
+
+ /**
+ * Disposes the colors for the given display.
+ *
+ * @param display the display for which to dispose the colors
+ * @since 3.3
+ */
+ private void dispose(Display display) {
+ if (fDisplayTable != null)
+ dispose((Map)fDisplayTable.remove(display));
+ }
+
+ /**
+ * Disposes the given color table.
+ *
+ * @param colorTable the color table that maps <code>RGB</code> to <code>Color</code>
+ * @since 3.3
+ */
+ private void dispose(Map colorTable) {
+ if (colorTable == null)
+ return;
+
+ Iterator iter= colorTable.values().iterator();
+ while (iter.hasNext())
+ ((Color) iter.next()).dispose();
+
+ colorTable.clear();
+ }
+
+}
View
2 src/ruby/java-mateview.rb
@@ -33,6 +33,8 @@
require 'org.eclipse.jface.text_3.5.0'
require 'org.eclipse.osgi'
require 'org.eclipse.text_3.5.0.v20090513-2000'
+require 'org.eclipse.core.jobs_3.4.100.v20090429-1800'
+require 'org.eclipse.core.runtime_3.5.0.v20090525'
require 'swt_wrapper'

0 comments on commit 8eef627

Please sign in to comment.