Newer
Older
import javafx.application.Platform;
Eilert Tunheim
committed
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Pos;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.*;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import static com.application.DB.Constants.*;
import static com.application.DB.DB.getCurrentDrying;
Eilert Tunheim
committed
import static com.application.Main.*;
import static com.application.DB.DB.setInputParameters;
import static com.application.GUI.LineChartFunctionality.loadSingleSeries;
Eilert Tunheim
committed
/**
* This class handles the popup input window
*
* @author Eilert Tunheim, Karin Pettersen, Mads Arnesen
* @version 1.0
public class InputPopUpWindow {
public static void exitDataThread(){
Platform.exit();
System.exit(0);
}
Eilert Tunheim
committed
public static void display() {
Eilert Tunheim
committed
Stage window = new Stage();
Eilert Tunheim
committed
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle("Input Parameters");
Eilert Tunheim
committed
// Top
Label inputLabel= new Label("Input");
Eilert Tunheim
committed
inputLabel.setId("inputTop");
// Center - Input fields
Eilert Tunheim
committed
Label treeSpeciesInputLabel = new Label("Tree Species");
treeSpeciesInputLabel.setId("inputLabel");
Eilert Tunheim
committed
ObservableList<String> treeSpecies = FXCollections.observableArrayList(
"Furu",
"Gran"
);
ComboBox<String> treeSpeciesList = new ComboBox<>(treeSpecies);
Eilert Tunheim
committed
treeSpeciesList.setPromptText("Select Tree Species");
treeSpeciesList.setId("inputDropDownBox");
treeSpeciesList.setEditable(true);
// Dimensions
Label dimensionsInputLabel = new Label("Dimensions");
dimensionsInputLabel.setId("inputLabel");
ObservableList<String> dimensions = FXCollections.observableArrayList(
Eilert Tunheim
committed
"47x150",
"47x175",
"47x200",
"47x225",
"47x250",
"50x150",
"50x175",
"50x200",
"50x225",
"50x250"
Eilert Tunheim
committed
);
ComboBox<String> dimensionsList = new ComboBox<>(dimensions);
Eilert Tunheim
committed
dimensionsList.setPromptText("Select Dimensions");
dimensionsList.setId("inputDropDownBox");
dimensionsList.setEditable(true);
Eilert Tunheim
committed
Label sawsetInputLabel = new Label("Sawset");
sawsetInputLabel.setId("inputLabel");
Eilert Tunheim
committed
ObservableList<String> sawset = FXCollections.observableArrayList(
"1ex",
"2ex",
"3ex",
"4ex"
);
ComboBox<String> sawsetList = new ComboBox<>(sawset);
Eilert Tunheim
committed
sawsetList.setPromptText("Select Dimensions");
sawsetList.setId("inputDropDownBox");
sawsetList.setEditable(true);
Eilert Tunheim
committed
Eilert Tunheim
committed
Label moistureGoalInputLabel = new Label("Moisture Goal");
moistureGoalInputLabel.setId("inputLabel");
Eilert Tunheim
committed
ObservableList<String> moistureGoal = FXCollections.observableArrayList(
"10%",
"12%",
"14%",
"16%",
"18%",
"20%"
);
ComboBox<String> moistureList = new ComboBox<>(moistureGoal);
Eilert Tunheim
committed
moistureList.setPromptText("Select Dimensions");
moistureList.setId("inputDropDownBox");
moistureList.setEditable(true);
Eilert Tunheim
committed
// Bottom - start button
Button startButton = new Button("Start");
startButton.setId("inputButtonStart");
startButton.setOnAction(e -> {
// Sets the start time
START_TIME = TODAYS_DATE;
Eilert Tunheim
committed
// Retrieves the user inputs
TREE_SPECIES = treeSpeciesList.getValue();
DIMENSIONS = dimensionsList.getValue();
SAWSET = sawsetList.getValue();
if(moistureList.getValue() != null && moistureList.getValue().contains("%"))
{
MOISTURE_GOAL = moistureList.getValue().replace("%","");
} else {
MOISTURE_GOAL = moistureList.getValue();
}
Eilert Tunheim
committed
Eilert Tunheim
committed
// If the input is null, sets the value to be empty
if (treeSpeciesList.getValue() == null) {
TREE_SPECIES = "";
}
if (dimensionsList.getValue() == null) {
DIMENSIONS = "";
}
if (sawsetList.getValue() == null) {
SAWSET = "";
}
if (moistureList.getValue() == null) {
MOISTURE_GOAL = "";
}
Eilert Tunheim
committed
Eilert Tunheim
committed
setTreeSpeciesText(TREE_SPECIES);
setDimensionsText(DIMENSIONS);
setSawsetText(SAWSET);
setMoistureGoalText(MOISTURE_GOAL);
Eilert Tunheim
committed
window.close();
/*
FutureTask[] randomNumberTasks = new FutureTask[1];
Callable callable = new CallableExample();
randomNumberTasks[0] = new FutureTask(callable);
Thread t = new Thread(randomNumberTasks[0]);
t.start();
try {
System.out.println(randomNumberTasks[0].get());
} catch (InterruptedException | ExecutionException ex) {
ex.printStackTrace();
}
});
*/
/*
Eilert Tunheim
committed
try {
//getData();
loadSingleSeries(setInputParameters());
Eilert Tunheim
committed
//loadMultipleSeries(setInputParameters());
//loadSingleSeries();
//loadMultipleSeries();
} catch (Exception ex) {
ex.printStackTrace();
}
}
);
*/
Eilert Tunheim
committed
try{
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
// Henter her data fra databasen
loadSingleSeries(setInputParameters(false,false,false,false));
Eilert Tunheim
committed
//loadSingleSeries();
//loadMultipleSeries();
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
thread.start();
} catch (Exception ex) {
ex.printStackTrace();
}
}
);
Eilert Tunheim
committed
// Fungerende ny thread!!@@@@@
try{
try {
// Henter her data fra databasen
Map<Integer, Map<String, Number>> data = setInputParameters();
Platform.runLater(() -> {
try {
loadSingleSeries(data);
} catch (Exception ex) {
ex.printStackTrace();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}
);
thread.setDaemon(true);
thread.start();
} catch (Exception ex) {
ex.printStackTrace();
}
// Retrieve data for current drying period
try{
Thread thread = new Thread(() -> {
try {
// Henter her data fra databasen
Map<String, Number> data = getCurrentDrying();
Platform.runLater(() -> {
try {
//loadSingleSeries(data);
} catch (Exception ex) {
ex.printStackTrace();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}
);
thread.setDaemon(true);
thread.start();
} catch (Exception ex) {
ex.printStackTrace();
}
}
);
Eilert Tunheim
committed
/*
// Fungerende ny thread!!@@@@@
try{
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
// Henter her data fra databasen
loadSingleSeries(setInputParameters());
//loadSingleSeries();
//loadMultipleSeries();
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
thread.start();
} catch (Exception ex) {
ex.printStackTrace();
}
}
Eilert Tunheim
committed
);
*/
Eilert Tunheim
committed
/*
class KwhThread implements Runnable {
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
Map<Integer, Map<String, Number>> dataVariable;
private volatile boolean finished;
@Override
public void run() {
try{
dataVariable = setInputParameters();
} catch (Exception ex) {
ex.printStackTrace();
}
finished = true;
synchronized (this){
this.notify();
}
}
public Map<Integer, Map<String, Number>> getDataVariable() throws InterruptedException {
synchronized (this){
if(!finished)
this.wait();
}
return dataVariable;
}
}
KwhThread kwhThread = new KwhThread();
Thread thread = new Thread(kwhThread);
thread.setName("GetKwhThread");
thread.start();
loadSingleSeries(kwhThread.getDataVariable());
} catch (Exception ex) {
ex.printStackTrace();
}
Eilert Tunheim
committed
*/
Eilert Tunheim
committed
/*
Eilert Tunheim
committed
*/
Eilert Tunheim
committed
VBox layout = new VBox(10);
Eilert Tunheim
committed
layout.getChildren().addAll(inputLabel, treeSpeciesInputLabel, treeSpeciesList, dimensionsInputLabel, dimensionsList,
sawsetInputLabel, sawsetList, moistureGoalInputLabel, moistureList, startButton);
Eilert Tunheim
committed
layout.setAlignment(Pos.CENTER);
Scene scene = new Scene(layout, 600, 500);
scene.getStylesheets().add(InputPopUpWindow.class.getResource("/com.application/CSS/styleSheet.css").toExternalForm());
Eilert Tunheim
committed
window.setScene(scene);
window.showAndWait();