add cache for ColorResource to remove amount of short-lived instances

Signed-off-by: Florian Thienel <florian@thienel.org>
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/boxes/verticalBlockHorizontalBar-output.txt b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/boxes/verticalBlockHorizontalBar-output.txt
index 2b8def5..8f5e665 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/boxes/verticalBlockHorizontalBar-output.txt
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/boxes/verticalBlockHorizontalBar-output.txt
@@ -10,13 +10,11 @@
 Graphics.drawLine(15, 90, 265, 90)
 Graphics.setLineWidth(10)
 Graphics.drawLine(260, 5, 260, 95)
-ColorResource[Color[r=0,g=0,b=0], -1].dispose()
 Graphics.moveOrigin(55, 35)
 Graphics.moveOrigin(0, 0)
 Graphics.createColor(Color[r=0,g=0,b=0])
 Graphics.setColor(TracingColorResource [color=Color[r=0,g=0,b=0], id=-1])
 Graphics.fillRect(0, 0, 150, 10)
-ColorResource[Color[r=0,g=0,b=0], -1].dispose()
 Graphics.moveOrigin(0, 0)
 Graphics.moveOrigin(-55, -35)
 Graphics.moveOrigin(0, 0)
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/FakeGraphics.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/FakeGraphics.java
index e26b1ac..da98074 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/FakeGraphics.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/FakeGraphics.java
@@ -98,7 +98,7 @@
 	}
 
 	@Override
