Exemplo n.º 1
0
  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 void handle(MouseEvent event) {
   // TODO Auto-generated method stub
   if (event.getEventType().equals(MouseEvent.MOUSE_CLICKED)) {
     if (parent != null) {
       kioskMain.setMode(dispMode.MODE_BUS);
       parent.getScene().setRoot(kioskMain);
     }
   }
 }
Exemplo n.º 3
0
 @Override
 public void handle(MouseEvent event) {
   txt = (Text) event.getTarget();
   if (event.getEventType() == MouseEvent.MOUSE_ENTERED) {
     actualWindow.setCursor(actualWindow.cursorHover);
     actualWindow.getMenuPanel().getModuleMenu().drawHover(txt);
   }
   if (event.getEventType() == MouseEvent.MOUSE_EXITED) {
     actualWindow.setCursor(actualWindow.cursor);
     actualWindow.getMenuPanel().getModuleMenu().unHover(txt);
   }
   if (event.getEventType() == MouseEvent.MOUSE_CLICKED) {
     if (txt != null && txt.getId() == "newPart") {
       actualModel.getMusic().getMusicMenu().stop();
       actualModel.nouvellePartie();
       actualWindow.switchPanel(actualWindow.getGamePanel());
       actualModel.getMusic().playLoop();
     }
   }
 }
Exemplo n.º 4
0
 @Override
 public void handle(MouseEvent event) {
   EventType<? extends Event> type = event.getEventType();
   if (type.equals(MouseEvent.MOUSE_ENTERED) || type.equals(MouseEvent.MOUSE_EXITED)) {
     refreshVisual();
   } else if (type.equals(MouseEvent.MOUSE_MOVED) || type.equals(MouseEvent.MOUSE_DRAGGED)) {
     if (originalBounds != null) {
       if (!originalBounds.contains(event.getSceneX(), event.getSceneY())) {
         // unhover the visual by making it mouse transparent
         getVisual().setMouseTransparent(true);
         // this will result in a MOUSE_EXITED event being fired,
         // which will lead to a refreshVisual() call, which will
         // update the visualization
       }
     }
   }
 }
Exemplo n.º 5
0
    public void handle(MouseEvent e) {
      EventType<?> type = e.getEventType();
      if (type == MouseEvent.MOUSE_MOVED) {

        // Set time to disappear
        scheduleDisappearTime = System.currentTimeMillis() + 1700;

        // Make buttons visible
        setButtonOpacities(0.75);

        // If thread doesn't exist, create it
        if (visibilityThread == null) {
          visibilityThread =
              new Thread() {

                public void run() {
                  // Keep comparing to scheduled time (which is
                  // updated outside of thread)
                  while (System.currentTimeMillis() < scheduleDisappearTime
                      || next.isHover()
                      || back.isHover()) {
                    try {
                      Thread.sleep(50);
                    } catch (InterruptedException e) {
                      logger.error("Cannot sleep !", e);
                    }
                  }

                  // Make buttons disappear
                  setButtonOpacities(0.0);

                  // Destroy thread
                  visibilityThread = null;
                }
              };
          visibilityThread.start();
        }
      }
    }
  @Override
  public void handle(MouseEvent event) {
    EventType<? extends MouseEvent> eventType = event.getEventType();
    if (eventType.equals(MouseEvent.MOUSE_CLICKED)) {
      if (openMenu != null) disposeOpenMenu();
      MenuItem hmi = new MenuItem("Help");
      hmi.setOnAction(e -> DialogService.openHelpDialog());

      PhongMaterial m = new PhongMaterial();
      m.setDiffuseColor(Color.GREEN);
      m.setSpecularColor(Color.WHITE);
      Box box = new Box(10, 10, 10);
      box.setMaterial(m);
      box.getTransforms().addAll(new Rotate(45, Rotate.Z_AXIS), new Rotate(45, Rotate.X_AXIS));

      MenuItem imi = new MenuItem("Inspect", new ImageView(Resources.SEARCH_ICON));
      imi.setOnAction(
          e -> {
            DialogService.openInspectDialog(node);
          });

      MenuItem emi = new MenuItem("Expand / Collapse", box);
      emi.setOnAction(
          e -> {
            handlePrimaryClick();
          });

      openMenu = new ContextMenu();
      openMenu.getItems().addAll(emi, imi, new SeparatorMenuItem(), hmi);
      openMenu.show(shape, event.getScreenX(), event.getScreenY());
    } else if (eventType.equals(MouseEvent.MOUSE_ENTERED)) {
      manager.submitTask(() -> manager.findReferingNodes(node, true));
    } else if (eventType.equals(MouseEvent.MOUSE_EXITED)) {
      manager.submitTask(() -> manager.findReferingNodes(node, false));
    }
  }
