Fix formatting
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@52 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
5436407515
commit
b2dbfcc317
22 changed files with 483 additions and 427 deletions
|
@ -41,19 +41,22 @@ public class JRummikub {
|
||||||
@Override
|
@Override
|
||||||
public void fire() {
|
public void fire() {
|
||||||
System.out.println("'Sort by number' fired");
|
System.out.println("'Sort by number' fired");
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
view.getPlayerPanel().getSortByColorEvent().add(new IListener() {
|
view.getPlayerPanel().getSortByColorEvent().add(new IListener() {
|
||||||
@Override
|
@Override
|
||||||
public void fire() {
|
public void fire() {
|
||||||
System.out.println("'Sort by color' fired");
|
System.out.println("'Sort by color' fired");
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
view.getPlayerPanel().getEndTurnEvent().add(new IListener() {
|
view.getPlayerPanel().getEndTurnEvent().add(new IListener() {
|
||||||
@Override
|
@Override
|
||||||
public void fire() {
|
public void fire() {
|
||||||
System.out.println("'End turn' fired");
|
System.out.println("'End turn' fired");
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//stones on the board
|
// stones on the board
|
||||||
Map<Stone, Position> stones = new HashMap<Stone, Position>();
|
Map<Stone, Position> stones = new HashMap<Stone, Position>();
|
||||||
stones.put(new Stone(1, StoneColor.ORANGE, false), new Position(0, 0));
|
stones.put(new Stone(1, StoneColor.ORANGE, false), new Position(0, 0));
|
||||||
stones.put(new Stone(10, StoneColor.BLUE, false), new Position(1, 0));
|
stones.put(new Stone(10, StoneColor.BLUE, false), new Position(1, 0));
|
||||||
|
@ -66,48 +69,65 @@ public class JRummikub {
|
||||||
|
|
||||||
view.getPlayerPanel().getBoard().setStones(stones);
|
view.getPlayerPanel().getBoard().setStones(stones);
|
||||||
|
|
||||||
view.getPlayerPanel().getBoard().getClickEvent().add(new IListener2<Position, Boolean>(){
|
view.getPlayerPanel().getBoard().getClickEvent()
|
||||||
|
.add(new IListener2<Position, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public void fire(Position p, Boolean collect) {
|
public void fire(Position p, Boolean collect) {
|
||||||
System.out.println("Board clicked at "+p+(collect?", collect":""));
|
System.out.println("Board clicked at " + p
|
||||||
|
+ (collect ? ", collect" : ""));
|
||||||
|
|
||||||
}});
|
}
|
||||||
view.getPlayerPanel().getBoard().getRangeClickEvent().add(new IListener2<Position, Boolean>(){
|
});
|
||||||
|
view.getPlayerPanel().getBoard().getRangeClickEvent()
|
||||||
|
.add(new IListener2<Position, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public void fire(Position p, Boolean collect) {
|
public void fire(Position p, Boolean collect) {
|
||||||
System.out.println("Board range-clicked at "+p+(collect?", collect":""));
|
System.out.println("Board range-clicked at " + p
|
||||||
|
+ (collect ? ", collect" : ""));
|
||||||
|
|
||||||
}});
|
}
|
||||||
view.getPlayerPanel().getBoard().getSetClickEvent().add(new IListener2<Position, Boolean>(){
|
});
|
||||||
|
view.getPlayerPanel().getBoard().getSetClickEvent()
|
||||||
|
.add(new IListener2<Position, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public void fire(Position p, Boolean collect) {
|
public void fire(Position p, Boolean collect) {
|
||||||
System.out.println("Board set-clicked at "+p+(collect?", collect":""));
|
System.out.println("Board set-clicked at " + p
|
||||||
|
+ (collect ? ", collect" : ""));
|
||||||
|
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
view.getTable().getClickEvent().add(new IListener2<Position, Boolean>(){
|
view.getTable().getClickEvent().add(new IListener2<Position, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public void fire(Position p, Boolean collect) {
|
public void fire(Position p, Boolean collect) {
|
||||||
System.out.println("Table clicked at "+p+(collect?", collect":""));
|
System.out.println("Table clicked at " + p
|
||||||
|
+ (collect ? ", collect" : ""));
|
||||||
|
|
||||||
}});
|
}
|
||||||
view.getTable().getRangeClickEvent().add(new IListener2<Position, Boolean>(){
|
});
|
||||||
|
view.getTable().getRangeClickEvent()
|
||||||
|
.add(new IListener2<Position, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public void fire(Position p, Boolean collect) {
|
public void fire(Position p, Boolean collect) {
|
||||||
System.out.println("Table range-clicked at "+p+(collect?", collect":""));
|
System.out.println("Table range-clicked at " + p
|
||||||
|
+ (collect ? ", collect" : ""));
|
||||||
|
|
||||||
}});
|
}
|
||||||
view.getTable().getSetClickEvent().add(new IListener2<Position, Boolean>(){
|
});
|
||||||
|
view.getTable().getSetClickEvent().add(new IListener2<Position, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public void fire(Position p, Boolean collect) {
|
public void fire(Position p, Boolean collect) {
|
||||||
System.out.println("Table set-clicked at "+p+(collect?", collect":""));
|
System.out.println("Table set-clicked at " + p
|
||||||
|
+ (collect ? ", collect" : ""));
|
||||||
|
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//stoneSets on the table
|
// stoneSets on the table
|
||||||
Map<StoneSet, Position> stoneSets = new HashMap<StoneSet, Position>();
|
Map<StoneSet, Position> stoneSets = new HashMap<StoneSet, Position>();
|
||||||
|
|
||||||
stoneSets.put(new StoneSet(new Stone(5, StoneColor.ORANGE, false)), new Position(0.5f, 1));
|
stoneSets.put(new StoneSet(new Stone(5, StoneColor.ORANGE, false)),
|
||||||
|
new Position(0.5f, 1));
|
||||||
|
|
||||||
List<Stone> stoneList = new ArrayList<Stone>();
|
List<Stone> stoneList = new ArrayList<Stone>();
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ package jrummikub.util;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
public class Event2<T1, T2> implements IEvent2<T1, T2> {
|
public class Event2<T1, T2> implements IEvent2<T1, T2> {
|
||||||
private HashSet<IListener2<T1, T2>> listeners = new HashSet<IListener2<T1, T2>>();
|
private HashSet<IListener2<T1, T2>> listeners = new HashSet<IListener2<T1, T2>>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(IListener2<T1, T2> listener) {
|
public void add(IListener2<T1, T2> listener) {
|
||||||
|
|
|
@ -2,5 +2,6 @@ package jrummikub.util;
|
||||||
|
|
||||||
public interface IEvent {
|
public interface IEvent {
|
||||||
public void add(IListener listener);
|
public void add(IListener listener);
|
||||||
|
|
||||||
public void remove(IListener listener);
|
public void remove(IListener listener);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,5 +2,6 @@ package jrummikub.util;
|
||||||
|
|
||||||
public interface IEvent1<T> {
|
public interface IEvent1<T> {
|
||||||
public void add(IListener1<T> listener);
|
public void add(IListener1<T> listener);
|
||||||
|
|
||||||
public void remove(IListener1<T> listener);
|
public void remove(IListener1<T> listener);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,5 +2,6 @@ package jrummikub.util;
|
||||||
|
|
||||||
public interface IEvent2<T1, T2> {
|
public interface IEvent2<T1, T2> {
|
||||||
public void add(IListener2<T1, T2> listener);
|
public void add(IListener2<T1, T2> listener);
|
||||||
|
|
||||||
public void remove(IListener2<T1, T2> listener);
|
public void remove(IListener2<T1, T2> listener);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,5 +20,4 @@ public class Pair<T1, T2> {
|
||||||
return second;
|
return second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import jrummikub.util.IEvent2;
|
||||||
|
|
||||||
public interface IClickable {
|
public interface IClickable {
|
||||||
public IEvent2<Position, Boolean> getClickEvent();
|
public IEvent2<Position, Boolean> getClickEvent();
|
||||||
|
|
||||||
public IEvent2<Position, Boolean> getRangeClickEvent();
|
public IEvent2<Position, Boolean> getRangeClickEvent();
|
||||||
|
|
||||||
public IEvent2<Position, Boolean> getSetClickEvent();
|
public IEvent2<Position, Boolean> getSetClickEvent();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,12 @@ public interface IPlayerPanel {
|
||||||
public IBoard getBoard();
|
public IBoard getBoard();
|
||||||
|
|
||||||
public void setCurrentPlayerName(String playerName);
|
public void setCurrentPlayerName(String playerName);
|
||||||
|
|
||||||
public void setTimeLeft(int time);
|
public void setTimeLeft(int time);
|
||||||
|
|
||||||
public IEvent getSortByNumberEvent();
|
public IEvent getSortByNumberEvent();
|
||||||
|
|
||||||
public IEvent getSortByColorEvent();
|
public IEvent getSortByColorEvent();
|
||||||
|
|
||||||
public IEvent getEndTurnEvent();
|
public IEvent getEndTurnEvent();
|
||||||
}
|
}
|
|
@ -7,7 +7,9 @@ import jrummikub.model.StoneSet;
|
||||||
|
|
||||||
public interface ITable extends IClickable {
|
public interface ITable extends IClickable {
|
||||||
public void setLeftPlayerName(String playerName);
|
public void setLeftPlayerName(String playerName);
|
||||||
|
|
||||||
public void setTopPlayerName(String playerName);
|
public void setTopPlayerName(String playerName);
|
||||||
|
|
||||||
public void setRightPlayerName(String playerName);
|
public void setRightPlayerName(String playerName);
|
||||||
|
|
||||||
public void setStoneSets(Map<StoneSet, Position> stoneSets);
|
public void setStoneSets(Map<StoneSet, Position> stoneSets);
|
||||||
|
|
|
@ -46,19 +46,22 @@ class Board extends StonePanel implements IBoard {
|
||||||
@Override
|
@Override
|
||||||
public void componentResized(ComponentEvent e) {
|
public void componentResized(ComponentEvent e) {
|
||||||
Insets insets = getInsets();
|
Insets insets = getInsets();
|
||||||
int size = (getHeight()-insets.top-insets.bottom)/BOARD_HEIGHT;
|
int size = (getHeight() - insets.top - insets.bottom) / BOARD_HEIGHT;
|
||||||
|
|
||||||
getStonePainter().setScale(size*StonePainter.HEIGHT_SCALE);
|
getStonePainter().setScale(size * StonePainter.HEIGHT_SCALE);
|
||||||
|
|
||||||
setSize(new Dimension(BOARD_WIDTH*getStonePainter().getStoneWidth()+insets.left+insets.right, getHeight()));
|
setSize(new Dimension(BOARD_WIDTH * getStonePainter().getStoneWidth()
|
||||||
|
+ insets.left + insets.right, getHeight()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private BufferedImage getScaledBackground(int size) {
|
private BufferedImage getScaledBackground(int size) {
|
||||||
BufferedImage scaled = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB);
|
BufferedImage scaled = new BufferedImage(size, size,
|
||||||
|
BufferedImage.TYPE_INT_RGB);
|
||||||
Graphics2D g = scaled.createGraphics();
|
Graphics2D g = scaled.createGraphics();
|
||||||
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
|
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
|
||||||
|
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
|
||||||
|
|
||||||
g.drawImage(BACKGROUND, 0, 0, size, size, null);
|
g.drawImage(BACKGROUND, 0, 0, size, size, null);
|
||||||
|
|
||||||
|
@ -68,9 +71,10 @@ class Board extends StonePanel implements IBoard {
|
||||||
@Override
|
@Override
|
||||||
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-insets.right, height = getHeight()-insets.top-insets.bottom;
|
int x = insets.left, y = insets.top, width = getWidth() - insets.left
|
||||||
Graphics2D g = (Graphics2D)g1.create(x, y, width, height);
|
- insets.right, height = getHeight() - insets.top - insets.bottom;
|
||||||
int size = height/BOARD_HEIGHT;
|
Graphics2D g = (Graphics2D) g1.create(x, y, width, height);
|
||||||
|
int size = height / BOARD_HEIGHT;
|
||||||
|
|
||||||
if (scaledBackground.getHeight() != size)
|
if (scaledBackground.getHeight() != size)
|
||||||
scaledBackground = getScaledBackground(size);
|
scaledBackground = getScaledBackground(size);
|
||||||
|
@ -81,7 +85,7 @@ class Board extends StonePanel implements IBoard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getStonePainter().setScale(size*StonePainter.HEIGHT_SCALE);
|
getStonePainter().setScale(size * StonePainter.HEIGHT_SCALE);
|
||||||
|
|
||||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
|
|
@ -30,13 +30,14 @@ class CustomBorder implements Border {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
|
public void paintBorder(Component c, Graphics g, int x, int y, int width,
|
||||||
|
int height) {
|
||||||
g.setColor(color);
|
g.setColor(color);
|
||||||
|
|
||||||
g.fillRect(x, y, width, top);
|
g.fillRect(x, y, width, top);
|
||||||
g.fillRect(x, y+height-bottom, width, bottom);
|
g.fillRect(x, y + height - bottom, width, bottom);
|
||||||
g.fillRect(x, y, left, height);
|
g.fillRect(x, y, left, height);
|
||||||
g.fillRect(x+width-right, y, right, height);
|
g.fillRect(x + width - right, y, right, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,6 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
private Event sortByColorEvent = new Event();
|
private Event sortByColorEvent = new Event();
|
||||||
private Event endTurnEvent = new Event();
|
private Event endTurnEvent = new Event();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Board getBoard() {
|
public Board getBoard() {
|
||||||
return board;
|
return board;
|
||||||
|
@ -54,10 +53,10 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public
|
public void setTimeLeft(int time) {
|
||||||
void setTimeLeft(int time) {
|
|
||||||
timeBar.setValue(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
|
@Override
|
||||||
|
@ -75,12 +74,12 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
return endTurnEvent;
|
return endTurnEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void createLeftPanel() {
|
private void createLeftPanel() {
|
||||||
leftPanel = new JPanel();
|
leftPanel = new JPanel();
|
||||||
leftPanel.setLayout(null);
|
leftPanel.setLayout(null);
|
||||||
leftPanel.setOpaque(false);
|
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 = new JLabel();
|
||||||
currentPlayerNameLabel.setHorizontalAlignment(JLabel.CENTER);
|
currentPlayerNameLabel.setHorizontalAlignment(JLabel.CENTER);
|
||||||
|
@ -94,7 +93,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
sortByNumberEvent.fire();
|
sortByNumberEvent.fire();
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
leftPanel.add(sortByNumberButton);
|
leftPanel.add(sortByNumberButton);
|
||||||
|
|
||||||
sortByColorButton = new JButton("<html><center>Sort by<br>color");
|
sortByColorButton = new JButton("<html><center>Sort by<br>color");
|
||||||
|
@ -102,26 +102,33 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
sortByColorEvent.fire();
|
sortByColorEvent.fire();
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
leftPanel.add(sortByColorButton);
|
leftPanel.add(sortByColorButton);
|
||||||
|
|
||||||
leftPanel.addComponentListener(new ComponentAdapter() {
|
leftPanel.addComponentListener(new 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()-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) {
|
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;
|
||||||
|
|
||||||
currentPlayerNameLabel.setBounds(x, y, width, firstLineHeight);
|
currentPlayerNameLabel.setBounds(x, y, width, firstLineHeight);
|
||||||
sortByNumberButton.setBounds(x, y+firstLineHeight+SIDE_PANEL_SEPARATOR, buttonWidth, height-SIDE_PANEL_SEPARATOR-firstLineHeight);
|
sortByNumberButton.setBounds(x, y + firstLineHeight
|
||||||
sortByColorButton.setBounds(x+buttonWidth+SIDE_PANEL_SEPARATOR, y+firstLineHeight+SIDE_PANEL_SEPARATOR, buttonWidth, height-SIDE_PANEL_SEPARATOR-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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -130,7 +137,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
rightPanel = new JPanel();
|
rightPanel = new JPanel();
|
||||||
rightPanel.setLayout(null);
|
rightPanel.setLayout(null);
|
||||||
rightPanel.setOpaque(false);
|
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 = new JProgressBar(0, 60);
|
||||||
timeBar.setStringPainted(true);
|
timeBar.setStringPainted(true);
|
||||||
|
@ -141,7 +149,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
endTurnEvent.fire();
|
endTurnEvent.fire();
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
rightPanel.add(endTurnButton);
|
rightPanel.add(endTurnButton);
|
||||||
|
|
||||||
|
@ -149,36 +158,39 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
@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()-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) {
|
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);
|
||||||
|
|
||||||
timeBar.setBounds(x, y, width, firstLineHeight);
|
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() {
|
private void rescale() {
|
||||||
Insets insets = getInsets();
|
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 boardWidth = board.getWidth();
|
||||||
int panelWidth = (width-boardWidth)/2;
|
int panelWidth = (width - boardWidth) / 2;
|
||||||
|
|
||||||
leftPanel.setBounds(x, y, panelWidth, height);
|
leftPanel.setBounds(x, y, panelWidth, height);
|
||||||
board.setBounds(x+panelWidth, y, boardWidth, height);
|
board.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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PlayerPanel() {
|
PlayerPanel() {
|
||||||
setLayout(null);
|
setLayout(null);
|
||||||
|
|
||||||
|
|
|
@ -26,14 +26,12 @@ class StonePainter {
|
||||||
|
|
||||||
private static final float BRIGHTER_SCALE = 1.15f;
|
private static final float BRIGHTER_SCALE = 1.15f;
|
||||||
|
|
||||||
public static final float HEIGHT_SCALE = ASPECT_RATIO/DEFAULT_WIDTH;
|
public static final float HEIGHT_SCALE = ASPECT_RATIO / DEFAULT_WIDTH;
|
||||||
|
|
||||||
|
|
||||||
private float scale;
|
private float scale;
|
||||||
|
|
||||||
|
|
||||||
private static int even(float f) {
|
private static int even(float f) {
|
||||||
return 2*(int)(f/2);
|
return 2 * (int) (f / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Color brighter(Color color) {
|
private static Color brighter(Color color) {
|
||||||
|
@ -41,11 +39,11 @@ class StonePainter {
|
||||||
int g = (int) (color.getRed() * BRIGHTER_SCALE);
|
int g = (int) (color.getRed() * BRIGHTER_SCALE);
|
||||||
int b = (int) (color.getRed() * BRIGHTER_SCALE);
|
int b = (int) (color.getRed() * BRIGHTER_SCALE);
|
||||||
|
|
||||||
return new Color(r>255?255:r, g>255?255:g, b>255?255:b);
|
return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255 : b);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Color getColor(StoneColor color) {
|
private static Color getColor(StoneColor color) {
|
||||||
switch(color) {
|
switch (color) {
|
||||||
case BLACK:
|
case BLACK:
|
||||||
return new Color(0.15f, 0.15f, 0.15f);
|
return new Color(0.15f, 0.15f, 0.15f);
|
||||||
case BLUE:
|
case BLUE:
|
||||||
|
@ -68,31 +66,33 @@ class StonePainter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param x x position in screen coordinates
|
* @param x
|
||||||
* @param y y position in screen coordinates
|
* x position in screen coordinates
|
||||||
|
* @param y
|
||||||
|
* y position in screen coordinates
|
||||||
* @return position in grid coordinates
|
* @return position in grid coordinates
|
||||||
*/
|
*/
|
||||||
public Position calculatePosition(int x, int y){
|
public Position calculatePosition(int x, int y) {
|
||||||
float width = getStoneWidth();
|
float width = getStoneWidth();
|
||||||
float height = getStoneHeight();
|
float height = getStoneHeight();
|
||||||
|
|
||||||
return new Position(x/width, y/height);
|
return new Position(x / width, y / height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStoneWidth() {
|
public int getStoneWidth() {
|
||||||
return even(DEFAULT_WIDTH*scale);
|
return even(DEFAULT_WIDTH * scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStoneHeight() {
|
public int getStoneHeight() {
|
||||||
return (int)(DEFAULT_WIDTH*scale/ASPECT_RATIO);
|
return (int) (DEFAULT_WIDTH * scale / ASPECT_RATIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
StonePainter(float scale) {
|
StonePainter(float scale) {
|
||||||
this.scale = scale;
|
this.scale = scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void paintStoneBackground(Graphics2D g, int x, int y,
|
private void paintStoneBackground(Graphics2D g, int x, int y, int width,
|
||||||
int width, int height, Color background) {
|
int height, Color background) {
|
||||||
// Paint background
|
// Paint background
|
||||||
g.setColor(background);
|
g.setColor(background);
|
||||||
g.fillRect(x, y, width, height);
|
g.fillRect(x, y, width, height);
|
||||||
|
@ -101,22 +101,22 @@ class StonePainter {
|
||||||
g.setColor(brighter(brighter(background)));
|
g.setColor(brighter(brighter(background)));
|
||||||
g.fillRect(x, y, 1, height);
|
g.fillRect(x, y, 1, height);
|
||||||
g.setColor(brighter(background));
|
g.setColor(brighter(background));
|
||||||
g.fillRect(x+1, y+1, 1, height-2);
|
g.fillRect(x + 1, y + 1, 1, height - 2);
|
||||||
|
|
||||||
g.setColor(brighter(brighter(background)));
|
g.setColor(brighter(brighter(background)));
|
||||||
g.fillRect(x, y, width, 1);
|
g.fillRect(x, y, width, 1);
|
||||||
g.setColor(brighter(background));
|
g.setColor(brighter(background));
|
||||||
g.fillRect(x+1, y+1, width-2, 1);
|
g.fillRect(x + 1, y + 1, width - 2, 1);
|
||||||
|
|
||||||
g.setColor(background.darker().darker());
|
g.setColor(background.darker().darker());
|
||||||
g.fillRect(x+width-1, y, 1, height);
|
g.fillRect(x + width - 1, y, 1, height);
|
||||||
g.setColor(background.darker());
|
g.setColor(background.darker());
|
||||||
g.fillRect(x+width-2, y+1, 1, height-2);
|
g.fillRect(x + width - 2, y + 1, 1, height - 2);
|
||||||
|
|
||||||
g.setColor(background.darker().darker());
|
g.setColor(background.darker().darker());
|
||||||
g.fillRect(x, y+height-1, width, 1);
|
g.fillRect(x, y + height - 1, width, 1);
|
||||||
g.setColor(background.darker());
|
g.setColor(background.darker());
|
||||||
g.fillRect(x+1, y+height-2, width-2, 1);
|
g.fillRect(x + 1, y + height - 2, width - 2, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void paintJokerFace(Graphics2D g, int x, int y, int width, int height) {
|
private void paintJokerFace(Graphics2D g, int x, int y, int width, int height) {
|
||||||
|
@ -128,40 +128,40 @@ class StonePainter {
|
||||||
g.setStroke(new BasicStroke(1));
|
g.setStroke(new BasicStroke(1));
|
||||||
GeneralPath path = new GeneralPath();
|
GeneralPath path = new GeneralPath();
|
||||||
// nose
|
// nose
|
||||||
path.moveTo(x+0.5f*width, y+0.45f*height);
|
path.moveTo(x + 0.5f * width, y + 0.45f * height);
|
||||||
path.lineTo(x+0.53f*width, y+0.6f*height);
|
path.lineTo(x + 0.53f * width, y + 0.6f * height);
|
||||||
path.lineTo(x+0.47f*width, y+0.6f*height);
|
path.lineTo(x + 0.47f * width, y + 0.6f * height);
|
||||||
path.closePath();
|
path.closePath();
|
||||||
g.fill(path);
|
g.fill(path);
|
||||||
|
|
||||||
path.reset();
|
path.reset();
|
||||||
// mouth, left
|
// mouth, left
|
||||||
path.moveTo(x+0.23f*width, y+0.75f*width);
|
path.moveTo(x + 0.23f * width, y + 0.75f * width);
|
||||||
path.lineTo(x+0.27f*width, y+0.65f*width);
|
path.lineTo(x + 0.27f * width, y + 0.65f * width);
|
||||||
// mouth, middle
|
// mouth, middle
|
||||||
path.moveTo(x+0.25f*width, y+0.7f*width);
|
path.moveTo(x + 0.25f * width, y + 0.7f * width);
|
||||||
path.lineTo(x+0.5f*width, y+0.8f*width);
|
path.lineTo(x + 0.5f * width, y + 0.8f * width);
|
||||||
path.lineTo(x+0.75f*width, y+0.7f*width);
|
path.lineTo(x + 0.75f * width, y + 0.7f * width);
|
||||||
// mouth, right
|
// mouth, right
|
||||||
path.moveTo(x+0.77f*width, y+0.75f*width);
|
path.moveTo(x + 0.77f * width, y + 0.75f * width);
|
||||||
path.lineTo(x+0.73f*width, y+0.65f*width);
|
path.lineTo(x + 0.73f * width, y + 0.65f * width);
|
||||||
g.draw(path);
|
g.draw(path);
|
||||||
|
|
||||||
path.reset();
|
path.reset();
|
||||||
// left eye
|
// left eye
|
||||||
path.moveTo(x+0.3f*width, y+0.41f*height);
|
path.moveTo(x + 0.3f * width, y + 0.41f * height);
|
||||||
path.lineTo(x+0.375f*width, y+0.375f*height);
|
path.lineTo(x + 0.375f * width, y + 0.375f * height);
|
||||||
path.lineTo(x+0.3f*width, y+0.34f*height);
|
path.lineTo(x + 0.3f * width, y + 0.34f * height);
|
||||||
path.lineTo(x+0.225f*width, y+0.375f*height);
|
path.lineTo(x + 0.225f * width, y + 0.375f * height);
|
||||||
path.closePath();
|
path.closePath();
|
||||||
g.draw(path);
|
g.draw(path);
|
||||||
|
|
||||||
path.reset();
|
path.reset();
|
||||||
// right eye
|
// right eye
|
||||||
path.moveTo(x+0.7f*width, y+0.41f*height);
|
path.moveTo(x + 0.7f * width, y + 0.41f * height);
|
||||||
path.lineTo(x+0.625f*width, y+0.375f*height);
|
path.lineTo(x + 0.625f * width, y + 0.375f * height);
|
||||||
path.lineTo(x+0.7f*width, y+0.34f*height);
|
path.lineTo(x + 0.7f * width, y + 0.34f * height);
|
||||||
path.lineTo(x+0.775f*width, y+0.375f*height);
|
path.lineTo(x + 0.775f * width, y + 0.375f * height);
|
||||||
path.closePath();
|
path.closePath();
|
||||||
g.draw(path);
|
g.draw(path);
|
||||||
|
|
||||||
|
@ -170,38 +170,43 @@ class StonePainter {
|
||||||
|
|
||||||
private void paintJoker(Graphics2D g, int x, int y, int width, int height,
|
private void paintJoker(Graphics2D g, int x, int y, int width, int height,
|
||||||
Color color) {
|
Color color) {
|
||||||
int faceSize = even(FACE_WIDTH*width);
|
int faceSize = even(FACE_WIDTH * width);
|
||||||
int pos = y + (int)(TEXT_POS*height);
|
int pos = y + (int) (TEXT_POS * height);
|
||||||
|
|
||||||
g.setColor(color);
|
g.setColor(color);
|
||||||
paintJokerFace(g, x+width/2-faceSize/2, pos-faceSize/2, faceSize, faceSize);
|
paintJokerFace(g, x + width / 2 - faceSize / 2, pos - faceSize / 2,
|
||||||
|
faceSize, faceSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void paintStoneNumber(Graphics2D g, int x, int y, int width,
|
private void paintStoneNumber(Graphics2D g, int x, int y, int width,
|
||||||
int height, Color color, int v) {
|
int height, Color color, int v) {
|
||||||
int pos = y + (int)(TEXT_POS*height);
|
int pos = y + (int) (TEXT_POS * height);
|
||||||
|
|
||||||
g.setFont(new Font("SansSerif", Font.BOLD, height/4));
|
g.setFont(new Font("SansSerif", Font.BOLD, height / 4));
|
||||||
FontMetrics fm = g.getFontMetrics();
|
FontMetrics fm = g.getFontMetrics();
|
||||||
String value = Integer.toString(v);
|
String value = Integer.toString(v);
|
||||||
Rectangle2D stringRect = fm.getStringBounds(value, g);
|
Rectangle2D stringRect = fm.getStringBounds(value, g);
|
||||||
|
|
||||||
g.setColor(color.darker());
|
g.setColor(color.darker());
|
||||||
g.drawString(value, (int)(x+width/2-stringRect.getWidth()/2)+1, pos+(fm.getAscent()-fm.getDescent())/2+1);
|
g.drawString(value, (int) (x + width / 2 - stringRect.getWidth() / 2) + 1,
|
||||||
|
pos + (fm.getAscent() - fm.getDescent()) / 2 + 1);
|
||||||
g.setColor(color);
|
g.setColor(color);
|
||||||
g.drawString(value, (int)(x+width/2-stringRect.getWidth()/2), pos+(fm.getAscent()-fm.getDescent())/2);
|
g.drawString(value, (int) (x + width / 2 - stringRect.getWidth() / 2), pos
|
||||||
|
+ (fm.getAscent() - fm.getDescent()) / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void paintCircle(Graphics2D g, int x, int y, int width, int height, Color background) {
|
private void paintCircle(Graphics2D g, int x, int y, int width, int height,
|
||||||
int size = even(width*CIRCLE_WIDTH);
|
Color background) {
|
||||||
int pos = y + (int)(CIRCLE_POS*height);
|
int size = even(width * CIRCLE_WIDTH);
|
||||||
|
int pos = y + (int) (CIRCLE_POS * height);
|
||||||
|
|
||||||
// Paint circle
|
// Paint circle
|
||||||
g.setColor(background.darker());
|
g.setColor(background.darker());
|
||||||
g.drawArc(x+width/2-size/2, pos-size/2, size, size, 50, 170);
|
g.drawArc(x + width / 2 - size / 2, pos - size / 2, size, size, 50, 170);
|
||||||
|
|
||||||
g.setColor(brighter(background));
|
g.setColor(brighter(background));
|
||||||
g.drawArc((int)(x+width/2-size/2), pos-size/2, size, size, -130, 170);
|
g.drawArc((int) (x + width / 2 - size / 2), pos - size / 2, size, size,
|
||||||
|
-130, 170);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paintStone(Graphics2D g, Stone stone, Position p, boolean selected) {
|
public void paintStone(Graphics2D g, Stone stone, Position p, boolean selected) {
|
||||||
|
@ -209,8 +214,8 @@ class StonePainter {
|
||||||
int width = getStoneWidth();
|
int width = getStoneWidth();
|
||||||
int height = getStoneHeight();
|
int height = getStoneHeight();
|
||||||
|
|
||||||
int x = (int)(p.getX()*width);
|
int x = (int) (p.getX() * width);
|
||||||
int y = (int)(p.getY()*height);
|
int y = (int) (p.getY() * height);
|
||||||
|
|
||||||
paintStoneBackground(g, x, y, width, height, background);
|
paintStoneBackground(g, x, y, width, height, background);
|
||||||
|
|
||||||
|
|
|
@ -42,8 +42,9 @@ abstract class StonePanel extends JPanel implements IClickable {
|
||||||
else if (e.getClickCount() >= 2)
|
else if (e.getClickCount() >= 2)
|
||||||
event = setClickEvent;
|
event = setClickEvent;
|
||||||
|
|
||||||
event.fire(stonePainter.calculatePosition(e.getX() - insets.left,
|
event.fire(
|
||||||
e.getY() - insets.top), e.isControlDown());
|
stonePainter.calculatePosition(e.getX() - insets.left, e.getY()
|
||||||
|
- insets.top), e.isControlDown());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ import jrummikub.model.StoneSet;
|
||||||
import jrummikub.view.ITable;
|
import jrummikub.view.ITable;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class Table extends StonePanel implements ITable {
|
class Table extends StonePanel implements ITable {
|
||||||
private final static ImageIcon background = new ImageIcon(
|
private final static ImageIcon background = new ImageIcon(
|
||||||
Board.class.getResource("/jrummikub/resource/felt.png"));
|
Board.class.getResource("/jrummikub/resource/felt.png"));
|
||||||
private final static float DEFAULT_SCALE = 1;
|
private final static float DEFAULT_SCALE = 1;
|
||||||
|
@ -32,7 +32,6 @@ public class Table extends StonePanel implements ITable {
|
||||||
private Map<StoneSet, Position> stoneSets = Collections.emptyMap();
|
private Map<StoneSet, Position> stoneSets = Collections.emptyMap();
|
||||||
private Collection<Stone> selectedStones = Collections.emptyList();
|
private Collection<Stone> selectedStones = Collections.emptyList();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLeftPlayerName(String playerName) {
|
public void setLeftPlayerName(String playerName) {
|
||||||
leftPlayerLabel.setText(playerName);
|
leftPlayerLabel.setText(playerName);
|
||||||
|
@ -110,15 +109,15 @@ public class Table extends StonePanel implements ITable {
|
||||||
paintStoneSet(g, stoneSet.getKey(), stoneSet.getValue());
|
paintStoneSet(g, stoneSet.getKey(), stoneSet.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
int selectedStonesWidth = getWidth()*3/5-14;
|
int selectedStonesWidth = getWidth() * 3 / 5 - 14;
|
||||||
int selectedStonesHeight = selectedStonePainter.getStoneHeight();
|
int selectedStonesHeight = selectedStonePainter.getStoneHeight();
|
||||||
int selectedStonesX = getWidth() / 2 - selectedStonesWidth / 2;
|
int selectedStonesX = getWidth() / 2 - selectedStonesWidth / 2;
|
||||||
int selectedStonesY = getHeight() - selectedStonesHeight - 12;
|
int selectedStonesY = getHeight() - selectedStonesHeight - 12;
|
||||||
|
|
||||||
if (!selectedStones.isEmpty()) {
|
if (!selectedStones.isEmpty()) {
|
||||||
g.setColor(new Color(0, 0, 0, 0.3f));
|
g.setColor(new Color(0, 0, 0, 0.3f));
|
||||||
g.fillRect(selectedStonesX-7, selectedStonesY-7, selectedStonesWidth + 14,
|
g.fillRect(selectedStonesX - 7, selectedStonesY - 7,
|
||||||
selectedStonesHeight + 14);
|
selectedStonesWidth + 14, selectedStonesHeight + 14);
|
||||||
|
|
||||||
Graphics2D translatedG = (Graphics2D) g.create(selectedStonesX,
|
Graphics2D translatedG = (Graphics2D) g.create(selectedStonesX,
|
||||||
selectedStonesY, selectedStonesWidth, selectedStonesHeight);
|
selectedStonesY, selectedStonesWidth, selectedStonesHeight);
|
||||||
|
@ -126,7 +125,8 @@ public class Table extends StonePanel implements ITable {
|
||||||
float x = 0;
|
float x = 0;
|
||||||
|
|
||||||
for (Stone stone : selectedStones) {
|
for (Stone stone : selectedStones) {
|
||||||
selectedStonePainter.paintStone(translatedG, stone, new Position(x, 0), false);
|
selectedStonePainter.paintStone(translatedG, stone, new Position(x, 0),
|
||||||
|
false);
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package jrummikub.view.impl;
|
package jrummikub.view.impl;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.event.ComponentAdapter;
|
import java.awt.event.ComponentAdapter;
|
||||||
import java.awt.event.ComponentEvent;
|
import java.awt.event.ComponentEvent;
|
||||||
|
@ -23,9 +22,8 @@ public class View extends JFrame implements IView {
|
||||||
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 ITable getTable() {
|
public ITable getTable() {
|
||||||
|
@ -36,7 +34,6 @@ public class View extends JFrame implements IView {
|
||||||
return playerPanel;
|
return playerPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public View() {
|
public View() {
|
||||||
super("JRummikub");
|
super("JRummikub");
|
||||||
setLayout(null);
|
setLayout(null);
|
||||||
|
@ -48,16 +45,20 @@ public class View extends JFrame implements IView {
|
||||||
add(table);
|
add(table);
|
||||||
|
|
||||||
playerPanel = new PlayerPanel();
|
playerPanel = new PlayerPanel();
|
||||||
playerPanel.setBorder(new CustomBorder(Color.BLACK, PLAYER_PANEL_BORDER_WIDTH, 0, 0, 0));
|
playerPanel.setBorder(new CustomBorder(Color.BLACK,
|
||||||
|
PLAYER_PANEL_BORDER_WIDTH, 0, 0, 0));
|
||||||
add(playerPanel);
|
add(playerPanel);
|
||||||
|
|
||||||
addComponentListener(new ComponentAdapter() {
|
addComponentListener(new ComponentAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void componentResized(ComponentEvent e) {
|
public void componentResized(ComponentEvent e) {
|
||||||
Insets insets = getInsets();
|
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 playerPanelHeight = even(Math.pow((double)width*width*height, 1/3.0)*PLAYER_PANEL_RATIO) + PLAYER_PANEL_BORDER_WIDTH;
|
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)
|
if (playerPanelHeight > PLAYER_PANEL_MAX_HEIGHT)
|
||||||
playerPanelHeight = PLAYER_PANEL_MAX_HEIGHT;
|
playerPanelHeight = PLAYER_PANEL_MAX_HEIGHT;
|
||||||
|
|
||||||
|
@ -65,7 +66,7 @@ public class View extends JFrame implements IView {
|
||||||
|
|
||||||
table.setBounds(x, y, width, tableHeight);
|
table.setBounds(x, y, width, tableHeight);
|
||||||
table.validate();
|
table.validate();
|
||||||
playerPanel.setBounds(x, y+tableHeight, width, playerPanelHeight);
|
playerPanel.setBounds(x, y + tableHeight, width, playerPanelHeight);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,8 @@ public class Event1Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void removeListener() {
|
@Test
|
||||||
|
public void removeListener() {
|
||||||
fired = 0;
|
fired = 0;
|
||||||
Event1<Integer> testEvent = new Event1<Integer>();
|
Event1<Integer> testEvent = new Event1<Integer>();
|
||||||
testEvent.add(new IListener1<Integer>() {
|
testEvent.add(new IListener1<Integer>() {
|
||||||
|
|
|
@ -65,7 +65,8 @@ public class Event2Test {
|
||||||
assertEquals(fired4, -10);
|
assertEquals(fired4, -10);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void removeListener() {
|
@Test
|
||||||
|
public void removeListener() {
|
||||||
fired = 0;
|
fired = 0;
|
||||||
fired2 = 0;
|
fired2 = 0;
|
||||||
Event2<Integer, Integer> testEvent = new Event2<Integer, Integer>();
|
Event2<Integer, Integer> testEvent = new Event2<Integer, Integer>();
|
||||||
|
|
|
@ -55,7 +55,8 @@ public class EventTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void removeListener() {
|
@Test
|
||||||
|
public void removeListener() {
|
||||||
fired = false;
|
fired = false;
|
||||||
Event testEvent = new Event();
|
Event testEvent = new Event();
|
||||||
testEvent.add(new IListener() {
|
testEvent.add(new IListener() {
|
||||||
|
|
Reference in a new issue