Host starts with button in ConnectionController

- Converted Event to Singleton for configuring and hosting no more than one game instance.
- Retrieve address and port from ConnectionAcceptor
- Automatically add local host to host list

#story[1010]
This commit is contained in:
Connor Taylor-Brown
2017-07-25 15:52:53 +12:00
parent a27c16d413
commit 7e3e865563
7 changed files with 108 additions and 98 deletions
@@ -8,11 +8,17 @@ import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import mock.app.Event;
import shared.exceptions.InvalidBoatDataException;
import shared.exceptions.InvalidRaceDataException;
import shared.exceptions.InvalidRegattaDataException;
import shared.exceptions.XMLReaderException;
import visualiser.model.RaceConnection;
import java.io.IOException;
import java.net.Socket;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.ResourceBundle;
/**
@@ -41,8 +47,6 @@ public class ConnectionController extends Controller {
public void initialize(URL location, ResourceBundle resources) {
// TODO - replace with config file
connections = FXCollections.observableArrayList();
connections.add(new RaceConnection("livedata.americascup.com", 4941));
connections.add(new RaceConnection("localhost", 4942));
connectionTable.setItems(connections);
hostnameColumn.setCellValueFactory(cellData -> cellData.getValue().hostnameProperty());
@@ -95,4 +99,28 @@ public class ConnectionController extends Controller {
}
}
/**
* Sets up a new host
*/
public void addLocal() {
try {
Event game = Event.getEvent();
urlField.textProperty().set(game.getAddress());
portField.textProperty().set(Integer.toString(game.getPort()));
game.start();
addConnection();
} catch (InvalidRaceDataException e) {
e.printStackTrace();
} catch (XMLReaderException e) {
e.printStackTrace();
} catch (InvalidBoatDataException e) {
e.printStackTrace();
} catch (InvalidRegattaDataException e) {
e.printStackTrace();
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}