corefx - added jfx progress bar under the menu, make use of the progress bar for start/stop

This commit is contained in:
Blake J. Harnden 2018-11-09 13:26:42 -08:00
parent 1b728770f1
commit 8864169683
3 changed files with 32 additions and 23 deletions

View file

@ -13,6 +13,7 @@ import com.core.ui.*;
import com.core.ui.dialogs.*; import com.core.ui.dialogs.*;
import com.core.utils.ConfigUtils; import com.core.utils.ConfigUtils;
import com.core.websocket.CoreWebSocket; import com.core.websocket.CoreWebSocket;
import com.jfoenix.controls.JFXProgressBar;
import javafx.application.Application; import javafx.application.Application;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.embed.swing.SwingNode; import javafx.embed.swing.SwingNode;
@ -47,6 +48,7 @@ public class Controller implements Initializable {
@FXML private BorderPane borderPane; @FXML private BorderPane borderPane;
@FXML private SwingNode swingNode; @FXML private SwingNode swingNode;
@FXML private MenuItem saveXmlMenuItem; @FXML private MenuItem saveXmlMenuItem;
@FXML private JFXProgressBar progressBar;
private Application application; private Application application;
private Stage window; private Stage window;

View file

@ -15,7 +15,6 @@ import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.ComboBox; import javafx.scene.control.ComboBox;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.Tooltip; import javafx.scene.control.Tooltip;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
@ -237,33 +236,37 @@ public class GraphToolbar extends VBox {
} }
private void startSession() { private void startSession() {
try { controller.getProgressBar().setVisible(true);
ProgressBar progressBar = new ProgressBar(); runButton.setDisable(true);
progressBar.setPrefWidth(Double.MAX_VALUE); new Thread(() -> {
controller.getBorderPane().setBottom(progressBar); try {
boolean result = controller.getCoreClient().start();
boolean result = controller.getCoreClient().start(); if (result) {
if (result) { Toast.success("Session Started");
Toast.success("Session Started"); setRunButton(true);
setRunButton(true); }
} catch (IOException ex) {
logger.error("failure starting session", ex);
} }
controller.getProgressBar().setVisible(false);
controller.getBorderPane().setBottom(null); }).start();
} catch (IOException ex) {
logger.error("failure starting session", ex);
}
} }
private void stopSession() { private void stopSession() {
try { controller.getProgressBar().setVisible(true);
boolean result = controller.getCoreClient().stop(); runButton.setDisable(true);
if (result) { new Thread(() -> {
Toast.success("Session Stopped"); try {
setRunButton(false); boolean result = controller.getCoreClient().stop();
if (result) {
Toast.success("Session Stopped");
setRunButton(false);
}
} catch (IOException ex) {
logger.error("failure to stopSession session", ex);
} }
} catch (IOException ex) { controller.getProgressBar().setVisible(false);
logger.error("failure to stopSession session", ex); }).start();
}
} }
public void setRunButton(boolean isRunning) { public void setRunButton(boolean isRunning) {
@ -277,6 +280,7 @@ public class GraphToolbar extends VBox {
if (runButton.getGraphic() != stopIcon) { if (runButton.getGraphic() != stopIcon) {
runButton.setGraphic(stopIcon); runButton.setGraphic(stopIcon);
} }
runButton.setDisable(false);
}); });
} else { } else {
Platform.runLater(() -> { Platform.runLater(() -> {
@ -287,6 +291,7 @@ public class GraphToolbar extends VBox {
if (runButton.getGraphic() != startIcon) { if (runButton.getGraphic() != startIcon) {
runButton.setGraphic(startIcon); runButton.setGraphic(startIcon);
} }
runButton.setDisable(false);
}); });
} }
} }

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXProgressBar?>
<?import javafx.embed.swing.SwingNode?> <?import javafx.embed.swing.SwingNode?>
<?import javafx.scene.control.Menu?> <?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?> <?import javafx.scene.control.MenuBar?>
@ -57,6 +58,7 @@
</Menu> </Menu>
</menus> </menus>
</MenuBar> </MenuBar>
<JFXProgressBar fx:id="progressBar" maxWidth="1.7976931348623157E308" visible="false" />
</children> </children>
</VBox> </VBox>
</top> </top>