Commit f711e136 authored by Carl Gützkow's avatar Carl Gützkow
Browse files

refactor: using set- instead of add-

parent 8cd04106
Pipeline #183773 passed with stages
in 39 seconds
......@@ -49,7 +49,7 @@ public class App extends Application {
Image image = new Image(imagePath);
stage.getIcons().add(image);
} catch(IllegalArgumentException e) {
new DialogBoxBuilder(ERROR).addMessage("Failed loading in image. \nError message: " + e.getMessage())
new DialogBoxBuilder(ERROR).setMessage("Failed loading in image. \nError message: " + e.getMessage())
.build().show();
}
......@@ -92,11 +92,11 @@ public class App extends Application {
} catch (IOException | IllegalStateException e) {
new DialogBoxBuilder(ERROR)
.addHeader("Scene could not be loaded in.\n" +
.setHeader("Scene could not be loaded in.\n" +
"Expand the \"Show details\" button to see full stack trace.\n" +
"Error message: " + e.getMessage())
.addMessage(e.getCause().toString())
.addListMessage(
.setMessage(e.getCause().toString())
.setListMessage(
Arrays.stream(e.getStackTrace())
.map(String::valueOf)
.collect(Collectors.toCollection(ArrayList::new)
......
......@@ -110,22 +110,22 @@ public class BattleController implements Initializable {
List<String> linesSkipped = fileHandler.getReadLinesSkipped();
DialogBoxBuilder dialogBoxBuilder = new DialogBoxBuilder(INFORMATION)
.addTitle("Army imported")
.addMessage("Army was successfully imported.");
.setTitle("Army imported")
.setMessage("Army was successfully imported.");
if (linesSkipped.size() > 0) {
dialogBoxBuilder.addMessage(
dialogBoxBuilder.setMessage(
dialogBoxBuilder.getMessage() + "\n" +
"In the process " + linesSkipped.size() + " units were corrupted.\n" +
"Expand the \"Show details\" button to see all corrupted lines."
)
.addListMessage(linesSkipped);
.setListMessage(linesSkipped);
try {
Path currentPath = Paths.get("").toAbsolutePath();
String imagePath = Paths.get(currentPath.toString(), "src","main","resources","icons", "corrupt-file.png").toString();
dialogBoxBuilder.addImage(imagePath);
dialogBoxBuilder.setImage(imagePath);
} catch(Exception e) {
new DialogBoxBuilder(ERROR).addMessage("Failed loading in image. \nError message: " + e.getCause().toString())
new DialogBoxBuilder(ERROR).setMessage("Failed loading in image. \nError message: " + e.getCause().toString())
.build().show();
}
}
......@@ -134,16 +134,16 @@ public class BattleController implements Initializable {
} catch (FileExtensionException e) {
new DialogBoxBuilder(ERROR)
.addTitle("File is not supported")
.addMessage(e.getMessage())
.setTitle("File is not supported")
.setMessage(e.getMessage())
.build().showAndWait();
} catch (IOException e) {
new DialogBoxBuilder(ERROR)
.addHeader("File could not be loaded")
.setHeader("File could not be loaded")
.build().showAndWait();
} catch (IllegalArgumentException e) {
new DialogBoxBuilder(ERROR)
.addMessage(e.getMessage())
.setMessage(e.getMessage())
.build().showAndWait();
}
scores[0] = 0;
......@@ -182,12 +182,12 @@ public class BattleController implements Initializable {
result = true;
} catch (IllegalArgumentException e) {
new DialogBoxBuilder(ERROR)
.addMessage(e.getMessage())
.setMessage(e.getMessage())
.build().showAndWait();
} catch (NullPointerException e) {
new DialogBoxBuilder(NONE)
.addTitle("Army does not exist")
.addMessage("Armies have not been imported")
.setTitle("Army does not exist")
.setMessage("Armies have not been imported")
.build().showAndWait();
}
return result;
......@@ -217,7 +217,7 @@ public class BattleController implements Initializable {
displayArmy(1, armyTwo);
} catch (UnsupportedOperationException | NullPointerException e) {
new DialogBoxBuilder(ERROR)
.addMessage(e.getMessage())
.setMessage(e.getMessage())
.build().showAndWait();
}
}
......@@ -259,7 +259,7 @@ public class BattleController implements Initializable {
public void editArmy(int armyNumber) {
if (originalArmies[armyNumber] == null) {
new DialogBoxBuilder(ERROR)
.addMessage("Army is not imported.")
.setMessage("Army is not imported.")
.build().showAndWait();
return;
}
......@@ -290,8 +290,8 @@ public class BattleController implements Initializable {
public void createArmy() {
DialogBox dialog = new DialogBoxBuilder(INFORMATION)
.addMessage("Which side do you want to create an army for?")
.addTitle("Create army").addHeader("Going to create army screen.")
.setMessage("Which side do you want to create an army for?")
.setTitle("Create army").setHeader("Going to create army screen.")
.build();
ObservableList<ButtonType> buttons = dialog.getButtonTypes();
buttons.clear();
......
......@@ -74,7 +74,7 @@ public class EditArmyController implements Initializable {
observableChangelog.add("✎ Changed name to " + newName);
} catch (IllegalArgumentException e) {
new DialogBoxBuilder(ERROR)
.addMessage(e.getMessage())
.setMessage(e.getMessage())
.build().showAndWait();
}
}
......@@ -101,7 +101,7 @@ public class EditArmyController implements Initializable {
observableChangelog.add("➕ Created " + amountOfUnits + " " + unitTypeClassName + ((amountOfUnits > 1) ? "s" : ""));
} catch (IllegalArgumentException e) {
new DialogBoxBuilder(ERROR)
.addMessage(e.getMessage())
.setMessage(e.getMessage())
.build().showAndWait();
}
}
......@@ -120,7 +120,7 @@ public class EditArmyController implements Initializable {
}
} catch (NullPointerException e) {
new DialogBoxBuilder(ERROR)
.addMessage("Unit to delete is not selected.")
.setMessage("Unit to delete is not selected.")
.build().showAndWait();
}
}
......@@ -132,7 +132,7 @@ public class EditArmyController implements Initializable {
*/
@FXML public void cancelAllChanges() {
Optional<ButtonType> result = new DialogBoxBuilder(CONFIRMATION)
.addMessage("Are you sure you want to cancel editing this army? \n" +
.setMessage("Are you sure you want to cancel editing this army? \n" +
"You will be returned to the battle page.")
.build().showAndWait();
if (result.isPresent() && result.get().equals(ButtonType.OK))
......@@ -152,13 +152,13 @@ public class EditArmyController implements Initializable {
displaySuccessfulPopupMessage("Army was successfully written to file.");
} catch (IOException e) {
new DialogBoxBuilder(ERROR)
.addHeader("Army could not be written to file.").build().showAndWait();
.setHeader("Army could not be written to file.").build().showAndWait();
} catch (NullPointerException e) {
new DialogBoxBuilder(ERROR)
.addMessage("No army has been chosen to edit.").build().showAndWait();
.setMessage("No army has been chosen to edit.").build().showAndWait();
} catch (FileExtensionException e) {
new DialogBoxBuilder(ERROR)
.addMessage(e.getMessage()).build().showAndWait();
.setMessage(e.getMessage()).build().showAndWait();
}
}
......@@ -168,7 +168,7 @@ public class EditArmyController implements Initializable {
*/
@FXML public void updateArmyAndGoBack() {
Optional<ButtonType> result = new DialogBoxBuilder(CONFIRMATION)
.addMessage("Are you sure you want to commit these changes? \n" +
.setMessage("Are you sure you want to commit these changes? \n" +
"You will be returned to the battle page.")
.build().showAndWait();
if (result.isPresent() && result.get().equals(ButtonType.OK)) {
......
......@@ -53,13 +53,13 @@ public class DialogBoxBuilder {
}
/**
* Add title to the dialog box builder configuration.
* Set title to the dialog box builder configuration.
* The title is displayed on the top of the window.
*
* @param title String - the title of the dialog box
* @return dialogBoxBuilder - DialogBoxBuilder - returned to add further configurations.
*/
public DialogBoxBuilder addTitle(String title) {
public DialogBoxBuilder setTitle(String title) {
this.title = title;
return this;
}
......@@ -71,18 +71,18 @@ public class DialogBoxBuilder {
* @param header String - the header of the dialog box
* @return dialogBoxBuilder - DialogBoxBuilder - returned to add further configurations.
*/
public DialogBoxBuilder addHeader(String header) {
public DialogBoxBuilder setHeader(String header) {
this.header = header;
return this;
}
/**
* Add message to the dialog box builder configuration.
* Set message to the dialog box builder configuration.
*
* @param message String - the message of the dialog box
* @return dialogBoxBuilder - DialogBoxBuilder - returned to add further configurations.
*/
public DialogBoxBuilder addMessage(String message) {
public DialogBoxBuilder setMessage(String message) {
this.message = message;
return this;
}
......@@ -95,7 +95,7 @@ public class DialogBoxBuilder {
* @param imageName String - the name of the image to display.
* @return dialogBoxBuilder - DialogBoxBuilder - returned to add further configurations.
*/
public DialogBoxBuilder addImage(String imageName) {
public DialogBoxBuilder setImage(String imageName) {
this.image = new Image(imageName, 50 ,50, false, false);
return this;
}
......@@ -106,7 +106,7 @@ public class DialogBoxBuilder {
* @param listMessages - List - the dialog box' list of messages
* @return dialogBoxBuilder - DialogBoxBuilder - returned to add further configurations.
*/
public DialogBoxBuilder addListMessage(List<String> listMessages) {
public DialogBoxBuilder setListMessage(List<String> listMessages) {
this.listMessages = listMessages;
return this;
}
......
......@@ -11,7 +11,7 @@
<HBox.margin>
<Insets bottom="50.0" left="25.0" right="25.0" top="40.0" />
</HBox.margin>
<Label text="Editing " fx:id="editArmyTitle" minHeight="-Infinity" minWidth="-Infinity" wrapText="true" maxWidth="300" alignment="CENTER" textAlignment="CENTER">
<Label text="Editing " fx:id="editArmyTitle" alignment="CENTER" maxWidth="600" textAlignment="CENTER" wrapText="true" minHeight="-Infinity">
<font>
<Font name="Arial" size="36.0" />
</font>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment