# HG changeset patch # User coffeys # Date 1412089675 -3600 # Node ID e975546b12ad48b8b11bf6aec68c3073e15d8c18 # Parent 2c00191a86c3d573914cac6f47cc02da756319ed# Parent 08ee676353cc2b83890cdb8606a8ef539a492da1 Merge diff -r 2c00191a86c3 -r e975546b12ad src/windows/native/sun/windows/awt_TextArea.cpp --- a/src/windows/native/sun/windows/awt_TextArea.cpp Mon Sep 29 17:39:13 2014 +0100 +++ b/src/windows/native/sun/windows/awt_TextArea.cpp Tue Sep 30 16:07:55 2014 +0100 @@ -47,16 +47,12 @@ jfieldID AwtTextArea::scrollbarVisibilityID; -WNDPROC AwtTextArea::sm_pDefWindowProc = NULL; - /************************************************************************ * AwtTextArea methods */ AwtTextArea::AwtTextArea() { - m_bIgnoreEnChange = FALSE; m_bCanUndo = FALSE; - m_hEditCtrl = NULL; m_lHDeltaAccum = 0; m_lVDeltaAccum = 0; } @@ -67,10 +63,6 @@ void AwtTextArea::Dispose() { - if (m_hEditCtrl != NULL) { - VERIFY(::DestroyWindow(m_hEditCtrl)); - m_hEditCtrl = NULL; - } AwtTextComponent::Dispose(); } @@ -91,10 +83,6 @@ } } -void AwtTextArea::EditGetSel(CHARRANGE &cr) { - SendMessage(EM_EXGETSEL, 0, reinterpret_cast(&cr)); -} - /* Count how many '\n's are there in jStr */ size_t AwtTextArea::CountNewLines(JNIEnv *env, jstring jStr, size_t maxlen) { @@ -149,159 +137,6 @@ return retValue; } -/* - * This routine is a window procedure for the subclass of the standard edit control - * used to generate context menu. RichEdit controls don't have built-in context menu. - * To implement this functionality we have to create an invisible edit control and - * forward WM_CONTEXTMENU messages from a RichEdit control to this helper edit control. - * While the edit control context menu is active we intercept the message generated in - * response to particular item selection and forward it back to the RichEdit control. - * (See AwtTextArea::WmContextMenu for more details). - */ -LRESULT -AwtTextArea::EditProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - - static BOOL bContextMenuActive = FALSE; - - LRESULT retValue = 0; - MsgRouting mr = mrDoDefault; - - DASSERT(::IsWindow(::GetParent(hWnd))); - - switch (message) { - case WM_UNDO: - case WM_CUT: - case WM_COPY: - case WM_PASTE: - case WM_CLEAR: - case EM_SETSEL: - if (bContextMenuActive) { - ::SendMessage(::GetParent(hWnd), message, wParam, lParam); - mr = mrConsume; - } - break; - case WM_CONTEXTMENU: - bContextMenuActive = TRUE; - break; - } - - if (mr == mrDoDefault) { - DASSERT(sm_pDefWindowProc != NULL); - retValue = ::CallWindowProc(sm_pDefWindowProc, - hWnd, message, wParam, lParam); - } - - if (message == WM_CONTEXTMENU) { - bContextMenuActive = FALSE; - } - - return retValue; -} - -MsgRouting -AwtTextArea::WmContextMenu(HWND hCtrl, UINT xPos, UINT yPos) { - /* Use the system provided edit control class to generate context menu. */ - if (m_hEditCtrl == NULL) { - DWORD dwStyle = WS_CHILD; - DWORD dwExStyle = 0; - m_hEditCtrl = ::CreateWindowEx(dwExStyle, - L"EDIT", - L"TEXT", - dwStyle, - 0, 0, 0, 0, - GetHWnd(), - reinterpret_cast( - static_cast( - CreateControlID())), - AwtToolkit::GetInstance().GetModuleHandle(), - NULL); - DASSERT(m_hEditCtrl != NULL); - if (sm_pDefWindowProc == NULL) { - sm_pDefWindowProc = (WNDPROC)::GetWindowLongPtr(m_hEditCtrl, - GWLP_WNDPROC); - } - ::SetLastError(0); - INT_PTR ret = ::SetWindowLongPtr(m_hEditCtrl, GWLP_WNDPROC, - (INT_PTR)AwtTextArea::EditProc); - DASSERT(ret != 0 || ::GetLastError() == 0); - } - - /* - * Tricks on the edit control to ensure that its context menu has - * the correct set of enabled items according to the RichEdit state. - */ - ::SetWindowText(m_hEditCtrl, TEXT("TEXT")); - - if (m_bCanUndo == TRUE && SendMessage(EM_CANUNDO)) { - /* Enable 'Undo' item. */ - ::SendMessage(m_hEditCtrl, WM_CHAR, 'A', 0); - } - - { - /* - * Initial selection for the edit control - (0,1). - * This enables 'Cut', 'Copy' and 'Delete' and 'Select All'. - */ - INT nStart = 0; - INT nEnd = 1; - if (SendMessage(EM_SELECTIONTYPE) == SEL_EMPTY) { - /* - * RichEdit selection is empty - clear selection of the edit control. - * This disables 'Cut', 'Copy' and 'Delete'. - */ - nStart = -1; - nEnd = 0; - } else { - - CHARRANGE cr; - EditGetSel(cr); - /* Check if all the text is selected. */ - if (cr.cpMin == 0) { - - int len = ::GetWindowTextLength(GetHWnd()); - if (cr.cpMin == 0 && cr.cpMax >= len) { - /* - * All the text is selected in RichEdit - select all the - * text in the edit control. This disables 'Select All'. - */ - nStart = 0; - nEnd = -1; - } - } - } - ::SendMessage(m_hEditCtrl, EM_SETSEL, (WPARAM)nStart, (LPARAM)nEnd); - } - - /* Disable 'Paste' item if the RichEdit control is read-only. */ - ::SendMessage(m_hEditCtrl, EM_SETREADONLY, - GetStyle() & ES_READONLY ? TRUE : FALSE, 0); - - POINT p; - p.x = xPos; - p.y = yPos; - - /* - * If the context menu is requested with SHIFT+F10 or VK_APPS key, - * we position its top left corner to the center of the RichEdit - * client rect. - */ - if (p.x == -1 && p.y == -1) { - RECT r; - VERIFY(::GetClientRect(GetHWnd(), &r)); - p.x = (r.left + r.right) / 2; - p.y = (r.top + r.bottom) / 2; - VERIFY(::ClientToScreen(GetHWnd(), &p)); - } - - // The context menu steals focus from the proxy. - // So, set the focus-restore flag up. - SetRestoreFocus(TRUE); - ::SendMessage(m_hEditCtrl, WM_CONTEXTMENU, (WPARAM)m_hEditCtrl, MAKELPARAM(p.x, p.y)); - SetRestoreFocus(FALSE); - - return mrConsume; -} - MsgRouting AwtTextArea::WmNcHitTest(UINT x, UINT y, LRESULT& retVal) { @@ -314,27 +149,8 @@ MsgRouting -AwtTextArea::WmNotify(UINT notifyCode) -{ - if (notifyCode == EN_CHANGE) { - /* - * Ignore notifications if the text hasn't been changed. - * EN_CHANGE sent on character formatting changes as well. - */ - if (m_bIgnoreEnChange == FALSE) { - m_bCanUndo = TRUE; - DoCallback("valueChanged", "()V"); - } else { - m_bCanUndo = FALSE; - } - } - return mrDoDefault; -} - -MsgRouting AwtTextArea::HandleEvent(MSG *msg, BOOL synthetic) { - MsgRouting returnVal; /* * RichEdit 1.0 control starts internal message loop if the * left mouse button is pressed while the cursor is not over @@ -486,26 +302,6 @@ } delete msg; return mrConsume; - } else if (msg->message == WM_RBUTTONUP || - (msg->message == WM_SYSKEYDOWN && msg->wParam == VK_F10 && - HIBYTE(::GetKeyState(VK_SHIFT)))) { - POINT p; - if (msg->message == WM_RBUTTONUP) { - VERIFY(::GetCursorPos(&p)); - } else { - p.x = -1; - p.y = -1; - } - - if (!::PostMessage(GetHWnd(), WM_CONTEXTMENU, (WPARAM)GetHWnd(), - MAKELPARAM(p.x, p.y))) { - JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); - JNU_ThrowInternalError(env, "Message not posted, native event queue may be full."); - env->ExceptionDescribe(); - env->ExceptionClear(); - } - delete msg; - return mrConsume; } else if (msg->message == WM_MOUSEWHEEL) { // 4417236: If there is an old version of RichEd32.dll which // does not provide the mouse wheel scrolling we have to @@ -596,15 +392,7 @@ // 4417236: end of fix } - /* - * Store the 'synthetic' parameter so that the WM_PASTE security check - * happens only for synthetic events. - */ - m_synthetic = synthetic; - returnVal = AwtComponent::HandleEvent(msg, synthetic); - m_synthetic = FALSE; - - return returnVal; + return AwtTextComponent::HandleEvent(msg, synthetic); } diff -r 2c00191a86c3 -r e975546b12ad src/windows/native/sun/windows/awt_TextArea.h --- a/src/windows/native/sun/windows/awt_TextArea.h Mon Sep 29 17:39:13 2014 +0100 +++ b/src/windows/native/sun/windows/awt_TextArea.h Tue Sep 30 16:07:55 2014 +0100 @@ -57,17 +57,11 @@ static size_t GetALength(JNIEnv* env, jstring jStr, size_t maxlen); LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); - static LRESULT CALLBACK EditProc(HWND hWnd, UINT message, - WPARAM wParam, LPARAM lParam); MsgRouting WmEnable(BOOL fEnabled); - MsgRouting WmContextMenu(HWND hCtrl, UINT xPos, UINT yPos); - MsgRouting WmNotify(UINT notifyCode); MsgRouting WmNcHitTest(UINT x, UINT y, LRESULT &retVal); MsgRouting HandleEvent(MSG *msg, BOOL synthetic); - INLINE void SetIgnoreEnChange(BOOL b) { m_bIgnoreEnChange = b; } - virtual BOOL InheritsNativeMouseWheelBehavior(); virtual void Reshape(int x, int y, int w, int h); @@ -81,22 +75,7 @@ protected: void EditSetSel(CHARRANGE &cr); - void EditGetSel(CHARRANGE &cr); private: - // RichEdit 1.0 control generates EN_CHANGE notifications not only - // on text changes, but also on any character formatting change. - // This flag is true when the latter case is detected. - BOOL m_bIgnoreEnChange; - - // RichEdit 1.0 control undoes a character formatting change - // if it is the latest. We don't create our own undo buffer, - // but just prohibit undo in case if the latest operation - // is a formatting change. - BOOL m_bCanUndo; - - HWND m_hEditCtrl; - static WNDPROC sm_pDefWindowProc; - LONG m_lHDeltaAccum; LONG m_lVDeltaAccum; diff -r 2c00191a86c3 -r e975546b12ad src/windows/native/sun/windows/awt_TextComponent.cpp --- a/src/windows/native/sun/windows/awt_TextComponent.cpp Mon Sep 29 17:39:13 2014 +0100 +++ b/src/windows/native/sun/windows/awt_TextComponent.cpp Tue Sep 30 16:07:55 2014 +0100 @@ -66,6 +66,8 @@ m_lLastPos = -1; m_isLFonly = FALSE; m_EOLchecked = FALSE; + m_hEditCtrl = NULL; + m_bIgnoreEnChange = FALSE; // javaEventsMask = 0; // accessibility support } @@ -213,6 +215,16 @@ return c; } +void AwtTextComponent::Dispose() +{ + if (m_hEditCtrl != NULL) { + VERIFY(::DestroyWindow(m_hEditCtrl)); + m_hEditCtrl = NULL; + } + AwtComponent::Dispose(); +} + + LRESULT AwtTextComponent::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { @@ -322,7 +334,16 @@ AwtTextComponent::WmNotify(UINT notifyCode) { if (notifyCode == EN_CHANGE) { - DoCallback("valueChanged", "()V"); + /* + * Ignore notifications if the text hasn't been changed. + * EN_CHANGE sent on character formatting changes as well. + */ + if (m_bIgnoreEnChange == FALSE) { + m_bCanUndo = TRUE; + DoCallback("valueChanged", "()V"); + } else { + m_bCanUndo = FALSE; + } } return mrDoDefault; } @@ -337,6 +358,28 @@ { MsgRouting returnVal; + if (msg->message == WM_RBUTTONUP || + (msg->message == WM_SYSKEYDOWN && msg->wParam == VK_F10 && + HIBYTE(::GetKeyState(VK_SHIFT)))) { + POINT p; + if (msg->message == WM_RBUTTONUP) { + VERIFY(::GetCursorPos(&p)); + } else { + p.x = -1; + p.y = -1; + } + + if (!::PostMessage(GetHWnd(), WM_CONTEXTMENU, (WPARAM)GetHWnd(), + MAKELPARAM(p.x, p.y))) { + JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); + JNU_ThrowInternalError(env, "Message not posted, native event queue may be full."); + env->ExceptionDescribe(); + env->ExceptionClear(); + } + delete msg; + return mrConsume; + } + /* * Store the 'synthetic' parameter so that the WM_PASTE security check * happens only for synthetic events. @@ -701,6 +744,10 @@ SendMessage(EM_SETBKGNDCOLOR, (WPARAM)FALSE, (LPARAM)GetBackgroundColor()); } +void AwtTextComponent::EditGetSel(CHARRANGE &cr) { + SendMessage(EM_EXGETSEL, 0, reinterpret_cast(&cr)); +} + /************************************************************************ * WTextComponentPeer native methods @@ -982,6 +1029,161 @@ } +/* + * This routine is a window procedure for the subclass of the standard edit control + * used to generate context menu. RichEdit controls don't have built-in context menu. + * To implement this functionality we have to create an invisible edit control and + * forward WM_CONTEXTMENU messages from a RichEdit control to this helper edit control. + * While the edit control context menu is active we intercept the message generated in + * response to particular item selection and forward it back to the RichEdit control. + * (See AwtTextArea::WmContextMenu for more details). + */ + +WNDPROC AwtTextComponent::sm_pDefWindowProc = NULL; + +LRESULT +AwtTextComponent::EditProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { + + static BOOL bContextMenuActive = FALSE; + + LRESULT retValue = 0; + MsgRouting mr = mrDoDefault; + + DASSERT(::IsWindow(::GetParent(hWnd))); + + switch (message) { + case WM_UNDO: + case WM_CUT: + case WM_COPY: + case WM_PASTE: + case WM_CLEAR: + case EM_SETSEL: + if (bContextMenuActive) { + ::SendMessage(::GetParent(hWnd), message, wParam, lParam); + mr = mrConsume; + } + break; + case WM_CONTEXTMENU: + bContextMenuActive = TRUE; + break; + } + + if (mr == mrDoDefault) { + DASSERT(sm_pDefWindowProc != NULL); + retValue = ::CallWindowProc(sm_pDefWindowProc, + hWnd, message, wParam, lParam); + } + + if (message == WM_CONTEXTMENU) { + bContextMenuActive = FALSE; + } + + return retValue; +} + +MsgRouting +AwtTextComponent::WmContextMenu(HWND hCtrl, UINT xPos, UINT yPos) { + /* Use the system provided edit control class to generate context menu. */ + if (m_hEditCtrl == NULL) { + DWORD dwStyle = WS_CHILD; + DWORD dwExStyle = 0; + m_hEditCtrl = ::CreateWindowEx(dwExStyle, + L"EDIT", + L"TEXT", + dwStyle, + 0, 0, 0, 0, + GetHWnd(), + reinterpret_cast( + static_cast( + CreateControlID())), + AwtToolkit::GetInstance().GetModuleHandle(), + NULL); + DASSERT(m_hEditCtrl != NULL); + if (sm_pDefWindowProc == NULL) { + sm_pDefWindowProc = (WNDPROC)::GetWindowLongPtr(m_hEditCtrl, + GWLP_WNDPROC); + } + ::SetLastError(0); + INT_PTR ret = ::SetWindowLongPtr(m_hEditCtrl, GWLP_WNDPROC, + (INT_PTR)AwtTextArea::EditProc); + DASSERT(ret != 0 || ::GetLastError() == 0); + } + + /* + * Tricks on the edit control to ensure that its context menu has + * the correct set of enabled items according to the RichEdit state. + */ + ::SetWindowText(m_hEditCtrl, TEXT("TEXT")); + + if (m_bCanUndo == TRUE && SendMessage(EM_CANUNDO)) { + /* Enable 'Undo' item. */ + ::SendMessage(m_hEditCtrl, WM_CHAR, 'A', 0); + } + + { + /* + * Initial selection for the edit control - (0,1). + * This enables 'Cut', 'Copy' and 'Delete' and 'Select All'. + */ + INT nStart = 0; + INT nEnd = 1; + if (SendMessage(EM_SELECTIONTYPE) == SEL_EMPTY) { + /* + * RichEdit selection is empty - clear selection of the edit control. + * This disables 'Cut', 'Copy' and 'Delete'. + */ + nStart = -1; + nEnd = 0; + } else { + + CHARRANGE cr; + EditGetSel(cr); + /* Check if all the text is selected. */ + if (cr.cpMin == 0) { + + int len = ::GetWindowTextLength(GetHWnd()); + if (cr.cpMin == 0 && cr.cpMax >= len) { + /* + * All the text is selected in RichEdit - select all the + * text in the edit control. This disables 'Select All'. + */ + nStart = 0; + nEnd = -1; + } + } + } + ::SendMessage(m_hEditCtrl, EM_SETSEL, (WPARAM)nStart, (LPARAM)nEnd); + } + + /* Disable 'Paste' item if the RichEdit control is read-only. */ + ::SendMessage(m_hEditCtrl, EM_SETREADONLY, + GetStyle() & ES_READONLY ? TRUE : FALSE, 0); + + POINT p; + p.x = xPos; + p.y = yPos; + + /* + * If the context menu is requested with SHIFT+F10 or VK_APPS key, + * we position its top left corner to the center of the RichEdit + * client rect. + */ + if (p.x == -1 && p.y == -1) { + RECT r; + VERIFY(::GetClientRect(GetHWnd(), &r)); + p.x = (r.left + r.right) / 2; + p.y = (r.top + r.bottom) / 2; + VERIFY(::ClientToScreen(GetHWnd(), &p)); + } + + // The context menu steals focus from the proxy. + // So, set the focus-restore flag up. + SetRestoreFocus(TRUE); + ::SendMessage(m_hEditCtrl, WM_CONTEXTMENU, (WPARAM)m_hEditCtrl, MAKELPARAM(p.x, p.y)); + SetRestoreFocus(FALSE); + + return mrConsume; +} // // Accessibility support diff -r 2c00191a86c3 -r e975546b12ad src/windows/native/sun/windows/awt_TextComponent.h --- a/src/windows/native/sun/windows/awt_TextComponent.h Mon Sep 29 17:39:13 2014 +0100 +++ b/src/windows/native/sun/windows/awt_TextComponent.h Tue Sep 30 16:07:55 2014 +0100 @@ -48,6 +48,8 @@ static AwtTextComponent* Create(jobject self, jobject parent, BOOL isMultiline); + virtual void Dispose(); + virtual LPCTSTR GetClassName(); LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); @@ -84,6 +86,8 @@ MsgRouting HandleEvent(MSG *msg, BOOL synthetic); MsgRouting WmPaste(); + INLINE void SetIgnoreEnChange(BOOL b) { m_bIgnoreEnChange = b; } + virtual BOOL IsFocusingMouseMessage(MSG *pMsg); /* To be fully implemented in a future release @@ -116,11 +120,24 @@ INLINE VOID SetEndSelectionPos(LONG lPos) { m_lEndPos = lPos; } INLINE VOID SetLastSelectionPos(LONG lPos) { m_lLastPos = lPos; } + void EditGetSel(CHARRANGE &cr); + // Used to prevent untrusted code from synthesizing a WM_PASTE message // by posting a -V KeyEvent BOOL m_synthetic; LONG EditGetCharFromPos(POINT& pt); + // RichEdit 1.0 control generates EN_CHANGE notifications not only + // on text changes, but also on any character formatting change. + // This flag is true when the latter case is detected. + BOOL m_bIgnoreEnChange; + + // RichEdit 1.0 control undoes a character formatting change + // if it is the latest. We don't create our own undo buffer, + // but just prohibit undo in case if the latest operation + // is a formatting change. + BOOL m_bCanUndo; + /***************************************************************** * Inner class OleCallback declaration. */ @@ -167,6 +184,13 @@ static OleCallback sm_oleCallback; + static WNDPROC sm_pDefWindowProc; + HWND m_hEditCtrl; + + static LRESULT CALLBACK EditProc(HWND hWnd, UINT message, + WPARAM wParam, LPARAM lParam); + MsgRouting WmContextMenu(HWND hCtrl, UINT xPos, UINT yPos); + // // Accessibility support // diff -r 2c00191a86c3 -r e975546b12ad src/windows/native/sun/windows/awt_TextField.cpp --- a/src/windows/native/sun/windows/awt_TextField.cpp Mon Sep 29 17:39:13 2014 +0100 +++ b/src/windows/native/sun/windows/awt_TextField.cpp Tue Sep 30 16:07:55 2014 +0100 @@ -238,13 +238,8 @@ break; } } - /* - * Store the 'synthetic' parameter so that the WM_PASTE security check - * happens only for synthetic events. - */ - m_synthetic = synthetic; - returnVal = AwtComponent::HandleEvent(msg, synthetic); - m_synthetic = FALSE; + + returnVal = AwtTextComponent::HandleEvent(msg, synthetic); if(systemBeeperEnabled){ SystemParametersInfo(SPI_SETBEEP, 1, NULL, 0); diff -r 2c00191a86c3 -r e975546b12ad test/java/awt/MouseInfo/JContainerMousePositionTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/MouseInfo/JContainerMousePositionTest.java Tue Sep 30 16:07:55 2014 +0100 @@ -0,0 +1,162 @@ +/* + * 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(new Runnable() { + public void run() { + JContainerMousePositionTest.init(); + } + }); + + robot.delay(500); + robot.waitForIdle(); + + final AtomicReference centerC4 = new AtomicReference<>(); + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + centerC4.set(jButton4.getLocation()); + contentPane.remove(jButton4); + contentPane.validate(); + contentPane.repaint(); + } + }); + robot.waitForIdle(); + + final AtomicReference frameBounds = new AtomicReference<>(); + final AtomicReference button1Size = new AtomicReference<>(); + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + 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); + + final AtomicReference pFalse = new AtomicReference<>(); + final AtomicReference pTrue = new AtomicReference<>(); + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + 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(new Runnable() { + public void run() { + 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(new Runnable() { + public void run() { + 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); + } +} + +