Skip to content
Snippets Groups Projects
Commit 52a69581 authored by Guyslain's avatar Guyslain
Browse files

Amélioration de l'interface souris (clic pour changer l'état, drag pour le copier)

parent fce9dbcc
No related branches found
No related tags found
No related merge requests found
......@@ -3,12 +3,12 @@ package view;
import datastruct.Coordinate;
import javafx.scene.input.MouseEvent;
public class FillingMouseListener implements MouseListener {
public class DraggingListener implements MouseListener {
private final MatrixPane matrix;
private final Coordinate source;
public FillingMouseListener(MatrixPane matrix, Coordinate source) {
public DraggingListener(MatrixPane matrix, Coordinate source) {
this.matrix = matrix;
this.source = source;
}
......@@ -29,9 +29,8 @@ public class FillingMouseListener implements MouseListener {
@Override
public void onMousePressed(MouseEvent event, Coordinate coordinate) {
this.matrix.getController().getSimulation().next(coordinate);
this.matrix.setMouseListener(
new FillingMouseListener(this.matrix, coordinate)
new MousePressedListener(this.matrix, coordinate)
);
}
......
......@@ -8,6 +8,8 @@ import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import java.util.List;
/**
* Created by Arnaud Labourel on 22/11/2018.
*/
......@@ -62,7 +64,11 @@ public class MatrixPane extends GridPane {
event -> this.startFullDrag()
);
cellRectangle.addEventHandler(
MouseDragEvent.MOUSE_DRAG_RELEASED,
MouseEvent.MOUSE_CLICKED,
event -> mouseListener.onMouseClicked(event, coord)
);
cellRectangle.addEventHandler(
MouseDragEvent.MOUSE_RELEASED,
event -> mouseListener.onMouseReleased(event, coord)
);
cellRectangle.addEventHandler(
......@@ -78,6 +84,8 @@ public class MatrixPane extends GridPane {
}
void resetWaitingListener() {
this.mouseListener = new WaitingMouseListener(this);
setMouseListener(new WaitingMouseListener(this));
}
}
......@@ -5,6 +5,7 @@ import javafx.scene.input.MouseEvent;
interface MouseListener {
default void onMouseClicked(MouseEvent event, Coordinate coordinate) {}
default void onMousePressed(MouseEvent event, Coordinate coordinate) {}
default void onMouseReleased(MouseEvent event, Coordinate coordinate) {}
default void onMouseEntered(MouseEvent event, Coordinate coordinate) {};
......
package view;
import datastruct.Coordinate;
import javafx.scene.input.MouseEvent;
public class MousePressedListener implements MouseListener {
private final Coordinate pressedCoordinate;
private final MatrixPane matrix;
public MousePressedListener(MatrixPane matrix, Coordinate coordinate) {
this.matrix = matrix;
this.pressedCoordinate = coordinate;
}
@Override
public void onMouseEntered(MouseEvent event, Coordinate coordinate) {
this.matrix.getController().getSimulation().copy(pressedCoordinate,coordinate);
this.matrix.setMouseListener(new DraggingListener(this.matrix, pressedCoordinate));
}
@Override
public void onMousePressed(MouseEvent event, Coordinate coordinate) {
this.matrix.setMouseListener(new MousePressedListener(this.matrix, coordinate));
}
@Override
public void onMouseReleased(MouseEvent event, Coordinate coordinate) {
if (coordinate.equals(pressedCoordinate)) {
this.matrix.getController().getSimulation().next(coordinate);
} else {
this.matrix.getController().getSimulation().copy(pressedCoordinate,coordinate);
}
this.matrix.resetWaitingListener();
}
}
......@@ -14,8 +14,7 @@ class WaitingMouseListener implements MouseListener {
@Override
public void onMousePressed(MouseEvent event, Coordinate coordinate) {
this.matrix.getController().getSimulation().next(coordinate);
this.matrix.setMouseListener(new FillingMouseListener(this.matrix, coordinate));
this.matrix.setMouseListener(new MousePressedListener(this.matrix, coordinate));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment