public DrawerLayout() {
    AnchorPane.setTopAnchor(toggleLayer, 0d);
    AnchorPane.setRightAnchor(toggleLayer, 0d);
    AnchorPane.setBottomAnchor(toggleLayer, 0d);
    AnchorPane.setLeftAnchor(toggleLayer, 0d);
    toggleLayer.setBackground(
        new Background(new BackgroundFill(Color.BLACK, new CornerRadii(0d), new Insets(0))));
    toggleLayer.setOpacity(0);
    toggleLayer.setVisible(false);

    toggleLayer.setOnMouseClicked(
        evt -> {
          if (evt.getButton().equals(MouseButton.PRIMARY)) {
            if (drawerOpened) {
              closeDrawer();
            }
          }
        });

    tableScreen.bind(widthProperty().lessThan(responsiveWidth).or(responsiveWidth.isEqualTo(0)));
    tableScreen.addListener(
        (observable, oldValue, newValue) -> {
          responsiveBehavior(newValue);
        });
  }
  @Test
  public void testComputeChildPrefAreaHeightHonorsMinWidthOverMax() {
    Pane pane = new Pane(); // Region extension which makes children sequence public

    MockRegion child = new MockRegion(10, 20, 200, 300, 500, 500);
    child.setMinHeight(600); // max less than pref
    pane.getChildren().add(child);

    assertEquals(600, pane.computeChildPrefAreaHeight(child, Insets.EMPTY), 1e-100);
  }
