From 5fa59abd71f2222612bb508f5a55470c7a19eeb8 Mon Sep 17 00:00:00 2001 From: Victor Hertel Date: Sun, 23 Jul 2017 02:04:42 +0200 Subject: [PATCH] Individually written methods of the GUI controller will be recognized and will be retained during regeneration after changes in the config file. Signed-off-by: Victor Hertel --- .../com/ksatstuttgart/usoc/ConfigHandler.java | 2 +- .../com/ksatstuttgart/usoc/GroundSegment.java | 3 +- .../com/ksatstuttgart/usoc/GuiBuilder.java | 80 ++++++++++++++++++- .../usoc/gui/controller/LogController.java | 15 +++- .../main/resources/config/config.properties | 4 +- .../src/main/resources/fxml/LogPanel.fxml | 1 + 6 files changed, 95 insertions(+), 10 deletions(-) diff --git a/Universal-Space-Operations-Center/src/main/java/com/ksatstuttgart/usoc/ConfigHandler.java b/Universal-Space-Operations-Center/src/main/java/com/ksatstuttgart/usoc/ConfigHandler.java index dd59795..3f61ca0 100644 --- a/Universal-Space-Operations-Center/src/main/java/com/ksatstuttgart/usoc/ConfigHandler.java +++ b/Universal-Space-Operations-Center/src/main/java/com/ksatstuttgart/usoc/ConfigHandler.java @@ -107,7 +107,7 @@ public static void updateConfigMod(String origin, String destination) throws IOE // Initialize file object String filePath = "src/main/resources/"; - // Writes data in configMod.propertes file + // Writes data in propertes file PrintWriter writer = new PrintWriter(filePath + destination); writer.println("# This document serves as the basis for comparisons"); writer.println("# to determine modified values in the config file."); diff --git a/Universal-Space-Operations-Center/src/main/java/com/ksatstuttgart/usoc/GroundSegment.java b/Universal-Space-Operations-Center/src/main/java/com/ksatstuttgart/usoc/GroundSegment.java index 27ea8c1..c432253 100755 --- a/Universal-Space-Operations-Center/src/main/java/com/ksatstuttgart/usoc/GroundSegment.java +++ b/Universal-Space-Operations-Center/src/main/java/com/ksatstuttgart/usoc/GroundSegment.java @@ -51,7 +51,8 @@ public void start(Stage stage) { * Checks whether a regeneration of the FXML structure is * necessary and carries it out in case it is */ - ConfigHandler.rebuildGui("config/config.properties", "config/configMod.properties"); + //ConfigHandler.rebuildGui("config/config.properties", "config/configMod.properties"); + GuiBuilder.logControlBuilder("gui/controller/LogController.java", "config/config.properties"); // JavaFX GUI String fxmlFile = "/fxml/MainFrame.fxml"; diff --git a/Universal-Space-Operations-Center/src/main/java/com/ksatstuttgart/usoc/GuiBuilder.java b/Universal-Space-Operations-Center/src/main/java/com/ksatstuttgart/usoc/GuiBuilder.java index d0a9bda..3742d8b 100644 --- a/Universal-Space-Operations-Center/src/main/java/com/ksatstuttgart/usoc/GuiBuilder.java +++ b/Universal-Space-Operations-Center/src/main/java/com/ksatstuttgart/usoc/GuiBuilder.java @@ -79,6 +79,67 @@ public static int[] getGridPosition(int input) { return position; } + + + + + /** + * Method defines array 'position' with two values ​​for a clear positional + * representation of the corresponding item in the GridPane. + * + * @param fileReader + * @param writer + * @param counter + * @param j + * @throws java.io.FileNotFoundException + * @throws java.io.IOException + */ + public static void writeMethod(FileReader fileReader, PrintWriter writer, int counter, int j) throws FileNotFoundException, IOException { + + BufferedReader bufferedReader = new BufferedReader(fileReader); + String separator = System.getProperty("line.separator"); + StringBuilder stringBuilder = new StringBuilder(); + + String line = bufferedReader.readLine(); + System.out.println(line); + + boolean tokenFound = false; + boolean newMethod = true; + stringBuilder.append(" @FXML \n"); + stringBuilder.append(" private void button").append(counter).append(j).append("(ActionEvent event) { \n"); + + while ( (line=bufferedReader.readLine()) != null ) { + + System.out.println("Zeilen..."); + + if (line.contains("private void button" + counter + j + "(ActionEvent event) {")) { + line = bufferedReader.readLine(); + + if (line.contains("// Automatically generated method button" + counter + j + "()")) { + tokenFound = false; + newMethod = true; + } else { + tokenFound = true; + newMethod = false; + } + + } else if (line.equals(" } ")) { + tokenFound = false; + } + + if (tokenFound) { + stringBuilder.append(line).append(separator) ; + } + } + + if (newMethod) { + stringBuilder.append(" // Automatically generated method button").append(counter).append(j).append("() \n"); + stringBuilder.append(" System.out.println(\"Button").append(counter).append(j).append(" was pressed!\"); \n"); + } + + stringBuilder.append(" } \n"); + writer.println(stringBuilder); + } @@ -313,6 +374,7 @@ public static void logControlBuilder(String filePath, String configPath) throws // Writes data in LogController.java file PrintWriter writer = new PrintWriter(path + filePath); + FileReader fileReader = new FileReader(path + filePath); writer.println("package com.ksatstuttgart.usoc.gui.controller; \n"); writer.println("import java.net.URL; \n" + "import java.util.ResourceBundle; \n" @@ -348,10 +410,20 @@ public static void logControlBuilder(String filePath, String configPath) throws for (int j=1; j<=numberOfControlItems; j++) { String control = config.getProperty("control[" + counter + "][" + j + "]"); if (control.equals("button")) { - writer.println(" @FXML \n" - + " private void button" + counter + j + "(ActionEvent event) { \n" - + " System.out.println(\"Button was pressed!\"); \n" - + " } \n"); + + + writeMethod(fileReader, writer, counter, j); + + + + + + + //writer.println(" @FXML \n" + // + " private void button" + counter + j + "(ActionEvent event) { \n" + // + " // Automatically generated method button" + counter + j + "() \n" + // + " System.out.println(\"Button" + counter + j + " was pressed!\"); \n" + // + " } \n"); } } } diff --git a/Universal-Space-Operations-Center/src/main/java/com/ksatstuttgart/usoc/gui/controller/LogController.java b/Universal-Space-Operations-Center/src/main/java/com/ksatstuttgart/usoc/gui/controller/LogController.java index b7d1ae0..b456013 100644 --- a/Universal-Space-Operations-Center/src/main/java/com/ksatstuttgart/usoc/gui/controller/LogController.java +++ b/Universal-Space-Operations-Center/src/main/java/com/ksatstuttgart/usoc/gui/controller/LogController.java @@ -30,17 +30,26 @@ private void iridiumReconnect(ActionEvent event) { @FXML private void button11(ActionEvent event) { - System.out.println("Button was pressed!"); + // Automatically generated method button11() + System.out.println("Button11 was pressed!"); } @FXML private void button14(ActionEvent event) { - System.out.println("Button was pressed!"); + // Automatically generated method button14() + System.out.println("Button14 was pressed!"); } @FXML private void button21(ActionEvent event) { - System.out.println("Button was pressed!"); + // Automatically generated method button21() + System.out.println("Button21 was pressed!"); + } + + @FXML + private void button26(ActionEvent event) { + // Automatically generated method button26() + System.out.println("Button26 was pressed!"); } @Override diff --git a/Universal-Space-Operations-Center/src/main/resources/config/config.properties b/Universal-Space-Operations-Center/src/main/resources/config/config.properties index 863312a..c6f96ec 100644 --- a/Universal-Space-Operations-Center/src/main/resources/config/config.properties +++ b/Universal-Space-Operations-Center/src/main/resources/config/config.properties @@ -32,7 +32,7 @@ # This option can be used to regenerate the entire GUI, # including FXML files and controllers. # After compiling once, set the option to false again. -RESET = false +RESET = true @@ -131,6 +131,8 @@ control[2][4] = label lText[2][4] = Label 2 control[2][5] = textField promptText[2][5] = Prompt Text 3 +control[2][6] = button + bText[2][6] = Text diff --git a/Universal-Space-Operations-Center/src/main/resources/fxml/LogPanel.fxml b/Universal-Space-Operations-Center/src/main/resources/fxml/LogPanel.fxml index d6a94cd..1590332 100644 --- a/Universal-Space-Operations-Center/src/main/resources/fxml/LogPanel.fxml +++ b/Universal-Space-Operations-Center/src/main/resources/fxml/LogPanel.fxml @@ -126,6 +126,7 @@