18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javafx.scene.control;
27
28 import com.sun.javafx.scene.control.behavior.TreeCellBehavior;
29 import com.sun.javafx.scene.control.behavior.TreeCellBehavior;
30 import javafx.collections.FXCollections;
31 import javafx.collections.ListChangeListener;
32 import javafx.collections.ObservableList;
33 import javafx.scene.input.KeyCode;
34 import java.util.List;
35 import com.sun.javafx.PlatformUtil;
36 import com.sun.javafx.util.Utils;
37 import com.sun.javafx.scene.control.behavior.TreeViewAnchorRetriever;
38 import com.sun.javafx.scene.control.infrastructure.KeyEventFirer;
39 import com.sun.javafx.scene.control.infrastructure.KeyModifier;
40 import com.sun.javafx.scene.control.infrastructure.StageLoader;
41 import com.sun.javafx.scene.control.infrastructure.VirtualFlowTestUtils;
42 import com.sun.javafx.tk.Toolkit;
43 import org.junit.After;
44 import org.junit.Before;
45 import org.junit.Ignore;
46 import org.junit.Test;
47 import static org.junit.Assert.assertEquals;
48 import static org.junit.Assert.assertFalse;
49 import static org.junit.Assert.assertNotNull;
50 import static org.junit.Assert.assertNotSame;
51 import static org.junit.Assert.assertNull;
52 import static org.junit.Assert.assertTrue;
53 import static org.junit.Assert.fail;
54
55 public class TreeViewKeyInputTest {
56 private TreeView<String> treeView;
57 private MultipleSelectionModel<TreeItem<String>> sm;
2175 sm.setSelectionMode(SelectionMode.SINGLE);
2176
2177 sm.clearAndSelect(5);
2178 assertEquals(5, getAnchor());
2179 assertTrue(fm.isFocused(5));
2180 assertTrue(sm.isSelected(5));
2181
2182 sm.selectedIndexProperty().addListener(observable -> {
2183 // we expect only one selected index change event, from 5 to 4
2184 assertEquals(4, sm.getSelectedIndex());
2185 });
2186
2187 keyboard.doKeyPress(KeyCode.UP);
2188 assertEquals(4, getAnchor());
2189 assertTrue(fm.isFocused(4));
2190 assertTrue(sm.isSelected(4));
2191 assertFalse(sm.isSelected(5));
2192 }
2193
2194 @Test public void test_rt36800() {
2195 // get the current exception handler before replacing with our own,
2196 // as ListListenerHelp intercepts the exception otherwise
2197 final Thread.UncaughtExceptionHandler exceptionHandler = Thread.currentThread().getUncaughtExceptionHandler();
2198 Thread.currentThread().setUncaughtExceptionHandler((t, e) -> fail("We don't expect any exceptions in this test!"));
2199
2200 final int items = 10;
2201 root.getChildren().clear();
2202 root.setExpanded(true);
2203 for (int i = 0; i < items; i++) {
2204 root.getChildren().add(new TreeItem<>("Row " + i));
2205 }
2206
2207 sm.setSelectionMode(SelectionMode.SINGLE);
2208
2209 sm.clearAndSelect(5);
2210 assertEquals(5, getAnchor());
2211 assertTrue(fm.isFocused(5));
2212 assertTrue(sm.isSelected(5));
2213
2214 keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 4
2215 keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 3
2216 keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 2
2217 keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 1
2218 keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 0
2219 keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // bug time?
2220
2221 assertEquals(0, getAnchor());
2222 assertTrue(fm.isFocused(0));
2223 assertTrue(sm.isSelected(0));
2224 assertFalse(sm.isSelected(1));
2225 assertFalse(sm.isSelected(2));
2226 assertFalse(sm.isSelected(3));
2227 assertFalse(sm.isSelected(4));
2228 assertFalse(sm.isSelected(5));
2229
2230 // reset the exception handler
2231 Thread.currentThread().setUncaughtExceptionHandler(exceptionHandler);
2232 }
2233
2234 @Test public void test_rt_37130_pageUpAtTop() {
2235 final int items = 100;
2236 root.getChildren().clear();
2237 root.setExpanded(true);
2238 for (int i = 0; i < items; i++) {
2239 root.getChildren().add(new TreeItem<>("Row " + i));
2240 }
2241
2242 sm.setSelectionMode(SelectionMode.MULTIPLE);
2243
2244 StageLoader sl = new StageLoader(treeView);
2245
2246 sm.select(5);
2247 keyboard.doKeyPress(KeyCode.PAGE_UP, KeyModifier.SHIFT);
2248 keyboard.doKeyPress(KeyCode.PAGE_UP, KeyModifier.SHIFT);
2249
2250 sl.dispose();
2251 }
|
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javafx.scene.control;
27
28 import com.sun.javafx.scene.control.behavior.TreeCellBehavior;
29 import com.sun.javafx.scene.control.behavior.TreeCellBehavior;
30 import javafx.collections.FXCollections;
31 import javafx.collections.ListChangeListener;
32 import javafx.collections.ObservableList;
33 import javafx.scene.input.KeyCode;
34 import java.util.List;
35 import com.sun.javafx.PlatformUtil;
36 import com.sun.javafx.util.Utils;
37 import com.sun.javafx.scene.control.behavior.TreeViewAnchorRetriever;
38 import com.sun.javafx.scene.control.infrastructure.ControlTestUtils;
39 import com.sun.javafx.scene.control.infrastructure.KeyEventFirer;
40 import com.sun.javafx.scene.control.infrastructure.KeyModifier;
41 import com.sun.javafx.scene.control.infrastructure.StageLoader;
42 import com.sun.javafx.scene.control.infrastructure.VirtualFlowTestUtils;
43 import com.sun.javafx.tk.Toolkit;
44 import org.junit.After;
45 import org.junit.Before;
46 import org.junit.Ignore;
47 import org.junit.Test;
48 import static org.junit.Assert.assertEquals;
49 import static org.junit.Assert.assertFalse;
50 import static org.junit.Assert.assertNotNull;
51 import static org.junit.Assert.assertNotSame;
52 import static org.junit.Assert.assertNull;
53 import static org.junit.Assert.assertTrue;
54 import static org.junit.Assert.fail;
55
56 public class TreeViewKeyInputTest {
57 private TreeView<String> treeView;
58 private MultipleSelectionModel<TreeItem<String>> sm;
2176 sm.setSelectionMode(SelectionMode.SINGLE);
2177
2178 sm.clearAndSelect(5);
2179 assertEquals(5, getAnchor());
2180 assertTrue(fm.isFocused(5));
2181 assertTrue(sm.isSelected(5));
2182
2183 sm.selectedIndexProperty().addListener(observable -> {
2184 // we expect only one selected index change event, from 5 to 4
2185 assertEquals(4, sm.getSelectedIndex());
2186 });
2187
2188 keyboard.doKeyPress(KeyCode.UP);
2189 assertEquals(4, getAnchor());
2190 assertTrue(fm.isFocused(4));
2191 assertTrue(sm.isSelected(4));
2192 assertFalse(sm.isSelected(5));
2193 }
2194
2195 @Test public void test_rt36800() {
2196 final int items = 10;
2197 root.getChildren().clear();
2198 root.setExpanded(true);
2199 for (int i = 0; i < items; i++) {
2200 root.getChildren().add(new TreeItem<>("Row " + i));
2201 }
2202
2203 sm.setSelectionMode(SelectionMode.SINGLE);
2204
2205 sm.clearAndSelect(5);
2206 assertEquals(5, getAnchor());
2207 assertTrue(fm.isFocused(5));
2208 assertTrue(sm.isSelected(5));
2209
2210 keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 4
2211 keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 3
2212 keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 2
2213 keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 1
2214 keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 0
2215
2216 final Thread.UncaughtExceptionHandler exceptionHandler = ControlTestUtils.setHandler();
2217 try {
2218 keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // bug time?
2219 } finally {
2220 ControlTestUtils.resetHandler(exceptionHandler);
2221 }
2222
2223 assertEquals(0, getAnchor());
2224 assertTrue(fm.isFocused(0));
2225 assertTrue(sm.isSelected(0));
2226 assertFalse(sm.isSelected(1));
2227 assertFalse(sm.isSelected(2));
2228 assertFalse(sm.isSelected(3));
2229 assertFalse(sm.isSelected(4));
2230 assertFalse(sm.isSelected(5));
2231 }
2232
2233 @Test public void test_rt_37130_pageUpAtTop() {
2234 final int items = 100;
2235 root.getChildren().clear();
2236 root.setExpanded(true);
2237 for (int i = 0; i < items; i++) {
2238 root.getChildren().add(new TreeItem<>("Row " + i));
2239 }
2240
2241 sm.setSelectionMode(SelectionMode.MULTIPLE);
2242
2243 StageLoader sl = new StageLoader(treeView);
2244
2245 sm.select(5);
2246 keyboard.doKeyPress(KeyCode.PAGE_UP, KeyModifier.SHIFT);
2247 keyboard.doKeyPress(KeyCode.PAGE_UP, KeyModifier.SHIFT);
2248
2249 sl.dispose();
2250 }
|