blob: 49cf209d5873855301e3081e389277a893e7ecd9 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2008 Istvan Rath and Daniel Varro
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Istvan Rath - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.editor.text.light;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
import org.eclipse.viatra2.editor.text.Activator;
public class VTEColorProvider
{
private static final RGB RGB_DEFAULT = new RGB(58, 58, 58);
private static final RGB RGB_KEYWORD = new RGB(42, 34, 127);
public static final RGB RGB_STRING = new RGB(255, 0, 42);
public static final RGB RGB_COMMENT = new RGB(63, 127, 95);
protected Map<Object, Color> fColorTable= new HashMap<Object, Color>(10);
public static void initializeDefaults(IPreferenceStore aStore)
{
PreferenceConverter.setDefault(aStore,IVTEConstants.COLOR_DEFAULT, RGB_DEFAULT);
PreferenceConverter.setDefault(aStore,IVTEConstants.COLOR_KEYWORD, RGB_KEYWORD);
PreferenceConverter.setDefault(aStore,IVTEConstants.COLOR_STRING, RGB_STRING);
PreferenceConverter.setDefault(aStore,IVTEConstants.COLOR_COMMENT, RGB_COMMENT);
}
/**
* Release all of the color resources held onto by the receiver.
*/
public void dispose()
{
Iterator<Color> e= fColorTable.values().iterator();
while (e.hasNext())
e.next().dispose();
}
public Color getColor(String aName)
{
Color color = fColorTable.get(aName);
if (color == null) {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
RGB rgb = PreferenceConverter.getColor(store,
IVTEConstants.PREFIX_COLOR + aName);
if (rgb != null)
{
color = new Color(Display.getCurrent(), rgb);
}
else
{
color = Display.getCurrent().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
}
fColorTable.put(aName, color);
fColorTable.put(rgb, color);
}
return color;
}
public Color getColor(RGB rgb) {
Color color = fColorTable.get(rgb);
if (color == null) {
color = new Color(Display.getCurrent(), rgb);
fColorTable.put(rgb, color);
}
return color;
}
}