1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-27 02:45:32 +02:00

bug 206218: [terminal] Terminal instances should use shared colors

https://bugs.eclipse.org/bugs/show_bug.cgi?id=206218
This commit is contained in:
Michael Scharf 2007-10-13 03:18:46 +00:00
parent fb49a4b183
commit 7fa5d0ab1e

View file

@ -18,47 +18,58 @@ import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
import org.eclipse.tm.terminal.model.Style;
import org.eclipse.tm.terminal.model.StyleColor;
public class StyleMap {
private static final String BLACK = "black"; //$NON-NLS-1$
private static final String WHITE = "white"; //$NON-NLS-1$
private static final String GRAY = "gray"; //$NON-NLS-1$
private static final String MAGENTA = "magenta"; //$NON-NLS-1$
private static final String CYAN = "cyan"; //$NON-NLS-1$
private static final String YELLOW = "yellow"; //$NON-NLS-1$
private static final String BLUE = "blue"; //$NON-NLS-1$
private static final String GREEN = "green"; //$NON-NLS-1$
private static final String RED = "red"; //$NON-NLS-1$
private static final String PREFIX = "org.eclipse.tm.internal."; //$NON-NLS-1$
// TODO propagate the name of the fonf in the FontRegistry
String fFontName="terminal.views.view.font.definition"; //$NON-NLS-1$
Map fColorMap=new HashMap();
Map fFontMap=new HashMap();
private Point fCharSize;
private final Style fDefaultStyle;
private Style fDefaultStyle;
private boolean fInvertColors;
StyleMap() {
Display display=Display.getCurrent();
fColorMap.put(StyleColor.getStyleColor("white"), new Color(display,255,255,255)); //$NON-NLS-1$
fColorMap.put(StyleColor.getStyleColor("black"), new Color(display,0,0,0)); //$NON-NLS-1$
fColorMap.put(StyleColor.getStyleColor("red"), new Color(display,255,128,128)); //$NON-NLS-1$
fColorMap.put(StyleColor.getStyleColor("green"), new Color(display,128,255,128)); //$NON-NLS-1$
fColorMap.put(StyleColor.getStyleColor("blue"), new Color(display,128,128,255)); //$NON-NLS-1$
fColorMap.put(StyleColor.getStyleColor("yellow"), new Color(display,255,255,0)); //$NON-NLS-1$
fColorMap.put(StyleColor.getStyleColor("cyan"), new Color(display,0,255,255)); //$NON-NLS-1$
fColorMap.put(StyleColor.getStyleColor("magenta"), new Color(display,255,255,0)); //$NON-NLS-1$
fColorMap.put(StyleColor.getStyleColor("gray"), new Color(display,128,128,128)); //$NON-NLS-1$
fColorMap.put(StyleColor.getStyleColor("WHITE"), new Color(display,255,255,255)); //$NON-NLS-1$
fColorMap.put(StyleColor.getStyleColor("BLACK"), new Color(display,0,0,0)); //$NON-NLS-1$
fColorMap.put(StyleColor.getStyleColor("RED"), new Color(display,255,128,128)); //$NON-NLS-1$
fColorMap.put(StyleColor.getStyleColor("GREEN"), new Color(display,128,255,128)); //$NON-NLS-1$
fColorMap.put(StyleColor.getStyleColor("BLUE"), new Color(display,128,128,255)); //$NON-NLS-1$
fColorMap.put(StyleColor.getStyleColor("YELLOW"), new Color(display,255,255,0)); //$NON-NLS-1$
fColorMap.put(StyleColor.getStyleColor("CYAN"), new Color(display,0,255,255)); //$NON-NLS-1$
fColorMap.put(StyleColor.getStyleColor("MAGENTA"), new Color(display,255,255,0)); //$NON-NLS-1$
fColorMap.put(StyleColor.getStyleColor("GRAY"), new Color(display,128,128,128)); //$NON-NLS-1$
fDefaultStyle=Style.getStyle(StyleColor.getStyleColor("black"),StyleColor.getStyleColor("white")); //$NON-NLS-1$ //$NON-NLS-2$
addColor(WHITE, 255,255,255);
addColor(BLACK, 0,0,0);
addColor(RED, 255,128,128);
addColor(GREEN, 128,255,128);
addColor(BLUE, 128,128,255);
addColor(YELLOW, 255,255,0);
addColor(CYAN, 0,255,255);
addColor(MAGENTA, 255,255,0);
addColor(GRAY, 128,128,128);
updateFont();
}
private void addColor(String name, int r, int g, int b) {
String colorName=PREFIX+name;
Color color=JFaceResources.getColorRegistry().get(colorName);
if(color==null) {
JFaceResources.getColorRegistry().put(colorName, new RGB(r,g,b));
color=JFaceResources.getColorRegistry().get(colorName);
}
fColorMap.put(StyleColor.getStyleColor(name), color);
fColorMap.put(StyleColor.getStyleColor(name.toUpperCase()), color);
}
public Color getColor(StyleColor colorName) {
return (Color) fColorMap.get(colorName);
}
public Color getForegrondColor(Style style) {
style = defaultIfNull(style);
if(isReverse(style))
if(style.isReverse())
return getColor(style.getBackground());
else
return getColor(style.getForground());
@ -70,21 +81,29 @@ public class StyleMap {
}
public Color getBackgroundColor(Style style) {
style = defaultIfNull(style);
if(isReverse(style))
if(style.isReverse())
return getColor(style.getForground());
else
return getColor(style.getBackground());
}
private boolean isReverse(Style style) {
if(fInvertColors)
return !style.isReverse();
else
return style.isReverse();
}
public void setInvertedColors(boolean invert) {
if(invert==fInvertColors)
return;
fInvertColors=invert;
swapColors(WHITE,BLACK);
fDefaultStyle=Style.getStyle(StyleColor.getStyleColor(BLACK),StyleColor.getStyleColor(WHITE));
}
void swapColors(String n1, String n2) {
swapColors2(n1, n2);
swapColors2(n1.toUpperCase(), n2.toUpperCase());
}
void swapColors2(String n1, String n2) {
Color c1=getColor(StyleColor.getStyleColor(n1));
Color c2=getColor(StyleColor.getStyleColor(n2));
fColorMap.put(StyleColor.getStyleColor(n1), c2);
fColorMap.put(StyleColor.getStyleColor(n2), c1);
}
// static Font getBoldFont(Font font) {
// FontData fontDatas[] = font.getFontData();