Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2015-09-07 16:55:02 +0000
committerThomas Wolf2015-09-07 17:02:16 +0000
commit235ed9d5ac2e14ee2ba0a07af80c099052eb441e (patch)
treeffb491778a625336c53f5debbef88aa31ad4d89a
parent00aaabadbcf41e3a1efe89e274d5d0d32f36dac9 (diff)
downloadegit-235ed9d5ac2e14ee2ba0a07af80c099052eb441e.tar.gz
egit-235ed9d5ac2e14ee2ba0a07af80c099052eb441e.tar.xz
egit-235ed9d5ac2e14ee2ba0a07af80c099052eb441e.zip
Simplify hyperlink syntax coloring in SpellcheckableMessageArea
Turns out we don't need to use a special TextAttribute, and neither do we need a special damager/repairer. Works nicely out of the box. Change-Id: Id2f0d36f3c2018c047ad1f4cf65e148c960f236d Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/dialogs/HyperlinkTokenScannerTest.java12
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/HyperlinkDamagerRepairer.java117
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/HyperlinkTokenScanner.java13
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/SpellcheckableMessageArea.java3
4 files changed, 17 insertions, 128 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/dialogs/HyperlinkTokenScannerTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/dialogs/HyperlinkTokenScannerTest.java
index 041250ed5e..4de8b1ad1c 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/dialogs/HyperlinkTokenScannerTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/dialogs/HyperlinkTokenScannerTest.java
@@ -15,6 +15,7 @@ import java.util.Arrays;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
import org.eclipse.jface.text.hyperlink.URLHyperlinkDetector;
import org.eclipse.jface.text.rules.IToken;
@@ -111,9 +112,14 @@ public class HyperlinkTokenScannerTest {
char ch = 'x';
if (token == HyperlinkTokenScanner.DEFAULT) {
ch = 'D';
- } else if (token
- .getData() instanceof HyperlinkDamagerRepairer.HyperlinkTextAttribute) {
- ch = 'H';
+ } else {
+ Object data = token.getData();
+ if (data instanceof TextAttribute) {
+ int style = ((TextAttribute) data).getStyle();
+ if ((style & TextAttribute.UNDERLINE) != 0) {
+ ch = 'H';
+ }
+ }
}
Arrays.fill(found, tokenOffset, tokenOffset + tokenLength, ch);
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/HyperlinkDamagerRepairer.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/HyperlinkDamagerRepairer.java
deleted file mode 100644
index 925d07c4d0..0000000000
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/HyperlinkDamagerRepairer.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2015 Thomas Wolf <thomas.wolf@paranor.ch>.
- *
- * 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
- *******************************************************************************/
-package org.eclipse.egit.ui.internal.dialogs;
-
-import org.eclipse.jface.text.TextAttribute;
-import org.eclipse.jface.text.TextPresentation;
-import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
-import org.eclipse.jface.text.rules.ITokenScanner;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyleRange;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-
-/**
- * A {@link DefaultDamagerRepairer} that can handle
- * {@link HyperlinkTextAttribute}s.
- *
- * @see HyperlinkTokenScanner
- */
-public class HyperlinkDamagerRepairer extends DefaultDamagerRepairer {
-
- /**
- * A {@link TextAttribute} that the {@link HyperlinkDamagerRepairer} uses to
- * set the {@link SWT#UNDERLINE_LINK} style property on a {@link StyleRange}
- * of a text.
- */
- protected static class HyperlinkTextAttribute extends TextAttribute {
-
- // Add SWT.UNDERLINE_LINK to avoid it compares equal to other
- // (non-hyperlink) TextAttributes.
-
- /**
- * Creates a text attribute for the given foreground color, no
- * background color and with the SWT normal style and SWT hyperlink
- * underlining.
- *
- * @param foreground
- * the foreground color, <code>null</code> if none
- */
- public HyperlinkTextAttribute(Color foreground) {
- this(foreground, null, SWT.UNDERLINE_LINK);
- }
-
- /**
- * Creates a text attribute with the given colors and style, plus SWT
- * hyperlink underlining.
- *
- * @param foreground
- * the foreground color, <code>null</code> if none
- * @param background
- * the background color, <code>null</code> if none
- * @param style
- * the style
- */
- public HyperlinkTextAttribute(Color foreground, Color background,
- int style) {
- this(foreground, background, style, null);
- }
-
- /**
- * Creates a text attribute with the given colors, style, and font, plus
- * SWT hyperlink underlining.
- *
- * @param foreground
- * the foreground color, <code>null</code> if none
- * @param background
- * the background color, <code>null</code> if none
- * @param style
- * the style
- * @param font
- * the font, <code>null</code> if none
- */
- public HyperlinkTextAttribute(Color foreground, Color background,
- int style, Font font) {
- super(foreground, background, style | SWT.UNDERLINE_LINK, font);
- }
- }
-
- /**
- * Creates a new instance that will use the given scanner to tokenize.
- *
- * @param scanner
- * the {@link ITokenScanner} to use for tokenizing and
- * determining the text attributes
- */
- public HyperlinkDamagerRepairer(ITokenScanner scanner) {
- super(scanner);
- }
-
- @Override
- protected void addRange(TextPresentation presentation, int offset,
- int length, TextAttribute attr) {
- if (attr != null) {
- int style = attr.getStyle();
- int fontStyle = style & (SWT.ITALIC | SWT.BOLD | SWT.NORMAL);
- StyleRange styleRange = new StyleRange(offset, length,
- attr.getForeground(), attr.getBackground(), fontStyle);
- styleRange.strikeout = (style
- & TextAttribute.STRIKETHROUGH) != 0;
- if (attr instanceof HyperlinkTextAttribute) {
- styleRange.underline = true;
- styleRange.underlineStyle = SWT.UNDERLINE_LINK;
- } else {
- styleRange.underline = (style
- & TextAttribute.UNDERLINE) != 0;
- }
- styleRange.font = attr.getFont();
- presentation.addStyleRange(styleRange);
- }
- }
-} \ No newline at end of file
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/HyperlinkTokenScanner.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/HyperlinkTokenScanner.java
index 672d4e850d..5a754b8231 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/HyperlinkTokenScanner.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/HyperlinkTokenScanner.java
@@ -15,6 +15,7 @@ import org.eclipse.jface.resource.JFaceColors;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
import org.eclipse.jface.text.rules.IToken;
@@ -99,8 +100,8 @@ public class HyperlinkTokenScanner implements ITokenScanner {
/**
* Configures the scanner by providing access to the document range that
- * should be scanned, plus defining the foreground color to use for hyperlink
- * syntax coloring.
+ * should be scanned, plus defining the foreground color to use for
+ * hyperlink syntax coloring.
*
* @param document
* the document to scan
@@ -110,9 +111,7 @@ public class HyperlinkTokenScanner implements ITokenScanner {
* the length of the document range to scan
* @param color
* the foreground color to use for hyperlinks; may be
- * {@code null} in which case the SWT default color for the
- * {@link org.eclipse.swt.SWT#UNDERLINE_LINK SWT.UNDERLINE_LINK}
- * style is applied
+ * {@code null} in which case the default color is applied
*/
protected void setRangeAndColor(@NonNull IDocument document, int offset,
int length, @Nullable Color color) {
@@ -120,7 +119,7 @@ public class HyperlinkTokenScanner implements ITokenScanner {
this.endOfRange = offset + length;
this.currentOffset = offset;
this.tokenStart = -1;
- hyperlinkToken = new Token(
- new HyperlinkDamagerRepairer.HyperlinkTextAttribute(color));
+ this.hyperlinkToken = new Token(
+ new TextAttribute(color, null, TextAttribute.UNDERLINE));
}
} \ No newline at end of file
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/SpellcheckableMessageArea.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/SpellcheckableMessageArea.java
index 10f9791cbf..079915f257 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/SpellcheckableMessageArea.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/SpellcheckableMessageArea.java
@@ -58,6 +58,7 @@ import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext;
import org.eclipse.jface.text.quickassist.IQuickAssistProcessor;
import org.eclipse.jface.text.reconciler.IReconciler;
+import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.AnnotationModel;
import org.eclipse.jface.text.source.IAnnotationAccess;
@@ -372,7 +373,7 @@ public class SpellcheckableMessageArea extends Composite {
PresentationReconciler reconciler = new PresentationReconciler();
reconciler.setDocumentPartitioning(
getConfiguredDocumentPartitioning(sourceViewer));
- HyperlinkDamagerRepairer hyperlinkDamagerRepairer = new HyperlinkDamagerRepairer(
+ DefaultDamagerRepairer hyperlinkDamagerRepairer = new DefaultDamagerRepairer(
new HyperlinkTokenScanner(
getHyperlinkDetectors(sourceViewer),
sourceViewer));

Back to the top