use of javafx.scene.input.MouseEvent in project org.csstudio.display.builder by kasemir.
the class JFXRepresentation method createModelRoot.
/**
* Create scrollpane etc. for hosting the model
*
* @return ScrollPane
* @throws IllegalStateException if had already been called
*/
public final ScrollPane createModelRoot() {
if (model_root != null)
throw new IllegalStateException("Already created model root");
widget_parent = new Pane();
scroll_body = new Group(widget_parent);
if (isEditMode()) {
horiz_bound = new Line();
horiz_bound.getStyleClass().add("display_model_bounds");
horiz_bound.setStartX(0);
vert_bound = new Line();
vert_bound.getStyleClass().add("display_model_bounds");
vert_bound.setStartY(0);
scroll_body.getChildren().addAll(vert_bound, horiz_bound);
}
model_root = new ScrollPane(scroll_body);
final InvalidationListener resized = prop -> handleViewportChanges();
model_root.widthProperty().addListener(resized);
model_root.heightProperty().addListener(resized);
// Middle Button (Wheel press) drag panning started
final EventHandler<MouseEvent> onMousePressedHandler = evt -> {
if (evt.isMiddleButtonDown()) {
lastMouseCoordinates.set(new Point2D(evt.getX(), evt.getY()));
scroll_body.setCursor(Cursor.CLOSED_HAND);
evt.consume();
}
};
if (isEditMode())
scroll_body.addEventFilter(MouseEvent.MOUSE_PRESSED, onMousePressedHandler);
else
scroll_body.setOnMousePressed(onMousePressedHandler);
// Middle Button (Wheel press) drag panning function
final EventHandler<MouseEvent> onMouseDraggedHandler = evt -> {
if (evt.isMiddleButtonDown()) {
double deltaX = evt.getX() - lastMouseCoordinates.get().getX();
double extraWidth = scroll_body.getLayoutBounds().getWidth() - model_root.getViewportBounds().getWidth();
double deltaH = deltaX * (model_root.getHmax() - model_root.getHmin()) / extraWidth;
double desiredH = model_root.getHvalue() - deltaH;
model_root.setHvalue(Math.max(0, Math.min(model_root.getHmax(), desiredH)));
double deltaY = evt.getY() - lastMouseCoordinates.get().getY();
double extraHeight = scroll_body.getLayoutBounds().getHeight() - model_root.getViewportBounds().getHeight();
double deltaV = deltaY * (model_root.getHmax() - model_root.getHmin()) / extraHeight;
double desiredV = model_root.getVvalue() - deltaV;
model_root.setVvalue(Math.max(0, Math.min(model_root.getVmax(), desiredV)));
evt.consume();
}
};
if (isEditMode())
scroll_body.addEventFilter(MouseEvent.MOUSE_DRAGGED, onMouseDraggedHandler);
else
scroll_body.setOnMouseDragged(onMouseDraggedHandler);
// Middle Button (Wheel press) drag panning finished
final EventHandler<MouseEvent> onMouseReleasedHandler = evt -> {
if (scroll_body.getCursor() == Cursor.CLOSED_HAND) {
scroll_body.setCursor(Cursor.DEFAULT);
evt.consume();
}
};
if (isEditMode())
scroll_body.addEventFilter(MouseEvent.MOUSE_RELEASED, onMouseReleasedHandler);
else
scroll_body.setOnMouseReleased(onMouseReleasedHandler);
// also handle the wheel
if (isEditMode())
model_root.addEventFilter(ScrollEvent.ANY, evt -> {
if (evt.isControlDown()) {
evt.consume();
doWheelZoom(evt.getDeltaY(), evt.getX(), evt.getY());
}
});
else
widget_parent.addEventHandler(ScrollEvent.ANY, evt -> {
if (evt.isControlDown()) {
evt.consume();
ScrollEvent gevt = evt.copyFor(model_root, scroll_body);
doWheelZoom(evt.getDeltaY(), gevt.getX(), gevt.getY());
}
});
return model_root;
}
use of javafx.scene.input.MouseEvent in project org.csstudio.display.builder by kasemir.
the class JFXBaseRepresentation method createComponents.
/**
* {@inheritDoc}
*/
@Override
public Parent createComponents(final Parent parent) throws Exception {
jfx_node = createJFXNode();
if (jfx_node != null) {
// Order JFX children same as model widgets within their container
int index = -1;
final Optional<Widget> container = model_widget.getParent();
if (container.isPresent()) {
if (container.get() instanceof TabsWidget) {
// Locate model_widget inside one of the Tab's children
final List<TabItemProperty> tabs = ((TabsWidget) container.get()).propTabs().getValue();
for (TabItemProperty tab : tabs) {
final int i = tab.children().getValue().indexOf(model_widget);
if (i >= 0) {
index = i;
break;
}
}
} else
index = container.get().getProperty(ChildrenProperty.DESCRIPTOR).getValue().indexOf(model_widget);
}
if (index < 0)
JFXRepresentation.getChildren(parent).add(jfx_node);
else
JFXRepresentation.getChildren(parent).add(index, jfx_node);
if (toolkit.isEditMode()) {
// Any visible item can be 'clicked' to allow editor to 'select' it
final EventHandler<MouseEvent> detect_click = event -> {
if (event.isPrimaryButtonDown()) {
event.consume();
toolkit.fireClick(model_widget, event.isControlDown());
}
};
if (isFilteringEditModeClicks())
jfx_node.addEventFilter(MouseEvent.MOUSE_PRESSED, detect_click);
else
jfx_node.addEventHandler(MouseEvent.MOUSE_PRESSED, detect_click);
} else
jfx_node.setOnContextMenuRequested((event) -> {
event.consume();
toolkit.fireContextMenu(model_widget);
});
}
registerListeners();
updateChanges();
return getChildParent(parent);
}
use of javafx.scene.input.MouseEvent in project Java_poker by MrLuckUA.
the class Main method start.
@Override
public void start(Stage primaryStage) {
Group root = new Group();
// Load image background
Image menuBackground = new Image(getClass().getClassLoader().getResourceAsStream("menu/background.png"));
ImageView menuBackgroundView = new ImageView(menuBackground);
menuBackgroundView.setFitHeight(menuBackground.getHeight());
menuBackgroundView.setFitWidth(menuBackground.getWidth());
// Add menuBackgroundView
root.getChildren().add(menuBackgroundView);
// Create scene
Scene scene = new Scene(root, menuBackground.getWidth(), menuBackground.getHeight());
// Load ask image
Image menuAsk = new Image(getClass().getClassLoader().getResourceAsStream("./menu/ask.png"));
ImageView menuAskView = new ImageView(menuAsk);
menuAskView.setFitHeight(menuAsk.getHeight());
menuAskView.setFitWidth(menuAsk.getWidth());
menuAskView.setY((int) (menuBackground.getHeight() / menuAsk.getHeight()));
menuAskView.setX((int) (menuBackground.getWidth() / menuAsk.getWidth()));
menuAskView.setCursor(Cursor.HAND);
menuAskView.setOnMouseClicked((MouseEvent event) -> {
Stage dialog = new Stage();
Image askInfo = new Image(getClass().getClassLoader().getResourceAsStream("poker_hands.jpg"));
ImageView askInfoView = new ImageView(askInfo);
dialog.setWidth(askInfo.getWidth());
dialog.setHeight(askInfo.getHeight());
dialog.setTitle("Info");
dialog.setResizable(false);
Group ss = new Group();
ss.getChildren().addAll(askInfoView);
ss.setOnMouseClicked(event1 -> dialog.close());
Scene lol = new Scene(ss);
dialog.setScene(lol);
dialog.show();
});
root.getChildren().add(menuAskView);
// Load start button
Image menuStartButton = new Image(getClass().getClassLoader().getResourceAsStream("./menu/button_start.png"));
ImageView menuStartButtonView = new ImageView(menuStartButton);
menuStartButtonView.setFitHeight(menuStartButton.getHeight());
menuStartButtonView.setFitWidth(menuStartButton.getWidth());
menuStartButtonView.setX((menuBackground.getWidth() - menuStartButton.getWidth()) / 2);
menuStartButtonView.setY((menuBackground.getHeight() - menuStartButton.getHeight()) / 3.6);
menuStartButtonView.setCursor(Cursor.HAND);
menuStartButtonView.setOnMouseClicked(event -> {
Table table = new Table();
Stage stage = new Stage();
try {
table.start(stage);
primaryStage.hide();
} catch (Exception e) {
e.printStackTrace();
}
if (!stage.isShowing()) {
primaryStage.show();
}
});
root.getChildren().add(menuStartButtonView);
// Load about button
Image menuAboutButton = new Image(getClass().getClassLoader().getResourceAsStream("./menu/button_about.png"));
ImageView menuAboutButtonView = new ImageView(menuAboutButton);
menuAboutButtonView.setFitHeight(menuAboutButton.getHeight());
menuAboutButtonView.setFitWidth(menuAboutButton.getWidth());
menuAboutButtonView.setX((menuBackground.getWidth() - menuAboutButton.getWidth()) / 2);
menuAboutButtonView.setY((menuBackground.getHeight() - menuAboutButton.getHeight()) / 2);
menuAboutButtonView.setCursor(Cursor.HAND);
menuAboutButtonView.setOnMouseClicked(event -> {
Stage dialog = new Stage();
dialog.setWidth(400);
dialog.setTitle("About");
dialog.setHeight(400);
dialog.setResizable(false);
Group ss = new Group();
Scene lol = new Scene(ss);
Button button = new Button("Close");
button.setDefaultButton(true);
button.setMinWidth(50);
button.setOnMouseClicked(event1 -> dialog.close());
ss.getChildren().add(button);
dialog.setScene(lol);
dialog.show();
});
root.getChildren().add(menuAboutButtonView);
// Load exit button
Image menuAExitButton = new Image(getClass().getClassLoader().getResourceAsStream("./menu/button_exit.png"));
ImageView menuExitButtonView = new ImageView(menuAExitButton);
menuExitButtonView.setFitHeight(menuAExitButton.getHeight());
menuExitButtonView.setFitWidth(menuAExitButton.getWidth());
menuExitButtonView.setX((menuBackground.getWidth() - menuAExitButton.getWidth()) / 2);
menuExitButtonView.setY((menuBackground.getHeight() - menuAExitButton.getHeight()) / 1.4);
menuExitButtonView.setCursor(Cursor.HAND);
menuExitButtonView.setOnMouseClicked(event -> {
System.out.println("Exit clicked!");
primaryStage.close();
});
root.getChildren().add(menuExitButtonView);
// Set title
primaryStage.setTitle("Texas Poker");
primaryStage.setScene(scene);
// Set min & max width and height
primaryStage.setResizable(false);
primaryStage.show();
}
use of javafx.scene.input.MouseEvent in project uPMT by coco35700.
the class MainViewTransformations method addBorderPaneMomentListener.
public static void addBorderPaneMomentListener(MomentExpVBox moment, Main main) {
moment.getMomentPane().setOnDragExited(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent event) {
moment.getMomentPane().setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY)));
}
});
moment.getMomentPane().setOnDragOver(new EventHandler<DragEvent>() {
public void handle(DragEvent event) {
// Checking if a type is already present
boolean doesntalreadyHasType = true;
String typeType = event.getDragboard().getRtf();
for (Node n : moment.getTypeSpace().getChildren()) {
TypeClassRepresentationController type = (TypeClassRepresentationController) n;
if (type.getClasse().getName().equals(typeType)) {
doesntalreadyHasType = false;
break;
}
}
boolean cond = true;
MomentExperience draggedMoment = null;
try {
draggedMoment = (MomentExperience) Serializer.deserialize((byte[]) event.getDragboard().getContent(MomentExpVBox.df));
if (draggedMoment != null) {
// draggedMoment ne peut pas etre depose sur lui meme
if (draggedMoment.equals(moment.getMoment()))
cond = false;
else // draggedMoment ne peut pas etre depose sur ses enfants
if (moment.isAChildOf(draggedMoment))
cond = false;
else // draggedMoment ne peut pas etre depose sur son pere direct
if (moment.isDirectParentOf(draggedMoment))
cond = false;
} else
cond = false;
} catch (Exception e) {
}
// setting the drag autorizations
if (((event.getDragboard().getString().equals("ajoutType") && doesntalreadyHasType) || event.getDragboard().getString().equals("ajoutMoment") || event.getDragboard().getString().equals("moveMoment")) && cond) {
event.acceptTransferModes(TransferMode.ANY);
moment.getMomentPane().setBackground(new Background(new BackgroundFill(Color.GRAY, CornerRadii.EMPTY, Insets.EMPTY)));
}
event.consume();
}
});
moment.getMomentPane().setOnDragDropped(new EventHandler<DragEvent>() {
public void handle(DragEvent event) {
if (event.getDragboard().getString().equals("ajoutType")) {
AddTypeCommand cmd = new AddTypeCommand(moment, event, main);
cmd.execute();
UndoCollector.INSTANCE.add(cmd);
}
if (event.getDragboard().getString().equals("ajoutMoment")) {
// Add Moment to a Moment : int: index in sous-moment / Moment: parentMoment / Main
MomentExperience newMoment = newMoment = new MomentExperience();
if (event.getDragboard().getContent(DataFormat.HTML) != null) {
newMoment.setDescripteme((String) event.getDragboard().getContent(DataFormat.HTML));
}
AddMomentCommand cmd = new AddMomentCommand(moment.getMoment().getSubMoments().size(), newMoment, moment.getMoment(), main);
cmd.execute();
UndoCollector.INSTANCE.add(cmd);
}
if (event.getDragboard().getString().equals("moveMoment")) {
MomentExperience serial = null;
try {
serial = (MomentExperience) Serializer.deserialize((byte[]) event.getDragboard().getContent(MomentExpVBox.df));
} catch (ClassNotFoundException | IOException e) {
e.printStackTrace();
}
MoveMomentToMomentCommand cmd = new MoveMomentToMomentCommand(serial, moment.getMoment(), moment.getMoment().getSubMoments().size(), main);
cmd.execute();
UndoCollector.INSTANCE.add(cmd);
}
event.setDropCompleted(true);
moment.getMomentPane().setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY)));
event.consume();
}
});
// Click the moment panel
moment.getMomentPane().setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if (event.getButton().equals(MouseButton.PRIMARY)) {
main.setCurrentMoment(moment);
boolean childHasFocus = false;
for (Node type : moment.getTypeSpace().getChildren()) {
TypeClassRepresentationController tt = (TypeClassRepresentationController) type;
if (tt.isFocused()) {
childHasFocus = true;
}
}
if (!childHasFocus) {
moment.requestFocus();
}
String print = "row: " + moment.getMoment().getRow() + "; column: " + moment.getMoment().getGridCol() + "; parent: balek";
/*if(moment.hasParent()) print+=moment.getMoment().getParent(main).getNom();
else print+=" null";*/
// System.out.println(print);
}
}
});
moment.focusedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue, Boolean newPropertyValue) {
if (newPropertyValue) {
moment.setBorderColor("#039ED3");
} else {
moment.setBorderColor("black");
}
}
});
}
use of javafx.scene.input.MouseEvent in project uPMT by coco35700.
the class InterviewTreeView method updateItem.
@Override
protected void updateItem(DescriptionInterview elem, boolean empty) {
super.updateItem(elem, empty);
if (empty || elem == null) {
setText(null);
setGraphic(null);
} else {
// if elem is an interview of the project
DescriptionInterview desc = ((DescriptionInterview) elem);
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/view/EntretienTreeView.fxml"));
InterviewTreeViewController controller = new InterviewTreeViewController(desc, this);
this.controller = controller;
loader.setController(controller);
BorderPane elementPane = (BorderPane) loader.load();
this.setGraphic(elementPane);
} catch (IOException e) {
e.printStackTrace();
}
if (desc.getName().equals("Interviews")) {
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/view/RootEntretienTreeView.fxml"));
RootInterviewTreeViewController controller = new RootInterviewTreeViewController(desc, main);
this.controller = controller;
loader.setController(controller);
BorderPane elementPane;
elementPane = (BorderPane) loader.load();
this.setGraphic(elementPane);
} catch (IOException e) {
e.printStackTrace();
}
} else {
this.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
main.setCurrentDescription(desc);
main.getTreeViewInterview().refresh();
main.getMainViewController().updateGrid();
}
});
if ((!main.getCurrentProject().getInterviews().isEmpty()) && desc.equals(main.getCurrentDescription())) {
((InterviewTreeViewController) controller).setSelected("blue");
} else {
((InterviewTreeViewController) controller).setSelected("black");
}
}
}
}
Aggregations