private void handleMouseEvent(MouseEvent me) {
    // Handle cursor
    final Scene scene = getScene();

    if (scene == null) {
      return;
    }

    // When another window is focused (just like the preview window),
    // we use default cursor
    if (scene.getWindow() != null && !scene.getWindow().isFocused()) {
      setCursor(Cursor.DEFAULT);
      return;
    }

    final LibraryListItem listItem = getItem();
    ILibraryItem item = null;

    if (listItem != null) {
      item = listItem.getLibItem();
    }

    boolean isSection = false;
    if (listItem != null && listItem.getSectionName() != null) {
      isSection = true;
    }

    if (me.getEventType() == MouseEvent.MOUSE_ENTERED) {
      if (isEmpty() || isSection) {
        setCursor(Cursor.DEFAULT);
      } else {
        setCursor(Cursor.OPEN_HAND);
      }
    } else if (me.getEventType() == MouseEvent.MOUSE_PRESSED) {
      if (isEmpty() || isSection) {
        setCursor(Cursor.DEFAULT);
      } else {
        setCursor(Cursor.CLOSED_HAND);
      }
    } else if (me.getEventType() == MouseEvent.MOUSE_RELEASED) {
      if (isEmpty() || isSection) {
        setCursor(Cursor.DEFAULT);
      } else {
        setCursor(Cursor.OPEN_HAND);
      }
    } else if (me.getEventType() == MouseEvent.MOUSE_EXITED) {
      setCursor(Cursor.DEFAULT);
    } else if (me.getEventType() == MouseEvent.MOUSE_CLICKED) {
      // On double click ask for addition of the drag able item on Content
      if (me.getClickCount() == 2 && me.getButton() == MouseButton.PRIMARY) {
        if (!isEmpty() && !isSection && item != null) {
          if (editorController.canPerformInsert(item)) {
            editorController.performInsert(item);
          }
        }
      }
    }
  }
    @Override
    public Point2D getScenePosition() {
      Scene scene;

      if (source instanceof Node) {
        scene = ((Node) source).getScene();
      } else if (source instanceof Scene) {
        scene = (Scene) source;
      } else {
        return null;
      }

      return screenPos.subtract(
          scene.getX() + scene.getWindow().getX(), scene.getY() + scene.getWindow().getY());
    }
