summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/view/impl')
-rw-r--r--src/jrummikub/view/impl/HandPanel.java55
-rw-r--r--src/jrummikub/view/impl/PlayerPanel.java22
-rw-r--r--src/jrummikub/view/impl/SidePanel.java112
-rw-r--r--src/jrummikub/view/impl/View.java15
4 files changed, 162 insertions, 42 deletions
diff --git a/src/jrummikub/view/impl/HandPanel.java b/src/jrummikub/view/impl/HandPanel.java
index 823ca12..181be07 100644
--- a/src/jrummikub/view/impl/HandPanel.java
+++ b/src/jrummikub/view/impl/HandPanel.java
@@ -35,9 +35,10 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
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);
+ 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);
@@ -63,14 +64,6 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
this.playerPanel = playerPanel;
setBorder(new MatteBorder(0, 1, 0, 1, Color.DARK_GRAY));
-
- addComponentListener(new ComponentAdapter() {
-
- @Override
- public void componentResized(ComponentEvent e) {
- rescale();
- }
- });
}
private BufferedImage getScaledBackground(int size, BufferedImage background) {
@@ -89,7 +82,8 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
protected void paintComponent(Graphics g1) {
Insets insets = getInsets();
int x = insets.left, y = insets.top, width = getWidth() - insets.left
- - insets.right, height = getHeight() - insets.top - insets.bottom;
+ - insets.right, height = getHeight() - insets.top
+ - insets.bottom;
Graphics2D g = (Graphics2D) g1.create(x, y, width, height);
int size = height / HEIGHT;
@@ -100,11 +94,13 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
if (repaintAll) {
if (background.getHeight() != size) {
if (!isEnabled()) {
- scaledDarkBackground = getScaledBackground(size, DARK_BACKGROUND);
+ scaledDarkBackground = getScaledBackground(size,
+ DARK_BACKGROUND);
} else {
scaledBackground = getScaledBackground(size, BACKGROUND);
}
- background = isEnabled() ? scaledBackground : scaledDarkBackground;
+ background = isEnabled() ? scaledBackground
+ : scaledDarkBackground;
}
for (int i = 0; i < HEIGHT; ++i) {
@@ -118,9 +114,14 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
g.translate(trans.getFirst(), trans.getSecond());
for (Pair<Stone, Position> entry : getStones()) {
- getStonePainter().paintStone(g, entry.getFirst(), entry.getSecond(),
- selectedStones.contains(entry.getFirst()) ? StoneState.SELECTED : StoneState.NORMAL,
- entry.getFirst() == getHoveredStone());
+ getStonePainter()
+ .paintStone(
+ g,
+ entry.getFirst(),
+ entry.getSecond(),
+ selectedStones.contains(entry.getFirst()) ? StoneState.SELECTED
+ : StoneState.NORMAL,
+ entry.getFirst() == getHoveredStone());
}
}
@@ -174,30 +175,30 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
@Override
public Pair<Integer, Integer> getTranslation() {
- return new Pair<Integer, Integer>(0, -getStonePainter().getStoneHeight()
- * currentRow);
+ return new Pair<Integer, Integer>(0, -getStonePainter()
+ .getStoneHeight() * currentRow);
}
/**
* Sets the stones that are to be painted selected
*
* @param stones
- * the selected stones
+ * the selected stones
*/
void setSelectedStones(Collection<Stone> stones) {
selectedStones = stones;
repaint();
}
- private void rescale() {
+ int rescale(int height) {
Insets insets = getInsets();
- int size = (getHeight() - insets.top - insets.bottom) / HEIGHT;
-
+ int size = (height - insets.top - insets.bottom) / HEIGHT;
getStonePainter().setScale(size * StonePainter.HEIGHT_SCALE);
-
- setSize(new Dimension(Hand.WIDTH * getStonePainter().getStoneWidth()
- + insets.left + insets.right, getHeight()));
-
+ int width = Hand.WIDTH * getStonePainter().getStoneWidth()
+ + insets.left + insets.right;
+ setSize(new Dimension(width, getHeight()));
repaintAll = true;
+ return width;
}
+
}
diff --git a/src/jrummikub/view/impl/PlayerPanel.java b/src/jrummikub/view/impl/PlayerPanel.java
index 2481f7e..2cf7eaa 100644
--- a/src/jrummikub/view/impl/PlayerPanel.java
+++ b/src/jrummikub/view/impl/PlayerPanel.java
@@ -60,6 +60,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
private Event endTurnEvent = new Event();
private Event redealEvent = new Event();
private Event pauseEvent = new Event();
+ private int leftPanelWidth;
HandPanel getHandPanel() {
return hand;
@@ -233,14 +234,15 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
return button;
}
- private void rescale() {
+ void rescale() {
Insets insets = getInsets();
int x = insets.left, y = insets.top, width = getWidth() - insets.left
- insets.right, height = getHeight() - insets.top - insets.bottom;
- int boardWidth = hand.getWidth();
+
+ int boardWidth = hand.rescale(height);
int handButtonWidth = (int) (width * HAND_ROW_BUTTON_RATIO);
int meanPanelWidth = (width - boardWidth) / 2;
- int leftPanelWidth = meanPanelWidth - handButtonWidth / 2;
+ leftPanelWidth = meanPanelWidth - handButtonWidth / 2;
int rightPanelWidth = meanPanelWidth + handButtonWidth / 2;
leftPanel.setBounds(x, y, leftPanelWidth, height);
@@ -251,6 +253,10 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
leftPanel.validate();
rightPanel.validate();
}
+
+ int getLeftPanelWidth() {
+ return leftPanelWidth;
+ }
void updateButtons() {
handRowUpButton.setEnabled(hand.canRowUp());
@@ -274,16 +280,6 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
createRightPanel();
add(rightPanel);
-
- ComponentListener rescaleListener = new ComponentAdapter() {
- @Override
- public void componentResized(ComponentEvent e) {
- rescale();
- }
- };
-
- addComponentListener(rescaleListener);
- hand.addComponentListener(rescaleListener);
}
@Override
diff --git a/src/jrummikub/view/impl/SidePanel.java b/src/jrummikub/view/impl/SidePanel.java
new file mode 100644
index 0000000..637ac76
--- /dev/null
+++ b/src/jrummikub/view/impl/SidePanel.java
@@ -0,0 +1,112 @@
+package jrummikub.view.impl;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.GridLayout;
+import java.awt.Insets;
+
+import javax.swing.BoxLayout;
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.border.MatteBorder;
+
+import com.sun.org.apache.bcel.internal.generic.DMUL;
+
+class SidePanel extends JPanel {
+ RuleInfoPanel ruleInfoPanel;
+ PlayerListPanel playerListPanel;
+ JScrollPane playerListScrollPane;
+
+ public SidePanel() {
+ setLayout(new GridBagLayout());
+
+ setBorder(new MatteBorder(0, 0, 0, 1, Color.BLACK));
+
+ GridBagConstraints c = new GridBagConstraints();
+
+ ruleInfoPanel = new RuleInfoPanel();
+ c.gridx = 0;
+ c.gridy = 0;
+ c.weightx = 1;
+ c.fill = GridBagConstraints.BOTH;
+ add(ruleInfoPanel, c);
+
+ playerListPanel = new PlayerListPanel();
+ c.gridx = 0;
+ c.gridy = 1;
+ c.weighty = 1;
+ c.weightx = 1;
+ c.fill = GridBagConstraints.BOTH;
+
+ playerListScrollPane = new JScrollPane(playerListPanel);
+ playerListScrollPane.setViewportBorder(null);
+ add(playerListScrollPane, c);
+
+ }
+
+ class RuleInfoPanel extends JPanel {
+ JLabel dummy;
+
+ public RuleInfoPanel() {
+ setLayout(new GridLayout(1, 1));
+ setBorder(new MatteBorder(0, 0, 1, 0, Color.GRAY));
+ dummy = new JLabel(
+ "<html><center>All work and no play<br>makes Jack a dull boy");
+ dummy.setHorizontalAlignment(JLabel.CENTER);
+ add(dummy);
+ // setPreferredSize(new Dimension(1, 50));
+ }
+
+ }
+
+ class PlayerListItem extends JPanel {
+ JLabel playerName;
+
+ public PlayerListItem() {
+ setLayout(new GridBagLayout());
+ setBorder(new MatteBorder(1, 0, 0, 0, Color.GRAY));
+
+ GridBagConstraints c = new GridBagConstraints();
+ c.gridx = 0;
+ c.gridy = 0;
+ c.weightx = 1;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.insets = new Insets(5, 5, 5, 5);
+
+ playerName = new JLabel("<html>Horst<br>&gt; 9000 Steine");
+ add(playerName, c);
+ }
+
+ }
+
+ class PlayerListPanel extends JPanel {
+ JPanel startSpacer;
+
+ public PlayerListPanel() {
+ setBackground(Color.RED);
+ setLayout(new GridBagLayout());
+
+ GridBagConstraints c = new GridBagConstraints();
+ startSpacer = new JPanel();
+ c.gridx = 0;
+ c.gridy = 0;
+ c.weightx = 1;
+ c.weighty = 1;
+ c.fill = GridBagConstraints.BOTH;
+ add(startSpacer, c);
+ c.weighty = 0;
+ c.fill = GridBagConstraints.HORIZONTAL;
+
+ for (int i = 1; i <= 16; i++) {
+ c.gridx = 0;
+ c.gridy = i;
+ add(new PlayerListItem(), c);
+ }
+ }
+ }
+
+}
diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java
index 5ede7b3..60202e4 100644
--- a/src/jrummikub/view/impl/View.java
+++ b/src/jrummikub/view/impl/View.java
@@ -62,6 +62,7 @@ public class View extends JFrame implements IView {
private LoginPanel loginPanel;
private ScorePanel scorePanel;
private GameListPanel gameListPanel;
+ private SidePanel sidePanel;
private BottomPanelType bottomPanelType;
@@ -321,6 +322,9 @@ public class View extends JFrame implements IView {
winPanel = new WinPanel();
winPanel.setVisible(false);
mainLayer.add(winPanel);
+
+ sidePanel = new SidePanel();
+ mainLayer.add(sidePanel);
}
@Override
@@ -335,6 +339,8 @@ public class View extends JFrame implements IView {
int width = getContentPane().getWidth(), height = getContentPane()
.getHeight();
+
+
layeredPane.setBounds(0, 0, width, height);
mainLayer.setBounds(0, 0, width, height);
@@ -346,9 +352,14 @@ public class View extends JFrame implements IView {
int tableHeight = height - playerPanelHeight;
- table.setBounds(0, 0, width, tableHeight);
- table.validate();
playerPanel.setBounds(0, tableHeight, width, playerPanelHeight);
+ playerPanel.rescale();
+
+ int sideWidth = playerPanel.getLeftPanelWidth() + 1;
+
+ table.setBounds(sideWidth, 0, width - sideWidth, tableHeight);
+ table.validate();
+ sidePanel.setBounds(0, 0, sideWidth, tableHeight);
startTurnPanel.setBounds(0, tableHeight, width, playerPanelHeight);
pausePanel.setBounds(0, tableHeight, width, playerPanelHeight);
winPanel.setBounds(0, tableHeight, width, playerPanelHeight);