/*
 * Copyright 2013 Palantir Technologies, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.palantir.typescript.text;

import java.util.Map;

import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;

import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;

/**
 * Converts RGB values into Colors.
 *
 * @author tyleradams
 */
public final class ColorManager {

    private final Map<RGB, Color> colorTable = Maps.newHashMap();

    public Color getColor(RGB rgb) {
        Preconditions.checkNotNull(rgb);

        Color color = this.colorTable.get(rgb);
        if (color == null) {
            color = new Color(Display.getCurrent(), rgb);
            this.colorTable.put(rgb, color);
        }

        return color;
    }

    public void dispose() {
        for (Color color : this.colorTable.values()) {
            color.dispose();
        }
    }
}

@@ -655,21 +655,64 @@
 ort 
-java.util.Map
+static com.google.common.base.Preconditions.checkNotNull
 ;%0A%0Ai
@@ -856,101 +856,168 @@
 mon.
-base.Preconditions;%0Aimport com.google.common.collect.Maps;%0A%0A/**%0A * Converts RGB values into C
+cache.CacheBuilder;%0Aimport com.google.common.cache.CacheLoader;%0Aimport com.google.common.cache.LoadingCache;%0A%0A/**%0A * The color manager creates and disposes of c
 olor
@@ -1101,19 +1101,28 @@
 e final 
-Map
+LoadingCache
 %3CRGB, Co
@@ -1135,189 +1135,145 @@
 olor
-Table = Maps.newHashMap();%0A%0A    public Color getColor(RGB rgb) %7B%0A        Preconditions.checkNotNull(rgb);%0A%0A        Color color = this.colorTable.get(rgb);%0A        if (color == null)
+s = CacheBuilder.newBuilder().build(new CacheLoader%3CRGB, Color%3E() %7B%0A        @Override%0A        public Color load(RGB rgb) throws Exception
  %7B%0A 
@@ -1287,15 +1287,14 @@
     
-color =
+return
  new
@@ -1340,76 +1340,128 @@
     
+%7D%0A
     
-this.colorTable.put(rgb, color);%0A        %7D%0A%0A        return color
+%7D);%0A%0A    public Color getColor(RGB rgb) %7B%0A        checkNotNull(rgb);%0A%0A        return this.colors.getUnchecked(rgb)
 ;%0A  
@@ -1534,13 +1534,17 @@
 olor
-Table
+s.asMap()
 .val

Use a cache for the colors