1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
|
/*
* Java ATK Wrapper for GNOME
* Copyright (C) 2009 Sun Microsystems Inc.
* Copyright (C) 2015 Magdalen Berns <m.berns@thismagpie.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.GNOME.Accessibility;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.io.*;
import javax.accessibility.*;
import java.awt.Toolkit;
import javax.management.*;
import javax.swing.JComboBox;
import java.lang.management.*;
public class AtkWrapper {
static boolean accessibilityEnabled = false;
static void initAtk() {
System.loadLibrary("atk-wrapper");
if (AtkWrapper.initNativeLibrary())
accessibilityEnabled = true;
}
static {
try {
Process p = Runtime.getRuntime().exec("@XPROP@ -root");
BufferedReader b = new BufferedReader(new InputStreamReader (p.getInputStream ()));
String result;
while ((result = b.readLine()) != null) {
if (result.indexOf("AT_SPI_IOR") >= 0 || result.indexOf("AT_SPI_BUS") >= 0) {
initAtk();
break;
}
}
if (!accessibilityEnabled) {
p = Runtime.getRuntime().exec("dbus-send --session --dest=org.a11y.Bus --print-reply /org/a11y/bus org.a11y.Bus.GetAddress");
b = new BufferedReader(new InputStreamReader (p.getInputStream ()));
while ((b.readLine()) != null);
p.waitFor();
if (p.exitValue() == 0)
initAtk();
}
java.util.List<GarbageCollectorMXBean> gcbeans = ManagementFactory.getGarbageCollectorMXBeans();
for (GarbageCollectorMXBean gcbean : gcbeans) {
NotificationEmitter emitter = (NotificationEmitter) gcbean;
NotificationListener listener = new NotificationListener() {
public void handleNotification(Notification notif, Object handback) {
AtkWrapper.GC();
}
};
emitter.addNotificationListener(listener, null, null);
}
} catch (Exception e) {
e.printStackTrace();
e.getCause();
}
}
/**
* winAdapter
*
* <http://docs.oracle.com/javase/8/docs/api/java/awt/event/WindowAdapter.html>
* <http://docs.oracle.com/javase/8/docs/api/java/awt/event/WindowEvent.html>
*/
final WindowAdapter winAdapter = new WindowAdapter() {
/**
* windowActivated:
* Invoked when a Window becomes the active Window.
* Only a Frame or a Dialog can be the active Window. The
* native windowing system may denote the active Window
* or its children with special decorations, such as a
* highlighted title bar. The active Window is always either
* the focused Window, or the first Frame or Dialog that is
* an owner of the focused Window.
* @param e A WindowEvent object
*/
public void windowActivated(WindowEvent e) {
Object o = e.getSource();
if ( o instanceof Accessible ) {
AccessibleContext ac = ((Accessible)o).getAccessibleContext();
AtkWrapper.windowActivate(ac);
}
}
/**
* windowDeactivated:
* Invoked when a Window is no longer the active Window.
* Only a Frame or a Dialog can be the active Window. The
* native windowing system may denote the active Window
* or its children with special decorations, such as a
* highlighted title bar. The active Window is always either
* the focused Window, or the first Frame or Dialog that is
* an owner of the focused Window.
* @param e A WindowEvent object
*/
public void windowDeactivated(WindowEvent e) {
Object o = e.getSource();
if (o instanceof Accessible) {
AccessibleContext ac = ((Accessible)o).getAccessibleContext();
AtkWrapper.windowDeactivate(ac);
}
}
/**
* windowStateChanged:
* Invoked when a window state is changed.
*
* @param e A WindowEvent object
*/
public void windowStateChanged(WindowEvent e) {
Object o = e.getSource();
if (o instanceof Accessible) {
AccessibleContext ac = ((Accessible)o).getAccessibleContext();
AtkWrapper.windowStateChange(ac);
if( (e.getNewState() & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH ) {
AtkWrapper.windowMaximize(ac);
}
}
}
/**
* windowDeiconified:
* Invoked when a window is deiconified.
* @param e A WindowEvent instance
*/
public void windowDeiconified(WindowEvent e) {
Object o = e.getSource();
if (o instanceof Accessible) {
AccessibleContext ac = ((Accessible)o).getAccessibleContext();
AtkWrapper.windowRestore(ac);
}
}
/**
* windowIconified:
* Invoked when a window is iconified.
* @param e A WindowEvent instance
*/
public void windowIconified(WindowEvent e) {
Object o = e.getSource();
if (o instanceof Accessible) {
AccessibleContext ac = ((Accessible)o).getAccessibleContext();
AtkWrapper.windowMinimize(ac);
}
}
/**
* windowOpened
* @param e A WindowEvent object
*/
public void windowOpened(WindowEvent e) {
Object o = e.getSource();
if ( o instanceof Accessible ) {
boolean isToplevel = isToplevel(o);
AccessibleContext ac = ((Accessible)o).getAccessibleContext();
AtkWrapper.windowOpen(ac, isToplevel);
}
}
/**
* windowClosed:
* Invoked when a window has been closed.
* @param e A WindowEvent object
*/
public void windowClosed(WindowEvent e) {
Object o = e.getSource();
if (o instanceof Accessible) {
boolean isToplevel = isToplevel(o);
AccessibleContext ac = ((Accessible)o).getAccessibleContext();
AtkWrapper.windowClose(ac, isToplevel);
}
}
/**
* windowClosing:
* Invoked when a window is in the process of being closed.
* @param e A WindowEvent object
*/
public void windowClosing(WindowEvent e) {
Object o = e.getSource();
if (o instanceof Accessible) {
boolean isToplevel = isToplevel(o);
AccessibleContext ac = ((Accessible)o).getAccessibleContext();
AtkWrapper.windowClose(ac, isToplevel);
}
}
/**
* windowGainedFocus:
* Invoked when the Window is set to be the focused Window,
* which means that the Window, or one of its subcomponents,
* will receive keyboard events.
* @param e A WindowEvent object
*/
public void windowGainedFocus(WindowEvent e) {
}
public void windowLostFocus(WindowEvent e) {
}
}; // Close WindowAdapter brace
final ComponentAdapter componentAdapter = new ComponentAdapter() {
/**
* componentResized
* * Invoked when the component's size changes and emits
* a "bounds-changed" signal.
* @param e a ComponentEvent object
*/
public void componentResized(ComponentEvent e) {
Object o = e.getSource();
if (o instanceof Accessible) {
AccessibleContext ac = ((Accessible)o).getAccessibleContext();
AtkWrapper.boundsChanged(ac);
}
}
/**
* componentMoved:
* Invoked when the component's position changes and emits
* a "bounds-changed" signal.
*
* @param e a ComponentEvent object
*/
public void componentMoved(ComponentEvent e){
Object o = e.getSource();
if (o instanceof Accessible) {
AccessibleContext ac = ((Accessible)o).getAccessibleContext();
AtkWrapper.boundsChanged(ac);
}
}
/**
* componentShown
* @param e A ComponentEvent object
*/
public void componentShown(ComponentEvent e) {
Object o = e.getSource();
if (o instanceof Accessible) {
AccessibleContext ac = ((Accessible)o).getAccessibleContext();
AtkWrapper.componentAdded(ac);
}
}
/**
* componentHidden:
* Invoked when the component has been made invisible.
* @param e A ComponentEvent object
*/
public void componentHidden(ComponentEvent e){
Object o = e.getSource();
if (o instanceof Accessible) {
AccessibleContext ac = ((Accessible)o).getAccessibleContext();
AtkWrapper.componentRemoved(ac);
}
}
};
/**
* isToplevel
* @param o an instance
* @return true if instance is of a window, frame or dialogue object
* false otherwise.
*/
public static boolean isToplevel(Object o) {
boolean isToplevel = false;
if (o instanceof java.awt.Window ||
o instanceof java.awt.Frame ||
o instanceof java.awt.Dialog) {
isToplevel = true;
}
return isToplevel;
}
final AWTEventListener globalListener = new AWTEventListener() {
private boolean firstEvent = true;
public void eventDispatched(AWTEvent e) {
if (firstEvent && accessibilityEnabled) {
firstEvent = false;
try {
AtkWrapper.loadAtkBridge();
} catch (Exception ex) {
ex.printStackTrace();
}
}
if(e instanceof WindowEvent) {
switch( e.getID() ) {
case WindowEvent.WINDOW_OPENED:
Window win = ((WindowEvent)e).getWindow();
win.addWindowListener(winAdapter);
win.addWindowStateListener(winAdapter);
win.addWindowFocusListener(winAdapter);
break;
case WindowEvent.WINDOW_LOST_FOCUS:
AtkWrapper.dispatchFocusEvent(null);
break;
default:
break;
}
} else if(e instanceof ContainerEvent ) {
switch( e.getID() ) {
case ContainerEvent.COMPONENT_ADDED:
{
Component c = ((ContainerEvent)e).getChild();
c.addComponentListener(componentAdapter);
break;
}
case ContainerEvent.COMPONENT_REMOVED:
{
Component c = ((ContainerEvent)e).getChild();
c.removeComponentListener(componentAdapter);
break;
}
default:
break;
}
} else if(e instanceof FocusEvent) {
switch(e.getID()) {
case FocusEvent.FOCUS_GAINED:
AtkWrapper.dispatchFocusEvent(e.getSource());
break;
default:
break;
}
}
}
};
static AccessibleContext oldSourceContext = null;
static AccessibleContext savedSourceContext= null;
static AccessibleContext oldPaneContext = null;
/**
* dispatchFocusEvent
* @param eventSource An instance of the event source object.
*/
static void dispatchFocusEvent(Object eventSource) {
if (eventSource == null) {
oldSourceContext = null;
return;
}
AccessibleContext ctx;
try {
if (eventSource instanceof AccessibleContext) {
ctx = (AccessibleContext)eventSource;
} else if (eventSource instanceof Accessible) {
ctx = ((Accessible)eventSource).getAccessibleContext();
} else {
return;
}
if (ctx == oldSourceContext) {
return;
}
if (oldSourceContext != null) {
AccessibleRole role = oldSourceContext.getAccessibleRole();
if (role == AccessibleRole.MENU || role == AccessibleRole.MENU_ITEM) {
String jrootpane = "javax.swing.JRootPane$AccessibleJRootPane";
String name = ctx.getClass().getName();
if (jrootpane.compareTo(name) == 0) {
oldPaneContext = ctx;
return;
}
}
savedSourceContext = ctx;
} else if (oldPaneContext == ctx) {
ctx = savedSourceContext;
} else {
savedSourceContext = ctx;
}
oldSourceContext = ctx;
AccessibleRole role = ctx.getAccessibleRole();
if (role == AccessibleRole.PAGE_TAB_LIST) {
AccessibleSelection accSelection = ctx.getAccessibleSelection();
if (accSelection != null && accSelection.getAccessibleSelectionCount() > 0) {
Object child = accSelection.getAccessibleSelection(0);
if (child instanceof AccessibleContext) {
ctx = (AccessibleContext)child;
} else if (child instanceof Accessible) {
ctx = ((Accessible)child).getAccessibleContext();
} else {
return;
}
}
}
focusNotify(ctx);
} catch (Exception e) {
e.printStackTrace();
}
}
final Toolkit toolkit = Toolkit.getDefaultToolkit();
static PropertyChangeListener propertyChangeListener = new PropertyChangeListener() {
/**
* propertyChange:
* @param e An instance of the PropertyChangeEvent object.
*/
public void propertyChange(PropertyChangeEvent e) {
Object o = e.getSource();
AccessibleContext ac;
if (o instanceof AccessibleContext) {
ac = (AccessibleContext)o;
} else if (o instanceof Accessible) {
ac = ((Accessible)o).getAccessibleContext();
} else {
return;
}
Object oldValue = e.getOldValue();
Object newValue = e.getNewValue();
String propertyName = e.getPropertyName();
if( propertyName.equals(AccessibleContext.ACCESSIBLE_CARET_PROPERTY) ) {
Object[] args = new Object[1];
args[0] = newValue;
emitSignal(ac, AtkSignal.TEXT_CARET_MOVED, args);
} else if( propertyName.equals(AccessibleContext.ACCESSIBLE_TEXT_PROPERTY) ) {
if (newValue == null) {
return;
}
if (newValue instanceof Integer) {
Object[] args = new Object[1];
args[0] = newValue;
emitSignal(ac, AtkSignal.TEXT_PROPERTY_CHANGED, args);
}
/*
if (oldValue == null && newValue != null) { //insertion event
if (!(newValue instanceof AccessibleTextSequence)) {
return;
}
AccessibleTextSequence newSeq = (AccessibleTextSequence)newValue;
Object[] args = new Object[2];
args[0] = new Integer(newSeq.startIndex);
args[1] = new Integer(newSeq.endIndex - newSeq.startIndex);
emitSignal(ac, AtkSignal.TEXT_PROPERTY_CHANGED_INSERT, args);
} else if (oldValue != null && newValue == null) { //deletion event
if (!(oldValue instanceof AccessibleTextSequence)) {
return;
}
AccessibleTextSequence oldSeq = (AccessibleTextSequence)oldValue;
Object[] args = new Object[2];
args[0] = new Integer(oldSeq.startIndex);
args[1] = new Integer(oldSeq.endIndex - oldSeq.startIndex);
emitSignal(ac, AtkSignal.TEXT_PROPERTY_CHANGED_DELETE, args);
} else if (oldValue != null && newValue != null) { //replacement event
//It seems ATK does not support "replace" currently
return;
}*/
} else if( propertyName.equals(AccessibleContext.ACCESSIBLE_CHILD_PROPERTY) ) {
if (oldValue == null && newValue != null) { //child added
AccessibleContext child_ac;
if (newValue instanceof Accessible) {
child_ac = ((Accessible)newValue).getAccessibleContext();
} else {
return;
}
Object[] args = new Object[2];
args[0] = Integer.valueOf(child_ac.getAccessibleIndexInParent());
args[1] = child_ac;
emitSignal(ac, AtkSignal.OBJECT_CHILDREN_CHANGED_ADD, args);
} else if (oldValue != null && newValue == null) { //child removed
AccessibleContext child_ac;
if (oldValue instanceof Accessible) {
child_ac = ((Accessible)oldValue).getAccessibleContext();
} else {
return;
}
Object[] args = new Object[2];
args[0] = Integer.valueOf(child_ac.getAccessibleIndexInParent());
args[1] = child_ac;
emitSignal(ac, AtkSignal.OBJECT_CHILDREN_CHANGED_REMOVE, args);
}
} else if( propertyName.equals(AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY) ) {
AccessibleContext child_ac;
if (newValue instanceof Accessible) {
child_ac = ((Accessible)newValue).getAccessibleContext();
} else {
return;
}
/*
* JComboBox sends two signals: object:active-descendant-changed and object:selection-changed.
* Information about the component is announced when processing the object:selection-changed signal.
* The object:active-descendant-changed signal interrupts this announcement in earlier versions of GNOME.
* Skipping the emission of object:active-descendant-changed signal resolves this issue.
* See: https://gitlab.gnome.org/GNOME/java-atk-wrapper/-/issues/29
*/
if (ac.getAccessibleRole() == AccessibleRole.COMBO_BOX) {
return;
}
Object[] args = new Object[1];
args[0] = child_ac;
emitSignal(ac, AtkSignal.OBJECT_ACTIVE_DESCENDANT_CHANGED, args);
} else if( propertyName.equals(AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY) ) {
boolean isTextEvent = false;
AccessibleRole role = ac.getAccessibleRole();
if ((role == AccessibleRole.TEXT) ||
role.toDisplayString(java.util.Locale.US).equalsIgnoreCase("paragraph")) {
isTextEvent = true;
} else if (role == AccessibleRole.MENU_BAR) {
dispatchFocusEvent(o);
} else if (role == AccessibleRole.PAGE_TAB_LIST) {
AccessibleSelection selection = ac.getAccessibleSelection();
if (selection != null &&
selection.getAccessibleSelectionCount() > 0) {
java.lang.Object child = selection.getAccessibleSelection(0);
dispatchFocusEvent(child);
}
}
/*
* When navigating through nodes, JTree sends two signals: object:selection-changed and object:active-descendant-changed.
* The object:selection-changed signal is emitted before object:active-descendant-changed, leading to the following issues:
* 1. When focusing on the root of the tree, object:active-descendant-changed interrupts the announcement and does not
* provide any output because the FOCUS MANAGER doesn't update the focus - it is already set to the same object.
* 2. For other nodes, the correct behavior happens because of the bug in JTree:
* AccessibleJTree incorrectly reports the selected children and object:selection-changed sets focus on the tree.
*
* Removing the object:selection-changed signal ensures that the locus of focus is updated during object:active-descendant-changed,
* allowing elements to be announced correctly.
* See: https://gitlab.gnome.org/GNOME/orca/-/issues/552
*/
if (ac.getAccessibleRole() == AccessibleRole.TREE) {
return;
}
if (!isTextEvent) {
emitSignal(ac, AtkSignal.OBJECT_SELECTION_CHANGED, null);
}
} else if( propertyName.equals(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY) ) {
emitSignal(ac, AtkSignal.OBJECT_VISIBLE_DATA_CHANGED, null);
}else if( propertyName.equals(AccessibleContext.ACCESSIBLE_ACTION_PROPERTY) ) {
Object[] args = new Object[2];
args[0] = oldValue;
args[1] = newValue;
emitSignal(ac, AtkSignal.OBJECT_PROPERTY_CHANGE_ACCESSIBLE_ACTIONS, args);
}else if( propertyName.equals(AccessibleContext.ACCESSIBLE_VALUE_PROPERTY) ) {
if (oldValue instanceof Number && newValue instanceof Number) {
Object[] args = new Object[2];
args[0] = Double.valueOf(((Number)oldValue).doubleValue());
args[1] = Double.valueOf(((Number)newValue).doubleValue());
emitSignal(ac, AtkSignal.OBJECT_PROPERTY_CHANGE_ACCESSIBLE_VALUE, args);
}
} else if(propertyName.equals(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY)) {
emitSignal(ac, AtkSignal.OBJECT_PROPERTY_CHANGE_ACCESSIBLE_DESCRIPTION, null);
} else if(propertyName.equals(AccessibleContext.ACCESSIBLE_NAME_PROPERTY)) {
emitSignal(ac, AtkSignal.OBJECT_PROPERTY_CHANGE_ACCESSIBLE_NAME, null);
} else if(propertyName.equals(AccessibleContext.ACCESSIBLE_HYPERTEXT_OFFSET)) {
emitSignal(ac, AtkSignal.OBJECT_PROPERTY_CHANGE_ACCESSIBLE_HYPERTEXT_OFFSET, null);
} else if(propertyName.equals(AccessibleContext.ACCESSIBLE_TABLE_MODEL_CHANGED)) {
emitSignal(ac, AtkSignal.TABLE_MODEL_CHANGED, null);
} else if( propertyName.equals(AccessibleContext.ACCESSIBLE_TABLE_CAPTION_CHANGED)) {
emitSignal(ac, AtkSignal.OBJECT_PROPERTY_CHANGE_ACCESSIBLE_TABLE_CAPTION, null);
} else if(propertyName.equals(AccessibleContext.ACCESSIBLE_TABLE_SUMMARY_CHANGED)) {
emitSignal(ac, AtkSignal.OBJECT_PROPERTY_CHANGE_ACCESSIBLE_TABLE_SUMMARY, null);
} else if(propertyName.equals(AccessibleContext.ACCESSIBLE_TABLE_COLUMN_HEADER_CHANGED)) {
emitSignal(ac, AtkSignal.OBJECT_PROPERTY_CHANGE_ACCESSIBLE_TABLE_COLUMN_HEADER, null);
} else if(propertyName.equals(AccessibleContext.ACCESSIBLE_TABLE_COLUMN_DESCRIPTION_CHANGED) ) {
emitSignal(ac, AtkSignal.OBJECT_PROPERTY_CHANGE_ACCESSIBLE_TABLE_COLUMN_DESCRIPTION, null);
} else if(propertyName.equals(AccessibleContext.ACCESSIBLE_TABLE_ROW_HEADER_CHANGED)) {
emitSignal(ac, AtkSignal.OBJECT_PROPERTY_CHANGE_ACCESSIBLE_TABLE_ROW_HEADER, null);
} else if(propertyName.equals(AccessibleContext.ACCESSIBLE_TABLE_ROW_DESCRIPTION_CHANGED)) {
emitSignal(ac, AtkSignal.OBJECT_PROPERTY_CHANGE_ACCESSIBLE_TABLE_ROW_DESCRIPTION, null);
} else if(propertyName.equals(AccessibleContext.ACCESSIBLE_STATE_PROPERTY)) {
Accessible parent = ac.getAccessibleParent();
AccessibleRole role = ac.getAccessibleRole();
if (role != null) {
if (newValue == AccessibleState.FOCUSED ||
newValue == AccessibleState.SELECTED) {
dispatchFocusEvent(o);
}
}
AccessibleState state;
boolean value = false;
if (newValue != null) {
state = (AccessibleState)newValue;
value = true;
} else {
state = (AccessibleState)oldValue;
value = false;
}
if (state == AccessibleState.COLLAPSED) {
state = AccessibleState.EXPANDED;
value = false;
}
if(parent instanceof JComboBox && oldValue ==
AccessibleState.VISIBLE) {
objectStateChange(ac, AccessibleState.SHOWING, value);
}
objectStateChange(ac, state, value);
if (parent instanceof JComboBox && newValue ==
AccessibleState.VISIBLE && oldValue == null) {
objectStateChange(ac, AccessibleState.SHOWING, value);
}
}
}
};
public static void registerPropertyChangeListener(AccessibleContext ac) {
if (ac != null) {
AtkUtil.invokeInSwing( () -> { ac.addPropertyChangeListener(propertyChangeListener); } );
}
}
public native static boolean initNativeLibrary();
public native static void loadAtkBridge();
public native static void GC();
public native static void focusNotify(AccessibleContext ac);
public native static void windowOpen(AccessibleContext ac,
boolean isToplevel);
public native static void windowClose(AccessibleContext ac,
boolean isToplevel);
public native static void windowMinimize(AccessibleContext ac);
public native static void windowMaximize(AccessibleContext ac);
public native static void windowRestore(AccessibleContext ac);
public native static void windowActivate(AccessibleContext ac);
public native static void windowDeactivate(AccessibleContext ac);
public native static void windowStateChange(AccessibleContext ac);
public native static void emitSignal(AccessibleContext ac, int id, Object[] args);
public native static void objectStateChange(AccessibleContext ac,
Object state, boolean value);
public native static void componentAdded(AccessibleContext ac);
public native static void componentRemoved(AccessibleContext ac);
public native static void boundsChanged(AccessibleContext ac);
public native static boolean dispatchKeyEvent(AtkKeyEvent e);
public native static long getInstance(AccessibleContext ac);
public static void printLog(String str) {
System.out.println(str);
}
public AtkWrapper() {
if (!accessibilityEnabled)
return;
toolkit.addAWTEventListener(globalListener,
AWTEvent.WINDOW_EVENT_MASK |
AWTEvent.FOCUS_EVENT_MASK |
AWTEvent.CONTAINER_EVENT_MASK);
toolkit.getSystemEventQueue().push(new EventQueue() {
boolean previousPressConsumed = false;
public void dispatchEvent(AWTEvent e) {
if (e instanceof KeyEvent) {
if (e.getID() == KeyEvent.KEY_PRESSED) {
boolean isConsumed = AtkWrapper.dispatchKeyEvent(new AtkKeyEvent((KeyEvent)e));
if (isConsumed) {
previousPressConsumed = true;
return;
}
} else if (e.getID() == KeyEvent.KEY_TYPED) {
if (previousPressConsumed) {
return;
}
} else if (e.getID() == KeyEvent.KEY_RELEASED) {
boolean isConsumed = AtkWrapper.dispatchKeyEvent(new AtkKeyEvent((KeyEvent)e));
previousPressConsumed = false;
if (isConsumed) {
return;
}
}
}
super.dispatchEvent(e);
}
});
}
public static long getInstanceFromSwing(AccessibleContext ac) {
return AtkUtil.invokeInSwing( () -> { return getInstance(ac); }, 0l);
}
public static void main(String args[]) {
new AtkWrapper();
}
}
|