Search in sources :

Example 6 with MomentExperience

use of model.MomentExperience 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 7 with MomentExperience

use of model.MomentExperience in project uPMT by coco35700.

the class IStats method nbOccurrences.

/**
 * Counts the number of occurences of appearance of a specific category in a specific interview
 * @param interview the current interview
 * @param category the current category of the schema
 * @return the number of times the category has been used in one specific interview
 */
public static int nbOccurrences(DescriptionInterview interview, Category category) {
    int cpt = 0;
    if (instance.mItwMoments.get(interview) == null) {
        for (MomentExperience mom_it : interview.getMoments()) {
            // we start with the first-level moments
            // then we find all the sub-moments employed in the model of the concerned interview
            instance.lookingForMoments(mom_it);
        }
        // we copy only the values of the moments found for 1 interview
        instance.mItwMoments.put(interview, new ArrayList<MomentExperience>(instance.mMomentsTmp));
        // we clear it because we need it free for the next interview
        instance.mMomentsTmp.clear();
    }
    for (MomentExperience moment : instance.mItwMoments.get(interview)) {
        if (moment.getTypes().contains(category)) {
            // then we compare if we find any category of the scheme in the model
            cpt++;
        }
    }
    return cpt;
}
Also used : MomentExperience(model.MomentExperience)

Aggregations

MomentExperience (model.MomentExperience)7 IOException (java.io.IOException)3 DropPane (controller.DropPane)2 MomentExpVBox (controller.MomentExpVBox)2 AddMomentCommand (controller.command.AddMomentCommand)2 MoveMomentToMomentCommand (controller.command.MoveMomentToMomentCommand)2 DragEvent (javafx.scene.input.DragEvent)2 Background (javafx.scene.layout.Background)2 BackgroundFill (javafx.scene.layout.BackgroundFill)2 ColumnConstraints (javafx.scene.layout.ColumnConstraints)2 TypeClassRepresentationController (controller.TypeClassRepresentationController)1 AddTypeCommand (controller.command.AddTypeCommand)1 MoveMomentCommand (controller.command.MoveMomentCommand)1 ObjectOutputStream (java.io.ObjectOutputStream)1 PrintWriter (java.io.PrintWriter)1 LinkedList (java.util.LinkedList)1 Node (javafx.scene.Node)1 AlertType (javafx.scene.control.Alert.AlertType)1 ButtonType (javafx.scene.control.ButtonType)1 MouseEvent (javafx.scene.input.MouseEvent)1