Search in sources :

Example 1 with AddMomentCommand

use of controller.command.AddMomentCommand in project uPMT by coco35700.

the class MainViewTransformations method addPaneOnDragListener.

/*
	 * Listener du panel qu'il y a entre plusieurs moment
	 * */
public static void addPaneOnDragListener(DropPane p, Main main) {
    p.setOnDragExited(new EventHandler<DragEvent>() {

        @Override
        public void handle(DragEvent event) {
            p.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY)));
        }
    });
    p.setOnDragOver(new EventHandler<DragEvent>() {

        public void handle(DragEvent event) {
            // setting the drag autorizations
            boolean cond = true;
            MomentExperience draggedMoment = null;
            try {
                draggedMoment = (MomentExperience) Serializer.deserialize((byte[]) event.getDragboard().getContent(MomentExpVBox.df));
                int pos = p.getCol();
                int i = ((Integer) event.getDragboard().getContent(MomentExpVBox.realCol));
                if (draggedMoment != null) {
                    if (!draggedMoment.hasParent()) {
                        // int pos = main.getGrid().getChildren().indexOf(p)/2;
                        if (p.hasMomentParent()) {
                            if (p.getMomentParent().getMoment().equals(draggedMoment))
                                cond = false;
                            else if (p.getMomentParent().isAChildOf(draggedMoment))
                                cond = false;
                        } else
                            cond = ((pos - i) > 1) || ((pos - i) < 0);
                    // System.out.println("pos-i="+(pos-i)+" -- 1 < "+(pos-i)+" < 0 ?"+cond);
                    } else {
                        if (p.hasMomentParent()) {
                            if (p.getMomentParent().getMoment().getID() == draggedMoment.getParentID()) {
                                cond = ((pos - i) > 1) || ((pos - i) < 0);
                            }
                        } else
                            cond = true;
                    }
                } else
                    cond = false;
            } catch (Exception e) {
            // System.out.println("null");
            }
            // System.out.println(Math.abs(i - pos));
            if ((event.getDragboard().getString().equals("ajoutMoment")) || (event.getDragboard().getString().equals("moveMoment") && cond)) {
                event.acceptTransferModes(TransferMode.ANY);
                // p.setBackground(new Background(new BackgroundFill(Color.GRAY, CornerRadii.EMPTY, Insets.EMPTY)));
                p.onDragOver(event.getDragboard().getString());
            }
            event.consume();
        }
    });
    p.setOnDragDropped(new EventHandler<DragEvent>() {

        public void handle(DragEvent event) {
            p.onDragExited();
            if (main.getCurrentDescription().getNumberOfMoments() == 0) {
                p.emptyProjectPane();
            }
            // int pos = main.getGrid().getColumnIndex(p)/2;
            int pos = p.getCol();
            if (event.getDragboard().getString().equals("ajoutMoment")) {
                AddMomentCommand cmd = null;
                MomentExperience moment = moment = new MomentExperience();
                if (event.getDragboard().getContent(DataFormat.HTML) != null) {
                    moment.setDescripteme((String) event.getDragboard().getContent(DataFormat.HTML));
                }
                if (p.hasMomentParent())
                    cmd = new AddMomentCommand(pos, moment, p.getMomentParent().getMoment(), main);
                else
                    cmd = new AddMomentCommand(pos, moment, main);
                cmd.execute();
                UndoCollector.INSTANCE.add(cmd);
            }
            if (event.getDragboard().getString().equals("moveMoment")) {
                // System.out.println("Panel, move a moment in index "+pos);
                MomentExperience serial = null;
                try {
                    serial = (MomentExperience) Serializer.deserialize((byte[]) event.getDragboard().getContent(MomentExpVBox.df));
                } catch (ClassNotFoundException | IOException e) {
                    e.printStackTrace();
                }
                if (p.hasMomentParent()) {
                    MoveMomentToMomentCommand cmd = new MoveMomentToMomentCommand(serial, p.getMomentParent().getMoment(), pos, main);
                    cmd.execute();
                    UndoCollector.INSTANCE.add(cmd);
                } else {
                    MoveMomentCommand cmd = new MoveMomentCommand(serial, pos, main);
                    cmd.execute();
                    UndoCollector.INSTANCE.add(cmd);
                }
            }
            // p.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY)));
            event.consume();
        }
    });
    p.setOnDragExited(new EventHandler<DragEvent>() {

        @Override
        public void handle(DragEvent arg0) {
            p.onDragExited();
            if (main.getCurrentDescription().getNumberOfMoments() == 0) {
                p.emptyProjectPane();
            }
        }
    });
}
Also used : DragEvent(javafx.scene.input.DragEvent) AddMomentCommand(controller.command.AddMomentCommand) Background(javafx.scene.layout.Background) BackgroundFill(javafx.scene.layout.BackgroundFill) MoveMomentCommand(controller.command.MoveMomentCommand) MomentExperience(model.MomentExperience) MoveMomentToMomentCommand(controller.command.MoveMomentToMomentCommand) IOException(java.io.IOException)

Example 2 with AddMomentCommand

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

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