提交 74ef472b 编写于 作者: A asaha

Merge

...@@ -698,6 +698,8 @@ f5d0aadb4d1ca74eda4e98cc0030f1618ef4c870 jdk8u131-b07 ...@@ -698,6 +698,8 @@ f5d0aadb4d1ca74eda4e98cc0030f1618ef4c870 jdk8u131-b07
40d00399869d8a28cfecf360234f340e9e0ad3b1 jdk8u131-b09 40d00399869d8a28cfecf360234f340e9e0ad3b1 jdk8u131-b09
c0091a673d766ce2e76a945bab6de325fe78dd88 jdk8u131-b10 c0091a673d766ce2e76a945bab6de325fe78dd88 jdk8u131-b10
3ab471c4760a808e39406303ff33a25a542b9c75 jdk8u131-b11 3ab471c4760a808e39406303ff33a25a542b9c75 jdk8u131-b11
d50ccb38def5968145fd3f6e0579416bb027e85c jdk8u131-b31
e54624a8ebe3639d3b2360adb9ae0fa32f1bef57 jdk8u131-b32
a160009bbe1417d85f1c0eec890fdb17391b3637 jdk8u141-b00 a160009bbe1417d85f1c0eec890fdb17391b3637 jdk8u141-b00
e95a13de2d36050302a1af422967f5260fc8eabd jdk8u141-b01 e95a13de2d36050302a1af422967f5260fc8eabd jdk8u141-b01
936085d9aff0554a3bdab2fcbbec1d1864e656a2 jdk8u141-b02 936085d9aff0554a3bdab2fcbbec1d1864e656a2 jdk8u141-b02
......
...@@ -84,6 +84,15 @@ class CAccessibility implements PropertyChangeListener { ...@@ -84,6 +84,15 @@ class CAccessibility implements PropertyChangeListener {
return null; return null;
} }
static <T> T invokeAndWait(final Callable<T> callable, final Component c, final T defValue) {
T value = null;
try {
value = LWCToolkit.invokeAndWait(callable, c);
} catch (final Exception e) { e.printStackTrace(); }
return value != null ? value : defValue;
}
static void invokeLater(final Runnable runnable, final Component c) { static void invokeLater(final Runnable runnable, final Component c) {
try { try {
LWCToolkit.invokeLater(runnable, c); LWCToolkit.invokeLater(runnable, c);
...@@ -179,7 +188,7 @@ class CAccessibility implements PropertyChangeListener { ...@@ -179,7 +188,7 @@ class CAccessibility implements PropertyChangeListener {
return new Boolean(as.isAccessibleChildSelected(index)); return new Boolean(as.isAccessibleChildSelected(index));
} }
}, c); }, c, false);
} }
public static AccessibleStateSet getAccessibleStateSet(final AccessibleContext ac, final Component c) { public static AccessibleStateSet getAccessibleStateSet(final AccessibleContext ac, final Component c) {
...@@ -201,7 +210,7 @@ class CAccessibility implements PropertyChangeListener { ...@@ -201,7 +210,7 @@ class CAccessibility implements PropertyChangeListener {
if (ass == null) return null; if (ass == null) return null;
return ass.contains(as); return ass.contains(as);
} }
}, c); }, c, false);
} }
static Field getAccessibleBundleKeyFieldWithReflection() { static Field getAccessibleBundleKeyFieldWithReflection() {
...@@ -267,7 +276,7 @@ class CAccessibility implements PropertyChangeListener { ...@@ -267,7 +276,7 @@ class CAccessibility implements PropertyChangeListener {
public Integer call() throws Exception { public Integer call() throws Exception {
return at.getCharCount(); return at.getCharCount();
} }
}, c); }, c, 0);
} }
// Accessibility Threadsafety for JavaComponentAccessibility.m // Accessibility Threadsafety for JavaComponentAccessibility.m
...@@ -284,7 +293,7 @@ class CAccessibility implements PropertyChangeListener { ...@@ -284,7 +293,7 @@ class CAccessibility implements PropertyChangeListener {
} }
public static int getAccessibleIndexInParent(final Accessible a, final Component c) { public static int getAccessibleIndexInParent(final Accessible a, final Component c) {
if (a == null) return 0; if (a == null) return -1;
return invokeAndWait(new Callable<Integer>() { return invokeAndWait(new Callable<Integer>() {
public Integer call() throws Exception { public Integer call() throws Exception {
...@@ -292,7 +301,7 @@ class CAccessibility implements PropertyChangeListener { ...@@ -292,7 +301,7 @@ class CAccessibility implements PropertyChangeListener {
if (ac == null) return null; if (ac == null) return null;
return ac.getAccessibleIndexInParent(); return ac.getAccessibleIndexInParent();
} }
}, c); }, c, -1);
} }
public static AccessibleComponent getAccessibleComponent(final Accessible a, final Component c) { public static AccessibleComponent getAccessibleComponent(final Accessible a, final Component c) {
...@@ -388,7 +397,7 @@ class CAccessibility implements PropertyChangeListener { ...@@ -388,7 +397,7 @@ class CAccessibility implements PropertyChangeListener {
return aComp.isFocusTraversable(); return aComp.isFocusTraversable();
} }
}, c); }, c, false);
} }
public static Accessible accessibilityHitTest(final Container parent, final float hitPointX, final float hitPointY) { public static Accessible accessibilityHitTest(final Container parent, final float hitPointX, final float hitPointY) {
...@@ -447,7 +456,7 @@ class CAccessibility implements PropertyChangeListener { ...@@ -447,7 +456,7 @@ class CAccessibility implements PropertyChangeListener {
return aComp.isEnabled(); return aComp.isEnabled();
} }
}, c); }, c, false);
} }
// KCH - can we make this a postEvent instead? // KCH - can we make this a postEvent instead?
...@@ -467,6 +476,24 @@ class CAccessibility implements PropertyChangeListener { ...@@ -467,6 +476,24 @@ class CAccessibility implements PropertyChangeListener {
}, c); }, c);
} }
public static void requestSelection(final Accessible a, final Component c) {
if (a == null) return;
invokeLater(new Runnable() {
public void run() {
AccessibleContext ac = a.getAccessibleContext();
if (ac == null) return;
int i = ac.getAccessibleIndexInParent();
if (i == -1) return;
Accessible parent = ac.getAccessibleParent();
AccessibleContext pac = parent.getAccessibleContext();
if (pac == null) return;
AccessibleSelection as = pac.getAccessibleSelection();
if (as == null) return;
as.addAccessibleSelection(i);
}
}, c);
}
public static Number getMaximumAccessibleValue(final Accessible a, final Component c) { public static Number getMaximumAccessibleValue(final Accessible a, final Component c) {
if (a == null) return null; if (a == null) return null;
...@@ -571,9 +598,57 @@ class CAccessibility implements PropertyChangeListener { ...@@ -571,9 +598,57 @@ class CAccessibility implements PropertyChangeListener {
if (a == null) return null; if (a == null) return null;
return invokeAndWait(new Callable<Object[]>() { return invokeAndWait(new Callable<Object[]>() {
public Object[] call() throws Exception { public Object[] call() throws Exception {
final ArrayList<Object> childrenAndRoles = new ArrayList<Object>(); ArrayList<Object> childrenAndRoles = new ArrayList<Object>();
_addChildren(a, whichChildren, allowIgnored, childrenAndRoles); _addChildren(a, whichChildren, allowIgnored, childrenAndRoles);
/* In the case of fetching a selection, need to check to see if
* the active descendant is at the beginning of the list. If it
* is not it needs to be moved to the beginning of the list so
* VoiceOver will annouce it correctly. The list returned
* from Java is always in order from top to bottom, but when shift
* selecting downward (extending the list) or multi-selecting using
* the VO keys control+option+command+return the active descendant
* is not at the top of the list in the shift select down case and
* may not be in the multi select case.
*/
if (whichChildren == JAVA_AX_SELECTED_CHILDREN) {
if (!childrenAndRoles.isEmpty()) {
AccessibleContext activeDescendantAC =
CAccessible.getActiveDescendant(a);
if (activeDescendantAC != null) {
String activeDescendantName =
activeDescendantAC.getAccessibleName();
AccessibleRole activeDescendantRole =
activeDescendantAC.getAccessibleRole();
// Move active descendant to front of list.
// List contains pairs of each selected item's
// Accessible and AccessibleRole.
ArrayList<Object> newArray = new ArrayList<Object>();
int count = childrenAndRoles.size();
Accessible currentAccessible = null;
AccessibleContext currentAC = null;
String currentName = null;
AccessibleRole currentRole = null;
for (int i = 0; i < count; i+=2) {
// Is this the active descendant?
currentAccessible = (Accessible)childrenAndRoles.get(i);
currentAC = currentAccessible.getAccessibleContext();
currentName = currentAC.getAccessibleName();
currentRole = (AccessibleRole)childrenAndRoles.get(i+1);
if ( currentName.equals(activeDescendantName) &&
currentRole.equals(activeDescendantRole) ) {
newArray.add(0, currentAccessible);
newArray.add(1, currentRole);
} else {
newArray.add(currentAccessible);
newArray.add(currentRole);
}
}
childrenAndRoles = newArray;
}
}
}
if ((whichChildren < 0) || (whichChildren * 2 >= childrenAndRoles.size())) { if ((whichChildren < 0) || (whichChildren * 2 >= childrenAndRoles.size())) {
return childrenAndRoles.toArray(); return childrenAndRoles.toArray();
} }
......
/* /*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,19 +26,21 @@ ...@@ -26,19 +26,21 @@
package sun.lwawt.macosx; package sun.lwawt.macosx;
import java.awt.Component; import java.awt.Component;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import javax.accessibility.Accessible; import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext; import javax.accessibility.AccessibleContext;
import javax.swing.JProgressBar; import javax.swing.JProgressBar;
import javax.swing.JSlider; import javax.swing.JSlider;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import static javax.accessibility.AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY;
import javax.swing.text.JTextComponent; import static javax.accessibility.AccessibleContext.ACCESSIBLE_CARET_PROPERTY;
import static javax.accessibility.AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY;
import static javax.accessibility.AccessibleContext.ACCESSIBLE_TEXT_PROPERTY;
class CAccessible extends CFRetainedResource implements Accessible { class CAccessible extends CFRetainedResource implements Accessible {
...@@ -73,10 +75,13 @@ class CAccessible extends CFRetainedResource implements Accessible { ...@@ -73,10 +75,13 @@ class CAccessible extends CFRetainedResource implements Accessible {
private static native void unregisterFromCocoaAXSystem(long ptr); private static native void unregisterFromCocoaAXSystem(long ptr);
private static native void valueChanged(long ptr); private static native void valueChanged(long ptr);
private static native void selectedTextChanged(long ptr);
private static native void selectionChanged(long ptr); private static native void selectionChanged(long ptr);
private Accessible accessible; private Accessible accessible;
private AccessibleContext activeDescendant;
private CAccessible(final Accessible accessible) { private CAccessible(final Accessible accessible) {
super(0L, true); // real pointer will be poked in by native super(0L, true); // real pointer will be poked in by native
...@@ -99,13 +104,10 @@ class CAccessible extends CFRetainedResource implements Accessible { ...@@ -99,13 +104,10 @@ class CAccessible extends CFRetainedResource implements Accessible {
return accessible.getAccessibleContext(); return accessible.getAccessibleContext();
} }
// currently only supports text components
public void addNotificationListeners(Component c) { public void addNotificationListeners(Component c) {
if (c instanceof JTextComponent) { if (c instanceof Accessible) {
JTextComponent tc = (JTextComponent) c; AccessibleContext ac = ((Accessible)c).getAccessibleContext();
AXTextChangeNotifier listener = new AXTextChangeNotifier(); ac.addPropertyChangeListener(new AXChangeNotifier());
tc.getDocument().addDocumentListener(listener);
tc.addCaretListener(listener);
} }
if (c instanceof JProgressBar) { if (c instanceof JProgressBar) {
JProgressBar pb = (JProgressBar) c; JProgressBar pb = (JProgressBar) c;
...@@ -117,29 +119,30 @@ class CAccessible extends CFRetainedResource implements Accessible { ...@@ -117,29 +119,30 @@ class CAccessible extends CFRetainedResource implements Accessible {
} }
private class AXTextChangeNotifier implements DocumentListener, CaretListener { private class AXChangeNotifier implements PropertyChangeListener {
@Override
public void changedUpdate(DocumentEvent e) {
if (ptr != 0) valueChanged(ptr);
}
@Override @Override
public void insertUpdate(DocumentEvent e) { public void propertyChange(PropertyChangeEvent e) {
if (ptr != 0) valueChanged(ptr); String name = e.getPropertyName();
} if ( ptr != 0 ) {
if (name.compareTo(ACCESSIBLE_CARET_PROPERTY) == 0) {
@Override selectedTextChanged(ptr);
public void removeUpdate(DocumentEvent e) { } else if (name.compareTo(ACCESSIBLE_TEXT_PROPERTY) == 0 ) {
if (ptr != 0) valueChanged(ptr); valueChanged(ptr);
} } else if (name.compareTo(ACCESSIBLE_SELECTION_PROPERTY) == 0 ) {
selectionChanged(ptr);
@Override } else if (name.compareTo(ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY) == 0 ) {
public void caretUpdate(CaretEvent e) { Object nv = e.getNewValue();
if (ptr != 0) selectionChanged(ptr); if (nv instanceof AccessibleContext) {
activeDescendant = (AccessibleContext)nv;
}
}
}
} }
} }
private class AXProgressChangeNotifier implements ChangeListener { private class AXProgressChangeNotifier implements ChangeListener {
@Override
public void stateChanged(ChangeEvent e) { public void stateChanged(ChangeEvent e) {
if (ptr != 0) valueChanged(ptr); if (ptr != 0) valueChanged(ptr);
} }
...@@ -148,4 +151,9 @@ class CAccessible extends CFRetainedResource implements Accessible { ...@@ -148,4 +151,9 @@ class CAccessible extends CFRetainedResource implements Accessible {
static Accessible getSwingAccessible(final Accessible a) { static Accessible getSwingAccessible(final Accessible a) {
return (a instanceof CAccessible) ? ((CAccessible)a).accessible : a; return (a instanceof CAccessible) ? ((CAccessible)a).accessible : a;
} }
static AccessibleContext getActiveDescendant(final Accessible a) {
return (a instanceof CAccessible) ? ((CAccessible)a).activeDescendant : null;
}
} }
...@@ -213,6 +213,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -213,6 +213,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
private boolean isFullScreenAnimationOn; private boolean isFullScreenAnimationOn;
private volatile boolean isIconifyAnimationActive; private volatile boolean isIconifyAnimationActive;
private volatile boolean isZoomed;
private Window target; private Window target;
private LWWindowPeer peer; private LWWindowPeer peer;
...@@ -497,14 +498,8 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -497,14 +498,8 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
} }
private boolean isMaximized() { private boolean isMaximized() {
if (undecorated) { return undecorated ? this.normalBounds != null
return this.normalBounds != null; : isZoomed;
}
AtomicBoolean ref = new AtomicBoolean();
execute(ptr -> {
ref.set(CWrapper.NSWindow.isZoomed(ptr));
});
return ref.get();
} }
private void maximize() { private void maximize() {
...@@ -970,6 +965,11 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -970,6 +965,11 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
protected void deliverMoveResizeEvent(int x, int y, int width, int height, protected void deliverMoveResizeEvent(int x, int y, int width, int height,
boolean byUser) { boolean byUser) {
AtomicBoolean ref = new AtomicBoolean();
execute(ptr -> {
ref.set(CWrapper.NSWindow.isZoomed(ptr));
});
isZoomed = ref.get();
checkZoom(); checkZoom();
final Rectangle oldB = nativeBounds; final Rectangle oldB = nativeBounds;
......
...@@ -361,9 +361,11 @@ static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobj ...@@ -361,9 +361,11 @@ static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobj
static JNF_MEMBER_CACHE(jm_isCollated, sjc_CPrinterJob, "isCollated", "()Z"); static JNF_MEMBER_CACHE(jm_isCollated, sjc_CPrinterJob, "isCollated", "()Z");
static JNF_MEMBER_CACHE(jm_getFromPage, sjc_CPrinterJob, "getFromPageAttrib", "()I"); static JNF_MEMBER_CACHE(jm_getFromPage, sjc_CPrinterJob, "getFromPageAttrib", "()I");
static JNF_MEMBER_CACHE(jm_getToPage, sjc_CPrinterJob, "getToPageAttrib", "()I"); static JNF_MEMBER_CACHE(jm_getToPage, sjc_CPrinterJob, "getToPageAttrib", "()I");
static JNF_MEMBER_CACHE(jm_getMinPage, sjc_CPrinterJob, "getMinPageAttrib", "()I");
static JNF_MEMBER_CACHE(jm_getMaxPage, sjc_CPrinterJob, "getMaxPageAttrib", "()I");
static JNF_MEMBER_CACHE(jm_getSelectAttrib, sjc_CPrinterJob, "getSelectAttrib", "()I"); static JNF_MEMBER_CACHE(jm_getSelectAttrib, sjc_CPrinterJob, "getSelectAttrib", "()I");
static JNF_MEMBER_CACHE(jm_getNumberOfPages, jc_Pageable, "getNumberOfPages", "()I"); static JNF_MEMBER_CACHE(jm_getNumberOfPages, jc_Pageable, "getNumberOfPages", "()I");
static JNF_MEMBER_CACHE(jm_getPageFormat, sjc_CPrinterJob, "getPageFormatFromAttributes", "()Ljava/awt/print/PageFormat;"); static JNF_MEMBER_CACHE(jm_getPageFormat, sjc_CPrinterJob, "getPageFormat", "(I)Ljava/awt/print/PageFormat;");
NSMutableDictionary* printingDictionary = [dst dictionary]; NSMutableDictionary* printingDictionary = [dst dictionary];
...@@ -372,32 +374,34 @@ static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobj ...@@ -372,32 +374,34 @@ static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobj
jboolean collated = JNFCallBooleanMethod(env, srcPrinterJob, jm_isCollated); // AWT_THREADING Safe (known object) jboolean collated = JNFCallBooleanMethod(env, srcPrinterJob, jm_isCollated); // AWT_THREADING Safe (known object)
[printingDictionary setObject:[NSNumber numberWithBool:collated ? YES : NO] forKey:NSPrintMustCollate]; [printingDictionary setObject:[NSNumber numberWithBool:collated ? YES : NO] forKey:NSPrintMustCollate];
jint jNumPages = JNFCallIntMethod(env, srcPageable, jm_getNumberOfPages); // AWT_THREADING Safe (!appKit) jint selectID = JNFCallIntMethod(env, srcPrinterJob, jm_getSelectAttrib);
if (jNumPages != java_awt_print_Pageable_UNKNOWN_NUMBER_OF_PAGES) jint fromPage = JNFCallIntMethod(env, srcPrinterJob, jm_getFromPage);
{ jint toPage = JNFCallIntMethod(env, srcPrinterJob, jm_getToPage);
jint selectID = JNFCallIntMethod(env, srcPrinterJob, jm_getSelectAttrib); if (selectID ==0) {
if (selectID ==0) { [printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintAllPages];
[printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintAllPages]; } else if (selectID == 2) {
} else if (selectID == 2) { // In Mac 10.7, Print ALL is deselected if PrintSelection is YES whether
// In Mac 10.7, Print ALL is deselected if PrintSelection is YES whether // NSPrintAllPages is YES or NO
// NSPrintAllPages is YES or NO [printingDictionary setObject:[NSNumber numberWithBool:NO] forKey:NSPrintAllPages];
[printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintSelectionOnly];
} else {
jint minPage = JNFCallIntMethod(env, srcPrinterJob, jm_getMinPage);
jint maxPage = JNFCallIntMethod(env, srcPrinterJob, jm_getMaxPage);
// for PD_SELECTION or PD_NOSELECTION, check from/to page
// to determine which radio button to select
if (fromPage > minPage || toPage < maxPage) {
[printingDictionary setObject:[NSNumber numberWithBool:NO] forKey:NSPrintAllPages]; [printingDictionary setObject:[NSNumber numberWithBool:NO] forKey:NSPrintAllPages];
[printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintSelectionOnly];
} else { } else {
[printingDictionary setObject:[NSNumber numberWithBool:NO] forKey:NSPrintAllPages]; [printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintAllPages];
} }
jint fromPage = JNFCallIntMethod(env, srcPrinterJob, jm_getFromPage);
jint toPage = JNFCallIntMethod(env, srcPrinterJob, jm_getToPage);
// setting fromPage and toPage will not be shown in the dialog if printing All pages
[printingDictionary setObject:[NSNumber numberWithInteger:fromPage] forKey:NSPrintFirstPage];
[printingDictionary setObject:[NSNumber numberWithInteger:toPage] forKey:NSPrintLastPage];
}
else
{
[printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintAllPages];
} }
jobject page = JNFCallObjectMethod(env, srcPrinterJob, jm_getPageFormat);
// setting fromPage and toPage will not be shown in the dialog if printing All pages
[printingDictionary setObject:[NSNumber numberWithInteger:fromPage] forKey:NSPrintFirstPage];
[printingDictionary setObject:[NSNumber numberWithInteger:toPage] forKey:NSPrintLastPage];
jobject page = JNFCallObjectMethod(env, srcPrinterJob, jm_getPageFormat, (jint)0);
if (page != NULL) { if (page != NULL) {
javaPageFormatToNSPrintInfo(env, NULL, page, dst); javaPageFormatToNSPrintInfo(env, NULL, page, dst);
} }
......
...@@ -64,16 +64,20 @@ ...@@ -64,16 +64,20 @@
jobject fCompLocal = (*env)->NewLocalRef(env, fComponent); jobject fCompLocal = (*env)->NewLocalRef(env, fComponent);
if ((*env)->IsSameObject(env, fCompLocal, NULL)) { if ((*env)->IsSameObject(env, fCompLocal, NULL)) {
return @"unknown"; return nil;
} }
NSString *str = nil; NSString *str = nil;
jobject jstr = JNFCallStaticObjectMethod(env, jm_getAccessibleActionDescription, fAccessibleAction, fIndex, fCompLocal); jstring jstr = JNFCallStaticObjectMethod( env,
jm_getAccessibleActionDescription,
fAccessibleAction,
fIndex,
fCompLocal );
if (jstr != NULL) { if (jstr != NULL) {
NSString *str = JNFJavaToNSString(env, jstr); // AWT_THREADING Safe (AWTRunLoopMode) str = JNFJavaToNSString(env, jstr); // AWT_THREADING Safe (AWTRunLoopMode)
(*env)->DeleteLocalRef(env, jstr); (*env)->DeleteLocalRef(env, jstr);
} }
(*env)->DeleteLocalRef(env, fCompLocal); (*env)->DeleteLocalRef(env, fCompLocal);
return str == nil ? @"unknown" : str; return str;
} }
- (void)perform - (void)perform
......
/* /*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -55,6 +55,7 @@ BOOL containsAxState(JNIEnv *env, jobject axContext, jobject axState, jobject co ...@@ -55,6 +55,7 @@ BOOL containsAxState(JNIEnv *env, jobject axContext, jobject axState, jobject co
BOOL isVertical(JNIEnv *env, jobject axContext, jobject component); BOOL isVertical(JNIEnv *env, jobject axContext, jobject component);
BOOL isHorizontal(JNIEnv *env, jobject axContext, jobject component); BOOL isHorizontal(JNIEnv *env, jobject axContext, jobject component);
BOOL isShowing(JNIEnv *env, jobject axContext, jobject component); BOOL isShowing(JNIEnv *env, jobject axContext, jobject component);
BOOL isSelectable(JNIEnv *env, jobject axContext, jobject component);
NSPoint getAxComponentLocationOnScreen(JNIEnv *env, jobject axComponent, jobject component); NSPoint getAxComponentLocationOnScreen(JNIEnv *env, jobject axComponent, jobject component);
jint getAxTextCharCount(JNIEnv *env, jobject axText, jobject component); jint getAxTextCharCount(JNIEnv *env, jobject axText, jobject component);
......
...@@ -151,6 +151,18 @@ BOOL isShowing(JNIEnv *env, jobject axContext, jobject component) ...@@ -151,6 +151,18 @@ BOOL isShowing(JNIEnv *env, jobject axContext, jobject component)
return showing; return showing;
} }
BOOL isSelectable(JNIEnv *env, jobject axContext, jobject component)
{
static JNF_STATIC_MEMBER_CACHE( jm_SELECTABLE,
sjc_AccessibleState,
"SELECTABLE",
"Ljavax/accessibility/AccessibleState;" );
jobject axSelectableState = JNFGetStaticObjectField(env, jm_SELECTABLE);
BOOL selectable = containsAxState(env, axContext, axSelectableState, component);
(*env)->DeleteLocalRef(env, axSelectableState);
return selectable;
}
NSPoint getAxComponentLocationOnScreen(JNIEnv *env, jobject axComponent, jobject component) NSPoint getAxComponentLocationOnScreen(JNIEnv *env, jobject axComponent, jobject component)
{ {
static JNF_STATIC_MEMBER_CACHE(jm_getLocationOnScreen, sjc_CAccessibility, "getLocationOnScreen", "(Ljavax/accessibility/AccessibleComponent;Ljava/awt/Component;)Ljava/awt/Point;"); static JNF_STATIC_MEMBER_CACHE(jm_getLocationOnScreen, sjc_CAccessibility, "getLocationOnScreen", "(Ljavax/accessibility/AccessibleComponent;Ljava/awt/Component;)Ljava/awt/Point;");
......
/* /*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
- (id)initWithParent:(NSObject*)parent withEnv:(JNIEnv *)env withAccessible:(jobject)accessible withIndex:(jint)index withView:(NSView *)view withJavaRole:(NSString *)javaRole; - (id)initWithParent:(NSObject*)parent withEnv:(JNIEnv *)env withAccessible:(jobject)accessible withIndex:(jint)index withView:(NSView *)view withJavaRole:(NSString *)javaRole;
- (void)unregisterFromCocoaAXSystem; - (void)unregisterFromCocoaAXSystem;
- (void)postValueChanged; - (void)postValueChanged;
- (void)postSelectedTextChanged;
- (void)postSelectionChanged; - (void)postSelectionChanged;
- (BOOL)isEqual:(id)anObject; - (BOOL)isEqual:(id)anObject;
- (BOOL)isAccessibleWithEnv:(JNIEnv *)env forAccessible:(jobject)accessible; - (BOOL)isAccessibleWithEnv:(JNIEnv *)env forAccessible:(jobject)accessible;
...@@ -71,6 +72,7 @@ ...@@ -71,6 +72,7 @@
- (NSString *)javaRole; - (NSString *)javaRole;
- (BOOL)isMenu; - (BOOL)isMenu;
- (BOOL)isSelected:(JNIEnv *)env; - (BOOL)isSelected:(JNIEnv *)env;
- (BOOL)isSelectable:(JNIEnv *)env;
- (BOOL)isVisible:(JNIEnv *)env; - (BOOL)isVisible:(JNIEnv *)env;
// attribute names // attribute names
...@@ -85,6 +87,8 @@ ...@@ -85,6 +87,8 @@
- (NSArray *)accessibilityChildrenAttribute; - (NSArray *)accessibilityChildrenAttribute;
- (BOOL)accessibilityIsChildrenAttributeSettable; - (BOOL)accessibilityIsChildrenAttributeSettable;
- (NSUInteger)accessibilityIndexOfChild:(id)child; - (NSUInteger)accessibilityIndexOfChild:(id)child;
- (NSArray *)accessibilityArrayAttributeValues:(NSString *)attribute
index:(NSUInteger)index maxCount:(NSUInteger)maxCount;
- (NSNumber *)accessibilityEnabledAttribute; - (NSNumber *)accessibilityEnabledAttribute;
- (BOOL)accessibilityIsEnabledAttributeSettable; - (BOOL)accessibilityIsEnabledAttributeSettable;
- (NSNumber *)accessibilityFocusedAttribute; - (NSNumber *)accessibilityFocusedAttribute;
...@@ -92,6 +96,8 @@ ...@@ -92,6 +96,8 @@
- (void)accessibilitySetFocusedAttribute:(id)value; - (void)accessibilitySetFocusedAttribute:(id)value;
- (NSString *)accessibilityHelpAttribute; - (NSString *)accessibilityHelpAttribute;
- (BOOL)accessibilityIsHelpAttributeSettable; - (BOOL)accessibilityIsHelpAttributeSettable;
- (NSValue *)accessibilityIndexAttribute;
- (BOOL)accessibilityIsIndexAttributeSettable;
- (id)accessibilityMaxValueAttribute; - (id)accessibilityMaxValueAttribute;
- (BOOL)accessibilityIsMaxValueAttributeSettable; - (BOOL)accessibilityIsMaxValueAttributeSettable;
- (id)accessibilityMinValueAttribute; - (id)accessibilityMinValueAttribute;
...@@ -108,6 +114,9 @@ ...@@ -108,6 +114,9 @@
- (BOOL)accessibilityIsRoleDescriptionAttributeSettable; - (BOOL)accessibilityIsRoleDescriptionAttributeSettable;
- (NSArray *)accessibilitySelectedChildrenAttribute; - (NSArray *)accessibilitySelectedChildrenAttribute;
- (BOOL)accessibilityIsSelectedChildrenAttributeSettable; - (BOOL)accessibilityIsSelectedChildrenAttributeSettable;
- (NSNumber *)accessibilitySelectedAttribute;
- (BOOL)accessibilityIsSelectedAttributeSettable;
- (void)accessibilitySetSelectedAttribute:(id)value;
- (NSValue *)accessibilitySizeAttribute; - (NSValue *)accessibilitySizeAttribute;
- (BOOL)accessibilityIsSizeAttributeSettable; - (BOOL)accessibilityIsSizeAttributeSettable;
- (NSString *)accessibilitySubroleAttribute; - (NSString *)accessibilitySubroleAttribute;
......
...@@ -201,12 +201,18 @@ static NSObject *sAttributeNamesLOCK = nil; ...@@ -201,12 +201,18 @@ static NSObject *sAttributeNamesLOCK = nil;
NSAccessibilityPostNotification(self, NSAccessibilityValueChangedNotification); NSAccessibilityPostNotification(self, NSAccessibilityValueChangedNotification);
} }
- (void)postSelectionChanged - (void)postSelectedTextChanged
{ {
AWT_ASSERT_APPKIT_THREAD; AWT_ASSERT_APPKIT_THREAD;
NSAccessibilityPostNotification(self, NSAccessibilitySelectedTextChangedNotification); NSAccessibilityPostNotification(self, NSAccessibilitySelectedTextChangedNotification);
} }
- (void)postSelectionChanged
{
AWT_ASSERT_APPKIT_THREAD;
NSAccessibilityPostNotification(self, NSAccessibilitySelectedChildrenChangedNotification);
}
- (BOOL)isEqual:(id)anObject - (BOOL)isEqual:(id)anObject
{ {
if (![anObject isKindOfClass:[self class]]) return NO; if (![anObject isKindOfClass:[self class]]) return NO;
...@@ -225,7 +231,7 @@ static NSObject *sAttributeNamesLOCK = nil; ...@@ -225,7 +231,7 @@ static NSObject *sAttributeNamesLOCK = nil;
{ {
if (sAttributeNamesForRoleCache == nil) { if (sAttributeNamesForRoleCache == nil) {
sAttributeNamesLOCK = [[NSObject alloc] init]; sAttributeNamesLOCK = [[NSObject alloc] init];
sAttributeNamesForRoleCache = [[NSMutableDictionary alloc] initWithCapacity:10]; sAttributeNamesForRoleCache = [[NSMutableDictionary alloc] initWithCapacity:60];
} }
if (sRoles == nil) { if (sRoles == nil) {
...@@ -281,6 +287,7 @@ static NSObject *sAttributeNamesLOCK = nil; ...@@ -281,6 +287,7 @@ static NSObject *sAttributeNamesLOCK = nil;
+ (NSArray *)childrenOfParent:(JavaComponentAccessibility *)parent withEnv:(JNIEnv *)env withChildrenCode:(NSInteger)whichChildren allowIgnored:(BOOL)allowIgnored + (NSArray *)childrenOfParent:(JavaComponentAccessibility *)parent withEnv:(JNIEnv *)env withChildrenCode:(NSInteger)whichChildren allowIgnored:(BOOL)allowIgnored
{ {
if (parent->fAccessible == NULL) return nil;
jobjectArray jchildrenAndRoles = (jobjectArray)JNFCallStaticObjectMethod(env, jm_getChildrenAndRoles, parent->fAccessible, parent->fComponent, whichChildren, allowIgnored); // AWT_THREADING Safe (AWTRunLoop) jobjectArray jchildrenAndRoles = (jobjectArray)JNFCallStaticObjectMethod(env, jm_getChildrenAndRoles, parent->fAccessible, parent->fComponent, whichChildren, allowIgnored); // AWT_THREADING Safe (AWTRunLoop)
if (jchildrenAndRoles == NULL) return nil; if (jchildrenAndRoles == NULL) return nil;
...@@ -316,11 +323,15 @@ static NSObject *sAttributeNamesLOCK = nil; ...@@ -316,11 +323,15 @@ static NSObject *sAttributeNamesLOCK = nil;
+ (JavaComponentAccessibility *)createWithAccessible:(jobject)jaccessible withEnv:(JNIEnv *)env withView:(NSView *)view + (JavaComponentAccessibility *)createWithAccessible:(jobject)jaccessible withEnv:(JNIEnv *)env withView:(NSView *)view
{ {
JavaComponentAccessibility *ret = nil;
jobject jcomponent = [(AWTView *)view awtComponent:env]; jobject jcomponent = [(AWTView *)view awtComponent:env];
jint index = JNFCallStaticIntMethod(env, sjm_getAccessibleIndexInParent, jaccessible, jcomponent); jint index = JNFCallStaticIntMethod(env, sjm_getAccessibleIndexInParent, jaccessible, jcomponent);
NSString *javaRole = getJavaRole(env, jaccessible, jcomponent); if (index >= 0) {
NSString *javaRole = getJavaRole(env, jaccessible, jcomponent);
ret = [self createWithAccessible:jaccessible role:javaRole index:index withEnv:env withView:view];
}
(*env)->DeleteLocalRef(env, jcomponent); (*env)->DeleteLocalRef(env, jcomponent);
return [self createWithAccessible:jaccessible role:javaRole index:index withEnv:env withView:view]; return ret;
} }
+ (JavaComponentAccessibility *) createWithAccessible:(jobject)jaccessible role:(NSString *)javaRole index:(jint)index withEnv:(JNIEnv *)env withView:(NSView *)view + (JavaComponentAccessibility *) createWithAccessible:(jobject)jaccessible role:(NSString *)javaRole index:(jint)index withEnv:(JNIEnv *)env withView:(NSView *)view
...@@ -370,7 +381,7 @@ static NSObject *sAttributeNamesLOCK = nil; ...@@ -370,7 +381,7 @@ static NSObject *sAttributeNamesLOCK = nil;
{ {
static JNF_STATIC_MEMBER_CACHE(jm_getInitialAttributeStates, sjc_CAccessibility, "getInitialAttributeStates", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)[Z"); static JNF_STATIC_MEMBER_CACHE(jm_getInitialAttributeStates, sjc_CAccessibility, "getInitialAttributeStates", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)[Z");
NSMutableArray *attributeNames = [NSMutableArray arrayWithCapacity:10]; NSMutableArray *attributeNames = [NSMutableArray arrayWithCapacity:20];
[attributeNames retain]; [attributeNames retain];
// all elements respond to parent, role, role description, window, topLevelUIElement, help // all elements respond to parent, role, role description, window, topLevelUIElement, help
...@@ -449,6 +460,12 @@ static NSObject *sAttributeNamesLOCK = nil; ...@@ -449,6 +460,12 @@ static NSObject *sAttributeNamesLOCK = nil;
// children // children
if (attributeStatesArray[6]) { if (attributeStatesArray[6]) {
[attributeNames addObject:NSAccessibilityChildrenAttribute]; [attributeNames addObject:NSAccessibilityChildrenAttribute];
if ([javaRole isEqualToString:@"list"]) {
[attributeNames addObject:NSAccessibilitySelectedChildrenAttribute];
[attributeNames addObject:NSAccessibilityVisibleChildrenAttribute];
}
// Just above, the below mentioned support has been added back in for lists.
// However, the following comments may still be useful for future fixes.
// [attributeNames addObject:NSAccessibilitySelectedChildrenAttribute]; // [attributeNames addObject:NSAccessibilitySelectedChildrenAttribute];
// [attributeNames addObject:NSAccessibilityVisibleChildrenAttribute]; // [attributeNames addObject:NSAccessibilityVisibleChildrenAttribute];
//According to AXRoles.txt: //According to AXRoles.txt:
...@@ -567,6 +584,14 @@ static NSObject *sAttributeNamesLOCK = nil; ...@@ -567,6 +584,14 @@ static NSObject *sAttributeNamesLOCK = nil;
return isChildSelected(env, ((JavaComponentAccessibility *)[self parent])->fAccessible, fIndex, fComponent); return isChildSelected(env, ((JavaComponentAccessibility *)[self parent])->fAccessible, fIndex, fComponent);
} }
- (BOOL)isSelectable:(JNIEnv *)env
{
jobject axContext = [self axContextWithEnv:env];
BOOL selectable = isSelectable(env, axContext, fComponent);
(*env)->DeleteLocalRef(env, axContext);
return selectable;
}
- (BOOL)isVisible:(JNIEnv *)env - (BOOL)isVisible:(JNIEnv *)env
{ {
if (fIndex == -1) { if (fIndex == -1) {
...@@ -586,18 +611,32 @@ static NSObject *sAttributeNamesLOCK = nil; ...@@ -586,18 +611,32 @@ static NSObject *sAttributeNamesLOCK = nil;
@synchronized(sAttributeNamesLOCK) { @synchronized(sAttributeNamesLOCK) {
NSString *javaRole = [self javaRole]; NSString *javaRole = [self javaRole];
NSArray *names = (NSArray *)[sAttributeNamesForRoleCache objectForKey:javaRole]; NSArray *names =
if (names != nil) return names; (NSArray *)[sAttributeNamesForRoleCache objectForKey:javaRole];
if (names == nil) {
names = [self initializeAttributeNamesWithEnv:env]; names = [self initializeAttributeNamesWithEnv:env];
if (names != nil) {
#ifdef JAVA_AX_DEBUG #ifdef JAVA_AX_DEBUG
NSLog(@"Initializing: %s for %@: %@", __FUNCTION__, javaRole, names); NSLog(@"Initializing: %s for %@: %@", __FUNCTION__, javaRole, names);
#endif #endif
[sAttributeNamesForRoleCache setObject:names forKey:javaRole]; [sAttributeNamesForRoleCache setObject:names forKey:javaRole];
return names;
} }
} // The above set of attributes is immutable per role, but some objects, if
// they are the child of a list, need to add the selected and index attributes.
id myParent = [self accessibilityParentAttribute];
if ([myParent isKindOfClass:[JavaComponentAccessibility class]]) {
NSString *parentRole = [(JavaComponentAccessibility *)myParent javaRole];
if ([parentRole isEqualToString:@"list"]) {
NSMutableArray *moreNames =
[[NSMutableArray alloc] initWithCapacity: [names count] + 2];
[moreNames addObjectsFromArray: names];
[moreNames addObject:NSAccessibilitySelectedAttribute];
[moreNames addObject:NSAccessibilityIndexAttribute];
return moreNames;
}
}
return names;
} // end @synchronized
#ifdef JAVA_AX_DEBUG #ifdef JAVA_AX_DEBUG
NSLog(@"Warning in %s: could not find attribute names for role: %@", __FUNCTION__, [self javaRole]); NSLog(@"Warning in %s: could not find attribute names for role: %@", __FUNCTION__, [self javaRole]);
...@@ -656,7 +695,10 @@ static NSObject *sAttributeNamesLOCK = nil; ...@@ -656,7 +695,10 @@ static NSObject *sAttributeNamesLOCK = nil;
- (NSArray *)accessibilityChildrenAttribute - (NSArray *)accessibilityChildrenAttribute
{ {
JNIEnv* env = [ThreadUtilities getJNIEnv]; JNIEnv* env = [ThreadUtilities getJNIEnv];
NSArray *children = [JavaComponentAccessibility childrenOfParent:self withEnv:env withChildrenCode:JAVA_AX_VISIBLE_CHILDREN allowIgnored:NO]; NSArray *children = [JavaComponentAccessibility childrenOfParent:self
withEnv:env
withChildrenCode:JAVA_AX_ALL_CHILDREN
allowIgnored:NO];
NSArray *value = nil; NSArray *value = nil;
if ([children count] > 0) { if ([children count] > 0) {
...@@ -680,7 +722,12 @@ static NSObject *sAttributeNamesLOCK = nil; ...@@ -680,7 +722,12 @@ static NSObject *sAttributeNamesLOCK = nil;
return [super accessibilityIndexOfChild:child]; return [super accessibilityIndexOfChild:child];
} }
return JNFCallStaticIntMethod([ThreadUtilities getJNIEnv], sjm_getAccessibleIndexInParent, ((JavaComponentAccessibility *)child)->fAccessible, ((JavaComponentAccessibility *)child)->fComponent); jint returnValue =
JNFCallStaticIntMethod( [ThreadUtilities getJNIEnv],
sjm_getAccessibleIndexInParent,
((JavaComponentAccessibility *)child)->fAccessible,
((JavaComponentAccessibility *)child)->fComponent );
return (returnValue == -1) ? NSNotFound : returnValue;
} }
// Without this optimization accessibilityChildrenAttribute is called in order to get the entire array of children. // Without this optimization accessibilityChildrenAttribute is called in order to get the entire array of children.
...@@ -754,7 +801,7 @@ static NSObject *sAttributeNamesLOCK = nil; ...@@ -754,7 +801,7 @@ static NSObject *sAttributeNamesLOCK = nil;
jobject val = JNFCallStaticObjectMethod(env, sjm_getAccessibleDescription, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) jobject val = JNFCallStaticObjectMethod(env, sjm_getAccessibleDescription, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
if (val == NULL) { if (val == NULL) {
return @"unknown"; return nil;
} }
NSString* str = JNFJavaToNSString(env, val); NSString* str = JNFJavaToNSString(env, val);
(*env)->DeleteLocalRef(env, val); (*env)->DeleteLocalRef(env, val);
...@@ -766,6 +813,18 @@ static NSObject *sAttributeNamesLOCK = nil; ...@@ -766,6 +813,18 @@ static NSObject *sAttributeNamesLOCK = nil;
return NO; return NO;
} }
- (NSValue *)accessibilityIndexAttribute
{
NSInteger index = fIndex;
NSValue *returnValue = [NSValue value:&index withObjCType:@encode(NSInteger)];
return returnValue;
}
- (BOOL)accessibilityIsIndexAttributeSettable
{
return NO;
}
// Element's maximum value (id) // Element's maximum value (id)
- (id)accessibilityMaxValueAttribute - (id)accessibilityMaxValueAttribute
{ {
...@@ -939,6 +998,33 @@ static NSObject *sAttributeNamesLOCK = nil; ...@@ -939,6 +998,33 @@ static NSObject *sAttributeNamesLOCK = nil;
return NO; // cmcnote: actually it should be. so need to write accessibilitySetSelectedChildrenAttribute also return NO; // cmcnote: actually it should be. so need to write accessibilitySetSelectedChildrenAttribute also
} }
- (NSNumber *)accessibilitySelectedAttribute
{
return [NSNumber numberWithBool:[self isSelected:[ThreadUtilities getJNIEnv]]];
}
- (BOOL)accessibilityIsSelectedAttributeSettable
{
if ([self isSelectable:[ThreadUtilities getJNIEnv]]) {
return YES;
} else {
return NO;
}
}
- (void)accessibilitySetSelectedAttribute:(id)value
{
static JNF_STATIC_MEMBER_CACHE( jm_requestSelection,
sjc_CAccessibility,
"requestSelection",
"(Ljavax/accessibility/Accessible;Ljava/awt/Component;)V" );
if ([(NSNumber*)value boolValue]) {
JNIEnv* env = [ThreadUtilities getJNIEnv];
JNFCallStaticVoidMethod(env, jm_requestSelection, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
}
}
// Element size (NSValue) // Element size (NSValue)
- (NSValue *)accessibilitySizeAttribute { - (NSValue *)accessibilitySizeAttribute {
JNIEnv* env = [ThreadUtilities getJNIEnv]; JNIEnv* env = [ThreadUtilities getJNIEnv];
...@@ -1005,7 +1091,7 @@ static NSObject *sAttributeNamesLOCK = nil; ...@@ -1005,7 +1091,7 @@ static NSObject *sAttributeNamesLOCK = nil;
jobject val = JNFCallStaticObjectMethod(env, sjm_getAccessibleName, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) jobject val = JNFCallStaticObjectMethod(env, sjm_getAccessibleName, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
if (val == NULL) { if (val == NULL) {
return @"unknown"; return nil;
} }
NSString* str = JNFJavaToNSString(env, val); NSString* str = JNFJavaToNSString(env, val);
(*env)->DeleteLocalRef(env, val); (*env)->DeleteLocalRef(env, val);
...@@ -1210,14 +1296,11 @@ static NSObject *sAttributeNamesLOCK = nil; ...@@ -1210,14 +1296,11 @@ static NSObject *sAttributeNamesLOCK = nil;
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CAccessibility_focusChanged JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CAccessibility_focusChanged
(JNIEnv *env, jobject jthis) (JNIEnv *env, jobject jthis)
{ {
JNF_COCOA_ENTER(env); JNF_COCOA_ENTER(env);
[ThreadUtilities performOnMainThread:@selector(postFocusChanged:) on:[JavaComponentAccessibility class] withObject:nil waitUntilDone:NO]; [ThreadUtilities performOnMainThread:@selector(postFocusChanged:) on:[JavaComponentAccessibility class] withObject:nil waitUntilDone:NO];
JNF_COCOA_EXIT(env); JNF_COCOA_EXIT(env);
} }
/* /*
* Class: sun_lwawt_macosx_CAccessible * Class: sun_lwawt_macosx_CAccessible
* Method: valueChanged * Method: valueChanged
...@@ -1231,6 +1314,22 @@ JNF_COCOA_ENTER(env); ...@@ -1231,6 +1314,22 @@ JNF_COCOA_ENTER(env);
JNF_COCOA_EXIT(env); JNF_COCOA_EXIT(env);
} }
/*
* Class: sun_lwawt_macosx_CAccessible
* Method: selectedTextChanged
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CAccessible_selectedTextChanged
(JNIEnv *env, jclass jklass, jlong element)
{
JNF_COCOA_ENTER(env);
[ThreadUtilities performOnMainThread:@selector(postSelectedTextChanged)
on:(JavaComponentAccessibility *)jlong_to_ptr(element)
withObject:nil
waitUntilDone:NO];
JNF_COCOA_EXIT(env);
}
/* /*
* Class: sun_lwawt_macosx_CAccessible * Class: sun_lwawt_macosx_CAccessible
* Method: selectionChanged * Method: selectionChanged
...@@ -1244,7 +1343,6 @@ JNF_COCOA_ENTER(env); ...@@ -1244,7 +1343,6 @@ JNF_COCOA_ENTER(env);
JNF_COCOA_EXIT(env); JNF_COCOA_EXIT(env);
} }
/* /*
* Class: sun_lwawt_macosx_CAccessible * Class: sun_lwawt_macosx_CAccessible
* Method: unregisterFromCocoaAXSystem * Method: unregisterFromCocoaAXSystem
......
/* /*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -60,6 +60,4 @@ ...@@ -60,6 +60,4 @@
- (NSValue *)accessibilityRangeForPositionAttributeForParameter:(id)parameter; - (NSValue *)accessibilityRangeForPositionAttributeForParameter:(id)parameter;
- (NSValue *)accessibilityRangeForIndexAttributeForParameter:(id)parameter; - (NSValue *)accessibilityRangeForIndexAttributeForParameter:(id)parameter;
// actions
- (NSDictionary *)getActions:(JNIEnv *)env;
@end @end
...@@ -427,13 +427,15 @@ NSValue *javaIntArrayToNSRangeValue(JNIEnv* env, jintArray array) { ...@@ -427,13 +427,15 @@ NSValue *javaIntArrayToNSRangeValue(JNIEnv* env, jintArray array) {
return javaIntArrayToNSRangeValue(env, axTextRange); return javaIntArrayToNSRangeValue(env, axTextRange);
} }
- (NSDictionary *)getActions:(JNIEnv *)env { /*
// cmcnote: this isn't correct; text can have actions. Not yet implemented. radr://3941691 * - (NSDictionary *)getActions:(JNIEnv *)env { ... }
// Editable text has AXShowMenu. Textfields have AXConfirm. Static text has no actions. *
#ifdef JAVA_AX_DEBUG * In the future, possibly add support: Editable text has AXShowMenu.
NSLog(@"Not yet implemented: %s\n", __FUNCTION__); * Textfields have AXConfirm.
#endif *
return nil; * Note: JLabels (static text) in JLists have a press/click selection action
} * which is currently handled in superclass JavaComponentAccessibility.
* If function is added here be sure to use [super getActions:env] for JLabels.
*/
@end @end
...@@ -3052,7 +3052,7 @@ public class JList<E> extends JComponent implements Scrollable, Accessible ...@@ -3052,7 +3052,7 @@ public class JList<E> extends JComponent implements Scrollable, Accessible
public Accessible getAccessibleAt(Point p) { public Accessible getAccessibleAt(Point p) {
int i = locationToIndex(p); int i = locationToIndex(p);
if (i >= 0) { if (i >= 0) {
return new AccessibleJListChild(JList.this, i); return new ActionableAccessibleJListChild(JList.this, i);
} else { } else {
return null; return null;
} }
...@@ -3079,7 +3079,7 @@ public class JList<E> extends JComponent implements Scrollable, Accessible ...@@ -3079,7 +3079,7 @@ public class JList<E> extends JComponent implements Scrollable, Accessible
if (i >= getModel().getSize()) { if (i >= getModel().getSize()) {
return null; return null;
} else { } else {
return new AccessibleJListChild(JList.this, i); return new ActionableAccessibleJListChild(JList.this, i);
} }
} }
...@@ -3184,7 +3184,7 @@ public class JList<E> extends JComponent implements Scrollable, Accessible ...@@ -3184,7 +3184,7 @@ public class JList<E> extends JComponent implements Scrollable, Accessible
protected class AccessibleJListChild extends AccessibleContext protected class AccessibleJListChild extends AccessibleContext
implements Accessible, AccessibleComponent { implements Accessible, AccessibleComponent {
private JList<E> parent = null; private JList<E> parent = null;
private int indexInParent; int indexInParent;
private Component component = null; private Component component = null;
private AccessibleContext accessibleContext = null; private AccessibleContext accessibleContext = null;
private ListModel<E> listModel; private ListModel<E> listModel;
...@@ -3204,7 +3204,7 @@ public class JList<E> extends JComponent implements Scrollable, Accessible ...@@ -3204,7 +3204,7 @@ public class JList<E> extends JComponent implements Scrollable, Accessible
return getComponentAtIndex(indexInParent); return getComponentAtIndex(indexInParent);
} }
private AccessibleContext getCurrentAccessibleContext() { AccessibleContext getCurrentAccessibleContext() {
Component c = getComponentAtIndex(indexInParent); Component c = getComponentAtIndex(indexInParent);
if (c instanceof Accessible) { if (c instanceof Accessible) {
return c.getAccessibleContext(); return c.getAccessibleContext();
...@@ -3370,10 +3370,6 @@ public class JList<E> extends JComponent implements Scrollable, Accessible ...@@ -3370,10 +3370,6 @@ public class JList<E> extends JComponent implements Scrollable, Accessible
} }
} }
public AccessibleAction getAccessibleAction() {
return getCurrentAccessibleContext().getAccessibleAction();
}
/** /**
* Get the AccessibleComponent associated with this object. In the * Get the AccessibleComponent associated with this object. In the
* implementation of the Java Accessibility API for this class, * implementation of the Java Accessibility API for this class,
...@@ -3387,15 +3383,18 @@ public class JList<E> extends JComponent implements Scrollable, Accessible ...@@ -3387,15 +3383,18 @@ public class JList<E> extends JComponent implements Scrollable, Accessible
} }
public AccessibleSelection getAccessibleSelection() { public AccessibleSelection getAccessibleSelection() {
return getCurrentAccessibleContext().getAccessibleSelection(); AccessibleContext ac = getCurrentAccessibleContext();
return ac != null ? ac.getAccessibleSelection() : null;
} }
public AccessibleText getAccessibleText() { public AccessibleText getAccessibleText() {
return getCurrentAccessibleContext().getAccessibleText(); AccessibleContext ac = getCurrentAccessibleContext();
return ac != null ? ac.getAccessibleText() : null;
} }
public AccessibleValue getAccessibleValue() { public AccessibleValue getAccessibleValue() {
return getCurrentAccessibleContext().getAccessibleValue(); AccessibleContext ac = getCurrentAccessibleContext();
return ac != null ? ac.getAccessibleValue() : null;
} }
...@@ -3588,7 +3587,13 @@ public class JList<E> extends JComponent implements Scrollable, Accessible ...@@ -3588,7 +3587,13 @@ public class JList<E> extends JComponent implements Scrollable, Accessible
public Point getLocationOnScreen() { public Point getLocationOnScreen() {
if (parent != null) { if (parent != null) {
Point listLocation = parent.getLocationOnScreen(); Point listLocation;
try {
listLocation = parent.getLocationOnScreen();
} catch (IllegalComponentStateException e) {
// This can happen if the component isn't visisble
return null;
}
Point componentLocation = parent.indexToLocation(indexInParent); Point componentLocation = parent.indexToLocation(indexInParent);
if (componentLocation != null) { if (componentLocation != null) {
componentLocation.translate(listLocation.x, listLocation.y); componentLocation.translate(listLocation.x, listLocation.y);
...@@ -3728,6 +3733,57 @@ public class JList<E> extends JComponent implements Scrollable, Accessible ...@@ -3728,6 +3733,57 @@ public class JList<E> extends JComponent implements Scrollable, Accessible
return null; return null;
} }
} }
} // inner class AccessibleJListChild } // inner class AccessibleJListChild
private class ActionableAccessibleJListChild
extends AccessibleJListChild
implements AccessibleAction {
ActionableAccessibleJListChild(JList<E> parent, int indexInParent) {
super(parent, indexInParent);
}
@Override
public AccessibleAction getAccessibleAction() {
AccessibleContext ac = getCurrentAccessibleContext();
if (ac == null) {
return null;
} else {
AccessibleAction aa = ac.getAccessibleAction();
if (aa != null) {
return aa;
} else {
return this;
}
}
}
@Override
public boolean doAccessibleAction(int i) {
if (i == 0) {
JList.this.setSelectedIndex(indexInParent);
return true;
} else {
return false;
}
}
@Override
public String getAccessibleActionDescription(int i) {
if (i == 0) {
return UIManager.getString("AbstractButton.clickText");
} else {
return null;
}
}
@Override
public int getAccessibleActionCount() {
return 1;
}
} // inner class ActionableAccessibleJListChild
} // inner class AccessibleJList } // inner class AccessibleJList
} }
...@@ -818,14 +818,6 @@ public abstract class RasterPrinterJob extends PrinterJob { ...@@ -818,14 +818,6 @@ public abstract class RasterPrinterJob extends PrinterJob {
} }
} }
protected PageFormat getPageFormatFromAttributes() {
if (attributes == null || attributes.isEmpty()) {
return null;
}
return attributeToPageFormat(getPrintService(), this.attributes);
}
/** /**
* Presents the user a dialog for changing properties of the * Presents the user a dialog for changing properties of the
* print job interactively. * print job interactively.
......
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8176490
* @summary Tests that there is no hang or deadlock when the visibility
* of parent and child windows is changed.
* @library ../../regtesthelpers
* @build Util
* @run main/timeout=20 WindowDeadlockTest
*/
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.Robot;
import test.java.awt.regtesthelpers.Util;
public class WindowDeadlockTest {
public static void main(String[] args) throws Exception {
Robot robot = Util.createRobot();
Frame main = new Frame("Main");
main.setBounds(0, 0, 200, 100);
main.setVisible(true);
Dialog first = new Dialog(main, "First");
first.setBounds(250, 0, 200, 100);
first.setVisible(true);
Dialog second = new Dialog(first, "Second");
second.setBounds(0, 150, 200, 100);
second.setVisible(true);
Util.waitForIdle(robot);
robot.delay(2000);
Dialog third = new Dialog(first, "Third", false);
third.setBounds(250, 150, 200, 100);
third.setVisible(true);
first.setVisible(false); // the hang takes place here
Util.waitForIdle(robot);
robot.delay(2000);
third.dispose();
second.dispose();
first.dispose();
main.dispose();
}
}
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
@bug 8167102
@summary PrintRequestAttributeSet breaks page size set using PageFormat
@run main/manual WrongPaperPrintingTest
*/
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.Size2DSyntax;
import javax.print.attribute.standard.Chromaticity;
import javax.print.attribute.standard.MediaSize;
import javax.print.attribute.standard.MediaSizeName;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.WindowConstants;
public class WrongPaperPrintingTest implements Printable {
private static final CountDownLatch testEndedSignal = new CountDownLatch(1);
private static final int testTimeout = 300000;
private static volatile String testFailureMsg;
private static volatile boolean testPassed;
private static volatile boolean testFinished;
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> createAndShowTestDialog());
try {
if (!testEndedSignal.await(testTimeout, TimeUnit.MILLISECONDS)) {
throw new RuntimeException(String.format(
"Test timeout '%d ms' elapsed.", testTimeout));
}
if (!testPassed) {
String failureMsg = testFailureMsg;
if ((failureMsg != null) && (!failureMsg.trim().isEmpty())) {
throw new RuntimeException(failureMsg);
} else {
throw new RuntimeException("Test failed.");
}
}
} catch (InterruptedException ie) {
throw new RuntimeException(ie);
} finally {
testFinished = true;
}
}
private static void doTest() {
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(Chromaticity.MONOCHROME);
MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
Paper paper = new Paper();
paper.setSize(size[0] * 72.0, size[1] * 72.0);
paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
PageFormat pf = new PageFormat();
pf.setPaper(paper);
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(new WrongPaperPrintingTest(), job.validatePage(pf));
if (job.printDialog()) {
try {
job.print(aset);
} catch (PrinterException pe) {
throw new RuntimeException(pe);
}
}
}
private static void pass() {
testPassed = true;
testEndedSignal.countDown();
}
private static void fail(String failureMsg) {
testFailureMsg = failureMsg;
testPassed = false;
testEndedSignal.countDown();
}
private static String convertMillisToTimeStr(int millis) {
if (millis < 0) {
return "00:00:00";
}
int hours = millis / 3600000;
int minutes = (millis - hours * 3600000) / 60000;
int seconds = (millis - hours * 3600000 - minutes * 60000) / 1000;
return String.format("%02d:%02d:%02d", hours, minutes, seconds);
}
private static void createAndShowTestDialog() {
String description =
" To run this test it is required to have a virtual PDF\r\n" +
" printer or any other printer supporting A5 paper size.\r\n" +
"\r\n" +
" 1. Verify that NOT A5 paper size is set as default for the\r\n" +
" printer to be used.\r\n" +
" 2. Click on \"Start Test\" button.\r\n" +
" 3. In the shown print dialog select the printer and click\r\n" +
" on \"Print\" button.\r\n" +
" 4. Verify that a page with a drawn rectangle is printed on\r\n" +
" a paper of A5 size which is (5.8 x 8.3 in) or\r\n" +
" (148 x 210 mm).\r\n" +
"\r\n" +
" If the printed page size is correct, click on \"PASS\"\r\n" +
" button, otherwise click on \"FAIL\" button.";
final JDialog dialog = new JDialog();
dialog.setTitle("WrongPaperPrintingTest");
dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
dialog.dispose();
fail("Main dialog was closed.");
}
});
final JLabel testTimeoutLabel = new JLabel(String.format(
"Test timeout: %s", convertMillisToTimeStr(testTimeout)));
final long startTime = System.currentTimeMillis();
final Timer timer = new Timer(0, null);
timer.setDelay(1000);
timer.addActionListener((e) -> {
int leftTime = testTimeout - (int)(System.currentTimeMillis() - startTime);
if ((leftTime < 0) || testFinished) {
timer.stop();
dialog.dispose();
}
testTimeoutLabel.setText(String.format(
"Test timeout: %s", convertMillisToTimeStr(leftTime)));
});
timer.start();
JTextArea textArea = new JTextArea(description);
textArea.setEditable(false);
final JButton testButton = new JButton("Start Test");
final JButton passButton = new JButton("PASS");
final JButton failButton = new JButton("FAIL");
testButton.addActionListener((e) -> {
testButton.setEnabled(false);
new Thread(() -> {
try {
doTest();
SwingUtilities.invokeLater(() -> {
passButton.setEnabled(true);
failButton.setEnabled(true);
});
} catch (Throwable t) {
t.printStackTrace();
dialog.dispose();
fail("Exception occurred in a thread executing the test.");
}
}).start();
});
passButton.setEnabled(false);
passButton.addActionListener((e) -> {
dialog.dispose();
pass();
});
failButton.setEnabled(false);
failButton.addActionListener((e) -> {
dialog.dispose();
fail("Size of a printed page is wrong.");
});
JPanel mainPanel = new JPanel(new BorderLayout());
JPanel labelPanel = new JPanel(new FlowLayout());
labelPanel.add(testTimeoutLabel);
mainPanel.add(labelPanel, BorderLayout.NORTH);
mainPanel.add(textArea, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel(new FlowLayout());
buttonPanel.add(testButton);
buttonPanel.add(passButton);
buttonPanel.add(failButton);
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
dialog.add(mainPanel);
dialog.pack();
dialog.setVisible(true);
}
@Override
public int print(Graphics g, PageFormat pf, int pageIndex)
throws PrinterException {
if (pageIndex == 0) {
g.setColor(Color.RED);
g.drawRect((int)pf.getImageableX(), (int)pf.getImageableY(),
(int)pf.getImageableWidth(), (int)pf.getImageableHeight());
return Printable.PAGE_EXISTS;
} else {
return Printable.NO_SUCH_PAGE;
}
}
}
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8061258
* @summary PrinterJob's native Print Dialog does not reflect
* specified Copies or Page Ranges
* @run main/manual DlgAttrsBug
*/
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Copies;
import javax.print.attribute.standard.PageRanges;
import javax.print.attribute.standard.DialogTypeSelection;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
public class DlgAttrsBug implements Printable {
private static Thread mainThread;
private static boolean testPassed;
private static boolean testGeneratedInterrupt;
public static void main(String[] args) throws Exception {
SwingUtilities.invokeAndWait(() -> {
doTest(DlgAttrsBug::printTest);
});
mainThread = Thread.currentThread();
try {
Thread.sleep(30000);
} catch (InterruptedException e) {
if (!testPassed && testGeneratedInterrupt) {
throw new RuntimeException("Print Dialog does not " +
"reflect Copies or Page Ranges");
}
}
if (!testGeneratedInterrupt) {
throw new RuntimeException("user has not executed the test");
}
}
private static void printTest() {
PrinterJob job = PrinterJob.getPrinterJob();
if (job.getPrintService() == null) {
System.out.println("No printers. Test cannot continue");
return;
}
job.setPrintable(new DlgAttrsBug());
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(new Copies(5));
aset.add(new PageRanges(3,4));
aset.add(DialogTypeSelection.NATIVE);
job.printDialog(aset);
}
public static synchronized void pass() {
testPassed = true;
testGeneratedInterrupt = true;
mainThread.interrupt();
}
public static synchronized void fail() {
testPassed = false;
testGeneratedInterrupt = true;
mainThread.interrupt();
}
private static void doTest(Runnable action) {
String description
= " Visual inspection of print dialog is required.\n"
+ " A print dialog will be shown.\n "
+ " Please verify Copies 5 is selected.\n"
+ " Also verify, Page Range is selected with "
+ " from page 3 and to Page 4.\n"
+ " If ok, press PASS else press FAIL";
final JDialog dialog = new JDialog();
dialog.setTitle("printSelectionTest");
JTextArea textArea = new JTextArea(description);
textArea.setEditable(false);
final JButton testButton = new JButton("Start Test");
final JButton passButton = new JButton("PASS");
passButton.setEnabled(false);
passButton.addActionListener((e) -> {
dialog.dispose();
pass();
});
final JButton failButton = new JButton("FAIL");
failButton.setEnabled(false);
failButton.addActionListener((e) -> {
dialog.dispose();
fail();
});
testButton.addActionListener((e) -> {
testButton.setEnabled(false);
action.run();
passButton.setEnabled(true);
failButton.setEnabled(true);
});
JPanel mainPanel = new JPanel(new BorderLayout());
mainPanel.add(textArea, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel(new FlowLayout());
buttonPanel.add(testButton);
buttonPanel.add(passButton);
buttonPanel.add(failButton);
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
dialog.add(mainPanel);
dialog.pack();
dialog.setVisible(true);
}
public int print(Graphics g, PageFormat pf, int pi)
throws PrinterException {
System.out.println("pi = " + pi);
if (pi >= 5) {
return NO_SUCH_PAGE;
}
g.drawString("Page : " + (pi+1), 200, 200);
return PAGE_EXISTS;
}
}
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.swing.AbstractListModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
/* @test
@bug 8076249
@summary NPE in AccessBridge while editing JList model
@author Mikhail Cherkasov
@run main AccessibleJListChildNPETest
*/
public class AccessibleJListChildNPETest {
private static String[] model = { "1", "2", "3", "4", "5", "6" };
private static JList<String> list;
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
final MyModel dataModel = new MyModel(Arrays.asList(model));
list = new JList<>(dataModel);
frame.getContentPane().add(list);
frame.pack();
frame.setVisible(true);
}
});
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
AccessibleContext ac = list.getAccessibleContext();
MyModel model = (MyModel)list.getModel();
Accessible accessibleChild = ac.getAccessibleChild(model.getSize()-1);
model.removeFirst();
accessibleChild.getAccessibleContext().getAccessibleSelection();
accessibleChild.getAccessibleContext().getAccessibleText();
accessibleChild.getAccessibleContext().getAccessibleValue();
}
});
}
protected static class MyModel extends AbstractListModel<String> {
private List<String> items = new ArrayList<>();
MyModel(final List<String> newItems) {
super();
items.addAll(newItems);
fireIntervalAdded(this, 0, getSize() - 1);
}
void removeFirst() {
if(getSize() > 0) {
items.remove(0);
fireIntervalRemoved(this, 0, 0);
}
}
@Override
public int getSize() {
return items.size();
}
@Override
public String getElementAt(int index) {
return items.get(index);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册