2015-10-09 13:37:45 +00:00
|
|
|
package com.coder.client;
|
|
|
|
|
|
2015-10-13 08:13:23 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.Map;
|
2015-10-09 13:37:45 +00:00
|
|
|
import java.util.logging.Level;
|
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
2015-11-13 13:25:36 +01:00
|
|
|
import com.coder.client.gui.GuiWindow;
|
2015-10-20 14:26:58 +00:00
|
|
|
import com.coder.client.gui.editor.EditorWindow;
|
|
|
|
|
import com.coder.client.gui.login.LoginDialog;
|
2015-10-23 13:44:11 +00:00
|
|
|
import com.coder.client.gui.newProject.NewProjectDialog;
|
2015-10-20 15:52:23 +00:00
|
|
|
import com.coder.client.gui.selectProject.SelectProjectDialog;
|
|
|
|
|
import com.coder.client.gui.selectServer.SelectServerDialog;
|
2015-10-09 13:37:45 +00:00
|
|
|
|
2015-10-13 08:53:07 +00:00
|
|
|
import zutil.log.CompactLogFormatter;
|
2015-10-09 13:37:45 +00:00
|
|
|
import zutil.log.LogUtil;
|
2015-10-20 14:26:58 +00:00
|
|
|
import javafx.application.Application;
|
2015-10-21 16:13:45 +00:00
|
|
|
import javafx.application.Platform;
|
2015-11-13 13:25:36 +01:00
|
|
|
import javafx.scene.Scene;
|
2015-10-20 14:26:58 +00:00
|
|
|
import javafx.stage.Stage;
|
2015-10-09 13:37:45 +00:00
|
|
|
|
2015-10-20 14:26:58 +00:00
|
|
|
public class CoderClient extends Application{
|
2015-10-09 13:37:45 +00:00
|
|
|
public static final Logger logger = LogUtil.getLogger();
|
2015-11-13 13:25:36 +01:00
|
|
|
private SessionHandler sessionHandler;
|
|
|
|
|
private ProjectHandler projectHandler;
|
|
|
|
|
private SSDPHandler ssdpHandler;
|
2015-10-27 12:18:22 +01:00
|
|
|
|
2015-10-21 14:23:00 +00:00
|
|
|
//GUI elements
|
2015-11-13 13:25:36 +01:00
|
|
|
private Stage mainStage;
|
2015-10-20 14:26:58 +00:00
|
|
|
private EditorWindow editorWindow;
|
|
|
|
|
private LoginDialog loginDialog;
|
|
|
|
|
private SelectProjectDialog selectProjectDialog;
|
2015-10-20 15:52:23 +00:00
|
|
|
private SelectServerDialog selectServerDialog;
|
2015-10-23 13:44:11 +00:00
|
|
|
private NewProjectDialog newProjectDialog;
|
2015-10-27 12:18:22 +01:00
|
|
|
|
2015-10-20 14:26:58 +00:00
|
|
|
public static void main(String[] args) {
|
2015-10-27 12:18:22 +01:00
|
|
|
Application.launch(args);
|
|
|
|
|
}
|
2015-10-20 14:26:58 +00:00
|
|
|
|
|
|
|
|
@Override
|
2015-11-11 16:13:01 +01:00
|
|
|
public void start(final Stage mainStage) throws Exception {
|
2015-10-27 12:18:22 +01:00
|
|
|
|
2015-10-20 14:26:58 +00:00
|
|
|
//setup logging
|
2015-10-28 12:56:22 +01:00
|
|
|
CompactLogFormatter formatter = new CompactLogFormatter();
|
2015-10-29 12:52:11 +01:00
|
|
|
LogUtil.setLevel("com.coder", Level.FINEST);
|
2015-10-28 12:56:22 +01:00
|
|
|
LogUtil.setFormatter("com.coder", formatter);
|
2015-10-29 12:52:11 +01:00
|
|
|
LogUtil.setLevel("zutil", Level.FINEST);
|
|
|
|
|
LogUtil.setFormatter("zutil", formatter);
|
|
|
|
|
LogUtil.setGlobalFormatter(formatter);
|
2015-10-27 12:18:22 +01:00
|
|
|
|
2015-11-13 13:25:36 +01:00
|
|
|
//setup handlers
|
|
|
|
|
try{
|
|
|
|
|
this.sessionHandler = new SessionHandler();
|
|
|
|
|
this.projectHandler = new ProjectHandler();
|
|
|
|
|
this.ssdpHandler = new SSDPHandler();
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
logger.log(Level.SEVERE, "could not load all handlers", e);
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-27 12:18:22 +01:00
|
|
|
//setup GUI elements
|
2015-11-13 13:25:36 +01:00
|
|
|
this.mainStage = mainStage;
|
2015-10-27 12:18:22 +01:00
|
|
|
mainStage.setTitle("CoderClient");
|
|
|
|
|
try{
|
2015-11-11 16:13:01 +01:00
|
|
|
this.selectServerDialog = new SelectServerDialog(this);
|
|
|
|
|
this.loginDialog = new LoginDialog(this);
|
|
|
|
|
this.selectProjectDialog = new SelectProjectDialog(this);
|
|
|
|
|
this.newProjectDialog = new NewProjectDialog(this);
|
|
|
|
|
this.editorWindow = new EditorWindow(this);
|
2015-10-27 12:18:22 +01:00
|
|
|
}catch(IOException e){
|
|
|
|
|
logger.log(Level.SEVERE, "could not load all GUI elements", e);
|
2015-11-13 13:25:36 +01:00
|
|
|
exit();
|
2015-10-27 12:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
2015-10-20 14:26:58 +00:00
|
|
|
//parse program arguments
|
|
|
|
|
Map<String, String> params = this.getParameters().getNamed();
|
|
|
|
|
for(String key : params.keySet()){
|
|
|
|
|
String value = params.get(key);
|
|
|
|
|
if(key.equals("username")){
|
2015-10-27 12:18:22 +01:00
|
|
|
loginDialog.setUsername(value);
|
2015-10-20 15:52:23 +00:00
|
|
|
}else if(key.equals("url")){
|
2015-10-27 12:18:22 +01:00
|
|
|
selectServerDialog.setServerAddress(value);
|
2015-10-21 14:23:00 +00:00
|
|
|
}else if(key.equals("port")){
|
|
|
|
|
try{
|
2015-10-27 12:18:22 +01:00
|
|
|
selectServerDialog.setServerPort(Integer.parseInt(value));
|
2015-10-21 14:23:00 +00:00
|
|
|
}catch(NumberFormatException e){
|
2015-11-05 13:58:45 +01:00
|
|
|
logger.warning("port argument to program is not of a integer type");
|
|
|
|
|
selectServerDialog.setServerPort(-1);
|
2015-10-21 14:23:00 +00:00
|
|
|
}
|
2015-10-22 14:08:31 +00:00
|
|
|
}else if(key.equals("project")){
|
2015-11-11 16:13:01 +01:00
|
|
|
projectHandler.setProject(value);
|
2015-10-20 14:26:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
2015-10-27 12:18:22 +01:00
|
|
|
|
2015-11-11 16:13:01 +01:00
|
|
|
//start program logic
|
|
|
|
|
selectServerDialog.setServerPort(-1);
|
2015-11-13 13:25:36 +01:00
|
|
|
showOnStage(selectServerDialog);
|
2015-11-11 16:13:01 +01:00
|
|
|
|
2015-10-20 14:26:58 +00:00
|
|
|
}
|
2015-11-13 13:25:36 +01:00
|
|
|
|
|
|
|
|
public void showOnStage(final GuiWindow gui){
|
|
|
|
|
Platform.runLater(new Runnable(){
|
2015-10-22 14:08:31 +00:00
|
|
|
@Override
|
2015-11-13 13:25:36 +01:00
|
|
|
public void run() {
|
|
|
|
|
Scene scene = gui.getScene();
|
|
|
|
|
mainStage.setScene(scene);
|
|
|
|
|
mainStage.setTitle(gui.getTitle());
|
|
|
|
|
logger.fine("about to show " + gui.getDescriptiveName() + " on stage");
|
|
|
|
|
gui.willShow();
|
|
|
|
|
mainStage.show();
|
|
|
|
|
logger.fine("showing " + gui.getDescriptiveName());
|
2015-10-22 14:08:31 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-10-27 12:18:22 +01:00
|
|
|
|
2015-11-11 16:13:01 +01:00
|
|
|
public void exit() {
|
|
|
|
|
logger.info("terminating");
|
|
|
|
|
Platform.exit();
|
|
|
|
|
System.exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public SessionHandler getSessionHandler() {
|
|
|
|
|
return this.sessionHandler;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ProjectHandler getProjectHandler(){
|
|
|
|
|
return this.projectHandler;
|
2015-10-20 14:26:58 +00:00
|
|
|
}
|
2015-11-13 13:25:36 +01:00
|
|
|
|
|
|
|
|
public SSDPHandler getSSDPHandler(){
|
|
|
|
|
return this.ssdpHandler;
|
|
|
|
|
}
|
2015-10-09 13:37:45 +00:00
|
|
|
|
|
|
|
|
}
|