-	public ColorResource createColor(final Color rgb) {
+	public ColorResource getColor(final Color rgb) {
 		return new ColorResource() {
 			@Override
 			public void dispose() {
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/endtoend/TracingGraphics.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/endtoend/TracingGraphics.java
index f3609f7..457fca9 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/endtoend/TracingGraphics.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/endtoend/TracingGraphics.java
@@ -60,7 +60,6 @@
 	private ColorResource color;
 	private ColorResource foreground;
 	private ColorResource background;
-	private final List<GraphicsListener> listeners = new CopyOnWriteArrayList<GraphicsListener>();
 
 	public TracingGraphics(final Tracer tracer) {
 		this.tracer = tracer;
@@ -97,7 +96,7 @@
 	}
 
 	@Override
-	public ColorResource createColor(final Color color) {
+	public ColorResource getColor(final Color color) {
 		tracer.trace("Graphics.createColor({0})", color);
 		return new TracingColorResource(tracer, color);
 	}
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/endtoend/simpleParagraph-output.txt b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/endtoend/simpleParagraph-output.txt
index 8124ee0..57050be 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/endtoend/simpleParagraph-output.txt
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/endtoend/simpleParagraph-output.txt
@@ -64,7 +64,6 @@
 Graphics.drawChars(The quick brown , 0, 16, 0, 0)
 Graphics.setFont(null)
 Graphics.setColor(null)
-ColorResource[Color[r=0,g=0,b=0], -1].dispose()
 Graphics.createFont(FontSpec [names=[monospaced], size=10.0, style=PLAIN])
 Graphics.setFont(TracingFontResource [fontSpec=FontSpec [names=[monospaced], size=10.0, style=PLAIN]])
 Graphics.createColor(Color[r=0,g=0,b=0])
@@ -72,7 +71,6 @@
 Graphics.drawChars(fox , 0, 4, 96, 0)
 Graphics.setFont(null)
 Graphics.setColor(null)
-ColorResource[Color[r=0,g=0,b=0], -1].dispose()
 Graphics.setAntialiased(false)
 Graphics.setAntialiased(false)
 Graphics.createFont(FontSpec [names=[monospaced], size=10.0, style=PLAIN])
@@ -82,7 +80,6 @@
 Graphics.drawChars(jumps, 0, 5, 0, 12)
 Graphics.setFont(null)
 Graphics.setColor(null)
-ColorResource[Color[r=0,g=0,b=0], -1].dispose()
 Graphics.createFont(FontSpec [names=[monospaced], size=10.0, style=PLAIN])
 Graphics.setFont(TracingFontResource [fontSpec=FontSpec [names=[monospaced], size=10.0, style=PLAIN]])
 Graphics.createColor(Color[r=0,g=0,b=0])
@@ -90,7 +87,6 @@
 Graphics.drawChars( over the lazy dog's , 0, 21, 0, 24)
 Graphics.setFont(null)
 Graphics.setColor(null)
-ColorResource[Color[r=0,g=0,b=0], -1].dispose()
 Graphics.createFont(FontSpec [names=[monospaced], size=10.0, style=PLAIN])
 Graphics.setFont(TracingFontResource [fontSpec=FontSpec [names=[monospaced], size=10.0, style=PLAIN]])
 Graphics.createColor(Color[r=0,g=0,b=0])
@@ -98,9 +94,7 @@
 Graphics.drawChars(tail., 0, 5, 126, 24)
 Graphics.setFont(null)
 Graphics.setColor(null)
-ColorResource[Color[r=0,g=0,b=0], -1].dispose()
 Graphics.createColor(Color[r=0,g=0,b=0])
 Graphics.setColor(TracingColorResource [color=Color[r=0,g=0,b=0], id=-1])
 Graphics.fillRect(0, 0, 20, 2)
 Graphics.setColor(null)
-ColorResource[Color[r=0,g=0,b=0], -1].dispose()
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Frame.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Frame.java
index beb6ff1..613fda0 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Frame.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Frame.java
@@ -124,15 +124,13 @@
 	}
 
 	private void drawBorder(final Graphics graphics) {
-		final ColorResource colorResource = graphics.createColor(Color.BLACK); // TODO store border color
+		final ColorResource colorResource = graphics.getColor(Color.BLACK); // TODO store border color
 		graphics.setColor(colorResource);
 
 		drawBorderLine(graphics, border.top, margin.top, margin.left - border.left / 2, margin.top, width - margin.right + border.right / 2);
 		drawBorderLine(graphics, border.left, margin.top - border.top / 2, margin.left, height - margin.bottom + border.bottom / 2, margin.left);
 		drawBorderLine(graphics, border.bottom, height - margin.bottom, margin.left - border.left / 2, height - margin.bottom, width - margin.right + border.right / 2);
 		drawBorderLine(graphics, border.right, margin.top - border.top / 2, width - margin.right, height - margin.bottom + border.bottom / 2, width - margin.right);
-
-		colorResource.dispose();
 	}
 
 	private void drawBorderLine(final Graphics graphics, final int lineWidth, final int top, final int left, final int bottom, final int right) {
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/HorizontalBar.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/HorizontalBar.java
index ce10b01..dab1d93 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/HorizontalBar.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/HorizontalBar.java
@@ -85,9 +85,8 @@
 
 	@Override
 	public void paint(final Graphics graphics) {
-		final ColorResource colorResource = graphics.createColor(color);
+		final ColorResource colorResource = graphics.getColor(color);
 		graphics.setColor(colorResource);
 		graphics.fillRect(0, 0, width, height);
-		colorResource.dispose();
 	}
 }
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Square.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Square.java
index c1d7dc0..4159342 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Square.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Square.java
@@ -76,12 +76,10 @@
 
 	@Override
 	public void paint(final Graphics graphics) {
-		final ColorResource colorResource = graphics.createColor(Color.BLACK); // TODO store square color
+		final ColorResource colorResource = graphics.getColor(Color.BLACK); // TODO store square color
 		graphics.setColor(colorResource);
 
 		graphics.fillRect(0, 0, size, size);
-
-		colorResource.dispose();
 	}
 
 	@Override
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/core/Color.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/core/Color.java
index 6208b58..ff92a5d 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/core/Color.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/core/Color.java
@@ -17,14 +17,16 @@
 public class Color {
 
 	public static final Color BLACK = new Color(0, 0, 0);
+	public static final Color WHITE = new Color(255, 255, 255);
+	public static final Color RED = new Color(255, 0, 0);
+	public static final Color GREEN = new Color(0, 255, 0);
+	public static final Color BLUE = new Color(0, 0, 255);
 
 	private final int red;
 	private final int green;
 	private final int blue;
 
 	/**
-	 * Class constructor.
-	 *
 	 * @param red
 	 *            red value, 0..255
 	 * @param green
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/core/Graphics.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/core/Graphics.java
index d9b9909..7049e2c 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/core/Graphics.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/core/Graphics.java
@@ -26,7 +26,7 @@
 
 	public int charsWidth(char[] data, int offset, int length);
 
-	public ColorResource createColor(Color rgb);
+	public ColorResource getColor(Color rgb);
 
 	public FontResource getFont(FontSpec fontSpec);
 
@@ -42,14 +42,6 @@
 
 	public int asRelativeY(int absoluteY);
 
-	public void start(Object o);
-
-	public void finish(Object o);
-
-	public void addListener(GraphicsListener listener);
-
-	public void removeListener(GraphicsListener listener);
-
 	public void drawChars(char[] chars, int offset, int length, int x, int y);
 
 	public void drawLine(int x1, int y1, int x2, int y2);
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/AbstractBlockBox.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/AbstractBlockBox.java
index 4615fca..4a06db1 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/AbstractBlockBox.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/AbstractBlockBox.java
@@ -573,8 +573,8 @@
 			foreground = g.getSystemColor(ColorResource.SELECTION_FOREGROUND);
 			background = g.getSystemColor(ColorResource.SELECTION_BACKGROUND);
 		} else {
-			foreground = g.createColor(new Color(0, 0, 0));
-			background = g.createColor(new Color(0xcc, 0xcc, 0xcc));
+			foreground = g.getColor(new Color(0, 0, 0));
+			background = g.getColor(new Color(0xcc, 0xcc, 0xcc));
 		}
 
 		final FontMetrics fm = g.getFontMetrics();
@@ -592,10 +592,6 @@
 		g.drawString(frameName, tabX + fm.getLeading() / 2, tabY);
 
 		g.setColor(oldColor);
-		if (!selected) {
-			foreground.dispose();
-			background.dispose();
-		}
 	}
 
 	protected String getSelectionFrameName(final INode node) {
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/AbstractBox.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/AbstractBox.java
index 9b3833a..3e65353 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/AbstractBox.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/AbstractBox.java
@@ -336,11 +336,10 @@
 		final Color backgroundColor = styles.getBackgroundColor();
 
 		if (backgroundColor != null) {
-			final ColorResource color = g.createColor(backgroundColor);
+			final ColorResource color = g.getColor(backgroundColor);
 			final ColorResource oldColor = g.setColor(color);
 			g.fillRect(left, top, right - left, bottom - top);
 			g.setColor(oldColor);
-			color.dispose();
 		}
 
 		if (drawBorders) {
@@ -360,46 +359,42 @@
 
 			// Bottom border
 			if (styles.getBorderBottomWidth() > 0) {
-				final ColorResource color = g.createColor(styles.getBorderBottomColor());
+				final ColorResource color = g.getColor(styles.getBorderBottomColor());
 				final ColorResource oldColor = g.setColor(color);
 				g.setLineStyle(lineStyle(styles.getBorderBottomStyle()));
 				g.setLineWidth(styles.getBorderBottomWidth());
 				g.drawLine(left + bw2, bottom - bw2 - 1, right - bw2, bottom - bw2 - 1);
 				g.setColor(oldColor);
-				color.dispose();
 			}
 
 			// Left border
 			if (hasLeft && styles.getBorderLeftWidth() > 0) {
-				final ColorResource color = g.createColor(styles.getBorderLeftColor());
+				final ColorResource color = g.getColor(styles.getBorderLeftColor());
 				final ColorResource oldColor = g.setColor(color);
 				g.setLineStyle(lineStyle(styles.getBorderLeftStyle()));
 				g.setLineWidth(styles.getBorderLeftWidth());
 				g.drawLine(left + lw2, top + lw2, left + lw2, bottom - lw2 - 1);
 				g.setColor(oldColor);
-				color.dispose();
 			}
 
 			// Right border
 			if (hasRight && styles.getBorderRightWidth() > 0) {
-				final ColorResource color = g.createColor(styles.getBorderRightColor());
+				final ColorResource color = g.getColor(styles.getBorderRightColor());
 				final ColorResource oldColor = g.setColor(color);
 				g.setLineStyle(lineStyle(styles.getBorderRightStyle()));
 				g.setLineWidth(styles.getBorderRightWidth());
 				g.drawLine(right - rw2 - 1, top + rw2, right - rw2 - 1, bottom - rw2 - 1);
 				g.setColor(oldColor);
-				color.dispose();
 			}
 
 			// Top border
 			if (styles.getBorderTopWidth() > 0) {
-				final ColorResource color = g.createColor(styles.getBorderTopColor());
+				final ColorResource color = g.getColor(styles.getBorderTopColor());
 				final ColorResource oldColor = g.setColor(color);
 				g.setLineStyle(lineStyle(styles.getBorderTopStyle()));
 				g.setLineWidth(styles.getBorderTopWidth());
 				g.drawLine(left + tw2, top + tw2, right - tw2, top + tw2);
 				g.setColor(oldColor);
-				color.dispose();
 			}
 
 			// g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/DocumentTextBox.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/DocumentTextBox.java
index 7cc5dad..348167f 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/DocumentTextBox.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/DocumentTextBox.java
@@ -143,11 +143,8 @@
 
 		final FontResource font = g.getFont(styles.getFont());
 		final FontResource oldFont = g.setCurrentFont(font);
-		final ColorResource foreground = g.createColor(styles.getColor());
+		final ColorResource foreground = g.getColor(styles.getColor());
 		final ColorResource oldForeground = g.setColor(foreground);
-		// ColorResource background =
-		// g.createColor(styles.getBackgroundColor());
-		// ColorResource oldBackground = g.setBackgroundColor(background);
 
 		final char[] chars = getText().toCharArray();
 
@@ -194,9 +191,6 @@
 
 		g.setCurrentFont(oldFont);
 		g.setColor(oldForeground);
-		// g.setBackgroundColor(oldBackground);
-		foreground.dispose();
-		// background.dispose();
 	}
 
 	/**
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/DrawableBox.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/DrawableBox.java
index 7b295ef..a20901d 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/DrawableBox.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/DrawableBox.java
@@ -104,7 +104,7 @@
 		}
 
 		final FontResource font = g.getFont(styles.getFont());
-		final ColorResource color = g.createColor(styles.getColor());
+		final ColorResource color = g.getColor(styles.getColor());
 
 		final FontResource oldFont = g.setCurrentFont(font);
 		final ColorResource oldColor = g.setColor(color);
@@ -122,7 +122,6 @@
 
 		g.setCurrentFont(oldFont);
 		g.setColor(oldColor);
-		color.dispose();
 	}
 
 	/**
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/HCaret.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/HCaret.java
index e6f06ff..9710c4a 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/HCaret.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/HCaret.java
@@ -40,11 +40,10 @@
 
 	@Override
 	public void draw(final Graphics g, final Color color) {
-		final ColorResource newColor = g.createColor(color);
+		final ColorResource newColor = g.getColor(color);
 		final ColorResource oldColor = g.setColor(newColor);
 		g.fillRect(getX(), getY(), length, LINE_WIDTH);
 		g.setColor(oldColor);
-		newColor.dispose();
 	}
 
 	/**
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/StaticTextBox.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/StaticTextBox.java
index 97a4ab0..4239496 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/StaticTextBox.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/StaticTextBox.java
@@ -136,7 +136,7 @@
 		}
 
 		final FontResource font = g.getFont(styles.getFont());
-		final ColorResource color = g.createColor(styles.getColor());
+		final ColorResource color = g.getColor(styles.getColor());
 
 		final FontResource oldFont = g.setCurrentFont(font);
 		final ColorResource oldColor = g.setColor(color);
@@ -150,7 +150,6 @@
 
 		g.setCurrentFont(oldFont);
 		g.setColor(oldColor);
-		color.dispose();
 	}
 
 	/**
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/TextCaret.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/TextCaret.java
index fc5d6c2..41075c9 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/TextCaret.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/layout/TextCaret.java
@@ -42,11 +42,10 @@
 
 	@Override
 	public void draw(final Graphics g, final Color color) {
-		final ColorResource newColor = g.createColor(color);
+		final ColorResource newColor = g.getColor(color);
 		final ColorResource oldColor = g.setColor(newColor);
 		g.fillRect(getX(), getY(), LINE_WIDTH, height);
 		g.setColor(oldColor);
-		newColor.dispose();
 	}
 
 	@Override
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/swt/SwtGraphics.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/swt/SwtGraphics.java
index 92afcfd..ac7ada7 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/swt/SwtGraphics.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/swt/SwtGraphics.java
@@ -8,6 +8,7 @@
  * Contributors:
  *     John Krasnay - initial API and implementation
  *     Mohamadou Nassourou - Bug 298912 - rudimentary support for images
+ *     Florian Thienel - font cache, color cache
  *******************************************************************************/
 package org.eclipse.vex.core.internal.widget.swt;
 
@@ -39,13 +40,6 @@
 
 /**
  * Implementation of the Vex Graphics interface, mapping it to a org.eclipse.swt.graphics.GC object.
- *
- * <p>
- * The GC given to us by SWT is that of the Canvas, which is just a viewport into the document. This class therefore
- * implements an "origin", which represents the top-left corner of the document relative to the top-left corner of the
- * canvas. The x- and y-coordinates of the origin are always negative.
- * </p>
- * .
  */
 public class SwtGraphics implements Graphics {
 
@@ -54,13 +48,13 @@
 	private int offsetY;
 
 	private final HashMap<FontSpec, FontResource> fonts = new HashMap<FontSpec, FontResource>();
+	private final HashMap<Color, ColorResource> colors = new HashMap<Color, ColorResource>();
 
 	private SwtFont currentFont;
 	private SwtFontMetrics currentFontMetrics;
+	private int lineStyle = LINE_SOLID;
 
 	/**
-	 * Class constructor.
-	 *
 	 * @param gc
 	 *            SWT GC to which we are drawing.
 	 */
@@ -75,6 +69,10 @@
 			font.dispose();
 		}
 		fonts.clear();
+		for (final ColorResource color : colors.values()) {
+			color.dispose();
+		}
+		colors.clear();
 
 		// TODO should not dispose something that comes from outside!
 		gc.dispose();
@@ -109,7 +107,6 @@
 	@Override
 	public void drawChars(final char[] chars, final int offset, final int length, final int x, final int y) {
 		drawString(new String(chars, offset, length), x, y);
-
 	}
 
 	@Override
@@ -300,7 +297,16 @@
 	}
 
 	@Override
-	public ColorResource createColor(final Color rgb) {
+	public ColorResource getColor(final Color rgb) {
+		ColorResource color = colors.get(rgb);
+		if (color == null) {
+			color = createColor(rgb);
+			colors.put(rgb, color);
+		}
+		return color;
+	}
+
+	private SwtColor createColor(final Color rgb) {
 		return new SwtColor(new org.eclipse.swt.graphics.Color(null, rgb.getRed(), rgb.getGreen(), rgb.getBlue()));
 	}
 
@@ -323,9 +329,7 @@
 			style |= SWT.ITALIC;
 		}
 		final int size = Math.round(fontSpec.getSize() * 72 / 90); // TODO: fix. SWT
-		// uses pts, AWT
-		// uses device
-		// units
+		// uses pts, AWT uses device units
 		final String[] names = fontSpec.getNames();
 		final FontData[] fd = new FontData[names.length];
 		for (int i = 0; i < names.length; i++) {
@@ -351,8 +355,4 @@
 		return gc.stringExtent(s).x;
 	}
 
-	// ========================================================== PRIVATE
-
-	private int lineStyle = LINE_SOLID;
-
 }
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/swt/VexWidget.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/swt/VexWidget.java
index 0b8914b..3da9172 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/swt/VexWidget.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/swt/VexWidget.java
@@ -852,12 +852,11 @@
 				bgColor = new Color(255, 255, 255);
 			}
 
-			final ColorResource color = g.createColor(bgColor);
+			final ColorResource color = g.getColor(bgColor);
 			final ColorResource oldColor = g.setColor(color);
 			final Rectangle r = g.getClipBounds();
 			g.fillRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
 			g.setColor(oldColor);
-			color.dispose();
 
 			impl.paint(g, 0, 0);
 		}