/* * Copyright (c) 2011, 2012, 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 * @key headful * @bug 6462008 * @summary Tests that mouse/keyboard work properly on JList with lead < 0 or > list.getModel().getSize() * @author Shannon Hickey * @run main bug6462008
*/ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*;
// Control + Space
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyRelease(KeyEvent.VK_SPACE);
robot.keyRelease(KeyEvent.VK_CONTROL);
// Control + A Single Selection
robot.keyPress(controlKey);
robot.keyPress(KeyEvent.VK_A);
robot.keyRelease(KeyEvent.VK_A);
robot.keyRelease(controlKey);
// Shift + Page Down /* * We really want to use robot here, but there seems to be a bug in AWT's * robot implementation (see 6463168). For now, we'll invoke the action * directly instead. When the bug is fixed, we'll use the following four * lines instead: * robot.keyPress(KeyEvent.VK_SHIFT); * robot.keyPress(KeyEvent.VK_PAGE_DOWN); * robot.keyRelease(KeyEvent.VK_PAGE_DOWN); * robot.keyRelease(KeyEvent.VK_SHIFT);
*/
int actualAnchor = lsm.getAnchorSelectionIndex(); int actualLead = lsm.getLeadSelectionIndex();
if (anchor != DONT_CARE && actualAnchor != anchor) { thrownew RuntimeException("anchor is " + actualAnchor + ", should be " + anchor);
}
if (lead != DONT_CARE && actualLead != lead) { thrownew RuntimeException("lead is " + actualLead + ", should be " + lead);
}
Arrays.sort(sels); boolean[] checks = newboolean[list.getModel().getSize()]; for (int i : sels) {
checks[i] = true;
}
int index0 = Math.min(lsm.getMinSelectionIndex(), 0); int index1 = Math.max(lsm.getMaxSelectionIndex(), list.getModel().getSize() - 1);
for (int i = index0; i <= index1; i++) { if (lsm.isSelectedIndex(i)) { if (i < 0 || i >= list.getModel().getSize() || !checks[i]) { thrownew RuntimeException(i + " is selected when it should not be");
}
} elseif (i >= 0 && i < list.getModel().getSize() && checks[i]) { thrownew RuntimeException(i + " is supposed to be selected");
}
}
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.