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:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,11 @@ public class RaceConnection {
|
||||
private final int port;
|
||||
private final StringProperty status;
|
||||
|
||||
/**
|
||||
* Constructor for remote host connections.
|
||||
* @param hostname URL for remote host
|
||||
* @param port port for game feed
|
||||
*/
|
||||
public RaceConnection(String hostname, int port) {
|
||||
this.hostname = new SimpleStringProperty(hostname);
|
||||
this.port = port;
|
||||
|
||||
Reference in New Issue
Block a user