Esempio n. 1
-1
  @Override
  public void start(Stage primaryStage) {
    primaryStage.setTitle("JavaFX layouts samples");

    Tab hboxTab = new Tab();
    hboxTab.setText("HBox");
    hboxTab.setClosable(false);
    hboxLayout.setBackground(createBackground(Color.LIGHTGREEN));
    hboxTab.setContent(hboxLayout);

    Tab vboxTab = new Tab();
    vboxTab.setText("VBox");
    vboxTab.setClosable(false);
    vboxLayout.setBackground(createBackground(Color.ORANGE));
    vboxTab.setContent(vboxLayout);

    Tab flowPaneTab = new Tab();
    flowPaneTab.setText("FlowPane");
    flowPaneTab.setClosable(false);
    flowLayout.setBackground(createBackground(Color.LIGHTSKYBLUE));
    flowPaneTab.setContent(flowLayout);

    Tab gridPaneTab = new Tab("GridPane");
    gridPaneTab.setClosable(false);
    gridLayout.setBackground(createBackground(Color.LIGHTCORAL));
    gridLayout.setGridLinesVisible(true);
    gridPaneTab.setContent(gridLayout);

    Tab borderPaneTab = new Tab();
    borderPaneTab.setText("BorderPane");
    borderPaneTab.setClosable(false);
    borderLayout.setBackground(createBackground(Color.LIGHTYELLOW));
    borderPaneTab.setContent(borderLayout);

    Tab stackPaneTab = new Tab();
    stackPaneTab.setText("StackPane");
    stackPaneTab.setClosable(false);
    stackLayout.setBackground(createBackground(Color.YELLOW));
    stackPaneTab.setContent(stackLayout);

    Tab tilePaneTab = new Tab("TilePane");
    tilePaneTab.setClosable(false);
    tileLayout.setBackground(createBackground(Color.LIGHTGOLDENRODYELLOW));
    tilePaneTab.setContent(tileLayout);

    updateChildren(false);
    TabPane tabPane = new TabPane();
    tabPane
        .getTabs()
        .addAll(
            hboxTab, vboxTab, flowPaneTab, gridPaneTab, borderPaneTab, stackPaneTab, tilePaneTab);

    VBox optionsPanel = new VBox();
    CheckBox componentType = new CheckBox("Use Buttons instead of Rectangles");
    componentType
        .selectedProperty()
        .addListener((observable, oldValue, newValue) -> updateChildren(newValue));
    optionsPanel.getChildren().add(componentType);
    optionsPanel.setPadding(new Insets(10));

    BorderPane mainLayout = new BorderPane();
    mainLayout.setCenter(tabPane);
    mainLayout.setLeft(optionsPanel);

    // show the generated scene graph
    Scene scene = new Scene(mainLayout);
    primaryStage.setScene(scene);
    primaryStage.show();
  }
Esempio n. 2
-1
  public GameController() {
    logger.debug("Instantiating model");
    board = new Board();

    logger.debug("Instantiating views");
    boardView = new BoardView(Block.COUNT);

    // instantiate click event handler only one time to save instantiation time
    EventHandler<MouseEvent> onCellViewClicked =
        new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent event) {
            boardView.requestFocus();
            CellView cellView = (CellView) event.getSource();
            moveFocusTo(cellView.row, cellView.col);
          }
        };

    // apply click event handler to all cells
    board.forEach(cell -> boardView.getCellView(cell).setOnMouseClicked(onCellViewClicked));

    // apply key press handler to the board (not each individual cell)
    boardView.setOnKeyPressed(this);

    // instantiate timer
    timer = new TimerWidget();

    // init check box for toggling hint mode
    hintMode = new CheckBox("Pencil (SHIFT)");
    hintMode.setFocusTraversable(false);
    autoMode = new CheckBox("Automation");
    autoMode.setFocusTraversable(false);
    autoMode.setSelected(true);
    remainMode = new CheckBox("Show remaining sum");
    remainMode.setFocusTraversable(false);
    remainMode.setSelected(true);

    // listener for hint mode and remain mode
    hintMode
        .selectedProperty()
        .addListener(
            new ChangeListener<Boolean>() {
              @Override
              public void changed(
                  ObservableValue<? extends Boolean> observable,
                  Boolean oldValue,
                  Boolean newValue) {
                if (newValue) {
                  boardView.setHintsCursor();
                } else {
                  boardView.setValueCursor();
                }
              }
            });

    remainMode
        .selectedProperty()
        .addListener(
            new ChangeListener<Boolean>() {
              @Override
              public void changed(
                  ObservableValue<? extends Boolean> observable,
                  Boolean oldValue,
                  Boolean newValue) {
                toggleGroupSumMode(newValue);
              }
            });

    VBox controlBox = new VBox(hintMode, autoMode, remainMode);
    controlBox.setPadding(new Insets(0, 10, 0, 50));
    controlBox.setSpacing(4);

    // init combination list view
    combinationView = new CombinationView();

    // init combinator view
    combinator = new CombinatorWidget();

    // organize all components in grid style
    view = new GridPane();
    view.setBackground(BackgroundFactory.create(Color.rgb(200, 230, 200)));
    view.add(boardView, 0, 0);
    controlPanel = new VBox(timer, controlBox, combinationView, combinator);
    controlPanel.setAlignment(Pos.TOP_CENTER);
    view.add(controlPanel, 1, 0);
  }