Added StartTurnPanel
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@102 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
a0a32b4f2d
commit
e39a539ee3
6 changed files with 427 additions and 290 deletions
|
@ -30,9 +30,9 @@ public class JRummikub {
|
|||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
IView view = new jrummikub.view.impl.View();
|
||||
final IView view = new jrummikub.view.impl.View();
|
||||
|
||||
view.getPlayerPanel().setCurrentPlayerName("Player 1");
|
||||
view.setCurrentPlayerName("Player 1");
|
||||
view.getPlayerPanel().setTimeLeft(42);
|
||||
view.getTablePanel().setLeftPlayerName("Player 2");
|
||||
view.getTablePanel().setTopPlayerName("Player 3");
|
||||
|
@ -54,6 +54,14 @@ public class JRummikub {
|
|||
@Override
|
||||
public void handle() {
|
||||
System.out.println("'End turn' fired");
|
||||
view.enableStartTurnPanel(true);
|
||||
}
|
||||
});
|
||||
view.getStartTurnEvent().add(new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
System.out.println("'Start turn' fired");
|
||||
view.enableStartTurnPanel(false);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -6,47 +6,39 @@ import jrummikub.util.IEvent;
|
|||
* The player panel that contains a player's board and other user interfaces
|
||||
*/
|
||||
public interface IPlayerPanel {
|
||||
/**
|
||||
* @return the board where the players hand stones are displayed
|
||||
*/
|
||||
public IHandPanel getHandPanel();
|
||||
/**
|
||||
* @return the board where the players hand stones are displayed
|
||||
*/
|
||||
public IHandPanel getHandPanel();
|
||||
|
||||
/**
|
||||
* Sets the current player's name
|
||||
*
|
||||
* @param playerName
|
||||
* the player name
|
||||
*/
|
||||
public void setCurrentPlayerName(String playerName);
|
||||
/**
|
||||
* Sets the time the player has left for his turn
|
||||
*
|
||||
* @param time
|
||||
* the time left
|
||||
*/
|
||||
public void setTimeLeft(int time);
|
||||
|
||||
/**
|
||||
* Sets the time the player has left for his turn
|
||||
*
|
||||
* @param time
|
||||
* the time left
|
||||
*/
|
||||
public void setTimeLeft(int time);
|
||||
/**
|
||||
* The sort by groups event is emitted when the player wants to sort his
|
||||
* stones by groups
|
||||
*
|
||||
* @return the event
|
||||
*/
|
||||
public IEvent getSortByGroupsEvent();
|
||||
|
||||
/**
|
||||
* The sort by groups event is emitted when the player wants to sort his
|
||||
* stones by groups
|
||||
*
|
||||
* @return the event
|
||||
*/
|
||||
public IEvent getSortByGroupsEvent();
|
||||
/**
|
||||
* The sort by runs event is emitted when the player wants to sort his stones
|
||||
* by runs
|
||||
*
|
||||
* @return the event
|
||||
*/
|
||||
public IEvent getSortByRunsEvent();
|
||||
|
||||
/**
|
||||
* The sort by runs event is emitted when the player wants to sort his stones
|
||||
* by runs
|
||||
*
|
||||
* @return the event
|
||||
*/
|
||||
public IEvent getSortByRunsEvent();
|
||||
|
||||
/**
|
||||
* The end turn event is emitted when the player wants to end his turn
|
||||
*
|
||||
* @return the event
|
||||
*/
|
||||
public IEvent getEndTurnEvent();
|
||||
/**
|
||||
* The end turn event is emitted when the player wants to end his turn
|
||||
*
|
||||
* @return the event
|
||||
*/
|
||||
public IEvent getEndTurnEvent();
|
||||
}
|
||||
|
|
|
@ -3,30 +3,54 @@ package jrummikub.view;
|
|||
import java.util.Collection;
|
||||
|
||||
import jrummikub.model.Stone;
|
||||
import jrummikub.util.IEvent;
|
||||
|
||||
/**
|
||||
* The top-level view interface
|
||||
*/
|
||||
public interface IView {
|
||||
/**
|
||||
* Returns the table
|
||||
*
|
||||
* @return the table
|
||||
*/
|
||||
public ITablePanel getTablePanel();
|
||||
/**
|
||||
* Returns the table
|
||||
*
|
||||
* @return the table
|
||||
*/
|
||||
public ITablePanel getTablePanel();
|
||||
|
||||
/**
|
||||
* Returns the player panel
|
||||
*
|
||||
* @return the playerPanel
|
||||
*/
|
||||
public IPlayerPanel getPlayerPanel();
|
||||
/**
|
||||
* Returns the player panel
|
||||
*
|
||||
* @return the playerPanel
|
||||
*/
|
||||
public IPlayerPanel getPlayerPanel();
|
||||
|
||||
/**
|
||||
* Sets the stones that are to be painted selected
|
||||
*
|
||||
* @param stones
|
||||
* the stones to be painted selected
|
||||
*/
|
||||
public void setSelectedStones(Collection<Stone> stones);
|
||||
/**
|
||||
* Sets the current player's name
|
||||
*
|
||||
* @param playerName
|
||||
* the player name
|
||||
*/
|
||||
public void setCurrentPlayerName(String playerName);
|
||||
|
||||
/**
|
||||
* Sets the stones that are to be painted selected
|
||||
*
|
||||
* @param stones
|
||||
* the stones to be painted selected
|
||||
*/
|
||||
public void setSelectedStones(Collection<Stone> stones);
|
||||
|
||||
/**
|
||||
* Enables or disables the player's StartTurnPanel
|
||||
*
|
||||
* @param enable
|
||||
* enable/disable
|
||||
*/
|
||||
public void enableStartTurnPanel(boolean enable);
|
||||
|
||||
/**
|
||||
* The start turn event is emitted when the player wants to start his turn
|
||||
*
|
||||
* @return the event
|
||||
*/
|
||||
public IEvent getStartTurnEvent();
|
||||
}
|
||||
|
|
|
@ -23,221 +23,219 @@ import jrummikub.view.IPlayerPanel;
|
|||
*/
|
||||
@SuppressWarnings("serial")
|
||||
class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||
private final static int SIDE_PANEL_INSET = 15;
|
||||
private final static int SIDE_PANEL_SEPARATOR = 10;
|
||||
private final static float SIDE_PANEL_FIRST_LINE_HEIGHT = 0.375f;
|
||||
private final static int SIDE_PANEL_MAX_WIDTH = 180;
|
||||
private final static float MAX_BUTTON_FONT_SIZE = 12;
|
||||
private final static int SIDE_PANEL_INSET = 15;
|
||||
private final static int SIDE_PANEL_SEPARATOR = 10;
|
||||
private final static float SIDE_PANEL_FIRST_LINE_HEIGHT = 0.375f;
|
||||
private final static int SIDE_PANEL_MAX_WIDTH = 180;
|
||||
private final static float MAX_BUTTON_FONT_SIZE = 12;
|
||||
|
||||
private final static DecimalFormat secondFormat = new DecimalFormat("00");
|
||||
private final static DecimalFormat secondFormat = new DecimalFormat("00");
|
||||
|
||||
private HandPanel hand;
|
||||
private HandPanel hand;
|
||||
|
||||
private JPanel leftPanel, rightPanel;
|
||||
private JPanel leftPanel, rightPanel;
|
||||
|
||||
private JLabel currentPlayerNameLabel;
|
||||
private JButton sortByGroupsButton;
|
||||
private JButton sortByRunsButton;
|
||||
private JProgressBar timeBar;
|
||||
private JButton endTurnButton;
|
||||
private JLabel currentPlayerNameLabel;
|
||||
private JButton sortByGroupsButton;
|
||||
private JButton sortByRunsButton;
|
||||
private JProgressBar timeBar;
|
||||
private JButton endTurnButton;
|
||||
|
||||
private Event sortByGroupsEvent = new Event();
|
||||
private Event sortByRunsEvent = new Event();
|
||||
private Event endTurnEvent = new Event();
|
||||
private Event sortByGroupsEvent = new Event();
|
||||
private Event sortByRunsEvent = new Event();
|
||||
private Event endTurnEvent = new Event();
|
||||
|
||||
@Override
|
||||
public HandPanel getHandPanel() {
|
||||
return hand;
|
||||
}
|
||||
@Override
|
||||
public HandPanel getHandPanel() {
|
||||
return hand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentPlayerName(String playerName) {
|
||||
currentPlayerNameLabel.setText(playerName);
|
||||
}
|
||||
void setCurrentPlayerName(String playerName) {
|
||||
currentPlayerNameLabel.setText(playerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTimeLeft(int time) {
|
||||
timeBar.setValue(time);
|
||||
timeBar.setString(Integer.toString(time / 60) + ":"
|
||||
+ secondFormat.format(time % 60));
|
||||
}
|
||||
@Override
|
||||
public void setTimeLeft(int time) {
|
||||
timeBar.setValue(time);
|
||||
timeBar.setString(Integer.toString(time / 60) + ":"
|
||||
+ secondFormat.format(time % 60));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEvent getSortByGroupsEvent() {
|
||||
return sortByGroupsEvent;
|
||||
}
|
||||
@Override
|
||||
public IEvent getSortByGroupsEvent() {
|
||||
return sortByGroupsEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEvent getSortByRunsEvent() {
|
||||
return sortByRunsEvent;
|
||||
}
|
||||
@Override
|
||||
public IEvent getSortByRunsEvent() {
|
||||
return sortByRunsEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEvent getEndTurnEvent() {
|
||||
return endTurnEvent;
|
||||
}
|
||||
@Override
|
||||
public IEvent getEndTurnEvent() {
|
||||
return endTurnEvent;
|
||||
}
|
||||
|
||||
private void createLeftPanel() {
|
||||
leftPanel = new JPanel();
|
||||
leftPanel.setLayout(null);
|
||||
leftPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET,
|
||||
SIDE_PANEL_INSET, SIDE_PANEL_INSET));
|
||||
private void createLeftPanel() {
|
||||
leftPanel = new JPanel();
|
||||
leftPanel.setLayout(null);
|
||||
leftPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET,
|
||||
SIDE_PANEL_INSET, SIDE_PANEL_INSET));
|
||||
|
||||
currentPlayerNameLabel = new JLabel();
|
||||
currentPlayerNameLabel.setHorizontalAlignment(JLabel.CENTER);
|
||||
currentPlayerNameLabel.setHorizontalTextPosition(JLabel.CENTER);
|
||||
currentPlayerNameLabel.setVerticalAlignment(JLabel.CENTER);
|
||||
currentPlayerNameLabel.setVerticalTextPosition(JLabel.CENTER);
|
||||
leftPanel.add(currentPlayerNameLabel);
|
||||
currentPlayerNameLabel = new JLabel();
|
||||
currentPlayerNameLabel.setHorizontalAlignment(JLabel.CENTER);
|
||||
currentPlayerNameLabel.setHorizontalTextPosition(JLabel.CENTER);
|
||||
currentPlayerNameLabel.setVerticalAlignment(JLabel.CENTER);
|
||||
currentPlayerNameLabel.setVerticalTextPosition(JLabel.CENTER);
|
||||
leftPanel.add(currentPlayerNameLabel);
|
||||
|
||||
sortByGroupsButton = new JButton("<html><center>Nach Gruppen sortieren");
|
||||
sortByGroupsButton.setFont(sortByGroupsButton.getFont().deriveFont(0));
|
||||
sortByGroupsButton.setMargin(new Insets(0, 0, 0, 0));
|
||||
sortByGroupsButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
sortByGroupsEvent.emit();
|
||||
}
|
||||
});
|
||||
leftPanel.add(sortByGroupsButton);
|
||||
sortByGroupsButton = new JButton("<html><center>Nach Gruppen sortieren");
|
||||
sortByGroupsButton.setFont(sortByGroupsButton.getFont().deriveFont(0));
|
||||
sortByGroupsButton.setMargin(new Insets(0, 0, 0, 0));
|
||||
sortByGroupsButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
sortByGroupsEvent.emit();
|
||||
}
|
||||
});
|
||||
leftPanel.add(sortByGroupsButton);
|
||||
|
||||
sortByRunsButton = new JButton("<html><center>Nach Reihen sortieren");
|
||||
sortByRunsButton.setFont(sortByRunsButton.getFont().deriveFont(0));
|
||||
sortByRunsButton.setMargin(new Insets(0, 0, 0, 0));
|
||||
sortByRunsButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
sortByRunsEvent.emit();
|
||||
}
|
||||
});
|
||||
leftPanel.add(sortByRunsButton);
|
||||
sortByRunsButton = new JButton("<html><center>Nach Reihen sortieren");
|
||||
sortByRunsButton.setFont(sortByRunsButton.getFont().deriveFont(0));
|
||||
sortByRunsButton.setMargin(new Insets(0, 0, 0, 0));
|
||||
sortByRunsButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
sortByRunsEvent.emit();
|
||||
}
|
||||
});
|
||||
leftPanel.add(sortByRunsButton);
|
||||
|
||||
leftPanel.addComponentListener(new LeftPanelResizeListener());
|
||||
}
|
||||
leftPanel.addComponentListener(new LeftPanelResizeListener());
|
||||
}
|
||||
|
||||
private void createRightPanel() {
|
||||
rightPanel = new JPanel();
|
||||
rightPanel.setLayout(null);
|
||||
rightPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET,
|
||||
SIDE_PANEL_INSET, SIDE_PANEL_INSET));
|
||||
private void createRightPanel() {
|
||||
rightPanel = new JPanel();
|
||||
rightPanel.setLayout(null);
|
||||
rightPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET,
|
||||
SIDE_PANEL_INSET, SIDE_PANEL_INSET));
|
||||
|
||||
timeBar = new JProgressBar(0, 60);
|
||||
timeBar.setStringPainted(true);
|
||||
rightPanel.add(timeBar);
|
||||
timeBar = new JProgressBar(0, 60);
|
||||
timeBar.setStringPainted(true);
|
||||
rightPanel.add(timeBar);
|
||||
|
||||
endTurnButton = new JButton("Zug beenden");
|
||||
endTurnButton.setFont(endTurnButton.getFont().deriveFont(0));
|
||||
endTurnButton.setMargin(new Insets(0, 0, 0, 0));
|
||||
endTurnButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
endTurnEvent.emit();
|
||||
}
|
||||
});
|
||||
endTurnButton = new JButton("Zug beenden");
|
||||
endTurnButton.setFont(endTurnButton.getFont().deriveFont(0));
|
||||
endTurnButton.setMargin(new Insets(0, 0, 0, 0));
|
||||
endTurnButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
endTurnEvent.emit();
|
||||
}
|
||||
});
|
||||
|
||||
rightPanel.add(endTurnButton);
|
||||
rightPanel.add(endTurnButton);
|
||||
|
||||
rightPanel.addComponentListener(new RightPanelResizeListener());
|
||||
}
|
||||
rightPanel.addComponentListener(new RightPanelResizeListener());
|
||||
}
|
||||
|
||||
private 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 panelWidth = (width - boardWidth) / 2;
|
||||
private 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 panelWidth = (width - boardWidth) / 2;
|
||||
|
||||
leftPanel.setBounds(x, y, panelWidth, height);
|
||||
hand.setBounds(x + panelWidth, y, boardWidth, height);
|
||||
rightPanel.setBounds(x + panelWidth + boardWidth, y, panelWidth, height);
|
||||
leftPanel.setBounds(x, y, panelWidth, height);
|
||||
hand.setBounds(x + panelWidth, y, boardWidth, height);
|
||||
rightPanel.setBounds(x + panelWidth + boardWidth, y, panelWidth, height);
|
||||
|
||||
leftPanel.validate();
|
||||
rightPanel.validate();
|
||||
}
|
||||
leftPanel.validate();
|
||||
rightPanel.validate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new PlayerPanel instance
|
||||
*/
|
||||
PlayerPanel() {
|
||||
setLayout(null);
|
||||
/**
|
||||
* Creates a new PlayerPanel instance
|
||||
*/
|
||||
PlayerPanel() {
|
||||
setLayout(null);
|
||||
|
||||
createLeftPanel();
|
||||
add(leftPanel);
|
||||
createLeftPanel();
|
||||
add(leftPanel);
|
||||
|
||||
hand = new HandPanel();
|
||||
add(hand);
|
||||
hand = new HandPanel();
|
||||
add(hand);
|
||||
|
||||
createRightPanel();
|
||||
add(rightPanel);
|
||||
createRightPanel();
|
||||
add(rightPanel);
|
||||
|
||||
ComponentListener rescaleListener = new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
rescale();
|
||||
}
|
||||
};
|
||||
ComponentListener rescaleListener = new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
rescale();
|
||||
}
|
||||
};
|
||||
|
||||
addComponentListener(rescaleListener);
|
||||
hand.addComponentListener(rescaleListener);
|
||||
}
|
||||
addComponentListener(rescaleListener);
|
||||
hand.addComponentListener(rescaleListener);
|
||||
}
|
||||
|
||||
private class LeftPanelResizeListener extends ComponentAdapter {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
Insets insets = leftPanel.getInsets();
|
||||
int x = insets.left, y = insets.top, width = leftPanel.getWidth()
|
||||
- insets.left - insets.right, height = leftPanel.getHeight()
|
||||
- insets.top - insets.bottom;
|
||||
private class LeftPanelResizeListener extends ComponentAdapter {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
Insets insets = leftPanel.getInsets();
|
||||
int x = insets.left, y = insets.top, width = leftPanel.getWidth()
|
||||
- insets.left - insets.right, height = leftPanel.getHeight()
|
||||
- insets.top - insets.bottom;
|
||||
|
||||
if (width > SIDE_PANEL_MAX_WIDTH) {
|
||||
x += (width - SIDE_PANEL_MAX_WIDTH) / 4;
|
||||
width = width / 2 + SIDE_PANEL_MAX_WIDTH / 2;
|
||||
}
|
||||
if (width > SIDE_PANEL_MAX_WIDTH) {
|
||||
x += (width - SIDE_PANEL_MAX_WIDTH) / 4;
|
||||
width = width / 2 + SIDE_PANEL_MAX_WIDTH / 2;
|
||||
}
|
||||
|
||||
int firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT);
|
||||
int buttonWidth = (width - SIDE_PANEL_SEPARATOR) / 2;
|
||||
int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight;
|
||||
float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
|
||||
if (fontSize > MAX_BUTTON_FONT_SIZE)
|
||||
fontSize = MAX_BUTTON_FONT_SIZE;
|
||||
int firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT);
|
||||
int buttonWidth = (width - SIDE_PANEL_SEPARATOR) / 2;
|
||||
int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight;
|
||||
float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
|
||||
if (fontSize > MAX_BUTTON_FONT_SIZE)
|
||||
fontSize = MAX_BUTTON_FONT_SIZE;
|
||||
|
||||
currentPlayerNameLabel.setBounds(x, y, width, firstLineHeight);
|
||||
sortByGroupsButton.setBounds(x, y + firstLineHeight
|
||||
+ SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
|
||||
sortByRunsButton.setBounds(x + buttonWidth + SIDE_PANEL_SEPARATOR, y
|
||||
+ firstLineHeight + SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
|
||||
currentPlayerNameLabel.setBounds(x, y, width, firstLineHeight);
|
||||
sortByGroupsButton.setBounds(x, y + firstLineHeight
|
||||
+ SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
|
||||
sortByRunsButton.setBounds(x + buttonWidth + SIDE_PANEL_SEPARATOR, y
|
||||
+ firstLineHeight + SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
|
||||
|
||||
sortByGroupsButton.setFont(sortByGroupsButton.getFont().deriveFont(
|
||||
fontSize));
|
||||
sortByRunsButton.setFont(sortByRunsButton.getFont()
|
||||
.deriveFont(fontSize));
|
||||
}
|
||||
}
|
||||
sortByGroupsButton.setFont(sortByGroupsButton.getFont().deriveFont(
|
||||
fontSize));
|
||||
sortByRunsButton.setFont(sortByRunsButton.getFont().deriveFont(fontSize));
|
||||
}
|
||||
}
|
||||
|
||||
private class RightPanelResizeListener extends ComponentAdapter {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
Insets insets = rightPanel.getInsets();
|
||||
int x = insets.left, y = insets.top, width = rightPanel.getWidth()
|
||||
- insets.left - insets.right, height = rightPanel.getHeight()
|
||||
- insets.top - insets.bottom;
|
||||
private class RightPanelResizeListener extends ComponentAdapter {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
Insets insets = rightPanel.getInsets();
|
||||
int x = insets.left, y = insets.top, width = rightPanel.getWidth()
|
||||
- insets.left - insets.right, height = rightPanel.getHeight()
|
||||
- insets.top - insets.bottom;
|
||||
|
||||
if (width > SIDE_PANEL_MAX_WIDTH) {
|
||||
x += (width - SIDE_PANEL_MAX_WIDTH) / 4;
|
||||
width = width / 2 + SIDE_PANEL_MAX_WIDTH / 2;
|
||||
}
|
||||
if (width > SIDE_PANEL_MAX_WIDTH) {
|
||||
x += (width - SIDE_PANEL_MAX_WIDTH) / 4;
|
||||
width = width / 2 + SIDE_PANEL_MAX_WIDTH / 2;
|
||||
}
|
||||
|
||||
int firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT);
|
||||
int buttonWidth = width;
|
||||
int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight;
|
||||
float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
|
||||
if (fontSize > MAX_BUTTON_FONT_SIZE)
|
||||
fontSize = MAX_BUTTON_FONT_SIZE;
|
||||
int firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT);
|
||||
int buttonWidth = width;
|
||||
int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight;
|
||||
float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
|
||||
if (fontSize > MAX_BUTTON_FONT_SIZE)
|
||||
fontSize = MAX_BUTTON_FONT_SIZE;
|
||||
|
||||
timeBar.setBounds(x, y, width, firstLineHeight);
|
||||
endTurnButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR,
|
||||
buttonWidth, buttonHeight);
|
||||
endTurnButton.setFont(endTurnButton.getFont().deriveFont(fontSize));
|
||||
}
|
||||
}
|
||||
timeBar.setBounds(x, y, width, firstLineHeight);
|
||||
endTurnButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR,
|
||||
buttonWidth, buttonHeight);
|
||||
endTurnButton.setFont(endTurnButton.getFont().deriveFont(fontSize));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
89
src/jrummikub/view/impl/StartTurnPanel.java
Normal file
89
src/jrummikub/view/impl/StartTurnPanel.java
Normal file
|
@ -0,0 +1,89 @@
|
|||
package jrummikub.view.impl;
|
||||
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import jrummikub.util.Event;
|
||||
import jrummikub.util.IEvent;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
class StartTurnPanel extends JPanel {
|
||||
private final static int PANEL_INSET = 15;
|
||||
private final static int PANEL_SEPARATOR = 10;
|
||||
private final static float PANEL_FIRST_LINE_HEIGHT = 0.375f;
|
||||
private final static int PANEL_MAX_WIDTH = 180;
|
||||
private final static float MAX_BUTTON_FONT_SIZE = 12;
|
||||
|
||||
private JLabel startTurnLabel;
|
||||
private JButton startTurnButton;
|
||||
|
||||
private Event startTurnEvent = new Event();
|
||||
|
||||
StartTurnPanel() {
|
||||
setLayout(null);
|
||||
setBorder(new EmptyBorder(PANEL_INSET, PANEL_INSET, PANEL_INSET,
|
||||
PANEL_INSET));
|
||||
|
||||
startTurnLabel = new JLabel();
|
||||
startTurnLabel.setHorizontalAlignment(JLabel.CENTER);
|
||||
startTurnLabel.setHorizontalTextPosition(JLabel.CENTER);
|
||||
startTurnLabel.setVerticalAlignment(JLabel.CENTER);
|
||||
startTurnLabel.setVerticalTextPosition(JLabel.CENTER);
|
||||
add(startTurnLabel);
|
||||
|
||||
startTurnButton = new JButton("Zug beginnen");
|
||||
startTurnButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
startTurnEvent.emit();
|
||||
}
|
||||
});
|
||||
add(startTurnButton);
|
||||
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
rescale();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void setCurrentPlayerName(String playerName) {
|
||||
startTurnLabel.setText("'" + playerName + "' ist jetzt an der Reihe.");
|
||||
}
|
||||
|
||||
IEvent getStartTurnEvent() {
|
||||
return startTurnEvent;
|
||||
}
|
||||
|
||||
private void rescale() {
|
||||
Insets insets = getInsets();
|
||||
int x = insets.left, y = insets.top, width = getWidth() - insets.left
|
||||
- insets.right, height = getHeight() - insets.top - insets.bottom;
|
||||
|
||||
if (width > PANEL_MAX_WIDTH) {
|
||||
x += (width - PANEL_MAX_WIDTH) / 4;
|
||||
width = width / 2 + PANEL_MAX_WIDTH / 2;
|
||||
}
|
||||
|
||||
int firstLineHeight = (int) ((height - PANEL_SEPARATOR) * PANEL_FIRST_LINE_HEIGHT);
|
||||
int buttonWidth = width;
|
||||
int buttonHeight = height - PANEL_SEPARATOR - firstLineHeight;
|
||||
float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
|
||||
if (fontSize > MAX_BUTTON_FONT_SIZE)
|
||||
fontSize = MAX_BUTTON_FONT_SIZE;
|
||||
|
||||
startTurnLabel.setBounds(x, y, width, firstLineHeight);
|
||||
startTurnButton.setBounds(x, y + firstLineHeight + PANEL_SEPARATOR,
|
||||
buttonWidth, buttonHeight);
|
||||
startTurnButton.setFont(startTurnButton.getFont().deriveFont(fontSize));
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ import javax.swing.JFrame;
|
|||
import javax.swing.border.MatteBorder;
|
||||
|
||||
import jrummikub.model.Stone;
|
||||
import jrummikub.util.IEvent;
|
||||
import jrummikub.view.IPlayerPanel;
|
||||
import jrummikub.view.ITablePanel;
|
||||
import jrummikub.view.IView;
|
||||
|
@ -19,70 +20,95 @@ import jrummikub.view.IView;
|
|||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class View extends JFrame implements IView {
|
||||
private TablePanel table;
|
||||
private PlayerPanel playerPanel;
|
||||
private TablePanel table;
|
||||
private PlayerPanel playerPanel;
|
||||
private StartTurnPanel startTurnPanel;
|
||||
|
||||
private final static float PLAYER_PANEL_RATIO = 0.14f;
|
||||
private final static int PLAYER_PANEL_BORDER_WIDTH = 1;
|
||||
private final static int PLAYER_PANEL_MAX_HEIGHT = 180 + PLAYER_PANEL_BORDER_WIDTH;
|
||||
private final static float PLAYER_PANEL_RATIO = 0.14f;
|
||||
private final static int PLAYER_PANEL_BORDER_WIDTH = 1;
|
||||
private final static int PLAYER_PANEL_MAX_HEIGHT = 180 + PLAYER_PANEL_BORDER_WIDTH;
|
||||
|
||||
private static int even(double d) {
|
||||
return 2 * (int) (d / 2);
|
||||
}
|
||||
private static int even(double d) {
|
||||
return 2 * (int) (d / 2);
|
||||
}
|
||||
|
||||
public ITablePanel getTablePanel() {
|
||||
return table;
|
||||
}
|
||||
@Override
|
||||
public ITablePanel getTablePanel() {
|
||||
return table;
|
||||
}
|
||||
|
||||
public IPlayerPanel getPlayerPanel() {
|
||||
return playerPanel;
|
||||
}
|
||||
@Override
|
||||
public IPlayerPanel getPlayerPanel() {
|
||||
return playerPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the view
|
||||
*/
|
||||
public View() {
|
||||
super("JRummikub");
|
||||
setLayout(null);
|
||||
/**
|
||||
* Create a new instance of the view
|
||||
*/
|
||||
public View() {
|
||||
super("JRummikub");
|
||||
setLayout(null);
|
||||
|
||||
setSize(800, 600);
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
setSize(800, 600);
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
|
||||
table = new TablePanel();
|
||||
add(table);
|
||||
table = new TablePanel();
|
||||
add(table);
|
||||
|
||||
playerPanel = new PlayerPanel();
|
||||
playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0, 0,
|
||||
Color.BLACK));
|
||||
add(playerPanel);
|
||||
playerPanel = new PlayerPanel();
|
||||
playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0, 0,
|
||||
Color.BLACK));
|
||||
add(playerPanel);
|
||||
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
Insets insets = getInsets();
|
||||
int width = getWidth() - insets.left
|
||||
- insets.right, height = getHeight() - insets.top - insets.bottom;
|
||||
startTurnPanel = new StartTurnPanel();
|
||||
startTurnPanel.setVisible(false);
|
||||
add(startTurnPanel);
|
||||
|
||||
int playerPanelHeight = even(Math.pow((double) width * width * height,
|
||||
1 / 3.0) * PLAYER_PANEL_RATIO)
|
||||
+ PLAYER_PANEL_BORDER_WIDTH;
|
||||
if (playerPanelHeight > PLAYER_PANEL_MAX_HEIGHT)
|
||||
playerPanelHeight = PLAYER_PANEL_MAX_HEIGHT;
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
Insets insets = getInsets();
|
||||
int width = getWidth() - insets.left - insets.right, height = getHeight()
|
||||
- insets.top - insets.bottom;
|
||||
|
||||
int tableHeight = height - playerPanelHeight;
|
||||
int playerPanelHeight = even(Math.pow((double) width * width * height,
|
||||
1 / 3.0) * PLAYER_PANEL_RATIO)
|
||||
+ PLAYER_PANEL_BORDER_WIDTH;
|
||||
if (playerPanelHeight > PLAYER_PANEL_MAX_HEIGHT)
|
||||
playerPanelHeight = PLAYER_PANEL_MAX_HEIGHT;
|
||||
|
||||
table.setBounds(0, 0, width, tableHeight);
|
||||
table.validate();
|
||||
playerPanel.setBounds(0, tableHeight, width, playerPanelHeight);
|
||||
}
|
||||
});
|
||||
int tableHeight = height - playerPanelHeight;
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
table.setBounds(0, 0, width, tableHeight);
|
||||
table.validate();
|
||||
playerPanel.setBounds(0, tableHeight, width, playerPanelHeight);
|
||||
startTurnPanel.setBounds(0, tableHeight, width, playerPanelHeight);
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public void setSelectedStones(Collection<Stone> stones) {
|
||||
table.setSelectedStones(stones);
|
||||
playerPanel.getHandPanel().setSelectedStones(stones);
|
||||
}
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectedStones(Collection<Stone> stones) {
|
||||
table.setSelectedStones(stones);
|
||||
playerPanel.getHandPanel().setSelectedStones(stones);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableStartTurnPanel(boolean enable) {
|
||||
playerPanel.setVisible(!enable);
|
||||
startTurnPanel.setVisible(enable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentPlayerName(String playerName) {
|
||||
playerPanel.setCurrentPlayerName(playerName);
|
||||
startTurnPanel.setCurrentPlayerName(playerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEvent getStartTurnEvent() {
|
||||
return startTurnPanel.getStartTurnEvent();
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue