- Added ConnectionController for initial client setup - Added RaceConnection class for socket data and checking - Configures StartController with a socket drawn from a host table #story[782]main
parent
ad58407021
commit
ac4fbda848
@ -1,14 +1,53 @@
|
|||||||
package seng302;
|
package seng302;
|
||||||
|
|
||||||
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
|
import javafx.beans.property.StringProperty;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.Socket;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by cbt24 on 3/05/17.
|
* Created by cbt24 on 3/05/17.
|
||||||
*/
|
*/
|
||||||
public class RaceConnection {
|
public class RaceConnection {
|
||||||
private String hostname;
|
private StringProperty hostname;
|
||||||
private int port;
|
private int port;
|
||||||
|
private StringProperty status;
|
||||||
|
|
||||||
public RaceConnection(String hostname, int port) {
|
public RaceConnection(String hostname, int port) {
|
||||||
this.hostname = hostname;
|
this.hostname = new SimpleStringProperty(hostname);
|
||||||
this.port = port;
|
this.port = port;
|
||||||
|
this.status = new SimpleStringProperty("");
|
||||||
|
check();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to create a socket to hostname and port, indicates status after test.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public boolean check() {
|
||||||
|
try(Socket s = new Socket(hostname.get(), port)) {
|
||||||
|
status.set("Ready");
|
||||||
|
return true;
|
||||||
|
} catch (IOException e) {}
|
||||||
|
|
||||||
|
status.set("Offline");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHostname() {
|
||||||
|
return hostname.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringProperty hostnameProperty() {
|
||||||
|
return hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPort() {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringProperty statusProperty() {
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,33 +1,54 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import javafx.scene.text.*?>
|
<?import javafx.geometry.Insets?>
|
||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.Button?>
|
||||||
<?import java.lang.*?>
|
<?import javafx.scene.control.Label?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.control.TableColumn?>
|
||||||
|
<?import javafx.scene.control.TableView?>
|
||||||
|
<?import javafx.scene.layout.AnchorPane?>
|
||||||
|
<?import javafx.scene.layout.ColumnConstraints?>
|
||||||
|
<?import javafx.scene.layout.GridPane?>
|
||||||
|
<?import javafx.scene.layout.RowConstraints?>
|
||||||
|
<?import javafx.scene.text.Font?>
|
||||||
|
|
||||||
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="seng302.Controllers.ConnectionController">
|
<AnchorPane fx:id="connectionWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.Controllers.ConnectionController">
|
||||||
|
<children>
|
||||||
|
<GridPane fx:id="connection" prefHeight="600.0" prefWidth="780.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
<columnConstraints>
|
<columnConstraints>
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="192.0" minWidth="10.0" prefWidth="50.0" />
|
<ColumnConstraints hgrow="SOMETIMES" maxWidth="600.0" minWidth="10.0" prefWidth="600.0" />
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="444.0" minWidth="10.0" prefWidth="444.0" />
|
<ColumnConstraints hgrow="SOMETIMES" maxWidth="600.0" minWidth="10.0" prefWidth="600.0" />
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="144.0" minWidth="10.0" prefWidth="56.0" />
|
|
||||||
</columnConstraints>
|
</columnConstraints>
|
||||||
<rowConstraints>
|
<rowConstraints>
|
||||||
<RowConstraints maxHeight="129.0" minHeight="10.0" prefHeight="61.0" vgrow="SOMETIMES" />
|
<RowConstraints maxHeight="182.0" minHeight="10.0" prefHeight="182.0" vgrow="SOMETIMES" />
|
||||||
<RowConstraints maxHeight="283.0" minHeight="10.0" prefHeight="239.0" vgrow="SOMETIMES" />
|
<RowConstraints maxHeight="434.0" minHeight="10.0" prefHeight="434.0" vgrow="SOMETIMES" />
|
||||||
<RowConstraints maxHeight="114.0" minHeight="10.0" prefHeight="89.0" vgrow="SOMETIMES" />
|
<RowConstraints maxHeight="174.0" minHeight="10.0" prefHeight="174.0" vgrow="SOMETIMES" />
|
||||||
</rowConstraints>
|
</rowConstraints>
|
||||||
<children>
|
<children>
|
||||||
<TableView prefHeight="500.0" prefWidth="900.0" GridPane.columnIndex="1" GridPane.rowIndex="1">
|
<TableView fx:id="connectionTable" prefHeight="200.0" prefWidth="1080.0" GridPane.columnSpan="2" GridPane.rowIndex="1">
|
||||||
<columns>
|
<columns>
|
||||||
<TableColumn prefWidth="217.0" text="Address" />
|
<TableColumn fx:id="hostnameColumn" prefWidth="453.99998474121094" text="Host" />
|
||||||
<TableColumn prefWidth="226.0" text="Status" />
|
<TableColumn fx:id="statusColumn" prefWidth="205.0" text="Status" />
|
||||||
</columns>
|
</columns>
|
||||||
|
<GridPane.margin>
|
||||||
|
<Insets left="50.0" right="50.0" />
|
||||||
|
</GridPane.margin>
|
||||||
</TableView>
|
</TableView>
|
||||||
<Label text="RaceVision" GridPane.columnIndex="1" GridPane.halignment="CENTER">
|
<Button mnemonicParsing="false" onAction="#checkConnections" text="Refresh" GridPane.halignment="RIGHT" GridPane.rowIndex="2">
|
||||||
|
<GridPane.margin>
|
||||||
|
<Insets right="20.0" />
|
||||||
|
</GridPane.margin>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="connectButton" mnemonicParsing="false" onAction="#connectSocket" text="Connect" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowIndex="2">
|
||||||
|
<GridPane.margin>
|
||||||
|
<Insets left="20.0" />
|
||||||
|
</GridPane.margin>
|
||||||
|
</Button>
|
||||||
|
<Label text="Welcome to RaceVision" GridPane.columnSpan="2" GridPane.halignment="CENTER">
|
||||||
<font>
|
<font>
|
||||||
<Font size="24.0" />
|
<Font size="36.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</Label>
|
||||||
<Button disable="true" mnemonicParsing="false" text="Connect" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="2" />
|
|
||||||
</children>
|
</children>
|
||||||
</GridPane>
|
</GridPane>
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
|
||||||
<?import javafx.scene.layout.AnchorPane?>
|
<?import javafx.scene.layout.AnchorPane?>
|
||||||
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" fx:id="main" xmlns="http://javafx.com/javafx/8"
|
|
||||||
fx:controller="seng302.Controllers.MainController">
|
<AnchorPane fx:id="main" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.Controllers.MainController">
|
||||||
<children>
|
<children>
|
||||||
<fx:include source="race.fxml" fx:id="race"/>
|
<fx:include fx:id="race" source="race.fxml" />
|
||||||
<fx:include source="start.fxml" fx:id="start"/>
|
<fx:include fx:id="start" source="start.fxml" />
|
||||||
|
<fx:include fx:id="connection" source="connect.fxml" />
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
package seng302;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.testng.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by connortaylorbrown on 3/05/17.
|
||||||
|
*/
|
||||||
|
public class RaceConnectionTest {
|
||||||
|
private RaceConnection onlineConnection;
|
||||||
|
private RaceConnection offlineConnection;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
onlineConnection = new RaceConnection("livedata.americascup.com", 4941);
|
||||||
|
offlineConnection = new RaceConnection("localhost", 4942);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onlineConnectionStatusReady() {
|
||||||
|
assertTrue(onlineConnection.check());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void offlineConnectionStatusOffline() {
|
||||||
|
assertFalse(offlineConnection.check());
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in new issue