Exemple #3
0
 /** Transforms the given bounds in the given scene to the screen's coordinate system. */
 public static Bounds boundsOnScreen(Bounds boundsInScene, Scene scene) {
   Bounds sceneBoundsInWindow = bounds(scene);
   Bounds windowBoundsOnScreen = bounds(scene.getWindow());
   return translateBounds(
       boundsInScene,
       byOffset(
           sceneBoundsInWindow.getMinX() + windowBoundsOnScreen.getMinX(),
           sceneBoundsInWindow.getMinY() + windowBoundsOnScreen.getMinY()));
 }
 @FXML
 public void onBackButtonClicked(MouseEvent event) throws IOException {
   Scene currentScene = ((Node) event.getSource()).getScene();
   Stage currentStage = (Stage) currentScene.getWindow();
   FXMLLoader loader =
       new FXMLLoader(getClass().getResource("OptionsMenu.fxml"), tusca_db.Tusca_db.BUNDLE);
   Parent root = (Parent) loader.load();
   Scene scene =
       new Scene(root, currentStage.getScene().getWidth(), currentStage.getScene().getHeight());
   currentStage.setScene(scene);
 }
 public void moveTo(Robot robot, Node visual, double localX, double localY)
     throws InterruptedException {
   Point2D localToScene = visual.localToScene(localX, localY);
   double x = scene.getWindow().getX() + localToScene.getX();
   double y = scene.getWindow().getY() + localToScene.getY();
   EventSynchronizer<MouseEvent> synchronizer =
       new EventSynchronizer<MouseEvent>(visual, MouseEvent.MOUSE_ENTERED);
   synchronizer.register();
   robot.mouseMove((int) x, (int) y);
   synchronizer.await();
 }
 /*     */ public WCPoint windowToScreen(WCPoint paramWCPoint) /*     */ {
   /* 125 */ WebView localWebView = this.accessor.getView();
   /* 126 */ Scene localScene = localWebView.getScene();
   /* 127 */ Window localWindow = null;
   /*     */
   /* 129 */ if ((localScene != null) && ((localWindow = localScene.getWindow()) != null))
   /*     */ {
     /* 132 */ Point2D localPoint2D =
         localWebView.localToScene(paramWCPoint.getX(), paramWCPoint.getY());
     /* 133 */ return new WCPoint(
         (float) (localPoint2D.getX() + localScene.getX() + localWindow.getX()),
         (float) (localPoint2D.getY() + localScene.getY() + localWindow.getY()));
     /*     */ }
   /*     */
   /* 136 */ return new WCPoint(0.0F, 0.0F);
   /*     */ }
 /*     */ public WCPoint screenToWindow(WCPoint paramWCPoint) {
   /* 108 */ WebView localWebView = this.accessor.getView();
   /* 109 */ Scene localScene = localWebView.getScene();
   /* 110 */ Window localWindow = null;
   /*     */
   /* 112 */ if ((localScene != null) && ((localWindow = localScene.getWindow()) != null))
   /*     */ {
     /* 115 */ Point2D localPoint2D =
         localWebView.sceneToLocal(
             paramWCPoint.getX() - localWindow.getX() - localScene.getX(),
             paramWCPoint.getY() - localWindow.getY() - localScene.getY());
     /*     */
     /* 118 */ return new WCPoint((float) localPoint2D.getX(), (float) localPoint2D.getY());
     /*     */ }
   /* 120 */ return new WCPoint(0.0F, 0.0F);
   /*     */ }
  public void loadCatalogs() {
    Button button;
    Catalog catalog;
    List<Item> items =
        ((CatalogCollection) (new CatalogModel()).getCollection()).loadByLibraryId(libraryId);
    int i = 1;

    for (Item item : items) {
      catalog = (Catalog) item;
      button = new Button(catalog.getName());
      int catalogId = catalog.getId();
      button.setId(String.valueOf(catalogId));
      button.getStyleClass().add("cake");
      button.setOnAction(
          (ActionEvent event) -> {
            try {
              Scene sceneCurrent = btnBack.getScene();
              Stage stage = (Stage) sceneCurrent.getWindow();

              FXMLLoader fxmlLoader =
                  new FXMLLoader(getClass().getResource("/view/template/book/BookList.fxml"));
              Parent sceneNew = fxmlLoader.load();

              BookListController controller = fxmlLoader.<BookListController>getController();
              controller.setCatalogId(catalogId);
              controller.setLibraryId(libraryId);
              controller.prepareData();

              stage.setScene(
                  new Scene(sceneNew, sceneCurrent.getWidth(), sceneCurrent.getHeight()));
            } catch (IOException e) {
              logger.log(Level.SEVERE, "Error configuring catalog buttons", e);
            }
          });
      catalogContainer.add(button, i++, 1);
    }
  }
  @Override
  public void start(Stage stage) throws Exception {
    stage.setResizable(false);

    // Doing it this way so we can get access to the main controller class,
    // so it can have knowledge of the application exit
    FXMLLoader loader = new FXMLLoader(getClass().getResource("MainLayout.fxml"));
    Parent root = (Parent) (loader.load());
    mMainController = (MainLayoutController) (loader.getController());

    Scene scene = new Scene(root);

    stage.setScene(scene);
    stage.show();

    // Add an event handler for the scene's close request, so we can tell the
    // main layout controller to shut down properly
    scene
        .getWindow()
        .setOnCloseRequest(
            (WindowEvent t) -> {
              mMainController.shutdown();
            });
  }
 public Stage getStage() {
   return (Stage) scene.getWindow();
 }
  public static void createStartTownSaloonView() {
    GridPane gridPane = new GridPane();

    gridPane.setHgap(2);
    gridPane.setVgap(2);
    gridPane.setId("saloonGridBackground");

    Button backBtn = new Button("Back");
    backBtn.setId("mainScreenBtn");
    gridPane.add(backBtn, 0, 0);

    URL url =
        StartTownSaloonView.class.getClassLoader().getResource("resources/saloonPianoMusic.mp3");
    assert url != null;
    final Media media = new Media(url.toString());
    final MediaPlayer mediaPlayer = new MediaPlayer(media);
    mediaPlayer.setVolume(25);
    mediaPlayer.setCycleCount(99);
    mediaPlayer.play();

    Scene scene =
        new Scene(
            gridPane,
            Main.getPrimaryStage().getScene().getWidth(),
            Main.getPrimaryStage().getScene().getHeight());

    scene.getStylesheets().add("resources/main.css");

    ArrayList<Tooltip> tooltipArrayList = new ArrayList<>();

    AddKeyListenerToScene.addGeneralKeyListener(scene);
    /**
     * Need to add a bunch of collision detection rectangles for clicking on people and getting a
     * toolip to popup.
     */
    scene.setOnMouseClicked(
        event -> {
          double x = event.getX();
          double y = event.getY();
          for (Tooltip eraseTooltip : tooltipArrayList) {
            eraseTooltip.hide();
          }

          if (x >= 767.0 && x <= 814.0 && y >= 378.0 && y <= 461.0) {
            Tooltip bartender = new Tooltip("What can I get ya?");
            bartender.setId("startTownSaloonTooltip");
            bartender.show(
                gridPane, 776.0 + scene.getWindow().getX(), 407.0 + scene.getWindow().getY());
            tooltipArrayList.add(bartender);
          }
          if (x >= 687.0 && x <= 759.0 && y >= 387.0 && y <= 507.0) {
            Tooltip oldManAtTheBar =
                new Tooltip("Whiskey, Mmm Mmm Mmm down to my belly, yum yum yum...*hiccup*");
            oldManAtTheBar.setId("startTownSaloonTooltip");
            oldManAtTheBar.show(
                gridPane, 745.0 + scene.getWindow().getX(), 432.0 + scene.getWindow().getY());
            tooltipArrayList.add(oldManAtTheBar);
          }
          if (x >= 43.0 && x <= 102.0 && y >= 330.0 && y <= 545.0) {
            Tooltip banjoPlayerInBack = new Tooltip("Yoddle yoddleeeee yoddleeeeheeeehoooo...");
            banjoPlayerInBack.setId("startTownSaloonTooltip");
            banjoPlayerInBack.show(
                gridPane, 83.0 + scene.getWindow().getX(), 356.0 + scene.getWindow().getY());
            tooltipArrayList.add(banjoPlayerInBack);
          }
          if (x >= 606.0 && x <= 662.0 && y >= 383.0 && y <= 688.0) {
            Tooltip secretAlienTechHintDude =
                new Tooltip(
                    "I was out in the fields...staring\n"
                        + "at the sky when suddenly a huge blinding\n"
                        + "light shot up from the ground. Aliens man\n"
                        + "I hope they left something behind for me to\n"
                        + "find!");
            secretAlienTechHintDude.setId("startTownSaloonTooltip");
            secretAlienTechHintDude.show(
                gridPane, 645.0 + scene.getWindow().getX(), 428.0 + scene.getWindow().getY());
            tooltipArrayList.add(secretAlienTechHintDude);
          }
          if (x >= 923.0 && x <= 1029.0 && y >= 385.0 && y <= 752.0) {
            Tooltip guyHittingOnGirlOnRight = new Tooltip("Sup baby gurrllllll");
            guyHittingOnGirlOnRight.setId("startTownSaloonTooltip");
            guyHittingOnGirlOnRight.show(
                gridPane, 952.0 + scene.getWindow().getX(), 427.0 + scene.getWindow().getY());
            tooltipArrayList.add(guyHittingOnGirlOnRight);
          }

          /**
           * Set listeners for window drags. If user drags the window then hide all the tooltips or
           * they will stay where they are until user hides them with the other commands. Aesthetics
           * only really.
           */
          scene
              .getWindow()
              .xProperty()
              .addListener(
                  (observable, oldValue, newValue) -> {
                    for (Tooltip eraseTooltip : tooltipArrayList) {
                      eraseTooltip.hide();
                    }
                  });
          scene
              .getWindow()
              .yProperty()
              .addListener(
                  (observable, oldValue, newValue) -> {
                    for (Tooltip eraseTooltip : tooltipArrayList) {
                      eraseTooltip.hide();
                    }
                  });

          // System.out.println(event.getX());
          // System.out.println(event.getY());
        });

    backBtn.setOnAction(
        event -> {
          Main.getPrimaryStage().setScene(StartingTownView.getStartingTownView());
          mediaPlayer.stop();
          for (Tooltip eraseTooltip : tooltipArrayList) {
            eraseTooltip.hide();
            eraseTooltip = null;
          }
        });

    setStartSaloon(scene);
    Main.getPrimaryStage().setScene(scene);
  }