1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 14:12:10 +02:00

Bug 341545 - [Accessibility] Traditional memory rendering uses colour to

convey information

Change-Id: I8127a026a3d6abb0291e35f606c622b1fa92ac2f
Reviewed-on: https://git.eclipse.org/r/11133
IP-Clean: Chris Recoskie <recoskie@ca.ibm.com>
Reviewed-by: Jesse Weinstein <Jesse.Weinstein@clinicomp.com>
Reviewed-by: Chris Recoskie <recoskie@ca.ibm.com>
Tested-by: Chris Recoskie <recoskie@ca.ibm.com>
This commit is contained in:
Mike Kucera 2013-03-13 16:37:34 -04:00 committed by Chris Recoskie
parent 07fcd9213c
commit d11a8c4902
9 changed files with 341 additions and 95 deletions

View file

@ -837,4 +837,35 @@ public abstract class AbstractPane extends Canvas
}
return fTextHeight;
}
protected boolean shouldDrawBox(TraditionalMemoryByte bytes[], int col)
{
TraditionalRendering ren = fRendering.getTraditionalRendering();
if (ren.getBoxEdit())
{
for (TraditionalMemoryByte tmb : bytes)
{
if (tmb.isEdited())
{
return true;
}
}
}
if (ren.getBoxChanged())
{
for (int i = 0; i < fRendering.getHistoryDepth(); i++)
{
for (TraditionalMemoryByte tmb : bytes)
{
if (tmb.isChanged(i))
{
return true;
}
}
}
}
return false;
}
}

View file