Exemplo n.º 7
0
    @Override
    public void handle(final MouseEvent mouseEvent) {
      final EventType<? extends MouseEvent> mouseEventType = mouseEvent.getEventType();
      final Scene scene = this.stage.getScene();

      final double mouseEventX = mouseEvent.getSceneX(),
          mouseEventY = mouseEvent.getSceneY(),
          sceneWidth = scene.getWidth(),
          sceneHeight = scene.getHeight();

      if (MouseEvent.MOUSE_MOVED.equals(mouseEventType) == true) {
        if (mouseEventX < this.border && mouseEventY < this.border) {
          this.cursorEvent = Cursor.NW_RESIZE;
        } else if (mouseEventX < this.border && mouseEventY > sceneHeight - this.border) {
          this.cursorEvent = Cursor.SW_RESIZE;
        } else if (mouseEventX > sceneWidth - this.border && mouseEventY < this.border) {
          this.cursorEvent = Cursor.NE_RESIZE;
        } else if (mouseEventX > sceneWidth - this.border
            && mouseEventY > sceneHeight - this.border) {
          this.cursorEvent = Cursor.SE_RESIZE;
        } else if (mouseEventX < this.border) {
          this.cursorEvent = Cursor.W_RESIZE;
        } else if (mouseEventX > sceneWidth - this.border) {
          this.cursorEvent = Cursor.E_RESIZE;
        } else if (mouseEventY < this.border) {
          this.cursorEvent = Cursor.N_RESIZE;
        } else if (mouseEventY > sceneHeight - this.border) {
          this.cursorEvent = Cursor.S_RESIZE;
        } else {
          this.cursorEvent = Cursor.DEFAULT;
        }
        scene.setCursor(this.cursorEvent);
      } else if (MouseEvent.MOUSE_PRESSED.equals(mouseEventType) == true) {
        this.startX = this.stage.getWidth() - mouseEventX;
        this.startY = this.stage.getHeight() - mouseEventY;
      } else if (MouseEvent.MOUSE_DRAGGED.equals(mouseEventType) == true) {
        this.resizing = false;
        if (Cursor.DEFAULT.equals(this.cursorEvent) == false) {
          if (Cursor.W_RESIZE.equals(this.cursorEvent) == false
              && Cursor.E_RESIZE.equals(this.cursorEvent) == false) {
            final double minHeight =
                this.stage.getMinHeight() > (this.border * 2)
                    ? this.stage.getMinHeight()
                    : (this.border * 2);
            if (Cursor.NW_RESIZE.equals(this.cursorEvent) == true
                || Cursor.N_RESIZE.equals(this.cursorEvent) == true
                || Cursor.NE_RESIZE.equals(this.cursorEvent) == true) {
              if (this.stage.getHeight() > minHeight || mouseEventY < 0) {
                this.resizing = true;
                this.stage.setHeight(
                    this.stage.getY() - mouseEvent.getScreenY() + this.stage.getHeight());
                this.stage.setY(mouseEvent.getScreenY());
              }
            } else {
              if (this.stage.getHeight() > minHeight
                  || mouseEventY + this.startY - this.stage.getHeight() > 0) {
                this.resizing = true;
                this.stage.setHeight(mouseEventY + this.startY);
              }
            }
          }

          if (Cursor.N_RESIZE.equals(this.cursorEvent) == false
              && Cursor.S_RESIZE.equals(this.cursorEvent) == false) {
            final double minWidth =
                this.stage.getMinWidth() > (this.border * 2)
                    ? this.stage.getMinWidth()
                    : (this.border * 2);
            if (Cursor.NW_RESIZE.equals(this.cursorEvent) == true
                || Cursor.W_RESIZE.equals(this.cursorEvent) == true
                || Cursor.SW_RESIZE.equals(this.cursorEvent) == true) {
              if (this.stage.getWidth() > minWidth || mouseEventX < 0) {
                this.resizing = true;
                this.stage.setWidth(
                    this.stage.getX() - mouseEvent.getScreenX() + this.stage.getWidth());
                this.stage.setX(mouseEvent.getScreenX());
              }
            } else {
              if (this.stage.getWidth() > minWidth
                  || mouseEventX + this.startX - this.stage.getWidth() > 0) {
                this.resizing = true;
                this.stage.setWidth(mouseEventX + this.startX);
              }
            }
          }
        }
      }
    }
