Started implementing of side panel
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@480 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
bf24a9279a
commit
fe7a2bc0ee
4 changed files with 162 additions and 42 deletions
|
@ -35,9 +35,10 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
|
||||||
ImageIcon image = new ImageIcon(
|
ImageIcon image = new ImageIcon(
|
||||||
HandPanel.class.getResource("/jrummikub/resource/wood.png"));
|
HandPanel.class.getResource("/jrummikub/resource/wood.png"));
|
||||||
ImageIcon darkImage = new ImageIcon(
|
ImageIcon darkImage = new ImageIcon(
|
||||||
HandPanel.class.getResource("/jrummikub/resource/dark_wood.png"));
|
HandPanel.class
|
||||||
BACKGROUND = new BufferedImage(image.getIconWidth(), image.getIconHeight(),
|
.getResource("/jrummikub/resource/dark_wood.png"));
|
||||||
BufferedImage.TYPE_INT_RGB);
|
BACKGROUND = new BufferedImage(image.getIconWidth(),
|
||||||
|
image.getIconHeight(), BufferedImage.TYPE_INT_RGB);
|
||||||
DARK_BACKGROUND = new BufferedImage(darkImage.getIconWidth(),
|
DARK_BACKGROUND = new BufferedImage(darkImage.getIconWidth(),
|
||||||
darkImage.getIconHeight(), BufferedImage.TYPE_INT_RGB);
|
darkImage.getIconHeight(), BufferedImage.TYPE_INT_RGB);
|
||||||
|
|
||||||
|
@ -63,14 +64,6 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
|
||||||
this.playerPanel = playerPanel;
|
this.playerPanel = playerPanel;
|
||||||
|
|
||||||
setBorder(new MatteBorder(0, 1, 0, 1, Color.DARK_GRAY));
|
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) {
|
private BufferedImage getScaledBackground(int size, BufferedImage background) {
|
||||||
|
@ -89,7 +82,8 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
|
||||||
protected void paintComponent(Graphics g1) {
|
protected void paintComponent(Graphics g1) {
|
||||||
Insets insets = getInsets();
|
Insets insets = getInsets();
|
||||||
int x = insets.left, y = insets.top, width = getWidth() - insets.left
|
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);
|
Graphics2D g = (Graphics2D) g1.create(x, y, width, height);
|
||||||
|
|
||||||
int size = height / HEIGHT;
|
int size = height / HEIGHT;
|
||||||
|
@ -100,11 +94,13 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
|
||||||
if (repaintAll) {
|
if (repaintAll) {
|
||||||
if (background.getHeight() != size) {
|
if (background.getHeight() != size) {
|
||||||
if (!isEnabled()) {
|
if (!isEnabled()) {
|
||||||
scaledDarkBackground = getScaledBackground(size, DARK_BACKGROUND);
|
scaledDarkBackground = getScaledBackground(size,
|
||||||
|
DARK_BACKGROUND);
|
||||||
} else {
|
} else {
|
||||||
scaledBackground = getScaledBackground(size, BACKGROUND);
|
scaledBackground = getScaledBackground(size, BACKGROUND);
|
||||||
}
|
}
|
||||||
background = isEnabled() ? scaledBackground : scaledDarkBackground;
|
background = isEnabled() ? scaledBackground
|
||||||
|
: scaledDarkBackground;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < HEIGHT; ++i) {
|
for (int i = 0; i < HEIGHT; ++i) {
|
||||||
|
@ -118,9 +114,14 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
|
||||||
g.translate(trans.getFirst(), trans.getSecond());
|
g.translate(trans.getFirst(), trans.getSecond());
|
||||||
|
|
||||||
for (Pair<Stone, Position> entry : getStones()) {
|
for (Pair<Stone, Position> entry : getStones()) {
|
||||||
getStonePainter().paintStone(g, entry.getFirst(), entry.getSecond(),
|
getStonePainter()
|
||||||
selectedStones.contains(entry.getFirst()) ? StoneState.SELECTED : StoneState.NORMAL,
|
.paintStone(
|
||||||
entry.getFirst() == getHoveredStone());
|
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
|
@Override
|
||||||
public Pair<Integer, Integer> getTranslation() {
|
public Pair<Integer, Integer> getTranslation() {
|
||||||
return new Pair<Integer, Integer>(0, -getStonePainter().getStoneHeight()
|
return new Pair<Integer, Integer>(0, -getStonePainter()
|
||||||
* currentRow);
|
.getStoneHeight() * currentRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the stones that are to be painted selected
|
* Sets the stones that are to be painted selected
|
||||||
*
|
*
|
||||||
* @param stones
|
* @param stones
|
||||||
* the selected stones
|
* the selected stones
|
||||||
*/
|
*/
|
||||||
void setSelectedStones(Collection<Stone> stones) {
|
void setSelectedStones(Collection<Stone> stones) {
|
||||||
selectedStones = stones;
|
selectedStones = stones;
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rescale() {
|
int rescale(int height) {
|
||||||
Insets insets = getInsets();
|
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);
|
getStonePainter().setScale(size * StonePainter.HEIGHT_SCALE);
|
||||||
|
int width = Hand.WIDTH * getStonePainter().getStoneWidth()
|
||||||
setSize(new Dimension(Hand.WIDTH * getStonePainter().getStoneWidth()
|
+ insets.left + insets.right;
|
||||||
+ insets.left + insets.right, getHeight()));
|
setSize(new Dimension(width, getHeight()));
|
||||||
|
|
||||||
repaintAll = true;
|
repaintAll = true;
|
||||||
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
private Event endTurnEvent = new Event();
|
private Event endTurnEvent = new Event();
|
||||||
private Event redealEvent = new Event();
|
private Event redealEvent = new Event();
|
||||||
private Event pauseEvent = new Event();
|
private Event pauseEvent = new Event();
|
||||||
|
private int leftPanelWidth;
|
||||||
|
|
||||||
HandPanel getHandPanel() {
|
HandPanel getHandPanel() {
|
||||||
return hand;
|
return hand;
|
||||||
|
@ -233,14 +234,15 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rescale() {
|
void rescale() {
|
||||||
Insets insets = getInsets();
|
Insets insets = getInsets();
|
||||||
int x = insets.left, y = insets.top, width = getWidth() - insets.left
|
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;
|
||||||
int boardWidth = hand.getWidth();
|
|
||||||
|
int boardWidth = hand.rescale(height);
|
||||||
int handButtonWidth = (int) (width * HAND_ROW_BUTTON_RATIO);
|
int handButtonWidth = (int) (width * HAND_ROW_BUTTON_RATIO);
|
||||||
int meanPanelWidth = (width - boardWidth) / 2;
|
int meanPanelWidth = (width - boardWidth) / 2;
|
||||||
int leftPanelWidth = meanPanelWidth - handButtonWidth / 2;
|
leftPanelWidth = meanPanelWidth - handButtonWidth / 2;
|
||||||
int rightPanelWidth = meanPanelWidth + handButtonWidth / 2;
|
int rightPanelWidth = meanPanelWidth + handButtonWidth / 2;
|
||||||
|
|
||||||
leftPanel.setBounds(x, y, leftPanelWidth, height);
|
leftPanel.setBounds(x, y, leftPanelWidth, height);
|
||||||
|
@ -251,6 +253,10 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
leftPanel.validate();
|
leftPanel.validate();
|
||||||
rightPanel.validate();
|
rightPanel.validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getLeftPanelWidth() {
|
||||||
|
return leftPanelWidth;
|
||||||
|
}
|
||||||
|
|
||||||
void updateButtons() {
|
void updateButtons() {
|
||||||
handRowUpButton.setEnabled(hand.canRowUp());
|
handRowUpButton.setEnabled(hand.canRowUp());
|
||||||
|
@ -274,16 +280,6 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
|
|
||||||
createRightPanel();
|
createRightPanel();
|
||||||
add(rightPanel);
|
add(rightPanel);
|
||||||
|
|
||||||
ComponentListener rescaleListener = new ComponentAdapter() {
|
|
||||||
@Override
|
|
||||||
public void componentResized(ComponentEvent e) {
|
|
||||||
rescale();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
addComponentListener(rescaleListener);
|
|
||||||
hand.addComponentListener(rescaleListener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
112
src/jrummikub/view/impl/SidePanel.java
Normal file
112
src/jrummikub/view/impl/SidePanel.java
Normal file
|
@ -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>> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -62,6 +62,7 @@ public class View extends JFrame implements IView {
|
||||||
private LoginPanel loginPanel;
|
private LoginPanel loginPanel;
|
||||||
private ScorePanel scorePanel;
|
private ScorePanel scorePanel;
|
||||||
private GameListPanel gameListPanel;
|
private GameListPanel gameListPanel;
|
||||||
|
private SidePanel sidePanel;
|
||||||
|
|
||||||
private BottomPanelType bottomPanelType;
|
private BottomPanelType bottomPanelType;
|
||||||
|
|
||||||
|
@ -321,6 +322,9 @@ public class View extends JFrame implements IView {
|
||||||
winPanel = new WinPanel();
|
winPanel = new WinPanel();
|
||||||
winPanel.setVisible(false);
|
winPanel.setVisible(false);
|
||||||
mainLayer.add(winPanel);
|
mainLayer.add(winPanel);
|
||||||
|
|
||||||
|
sidePanel = new SidePanel();
|
||||||
|
mainLayer.add(sidePanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -335,6 +339,8 @@ public class View extends JFrame implements IView {
|
||||||
int width = getContentPane().getWidth(), height = getContentPane()
|
int width = getContentPane().getWidth(), height = getContentPane()
|
||||||
.getHeight();
|
.getHeight();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
layeredPane.setBounds(0, 0, width, height);
|
layeredPane.setBounds(0, 0, width, height);
|
||||||
mainLayer.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;
|
int tableHeight = height - playerPanelHeight;
|
||||||
|
|
||||||
table.setBounds(0, 0, width, tableHeight);
|
|
||||||
table.validate();
|
|
||||||
playerPanel.setBounds(0, tableHeight, width, playerPanelHeight);
|
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);
|
startTurnPanel.setBounds(0, tableHeight, width, playerPanelHeight);
|
||||||
pausePanel.setBounds(0, tableHeight, width, playerPanelHeight);
|
pausePanel.setBounds(0, tableHeight, width, playerPanelHeight);
|
||||||
winPanel.setBounds(0, tableHeight, width, playerPanelHeight);
|
winPanel.setBounds(0, tableHeight, width, playerPanelHeight);
|
||||||
|
|
Reference in a new issue