use of org.eclipse.swt.accessibility.AccessibleEvent in project tdi-studio-se by Talend.
the class ColorCombo method initAccessible.
void initAccessible() {
AccessibleAdapter accessibleAdapter = new AccessibleAdapter() {
@Override
public void getName(AccessibleEvent e) {
String name = null;
Label label = getAssociatedLabel();
if (label != null) {
name = stripMnemonic(label.getText());
}
e.result = name;
}
@Override
public void getKeyboardShortcut(AccessibleEvent e) {
String shortcut = null;
Label label = getAssociatedLabel();
if (label != null) {
String text = label.getText();
if (text != null) {
char mnemonic = _findMnemonic(text);
if (mnemonic != '\0') {
//$NON-NLS-1$
shortcut = "Alt+" + mnemonic;
}
}
}
e.result = shortcut;
}
@Override
public void getHelp(AccessibleEvent e) {
e.result = getToolTipText();
}
};
getAccessible().addAccessibleListener(accessibleAdapter);
text.getAccessible().addAccessibleListener(accessibleAdapter);
list.getAccessible().addAccessibleListener(accessibleAdapter);
arrow.getAccessible().addAccessibleListener(new AccessibleAdapter() {
@Override
public void getName(AccessibleEvent e) {
//$NON-NLS-1$ //$NON-NLS-2$
e.result = isDropped() ? SWT.getMessage("SWT_Close") : SWT.getMessage("SWT_Open");
}
@Override
public void getKeyboardShortcut(AccessibleEvent e) {
//$NON-NLS-1$
e.result = "Alt+Down Arrow";
}
@Override
public void getHelp(AccessibleEvent e) {
e.result = getToolTipText();
}
});
getAccessible().addAccessibleTextListener(new AccessibleTextAdapter() {
@Override
public void getCaretOffset(AccessibleTextEvent e) {
e.offset = text.getCaretPosition();
}
@Override
public void getSelectionRange(AccessibleTextEvent e) {
Point sel = text.getSelection();
e.offset = sel.x;
e.length = sel.y - sel.x;
}
});
getAccessible().addAccessibleControlListener(new AccessibleControlAdapter() {
@Override
public void getChildAtPoint(AccessibleControlEvent e) {
Point testPoint = toControl(e.x, e.y);
if (getBounds().contains(testPoint)) {
e.childID = ACC.CHILDID_SELF;
}
}
@Override
public void getLocation(AccessibleControlEvent e) {
Rectangle location = getBounds();
Point pt = getParent().toDisplay(location.x, location.y);
e.x = pt.x;
e.y = pt.y;
e.width = location.width;
e.height = location.height;
}
@Override
public void getChildCount(AccessibleControlEvent e) {
e.detail = 0;
}
@Override
public void getRole(AccessibleControlEvent e) {
e.detail = ACC.ROLE_COMBOBOX;
}
@Override
public void getState(AccessibleControlEvent e) {
e.detail = ACC.STATE_NORMAL;
}
@Override
public void getValue(AccessibleControlEvent e) {
e.result = getText();
}
});
text.getAccessible().addAccessibleControlListener(new AccessibleControlAdapter() {
@Override
public void getRole(AccessibleControlEvent e) {
e.detail = text.getEditable() ? ACC.ROLE_TEXT : ACC.ROLE_LABEL;
}
});
arrow.getAccessible().addAccessibleControlListener(new AccessibleControlAdapter() {
@Override
public void getDefaultAction(AccessibleControlEvent e) {
//$NON-NLS-1$ //$NON-NLS-2$
e.result = isDropped() ? SWT.getMessage("SWT_Close") : SWT.getMessage("SWT_Open");
}
});
}
use of org.eclipse.swt.accessibility.AccessibleEvent in project translationstudio8 by heartsome.
the class TSWizardDialog method createPreviousAndNextButtons.
/**
* Creates the Previous and Next buttons for this wizard dialog. Creates
* standard (<code>SWT.PUSH</code>) buttons and registers for their
* selection events. Note that the number of columns in the button bar
* composite is incremented. These buttons are created specially to prevent
* any space between them.
*
* @param parent
* the parent button bar
* @return a composite containing the new buttons
*/
private Composite createPreviousAndNextButtons(Composite parent) {
// increment the number of columns in the button bar
((GridLayout) parent.getLayout()).numColumns++;
Composite composite = new Composite(parent, SWT.NONE);
// create a layout with spacing and margins appropriate for the font
// size.
GridLayout layout = new GridLayout();
// will be incremented by createButton
layout.numColumns = 0;
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
composite.setLayout(layout);
GridData data = new GridData(GridData.HORIZONTAL_ALIGN_CENTER | GridData.VERTICAL_ALIGN_CENTER);
composite.setLayoutData(data);
composite.setFont(parent.getFont());
backButton = createButton(composite, IDialogConstants.BACK_ID, IDialogConstants.BACK_LABEL, false);
nextButton = createButton(composite, IDialogConstants.NEXT_ID, IDialogConstants.NEXT_LABEL, false);
// make sure screen readers skip visual '<', '>' chars on buttons:
final String backReaderText = IDialogConstants.BACK_LABEL.replace('<', ' ');
backButton.getAccessible().addAccessibleListener(new AccessibleAdapter() {
public void getName(AccessibleEvent e) {
e.result = backReaderText;
}
});
final String nextReaderText = IDialogConstants.NEXT_LABEL.replace('>', ' ');
nextButton.getAccessible().addAccessibleListener(new AccessibleAdapter() {
public void getName(AccessibleEvent e) {
e.result = nextReaderText;
}
});
return composite;
}
use of org.eclipse.swt.accessibility.AccessibleEvent in project eclipse.platform.swt by eclipse.
the class Shape method addListeners.
void addListeners() {
addPaintListener(e -> {
GC gc = e.gc;
Display display = getDisplay();
Color c = display.getSystemColor(color);
gc.setBackground(c);
Rectangle rect = getClientArea();
int length = Math.min(rect.width, rect.height);
if (shape == CIRCLE) {
gc.fillOval(0, 0, length, length);
} else {
gc.fillRectangle(0, 0, length, length);
}
if (isFocusControl())
gc.drawFocus(rect.x, rect.y, rect.width, rect.height);
});
addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
redraw();
}
@Override
public void focusLost(FocusEvent e) {
redraw();
}
});
addMouseListener(MouseListener.mouseDownAdapter(e -> {
if (getClientArea().contains(e.x, e.y)) {
setFocus();
}
}));
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
// key listener enables traversal out
}
});
addTraverseListener(e -> {
switch(e.detail) {
case SWT.TRAVERSE_TAB_NEXT:
case SWT.TRAVERSE_TAB_PREVIOUS:
e.doit = true;
break;
}
});
getAccessible().addAccessibleListener(new AccessibleAdapter() {
@Override
public void getName(AccessibleEvent e) {
MessageFormat formatter = new MessageFormat("");
// $NON_NLS$
formatter.applyPattern(bundle.getString("name"));
// $NON_NLS$
String colorName = bundle.getString("color" + color);
// $NON_NLS$
String shapeName = bundle.getString("shape" + shape);
// $NON_NLS$
e.result = formatter.format(new String[] { colorName, shapeName });
}
});
getAccessible().addAccessibleControlListener(new AccessibleControlAdapter() {
@Override
public void getRole(AccessibleControlEvent e) {
e.detail = ACC.ROLE_GRAPHIC;
}
@Override
public void getState(AccessibleControlEvent e) {
e.detail = ACC.STATE_FOCUSABLE;
if (isFocusControl())
e.detail |= ACC.STATE_FOCUSED;
}
});
}
use of org.eclipse.swt.accessibility.AccessibleEvent in project eclipse.platform.swt by eclipse.
the class AccessibleValueExample method main.
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setText("Accessible Value Example");
final Canvas canvas = new Canvas(shell, SWT.DOUBLE_BUFFERED);
canvas.addPaintListener(e -> {
Rectangle rect = canvas.getClientArea();
String val = String.valueOf(value);
Point size = e.gc.stringExtent(val);
e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_LIST_SELECTION));
e.gc.fillRectangle(0, 0, rect.width * value / (max - min), rect.height);
e.gc.drawString(val, rect.x + (rect.width - size.x) / 2, rect.y + (rect.height - size.y) / 2, true);
});
Accessible accessible = canvas.getAccessible();
accessible.addAccessibleListener(new AccessibleAdapter() {
@Override
public void getName(AccessibleEvent e) {
e.result = "The value of this canvas is " + value;
}
});
accessible.addAccessibleControlListener(new AccessibleControlAdapter() {
@Override
public void getRole(AccessibleControlEvent e) {
e.detail = ACC.ROLE_PROGRESSBAR;
}
});
accessible.addAccessibleValueListener(new AccessibleValueAdapter() {
@Override
public void setCurrentValue(AccessibleValueEvent e) {
value = e.value.intValue();
canvas.redraw();
}
@Override
public void getMinimumValue(AccessibleValueEvent e) {
e.value = Integer.valueOf(min);
}
@Override
public void getMaximumValue(AccessibleValueEvent e) {
e.value = Integer.valueOf(max);
}
@Override
public void getCurrentValue(AccessibleValueEvent e) {
e.value = Integer.valueOf(value);
}
});
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
use of org.eclipse.swt.accessibility.AccessibleEvent in project eclipse.platform.swt by eclipse.
the class BarChart method addListeners.
void addListeners() {
addPaintListener(e -> {
GC gc = e.gc;
Rectangle rect = getClientArea();
Display display = getDisplay();
int count = data.size();
Point valueSize = gc.stringExtent(Integer.valueOf(valueMax).toString());
int leftX = rect.x + 2 * GAP + valueSize.x;
int bottomY = rect.y + rect.height - 2 * GAP - valueSize.y;
int unitWidth = (rect.width - 4 * GAP - valueSize.x - AXIS_WIDTH) / count - GAP;
int unitHeight = (rect.height - 3 * GAP - AXIS_WIDTH - 2 * valueSize.y) / ((valueMax - valueMin) / valueIncrement);
// draw the title
int titleWidth = gc.stringExtent(title).x;
int center = (Math.max(titleWidth, count * (unitWidth + GAP) + GAP) - titleWidth) / 2;
gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
gc.drawString(title, leftX + AXIS_WIDTH + center, rect.y + GAP);
// draw the y axis and value labels
gc.setLineWidth(AXIS_WIDTH);
gc.drawLine(leftX, rect.y + GAP + valueSize.y, leftX, bottomY);
for (int i1 = valueMin; i1 <= valueMax; i1 += valueIncrement) {
int y = bottomY - i1 * unitHeight;
gc.drawLine(leftX, y, leftX - GAP, y);
gc.drawString(Integer.valueOf(i1).toString(), rect.x + GAP, y - valueSize.y);
}
// draw the x axis and item labels
gc.drawLine(leftX, bottomY, rect.x + rect.width - GAP, bottomY);
for (int i2 = 0; i2 < count; i2++) {
Object[] dataItem1 = data.get(i2);
String itemLabel = (String) dataItem1[0];
int x1 = leftX + AXIS_WIDTH + GAP + i2 * (unitWidth + GAP);
gc.drawString(itemLabel, x1, bottomY + GAP);
}
// draw the bars
gc.setBackground(display.getSystemColor(color));
for (int i3 = 0; i3 < count; i3++) {
Object[] dataItem2 = data.get(i3);
int itemValue1 = ((Integer) dataItem2[1]).intValue();
int x2 = leftX + AXIS_WIDTH + GAP + i3 * (unitWidth + GAP);
gc.fillRectangle(x2, bottomY - AXIS_WIDTH - itemValue1 * unitHeight, unitWidth, itemValue1 * unitHeight);
}
if (isFocusControl()) {
if (selectedItem == -1) {
// draw the focus rectangle around the whole bar chart
gc.drawFocus(rect.x, rect.y, rect.width, rect.height);
} else {
// draw the focus rectangle around the selected item
Object[] dataItem3 = data.get(selectedItem);
int itemValue2 = ((Integer) dataItem3[1]).intValue();
int x3 = leftX + AXIS_WIDTH + GAP + selectedItem * (unitWidth + GAP);
gc.drawFocus(x3, bottomY - itemValue2 * unitHeight - AXIS_WIDTH, unitWidth, itemValue2 * unitHeight + AXIS_WIDTH + GAP + valueSize.y);
}
}
});
addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
redraw();
}
@Override
public void focusLost(FocusEvent e) {
redraw();
}
});
addMouseListener(MouseListener.mouseDownAdapter(e -> {
if (getClientArea().contains(e.x, e.y)) {
setFocus();
int item = -1;
int count = data.size();
for (int i = 0; i < count; i++) {
if (itemBounds(i).contains(e.x, e.y)) {
item = i;
break;
}
}
if (item != selectedItem) {
selectedItem = item;
redraw();
getAccessible().setFocus(item);
getAccessible().selectionChanged();
}
}
}));
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
boolean change = false;
switch(e.keyCode) {
case SWT.ARROW_DOWN:
case SWT.ARROW_RIGHT:
selectedItem++;
if (selectedItem >= data.size())
selectedItem = 0;
change = true;
break;
case SWT.ARROW_UP:
case SWT.ARROW_LEFT:
selectedItem--;
if (selectedItem <= -1)
selectedItem = data.size() - 1;
change = true;
break;
case SWT.HOME:
selectedItem = 0;
change = true;
break;
case SWT.END:
selectedItem = data.size() - 1;
change = true;
break;
}
if (change) {
redraw();
getAccessible().setFocus(selectedItem);
getAccessible().selectionChanged();
}
}
});
addTraverseListener(e -> {
switch(e.detail) {
case SWT.TRAVERSE_TAB_NEXT:
case SWT.TRAVERSE_TAB_PREVIOUS:
e.doit = true;
break;
}
});
getAccessible().addAccessibleListener(new AccessibleAdapter() {
@Override
public void getName(AccessibleEvent e) {
// $NON_NLS$
MessageFormat formatter = new MessageFormat("");
// $NON_NLS$
formatter.applyPattern(bundle.getString("name"));
int childID = e.childID;
if (childID == ACC.CHILDID_SELF) {
e.result = title;
} else {
Object[] item = data.get(childID);
e.result = formatter.format(item);
}
}
@Override
public void getDescription(AccessibleEvent e) {
int childID = e.childID;
if (childID != ACC.CHILDID_SELF) {
Object[] item = data.get(childID);
String value = item[1].toString();
// $NON_NLS$
String colorName = bundle.getString("color" + color);
// $NON_NLS$
MessageFormat formatter = new MessageFormat("");
// $NON_NLS$
formatter.applyPattern(bundle.getString("color_value"));
e.result = formatter.format(new String[] { colorName, value });
}
}
});
getAccessible().addAccessibleControlListener(new AccessibleControlAdapter() {
@Override
public void getRole(AccessibleControlEvent e) {
if (e.childID == ACC.CHILDID_SELF) {
e.detail = ACC.ROLE_LIST;
} else {
e.detail = ACC.ROLE_LISTITEM;
}
}
@Override
public void getChildCount(AccessibleControlEvent e) {
e.detail = data.size();
}
@Override
public void getChildren(AccessibleControlEvent e) {
int count = data.size();
Object[] children = new Object[count];
for (int i = 0; i < count; i++) {
children[i] = Integer.valueOf(i);
}
e.children = children;
}
@Override
public void getChildAtPoint(AccessibleControlEvent e) {
Point testPoint = toControl(e.x, e.y);
int childID = ACC.CHILDID_NONE;
if (getClientArea().contains(testPoint)) {
childID = ACC.CHILDID_SELF;
int count = data.size();
for (int i = 0; i < count; i++) {
if (itemBounds(i).contains(testPoint)) {
childID = i;
break;
}
}
}
e.childID = childID;
}
@Override
public void getLocation(AccessibleControlEvent e) {
Rectangle location = null;
Point pt = null;
int childID = e.childID;
if (childID == ACC.CHILDID_SELF) {
location = getClientArea();
pt = getParent().toDisplay(location.x, location.y);
} else {
location = itemBounds(childID);
pt = toDisplay(location.x, location.y);
}
e.x = pt.x;
e.y = pt.y;
e.width = location.width;
e.height = location.height;
}
@Override
public void getFocus(AccessibleControlEvent e) {
int childID = ACC.CHILDID_NONE;
if (isFocusControl()) {
if (selectedItem == -1) {
childID = ACC.CHILDID_SELF;
} else {
childID = selectedItem;
}
}
e.childID = childID;
}
@Override
public void getSelection(AccessibleControlEvent e) {
e.childID = (selectedItem == -1) ? ACC.CHILDID_NONE : selectedItem;
}
@Override
public void getValue(AccessibleControlEvent e) {
int childID = e.childID;
if (childID != ACC.CHILDID_SELF) {
Object[] dataItem = data.get(childID);
e.result = ((Integer) dataItem[1]).toString();
}
}
@Override
public void getState(AccessibleControlEvent e) {
int childID = e.childID;
e.detail = ACC.STATE_FOCUSABLE;
if (isFocusControl())
e.detail |= ACC.STATE_FOCUSED;
if (childID != ACC.CHILDID_SELF) {
e.detail |= ACC.STATE_SELECTABLE;
if (childID == selectedItem)
e.detail |= ACC.STATE_SELECTED;
}
}
});
}
Aggregations