diff --git a/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100Emulator.java b/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100Emulator.java index bf7d66fe267..06dcba26fb4 100644 --- a/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100Emulator.java +++ b/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100Emulator.java @@ -13,6 +13,7 @@ * Contributors: * Michael Scharf (Wind River) - split into core, view and connector plugins * Martin Oberhuber (Wind River) - fixed copyright headers and beautified + * Michael Scharf (Wind River) - [209746] There are cases where some colors not displayed correctly *******************************************************************************/ package org.eclipse.tm.internal.terminal.emulator; @@ -777,7 +778,7 @@ public class VT100Emulator implements ControlListener { break; case 37: - text.setStyle(style.setForground("WHITE")); //$NON-NLS-1$ + text.setStyle(style.setForground("WHITE_FOREGROUND")); //$NON-NLS-1$ break; case 40: diff --git a/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/textcanvas/StyleMap.java b/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/textcanvas/StyleMap.java index 288158231e0..cad496038d4 100644 --- a/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/textcanvas/StyleMap.java +++ b/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/textcanvas/StyleMap.java @@ -7,6 +7,7 @@ * * Contributors: * Michael Scharf (Wind River) - initial API and implementation + * Michael Scharf (Wind River) - [209746] There are cases where some colors not displayed correctly *******************************************************************************/ package org.eclipse.tm.internal.terminal.textcanvas; @@ -14,6 +15,7 @@ import java.util.HashMap; import java.util.Map; import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.GC; @@ -26,6 +28,7 @@ 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 WHITE_FOREGROUND = "white_foreground"; //$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$ @@ -37,76 +40,102 @@ public class StyleMap { private static final String PREFIX = "org.eclipse.tm.internal."; //$NON-NLS-1$ // TODO propagate the name of the font in the FontRegistry String fFontName="terminal.views.view.font.definition"; //$NON-NLS-1$ - Map fColorMap=new HashMap(); + Map fColorMapForeground=new HashMap(); + Map fColorMapBackground=new HashMap(); Map fFontMap=new HashMap(); private Point fCharSize; - private Style fDefaultStyle; + private final Style fDefaultStyle; private boolean fInvertColors; private boolean fProportional; private final int[] fOffsets=new int[256]; StyleMap() { - 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); + initColors(); fDefaultStyle=Style.getStyle(StyleColor.getStyleColor(BLACK),StyleColor.getStyleColor(WHITE)); updateFont(); } - private void addColor(String name, int r, int g, int b) { - String colorName=PREFIX+name; + private void initColors() { + initForegroundColors(); + initBackgroundColors(); + } + private void initForegroundColors() { + if(fInvertColors) { + setColor(fColorMapForeground, WHITE, 0, 0, 0); + setColor(fColorMapForeground, WHITE_FOREGROUND, 50, 50, 50); + setColor(fColorMapForeground, BLACK, 255, 255, 255); + } else { + setColor(fColorMapForeground, WHITE, 255, 255, 255); + setColor(fColorMapForeground, WHITE_FOREGROUND, 229, 229, 229); + setColor(fColorMapForeground, BLACK, 0, 0, 0); + } + setColor(fColorMapForeground, RED, 255, 128, 128); + setColor(fColorMapForeground, GREEN, 128, 255, 128); + setColor(fColorMapForeground, BLUE, 128, 128, 255); + setColor(fColorMapForeground, YELLOW, 255, 255, 0); + setColor(fColorMapForeground, CYAN, 0, 255, 255); + setColor(fColorMapForeground, MAGENTA, 255, 255, 0); + setColor(fColorMapForeground, GRAY, 128, 128, 128); + } + + private void initBackgroundColors() { + if(fInvertColors) { + setColor(fColorMapBackground, WHITE, 0, 0, 0); + setColor(fColorMapBackground, WHITE_FOREGROUND, 50, 50, 50); // only used when colors are inverse + setColor(fColorMapBackground, BLACK, 255, 255, 255); + } else { + setColor(fColorMapBackground, WHITE, 255, 255, 255); + setColor(fColorMapBackground, WHITE_FOREGROUND, 229, 229, 229); + setColor(fColorMapBackground, BLACK, 0, 0, 0); + } + setColor(fColorMapBackground, RED, 255, 128, 128); + setColor(fColorMapBackground, GREEN, 128, 255, 128); + setColor(fColorMapBackground, BLUE, 128, 128, 255); + setColor(fColorMapBackground, YELLOW, 255, 255, 0); + setColor(fColorMapBackground, CYAN, 0, 255, 255); + setColor(fColorMapBackground, MAGENTA, 255, 255, 0); + setColor(fColorMapBackground, GRAY, 128, 128, 128); + } + private void setColor(Map colorMap, String name, int r, int g, int b) { + String colorName=PREFIX+r+"-"+g+"-"+b; //$NON-NLS-1$//$NON-NLS-2$ 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); + colorMap.put(StyleColor.getStyleColor(name), color); + colorMap.put(StyleColor.getStyleColor(name.toUpperCase()), color); } + public Color getForegrondColor(Style style) { style = defaultIfNull(style); if(style.isReverse()) - return getColor(style.getBackground()); + return getColor(fColorMapForeground,style.getBackground()); else - return getColor(style.getForground()); + return getColor(fColorMapForeground,style.getForground()); + } + public Color getBackgroundColor(Style style) { + style = defaultIfNull(style); + if(style.isReverse()) + return getColor(fColorMapBackground,style.getForground()); + else + return getColor(fColorMapBackground,style.getBackground()); + } + Color getColor(Map map,StyleColor color) { + Color c=(Color) map.get(color); + if(c==null) { + c=Display.getCurrent().getSystemColor(SWT.COLOR_GRAY); + } + return c; } private Style defaultIfNull(Style style) { if(style==null) style=fDefaultStyle; return style; } - public Color getBackgroundColor(Style style) { - style = defaultIfNull(style); - if(style.isReverse()) - return getColor(style.getForground()); - else - return getColor(style.getBackground()); - } 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); - + initColors(); } // static Font getBoldFont(Font font) { // FontData fontDatas[] = font.getFontData();