Fix warnings

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@484 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Ida Massow 2011-06-19 16:11:23 +02:00
parent 92fe29000b
commit d0d349e5a8
14 changed files with 129 additions and 75 deletions

View file

@ -245,7 +245,7 @@ public class MockView implements IView {
} }
@Override @Override
public void showError() { public void showLoadingError() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }

View file

@ -68,7 +68,7 @@ public class ApplicationControl {
saveControl.getLoadErrorEvent().add(new IListener() { saveControl.getLoadErrorEvent().add(new IListener() {
@Override @Override
public void handle() { public void handle() {
view.showError(); view.showLoadingError();
} }
}); });
} }

View file

@ -108,15 +108,19 @@ public class SaveControl {
loadErrorEvent.emit(); loadErrorEvent.emit();
} }
} }
public Event getLoadErrorEvent(){ /**
* The load error event is emitted when the file selected for loading is not
* a rum file
*
* @return the event
*/
public Event getLoadErrorEvent() {
return loadErrorEvent; return loadErrorEvent;
} }
private void save(File file) { private void save(File file) {
if (gameState == null || gameSettings == null) { if (gameState == null || gameSettings == null) {
// TODO Menüpunkt ausgrauen
System.err.println("kein aktives Spiel");
return; return;
} }
try { try {

View file

@ -32,6 +32,9 @@ import org.jivesoftware.smack.util.Base64;
import org.jivesoftware.smackx.muc.DiscussionHistory; import org.jivesoftware.smackx.muc.DiscussionHistory;
import org.jivesoftware.smackx.muc.MultiUserChat; import org.jivesoftware.smackx.muc.MultiUserChat;
/**
* Connection control managing network connections, essages and events
*/
public class ConnectionControl implements IConnectionControl { public class ConnectionControl implements IConnectionControl {
private final static String ELEMENT_NAME = "rummikub"; private final static String ELEMENT_NAME = "rummikub";
private final static String NAMESPACE = "http://home.universe-factory.net/rummikub/"; private final static String NAMESPACE = "http://home.universe-factory.net/rummikub/";
@ -59,6 +62,12 @@ public class ConnectionControl implements IConnectionControl {
private volatile GameData offeredGame; private volatile GameData offeredGame;
/**
* Creates new connection control
*
* @param loginData
* player's login data
*/
public ConnectionControl(LoginData loginData) { public ConnectionControl(LoginData loginData) {
this.loginData = loginData; this.loginData = loginData;
} }
@ -222,7 +231,8 @@ public class ConnectionControl implements IConnectionControl {
protected void addData(DefaultPacketExtension extension) { protected void addData(DefaultPacketExtension extension) {
extension.setValue("messageType", "change_color"); extension.setValue("messageType", "change_color");
extension.setValue("uuid", uuid.toString()); extension.setValue("uuid", uuid.toString());
extension.setValue("color", Base64.encodeObject(color, Base64.GZIP)); extension.setValue("color",
Base64.encodeObject(color, Base64.GZIP));
} }
}); });
@ -248,8 +258,8 @@ public class ConnectionControl implements IConnectionControl {
protected void addData(DefaultPacketExtension extension) { protected void addData(DefaultPacketExtension extension) {
extension.setValue("messageType", "game_offer"); extension.setValue("messageType", "game_offer");
extension.setValue("uuid", data.getGameID().toString()); extension.setValue("uuid", data.getGameID().toString());
extension.setValue("gameSettings", extension.setValue("gameSettings", Base64.encodeObject(
Base64.encodeObject(data.getGameSettings(), Base64.GZIP)); data.getGameSettings(), Base64.GZIP));
} }
}); });
} }
@ -287,8 +297,8 @@ public class ConnectionControl implements IConnectionControl {
.getExtension(ELEMENT_NAME, NAMESPACE); .getExtension(ELEMENT_NAME, NAMESPACE);
if (((Message) packet).getType() == Message.Type.error) { if (((Message) packet).getType() == Message.Type.error) {
System.err.println("Received error message from '" + packet.getFrom() System.err.println("Received error message from '"
+ "'"); + packet.getFrom() + "'");
return; return;
} }
@ -304,13 +314,14 @@ public class ConnectionControl implements IConnectionControl {
String sender, String messageType) { String sender, String messageType) {
if (messageType.equals("game_offer")) { if (messageType.equals("game_offer")) {
UUID uuid = UUID.fromString(extension.getValue("uuid")); UUID uuid = UUID.fromString(extension.getValue("uuid"));
GameSettings settings = (GameSettings) Base64.decodeToObject(extension GameSettings settings = (GameSettings) Base64
.getValue("gameSettings")); .decodeToObject(extension.getValue("gameSettings"));
GameData gameData = new GameData(uuid, settings, sender); GameData gameData = new GameData(uuid, settings, sender);
gameOfferEvent.emit(gameData); gameOfferEvent.emit(gameData);
} else if (messageType.equals("game_withdrawal")) { } else if (messageType.equals("game_withdrawal")) {
gameWithdrawalEvent.emit(UUID.fromString(extension.getValue("uuid"))); gameWithdrawalEvent
.emit(UUID.fromString(extension.getValue("uuid")));
} else if (messageType.equals("game_request")) { } else if (messageType.equals("game_request")) {
if (offeredGame != null) { if (offeredGame != null) {
sendGameOffer(); sendGameOffer();
@ -393,7 +404,8 @@ public class ConnectionControl implements IConnectionControl {
break; // Join was successful, break the loop break; // Join was successful, break the loop
} catch (XMPPException e) { } catch (XMPPException e) {
XMPPError error = e.getXMPPError(); XMPPError error = e.getXMPPError();
if (error.getType() == Type.CANCEL && error.getCode() == 409) { if (error.getType() == Type.CANCEL
&& error.getCode() == 409) {
// There was a conflict, try again with another // There was a conflict, try again with another
// nickname // nickname
nickname += "_"; nickname += "_";

View file

@ -37,6 +37,8 @@ public class NetworkControl {
* *
* @param loginData * @param loginData
* user's login data * user's login data
* @param connectionControl
* current connection for events and messages
* @param view * @param view
* for events and handlers * for events and handlers
*/ */
@ -48,24 +50,24 @@ public class NetworkControl {
addConnectionSetupListeners(loginData, view); addConnectionSetupListeners(loginData, view);
addConnectionControlListeners(view); addConnectionControlListeners(view);
connections.add(view.getGameListPanel().getJoinEvent().add( connections.add(view.getGameListPanel().getJoinEvent()
new IListener1<GameData>() { .add(new IListener1<GameData>() {
@Override @Override
public void handle(GameData gameData) { public void handle(GameData gameData) {
join(gameData); join(gameData);
} }
})); }));
connections.add(view.getGameListPanel().getOpenNewGameEvent().add( connections.add(view.getGameListPanel().getOpenNewGameEvent()
new IListener() { .add(new IListener() {
@Override @Override
public void handle() { public void handle() {
createSettingsControl(); createSettingsControl();
} }
})); }));
connections.add(view.getGameListPanel().getCancelEvent().add( connections.add(view.getGameListPanel().getCancelEvent()
new IListener() { .add(new IListener() {
@Override @Override
public void handle() { public void handle() {
abort(); abort();
@ -222,8 +224,8 @@ public class NetworkControl {
} }
view.showGameListPanel(false); view.showGameListPanel(false);
settingsControl = new NetworkSettingsControl(connectionControl settingsControl = new NetworkSettingsControl(
.getNickname(), view, new GameSettings()); connectionControl.getNickname(), view, new GameSettings());
settingsControl.getOfferGameEvent().add(new IListener1<GameSettings>() { settingsControl.getOfferGameEvent().add(new IListener1<GameSettings>() {
@Override @Override
public void handle(GameSettings settings) { public void handle(GameSettings settings) {

View file

@ -61,7 +61,6 @@ public class Pair<T1, T2> implements Serializable {
return result; return result;
} }
@SuppressWarnings("unchecked")
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj)
@ -70,6 +69,7 @@ public class Pair<T1, T2> implements Serializable {
return false; return false;
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
@SuppressWarnings("rawtypes")
Pair other = (Pair) obj; Pair other = (Pair) obj;
if (first == null) { if (first == null) {
if (other.first != null) if (other.first != null)

View file

@ -237,7 +237,6 @@ public interface IView {
*/ */
public void showGameListPanel(boolean show); public void showGameListPanel(boolean show);
/** /**
* Is set if a player tried to lay out less than initial meld threshold * Is set if a player tried to lay out less than initial meld threshold
* *
@ -250,6 +249,7 @@ public interface IView {
* Show stone collection * Show stone collection
* *
* @param enable * @param enable
* showing collection
*/ */
public void setStoneCollectionHidden(boolean enable); public void setStoneCollectionHidden(boolean enable);
@ -258,7 +258,14 @@ public interface IView {
*/ */
public void setInitialMeldFirstError(); public void setInitialMeldFirstError();
/**
* Set invalid sets to enable showing
*
* @param sets
* invalid sets on table
*/
public void setInvalidStoneSets(Collection<StoneSet> sets); public void setInvalidStoneSets(Collection<StoneSet> sets);
/** /**
* Different types of bottom panels * Different types of bottom panels
*/ */
@ -276,7 +283,16 @@ public interface IView {
/** */ /** */
WIN_PANEL WIN_PANEL
} }
void showError();
/**
* Show when loading is unsuccessful
*/
void showLoadingError();
/**
* Enables/disables saving in menu bar
*
* @param enable
*/
void enableSave(boolean enable); void enableSave(boolean enable);
} }

View file

@ -6,8 +6,6 @@ import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Insets; import java.awt.Insets;
import java.awt.RenderingHints; import java.awt.RenderingHints;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;

View file

@ -6,7 +6,6 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter; import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent; import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Collections; import java.util.Collections;

View file

@ -165,7 +165,7 @@ public class View extends JFrame implements IView {
} }
@Override @Override
public void showError() { public void showLoadingError() {
JOptionPane.showMessageDialog(this, "Kein g\u00fcltiger Spielstand", JOptionPane.showMessageDialog(this, "Kein g\u00fcltiger Spielstand",
"Fehler", JOptionPane.ERROR_MESSAGE); "Fehler", JOptionPane.ERROR_MESSAGE);
} }

View file

@ -1,7 +1,7 @@
package jrummikub.control.network; package jrummikub.control.network;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue;
import java.awt.Color; import java.awt.Color;
import java.util.UUID; import java.util.UUID;
@ -17,6 +17,9 @@ import jrummikub.view.MockView;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
/**
* Test class for game join control
*/
public class GameJoinControlTest { public class GameJoinControlTest {
LoginData loginData; LoginData loginData;
MockConnectionControl mockConnection; MockConnectionControl mockConnection;

View file

@ -1,23 +1,24 @@
package jrummikub.control.network; package jrummikub.control.network;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.awt.Color; import java.awt.Color;
import java.util.UUID; import java.util.UUID;
import jrummikub.model.GameSettings;
import jrummikub.model.PlayerSettings;
import jrummikub.model.PlayerSettings.Type; import jrummikub.model.PlayerSettings.Type;
import jrummikub.util.GameData;
import jrummikub.util.LoginData; import jrummikub.util.LoginData;
import jrummikub.view.MockView;
import jrummikub.view.ISettingsPanel.SettingsMode; import jrummikub.view.ISettingsPanel.SettingsMode;
import jrummikub.view.MockView;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
/**
* Test class for game offer control
*/
public class GameOfferControlTest { public class GameOfferControlTest {
LoginData loginData; LoginData loginData;
MockConnectionControl mockConnection; MockConnectionControl mockConnection;
@ -53,31 +54,36 @@ public class GameOfferControlTest {
assertEquals(SettingsMode.NETWORK_OFFER, assertEquals(SettingsMode.NETWORK_OFFER,
view.settingsPanel.settingsMode); view.settingsPanel.settingsMode);
view.settingsPanel.changePlayerColorEvent.emit(0, Color.PINK); view.settingsPanel.changePlayerColorEvent.emit(0, Color.PINK);
assertEquals(Color.PINK, mockConnection.playerColor); assertEquals(Color.PINK, mockConnection.playerColor);
view.settingsPanel.backEvent.emit(); view.settingsPanel.backEvent.emit();
assertFalse(view.isSettingsPanelVisible); assertFalse(view.isSettingsPanelVisible);
assertTrue(view.isGameListPanelVisible); assertTrue(view.isGameListPanelVisible);
} }
/** */ /** */
@Test @Test
public void getJoinLeaveTest(){ public void getJoinLeaveTest() {
view.gameListPanel.openNewGameEvent.emit(); view.gameListPanel.openNewGameEvent.emit();
view.settingsPanel.offerGameEvent.emit(); view.settingsPanel.offerGameEvent.emit();
mockConnection.gameJoinEvent.emit("Berta"); mockConnection.gameJoinEvent.emit("Berta");
assertEquals("Berta", mockConnection.offeredGame.getGameSettings().getPlayerList().get(1).getName()); assertEquals("Berta", mockConnection.offeredGame.getGameSettings()
assertSame(Type.NETWORK, mockConnection.offeredGame.getGameSettings().getPlayerList().get(1).getType()); .getPlayerList().get(1).getName());
assertSame(Type.NETWORK, mockConnection.offeredGame.getGameSettings()
.getPlayerList().get(1).getType());
mockConnection.changeColorEvent.emit("Berta", Color.BLUE); mockConnection.changeColorEvent.emit("Berta", Color.BLUE);
assertEquals(Color.BLUE, mockConnection.offeredGame.getGameSettings().getPlayerList().get(1).getColor()); assertEquals(Color.BLUE, mockConnection.offeredGame.getGameSettings()
.getPlayerList().get(1).getColor());
mockConnection.gameLeaveEvent.emit("Berta"); mockConnection.gameLeaveEvent.emit("Berta");
assertEquals("Offen", mockConnection.offeredGame.getGameSettings().getPlayerList().get(1).getName()); assertEquals("Offen", mockConnection.offeredGame.getGameSettings()
assertSame(Type.VACANT, mockConnection.offeredGame.getGameSettings().getPlayerList().get(1).getType()); .getPlayerList().get(1).getName());
} assertSame(Type.VACANT, mockConnection.offeredGame.getGameSettings()
.getPlayerList().get(1).getType());
}
} }

View file

@ -1,7 +1,9 @@
package jrummikub.control.network; package jrummikub.control.network;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.awt.Color; import java.awt.Color;
import java.util.UUID; import java.util.UUID;
@ -11,12 +13,15 @@ import jrummikub.model.PlayerSettings;
import jrummikub.model.PlayerSettings.Type; import jrummikub.model.PlayerSettings.Type;
import jrummikub.util.GameData; import jrummikub.util.GameData;
import jrummikub.util.LoginData; import jrummikub.util.LoginData;
import jrummikub.view.MockView;
import jrummikub.view.ISettingsPanel.SettingsMode; import jrummikub.view.ISettingsPanel.SettingsMode;
import jrummikub.view.MockView;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
/**
* Test class for network control
*/
public class NetworkControlTest { public class NetworkControlTest {
LoginData loginData; LoginData loginData;
MockConnectionControl mockConnection; MockConnectionControl mockConnection;
@ -76,9 +81,9 @@ public class NetworkControlTest {
assertEquals(SettingsMode.NETWORK_OFFER, assertEquals(SettingsMode.NETWORK_OFFER,
view.settingsPanel.settingsMode); view.settingsPanel.settingsMode);
} }
/** */ /** */
@Test @Test
public void joinGameTest() { public void joinGameTest() {
mockConnection.connectedEvent.emit(); mockConnection.connectedEvent.emit();
GameData data = offerTestGame(id1, "Berta"); GameData data = offerTestGame(id1, "Berta");
@ -112,12 +117,12 @@ public class NetworkControlTest {
assertEquals(id2, view.gameListPanel.gameList.get(0).getGameID()); assertEquals(id2, view.gameListPanel.gameList.get(0).getGameID());
assertEquals("Horst", view.gameListPanel.gameList.get(0).getHost()); assertEquals("Horst", view.gameListPanel.gameList.get(0).getHost());
} }
/** */ /** */
@Test @Test
public void testCancel(){ public void testCancel() {
mockConnection.connectedEvent.emit(); mockConnection.connectedEvent.emit();
view.gameListPanel.cancelEvent.emit(); view.gameListPanel.cancelEvent.emit();
assertFalse(view.isGameListPanelVisible); assertFalse(view.isGameListPanelVisible);
assertFalse(mockConnection.connected); assertFalse(mockConnection.connected);

View file

@ -1,21 +1,23 @@
package jrummikub.control.network; package jrummikub.control.network;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.util.UUID; import java.util.UUID;
import jrummikub.model.PlayerSettings.Type; import jrummikub.model.PlayerSettings.Type;
import jrummikub.util.LoginData; import jrummikub.util.LoginData;
import jrummikub.view.MockView;
import jrummikub.view.ISettingsPanel.SettingsMode; import jrummikub.view.ISettingsPanel.SettingsMode;
import jrummikub.view.MockView;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
/**
* Test class for network settings control
*/
public class NetworkSettingsControlTest { public class NetworkSettingsControlTest {
LoginData loginData; LoginData loginData;
MockConnectionControl mockConnection; MockConnectionControl mockConnection;
@ -36,7 +38,7 @@ public class NetworkSettingsControlTest {
networkControl = new NetworkControl(loginData, mockConnection, view); networkControl = new NetworkControl(loginData, mockConnection, view);
networkControl.startNetwork(); networkControl.startNetwork();
mockConnection.connectedEvent.emit(); mockConnection.connectedEvent.emit();
} }
/** */ /** */
@ -45,7 +47,8 @@ public class NetworkSettingsControlTest {
view.gameListPanel.openNewGameEvent.emit(); view.gameListPanel.openNewGameEvent.emit();
assertFalse(view.isGameListPanelVisible); assertFalse(view.isGameListPanelVisible);
assertTrue(view.isSettingsPanelVisible); assertTrue(view.isSettingsPanelVisible);
assertEquals(SettingsMode.NETWORK_SETUP, view.settingsPanel.settingsMode); assertEquals(SettingsMode.NETWORK_SETUP,
view.settingsPanel.settingsMode);
view.settingsPanel.addPlayerEvent.emit(); view.settingsPanel.addPlayerEvent.emit();
view.settingsPanel.addPlayerEvent.emit(); view.settingsPanel.addPlayerEvent.emit();
view.settingsPanel.changePlayerTypeEvent.emit(1, Type.VACANT); view.settingsPanel.changePlayerTypeEvent.emit(1, Type.VACANT);
@ -53,16 +56,22 @@ public class NetworkSettingsControlTest {
view.settingsPanel.changeJokerNumberEvent.emit(4); view.settingsPanel.changeJokerNumberEvent.emit(4);
view.settingsPanel.changeHighestValueEvent.emit(10); view.settingsPanel.changeHighestValueEvent.emit(10);
view.settingsPanel.offerGameEvent.emit(); view.settingsPanel.offerGameEvent.emit();
assertEquals(SettingsMode.NETWORK_OFFER, view.settingsPanel.settingsMode); assertEquals(SettingsMode.NETWORK_OFFER,
view.settingsPanel.settingsMode);
assertEquals(4, mockConnection.offeredGame.getGameSettings().getPlayerList().size());
assertSame(Type.VACANT, mockConnection.offeredGame.getGameSettings().getPlayerList().get(1).getType()); assertEquals(4, mockConnection.offeredGame.getGameSettings()
assertSame(Type.COMPUTER, mockConnection.offeredGame.getGameSettings().getPlayerList().get(2).getType()); .getPlayerList().size());
assertSame(Type.VACANT, mockConnection.offeredGame.getGameSettings().getPlayerList().get(3).getType()); assertSame(Type.VACANT, mockConnection.offeredGame.getGameSettings()
assertEquals(4, mockConnection.offeredGame.getGameSettings().getJokerNumber()); .getPlayerList().get(1).getType());
assertEquals(10, mockConnection.offeredGame.getGameSettings().getHighestValue()); assertSame(Type.COMPUTER, mockConnection.offeredGame.getGameSettings()
.getPlayerList().get(2).getType());
assertSame(Type.VACANT, mockConnection.offeredGame.getGameSettings()
.getPlayerList().get(3).getType());
assertEquals(4, mockConnection.offeredGame.getGameSettings()
.getJokerNumber());
assertEquals(10, mockConnection.offeredGame.getGameSettings()
.getHighestValue());
} }
} }