Search in sources :

Example 51 with MouseEvent

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;
}
Also used : Line(javafx.scene.shape.Line) Color(java.awt.Color) PredefinedColorMaps(org.csstudio.display.builder.model.properties.PredefinedColorMaps) GaugeWidget(org.csstudio.display.builder.model.widgets.GaugeWidget) PictureWidget(org.csstudio.display.builder.model.widgets.PictureWidget) RegistryFactory(org.eclipse.core.runtime.RegistryFactory) EllipseWidget(org.csstudio.display.builder.model.widgets.EllipseWidget) TextEntryRepresentation(org.csstudio.display.builder.representation.javafx.widgets.TextEntryRepresentation) TextUpdateWidget(org.csstudio.display.builder.model.widgets.TextUpdateWidget) ScrollBarRepresentation(org.csstudio.display.builder.representation.javafx.widgets.ScrollBarRepresentation) Line(javafx.scene.shape.Line) Future(java.util.concurrent.Future) TankWidget(org.csstudio.display.builder.model.widgets.TankWidget) XYPlotWidget(org.csstudio.display.builder.model.widgets.plots.XYPlotWidget) ScrollPane(javafx.scene.control.ScrollPane) XYPlotRepresentation(org.csstudio.display.builder.representation.javafx.widgets.plots.XYPlotRepresentation) Map(java.util.Map) MultiStateLEDWidget(org.csstudio.display.builder.model.widgets.MultiStateLEDWidget) Point2D(javafx.geometry.Point2D) WidgetRepresentation(org.csstudio.display.builder.representation.WidgetRepresentation) Transform(javafx.scene.transform.Transform) ThermometerWidget(org.csstudio.display.builder.model.widgets.ThermometerWidget) NamedColorMappings(org.csstudio.javafx.rtplot.NamedColorMappings) LinearMeterWidget(org.csstudio.display.builder.model.widgets.LinearMeterWidget) PolygonWidget(org.csstudio.display.builder.model.widgets.PolygonWidget) TabsWidget(org.csstudio.display.builder.model.widgets.TabsWidget) ScaledSliderRepresentation(org.csstudio.display.builder.representation.javafx.widgets.ScaledSliderRepresentation) BoolButtonWidget(org.csstudio.display.builder.model.widgets.BoolButtonWidget) ArcRepresentation(org.csstudio.display.builder.representation.javafx.widgets.ArcRepresentation) Group(javafx.scene.Group) Platform(javafx.application.Platform) CountDownLatch(java.util.concurrent.CountDownLatch) LEDRepresentation(org.csstudio.display.builder.representation.javafx.widgets.LEDRepresentation) RadioRepresentation(org.csstudio.display.builder.representation.javafx.widgets.RadioRepresentation) TabsRepresentation(org.csstudio.display.builder.representation.javafx.widgets.TabsRepresentation) ColorMappingFunction(org.csstudio.javafx.rtplot.ColorMappingFunction) BasicStroke(java.awt.BasicStroke) ObservableList(javafx.collections.ObservableList) CheckBoxWidget(org.csstudio.display.builder.model.widgets.CheckBoxWidget) TableWidget(org.csstudio.display.builder.model.widgets.TableWidget) Bounds(javafx.geometry.Bounds) ClockRepresentation(org.csstudio.display.builder.representation.javafx.widgets.ClockRepresentation) ArcWidget(org.csstudio.display.builder.model.widgets.ArcWidget) JFXBaseRepresentation(org.csstudio.display.builder.representation.javafx.widgets.JFXBaseRepresentation) EmbeddedDisplayRepresentation(org.csstudio.display.builder.representation.javafx.widgets.EmbeddedDisplayRepresentation) KnobWidget(org.csstudio.display.builder.model.widgets.KnobWidget) GroupRepresentation(org.csstudio.display.builder.representation.javafx.widgets.GroupRepresentation) ThumbWheelWidget(org.csstudio.display.builder.model.widgets.ThumbWheelWidget) ImageWidget(org.csstudio.display.builder.model.widgets.plots.ImageWidget) TextSymbolWidget(org.csstudio.display.builder.model.widgets.TextSymbolWidget) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) RectangleRepresentation(org.csstudio.display.builder.representation.javafx.widgets.RectangleRepresentation) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) TextEntryWidget(org.csstudio.display.builder.model.widgets.TextEntryWidget) EllipseRepresentation(org.csstudio.display.builder.representation.javafx.widgets.EllipseRepresentation) MeterWidget(org.csstudio.display.builder.model.widgets.MeterWidget) Node(javafx.scene.Node) ImagePattern(javafx.scene.paint.ImagePattern) TableRepresentation(org.csstudio.display.builder.representation.javafx.widgets.TableRepresentation) Background(javafx.scene.layout.Background) File(java.io.File) ImageRepresentation(org.csstudio.display.builder.representation.javafx.widgets.plots.ImageRepresentation) ExecutionException(java.util.concurrent.ExecutionException) ArrayWidget(org.csstudio.display.builder.model.widgets.ArrayWidget) Cursor(javafx.scene.Cursor) FileChooser(javafx.stage.FileChooser) ComboWidget(org.csstudio.display.builder.model.widgets.ComboWidget) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) GaugeRepresentation(org.csstudio.display.builder.representation.javafx.widgets.GaugeRepresentation) Widget(org.csstudio.display.builder.model.Widget) NamedColorMapping(org.csstudio.javafx.rtplot.NamedColorMapping) EventHandler(javafx.event.EventHandler) ToolkitRepresentation(org.csstudio.display.builder.representation.ToolkitRepresentation) ComboRepresentation(org.csstudio.display.builder.representation.javafx.widgets.ComboRepresentation) LinearMeterRepresentation(org.csstudio.display.builder.representation.javafx.widgets.LinearMeterRepresentation) WebBrowserRepresentation(org.csstudio.display.builder.representation.javafx.widgets.WebBrowserRepresentation) TimeoutException(java.util.concurrent.TimeoutException) RenderingHints(java.awt.RenderingHints) ChoiceDialog(javafx.scene.control.ChoiceDialog) ClockWidget(org.csstudio.display.builder.model.widgets.ClockWidget) ProgressBarWidget(org.csstudio.display.builder.model.widgets.ProgressBarWidget) InvalidationListener(javafx.beans.InvalidationListener) PictureRepresentation(org.csstudio.display.builder.representation.javafx.widgets.PictureRepresentation) Parent(javafx.scene.Parent) RectangleWidget(org.csstudio.display.builder.model.widgets.RectangleWidget) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) ActionButtonRepresentation(org.csstudio.display.builder.representation.javafx.widgets.ActionButtonRepresentation) SpinnerRepresentation(org.csstudio.display.builder.representation.javafx.widgets.SpinnerRepresentation) WidgetRepresentationFactory(org.csstudio.display.builder.representation.WidgetRepresentationFactory) Status(javafx.scene.media.MediaPlayer.Status) Pane(javafx.scene.layout.Pane) Alert(javafx.scene.control.Alert) MeterRepresentation(org.csstudio.display.builder.representation.javafx.widgets.MeterRepresentation) BufferedImage(java.awt.image.BufferedImage) ArrayRepresentation(org.csstudio.display.builder.representation.javafx.widgets.ArrayRepresentation) PolylineWidget(org.csstudio.display.builder.model.widgets.PolylineWidget) ThermometerRepresentation(org.csstudio.display.builder.representation.javafx.widgets.ThermometerRepresentation) List(java.util.List) ByteMonitorWidget(org.csstudio.display.builder.model.widgets.ByteMonitorWidget) RadioWidget(org.csstudio.display.builder.model.widgets.RadioWidget) LabelRepresentation(org.csstudio.display.builder.representation.javafx.widgets.LabelRepresentation) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) Scale(javafx.scene.transform.Scale) Optional(java.util.Optional) ThumbWheelRepresentation(org.csstudio.display.builder.representation.javafx.widgets.ThumbWheelRepresentation) Media(javafx.scene.media.Media) NavigationTabsWidget(org.csstudio.display.builder.model.widgets.NavigationTabsWidget) ProgressBarRepresentation(org.csstudio.display.builder.representation.javafx.widgets.ProgressBarRepresentation) NavigationTabsRepresentation(org.csstudio.display.builder.representation.javafx.widgets.NavigationTabsRepresentation) CornerRadii(javafx.scene.layout.CornerRadii) Scene(javafx.scene.Scene) DisplayModel(org.csstudio.display.builder.model.DisplayModel) LEDWidget(org.csstudio.display.builder.model.widgets.LEDWidget) ButtonType(javafx.scene.control.ButtonType) MouseEvent(javafx.scene.input.MouseEvent) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Level(java.util.logging.Level) Insets(javafx.geometry.Insets) Graphics2D(java.awt.Graphics2D) ScrollBarWidget(org.csstudio.display.builder.model.widgets.ScrollBarWidget) WidgetColor(org.csstudio.display.builder.model.properties.WidgetColor) TextUpdateRepresentation(org.csstudio.display.builder.representation.javafx.widgets.TextUpdateRepresentation) BackgroundFill(javafx.scene.layout.BackgroundFill) TankRepresentation(org.csstudio.display.builder.representation.javafx.widgets.TankRepresentation) DigitalClockRepresentation(org.csstudio.display.builder.representation.javafx.widgets.DigitalClockRepresentation) WebBrowserWidget(org.csstudio.display.builder.model.widgets.WebBrowserWidget) DigitalClockWidget(org.csstudio.display.builder.model.widgets.DigitalClockWidget) TextSymbolRepresentation(org.csstudio.display.builder.representation.javafx.widgets.TextSymbolRepresentation) MediaPlayer(javafx.scene.media.MediaPlayer) ByteMonitorRepresentation(org.csstudio.display.builder.representation.javafx.widgets.ByteMonitorRepresentation) PolylineRepresentation(org.csstudio.display.builder.representation.javafx.widgets.PolylineRepresentation) ObjectProperty(javafx.beans.property.ObjectProperty) CheckBoxRepresentation(org.csstudio.display.builder.representation.javafx.widgets.CheckBoxRepresentation) SymbolRepresentation(org.csstudio.display.builder.representation.javafx.widgets.SymbolRepresentation) WritableImage(javafx.scene.image.WritableImage) EmbeddedDisplayWidget(org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget) SpinnerWidget(org.csstudio.display.builder.model.widgets.SpinnerWidget) SymbolWidget(org.csstudio.display.builder.model.widgets.SymbolWidget) ScrollEvent(javafx.scene.input.ScrollEvent) Styles(org.csstudio.javafx.Styles) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ScaledSliderWidget(org.csstudio.display.builder.model.widgets.ScaledSliderWidget) BoolButtonRepresentation(org.csstudio.display.builder.representation.javafx.widgets.BoolButtonRepresentation) PolygonRepresentation(org.csstudio.display.builder.representation.javafx.widgets.PolygonRepresentation) ActionButtonWidget(org.csstudio.display.builder.model.widgets.ActionButtonWidget) KnobRepresentation(org.csstudio.display.builder.representation.javafx.widgets.KnobRepresentation) UntypedWidgetPropertyListener(org.csstudio.display.builder.model.UntypedWidgetPropertyListener) WidgetPropertyListener(org.csstudio.display.builder.model.WidgetPropertyListener) SwingFXUtils(javafx.embed.swing.SwingFXUtils) Window(javafx.stage.Window) DialogHelper(org.csstudio.javafx.DialogHelper) MultiStateLEDRepresentation(org.csstudio.display.builder.representation.javafx.widgets.MultiStateLEDRepresentation) Group(javafx.scene.Group) MouseEvent(javafx.scene.input.MouseEvent) Point2D(javafx.geometry.Point2D) ScrollEvent(javafx.scene.input.ScrollEvent) ScrollPane(javafx.scene.control.ScrollPane) InvalidationListener(javafx.beans.InvalidationListener) ScrollPane(javafx.scene.control.ScrollPane) Pane(javafx.scene.layout.Pane)

