示例#1
0
  /** @@author A0125419H */
  private void addMainMenu(ArrayList<Pair<String, String>> mainMenuOptions) {
    int numCommmands = mainMenuOptions.size();
    int totalPages =
        (int)
            Math.ceil(
                numCommmands / 1.0 / UiConstants.ENTRIES_PER_PAGE_HELP_MENU); // convert to double
    int entryNo = 0;
    for (int i = 0; i < totalPages; i++) {
      GridPane newGrid = gridHelper.setUpGrid(UiConstants.GRID_SETTINGS_ACTION_HELP);
      ArrayList<StackPane> menuElements = new ArrayList<StackPane>();
      // newGrid.setGridLinesVisible(true);
      for (int j = 0; j < UiConstants.ENTRIES_PER_PAGE_HELP_MENU; j++) {
        if (entryNo >= numCommmands) {
          break;
        }
        String optionText = mainMenuOptions.get(entryNo).getKey();
        Label current =
            gridHelper.createLabelInCell(
                0, j, optionText, UiConstants.STYLE_PROMPT_SELECTED, newGrid);
        GridPane.setFillWidth(current.getParent(), false);
        GridPane.setFillHeight(current.getParent(), false);
        GridPane.setHalignment(current.getParent(), HPos.CENTER);
        if (entryNo > 0) {
          menuElements.add(gridHelper.getWrapperAtCell(0, j, newGrid));
        }
        UiTextBuilder myBuilder = new UiTextBuilder();
        myBuilder.addMarker(0, UiConstants.STYLE_PROMPT_SELECTED);

        String descriptionText = mainMenuOptions.get(entryNo).getValue();
        gridHelper.createStyledCell(1, j, "", newGrid);
        gridHelper.addTextFlowToCell(
            1, j, myBuilder.build(descriptionText), TextAlignment.LEFT, newGrid);
        GridPane.setHalignment(current.getParent(), HPos.CENTER);
        entryNo++;
      }
      helpView.addGridToPagination(newGrid, menuElements);
    }
    helpView.initializeDisplay(totalPages); // update UI and bind call back
  }