Exemplo n.º 8
0
  @Override
  public void handle(MouseEvent event) {
    if (event.getEventType() == MouseEvent.MOUSE_PRESSED) {
      if (dockNode.isFloating()
          && event.getClickCount() == 2
          && event.getButton() == MouseButton.PRIMARY) {
        dockNode.setMaximized(!dockNode.isMaximized());
      } else {
        // drag detected is used in place of mouse pressed so there is some threshold for the
        // dragging which is determined by the default drag detection threshold
        dragStart = new Point2D(event.getX(), event.getY());
      }
    } else if (event.getEventType() == MouseEvent.DRAG_DETECTED) {
      if (!dockNode.isFloating()) {
        // if we are not using a custom title bar and the user
        // is not forcing the default one for floating and
        // the dock node does have native window decorations
        // then we need to offset the stage position by
        // the height of this title bar
        if (!dockNode.isCustomTitleBar() && dockNode.isDecorated()) {
          dockNode.setFloating(true, new Point2D(0, DockTitleBar.this.getHeight()));
        } else {
          dockNode.setFloating(true);
        }

        // TODO: Find a better solution.
        // Temporary work around for nodes losing the drag event when removed from
        // the scene graph.
        // A possible alternative is to use "ghost" panes in the DockPane layout
        // while making DockNode simply an overlay stage that is always shown.
        // However since flickering when popping out was already eliminated that would
        // be overkill and is not a suitable solution for native decorations.
        // Bug report open: https://bugs.openjdk.java.net/browse/JDK-8133335
        DockPane dockPane = this.getDockNode().getDockPane();
        if (dockPane != null) {
          dockPane.addEventFilter(MouseEvent.MOUSE_DRAGGED, this);
          dockPane.addEventFilter(MouseEvent.MOUSE_RELEASED, this);
        }
      } else if (dockNode.isMaximized()) {
        double ratioX = event.getX() / this.getDockNode().getWidth();
        double ratioY = event.getY() / this.getDockNode().getHeight();

        // Please note that setMaximized is ruined by width and height changes occurring on the
        // stage and there is currently a bug report filed for this though I did not give them an
        // accurate test case which I should and wish I would have. This was causing issues in the
        // original release requiring maximized behavior to be implemented manually by saving the
        // restored bounds. The problem was that the resize functionality in DockNode.java was
        // executing at the same time canceling the maximized change.
        // https://bugs.openjdk.java.net/browse/JDK-8133334

        // restore/minimize the window after we have obtained its dimensions
        dockNode.setMaximized(false);

        // scale the drag start location by our restored dimensions
        dragStart = new Point2D(ratioX * dockNode.getWidth(), ratioY * dockNode.getHeight());
      }
      dragging = true;
      event.consume();
    } else if (event.getEventType() == MouseEvent.MOUSE_DRAGGED) {
      if (dockNode.isFloating()
          && event.getClickCount() == 2
          && event.getButton() == MouseButton.PRIMARY) {
        event.setDragDetect(false);
        event.consume();
        return;
      }

      if (!dragging) return;

      Stage stage = dockNode.getStage();
      Insets insetsDelta = this.getDockNode().getBorderPane().getInsets();

      // dragging this way makes the interface more responsive in the event
      // the system is lagging as is the case with most current JavaFX
      // implementations on Linux
      stage.setX(event.getScreenX() - dragStart.getX() - insetsDelta.getLeft());
      stage.setY(event.getScreenY() - dragStart.getY() - insetsDelta.getTop());

      // TODO: change the pick result by adding a copyForPick()
      DockEvent dockEnterEvent =
          new DockEvent(
              this,
              DockEvent.NULL_SOURCE_TARGET,
              DockEvent.DOCK_ENTER,
              event.getX(),
              event.getY(),
              event.getScreenX(),
              event.getScreenY(),
              null);
      DockEvent dockOverEvent =
          new DockEvent(
              this,
              DockEvent.NULL_SOURCE_TARGET,
              DockEvent.DOCK_OVER,
              event.getX(),
              event.getY(),
              event.getScreenX(),
              event.getScreenY(),
              null);
      DockEvent dockExitEvent =
          new DockEvent(
              this,
              DockEvent.NULL_SOURCE_TARGET,
              DockEvent.DOCK_EXIT,
              event.getX(),
              event.getY(),
              event.getScreenX(),
              event.getScreenY(),
              null);

      EventTask eventTask =
          new EventTask() {
            @Override
            public void run(Node node, Node dragNode) {
              executions++;

              if (dragNode != node) {
                Event.fireEvent(node, dockEnterEvent.copyFor(DockTitleBar.this, node));

                if (dragNode != null) {
                  // fire the dock exit first so listeners
                  // can actually keep track of the node we
                  // are currently over and know when we
                  // aren't over any which DOCK_OVER
                  // does not provide
                  Event.fireEvent(dragNode, dockExitEvent.copyFor(DockTitleBar.this, dragNode));
                }

                dragNodes.put(node.getScene().getWindow(), node);
              }
              Event.fireEvent(node, dockOverEvent.copyFor(DockTitleBar.this, node));
            }
          };

      this.pickEventTarget(
          new Point2D(event.getScreenX(), event.getScreenY()), eventTask, dockExitEvent);
    } else if (event.getEventType() == MouseEvent.MOUSE_RELEASED) {
      dragging = false;

      DockEvent dockReleasedEvent =
          new DockEvent(
              this,
              DockEvent.NULL_SOURCE_TARGET,
              DockEvent.DOCK_RELEASED,
              event.getX(),
              event.getY(),
              event.getScreenX(),
              event.getScreenY(),
              null,
              this.getDockNode());

      EventTask eventTask =
          new EventTask() {
            @Override
            public void run(Node node, Node dragNode) {
              executions++;
              if (dragNode != node) {
                Event.fireEvent(node, dockReleasedEvent.copyFor(DockTitleBar.this, node));
              }
              Event.fireEvent(node, dockReleasedEvent.copyFor(DockTitleBar.this, node));
            }
          };

      this.pickEventTarget(new Point2D(event.getScreenX(), event.getScreenY()), eventTask, null);

      dragNodes.clear();

      // Remove temporary event handler for bug mentioned above.
      DockPane dockPane = this.getDockNode().getDockPane();
      if (dockPane != null) {
        dockPane.removeEventFilter(MouseEvent.MOUSE_DRAGGED, this);
        dockPane.removeEventFilter(MouseEvent.MOUSE_RELEASED, this);
      }
    }
  }