void generateChildrenImpl(final int depth) { if (depth == 0) return; setStateOnlyNonPlayableImpl(false); childGrids = new GridCollection(this); states |= States.HAS_CHILDREN; ChangeBlockListener evtChange = new ChangeBlockListener(); PlayListener evtPlay = new PlayListener(); EndListener evtEnd = new EndListener(); final int size = getHandle().getWidth() / GridConsts.DIMENSION; for (int i = 0; i < GridConsts.DIMENSION; ++i) { for (int j = 0; j < GridConsts.DIMENSION; ++j) { AWTGrid g = new AWTGrid(getGameManager(), eventKey); AWTGridHandle h = g.getHandle(); h.setSize(size); h.setLocation(i * size, j * size); addImpl(g); g.changeBlockEvent().addListener(evtChange); g.playEvent().addListener(evtPlay); g.endEvent().addListener(evtEnd); g.peerGrids = childGrids; childGrids.putGrid(new GridCoord(i, j), g); } } childGrids.forEach( new Consumer<Grid>() { public void accept(Grid t) { if (t instanceof AWTGrid) { ((AWTGrid) t).generateChildrenImpl(depth - 1); } } }); }
final void setStatePlayableAndFilteredImpl(boolean playable) { if (isStateLockedImpl()) return; synchronized (mutex) { states = playable ? (states | States.PLAYABLE) : (states & ~States.PLAYABLE); AWTGridHandle handle = getHandle(); handle.setFiltered(!playable); } }
final void setStateLockedImpl() { setStatePlayableAndFilteredImpl(false); synchronized (mutex) { this.states |= States.LOCKED; AWTGridHandle handle = getHandle(); handle.setFiltered(true); } }
@Override public void mouseEntered(MouseEvent evt) { if (isStateLockedImpl() || hasStateChildrenImpl()) { return; } checkColors(); Color c = isStatePlayableImpl() ? playableColor : unplayableColor; AWTGridHandle h = getHandle(); h.setBackground(c); h.setForeground(c); h.setImage(getImageOfPlayerImpl(getGameManager().getTurnManager().getCurrentPlayer())); }
@Override public void mouseExited(MouseEvent evt) { checkColors(); if (neutral != null) { AWTGridHandle h = getHandle(); h.setBackground(neutral); h.setForeground(neutral); } if (isStateLockedImpl() || hasStateChildrenImpl()) { return; } getHandle().setImage(null, false); }
{ guiHandle = new AWTGridHandle(); guiHandle.setLayout(null); guiHandle.addMouseListener(new AWTMouseListener()); }