Example 52 with MouseEvent

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);
}
Also used : EventHandler(javafx.event.EventHandler) DisplayModel(org.csstudio.display.builder.model.DisplayModel) TabsWidget(org.csstudio.display.builder.model.widgets.TabsWidget) Node(javafx.scene.Node) MouseEvent(javafx.scene.input.MouseEvent) CommonWidgetProperties(org.csstudio.display.builder.model.properties.CommonWidgetProperties) Objects(java.util.Objects) JFXRepresentation(org.csstudio.display.builder.representation.javafx.JFXRepresentation) Parent(javafx.scene.Parent) List(java.util.List) ChildrenProperty(org.csstudio.display.builder.model.ChildrenProperty) Optional(java.util.Optional) DirtyFlag(org.csstudio.display.builder.model.DirtyFlag) WidgetRepresentation(org.csstudio.display.builder.representation.WidgetRepresentation) Widget(org.csstudio.display.builder.model.Widget) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) TabItemProperty(org.csstudio.display.builder.model.widgets.TabsWidget.TabItemProperty) TabsWidget(org.csstudio.display.builder.model.widgets.TabsWidget) TabItemProperty(org.csstudio.display.builder.model.widgets.TabsWidget.TabItemProperty) MouseEvent(javafx.scene.input.MouseEvent) TabsWidget(org.csstudio.display.builder.model.widgets.TabsWidget) Widget(org.csstudio.display.builder.model.Widget)

