From 5bf1b2197190a5b36e54506bfc3e81b4294f188d Mon Sep 17 00:00:00 2001 From: Laurent Petit Date: Thu, 17 Feb 2011 11:09:35 +0100 Subject: [PATCH] Fixes #210 and #209. Also placed some printlns for a while for easing reporting if the fix is not complete. --- ccw.core/META-INF/MANIFEST.MF | 1 + ccw.core/src/ccw/CCWPlugin.java | 51 +++++++++++++++++++++------------ 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/ccw.core/META-INF/MANIFEST.MF b/ccw.core/META-INF/MANIFEST.MF index 32d6098f..9fa891e8 100644 --- a/ccw.core/META-INF/MANIFEST.MF +++ b/ccw.core/META-INF/MANIFEST.MF @@ -48,3 +48,4 @@ Export-Package: ccw, ccw.utils.editors.antlrbased, ccw.wizards Bundle-ActivationPolicy: lazy + diff --git a/ccw.core/src/ccw/CCWPlugin.java b/ccw.core/src/ccw/CCWPlugin.java index e3e2c714..b88b8b21 100644 --- a/ccw.core/src/ccw/CCWPlugin.java +++ b/ccw.core/src/ccw/CCWPlugin.java @@ -77,7 +77,8 @@ public static Color getSystemColor(int swtKey) { * dispose the color themselves) */ public static Color getCCWColor(int index) { - return CCWPlugin.getDefault().allColors[index]; + CCWPlugin defaultPlugin = getDefault(); + return defaultPlugin.getAllColors()[index]; } /** The shared instance */ @@ -88,13 +89,23 @@ public static Color getCCWColor(int index) { // clear as mud to me at the moment public Color[] allColors; + /** + * Must be called from the UI thread + */ + public Color[] getAllColors() { + if (allColors == null) { + initializeParenRainbowColors(); + } + return allColors; + } + private ColorRegistry colorRegistry; private FontRegistry fontRegistry; private ServerSocket ackREPLServer; - private synchronized void startREPLServer() throws CoreException { + public synchronized void startREPLServer() throws CoreException { if (ackREPLServer == null) { try { ackREPLServer = (ServerSocket)((List)Var.find(Symbol.intern("clojure.tools.nrepl/start-server")).invoke()).get(0); @@ -114,27 +125,27 @@ public int getREPLServerPort() throws CoreException { } public CCWPlugin() { + System.out.println("CCWPlugin instanciated"); } public void start(BundleContext context) throws Exception { + System.out.println("CCWPlugin start() starts"); super.start(context); - plugin = this; startClojureCode(context); - startREPLServer(); - initializeParenRainbowColors(); + System.out.println("CCWPlugin start() ends"); } private synchronized void createColorRegistry() { if (colorRegistry == null) { - DisplayUtil.syncExec(new Runnable() { - public void run() { - colorRegistry = new ColorRegistry(getWorkbench().getDisplay()); - colorRegistry.put("ccw.repl.expressionBackground", new RGB(0xf0, 0xf0, 0xf0)); - }}); + colorRegistry = new ColorRegistry(getWorkbench().getDisplay()); + colorRegistry.put("ccw.repl.expressionBackground", new RGB(0xf0, 0xf0, 0xf0)); } } + /** + * Must be called from the UI thread only + */ public ColorRegistry getColorRegistry() { if (colorRegistry == null) { createColorRegistry(); @@ -221,15 +232,17 @@ private void stopREPLServer() { } } - private void initializeParenRainbowColors() { - allColors = new Color[] { - new Color(Display.getDefault(), 0x00, 0xCC, 0x00), - new Color(Display.getDefault(), 0x00, 0x88, 0xAA), - new Color(Display.getDefault(), 0x66, 0x00, 0xAA), - new Color(Display.getDefault(), 0x00, 0x77, 0x00), - new Color(Display.getDefault(), 0x77, 0xEE, 0x00), - new Color(Display.getDefault(), 0xFF, 0x88, 0x00) - }; + private synchronized void initializeParenRainbowColors() { + if (allColors == null) { + allColors = new Color[] { + new Color(Display.getDefault(), 0x00, 0xCC, 0x00), + new Color(Display.getDefault(), 0x00, 0x88, 0xAA), + new Color(Display.getDefault(), 0x66, 0x00, 0xAA), + new Color(Display.getDefault(), 0x00, 0x77, 0x00), + new Color(Display.getDefault(), 0x77, 0xEE, 0x00), + new Color(Display.getDefault(), 0xFF, 0x88, 0x00) + }; + } } private void disposeParenRainbowColors() {