summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl/PlayerPanel.java
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-05-01 19:14:55 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-05-01 19:14:55 +0200
commitb2dbfcc317d7cdec57cc4081801e75a9d25b1d07 (patch)
tree1b45352d56a4eeb3543ca1257eb322a691150607 /src/jrummikub/view/impl/PlayerPanel.java
parent5436407515a14ed6a53276c26f0b8403ec27020f (diff)
downloadJRummikub-b2dbfcc317d7cdec57cc4081801e75a9d25b1d07.tar
JRummikub-b2dbfcc317d7cdec57cc4081801e75a9d25b1d07.zip
Fix formatting
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@52 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/view/impl/PlayerPanel.java')
-rw-r--r--src/jrummikub/view/impl/PlayerPanel.java136
1 files changed, 74 insertions, 62 deletions
diff --git a/src/jrummikub/view/impl/PlayerPanel.java b/src/jrummikub/view/impl/PlayerPanel.java
index abf7cc9..ef8b4f6 100644
--- a/src/jrummikub/view/impl/PlayerPanel.java
+++ b/src/jrummikub/view/impl/PlayerPanel.java
@@ -25,24 +25,23 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
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 DecimalFormat secondFormat = new DecimalFormat("00");
-
+
private Board board;
-
+
JPanel leftPanel, rightPanel;
-
+
private JLabel currentPlayerNameLabel;
private JButton sortByNumberButton;
private JButton sortByColorButton;
private JProgressBar timeBar;
private JButton endTurnButton;
-
+
private Event sortByNumberEvent = new Event();
private Event sortByColorEvent = new Event();
private Event endTurnEvent = new Event();
-
-
+
@Override
public Board getBoard() {
return board;
@@ -52,154 +51,167 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
public void setCurrentPlayerName(String playerName) {
currentPlayerNameLabel.setText(playerName);
}
-
+
@Override
- public
- void setTimeLeft(int time) {
+ public void setTimeLeft(int time) {
timeBar.setValue(time);
- timeBar.setString(Integer.toString(time/60) + ":" + secondFormat.format(time%60));
+ timeBar.setString(Integer.toString(time / 60) + ":"
+ + secondFormat.format(time % 60));
}
-
+
@Override
public IEvent getSortByNumberEvent() {
return sortByNumberEvent;
}
-
+
@Override
public IEvent getSortByColorEvent() {
return sortByColorEvent;
}
-
+
@Override
public IEvent getEndTurnEvent() {
return endTurnEvent;
}
-
-
+
private void createLeftPanel() {
leftPanel = new JPanel();
leftPanel.setLayout(null);
leftPanel.setOpaque(false);
- leftPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET, SIDE_PANEL_INSET, SIDE_PANEL_INSET));
-
+ 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);
-
+
sortByNumberButton = new JButton("<html><center>Sort by<br>number");
sortByNumberButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
sortByNumberEvent.fire();
- }});
+ }
+ });
leftPanel.add(sortByNumberButton);
-
+
sortByColorButton = new JButton("<html><center>Sort by<br>color");
sortByColorButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
sortByColorEvent.fire();
- }});
+ }
+ });
leftPanel.add(sortByColorButton);
-
+
leftPanel.addComponentListener(new 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;
-
+ 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;
+ 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 firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT);
+ int buttonWidth = (width - SIDE_PANEL_SEPARATOR) / 2;
+
currentPlayerNameLabel.setBounds(x, y, width, firstLineHeight);
- sortByNumberButton.setBounds(x, y+firstLineHeight+SIDE_PANEL_SEPARATOR, buttonWidth, height-SIDE_PANEL_SEPARATOR-firstLineHeight);
- sortByColorButton.setBounds(x+buttonWidth+SIDE_PANEL_SEPARATOR, y+firstLineHeight+SIDE_PANEL_SEPARATOR, buttonWidth, height-SIDE_PANEL_SEPARATOR-firstLineHeight);
+ sortByNumberButton.setBounds(x, y + firstLineHeight
+ + SIDE_PANEL_SEPARATOR, buttonWidth, height - SIDE_PANEL_SEPARATOR
+ - firstLineHeight);
+ sortByColorButton.setBounds(x + buttonWidth + SIDE_PANEL_SEPARATOR, y
+ + firstLineHeight + SIDE_PANEL_SEPARATOR, buttonWidth, height
+ - SIDE_PANEL_SEPARATOR - firstLineHeight);
}
});
}
-
+
private void createRightPanel() {
rightPanel = new JPanel();
rightPanel.setLayout(null);
rightPanel.setOpaque(false);
- rightPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET, SIDE_PANEL_INSET, SIDE_PANEL_INSET));
-
+ 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);
-
+
endTurnButton = new JButton("End turn");
endTurnButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
endTurnEvent.fire();
- }});
-
+ }
+ });
+
rightPanel.add(endTurnButton);
-
+
rightPanel.addComponentListener(new 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;
-
+ 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;
+ 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 firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT);
+
timeBar.setBounds(x, y, width, firstLineHeight);
- endTurnButton.setBounds(x, y+firstLineHeight+SIDE_PANEL_SEPARATOR, width, height-SIDE_PANEL_SEPARATOR-firstLineHeight);
+ endTurnButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR,
+ width, height - SIDE_PANEL_SEPARATOR - firstLineHeight);
}
});
}
-
+
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 x = insets.left, y = insets.top, width = getWidth() - insets.left
+ - insets.right, height = getHeight() - insets.top - insets.bottom;
int boardWidth = board.getWidth();
- int panelWidth = (width-boardWidth)/2;
-
+ int panelWidth = (width - boardWidth) / 2;
+
leftPanel.setBounds(x, y, panelWidth, height);
- board.setBounds(x+panelWidth, y, boardWidth, height);
- rightPanel.setBounds(x+panelWidth+boardWidth, y, panelWidth, height);
-
+ board.setBounds(x + panelWidth, y, boardWidth, height);
+ rightPanel.setBounds(x + panelWidth + boardWidth, y, panelWidth, height);
+
leftPanel.validate();
rightPanel.validate();
}
-
-
+
PlayerPanel() {
setLayout(null);
-
+
setBackground(Color.LIGHT_GRAY);
createLeftPanel();
add(leftPanel);
-
+
board = new Board();
add(board);
-
+
createRightPanel();
add(rightPanel);
-
+
ComponentListener rescaleListener = new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
rescale();
}
};
-
+
addComponentListener(rescaleListener);
board.addComponentListener(rescaleListener);
}