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
|
@ -28,97 +28,117 @@ public class JRummikub {
|
||||||
UIManager.setLookAndFeel(nativeLF);
|
UIManager.setLookAndFeel(nativeLF);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
IView view = new jrummikub.view.impl.View();
|
IView view = new jrummikub.view.impl.View();
|
||||||
|
|
||||||
view.getPlayerPanel().setCurrentPlayerName("Player 1");
|
view.getPlayerPanel().setCurrentPlayerName("Player 1");
|
||||||
view.getPlayerPanel().setTimeLeft(42);
|
view.getPlayerPanel().setTimeLeft(42);
|
||||||
view.getTable().setLeftPlayerName("Player 2");
|
view.getTable().setLeftPlayerName("Player 2");
|
||||||
view.getTable().setTopPlayerName("Player 3");
|
view.getTable().setTopPlayerName("Player 3");
|
||||||
view.getTable().setRightPlayerName("Player 4");
|
view.getTable().setRightPlayerName("Player 4");
|
||||||
|
|
||||||
view.getPlayerPanel().getSortByNumberEvent().add(new IListener() {
|
view.getPlayerPanel().getSortByNumberEvent().add(new IListener() {
|
||||||
@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));
|
||||||
stones.put(new Stone(9, StoneColor.RED, false), new Position(0.5f, 1));
|
stones.put(new Stone(9, StoneColor.RED, false), new Position(0.5f, 1));
|
||||||
stones.put(new Stone(7, StoneColor.BLACK, false), new Position(1.75f, 1));
|
stones.put(new Stone(7, StoneColor.BLACK, false), new Position(1.75f, 1));
|
||||||
|
|
||||||
Stone stoneJoker = new Stone(0, StoneColor.RED, true);
|
Stone stoneJoker = new Stone(0, StoneColor.RED, true);
|
||||||
stones.put(stoneJoker, new Position(2.5f, 0));
|
stones.put(stoneJoker, new Position(2.5f, 0));
|
||||||
stones.put(new Stone(0, StoneColor.BLACK, true), new Position(3.5f, 0));
|
stones.put(new Stone(0, StoneColor.BLACK, true), new Position(3.5f, 0));
|
||||||
|
|
||||||
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
|
||||||
|
public void fire(Position p, Boolean collect) {
|
||||||
|
System.out.println("Board clicked at " + p
|
||||||
|
+ (collect ? ", collect" : ""));
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
view.getPlayerPanel().getBoard().getRangeClickEvent()
|
||||||
|
.add(new IListener2<Position, Boolean>() {
|
||||||
|
@Override
|
||||||
|
public void fire(Position p, Boolean collect) {
|
||||||
|
System.out.println("Board range-clicked at " + p
|
||||||
|
+ (collect ? ", collect" : ""));
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
view.getPlayerPanel().getBoard().getSetClickEvent()
|
||||||
|
.add(new IListener2<Position, Boolean>() {
|
||||||
|
@Override
|
||||||
|
public void fire(Position p, Boolean collect) {
|
||||||
|
System.out.println("Board set-clicked at " + p
|
||||||
|
+ (collect ? ", collect" : ""));
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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("Board clicked at "+p+(collect?", collect":""));
|
System.out.println("Table clicked at " + p
|
||||||
|
+ (collect ? ", collect" : ""));
|
||||||
}});
|
|
||||||
view.getPlayerPanel().getBoard().getRangeClickEvent().add(new IListener2<Position, Boolean>(){
|
}
|
||||||
|
});
|
||||||
|
view.getTable().getRangeClickEvent()
|
||||||
|
.add(new IListener2<Position, Boolean>() {
|
||||||
|
@Override
|
||||||
|
public void fire(Position p, Boolean collect) {
|
||||||
|
System.out.println("Table range-clicked at " + p
|
||||||
|
+ (collect ? ", collect" : ""));
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
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("Board range-clicked at "+p+(collect?", collect":""));
|
System.out.println("Table set-clicked at " + p
|
||||||
|
+ (collect ? ", collect" : ""));
|
||||||
}});
|
|
||||||
view.getPlayerPanel().getBoard().getSetClickEvent().add(new IListener2<Position, Boolean>(){
|
}
|
||||||
@Override
|
});
|
||||||
public void fire(Position p, Boolean collect) {
|
|
||||||
System.out.println("Board set-clicked at "+p+(collect?", collect":""));
|
// stoneSets on the table
|
||||||
|
|
||||||
}});
|
|
||||||
|
|
||||||
view.getTable().getClickEvent().add(new IListener2<Position, Boolean>(){
|
|
||||||
@Override
|
|
||||||
public void fire(Position p, Boolean collect) {
|
|
||||||
System.out.println("Table clicked at "+p+(collect?", collect":""));
|
|
||||||
|
|
||||||
}});
|
|
||||||
view.getTable().getRangeClickEvent().add(new IListener2<Position, Boolean>(){
|
|
||||||
@Override
|
|
||||||
public void fire(Position p, Boolean collect) {
|
|
||||||
System.out.println("Table range-clicked at "+p+(collect?", collect":""));
|
|
||||||
|
|
||||||
}});
|
|
||||||
view.getTable().getSetClickEvent().add(new IListener2<Position, Boolean>(){
|
|
||||||
@Override
|
|
||||||
public void fire(Position p, Boolean collect) {
|
|
||||||
System.out.println("Table set-clicked at "+p+(collect?", collect":""));
|
|
||||||
|
|
||||||
}});
|
|
||||||
|
|
||||||
//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>();
|
||||||
|
|
||||||
stoneList.add(new Stone(7, StoneColor.BLACK, false));
|
stoneList.add(new Stone(7, StoneColor.BLACK, false));
|
||||||
Stone stone8 = new Stone(8, StoneColor.BLACK, false);
|
Stone stone8 = new Stone(8, StoneColor.BLACK, false);
|
||||||
stoneList.add(stone8);
|
stoneList.add(stone8);
|
||||||
stoneList.add(new Stone(9, StoneColor.BLACK, false));
|
stoneList.add(new Stone(9, StoneColor.BLACK, false));
|
||||||
stoneList.add(new Stone(10, StoneColor.BLACK, false));
|
stoneList.add(new Stone(10, StoneColor.BLACK, false));
|
||||||
|
|
||||||
stoneSets.put(new StoneSet(stoneList), new Position(3.5f, 4));
|
stoneSets.put(new StoneSet(stoneList), new Position(3.5f, 4));
|
||||||
|
|
||||||
view.getTable().setStoneSets(stoneSets);
|
view.getTable().setStoneSets(stoneSets);
|
||||||
|
|
||||||
view.setSelectedStones(Arrays.asList(stoneJoker, stone8));
|
view.setSelectedStones(Arrays.asList(stoneJoker, stone8));
|
||||||
|
|
|
@ -4,7 +4,7 @@ import java.util.HashSet;
|
||||||
|
|
||||||
public class Event implements IEvent {
|
public class Event implements IEvent {
|
||||||
private HashSet<IListener> listeners = new HashSet<IListener>();
|
private HashSet<IListener> listeners = new HashSet<IListener>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(IListener listener) {
|
public void add(IListener listener) {
|
||||||
listeners.add(listener);
|
listeners.add(listener);
|
||||||
|
|
|
@ -4,7 +4,7 @@ import java.util.HashSet;
|
||||||
|
|
||||||
public class Event1<T> implements IEvent1<T> {
|
public class Event1<T> implements IEvent1<T> {
|
||||||
private HashSet<IListener1<T>> listeners = new HashSet<IListener1<T>>();
|
private HashSet<IListener1<T>> listeners = new HashSet<IListener1<T>>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(IListener1<T> listener) {
|
public void add(IListener1<T> listener) {
|
||||||
listeners.add(listener);
|
listeners.add(listener);
|
||||||
|
|
|
@ -3,8 +3,8 @@ 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) {
|
||||||
listeners.add(listener);
|
listeners.add(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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,21 +4,20 @@ package jrummikub.util;
|
||||||
* A pair of objects
|
* A pair of objects
|
||||||
*/
|
*/
|
||||||
public class Pair<T1, T2> {
|
public class Pair<T1, T2> {
|
||||||
final T1 first;
|
final T1 first;
|
||||||
final T2 second;
|
final T2 second;
|
||||||
|
|
||||||
public Pair(T1 first, T2 second) {
|
|
||||||
this.first = first;
|
|
||||||
this.second = second;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T1 getFirst() {
|
public Pair(T1 first, T2 second) {
|
||||||
return first;
|
this.first = first;
|
||||||
}
|
this.second = second;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T1 getFirst() {
|
||||||
|
return first;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T2 getSecond() {
|
||||||
|
return second;
|
||||||
|
}
|
||||||
|
|
||||||
public T2 getSecond() {
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,14 @@ import jrummikub.util.IEvent;
|
||||||
|
|
||||||
public interface IPlayerPanel {
|
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,8 +7,10 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,4 +16,4 @@ public interface IView {
|
||||||
public IPlayerPanel getPlayerPanel();
|
public IPlayerPanel getPlayerPanel();
|
||||||
|
|
||||||
public void setSelectedStones(Collection<Stone> stones);
|
public void setSelectedStones(Collection<Stone> stones);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,14 +23,14 @@ import jrummikub.view.IBoard;
|
||||||
class Board extends StonePanel implements IBoard {
|
class Board extends StonePanel implements IBoard {
|
||||||
private final static int BOARD_HEIGHT = 2;
|
private final static int BOARD_HEIGHT = 2;
|
||||||
private final static int BOARD_WIDTH = 14;
|
private final static int BOARD_WIDTH = 14;
|
||||||
|
|
||||||
private final static BufferedImage BACKGROUND;
|
private final static BufferedImage BACKGROUND;
|
||||||
static {
|
static {
|
||||||
ImageIcon image = new ImageIcon(
|
ImageIcon image = new ImageIcon(
|
||||||
Board.class.getResource("/jrummikub/resource/wood.png"));
|
Board.class.getResource("/jrummikub/resource/wood.png"));
|
||||||
BACKGROUND = new BufferedImage(image.getIconWidth(), image.getIconHeight(),
|
BACKGROUND = new BufferedImage(image.getIconWidth(), image.getIconHeight(),
|
||||||
BufferedImage.TYPE_INT_RGB);
|
BufferedImage.TYPE_INT_RGB);
|
||||||
|
|
||||||
image.paintIcon(null, BACKGROUND.createGraphics(), 0, 0);
|
image.paintIcon(null, BACKGROUND.createGraphics(), 0, 0);
|
||||||
}
|
}
|
||||||
private BufferedImage scaledBackground = BACKGROUND;
|
private BufferedImage scaledBackground = BACKGROUND;
|
||||||
|
@ -40,52 +40,56 @@ class Board extends StonePanel implements IBoard {
|
||||||
|
|
||||||
Board() {
|
Board() {
|
||||||
setBorder(new CustomBorder(Color.DARK_GRAY, 0, 1, 0, 1));
|
setBorder(new CustomBorder(Color.DARK_GRAY, 0, 1, 0, 1));
|
||||||
|
|
||||||
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 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);
|
||||||
|
|
||||||
return scaled;
|
return scaled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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);
|
||||||
|
|
||||||
for (int i = 0; i < BOARD_HEIGHT; ++i) {
|
for (int i = 0; i < BOARD_HEIGHT; ++i) {
|
||||||
for (int xpos = -size * i / 3; xpos < width; xpos += size) {
|
for (int xpos = -size * i / 3; xpos < width; xpos += size) {
|
||||||
g.drawImage(scaledBackground, xpos, size * i, null);
|
g.drawImage(scaledBackground, xpos, size * i, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
for (Map.Entry<Stone, Position> entry : stones.entrySet()) {
|
for (Map.Entry<Stone, Position> entry : stones.entrySet()) {
|
||||||
getStonePainter().paintStone(g, entry.getKey(), entry.getValue(),
|
getStonePainter().paintStone(g, entry.getKey(), entry.getValue(),
|
||||||
selectedStones.contains(entry.getKey()));
|
selectedStones.contains(entry.getKey()));
|
||||||
|
@ -97,7 +101,7 @@ class Board extends StonePanel implements IBoard {
|
||||||
this.stones = stones;
|
this.stones = stones;
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSelectedStones(Collection<Stone> stones) {
|
public void setSelectedStones(Collection<Stone> stones) {
|
||||||
selectedStones = stones;
|
selectedStones = stones;
|
||||||
repaint();
|
repaint();
|
||||||
|
|
|
@ -10,7 +10,7 @@ import javax.swing.border.Border;
|
||||||
class CustomBorder implements Border {
|
class CustomBorder implements Border {
|
||||||
private Color color;
|
private Color color;
|
||||||
private int top, left, bottom, right;
|
private int top, left, bottom, right;
|
||||||
|
|
||||||
public CustomBorder(Color color, int top, int left, int bottom, int right) {
|
public CustomBorder(Color color, int top, int left, int bottom, int right) {
|
||||||
this.color = color;
|
this.color = color;
|
||||||
this.top = top;
|
this.top = top;
|
||||||
|
@ -18,7 +18,7 @@ class CustomBorder implements Border {
|
||||||
this.bottom = bottom;
|
this.bottom = bottom;
|
||||||
this.right = right;
|
this.right = right;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Insets getBorderInsets(Component c) {
|
public Insets getBorderInsets(Component c) {
|
||||||
return new Insets(top, left, bottom, right);
|
return new Insets(top, left, bottom, right);
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,24 +25,23 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
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 DecimalFormat secondFormat = new DecimalFormat("00");
|
private final static DecimalFormat secondFormat = new DecimalFormat("00");
|
||||||
|
|
||||||
private Board board;
|
private Board board;
|
||||||
|
|
||||||
JPanel leftPanel, rightPanel;
|
JPanel leftPanel, rightPanel;
|
||||||
|
|
||||||
private JLabel currentPlayerNameLabel;
|
private JLabel currentPlayerNameLabel;
|
||||||
private JButton sortByNumberButton;
|
private JButton sortByNumberButton;
|
||||||
private JButton sortByColorButton;
|
private JButton sortByColorButton;
|
||||||
private JProgressBar timeBar;
|
private JProgressBar timeBar;
|
||||||
private JButton endTurnButton;
|
private JButton endTurnButton;
|
||||||
|
|
||||||
private Event sortByNumberEvent = new Event();
|
private Event sortByNumberEvent = new Event();
|
||||||
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;
|
||||||
|
@ -52,154 +51,167 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
public void setCurrentPlayerName(String playerName) {
|
public void setCurrentPlayerName(String playerName) {
|
||||||
currentPlayerNameLabel.setText(playerName);
|
currentPlayerNameLabel.setText(playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@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
|
||||||
public IEvent getSortByNumberEvent() {
|
public IEvent getSortByNumberEvent() {
|
||||||
return sortByNumberEvent;
|
return sortByNumberEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEvent getSortByColorEvent() {
|
public IEvent getSortByColorEvent() {
|
||||||
return sortByColorEvent;
|
return sortByColorEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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.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);
|
||||||
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);
|
||||||
|
|
||||||
sortByNumberButton = new JButton("<html><center>Sort by<br>number");
|
sortByNumberButton = new JButton("<html><center>Sort by<br>number");
|
||||||
sortByNumberButton.addActionListener(new ActionListener() {
|
sortByNumberButton.addActionListener(new ActionListener() {
|
||||||
@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");
|
||||||
sortByColorButton.addActionListener(new ActionListener() {
|
sortByColorButton.addActionListener(new ActionListener() {
|
||||||
@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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createRightPanel() {
|
private void createRightPanel() {
|
||||||
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);
|
||||||
rightPanel.add(timeBar);
|
rightPanel.add(timeBar);
|
||||||
|
|
||||||
endTurnButton = new JButton("End turn");
|
endTurnButton = new JButton("End turn");
|
||||||
endTurnButton.addActionListener(new ActionListener() {
|
endTurnButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
endTurnEvent.fire();
|
endTurnEvent.fire();
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
rightPanel.add(endTurnButton);
|
rightPanel.add(endTurnButton);
|
||||||
|
|
||||||
rightPanel.addComponentListener(new ComponentAdapter() {
|
rightPanel.addComponentListener(new 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()-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);
|
||||||
|
|
||||||
setBackground(Color.LIGHT_GRAY);
|
setBackground(Color.LIGHT_GRAY);
|
||||||
|
|
||||||
createLeftPanel();
|
createLeftPanel();
|
||||||
add(leftPanel);
|
add(leftPanel);
|
||||||
|
|
||||||
board = new Board();
|
board = new Board();
|
||||||
add(board);
|
add(board);
|
||||||
|
|
||||||
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);
|
||||||
board.addComponentListener(rescaleListener);
|
board.addComponentListener(rescaleListener);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,29 +23,27 @@ class StonePainter {
|
||||||
|
|
||||||
private static final Color BACKGROUND_COLOR = new Color(0.9f, 0.9f, 0.6f);
|
private static final Color BACKGROUND_COLOR = new Color(0.9f, 0.9f, 0.6f);
|
||||||
private static final Color SELECTED_COLOR = BACKGROUND_COLOR.darker();
|
private static final Color SELECTED_COLOR = BACKGROUND_COLOR.darker();
|
||||||
|
|
||||||
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) {
|
||||||
int r = (int) (color.getRed() * BRIGHTER_SCALE);
|
int r = (int) (color.getRed() * BRIGHTER_SCALE);
|
||||||
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:
|
||||||
|
@ -55,10 +53,10 @@ class StonePainter {
|
||||||
case RED:
|
case RED:
|
||||||
return new Color(0.9f, 0.0f, 0.25f);
|
return new Color(0.9f, 0.0f, 0.25f);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setScale(float scale) {
|
public void setScale(float scale) {
|
||||||
this.scale = scale;
|
this.scale = scale;
|
||||||
}
|
}
|
||||||
|
@ -66,164 +64,171 @@ class StonePainter {
|
||||||
public float getScale() {
|
public float getScale() {
|
||||||
return scale;
|
return scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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);
|
||||||
|
|
||||||
// Paint bevel border
|
// Paint bevel border
|
||||||
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) {
|
||||||
Stroke oldStroke = g.getStroke();
|
Stroke oldStroke = g.getStroke();
|
||||||
|
|
||||||
g.setStroke(new BasicStroke(2));
|
g.setStroke(new BasicStroke(2));
|
||||||
g.drawOval(x, y, width, height);
|
g.drawOval(x, y, width, height);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
g.setStroke(oldStroke);
|
g.setStroke(oldStroke);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
Color background = selected ? SELECTED_COLOR : BACKGROUND_COLOR;
|
Color background = selected ? SELECTED_COLOR : BACKGROUND_COLOR;
|
||||||
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);
|
||||||
|
|
||||||
Color color = getColor(stone.getColor());
|
Color color = getColor(stone.getColor());
|
||||||
if (selected)
|
if (selected)
|
||||||
color = color.darker();
|
color = color.darker();
|
||||||
|
|
||||||
if (stone.isJoker()) {
|
if (stone.isJoker()) {
|
||||||
paintJoker(g, x, y, width, height, color);
|
paintJoker(g, x, y, width, height, color);
|
||||||
} else {
|
} else {
|
||||||
paintStoneNumber(g, x, y, width, height, color, stone.getValue());
|
paintStoneNumber(g, x, y, width, height, color, stone.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
paintCircle(g, x, y, width, height, background);
|
paintCircle(g, x, y, width, height, background);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,37 +13,38 @@ import jrummikub.view.IClickable;
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
abstract class StonePanel extends JPanel implements IClickable {
|
abstract class StonePanel extends JPanel implements IClickable {
|
||||||
private StonePainter stonePainter;
|
private StonePainter stonePainter;
|
||||||
|
|
||||||
private Event2<Position, Boolean> clickEvent = new Event2<Position, Boolean>();
|
private Event2<Position, Boolean> clickEvent = new Event2<Position, Boolean>();
|
||||||
private Event2<Position, Boolean> rangeClickEvent = new Event2<Position, Boolean>();
|
private Event2<Position, Boolean> rangeClickEvent = new Event2<Position, Boolean>();
|
||||||
private Event2<Position, Boolean> setClickEvent = new Event2<Position, Boolean>();
|
private Event2<Position, Boolean> setClickEvent = new Event2<Position, Boolean>();
|
||||||
|
|
||||||
protected StonePainter getStonePainter() {
|
protected StonePainter getStonePainter() {
|
||||||
return stonePainter;
|
return stonePainter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StonePanel() {
|
public StonePanel() {
|
||||||
this(1);
|
this(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public StonePanel(float scale) {
|
public StonePanel(float scale) {
|
||||||
super(true); // Set double buffered
|
super(true); // Set double buffered
|
||||||
|
|
||||||
stonePainter = new StonePainter(scale);
|
stonePainter = new StonePainter(scale);
|
||||||
|
|
||||||
addMouseListener(new MouseAdapter() {
|
addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
Insets insets = getInsets();
|
Insets insets = getInsets();
|
||||||
Event2<Position, Boolean> event = clickEvent;
|
Event2<Position, Boolean> event = clickEvent;
|
||||||
|
|
||||||
if (e.isShiftDown())
|
if (e.isShiftDown())
|
||||||
event = rangeClickEvent;
|
event = rangeClickEvent;
|
||||||
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,20 +19,19 @@ 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;
|
||||||
|
|
||||||
private JLabel leftPlayerLabel, topPlayerLabel, rightPlayerLabel;
|
private JLabel leftPlayerLabel, topPlayerLabel, rightPlayerLabel;
|
||||||
private JPanel innerPanel;
|
private JPanel innerPanel;
|
||||||
|
|
||||||
private StonePainter selectedStonePainter = new StonePainter(1.2f);
|
private StonePainter selectedStonePainter = new StonePainter(1.2f);
|
||||||
|
|
||||||
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);
|
||||||
|
@ -53,7 +52,7 @@ public class Table extends StonePanel implements ITable {
|
||||||
this.stoneSets = stoneSets;
|
this.stoneSets = stoneSets;
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSelectedStones(Collection<Stone> stones) {
|
public void setSelectedStones(Collection<Stone> stones) {
|
||||||
selectedStones = stones;
|
selectedStones = stones;
|
||||||
repaint();
|
repaint();
|
||||||
|
@ -61,7 +60,7 @@ public class Table extends StonePanel implements ITable {
|
||||||
|
|
||||||
Table() {
|
Table() {
|
||||||
super(DEFAULT_SCALE);
|
super(DEFAULT_SCALE);
|
||||||
|
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
|
|
||||||
leftPlayerLabel = new JLabel();
|
leftPlayerLabel = new JLabel();
|
||||||
|
@ -92,7 +91,7 @@ public class Table extends StonePanel implements ITable {
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintComponent(Graphics g1) {
|
protected void paintComponent(Graphics g1) {
|
||||||
Graphics2D g = (Graphics2D) g1;
|
Graphics2D g = (Graphics2D) g1;
|
||||||
|
@ -109,24 +108,25 @@ public class Table extends StonePanel implements ITable {
|
||||||
for (Map.Entry<StoneSet, Position> stoneSet : stoneSets.entrySet()) {
|
for (Map.Entry<StoneSet, Position> stoneSet : stoneSets.entrySet()) {
|
||||||
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);
|
||||||
|
|
||||||
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;
|
||||||
|
@ -18,16 +17,15 @@ import jrummikub.view.IView;
|
||||||
public class View extends JFrame implements IView {
|
public class View extends JFrame implements IView {
|
||||||
private Table table;
|
private Table table;
|
||||||
private PlayerPanel playerPanel;
|
private PlayerPanel playerPanel;
|
||||||
|
|
||||||
private final static float PLAYER_PANEL_RATIO = 0.125f;
|
private final static float PLAYER_PANEL_RATIO = 0.125f;
|
||||||
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() {
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
@ -36,39 +34,42 @@ public class View extends JFrame implements IView {
|
||||||
return playerPanel;
|
return playerPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public View() {
|
public View() {
|
||||||
super("JRummikub");
|
super("JRummikub");
|
||||||
setLayout(null);
|
setLayout(null);
|
||||||
|
|
||||||
setSize(1000, 700);
|
setSize(1000, 700);
|
||||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
|
|
||||||
table = new Table();
|
table = new Table();
|
||||||
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;
|
||||||
|
|
||||||
int tableHeight = height - playerPanelHeight;
|
int tableHeight = height - playerPanelHeight;
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,77 +6,78 @@ import org.junit.Test;
|
||||||
|
|
||||||
public class Event1Test {
|
public class Event1Test {
|
||||||
|
|
||||||
int fired, fired2;
|
int fired, fired2;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void singleListener() {
|
public void singleListener() {
|
||||||
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>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fire(Integer n) {
|
public void fire(Integer n) {
|
||||||
fired += n;
|
fired += n;
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertEquals(fired, 0);
|
assertEquals(fired, 0);
|
||||||
testEvent.fire(10);
|
testEvent.fire(10);
|
||||||
assertEquals(fired, 10);
|
assertEquals(fired, 10);
|
||||||
testEvent.fire(20);
|
testEvent.fire(20);
|
||||||
assertEquals(fired, 30);
|
assertEquals(fired, 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void twoListeners() {
|
public void twoListeners() {
|
||||||
fired = 0;
|
fired = 0;
|
||||||
fired2 = 0;
|
fired2 = 0;
|
||||||
Event1<Integer> testEvent = new Event1<Integer>();
|
Event1<Integer> testEvent = new Event1<Integer>();
|
||||||
testEvent.add(new IListener1<Integer>() {
|
testEvent.add(new IListener1<Integer>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fire(Integer n) {
|
public void fire(Integer n) {
|
||||||
fired += n;
|
fired += n;
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
testEvent.add(new IListener1<Integer>() {
|
testEvent.add(new IListener1<Integer>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fire(Integer n) {
|
public void fire(Integer n) {
|
||||||
fired2 -= n;
|
fired2 -= n;
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertEquals(fired, 0);
|
assertEquals(fired, 0);
|
||||||
assertEquals(fired2, 0);
|
assertEquals(fired2, 0);
|
||||||
testEvent.fire(5);
|
testEvent.fire(5);
|
||||||
assertEquals(fired, 5);
|
assertEquals(fired, 5);
|
||||||
assertEquals(fired2, -5);
|
assertEquals(fired2, -5);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void removeListener() {
|
|
||||||
fired = 0;
|
|
||||||
Event1<Integer> testEvent = new Event1<Integer>();
|
|
||||||
testEvent.add(new IListener1<Integer>() {
|
|
||||||
|
|
||||||
@Override
|
@Test
|
||||||
public void fire(Integer n) {
|
public void removeListener() {
|
||||||
fired += n;
|
fired = 0;
|
||||||
|
Event1<Integer> testEvent = new Event1<Integer>();
|
||||||
|
testEvent.add(new IListener1<Integer>() {
|
||||||
|
|
||||||
}
|
@Override
|
||||||
});
|
public void fire(Integer n) {
|
||||||
IListener1<Integer> rem = new IListener1<Integer>() {
|
fired += n;
|
||||||
|
|
||||||
@Override
|
}
|
||||||
public void fire(Integer n) {
|
});
|
||||||
fail();
|
IListener1<Integer> rem = new IListener1<Integer>() {
|
||||||
}
|
|
||||||
};
|
@Override
|
||||||
testEvent.add(rem);
|
public void fire(Integer n) {
|
||||||
testEvent.remove(rem);
|
fail();
|
||||||
testEvent.fire(10);
|
}
|
||||||
assertEquals(fired, 10);
|
};
|
||||||
}
|
testEvent.add(rem);
|
||||||
|
testEvent.remove(rem);
|
||||||
|
testEvent.fire(10);
|
||||||
|
assertEquals(fired, 10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,8 +64,9 @@ public class Event2Test {
|
||||||
assertEquals(fired3, -5);
|
assertEquals(fired3, -5);
|
||||||
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>();
|
||||||
|
@ -78,7 +79,7 @@ public class Event2Test {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
IListener2<Integer, Integer> rem = new IListener2<Integer, Integer>() {
|
IListener2<Integer, Integer> rem = new IListener2<Integer, Integer>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fire(Integer n, Integer m) {
|
public void fire(Integer n, Integer m) {
|
||||||
fail();
|
fail();
|
||||||
|
|
|
@ -4,79 +4,80 @@ import org.junit.Test;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class EventTest {
|
public class EventTest {
|
||||||
boolean fired, fired2;
|
boolean fired, fired2;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void singleListener() {
|
public void singleListener() {
|
||||||
fired = false;
|
fired = false;
|
||||||
Event testEvent = new Event();
|
Event testEvent = new Event();
|
||||||
testEvent.add(new IListener() {
|
testEvent.add(new IListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fire() {
|
public void fire() {
|
||||||
fired = true;
|
fired = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertFalse(fired);
|
assertFalse(fired);
|
||||||
testEvent.fire();
|
testEvent.fire();
|
||||||
assertTrue(fired);
|
assertTrue(fired);
|
||||||
fired = false;
|
fired = false;
|
||||||
testEvent.fire();
|
testEvent.fire();
|
||||||
assertTrue(fired);
|
assertTrue(fired);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void twoListeners() {
|
public void twoListeners() {
|
||||||
fired = false;
|
fired = false;
|
||||||
fired2 = false;
|
fired2 = false;
|
||||||
Event testEvent = new Event();
|
Event testEvent = new Event();
|
||||||
testEvent.add(new IListener() {
|
testEvent.add(new IListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fire() {
|
public void fire() {
|
||||||
fired = true;
|
fired = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
testEvent.add(new IListener() {
|
testEvent.add(new IListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fire() {
|
public void fire() {
|
||||||
fired2 = true;
|
fired2 = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertFalse(fired);
|
assertFalse(fired);
|
||||||
assertFalse(fired2);
|
assertFalse(fired2);
|
||||||
testEvent.fire();
|
testEvent.fire();
|
||||||
assertTrue(fired);
|
assertTrue(fired);
|
||||||
assertTrue(fired2);
|
assertTrue(fired2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void removeListener() {
|
|
||||||
fired = false;
|
|
||||||
Event testEvent = new Event();
|
|
||||||
testEvent.add(new IListener() {
|
|
||||||
|
|
||||||
@Override
|
@Test
|
||||||
public void fire() {
|
public void removeListener() {
|
||||||
fired = true;
|
fired = false;
|
||||||
|
Event testEvent = new Event();
|
||||||
|
testEvent.add(new IListener() {
|
||||||
|
|
||||||
}
|
@Override
|
||||||
});
|
public void fire() {
|
||||||
IListener rem = new IListener() {
|
fired = true;
|
||||||
|
|
||||||
@Override
|
}
|
||||||
public void fire() {
|
});
|
||||||
fail();
|
IListener rem = new IListener() {
|
||||||
}
|
|
||||||
};
|
@Override
|
||||||
testEvent.add(rem);
|
public void fire() {
|
||||||
testEvent.remove(rem);
|
fail();
|
||||||
testEvent.fire();
|
}
|
||||||
assertTrue(fired);
|
};
|
||||||
}
|
testEvent.add(rem);
|
||||||
|
testEvent.remove(rem);
|
||||||
|
testEvent.fire();
|
||||||
|
assertTrue(fired);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue