now using JavaFX instead of Swing
This commit is contained in:
parent
83e0196c50
commit
3177714fc5
22 changed files with 518 additions and 686 deletions
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry excluding="com/coder/client/gui/GUIManager.java|com/coder/client/Main.java" kind="src" path="src"/>
|
||||
<classpathentry excluding="com/coder/client/gui/GUIManager.java|com/coder/client/CoderClient2.java|com/coder/client/LoginDialog.java|com/coder/client/ProjectEditorWindow.java|com/coder/client/ProjectFileTreeModel.java|com/coder/client/LoginCridentials.java|com/coder/client/ProjectSelectDialog.java|com/coder/client/gui/GUI_TEST_MAIN.java" kind="src" path="src"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/ZUtil"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/CoderServer"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/java-8-openjdk-i386"/>
|
||||
|
|
|
|||
|
|
@ -7,6 +7,13 @@ import java.util.logging.Logger;
|
|||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import com.coder.client.Session;
|
||||
import com.coder.client.gui.editor.EditorWindow;
|
||||
import com.coder.client.gui.editor.EditorWindowListener;
|
||||
import com.coder.client.gui.login.LoginDialog;
|
||||
import com.coder.client.gui.login.LoginDialogAction;
|
||||
import com.coder.client.gui.project.SelectProjectDialog;
|
||||
import com.coder.client.gui.project.SelectProjectDialogListener;
|
||||
import com.coder.server.CoderServer;
|
||||
import com.coder.server.message.CoderMessage;
|
||||
import com.coder.server.message.ConfigData;
|
||||
|
|
@ -16,29 +23,124 @@ import com.coder.server.message.ProjectRspMsg;
|
|||
|
||||
import zutil.log.CompactLogFormatter;
|
||||
import zutil.log.LogUtil;
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class CoderClient extends Thread{
|
||||
public class CoderClient extends Application{
|
||||
public static final Logger logger = LogUtil.getLogger();
|
||||
private int port = CoderServer.SERVER_PORT;
|
||||
private static final int DEFAULT_CONNECTION_RETRIES = 5;
|
||||
|
||||
private String url;
|
||||
private int port;
|
||||
private Session session;
|
||||
private ProjectEditorWindow projectEditorWindow;
|
||||
private ProjectSelectDialog projectSelectDialog;
|
||||
private String url;
|
||||
private Stage mainStage;
|
||||
private String username = null;
|
||||
private char[] password = null;
|
||||
private int connectionRetriesLimit = DEFAULT_CONNECTION_RETRIES; //if zero, try forever
|
||||
private EditorWindow editorWindow;
|
||||
private LoginDialog loginDialog;
|
||||
private SelectProjectDialog selectProjectDialog;
|
||||
|
||||
public CoderClient(String url, int port) {
|
||||
this.url = url;
|
||||
this.port = port;
|
||||
public static void main(String[] args) {
|
||||
Application.launch(args);
|
||||
}
|
||||
|
||||
this.projectEditorWindow = new ProjectEditorWindow("CoderClient");
|
||||
this.projectSelectDialog = new ProjectSelectDialog(null);
|
||||
@Override
|
||||
public void start(Stage mainStage) throws Exception {
|
||||
|
||||
//setup logging
|
||||
LogUtil.setGlobalLevel(Level.INFO);
|
||||
LogUtil.setGlobalFormatter(new CompactLogFormatter());
|
||||
|
||||
//parse program arguments
|
||||
Map<String, String> params = this.getParameters().getNamed();
|
||||
String username = null;
|
||||
char[] password = null;
|
||||
boolean reconnectForever = false;
|
||||
for(String key : params.keySet()){
|
||||
String value = params.get(key);
|
||||
if(key.equals("username")){
|
||||
username = value;
|
||||
}else if(key.equals("password")){
|
||||
password = value.toCharArray();
|
||||
}else if(key.equals("retry-connect-forever")){
|
||||
reconnectForever = true;
|
||||
}
|
||||
}
|
||||
|
||||
//create a client instance
|
||||
this.url = "127.0.0.1";
|
||||
if(username != null){
|
||||
this.username = username;
|
||||
if(password != null){
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
if(reconnectForever){
|
||||
this.connectionRetriesLimit = 0;
|
||||
}
|
||||
|
||||
//loading GUI
|
||||
this.mainStage = mainStage;
|
||||
mainStage.setTitle("CoderClient");
|
||||
this.editorWindow = new EditorWindow();
|
||||
this.loginDialog = new LoginDialog();
|
||||
this.selectProjectDialog = new SelectProjectDialog();
|
||||
|
||||
//register listeners
|
||||
registerListeners();
|
||||
|
||||
//start program logic
|
||||
run();
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
|
||||
this.selectProjectDialog.addSelectProjectDialogListener(new SelectProjectDialogListener() {
|
||||
@Override
|
||||
public void willShow() {
|
||||
//clear current list of project
|
||||
selectProjectDialog.clearProjectList();
|
||||
|
||||
//send a request for a new list of projects
|
||||
CoderMessage msg = new CoderMessage();
|
||||
msg.ProjectListReq = new ProjectListReqMsg();
|
||||
try {
|
||||
session.send(msg);
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.SEVERE, "Unable to send ProjectListReqMsg", e);
|
||||
closeCurrentSession();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void openProject(String selectedProjectName) {
|
||||
selectProjectDialog.close();
|
||||
editorWindow.showOnStage(mainStage);
|
||||
}
|
||||
@Override
|
||||
public void newProject() {
|
||||
selectProjectDialog.close();
|
||||
//TODO
|
||||
}
|
||||
@Override
|
||||
public void cancel() {
|
||||
selectProjectDialog.close();
|
||||
}
|
||||
});
|
||||
|
||||
this.editorWindow.addMessageSentListener(new EditorWindowListener() {
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void closeCurrentSession(){
|
||||
if(this.session != null){
|
||||
session.close();
|
||||
session = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void run(){
|
||||
|
|
@ -80,10 +182,9 @@ public class CoderClient extends Thread{
|
|||
}else{
|
||||
//ask for username and password in a dialog window
|
||||
logger.info("All or some login credentials have not been given. Using a dialog for input.");
|
||||
LoginDialog loginDialog = new LoginDialog(username, null);
|
||||
loginDialog.setVisible(true); //blocking
|
||||
loginDialog.dispose();
|
||||
if(loginDialog.getAction() == LoginDialog.LoginDialogAction.CANCEL){
|
||||
loginDialog.setUsername(username);
|
||||
loginDialog.showModal(this.mainStage);
|
||||
if(loginDialog.getAction() == LoginDialogAction.CANCEL){
|
||||
logger.fine("Login dialog closed or canceled by the user. terminating.");
|
||||
break;
|
||||
}
|
||||
|
|
@ -100,19 +201,13 @@ public class CoderClient extends Thread{
|
|||
continue;
|
||||
}
|
||||
|
||||
//forget the password
|
||||
for(int i = 0; i < password.length; ++i){
|
||||
password[i] = '*';
|
||||
}
|
||||
password = null;
|
||||
|
||||
//resister a message listener to the session
|
||||
session.addCoderMessageReceivedListener(new CoderMessageReceivedListener() {
|
||||
@Override
|
||||
public void projectListRspReceived(Map<String, ProjectListData> projectListRsp) {
|
||||
for(String projectName : projectListRsp.keySet()){
|
||||
ProjectListData projectData = projectListRsp.get(projectName);
|
||||
projectSelectDialog.addProjectToList(projectName, projectData.type);
|
||||
selectProjectDialog.addProjectToList(projectName, projectData.type);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
|
|
@ -128,136 +223,24 @@ public class CoderClient extends Thread{
|
|||
//start receiving traffic from the server
|
||||
session.start();
|
||||
|
||||
//clear the current local project list
|
||||
this.projectSelectDialog.clearProjectList();
|
||||
|
||||
//request a new project list from the server
|
||||
CoderMessage msg = new CoderMessage();
|
||||
msg.ProjectListReq = new ProjectListReqMsg();
|
||||
try {
|
||||
session.send(msg);
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.SEVERE, "Unable to send ProjectListReqMsg", e);
|
||||
continue;
|
||||
}
|
||||
|
||||
//show the project selector dialog
|
||||
this.projectSelectDialog.setVisible(true); //blocking
|
||||
if(this.projectSelectDialog.getAction() == ProjectSelectDialog.ProjectSelectDialogAction.CANCEL){
|
||||
logger.fine("Project select dialog closed or canceled by the user. terminating.");
|
||||
break;
|
||||
}
|
||||
String selectedProjectName = this.projectSelectDialog.getSelecteProjectName();
|
||||
logger.info("Project \"" +selectedProjectName+ "\" was selected.");
|
||||
|
||||
//add a listener to forward messages from the editor GUI to the server
|
||||
this.projectEditorWindow.addMessageSentListener(new GUIMessageSentListener(){
|
||||
@Override
|
||||
public void sendMessage(CoderMessage msg) {
|
||||
try {
|
||||
session.send(msg);
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.SEVERE, "could not forward message from editor to the server", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//show the user the editor GUI
|
||||
this.projectEditorWindow.setVisible(true);
|
||||
try {Thread.sleep(1000);} catch (InterruptedException e) {}
|
||||
this.selectProjectDialog.showModal(mainStage);
|
||||
|
||||
//wait here until the session is closed for some reason
|
||||
|
||||
while(session.isConnected()){
|
||||
Thread.yield();
|
||||
}
|
||||
|
||||
//hide the main GUI
|
||||
logger.fine("The socket was closed.");
|
||||
this.projectEditorWindow.setVisible(false);
|
||||
mainStage.close();
|
||||
Thread.yield();
|
||||
}
|
||||
logger.info("The program till now terminate");
|
||||
closeCurrentSession();
|
||||
this.projectEditorWindow.dispose();
|
||||
// this.projectEditorWindow.dispose();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
private void closeCurrentSession(){
|
||||
if(this.session != null){
|
||||
session.close();
|
||||
session = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setPassword(char[] password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public void setRetryConnectForever(boolean tryForever) {
|
||||
if(tryForever){
|
||||
this.connectionRetriesLimit = 0;
|
||||
}else{
|
||||
this.connectionRetriesLimit = DEFAULT_CONNECTION_RETRIES;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
int port = CoderServer.SERVER_PORT;
|
||||
String username = null;
|
||||
char[] password = null;
|
||||
boolean reconnectForever = false;
|
||||
|
||||
//parse program arguments
|
||||
for(int i = 0; i < args.length; ++i){
|
||||
String arg = args[i];
|
||||
if(arg.equals("-h") || arg.equals("--help")){
|
||||
System.out.println("Usage: CoderClient [options]");
|
||||
System.out.println("Options:");
|
||||
System.out.println("-h|--help Print this help.");
|
||||
System.out.println("-u|--username <username> Set the username to use when authenticating.");
|
||||
System.out.println("-p|--password <password> Set the password used when authenticating. The password will not be safetly");
|
||||
System.out.println(" stored and ths option should not be used in anything but debuging.");
|
||||
System.out.println(" A password cannot be defined without a username. If booth");
|
||||
System.out.println(" a username and a password has been defined by arguments the software will not.");
|
||||
System.out.println(" prompt for this.");
|
||||
System.out.println(" If not a port have been defined, the deafult port will be used.");
|
||||
System.out.println("--retry-connect-forever Make the software never stop trying to reconnect to its peer.");
|
||||
System.exit(0);
|
||||
}else if(arg.equals("-u") || arg.equals("--username")){
|
||||
i++;
|
||||
if(i < args.length){
|
||||
username = args[i];
|
||||
}else{
|
||||
System.err.println("missing username argument");
|
||||
System.exit(1);
|
||||
}
|
||||
}else if(arg.equals("-p") || arg.equals("--password")){
|
||||
i++;
|
||||
if(i < args.length){
|
||||
password = args[i].toCharArray();
|
||||
}else{
|
||||
System.err.println("missing password argument");
|
||||
System.exit(1);
|
||||
}
|
||||
}else if(arg.equals("--retry-connect-forever")){
|
||||
reconnectForever = true;
|
||||
}
|
||||
}
|
||||
|
||||
//create a client instance
|
||||
CoderClient client = new CoderClient("127.0.0.1", port);
|
||||
if(username != null){
|
||||
client.setUsername(username);
|
||||
if(password != null){
|
||||
client.setPassword(password);
|
||||
}
|
||||
}
|
||||
client.setRetryConnectForever(reconnectForever);
|
||||
client.start();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
package com.coder.client;
|
||||
|
||||
import com.coder.server.message.CoderMessage;
|
||||
|
||||
public interface GUIMessageSentListener {
|
||||
|
||||
void sendMessage(CoderMessage msg);
|
||||
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
package com.coder.client;
|
||||
|
||||
public class LoginCridentials {
|
||||
|
||||
private String username;
|
||||
private char[] password;
|
||||
|
||||
public LoginCridentials(String username, char[] password){
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getUsername(){
|
||||
return this.username;
|
||||
}
|
||||
|
||||
public char[] getPassword(){
|
||||
return this.password;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,161 +0,0 @@
|
|||
package com.coder.client;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPasswordField;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
||||
public class LoginDialog extends JDialog {
|
||||
private static final long serialVersionUID = 9196349269499229433L;
|
||||
public static enum LoginDialogAction{
|
||||
LOGIN,
|
||||
CANCEL
|
||||
}
|
||||
private LoginDialogAction loginAction = LoginDialogAction.CANCEL;
|
||||
private JTextField usernameTextField;
|
||||
private JPasswordField passwordPasswordField;
|
||||
private JButton loginButton;
|
||||
private JButton cancelButton;
|
||||
|
||||
public LoginDialog(String username, Frame parent) {
|
||||
super(parent, "Login", true);
|
||||
|
||||
JPanel fieldPanel = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints gridBagConstraints = new GridBagConstraints();
|
||||
|
||||
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||||
|
||||
JLabel usernameLabel = new JLabel("Username: ");
|
||||
gridBagConstraints.gridx = 0;
|
||||
gridBagConstraints.gridy = 0;
|
||||
gridBagConstraints.gridwidth = 1;
|
||||
fieldPanel.add(usernameLabel, gridBagConstraints);
|
||||
|
||||
usernameTextField = new JTextField(20);
|
||||
usernameTextField.setText(username);
|
||||
gridBagConstraints.gridx = 1;
|
||||
gridBagConstraints.gridy = 0;
|
||||
gridBagConstraints.gridwidth = 2;
|
||||
fieldPanel.add(usernameTextField, gridBagConstraints);
|
||||
|
||||
JLabel passwordLabel = new JLabel("Password: ");
|
||||
gridBagConstraints.gridx = 0;
|
||||
gridBagConstraints.gridy = 1;
|
||||
gridBagConstraints.gridwidth = 1;
|
||||
fieldPanel.add(passwordLabel, gridBagConstraints);
|
||||
|
||||
passwordPasswordField = new JPasswordField(20);
|
||||
gridBagConstraints.gridx = 1;
|
||||
gridBagConstraints.gridy = 1;
|
||||
gridBagConstraints.gridwidth = 2;
|
||||
fieldPanel.add(passwordPasswordField, gridBagConstraints);
|
||||
fieldPanel.setBorder(new LineBorder(Color.GRAY));
|
||||
|
||||
loginButton = new JButton("Login");
|
||||
|
||||
cancelButton = new JButton("Cancel");
|
||||
|
||||
JPanel buttonPanel = new JPanel();
|
||||
buttonPanel.add(loginButton);
|
||||
buttonPanel.add(cancelButton);
|
||||
|
||||
getContentPane().add(fieldPanel, BorderLayout.CENTER);
|
||||
getContentPane().add(buttonPanel, BorderLayout.PAGE_END);
|
||||
|
||||
|
||||
loginButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
loginAction = LoginDialogAction.LOGIN;
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
loginAction = LoginDialogAction.CANCEL;
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
usernameTextField.addKeyListener(new KeyListener(){
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if(e.getKeyCode() == KeyEvent.VK_ENTER){
|
||||
loginButton.doClick();
|
||||
}else if(e.getKeyCode() == KeyEvent.VK_ESCAPE){
|
||||
cancelButton.doClick();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
passwordPasswordField.addKeyListener(new KeyListener(){
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if(e.getKeyCode() == KeyEvent.VK_ENTER){
|
||||
loginButton.doClick();
|
||||
}else if(e.getKeyCode() == KeyEvent.VK_ESCAPE){
|
||||
cancelButton.doClick();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
//pack the dialog
|
||||
pack();
|
||||
|
||||
//move focus to the password field if already a username has been defined. must be done after pack()
|
||||
if(username != null && username.isEmpty() == false){
|
||||
passwordPasswordField.requestFocusInWindow();
|
||||
}
|
||||
|
||||
setResizable(false);
|
||||
setLocationRelativeTo(parent);
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return usernameTextField.getText().trim();
|
||||
}
|
||||
|
||||
public char[] getPassword() {
|
||||
return passwordPasswordField.getPassword();
|
||||
}
|
||||
|
||||
public LoginDialogAction getAction() {
|
||||
return this.loginAction;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
package com.coder.client;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.coder.client.gui.EditorWindowController;
|
||||
import com.coder.client.gui.GUIManager;
|
||||
import com.coder.server.CoderServer;
|
||||
|
||||
import zutil.log.LogUtil;
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class Main extends Application {
|
||||
public static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
public static void main(String[] args) {
|
||||
Application.launch(Main.class, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage mainStage) throws Exception {
|
||||
|
||||
//parse program arguments
|
||||
Map<String, String> params = this.getParameters().getNamed();
|
||||
String username = null;
|
||||
char[] password = null;
|
||||
boolean reconnectForever = false;
|
||||
for(String key : params.keySet()){
|
||||
String value = params.get(key);
|
||||
if(key.equals("username")){
|
||||
username = value;
|
||||
}else if(key.equals("password")){
|
||||
password = value.toCharArray();
|
||||
}else if(key.equals("retry-connect-forever")){
|
||||
reconnectForever = true;
|
||||
}
|
||||
}
|
||||
|
||||
//load FXML resources
|
||||
GUIManager guiManager = new GUIManager(mainStage);
|
||||
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/com/coder/client/gui/EditorWindowGUI.fxml"));
|
||||
Scene scene = new Scene((Parent)loader.load());
|
||||
EditorWindowController editorController = loader.<EditorWindowController>getController();
|
||||
editorController.setScene(scene);
|
||||
guiManager.setEditWindow(editorController);
|
||||
|
||||
|
||||
mainStage.setTitle("CoderClient");
|
||||
|
||||
//create a client instance
|
||||
int port = CoderServer.SERVER_PORT;
|
||||
CoderClient client = new CoderClient("127.0.0.1", port, guiManager);
|
||||
if(username != null){
|
||||
client.setUsername(username);
|
||||
if(password != null){
|
||||
client.setPassword(password);
|
||||
}
|
||||
}
|
||||
client.setRetryConnectForever(reconnectForever);
|
||||
client.start();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,106 +0,0 @@
|
|||
package com.coder.client;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.util.HashSet;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.event.TreeSelectionEvent;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreeSelectionModel;
|
||||
|
||||
import com.coder.server.message.CoderMessage;
|
||||
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
public class ProjectEditorWindow extends JFrame implements TreeSelectionListener {
|
||||
private static final long serialVersionUID = -5486192344225335322L;
|
||||
public static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
private JTree fileTree;
|
||||
private ProjectFileTreeModel fileTreeModel;
|
||||
private JTextArea codingArea;
|
||||
private JButton compileButton;
|
||||
private JButton runButton;
|
||||
private HashSet<GUIMessageSentListener> GUIMessageSentListeners = new HashSet<GUIMessageSentListener>();
|
||||
|
||||
public ProjectEditorWindow(String title){
|
||||
super(title);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
Dimension minimumSize = new Dimension(500,300);
|
||||
this.setMinimumSize(minimumSize);
|
||||
|
||||
//left panel containing a file tree
|
||||
this.fileTreeModel = new ProjectFileTreeModel();
|
||||
this.fileTree = new JTree(fileTreeModel);
|
||||
fileTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
||||
fileTree.addTreeSelectionListener(this);
|
||||
|
||||
//test pane
|
||||
this.codingArea = new JTextArea();
|
||||
JScrollPane textScrolPane = new JScrollPane(codingArea);
|
||||
codingArea.setEditable(false);
|
||||
|
||||
//right top pane
|
||||
JPanel rightTopPanel = new JPanel();
|
||||
|
||||
//right bottom pane
|
||||
JPanel rightBottomPanel = new JPanel();
|
||||
this.compileButton = new JButton("Compile");
|
||||
compileButton.setEnabled(false);
|
||||
rightBottomPanel.add(compileButton);
|
||||
this.runButton = new JButton("Run");
|
||||
runButton.setEnabled(false);
|
||||
rightBottomPanel.add(runButton);
|
||||
|
||||
//split panes
|
||||
JSplitPane rightVerticalSpitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, rightTopPanel, rightBottomPanel);
|
||||
rightVerticalSpitPane.setResizeWeight(1.0);
|
||||
rightVerticalSpitPane.setEnabled(false);
|
||||
JSplitPane rightHorizontalSpitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, textScrolPane, rightVerticalSpitPane);
|
||||
rightHorizontalSpitPane.setResizeWeight(1.0);
|
||||
JSplitPane leftHorizontalSpitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, fileTree, rightHorizontalSpitPane);
|
||||
leftHorizontalSpitPane.setResizeWeight(0.0);
|
||||
this.add(leftHorizontalSpitPane);
|
||||
|
||||
//pack the window
|
||||
this.pack();
|
||||
}
|
||||
|
||||
//TreeSelectionListener interface impl.
|
||||
@Override
|
||||
public void valueChanged(TreeSelectionEvent event) {
|
||||
DefaultMutableTreeNode node = (DefaultMutableTreeNode)fileTree.getLastSelectedPathComponent();
|
||||
if(node == null)
|
||||
return;
|
||||
Object nodeInfo = node.getUserObject();
|
||||
if(node.isLeaf()){
|
||||
logger.fine("A file has been selected in the file tree");
|
||||
}else{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void addMessageSentListener(GUIMessageSentListener listener) {
|
||||
this.GUIMessageSentListeners.add(listener);
|
||||
}
|
||||
|
||||
private void sendMessage(CoderMessage msg){
|
||||
for(GUIMessageSentListener listener : GUIMessageSentListeners){
|
||||
listener.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void setProjectName(String projectName) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
package com.coder.client;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import javax.swing.event.TreeModelListener;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreeModel;
|
||||
import javax.swing.tree.TreePath;
|
||||
|
||||
public class ProjectFileTreeModel implements TreeModel {
|
||||
|
||||
private HashSet<TreeModelListener> treeModelListeners;
|
||||
|
||||
public ProjectFileTreeModel(){
|
||||
treeModelListeners = new HashSet<TreeModelListener>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTreeModelListener(TreeModelListener listener) {
|
||||
this.treeModelListeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getChild(Object arg0, int arg1) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChildCount(Object arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndexOfChild(Object arg0, Object arg1) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRoot() {
|
||||
return new DefaultMutableTreeNode("[Project Name]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaf(Object arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeTreeModelListener(TreeModelListener listener) {
|
||||
this.treeModelListeners.remove(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void valueForPathChanged(TreePath arg0, Object arg1) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
package com.coder.client;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPasswordField;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
||||
public class ProjectSelectDialog extends JDialog {
|
||||
private static final long serialVersionUID = 3664648491769811261L;
|
||||
|
||||
public static enum ProjectSelectDialogAction{
|
||||
PROJECT_SELECTED,
|
||||
CANCEL
|
||||
}
|
||||
private ProjectSelectDialogAction action = ProjectSelectDialogAction.CANCEL;
|
||||
|
||||
public ProjectSelectDialog(Frame parent) {
|
||||
super(parent, "Select Project", true);
|
||||
|
||||
//TODO
|
||||
|
||||
//pack the dialog
|
||||
pack();
|
||||
|
||||
setLocationRelativeTo(parent);
|
||||
}
|
||||
|
||||
public String getSelecteProjectName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ProjectSelectDialogAction getAction() {
|
||||
return this.action;
|
||||
}
|
||||
|
||||
public void clearProjectList() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void addProjectToList(String projectName, String type) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -98,9 +98,13 @@ public class Session extends Thread {
|
|||
return;
|
||||
}
|
||||
|
||||
public void send(CoderMessage msg) throws IOException{
|
||||
out.writeObject(msg);
|
||||
out.flush();
|
||||
public boolean send(CoderMessage msg) throws IOException{
|
||||
if(out != null){
|
||||
out.writeObject(msg);
|
||||
out.flush();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addCoderMessageReceivedListener(CoderMessageReceivedListener listener){
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
package com.coder.client.gui;
|
||||
|
||||
public class Controller {
|
||||
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
package com.coder.client.gui;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class EditorWindow extends Application {
|
||||
|
||||
public EditorWindow(){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws Exception {
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("EditorWindowGUI.fxml"));
|
||||
|
||||
EditorWindowController editorController = loader.<EditorWindowController>getController();
|
||||
|
||||
Scene editorScene = new Scene((Parent)loader.load());
|
||||
|
||||
stage.setTitle("CoderClient");
|
||||
stage.setScene(editorScene);
|
||||
stage.show();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Application.launch(EditorWindow.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
74
src/com/coder/client/gui/GuiWindow.java
Normal file
74
src/com/coder/client/gui/GuiWindow.java
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
package com.coder.client.gui;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public abstract class GuiWindow implements Initializable{
|
||||
|
||||
private Scene scene;
|
||||
private Stage stage;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param fxmlFile The .fxml file to load for this GUI element
|
||||
* @throws IOException If unable to find or load the file
|
||||
*/
|
||||
public GuiWindow(URL fxmlFile) throws IOException{
|
||||
FXMLLoader loader = new FXMLLoader(fxmlFile);
|
||||
loader.setController(this);
|
||||
scene = new Scene((Parent)loader.load());
|
||||
}
|
||||
|
||||
/**
|
||||
* show on the given stage
|
||||
* @param stage The stage to show on
|
||||
*/
|
||||
public void showOnStage(Stage stage){
|
||||
stage.setScene(scene);
|
||||
this.stage = stage;
|
||||
willShow();
|
||||
stage.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* show a modal dialog
|
||||
* @param parent The dialogs parent
|
||||
*/
|
||||
public void showModal(Stage parent){
|
||||
Stage modalStage = new Stage();
|
||||
modalStage.initModality(Modality.WINDOW_MODAL);
|
||||
modalStage.initOwner(parent);
|
||||
modalStage.setScene(scene);
|
||||
this.stage = modalStage;
|
||||
willShow();
|
||||
modalStage.showAndWait();
|
||||
}
|
||||
|
||||
/**
|
||||
* hide the stage
|
||||
*/
|
||||
public void close(){
|
||||
if(stage != null){
|
||||
stage.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called every time before showed on stage
|
||||
*/
|
||||
protected abstract void willShow();
|
||||
|
||||
/**
|
||||
* Will be called once when created
|
||||
*/
|
||||
public abstract void initialize(URL fxmlFileLocation, ResourceBundle resources);
|
||||
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<SplitPane dividerPositions="0.26588628762541805, 0.7391304347826086" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.coder.client.gui.EditorWindowController">
|
||||
<SplitPane dividerPositions="0.26588628762541805, 0.7391304347826086" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<items>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" SplitPane.resizableWithParent="false">
|
||||
<children>
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.coder.client.gui;
|
||||
package com.coder.client.gui.editor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
|
@ -8,7 +9,7 @@ import java.util.ResourceBundle;
|
|||
import org.controlsfx.control.PropertySheet;
|
||||
import org.controlsfx.property.editor.PropertyEditor;
|
||||
|
||||
import com.coder.client.GUIMessageSentListener;
|
||||
import com.coder.client.gui.GuiWindow;
|
||||
import com.coder.client.property.CheckBoxProperty;
|
||||
import com.coder.client.property.CoderClientProperty;
|
||||
import com.coder.client.property.ComboBoxProperty;
|
||||
|
|
@ -19,16 +20,16 @@ import javafx.beans.value.ChangeListener;
|
|||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.control.TreeItem;
|
||||
import javafx.scene.control.TreeView;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.util.Callback;
|
||||
|
||||
public class EditorWindowController extends Controller implements Initializable {
|
||||
public class EditorWindow extends GuiWindow {
|
||||
|
||||
private HashSet<GUIMessageSentListener> GUIMessageSentListeners = new HashSet<GUIMessageSentListener>();
|
||||
private HashSet<EditorWindowListener> listsners = new HashSet<EditorWindowListener>();
|
||||
|
||||
@FXML private TreeView<String> fileTreeView;
|
||||
@FXML private TextArea editTextArea;
|
||||
|
|
@ -36,15 +37,18 @@ public class EditorWindowController extends Controller implements Initializable
|
|||
@FXML private Button compileButton;
|
||||
@FXML private Button runButton;
|
||||
|
||||
public EditorWindowController(){
|
||||
super();
|
||||
public EditorWindow() throws IOException{
|
||||
super(EditorWindow.class.getResource("EditorWindow.fxml"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
|
||||
|
||||
setupPropertySheet();
|
||||
setupFileTreeView();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void willShow(){
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -100,14 +104,8 @@ public class EditorWindowController extends Controller implements Initializable
|
|||
propertySheet.getItems().add(p2);
|
||||
}
|
||||
|
||||
public void addMessageSentListener(GUIMessageSentListener listener) {
|
||||
this.GUIMessageSentListeners.add(listener);
|
||||
}
|
||||
|
||||
private void sendMessage(CoderMessage msg){
|
||||
for(GUIMessageSentListener listener : GUIMessageSentListeners){
|
||||
listener.sendMessage(msg);
|
||||
}
|
||||
public void addMessageSentListener(EditorWindowListener listener) {
|
||||
this.listsners.add(listener);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package com.coder.client.gui.editor;
|
||||
|
||||
public interface EditorWindowListener {
|
||||
|
||||
}
|
||||
42
src/com/coder/client/gui/login/LoginDialog.fxml
Normal file
42
src/com/coder/client/gui/login/LoginDialog.fxml
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import java.lang.*?>
|
||||
<?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>
|
||||
<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>
|
||||
<Label text="username" />
|
||||
<TextField fx:id="usernameTextField" onKeyPressed="#keyPressed" prefHeight="25.0" prefWidth="291.0" GridPane.columnIndex="1" />
|
||||
<Label text="password" GridPane.rowIndex="1" />
|
||||
<PasswordField fx:id="passwordPasswordField" onKeyPressed="#keyPressed" prefHeight="25.0" prefWidth="291.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
||||
<HBox alignment="CENTER_RIGHT" prefHeight="69.0" prefWidth="218.0" GridPane.columnIndex="1" GridPane.rowIndex="2">
|
||||
<children>
|
||||
<Button fx:id="loginButton" mnemonicParsing="false" onAction="#login" text="Login">
|
||||
<HBox.margin>
|
||||
<Insets right="10.0" />
|
||||
</HBox.margin>
|
||||
</Button>
|
||||
<Button fx:id="cancelButton" mnemonicParsing="false" onAction="#cancel" text="Cancel">
|
||||
<HBox.margin>
|
||||
<Insets />
|
||||
</HBox.margin>
|
||||
</Button>
|
||||
</children>
|
||||
</HBox>
|
||||
</children>
|
||||
<padding>
|
||||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
||||
</padding>
|
||||
</GridPane>
|
||||
87
src/com/coder/client/gui/login/LoginDialog.java
Normal file
87
src/com/coder/client/gui/login/LoginDialog.java
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
package com.coder.client.gui.login;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.PasswordField;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
|
||||
import com.coder.client.gui.GuiWindow;
|
||||
|
||||
public class LoginDialog extends GuiWindow {
|
||||
public static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
@FXML private TextField usernameTextField;
|
||||
@FXML private PasswordField passwordPasswordField;
|
||||
@FXML private Button cancelButton;
|
||||
@FXML private Button loginButton;
|
||||
private LoginDialogAction action;
|
||||
|
||||
public LoginDialog() throws IOException {
|
||||
super(LoginDialog.class.getResource("LoginDialog.fxml"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void willShow(){
|
||||
action = LoginDialogAction.CANCEL;
|
||||
passwordPasswordField.setText("");
|
||||
if(!usernameTextField.getText().isEmpty()){
|
||||
passwordPasswordField.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void keyPressed(KeyEvent event) {
|
||||
if(event.getCode() == KeyCode.ENTER){
|
||||
logger.fine("User pressed the ENTER key");
|
||||
loginButton.fire();
|
||||
}else if(event.getCode() == KeyCode.ESCAPE){
|
||||
logger.fine("User pressed the ESCAPE key");
|
||||
cancelButton.fire();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void login(ActionEvent event){
|
||||
action = LoginDialogAction.LOGIN;
|
||||
this.close();
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void cancel(ActionEvent event){
|
||||
action = LoginDialogAction.CANCEL;
|
||||
this.close();
|
||||
}
|
||||
|
||||
public LoginDialogAction getAction(){
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setUsername(String username){
|
||||
usernameTextField.setText(username);
|
||||
}
|
||||
|
||||
public String getUsername(){
|
||||
return usernameTextField.getText();
|
||||
}
|
||||
|
||||
public char[] getPassword(){
|
||||
//TODO: fix this since is not safe since the password will be in a string
|
||||
return passwordPasswordField.getText().toCharArray();
|
||||
}
|
||||
|
||||
}
|
||||
6
src/com/coder/client/gui/login/LoginDialogAction.java
Normal file
6
src/com/coder/client/gui/login/LoginDialogAction.java
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
package com.coder.client.gui.login;
|
||||
|
||||
public enum LoginDialogAction {
|
||||
LOGIN,
|
||||
CANCEL
|
||||
}
|
||||
51
src/com/coder/client/gui/project/SelectProjectDialog.fxml
Normal file
51
src/com/coder/client/gui/project/SelectProjectDialog.fxml
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import java.lang.*?>
|
||||
<?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">
|
||||
<children>
|
||||
<ScrollPane fitToHeight="true" fitToWidth="true" hbarPolicy="NEVER">
|
||||
<content>
|
||||
<ListView fx:id="projectListView" prefHeight="200.0" prefWidth="200.0" />
|
||||
</content>
|
||||
</ScrollPane>
|
||||
<GridPane prefHeight="77.0" prefWidth="396.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<HBox alignment="CENTER_RIGHT" prefHeight="100.0" prefWidth="200.0" GridPane.columnIndex="1">
|
||||
<children>
|
||||
<Button fx:id="cancelButton" mnemonicParsing="false" onAction="#cancel" text="Cancel">
|
||||
<HBox.margin>
|
||||
<Insets right="10.0" />
|
||||
</HBox.margin>
|
||||
</Button>
|
||||
<Button fx:id="openProjectButton" mnemonicParsing="false" onAction="#openProject" text="Open Project">
|
||||
<HBox.margin>
|
||||
<Insets right="10.0" />
|
||||
</HBox.margin>
|
||||
</Button>
|
||||
</children>
|
||||
</HBox>
|
||||
<HBox alignment="CENTER_LEFT" prefHeight="100.0" prefWidth="200.0">
|
||||
<children>
|
||||
<Button fx:id="newProjectButton" mnemonicParsing="false" onAction="#newProject" text="New Project">
|
||||
<HBox.margin>
|
||||
<Insets left="10.0" />
|
||||
</HBox.margin>
|
||||
</Button>
|
||||
</children>
|
||||
</HBox>
|
||||
</children>
|
||||
</GridPane>
|
||||
</children>
|
||||
</VBox>
|
||||
95
src/com/coder/client/gui/project/SelectProjectDialog.java
Normal file
95
src/com/coder/client/gui/project/SelectProjectDialog.java
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
package com.coder.client.gui.project;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.HashSet;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
|
||||
import com.coder.client.gui.GuiWindow;
|
||||
|
||||
public class SelectProjectDialog extends GuiWindow {
|
||||
public static final Logger logger = LogUtil.getLogger();
|
||||
private HashSet<SelectProjectDialogListener> listeners;
|
||||
|
||||
@FXML private ListView projectListView;
|
||||
@FXML private Button newProjectButton;
|
||||
@FXML private Button cancelButton;
|
||||
@FXML private Button openProjectButton;
|
||||
|
||||
public SelectProjectDialog() throws IOException {
|
||||
super(SelectProjectDialog.class.getResource("SelectProjectDialog.fxml"));
|
||||
listeners = new HashSet<SelectProjectDialogListener>();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void willShow() {
|
||||
for(SelectProjectDialogListener listener : this.listeners){
|
||||
listener.willShow();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void keyPressed(KeyEvent event) {
|
||||
if(event.getCode() == KeyCode.ENTER){
|
||||
logger.fine("User pressed the ENTER key");
|
||||
openProjectButton.fire();
|
||||
}else if(event.getCode() == KeyCode.ESCAPE){
|
||||
logger.fine("User pressed the ESCAPE key");
|
||||
cancelButton.fire();
|
||||
}else if(event.getCode() == KeyCode.N && event.isControlDown()){ //CTRL+N
|
||||
logger.fine("User pressed CTRL+N");
|
||||
newProjectButton.fire();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void newProject(ActionEvent event){
|
||||
for(SelectProjectDialogListener listener : this.listeners){
|
||||
listener.newProject();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void cancel(ActionEvent event){
|
||||
for(SelectProjectDialogListener listener : this.listeners){
|
||||
listener.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void openProject(ActionEvent event){
|
||||
for(SelectProjectDialogListener listener : this.listeners){
|
||||
//TODO: get selected project in the list view
|
||||
String selectedProjectName = "project name";
|
||||
listener.openProject(selectedProjectName);
|
||||
}
|
||||
}
|
||||
|
||||
public void addSelectProjectDialogListener(SelectProjectDialogListener listener){
|
||||
this.listeners.add(listener);
|
||||
}
|
||||
|
||||
public void clearProjectList(){
|
||||
//TODO
|
||||
}
|
||||
|
||||
public void addProjectToList(String name, String type){
|
||||
//TODO
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.coder.client.gui.project;
|
||||
|
||||
public interface SelectProjectDialogListener {
|
||||
|
||||
void newProject();
|
||||
|
||||
void cancel();
|
||||
|
||||
void openProject(String selectedProjectName);
|
||||
|
||||
void willShow();
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue