patternjavaMinor
Dashboard for running programs in JavaFX 8
Viewed 0 times
dashboardrunningforprogramsjavafx
Problem
I have decided to create a dashboard view of a number of running processes/programs/applications, because it became tedious to monitor a bunch of applications, which I had to boot up manually.
Please keep in mind that the .fxml files have been autogenerated using JavaFX SceneBuilder 2.0 and hence may not have proper formatting, but are necessary if you want to run the program.
I'd like a review on all aspects and the design may also be reviewed if you wish, but I'm not a GUI designer.
Dashboard.java
DashboardTabPaneController.java
Server.java
```
public class Server {
private final String name;
private final List commands;
private final ProcessBuilder processBuilder;
private boolean running = false;
private Runnable startHandler = () -> {};
private Runnable stopHandler = () -> {};
public Server() {
this.name = null;
this.commands = null;
this.processBuilder = null;
}
private Process process;
public Server(final String name, final List commands) {
this.name = Objects.requireNonNull(name, "name");
this.commands = Objects.requireNonNull(commands, "commands");
this.processBuilder = new ProcessBuilder(commands);
}
public void setStartHan
Please keep in mind that the .fxml files have been autogenerated using JavaFX SceneBuilder 2.0 and hence may not have proper formatting, but are necessary if you want to run the program.
I'd like a review on all aspects and the design may also be reviewed if you wish, but I'm not a GUI designer.
Dashboard.java
public class Dashboard extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("Dashboard.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("DPC2 Dashboard");
stage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}DashboardTabPaneController.java
public class DashboardTabPaneController {
@FXML
private Button button;
@FXML
private TextArea textArea;
public Button getButton() {
return button;
}
public TextArea getTextArea() {
return textArea;
}
}Server.java
```
public class Server {
private final String name;
private final List commands;
private final ProcessBuilder processBuilder;
private boolean running = false;
private Runnable startHandler = () -> {};
private Runnable stopHandler = () -> {};
public Server() {
this.name = null;
this.commands = null;
this.processBuilder = null;
}
private Process process;
public Server(final String name, final List commands) {
this.name = Objects.requireNonNull(name, "name");
this.commands = Objects.requireNonNull(commands, "commands");
this.processBuilder = new ProcessBuilder(commands);
}
public void setStartHan
Solution
JavaFX Related
-
main() method : in Dashboard.java You do not need it. It's an IDE bug, It's only required for old IDEs. (I recommend using the latest NetBeans, version 8) from Oracle
The
file for the application is created with the JavaFX Packager tool,
which embeds the JavaFX Launcher in the JAR file. However, it is
useful to include the
created without the JavaFX Launcher, such as when using an IDE in
which the JavaFX tools are not fully integrated. Also, Swing
applications that embed JavaFX code require the
-
Use Toggle Buttons : in DashboardController.java you are doing
from Oracle
Two or more toggle buttons can be combined into a group where only one button at a time can be selected
Other
-
Class Names : The class
It is easy to say that names should reveal intent.
-
Package Names : you are using package name
Humans are good at words. A significant part of our brains is
dedicated to the concept of words. And words are, by definition,
pronounceable. It would be a shame not to take advantage of that huge
portion of our brains that has evolved to deal with spoken lan- guage.
So make your names pronounceable.
-
main() method : in Dashboard.java You do not need it. It's an IDE bug, It's only required for old IDEs. (I recommend using the latest NetBeans, version 8) from Oracle
The
main() method is not required for JavaFX applications when the JARfile for the application is created with the JavaFX Packager tool,
which embeds the JavaFX Launcher in the JAR file. However, it is
useful to include the
main() method so you can run JAR files that werecreated without the JavaFX Launcher, such as when using an IDE in
which the JavaFX tools are not fully integrated. Also, Swing
applications that embed JavaFX code require the
main() method.-
Use Toggle Buttons : in DashboardController.java you are doing
switch (generalButton.getText()) I suggest using ToggleButtons instead. It's built for toggling after all.from Oracle
Two or more toggle buttons can be combined into a group where only one button at a time can be selected
Other
-
Class Names : The class
Server can be refactored to something that reveals it's intent. I suggest Process. from Clean Code It is easy to say that names should reveal intent.
-
Package Names : you are using package name
dpc2dashboard which I think can be refactored to dashboard which would make more sense and more pronounceable. from Clean Code Humans are good at words. A significant part of our brains is
dedicated to the concept of words. And words are, by definition,
pronounceable. It would be a shame not to take advantage of that huge
portion of our brains that has evolved to deal with spoken lan- guage.
So make your names pronounceable.
Context
StackExchange Code Review Q#57026, answer score: 4
Revisions (0)
No revisions yet.