Ejemplo n.º 3
0
  public void start(Stage primaryStage) {

    // Creates the pane and font objects to be used, as well as a string for the chars.
    Pane paneOne = new Pane();
    Font mainFont = Font.font("Times New Roman", FontWeight.BOLD, FontPosture.REGULAR, 35);
    String text = "Welcome to Java ";

    // Makes a point in the very center of the 600x600 scene, a double for distance
    // from the center, and one for the starting rotation of the first character.
    double centerX = 300;
    double centerY = 300;
    double distance = 200;
    double rotation = 90;

    for (int i = 0; i < text.length(); i++) {
      /**
       * To make the positions work correctly, I treat the characters as elements on a unit circle.
       * I find the angle by multiplying 2 * pi by i, then dividing that by the length of the text.
       * Next, I find the A. cos and B. sin of the angle, and multiply that by the distance from the
       * center to find the change in X and Y respectively. Finally, the X and Y for the current
       * character are found by adding the change in X and Y to the center X and Y.
       */
      double unitCircleAngle = (2 * Math.PI * i) / text.length();
      double deltaX = distance * Math.cos(unitCircleAngle);
      double deltaY = distance * Math.sin(unitCircleAngle);
      double currentX = centerX + deltaX;
      double currentY = centerY + deltaY;

      // I make a string of the char at index i by finding the charAt, then using the
      // Character.toString
      // method to cast it a string; then I make a Text object using the current X and Y and the
      // current
      // character. I set the font, and current rotation of the character. Finally, I add 22.5 to
      // the rotation
      // to ensure that it is at the appropriate rotation for the next character.
      String tempChar = Character.toString(text.charAt(i));
      ;
      Text tempText = new Text(currentX, currentY, tempChar);

      tempText.setFont(mainFont);
      tempText.setRotate(rotation);

      paneOne.getChildren().add(tempText);
      rotation = rotation + 22.5;
    }

    // I make a scene of the appropriate size using the pane with the characters, set the stage
    // title, add the
    // scene to the stage, and show it.
    Scene sceneOne = new Scene(paneOne, 600, 600);
    primaryStage.setTitle("Characters Around A Circle");
    primaryStage.setScene(sceneOne);
    primaryStage.show();
  }
 private void responsiveBehavior(boolean tabletScreen) {
   if (content != null && nav != null) {
     if (tabletScreen) {
       AnchorPane.setLeftAnchor(content, 0d);
       nav.setTranslateX(-DEFAULT_WIDTH_NAV);
     } else {
       AnchorPane.setLeftAnchor(content, DEFAULT_WIDTH_NAV);
       nav.setTranslateX(0);
       toggleLayer.setVisible(false);
       drawerOpened = false;
     }
   }
 }
  @Test
  public void testLayoutInAreaWithLargerMin() {
    Pane pane = new Pane(); // Region extension which makes children sequence public

    MockResizable child = new MockResizable(10, 20, 30, 40, 50, 60);
    pane.getChildren().add(child);

    pane.layoutInArea(child, 10, 10, 5, 5, 0, HPos.CENTER, VPos.CENTER);

    assertEquals(10, child.getWidth(), 1e-100);
    assertEquals(20, child.getHeight(), 1e-100);
    assertEquals(8, child.getLayoutX(), 1e-100);
    assertEquals(3, child.getLayoutY(), 1e-100);
  }
  public GroupChatNickEditFrame(final XmppAccountRoot xmppAccountRoot, final XmppItem xmppItem) {
    super(MidletMain.screen);
    /** Accepting variables * */
    this.xmppAccountRoot = xmppAccountRoot;
    this.xmppItem = xmppItem;
    /** Header * */
    header = new Header(Localization.getMessage("GROUP_CHAT_NICK_EDIT"));
    /** Soft * */
    soft = new Soft(MidletMain.screen);
    /** Left soft items * */
    soft.leftSoft =
        new PopupItem(Localization.getMessage("BACK")) {

          public void actionPerformed() {
            MidletMain.screen.setActiveWindow(s_prevWindow);
          }
        };
    /** Right soft items * */
    soft.rightSoft =
        new PopupItem(Localization.getMessage("APPLY")) {

          public void actionPerformed() {
            try {
              XmppSender.sendPresence(
                  xmppAccountRoot.xmppSession.xmlWriter,
                  null,
                  xmppItem.userId.concat("/").concat(nickField.getText()),
                  null,
                  XmppStatusUtil.getStatusDescr(xmppAccountRoot.statusIndex),
                  null,
                  5,
                  false,
                  null,
                  null);
              xmppItem.groupChatNick = nickField.getText();
            } catch (IOException ex) {
            }
            MidletMain.screen.setActiveWindow(s_prevWindow);
          }
        };
    /** Pane * */
    Pane pane = new Pane(null, false);
    pane.addItem(new Label(Localization.getMessage("NICK_NAME")));
    nickField = new Field(xmppItem.groupChatNick);
    nickField.setFocusable(true);
    nickField.setFocused(true);
    pane.addItem(nickField);
    /** Setting GObject * */
    setGObject(pane);
  }
  @Test
  public void testPositionInAreaForResizableBottomCenter() {
    Pane pane = new Pane(); // Region extension which makes children sequence public

    MockResizable child = new MockResizable(10, 20, 30, 40, 50, 60);
    pane.getChildren().add(child);

    child.autosize();
    pane.positionInArea(child, 10, 10, 100, 100, 0, HPos.CENTER, VPos.BOTTOM);

    assertEquals(30, child.getWidth(), 1e-100);
    assertEquals(40, child.getHeight(), 1e-100);
    assertEquals(45, child.getLayoutX(), 1e-100);
    assertEquals(70, child.getLayoutY(), 1e-100);
  }
  @Test
  public void testPositionInAreaForResizableBaselineRight() {
    Pane pane = new Pane(); // Region extension which makes children sequence public

    MockResizable child = new MockResizable(10, 20, 30, 40, 50, 60); // baseline = 30
    pane.getChildren().add(child);

    child.autosize();
    pane.positionInArea(child, 10, 10, 100, 100, 50, HPos.RIGHT, VPos.BASELINE);

    assertEquals(30, child.getWidth(), 1e-100);
    assertEquals(40, child.getHeight(), 1e-100);
    assertEquals(80, child.getLayoutX(), 1e-100);
    assertEquals(30, child.getLayoutY(), 1e-100);
  }
  @Test
  public void testLayoutInAreaHonorsAreaHeightOverPrefWithNOFill() {
    Pane pane = new Pane(); // Region extension which makes children sequence public

    MockRegion child = new MockRegion(10, 20, 200, 300, 500, 500);
    pane.getChildren().add(child);

    pane.layoutInArea(
        child, 10, 10, 300, 100, 0, Insets.EMPTY, false, false, HPos.CENTER, VPos.CENTER);

    assertEquals(200, child.getWidth(), 1e-100);
    assertEquals(100, child.getHeight(), 1e-100);
    assertEquals(60, child.getLayoutX(), 1e-100);
    assertEquals(10, child.getLayoutY(), 1e-100);
  }
  @Test
  public void testLayoutInAreaHonorsMinHeightOverMax() {
    Pane pane = new Pane(); // Region extension which makes children sequence public

    MockRegion child = new MockRegion(10, 20, 200, 300, 500, 500);
    child.setMinHeight(600); // max less than min
    pane.getChildren().add(child);

    pane.layoutInArea(child, 10, 10, 300, 300, 0, HPos.CENTER, VPos.CENTER);

    assertEquals(300, child.getWidth(), 1e-100);
    assertEquals(600, child.getHeight(), 1e-100);
    assertEquals(10, child.getLayoutX(), 1e-100);
    assertEquals(-140, child.getLayoutY(), 1e-100);
  }
