コード例 #1
0
 @Test
 public void setAbsorberTest() {
   Absorber absorb = new Absorber("absorb", 0, 0, 60, 60);
   model.setAbsorber(absorb);
   assertTrue(model.getAbsorber() != null);
   assertEquals(model.getAbsorber(), absorb);
 }
コード例 #2
0
 @Test
 public void addAbsorberTest() {
   assertTrue(model.getAbsorber() == null);
   model.addAbsorber("absorb", 0, 0, 20, 20);
   model.addAbsorber("absorb", 0, 20, 60, 80);
   assertFalse(model.getAbsorber() == null);
   assertTrue(model.getAbsorber().getXTopLeft() == 0);
   assertTrue(model.getAbsorber().getYTopLeft() == 20);
   assertTrue(model.getAbsorber().getXBottomRight() == 60);
   assertTrue(model.getAbsorber().getYBottomRight() == 80);
 }
コード例 #3
0
 @Override
 public void mouseClicked(MouseEvent mouseEvent) {
   Board b = bgui.getGridView();
   if (b.getAction() == Board.Action.KEY_DISCONNECT) {
     Point mouseP = MouseInfo.getPointerInfo().getLocation();
     Point gridP = b.getLocationOnScreen();
     int x = mouseP.x - gridP.x;
     int y = mouseP.y - gridP.y;
     x -= x % 20;
     y -= y % 20;
     f = m.findFlipper(x, y);
     String keys = "";
     if (f != null) {
       for (KeyConnectionFlipper kcf : m.getKeyConnectionsFlipper()) {
         if (kcf.getFlipper().equals(f)) {
           keys += ("'" + KeyEvent.getKeyText(kcf.getKeyID()) + "', ");
         }
       }
       if (keys.length() > 2) {
         keys = keys.substring(0, keys.length() - 2);
       }
       abs = null;
       b.requestFocus();
       bgui.setMessageColor(Color.BLACK);
       bgui.setMessage(
           "This flipper is connected to keys "
               + keys
               + ". Press key to remove connection to it.");
     } else if (m.getAbsorber() != null
         && x <= m.getAbsorber().getXBottomRight()
         && x >= m.getAbsorber().getXTopLeft()
         && y <= m.getAbsorber().getYBottomRight()
         && y >= m.getAbsorber().getYTopLeft()) {
       for (KeyConnectionAbs kca : m.getKeyConnectionsAbs()) {
         keys += ("'" + KeyEvent.getKeyText(kca.getKeyID()) + "', ");
       }
       if (keys.length() > 2) {
         keys = keys.substring(0, keys.length() - 2);
       }
       abs = m.getAbsorber();
       b.requestFocus();
       bgui.setMessageColor(Color.BLACK);
       bgui.setMessage(
           "This absorber is connected to keys "
               + keys
               + ". Press key to remove connection to it.");
     }
   }
 }