Merge
This commit is contained in:
commit
ce0b21b5f0
@ -674,9 +674,4 @@ final public class XConstants {
|
||||
public static final long XkbModifierMapMask = (1L<<2);
|
||||
public static final long XkbVirtualModsMask = (1L<<6); //server map
|
||||
|
||||
/*****************************************************************
|
||||
* X SHARED MEMORY EXTENSION FUNCTIONS
|
||||
*****************************************************************/
|
||||
|
||||
public static final int X_ShmAttach = 1;
|
||||
}
|
||||
|
@ -42,29 +42,6 @@ public abstract class XErrorHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a base synthetic error handler containing a boolean flag which allows
|
||||
* to show that an error is handled or not.
|
||||
*/
|
||||
public static class XErrorHandlerWithFlag extends XBaseErrorHandler {
|
||||
private volatile boolean errorOccurred = false;
|
||||
|
||||
public boolean getErrorOccurredFlag() {
|
||||
return errorOccurred;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an internal boolean flag to a particular value. Should be always called with
|
||||
* <code>false</code> value of the parameter <code>errorOccurred</code> before this
|
||||
* error handler is set as current.
|
||||
* @param errorOccurred <code>true</code> to indicate that an error was handled,
|
||||
* <code>false</code> to reset the internal boolean flag
|
||||
*/
|
||||
public void setErrorOccurredFlag(boolean errorOccurred) {
|
||||
this.errorOccurred = errorOccurred;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Instead of validating window id, we simply call XGetWindowProperty,
|
||||
* but temporary install this function as the error handler to ignore
|
||||
@ -99,51 +76,4 @@ public abstract class XErrorHandler {
|
||||
return theInstance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a synthetic error handler for errors generated by the native function
|
||||
* <code>XShmAttach</code>. If an error is handled, an internal boolean flag of the
|
||||
* handler is set to <code>true</code>.
|
||||
*/
|
||||
public static final class XShmAttachHandler extends XErrorHandlerWithFlag {
|
||||
private XShmAttachHandler() {}
|
||||
|
||||
@Override
|
||||
public int handleError(long display, XErrorEvent err) {
|
||||
if (err.get_minor_code() == XConstants.X_ShmAttach) {
|
||||
setErrorOccurredFlag(true);
|
||||
return 0;
|
||||
}
|
||||
return super.handleError(display, err);
|
||||
}
|
||||
|
||||
// Shared instance
|
||||
private static XShmAttachHandler theInstance = new XShmAttachHandler();
|
||||
public static XShmAttachHandler getInstance() {
|
||||
return theInstance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a synthetic error handler for <code>BadAlloc</code> errors generated by the
|
||||
* native <code>glX*</code> functions. Its internal boolean flag is set to <code>true</code>,
|
||||
* if an error is handled.
|
||||
*/
|
||||
public static final class GLXBadAllocHandler extends XErrorHandlerWithFlag {
|
||||
private GLXBadAllocHandler() {}
|
||||
|
||||
@Override
|
||||
public int handleError(long display, XErrorEvent err) {
|
||||
if (err.get_error_code() == XConstants.BadAlloc) {
|
||||
setErrorOccurredFlag(true);
|
||||
return 0;
|
||||
}
|
||||
return super.handleError(display, err);
|
||||
}
|
||||
|
||||
private static GLXBadAllocHandler theInstance = new GLXBadAllocHandler();
|
||||
public static GLXBadAllocHandler getInstance() {
|
||||
return theInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public final class XErrorHandlerUtil {
|
||||
private static long display;
|
||||
|
||||
/**
|
||||
* Error handler at the moment of <code>XErrorHandlerUtil</code> initialization.
|
||||
* Error handler at the moment of {@code XErrorHandlerUtil} initialization.
|
||||
*/
|
||||
private static long saved_error_handler;
|
||||
|
||||
@ -63,7 +63,7 @@ public final class XErrorHandlerUtil {
|
||||
new GetBooleanAction("sun.awt.noisyerrorhandler"));
|
||||
|
||||
/**
|
||||
* The flag indicating that <code>init</code> was called already.
|
||||
* The flag indicating that {@code init} was called already.
|
||||
*/
|
||||
private static boolean initPassed;
|
||||
|
||||
@ -73,9 +73,9 @@ public final class XErrorHandlerUtil {
|
||||
private XErrorHandlerUtil() {}
|
||||
|
||||
/**
|
||||
* Sets the toolkit global error handler, stores the connection to X11 server, which
|
||||
* will be used during an error handling process. This method is called once from
|
||||
* <code>awt_init_Display</code> function defined in <code>awt_GraphicsEnv.c</code>
|
||||
* Sets the toolkit global error handler, stores the connection to X11 server,
|
||||
* which will be used during an error handling process. This method is called
|
||||
* once from {@code awt_init_Display} function defined in {@code awt_GraphicsEnv.c}
|
||||
* file immediately after the connection to X11 window server is opened.
|
||||
* @param display the connection to X11 server which should be stored
|
||||
*/
|
||||
@ -109,9 +109,9 @@ public final class XErrorHandlerUtil {
|
||||
}
|
||||
|
||||
private static void RESTORE_XERROR_HANDLER(boolean doXSync) {
|
||||
// Wait until all requests are processed by the X server
|
||||
// and only then uninstall the error handler.
|
||||
if (doXSync) {
|
||||
// Wait until all requests are processed by the X server
|
||||
// and only then uninstall the error handler.
|
||||
XSync();
|
||||
}
|
||||
current_error_handler = null;
|
||||
|
@ -906,6 +906,20 @@ Java_sun_awt_X11GraphicsDevice_getDisplay(JNIEnv *env, jobject this)
|
||||
|
||||
static jint canUseShmExt = UNSET_MITSHM;
|
||||
static jint canUseShmExtPixmaps = UNSET_MITSHM;
|
||||
static jboolean xshmAttachFailed = JNI_FALSE;
|
||||
|
||||
int XShmAttachXErrHandler(Display *display, XErrorEvent *xerr) {
|
||||
if (xerr->minor_code == X_ShmAttach) {
|
||||
xshmAttachFailed = JNI_TRUE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
jboolean isXShmAttachFailed() {
|
||||
return xshmAttachFailed;
|
||||
}
|
||||
void resetXShmAttachFailed() {
|
||||
xshmAttachFailed = JNI_FALSE;
|
||||
}
|
||||
|
||||
extern int mitShmPermissionMask;
|
||||
|
||||
@ -913,7 +927,6 @@ void TryInitMITShm(JNIEnv *env, jint *shmExt, jint *shmPixmaps) {
|
||||
XShmSegmentInfo shminfo;
|
||||
int XShmMajor, XShmMinor;
|
||||
int a, b, c;
|
||||
jboolean xShmAttachResult;
|
||||
|
||||
AWT_LOCK();
|
||||
if (canUseShmExt != UNSET_MITSHM) {
|
||||
@ -957,14 +970,21 @@ void TryInitMITShm(JNIEnv *env, jint *shmExt, jint *shmPixmaps) {
|
||||
}
|
||||
shminfo.readOnly = True;
|
||||
|
||||
xShmAttachResult = TryXShmAttach(env, awt_display, &shminfo);
|
||||
resetXShmAttachFailed();
|
||||
/**
|
||||
* The J2DXErrHandler handler will set xshmAttachFailed
|
||||
* to JNI_TRUE if any Shm error has occured.
|
||||
*/
|
||||
EXEC_WITH_XERROR_HANDLER(XShmAttachXErrHandler,
|
||||
XShmAttach(awt_display, &shminfo));
|
||||
|
||||
/**
|
||||
* Get rid of the id now to reduce chances of leaking
|
||||
* system resources.
|
||||
*/
|
||||
shmctl(shminfo.shmid, IPC_RMID, 0);
|
||||
|
||||
if (xShmAttachResult == JNI_TRUE) {
|
||||
if (isXShmAttachFailed() == JNI_FALSE) {
|
||||
canUseShmExt = CAN_USE_MITSHM;
|
||||
/* check if we can use shared pixmaps */
|
||||
XShmQueryVersion(awt_display, &XShmMajor, &XShmMinor,
|
||||
@ -979,23 +999,6 @@ void TryInitMITShm(JNIEnv *env, jint *shmExt, jint *shmPixmaps) {
|
||||
}
|
||||
AWT_UNLOCK();
|
||||
}
|
||||
|
||||
/*
|
||||
* Must be called with the acquired AWT lock.
|
||||
*/
|
||||
jboolean TryXShmAttach(JNIEnv *env, Display *display, XShmSegmentInfo *shminfo) {
|
||||
jboolean errorOccurredFlag = JNI_FALSE;
|
||||
jobject errorHandlerRef;
|
||||
|
||||
/*
|
||||
* XShmAttachHandler will set its internal flag to JNI_TRUE, if any Shm error occurs.
|
||||
*/
|
||||
EXEC_WITH_XERROR_HANDLER(env, "sun/awt/X11/XErrorHandler$XShmAttachHandler",
|
||||
"()Lsun/awt/X11/XErrorHandler$XShmAttachHandler;", JNI_TRUE,
|
||||
errorHandlerRef, errorOccurredFlag,
|
||||
XShmAttach(display, shminfo));
|
||||
return errorOccurredFlag == JNI_FALSE ? JNI_TRUE : JNI_FALSE;
|
||||
}
|
||||
#endif /* MITSHM */
|
||||
|
||||
/*
|
||||
|
@ -53,7 +53,8 @@
|
||||
extern int XShmQueryExtension();
|
||||
|
||||
void TryInitMITShm(JNIEnv *env, jint *shmExt, jint *shmPixmaps);
|
||||
jboolean TryXShmAttach(JNIEnv *env, Display *display, XShmSegmentInfo *shminfo);
|
||||
void resetXShmAttachFailed();
|
||||
jboolean isXShmAttachFailed();
|
||||
|
||||
#endif /* MITSHM */
|
||||
|
||||
|
@ -41,6 +41,11 @@
|
||||
|
||||
#include "java_awt_event_MouseWheelEvent.h"
|
||||
|
||||
/*
|
||||
* Called by "ToolkitErrorHandler" function in "XlibWrapper.c" file.
|
||||
*/
|
||||
XErrorHandler current_native_xerror_handler = NULL;
|
||||
|
||||
extern jint getModifiers(uint32_t state, jint button, jint keyCode);
|
||||
extern jint getButton(uint32_t button);
|
||||
|
||||
|
@ -29,57 +29,29 @@
|
||||
#ifndef HEADLESS
|
||||
#include "gdefs.h"
|
||||
|
||||
/*
|
||||
* Expected types of arguments of the macro.
|
||||
* (JNIEnv*, const char*, const char*, jboolean, jobject)
|
||||
*/
|
||||
#define WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature, \
|
||||
handlerHasFlag, handlerRef) do { \
|
||||
handlerRef = JNU_CallStaticMethodByName(env, NULL, handlerClassName, "getInstance", \
|
||||
getInstanceSignature).l; \
|
||||
if (handlerHasFlag == JNI_TRUE) { \
|
||||
JNU_CallMethodByName(env, NULL, handlerRef, "setErrorOccurredFlag", "(Z)V", JNI_FALSE); \
|
||||
} \
|
||||
JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil", "WITH_XERROR_HANDLER", \
|
||||
"(Lsun/awt/X11/XErrorHandler;)V", handlerRef); \
|
||||
#define WITH_XERROR_HANDLER(f) do { \
|
||||
XSync(awt_display, False); \
|
||||
current_native_xerror_handler = (f); \
|
||||
} while (0)
|
||||
|
||||
#define RESTORE_XERROR_HANDLER do { \
|
||||
XSync(awt_display, False); \
|
||||
current_native_xerror_handler = NULL; \
|
||||
} while (0)
|
||||
|
||||
#define EXEC_WITH_XERROR_HANDLER(f, code) do { \
|
||||
WITH_XERROR_HANDLER(f); \
|
||||
do { \
|
||||
code; \
|
||||
} while (0); \
|
||||
RESTORE_XERROR_HANDLER; \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Expected types of arguments of the macro.
|
||||
* (JNIEnv*, jboolean)
|
||||
* Called by "ToolkitErrorHandler" function in "XlibWrapper.c" file.
|
||||
*/
|
||||
#define RESTORE_XERROR_HANDLER(env, doXSync) do { \
|
||||
JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil", \
|
||||
"RESTORE_XERROR_HANDLER", "(Z)V", doXSync); \
|
||||
} while (0)
|
||||
extern XErrorHandler current_native_xerror_handler;
|
||||
|
||||
/*
|
||||
* Expected types of arguments of the macro.
|
||||
* (JNIEnv*, const char*, const char*, jboolean, jobject, jboolean, No type - C expression)
|
||||
*/
|
||||
#define EXEC_WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature, handlerHasFlag, \
|
||||
handlerRef, errorOccurredFlag, code) do { \
|
||||
handlerRef = NULL; \
|
||||
WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature, handlerHasFlag, handlerRef); \
|
||||
do { \
|
||||
code; \
|
||||
} while (0); \
|
||||
RESTORE_XERROR_HANDLER(env, JNI_TRUE); \
|
||||
if (handlerHasFlag == JNI_TRUE) { \
|
||||
GET_HANDLER_ERROR_OCCURRED_FLAG(env, handlerRef, errorOccurredFlag); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Expected types of arguments of the macro.
|
||||
* (JNIEnv*, jobject, jboolean)
|
||||
*/
|
||||
#define GET_HANDLER_ERROR_OCCURRED_FLAG(env, handlerRef, errorOccurredFlag) do { \
|
||||
if (handlerRef != NULL) { \
|
||||
errorOccurredFlag = JNU_CallMethodByName(env, NULL, handlerRef, "getErrorOccurredFlag", \
|
||||
"()Z").z; \
|
||||
} \
|
||||
} while (0)
|
||||
#endif /* !HEADLESS */
|
||||
|
||||
#ifndef INTERSECTS
|
||||
|
@ -48,6 +48,8 @@ extern DisposeFunc OGLSD_Dispose;
|
||||
extern void
|
||||
OGLSD_SetNativeDimensions(JNIEnv *env, OGLSDOps *oglsdo, jint w, jint h);
|
||||
|
||||
jboolean surfaceCreationFailed = JNI_FALSE;
|
||||
|
||||
#endif /* !HEADLESS */
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
@ -347,6 +349,15 @@ OGLSD_InitOGLWindow(JNIEnv *env, OGLSDOps *oglsdo)
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
static int
|
||||
GLXSD_BadAllocXErrHandler(Display *display, XErrorEvent *xerr)
|
||||
{
|
||||
if (xerr->error_code == BadAlloc) {
|
||||
surfaceCreationFailed = JNI_TRUE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_sun_java2d_opengl_GLXSurfaceData_initPbuffer
|
||||
(JNIEnv *env, jobject glxsd,
|
||||
@ -362,8 +373,6 @@ Java_sun_java2d_opengl_GLXSurfaceData_initPbuffer
|
||||
int attrlist[] = {GLX_PBUFFER_WIDTH, 0,
|
||||
GLX_PBUFFER_HEIGHT, 0,
|
||||
GLX_PRESERVED_CONTENTS, GL_FALSE, 0};
|
||||
jboolean errorOccurredFlag;
|
||||
jobject errorHandlerRef;
|
||||
|
||||
J2dTraceLn3(J2D_TRACE_INFO,
|
||||
"GLXSurfaceData_initPbuffer: w=%d h=%d opq=%d",
|
||||
@ -391,15 +400,12 @@ Java_sun_java2d_opengl_GLXSurfaceData_initPbuffer
|
||||
attrlist[1] = width;
|
||||
attrlist[3] = height;
|
||||
|
||||
errorOccurredFlag = JNI_FALSE;
|
||||
WITH_XERROR_HANDLER(env, "sun/awt/X11/XErrorHandler$GLXBadAllocHandler",
|
||||
"()Lsun/awt/X11/XErrorHandler$GLXBadAllocHandler;", JNI_TRUE, errorHandlerRef);
|
||||
pbuffer = j2d_glXCreatePbuffer(awt_display, glxinfo->fbconfig, attrlist);
|
||||
XSync(awt_display, False);
|
||||
RESTORE_XERROR_HANDLER(env, JNI_FALSE);
|
||||
GET_HANDLER_ERROR_OCCURRED_FLAG(env, errorHandlerRef, errorOccurredFlag);
|
||||
|
||||
if ((pbuffer == 0) || errorOccurredFlag) {
|
||||
surfaceCreationFailed = JNI_FALSE;
|
||||
EXEC_WITH_XERROR_HANDLER(
|
||||
GLXSD_BadAllocXErrHandler,
|
||||
pbuffer = j2d_glXCreatePbuffer(awt_display,
|
||||
glxinfo->fbconfig, attrlist));
|
||||
if ((pbuffer == 0) || surfaceCreationFailed) {
|
||||
J2dRlsTraceLn(J2D_TRACE_ERROR,
|
||||
"GLXSurfaceData_initPbuffer: could not create glx pbuffer");
|
||||
return JNI_FALSE;
|
||||
|
@ -65,6 +65,7 @@ static UnlockFunc X11SD_Unlock;
|
||||
static DisposeFunc X11SD_Dispose;
|
||||
static GetPixmapBgFunc X11SD_GetPixmapWithBg;
|
||||
static ReleasePixmapBgFunc X11SD_ReleasePixmapWithBg;
|
||||
extern int XShmAttachXErrHandler(Display *display, XErrorEvent *xerr);
|
||||
extern AwtGraphicsConfigDataPtr
|
||||
getGraphicsConfigFromComponentPeer(JNIEnv *env, jobject this);
|
||||
extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
|
||||
@ -532,8 +533,6 @@ XImage* X11SD_CreateSharedImage(X11SDOps *xsdo,
|
||||
{
|
||||
XImage *img = NULL;
|
||||
XShmSegmentInfo *shminfo;
|
||||
JNIEnv* env;
|
||||
jboolean xShmAttachResult;
|
||||
|
||||
shminfo = malloc(sizeof(XShmSegmentInfo));
|
||||
if (shminfo == NULL) {
|
||||
@ -573,8 +572,9 @@ XImage* X11SD_CreateSharedImage(X11SDOps *xsdo,
|
||||
|
||||
shminfo->readOnly = False;
|
||||
|
||||
env = (JNIEnv*)JNU_GetEnv(jvm, JNI_VERSION_1_2);
|
||||
xShmAttachResult = TryXShmAttach(env, awt_display, shminfo);
|
||||
resetXShmAttachFailed();
|
||||
EXEC_WITH_XERROR_HANDLER(XShmAttachXErrHandler,
|
||||
XShmAttach(awt_display, shminfo));
|
||||
|
||||
/*
|
||||
* Once the XSync round trip has finished then we
|
||||
@ -583,7 +583,7 @@ XImage* X11SD_CreateSharedImage(X11SDOps *xsdo,
|
||||
*/
|
||||
shmctl(shminfo->shmid, IPC_RMID, 0);
|
||||
|
||||
if (xShmAttachResult == JNI_FALSE) {
|
||||
if (isXShmAttachFailed() == JNI_TRUE) {
|
||||
J2dRlsTraceLn1(J2D_TRACE_ERROR,
|
||||
"X11SD_SetupSharedSegment XShmAttach has failed: %s",
|
||||
strerror(errno));
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include <sizecalc.h>
|
||||
|
||||
#include <awt.h>
|
||||
#include <awt_util.h>
|
||||
#include <jvm.h>
|
||||
|
||||
#include <Region.h>
|
||||
@ -1266,6 +1267,10 @@ JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_IsKanaKeyboard
|
||||
JavaVM* jvm = NULL;
|
||||
static int ToolkitErrorHandler(Display * dpy, XErrorEvent * event) {
|
||||
JNIEnv * env;
|
||||
// First call the native synthetic error handler declared in "awt_util.h" file.
|
||||
if (current_native_xerror_handler != NULL) {
|
||||
current_native_xerror_handler(dpy, event);
|
||||
}
|
||||
if (jvm != NULL) {
|
||||
env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
|
||||
if (env) {
|
||||
|
@ -25,7 +25,9 @@
|
||||
@test
|
||||
@bug 7050935
|
||||
@summary closed/java/awt/Choice/WheelEventsConsumed/WheelEventsConsumed.html fails on win32
|
||||
@library ../../regtesthelpers
|
||||
@author Oleg Pekhovskiy: area=awt-choice
|
||||
@build Util
|
||||
@run main ChoiceMouseWheelTest
|
||||
*/
|
||||
|
||||
@ -142,8 +144,7 @@ public class ChoiceMouseWheelTest extends Frame {
|
||||
throw new RuntimeException("Mouse Wheel scroll position error!");
|
||||
}
|
||||
|
||||
System.exit(0);
|
||||
|
||||
dispose();
|
||||
} catch (AWTException e) {
|
||||
throw new RuntimeException("AWTException occurred - problem creating robot!");
|
||||
}
|
||||
|
@ -0,0 +1,45 @@
|
||||
<!--
|
||||
Copyright (c) 2013, 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.
|
||||
-->
|
||||
|
||||
<html>
|
||||
<!--
|
||||
@test
|
||||
@bug 7161437
|
||||
@summary We should support "apple.awt.fileDialogForDirectories" property.
|
||||
@author Sergey Bylokhov area=awt.filedialog
|
||||
@library ../../regtesthelpers
|
||||
@build Sysout
|
||||
@run applet/manual=yesno FileDialogForDirectories.html
|
||||
-->
|
||||
<head>
|
||||
<title> FileDialogForDirectories </title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>FileDialogForDirectories<br>Bug ID: 7161437</h1>
|
||||
|
||||
<p> See the dialog box (usually in upper left corner) for instructions</p>
|
||||
|
||||
<APPLET CODE="FileDialogForDirectories.class" WIDTH=200 HEIGHT=200></APPLET>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 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 sun.awt.OSInfo;
|
||||
import test.java.awt.regtesthelpers.Sysout;
|
||||
|
||||
import java.applet.Applet;
|
||||
import java.awt.Button;
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class FileDialogForDirectories extends Applet implements ActionListener {
|
||||
private volatile Button showBtn;
|
||||
private volatile FileDialog fd;
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
|
||||
Sysout.createDialogWithInstructions(new String[]{
|
||||
"Press PASS, this test is for MacOS X only."});
|
||||
return;
|
||||
}
|
||||
|
||||
System.setProperty("apple.awt.fileDialogForDirectories", "true");
|
||||
|
||||
setLayout(new GridLayout(1, 1));
|
||||
|
||||
fd = new FileDialog(new Frame(), "Open");
|
||||
|
||||
showBtn = new Button("Show File Dialog");
|
||||
showBtn.addActionListener(this);
|
||||
add(showBtn);
|
||||
String[] instructions = {
|
||||
"1) Click on 'Show File Dialog' button. A file dialog will come up.",
|
||||
"2) Check that files can't be selected.",
|
||||
"3) Check that directories can be selected.",
|
||||
"4) Repeat steps 1 - 3 a few times for different files and directories.",
|
||||
"5) If it's true then the test passed, otherwise it failed."};
|
||||
Sysout.createDialogWithInstructions(instructions);
|
||||
}//End init()
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
setSize(200, 200);
|
||||
show();
|
||||
}// start()
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (e.getSource() == showBtn) {
|
||||
fd.setVisible(true);
|
||||
String output = fd.getFile();
|
||||
if (output != null) {
|
||||
Sysout.println(output + " is selected");
|
||||
}
|
||||
}
|
||||
}
|
||||
}// class ManualYesNoTest
|
@ -29,6 +29,8 @@
|
||||
@run main MouseModifiersUnitTest_Extra
|
||||
*/
|
||||
|
||||
import sun.awt.OSInfo;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.Arrays;
|
||||
@ -61,6 +63,17 @@ public class MouseModifiersUnitTest_Extra extends Frame {
|
||||
static int [] modifiersExStandardCTRL;
|
||||
static int [] modifiersExStandardALT;
|
||||
|
||||
private final static String SHIFT_MODIFIER = OSInfo.getOSType().equals(OSInfo.OSType.MACOSX) ?
|
||||
"\u21e7" : "Shift";
|
||||
|
||||
private final static String ALT_MODIFIER = OSInfo.getOSType().equals(OSInfo.OSType.MACOSX) ?
|
||||
"\u2325" : "Alt";
|
||||
|
||||
|
||||
private final static String CTRL_MODIFIER = OSInfo.getOSType().equals(OSInfo.OSType.MACOSX) ?
|
||||
"\u2303" : "Ctrl";
|
||||
|
||||
|
||||
// BUTTON1, 2, 3 press-release.
|
||||
final static int modifiersStandard = 0; //InputEvent.BUTTON_DOWN_MASK;
|
||||
|
||||
@ -77,7 +90,8 @@ public class MouseModifiersUnitTest_Extra extends Frame {
|
||||
|
||||
if (modifiersEx != curStandardExModifiers[index]){
|
||||
// System.out.println(">>>>>>>>>>>>>>> Pressed. modifiersEx "+modifiersEx +" : "+!= curStandardExModifiers");
|
||||
MessageLogger.reportError("Test failed : Pressed. modifiersEx != curStandardExModifiers. Got: " + modifiersEx + " , Expected: " + curStandardExModifiers[index]);
|
||||
MessageLogger.reportError("Test failed : Pressed. modifiersEx != curStandardExModifiers. Got: "
|
||||
+ modifiersEx + " , Expected: " + curStandardExModifiers[index]);
|
||||
}
|
||||
|
||||
//check event.paramString() output
|
||||
@ -88,51 +102,54 @@ public class MouseModifiersUnitTest_Extra extends Frame {
|
||||
checkExtModifiersOnPress(testModifier, paramStringElements, button);
|
||||
}
|
||||
|
||||
public static void checkExtModifiersOnReleaseClick(int testModifier, HashMap h, int button){
|
||||
public static void checkExtModifiersOnReleaseClick(int testModifier, HashMap<String, String> h, int button){
|
||||
String ethalon = "";
|
||||
switch (testModifier){
|
||||
case SHIFT:{
|
||||
ethalon = "Shift";
|
||||
ethalon = SHIFT_MODIFIER;
|
||||
break;
|
||||
}
|
||||
case ALT:{
|
||||
ethalon = "Alt";
|
||||
ethalon = ALT_MODIFIER;
|
||||
break;
|
||||
}
|
||||
case CTRL:{
|
||||
ethalon = "Ctrl";
|
||||
ethalon = CTRL_MODIFIER;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//
|
||||
|
||||
if (h.get("extModifiers") == null){
|
||||
h.put("extModifiers", "");
|
||||
}
|
||||
|
||||
if (!ethalon.equals(h.get("extModifiers"))) {
|
||||
MessageLogger.reportError("Test failed : Released/Clicked. extModifiers = " +h.get("extModifiers")+" instead of : "+ethalon);
|
||||
MessageLogger.reportError("Test failed : Released/Clicked. extModifiers = "
|
||||
+ h.get("extModifiers") + " instead of : " + ethalon);
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkExtModifiersOnPress(int testModifier, HashMap h, int button){
|
||||
public static void checkExtModifiersOnPress(int testModifier, HashMap<String, String> h, int button){
|
||||
String ethalon = "";
|
||||
switch (testModifier){
|
||||
case SHIFT:{
|
||||
ethalon = "Shift+";
|
||||
ethalon = SHIFT_MODIFIER + "+";
|
||||
break;
|
||||
}
|
||||
case ALT:{
|
||||
ethalon = "Alt+";
|
||||
ethalon = ALT_MODIFIER + "+";
|
||||
break;
|
||||
}
|
||||
case CTRL:{
|
||||
ethalon = "Ctrl+";
|
||||
ethalon = CTRL_MODIFIER + "+";
|
||||
break;
|
||||
}
|
||||
}
|
||||
ethalon = ethalon + "Button" +button;
|
||||
|
||||
if (!h.get("extModifiers").equals(ethalon)) {
|
||||
MessageLogger.reportError("Test failed : Pressed. extModifiers = " +h.get("extModifiers")+" instead of : "+ethalon);
|
||||
MessageLogger.reportError("Test failed : Pressed. extModifiers = " +h.get("extModifiers")+" instead of : "
|
||||
+ ethalon);
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,7 +169,7 @@ public class MouseModifiersUnitTest_Extra extends Frame {
|
||||
}
|
||||
}
|
||||
public static HashMap<String, String> tokenizeParamString(String param){
|
||||
HashMap <String, String> params = new HashMap<String, String>();
|
||||
HashMap <String, String> params = new HashMap<>();
|
||||
StringTokenizer st = new StringTokenizer(param, ",=");
|
||||
while (st.hasMoreTokens()){
|
||||
String tmp = st.nextToken();
|
||||
@ -167,7 +184,7 @@ public class MouseModifiersUnitTest_Extra extends Frame {
|
||||
}
|
||||
|
||||
public static Vector<String> tokenizeModifiers(String modifierList){
|
||||
Vector<String> modifiers = new Vector<String>();
|
||||
Vector<String> modifiers = new Vector<>();
|
||||
StringTokenizer st = new StringTokenizer(modifierList, "+");
|
||||
while (st.hasMoreTokens()){
|
||||
String tmp = st.nextToken();
|
||||
@ -189,7 +206,8 @@ public class MouseModifiersUnitTest_Extra extends Frame {
|
||||
}
|
||||
|
||||
if (modifiersEx != curStandardExModifiers[index]){
|
||||
MessageLogger.reportError("Test failed : Released. modifiersEx != curStandardExModifiers. Got: " + modifiersEx + " , Expected: " + curStandardExModifiers[index]);
|
||||
MessageLogger.reportError("Test failed : Released. modifiersEx != curStandardExModifiers. Got: "
|
||||
+ modifiersEx + " , Expected: " + curStandardExModifiers[index]);
|
||||
}
|
||||
|
||||
//check event.paramString() output
|
||||
@ -212,7 +230,8 @@ public class MouseModifiersUnitTest_Extra extends Frame {
|
||||
}
|
||||
|
||||
if (modifiersEx != curStandardExModifiers[index]){
|
||||
MessageLogger.reportError("Test failed : Clicked. modifiersEx != curStandardExModifiers. Got: " + modifiersEx + " , Expected: " + curStandardExModifiers[index]);
|
||||
MessageLogger.reportError("Test failed : Clicked. modifiersEx != curStandardExModifiers. Got: "
|
||||
+ modifiersEx + " , Expected: " + curStandardExModifiers[index]);
|
||||
}
|
||||
|
||||
//check event.paramString() output
|
||||
@ -243,22 +262,10 @@ public class MouseModifiersUnitTest_Extra extends Frame {
|
||||
static Robot robot;
|
||||
public void init() {
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
String[] instructions =
|
||||
{
|
||||
"This test should be used with the mouse having more then three buttons.",
|
||||
"Currently, " + MouseInfo.getNumberOfButtons() +" buttons are available.",
|
||||
"If there are less then three buttons, press PASS.",
|
||||
"1. Press each extra mouse button.",
|
||||
"2. For each mouse event its modifiers and ExModifiers will be printed.",
|
||||
"3. Verify that they are correct.",
|
||||
"4. Press Pass or Fail accordingly."
|
||||
};
|
||||
// Sysout.createDialogWithInstructions( instructions );
|
||||
|
||||
// addMouseListener(adapterTest1);
|
||||
try {
|
||||
robot = new Robot();
|
||||
robot.setAutoDelay(100);
|
||||
robot.setAutoWaitForIdle(true);
|
||||
} catch (Exception e) {
|
||||
MessageLogger.reportError("Test failed. "+e);
|
||||
}
|
||||
@ -297,9 +304,8 @@ public class MouseModifiersUnitTest_Extra extends Frame {
|
||||
robot.delay(1000);
|
||||
robot.mouseMove(getLocationOnScreen().x + getWidth()/2, getLocationOnScreen().y + getHeight()/2);
|
||||
for (int i = 3; i< mouseButtonDownMasks.length; i++){
|
||||
System.out.println("testNONE() => " +mouseButtonDownMasks[i] );
|
||||
System.out.println("testNONE() => " + mouseButtonDownMasks[i]);
|
||||
robot.mousePress(mouseButtonDownMasks[i]);
|
||||
robot.delay(100);
|
||||
robot.mouseRelease(mouseButtonDownMasks[i]);
|
||||
}
|
||||
robot.delay(1000);
|
||||
@ -312,9 +318,8 @@ public class MouseModifiersUnitTest_Extra extends Frame {
|
||||
robot.mouseMove(getLocationOnScreen().x + getWidth()/2, getLocationOnScreen().y + getHeight()/2);
|
||||
for (int i = 3; i< mouseButtonDownMasks.length; i++){
|
||||
robot.keyPress(KeyEvent.VK_SHIFT);
|
||||
System.out.println("testSHIFT() => " +mouseButtonDownMasks[i] );
|
||||
System.out.println("testSHIFT() => " + mouseButtonDownMasks[i]);
|
||||
robot.mousePress(mouseButtonDownMasks[i]);
|
||||
robot.delay(100);
|
||||
robot.mouseRelease(mouseButtonDownMasks[i]);
|
||||
robot.keyRelease(KeyEvent.VK_SHIFT);
|
||||
}
|
||||
@ -328,9 +333,8 @@ public class MouseModifiersUnitTest_Extra extends Frame {
|
||||
robot.mouseMove(getLocationOnScreen().x + getWidth()/2, getLocationOnScreen().y + getHeight()/2);
|
||||
for (int i = 3; i< mouseButtonDownMasks.length; i++){
|
||||
robot.keyPress(KeyEvent.VK_CONTROL);
|
||||
System.out.println("testCTRL() => " +mouseButtonDownMasks[i] );
|
||||
System.out.println("testCTRL() => " + mouseButtonDownMasks[i]);
|
||||
robot.mousePress(mouseButtonDownMasks[i]);
|
||||
robot.delay(100);
|
||||
robot.mouseRelease(mouseButtonDownMasks[i]);
|
||||
robot.keyRelease(KeyEvent.VK_CONTROL);
|
||||
}
|
||||
@ -344,9 +348,8 @@ public class MouseModifiersUnitTest_Extra extends Frame {
|
||||
robot.mouseMove(getLocationOnScreen().x + getWidth()/2, getLocationOnScreen().y + getHeight()/2);
|
||||
for (int i = 3; i< mouseButtonDownMasks.length; i++){
|
||||
robot.keyPress(KeyEvent.VK_ALT);
|
||||
System.out.println("testALT() => " +mouseButtonDownMasks[i] );
|
||||
System.out.println("testALT() => " + mouseButtonDownMasks[i]);
|
||||
robot.mousePress(mouseButtonDownMasks[i]);
|
||||
robot.delay(100);
|
||||
robot.mouseRelease(mouseButtonDownMasks[i]);
|
||||
robot.keyRelease(KeyEvent.VK_ALT);
|
||||
}
|
||||
|
148
jdk/test/java/awt/MouseInfo/JContainerMousePositionTest.java
Normal file
148
jdk/test/java/awt/MouseInfo/JContainerMousePositionTest.java
Normal file
@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 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
|
||||
@summary unit test for a new method in Container class: getMousePosition(boolean)
|
||||
@author dav@sparc.spb.su: area=
|
||||
@bug 4009555
|
||||
@run main JContainerMousePositionTest
|
||||
*/
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
// this test looks at mouse pointer when it
|
||||
// 1 over component
|
||||
// 2 over Container, but not over one of its child Components.
|
||||
// out of bounds of Container
|
||||
// two values of paramater allowChildren are considered.
|
||||
|
||||
public class JContainerMousePositionTest {
|
||||
//Declare things used in the test, like buttons and labels here
|
||||
private static JButton jButton1;
|
||||
private static JButton jButton4;
|
||||
private static JFrame frame1;
|
||||
private static Container contentPane;
|
||||
|
||||
public static void main(final String[] args) throws Exception {
|
||||
Robot robot = new Robot();
|
||||
robot.setAutoDelay(200);
|
||||
robot.setAutoWaitForIdle(true);
|
||||
|
||||
SwingUtilities.invokeAndWait(JContainerMousePositionTest::init);
|
||||
|
||||
robot.delay(500);
|
||||
robot.waitForIdle();
|
||||
|
||||
AtomicReference<Point> centerC4 = new AtomicReference<>();
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
centerC4.set(jButton4.getLocation());
|
||||
contentPane.remove(jButton4);
|
||||
contentPane.validate();
|
||||
contentPane.repaint();
|
||||
});
|
||||
robot.waitForIdle();
|
||||
|
||||
AtomicReference<Rectangle> frameBounds = new AtomicReference<>();
|
||||
AtomicReference<Dimension> button1Size = new AtomicReference<>();
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
frameBounds.set(frame1.getBounds());
|
||||
button1Size.set(jButton1.getSize());
|
||||
});
|
||||
|
||||
//point mouse to center of top-left Component (button1)
|
||||
robot.mouseMove(frameBounds.get().x + button1Size.get().width / 2,
|
||||
frameBounds.get().y + button1Size.get().height / 2);
|
||||
|
||||
AtomicReference<Point> pFalse = new AtomicReference<>();
|
||||
AtomicReference<Point> pTrue = new AtomicReference<>();
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
pFalse.set(frame1.getMousePosition(false));
|
||||
pTrue.set(frame1.getMousePosition(true));
|
||||
});
|
||||
robot.waitForIdle();
|
||||
if (pFalse.get() != null) {
|
||||
throw new RuntimeException("Test failed: Container.getMousePosition(false) returned non-null over one of children.");
|
||||
}
|
||||
System.out.println("Test stage completed: Container.getMousePosition(false) returned null result over child Component. Passed.");
|
||||
|
||||
if (pTrue.get() == null) {
|
||||
throw new RuntimeException("Test failed: Container.getMousePosition(true) returned null result over child Component");
|
||||
}
|
||||
System.out.println("Test stage compelted: Container.getMousePosition(true) returned non-null result over child Component. Passed.");
|
||||
|
||||
//point mouse out from Container's area
|
||||
robot.mouseMove(frameBounds.get().x + frameBounds.get().width + 10,
|
||||
frameBounds.get().y + frameBounds.get().height + 10);
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
pFalse.set(frame1.getMousePosition(false));
|
||||
pTrue.set(frame1.getMousePosition(true));
|
||||
});
|
||||
robot.waitForIdle();
|
||||
if (pFalse.get() != null || pTrue.get() != null) {
|
||||
throw new RuntimeException("Test failed: Container.getMousePosition(boolean) returned incorrect result outside Container");
|
||||
}
|
||||
System.out.println("Test stage completed: Container.getMousePosition(boolean) returned null result outside Container. Passed.");
|
||||
|
||||
//point mouse in place free from child components (right-botton component)
|
||||
robot.mouseMove(frameBounds.get().x + centerC4.get().x,
|
||||
frameBounds.get().y + centerC4.get().y);
|
||||
|
||||
robot.delay(3000);
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
pFalse.set(contentPane.getMousePosition(false));
|
||||
pTrue.set(frame1.getMousePosition(true));
|
||||
});
|
||||
robot.waitForIdle();
|
||||
|
||||
if (pFalse.get() == null || pTrue.get() == null) {
|
||||
throw new RuntimeException("Test failed: Container.getMousePosition(boolean) returned null result inside Container.");
|
||||
}
|
||||
System.out.println("Test stage completed: Container.getMousePosition(boolean) returned non-null results inside Container. Passed.");
|
||||
|
||||
if (pTrue.get().x != centerC4.get().x || pTrue.get().y != centerC4.get().y) {
|
||||
throw new RuntimeException("Test failed: Container.getMousePosition(true) returned incorrect result inside Container.");
|
||||
}
|
||||
System.out.println("Test stage completed: Container.getMousePosition(true) returned correct result inside Container. Passed.");
|
||||
|
||||
System.out.println("TEST PASSED");
|
||||
}
|
||||
|
||||
private static void init() {
|
||||
frame1 = new JFrame("Testing getMousePosition() on LWs");
|
||||
jButton1 = new JButton("C1");
|
||||
jButton4 = new JButton("C4");
|
||||
contentPane = frame1.getContentPane();
|
||||
contentPane.setLayout(new GridLayout(2, 2, 25, 25));
|
||||
contentPane.add(jButton1);
|
||||
contentPane.add(new JButton("C2"));
|
||||
contentPane.add(new JButton("C3"));
|
||||
contentPane.add(jButton4);
|
||||
frame1.setSize(200, 200);
|
||||
frame1.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,9 +96,7 @@ public class ManualHTMLDataFlavorTest extends Applet {
|
||||
Sysout.println(t.getTransferData(DataFlavor.fragmentHtmlFlavor).toString());
|
||||
Sysout.println("SELECTION:");
|
||||
Sysout.println(t.getTransferData(DataFlavor.selectionHtmlFlavor).toString());
|
||||
} catch (UnsupportedFlavorException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
} catch (UnsupportedFlavorException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@ -116,6 +114,7 @@ public class ManualHTMLDataFlavorTest extends Applet {
|
||||
" otherwise for instance iexplore can prohibit drag and drop from",
|
||||
" the browser to other applications because of",
|
||||
" the protected mode restrictions.",
|
||||
" On Mac OS X do NOT use Safari, it does not provide the needed DataFlavor",
|
||||
"3) Check the data in the output area of this dialog",
|
||||
"5) The output should not contain information that any of",
|
||||
" flavors is not present in the system clipboard",
|
||||
|
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 2013 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 4173714
|
||||
@summary java.awt.button behaves differently under Win32/Solaris
|
||||
@author tdv@sparc.spb.su
|
||||
@library ../../../regtesthelpers
|
||||
@build Util
|
||||
@run main DisabledComponentsTest
|
||||
*/
|
||||
|
||||
/**
|
||||
* DisabledComponentsTest.java
|
||||
*
|
||||
* summary: java.awt.button behaves differently under Win32/Solaris
|
||||
* Disabled component should not receive events. This is what this
|
||||
* test checks out.
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import test.java.awt.regtesthelpers.Util;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class DisabledComponentsTest {
|
||||
|
||||
private static Frame frame;
|
||||
private static Button b = new Button("Button");
|
||||
private static final AtomicBoolean pressed = new AtomicBoolean(false);
|
||||
private static final AtomicBoolean entered = new AtomicBoolean(false);
|
||||
|
||||
private static void init() {
|
||||
frame = new Frame("Test");
|
||||
frame.setBounds(100, 100, 100, 100);
|
||||
b = new Button("Test");
|
||||
b.setEnabled(false);
|
||||
b.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
System.err.println("Mouse pressed. target=" + e.getSource());
|
||||
if (!b.isEnabled()) {
|
||||
System.err.println("TEST FAILED: BUTTON RECEIVED AN EVENT WHEN DISABLED!");
|
||||
pressed.set(true);
|
||||
}
|
||||
}
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
System.out.println("Mouse entered. target=" + e.getSource());
|
||||
if (!b.isEnabled())
|
||||
System.err.println("TEST FAILED: BUTTON RECEIVED AN EVENT WHEN DISABLED!");
|
||||
entered.set(true);
|
||||
}
|
||||
});
|
||||
frame.add(b);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
try {
|
||||
Robot r = Util.createRobot();
|
||||
r.setAutoDelay(200);
|
||||
r.setAutoWaitForIdle(true);
|
||||
r.mouseMove(0, 0);
|
||||
SwingUtilities.invokeAndWait(DisabledComponentsTest::init);
|
||||
Util.waitForIdle(r);
|
||||
Util.pointOnComp(b, r);
|
||||
if (entered.get()) {
|
||||
throw new RuntimeException("TEST FAILED: disabled button received MouseEntered event");
|
||||
}
|
||||
Util.clickOnComp(b, r);
|
||||
if (pressed.get()) {
|
||||
throw new RuntimeException("TEST FAILED: disabled button received MousePressed event");
|
||||
}
|
||||
} finally {
|
||||
if (frame != null) {
|
||||
frame.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 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 6317481 8012325
|
||||
@summary REG:Pressing the mouse, dragging and releasing it outside the button triggers ActionEvent, XAWT
|
||||
@author Dmitry.Cherepanov@SUN.COM area=awt.event
|
||||
@run main EnterAsGrabbedEvent
|
||||
*/
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class EnterAsGrabbedEvent
|
||||
{
|
||||
//Declare things used in the test, like buttons and labels here
|
||||
private static Frame frame;
|
||||
private static Button button;
|
||||
private static volatile boolean enterTriggered = false;
|
||||
private static volatile boolean actionTriggered = false;
|
||||
|
||||
private static void init()
|
||||
{
|
||||
frame = new Frame();
|
||||
frame.setLayout(new FlowLayout());
|
||||
button = new Button("button");
|
||||
button.addActionListener(actionEvent -> {
|
||||
actionTriggered = true;
|
||||
});
|
||||
frame.add(button);
|
||||
frame.setBounds(100, 100, 200, 200);
|
||||
frame.setVisible(true);
|
||||
frame.validate();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
try {
|
||||
Robot r = new Robot();
|
||||
r.setAutoDelay(200);
|
||||
r.setAutoWaitForIdle(true);
|
||||
SwingUtilities.invokeAndWait(EnterAsGrabbedEvent::init);
|
||||
r.waitForIdle();
|
||||
|
||||
Point loc = button.getLocationOnScreen();
|
||||
r.mouseMove(loc.x+button.getWidth()/2, loc.y+button.getHeight()/2);
|
||||
r.mousePress(InputEvent.BUTTON1_MASK);
|
||||
|
||||
// in this case (drag mouse outside the button):
|
||||
// NotifyEnter (->MouseEnter) should be dispatched to the top-level
|
||||
// event if the grabbed window is the component (button)
|
||||
frame.addMouseListener(
|
||||
new MouseAdapter() {
|
||||
public void mouseEntered(MouseEvent me) {
|
||||
System.out.println(me);
|
||||
enterTriggered = true;
|
||||
}
|
||||
|
||||
// Just for tracing
|
||||
public void mouseExited(MouseEvent me) {
|
||||
System.out.println(me);
|
||||
}
|
||||
});
|
||||
|
||||
// Just for tracing
|
||||
button.addMouseListener(
|
||||
new MouseAdapter(){
|
||||
public void mouseEntered(MouseEvent me){
|
||||
System.out.println(me);
|
||||
}
|
||||
public void mouseExited(MouseEvent me){
|
||||
System.out.println(me);
|
||||
}
|
||||
});
|
||||
|
||||
r.mouseMove(loc.x+button.getWidth() + 1, loc.y+button.getHeight()/2);
|
||||
|
||||
r.mouseRelease(InputEvent.BUTTON1_MASK);
|
||||
|
||||
if (!enterTriggered) {
|
||||
throw new RuntimeException("Test failed. MouseEntered was not triggered");
|
||||
}
|
||||
|
||||
if (actionTriggered) {
|
||||
throw new RuntimeException("Test failed. ActionEvent triggered");
|
||||
}
|
||||
} finally {
|
||||
if (frame != null) {
|
||||
frame.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 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.awt.Rectangle;
|
||||
import java.awt.Robot;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import sun.awt.OSInfo;
|
||||
import sun.awt.SunToolkit;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 7124513
|
||||
* @summary We should support NSTexturedBackgroundWindowMask style on OSX.
|
||||
* @author Sergey Bylokhov
|
||||
*/
|
||||
public final class NSTexturedJFrame {
|
||||
|
||||
private static final String BRUSH = "apple.awt.brushMetalLook";
|
||||
private static final String STYLE = "Window.style";
|
||||
private static final BufferedImage[] images = new BufferedImage[3];
|
||||
private static Rectangle bounds;
|
||||
private static volatile int step;
|
||||
private static JFrame frame;
|
||||
|
||||
public static void main(final String[] args) throws Exception {
|
||||
if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
|
||||
System.out.println("This test is for OSX, considered passed.");
|
||||
return;
|
||||
}
|
||||
// Default window appearance
|
||||
showFrame();
|
||||
step++;
|
||||
// apple.awt.brushMetalLook appearance
|
||||
showFrame();
|
||||
step++;
|
||||
// Window.style appearance
|
||||
showFrame();
|
||||
|
||||
// images on step 1 and 2 should be same
|
||||
testImages(images[1], images[2], false);
|
||||
// images on step 1 and 2 should be different from default
|
||||
testImages(images[0], images[1], true);
|
||||
testImages(images[0], images[2], true);
|
||||
}
|
||||
|
||||
private static void testImages(BufferedImage img1, BufferedImage img2,
|
||||
boolean shouldbeDifferent) {
|
||||
boolean different = false;
|
||||
for (int x = 0; x < img1.getWidth(); ++x) {
|
||||
for (int y = 0; y < img1.getHeight(); ++y) {
|
||||
if (img1.getRGB(x, y) != img2.getRGB(x, y)) {
|
||||
different = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (different != shouldbeDifferent) {
|
||||
throw new RuntimeException("Textured property does not work");
|
||||
}
|
||||
}
|
||||
|
||||
private static void showFrame() throws Exception {
|
||||
final Robot robot = new Robot();
|
||||
robot.setAutoDelay(50);
|
||||
createUI();
|
||||
images[step] = robot.createScreenCapture(bounds);
|
||||
SwingUtilities.invokeAndWait(frame::dispose);
|
||||
sleep();
|
||||
}
|
||||
|
||||
private static void createUI() throws Exception {
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
frame = new JFrame();
|
||||
frame.setUndecorated(true);
|
||||
frame.setSize(400, 400);
|
||||
frame.setLocationRelativeTo(null);
|
||||
switch (step) {
|
||||
case 1:
|
||||
frame.getRootPane().putClientProperty(BRUSH, true);
|
||||
break;
|
||||
case 2:
|
||||
frame.getRootPane().putClientProperty(STYLE, "textured");
|
||||
}
|
||||
frame.setVisible(true);
|
||||
});
|
||||
sleep();
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
bounds = frame.getBounds();
|
||||
});
|
||||
sleep();
|
||||
}
|
||||
|
||||
private static void sleep() throws InterruptedException {
|
||||
((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user