--- /dev/null 2014-04-08 13:33:32.287183578 +0400 +++ new/test/java/awt/Frame/SetBounds/SetBounds.java 2014-04-10 14:45:43.653184227 +0400 @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2007, 2014, 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 javax.swing.*; +import java.applet.Applet; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.HashMap; +import java.util.Map; + +import static jdk.testlibrary.Asserts.*; + +/* + * @test 1.1 2001/05/14 + * @summary Checking Whether + * 1.When Frame.setExtendedStateBounds() is called for a + * Frame with state as Frame.NORMAL, the bounds of the + * Frame must be the same as what is specified when frame + * is in normal state. + * + * 2.When Frame.setExtendedStateBounds()is called for a + * Frame with state as Frame.MAXIMIZED_VERT,the bounds + * of the Frame must be the same as what is specified + * when frame is in vertically maximized state. + * + * 3.When Frame.setExtendedStateBounds()is called for a + * Frame with state as Frame.MAXIMIZED_HORZ,the bounds + * of the Frame must be the same as what is specified + * when frame is in horizontally maximized state. + * + * 4.When Frame.setExtendedStateBounds()is called for a + * Frame with state as Frame.MAXIMIZED_BOTH,the bounds + * of the Frame must be the same as what is specified + * when frame is in maximized state. + * + * @library ../../../../lib/testlibrary + * @build ExtendedRobot jdk.testlibrary.Asserts + * @run main SetBounds + */ + +public class SetBounds extends Applet implements ActionListener { + + Frame testFrame; + Button[] buttons = new Button[4]; + Map borders = new HashMap(); + { + borders.put("NORMAL", new Rectangle(50,50,350,350)); + borders.put("MAXIMIZED_HORIZ", new Rectangle(50,50,500,350)); + borders.put("MAXIMIZED_VERT", new Rectangle(50,50,350,500)); + borders.put("MAXIMIZED_BOTH", new Rectangle(50,50,600,600)); + } + Rectangle bound = null; + ExtendedRobot robot; + boolean flag = false; + boolean actionPerformed; + + public Point targetCenter(Component target) { + int w = target.getWidth(); + int h = target.getHeight(); + Point loc = target.getLocationOnScreen(); + loc.x += (w/2); + loc.y += (h/2); + return loc; + } + + public SetBounds() throws Exception { + // CONFIG: Do any other initialization here. + try { + robot = new ExtendedRobot(); + } catch (AWTException e) { + e.printStackTrace(); + } + + SwingUtilities.invokeAndWait(() -> { + testFrame = new Frame( "TestFrame "); + testFrame.setLayout(new FlowLayout()); + + buttons[0] = new Button("NORMAL"); + buttons[1] = new Button("BOTH"); + buttons[2] = new Button("HORIZ"); + buttons[3] = new Button("VERT"); + + for (Button button : buttons) { + button.addActionListener(this); + testFrame.add(button); + } + + testFrame.setSize(200, 200); + testFrame.setVisible(true); + }); + + robot.waitForIdle(); + + } + + String getKey(Button button){ + if (button.getLabel().equals("NORMAL")) { + return button.getLabel(); + } else { + return "MAXIMIZED_"+button.getLabel(); + } + } + + void verify(String state) throws Exception { + if(Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.class.getField(state).getInt(null)) ) { + testFrame.setBounds(borders.get(state)); + bound = testFrame.getBounds(); + } else { + flag = true; + System.out.println("Frame."+state+" not supported"); + } + actionPerformed = true; + } + public void actionPerformed(ActionEvent ae) { + try { + verify(getKey((Button) ae.getSource())); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void doTest() { + // CONFIG: Put here the code to exercise and verify the GUI. + + for (Button button : buttons) { + actionPerformed = false; + bound = null; + flag = false; + robot.mouseMove(targetCenter(button)); + robot.waitForIdle(); + robot.click(); + robot.waitForIdle(); + + assertTrue(actionPerformed, "'"+getKey(button)+"' button did not trigger action when clicked"); + + if (!flag) { + assertEquals(bound, borders.get(getKey(button)), + "The Bounds of the Frame is not same as what" + + " is specified when the frame is in Frame. "+getKey(button)+" state"); + } + } + } + + public static void main(String[] args) throws Exception { + new SetBounds().doTest(); + } +} --- /dev/null 2014-04-08 13:33:32.287183578 +0400 +++ new/test/java/awt/GridLayout/ChangeGridSize/ChangeGridSize.java 2014-04-10 14:45:44.053184220 +0400 @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2006, 2014, 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 javax.swing.*; +import java.awt.*; +import java.awt.event.InputEvent; +import static jdk.testlibrary.Asserts.assertTrue; + +/* + * @test + * @summary Have different components having different preferred sizes + * added to a grid layout. Change the rows and columns of the + * grid layout and check the components are re-laid out. + * The strategy followed is to calculate the component location + * depending on the preferred sizes and gaps and click the cornors + * of the components to check if events are triggered + * @library ../../../../lib/testlibrary/ + * @build ExtendedRobot jdk.testlibrary.Asserts + * @run main ChangeGridSize + * @run main ChangeGridSize -hg 20 -vg 20 + */ + +public class ChangeGridSize { + + private int hGap, vGap; + private int width = 200; + private int height = 200; + private int rows = 3; + private int columns = 2; + private int componentCount = 6; + + private JButton[] buttons; + private JFrame frame; + + private ExtendedRobot robot; + private GridLayout layout; + + private boolean actionPerformed = false; + + public ChangeGridSize(int hGap, int vGap) throws Exception { + this.hGap = hGap; + this.vGap = vGap; + robot = new ExtendedRobot(); + SwingUtilities.invokeAndWait( () -> { + frame = new JFrame("Test frame"); + frame.setSize(width, height); + layout = new GridLayout(rows + 3, columns - 1, hGap, vGap); + frame.getContentPane().setLayout(layout); + + buttons = new JButton[componentCount]; + for (int i = 0; i < componentCount; i++) { + buttons[i] = new JButton("Button" + i); + frame.getContentPane().add(buttons[i]); + buttons[i].addActionListener( (event) -> { actionPerformed = true; }); + } + + frame.setVisible(true); + }); + } + + public static void main(String[] args) throws Exception { + int hGap = 0; + int vGap = 0; + for (int i = 0; i < args.length; i++) { + switch (args[i]) { + case "-hg": + hGap = Integer.parseInt(args[++i]); + break; + case "-vg": + vGap = Integer.parseInt(args[++i]); + break; + } + } + new ChangeGridSize(hGap, vGap).doTest(); + } + + private void resizeFrame() throws Exception { + SwingUtilities.invokeAndWait( () -> { + double dH = (frame.getContentPane().getSize().getHeight() - vGap*(rows-1)) % rows; + height -= dH; + frame.setSize(width, height); + frame.getContentPane().revalidate(); + }); + robot.waitForIdle(); + } + + private void changeGridSize() throws Exception { + SwingUtilities.invokeAndWait(() -> { + layout.setRows(rows); + layout.setColumns(columns); + + frame.getContentPane().revalidate(); + }); + robot.waitForIdle(); + } + + public void testBoundaries(int topLeftX, int topLeftY, int bottomRightX, int bottomRightY) throws Exception { + + actionPerformed = false; + robot.mouseMove(topLeftX, topLeftY); + robot.delay(500); + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.delay(500); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + robot.delay(3000); + robot.waitForIdle(); + + assertTrue(actionPerformed, "Clicking on the left top of button did not trigger action event"); + + actionPerformed = false; + robot.mouseMove(bottomRightX, bottomRightY); + robot.delay(500); + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.delay(500); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + robot.delay(3000); + robot.waitForIdle(); + + assertTrue(actionPerformed, "Clicking on the bottom right of button did not trigger action event"); + } + + private void doTest() throws Exception { + robot.waitForIdle(); + changeGridSize(); + resizeFrame(); + + int availableWidth = width - frame.getInsets().left - + frame.getInsets().right; + int componentWidth = (availableWidth + hGap) / columns - hGap; + int availableHeight = height - frame.getInsets().top - + frame.getInsets().bottom; + int componentHeight = (availableHeight + vGap) / rows - vGap; + + for (int i = 0; i < buttons.length; i++) { + if (buttons[i].getSize().width != componentWidth || + buttons[i].getSize().height != componentHeight) { + throw new RuntimeException( + "FAIL: Button " + i + " not of proper size" + + "Expected: " + componentWidth + "*" + componentHeight + + "Actual: " + buttons[i].getSize().width + "*" + buttons[i].getSize().height); + } + } + + // Components are visible. They should trigger events. + // Now you can check for the actual size shown. + int currentRow = 1; + int currentColumn = 0; + for (int i = 0; i < buttons.length; i++) { + currentColumn++; + if (currentColumn > columns) { + currentColumn = 1; + currentRow++; + } + + int topPosX = frame.getLocationOnScreen().x + + frame.getInsets().left + + (currentColumn - 1) * (componentWidth + hGap); + int topPosY = frame.getLocationOnScreen().y + + frame.getInsets().top + + (currentRow - 1) * (componentHeight + vGap); + + int bottomPosX = topPosX + componentWidth - 1; + int bottomPosY = topPosY + componentHeight - 1; + testBoundaries(topPosX, topPosY, bottomPosX, bottomPosY); + } + } +} --- /dev/null 2014-04-08 13:33:32.287183578 +0400 +++ new/test/java/awt/GridLayout/ComponentPreferredSize/ComponentPreferredSize.java 2014-04-10 14:45:44.465184212 +0400 @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2006, 2014, 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 javax.swing.*; +import java.awt.*; +import java.awt.event.InputEvent; +import static jdk.testlibrary.Asserts.assertTrue; + +/* + * @test + * @summary Have different components having different preferred sizes + * added to a grid layout having various values of row/columns. + * Check if the compnents are correctly laid out. + * The strategy followed is to calculate the component location + * depending on the preferred sizes and gaps and click the cornors + * of the components to check if events are triggered + * @library ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @run main ComponentPreferredSize + * @run main ComponentPreferredSize -hg 20 -vg 20 + */ + +public class ComponentPreferredSize { + + private int hGap, vGap; + private int width = 200; + private int height = 200; + private int rows = 3; + private int columns = 2; + private int componentCount = 6; + + private JButton[] buttons; + private JFrame frame; + + private ExtendedRobot robot; + private GridLayout layout; + + private boolean actionPerformed = false; + + public ComponentPreferredSize(int hGap, int vGap) throws Exception { + this.hGap = hGap; + this.vGap = vGap; + robot = new ExtendedRobot(); + SwingUtilities.invokeAndWait( () -> { + frame = new JFrame("Test frame"); + frame.setSize(width, height); + layout = new GridLayout(rows, columns, hGap, vGap); + frame.getContentPane().setLayout(layout); + + buttons = new JButton[componentCount]; + for (int i = 0; i < componentCount; i++) { + buttons[i] = new JButton("Button" + i); + buttons[i].setPreferredSize(new Dimension((int) Math.random() * 100, + (int) Math.random() * 100)); + frame.getContentPane().add(buttons[i]); + buttons[i].addActionListener((event) -> {actionPerformed = true;}); + } + + frame.setVisible(true); + }); + } + + public static void main(String[] args) throws Exception { + int hGap = 0; + int vGap = 0; + for (int i = 0; i < args.length; i++) { + switch (args[i]) { + case "-hg": + hGap = Integer.parseInt(args[++i]); + break; + case "-vg": + vGap = Integer.parseInt(args[++i]); + break; + } + } + new ComponentPreferredSize(hGap, vGap).doTest(); + } + + private void resizeFrame() throws Exception { + SwingUtilities.invokeAndWait( () -> { + double dH = (frame.getContentPane().getSize().getHeight() - vGap*(rows-1)) % rows; + height -= dH; + frame.setSize(width, height); + frame.getContentPane().revalidate(); + }); + robot.waitForIdle(); + } + + public void testBoundaries(int topLeftX, int topLeftY, int bottomRightX, int bottomRightY) throws Exception { + + actionPerformed = false; + robot.mouseMove(topLeftX, topLeftY); + robot.delay(500); + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.delay(500); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + robot.delay(3000); + robot.waitForIdle(); + + assertTrue(actionPerformed, "Clicking on the left top of button did not trigger action event"); + + actionPerformed = false; + robot.mouseMove(bottomRightX, bottomRightY); + robot.delay(500); + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.delay(500); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + robot.delay(3000); + robot.waitForIdle(); + + assertTrue(actionPerformed, "Clicking on the bottom right of button did not trigger action event"); + } + + private void doTest() throws Exception { + robot.waitForIdle(); + resizeFrame(); + + int availableWidth = width - frame.getInsets().left - + frame.getInsets().right; + int componentWidth = (availableWidth + hGap) / columns - hGap; + int availableHeight = height - frame.getInsets().top - + frame.getInsets().bottom; + int componentHeight = (availableHeight + vGap) / rows - vGap; + + for (int i = 0; i < buttons.length; i++) { + if (buttons[i].getSize().width != componentWidth || + buttons[i].getSize().height != componentHeight) { + throw new RuntimeException( + "FAIL: Button " + i + " not of proper size" + + "Expected: " + componentWidth + "*" + componentHeight + + "Actual: " + buttons[i].getSize().width + "*" + buttons[i].getSize().height); + } + } + + // Components are visible. They should trigger events. + // Now you can check for the actual size shown. + int currentRow = 1; + int currentColumn = 0; + for (int i = 0; i < buttons.length; i++) { + currentColumn++; + if (currentColumn > columns) { + currentColumn = 1; + currentRow++; + } + + int topPosX = frame.getLocationOnScreen().x + + frame.getInsets().left + + (currentColumn - 1) * (componentWidth + hGap); + int topPosY = frame.getLocationOnScreen().y + + frame.getInsets().top + + (currentRow - 1) * (componentHeight + vGap); + + int bottomPosX = topPosX + componentWidth - 1; + int bottomPosY = topPosY + componentHeight - 1; + testBoundaries(topPosX, topPosY, bottomPosX, bottomPosY); + } + } +} --- /dev/null 2014-04-08 13:33:32.287183578 +0400 +++ new/test/java/awt/Robot/ModifierRobotKey/ModifierRobotKeyTest.java 2014-04-10 14:45:44.893184205 +0400 @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2007, 2014, 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 javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +import static sun.awt.OSInfo.*; +import static jdk.testlibrary.Asserts.assertTrue; + +/* + * @test + * @summary Make sure that modifier key mask is set when robot press + * some key with one or more modifiers. + * + * @library ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @run main ModifierRobotKeyTest + */ + +public class ModifierRobotKeyTest extends KeyAdapter { + + private boolean focusGained = false; + private boolean startTest = false; + private ExtendedRobot robot; + private Frame frame; + private Canvas canvas; + + private boolean tempPress = false; + + private int[] textKeys, modifierKeys, inputMasks; + private boolean[] modifierStatus, textStatus; + + public static void main(String[] args) throws Exception { + ModifierRobotKeyTest test = new ModifierRobotKeyTest(); + test.doTest(); + } + + public ModifierRobotKeyTest() throws Exception { + modifierKeys = new int[3]; + modifierKeys[0] = KeyEvent.VK_SHIFT; + modifierKeys[1] = KeyEvent.VK_CONTROL; + modifierKeys[2] = KeyEvent.VK_ALT; + + inputMasks = new int[3]; + inputMasks[0] = InputEvent.SHIFT_MASK; + inputMasks[1] = InputEvent.CTRL_MASK; + inputMasks[2] = InputEvent.ALT_MASK; + + modifierStatus = new boolean[modifierKeys.length]; + + textKeys = new int[2]; + textKeys[0] = KeyEvent.VK_A; + + switch (getOSType()) { + case SOLARIS: + textKeys[1] = KeyEvent.VK_S; + break; + case MACOSX: + textKeys[1] = KeyEvent.VK_K; + break; + default: + textKeys[1] = KeyEvent.VK_I; + break; + } + + textStatus = new boolean[textKeys.length]; + + SwingUtilities.invokeAndWait( () -> { initializeGUI(); }); + } + + public void keyPressed(KeyEvent event) { + + tempPress = true; + + if (! startTest) { + return; + } + for (int x = 0; x < inputMasks.length; x++) { + if ((event.getModifiers() & inputMasks[x]) != 0) { + System.out.println("Modifier set: " + event.getKeyModifiersText(inputMasks[x])); + modifierStatus[x] = true; + } + } + for (int x = 0; x < textKeys.length; x++) { + if (event.getKeyCode() == textKeys[x]) { + System.out.println("Text set: " + event.getKeyText(textKeys[x])); + textStatus[x] = true; + } + } + } + + private void initializeGUI() { + frame = new Frame("Test frame"); + canvas = new Canvas(); + canvas.addFocusListener(new FocusAdapter() { + public void focusGained(FocusEvent event) { focusGained = true; } + }); + canvas.addKeyListener(this); + frame.setLayout(new BorderLayout()); + frame.add(canvas); + frame.setSize(200, 200); + frame.setVisible(true); + } + + public void doTest() throws Exception { + robot = new ExtendedRobot(); + + robot.mouseMove((int) frame.getLocationOnScreen().getX() + frame.getSize().width / 2, + (int) frame.getLocationOnScreen().getY() + frame.getSize().height / 2); + robot.click(MouseEvent.BUTTON1_MASK); + robot.waitForIdle(); + + assertTrue(focusGained, "FAIL: Canvas failed to gain focus!"); + + for (int i = 0; i < modifierKeys.length; i++) { + for (int j = 0; j < textKeys.length; j++) { + tempPress = false; + robot.keyPress(modifierKeys[i]); + robot.waitForIdle(); + + assertTrue(tempPress, "FAIL: keyPressed not triggered for i=" + i); + + resetStatus(); + startTest = true; + robot.keyPress(textKeys[j]); + robot.waitForIdle(); + + assertTrue(modifierStatus[i] && textStatus[j], + "FAIL: KeyEvent not proper!"+ + "Key checked: i=" + i + "; j=" + j+ + "ModifierStatus = " + modifierStatus[i]+ + "TextStatus = " + textStatus[j]); + startTest = false; + robot.keyRelease(textKeys[j]); + robot.waitForIdle(); + robot.keyRelease(modifierKeys[i]); + robot.waitForIdle(); + } + } + + for (int i = 0; i < modifierKeys.length; i++) { + for (int j = i + 1; j < modifierKeys.length; j++) { + for (int k = 0; k < textKeys.length; k++) { + tempPress = false; + robot.keyPress(modifierKeys[i]); + robot.waitForIdle(); + assertTrue(tempPress, "FAIL: MultiKeyTest: keyPressed not triggered for i=" + i); + + tempPress = false; + robot.keyPress(modifierKeys[j]); + robot.waitForIdle(); + assertTrue(tempPress, "FAIL: MultiKeyTest keyPressed not triggered for j=" + j); + + resetStatus(); + startTest = true; + robot.keyPress(textKeys[k]); + robot.waitForIdle(); + + assertTrue(modifierStatus[i] && modifierStatus[j] && textStatus[k], + "FAIL: KeyEvent not proper!"+ + "Key checked: i=" + i + "; j=" + j + "; k=" + k+ + "Modifier1Status = " + modifierStatus[i]+ + "Modifier2Status = " + modifierStatus[j]+ + "TextStatus = " + textStatus[k]); + + startTest = false; + robot.keyRelease(textKeys[k]); + robot.waitForIdle(); + robot.keyRelease(modifierKeys[j]); + robot.waitForIdle(); + robot.keyRelease(modifierKeys[i]); + robot.waitForIdle(); + } + } + } + } + + private void resetStatus() { + for (int i = 0; i < modifierStatus.length; i++) { + modifierStatus[i] = false; + } + for (int i = 0; i < textStatus.length; i++) { + textStatus[i] = false; + } + } + +} --- /dev/null 2014-04-08 13:33:32.287183578 +0400 +++ new/test/java/awt/Toolkit/LockingKeyStateTest/LockingKeyStateTest.java 2014-04-10 14:45:45.321184197 +0400 @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2014, 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 javax.swing.*; +import java.awt.*; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; + +import static jdk.testlibrary.Asserts.assertTrue; + +/* + @test + @summary + @author Yuri.Nesterenko, Dmitriy.Ermashov + @library ../../../../lib/testlibrary + @build ExtendedRobot + @run main LockingKeyStateTest +*/ + +public class LockingKeyStateTest { + + Frame frame; + ExtendedRobot robot; + + // Note that Kana lock you may actually toggle only if you have one. + static int[] lockingKeys = { KeyEvent.VK_CAPS_LOCK, KeyEvent.VK_NUM_LOCK, + KeyEvent.VK_SCROLL_LOCK, KeyEvent.VK_KANA_LOCK }; + boolean[] getSupported = new boolean[lockingKeys.length]; + boolean[] setSupported = new boolean[lockingKeys.length]; + boolean[] state0 = new boolean[lockingKeys.length]; + + Toolkit toolkit = Toolkit.getDefaultToolkit(); + + LockingKeyStateTest() throws Exception { + robot = new ExtendedRobot(); + SwingUtilities.invokeAndWait(() -> { createGui(); }); + } + + void fillArrays() { + for(int i = 0; i < lockingKeys.length; i++) { + getSupported[i] = false; + setSupported[i] = false; + try { + state0[i] = toolkit.getLockingKeyState(lockingKeys[i]); + getSupported[i] = true; + toolkit.setLockingKeyState(lockingKeys[i], state0[i]); + setSupported[i] = true; + }catch(UnsupportedOperationException uoe) { + } + System.out.println(" State get/set of "+KeyEvent.getKeyText(lockingKeys[i])+" is supported? "+ + getSupported[i]+", "+setSupported[i]); + } + } + + void toggleAll(boolean b) { + for(int i = 0; i < lockingKeys.length; i++) { + if(setSupported[i]) { + toolkit.setLockingKeyState(lockingKeys[i], b); + } + } + } + + void checkAll(boolean b) { + for(int i = 0; i < lockingKeys.length; i++) { + if(getSupported[i] && setSupported[i]) { + assertTrue(toolkit.getLockingKeyState(lockingKeys[i]) == b, "Oops! State of "+KeyEvent.getKeyText(lockingKeys[i])+" is not "+b); + System.out.println("OK, state of "+KeyEvent.getKeyText(lockingKeys[i])+" is "+b); + } + } + } + + void restoreAll() { + for(int i = 0; i < lockingKeys.length; i++) { + if(setSupported[i] && getSupported[i]) { + toolkit.setLockingKeyState(lockingKeys[i], state0[i]); + } + } + } + + public void createGui() { + fillArrays(); + frame = new Frame("LockingKeyStateTest Title"); + // (KeyAdapter) keyPressed(ke) -> { + + frame.addKeyListener( new KeyAdapter() { + public void keyPressed(KeyEvent ke) { + switch(ke.getKeyCode()) { + case KeyEvent.VK_1 : + toggleAll(true); break; + case KeyEvent.VK_2 : + checkAll(true); break; + case KeyEvent.VK_3 : + toggleAll(false); break; + case KeyEvent.VK_4 : + checkAll(false); break; + case KeyEvent.VK_5 : + restoreAll(); break; + default:; + } + } + }); + frame.setSize(200,200); + frame.setVisible(true); + } + + void doTest(){ + robot.waitForIdle(); + robot.mouseMove(frame.getLocationOnScreen().x + frame.getWidth() / 2, + frame.getLocationOnScreen().y + frame.getHeight() / 2); + robot.click(); + + robot.type('1'); + robot.type('2'); + robot.type('3'); + robot.type('4'); + robot.type('5'); + robot.waitForIdle(); + + } + + public static void main(String argv[]) throws Exception { + LockingKeyStateTest af = new LockingKeyStateTest(); + af.doTest(); + + } +}