Skip to content

Commit

Permalink
Individually written methods of the GUI controller will be recognized…
Browse files Browse the repository at this point in the history
… 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 5fa59ab
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 10 deletions.
Expand Up @@ -107,7 +107,7 @@ public static void updateConfigMod(String origin, String destination) throws IOE
// Initialize file object // Initialize file object
String filePath = "src/main/resources/"; String filePath = "src/main/resources/";


// Writes data in configMod.propertes file // Writes data in propertes file
PrintWriter writer = new PrintWriter(filePath + destination); PrintWriter writer = new PrintWriter(filePath + destination);
writer.println("# This document serves as the basis for comparisons"); writer.println("# This document serves as the basis for comparisons");
writer.println("# to determine modified values in the config file."); writer.println("# to determine modified values in the config file.");
Expand Down
Expand Up @@ -51,7 +51,8 @@ public void start(Stage stage) {
* Checks whether a regeneration of the FXML structure is * Checks whether a regeneration of the FXML structure is
* necessary and carries it out in case it 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 // JavaFX GUI
String fxmlFile = "/fxml/MainFrame.fxml"; String fxmlFile = "/fxml/MainFrame.fxml";
Expand Down
Expand Up @@ -79,6 +79,67 @@ public static int[] getGridPosition(int input) {


return position; 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);
}






Expand Down Expand Up @@ -313,6 +374,7 @@ public static void logControlBuilder(String filePath, String configPath) throws


// Writes data in LogController.java file // Writes data in LogController.java file
PrintWriter writer = new PrintWriter(path + filePath); PrintWriter writer = new PrintWriter(path + filePath);
FileReader fileReader = new FileReader(path + filePath);
writer.println("package com.ksatstuttgart.usoc.gui.controller; \n"); writer.println("package com.ksatstuttgart.usoc.gui.controller; \n");
writer.println("import java.net.URL; \n" writer.println("import java.net.URL; \n"
+ "import java.util.ResourceBundle; \n" + "import java.util.ResourceBundle; \n"
Expand Down Expand Up @@ -348,10 +410,20 @@ public static void logControlBuilder(String filePath, String configPath) throws
for (int j=1; j<=numberOfControlItems; j++) { for (int j=1; j<=numberOfControlItems; j++) {
String control = config.getProperty("control[" + counter + "][" + j + "]"); String control = config.getProperty("control[" + counter + "][" + j + "]");
if (control.equals("button")) { if (control.equals("button")) {
writer.println(" @FXML \n"
+ " private void button" + counter + j + "(ActionEvent event) { \n"
+ " System.out.println(\"Button was pressed!\"); \n" writeMethod(fileReader, writer, counter, j);
+ " } \n");





//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");
} }
} }
} }
Expand Down
Expand Up @@ -30,17 +30,26 @@ private void iridiumReconnect(ActionEvent event) {


@FXML @FXML
private void button11(ActionEvent event) { private void button11(ActionEvent event) {
System.out.println("Button was pressed!"); // Automatically generated method button11()
System.out.println("Button11 was pressed!");
} }


@FXML @FXML
private void button14(ActionEvent event) { private void button14(ActionEvent event) {
System.out.println("Button was pressed!"); // Automatically generated method button14()
System.out.println("Button14 was pressed!");
} }


@FXML @FXML
private void button21(ActionEvent event) { 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 @Override
Expand Down
Expand Up @@ -32,7 +32,7 @@
# This option can be used to regenerate the entire GUI, # This option can be used to regenerate the entire GUI,
# including FXML files and controllers. # including FXML files and controllers.
# After compiling once, set the option to false again. # After compiling once, set the option to false again.
RESET = false RESET = true






Expand Down Expand Up @@ -131,6 +131,8 @@ control[2][4] = label
lText[2][4] = Label 2 lText[2][4] = Label 2
control[2][5] = textField control[2][5] = textField
promptText[2][5] = Prompt Text 3 promptText[2][5] = Prompt Text 3
control[2][6] = button
bText[2][6] = Text






Expand Down
Expand Up @@ -126,6 +126,7 @@
<TextField promptText="Prompt Text 2" GridPane.columnIndex="0" GridPane.rowIndex="1" /> <TextField promptText="Prompt Text 2" GridPane.columnIndex="0" GridPane.rowIndex="1" />
<Label text="Label 2" GridPane.columnIndex="1" GridPane.rowIndex="1" /> <Label text="Label 2" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField promptText="Prompt Text 3" GridPane.columnIndex="0" GridPane.rowIndex="2" /> <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> </children>
</GridPane> </GridPane>
</top> </top>
Expand Down

0 comments on commit 5fa59ab

Please sign in to comment.