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) {
|
} 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.getPlayerPanel().setTimeLeft(42);
|
||||||
view.getTablePanel().setLeftPlayerName("Player 2");
|
view.getTablePanel().setLeftPlayerName("Player 2");
|
||||||
view.getTablePanel().setTopPlayerName("Player 3");
|
view.getTablePanel().setTopPlayerName("Player 3");
|
||||||
|
@ -54,6 +54,14 @@ public class JRummikub {
|
||||||
@Override
|
@Override
|
||||||
public void handle() {
|
public void handle() {
|
||||||
System.out.println("'End turn' fired");
|
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
|
* The player panel that contains a player's board and other user interfaces
|
||||||
*/
|
*/
|
||||||
public interface IPlayerPanel {
|
public interface IPlayerPanel {
|
||||||
/**
|
/**
|
||||||
* @return the board where the players hand stones are displayed
|
* @return the board where the players hand stones are displayed
|
||||||
*/
|
*/
|
||||||
public IHandPanel getHandPanel();
|
public IHandPanel getHandPanel();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the current player's name
|
* Sets the time the player has left for his turn
|
||||||
*
|
*
|
||||||
* @param playerName
|
* @param time
|
||||||
* the player name
|
* the time left
|
||||||
*/
|
*/
|
||||||
public void setCurrentPlayerName(String playerName);
|
public void setTimeLeft(int time);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the time the player has left for his turn
|
* The sort by groups event is emitted when the player wants to sort his
|
||||||
*
|
* stones by groups
|
||||||
* @param time
|
*
|
||||||
* the time left
|
* @return the event
|
||||||
*/
|
*/
|
||||||
public void setTimeLeft(int time);
|
public IEvent getSortByGroupsEvent();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The sort by groups event is emitted when the player wants to sort his
|
* The sort by runs event is emitted when the player wants to sort his stones
|
||||||
* stones by groups
|
* by runs
|
||||||
*
|
*
|
||||||
* @return the event
|
* @return the event
|
||||||
*/
|
*/
|
||||||
public IEvent getSortByGroupsEvent();
|
public IEvent getSortByRunsEvent();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The sort by runs event is emitted when the player wants to sort his stones
|
* The end turn event is emitted when the player wants to end his turn
|
||||||
* by runs
|
*
|
||||||
*
|
* @return the event
|
||||||
* @return the event
|
*/
|
||||||
*/
|
public IEvent getEndTurnEvent();
|
||||||
public IEvent getSortByRunsEvent();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 java.util.Collection;
|
||||||
|
|
||||||
import jrummikub.model.Stone;
|
import jrummikub.model.Stone;
|
||||||
|
import jrummikub.util.IEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The top-level view interface
|
* The top-level view interface
|
||||||
*/
|
*/
|
||||||
public interface IView {
|
public interface IView {
|
||||||
/**
|
/**
|
||||||
* Returns the table
|
* Returns the table
|
||||||
*
|
*
|
||||||
* @return the table
|
* @return the table
|
||||||
*/
|
*/
|
||||||
public ITablePanel getTablePanel();
|
public ITablePanel getTablePanel();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the player panel
|
* Returns the player panel
|
||||||
*
|
*
|
||||||
* @return the playerPanel
|
* @return the playerPanel
|
||||||
*/
|
*/
|
||||||
public IPlayerPanel getPlayerPanel();
|
public IPlayerPanel getPlayerPanel();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the stones that are to be painted selected
|
* Sets the current player's name
|
||||||
*
|
*
|
||||||
* @param stones
|
* @param playerName
|
||||||
* the stones to be painted selected
|
* the player name
|
||||||
*/
|
*/
|
||||||
public void setSelectedStones(Collection<Stone> stones);
|
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")
|
@SuppressWarnings("serial")
|
||||||
class PlayerPanel extends JPanel implements IPlayerPanel {
|
class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
private final static int SIDE_PANEL_INSET = 15;
|
private final static int SIDE_PANEL_INSET = 15;
|
||||||
private final static int SIDE_PANEL_SEPARATOR = 10;
|
private final static int SIDE_PANEL_SEPARATOR = 10;
|
||||||
private final static float SIDE_PANEL_FIRST_LINE_HEIGHT = 0.375f;
|
private final static float SIDE_PANEL_FIRST_LINE_HEIGHT = 0.375f;
|
||||||
private final static int SIDE_PANEL_MAX_WIDTH = 180;
|
private final static int SIDE_PANEL_MAX_WIDTH = 180;
|
||||||
private final static float MAX_BUTTON_FONT_SIZE = 12;
|
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 JLabel currentPlayerNameLabel;
|
||||||
private JButton sortByGroupsButton;
|
private JButton sortByGroupsButton;
|
||||||
private JButton sortByRunsButton;
|
private JButton sortByRunsButton;
|
||||||
private JProgressBar timeBar;
|
private JProgressBar timeBar;
|
||||||
private JButton endTurnButton;
|
private JButton endTurnButton;
|
||||||
|
|
||||||
private Event sortByGroupsEvent = new Event();
|
private Event sortByGroupsEvent = new Event();
|
||||||
private Event sortByRunsEvent = new Event();
|
private Event sortByRunsEvent = new Event();
|
||||||
private Event endTurnEvent = new Event();
|
private Event endTurnEvent = new Event();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandPanel getHandPanel() {
|
public HandPanel getHandPanel() {
|
||||||
return hand;
|
return hand;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
void setCurrentPlayerName(String playerName) {
|
||||||
public void setCurrentPlayerName(String playerName) {
|
currentPlayerNameLabel.setText(playerName);
|
||||||
currentPlayerNameLabel.setText(playerName);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTimeLeft(int time) {
|
public void setTimeLeft(int time) {
|
||||||
timeBar.setValue(time);
|
timeBar.setValue(time);
|
||||||
timeBar.setString(Integer.toString(time / 60) + ":"
|
timeBar.setString(Integer.toString(time / 60) + ":"
|
||||||
+ secondFormat.format(time % 60));
|
+ secondFormat.format(time % 60));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEvent getSortByGroupsEvent() {
|
public IEvent getSortByGroupsEvent() {
|
||||||
return sortByGroupsEvent;
|
return sortByGroupsEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEvent getSortByRunsEvent() {
|
public IEvent getSortByRunsEvent() {
|
||||||
return sortByRunsEvent;
|
return sortByRunsEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEvent getEndTurnEvent() {
|
public IEvent getEndTurnEvent() {
|
||||||
return endTurnEvent;
|
return endTurnEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createLeftPanel() {
|
private void createLeftPanel() {
|
||||||
leftPanel = new JPanel();
|
leftPanel = new JPanel();
|
||||||
leftPanel.setLayout(null);
|
leftPanel.setLayout(null);
|
||||||
leftPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET,
|
leftPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET,
|
||||||
SIDE_PANEL_INSET, SIDE_PANEL_INSET));
|
SIDE_PANEL_INSET, SIDE_PANEL_INSET));
|
||||||
|
|
||||||
currentPlayerNameLabel = new JLabel();
|
currentPlayerNameLabel = new JLabel();
|
||||||
currentPlayerNameLabel.setHorizontalAlignment(JLabel.CENTER);
|
currentPlayerNameLabel.setHorizontalAlignment(JLabel.CENTER);
|
||||||
currentPlayerNameLabel.setHorizontalTextPosition(JLabel.CENTER);
|
currentPlayerNameLabel.setHorizontalTextPosition(JLabel.CENTER);
|
||||||
currentPlayerNameLabel.setVerticalAlignment(JLabel.CENTER);
|
currentPlayerNameLabel.setVerticalAlignment(JLabel.CENTER);
|
||||||
currentPlayerNameLabel.setVerticalTextPosition(JLabel.CENTER);
|
currentPlayerNameLabel.setVerticalTextPosition(JLabel.CENTER);
|
||||||
leftPanel.add(currentPlayerNameLabel);
|
leftPanel.add(currentPlayerNameLabel);
|
||||||
|
|
||||||
sortByGroupsButton = new JButton("<html><center>Nach Gruppen sortieren");
|
sortByGroupsButton = new JButton("<html><center>Nach Gruppen sortieren");
|
||||||
sortByGroupsButton.setFont(sortByGroupsButton.getFont().deriveFont(0));
|
sortByGroupsButton.setFont(sortByGroupsButton.getFont().deriveFont(0));
|
||||||
sortByGroupsButton.setMargin(new Insets(0, 0, 0, 0));
|
sortByGroupsButton.setMargin(new Insets(0, 0, 0, 0));
|
||||||
sortByGroupsButton.addActionListener(new ActionListener() {
|
sortByGroupsButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
sortByGroupsEvent.emit();
|
sortByGroupsEvent.emit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
leftPanel.add(sortByGroupsButton);
|
leftPanel.add(sortByGroupsButton);
|
||||||
|
|
||||||
sortByRunsButton = new JButton("<html><center>Nach Reihen sortieren");
|
sortByRunsButton = new JButton("<html><center>Nach Reihen sortieren");
|
||||||
sortByRunsButton.setFont(sortByRunsButton.getFont().deriveFont(0));
|
sortByRunsButton.setFont(sortByRunsButton.getFont().deriveFont(0));
|
||||||
sortByRunsButton.setMargin(new Insets(0, 0, 0, 0));
|
sortByRunsButton.setMargin(new Insets(0, 0, 0, 0));
|
||||||
sortByRunsButton.addActionListener(new ActionListener() {
|
sortByRunsButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
sortByRunsEvent.emit();
|
sortByRunsEvent.emit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
leftPanel.add(sortByRunsButton);
|
leftPanel.add(sortByRunsButton);
|
||||||
|
|
||||||
leftPanel.addComponentListener(new LeftPanelResizeListener());
|
leftPanel.addComponentListener(new LeftPanelResizeListener());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createRightPanel() {
|
private void createRightPanel() {
|
||||||
rightPanel = new JPanel();
|
rightPanel = new JPanel();
|
||||||
rightPanel.setLayout(null);
|
rightPanel.setLayout(null);
|
||||||
rightPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET,
|
rightPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET,
|
||||||
SIDE_PANEL_INSET, SIDE_PANEL_INSET));
|
SIDE_PANEL_INSET, SIDE_PANEL_INSET));
|
||||||
|
|
||||||
timeBar = new JProgressBar(0, 60);
|
timeBar = new JProgressBar(0, 60);
|
||||||
timeBar.setStringPainted(true);
|
timeBar.setStringPainted(true);
|
||||||
rightPanel.add(timeBar);
|
rightPanel.add(timeBar);
|
||||||
|
|
||||||
endTurnButton = new JButton("Zug beenden");
|
endTurnButton = new JButton("Zug beenden");
|
||||||
endTurnButton.setFont(endTurnButton.getFont().deriveFont(0));
|
endTurnButton.setFont(endTurnButton.getFont().deriveFont(0));
|
||||||
endTurnButton.setMargin(new Insets(0, 0, 0, 0));
|
endTurnButton.setMargin(new Insets(0, 0, 0, 0));
|
||||||
endTurnButton.addActionListener(new ActionListener() {
|
endTurnButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
endTurnEvent.emit();
|
endTurnEvent.emit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
rightPanel.add(endTurnButton);
|
rightPanel.add(endTurnButton);
|
||||||
|
|
||||||
rightPanel.addComponentListener(new RightPanelResizeListener());
|
rightPanel.addComponentListener(new RightPanelResizeListener());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rescale() {
|
private 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.getWidth();
|
||||||
int panelWidth = (width - boardWidth) / 2;
|
int panelWidth = (width - boardWidth) / 2;
|
||||||
|
|
||||||
leftPanel.setBounds(x, y, panelWidth, height);
|
leftPanel.setBounds(x, y, panelWidth, height);
|
||||||
hand.setBounds(x + panelWidth, y, boardWidth, height);
|
hand.setBounds(x + panelWidth, y, boardWidth, height);
|
||||||
rightPanel.setBounds(x + panelWidth + boardWidth, y, panelWidth, height);
|
rightPanel.setBounds(x + panelWidth + boardWidth, y, panelWidth, height);
|
||||||
|
|
||||||
leftPanel.validate();
|
leftPanel.validate();
|
||||||
rightPanel.validate();
|
rightPanel.validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new PlayerPanel instance
|
* Creates a new PlayerPanel instance
|
||||||
*/
|
*/
|
||||||
PlayerPanel() {
|
PlayerPanel() {
|
||||||
setLayout(null);
|
setLayout(null);
|
||||||
|
|
||||||
createLeftPanel();
|
createLeftPanel();
|
||||||
add(leftPanel);
|
add(leftPanel);
|
||||||
|
|
||||||
hand = new HandPanel();
|
hand = new HandPanel();
|
||||||
add(hand);
|
add(hand);
|
||||||
|
|
||||||
createRightPanel();
|
createRightPanel();
|
||||||
add(rightPanel);
|
add(rightPanel);
|
||||||
|
|
||||||
ComponentListener rescaleListener = new ComponentAdapter() {
|
ComponentListener rescaleListener = new ComponentAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void componentResized(ComponentEvent e) {
|
public void componentResized(ComponentEvent e) {
|
||||||
rescale();
|
rescale();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
addComponentListener(rescaleListener);
|
addComponentListener(rescaleListener);
|
||||||
hand.addComponentListener(rescaleListener);
|
hand.addComponentListener(rescaleListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LeftPanelResizeListener extends ComponentAdapter {
|
private class LeftPanelResizeListener extends ComponentAdapter {
|
||||||
@Override
|
@Override
|
||||||
public void componentResized(ComponentEvent e) {
|
public void componentResized(ComponentEvent e) {
|
||||||
Insets insets = leftPanel.getInsets();
|
Insets insets = leftPanel.getInsets();
|
||||||
int x = insets.left, y = insets.top, width = leftPanel.getWidth()
|
int x = insets.left, y = insets.top, width = leftPanel.getWidth()
|
||||||
- insets.left - insets.right, height = leftPanel.getHeight()
|
- insets.left - insets.right, height = leftPanel.getHeight()
|
||||||
- insets.top - insets.bottom;
|
- insets.top - insets.bottom;
|
||||||
|
|
||||||
if (width > SIDE_PANEL_MAX_WIDTH) {
|
if (width > SIDE_PANEL_MAX_WIDTH) {
|
||||||
x += (width - SIDE_PANEL_MAX_WIDTH) / 4;
|
x += (width - SIDE_PANEL_MAX_WIDTH) / 4;
|
||||||
width = width / 2 + SIDE_PANEL_MAX_WIDTH / 2;
|
width = width / 2 + SIDE_PANEL_MAX_WIDTH / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT);
|
int firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT);
|
||||||
int buttonWidth = (width - SIDE_PANEL_SEPARATOR) / 2;
|
int buttonWidth = (width - SIDE_PANEL_SEPARATOR) / 2;
|
||||||
int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight;
|
int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight;
|
||||||
float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
|
float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
|
||||||
if (fontSize > MAX_BUTTON_FONT_SIZE)
|
if (fontSize > MAX_BUTTON_FONT_SIZE)
|
||||||
fontSize = MAX_BUTTON_FONT_SIZE;
|
fontSize = MAX_BUTTON_FONT_SIZE;
|
||||||
|
|
||||||
currentPlayerNameLabel.setBounds(x, y, width, firstLineHeight);
|
currentPlayerNameLabel.setBounds(x, y, width, firstLineHeight);
|
||||||
sortByGroupsButton.setBounds(x, y + firstLineHeight
|
sortByGroupsButton.setBounds(x, y + firstLineHeight
|
||||||
+ SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
|
+ SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
|
||||||
sortByRunsButton.setBounds(x + buttonWidth + SIDE_PANEL_SEPARATOR, y
|
sortByRunsButton.setBounds(x + buttonWidth + SIDE_PANEL_SEPARATOR, y
|
||||||
+ firstLineHeight + SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
|
+ firstLineHeight + SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
|
||||||
|
|
||||||
sortByGroupsButton.setFont(sortByGroupsButton.getFont().deriveFont(
|
sortByGroupsButton.setFont(sortByGroupsButton.getFont().deriveFont(
|
||||||
fontSize));
|
fontSize));
|
||||||
sortByRunsButton.setFont(sortByRunsButton.getFont()
|
sortByRunsButton.setFont(sortByRunsButton.getFont().deriveFont(fontSize));
|
||||||
.deriveFont(fontSize));
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private class RightPanelResizeListener extends ComponentAdapter {
|
private class RightPanelResizeListener extends ComponentAdapter {
|
||||||
@Override
|
@Override
|
||||||
public void componentResized(ComponentEvent e) {
|
public void componentResized(ComponentEvent e) {
|
||||||
Insets insets = rightPanel.getInsets();
|
Insets insets = rightPanel.getInsets();
|
||||||
int x = insets.left, y = insets.top, width = rightPanel.getWidth()
|
int x = insets.left, y = insets.top, width = rightPanel.getWidth()
|
||||||
- insets.left - insets.right, height = rightPanel.getHeight()
|
- insets.left - insets.right, height = rightPanel.getHeight()
|
||||||
- insets.top - insets.bottom;
|
- insets.top - insets.bottom;
|
||||||
|
|
||||||
if (width > SIDE_PANEL_MAX_WIDTH) {
|
if (width > SIDE_PANEL_MAX_WIDTH) {
|
||||||
x += (width - SIDE_PANEL_MAX_WIDTH) / 4;
|
x += (width - SIDE_PANEL_MAX_WIDTH) / 4;
|
||||||
width = width / 2 + SIDE_PANEL_MAX_WIDTH / 2;
|
width = width / 2 + SIDE_PANEL_MAX_WIDTH / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT);
|
int firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT);
|
||||||
int buttonWidth = width;
|
int buttonWidth = width;
|
||||||
int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight;
|
int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight;
|
||||||
float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
|
float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
|
||||||
if (fontSize > MAX_BUTTON_FONT_SIZE)
|
if (fontSize > MAX_BUTTON_FONT_SIZE)
|
||||||
fontSize = MAX_BUTTON_FONT_SIZE;
|
fontSize = MAX_BUTTON_FONT_SIZE;
|
||||||
|
|
||||||
timeBar.setBounds(x, y, width, firstLineHeight);
|
timeBar.setBounds(x, y, width, firstLineHeight);
|
||||||
endTurnButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR,
|
endTurnButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR,
|
||||||
buttonWidth, buttonHeight);
|
buttonWidth, buttonHeight);
|
||||||
endTurnButton.setFont(endTurnButton.getFont().deriveFont(fontSize));
|
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 javax.swing.border.MatteBorder;
|
||||||
|
|
||||||
import jrummikub.model.Stone;
|
import jrummikub.model.Stone;
|
||||||
|
import jrummikub.util.IEvent;
|
||||||
import jrummikub.view.IPlayerPanel;
|
import jrummikub.view.IPlayerPanel;
|
||||||
import jrummikub.view.ITablePanel;
|
import jrummikub.view.ITablePanel;
|
||||||
import jrummikub.view.IView;
|
import jrummikub.view.IView;
|
||||||
|
@ -19,70 +20,95 @@ import jrummikub.view.IView;
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class View extends JFrame implements IView {
|
public class View extends JFrame implements IView {
|
||||||
private TablePanel table;
|
private TablePanel table;
|
||||||
private PlayerPanel playerPanel;
|
private PlayerPanel playerPanel;
|
||||||
|
private StartTurnPanel startTurnPanel;
|
||||||
|
|
||||||
private final static float PLAYER_PANEL_RATIO = 0.14f;
|
private final static float PLAYER_PANEL_RATIO = 0.14f;
|
||||||
private final static int PLAYER_PANEL_BORDER_WIDTH = 1;
|
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 int PLAYER_PANEL_MAX_HEIGHT = 180 + PLAYER_PANEL_BORDER_WIDTH;
|
||||||
|
|
||||||
private static int even(double d) {
|
private static int even(double d) {
|
||||||
return 2 * (int) (d / 2);
|
return 2 * (int) (d / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ITablePanel getTablePanel() {
|
@Override
|
||||||
return table;
|
public ITablePanel getTablePanel() {
|
||||||
}
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
public IPlayerPanel getPlayerPanel() {
|
@Override
|
||||||
return playerPanel;
|
public IPlayerPanel getPlayerPanel() {
|
||||||
}
|
return playerPanel;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance of the view
|
* Create a new instance of the view
|
||||||
*/
|
*/
|
||||||
public View() {
|
public View() {
|
||||||
super("JRummikub");
|
super("JRummikub");
|
||||||
setLayout(null);
|
setLayout(null);
|
||||||
|
|
||||||
setSize(800, 600);
|
setSize(800, 600);
|
||||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
|
|
||||||
table = new TablePanel();
|
table = new TablePanel();
|
||||||
add(table);
|
add(table);
|
||||||
|
|
||||||
playerPanel = new PlayerPanel();
|
playerPanel = new PlayerPanel();
|
||||||
playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0, 0,
|
playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0, 0,
|
||||||
Color.BLACK));
|
Color.BLACK));
|
||||||
add(playerPanel);
|
add(playerPanel);
|
||||||
|
|
||||||
addComponentListener(new ComponentAdapter() {
|
startTurnPanel = new StartTurnPanel();
|
||||||
@Override
|
startTurnPanel.setVisible(false);
|
||||||
public void componentResized(ComponentEvent e) {
|
add(startTurnPanel);
|
||||||
Insets insets = getInsets();
|
|
||||||
int width = getWidth() - insets.left
|
|
||||||
- insets.right, height = getHeight() - insets.top - insets.bottom;
|
|
||||||
|
|
||||||
int playerPanelHeight = even(Math.pow((double) width * width * height,
|
addComponentListener(new ComponentAdapter() {
|
||||||
1 / 3.0) * PLAYER_PANEL_RATIO)
|
@Override
|
||||||
+ PLAYER_PANEL_BORDER_WIDTH;
|
public void componentResized(ComponentEvent e) {
|
||||||
if (playerPanelHeight > PLAYER_PANEL_MAX_HEIGHT)
|
Insets insets = getInsets();
|
||||||
playerPanelHeight = PLAYER_PANEL_MAX_HEIGHT;
|
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);
|
int tableHeight = height - playerPanelHeight;
|
||||||
table.validate();
|
|
||||||
playerPanel.setBounds(0, tableHeight, width, playerPanelHeight);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
setVisible(true);
|
table.setBounds(0, 0, width, tableHeight);
|
||||||
}
|
table.validate();
|
||||||
|
playerPanel.setBounds(0, tableHeight, width, playerPanelHeight);
|
||||||
|
startTurnPanel.setBounds(0, tableHeight, width, playerPanelHeight);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
@Override
|
setVisible(true);
|
||||||
public void setSelectedStones(Collection<Stone> stones) {
|
}
|
||||||
table.setSelectedStones(stones);
|
|
||||||
playerPanel.getHandPanel().setSelectedStones(stones);
|
@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