1 /* 2 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 test 26 @bug 6299858 7124338 27 @summary PIT. Focused border not shown on List if selected item is removed, XToolkit 28 @author Dmitry.Cherepanov@SUN.COM area=awt.list 29 @run applet FirstItemRemoveTest.html 30 */ 31 32 import jdk.test.lib.Platform; 33 34 import java.applet.Applet; 35 import java.awt.*; 36 import java.awt.event.*; 37 38 public class FirstItemRemoveTest extends Applet 39 { 40 List list = new List(4, false); 41 Panel panel = new Panel(); 42 43 public void init() 44 { 45 list.add("000"); 46 list.add("111"); 47 list.add("222"); 48 list.add("333"); 49 list.add("444"); 50 list.add("555"); 51 52 panel.setLayout(new FlowLayout ()); 53 panel.add(list); 54 55 this.add(panel); 56 this.setLayout (new FlowLayout ()); 57 }//End init() 58 59 public void start () 60 { 61 setSize (200,200); 62 setVisible(true); 63 validate(); 64 65 test(); 66 }// start() 67 68 private void test(){ 69 70 if (Platform.isOSX()) { 71 System.err.println("Skipped. This test is not for OS X."); 72 return; 73 } 74 75 Robot r; 76 try { 77 r = new Robot(); 78 } catch(AWTException e) { 79 throw new RuntimeException(e.getMessage()); 80 } 81 82 // Removing first item in order to reproduce incorrect behaviour 83 r.delay(1000); 84 list.remove(0); 85 r.delay(1000); 86 87 // Request focus to list 88 Point loc = this.getLocationOnScreen(); 89 r.delay(1000); 90 91 r.mouseMove(loc.x+10, loc.y+10); 92 r.delay(10); 93 r.mousePress(InputEvent.BUTTON1_MASK); 94 r.delay(10); 95 r.mouseRelease(InputEvent.BUTTON1_MASK); 96 r.delay(1000); 97 98 list.requestFocusInWindow(); 99 r.delay(1000); 100 r.waitForIdle(); 101 if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != list){ 102 throw new RuntimeException("Test failed - list isn't focus owner."); 103 } 104 105 // The focus index should be set to first item after removing 106 // So if we press VK_SPACE then the selected item will be equals 0. 107 r.delay(100); 108 r.keyPress(KeyEvent.VK_SPACE); 109 r.delay(10); 110 r.keyRelease(KeyEvent.VK_SPACE); 111 r.delay(1000); 112 r.waitForIdle(); 113 114 int selectedIndex = list.getSelectedIndex(); 115 if (selectedIndex != 0){ 116 throw new RuntimeException("Test failed. list.getSelectedIndex() = "+selectedIndex); 117 } 118 119 } 120 121 }// class AutomaticAppletTest