Skip to content
Browse files

Corrected color resources leaks

  • Loading branch information...
1 parent ceb060b commit d0ee917ada48e4b49c1d4ed39f96c58a74520bd4 @laurentpetit committed
View
5 ccw.core/src/ccw/editors/antlrbased/AntlrBasedClojureEditor.java
@@ -115,7 +115,8 @@ protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler rule
ISourceViewer viewer = new ClojureSourceViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles, getPreferenceStore());
// ensure decoration support has been created and configured.
getSourceViewerDecorationSupport(viewer);
- viewer.getTextWidget().addCaretListener(new SameWordHighlightingCaretListener(this));
+ viewer.getTextWidget().addCaretListener(new SameWordHighlightingCaretListener(this, CCWPlugin
+ .getDefault().getColorRegistry()));
return viewer;
}
@@ -180,7 +181,7 @@ protected void createActions() {
action = new LoadFileAction(this);
action.setActionDefinitionId(IClojureEditorActionDefinitionIds.LOAD_FILE);
setAction(LoadFileAction.ID, action);
- action = new RunTestsAction(this);
+ action = new RunTestsAction(this, CCWPlugin.getDefault().getColorRegistry());
action.setActionDefinitionId(IClojureEditorActionDefinitionIds.RUN_TESTS);
setAction(RunTestsAction.RUN_TESTS_ID, action);
action = new CompileLibAction(this);
View
25 ccw.core/src/ccw/editors/antlrbased/RunTestsAction.java
@@ -14,20 +14,33 @@
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.Action;
+import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.graphics.RGB;
import org.eclipse.ui.console.IOConsole;
import ccw.debug.ClojureClient;
public class RunTestsAction extends Action {
public static final String RUN_TESTS_ID = "RunTestsAction";
+ private static final String FAILED_TESTS_COLOR_KEY = "ccw.editors.RunTestsAction.COLOR_KEY";
+ private static final String PASSED_TESTS_COLOR_KEY = "ccw.editors.RunTestsAction.COLOR_KEY";
private final AntlrBasedClojureEditor editor;
+ private final ColorRegistry colorRegistry;
- public RunTestsAction(AntlrBasedClojureEditor editor) {
+ public RunTestsAction(AntlrBasedClojureEditor editor, ColorRegistry colorRegistry) {
this.editor = editor;
+ this.colorRegistry = colorRegistry;
+ initColorRegistry();
+ }
+ private void initColorRegistry() {
+ if (!colorRegistry.hasValueFor(FAILED_TESTS_COLOR_KEY)) {
+ colorRegistry.put(FAILED_TESTS_COLOR_KEY, new RGB(0xff, 0xff, 0xcf));
+ }
+ if (!colorRegistry.hasValueFor(PASSED_TESTS_COLOR_KEY)) {
+ colorRegistry.put(PASSED_TESTS_COLOR_KEY, new RGB(0xcf, 0xff, 0xcf));
+ }
}
-
@Override
public void run() {
super.run();
@@ -39,7 +52,7 @@ public void run() {
runTests(lib, clojure);
} else {
editor.setStatusLineErrorMessage(ClojureEditorMessages.Compilation_failed);
- setReplBackgroundColor(new Color(Display.getDefault(), 0xff, 0xff, 0xcf));
+ setReplBackgroundColor(colorRegistry.get(FAILED_TESTS_COLOR_KEY));
}
}
@@ -47,10 +60,10 @@ private void runTests(String lib, ClojureClient clojure) {
String results = clojure.remoteLoad(runTestsCommand(lib));
if (results.contains(":fail 0, :error 0")) {
editor.setStatusLineErrorMessage(ClojureEditorMessages.Tests_passed);
- setReplBackgroundColor(new Color(Display.getDefault(), 0xcf, 0xff, 0xcf));
+ setReplBackgroundColor(colorRegistry.get(PASSED_TESTS_COLOR_KEY));
} else {
editor.setStatusLineErrorMessage(ClojureEditorMessages.Tests_failed);
- setReplBackgroundColor(new Color(Display.getDefault(), 0xff, 0xcf, 0xcf));
+ setReplBackgroundColor(colorRegistry.get(FAILED_TESTS_COLOR_KEY));
}
}
View
24 ccw.core/src/ccw/editors/antlrbased/SameWordHighlightingCaretListener.java
@@ -10,19 +10,35 @@
*******************************************************************************/
package ccw.editors.antlrbased;
+import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.ITokenScanner;
import org.eclipse.swt.custom.CaretEvent;
import org.eclipse.swt.custom.CaretListener;
import org.eclipse.swt.custom.StyleRange;
-import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
public class SameWordHighlightingCaretListener implements CaretListener {
+ private static final String COLOR_KEY = "ccw.editors.SameWordHighlightingCaretListener.COLOR_KEY";
+ private static final String OTHER_MATCHES_COLOR_KEY = "ccw.editors.SameWordHighlightingCaretListener.OTHER_MATCHES_COLOR_KEY";
+
private final AntlrBasedClojureEditor editor;
+ private final ColorRegistry colorRegistry;
- public SameWordHighlightingCaretListener(AntlrBasedClojureEditor editor) {
+ public SameWordHighlightingCaretListener(AntlrBasedClojureEditor editor, ColorRegistry colorRegistry) {
this.editor = editor;
+ this.colorRegistry = colorRegistry;
+ initColorRegistry();
+ }
+
+ private void initColorRegistry() {
+ if (!colorRegistry.hasValueFor(COLOR_KEY)) {
+ colorRegistry.put(COLOR_KEY, new RGB(225, 225, 225));
+ }
+ if (!colorRegistry.hasValueFor(OTHER_MATCHES_COLOR_KEY)) {
+ colorRegistry.put(OTHER_MATCHES_COLOR_KEY, new RGB(255, 255, 180));
+ }
}
public void caretMoved(CaretEvent event) {
@@ -41,7 +57,7 @@ public void caretMoved(CaretEvent event) {
}
private StyleRange createRange(Tokens tokens) {
- return tokens.styleRange(new Color(editor.sourceViewer().getTextWidget().getDisplay(), 225, 225, 225));
+ return tokens.styleRange(colorRegistry.get(COLOR_KEY));
}
private void colorOtherMatches(IDocument document, Tokens tokens, String original) {
@@ -52,7 +68,7 @@ private void colorOtherMatches(IDocument document, Tokens tokens, String origina
if (token.getData() == null) {
String tokenContents = tokens.tokenContents();
if (tokenContents.equals(original)) {
- StyleRange range = tokens.styleRange(new Color(editor.sourceViewer().getTextWidget().getDisplay(), 255, 255, 180));
+ StyleRange range = tokens.styleRange(colorRegistry.get(OTHER_MATCHES_COLOR_KEY));
editor.sourceViewer().getTextWidget().setStyleRange(range);
}
}

0 comments on commit d0ee917

Please sign in to comment.
Something went wrong with that request. Please try again.