Ejemplo n.º 11
0
 @Override
 public void requestLayout() {
   if (!computingRuns) {
     runs = null;
   }
   super.requestLayout();
 }
 public void setNav(Pane nav) {
   this.nav = nav;
   nav.setPrefWidth(DEFAULT_WIDTH_NAV);
   AnchorPane.setTopAnchor(nav, 0d);
   AnchorPane.setBottomAnchor(nav, 0d);
   getChildren().add(nav);
 }
  @Test
  public void testLayoutInAreaWithMaxConstrainedToPref() {
    Pane pane = new Pane(); // Region extension which makes children sequence public

    MockRegion child = new MockRegion(10, 20, 30, 40, 500, 500);
    child.setMinSize(50, 60);
    child.setPrefSize(100, 200);
    child.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
    pane.getChildren().add(child);

    pane.layoutInArea(child, 10, 10, 300, 300, 0, HPos.CENTER, VPos.CENTER);

    assertEquals(100, child.getWidth(), 1e-100);
    assertEquals(200, child.getHeight(), 1e-100);
    assertEquals(110, child.getLayoutX(), 1e-100);
    assertEquals(60, child.getLayoutY(), 1e-100);
  }
 private void drawerAnimation() {
   Timeline animation;
   if (drawerOpened) {
     toggleLayer.setVisible(true);
     animation =
         new Timeline(
             new KeyFrame(
                 DEFAULT_TIME_ANIM,
                 new KeyValue(nav.translateXProperty(), 0, Interpolator.EASE_OUT),
                 new KeyValue(toggleLayer.opacityProperty(), 0.3)));
   } else {
     animation =
         new Timeline(
             new KeyFrame(
                 DEFAULT_TIME_ANIM,
                 new KeyValue(nav.translateXProperty(), -DEFAULT_WIDTH_NAV, Interpolator.EASE_IN),
                 new KeyValue(toggleLayer.opacityProperty(), 0)));
     animation.setOnFinished(
         evt -> {
           toggleLayer.setOpacity(0);
           toggleLayer.setVisible(false);
         });
   }
   animation.play();
 }
  @Test
  public void testChildMinAreaHeight() {
    Pane pane = new Pane();

    Region c1 = new MockBiased(Orientation.HORIZONTAL, 100, 100);
    Region c2 = new MockBiased(Orientation.VERTICAL, 100, 100);
    Region c3 = new MockRegion(10, 10, 100, 100, 1000, 1000);

    pane.getChildren().addAll(c1, c2, c3);

    assertEquals(
        3,
        pane.computeChildMinAreaHeight(c1, -1, new Insets(1), -1),
        1e-100); /*Insets + minimal for biased is 1 */
    assertEquals(
        2 + Math.ceil(100 * 100 / 48.0),
        pane.computeChildMinAreaHeight(c1, -1, new Insets(1), 50),
        1e-100);
    assertEquals(
        12 + Math.ceil(100 * 100 / 48.0),
        pane.computeChildMinAreaHeight(c1, 10, new Insets(1), 50),
        1e-100);
    assertEquals(12, pane.computeChildMinAreaHeight(c2, -1, new Insets(1), -1), 1e-100);
    assertEquals(12, pane.computeChildMinAreaHeight(c2, -1, new Insets(1), 50), 1e-100);
    assertEquals(12, pane.computeChildMinAreaHeight(c3, -1, new Insets(1), -1), 1e-100);
    assertEquals(12, pane.computeChildMinAreaHeight(c3, -1, new Insets(1), 50), 1e-100);
  }
  @Test
  public void testChildMaxAreaWidth() {
    Pane pane = new Pane();

    Region c1 = new MockBiased(Orientation.HORIZONTAL, 100, 100);
    Region c2 = new MockBiased(Orientation.VERTICAL, 100, 100);
    Region c3 = new MockRegion(10, 10, 100, 100, 1000, 1000);

    pane.getChildren().addAll(c1, c2, c3);

    assertEquals(10002, pane.computeChildMaxAreaWidth(c1, -1, new Insets(1), -1, false), 1e-100);
    assertEquals(10002, pane.computeChildMaxAreaWidth(c1, -1, new Insets(1), 50, false), 1e-100);
    assertEquals(
        102,
        pane.computeChildMaxAreaWidth(c2, -1, new Insets(1), -1, false),
        1e-100); // Vertival bias is not applied when no height/baseline offset is set
    assertEquals(
        2 + Math.ceil(100 * 100 / 48.0),
        pane.computeChildMaxAreaWidth(c2, -1, new Insets(1), 50, false),
        1e-100);
    assertEquals(
        2 + Math.ceil(100 * 100 / 38.0),
        pane.computeChildMaxAreaWidth(c2, 10, new Insets(1), 50, false),
        1e-100);
    assertEquals(1002, pane.computeChildMaxAreaWidth(c3, -1, new Insets(1), -1, false), 1e-100);
    assertEquals(1002, pane.computeChildMaxAreaWidth(c3, -1, new Insets(1), 50, false), 1e-100);
  }
