11package nl .tudelft .pooralien ;
22
3+ import nl .tudelft .pooralien .ui .Animation ;
4+ import nl .tudelft .pooralien .ui .MainScreen ;
5+ import nl .tudelft .pooralien .ui .RTLDragAnimation ;
6+ import nl .tudelft .pooralien .ui .TTBDragAnimation ;
7+
38import java .awt .event .MouseEvent ;
49import java .awt .event .MouseListener ;
510import java .awt .event .MouseMotionListener ;
6- import javax .swing .JFrame ;
711import java .awt .Point ;
812
913/**
1418public class MouseEventHandler implements MouseListener , MouseMotionListener {
1519
1620 private MouseEventHandler .MouseAction mouseAction ;
21+ private MainScreen mainScreen ;
22+ private Animation dragAnimation ;
1723
1824 /**
1925 * Initiate event mouse listeners on a given JFrame.
2026 *
21- * @param window the JFrame where where to listen for events
27+ * @param mainScreen the JFrame where where to listen for events
2228 */
23- public MouseEventHandler (JFrame window ) {
24- window .addMouseListener (this );
25- window .addMouseMotionListener (this );
29+ public MouseEventHandler (MainScreen mainScreen ) {
30+ mainScreen .addMouseListener (this );
31+ mainScreen .addMouseMotionListener (this );
32+ this .mainScreen = mainScreen ;
2633 }
2734
2835 /**
@@ -32,7 +39,6 @@ public MouseEventHandler(JFrame window) {
3239 * @param e the mouse event that was captured
3340 */
3441 public void mousePressed (MouseEvent e ) {
35- System .out .println ("Create MouseAction Object" );
3642 Point mousePosition = new Point (e .getX (), e .getY ());
3743 mouseAction = new MouseEventHandler .MouseAction (mousePosition );
3844 }
@@ -51,7 +57,11 @@ public void mouseReleased(MouseEvent e) {
5157 if (mouseAction .getMouseActionType () == MouseAction .CLICK_ACTION ) {
5258 System .out .println ("Click Action on x:" + xPos + ", y:" + yPos );
5359 } else {
54- System .out .println ("End Drag Animation" );
60+ if (dragAnimation == null ) {
61+ return ;
62+ }
63+ dragAnimation .end ();
64+ dragAnimation = null ;
5565 }
5666 }
5767
@@ -111,10 +121,17 @@ public void mouseDragged(MouseEvent e) {
111121 mouseAction .setPosition (mousePosition );
112122
113123 if (mouseAction .getMouseActionType () != MouseAction .CLICK_ACTION ) {
124+ Point p = e .getPoint ();
125+ if (dragAnimation != null ) {
126+ dragAnimation .update (p );
127+ return ;
128+ }
114129 if (mouseAction .getMouseActionType () == MouseAction .HORIZONTAL_DRAG_ACTION ) {
115- System .out .println ("Animate DRAG Horizontal x:" + e .getX () + ", y:" + e .getY ());
130+ dragAnimation = new RTLDragAnimation (mainScreen );
131+ dragAnimation .start (p );
116132 } else if (mouseAction .getMouseActionType () == MouseAction .VERTICAL_DRAG_ACTION ) {
117- System .out .println ("Animate DRAG Vertical x:" + e .getX () + ", y:" + e .getY ());
133+ dragAnimation = new TTBDragAnimation (mainScreen );
134+ dragAnimation .start (p );
118135 }
119136 }
120137 }
@@ -133,8 +150,6 @@ public class MouseAction {
133150 private Point startPoint ;
134151 private Point currentPoint ;
135152
136- //private int xPosStart, yPosStart;
137- //private int xPosCurrent, yPosCurrent;
138153 private int mouseActionType ;
139154
140155
0 commit comments