提交 9a4f6fde 编写于 作者: L lana

Merge

......@@ -1068,7 +1068,7 @@ public class Dialog extends Window {
modalityPushed();
try {
EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue();
secondaryLoop = eventQueue.createSecondaryLoop(cond, modalFilter, 5000);
secondaryLoop = eventQueue.createSecondaryLoop(cond, modalFilter, 0);
if (!secondaryLoop.enter()) {
secondaryLoop = null;
}
......
......@@ -142,6 +142,9 @@ public abstract class KeyboardFocusManager
public void removeLastFocusRequest(Component heavyweight) {
KeyboardFocusManager.removeLastFocusRequest(heavyweight);
}
public void setMostRecentFocusOwner(Window window, Component component) {
KeyboardFocusManager.setMostRecentFocusOwner(window, component);
}
}
);
}
......
......@@ -51,7 +51,7 @@ import java.awt.Event;
* in the range from {@code ACTION_FIRST} to {@code ACTION_LAST}.
*
* @see ActionListener
* @see <a href="http://java.sun.com/docs/books/tutorial/post1.0/ui/eventmodel.html">Tutorial: Java 1.1 Event Model</a>
* @see <a href="http://java.sun.com/docs/books/tutorial/uiswing/events/actionlistener.html">Tutorial: How to Write an Action Listener</a>
*
* @author Carl Quinn
* @since 1.1
......
......@@ -344,6 +344,11 @@ public final class AWTAccessor {
* Removes the last focus request for the heavyweight from the queue.
*/
void removeLastFocusRequest(Component heavyweight);
/*
* Sets the most recent focus owner in the window.
*/
void setMostRecentFocusOwner(Window window, Component component);
}
/*
......
......@@ -70,7 +70,10 @@ public abstract class EmbeddedFrame extends Frame
// JDK 1.1 compatibility
private static final long serialVersionUID = 2967042741780317130L;
// Use these in traverseOut method to determine directions
/*
* The constants define focus traversal directions.
* Use them in {@code traverseIn}, {@code traverseOut} methods.
*/
protected static final boolean FORWARD = true;
protected static final boolean BACKWARD = false;
......@@ -283,6 +286,41 @@ public abstract class EmbeddedFrame extends Frame
return false;
}
/**
* This method is called by the embedder when we should receive focus as element
* of the traversal chain. The method requests focus on:
* 1. the first Component of this EmbeddedFrame if user moves focus forward
* in the focus traversal cycle.
* 2. the last Component of this EmbeddedFrame if user moves focus backward
* in the focus traversal cycle.
*
* The direction parameter specifies which of the two mentioned cases is
* happening. Use FORWARD and BACKWARD constants defined in the EmbeddedFrame class
* to avoid confusing boolean values.
*
* A concrete implementation of this method is defined in the platform-dependent
* subclasses.
*
* @param direction FORWARD or BACKWARD
* @return true, if the EmbeddedFrame wants to get focus, false otherwise.
*/
public boolean traverseIn(boolean direction) {
Component comp = null;
if (direction == FORWARD) {
comp = getFocusTraversalPolicy().getFirstComponent(this);
} else {
comp = getFocusTraversalPolicy().getLastComponent(this);
}
if (comp != null) {
// comp.requestFocus(); - Leads to a hung.
AWTAccessor.getKeyboardFocusManagerAccessor().setMostRecentFocusOwner(this, comp);
synthesizeWindowActivation(true);
}
return (null != comp);
}
/**
* This method is called from dispatchKeyEvent in the following two cases:
* 1. The focus is on the first Component of this EmbeddedFrame and we are
......
......@@ -64,7 +64,10 @@ class GtkFileDialogPeer extends XDialogPeer implements FileDialogPeer {
accessor.setFile(fd, null);
accessor.setFiles(fd, null, null);
} else {
accessor.setDirectory(fd, directory);
// Fix 6987233: add the trailing slash if it's absent
accessor.setDirectory(fd, directory +
(directory.endsWith(File.separator) ?
"" : File.separator));
accessor.setFile(fd, filenames[0]);
accessor.setFiles(fd, directory, filenames);
}
......
......@@ -705,12 +705,8 @@ public class XBaseWindow {
throw new IllegalStateException("Attempt to resize uncreated window");
}
insLog.fine("Setting bounds on " + this + " to (" + x + ", " + y + "), " + width + "x" + height);
if (width <= 0) {
width = 1;
}
if (height <= 0) {
height = 1;
}
width = Math.max(MIN_SIZE, width);
height = Math.max(MIN_SIZE, height);
XToolkit.awtLock();
try {
XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), getWindow(), x,y,width,height);
......
......@@ -763,12 +763,8 @@ abstract class XDecoratedPeer extends XWindowPeer {
}
private void checkShellRectSize(Rectangle shellRect) {
if (shellRect.width < 0) {
shellRect.width = 1;
}
if (shellRect.height < 0) {
shellRect.height = 1;
}
shellRect.width = Math.max(MIN_SIZE, shellRect.width);
shellRect.height = Math.max(MIN_SIZE, shellRect.height);
}
private void checkShellRectPos(Rectangle shellRect) {
......
......@@ -28,9 +28,12 @@ package sun.awt.X11;
import sun.awt.EmbeddedFrame;
import java.awt.*;
import java.awt.AWTKeyStroke;
import java.util.logging.Logger;
public class XEmbeddedFrame extends EmbeddedFrame {
private static final Logger log = Logger.getLogger(XEmbeddedFrame.class.getName());
long handle;
public XEmbeddedFrame() {
}
......@@ -70,6 +73,21 @@ public class XEmbeddedFrame extends EmbeddedFrame {
this(handle, supportsXEmbed, false);
}
/*
* The method shouldn't be called in case of active XEmbed.
*/
public boolean traverseIn(boolean direction) {
XEmbeddedFramePeer peer = (XEmbeddedFramePeer)getPeer();
if (peer != null) {
if (peer.supportsXEmbed() && peer.isXEmbedActive()) {
log.fine("The method shouldn't be called when XEmbed is active!");
} else {
return super.traverseIn(direction);
}
}
return false;
}
protected boolean traverseOut(boolean direction) {
XEmbeddedFramePeer xefp = (XEmbeddedFramePeer) getPeer();
if (direction == FORWARD) {
......@@ -81,6 +99,20 @@ public class XEmbeddedFrame extends EmbeddedFrame {
return true;
}
/*
* The method shouldn't be called in case of active XEmbed.
*/
public void synthesizeWindowActivation(boolean doActivate) {
XEmbeddedFramePeer peer = (XEmbeddedFramePeer)getPeer();
if (peer != null) {
if (peer.supportsXEmbed() && peer.isXEmbedActive()) {
log.fine("The method shouldn't be called when XEmbed is active!");
} else {
peer.synthesizeFocusInOut(doActivate);
}
}
}
public void registerAccelerator(AWTKeyStroke stroke) {
XEmbeddedFramePeer xefp = (XEmbeddedFramePeer) getPeer();
if (xefp != null) {
......
......@@ -35,6 +35,8 @@ import sun.util.logging.PlatformLogger;
import sun.awt.EmbeddedFrame;
import sun.awt.SunToolkit;
import static sun.awt.X11.XConstants.*;
public class XEmbeddedFramePeer extends XFramePeer {
private static final PlatformLogger xembedLog = PlatformLogger.getLogger("sun.awt.X11.xembed.XEmbeddedFramePeer");
......@@ -305,4 +307,20 @@ public class XEmbeddedFramePeer extends XFramePeer {
EmbeddedFrame frame = (EmbeddedFrame)target;
frame.notifyModalBlocked(blocker, blocked);
}
public void synthesizeFocusInOut(boolean doFocus) {
XFocusChangeEvent xev = new XFocusChangeEvent();
XToolkit.awtLock();
try {
xev.set_type(doFocus ? FocusIn : FocusOut);
xev.set_window(getFocusProxy().getWindow());
xev.set_mode(NotifyNormal);
XlibWrapper.XSendEvent(XToolkit.getDisplay(), getFocusProxy().getWindow(), false,
NoEventMask, xev.pData);
} finally {
XToolkit.awtUnlock();
xev.dispose();
}
}
}
......@@ -1482,8 +1482,19 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
try {
if (numberOfButtons == 0) {
numberOfButtons = getNumberOfButtonsImpl();
numberOfButtons = (numberOfButtons > MAX_BUTTONS_SUPPORTED)? MAX_BUTTONS_SUPPORTED : numberOfButtons;
//4th and 5th buttons are for wheel and shouldn't be reported as buttons.
//If we have more than 3 physical buttons and a wheel, we report N-2 buttons.
//If we have 3 physical buttons and a wheel, we report 3 buttons.
//If we have 1,2,3 physical buttons, we report it as is i.e. 1,2 or 3 respectively.
if (numberOfButtons >=5) {
numberOfButtons -= 2;
} else if (numberOfButtons == 4 || numberOfButtons ==5){
numberOfButtons = 3;
}
}
return (numberOfButtons > MAX_BUTTONS_SUPPORTED)? MAX_BUTTONS_SUPPORTED : numberOfButtons;
//Assume don't have to re-query the number again and again.
return numberOfButtons;
} finally {
awtUnlock();
}
......
......@@ -556,24 +556,26 @@ public abstract class WComponentPeer extends WObjectPeer
Component target = (Component)getTarget();
Window window = SunToolkit.getContainingWindow(target);
if (window != null && !window.isOpaque()) {
// Non-opaque windows do not support heavyweight children.
// Redirect all painting to the Window's Graphics instead.
// The caller is responsible for calling the
// WindowPeer.updateWindow() after painting has finished.
int x = 0, y = 0;
for (Component c = target; c != window; c = c.getParent()) {
x += c.getX();
y += c.getY();
}
if (window != null) {
Graphics g =
((WWindowPeer)window.getPeer()).getTranslucentGraphics();
// getTranslucentGraphics() returns non-null value for non-opaque windows only
if (g != null) {
// Non-opaque windows do not support heavyweight children.
// Redirect all painting to the Window's Graphics instead.
// The caller is responsible for calling the
// WindowPeer.updateWindow() after painting has finished.
int x = 0, y = 0;
for (Component c = target; c != window; c = c.getParent()) {
x += c.getX();
y += c.getY();
}
g.translate(x, y);
g.clipRect(0, 0, target.getWidth(), target.getHeight());
g.translate(x, y);
g.clipRect(0, 0, target.getWidth(), target.getHeight());
return g;
return g;
}
}
SurfaceData surfaceData = this.surfaceData;
......
......@@ -191,9 +191,20 @@ public class WEmbeddedFrame extends EmbeddedFrame {
public void activateEmbeddingTopLevel() {
}
public void synthesizeWindowActivation(boolean doActivate) {
((WEmbeddedFramePeer)getPeer()).synthesizeWmActivate(doActivate);
public void synthesizeWindowActivation(final boolean doActivate) {
if (!doActivate || EventQueue.isDispatchThread()) {
((WEmbeddedFramePeer)getPeer()).synthesizeWmActivate(doActivate);
} else {
// To avoid focus concurrence b/w IE and EmbeddedFrame
// activation is postponed by means of posting it to EDT.
EventQueue.invokeLater(new Runnable() {
public void run() {
((WEmbeddedFramePeer)getPeer()).synthesizeWmActivate(true);
}
});
}
}
public void registerAccelerator(AWTKeyStroke stroke) {}
public void unregisterAccelerator(AWTKeyStroke stroke) {}
......
......@@ -594,16 +594,6 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer,
}
}
@Override
public Graphics getGraphics() {
synchronized (getStateLock()) {
if (!isOpaque) {
return getTranslucentGraphics();
}
}
return super.getGraphics();
}
@Override
public void setBackground(Color c) {
super.setBackground(c);
......
......@@ -2329,6 +2329,19 @@ MsgRouting AwtComponent::WmMouseDown(UINT flags, int x, int y, int button)
MSG msg;
InitMessage(&msg, lastMessage, flags, MAKELPARAM(x, y), x, y);
AwtWindow *toplevel = GetContainer();
if (toplevel && !toplevel->IsSimpleWindow()) {
/*
* The frame should be focused by click in case it is
* the active window but not the focused window. See 6886678.
*/
if (toplevel->GetHWnd() == ::GetActiveWindow() &&
toplevel->GetHWnd() != AwtComponent::GetFocusedWindow())
{
toplevel->AwtSetActiveWindow();
}
}
SendMouseEvent(java_awt_event_MouseEvent_MOUSE_PRESSED, now, x, y,
GetJavaModifiers(), clickCount, JNI_FALSE,
GetButton(button), &msg);
......
......@@ -59,15 +59,17 @@ JNIEXPORT jstring JNICALL Java_sun_awt_windows_WDesktopPeer_ShellExecute
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
(int)retval,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR)&buffer,
0,
NULL );
jstring errmsg = JNU_NewStringPlatform(env, buffer, len);
LocalFree(buffer);
return errmsg;
if (buffer) {
jstring errmsg = JNU_NewStringPlatform(env, buffer);
LocalFree(buffer);
return errmsg;
}
}
return NULL;
......
......@@ -505,7 +505,8 @@ void AwtDesktopProperties::GetOtherParameters() {
SetIntegerProperty(TEXT("win.drag.width"), cxdrag);
SetIntegerProperty(TEXT("win.drag.height"), cydrag);
SetIntegerProperty(TEXT("DnD.gestureMotionThreshold"), max(cxdrag, cydrag)/2);
SetIntegerProperty(TEXT("awt.mouse.numButtons"), GetSystemMetrics(SM_CMOUSEBUTTONS));
SetIntegerProperty(TEXT("awt.mouse.numButtons"), AwtToolkit::GetNumberOfButtons());
SetIntegerProperty(TEXT("awt.multiClickInterval"), GetDoubleClickTime());
// BEGIN cross-platform properties
......
......@@ -133,6 +133,8 @@ extern "C" JNIEXPORT jboolean JNICALL AWTIsHeadless() {
static LPCTSTR szAwtToolkitClassName = TEXT("SunAwtToolkit");
static const int MOUSE_BUTTONS_WINDOWS_SUPPORTED = 5; //three standard buttons + XBUTTON1 + XBUTTON2.
UINT AwtToolkit::GetMouseKeyState()
{
static BOOL mbSwapped = ::GetSystemMetrics(SM_SWAPBUTTON);
......@@ -2310,5 +2312,9 @@ void AwtToolkit::setExtraMouseButtonsEnabled(BOOL enable) {
JNIEXPORT jint JNICALL Java_sun_awt_windows_WToolkit_getNumberOfButtonsImpl
(JNIEnv *, jobject self) {
return GetSystemMetrics(SM_CMOUSEBUTTONS);
return AwtToolkit::GetNumberOfButtons();
}
UINT AwtToolkit::GetNumberOfButtons() {
return MOUSE_BUTTONS_WINDOWS_SUPPORTED;
}
......@@ -185,6 +185,7 @@ public:
BOOL IsDynamicLayoutActive();
BOOL areExtraMouseButtonsEnabled();
void setExtraMouseButtonsEnabled(BOOL enable);
static UINT GetNumberOfButtons();
INLINE BOOL localPump() { return m_localPump; }
INLINE BOOL VerifyComponents() { return FALSE; } // TODO: Use new DebugHelper class to set this flag
......
/*
* Copyright (c) 1995, 2010, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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 FocusOwnerFrameOnClick.java %W% %E%
@bug 6886678
@summary Tests that clicking an owner frame switches focus from its owned window.
@author Anton Tarasov: area=awt.focus
@library ../../regtesthelpers
@build Util
@run main FocusOwnerFrameOnClick
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.concurrent.atomic.AtomicBoolean;
import java.lang.reflect.InvocationTargetException;
import test.java.awt.regtesthelpers.Util;
public class FocusOwnerFrameOnClick extends Applet {
Robot robot;
Frame frame = new Frame("Frame");
Window window = new Window(frame);
Button fButton = new Button("fButton");
Button wButton = new Button("wButton");
AtomicBoolean focused = new AtomicBoolean(false);
public static void main(String[] args) {
FocusOwnerFrameOnClick app = new FocusOwnerFrameOnClick();
app.init();
app.start();
}
public void init() {
robot = Util.createRobot();
frame.setLayout(new FlowLayout());
frame.setSize(200, 200);
frame.add(fButton);
window.setLocation(300, 0);
window.add(wButton);
window.pack();
}
public void start() {
frame.setVisible(true);
Util.waitForIdle(robot);
window.setVisible(true);
Util.waitForIdle(robot);
if (!wButton.hasFocus()) {
if (!Util.trackFocusGained(wButton, new Runnable() {
public void run() {
Util.clickOnComp(wButton, robot);
}
}, 2000, false))
{
throw new TestErrorException("wButton didn't gain focus on showing");
}
}
Runnable clickAction = new Runnable() {
public void run() {
Point loc = fButton.getLocationOnScreen();
Dimension dim = fButton.getSize();
robot.mouseMove(loc.x, loc.y + dim.height + 20);
robot.delay(50);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(50);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
};
if (!Util.trackWindowGainedFocus(frame, clickAction, 2000, true)) {
throw new TestFailedException("The frame wasn't focused on click");
}
System.out.println("Test passed.");
}
}
/**
* Thrown when the behavior being verified is found wrong.
*/
class TestFailedException extends RuntimeException {
TestFailedException(String msg) {
super("Test failed: " + msg);
}
}
/**
* Thrown when an error not related to the behavior being verified is encountered.
*/
class TestErrorException extends RuntimeException {
TestErrorException(String msg) {
super("Unexpected error: " + msg);
}
}
......@@ -21,16 +21,15 @@ public class MouseModifiersUnitTest_Extra extends Frame {
static final int SHIFT = 1;
static final int CTRL = 2;
static final int ALT = 3;
static CheckingModifierAdapter adapterTest1;
static CheckingModifierAdapter adapterTest2;
static CheckingModifierAdapter adapterTest3;
static CheckingModifierAdapter adapterTest4;
static CheckingModifierAdapterExtra adapterTest1;
static CheckingModifierAdapterExtra adapterTest2;
static CheckingModifierAdapterExtra adapterTest3;
static CheckingModifierAdapterExtra adapterTest4;
static boolean debug = true; //dump all errors (debug) or throw first(under jtreg) exception
static boolean autorun = false; //use robot or manual run
static int testModifier = NONE;
static int [] mouseButtons;
static int [] mouseButtonDownMasks;
//an arrays representing a modifiersEx of extra mouse buttons while using ALT/CTRL/SHIFT or none of them
......@@ -39,7 +38,6 @@ public class MouseModifiersUnitTest_Extra extends Frame {
static int [] modifiersExStandardCTRL;
static int [] modifiersExStandardALT;
// final static int [] mouseButtons = new int [] {MouseEvent.BUTTON1_MASK, MouseEvent.BUTTON2_MASK, MouseEvent.BUTTON3_MASK};
// BUTTON1, 2, 3 press-release.
final static int modifiersStandard = 0; //InputEvent.BUTTON_DOWN_MASK;
......@@ -56,7 +54,7 @@ public class MouseModifiersUnitTest_Extra extends Frame {
if (modifiersEx != curStandardExModifiers[index]){
// System.out.println(">>>>>>>>>>>>>>> Pressed. modifiersEx "+modifiersEx +" : "+!= curStandardExModifiers");
MessageLogger.reportError("Test failed : Pressed. modifiersEx != curStandardExModifiers");
MessageLogger.reportError("Test failed : Pressed. modifiersEx != curStandardExModifiers. Got: " + modifiersEx + " , Expected: " + curStandardExModifiers[index]);
}
//check event.paramString() output
......@@ -168,7 +166,7 @@ public class MouseModifiersUnitTest_Extra extends Frame {
}
if (modifiersEx != curStandardExModifiers[index]){
MessageLogger.reportError("Test failed : Released. modifiersEx != curStandardExModifiers");
MessageLogger.reportError("Test failed : Released. modifiersEx != curStandardExModifiers. Got: " + modifiersEx + " , Expected: " + curStandardExModifiers[index]);
}
//check event.paramString() output
......@@ -191,7 +189,7 @@ public class MouseModifiersUnitTest_Extra extends Frame {
}
if (modifiersEx != curStandardExModifiers[index]){
MessageLogger.reportError("Test failed : Clicked. modifiersEx != curStandardExModifiers");
MessageLogger.reportError("Test failed : Clicked. modifiersEx != curStandardExModifiers. Got: " + modifiersEx + " , Expected: " + curStandardExModifiers[index]);
}
//check event.paramString() output
......@@ -275,11 +273,11 @@ public class MouseModifiersUnitTest_Extra extends Frame {
this.addMouseListener(adapterTest1);
robot.delay(1000);
robot.mouseMove(getLocationOnScreen().x + getWidth()/2, getLocationOnScreen().y + getHeight()/2);
for (int i = 3; i< mouseButtons.length; i++){
System.out.println("testNONE() => " +mouseButtons[i] );
robot.mousePress(mouseButtons[i]);
for (int i = 3; i< mouseButtonDownMasks.length; i++){
System.out.println("testNONE() => " +mouseButtonDownMasks[i] );
robot.mousePress(mouseButtonDownMasks[i]);
robot.delay(100);
robot.mouseRelease(mouseButtons[i]);
robot.mouseRelease(mouseButtonDownMasks[i]);
}
robot.delay(1000);
this.removeMouseListener(adapterTest1);
......@@ -289,12 +287,12 @@ public class MouseModifiersUnitTest_Extra extends Frame {
this.addMouseListener(adapterTest2);
robot.delay(1000);
robot.mouseMove(getLocationOnScreen().x + getWidth()/2, getLocationOnScreen().y + getHeight()/2);
for (int i = 3; i< mouseButtons.length; i++){
for (int i = 3; i< mouseButtonDownMasks.length; i++){
robot.keyPress(KeyEvent.VK_SHIFT);
System.out.println("testSHIFT() => " +mouseButtons[i] );
robot.mousePress(mouseButtons[i]);
System.out.println("testSHIFT() => " +mouseButtonDownMasks[i] );
robot.mousePress(mouseButtonDownMasks[i]);
robot.delay(100);
robot.mouseRelease(mouseButtons[i]);
robot.mouseRelease(mouseButtonDownMasks[i]);
robot.keyRelease(KeyEvent.VK_SHIFT);
}
robot.delay(1000);
......@@ -305,12 +303,12 @@ public class MouseModifiersUnitTest_Extra extends Frame {
this.addMouseListener(adapterTest3);
robot.delay(1000);
robot.mouseMove(getLocationOnScreen().x + getWidth()/2, getLocationOnScreen().y + getHeight()/2);
for (int i = 3; i< mouseButtons.length; i++){
for (int i = 3; i< mouseButtonDownMasks.length; i++){
robot.keyPress(KeyEvent.VK_CONTROL);
System.out.println("testCTRL() => " +mouseButtons[i] );
robot.mousePress(mouseButtons[i]);
System.out.println("testCTRL() => " +mouseButtonDownMasks[i] );
robot.mousePress(mouseButtonDownMasks[i]);
robot.delay(100);
robot.mouseRelease(mouseButtons[i]);
robot.mouseRelease(mouseButtonDownMasks[i]);
robot.keyRelease(KeyEvent.VK_CONTROL);
}
robot.delay(1000);
......@@ -321,12 +319,12 @@ public class MouseModifiersUnitTest_Extra extends Frame {
this.addMouseListener(adapterTest4);
robot.delay(1000);
robot.mouseMove(getLocationOnScreen().x + getWidth()/2, getLocationOnScreen().y + getHeight()/2);
for (int i = 3; i< mouseButtons.length; i++){
for (int i = 3; i< mouseButtonDownMasks.length; i++){
robot.keyPress(KeyEvent.VK_ALT);
System.out.println("testALT() => " +mouseButtons[i] );
robot.mousePress(mouseButtons[i]);
System.out.println("testALT() => " +mouseButtonDownMasks[i] );
robot.mousePress(mouseButtonDownMasks[i]);
robot.delay(100);
robot.mouseRelease(mouseButtons[i]);
robot.mouseRelease(mouseButtonDownMasks[i]);
robot.keyRelease(KeyEvent.VK_ALT);
}
robot.delay(1000);
......@@ -368,52 +366,52 @@ public class MouseModifiersUnitTest_Extra extends Frame {
}
public static void initAdapters(){
adapterTest1 = new CheckingModifierAdapter(NONE);
adapterTest2 = new CheckingModifierAdapter(SHIFT);
adapterTest3 = new CheckingModifierAdapter(CTRL);
adapterTest4 = new CheckingModifierAdapter(ALT);
adapterTest1 = new CheckingModifierAdapterExtra(NONE);
adapterTest2 = new CheckingModifierAdapterExtra(SHIFT);
adapterTest3 = new CheckingModifierAdapterExtra(CTRL);
adapterTest4 = new CheckingModifierAdapterExtra(ALT);
}
public static void initVars(){
int [] tmp = new int [MouseInfo.getNumberOfButtons()];
for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
tmp[i] = InputEvent.getMaskForButton(i+1);
// System.out.println("TEST: "+tmp[i]);
//Init the array of the mouse button masks. It will be used for generating mouse events.
mouseButtonDownMasks = new int [MouseInfo.getNumberOfButtons()];
for (int i = 0; i < mouseButtonDownMasks.length; i++){
mouseButtonDownMasks[i] = InputEvent.getMaskForButton(i+1);
System.out.println("MouseArray [i] == "+mouseButtonDownMasks[i]);
}
mouseButtons = Arrays.copyOf(tmp, tmp.length);
for (int i = 0; i < mouseButtons.length; i++){
System.out.println("MouseArray [i] == "+mouseButtons[i]);
}
mouseButtonDownMasks = Arrays.copyOf(tmp, tmp.length);
// So we need to get the number of extra buttons on the mouse: "MouseInfo.getNumberOfButtons() - 3"
// and multyply on 3 because each button will generate three events : PRESS, RELEASE and CLICK.
tmp = new int [(MouseInfo.getNumberOfButtons()-3)*3];
Arrays.fill(tmp, 0);
int [] tmp = new int [(MouseInfo.getNumberOfButtons()-3)*3];
//Fill array of expected results for the case when mouse buttons are only used (no-modifier keys)
Arrays.fill(tmp, 0);
for (int i = 0, j = 3; i < tmp.length; i = i + 3, j++){
tmp[i] = mouseButtonDownMasks[j];
}
modifiersExStandard = Arrays.copyOf(tmp, tmp.length);
//Fill array of expected results for the case when mouse buttons are only used with SHIFT modifier key
Arrays.fill(tmp, InputEvent.SHIFT_DOWN_MASK);
for (int i = 0, j = 3; i < MouseInfo.getNumberOfButtons(); i = i + 3, j++){
tmp[i] = tmp[j] | mouseButtonDownMasks[j];
for (int i = 0, j = 3; i < tmp.length; i = i + 3, j++){
System.out.println("modifiersExStandardSHIFT FILLING : " + tmp[i] + " + " + mouseButtonDownMasks[j]);
tmp[i] = tmp[i] | mouseButtonDownMasks[j];
}
modifiersExStandardSHIFT = Arrays.copyOf(tmp, tmp.length);
//Fill array of expected results for the case when mouse buttons are only used with CTRL modifier key
Arrays.fill(tmp, InputEvent.CTRL_DOWN_MASK);
for (int i = 0, j = 3; i < MouseInfo.getNumberOfButtons(); i = i + 3, j++){
tmp[i] = tmp[j] | mouseButtonDownMasks[j];
for (int i = 0, j = 3; i < tmp.length; i = i + 3, j++){
System.out.println("modifiersExStandardCTRL FILLING : " + tmp[i] + " + " + mouseButtonDownMasks[j]);
tmp[i] = tmp[i] | mouseButtonDownMasks[j];
}
modifiersExStandardCTRL = Arrays.copyOf(tmp, tmp.length);
//Fill array of expected results for the case when mouse buttons are only used with ALT modifier key
Arrays.fill(tmp, InputEvent.ALT_DOWN_MASK);
for (int i = 0, j = 3; i < MouseInfo.getNumberOfButtons(); i = i + 3, j++){
tmp[i] = tmp[j] | mouseButtonDownMasks[j];
for (int i = 0, j = 3; i < tmp.length; i = i + 3, j++){
System.out.println("modifiersExStandardALT FILLING : " + tmp[i] + " + " + mouseButtonDownMasks[j]);
tmp[i] = tmp[i] | mouseButtonDownMasks[j];
}
modifiersExStandardALT = Arrays.copyOf(tmp, tmp.length);
}
......@@ -436,9 +434,9 @@ public class MouseModifiersUnitTest_Extra extends Frame {
/* A class that invoke appropriate verification
* routine with current modifier.
*/
class CheckingModifierAdapter extends MouseAdapter{
class CheckingModifierAdapterExtra extends MouseAdapter{
int modifier;
public CheckingModifierAdapter(int modifier){
public CheckingModifierAdapterExtra(int modifier){
this.modifier = modifier;
}
......
......@@ -90,7 +90,7 @@ public class ToolkitPropertyTest_Enable extends Frame {
int [] buttonMasks = new int[MouseInfo.getNumberOfButtons()]; // = InputEvent.getButtonDownMasks();
for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
buttonMasks[i] = InputEvent.getMaskForButton(i+1);
System.out.println("TEST: "+buttonMasks[i]);
System.out.println("TEST: buttonMasks["+ i +"] = " + buttonMasks[i]);
}
for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册