Ejemplo n.º 17
0
  public void createWallLine(int y) {
    PositionButton button;
    Pane wallRec;

    for (int x = 0; x < 8; x++) {
      wallRec = new Pane();
      wallRec.setPrefSize(30, 10);
      wallRec.setId("wallRec");

      horizontalWalls[x][y] = wallRec;
      gameGrid.setConstraints(horizontalWalls[x][y], column, row);
      gameGrid.getChildren().add(horizontalWalls[x][y]);

      column++;

      button = new WallPositionButton(new Position(x, y));
      button.setPrefSize(10, 10);
      button.setId("wallPosBtn");

      wallPositionButtons[x][y] = button;

      gameGrid.setConstraints(wallPositionButtons[x][y], column, row);
      gameGrid.getChildren().addAll(wallPositionButtons[x][y]);

      column++;
    }

    wallRec = new Pane();
    wallRec.setPrefSize(30, 10);
    wallRec.setId("wallRec");

    horizontalWalls[8][y] = wallRec;
    gameGrid.setConstraints(horizontalWalls[8][y], column, row);
    gameGrid.getChildren().add(horizontalWalls[8][y]);

    column = 0;
    row++;
  }
  @Test
  public void testLayoutInAreaWithBaselineOffset() {
    Pane pane = new Pane(); // Region extension which makes children sequence public

    Region c1 = new MockBiased(Orientation.HORIZONTAL, 100, 100);
    Region c2 = new MockBiased(Orientation.VERTICAL, 100, 100);
    Region c3 = new MockRegion(10, 10, 100, 100, 1000, 1000);

    pane.getChildren().addAll(c1, c2, c3);
    pane.layoutInArea(
        c1, 10, 10, 300, 100, 20, Insets.EMPTY, false, false, HPos.CENTER, VPos.BASELINE);
    pane.layoutInArea(
        c2, 10, 10, 300, 100, 20, Insets.EMPTY, false, false, HPos.CENTER, VPos.BASELINE);
    pane.layoutInArea(
        c3, 10, 10, 300, 100, 20, Insets.EMPTY, false, false, HPos.CENTER, VPos.BASELINE);

    assertEquals(100, c1.getHeight(), 1e-100); // min height == pref height
    // As the other 2 Regions don't have a baseline offset, their baseline offset is "same as
    // height", therefore
    // they can be max 20px tall
    assertEquals(20, c2.getHeight(), 1e-100);
    assertEquals(20, c3.getHeight(), 1e-100);
  }
