/** * Spusti se pri zmacknuti tlacitka. Pokud je pod mysi obraz figury, zjisti, zda se muze pohnout * (pokud ano, upravi ho pro tahnuti, nastavi ho do figLabel) a zobrazi kontextovou napovedu. */ private void eCatcherMousePressed( java.awt.event.MouseEvent evt) { // GEN-FIRST:event_eCatcherMousePressed if (figLabel != null || finished) { return; } BoardSquare bsquare = (BoardSquare) eCatcher.getComponentAt(evt.getPoint()); JPanel fsquare = (JPanel) figurePan.getComponent(bsquare.getIndex()); sourceBSquare = bsquare; Point defLocation = fsquare.getLocation(); xAdjustment = (int) defLocation.getX() - evt.getX(); yAdjustment = (int) defLocation.getY() - evt.getY(); if (fsquare.getComponentCount() == 0) { return; } figLabel = (JLabel) fsquare.getComponent(0); setFocus(gui.getFocus(bsquare.getColumn(), bsquare.getRow())); if (!gui.canMove(bsquare.getColumn(), bsquare.getRow())) { figLabel = null; return; } fsquare.remove(figLabel); boardPane.add(figLabel, 0); figLabel.setLocation(evt.getX() + xAdjustment, evt.getY() + yAdjustment); figLabel.setSize(figLabel.getWidth(), figLabel.getHeight()); } // GEN-LAST:event_eCatcherMousePressed
/** * Spousti se pri uvolneni tlacitka mysi. Pokud byl tazen obraz figury, vyhodnoti tah a bud jej * potvrdi a ukonci tah hrace nebo zamitne a vrati obraz figury na puvodni pozici. */ private void eCatcherMouseReleased( java.awt.event.MouseEvent evt) { // GEN-FIRST:event_eCatcherMouseReleased removeFocus(); if (figLabel == null) { return; } figLabel.setVisible(false); boardPane.remove(figLabel); BoardSquare bsquare = (BoardSquare) eCatcher.getComponentAt(evt.getPoint()); if (bsquare == null || !gui.move( sourceBSquare.getColumn(), sourceBSquare.getRow(), bsquare.getColumn(), bsquare.getRow())) { ((JPanel) figurePan.getComponent(sourceBSquare.getIndex())).add(figLabel); figLabel.setVisible(true); } figLabel = null; } // GEN-LAST:event_eCatcherMouseReleased