@Ignore @Test public void setCurrentPageIndexAndNavigateWithMouse() { pagination.setPageCount(25); pagination.setPageFactory( new Callback<Integer, Node>() { @Override public Node call(Integer pageIndex) { Node n = createPage(pageIndex); return n; } }); root.setPrefSize(400, 400); root.getChildren().add(pagination); show(); root.impl_reapplyCSS(); root.layout(); tk.firePulse(); assertTrue(pagination.isFocused()); double xval = (pagination.localToScene(pagination.getLayoutBounds())).getMinX(); double yval = (pagination.localToScene(pagination.getLayoutBounds())).getMinY(); scene.impl_processMouseEvent( MouseEventGenerator.generateMouseEvent(MouseEvent.MOUSE_PRESSED, xval + 170, yval + 380)); tk.firePulse(); assertEquals(3, pagination.getCurrentPageIndex()); }
/** * ****************************************************************** Miscellaneous Tests * * ****************************************************************** */ @Test public void setCurrentPageIndexAndNavigateWithKeyBoard() { pagination.setPageCount(25); pagination.setPageFactory( new Callback<Integer, Node>() { @Override public Node call(Integer pageIndex) { Node n = createPage(pageIndex); return n; } }); root.setPrefSize(400, 400); root.getChildren().add(pagination); show(); tk.firePulse(); assertTrue(pagination.isFocused()); KeyEventFirer keyboard = new KeyEventFirer(pagination); keyboard.doRightArrowPress(); tk.firePulse(); assertEquals(1, pagination.getCurrentPageIndex()); keyboard.doRightArrowPress(); tk.firePulse(); assertEquals(2, pagination.getCurrentPageIndex()); }
@Test public void setMaxPageIndicatorCountGreaterThanPageCount() { pagination.setPageCount(100); root.setPrefSize(400, 400); root.getChildren().add(pagination); show(); pagination.setMaxPageIndicatorCount(101); assertEquals(10, pagination.getMaxPageIndicatorCount()); }
@Test public void setCountToZero() { pagination.setPageCount(0); root.setPrefSize(400, 400); root.getChildren().add(pagination); show(); assertEquals(Integer.MAX_VALUE, pagination.getPageCount()); }
@Test public void setCurrentPageIndexGreaterThanPageCount() { pagination.setPageCount(100); root.setPrefSize(400, 400); root.getChildren().add(pagination); show(); pagination.setCurrentPageIndex(5); pagination.setCurrentPageIndex(100); assertEquals(99, pagination.getCurrentPageIndex()); }
@Test public void setCurrentPageIndexLessThanZero() { pagination.setPageCount(100); root.setPrefSize(400, 400); root.getChildren().add(pagination); show(); pagination.setCurrentPageIndex(5); pagination.setCurrentPageIndex(-1); assertEquals(0, pagination.getCurrentPageIndex()); }
@Test public void pageCountIsLessThanMaxPageIndicatorCount_RT21660() { pagination.setPageCount(5); root.setPrefSize(400, 400); root.getChildren().add(pagination); show(); pagination.setCurrentPageIndex(4); tk.firePulse(); assertTrue(pagination.isFocused()); KeyEventFirer keyboard = new KeyEventFirer(pagination); keyboard.doRightArrowPress(); tk.firePulse(); assertEquals(4, pagination.getCurrentPageIndex()); }
@Test public void setCurrentPageIndexAndVerifyCallback() { pagination.setPageCount(25); pagination.setPageFactory( new Callback<Integer, Node>() { @Override public Node call(Integer pageIndex) { Node n = createPage(pageIndex); assertTrue(pageIndex == 0 || pageIndex == 4); return n; } }); root.setPrefSize(400, 400); root.getChildren().add(pagination); show(); pagination.setCurrentPageIndex(4); }
/** リザルト画面を生成する。 */ public ResultScreen() { // スペースキー押下時にタイトル画面に切り替えるようにする。 setOnKeyTyped( event -> { // KeyTyped イベントの場合は KeyCode を得られないので,Character で判定する。 if (event.getCharacter().equals(" ")) { Main.changeScreen(0); } }); setFocusTraversable(true); // ゲーム情報の最終値を取得する。 long score = GameContext.getScore(); long lifeBonus = GameContext.getLifeCount() * Configuration.SCORE_PER_LIFE; GameContext.addScore(lifeBonus); long totalScore = GameContext.getScore(); // ランクを計算する。 String rank; if (totalScore >= Configuration.SCORE_BORDER_OF_RANK_S) { rank = "S"; } else if (totalScore >= Configuration.SCORE_BORDER_OF_RANK_A) { rank = "A"; } else if (totalScore >= Configuration.SCORE_BORDER_OF_RANK_B) { rank = "B"; } else if (totalScore >= Configuration.SCORE_BORDER_OF_RANK_C) { rank = "C"; } else if (totalScore >= Configuration.SCORE_BORDER_OF_RANK_D) { rank = "D"; } else { rank = "E"; } // 画面に表示するテキストを生成する。 Text resultCaptionText = createText("CONGRATULATION!!", 100, Color.GREENYELLOW); Text scoreCaptionText = createText("SCORE", 50, Color.GREENYELLOW); Text scoreText = createText(Long.toString(score), "monospace", 50, Color.GREENYELLOW); Text lifeBonusCaptionText = createText("LIFE BONUS", 50, Color.GREENYELLOW); Text lifeBonusText = createText(Long.toString(lifeBonus), "monospace", 50, Color.GREENYELLOW); Text totalScoreCaptionText = createText("TOTAL SCORE", 50, Color.GREENYELLOW); Text totalScoreText = createText(Long.toString(totalScore), "monospace", 50, Color.GREENYELLOW); Text rankCaptionText = createText("RANK", 50, Color.GREENYELLOW); Text rankText = createText(rank, 50, Color.GREENYELLOW); // 区切り線を生成する。 VBox[] partitionPanes = new VBox[3]; IntStream.range(0, partitionPanes.length) .forEach( i -> { partitionPanes[i] = new VBox(); partitionPanes[i].setPrefHeight(Configuration.PARTITION_HEIGHT); partitionPanes[i].setStyle("-fx-background-color: greenyellow;"); }); // テキスト,および区切り線をグリッドペインに配置する。 GridPane gridPane = new GridPane(); GridPane.setHalignment(resultCaptionText, HPos.CENTER); GridPane.setHalignment(scoreText, HPos.RIGHT); GridPane.setHalignment(lifeBonusText, HPos.RIGHT); GridPane.setHalignment(totalScoreText, HPos.RIGHT); GridPane.setHalignment(rankText, HPos.CENTER); GridPane.setHgrow(scoreCaptionText, Priority.ALWAYS); gridPane.add(resultCaptionText, 0, 0, 2, 1); gridPane.add(partitionPanes[0], 0, 1, 2, 1); gridPane.add(scoreCaptionText, 0, 2); gridPane.add(scoreText, 1, 2); gridPane.add(lifeBonusCaptionText, 0, 3); gridPane.add(lifeBonusText, 1, 3); gridPane.add(partitionPanes[1], 0, 4, 2, 1); gridPane.add(totalScoreCaptionText, 0, 5); gridPane.add(totalScoreText, 1, 5); gridPane.add(rankCaptionText, 0, 6); gridPane.add(rankText, 1, 6); gridPane.add(partitionPanes[2], 0, 7, 2, 1); // グリッドペインをスタックペインに配置する。 // こうすることで,グリッドペインが画面の中央に配置される。 StackPane stackPane = new StackPane(new Group(gridPane)); stackPane.setPrefSize(Configuration.SCREEN_WIDTH, Configuration.SCREEN_HEIGHT); stackPane.setStyle("-fx-background-color: black;"); // 画面にスタックペインを配置する。 getChildren().add(stackPane); }