GUIMain.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package mdd.client;
  2. import javafx.application.Application;
  3. import javafx.application.Platform;
  4. import javafx.beans.value.ChangeListener;
  5. import javafx.beans.value.ObservableValue;
  6. import javafx.event.EventHandler;
  7. import javafx.fxml.FXML;
  8. import javafx.fxml.FXMLLoader;
  9. import javafx.scene.Parent;
  10. import javafx.scene.Scene;
  11. import javafx.scene.control.SplitPane;
  12. import javafx.scene.input.KeyCode;
  13. import javafx.stage.Stage;
  14. import javafx.scene.input.KeyEvent;
  15. import javafx.stage.WindowEvent;
  16. import org.json.simple.JSONObject;
  17. import java.io.IOException;
  18. public class GUIMain extends Application implements IGUIEventClient{
  19. private GUIEventHandler _eventHandler;
  20. private Client client = Client.client;
  21. public static void main(String[] args) {
  22. launch(args);
  23. }
  24. @Override
  25. public void start(Stage primaryStage){
  26. _eventHandler = GUIEventHandler.getEventHandler();
  27. Parent root = null;
  28. FXMLLoader loader = new FXMLLoader(getClass().getResource("main.fxml"));
  29. try {
  30. root = loader.load();
  31. } catch (IOException e) {
  32. throw new RuntimeException(e);
  33. }
  34. root.setFocusTraversable(true);
  35. root.setOnKeyPressed(e -> {
  36. System.out.println("[Application]: "+e.getText());
  37. JSONObject json = new JSONObject();
  38. KeyCode code = e.getCode();
  39. if (code == KeyCode.ENTER){
  40. json.put("key", "ENTER");
  41. }else if(code == KeyCode.DELETE){
  42. json.put("key", "DELETE");
  43. }
  44. _eventHandler.publishEvent(5, "KeyTyped", json);
  45. /*if (isSelected) {
  46. JSONObject json = new JSONObject();
  47. json.put("id", ID);
  48. _eventHandler.publishEvent("OPEN_PROCESSOR", json);
  49. }*/
  50. });
  51. FXMLDocumentController controller = loader.getController();
  52. Scene scene = new Scene(root);
  53. scene.getStylesheets().add(String.valueOf(getClass().getResource("dark-theme.css")));
  54. //TODO change back to FullScreen
  55. //primaryStage.setFullScreen(true);
  56. primaryStage.setMaximized(true);
  57. primaryStage.setScene(scene);
  58. primaryStage.showingProperty().addListener(new ChangeListener<Boolean>() {
  59. @Override
  60. public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
  61. if (newValue) {
  62. controller.sPane.setDividerPositions(0.1f, 0.9f);
  63. observable.removeListener(this);
  64. }
  65. }
  66. });
  67. primaryStage.setOnCloseRequest(e -> {
  68. Platform.exit();
  69. System.exit(0);
  70. });
  71. primaryStage.show();
  72. }
  73. @Override
  74. public void processGUIEvent(String event, JSONObject args) {
  75. }
  76. @Override
  77. public void close() throws Exception {
  78. }
  79. }