Search in sources :

Example 1 with AddTypeCommand

use of controller.command.AddTypeCommand 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)

Aggregations

TypeClassRepresentationController (controller.TypeClassRepresentationController)1 AddMomentCommand (controller.command.AddMomentCommand)1 AddTypeCommand (controller.command.AddTypeCommand)1 MoveMomentToMomentCommand (controller.command.MoveMomentToMomentCommand)1 IOException (java.io.IOException)1 Node (javafx.scene.Node)1 DragEvent (javafx.scene.input.DragEvent)1 MouseEvent (javafx.scene.input.MouseEvent)1 Background (javafx.scene.layout.Background)1 BackgroundFill (javafx.scene.layout.BackgroundFill)1 MomentExperience (model.MomentExperience)1