Fix formatting

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@52 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-05-01 19:14:55 +02:00
parent 5436407515
commit b2dbfcc317
22 changed files with 483 additions and 427 deletions

View file

@ -41,17 +41,20 @@ public class JRummikub {
@Override
public void fire() {
System.out.println("'Sort by number' fired");
}});
}
});
view.getPlayerPanel().getSortByColorEvent().add(new IListener() {
@Override
public void fire() {
System.out.println("'Sort by color' fired");
}});
}
});
view.getPlayerPanel().getEndTurnEvent().add(new IListener() {
@Override
public void fire() {
System.out.println("'End turn' fired");
}});
}
});
// stones on the board
Map<Stone, Position> stones = new HashMap<Stone, Position>();
@ -66,48 +69,65 @@ public class JRummikub {
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":""));
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
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
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>() {
@Override
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
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>() {
@Override
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
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>();

View file

@ -2,5 +2,6 @@ package jrummikub.util;
public interface IEvent {
public void add(IListener listener);
public void remove(IListener listener);
}

View file

@ -2,5 +2,6 @@ package jrummikub.util;
public interface IEvent1<T> {
public void add(IListener1<T> listener);
public void remove(IListener1<T> listener);
}

View file

@ -2,5 +2,6 @@ package jrummikub.util;
public interface IEvent2<T1, T2> {
public void add(IListener2<T1, T2> listener);
public void remove(IListener2<T1, T2> listener);
}

View file

@ -20,5 +20,4 @@ public class Pair<T1, T2> {
return second;
}
}

View file

@ -5,6 +5,8 @@ import jrummikub.util.IEvent2;
public interface IClickable {
public IEvent2<Position, Boolean> getClickEvent();
public IEvent2<Position, Boolean> getRangeClickEvent();
public IEvent2<Position, Boolean> getSetClickEvent();
}

View file

@ -6,9 +6,12 @@ public interface IPlayerPanel {
public IBoard getBoard();
public void setCurrentPlayerName(String playerName);
public void setTimeLeft(int time);
public IEvent getSortByNumberEvent();
public IEvent getSortByColorEvent();
public IEvent getEndTurnEvent();
}

View file

@ -7,7 +7,9 @@ import jrummikub.model.StoneSet;
public interface ITable extends IClickable {
public void setLeftPlayerName(String playerName);
public void setTopPlayerName(String playerName);
public void setRightPlayerName(String playerName);
public void setStoneSets(Map<StoneSet, Position> stoneSets);

View file

@ -50,15 +50,18 @@ class Board extends StonePanel implements IBoard {
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) {
BufferedImage scaled = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB);
BufferedImage scaled = new BufferedImage(size, size,
BufferedImage.TYPE_INT_RGB);
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);
@ -68,7 +71,8 @@ class Board extends StonePanel implements IBoard {
@Override
protected void paintComponent(Graphics g1) {
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;
Graphics2D g = (Graphics2D) g1.create(x, y, width, height);
int size = height / BOARD_HEIGHT;

View file

@ -30,7 +30,8 @@ class CustomBorder implements Border {
}
@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.fillRect(x, y, width, top);

View file

@ -42,7 +42,6 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
private Event sortByColorEvent = new Event();
private Event endTurnEvent = new Event();
@Override
public Board getBoard() {
return board;
@ -54,10 +53,10 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
}
@Override
public
void setTimeLeft(int time) {
public void setTimeLeft(int time) {
timeBar.setValue(time);
timeBar.setString(Integer.toString(time/60) + ":" + secondFormat.format(time%60));
timeBar.setString(Integer.toString(time / 60) + ":"
+ secondFormat.format(time % 60));
}
@Override
@ -75,12 +74,12 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
return endTurnEvent;
}
private void createLeftPanel() {
leftPanel = new JPanel();
leftPanel.setLayout(null);
leftPanel.setOpaque(false);
leftPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET, SIDE_PANEL_INSET, SIDE_PANEL_INSET));
leftPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET,
SIDE_PANEL_INSET, SIDE_PANEL_INSET));
currentPlayerNameLabel = new JLabel();
currentPlayerNameLabel.setHorizontalAlignment(JLabel.CENTER);
@ -94,7 +93,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
@Override
public void actionPerformed(ActionEvent arg0) {
sortByNumberEvent.fire();
}});
}
});
leftPanel.add(sortByNumberButton);
sortByColorButton = new JButton("<html><center>Sort by<br>color");
@ -102,14 +102,17 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
@Override
public void actionPerformed(ActionEvent arg0) {
sortByColorEvent.fire();
}});
}
});
leftPanel.add(sortByColorButton);
leftPanel.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
Insets insets = leftPanel.getInsets();
int x = insets.left, y = insets.top, width = leftPanel.getWidth()-insets.left-insets.right, height = leftPanel.getHeight()-insets.top-insets.bottom;
int x = insets.left, y = insets.top, width = leftPanel.getWidth()
- insets.left - insets.right, height = leftPanel.getHeight()
- insets.top - insets.bottom;
if (width > SIDE_PANEL_MAX_WIDTH) {
x += (width - SIDE_PANEL_MAX_WIDTH) / 4;
@ -120,8 +123,12 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
int buttonWidth = (width - SIDE_PANEL_SEPARATOR) / 2;
currentPlayerNameLabel.setBounds(x, y, width, firstLineHeight);
sortByNumberButton.setBounds(x, y+firstLineHeight+SIDE_PANEL_SEPARATOR, buttonWidth, height-SIDE_PANEL_SEPARATOR-firstLineHeight);
sortByColorButton.setBounds(x+buttonWidth+SIDE_PANEL_SEPARATOR, y+firstLineHeight+SIDE_PANEL_SEPARATOR, buttonWidth, height-SIDE_PANEL_SEPARATOR-firstLineHeight);
sortByNumberButton.setBounds(x, y + firstLineHeight
+ SIDE_PANEL_SEPARATOR, buttonWidth, height - SIDE_PANEL_SEPARATOR
- firstLineHeight);
sortByColorButton.setBounds(x + buttonWidth + SIDE_PANEL_SEPARATOR, y
+ firstLineHeight + SIDE_PANEL_SEPARATOR, buttonWidth, height
- SIDE_PANEL_SEPARATOR - firstLineHeight);
}
});
}
@ -130,7 +137,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
rightPanel = new JPanel();
rightPanel.setLayout(null);
rightPanel.setOpaque(false);
rightPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET, SIDE_PANEL_INSET, SIDE_PANEL_INSET));
rightPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET,
SIDE_PANEL_INSET, SIDE_PANEL_INSET));
timeBar = new JProgressBar(0, 60);
timeBar.setStringPainted(true);
@ -141,7 +149,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
@Override
public void actionPerformed(ActionEvent arg0) {
endTurnEvent.fire();
}});
}
});
rightPanel.add(endTurnButton);
@ -149,7 +158,9 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
@Override
public void componentResized(ComponentEvent e) {
Insets insets = rightPanel.getInsets();
int x = insets.left, y = insets.top, width = rightPanel.getWidth()-insets.left-insets.right, height = rightPanel.getHeight()-insets.top-insets.bottom;
int x = insets.left, y = insets.top, width = rightPanel.getWidth()
- insets.left - insets.right, height = rightPanel.getHeight()
- insets.top - insets.bottom;
if (width > SIDE_PANEL_MAX_WIDTH) {
x += (width - SIDE_PANEL_MAX_WIDTH) / 4;
@ -159,14 +170,16 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
int firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT);
timeBar.setBounds(x, y, width, firstLineHeight);
endTurnButton.setBounds(x, y+firstLineHeight+SIDE_PANEL_SEPARATOR, width, height-SIDE_PANEL_SEPARATOR-firstLineHeight);
endTurnButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR,
width, height - SIDE_PANEL_SEPARATOR - firstLineHeight);
}
});
}
private void rescale() {
Insets insets = getInsets();
int x = insets.left, y = insets.top, width = getWidth()-insets.left-insets.right, height = getHeight()-insets.top-insets.bottom;
int x = insets.left, y = insets.top, width = getWidth() - insets.left
- insets.right, height = getHeight() - insets.top - insets.bottom;
int boardWidth = board.getWidth();
int panelWidth = (width - boardWidth) / 2;
@ -178,7 +191,6 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
rightPanel.validate();
}
PlayerPanel() {
setLayout(null);

View file

@ -28,10 +28,8 @@ class StonePainter {
public static final float HEIGHT_SCALE = ASPECT_RATIO / DEFAULT_WIDTH;
private float scale;
private static int even(float f) {
return 2 * (int) (f / 2);
}
@ -68,8 +66,10 @@ class StonePainter {
}
/**
* @param x x position in screen coordinates
* @param y y position in screen coordinates
* @param x
* x position in screen coordinates
* @param y
* y position in screen coordinates
* @return position in grid coordinates
*/
public Position calculatePosition(int x, int y) {
@ -91,8 +91,8 @@ class StonePainter {
this.scale = scale;
}
private void paintStoneBackground(Graphics2D g, int x, int y,
int width, int height, Color background) {
private void paintStoneBackground(Graphics2D g, int x, int y, int width,
int height, Color background) {
// Paint background
g.setColor(background);
g.fillRect(x, y, width, height);
@ -174,7 +174,8 @@ class StonePainter {
int pos = y + (int) (TEXT_POS * height);
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,
@ -187,12 +188,15 @@ class StonePainter {
Rectangle2D stringRect = fm.getStringBounds(value, g);
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.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,
Color background) {
int size = even(width * CIRCLE_WIDTH);
int pos = y + (int) (CIRCLE_POS * height);
@ -201,7 +205,8 @@ class StonePainter {
g.drawArc(x + width / 2 - size / 2, pos - size / 2, size, size, 50, 170);
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) {

View file

@ -42,8 +42,9 @@ abstract class StonePanel extends JPanel implements IClickable {
else if (e.getClickCount() >= 2)
event = setClickEvent;
event.fire(stonePainter.calculatePosition(e.getX() - insets.left,
e.getY() - insets.top), e.isControlDown());
event.fire(
stonePainter.calculatePosition(e.getX() - insets.left, e.getY()
- insets.top), e.isControlDown());
}
});
}

View file

@ -19,7 +19,7 @@ import jrummikub.model.StoneSet;
import jrummikub.view.ITable;
@SuppressWarnings("serial")
public class Table extends StonePanel implements ITable {
class Table extends StonePanel implements ITable {
private final static ImageIcon background = new ImageIcon(
Board.class.getResource("/jrummikub/resource/felt.png"));
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 Collection<Stone> selectedStones = Collections.emptyList();
@Override
public void setLeftPlayerName(String playerName) {
leftPlayerLabel.setText(playerName);
@ -117,8 +116,8 @@ public class Table extends StonePanel implements ITable {
if (!selectedStones.isEmpty()) {
g.setColor(new Color(0, 0, 0, 0.3f));
g.fillRect(selectedStonesX-7, selectedStonesY-7, selectedStonesWidth + 14,
selectedStonesHeight + 14);
g.fillRect(selectedStonesX - 7, selectedStonesY - 7,
selectedStonesWidth + 14, selectedStonesHeight + 14);
Graphics2D translatedG = (Graphics2D) g.create(selectedStonesX,
selectedStonesY, selectedStonesWidth, selectedStonesHeight);
@ -126,7 +125,8 @@ public class Table extends StonePanel implements ITable {
float x = 0;
for (Stone stone : selectedStones) {
selectedStonePainter.paintStone(translatedG, stone, new Position(x, 0), false);
selectedStonePainter.paintStone(translatedG, stone, new Position(x, 0),
false);
x++;
}
}

View file

@ -1,7 +1,6 @@
package jrummikub.view.impl;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
@ -23,7 +22,6 @@ public class View extends JFrame implements IView {
private final static int PLAYER_PANEL_BORDER_WIDTH = 1;
private final static int PLAYER_PANEL_MAX_HEIGHT = 180 + PLAYER_PANEL_BORDER_WIDTH;
private static int even(double d) {
return 2 * (int) (d / 2);
}
@ -36,7 +34,6 @@ public class View extends JFrame implements IView {
return playerPanel;
}
public View() {
super("JRummikub");
setLayout(null);
@ -48,16 +45,20 @@ public class View extends JFrame implements IView {
add(table);
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);
addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
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)
playerPanelHeight = PLAYER_PANEL_MAX_HEIGHT;

View file

@ -56,7 +56,8 @@ public class Event1Test {
}
@Test public void removeListener() {
@Test
public void removeListener() {
fired = 0;
Event1<Integer> testEvent = new Event1<Integer>();
testEvent.add(new IListener1<Integer>() {

View file

@ -65,7 +65,8 @@ public class Event2Test {
assertEquals(fired4, -10);
}
@Test public void removeListener() {
@Test
public void removeListener() {
fired = 0;
fired2 = 0;
Event2<Integer, Integer> testEvent = new Event2<Integer, Integer>();

View file

@ -55,7 +55,8 @@ public class EventTest {
}
@Test public void removeListener() {
@Test
public void removeListener() {
fired = false;
Event testEvent = new Event();
testEvent.add(new IListener() {