Newer
Older
package com.application;
Eilert Tunheim
committed
import com.application.DB.HelpingFunctions;
import com.application.GUI.InputPopUpWindow;
Eilert Tunheim
committed
import com.application.GUI.OutputPopUpWindow;
import com.application.GUI.ProgressBar.RingProgressIndicator;
import com.application.GUI.LineChartFunctionality;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.Pos;
import javafx.scene.chart.LineChart;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.logging.Logger;
Eilert Tunheim
committed
import static com.application.DB.Constants.*;
import static com.application.DB.HelpingFunctions.*;
import static com.application.DB.HelpingFunctions.isLoadedData;
import static com.application.GUI.LineChartFunctionality.getDataPointsXAxis;
import static com.application.GUI.LineChartFunctionality.getLiveData;
import static java.util.logging.Level.SEVERE;
/**
* This class launches the application
*
* @author Eilert Tunheim, Karin Pettersen, Mads Arnesen
* @version 1.0.0
*/
public class Main extends Application {
private BorderPane topBar;
private HBox logoBar;
private VBox sideBar;
private MenuBar menuBar;
private HBox bottomBar;
Eilert Tunheim
committed
private static TextField treeSpeciesText;
private static TextField dimensionsText;
private static TextField sawsetText;
private static TextField moistureGoalText;
Eilert Tunheim
committed
private static CheckMenuItem menuViewLiveData;
private static CheckMenuItem menuViewRegression;
private static CheckMenuItem menuViewRegressionShadow;
private static CheckMenuItem menuViewPreviousData;
private static CheckBox liveDataBox;
private static CheckBox regressionBox;
private static CheckBox regressionConfidenceIntervalBox;
private static CheckBox previousBox;
/**
* Starts the application
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
launch(args);
}
public static void exitApplication(){
Platform.exit();
System.exit(0);
}
/**
* Initializes the application with all the different panes.
*
* @throws Exception Exception in super.
*/
@Override
public void init() throws Exception {
super.init();
// Initializing variables
this.lineChartFunctionality = new LineChartFunctionality();
this.topBar = new BorderPane();
this.logoBar = new HBox();
this.sideBar = new VBox();
this.menuBar = new MenuBar();
this.bottomBar = new HBox();
}
* Sets the primaryStage and sets the scene for the window.
* @param primaryStage
* @throws Exception
*/
@Override
public void start(Stage primaryStage) throws Exception {
// Create panes for root
BorderPane root = new BorderPane();
this.menuBar = createMenuBar();
this.sideBar = createSideBar();
this.logoBar = createLogoBar();
LineChart<String, Number> lineChart = LineChartFunctionality.getLineChart();
//Set id's to connect to css stylesheet
root.setId("root");
this.logoBar.setId("logoBar");
this.menuBar.setId("menuBar");
this.sideBar.setId("sideBar");
this.bottomBar = createBottomBar();
this.bottomBar.setId("bottomBar");
lineChart.setId("lineChart");
// Sett the menubar in a vbox inorder to stretch over the whole screen
VBox vBox = new VBox(this.menuBar);
// Sets alignment for the topBar
this.topBar.setTop(vBox);
this.topBar.setCenter(logoBar);
// Sets alignment for the panes to the parent root
root.setTop(this.topBar);
root.setLeft(this.sideBar);
root.setCenter(lineChart);
root.setBottom(this.bottomBar);
VBox.setVgrow(this.logoBar, Priority.ALWAYS);
// Sets the scene and defines boundaries
Scene scene = new Scene(root, 1200, 600);
scene.getStylesheets().add(getClass().getResource("/com.application/CSS/styleSheet.css").toExternalForm());
primaryStage.setTitle("Moelven Drying Application");
primaryStage.setMaximized(true);
primaryStage.setMinHeight(600);
primaryStage.setMinWidth(1200);
primaryStage.setScene(scene);
primaryStage.show();
// Displays the input parameters popup window
InputPopUpWindow.display();
/**
* Creates the menubar with buttons.
* Defines each action when button is clicked.
*
* @return MenuBar as a HBox
*/
private MenuBar createMenuBar() {
// Creating a menubar
MenuBar menuBar = new MenuBar();
// Defining the individual menus
Menu menuFile = new Menu("File");
Menu menuHelp = new Menu("Help");
MenuItem menuFileExit = new MenuItem("Exit");
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
menuFileExit.setOnAction(event -> exitApplication());
setMenuViewLiveData(new CheckMenuItem ("Live Data"));
setMenuViewRegression(new CheckMenuItem ("Regression"));
setMenuViewRegressionShadow(new CheckMenuItem ("Regression Shadow"));
setMenuViewPreviousData(new CheckMenuItem ("Previous Data"));
getMenuViewLiveData().setOnAction(event -> {
if(getMenuViewLiveData().isSelected()){
LineChartFunctionality.setPrintLiveData(true);
LineChartFunctionality.printGraphs();
} else {
LineChartFunctionality.setPrintLiveData(false);
LineChartFunctionality.printGraphs();
}
});
getMenuViewRegression().setOnAction(event -> {
if(getMenuViewRegression().isSelected()){
LineChartFunctionality.setPrintRegression(true);
LineChartFunctionality.printGraphs();
} else {
LineChartFunctionality.setPrintRegression(false);
LineChartFunctionality.printGraphs();
}
});
getMenuViewRegressionShadow().setOnAction(event -> {
if(getMenuViewRegressionShadow().isSelected()){
LineChartFunctionality.setPrintRegressionConfidenceInterval(true);
LineChartFunctionality.printGraphs();
} else {
LineChartFunctionality.setPrintRegressionConfidenceInterval(false);
LineChartFunctionality.printGraphs();
}
});
getMenuViewPreviousData().setOnAction(event -> {
if(getMenuViewPreviousData().isSelected()){
LineChartFunctionality.setPrintPreviousData(true);
LineChartFunctionality.printGraphs();
} else {
LineChartFunctionality.setPrintPreviousData(false);
LineChartFunctionality.printGraphs();
}
});
menuFile.getItems().addAll(menuFileExit);
menuView.getItems().addAll(getMenuViewLiveData(), getMenuViewRegression(), getMenuViewRegressionShadow(), getMenuViewPreviousData());
// Adding the menus to the menubar
menuBar.getMenus().addAll(menuFile, menuView, menuHelp);
// Returns the menubar
return menuBar;
}
private VBox createSideBar(){
// Creating a vbox
VBox sideBarVBox = new VBox();
Label treeSpeciesLabel = new Label("Tree Species");
treeSpeciesLabel.setId("sideBarLabelText");
Eilert Tunheim
committed
treeSpeciesText = new TextField();
treeSpeciesText.setId("sideBarLabelText");
treeSpeciesText.setPromptText("No Input");
Eilert Tunheim
committed
treeSpeciesText.setText(HelpingFunctions.TREE_SPECIES);
Eilert Tunheim
committed
treeSpeciesText.setEditable(false);
Label dimensionsLabel = new Label("Width x Height");
dimensionsLabel.setId("sideBarLabelText");
Eilert Tunheim
committed
dimensionsText = new TextField();
dimensionsText.setId("sideBarLabelText");
dimensionsText.setPromptText("No Input");
Eilert Tunheim
committed
dimensionsText.setText(HelpingFunctions.DIMENSIONS);
Eilert Tunheim
committed
dimensionsText.setEditable(false);
Label sawsetLabel = new Label("Sawset");
sawsetLabel.setId("sideBarLabelText");
Eilert Tunheim
committed
sawsetText = new TextField();
sawsetText.setId("sideBarLabelText");
sawsetText.setPromptText("No Input");
Eilert Tunheim
committed
sawsetText.setText(HelpingFunctions.SAWSET);
Eilert Tunheim
committed
sawsetText.setEditable(false);
Label moistureGoalLabel = new Label("Moisture Goal");
moistureGoalLabel.setId("sideBarLabelText");
Eilert Tunheim
committed
moistureGoalText = new TextField();
moistureGoalText.setId("sideBarLabelText");
moistureGoalText.setPromptText("No Input");
Eilert Tunheim
committed
moistureGoalText.setText(HelpingFunctions.MOISTURE_GOAL);
Eilert Tunheim
committed
moistureGoalText.setEditable(false);
Label timeLeftLabel = new Label("Time Left");
timeLeftLabel.setId("sideBarLabelText");
timeLeftText = new TextField();
timeLeftText.setId("sideBarLabelText");
timeLeftText.setPromptText("Calculating...");
timeLeftText.setText(TIME_LEFT);
timeLeftText.setEditable(false);
Eilert Tunheim
committed
Button inputParametersButton = new Button("Input Parameters");
inputParametersButton.setId("sideBarButtonInputParameters");
inputParametersButton.setOnAction(e -> InputPopUpWindow.display());
Button finishButton = new Button("Finish");
finishButton.setId("sideBarButtonFinish");
Eilert Tunheim
committed
finishButton.setOnAction(e -> OutputPopUpWindow.displayOutputWindow());
Eilert Tunheim
committed
Button exitButton = new Button("Exit");
exitButton.setId("sideBarButtonExit");
exitButton.setOnAction(e -> exitApplication());
// Creating the circular progressbar
RingProgressIndicator ringProgressIndicator = new RingProgressIndicator();
ringProgressIndicator.setRingWidth(100);
ringProgressIndicator.makeIndeterminate();
class WorkerThread extends Thread{
RingProgressIndicator rpi;
int progress = 0;
public WorkerThread(RingProgressIndicator rpi){
this.rpi = rpi;
}
@Override
public void run() {
while (!IS_FINISHED) {
Eilert Tunheim
committed
ringProgressIndicator.makeIndeterminate();
Thread.sleep(500L * NUMBER_OF_SECONDS_LIVE_DATA);
} catch (InterruptedException e) {
e.printStackTrace();
}
while (isLoadedData()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
Logger.getLogger(getClass().getName()).log(SEVERE, null, e);
}
Platform.runLater(() -> {
rpi.setProgress(progress);
});
progress = getLiveData().size()/ getDataPointsXAxis()*100;
if (progress > 100) {
break;
}
}
}
}
}
new WorkerThread(ringProgressIndicator).start();
Eilert Tunheim
committed
sideBarVBox.getChildren().addAll(ringProgressIndicator, treeSpeciesLabel, treeSpeciesText, dimensionsLabel, dimensionsText,
sawsetLabel, sawsetText, moistureGoalLabel, moistureGoalText, timeLeftLabel, timeLeftText, inputParametersButton, finishButton, exitButton);
VBox.setVgrow(sideBarVBox, Priority.ALWAYS);
return sideBarVBox;
}
/**
* This function imports the logos and defines the alignments
* @return a logoBar containing the logos in proper alignments
* @throws FileNotFoundException
*/
private HBox createLogoBar() throws FileNotFoundException {
// Defining the image paths
Image moelvenLogoM = new Image(new FileInputStream("src/main/resources/com.application/GUI/moelven_logo_m.png"));
Image moelvenLogoTitle = new Image(new FileInputStream("src/main/resources/com.application/GUI/moelven_logo_title.png"));
// Creating imageview objects
ImageView imageViewM = new ImageView(moelvenLogoM);
ImageView imageViewTitle = new ImageView(moelvenLogoTitle);
// Defining resolution and aspect ratio
imageViewM.setFitHeight(100);
imageViewM.setPreserveRatio(true);
imageViewTitle.setFitHeight(100);
imageViewTitle.setPreserveRatio(true);
// Defining alignments
Region region1 = new Region();
HBox.setHgrow(region1, Priority.ALWAYS);
Region region2 = new Region();
HBox.setHgrow(region2, Priority.ALWAYS);
return new HBox(imageViewM, region1, imageViewTitle, region2);
}
Eilert Tunheim
committed
private HBox createBottomBar(){
HBox hBox = new HBox();
Label liveDataText = new Label("View Live Data");
setLiveDataBox(new CheckBox());
getLiveDataBox().setSelected(true);
getLiveDataBox().setOnAction(event -> {
if(getLiveDataBox().isSelected()){
LineChartFunctionality.setPrintLiveData(true);
LineChartFunctionality.printGraphs();
LineChartFunctionality.setPrintLiveData(false);
LineChartFunctionality.printGraphs();
});
Label regressionText = new Label("View Regression");
setRegressionBox(new CheckBox());
getRegressionBox().setSelected(true);
getRegressionBox().setOnAction(event -> {
if(getRegressionBox().isSelected()){
LineChartFunctionality.setPrintRegression(true);
LineChartFunctionality.printGraphs();
LineChartFunctionality.setPrintRegression(false);
LineChartFunctionality.printGraphs();
Label regressionConfidenceIntervalText = new Label("View Regression Shadow");
setRegressionConfidenceIntervalBox(new CheckBox());
getRegressionConfidenceIntervalBox().setSelected(false);
getRegressionConfidenceIntervalBox().setOnAction(event -> {
if(getRegressionConfidenceIntervalBox().isSelected()){
LineChartFunctionality.setPrintRegressionConfidenceInterval(true);
LineChartFunctionality.printGraphs();
} else {
LineChartFunctionality.setPrintRegressionConfidenceInterval(false);
LineChartFunctionality.printGraphs();
}
});
Label previousText = new Label("View Previous Data");
setPreviousBox(new CheckBox());
getPreviousBox().setSelected(true);
getPreviousBox().setOnAction(event -> {
if(getPreviousBox().isSelected()){
LineChartFunctionality.setPrintPreviousData(true);
LineChartFunctionality.printGraphs();
} else {
LineChartFunctionality.setPrintPreviousData(false);
LineChartFunctionality.printGraphs();
}
hBox.getChildren().addAll(liveDataText, liveDataBox, regressionText, regressionBox, regressionConfidenceIntervalText, regressionConfidenceIntervalBox, previousText, previousBox);
hBox.setAlignment(Pos.CENTER_RIGHT);
hBox.setSpacing(5);
return hBox;
}
Eilert Tunheim
committed
public static void setTreeSpeciesText(String treeSpeciesText) {
Main.treeSpeciesText.setText(treeSpeciesText);
}
public static void setDimensionsText(String dimensionsText) {
Main.dimensionsText.setText(dimensionsText);
}
public static void setSawsetText(String sawsetText) {
Main.sawsetText.setText(sawsetText);
}
public static void setMoistureGoalText(String moistureGoalText) {
Main.moistureGoalText.setText(moistureGoalText);
}
public static void setTimeLeftText(String moistureGoalText) {
Main.timeLeftText.setText(moistureGoalText);
}
public LineChartFunctionality getLineChartFunctionality() {
return lineChartFunctionality;
}
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
public static CheckMenuItem getMenuViewLiveData() {
return menuViewLiveData;
}
public static void setMenuViewLiveData(CheckMenuItem menuViewLiveData) {
Main.menuViewLiveData = menuViewLiveData;
}
public static CheckMenuItem getMenuViewRegression() {
return menuViewRegression;
}
public void setMenuViewRegression(CheckMenuItem menuViewRegression) {
Main.menuViewRegression = menuViewRegression;
}
public static CheckMenuItem getMenuViewRegressionShadow() {
return menuViewRegressionShadow;
}
public void setMenuViewRegressionShadow(CheckMenuItem menuViewRegressionShadow) {
this.menuViewRegressionShadow = menuViewRegressionShadow;
}
public static CheckMenuItem getMenuViewPreviousData() {
return menuViewPreviousData;
}
public void setMenuViewPreviousData(CheckMenuItem menuViewPreviousData) {
Main.menuViewPreviousData = menuViewPreviousData;
}
public static CheckBox getLiveDataBox() {
return liveDataBox;
}
public void setLiveDataBox(CheckBox liveDataBox) {
Main.liveDataBox = liveDataBox;
}
public static CheckBox getRegressionBox() {
return regressionBox;
}
public void setRegressionBox(CheckBox regressionBox) {
Main.regressionBox = regressionBox;
}
public static CheckBox getRegressionConfidenceIntervalBox() {
return regressionConfidenceIntervalBox;
}
public void setRegressionConfidenceIntervalBox(CheckBox regressionConfidenceIntervalBox) {
Main.regressionConfidenceIntervalBox = regressionConfidenceIntervalBox;
}
public static CheckBox getPreviousBox() {
return previousBox;
}
public void setPreviousBox(CheckBox previousBox) {
Main.previousBox = previousBox;
}