diff options
Diffstat (limited to 'src/jrummikub/view/impl')
-rw-r--r-- | src/jrummikub/view/impl/HandPanel.java | 29 | ||||
-rw-r--r-- | src/jrummikub/view/impl/PlayerPanel.java | 20 | ||||
-rw-r--r-- | src/jrummikub/view/impl/View.java | 9 |
3 files changed, 49 insertions, 9 deletions
diff --git a/src/jrummikub/view/impl/HandPanel.java b/src/jrummikub/view/impl/HandPanel.java index bede319..1851ed9 100644 --- a/src/jrummikub/view/impl/HandPanel.java +++ b/src/jrummikub/view/impl/HandPanel.java @@ -29,16 +29,23 @@ class HandPanel extends AbstractStonePanel implements IHandPanel { private final static int HEIGHT = 2; private final static BufferedImage BACKGROUND; + private final static BufferedImage DARK_BACKGROUND; static { ImageIcon image = new ImageIcon( HandPanel.class.getResource("/jrummikub/resource/wood.png")); + ImageIcon darkImage = new ImageIcon( + HandPanel.class.getResource("/jrummikub/resource/dark_wood.png")); BACKGROUND = new BufferedImage(image.getIconWidth(), image.getIconHeight(), BufferedImage.TYPE_INT_RGB); + DARK_BACKGROUND = new BufferedImage(darkImage.getIconWidth(), darkImage.getIconHeight(), + BufferedImage.TYPE_INT_RGB); image.paintIcon(null, BACKGROUND.createGraphics(), 0, 0); + darkImage.paintIcon(null, DARK_BACKGROUND.createGraphics(), 0, 0); } private BufferedImage scaledBackground = BACKGROUND; + private BufferedImage scaledDarkBackground = BACKGROUND; private PlayerPanel playerPanel; @@ -47,7 +54,6 @@ class HandPanel extends AbstractStonePanel implements IHandPanel { private boolean repaintAll = true; private Collection<Stone> selectedStones = Collections.emptyList(); - /** * Creates a new Board instance */ @@ -65,14 +71,14 @@ class HandPanel extends AbstractStonePanel implements IHandPanel { }); } - private BufferedImage getScaledBackground(int size) { + private BufferedImage getScaledBackground(int size, BufferedImage background) { BufferedImage scaled = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB); Graphics2D g = scaled.createGraphics(); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); - g.drawImage(BACKGROUND, 0, 0, size, size, null); + g.drawImage(background, 0, 0, size, size, null); return scaled; } @@ -86,13 +92,22 @@ class HandPanel extends AbstractStonePanel implements IHandPanel { int size = height / HEIGHT; + + BufferedImage background = isEnabled() ? scaledBackground : scaledDarkBackground ; + if (repaintAll) { - if (scaledBackground.getHeight() != size) - scaledBackground = getScaledBackground(size); - + if (background.getHeight() != size) { + if (!isEnabled()) { + scaledDarkBackground = getScaledBackground(size, DARK_BACKGROUND); + } else { + scaledBackground = getScaledBackground(size, BACKGROUND); + } + background = isEnabled() ? scaledBackground : scaledDarkBackground; + } + for (int i = 0; i < HEIGHT; ++i) { for (int xpos = -size * i / 3; xpos < width; xpos += size) { - g.drawImage(scaledBackground, xpos, size * i, null); + g.drawImage(background, xpos, size * i, null); } } } diff --git a/src/jrummikub/view/impl/PlayerPanel.java b/src/jrummikub/view/impl/PlayerPanel.java index 5eba07a..ba0deb4 100644 --- a/src/jrummikub/view/impl/PlayerPanel.java +++ b/src/jrummikub/view/impl/PlayerPanel.java @@ -8,6 +8,7 @@ import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.text.DecimalFormat; +import java.util.Collections; import javax.swing.JButton; import javax.swing.JLabel; @@ -16,8 +17,11 @@ import javax.swing.JProgressBar; import javax.swing.UIManager; import javax.swing.border.EmptyBorder; +import jrummikub.model.Position; +import jrummikub.model.Stone; import jrummikub.util.Event; import jrummikub.util.IEvent; +import jrummikub.util.Pair; import jrummikub.view.IPlayerPanel; /** @@ -382,4 +386,20 @@ class PlayerPanel extends JPanel implements IPlayerPanel { keepStonesButton.setVisible(false); } } + + void enableButtons(boolean enable) { + sortByGroupsButton.setEnabled(enable); + sortByRunsButton.setEnabled(enable); + if (!enable) { + setEndTurnMode(false, false); + endTurnButton.setText("<html><center>Computer denkt nach"); + hand.setStones(Collections.<Pair<Stone,Position>>emptyList()); + handRowDownButton.setEnabled(false); + handRowDownButton.setEnabled(false); + } + endTurnButton.setEnabled(enable); + redealButton.setEnabled(enable); + keepStonesButton.setEnabled(enable); + hand.setEnabled(enable); + } } diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java index e374f8c..fceaeeb 100644 --- a/src/jrummikub/view/impl/View.java +++ b/src/jrummikub/view/impl/View.java @@ -97,8 +97,8 @@ public class View extends JFrame implements IView { mainLayer.add(table); playerPanel = new PlayerPanel(); - playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0, 0, - Color.BLACK)); + playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0, + 0, Color.BLACK)); mainLayer.add(playerPanel); startTurnPanel = new StartTurnPanel(); @@ -250,4 +250,9 @@ public class View extends JFrame implements IView { playerPanel.showButtons(false); } } + + @Override + public void enableThinkPanel(boolean enable) { + playerPanel.enableButtons(!enable); + } } |