Implemented SSDP client and is now using graphical list cells in ListViews
This commit is contained in:
parent
120dded24f
commit
34cf5865fe
16 changed files with 428 additions and 86 deletions
26
lib/controlsfx-8.20.9-LICENSE.txt
Normal file
26
lib/controlsfx-8.20.9-LICENSE.txt
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2013, 2014, ControlsFX
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of ControlsFX, any associated website, nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL CONTROLSFX BE LIABLE FOR ANY
|
||||||
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
@ -5,8 +5,6 @@ import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
|
|
||||||
import com.coder.client.Session;
|
import com.coder.client.Session;
|
||||||
import com.coder.client.gui.editor.EditorWindow;
|
import com.coder.client.gui.editor.EditorWindow;
|
||||||
import com.coder.client.gui.editor.EditorWindowListener;
|
import com.coder.client.gui.editor.EditorWindowListener;
|
||||||
|
|
@ -25,6 +23,9 @@ import com.coder.server.message.ProjectRspMsg;
|
||||||
|
|
||||||
import zutil.log.CompactLogFormatter;
|
import zutil.log.CompactLogFormatter;
|
||||||
import zutil.log.LogUtil;
|
import zutil.log.LogUtil;
|
||||||
|
import zutil.net.ssdp.SSDPClient;
|
||||||
|
import zutil.net.ssdp.SSDPClient.SSDPServiceListener;
|
||||||
|
import zutil.net.ssdp.StandardSSDPInfo;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
@ -45,7 +46,12 @@ public class CoderClient extends Application{
|
||||||
private String serverURL = null;
|
private String serverURL = null;
|
||||||
private int serverPort = CoderServer.SERVER_PORT;
|
private int serverPort = CoderServer.SERVER_PORT;
|
||||||
private String username = null;
|
private String username = null;
|
||||||
private char[] password = null;
|
private char[] password = null; //should only be anything else than null if defined by program argument
|
||||||
|
private String loginErrorMessage = "";
|
||||||
|
private String project = null;
|
||||||
|
|
||||||
|
//services
|
||||||
|
SSDPClient ssdpClient;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Application.launch(args);
|
Application.launch(args);
|
||||||
|
|
@ -74,13 +80,15 @@ public class CoderClient extends Application{
|
||||||
}catch(NumberFormatException e){
|
}catch(NumberFormatException e){
|
||||||
logger.warning("port argument to program is not of a integer type. using default port.");
|
logger.warning("port argument to program is not of a integer type. using default port.");
|
||||||
}
|
}
|
||||||
|
}else if(key.equals("project")){
|
||||||
|
this.project = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(this.username == null){ //ignore the password if no username was set
|
if(this.username == null){ //ignore the password if no username was set
|
||||||
this.password = null;
|
this.password = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//loading GUI
|
//setup GUI elements
|
||||||
this.mainStage = mainStage;
|
this.mainStage = mainStage;
|
||||||
mainStage.setTitle("CoderClient");
|
mainStage.setTitle("CoderClient");
|
||||||
try{
|
try{
|
||||||
|
|
@ -90,6 +98,15 @@ public class CoderClient extends Application{
|
||||||
setupEditWindow();
|
setupEditWindow();
|
||||||
}catch(IOException e){
|
}catch(IOException e){
|
||||||
logger.log(Level.SEVERE, "could not load all GUI elements", e);
|
logger.log(Level.SEVERE, "could not load all GUI elements", e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//setup SSDP client
|
||||||
|
try{
|
||||||
|
setupSSDPClient();
|
||||||
|
}catch(IOException e){
|
||||||
|
logger.log(Level.SEVERE, "could not setup SSDP client", e);
|
||||||
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//start program logic
|
//start program logic
|
||||||
|
|
@ -103,6 +120,13 @@ public class CoderClient extends Application{
|
||||||
@Override
|
@Override
|
||||||
public void willShow() {
|
public void willShow() {
|
||||||
closeCurrentSession();
|
closeCurrentSession();
|
||||||
|
ssdpClient.clearServices();
|
||||||
|
selectServerDialog.clearServerList();
|
||||||
|
if(ssdpClient != null){
|
||||||
|
ssdpClient.requestService("coder:discover");
|
||||||
|
}else{
|
||||||
|
logger.severe("could not send a SSDP request since the client is not setup");
|
||||||
|
}
|
||||||
selectServerDialog.setServerAddress(serverURL);
|
selectServerDialog.setServerAddress(serverURL);
|
||||||
selectServerDialog.setServerPort(serverPort);
|
selectServerDialog.setServerPort(serverPort);
|
||||||
}
|
}
|
||||||
|
|
@ -121,13 +145,13 @@ public class CoderClient extends Application{
|
||||||
if(session == null){
|
if(session == null){
|
||||||
logger.warning("Could not setup a connection to " + serverURL + ":" + port);
|
logger.warning("Could not setup a connection to " + serverURL + ":" + port);
|
||||||
serverURL = null;
|
serverURL = null;
|
||||||
|
serverPort = CoderServer.SERVER_PORT;
|
||||||
selectServerDialog.showOnStage(mainStage);
|
selectServerDialog.showOnStage(mainStage);
|
||||||
}else{
|
}else{
|
||||||
loginDialog.showOnStage(mainStage);
|
loginDialog.showOnStage(mainStage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupLoginDialog() throws IOException {
|
private void setupLoginDialog() throws IOException {
|
||||||
|
|
@ -137,6 +161,7 @@ public class CoderClient extends Application{
|
||||||
public void willShow() {
|
public void willShow() {
|
||||||
loginDialog.setUsername(username);
|
loginDialog.setUsername(username);
|
||||||
loginDialog.setPassword(password);
|
loginDialog.setPassword(password);
|
||||||
|
loginDialog.setErrorMessage(loginErrorMessage);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
|
|
@ -151,14 +176,16 @@ public class CoderClient extends Application{
|
||||||
//authenticate session
|
//authenticate session
|
||||||
boolean authenticated = session.authenticate(username, password);
|
boolean authenticated = session.authenticate(username, password);
|
||||||
if(!authenticated){
|
if(!authenticated){
|
||||||
JOptionPane.showMessageDialog(null, "Wrong username or password", "Authentication Failed", JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
logger.severe("Authentication failed: wrong username or password");
|
logger.severe("Authentication failed: wrong username or password");
|
||||||
password = null;
|
password = null;
|
||||||
loginDialog.showOnStage(mainStage);
|
loginErrorMessage = "Wrong username or password";
|
||||||
|
selectServerDialog.showOnStage(mainStage);
|
||||||
|
}else{
|
||||||
|
loginErrorMessage = "";
|
||||||
|
setupSessionListener(); //resister a message listener to the session
|
||||||
|
session.start(); //start receiving traffic from the server
|
||||||
|
selectProjectDialog.showOnStage(mainStage);
|
||||||
}
|
}
|
||||||
setupSessionListener(); //resister a message listener to the session
|
|
||||||
session.start(); //start receiving traffic from the server
|
|
||||||
selectProjectDialog.showOnStage(mainStage);
|
|
||||||
}
|
}
|
||||||
private void setupSessionListener(){
|
private void setupSessionListener(){
|
||||||
session.addCoderMessageReceivedListener(new CoderMessageReceivedListener() {
|
session.addCoderMessageReceivedListener(new CoderMessageReceivedListener() {
|
||||||
|
|
@ -187,17 +214,22 @@ public class CoderClient extends Application{
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupSelectProjectDialog() throws IOException {
|
private void setupSelectProjectDialog() throws IOException {
|
||||||
this.selectProjectDialog = new SelectProjectDialog();
|
this.selectProjectDialog = new SelectProjectDialog();
|
||||||
this.selectProjectDialog.addSelectProjectDialogListener(new SelectProjectDialogListener() {
|
this.selectProjectDialog.addSelectProjectDialogListener(new SelectProjectDialogListener() {
|
||||||
@Override
|
@Override
|
||||||
public void willShow() {
|
public void willShow() {
|
||||||
selectProjectDialog.clearProjectList();
|
selectProjectDialog.clearProjectList();
|
||||||
sendProjectListReq();
|
if(project == null){
|
||||||
|
sendProjectListReq();
|
||||||
|
}else{
|
||||||
|
selectProjectDialog.setProject(project);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void openProject(String selectedProjectName) {
|
public void open(String selectedProjectName) {
|
||||||
|
project = selectedProjectName;
|
||||||
editorWindow.showOnStage(mainStage);
|
editorWindow.showOnStage(mainStage);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -247,6 +279,25 @@ public class CoderClient extends Application{
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupSSDPClient() throws IOException{
|
||||||
|
this.ssdpClient = new SSDPClient();
|
||||||
|
ssdpClient.setListener(new SSDPServiceListener() {
|
||||||
|
@Override
|
||||||
|
public void newService(final StandardSSDPInfo service) {
|
||||||
|
if(selectServerDialog != null){
|
||||||
|
Platform.runLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
String ip = service.getInetAddress().getHostAddress();
|
||||||
|
selectServerDialog.addServerToList(ip);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ssdpClient.start();
|
||||||
|
}
|
||||||
|
|
||||||
private void closeCurrentSession(){
|
private void closeCurrentSession(){
|
||||||
if(this.session != null){
|
if(this.session != null){
|
||||||
logger.info("disconnecting from server");
|
logger.info("disconnecting from server");
|
||||||
|
|
|
||||||
|
|
@ -70,11 +70,11 @@ public class Session extends Thread {
|
||||||
try {
|
try {
|
||||||
msg = in.readGenericObject();
|
msg = in.readGenericObject();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
//logger.log(Level.SEVERE, "socket is probably closed by the peer", e);
|
logger.log(Level.FINE, "socket was probably closed by the peer", e);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(msg == null){
|
if(msg == null){
|
||||||
//logger.severe("socket is probably closed by the peer");
|
logger.fine("socket was probably closed by the peer");
|
||||||
break;
|
break;
|
||||||
}else{
|
}else{
|
||||||
handleMessage(msg);
|
handleMessage(msg);
|
||||||
|
|
|
||||||
|
|
@ -1,42 +1,33 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.paint.*?>
|
||||||
<?import javafx.scene.text.*?>
|
<?import javafx.scene.text.*?>
|
||||||
<?import javafx.geometry.*?>
|
<?import javafx.geometry.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
<?import java.lang.*?>
|
<?import java.lang.*?>
|
||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.*?>
|
||||||
|
|
||||||
<GridPane prefHeight="113.0" prefWidth="294.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
|
|
||||||
<columnConstraints>
|
<AnchorPane prefHeight="116.0" prefWidth="378.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
|
||||||
<ColumnConstraints maxWidth="142.0" minWidth="10.0" prefWidth="76.0" />
|
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="228.0" minWidth="10.0" prefWidth="198.0" />
|
|
||||||
</columnConstraints>
|
|
||||||
<rowConstraints>
|
|
||||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
|
||||||
</rowConstraints>
|
|
||||||
<children>
|
<children>
|
||||||
<Label text="username" />
|
<Label layoutX="10.0" layoutY="17.0" text="username" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="17.0" />
|
||||||
<TextField fx:id="usernameTextField" onKeyPressed="#keyPressed" prefHeight="25.0" prefWidth="291.0" GridPane.columnIndex="1" />
|
<TextField fx:id="usernameTextField" layoutX="80.0" layoutY="13.0" onKeyPressed="#keyPressed" prefHeight="25.0" prefWidth="291.0" AnchorPane.leftAnchor="80.0" AnchorPane.rightAnchor="7.0" AnchorPane.topAnchor="13.0" />
|
||||||
<Label text="password" GridPane.rowIndex="1" />
|
<Label layoutX="10.0" layoutY="48.0" text="password" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="48.0" />
|
||||||
<PasswordField fx:id="passwordPasswordField" onKeyPressed="#keyPressed" prefHeight="25.0" prefWidth="291.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
<PasswordField fx:id="passwordPasswordField" layoutX="80.0" layoutY="44.0" onKeyPressed="#keyPressed" prefHeight="25.0" prefWidth="291.0" AnchorPane.leftAnchor="80.0" AnchorPane.rightAnchor="7.0" AnchorPane.topAnchor="44.0" />
|
||||||
<HBox alignment="CENTER_RIGHT" prefHeight="69.0" prefWidth="218.0" GridPane.columnIndex="1" GridPane.rowIndex="2">
|
<Label fx:id="errorLabel" alignment="TOP_LEFT" layoutX="10.0" layoutY="75.0" maxWidth="1.7976931348623157E308" prefHeight="35.0" prefWidth="242.0" text="error" textFill="RED" wrapText="true" />
|
||||||
|
<HBox alignment="CENTER_RIGHT" layoutX="42.0" layoutY="34.0" prefHeight="35.0" prefWidth="200.0" AnchorPane.bottomAnchor="5.0" AnchorPane.rightAnchor="0.0">
|
||||||
<children>
|
<children>
|
||||||
|
<Button fx:id="cancelButton" mnemonicParsing="false" onAction="#cancel" text="Cancel">
|
||||||
|
<HBox.margin>
|
||||||
|
<Insets right="10.0" />
|
||||||
|
</HBox.margin>
|
||||||
|
</Button>
|
||||||
<Button fx:id="loginButton" mnemonicParsing="false" onAction="#login" text="Login">
|
<Button fx:id="loginButton" mnemonicParsing="false" onAction="#login" text="Login">
|
||||||
<HBox.margin>
|
<HBox.margin>
|
||||||
<Insets right="10.0" />
|
<Insets right="10.0" />
|
||||||
</HBox.margin>
|
</HBox.margin>
|
||||||
</Button>
|
</Button>
|
||||||
<Button fx:id="cancelButton" mnemonicParsing="false" onAction="#cancel" text="Cancel">
|
|
||||||
<HBox.margin>
|
|
||||||
<Insets />
|
|
||||||
</HBox.margin>
|
|
||||||
</Button>
|
|
||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
</children>
|
</children>
|
||||||
<padding>
|
</AnchorPane>
|
||||||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
|
||||||
</padding>
|
|
||||||
</GridPane>
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import zutil.log.LogUtil;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.PasswordField;
|
import javafx.scene.control.PasswordField;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.input.KeyCode;
|
import javafx.scene.input.KeyCode;
|
||||||
|
|
@ -26,6 +27,7 @@ public class LoginDialog extends GuiWindow {
|
||||||
@FXML private PasswordField passwordPasswordField;
|
@FXML private PasswordField passwordPasswordField;
|
||||||
@FXML private Button cancelButton;
|
@FXML private Button cancelButton;
|
||||||
@FXML private Button loginButton;
|
@FXML private Button loginButton;
|
||||||
|
@FXML private Label errorLabel;
|
||||||
|
|
||||||
public LoginDialog() throws IOException {
|
public LoginDialog() throws IOException {
|
||||||
super(LoginDialog.class.getResource("LoginDialog.fxml"));
|
super(LoginDialog.class.getResource("LoginDialog.fxml"));
|
||||||
|
|
@ -34,7 +36,7 @@ public class LoginDialog extends GuiWindow {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
|
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
|
||||||
|
errorLabel.setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -42,11 +44,14 @@ public class LoginDialog extends GuiWindow {
|
||||||
for(LoginDialogListener listener : this.listeners){
|
for(LoginDialogListener listener : this.listeners){
|
||||||
listener.willShow();
|
listener.willShow();
|
||||||
}
|
}
|
||||||
if(!usernameTextField.getText().isEmpty() && !passwordPasswordField.getText().isEmpty()){
|
if(usernameTextField.getText() != null && !usernameTextField.getText().isEmpty() && passwordPasswordField.getText() != null && !passwordPasswordField.getText().isEmpty()){
|
||||||
loginButton.fire();
|
loginButton.fire();
|
||||||
}
|
}else{
|
||||||
if(!usernameTextField.getText().isEmpty()){
|
if(errorLabel.getText() != null && errorLabel.getText().isEmpty() && usernameTextField.getText() != null && !usernameTextField.getText().isEmpty()){
|
||||||
passwordPasswordField.requestFocus();
|
passwordPasswordField.requestFocus();
|
||||||
|
}else{
|
||||||
|
usernameTextField.requestFocus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,4 +101,8 @@ public class LoginDialog extends GuiWindow {
|
||||||
return "Login";
|
return "Login";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setErrorMessage(String msg) {
|
||||||
|
errorLabel.setText(msg);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
31
src/com/coder/client/gui/selectProject/ProjectListCell.fxml
Normal file
31
src/com/coder/client/gui/selectProject/ProjectListCell.fxml
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.geometry.*?>
|
||||||
|
<?import javafx.scene.text.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import java.lang.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
|
||||||
|
<AnchorPane maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="40.0" prefWidth="186.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
|
||||||
|
<children>
|
||||||
|
<Label fx:id="nameLabel" layoutX="52.0" layoutY="17.0" prefHeight="24.0" prefWidth="316.0" text="Project Name" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="0.0">
|
||||||
|
<font>
|
||||||
|
<Font name="System Bold" size="16.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Label fx:id="typeLabel" layoutX="30.0" layoutY="23.0" prefHeight="17.0" text="Project Type" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="30.0">
|
||||||
|
<padding>
|
||||||
|
<Insets right="15.0" />
|
||||||
|
</padding>
|
||||||
|
<font>
|
||||||
|
<Font name="System Bold Italic" size="12.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Label fx:id="descriptionLabel" layoutX="114.0" layoutY="23.0" prefHeight="17.0" text="Description" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="117.0" AnchorPane.rightAnchor="5.0">
|
||||||
|
<font>
|
||||||
|
<Font name="System Italic" size="12.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
42
src/com/coder/client/gui/selectProject/ProjectListCell.java
Normal file
42
src/com/coder/client/gui/selectProject/ProjectListCell.java
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.coder.client.gui.selectProject;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Node;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.ListCell;
|
||||||
|
|
||||||
|
class ProjectListCell extends ListCell<ProjectListItem> {
|
||||||
|
|
||||||
|
@FXML private Label nameLabel;
|
||||||
|
@FXML private Label typeLabel;
|
||||||
|
@FXML private Label descriptionLabel;
|
||||||
|
private Node node;
|
||||||
|
|
||||||
|
public ProjectListCell() throws IOException{
|
||||||
|
FXMLLoader loader = new FXMLLoader(ProjectListCell.class.getResource("ProjectListCell.fxml"));
|
||||||
|
loader.setController(this);
|
||||||
|
this.node = (Node)loader.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateItem(ProjectListItem item, boolean empty){
|
||||||
|
super.updateItem(item, empty);
|
||||||
|
if(empty){
|
||||||
|
setText("");
|
||||||
|
setGraphic(null);
|
||||||
|
}else if(item != null){
|
||||||
|
setText("");
|
||||||
|
nameLabel.setText(item.getName());
|
||||||
|
typeLabel.setText(item.getType());
|
||||||
|
descriptionLabel.setText(item.getDescription());
|
||||||
|
setGraphic(node);
|
||||||
|
}else{
|
||||||
|
setText("NULL");
|
||||||
|
setGraphic(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,18 +1,30 @@
|
||||||
package com.coder.client.gui.selectProject;
|
package com.coder.client.gui.selectProject;
|
||||||
|
|
||||||
public class ProjectListItem {
|
class ProjectListItem {
|
||||||
private String projectName;
|
private String name;
|
||||||
private String type;
|
private String type;
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
public ProjectListItem(String projectName, String type, String description) {
|
public ProjectListItem(String projectName, String type, String description) {
|
||||||
this.projectName = projectName;
|
this.name = projectName;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName(){
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType(){
|
||||||
|
return this.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription(){
|
||||||
|
return this.description;
|
||||||
|
}
|
||||||
|
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return "ProjectName="+projectName+", type="+type+", description="+description;
|
return "PROJECT: ProjectName="+name+", type="+type+", description="+description;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,11 @@
|
||||||
<?import java.lang.*?>
|
<?import java.lang.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
|
||||||
<AnchorPane xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
|
<AnchorPane xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
|
||||||
<children>
|
<children>
|
||||||
<ScrollPane fitToHeight="true" fitToWidth="true" hbarPolicy="NEVER" prefHeight="164.0" prefWidth="396.0" AnchorPane.bottomAnchor="50.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
<ScrollPane fitToHeight="true" fitToWidth="true" hbarPolicy="NEVER" prefHeight="164.0" prefWidth="396.0" AnchorPane.bottomAnchor="50.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
<content>
|
<content>
|
||||||
<ListView fx:id="projectListView" prefHeight="200.0" prefWidth="200.0" />
|
<ListView fx:id="projectListView" onKeyPressed="#keyPressed" onMouseClicked="#mouseClickedOnList" prefHeight="200.0" prefWidth="200.0" />
|
||||||
</content>
|
</content>
|
||||||
</ScrollPane>
|
</ScrollPane>
|
||||||
<GridPane maxHeight="-Infinity" minHeight="-Infinity" prefHeight="50.0" prefWidth="396.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
|
<GridPane maxHeight="-Infinity" minHeight="-Infinity" prefHeight="50.0" prefWidth="396.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
|
||||||
|
|
@ -30,7 +29,7 @@
|
||||||
<Insets right="10.0" />
|
<Insets right="10.0" />
|
||||||
</HBox.margin>
|
</HBox.margin>
|
||||||
</Button>
|
</Button>
|
||||||
<Button fx:id="openProjectButton" mnemonicParsing="false" onAction="#openProject" text="Open Project">
|
<Button fx:id="openButton" defaultButton="true" disable="true" mnemonicParsing="false" onAction="#open" text="Open">
|
||||||
<HBox.margin>
|
<HBox.margin>
|
||||||
<Insets right="10.0" />
|
<Insets right="10.0" />
|
||||||
</HBox.margin>
|
</HBox.margin>
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,13 @@ import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import zutil.log.LogUtil;
|
import zutil.log.LogUtil;
|
||||||
|
|
||||||
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
|
|
@ -17,6 +20,8 @@ import javafx.scene.control.ListCell;
|
||||||
import javafx.scene.control.ListView;
|
import javafx.scene.control.ListView;
|
||||||
import javafx.scene.input.KeyCode;
|
import javafx.scene.input.KeyCode;
|
||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.KeyEvent;
|
||||||
|
import javafx.scene.input.MouseButton;
|
||||||
|
import javafx.scene.input.MouseEvent;
|
||||||
import javafx.util.Callback;
|
import javafx.util.Callback;
|
||||||
|
|
||||||
import com.coder.client.gui.GuiWindow;
|
import com.coder.client.gui.GuiWindow;
|
||||||
|
|
@ -30,7 +35,9 @@ public class SelectProjectDialog extends GuiWindow {
|
||||||
@FXML private ListView<ProjectListItem> projectListView;
|
@FXML private ListView<ProjectListItem> projectListView;
|
||||||
@FXML private Button newProjectButton;
|
@FXML private Button newProjectButton;
|
||||||
@FXML private Button cancelButton;
|
@FXML private Button cancelButton;
|
||||||
@FXML private Button openProjectButton;
|
@FXML private Button openButton;
|
||||||
|
|
||||||
|
private String projectName = null;
|
||||||
|
|
||||||
public SelectProjectDialog() throws IOException {
|
public SelectProjectDialog() throws IOException {
|
||||||
super(SelectProjectDialog.class.getResource("SelectProjectDialog.fxml"));
|
super(SelectProjectDialog.class.getResource("SelectProjectDialog.fxml"));
|
||||||
|
|
@ -42,6 +49,11 @@ public class SelectProjectDialog extends GuiWindow {
|
||||||
for(SelectProjectDialogListener listener : this.listeners){
|
for(SelectProjectDialogListener listener : this.listeners){
|
||||||
listener.willShow();
|
listener.willShow();
|
||||||
}
|
}
|
||||||
|
if(this.projectName != null){
|
||||||
|
openButton.setDisable(false);
|
||||||
|
openButton.fire();
|
||||||
|
}
|
||||||
|
openButton.setDisable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -51,32 +63,41 @@ public class SelectProjectDialog extends GuiWindow {
|
||||||
projectListView.setCellFactory(new Callback<ListView<ProjectListItem>, ListCell<ProjectListItem>>(){
|
projectListView.setCellFactory(new Callback<ListView<ProjectListItem>, ListCell<ProjectListItem>>(){
|
||||||
@Override
|
@Override
|
||||||
public ListCell<ProjectListItem> call(ListView<ProjectListItem> arg0) {
|
public ListCell<ProjectListItem> call(ListView<ProjectListItem> arg0) {
|
||||||
System.out.println("cell factory");
|
try {
|
||||||
ListCell<ProjectListItem> cell = new ListCell<ProjectListItem>(){
|
return new ProjectListCell();
|
||||||
@Override
|
} catch (IOException e) {
|
||||||
protected void updateItem(ProjectListItem item, boolean empty){
|
logger.log(Level.SEVERE, "could not crate a ProjectListCell instance", e);
|
||||||
System.out.println("update item: " + item);
|
}
|
||||||
super.updateItem(item, empty);
|
return null;
|
||||||
if(empty){
|
|
||||||
setText("");
|
|
||||||
setGraphic(null);
|
|
||||||
}
|
|
||||||
if(item != null){
|
|
||||||
setText(item.toString());
|
|
||||||
//setGraphic(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return cell;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
projectListView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<ProjectListItem>() {
|
||||||
|
@Override
|
||||||
|
public void changed(ObservableValue<? extends ProjectListItem> observable, ProjectListItem oldValue, ProjectListItem vewValue) {
|
||||||
|
if(observable.getValue() != null){
|
||||||
|
logger.fine("ProjectListItem [" + observable.getValue() + "] selected in the project list");
|
||||||
|
openButton.setDisable(false);
|
||||||
|
}else{
|
||||||
|
openButton.setDisable(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
protected void mouseClickedOnList(MouseEvent event){
|
||||||
|
if(event.getButton().equals(MouseButton.PRIMARY)){
|
||||||
|
if(event.getClickCount() == 2){ //if doublecklick
|
||||||
|
openButton.fire();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected void keyPressed(KeyEvent event) {
|
protected void keyPressed(KeyEvent event) {
|
||||||
if(event.getCode() == KeyCode.ENTER){
|
if(event.getCode() == KeyCode.ENTER){
|
||||||
logger.fine("User pressed the ENTER key");
|
logger.fine("User pressed the ENTER key");
|
||||||
openProjectButton.fire();
|
openButton.fire();
|
||||||
}else if(event.getCode() == KeyCode.ESCAPE){
|
}else if(event.getCode() == KeyCode.ESCAPE){
|
||||||
logger.fine("User pressed the ESCAPE key");
|
logger.fine("User pressed the ESCAPE key");
|
||||||
cancelButton.fire();
|
cancelButton.fire();
|
||||||
|
|
@ -108,11 +129,15 @@ public class SelectProjectDialog extends GuiWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected void openProject(ActionEvent event){
|
protected void open(ActionEvent event){
|
||||||
|
if(this.projectName == null){
|
||||||
|
ProjectListItem selectedItem = projectListView.getSelectionModel().getSelectedItem();
|
||||||
|
projectName = selectedItem.getName();
|
||||||
|
}
|
||||||
for(SelectProjectDialogListener listener : this.listeners){
|
for(SelectProjectDialogListener listener : this.listeners){
|
||||||
//TODO: get selected project in the list view
|
if(projectName != null){
|
||||||
String selectedProjectName = "project name";
|
listener.open(projectName);
|
||||||
listener.openProject(selectedProjectName);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -133,7 +158,11 @@ public class SelectProjectDialog extends GuiWindow {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getTitle() {
|
protected String getTitle() {
|
||||||
return "Select Project";
|
return "Open Project";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProject(String project) {
|
||||||
|
this.projectName = project;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ public interface SelectProjectDialogListener {
|
||||||
|
|
||||||
void cancel();
|
void cancel();
|
||||||
|
|
||||||
void openProject(String selectedProjectName);
|
void open(String selectedProjectName);
|
||||||
|
|
||||||
void willShow();
|
void willShow();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,15 @@
|
||||||
<?import java.lang.*?>
|
<?import java.lang.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="217.0" prefWidth="396.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
|
|
||||||
|
<AnchorPane xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
|
||||||
<children>
|
<children>
|
||||||
<ScrollPane fitToHeight="true" fitToWidth="true" hbarPolicy="NEVER">
|
<ScrollPane fitToHeight="true" fitToWidth="true" hbarPolicy="NEVER" prefHeight="248.0" prefWidth="396.0" AnchorPane.bottomAnchor="50.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
<content>
|
<content>
|
||||||
<ListView fx:id="serverListView" prefHeight="200.0" prefWidth="200.0" />
|
<ListView fx:id="serverListView" onKeyPressed="#keyPressed" onMouseClicked="#mouseClickedOnList" prefHeight="200.0" prefWidth="200.0" />
|
||||||
</content>
|
</content>
|
||||||
</ScrollPane>
|
</ScrollPane>
|
||||||
<GridPane prefHeight="77.0" prefWidth="396.0">
|
<GridPane layoutY="171.0" prefHeight="50.0" prefWidth="396.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
|
||||||
<columnConstraints>
|
<columnConstraints>
|
||||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||||
|
|
@ -21,14 +22,14 @@
|
||||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||||
</rowConstraints>
|
</rowConstraints>
|
||||||
<children>
|
<children>
|
||||||
<HBox alignment="CENTER_RIGHT" prefHeight="100.0" prefWidth="200.0" GridPane.columnIndex="1">
|
<HBox alignment="CENTER_RIGHT" maxHeight="-Infinity" minHeight="-Infinity" prefHeight="100.0" prefWidth="200.0" GridPane.columnIndex="1">
|
||||||
<children>
|
<children>
|
||||||
<Button fx:id="exitButton" mnemonicParsing="false" onAction="#exit" text="Exit">
|
<Button fx:id="exitButton" mnemonicParsing="false" onAction="#exit" text="Exit">
|
||||||
<HBox.margin>
|
<HBox.margin>
|
||||||
<Insets right="10.0" />
|
<Insets right="10.0" />
|
||||||
</HBox.margin>
|
</HBox.margin>
|
||||||
</Button>
|
</Button>
|
||||||
<Button fx:id="connectButton" mnemonicParsing="false" onAction="#connect" text="Connect">
|
<Button fx:id="connectButton" defaultButton="true" disable="true" mnemonicParsing="false" onAction="#connect" text="Connect">
|
||||||
<HBox.margin>
|
<HBox.margin>
|
||||||
<Insets right="10.0" />
|
<Insets right="10.0" />
|
||||||
</HBox.margin>
|
</HBox.margin>
|
||||||
|
|
@ -39,4 +40,4 @@
|
||||||
</children>
|
</children>
|
||||||
</GridPane>
|
</GridPane>
|
||||||
</children>
|
</children>
|
||||||
</VBox>
|
</AnchorPane>
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,23 @@ import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.ListCell;
|
||||||
|
import javafx.scene.control.ListView;
|
||||||
|
import javafx.scene.input.KeyCode;
|
||||||
|
import javafx.scene.input.KeyEvent;
|
||||||
|
import javafx.scene.input.MouseButton;
|
||||||
|
import javafx.scene.input.MouseEvent;
|
||||||
|
import javafx.util.Callback;
|
||||||
|
|
||||||
import zutil.log.LogUtil;
|
import zutil.log.LogUtil;
|
||||||
|
|
||||||
|
|
@ -17,9 +29,12 @@ import com.coder.client.gui.GuiWindow;
|
||||||
public class SelectServerDialog extends GuiWindow {
|
public class SelectServerDialog extends GuiWindow {
|
||||||
public static final Logger logger = LogUtil.getLogger();
|
public static final Logger logger = LogUtil.getLogger();
|
||||||
private HashSet<SelectServerDialogListener> listeners;
|
private HashSet<SelectServerDialogListener> listeners;
|
||||||
|
private ObservableList<ServerListItem> serverList;
|
||||||
|
|
||||||
private String address = null;
|
private String address = null;
|
||||||
private int port = -1;
|
private int port = -1;
|
||||||
|
|
||||||
|
@FXML private ListView<ServerListItem> serverListView;
|
||||||
@FXML private Button exitButton;
|
@FXML private Button exitButton;
|
||||||
@FXML private Button connectButton;
|
@FXML private Button connectButton;
|
||||||
|
|
||||||
|
|
@ -34,15 +49,60 @@ public class SelectServerDialog extends GuiWindow {
|
||||||
listener.willShow();
|
listener.willShow();
|
||||||
}
|
}
|
||||||
if(address != null && port != -1){
|
if(address != null && port != -1){
|
||||||
|
connectButton.setDisable(false);
|
||||||
connectButton.fire();
|
connectButton.fire();
|
||||||
}
|
}
|
||||||
|
connectButton.setDisable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
|
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
|
||||||
// TODO Auto-generated method stub
|
serverList = FXCollections.observableArrayList();
|
||||||
|
serverListView.setItems(serverList);
|
||||||
|
serverListView.setCellFactory(new Callback<ListView<ServerListItem>, ListCell<ServerListItem>>(){
|
||||||
|
@Override
|
||||||
|
public ListCell<ServerListItem> call(ListView<ServerListItem> arg0) {
|
||||||
|
try {
|
||||||
|
return new ServerListCell();
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.log(Level.SEVERE, "could not crate a ServerListCell instance", e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
serverListView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<ServerListItem>() {
|
||||||
|
@Override
|
||||||
|
public void changed(ObservableValue<? extends ServerListItem> observable, ServerListItem oldValue, ServerListItem vewValue) {
|
||||||
|
if(observable.getValue() != null){
|
||||||
|
logger.fine("ServerListItem [" + observable.getValue() + "] selected in the server list");
|
||||||
|
address = observable.getValue().getIP();
|
||||||
|
connectButton.setDisable(false);
|
||||||
|
}else{
|
||||||
|
connectButton.setDisable(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
protected void mouseClickedOnList(MouseEvent event){
|
||||||
|
if(event.getButton().equals(MouseButton.PRIMARY)){
|
||||||
|
if(event.getClickCount() == 2){
|
||||||
|
connectButton.fire();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
protected void keyPressed(KeyEvent event) {
|
||||||
|
if(event.getCode() == KeyCode.ENTER){
|
||||||
|
logger.fine("User pressed the ENTER key");
|
||||||
|
connectButton.fire();
|
||||||
|
}else if(event.getCode() == KeyCode.ESCAPE){
|
||||||
|
logger.fine("User pressed the ESCAPE key");
|
||||||
|
exitButton.fire();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected void exit(ActionEvent event){
|
protected void exit(ActionEvent event){
|
||||||
|
|
@ -68,12 +128,22 @@ public class SelectServerDialog extends GuiWindow {
|
||||||
|
|
||||||
public void setServerPort(int serverPort) {
|
public void setServerPort(int serverPort) {
|
||||||
this.port = serverPort;
|
this.port = serverPort;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getTitle() {
|
protected String getTitle() {
|
||||||
return "Select Server";
|
return "Select Server";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addServerToList(String ip) {
|
||||||
|
logger.fine("Adding server \"" + ip + "\" to server list");
|
||||||
|
ServerListItem item = new ServerListItem(ip);
|
||||||
|
this.serverList.add(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearServerList(){
|
||||||
|
logger.fine("Clearing server list");
|
||||||
|
serverList.clear();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
25
src/com/coder/client/gui/selectServer/ServerListCell.fxml
Normal file
25
src/com/coder/client/gui/selectServer/ServerListCell.fxml
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.geometry.*?>
|
||||||
|
<?import javafx.scene.text.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import java.lang.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
<AnchorPane maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="40.0" prefWidth="186.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
|
||||||
|
<children>
|
||||||
|
<Label fx:id="serverNameLabel" layoutX="52.0" layoutY="17.0" prefHeight="24.0" prefWidth="316.0" text="Server Name" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="0.0">
|
||||||
|
<font>
|
||||||
|
<Font name="System Bold" size="16.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Label fx:id="ipLabel" layoutX="30.0" layoutY="23.0" prefHeight="17.0" text="IP" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="30.0" AnchorPane.rightAnchor="10.0">
|
||||||
|
<padding>
|
||||||
|
<Insets right="15.0" />
|
||||||
|
</padding>
|
||||||
|
<font>
|
||||||
|
<Font name="System Bold Italic" size="12.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
37
src/com/coder/client/gui/selectServer/ServerListCell.java
Normal file
37
src/com/coder/client/gui/selectServer/ServerListCell.java
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.coder.client.gui.selectServer;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Node;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.ListCell;
|
||||||
|
|
||||||
|
class ServerListCell extends ListCell<ServerListItem> {
|
||||||
|
|
||||||
|
@FXML private Label ipLabel;
|
||||||
|
private Node node;
|
||||||
|
|
||||||
|
public ServerListCell() throws IOException{
|
||||||
|
FXMLLoader loader = new FXMLLoader(ServerListCell.class.getResource("ServerListCell.fxml"));
|
||||||
|
loader.setController(this);
|
||||||
|
this.node = (Node)loader.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateItem(ServerListItem item, boolean empty){
|
||||||
|
super.updateItem(item, empty);
|
||||||
|
if(empty){
|
||||||
|
setText("");
|
||||||
|
setGraphic(null);
|
||||||
|
}else if(item != null){
|
||||||
|
setText("");
|
||||||
|
ipLabel.setText(item.getIP());
|
||||||
|
setGraphic(node);
|
||||||
|
}else{
|
||||||
|
setText("NULL");
|
||||||
|
setGraphic(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
19
src/com/coder/client/gui/selectServer/ServerListItem.java
Normal file
19
src/com/coder/client/gui/selectServer/ServerListItem.java
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.coder.client.gui.selectServer;
|
||||||
|
|
||||||
|
class ServerListItem {
|
||||||
|
|
||||||
|
private String ip = null;
|
||||||
|
|
||||||
|
public ServerListItem(String ip){
|
||||||
|
this.ip = ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIP(){
|
||||||
|
return this.ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString(){
|
||||||
|
return "SERVER: ip="+ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue