Noch mehr Kommentare, z.B. alle Methoden im Model und in der IView
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@547 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
e4e66240bf
commit
7899a38fe6
8 changed files with 159 additions and 36 deletions
|
@ -18,6 +18,12 @@ public class DedicatedServer {
|
||||||
String serverPassword;
|
String serverPassword;
|
||||||
String hostName;
|
String hostName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new dedicated server with the specified password
|
||||||
|
*
|
||||||
|
* @param serverPassword
|
||||||
|
* the password
|
||||||
|
*/
|
||||||
public DedicatedServer(String serverPassword) {
|
public DedicatedServer(String serverPassword) {
|
||||||
this.serverPassword = serverPassword;
|
this.serverPassword = serverPassword;
|
||||||
try {
|
try {
|
||||||
|
@ -29,6 +35,11 @@ public class DedicatedServer {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for host name
|
||||||
|
*
|
||||||
|
* @return host name
|
||||||
|
*/
|
||||||
public String getHostName() {
|
public String getHostName() {
|
||||||
return hostName;
|
return hostName;
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,7 +231,8 @@ public interface ISettingsPanel {
|
||||||
public void setPlayerNamesEditable(List<Boolean> editable);
|
public void setPlayerNamesEditable(List<Boolean> editable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emitted when a new game is started and looking for players
|
* The offer new game event is emitted when a new game is started and
|
||||||
|
* looking for players
|
||||||
*
|
*
|
||||||
* @return the event
|
* @return the event
|
||||||
*/
|
*/
|
||||||
|
@ -245,6 +246,12 @@ public interface ISettingsPanel {
|
||||||
*/
|
*/
|
||||||
public void setPlayerColors(Set<Color> colors);
|
public void setPlayerColors(Set<Color> colors);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The change see hand size event is emitted when the player chooses to see
|
||||||
|
* the other players hand sizes
|
||||||
|
*
|
||||||
|
* @return the event
|
||||||
|
*/
|
||||||
public IEvent1<Boolean> getChangeSeeHandSizeEvent();
|
public IEvent1<Boolean> getChangeSeeHandSizeEvent();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,14 +5,42 @@ import java.util.List;
|
||||||
import jrummikub.model.GameSettings;
|
import jrummikub.model.GameSettings;
|
||||||
import jrummikub.model.IPlayer;
|
import jrummikub.model.IPlayer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Side panel to show all players and relevant player information in round
|
||||||
|
* order, game settings and stone heap size
|
||||||
|
*/
|
||||||
public interface ISidePanel {
|
public interface ISidePanel {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the game settings to top of side panel
|
||||||
|
*
|
||||||
|
* @param settings
|
||||||
|
* current game settings
|
||||||
|
*/
|
||||||
public void setGameSettings(GameSettings settings);
|
public void setGameSettings(GameSettings settings);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the total heap size for progress bar
|
||||||
|
*
|
||||||
|
* @param capacity
|
||||||
|
* total heap size
|
||||||
|
*/
|
||||||
void setHeapCapacity(int capacity);
|
void setHeapCapacity(int capacity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the current heap size
|
||||||
|
*
|
||||||
|
* @param size
|
||||||
|
* number of stones in current heap
|
||||||
|
*/
|
||||||
void setHeapSize(int size);
|
void setHeapSize(int size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the player information in order of turns
|
||||||
|
*
|
||||||
|
* @param players
|
||||||
|
* players in current game
|
||||||
|
*/
|
||||||
void setPlayers(List<IPlayer> players);
|
void setPlayers(List<IPlayer> players);
|
||||||
|
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ public interface IStoneCollectionPanel extends IStonePanel {
|
||||||
* Hide stone collection
|
* Hide stone collection
|
||||||
*
|
*
|
||||||
* @param enable
|
* @param enable
|
||||||
|
* see stone collection
|
||||||
*/
|
*/
|
||||||
void setHidden(boolean enable);
|
void setHidden(boolean enable);
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,8 +124,8 @@ public interface IView {
|
||||||
public void setCurrentPlayerColor(Color color);
|
public void setCurrentPlayerColor(Color color);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is used for the PlayerPanel to display if a player has laid out along with
|
* Is used for the PlayerPanel to display if a player has laid out along
|
||||||
* the name
|
* with the name
|
||||||
*
|
*
|
||||||
* @param hasLaidOut
|
* @param hasLaidOut
|
||||||
* specifies if the current player has laid out or not
|
* specifies if the current player has laid out or not
|
||||||
|
@ -148,8 +148,8 @@ public interface IView {
|
||||||
public void setBottomPanel(BottomPanelType type);
|
public void setBottomPanel(BottomPanelType type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The menu new game event is emitted when the user selects the new game menu
|
* The menu new game event is emitted when the user selects the new game
|
||||||
* entry
|
* menu entry
|
||||||
*
|
*
|
||||||
* @return the event
|
* @return the event
|
||||||
*/
|
*/
|
||||||
|
@ -337,6 +337,13 @@ public interface IView {
|
||||||
*/
|
*/
|
||||||
public IConnectPanel getConnectPanel();
|
public IConnectPanel getConnectPanel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the pause button if pausing should be possible in the current
|
||||||
|
* situation
|
||||||
|
*
|
||||||
|
* @param mayPause
|
||||||
|
* pausing possible
|
||||||
|
*/
|
||||||
public void setMayPause(boolean mayPause);
|
public void setMayPause(boolean mayPause);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -77,8 +77,9 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel,
|
||||||
public void mouseMoved(MouseEvent e) {
|
public void mouseMoved(MouseEvent e) {
|
||||||
Insets insets = getInsets();
|
Insets insets = getInsets();
|
||||||
Pair<Integer, Integer> trans = getTranslation();
|
Pair<Integer, Integer> trans = getTranslation();
|
||||||
Position pos = stonePainter.calculatePosition(e.getX() - insets.left
|
Position pos = stonePainter.calculatePosition(e.getX()
|
||||||
- trans.getFirst(), e.getY() - insets.top - trans.getSecond());
|
- insets.left - trans.getFirst(), e.getY() - insets.top
|
||||||
|
- trans.getSecond());
|
||||||
|
|
||||||
setHoveredStone(getStoneAt(pos));
|
setHoveredStone(getStoneAt(pos));
|
||||||
|
|
||||||
|
@ -132,6 +133,12 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel,
|
||||||
event.emit(stone, control);
|
event.emit(stone, control);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the stone over which the cursor hovers
|
||||||
|
*
|
||||||
|
* @param stone
|
||||||
|
* stone under cursor
|
||||||
|
*/
|
||||||
private void setHoveredStone(Stone stone) {
|
private void setHoveredStone(Stone stone) {
|
||||||
Stone oldStone = hoveredStone;
|
Stone oldStone = hoveredStone;
|
||||||
hoveredStone = stone;
|
hoveredStone = stone;
|
||||||
|
@ -170,6 +177,13 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel,
|
||||||
protected void handleOtherMoveEvent(Position pos) {
|
protected void handleOtherMoveEvent(Position pos) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the stone at the specified position
|
||||||
|
*
|
||||||
|
* @param pos
|
||||||
|
* position
|
||||||
|
* @return the stone
|
||||||
|
*/
|
||||||
private Stone getStoneAt(Position pos) {
|
private Stone getStoneAt(Position pos) {
|
||||||
for (Pair<Stone, Position> entry : stones) {
|
for (Pair<Stone, Position> entry : stones) {
|
||||||
Stone stone = entry.getFirst();
|
Stone stone = entry.getFirst();
|
||||||
|
@ -194,7 +208,8 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the translation in pixels the stones in this panel are painted with
|
* Returns the translation in pixels the stones in this panel are painted
|
||||||
|
* with
|
||||||
*
|
*
|
||||||
* @return the translation
|
* @return the translation
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -49,6 +49,9 @@ class GameListPanel extends JPanel implements IGameListPanel {
|
||||||
|
|
||||||
private List<GameData> games = Collections.emptyList();
|
private List<GameData> games = Collections.emptyList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates new game list panel
|
||||||
|
*/
|
||||||
GameListPanel() {
|
GameListPanel() {
|
||||||
setLayout(new GridBagLayout());
|
setLayout(new GridBagLayout());
|
||||||
GridBagConstraints c = new GridBagConstraints();
|
GridBagConstraints c = new GridBagConstraints();
|
||||||
|
@ -70,10 +73,13 @@ class GameListPanel extends JPanel implements IGameListPanel {
|
||||||
|
|
||||||
addButtons(c);
|
addButtons(c);
|
||||||
|
|
||||||
setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder(
|
setBorder(new CompoundBorder(new LineBorder(Color.BLACK),
|
||||||
10, 10, 10, 10)));
|
new EmptyBorder(10, 10, 10, 10)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the game list to be displayed in the panel
|
||||||
|
*/
|
||||||
private void createGameList() {
|
private void createGameList() {
|
||||||
GridBagConstraints c = new GridBagConstraints();
|
GridBagConstraints c = new GridBagConstraints();
|
||||||
c.fill = GridBagConstraints.BOTH;
|
c.fill = GridBagConstraints.BOTH;
|
||||||
|
@ -113,6 +119,12 @@ class GameListPanel extends JPanel implements IGameListPanel {
|
||||||
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), c);
|
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds all three buttons to the panel
|
||||||
|
*
|
||||||
|
* @param c
|
||||||
|
* constraints for button positioning
|
||||||
|
*/
|
||||||
private void addButtons(GridBagConstraints c) {
|
private void addButtons(GridBagConstraints c) {
|
||||||
joinButton = new JButton("Beitreten");
|
joinButton = new JButton("Beitreten");
|
||||||
c.gridwidth = 1;
|
c.gridwidth = 1;
|
||||||
|
@ -154,6 +166,9 @@ class GameListPanel extends JPanel implements IGameListPanel {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets panel if all games have been removed from list
|
||||||
|
*/
|
||||||
void reset() {
|
void reset() {
|
||||||
games.clear();
|
games.clear();
|
||||||
}
|
}
|
||||||
|
@ -193,6 +208,9 @@ class GameListPanel extends JPanel implements IGameListPanel {
|
||||||
return cancelEvent;
|
return cancelEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emits a join event if a user selects a game and dedides to join it
|
||||||
|
*/
|
||||||
private void join() {
|
private void join() {
|
||||||
Object data = gameList.getSelectedValue();
|
Object data = gameList.getSelectedValue();
|
||||||
|
|
||||||
|
@ -201,6 +219,13 @@ class GameListPanel extends JPanel implements IGameListPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Counts the empty slots for network players in a game
|
||||||
|
*
|
||||||
|
* @param gameData
|
||||||
|
* of the game
|
||||||
|
* @return Pair of occupied spaces and vacant spaces
|
||||||
|
*/
|
||||||
private static Pair<Integer, Integer> getPlayerSlotCount(GameData gameData) {
|
private static Pair<Integer, Integer> getPlayerSlotCount(GameData gameData) {
|
||||||
int total = gameData.getGameSettings().getPlayerList().size();
|
int total = gameData.getGameSettings().getPlayerList().size();
|
||||||
int occupied = total;
|
int occupied = total;
|
||||||
|
@ -214,11 +239,17 @@ class GameListPanel extends JPanel implements IGameListPanel {
|
||||||
return new Pair<Integer, Integer>(occupied, total);
|
return new Pair<Integer, Integer>(occupied, total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class presenting the game data in a readable way
|
||||||
|
*/
|
||||||
private static class GameDataCellRenderer extends JPanel implements
|
private static class GameDataCellRenderer extends JPanel implements
|
||||||
ListCellRenderer {
|
ListCellRenderer {
|
||||||
private static final long serialVersionUID = -892701906163443927L;
|
private static final long serialVersionUID = -892701906163443927L;
|
||||||
JLabel hostLabel, playerCountLabel;
|
JLabel hostLabel, playerCountLabel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new game data cell renderer
|
||||||
|
*/
|
||||||
GameDataCellRenderer() {
|
GameDataCellRenderer() {
|
||||||
setLayout(new GridBagLayout());
|
setLayout(new GridBagLayout());
|
||||||
GridBagConstraints c = new GridBagConstraints();
|
GridBagConstraints c = new GridBagConstraints();
|
||||||
|
|
|
@ -140,6 +140,9 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
|
||||||
playerPanel.updateButtons();
|
playerPanel.updateButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates panel after visible row changed
|
||||||
|
*/
|
||||||
void rowUp() {
|
void rowUp() {
|
||||||
currentRow--;
|
currentRow--;
|
||||||
repaintAll = true;
|
repaintAll = true;
|
||||||
|
@ -148,6 +151,9 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
|
||||||
playerPanel.updateButtons();
|
playerPanel.updateButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates panel after visible row changed
|
||||||
|
*/
|
||||||
void rowDown() {
|
void rowDown() {
|
||||||
currentRow++;
|
currentRow++;
|
||||||
repaintAll = true;
|
repaintAll = true;
|
||||||
|
@ -163,10 +169,20 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
|
||||||
playerPanel.updateButtons();
|
playerPanel.updateButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is there a higher row than the current row
|
||||||
|
*
|
||||||
|
* @return higher row present
|
||||||
|
*/
|
||||||
boolean canRowUp() {
|
boolean canRowUp() {
|
||||||
return (currentRow > 0);
|
return (currentRow > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is there a lower row than the current row
|
||||||
|
*
|
||||||
|
* @return higher row present
|
||||||
|
*/
|
||||||
boolean canRowDown() {
|
boolean canRowDown() {
|
||||||
return (currentRow < maxRow);
|
return (currentRow < maxRow);
|
||||||
}
|
}
|
||||||
|
@ -188,6 +204,13 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rescales the hand panel according to window size
|
||||||
|
*
|
||||||
|
* @param height
|
||||||
|
* of hand panel
|
||||||
|
* @return width of hand panel
|
||||||
|
*/
|
||||||
int rescale(int height) {
|
int rescale(int height) {
|
||||||
Insets insets = getInsets();
|
Insets insets = getInsets();
|
||||||
int size = (height - insets.top - insets.bottom) / HEIGHT;
|
int size = (height - insets.top - insets.bottom) / HEIGHT;
|
||||||
|
|
Reference in a new issue