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 hostName;
|
||||
|
||||
/**
|
||||
* Creates a new dedicated server with the specified password
|
||||
*
|
||||
* @param serverPassword
|
||||
* the password
|
||||
*/
|
||||
public DedicatedServer(String serverPassword) {
|
||||
this.serverPassword = serverPassword;
|
||||
try {
|
||||
|
@ -29,6 +35,11 @@ public class DedicatedServer {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for host name
|
||||
*
|
||||
* @return host name
|
||||
*/
|
||||
public String getHostName() {
|
||||
return hostName;
|
||||
}
|
||||
|
|
|
@ -231,7 +231,8 @@ public interface ISettingsPanel {
|
|||
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
|
||||
*/
|
||||
|
@ -245,6 +246,12 @@ public interface ISettingsPanel {
|
|||
*/
|
||||
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();
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,14 +5,42 @@ import java.util.List;
|
|||
import jrummikub.model.GameSettings;
|
||||
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 {
|
||||
|
||||
/**
|
||||
* Sets the game settings to top of side panel
|
||||
*
|
||||
* @param settings
|
||||
* current game settings
|
||||
*/
|
||||
public void setGameSettings(GameSettings settings);
|
||||
|
||||
/**
|
||||
* Sets the total heap size for progress bar
|
||||
*
|
||||
* @param capacity
|
||||
* total heap size
|
||||
*/
|
||||
void setHeapCapacity(int capacity);
|
||||
|
||||
/**
|
||||
* Sets the current heap size
|
||||
*
|
||||
* @param size
|
||||
* number of stones in current heap
|
||||
*/
|
||||
void setHeapSize(int size);
|
||||
|
||||
/**
|
||||
* Sets the player information in order of turns
|
||||
*
|
||||
* @param players
|
||||
* players in current game
|
||||
*/
|
||||
void setPlayers(List<IPlayer> players);
|
||||
|
||||
}
|
|
@ -9,6 +9,7 @@ public interface IStoneCollectionPanel extends IStonePanel {
|
|||
* Hide stone collection
|
||||
*
|
||||
* @param enable
|
||||
* see stone collection
|
||||
*/
|
||||
void setHidden(boolean enable);
|
||||
}
|
||||
|
|
|
@ -124,8 +124,8 @@ public interface IView {
|
|||
public void setCurrentPlayerColor(Color color);
|
||||
|
||||
/**
|
||||
* Is used for the PlayerPanel to display if a player has laid out along with
|
||||
* the name
|
||||
* Is used for the PlayerPanel to display if a player has laid out along
|
||||
* with the name
|
||||
*
|
||||
* @param hasLaidOut
|
||||
* specifies if the current player has laid out or not
|
||||
|
@ -148,8 +148,8 @@ public interface IView {
|
|||
public void setBottomPanel(BottomPanelType type);
|
||||
|
||||
/**
|
||||
* The menu new game event is emitted when the user selects the new game menu
|
||||
* entry
|
||||
* The menu new game event is emitted when the user selects the new game
|
||||
* menu entry
|
||||
*
|
||||
* @return the event
|
||||
*/
|
||||
|
@ -337,6 +337,13 @@ public interface IView {
|
|||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
|
|
|
@ -77,8 +77,9 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel,
|
|||
public void mouseMoved(MouseEvent e) {
|
||||
Insets insets = getInsets();
|
||||
Pair<Integer, Integer> trans = getTranslation();
|
||||
Position pos = stonePainter.calculatePosition(e.getX() - insets.left
|
||||
- trans.getFirst(), e.getY() - insets.top - trans.getSecond());
|
||||
Position pos = stonePainter.calculatePosition(e.getX()
|
||||
- insets.left - trans.getFirst(), e.getY() - insets.top
|
||||
- trans.getSecond());
|
||||
|
||||
setHoveredStone(getStoneAt(pos));
|
||||
|
||||
|
@ -132,6 +133,12 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel,
|
|||
event.emit(stone, control);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the stone over which the cursor hovers
|
||||
*
|
||||
* @param stone
|
||||
* stone under cursor
|
||||
*/
|
||||
private void setHoveredStone(Stone stone) {
|
||||
Stone oldStone = hoveredStone;
|
||||
hoveredStone = stone;
|
||||
|
@ -170,6 +177,13 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel,
|
|||
protected void handleOtherMoveEvent(Position pos) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the stone at the specified position
|
||||
*
|
||||
* @param pos
|
||||
* position
|
||||
* @return the stone
|
||||
*/
|
||||
private Stone getStoneAt(Position pos) {
|
||||
for (Pair<Stone, Position> entry : stones) {
|
||||
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
|
||||
*/
|
||||
|
|
|
@ -49,6 +49,9 @@ class GameListPanel extends JPanel implements IGameListPanel {
|
|||
|
||||
private List<GameData> games = Collections.emptyList();
|
||||
|
||||
/**
|
||||
* Creates new game list panel
|
||||
*/
|
||||
GameListPanel() {
|
||||
setLayout(new GridBagLayout());
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
|
@ -70,10 +73,13 @@ class GameListPanel extends JPanel implements IGameListPanel {
|
|||
|
||||
addButtons(c);
|
||||
|
||||
setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder(
|
||||
10, 10, 10, 10)));
|
||||
setBorder(new CompoundBorder(new LineBorder(Color.BLACK),
|
||||
new EmptyBorder(10, 10, 10, 10)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the game list to be displayed in the panel
|
||||
*/
|
||||
private void createGameList() {
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
c.fill = GridBagConstraints.BOTH;
|
||||
|
@ -113,6 +119,12 @@ class GameListPanel extends JPanel implements IGameListPanel {
|
|||
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all three buttons to the panel
|
||||
*
|
||||
* @param c
|
||||
* constraints for button positioning
|
||||
*/
|
||||
private void addButtons(GridBagConstraints c) {
|
||||
joinButton = new JButton("Beitreten");
|
||||
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() {
|
||||
games.clear();
|
||||
}
|
||||
|
@ -193,6 +208,9 @@ class GameListPanel extends JPanel implements IGameListPanel {
|
|||
return cancelEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits a join event if a user selects a game and dedides to join it
|
||||
*/
|
||||
private void join() {
|
||||
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) {
|
||||
int total = gameData.getGameSettings().getPlayerList().size();
|
||||
int occupied = total;
|
||||
|
@ -214,11 +239,17 @@ class GameListPanel extends JPanel implements IGameListPanel {
|
|||
return new Pair<Integer, Integer>(occupied, total);
|
||||
}
|
||||
|
||||
/**
|
||||
* Class presenting the game data in a readable way
|
||||
*/
|
||||
private static class GameDataCellRenderer extends JPanel implements
|
||||
ListCellRenderer {
|
||||
private static final long serialVersionUID = -892701906163443927L;
|
||||
JLabel hostLabel, playerCountLabel;
|
||||
|
||||
/**
|
||||
* Create new game data cell renderer
|
||||
*/
|
||||
GameDataCellRenderer() {
|
||||
setLayout(new GridBagLayout());
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
|
|
|
@ -140,6 +140,9 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
|
|||
playerPanel.updateButtons();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates panel after visible row changed
|
||||
*/
|
||||
void rowUp() {
|
||||
currentRow--;
|
||||
repaintAll = true;
|
||||
|
@ -148,6 +151,9 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
|
|||
playerPanel.updateButtons();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates panel after visible row changed
|
||||
*/
|
||||
void rowDown() {
|
||||
currentRow++;
|
||||
repaintAll = true;
|
||||
|
@ -163,10 +169,20 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
|
|||
playerPanel.updateButtons();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is there a higher row than the current row
|
||||
*
|
||||
* @return higher row present
|
||||
*/
|
||||
boolean canRowUp() {
|
||||
return (currentRow > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is there a lower row than the current row
|
||||
*
|
||||
* @return higher row present
|
||||
*/
|
||||
boolean canRowDown() {
|
||||
return (currentRow < maxRow);
|
||||
}
|
||||
|
@ -188,6 +204,13 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
|
|||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rescales the hand panel according to window size
|
||||
*
|
||||
* @param height
|
||||
* of hand panel
|
||||
* @return width of hand panel
|
||||
*/
|
||||
int rescale(int height) {
|
||||
Insets insets = getInsets();
|
||||
int size = (height - insets.top - insets.bottom) / HEIGHT;
|
||||
|
|
Reference in a new issue