@ -0,0 +1,99 @@
/*******************************************************************************
* Copyright (c) 2013 IBM Corporation and others.
* 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:
* IBM - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.ui.memory.traditional;
import org.eclipse.jface.preference.ColorSelector;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
public class ColorAndEffectFieldEditor extends FieldEditor {
private final String nameBold;
private final String nameItalic;
private final String nameBox;
private ColorSelector colorSelector;
private Button checkBold;
private Button checkItalic;
private Button checkBox; // :)
public ColorAndEffectFieldEditor(String name, String nameBold, String nameItalic, String nameBox, String labelText, Composite parent) {
super(name, labelText, parent);
this.nameBold = nameBold;
this.nameItalic = nameItalic;
this.nameBox = nameBox;
}
@Override
protected void adjustForNumColumns(int numColumns) {
((GridData) checkItalic.getLayoutData()).horizontalSpan = numColumns - 4;
}
@Override
protected void doFillIntoGrid(Composite parent, int numColumns) {
Control control = getLabelControl(parent);
control.setLayoutData(new GridData());
colorSelector = new ColorSelector(parent);
colorSelector.getButton().setLayoutData(new GridData());
checkBold = new Button(parent, SWT.CHECK);
checkBold.setText(TraditionalRenderingMessages.getString("ColorAndEffectFieldEditor.bold"));
checkBold.setLayoutData(new GridData());
checkItalic = new Button(parent, SWT.CHECK);
checkItalic.setText(TraditionalRenderingMessages.getString("ColorAndEffectFieldEditor.italic"));
checkItalic.setLayoutData(new GridData());
checkBox = new Button(parent, SWT.CHECK);
checkBox.setText(TraditionalRenderingMessages.getString("ColorAndEffectFieldEditor.box"));
checkBox.setLayoutData(new GridData());
}
@Override
protected void doLoad() {
IPreferenceStore store = getPreferenceStore();
colorSelector.setColorValue(PreferenceConverter.getColor(store, getPreferenceName()));
checkBold.setSelection(store.getBoolean(nameBold));
checkItalic.setSelection(store.getBoolean(nameItalic));
checkBox.setSelection(store.getBoolean(nameBox));
}
@Override
protected void doLoadDefault() {
IPreferenceStore store = getPreferenceStore();
colorSelector.setColorValue(PreferenceConverter.getDefaultColor(store, getPreferenceName()));
checkBold.setSelection(store.getDefaultBoolean(nameBold));
checkItalic.setSelection(store.getDefaultBoolean(nameItalic));
checkBox.setSelection(store.getDefaultBoolean(nameBox));
}
@Override
protected void doStore() {
IPreferenceStore store = getPreferenceStore();
PreferenceConverter.setValue(store, getPreferenceName(), colorSelector.getColorValue());
store.setValue(nameBold, checkBold.getSelection());
store.setValue(nameItalic, checkItalic.getSelection());
store.setValue(nameBox, checkBox.getSelection());
}
@Override
public int getNumberOfControls() {
return 5;
}
}

View file

@ -256,7 +256,6 @@ public class DataPane extends AbstractPane
protected void doPaintData(PaintEvent pe)
{
GC gc = pe.gc;
gc.setFont(fRendering.getFont());
int cellHeight = getCellHeight();
int cellWidth = getCellWidth();
@ -271,10 +270,12 @@ public class DataPane extends AbstractPane
{
for(int col = 0; col < columns; col++)
{
if(isOdd(col))
gc.setForeground(fRendering.getTraditionalRendering().getColorText());
else
gc.setForeground(fRendering.getTraditionalRendering().getColorTextAlternate());
gc.setFont(fRendering.getFont());
if (isOdd(col))
gc.setForeground(fRendering.getTraditionalRendering().getColorText());
else
gc.setForeground(fRendering.getTraditionalRendering().getColorTextAlternate());
BigInteger cellAddress = start.add(BigInteger.valueOf((i
* fRendering.getColumnCount() + col)
@ -283,6 +284,8 @@ public class DataPane extends AbstractPane
TraditionalMemoryByte bytes[] = fRendering.getBytes(cellAddress,
fRendering.getBytesPerColumn());
boolean drawBox = false;
if(fRendering.getSelection().isSelected(cellAddress))
{
gc.setBackground(fRendering.getTraditionalRendering().getColorSelection());
@ -301,12 +304,19 @@ public class DataPane extends AbstractPane
// Allow subclasses to override this method to do their own coloring
applyCustomColor(gc, bytes, col);
drawBox = shouldDrawBox(bytes, col);
}
gc.drawText(getCellText(bytes), cellWidth * col
+ fRendering.getCellPadding(), cellHeight * i
+ fRendering.getCellPadding());
if(drawBox)
{
gc.setForeground(fRendering.getTraditionalRendering().getColorTextAlternate());
gc.drawRectangle(cellWidth * col, cellHeight * i, cellWidth, cellHeight-1);
}
BigInteger cellEndAddress = cellAddress.add(BigInteger
.valueOf(fRendering.getAddressesPerColumn()));
cellEndAddress = cellEndAddress.subtract(BigInteger
@ -340,50 +350,55 @@ public class DataPane extends AbstractPane
fRendering.logError(TraditionalRenderingMessages
.getString("TraditionalRendering.FAILURE_PAINT"), e); //$NON-NLS-1$
}
}
// Allow subclasses to override this method to do their own coloring
protected void applyCustomColor(GC gc, TraditionalMemoryByte bytes[], int col)
// Allow subclasses to override this method to do their own coloring
protected void applyCustomColor(GC gc, TraditionalMemoryByte bytes[], int col)
{
// TODO consider adding finer granularity?
boolean anyByteEditing = false;
for(int n = 0; n < bytes.length && !anyByteEditing; n++)
if(bytes[n] instanceof TraditionalMemoryByte)
if(bytes[n].isEdited())
anyByteEditing = true;
if(isOdd(col))
gc.setForeground(fRendering.getTraditionalRendering().getColorText());
else
gc.setForeground(fRendering.getTraditionalRendering().getColorTextAlternate());
gc.setBackground(fRendering.getTraditionalRendering().getColorBackground());
if(anyByteEditing)
// TODO consider adding finer granularity?
boolean anyByteEditing = false;
for (int n = 0; n < bytes.length && !anyByteEditing; n++)
if (bytes[n] instanceof TraditionalMemoryByte)
if (bytes[n].isEdited())
anyByteEditing = true;
TraditionalRendering ren = fRendering.getTraditionalRendering();
if (isOdd(col))
gc.setForeground(ren.getColorText());
else
gc.setForeground(ren.getColorTextAlternate());
gc.setBackground(ren.getColorBackground());
if (anyByteEditing)
{
gc.setForeground(fRendering.getTraditionalRendering().getColorEdit());
gc.setForeground(ren.getColorEdit());
gc.setFont(ren.getFontEdit(gc.getFont()));
}
else
{
boolean isColored = false;
for(int i = 0; i < fRendering.getHistoryDepth() && !isColored; i++)
{
// TODO consider adding finer granularity?
for(int n = 0; n < bytes.length; n++)
{
if(bytes[n].isChanged(i))
{
if(i == 0)
gc.setForeground(fRendering.getTraditionalRendering().getColorsChanged()[i]);
else
gc.setBackground(fRendering.getTraditionalRendering().getColorsChanged()[i]);
isColored = true;
break;
}
}
}
boolean isColored = false;
for (int i = 0; i < fRendering.getHistoryDepth() && !isColored; i++)
{
// TODO consider adding finer granularity?
for (int n = 0; n < bytes.length; n++)
{
if (bytes[n].isChanged(i))
{
if (i == 0)
gc.setForeground(ren.getColorsChanged()[i]);
else
gc.setBackground(ren.getColorsChanged()[i]);
gc.setFont(ren.getFontChanged(gc.getFont()));
isColored = true;
break;
}
}
}
}
}
}

View file

@ -242,10 +242,12 @@ public class TextPane extends AbstractPane
{
for(int col = 0; col < columns; col++)
{
if(isOdd(col))
gc.setForeground(fRendering.getTraditionalRendering().getColorText());
else
gc.setForeground(fRendering.getTraditionalRendering().getColorTextAlternate());
gc.setFont(fRendering.getFont());
if (isOdd(col))
gc.setForeground(fRendering.getTraditionalRendering().getColorText());
else
gc.setForeground(fRendering.getTraditionalRendering().getColorTextAlternate());
BigInteger cellAddress = start.add(BigInteger.valueOf((i
* columns + col)
@ -254,6 +256,8 @@ public class TextPane extends AbstractPane
TraditionalMemoryByte bytes[] = fRendering.getBytes(cellAddress,
fRendering.getBytesPerColumn());
boolean drawBox = false;
if(fRendering.getSelection().isSelected(cellAddress))
{
gc.setBackground(fRendering.getTraditionalRendering().getColorSelection());
@ -269,12 +273,19 @@ public class TextPane extends AbstractPane
cellWidth, cellHeight);
applyCustomColor(gc, bytes, col);
drawBox = shouldDrawBox(bytes, col);
}
gc.drawText(fRendering.formatText(bytes,
isLittleEndian, fRendering.getTextMode()), cellWidth * col, cellHeight * i
+ fRendering.getCellPadding());
if(drawBox)
{
gc.setForeground(fRendering.getTraditionalRendering().getColorTextAlternate());
gc.drawRectangle(cellWidth * col - (col == 0 ? 0 : 1), cellHeight * i, cellWidth - (col == 0 ? 1 : 0), cellHeight-1);
}
if(fRendering.isDebug())
gc.drawRectangle(cellWidth * col, cellHeight * i
+ fRendering.getCellPadding(), cellWidth,
@ -292,44 +303,50 @@ public class TextPane extends AbstractPane
// Allow subclasses to override this method to do their own coloring
protected void applyCustomColor(GC gc, TraditionalMemoryByte bytes[], int col)
{
// TODO consider adding finer granularity?
{
// TODO consider adding finer granularity?
boolean anyByteEditing = false;
for(int n = 0; n < bytes.length && !anyByteEditing; n++)
if(bytes[n] instanceof TraditionalMemoryByte)
if(bytes[n].isEdited())
anyByteEditing = true;
if(isOdd(col))
gc.setForeground(fRendering.getTraditionalRendering().getColorText());
else
gc.setForeground(fRendering.getTraditionalRendering().getColorTextAlternate());
gc.setBackground(fRendering.getTraditionalRendering().getColorBackground());
if(anyByteEditing)
{
gc.setForeground(fRendering.getTraditionalRendering().getColorEdit());
}
else
{
boolean isColored = false;
for(int i = 0; i < fRendering.getHistoryDepth() && !isColored; i++)
{
// TODO consider adding finer granularity?
for(int n = 0; n < bytes.length; n++)
{
if(bytes[n].isChanged(i))
{
if(i == 0)
gc.setForeground(fRendering.getTraditionalRendering().getColorsChanged()[i]);
else
gc.setBackground(fRendering.getTraditionalRendering().getColorsChanged()[i]);
isColored = true;
break;
}
}
}
}
}
for (int n = 0; n < bytes.length && !anyByteEditing; n++)
if (bytes[n] instanceof TraditionalMemoryByte)
if (bytes[n].isEdited())
anyByteEditing = true;
TraditionalRendering ren = fRendering.getTraditionalRendering();
if (isOdd(col))
gc.setForeground(ren.getColorText());
else
gc.setForeground(ren.getColorTextAlternate());
gc.setBackground(ren.getColorBackground());
if (anyByteEditing)
{
gc.setForeground(ren.getColorEdit());
gc.setFont(ren.getFontEdit(gc.getFont()));
}
else
{
boolean isColored = false;
for (int i = 0; i < fRendering.getHistoryDepth() && !isColored; i++)
{
// TODO consider adding finer granularity?
for (int n = 0; n < bytes.length; n++)
{
if (bytes[n].isChanged(i))
{
if (i == 0)
gc.setForeground(ren.getColorsChanged()[i]);
else
gc.setBackground(ren.getColorsChanged()[i]);
gc.setFont(ren.getFontChanged(gc.getFont()));
isColored = true;
break;
}
}
}
}
}
}

View file

@ -13,6 +13,8 @@ package org.eclipse.cdt.debug.ui.memory.traditional;
import java.lang.reflect.Method;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.debug.core.model.provisional.IMemoryRenderingViewportProvider;
import org.eclipse.core.commands.AbstractHandler;
@ -65,6 +67,8 @@ import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
@ -240,6 +244,7 @@ public class TraditionalRendering extends AbstractMemoryRendering implements IRe
if(this.fRendering != null)
this.fRendering.dispose();
disposeColors();
disposeFonts();
super.dispose();
}
@ -494,6 +499,8 @@ public class TraditionalRendering extends AbstractMemoryRendering implements IRe
private Color colorText;
private Color colorTextAlternate;
private Map<Integer,Font> fonts = new HashMap<Integer,Font>(3);
public void allocateColors()
{
IPreferenceStore store = TraditionalRenderingPlugin.getDefault().getPreferenceStore();
@ -558,6 +565,12 @@ public class TraditionalRendering extends AbstractMemoryRendering implements IRe
disposeChangedColors();
}
public void disposeFonts()
{
for (Font font : fonts.values())
font.dispose();
}
public void applyPreferences()
{
if(fRendering != null && !fRendering.isDisposed())
@ -578,6 +591,53 @@ public class TraditionalRendering extends AbstractMemoryRendering implements IRe
}
}
private Font makeFont(Font font, String boldKey, String italicKey)
{
IPreferenceStore store = TraditionalRenderingPlugin.getDefault().getPreferenceStore();
int style = SWT.NONE;
if (store.getBoolean(boldKey))
style |= SWT.BOLD;
if (store.getBoolean(italicKey))
style |= SWT.ITALIC;
if (style == SWT.NONE)
return font;
Font modified = fonts.get(style);
if (modified == null)
{
FontData fontData = font.getFontData()[0];
modified = new Font(font.getDevice(), fontData.getName(), fontData.getHeight(), fontData.getStyle() | style);
fonts.put(style, modified);
}
return modified;
}
public Font getFontChanged(Font font)
{
return makeFont(font, TraditionalRenderingPreferenceConstants.MEM_COLOR_CHANGED_BOLD,
TraditionalRenderingPreferenceConstants.MEM_COLOR_CHANGED_ITALIC);
}
public Font getFontEdit(Font font)
{
return makeFont(font, TraditionalRenderingPreferenceConstants.MEM_COLOR_EDIT_BOLD,
TraditionalRenderingPreferenceConstants.MEM_COLOR_EDIT_ITALIC);
}
public boolean getBoxChanged()
{
IPreferenceStore store = TraditionalRenderingPlugin.getDefault().getPreferenceStore();
return store.getBoolean(TraditionalRenderingPreferenceConstants.MEM_COLOR_CHANGED_BOX);
}
public boolean getBoxEdit()
{
IPreferenceStore store = TraditionalRenderingPlugin.getDefault().getPreferenceStore();
return store.getBoolean(TraditionalRenderingPreferenceConstants.MEM_COLOR_EDIT_BOX);
}
public Color getColorBackground()
{
IPreferenceStore store = TraditionalRenderingPlugin.getDefault().getPreferenceStore();

View file

@ -17,13 +17,20 @@ package org.eclipse.cdt.debug.ui.memory.traditional;
public class TraditionalRenderingPreferenceConstants {
public static final String MEM_COLOR_CHANGED = "memoryColorChanged";
public static final String MEM_COLOR_CHANGED_ITALIC = "memoryColorChanged.italic";
public static final String MEM_COLOR_CHANGED_BOLD = "memoryColorChanged.bold";
public static final String MEM_COLOR_CHANGED_BOX = "memoryColorChanged.box";
public static final String MEM_COLOR_EDIT = "memoryColorEdit";
public static final String MEM_COLOR_EDIT_ITALIC = "memoryColorEdit.italic";
public static final String MEM_COLOR_EDIT_BOLD = "memoryColorEdit.bold";
public static final String MEM_COLOR_EDIT_BOX = "memoryColorEdit.box";
public static final String MEM_USE_GLOBAL_BACKGROUND = "memUseGlobalBackground";
public static final String MEM_COLOR_BACKGROUND = "memoryColorBackground";
public static final String MEM_COLOR_EDIT = "memoryColorEdit";
public static final String MEM_COLOR_TEXT = "memoryColorText";
public static final String MEM_USE_GLOBAL_SELECTION = "memUseGlobalSelection";

View file

@ -38,6 +38,14 @@ public class TraditionalRenderingPreferenceInitializer extends AbstractPreferenc
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_USE_GLOBAL_SELECTION, true);
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_COLOR_CHANGED, "255,0,0");
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_COLOR_CHANGED_ITALIC, false);
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_COLOR_CHANGED_BOLD, false);
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_COLOR_CHANGED_BOX, true);
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_COLOR_EDIT, "0,255,0");
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_COLOR_EDIT_ITALIC, true);
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_COLOR_EDIT_BOLD, false);
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_COLOR_EDIT_BOX, true);
Color systemSelection = Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION);
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_COLOR_SELECTION, systemSelection.getRed()
@ -45,8 +53,6 @@ public class TraditionalRenderingPreferenceInitializer extends AbstractPreferenc
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_LIGHTEN_DARKEN_ALTERNATE_CELLS, "5");
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_COLOR_EDIT, "0,255,0");
Color systemText = Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
store.setDefault(TraditionalRenderingPreferenceConstants.MEM_COLOR_TEXT, systemText.getRed()
+ "," + systemText.getGreen() + "," + systemText.getBlue());

View file

@ -76,13 +76,21 @@ public class TraditionalRenderingPreferencePage
addField(new ColorFieldEditor(TraditionalRenderingPreferenceConstants.MEM_COLOR_BACKGROUND,
TraditionalRenderingMessages.getString("TraditionalRenderingPreferencePage_BackgroundColor"), getFieldEditorParent())); //$NON-NLS-1$
addField(new ColorFieldEditor(TraditionalRenderingPreferenceConstants.MEM_COLOR_CHANGED,
TraditionalRenderingMessages.getString("TraditionalRenderingPreferencePage_ChangedColor"), getFieldEditorParent())); //$NON-NLS-1$
addField(new ColorFieldEditor(TraditionalRenderingPreferenceConstants.MEM_COLOR_EDIT,
TraditionalRenderingMessages.getString("TraditionalRenderingPreferencePage_EditColor"), getFieldEditorParent())); //$NON-NLS-1$
addField(new ColorAndEffectFieldEditor(TraditionalRenderingPreferenceConstants.MEM_COLOR_CHANGED,
TraditionalRenderingPreferenceConstants.MEM_COLOR_CHANGED_BOLD,
TraditionalRenderingPreferenceConstants.MEM_COLOR_CHANGED_ITALIC,
TraditionalRenderingPreferenceConstants.MEM_COLOR_CHANGED_BOX,
TraditionalRenderingMessages.getString("TraditionalRenderingPreferencePage_ChangedColor"), //$NON-NLS-1$
getFieldEditorParent()));
addField(new ColorAndEffectFieldEditor(TraditionalRenderingPreferenceConstants.MEM_COLOR_EDIT,
TraditionalRenderingPreferenceConstants.MEM_COLOR_EDIT_BOLD,
TraditionalRenderingPreferenceConstants.MEM_COLOR_EDIT_ITALIC,
TraditionalRenderingPreferenceConstants.MEM_COLOR_EDIT_BOX,
TraditionalRenderingMessages.getString("TraditionalRenderingPreferencePage_EditColor"), //$NON-NLS-1$
getFieldEditorParent()));
addField(new BooleanFieldEditor(TraditionalRenderingPreferenceConstants.MEM_USE_GLOBAL_SELECTION,
TraditionalRenderingMessages.getString("TraditionalRenderingPreferencePage_UseGlobalSelectionColor"), getFieldEditorParent())); //$NON-NLS-1$

View file

@ -83,3 +83,6 @@ TraditionalRenderingPreferencePage_TextColor=&Text Color:
TraditionalRenderingPreferencePage_UseGlobalBackgroundColor=Use Global B&ackground Color
TraditionalRenderingPreferencePage_UseGlobalSelectionColor=Use Global Se&lection Color
TraditionalRenderingPreferencePage_UseGlobalTextColor=Use Global Te&xt Color
ColorAndEffectFieldEditor.bold=Bold
ColorAndEffectFieldEditor.italic=Italic
ColorAndEffectFieldEditor.box=Box