Fixed: [Issue 25] Terminal Plugin displays bold+black as white color
diff --git a/com.google.eclipse.tm.terminal/src/com/google/eclipse/tm/internal/terminal/textcanvas/StyleMap.java b/com.google.eclipse.tm.terminal/src/com/google/eclipse/tm/internal/terminal/textcanvas/StyleMap.java
index 92a4a9f..ae96f4a 100644
--- a/com.google.eclipse.tm.terminal/src/com/google/eclipse/tm/internal/terminal/textcanvas/StyleMap.java
+++ b/com.google.eclipse.tm.terminal/src/com/google/eclipse/tm/internal/terminal/textcanvas/StyleMap.java
@@ -9,7 +9,7 @@
 
 import java.util.*;
 
-import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.*;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.*;
 import org.eclipse.swt.widgets.Display;
@@ -48,8 +48,8 @@
 
   private final int[] offsets = new int[256];
 
-  private RGB background = new RGB(0, 0, 0);
-  private RGB foreground = new RGB(229, 229, 229);
+  private Color background = getColor(new RGB(0, 0, 0));
+  private Color foreground = getColor(new RGB(229, 229, 229));
 
   private Font font = JFaceResources.getFontRegistry().get(fontName);
 
@@ -69,7 +69,7 @@
     if (invertColors) {
       setColor(colorMapForeground, WHITE, 0, 0, 0);
       setColor(colorMapForeground, WHITE_FOREGROUND, 50, 50, 50);
-      setColor(colorMapForeground, BLACK, foreground.red, foreground.green, foreground.blue); // set foreground
+      setColor(colorMapForeground, BLACK, 229, 229, 229);
     } else {
       setColor(colorMapForeground, WHITE, 255, 255, 255);
       setColor(colorMapForeground, WHITE_FOREGROUND, 229, 229, 229);
@@ -86,9 +86,9 @@
 
   private void initBackgroundColors() {
     if (invertColors) {
-      setColor(colorMapBackground, WHITE, background.red, background.green, background.blue); // set background
+      setColor(colorMapBackground, WHITE, 0, 0, 0);
       setColor(colorMapBackground, WHITE_FOREGROUND, 50, 50, 50); // only used when colors are inverse
-      setColor(colorMapBackground, BLACK, foreground.red, foreground.green, foreground.blue); // set cursor color
+      setColor(colorMapBackground, BLACK, 255, 255, 255); // cursor color
     } else {
       setColor(colorMapBackground, WHITE, 255, 255, 255);
       setColor(colorMapBackground, WHITE_FOREGROUND, 229, 229, 229);
@@ -123,39 +123,40 @@
   }
 
   private void setColor(Map<StyleColor, Color> colorMap, String name, int r, int g, int b) {
-    String colorName = PREFIX + r + "-" + g + "-" + b;
-    Color color = JFaceResources.getColorRegistry().get(colorName);
-    if (color == null) {
-      JFaceResources.getColorRegistry().put(colorName, new RGB(r, g, b));
-      color = JFaceResources.getColorRegistry().get(colorName);
-    }
-    colorMap.put(StyleColor.getStyleColor(name), color);
-    colorMap.put(StyleColor.getStyleColor(name.toUpperCase()), color);
+    Color color = getColor(new RGB(r, g, b));
+    setColor(colorMap, color, StyleColor.getStyleColor(name));
+    setColor(colorMap, color, StyleColor.getStyleColor(name.toUpperCase()));
   }
 
-  public Color getForegrondColor(Style style) {
-    style = defaultIfNull(style);
-    Map<StyleColor, Color> map = style.isBold() ? colorMapIntense : colorMapForeground;
-    if (style.isReverse()) {
-      return getColor(map, style.getBackground());
+  private void setColor(Map<StyleColor, Color> colorMap, Color color, StyleColor styleColor) {
+    if (styleColor != null) {
+      colorMap.put(styleColor, color);
     }
-    return getColor(map, style.getForground());
+  }
+
+  public Color getForegroundColor(Style style) {
+    if (style == null) {
+      return foreground;
+    }
+    StyleColor color = style.isReverse() ? style.getBackground() : style.getForeground();
+    Map<StyleColor, Color> map = style.isBold() ? colorMapIntense : colorMapForeground;
+    Color actualColor = map.get(color);
+    if (actualColor == null) {
+      actualColor = foreground;
+    }
+    return actualColor;
   }
 
   public Color getBackgroundColor(Style style) {
-    style = defaultIfNull(style);
-    if (style.isReverse()) {
-      return getColor(colorMapBackground, style.getForground());
+    if (style == null) {
+      return background;
     }
-    return getColor(colorMapBackground, style.getBackground());
-  }
-
-  Color getColor(Map<StyleColor, Color> map, StyleColor color) {
-    Color c = map.get(color);
-    if (c == null) {
-      c = Display.getCurrent().getSystemColor(SWT.COLOR_GRAY);
+    StyleColor color = style.isReverse() ? style.getForeground() : style.getBackground();
+    Color actualColor = colorMapBackground.get(color);
+    if (actualColor == null) {
+      actualColor = background;
     }
-    return c;
+    return actualColor;
   }
 
   private Style defaultIfNull(Style style) {
@@ -272,9 +273,19 @@
   }
 
   public void setColors(RGB background, RGB foreground) {
-    this.background = background;
-    this.foreground = foreground;
-    initColors();
+    this.background = getColor(background);
+    this.foreground = getColor(foreground);
+  }
+
+  private Color getColor(RGB colorData) {
+    String name = PREFIX + colorData.red + "-" + colorData.green + "-" + colorData.blue;
+    ColorRegistry colorRegistry = JFaceResources.getColorRegistry();
+    Color color = colorRegistry.get(name);
+    if (color == null) {
+      colorRegistry.put(name, colorData);
+      color = colorRegistry.get(name);
+    }
+    return color;
   }
 
   public void setFont(Font font) {
diff --git a/com.google.eclipse.tm.terminal/src/com/google/eclipse/tm/internal/terminal/textcanvas/TextLineRenderer.java b/com.google.eclipse.tm.terminal/src/com/google/eclipse/tm/internal/terminal/textcanvas/TextLineRenderer.java
index f3c2ed3..95b562f 100644
--- a/com.google.eclipse.tm.terminal/src/com/google/eclipse/tm/internal/terminal/textcanvas/TextLineRenderer.java
+++ b/com.google.eclipse.tm.terminal/src/com/google/eclipse/tm/internal/terminal/textcanvas/TextLineRenderer.java
@@ -97,12 +97,13 @@
       int cursorColumn = model.getCursorColumn();
       if (cursorColumn < getTerminalText().getWidth()) {
         Style style = getTerminalText().getStyle(row, cursorColumn);
-        if (style == null) {
-          // TODO make the cursor color customizable
-          style = Style.getStyle("BLACK", "WHITE");
+        if (style != null) {
+          style = style.setReverse(!style.isReverse());
+          setupGC(gc, style);
+        } else {
+          setBackground(gc, styleMap.getForegroundColor(null));
+          setForeground(gc, styleMap.getBackgroundColor(null));
         }
-        style = style.setReverse(!style.isReverse());
-        setupGC(gc, style);
         String text = String.valueOf(getTerminalText().getChar(row, cursorColumn));
         drawText(gc, x, y, colFirst, cursorColumn, text);
       }
@@ -117,9 +118,10 @@
       // gc.fillRectangle(x, y, styleMap.getFontWidth() * text.length(), styleMap.getFontHeight());
       for (int i = 0; i < text.length(); i++) {
         char c = text.charAt(i);
-        int newX = x + offset + i * styleMap.getFontWidth();
+        int fontWidth = styleMap.getFontWidth();
+        int newX = x + offset + i * fontWidth;
         // TODO why do I have to draw the background character by character?
-        gc.fillRectangle(newX, y, styleMap.getFontWidth(), styleMap.getFontHeight());
+        gc.fillRectangle(newX, y, fontWidth, styleMap.getFontHeight());
         if (c != ' ' && c != '\000') {
           gc.drawString(String.valueOf(c), styleMap.getCharOffset(c) + newX, y, true);
         }
@@ -131,17 +133,23 @@
   }
 
   private void setupGC(GC gc, Style style) {
-    Color c = styleMap.getForegrondColor(style);
-    if (c != gc.getForeground()) {
-      gc.setForeground(c);
+    setForeground(gc, styleMap.getForegroundColor(style));
+    setBackground(gc, styleMap.getBackgroundColor(style));
+    Font font = styleMap.getFont(style);
+    if (font != gc.getFont()) {
+      gc.setFont(font);
     }
-    c = styleMap.getBackgroundColor(style);
-    if (c != gc.getBackground()) {
-      gc.setBackground(c);
+  }
+
+  private void setForeground(GC gc, Color color) {
+    if (color != gc.getForeground()) {
+      gc.setForeground(color);
     }
-    Font f = styleMap.getFont(style);
-    if (f != gc.getFont()) {
-      gc.setFont(f);
+  }
+
+  private void setBackground(GC gc, Color color) {
+    if (color != gc.getBackground()) {
+      gc.setBackground(color);
     }
   }
 
diff --git a/com.google.eclipse.tm.terminal/src/com/google/eclipse/tm/terminal/model/Style.java b/com.google.eclipse.tm.terminal/src/com/google/eclipse/tm/terminal/model/Style.java
index d8f9a58..9dada9f 100644
--- a/com.google.eclipse.tm.terminal/src/com/google/eclipse/tm/terminal/model/Style.java
+++ b/com.google.eclipse.tm.terminal/src/com/google/eclipse/tm/terminal/model/Style.java
@@ -11,7 +11,7 @@
 
 // TODO add an Object for user data, use weak map to keep track of styles with associated user data.
 public class Style {
-  private final StyleColor forground;
+  private final StyleColor foreground;
   private final StyleColor background;
   private final boolean bold;
   private final boolean blink;
@@ -22,7 +22,7 @@
 
   private Style(StyleColor forground, StyleColor background, boolean bold, boolean blink, boolean underline,
       boolean reverse) {
-    this.forground = forground;
+    this.foreground = forground;
     this.background = background;
     this.bold = bold;
     this.blink = blink;
@@ -58,7 +58,7 @@
   }
 
   public Style setBackground(StyleColor background) {
-    return getStyle(forground, background, bold, blink, underline, reverse);
+    return getStyle(foreground, background, bold, blink, underline, reverse);
   }
 
   public Style setForground(String colorName) {
@@ -66,23 +66,23 @@
   }
 
   public Style setBackground(String colorName) {
-    return getStyle(forground, StyleColor.getStyleColor(colorName), bold, blink, underline, reverse);
+    return getStyle(foreground, StyleColor.getStyleColor(colorName), bold, blink, underline, reverse);
   }
 
   public Style setBold(boolean bold) {
-    return getStyle(forground, background, bold, blink, underline, reverse);
+    return getStyle(foreground, background, bold, blink, underline, reverse);
   }
 
   public Style setBlink(boolean blink) {
-    return getStyle(forground, background, bold, blink, underline, reverse);
+    return getStyle(foreground, background, bold, blink, underline, reverse);
   }
 
   public Style setUnderline(boolean underline) {
-    return getStyle(forground, background, bold, blink, underline, reverse);
+    return getStyle(foreground, background, bold, blink, underline, reverse);
   }
 
   public Style setReverse(boolean reverse) {
-    return getStyle(forground, background, bold, blink, underline, reverse);
+    return getStyle(foreground, background, bold, blink, underline, reverse);
   }
 
   public StyleColor getBackground() {
@@ -97,8 +97,8 @@
     return bold;
   }
 
-  public StyleColor getForground() {
-    return forground;
+  public StyleColor getForeground() {
+    return foreground;
   }
 
   public boolean isReverse() {
@@ -115,7 +115,7 @@
     result = prime * result + ((background == null) ? 0 : background.hashCode());
     result = prime * result + (blink ? 1231 : 1237);
     result = prime * result + (bold ? 1231 : 1237);
-    result = prime * result + ((forground == null) ? 0 : forground.hashCode());
+    result = prime * result + ((foreground == null) ? 0 : foreground.hashCode());
     result = prime * result + (reverse ? 1231 : 1237);
     result = prime * result + (underline ? 1231 : 1237);
     return result;
@@ -141,7 +141,7 @@
     if (bold != other.bold) {
       return false;
     }
-    if (forground != other.forground) {
+    if (foreground != other.foreground) {
       return false;
     }
     if (reverse != other.reverse) {
@@ -152,8 +152,8 @@
 
   @Override public String toString() {
     StringBuilder builder = new StringBuilder();
-    builder.append("Style [forground=");
-    builder.append(forground);
+    builder.append("Style [foreground=");
+    builder.append(foreground);
     builder.append(", background=");
     builder.append(background);
     builder.append(", bold=");
diff --git a/com.google.eclipse.tm.terminal/src/com/google/eclipse/tm/terminal/model/StyleColor.java b/com.google.eclipse.tm.terminal/src/com/google/eclipse/tm/terminal/model/StyleColor.java
index 7846207..6170485 100644
--- a/com.google.eclipse.tm.terminal/src/com/google/eclipse/tm/terminal/model/StyleColor.java
+++ b/com.google.eclipse.tm.terminal/src/com/google/eclipse/tm/terminal/model/StyleColor.java
@@ -7,23 +7,16 @@
  *******************************************************************************/
 package com.google.eclipse.tm.terminal.model;
 
-import java.util.*;
+import java.util.concurrent.*;
 
 public class StyleColor {
-  private static final Map<String, StyleColor> STYLE_COLORS = new HashMap<String, StyleColor>();
+  private static final ConcurrentMap<String, StyleColor> STYLE_COLORS = new ConcurrentHashMap<String, StyleColor>();
 
   private final String name;
 
   public static StyleColor getStyleColor(String name) {
-    StyleColor result;
-    synchronized (STYLE_COLORS) {
-      result = STYLE_COLORS.get(name);
-      if (result == null) {
-        result = new StyleColor(name);
-        STYLE_COLORS.put(name, result);
-      }
-    }
-    return result;
+    StyleColor result = new StyleColor(name);
+    return STYLE_COLORS.putIfAbsent(name, result);
   }
 
   private StyleColor(String name) {