Example 53 with MouseEvent

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();
}
Also used : Group(javafx.scene.Group) MouseEvent(javafx.scene.input.MouseEvent) Button(javafx.scene.control.Button) Stage(javafx.stage.Stage) ImageView(javafx.scene.image.ImageView) Image(javafx.scene.image.Image) Scene(javafx.scene.Scene)

Example 54 with MouseEvent

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");
            }
        }
    });
}
Also used : TypeClassRepresentationController(controller.TypeClassRepresentationController) MouseEvent(javafx.scene.input.MouseEvent) Background(javafx.scene.layout.Background) BackgroundFill(javafx.scene.layout.BackgroundFill) Node(javafx.scene.Node) MoveMomentToMomentCommand(controller.command.MoveMomentToMomentCommand) IOException(java.io.IOException) DragEvent(javafx.scene.input.DragEvent) AddMomentCommand(controller.command.AddMomentCommand) AddTypeCommand(controller.command.AddTypeCommand) MomentExperience(model.MomentExperience)

Example 55 with MouseEvent

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");
            }
        }
    }
}
Also used : BorderPane(javafx.scene.layout.BorderPane) MouseEvent(javafx.scene.input.MouseEvent) DescriptionInterview(model.DescriptionInterview) IOException(java.io.IOException) FXMLLoader(javafx.fxml.FXMLLoader)

Aggregations

MouseEvent (javafx.scene.input.MouseEvent)93 KeyCode (javafx.scene.input.KeyCode)33 Scene (javafx.scene.Scene)32 Group (javafx.scene.Group)29 PerspectiveCamera (javafx.scene.PerspectiveCamera)23 PointLight (javafx.scene.PointLight)22 Rotate (javafx.scene.transform.Rotate)21 List (java.util.List)20 EventHandler (javafx.event.EventHandler)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)17 Color (javafx.scene.paint.Color)16 AnimationTimer (javafx.animation.AnimationTimer)14 Image (javafx.scene.image.Image)13 Font (javafx.scene.text.Font)13 ArrayList (java.util.ArrayList)12 Pane (javafx.scene.layout.Pane)12 KeyFrame (javafx.animation.KeyFrame)10 Timeline (javafx.animation.Timeline)10 Insets (javafx.geometry.Insets)10 ImageView (javafx.scene.image.ImageView)10