4
4
import javafx .scene .canvas .Canvas ;
5
5
import javafx .scene .canvas .GraphicsContext ;
6
6
import javafx .scene .input .MouseEvent ;
7
+ import javafx .scene .layout .AnchorPane ;
7
8
import javafx .scene .paint .Color ;
8
9
9
10
/**
@@ -14,11 +15,11 @@ class MiniMapController {
14
15
private final Canvas miniMap ;
15
16
private final int size ;
16
17
17
- private boolean visible = false ;
18
+ private boolean visible = true ;
18
19
private GraphController graphController ;
19
20
private GuiController guiController ;
20
21
21
- private final static int SPLIT_PANEL_WIDTH = 15 ;
22
+ private static final int SPLIT_PANEL_WIDTH = 15 ;
22
23
23
24
/**
24
25
* Constructor for the miniMap.
@@ -28,6 +29,9 @@ class MiniMapController {
28
29
*/
29
30
MiniMapController (Canvas miniMap , int size ) {
30
31
this .miniMap = miniMap ;
32
+ AnchorPane .setRightAnchor (miniMap , 0.d );
33
+ AnchorPane .setLeftAnchor (miniMap , 0.d );
34
+ AnchorPane .setBottomAnchor (miniMap , 0.d );
31
35
Platform .runLater (this .miniMap ::toFront );
32
36
miniMap .setVisible (visible );
33
37
this .size = size ;
@@ -39,18 +43,32 @@ class MiniMapController {
39
43
*/
40
44
private void drawMiniMap () {
41
45
GraphicsContext gc = miniMap .getGraphicsContext2D ();
42
- gc .setFill (Color .LIGHTGRAY );
46
+ gc .setFill (Color .BURLYWOOD );
43
47
gc .fillRect (0 , 0 , miniMap .getWidth (), 50 );
44
48
45
49
gc .setStroke (Color .BLACK );
46
50
gc .setLineWidth (2 );
47
- gc .strokeLine (0 , 25 , miniMap .getWidth (), 25 );
51
+ gc .strokeLine (0 , 49 , miniMap .getWidth (), 49 );
52
+ gc .strokeLine (0 , 1 , miniMap .getWidth (), 1 );
53
+
54
+ for (int i = 0 ; i <= 10 ; i ++) {
55
+ gc .setStroke (Color .BLACK );
56
+ gc .setLineWidth (1 );
57
+ gc .strokeLine (i * miniMap .getWidth () / 10 , 50 , i * miniMap .getWidth () / 10 , 0 );
58
+ }
59
+ for (int i = 0 ; i < 10 ; i ++) {
60
+ gc .setFill (Color .BLACK );
61
+ gc .fillText (String .valueOf (i * graphController .getGraph ().size () / 10 ),
62
+ i * miniMap .getWidth () / 10 , 45 );
63
+ }
48
64
}
49
65
50
66
/**
51
67
* Toggle the visibility of the MiniMap.
68
+ *
69
+ * @param centerNodeId node to be centered on.
52
70
*/
53
- public void toggleVisibility (int centerNodeId ) {
71
+ void toggleVisibility (int centerNodeId ) {
54
72
visible = !visible ;
55
73
this .miniMap .setVisible (visible );
56
74
if (visible ) {
@@ -59,15 +77,23 @@ public void toggleVisibility(int centerNodeId) {
59
77
}
60
78
}
61
79
62
- public void handleMouse (MouseEvent event ) {
63
- double locX = event .getSceneX () - this .guiController .anchorLeftControlPanel .getWidth () - SPLIT_PANEL_WIDTH ;
80
+ /**
81
+ * Method to handle the event of the mouse.
82
+ *
83
+ * @param event MouseEvent to be processed.
84
+ */
85
+ private void handleMouse (MouseEvent event ) {
86
+ double locX = event .getSceneX () - this .guiController .getAnchorLeftControlPanel ().getWidth () - SPLIT_PANEL_WIDTH ;
64
87
double ratio = locX / miniMap .getBoundsInParent ().getMaxX ();
65
88
int centerNodeId = (int ) Math .ceil (graphController .getGraph ().size () * ratio );
66
- System . out . println ( "clicked" );
67
- Platform . runLater (() -> graphController . draw (centerNodeId , 10 ) );
89
+ guiController . setText ( centerNodeId );
90
+ guiController . draw ();
68
91
}
69
92
70
- public void initClick () {
93
+ /**
94
+ * Method to initialize the mouseEvent.
95
+ */
96
+ private void initClick () {
71
97
miniMap .setOnMousePressed (this ::handleMouse );
72
98
}
73
99
@@ -77,19 +103,19 @@ public void initClick() {
77
103
*
78
104
* @param centerNode int of the centernode currently at.
79
105
*/
80
- public void showPosition (int centerNode ) {
106
+ void showPosition (int centerNode ) {
81
107
GraphicsContext gc = miniMap .getGraphicsContext2D ();
82
108
gc .clearRect (0 , 0 , miniMap .getWidth (), miniMap .getHeight ());
83
109
drawMiniMap ();
84
110
gc .setFill (Color .RED );
85
111
gc .fillOval ((centerNode / (double ) size ) * miniMap .getWidth (), 20 , 10 , 10 );
86
112
}
87
113
88
- public void setGraphController (GraphController graphController ) {
114
+ void setGraphController (GraphController graphController ) {
89
115
this .graphController = graphController ;
90
116
}
91
117
92
- public void setGuiController (GuiController guiController ) {
118
+ void setGuiController (GuiController guiController ) {
93
119
this .guiController = guiController ;
94
120
}
95
121
}
0 commit comments