mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
- Learned how JFX Validators work and implemented them for direct connection.
- Aside from the error message when a server cannot be found (which is the default javafx one) I think the serverlist is pretty much done. tags: #story[1245]
This commit is contained in:
@@ -3,9 +3,12 @@ package seng302.visualiser.controllers;
|
|||||||
import com.jfoenix.controls.JFXButton;
|
import com.jfoenix.controls.JFXButton;
|
||||||
import com.jfoenix.controls.JFXDialog;
|
import com.jfoenix.controls.JFXDialog;
|
||||||
import com.jfoenix.controls.JFXDialog.DialogTransition;
|
import com.jfoenix.controls.JFXDialog.DialogTransition;
|
||||||
|
import com.jfoenix.validation.RequiredFieldValidator;
|
||||||
import com.sun.org.apache.xpath.internal.SourceTree;
|
import com.sun.org.apache.xpath.internal.SourceTree;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
@@ -13,6 +16,8 @@ import com.jfoenix.controls.JFXTextField;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
@@ -73,8 +78,14 @@ public class ServerListController implements Initializable, ServerListenerDelega
|
|||||||
attemptToDirectConnect();
|
attemptToDirectConnect();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
RequiredFieldValidator validator = new RequiredFieldValidator();
|
||||||
|
textField.getValidators().add(validator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
serverHostName.getValidators().get(0).setMessage("Correct HostName Required");
|
||||||
|
serverPortNumber.getValidators().get(0).setMessage("Correct Port Number Required");
|
||||||
|
|
||||||
// Start listening for servers on network
|
// Start listening for servers on network
|
||||||
try {
|
try {
|
||||||
ServerListener.getInstance().setDelegate(this);
|
ServerListener.getInstance().setDelegate(this);
|
||||||
@@ -82,14 +93,18 @@ public class ServerListController implements Initializable, ServerListenerDelega
|
|||||||
logger.warn("Could not start Server Listener Delegate");
|
logger.warn("Could not start Server Listener Delegate");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create Label for no servers found.
|
||||||
noServersFound = new Label();
|
noServersFound = new Label();
|
||||||
noServersFound.setText("No Servers Found");
|
|
||||||
noServersFound.setTextFill(Color.BLACK);
|
|
||||||
noServersFound.setAlignment(Pos.CENTER);
|
|
||||||
noServersFound.minWidthProperty().bind(serverListVBox.widthProperty());
|
noServersFound.minWidthProperty().bind(serverListVBox.widthProperty());
|
||||||
noServersFound.setStyle("-fx-font-size: 30px; -fx-padding:50px;");
|
noServersFound.setAlignment(Pos.CENTER);
|
||||||
|
noServersFound.setText("No Servers Found");
|
||||||
|
noServersFound.setStyle(
|
||||||
|
"-fx-font-size: 30px;"
|
||||||
|
+ "-fx-padding:50px;"
|
||||||
|
+ "-fx-text-fill: -fx-pp-dark-text-color;"
|
||||||
|
);
|
||||||
serverListVBox.getChildren().add(noServersFound);
|
serverListVBox.getChildren().add(noServersFound);
|
||||||
|
|
||||||
// Set up dialog for server creation
|
// Set up dialog for server creation
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
FXMLLoader dialogContent = new FXMLLoader(getClass().getResource(
|
FXMLLoader dialogContent = new FXMLLoader(getClass().getResource(
|
||||||
@@ -108,8 +123,8 @@ public class ServerListController implements Initializable, ServerListenerDelega
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private void attemptToDirectConnect() {
|
private void attemptToDirectConnect() {
|
||||||
if (validateHostName() && validatePortNumber()) {
|
if (validateHostName(serverHostName.getText()) && validatePortNumber(serverPortNumber.getText())) {
|
||||||
System.out.println("Do some stuff");
|
DirectConnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,17 +132,29 @@ public class ServerListController implements Initializable, ServerListenerDelega
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private Boolean validateHostName() {
|
private Boolean validateHostName(String hostName) {
|
||||||
|
if (hostName.length() == 0) {
|
||||||
|
serverHostName.validate();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// Validate the Host Name here.
|
// Validate the Host Name here.
|
||||||
|
try {
|
||||||
|
/* The result of this is ignored. All We want to do is test that
|
||||||
|
the hostname matches some form. I'm not 100% sure how valid this is. */
|
||||||
|
InetAddress.getByName(hostName);
|
||||||
return true;
|
return true;
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
// Fails to resolve the host name.
|
||||||
|
serverHostName.validate();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private Boolean validatePortNumber() {
|
private Boolean validatePortNumber(String portNumber) {
|
||||||
if (serverPortNumber.getLength() == 0) return false;
|
|
||||||
try {
|
try {
|
||||||
Integer portNum = Integer.parseInt(serverPortNumber.getText());
|
Integer portNum = Integer.parseInt(serverPortNumber.getText());
|
||||||
if (portNum > 1024 && portNum <= 65536) {
|
if (portNum > 1024 && portNum <= 65536) {
|
||||||
@@ -136,6 +163,7 @@ public class ServerListController implements Initializable, ServerListenerDelega
|
|||||||
System.out.println(portNum.toString() + "is not a valid port number");
|
System.out.println(portNum.toString() + "is not a valid port number");
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
|
serverPortNumber.validate();
|
||||||
System.out.println("Not a valid number.");
|
System.out.println("Not a valid number.");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -163,14 +191,11 @@ public class ServerListController implements Initializable, ServerListenerDelega
|
|||||||
* @param servers
|
* @param servers
|
||||||
*/
|
*/
|
||||||
private void refreshServers(List<ServerDescription> servers) {
|
private void refreshServers(List<ServerDescription> servers) {
|
||||||
// TODO: 7/09/17 ajm412: Add some way to force a refresh.
|
|
||||||
// TODO: 7/09/17 ajm412: Add something for No Servers Found.
|
|
||||||
serverListVBox.getChildren().clear();
|
serverListVBox.getChildren().clear();
|
||||||
|
|
||||||
if (servers.size() == 0) {
|
if (servers.size() == 0) { // "No Servers Found"
|
||||||
serverListVBox.getChildren().add(noServersFound);
|
serverListVBox.getChildren().add(noServersFound);
|
||||||
} else {
|
} else { // Populate the server list with a series of server cell objects.
|
||||||
// Populate the server list with a series of server cell objects.
|
|
||||||
for (ServerDescription server : servers) {
|
for (ServerDescription server : servers) {
|
||||||
VBox pane = null;
|
VBox pane = null;
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,12 @@
|
|||||||
-fx-prompt-text-fill: -fx-pp-light-text-color;
|
-fx-prompt-text-fill: -fx-pp-light-text-color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#serverHostName .error-label, #serverPortNumber .error-label {
|
||||||
|
-fx-font-size: 12px;
|
||||||
|
-fx-text-fill: palevioletred;
|
||||||
|
}
|
||||||
|
|
||||||
#connectGridPane {
|
#connectGridPane {
|
||||||
-fx-background-color: -fx-pp-theme-color;
|
-fx-background-color: -fx-pp-theme-color;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import com.jfoenix.controls.*?>
|
|
||||||
<?import java.lang.*?>
|
|
||||||
<?import javafx.geometry.*?>
|
|
||||||
<?import javafx.scene.control.*?>
|
|
||||||
<?import javafx.scene.layout.*?>
|
|
||||||
<?import javafx.scene.text.*?>
|
|
||||||
<?import com.jfoenix.controls.JFXButton?>
|
<?import com.jfoenix.controls.JFXButton?>
|
||||||
<?import com.jfoenix.controls.JFXTextField?>
|
<?import com.jfoenix.controls.JFXTextField?>
|
||||||
<?import java.lang.String?>
|
<?import java.lang.String?>
|
||||||
@@ -15,10 +9,11 @@
|
|||||||
<?import javafx.scene.layout.ColumnConstraints?>
|
<?import javafx.scene.layout.ColumnConstraints?>
|
||||||
<?import javafx.scene.layout.GridPane?>
|
<?import javafx.scene.layout.GridPane?>
|
||||||
<?import javafx.scene.layout.RowConstraints?>
|
<?import javafx.scene.layout.RowConstraints?>
|
||||||
|
<?import javafx.scene.layout.StackPane?>
|
||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.scene.layout.VBox?>
|
||||||
<?import javafx.scene.text.Font?>
|
<?import javafx.scene.text.Font?>
|
||||||
|
|
||||||
<StackPane fx:id="serverListMainStackPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.visualiser.controllers.ServerListController">
|
<StackPane fx:id="serverListMainStackPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.visualiser.controllers.ServerListController">
|
||||||
<children>
|
<children>
|
||||||
<GridPane fx:id="serverListMainGridPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
|
<GridPane fx:id="serverListMainGridPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
|
||||||
<children>
|
<children>
|
||||||
@@ -49,7 +44,7 @@
|
|||||||
<ColumnConstraints hgrow="SOMETIMES" />
|
<ColumnConstraints hgrow="SOMETIMES" />
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="280.0" minWidth="180.0" prefWidth="180.0" />
|
<ColumnConstraints hgrow="SOMETIMES" maxWidth="280.0" minWidth="180.0" prefWidth="180.0" />
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="320.0" minWidth="280.0" prefWidth="280.0" />
|
<ColumnConstraints hgrow="SOMETIMES" maxWidth="320.0" minWidth="280.0" prefWidth="280.0" />
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="150.0" minWidth="150.0" prefWidth="150.0" />
|
<ColumnConstraints hgrow="SOMETIMES" maxWidth="-Infinity" minWidth="-Infinity" prefWidth="180.0" />
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="17.0" minWidth="17.0" prefWidth="17.0" />
|
<ColumnConstraints hgrow="SOMETIMES" maxWidth="17.0" minWidth="17.0" prefWidth="17.0" />
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="273.0" minWidth="250.0" prefWidth="273.0" />
|
<ColumnConstraints hgrow="SOMETIMES" maxWidth="273.0" minWidth="250.0" prefWidth="273.0" />
|
||||||
</columnConstraints>
|
</columnConstraints>
|
||||||
|
|||||||
Reference in New Issue
Block a user