Skip to content

Commit cd915d7

Browse files
committed
Merge pull request #76 from ProgrammingLife3/zoombarDrag
You can now drag the zoombar!
2 parents 0d44e4c + f897494 commit cd915d7

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

src/main/java/tudelft/ti2806/pl3/zoombar/ZoomBarController.java

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
import tudelft.ti2806.pl3.visualization.GraphMovedListener;
99

1010
import java.awt.Component;
11+
import java.awt.event.MouseAdapter;
1112
import java.awt.event.MouseEvent;
12-
import java.awt.event.MouseListener;
13+
import java.awt.event.MouseMotionAdapter;
1314

1415
/**
1516
* Controller that controls the zoom bar at the bottom of the screen.
1617
* The zoom bar is used to navigate through and zoom in on the graph.
1718
* Created by Boris Mattijssen on 06-05-15.
1819
*/
19-
public class ZoomBarController implements Controller, GraphMovedListener, GraphLoadedListener, MouseListener {
20+
public class ZoomBarController implements Controller, GraphMovedListener, GraphLoadedListener {
2021

2122
private ZoomBarView zoomBarView;
2223
private ControllerContainer cc;
@@ -31,7 +32,8 @@ public class ZoomBarController implements Controller, GraphMovedListener, GraphL
3132
public ZoomBarController(ControllerContainer cc) {
3233
this.cc = cc;
3334
zoomBarView = new ZoomBarView();
34-
zoomBarView.addMouseListener(this);
35+
zoomBarView.addMouseListener(new ZoomBarMouseClicked());
36+
zoomBarView.addMouseMotionListener(new ZoomBarMouseDragged());
3537
cc.getGraphController().addGraphMovedListener(this);
3638
cc.getGraphController().getGraphView().addGraphLoadedListener(this);
3739
cc.getGraphController().getFilteredObservable().addObserver(zoomBarView);
@@ -63,33 +65,38 @@ private void updateView() {
6365
zoomBarView.moved();
6466
}
6567

66-
@Override
67-
public void mouseClicked(MouseEvent e) {
68+
/**
69+
* Navigate to the graph on the given mouse x position.
70+
*
71+
* @param mouseX
72+
* The mouse x position
73+
*/
74+
private void navigateInGraph(float mouseX) {
6875
double size = cc.getGraphController().getGraphView().getGraphDimension();
69-
float factor = (float) e.getX()
76+
float factor = (float) mouseX
7077
/ (float) ScreenSize.getInstance().getWidth();
7178
float newPos = (float) (factor * size);
7279
cc.getGraphController().moveView(newPos);
7380
}
7481

75-
@Override
76-
public void mousePressed(MouseEvent e) {
77-
78-
}
79-
80-
@Override
81-
public void mouseReleased(MouseEvent e) {
82-
83-
}
84-
85-
@Override
86-
public void mouseEntered(MouseEvent e) {
87-
82+
/**
83+
* Class that handles the mouse click.
84+
*/
85+
private class ZoomBarMouseClicked extends MouseAdapter {
86+
@Override
87+
public void mouseClicked(MouseEvent e) {
88+
navigateInGraph(e.getX());
89+
}
8890
}
8991

90-
@Override
91-
public void mouseExited(MouseEvent e) {
92-
92+
/**
93+
* Class that handles the mouse drag.
94+
*/
95+
private class ZoomBarMouseDragged extends MouseMotionAdapter {
96+
@Override
97+
public void mouseDragged(MouseEvent e) {
98+
navigateInGraph(e.getX());
99+
}
93100
}
94101

95102
public Component getPanel() {

0 commit comments

Comments
 (0)