Ejemplo n.º 19
0
  public void createMoveLine(int y) {
    PositionButton button;
    Pane wallRec;

    button = new PlayerPositionButton(new Position(0, y));
    button.setPrefSize(60, 60);
    button.setId("board");

    playerPositionButtons[0][y] = button;
    gameGrid.setConstraints(button, column, row);
    gameGrid.getChildren().addAll(playerPositionButtons[0][y]);

    for (int x = 1; x < 9; x++) {
      column++;

      wallRec = new Pane();
      wallRec.setPrefSize(10, 30);
      wallRec.setId("wallRec");

      verticalWalls[x][y] = wallRec;
      gameGrid.setConstraints(wallRec, column, row);
      gameGrid.getChildren().add(verticalWalls[x][y]);

      column++;

      button = new PlayerPositionButton(new Position(x, y));
      button.setPrefSize(60, 60);

      button.setId("board");

      playerPositionButtons[x][y] = button;
      gameGrid.setConstraints(button, column, row);
      gameGrid.getChildren().addAll(playerPositionButtons[x][y]);
    }
    column = 0;
    row++;
  }
  @Test
  public void testChildMinAreaWidth() {
    Pane pane = new Pane();

    Region c1 = new MockBiased(Orientation.HORIZONTAL, 100, 100);
    Region c2 = new MockBiased(Orientation.VERTICAL, 100, 100);
    Region c3 = new MockRegion(10, 10, 100, 100, 1000, 1000);

    pane.getChildren().addAll(c1, c2, c3);

    assertEquals(12, pane.computeChildMinAreaWidth(c1, new Insets(1)), 1e-100);
    assertEquals(12, pane.computeChildMinAreaWidth(c1, 0, new Insets(1), 50, false), 1e-100);
    assertEquals(102, pane.computeChildMinAreaWidth(c2, new Insets(1)), 1e-100);
    assertEquals(
        2 + Math.ceil(100 * 100 / 48.0),
        pane.computeChildMinAreaWidth(c2, -1, new Insets(1), 50, false),
        1e-100); // vertically biased, effective height is 49
    assertEquals(
        2 + Math.ceil(100 * 100 / 38.0),
        pane.computeChildMinAreaWidth(c2, 10, new Insets(1), 50, false),
        1e-100); // vertically biased, effective height is 49
    assertEquals(12, pane.computeChildMinAreaWidth(c3, new Insets(1)), 1e-100);
    assertEquals(12, pane.computeChildMinAreaWidth(c3, 0, new Insets(1), 50, false), 1e-100);
  }
Ejemplo n.º 21
0
  /** initialize secondary structure view items */
  private void initSecondaryView() {
    // clear the secondary structure pane on initialization
    pane2D.getChildren().clear();

    if (view2DController.getGraph2d() != null) {
      pane2D.widthProperty().removeListener(view2DController.getWidthChangeListener());
      pane2D.heightProperty().removeListener(view2DController.getHeightChangeListener());
    }

    view2DController.initGraph2d(
        rnaSequence3D.extractString(),
        rnaSequence3D.getNucleotides().size(),
        rnaSequence3D.computeWCBonds(),
        (int) pane2D.getWidth(),
        (int) pane2D.getHeight());

    listenOnPane2dResize();
    view2DController.setScaleBinding(pane2D.widthProperty(), pane2D.heightProperty());

    view2DController.getGraph2d().setSelectionModel(selectionModel);
    pane2D.getChildren().add(view2DController.getGraph2d());
  }
Ejemplo n.º 22
0
  public static GridPane addGridPane(Pane parent) {
    GridPane gridPane = new GridPane();
    AnchorPane.setLeftAnchor(gridPane, 10d);
    AnchorPane.setRightAnchor(gridPane, 10d);
    AnchorPane.setTopAnchor(gridPane, 10d);
    AnchorPane.setBottomAnchor(gridPane, 10d);
    gridPane.setHgap(Layout.GRID_GAP);
    gridPane.setVgap(Layout.GRID_GAP);
    ColumnConstraints columnConstraints1 = new ColumnConstraints();
    columnConstraints1.setHalignment(HPos.RIGHT);
    columnConstraints1.setHgrow(Priority.SOMETIMES);

    ColumnConstraints columnConstraints2 = new ColumnConstraints();
    columnConstraints2.setHgrow(Priority.ALWAYS);

    gridPane.getColumnConstraints().addAll(columnConstraints1, columnConstraints2);

    parent.getChildren().add(gridPane);
    return gridPane;
  }
