/** Updates the displayed CardButtons, moving them from the mainWindow to the pileWindow */ public void preTurn() { List<Card> pileCards = pile.getCards(); List<CardButton> toBeRemoved = new ArrayList(); for (CardButton button : cardButtonMap.values()) { if (pileCards.contains(button.getCard())) { toBeRemoved.add(button); createCardGraphics(button.getCard(), pileWindow).setToPile(true); } } removeCardButtons(toBeRemoved, mainWindow); }
/** * Removes a list of CardButtons from a JComponent * * @param list the list of CardButtons to be removed * @param fromWhere the JComponent to remove the CardButtons from */ private void removeCardButtons(List<CardButton> list, JComponent fromWhere) { for (CardButton button : list) { fromWhere.remove(button); cardButtonMap.remove(button.getCard()); } fromWhere.revalidate(); validate(); }
@Test public void testBoardCardContainLargeIconOfEmptyCard() { CardButton[] buttons = boardPanel.getButtons(); cardButton = buttons[0]; Card card = cardButton.getCard(); String oldPath = cardButton.getIconPath() + (card.getRevertedName() + ".gif"); java.net.URL oldImgURL = getClass().getResource(oldPath); ImageIcon oldIcon = new ImageIcon(oldImgURL, card.toString()); String path = cardButton.getIconPath() + "ec.gif"; java.net.URL imgURL = getClass().getResource(path); ImageIcon icon = new ImageIcon(imgURL, card.toString()); assertTrue( "button have large image icon", ((ImageIcon) cardButton.getIcon()).getImage().equals(oldIcon.getImage())); cardButton.doClick(); assertNull("button have don't have card", cardButton.getCard()); assertTrue( "button have large empty card icon", ((ImageIcon) cardButton.getIcon()).getImage().equals(icon.getImage())); }