-Adding a handler for SSDP -CoderClient giving control to each controller to be able to show itself on the main stage
135 lines
3.7 KiB
Java
Executable file
135 lines
3.7 KiB
Java
Executable file
package com.coder.client;
|
|
|
|
import java.io.IOException;
|
|
import java.util.Map;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
|
|
import com.coder.client.gui.GuiWindow;
|
|
import com.coder.client.gui.editor.EditorWindow;
|
|
import com.coder.client.gui.login.LoginDialog;
|
|
import com.coder.client.gui.newProject.NewProjectDialog;
|
|
import com.coder.client.gui.selectProject.SelectProjectDialog;
|
|
import com.coder.client.gui.selectServer.SelectServerDialog;
|
|
|
|
import zutil.log.CompactLogFormatter;
|
|
import zutil.log.LogUtil;
|
|
import javafx.application.Application;
|
|
import javafx.application.Platform;
|
|
import javafx.scene.Scene;
|
|
import javafx.stage.Stage;
|
|
|
|
public class CoderClient extends Application{
|
|
public static final Logger logger = LogUtil.getLogger();
|
|
private SessionHandler sessionHandler;
|
|
private ProjectHandler projectHandler;
|
|
private SSDPHandler ssdpHandler;
|
|
|
|
//GUI elements
|
|
private Stage mainStage;
|
|
private EditorWindow editorWindow;
|
|
private LoginDialog loginDialog;
|
|
private SelectProjectDialog selectProjectDialog;
|
|
private SelectServerDialog selectServerDialog;
|
|
private NewProjectDialog newProjectDialog;
|
|
|
|
public static void main(String[] args) {
|
|
Application.launch(args);
|
|
}
|
|
|
|
@Override
|
|
public void start(final Stage mainStage) throws Exception {
|
|
|
|
//setup logging
|
|
CompactLogFormatter formatter = new CompactLogFormatter();
|
|
LogUtil.setLevel("com.coder", Level.FINEST);
|
|
LogUtil.setFormatter("com.coder", formatter);
|
|
LogUtil.setLevel("zutil", Level.FINEST);
|
|
LogUtil.setFormatter("zutil", formatter);
|
|
LogUtil.setGlobalFormatter(formatter);
|
|
|
|
//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();
|
|
}
|
|
|
|
//setup GUI elements
|
|
this.mainStage = mainStage;
|
|
mainStage.setTitle("CoderClient");
|
|
try{
|
|
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);
|
|
}catch(IOException e){
|
|
logger.log(Level.SEVERE, "could not load all GUI elements", e);
|
|
exit();
|
|
}
|
|
|
|
//parse program arguments
|
|
Map<String, String> params = this.getParameters().getNamed();
|
|
for(String key : params.keySet()){
|
|
String value = params.get(key);
|
|
if(key.equals("username")){
|
|
loginDialog.setUsername(value);
|
|
}else if(key.equals("url")){
|
|
selectServerDialog.setServerAddress(value);
|
|
}else if(key.equals("port")){
|
|
try{
|
|
selectServerDialog.setServerPort(Integer.parseInt(value));
|
|
}catch(NumberFormatException e){
|
|
logger.warning("port argument to program is not of a integer type");
|
|
selectServerDialog.setServerPort(-1);
|
|
}
|
|
}else if(key.equals("project")){
|
|
projectHandler.setProject(value);
|
|
}
|
|
}
|
|
|
|
//start program logic
|
|
selectServerDialog.setServerPort(-1);
|
|
showOnStage(selectServerDialog);
|
|
|
|
}
|
|
|
|
public void showOnStage(final GuiWindow gui){
|
|
Platform.runLater(new Runnable(){
|
|
@Override
|
|
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());
|
|
}
|
|
});
|
|
}
|
|
|
|
public void exit() {
|
|
logger.info("terminating");
|
|
Platform.exit();
|
|
System.exit(0);
|
|
}
|
|
|
|
|
|
public SessionHandler getSessionHandler() {
|
|
return this.sessionHandler;
|
|
}
|
|
|
|
public ProjectHandler getProjectHandler(){
|
|
return this.projectHandler;
|
|
}
|
|
|
|
public SSDPHandler getSSDPHandler(){
|
|
return this.ssdpHandler;
|
|
}
|
|
|
|
}
|