Java Code Examples for javafx.scene.input.MouseEvent#MOUSE_CLICKED

The following examples show how to use javafx.scene.input.MouseEvent#MOUSE_CLICKED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TreeViewApp.java    From oim-fx with MIT License 5 votes vote down vote up
@Override

	public void start(Stage primaryStage) throws Exception {
		primaryStage.initStyle(StageStyle.TRANSPARENT);
		primaryStage.setScene(new Scene(createContent()));
		primaryStage.show();
		EventType<MouseEvent> type = MouseEvent.MOUSE_CLICKED;
		primaryStage.addEventHandler(type,e->{
			System.out.println(e);
		});
	}
 
Example 2
Source File: ListWidgetBase.java    From phoenicis with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Selects the {@link ListWidgetElement} which belongs to the given {@link E innerElement}
 *
 * @param innerElement The inner element
 */
public void select(E innerElement) {
    final MouseEvent event = new MouseEvent(
            MouseEvent.MOUSE_CLICKED, 0, 0, 0, 0, MouseButton.PRIMARY, 1,
            false, false, false, false, false,
            false, false, false, false, false,
            null);

    select(innerElement, event);
}
 
Example 3
Source File: GUIConsoleInput.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a new GUI console input.
 *
 * @param area GUI text area
 */
public GUIConsoleInput(InlineCssTextArea area) {
  this.area = area;
  initialPos = -1;
  inputText = null;
  area.setEditable(false);
  queue = new ArrayBlockingQueue<>(1);
  listener = new EventHandler<KeyEvent>() {
    @Override
    public void handle(KeyEvent e) {
      switch (e.getCode()) {
        case UP:
        case KP_UP:
        case PAGE_UP:
          area.moveTo(initialPos);
          e.consume();
          break;
        case DOWN:
        case KP_DOWN:
        case PAGE_DOWN:
          area.moveTo(area.getLength());
          e.consume();
          break;
        // ensure always that caret position is >= initialPos
        case LEFT:
        case KP_LEFT:
        case BACK_SPACE:
          if (area.getCaretPosition() == initialPos)
            e.consume();
          break;
        // return user response
        case ENTER:
          // after user release enter key return response
          if (e.getEventType() == KeyEvent.KEY_RELEASED)
            returnResponse();
          break;
        // nothing
        default:
          // change area input color
          if (initialPos < area.getLength()) {
            area.setStyle(initialPos, area.getLength(), "-fx-fill: #4a148c;");
          }
          break;
      }
    }
  };
  mouseListener = new EventHandler<MouseEvent>() {
    @Override
    public void handle(MouseEvent e) {
      EventType<? extends MouseEvent> type = e.getEventType();
      // disable mouse selection
      if (type == MouseEvent.DRAG_DETECTED || type == MouseEvent.MOUSE_DRAGGED)
        e.consume();
      // control caret position
      if (type == MouseEvent.MOUSE_CLICKED || type == MouseEvent.MOUSE_RELEASED || type == MouseEvent.MOUSE_PRESSED) {
        if (e.getButton() == MouseButton.PRIMARY) {
          if (area.getCaretPosition() < initialPos) {
            area.setDisable(true);
            area.moveTo(initialPos);
            area.setDisable(false);
          }
        } else {
          e.consume();
        }
      }
    }
  };
  stopListener = new ChangeListener<Boolean>() {
    @Override
    public void changed(ObservableValue obs, Boolean oldValue, Boolean newValue) {
      if (!newValue) {
        returnResponse();
      }
    }
  };
}
 
Example 4
Source File: CameraController.java    From FXyzLib with GNU General Public License v3.0 4 votes vote down vote up
private void handleMouseEvent(MouseEvent t) {

        if (t.getEventType() == MouseEvent.MOUSE_PRESSED) {
            switch (t.getButton()) {
                case PRIMARY:
                    handlePrimaryMousePress(t);
                    break;
                case MIDDLE:
                    handleMiddleMousePress(t);
                    break;
                case SECONDARY:
                    handleSecondaryMousePress(t);
                    break;
                default:
                    throw new AssertionError();
            }
            handleMousePress(t);
        } else if (t.getEventType() == MouseEvent.MOUSE_DRAGGED) {
            Point2D d = getMouseDelta(t);

            switch (t.getButton()) {
                case PRIMARY:
                    handlePrimaryMouseDrag(t, d, speed);
                    break;
                case MIDDLE:
                    handleMiddleMouseDrag(t, d, speed);
                    break;
                case SECONDARY:
                    handleSecondaryMouseDrag(t, d, speed);
                    break;
                default:
                    throw new AssertionError();
            }
        } else if (t.getEventType() == MouseEvent.MOUSE_MOVED) {
            handleMouseMoved(t, getMouseDelta(t), speed);
        } else if (t.getEventType() == MouseEvent.MOUSE_CLICKED) {
            switch (t.getButton()) {
                case PRIMARY:
                    handlePrimaryMouseClick(t);
                    break;
                case MIDDLE:
                    handleMiddleMouseClick(t);
                    break;
                case SECONDARY:
                    handleSecondaryMouseClick(t);
                    break;
                default:
                    throw new AssertionError();
            }
        }
    }