Permalink
Browse files

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 <victor.hertel@web.de>
  • Loading branch information...
vhertel committed Jul 23, 2017
1 parent f5166d8 commit 5fa59abd71f2222612bb508f5a55470c7a19eeb8
@@ -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.");
@@ -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";
@@ -79,6 +79,67 @@ public static int setExperimentName() {
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");
}
}
}
@@ -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
@@ -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
@@ -126,6 +126,7 @@
<TextField promptText="Prompt Text 2" GridPane.columnIndex="0" GridPane.rowIndex="1" />
<Label text="Label 2" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField promptText="Prompt Text 3" GridPane.columnIndex="0" GridPane.rowIndex="2" />
<Button text="Text" onAction="#button26" mnemonicParsing="false" GridPane.columnIndex="1" GridPane.rowIndex="2" />
</children>
</GridPane>
</top>

0 comments on commit 5fa59ab

Please sign in to comment.