/**
* Fancy premium diesel
*/
- PREMIUM_DIESEL("Premium Diesel"),
+ PREMIUM_DIESEL("Premium diesel"),
/**
* Gas, Gas, Gas, I'm gonna step on the gas
*/
private FuelType(String name) {
this.name = name;
}
+
+ /**
+ * Use this to get a reasonable display name out of the fuel types
+ */
+ @Override
+ public String toString() {
+ return name;
+ }
}
/**
* Main controller class
+ *
+ * @author Sergej Pavlenko
+ * @author Robin Cheney
*/
public class FuelStationUIController {
controllerConsumer.accept(controller);
}
+ /**
+ * Get the {@link FuelStation} selected in the Drop-Down list at the top left of
+ * the screen
+ *
+ * @return the selected fuel station or {@code null} if none selected
+ */
public FuelStation getSelectedStation() {
int idx = comboFuelStations.getSelectionModel().getSelectedIndex();
if (idx < 0 || idx >= Main.fuelStations.size())
return Main.fuelStations.get(idx);
}
+ /**
+ * Refresh all station displays. MUST BE CALLED WHEN UPDATING ANYTHING, OR
+ * OTHERWISE NOT EVERYTHING WILL BE DISPLAYED UP-TO-DATE EVERYWHERE
+ */
@FXML
public void refreshStationNames() {
comboFuelStations.getItems().setAll(
return fs.getSimpleName();
}
+ /**
+ * Append the {@code text} to the output dialogue (with two linebreaks appended)
+ *
+ * @param text Text to put out
+ */
public void appendOutput(String text) {
outputArea.appendText(text + "\n\n");
}
+ /**
+ * Display an error window to inform the user of invalid input, or something
+ * else. Depends on the content of {@code msg}
+ *
+ * @param msg Error message to show in the lower body of the error window
+ */
public void showError(String msg) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setHeaderText("Error");
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
+/**
+ * Controller class for the "NewStation" Tab
+ *
+ * @author Sergej Pavlenko
+ * @author Robin Cheney
+ */
public class NewStationTabController {
@FXML
private FuelStationUIController parentController;
- // Called by parent after full initialization
+ /**
+ * For timing reasons this is a common method for every controller that is for a
+ * tab (not to confuse with the main window controller
+ * {@link FuelStationUIController}). This passes the controller object from the
+ * main controller to the controllers for the individual tabs as fields.
+ * Necessary, if you need to access any methods from the main controller, which
+ * is much likely the case
+ */
public void setParentController(FuelStationUIController parent) {
this.parentController = parent;
}
+ /**
+ * Change the label text for the attribute
+ */
@FXML
private void setAttributeTypeFromSmallStation() {
attrLabel.setText("Number of drink vending machines:");
}
+ /**
+ * Change the label text for the attribute
+ */
@FXML
private void setAttributeTypeFromMediumStation() {
attrLabel.setText("m² of retail space:");
}
+ /**
+ * Change the label text for the attribute
+ */
@FXML
private void setAttributeTypeFromLargeStation() {
attrLabel.setText("Company running the integrated supermarket:");
}
+ /**
+ * Add a new fuel station
+ */
@FXML
private void add() {
try {
import de.diejungsvondertanke.tankstelle.Fuel;
import de.diejungsvondertanke.tankstelle.FuelStation;
import de.diejungsvondertanke.tankstelle.Main;
-import javafx.application.Platform;
import javafx.beans.property.SimpleFloatProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
+/**
+ * Controller class for the "Overview" Tab
+ *
+ * @author Sergej Pavlenko
+ * @author Robin Cheney
+ */
public class OverviewTabController {
@FXML
private FuelStationUIController parentController;
- // Called by parent after full initialization
+ /**
+ * For timing reasons this is a common method for every controller that is for a
+ * tab (not to confuse with the main window controller
+ * {@link FuelStationUIController}). This passes the controller object from the
+ * main controller to the controllers for the individual tabs as fields.
+ * Necessary, if you need to access any methods from the main controller, which
+ * is much likely the case
+ */
public void setParentController(FuelStationUIController parent) {
this.parentController = parent;
}
+ /**
+ * initialize the table
+ */
@FXML
public void initialize() {
colStation.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().getStation()));
colPrice.setCellValueFactory(data -> new SimpleFloatProperty(data.getValue().getPrice()).asObject());
}
+ /**
+ * Refresh the table to sync with latest changes
+ */
@FXML
public void refresh() {
table.getItems().clear();
table.getItems().add(
new FuelRow(
parentController.getDisplayName(station),
- station.getClass().getSimpleName(),
+ station.getSimpleName(),
f.FUEL_TYPE.toString(),
f.getStored_amount(),
f.CAPACITY,
// table.setItems(list);
}
+ /**
+ * This is just a debugging function. Do not use in a production environment
+ *
+ * @param node A displayed {@link Node} (i. e. from one of the Tabs) to display
+ * a tree-like inner structure for
+ * @param depth max. recursion depth
+ */
public static void printNodeTree(Node node, int depth) {
// Indentation
String indent = " ".repeat(depth);
}
}
+ /**
+ * Glorified record class for the data rows from the table.
+ */
public class FuelRow {
String station;
int capacity;
float price;
+ /**
+ * Getter function
+ *
+ * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
+ * REAL STATION OBJECTS
+ *
+ * @return the fuel station DISPLAY NAME, NOT THE STATION OBJECT
+ */
public String getStation() {
return station;
}
+ /**
+ * Set the new display name for the fuel station.
+ *
+ * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
+ * REAL STATION OBJECTS
+ *
+ * @param station new display name
+ */
public void setStation(String station) {
this.station = station;
}
+ /**
+ * Getter function
+ *
+ * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
+ * REAL STATION OBJECTS
+ *
+ * @return the fuel station type as a string
+ */
public String getType() {
return type;
}
+ /**
+ * set new fuel station type as a string
+ *
+ * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
+ * REAL STATION OBJECTS
+ *
+ * @param type the new fuel station type
+ */
public void setType(String type) {
this.type = type;
}
+ /**
+ * Getter function
+ *
+ * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
+ * REAL STATION OBJECTS
+ *
+ * @return the fuel type
+ */
public String getFuel() {
return fuel;
}
+ /**
+ * Set new fuel type as a string
+ *
+ * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
+ * REAL STATION OBJECTS
+ *
+ * @param fuel new fuel type as a string
+ */
public void setFuel(String fuel) {
this.fuel = fuel;
}
+ /**
+ * Getter function
+ *
+ * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
+ * REAL STATION OBJECTS
+ *
+ * @return the stored fuel amount
+ */
public double getAmount() {
return amount;
}
+ /**
+ * Set new stored amount
+ *
+ * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
+ * REAL STATION OBJECTS
+ *
+ * @param amount new stored amount
+ */
public void setAmount(double amount) {
this.amount = amount;
}
+ /**
+ * Getter function
+ *
+ * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
+ * REAL STATION OBJECTS
+ *
+ * @return maximum fuel capacity
+ */
public int getCapacity() {
return capacity;
}
+ /**
+ * Set new maximum fuel capacity
+ *
+ * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
+ * REAL STATION OBJECTS
+ *
+ * @param capacity new maximum fuel capacity
+ */
public void setCapacity(int capacity) {
this.capacity = capacity;
}
+ /**
+ * Getter function
+ *
+ * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
+ * REAL STATION OBJECTS
+ *
+ * @return fuel price per litre
+ */
public float getPrice() {
return price;
}
+ /**
+ * Set new price per litre
+ *
+ * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
+ * REAL STATION OBJECTS
+ *
+ * @param price new price per litre
+ */
public void setPrice(float price) {
this.price = price;
}
+ /**
+ * constructs new FuelRows. This is used as a datatype in the "Overview" Tabs
+ * table
+ *
+ * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
+ * REAL STATION OBJECTS
+ *
+ * @param station display name for the fuel station
+ * @param type display name for the station type/size
+ * @param fuel display name for the fuel type
+ * @param amount stored amount of fuel
+ * @param capacity maximum capacity
+ * @param price price per litre
+ */
public FuelRow(String station, String type, String fuel, double amount, int capacity, float price) {
this.station = station;
this.type = type;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;
+/**
+ * Controller class for the "Price" Tab
+ *
+ * @author Sergej Pavlenko
+ * @author Robin Cheney
+ */
public class PriceTabController {
@FXML
private FuelStationUIController parentController;
- // Called by parent after full initialization
+ /**
+ * For timing reasons this is a common method for every controller that is for a
+ * tab (not to confuse with the main window controller
+ * {@link FuelStationUIController}). This passes the controller object from the
+ * main controller to the controllers for the individual tabs as fields.
+ * Necessary, if you need to access any methods from the main controller, which
+ * is much likely the case
+ */
public void setParentController(FuelStationUIController parent) {
this.parentController = parent;
}
+ /**
+ * Save the price change
+ */
@FXML
private void save() {
FuelStation station = parentController.getSelectedStation();
} catch (NumberFormatException ex) {
parentController.showError("Invalid number.");
} catch (NoSuchFuelTypeError ex) {
- parentController.showError("Fuel type unavailable.");
+ parentController.showError("Fuel type not selected or unavailable.");
}
}
}
import javafx.scene.control.ListView;
import javafx.scene.control.SelectionMode;
+/**
+ * Controller class for the "Result" Tab
+ *
+ * @author Sergej Pavlenko
+ * @author Robin Cheney
+ */
public class ResultTabController {
@FXML
listFuelStations.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
}
+ /**
+ * For timing reasons this is a common method for every controller that is for a
+ * tab (not to confuse with the main window controller
+ * {@link FuelStationUIController}). This passes the controller object from the
+ * main controller to the controllers for the individual tabs as fields.
+ * Necessary, if you need to access any methods from the main controller, which
+ * is much likely the case
+ */
public void setParentController(FuelStationUIController parentController) {
this.parentController = parentController;
}
}
}
- // Example action using parent
+ /**
+ * Output the total revenue if all fuel was sold at the set prices
+ */
@FXML
private void handleTotalPrice() {
if (parentController != null) {
}
}
+ /**
+ * Output the fuel station with the highest price for a fuel type
+ */
@FXML
private void handleHighestPrice() {
FuelType type = parentController.comboFuelTypes.getValue();
}
}
+ /**
+ * Output the fuel station with the lowest price for a fuel type
+ */
@FXML
private void handleHighestTotalValue() {
try {
}
}
+ /**
+ *
+ */
@FXML
private void handleStock() {
FuelType type = parentController.comboFuelTypes.getValue();
import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError;
import javafx.fxml.FXML;
+/**
+ * Controller class for the "Search" Tab
+ *
+ * @author Sergej Pavlenko
+ * @author Robin Cheney
+ */
public class SearchTabController {
private FuelStationUIController parentController;
- // Called by parent after full initialization
+ /**
+ * For timing reasons this is a common method for every controller that is for a
+ * tab (not to confuse with the main window controller
+ * {@link FuelStationUIController}). This passes the controller object from the
+ * main controller to the controllers for the individual tabs as fields.
+ * Necessary, if you need to access any methods from the main controller, which
+ * is much likely the case
+ */
public void setParentController(FuelStationUIController parent) {
this.parentController = parent;
}
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
+/**
+ * Controller class for the "Stock" Tab
+ *
+ * @author Sergej Pavlenko
+ * @author Robin Cheney
+ */
public class StockTabController {
@FXML
private FuelStationUIController parentController;
- // Called by parent after full initialization
+ /**
+ * For timing reasons this is a common method for every controller that is for a
+ * tab (not to confuse with the main window controller
+ * {@link FuelStationUIController}). This passes the controller object from the
+ * main controller to the controllers for the individual tabs as fields.
+ * Necessary, if you need to access any methods from the main controller, which
+ * is much likely the case
+ */
public void setParentController(FuelStationUIController parent) {
this.parentController = parent;
}
throw new NoSuchFuelTypeError("Fuel type not available");
}
+ /**
+ * Save stock changes to the selected fuel type for the selected station
+ */
@FXML
private void save() {
FuelStation station = parentController.getSelectedStation();
import javafx.fxml.FXML;
import javafx.scene.control.TextField;
+/**
+ * Controller class for the "Understaffed" Tab
+ *
+ * @author Sergej Pavlenko
+ * @author Robin Cheney
+ */
public class UnderstaffedTabController {
@FXML
private FuelStationUIController parentController;
- // Called by parent after full initialization
+ /**
+ * For timing reasons this is a common method for every controller that is for a
+ * tab (not to confuse with the main window controller
+ * {@link FuelStationUIController}). This passes the controller object from the
+ * main controller to the controllers for the individual tabs as fields.
+ * Necessary, if you need to access any methods from the main controller, which
+ * is much likely the case
+ */
public void setParentController(FuelStationUIController parent) {
this.parentController = parent;
}