Ejemplo n.º 23
0
  /** initialize tertiary structure view */
  private void initTertiaryView() {
    Group models3D = new Group();
    rnaSequence3D = new RNASequence(model.getPdbfile());

    if (tertiaryRoom == null) {
      tertiaryRoom = new Room(models3D, 50, 50);
      tertiaryRoom.rotateCamera(tertiaryRoom);
      tertiaryRoom.scaleCamera(scene);
      tertiaryRoom.alignToParent(pane3D);
      tertiaryRoom.setPickOnBounds(false);
      pane3D.getChildren().add(tertiaryRoom);
    } else {
      tertiaryRoom.setObject(rnaSequence3D);
    }

    if (reloadItem.isSelected()) loadOneModel(0);
    if (!reloadItem.isSelected()) loadAllmodels();
    ((MeshModel) rnaSequence3D.getModels().get(1)).colorPyrPur();

    rnaSequence3D.setSelectionModel(selectionModel);
    tertiaryRoom.setCameraCenter(rnaSequence3D.computeCenter());

    activateRightSideButtons();
  }
  /**
   * Draws the MapMaker screen and displays it to the user
   *
   * @param primaryStage the stage to show it in
   * @throws Exception
   */
  public void drawScreen(Stage primaryStage) throws Exception {
    // Create the base BorderPane for the whole window
    BorderPane borderPane = new BorderPane();
    borderPane.setStyle("-fx-background-color: papayawhip");

    // Add some instructions to the user
    String text =
        "Instructions:\n"
            + "1. Click on the map component that you would like to place in the map\n"
            + "2. Click on the place in the map where you want to place the component\n"
            + "3. Repeat until you built the map you want!\n"
            + "4. Hit the 'Save' button when you are done";
    Label instructions = new Label(text);
    instructions.setFont(Font.font("Arial", FontWeight.BOLD, 12));
    instructions.setPadding(new Insets(5, 5, 5, 5));
    borderPane.setTop(instructions);

    // Create the blank Map
    Pane mapPane = new Pane();
    Map map = new Map(width, height);
    MapGridGUIDecorator mapGridGUIDecorator = new MapGridGUIDecorator(map.getGrid());
    ResizeFactor rf = ResizeFactor.getSuggestedResizeFactor(width, height);
    mapGridGUIDecorator.setResizeFactor(rf);
    GridPane mapGridPane = mapGridGUIDecorator.drawComponents();
    mapGridPane.setPadding(new Insets(0, 0, 5, 5));
    mapPane.getChildren().add(mapGridPane);
    borderPane.setCenter(mapPane);
    MapMakerController.setCurrentFocused(ComponentType.NOTHING);

    VBox sideComponents = new VBox();

    /* Add "Components" label */
    Label componentsLabel = new Label("Components");
    componentsLabel.setFont(Font.font("Arial", FontWeight.EXTRA_BOLD, 14));
    componentsLabel.setPadding(new Insets(15, 5, 0, 20));
    sideComponents.getChildren().add(componentsLabel);

    /* Add Intersection square image */
    VBox intersectionPane = new VBox();
    Label intersectionLabel = new Label("Intersection");
    intersectionLabel.setPadding(new Insets(5, 5, 0, 30));
    intersectionLabel.setFont(Font.font("Arial", FontWeight.SEMI_BOLD, 12));
    Image intersectionImg = new Image("IntersectionX.png", 60, 60, true, false);
    intersectionImgView = new ImageView(intersectionImg);
    StackPane intersectionStackPane = new StackPane(intersectionImgView);
    intersectionStackPane.setPadding(new Insets(0, 10, 10, 10));
    intersectionPane.getChildren().add(intersectionLabel);
    intersectionPane.getChildren().add(intersectionStackPane);
    sideComponents.getChildren().add(intersectionPane);

    /* Add RoadNS square image */
    VBox roadNSPane = new VBox();
    Label roadNSLabel = new Label("Road (North-South)");
    roadNSLabel.setPadding(new Insets(5, 5, 0, 15));
    roadNSLabel.setFont(Font.font("Arial", FontWeight.SEMI_BOLD, 12));
    Image roadNSImg = new Image("RoadBackgroundNS.png", 60, 60, true, false);
    roadNSImgView = new ImageView(roadNSImg);
    StackPane roadNSStackPane = new StackPane(roadNSImgView);
    roadNSStackPane.setPadding(new Insets(0, 10, 10, 10));
    roadNSPane.getChildren().add(roadNSLabel);
    roadNSPane.getChildren().add(roadNSStackPane);
    sideComponents.getChildren().add(roadNSPane);

    /* Add RoadEW square image */
    VBox roadEWPane = new VBox();
    Label roadEWLabel = new Label("Road (East-West)");
    roadEWLabel.setPadding(new Insets(5, 5, 0, 15));
    roadEWLabel.setFont(Font.font("Arial", FontWeight.SEMI_BOLD, 12));
    Image roadEWImg = new Image("RoadBackgroundEW.png", 60, 60, true, false);
    roadEWImgView = new ImageView(roadEWImg);
    StackPane roadEWStackPane = new StackPane(roadEWImgView);
    roadEWStackPane.setPadding(new Insets(0, 10, 10, 10));
    roadEWPane.getChildren().add(roadEWLabel);
    roadEWPane.getChildren().add(roadEWStackPane);
    sideComponents.getChildren().add(roadEWPane);

    /* Add Grass square image to empty out cells */
    VBox grassPane = new VBox();
    Label grassLabel = new Label("Grass (clear square)");
    grassLabel.setPadding(new Insets(5, 5, 0, 15));
    grassLabel.setFont(Font.font("Arial", FontWeight.SEMI_BOLD, 12));
    Image grassImg = new Image("Grass.png", 60, 60, true, false);
    grassImgView = new ImageView(grassImg);
    StackPane grassStackPane = new StackPane(grassImgView);
    grassStackPane.setPadding(new Insets(0, 10, 10, 10));
    grassPane.getChildren().add(grassLabel);
    grassPane.getChildren().add(grassStackPane);
    sideComponents.getChildren().add(grassPane);

    /* Add Save, Reset buttons */
    VBox buttonsPane = new VBox();
    buttonsPane.setPadding(new Insets(0, 0, 0, 10));
    Label toolsLabel = new Label("Tools");
    toolsLabel.setFont(Font.font("Arial", FontWeight.EXTRA_BOLD, 14));
    toolsLabel.setPadding(new Insets(15, 5, 5, 35));
    buttonsPane.getChildren().add(toolsLabel);
    Insets padding = new Insets(0, 0, 5, 0);
    Button saveButton = new Button("Save Map");
    StackPane saveButtonPane = new StackPane(saveButton);
    saveButtonPane.setPadding(padding);
    saveButton.setStyle("-fx-base:Gold");
    saveButton.setFont(Font.font("System Bold Italic", FontWeight.BOLD, 13));
    buttonsPane.getChildren().add(saveButtonPane);
    Button resetButton = new Button("Reset Map");
    resetButton.setStyle("-fx-base:Gold");
    resetButton.setFont(Font.font("System Bold Italic", FontWeight.BOLD, 13));
    StackPane resetButtonPane = new StackPane(resetButton);
    resetButtonPane.setPadding(padding);
    buttonsPane.getChildren().add(resetButtonPane);
    Button backButton = new Button("Go Back");
    backButton.setStyle("-fx-base:Gold");
    backButton.setFont(Font.font("System Bold Italic", FontWeight.BOLD, 13));
    StackPane backButtonPane = new StackPane(backButton);
    backButtonPane.setPadding(padding);
    buttonsPane.getChildren().add(backButtonPane);

    sideComponents.getChildren().add(buttonsPane);

    Ticker.start();

    /* Add click processing for Map grid squares */
    for (int i = 0; i < height; i++) {
      for (int j = 0; j < width; j++) {
        Node current = getNodeFromIndex(i, j, mapGridPane);
        final int x = j;
        final int y = i;
        current.setOnMouseClicked(
            (MouseEvent click) -> {
              MapMakerController.setPreviousFocused(MapMakerController.getCurrentFocused());
              MapMakerController.setCurrentFocused(ComponentType.MAP_SQUARE);
              current.requestFocus();
            });
        current
            .focusedProperty()
            .addListener(
                (ObservableValue<? extends Boolean> observable,
                    Boolean oldValue,
                    Boolean newValue) -> {
                  ComponentType previous = MapMakerController.getPreviousFocused();
                  if (previous == ComponentType.INTERSECTION) {
                    addIntersection(
                        x, y, map, mapGridGUIDecorator, mapGridPane, intersectionImgView);
                  } else if (previous == ComponentType.ROADNS) {
                    addRoadNS(x, y, map, mapGridGUIDecorator, mapGridPane, roadNSImgView);
                  } else if (previous == ComponentType.ROADEW) {
                    addRoadEW(x, y, map, mapGridGUIDecorator, mapGridPane, roadEWImgView);
                  } else if (previous == ComponentType.GRASS) {
                    addGrass(x, y, map, mapGridGUIDecorator, mapGridPane, grassImgView);
                  }
                });
      }
    }

    /* Add intersection icon click processing */
    DropShadow ds = new DropShadow(15, Color.BLUE);
    intersectionImgView.setOnMouseClicked(
        click -> {
          MapMakerController.setPreviousFocused(MapMakerController.getCurrentFocused());
          MapMakerController.setCurrentFocused(ComponentType.INTERSECTION);
          intersectionImgView.requestFocus();
        });
    intersectionImgView
        .focusedProperty()
        .addListener(
            (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
              if (newValue) intersectionImgView.setEffect(ds);
              else intersectionImgView.setEffect(null);
            });

    /* Add roadNS icon click processing */
    roadNSImgView.setOnMouseClicked(
        click -> {
          MapMakerController.setPreviousFocused(MapMakerController.getCurrentFocused());
          MapMakerController.setCurrentFocused(ComponentType.ROADNS);
          roadNSImgView.requestFocus();
        });
    roadNSImgView
        .focusedProperty()
        .addListener(
            (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
              if (newValue) roadNSImgView.setEffect(ds);
              else roadNSImgView.setEffect(null);
            });

    /* Add roadEW icon click processing */
    roadEWImgView.setOnMouseClicked(
        click -> {
          MapMakerController.setPreviousFocused(MapMakerController.getCurrentFocused());
          MapMakerController.setCurrentFocused(ComponentType.ROADEW);
          roadEWImgView.requestFocus();
        });
    roadEWImgView
        .focusedProperty()
        .addListener(
            (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
              if (newValue) roadEWImgView.setEffect(ds);
              else roadEWImgView.setEffect(null);
            });

    /* Add grass icon click processing */
    grassImgView.setOnMouseClicked(
        click -> {
          MapMakerController.setPreviousFocused(MapMakerController.getCurrentFocused());
          MapMakerController.setCurrentFocused(ComponentType.GRASS);
          grassImgView.requestFocus();
        });
    grassImgView
        .focusedProperty()
        .addListener(
            (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
              if (newValue) grassImgView.setEffect(ds);
              else grassImgView.setEffect(null);
            });

    /* Add save button functionality */
    saveButton.setOnMouseClicked(
        click -> {
          TextInputDialog nameDialog = new TextInputDialog();
          nameDialog.setTitle("Save Map");
          nameDialog.setHeaderText(
              "Please provide a name for your map (no spaces or special characters).\nSaved maps go into the /maps directory of your working directory.");
          nameDialog.setContentText("File name");
          Button btOk = (Button) nameDialog.getDialogPane().lookupButton(ButtonType.OK);
          TextField textfield = nameDialog.getEditor();
          Platform.runLater(() -> textfield.requestFocus());
          btOk.setDisable(true);
          textfield
              .textProperty()
              .addListener(
                  ((observable, oldValue, newValue) -> {
                    btOk.setDisable(newValue.trim().isEmpty());
                  }));

          Optional<String> result = nameDialog.showAndWait();
          result.ifPresent(
              name -> {
                name = name.concat(".map");
                try {
                  Map finalMap = buildAndSaveMap(map);
                  finalMap.saveMap(name);
                  goBack(primaryStage);
                } catch (Exception e) {
                  e.printStackTrace();
                }
              });
        });

    resetButton.setOnMouseClicked(
        click -> {
          for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
              Component component = map.getAtLocation(new Coordinate(x, y));
              if (component instanceof Road || component instanceof Intersection) {
                addGrass(x, y, map, mapGridGUIDecorator, mapGridPane, grassImgView);
              }
            }
          }
        });

    backButton.setOnMouseClicked(
        click -> {
          try {
            goBack(primaryStage);
          } catch (Exception e) {
            e.printStackTrace();
          }
        });

    borderPane.setRight(sideComponents);
    Scene scene = new Scene(borderPane);
    primaryStage.setScene(scene);
    primaryStage.centerOnScreen();
    primaryStage.setResizable(false);
  }
Ejemplo n.º 25
0
  private void listenOnPane2dResize() {
    view2DController.initProperties();

    pane2D.widthProperty().addListener(view2DController.getWidthChangeListener());
    pane2D.heightProperty().addListener(view2DController.getHeightChangeListener());
  }