@@ -32,7 +32,13 @@ public GraphicalBoard(SpaghettiInterface parent) {
32
32
}
33
33
34
34
public void setBoard (Board board ) {
35
- if (this .board != null ) this .board .removeBoardListener (this );
35
+ if (this .board != null ) {
36
+ this .board .removeBoardListener (this );
37
+ for (BoardListener l : this .board .getBoardListeners ())
38
+ if (isChild (l )) {
39
+ this .board .removeBoardListener (l );
40
+ }
41
+ }
36
42
this .board = board ;
37
43
if (board != null ) board .addBoardListener (this );
38
44
}
@@ -156,11 +162,11 @@ public void paintComponent(Graphics g) {
156
162
if (msg != null ) {
157
163
g2 .setRenderingHint (RenderingHints .KEY_ANTIALIASING , RenderingHints .VALUE_ANTIALIAS_OFF );
158
164
g2 .setColor (parent .colorPalette .get (8 ));
159
- g2 .drawRect ( 0 , 0 , 100 , 50 );
165
+ g2 .fillRect ( 50 , 50 , 100 , 30 );
160
166
g2 .setRenderingHint (RenderingHints .KEY_ANTIALIASING , RenderingHints .VALUE_ANTIALIAS_ON );
161
167
g2 .setFont (font );
162
168
g2 .setColor (parent .colorPalette .get (0 ));
163
- g2 .drawString (msg , 0 , 0 );
169
+ g2 .drawString (msg , 50 , 50 );
164
170
g2 .setRenderingHint (RenderingHints .KEY_ANTIALIASING , RenderingHints .VALUE_ANTIALIAS_OFF );
165
171
}
166
172
@@ -357,14 +363,18 @@ public void close() {
357
363
highlight = null ;
358
364
}
359
365
366
+ public boolean isChild (BoardListener l ) {
367
+ return l instanceof MouseInputBoardController &&
368
+ ((MouseInputBoardController )l ).gb == this ;
369
+ }
370
+
360
371
public boolean isBoardRunning () {
361
372
return board != null && board .getCurrentState () == BoardState .RUNNING ;
362
373
}
363
374
364
375
public boolean isControllerTurn () {
365
376
return isBoardRunning () &&
366
- board .getControllerTurn () instanceof MouseInputBoardController &&
367
- ((MouseInputBoardController )board .getControllerTurn ()).gb == this ;
377
+ isChild (board .getControllerTurn ());
368
378
}
369
379
370
380
@ Override
@@ -417,7 +427,11 @@ public void mouseDragged(MouseEvent e) {
417
427
418
428
@ Override
419
429
public void mouseMoved (MouseEvent e ) {
420
- if (!isBoardRunning ()) return ;
430
+ if (!isBoardRunning ()) {
431
+ sample = null ;
432
+ highlight = null ;
433
+ return ;
434
+ }
421
435
if (inSample (e .getPoint ())) {
422
436
highlight = null ;
423
437
sampleHighlight = getTypeFromSample (e .getPoint ());
@@ -444,8 +458,8 @@ public void enablePage(JFrame frame) {
444
458
public void disablePage (JFrame frame ) {
445
459
frame .getContentPane ().removeAll ();
446
460
removeKeyListener (this );
447
- close ();
448
461
parent .repaint ();
462
+ close ();
449
463
}
450
464
451
465
@ Override
@@ -454,7 +468,9 @@ public void keyTyped(KeyEvent e) {
454
468
455
469
@ Override
456
470
public void keyPressed (KeyEvent e ) {
457
- if (e .getKeyCode () == KeyEvent .VK_ESCAPE ) parent .setPage (parent .getStartPage ());
471
+ if (e .getKeyCode () == KeyEvent .VK_ESCAPE ) {
472
+ parent .setPage (parent .getStartPage ());
473
+ }
458
474
}
459
475
460
476
@ Override
0 commit comments