From: Robin Cheney Date: Mon, 1 Dec 2025 08:43:47 +0000 (+0100) Subject: Reworked some tabs X-Git-Url: https://git.eternal.ddnss.de/?a=commitdiff_plain;h=d385f2604609b80c45734ddcba58cc2c100ef419;p=tankstelle.git Reworked some tabs Some refactoring (moved the core .java files into .core package) Introduced two new error classes (FuelTypeException, NoFuelTypeSelectedError) Moved FuelRow record to separate file Added some fail safe checks to give proper feedback --- diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/FuelStationUI.java.old b/src/main/java/de/diejungsvondertanke/tankstelle/FuelStationUI.java.old deleted file mode 100644 index 54c1f26..0000000 --- a/src/main/java/de/diejungsvondertanke/tankstelle/FuelStationUI.java.old +++ /dev/null @@ -1,593 +0,0 @@ -package de.diejungsvondertanke.tankstelle; - -import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError; - -import javax.swing.*; -import javax.swing.table.DefaultTableModel; -import java.awt.*; -import java.util.List; - -/** - * GUI for fuel stations - * - * @author Sergej Pavlenko - */ -public class FuelStationUI extends JFrame { - - private JComboBox comboFuelStations; - private JComboBox comboFuelTypes; - private JTextArea outputArea; - private JPanel contentPane = new JPanel(); - private JList listFuelStations; - private JTable tableFuelTypesPerStation; - private javax.swing.table.DefaultTableModel fuelTableModel; - - public FuelStationUI() { - setContentPane(contentPane); - setTitle("Fuel Station Management System"); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setSize(800, 600); - setLocationRelativeTo(null); - - initComponents(); - } - - /** - * Layout for GUI - * - * @author Sergej Pavlenko - */ - private void initComponents() { - setLayout(new BorderLayout()); - - JPanel selectionPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - - comboFuelStations = new JComboBox<>(buildStationNames()); - comboFuelTypes = new JComboBox<>(FuelType.values()); - - listFuelStations = new JList<>(); - listFuelStations.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); - - refreshStationNames(); - - selectionPanel.add(new JLabel("Fuel station:")); - selectionPanel.add(comboFuelStations); - selectionPanel.add(new JLabel("Fuel type:")); - selectionPanel.add(comboFuelTypes); - - add(selectionPanel, BorderLayout.NORTH); - - JTabbedPane tabbedPane = new JTabbedPane(); - tabbedPane.addTab("Result", createResultPanel()); - tabbedPane.addTab("Change price", createPricePanel()); - tabbedPane.addTab("Change stock", createStockPanel()); - tabbedPane.addTab("Search", createSearchPanel()); - tabbedPane.addTab("New fuel station", createNewFuelStationPanel()); - tabbedPane.addTab("Overview", createOverviewPanel()); - - add(tabbedPane, BorderLayout.CENTER); - - outputArea = new JTextArea(); - outputArea.setEditable(false); - outputArea.setLineWrap(true); - outputArea.setWrapStyleWord(true); - JScrollPane scrollPane = new JScrollPane(outputArea); - scrollPane.setPreferredSize(new Dimension(800, 150)); - add(scrollPane, BorderLayout.SOUTH); - } - - /** - * Creates names for the fuel stations - * - * @return fuel station names - * - * @author Sergej Pavlenko - */ - private String[] buildStationNames() { - List stations = Main.fuelStations; - String[] names = new String[stations.size()]; - for (int i = 0; i < stations.size(); i++) { - FuelStation fs = stations.get(i); - String typeName = fs.getClass().getSimpleName(); - names[i] = "Station " + (i + 1) + " (" + typeName + ")"; - } - return names; - } - - /** - * Getter method - * - * @return selected fuel station - * - * @author Sergej Pavlenko - */ - private FuelStation getSelectedStation() { - int idx = comboFuelStations.getSelectedIndex(); - if (idx < 0 || idx >= Main.fuelStations.size()) { - return null; - } - return Main.fuelStations.get(idx); - } - - /** - * Create Panel for results of arithmetic operations - * - * @return result panel - * - * @author Sergej Pavlenko - */ - private JPanel createResultPanel() { - JPanel panel = new JPanel(new BorderLayout()); - - JPanel buttonPanel = new JPanel(new GridLayout(0, 1, 5, 5)); - - JButton btnTotalPrice = new JButton("Total selling value of all available fuel types"); - btnTotalPrice.addActionListener(e -> { - float sum = 0f; - for (FuelStation station : Main.fuelStations) { - sum += station.get_cumulative_retail_price(); - } - appendOutput(String.format( - "Total selling value of all available fuel types: %.2f €", sum)); - }); - - JButton btnHighestPrice = new JButton("Fuel station with highest price (chosen fuel type)"); - btnHighestPrice.addActionListener(e -> { - FuelType type = (FuelType) comboFuelTypes.getSelectedItem(); - try { - FuelStation fs = Main.getHighestPrice(type); - appendOutput("Fuel station with highest price for " + type + ": " - + getDisplayName(fs)); - } catch (NoSuchFuelTypeError ex) { - showError("No fitting fuel station with chosen fuel type " + type + " found."); - } - }); - - JButton btnHighestTotalValue = new JButton("Fuel station with highest total value of all available fuel types"); - btnHighestTotalValue.addActionListener(e -> { - try { - FuelStation fs = Main.getHighestAccumulatedValue(); - appendOutput("Fuel station with highest total value of all available fuel types: " - + getDisplayName(fs)); - } catch (NoSuchFuelTypeError ex) { - showError("Error when calculating highest total value."); - } - }); - - JButton btnStock = new JButton("Highest / lowest stock (chosen fuel type)"); - btnStock.addActionListener(e -> { - FuelType type = (FuelType) comboFuelTypes.getSelectedItem(); - try { - FuelStation max = Main.getHighestStoredAmount(type); - FuelStation min = Main.getLowestStoredAmount(type); - appendOutput("For fuel type " + type + ":\n" + - " Highest stock: " + getDisplayName(max) + "\n" + - " Lowest stock: " + getDisplayName(min)); - } catch (NoSuchFuelTypeError ex) { - showError("No fitting fuel station with fuel type " + type + " found."); - } - }); - - JButton btnTotalStock = new JButton("Total stock (chosen fuel station, chosen fuel type)"); - btnTotalStock.addActionListener(e -> { - FuelType type = (FuelType) comboFuelTypes.getSelectedItem(); - int[] indices = listFuelStations.getSelectedIndices(); - - if (indices.length == 0) { - showError("Please select at least one fuel station."); - return; - } - - FuelStation[] selectedStations = new FuelStation[indices.length]; - for (int i = 0; i < indices.length; i++) { - selectedStations[i] = Main.fuelStations.get(indices[i]); - } - - float total = Main.getTotalStockLevelOfFuel(type, selectedStations); - appendOutput(String.format("Total stock of %s across %d chosen fuel stations: %.2f L", type, indices.length, - total)); - }); - - buttonPanel.add(btnTotalPrice); - buttonPanel.add(btnHighestPrice); - buttonPanel.add(btnHighestTotalValue); - buttonPanel.add(btnStock); - buttonPanel.add(btnTotalStock); - - JScrollPane listScroller = new JScrollPane(listFuelStations); - listScroller.setPreferredSize(new Dimension(250, 0)); - - JPanel listPanel = new JPanel(new BorderLayout()); - listPanel.add(new JLabel("Fuel station selection (multiple possible):"), BorderLayout.NORTH); - listPanel.add(listFuelStations, BorderLayout.CENTER); - - panel.add(buttonPanel, BorderLayout.CENTER); - panel.add(listScroller, BorderLayout.EAST); - panel.add(listPanel, BorderLayout.EAST); - - return panel; - } - - /** - * Create Panel for price changing - * - * @return price changing Panel - * - * @author Sergej Pavlenko - */ - private JPanel createPricePanel() { - JPanel panel = new JPanel(new GridBagLayout()); - GridBagConstraints gbc = new GridBagConstraints(); - gbc.insets = new Insets(5, 5, 5, 5); - gbc.fill = GridBagConstraints.HORIZONTAL; - - JLabel lblPrice = new JLabel("New price per litre (€):"); - JTextField txtPrice = new JTextField(10); - JButton btnSave = new JButton("Change price"); - - btnSave.addActionListener(e -> { - FuelStation station = getSelectedStation(); - FuelType type = (FuelType) comboFuelTypes.getSelectedItem(); - if (station == null) { - showError("No fuel station chosen."); - return; - } - try { - float newPrice = Float.parseFloat(txtPrice.getText().replace(",", ".")); - station.set_price(type, newPrice); - appendOutput(String.format( - "Price changed of %s at %s to %.3f €/L.", - type, getDisplayName(station), newPrice)); - txtPrice.setText(""); - } catch (NumberFormatException ex) { - showError("Please enter a valid number for the price."); - } catch (NoSuchFuelTypeError ex) { - showError("This fuel station does not offer the fuel type " + type); - } - }); - - gbc.gridx = 0; - gbc.gridy = 0; - panel.add(lblPrice, gbc); - gbc.gridx = 1; - panel.add(txtPrice, gbc); - - gbc.gridx = 0; - gbc.gridy = 1; - gbc.gridwidth = 2; - panel.add(btnSave, gbc); - - return panel; - } - - /** - * Create Panel to change stock - * - * @author Sergej Pavlenko - */ - private JPanel createStockPanel() { - JPanel panel = new JPanel(new GridBagLayout()); - GridBagConstraints gbc = new GridBagConstraints(); - gbc.insets = new Insets(5, 5, 5, 5); - gbc.fill = GridBagConstraints.HORIZONTAL; - - JLabel lblAmount = new JLabel("Amount (litre):"); - JTextField txtAmount = new JTextField(10); - JRadioButton rbAbsolute = new JRadioButton("Set absolute amount", true); - JRadioButton rbDelta = new JRadioButton("Change amount (+/-)"); - ButtonGroup group = new ButtonGroup(); - group.add(rbAbsolute); - group.add(rbDelta); - - JButton btnSave = new JButton("Change stock"); - - btnSave.addActionListener(e -> { - FuelStation station = getSelectedStation(); - FuelType type = (FuelType) comboFuelTypes.getSelectedItem(); - if (station == null) { - showError("No fuel station chosen."); - return; - } - try { - float value = Float.parseFloat(txtAmount.getText().replace(",", ".")); - int capacity = getCapacity(station, type); - float current = station.getStored_amount(type); - - if (rbAbsolute.isSelected()) { - if (value < 0) { - showError("Please enter a positive number"); - return; - } - if (value > capacity) { - showError("Maximum capacity of " + capacity + " L is being crossed."); - return; - } - station.set_stored_amount(value, type); - appendOutput(String.format( - "Changed stock of %s at %s to %.2f litre.", - type, getDisplayName(station), value)); - txtAmount.setText(""); - } else { - float updated = current + value; - if (updated < 0) { - showError("The amount of fuel may not be negative."); - return; - } - if (updated > capacity) { - showError("Maximum capacity of " + capacity + " L is being crossed."); - return; - } - - station.add_stored_amount(value, type); - appendOutput(String.format( - "Stock changed of %s at %s by %.2f litre.", - type, getDisplayName(station), value)); - txtAmount.setText(""); - } - } catch (NumberFormatException ex) { - showError("Please enter a valid number for the amount."); - } catch (ArithmeticException ex) { - showError("Error: " + ex.getMessage()); - } catch (NoSuchFuelTypeError ex) { - showError("This fuel station does not offer the fuel type " + type); - } - }); - - int y = 0; - gbc.gridx = 0; - gbc.gridy = y; - panel.add(lblAmount, gbc); - gbc.gridx = 1; - panel.add(txtAmount, gbc); - - y++; - gbc.gridx = 0; - gbc.gridy = y; - gbc.gridwidth = 2; - panel.add(rbAbsolute, gbc); - - y++; - gbc.gridy = y; - panel.add(rbDelta, gbc); - - y++; - gbc.gridy = y; - panel.add(btnSave, gbc); - - return panel; - } - - private int getCapacity(FuelStation station, FuelType type) throws NoSuchFuelTypeError { - for (Fuel f : station.fuels) { - if (f.FUEL_TYPE == type) { - return f.CAPACITY; - } - } - throw new NoSuchFuelTypeError("This fuel station does not offer the fuel type " + type); - } - - /** - * Create Panel for searching for a fuel station with a specific fuel type - * - * @author Sergej Pavlenko - */ - private JPanel createSearchPanel() { - JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - - JButton btnListFuelStations = new JButton("Show fuel stations with chosen fuel type"); - btnListFuelStations.addActionListener(e -> { - FuelType type = (FuelType) comboFuelTypes.getSelectedItem(); - StringBuilder sb = new StringBuilder(); - sb.append("Fuel station with fuel type ").append(type).append(":\n"); - for (FuelStation station : Main.fuelStations) { - try { - station.getStored_amount(type); - sb.append(" - ").append(getDisplayName(station)).append("\n"); - } catch (NoSuchFuelTypeError ex) { - } - } - appendOutput(sb.toString()); - }); - - panel.add(btnListFuelStations); - return panel; - } - - /** - * Create Panel for making new fuel stations - * - * @author Sergej Pavlenko - */ - private JPanel createNewFuelStationPanel() { - JPanel panel = new JPanel(new GridBagLayout()); - GridBagConstraints gbc = new GridBagConstraints(); - gbc.insets = new Insets(5, 5, 5, 5); - gbc.fill = GridBagConstraints.HORIZONTAL; - gbc.anchor = GridBagConstraints.WEST; - - JRadioButton rbSmall = new JRadioButton("Small fuel station", true); - JRadioButton rbMedium = new JRadioButton("Medium fuel station", true); - JRadioButton rbLarge = new JRadioButton("Large fuel station", true); - - ButtonGroup buttonGroup = new ButtonGroup(); - buttonGroup.add(rbSmall); - buttonGroup.add(rbMedium); - buttonGroup.add(rbLarge); - - JLabel lblAtrributes = new JLabel("Special attribute:"); - JTextField txtAtrributes = new JTextField(15); - JLabel lblHint = new JLabel("Small: amount of vending machines, Medium: m^2, Large: supermarket-company"); - - JButton btnAdd = new JButton("Add fuel station"); - btnAdd.addActionListener(e -> { - try { - if (rbSmall.isSelected()) { - short vendingMachines = Short.parseShort(txtAtrributes.getText().trim()); - Main.addNewFuelStation(vendingMachines); - appendOutput("Fuel station with " + vendingMachines + " vending machines has been added."); - } else if (rbMedium.isSelected()) { - float retailSpace = Float.parseFloat(txtAtrributes.getText().replace(",", ".").trim()); - Main.addNewFuelStation(retailSpace); - appendOutput("Fuel station with " + retailSpace + " m^2 retail space has been added."); - } else if (rbLarge.isSelected()) { - String supermarketCompany = txtAtrributes.getText().trim(); - Main.addNewFuelStation(supermarketCompany); - appendOutput("Fuel station with supermarket-company" + supermarketCompany + " has been added."); - } - refreshStationNames(); - txtAtrributes.setText(""); - } catch (NumberFormatException ex) { - showError("Please enter a valid number (for small / medium)."); - } catch (IllegalArgumentException ex) { - showError(ex.getMessage()); - } - }); - - int y = 0; - gbc.gridx = 0; - gbc.gridy = y; - gbc.gridwidth = 3; - panel.add(new JLabel("Type of new fuel station:"), gbc); - - y++; - gbc.gridy = y; - gbc.gridwidth = 1; - panel.add(rbSmall, gbc); - gbc.gridx = 1; - panel.add(rbMedium, gbc); - gbc.gridx = 2; - panel.add(rbLarge, gbc); - - y++; - gbc.gridx = 0; - gbc.gridy = y; - panel.add(lblAtrributes, gbc); - gbc.gridx = 1; - gbc.gridwidth = 2; - panel.add(txtAtrributes, gbc); - - y++; - gbc.gridx = 0; - gbc.gridy = y; - gbc.gridwidth = 3; - panel.add(lblHint, gbc); - - y++; - gbc.gridy = y; - panel.add(btnAdd, gbc); - - return panel; - } - - /** - * Create Panel for overview of fuel stations - * - * @return overview Panel - * - * @author Sergej Pavlenko - */ - private JPanel createOverviewPanel() { - JPanel panel = new JPanel(new BorderLayout()); - - fuelTableModel = new DefaultTableModel( - new Object[] { "Fuel station", "Station type", "Fuel", "Amount (L)", "Capacity (L)", "Price (€/L)" }, - 0) { - @Override - public boolean isCellEditable(int row, int column) { - return false; - } - }; - - tableFuelTypesPerStation = new JTable(fuelTableModel); - - JScrollPane scrollPane = new JScrollPane(tableFuelTypesPerStation); - - JButton btnRefresh = new JButton("Refresh"); - btnRefresh.addActionListener(e -> refreshFuelTable()); - - JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - topPanel.add(new JLabel("Overview of all fuels per fuel station")); - topPanel.add(btnRefresh); - - panel.add(topPanel, BorderLayout.NORTH); - panel.add(scrollPane, BorderLayout.CENTER); - - refreshFuelTable(); - - return panel; - } - - /** - * Updates the selection of fuel stations for ComboBox and List - * - * @author Sergej Pavlenko - */ - private void refreshStationNames() { - String[] names = buildStationNames(); - - comboFuelStations.setModel(new DefaultComboBoxModel<>(names)); - - listFuelStations.setListData(names); - } - - /** - * Updates table to keep up with changes - * - * @author Sergej Pavlenko - */ - private void refreshFuelTable() { - if (fuelTableModel == null) { - return; - } - - fuelTableModel.setRowCount(0); - - for (FuelStation station : Main.fuelStations) { - String stationName = getDisplayName(station); - String stationType = station.getClass().getSimpleName(); - - for (Fuel fuel : station.fuels) { - Object[] row = new Object[] { - stationName, - stationType, - fuel.FUEL_TYPE, - fuel.getStored_amount(), - fuel.CAPACITY, - fuel.getPrice() - }; - fuelTableModel.addRow(row); - } - } - } - - private String getDisplayName(FuelStation station) { - int index = Main.fuelStations.indexOf(station); - if (index >= 0 && index < comboFuelStations.getItemCount()) { - return comboFuelStations.getItemAt(index); - } - return station.getClass().getSimpleName(); - } - - /** - * Creates a text output area - * - * @param text text output area - * - * @author Sergej Pavlenko - */ - private void appendOutput(String text) { - outputArea.append(text + "\n\n"); - outputArea.setCaretPosition(outputArea.getDocument().getLength()); - } - - /** - * Creates an error message - * - * @param message error message - * - * @author Sergej Pavlenko - */ - private void showError(String message) { - JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE); - } -} diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/FuelStationUIController.java b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/FuelStationUIController.java index 6be6532..64c8fde 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/FuelStationUIController.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/FuelStationUIController.java @@ -3,7 +3,9 @@ package de.diejungsvondertanke.tankstelle.controllers; import java.io.IOException; import java.util.function.Consumer; -import de.diejungsvondertanke.tankstelle.*; +import de.diejungsvondertanke.tankstelle.core.FuelStation; +import de.diejungsvondertanke.tankstelle.core.FuelType; +import de.diejungsvondertanke.tankstelle.core.Main; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; @@ -71,11 +73,14 @@ public class FuelStationUIController { * If not done correctly, using the controller in the subtabs WILL FAIL. * * USING THE CONTROLLER OBJECT INSIDE THE {@code initialize()} FUNCTION OF THE - * SUBTABS IS NOT PERMITTED AND WILL ALWAYS BE {@code null} DUE TO TIMING + * SUBTABS WILL NOT WORK AND WILL ALWAYS BE {@code null} DUE TO TIMING ISSUES */ @FXML public void initialize() { - // Load all tabs manually and keep controllers + /* + * Load all tabs manually and keep controllers + * If anyone asks, yes, this is necessary + */ comboFuelTypes.getItems().setAll(FuelType.values()); try { @@ -114,21 +119,21 @@ public class FuelStationUIController { }); } catch (Exception e) { e.printStackTrace(); - // TODO: handle exception } + // refresh every display refreshStationNames(); } /** * Generic tab loader helper * - * @param I have no idea what this does other than generalise - * the type for the consumer + * @param Controller class * @param fxmlPath Path to the .fxml resource file * @param container A container that inherits from {@link Parent}, for * example {@link GridPane}, {@link HBoc} or * {@link BorderPane} - * @param controllerConsumer A {@link Consumer} to + * @param controllerConsumer A {@link Consumer} to recieve the controller object + * from the loaded Tab * @throws IOException If loading the Tab failed because the .fxml file was not * found */ @@ -155,7 +160,7 @@ public class FuelStationUIController { * 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 + * @return The selected fuel station or {@code null} if none selected */ public FuelStation getSelectedStation() { int idx = comboFuelStations.getSelectionModel().getSelectedIndex(); @@ -182,8 +187,8 @@ public class FuelStationUIController { /** * Create some display String for the fuel station lists in the UI * - * @param fs a {@link FuelStation} object to get the display name for - * @return the display name string + * @param fs A {@link FuelStation} object to get the display name for + * @return The display name string */ public String getDisplayName(FuelStation fs) { int index = Main.fuelStations.indexOf(fs); diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/NewStationTabController.java b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/NewStationTabController.java index eae4e16..3904e1b 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/NewStationTabController.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/NewStationTabController.java @@ -1,6 +1,6 @@ package de.diejungsvondertanke.tankstelle.controllers; -import de.diejungsvondertanke.tankstelle.Main; +import de.diejungsvondertanke.tankstelle.core.Main; import javafx.fxml.FXML; import javafx.scene.control.Label; import javafx.scene.control.RadioButton; diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/OverviewTabController.java b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/OverviewTabController.java index 3b5d55c..d78ccb6 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/OverviewTabController.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/OverviewTabController.java @@ -1,8 +1,10 @@ package de.diejungsvondertanke.tankstelle.controllers; -import de.diejungsvondertanke.tankstelle.Fuel; -import de.diejungsvondertanke.tankstelle.FuelStation; -import de.diejungsvondertanke.tankstelle.Main; +import de.diejungsvondertanke.tankstelle.core.Fuel; +import de.diejungsvondertanke.tankstelle.core.FuelStation; +import de.diejungsvondertanke.tankstelle.core.Main; +import de.diejungsvondertanke.tankstelle.ui.FuelRow; + import javafx.beans.property.SimpleFloatProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; @@ -56,12 +58,12 @@ public class OverviewTabController { */ @FXML public void initialize() { - colStation.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().getStation())); - colType.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().getType())); - colFuel.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().getFuel())); - colAmount.setCellValueFactory(data -> new SimpleDoubleProperty(data.getValue().getAmount()).asObject()); - colCapacity.setCellValueFactory(data -> new SimpleIntegerProperty(data.getValue().getCapacity()).asObject()); - colPrice.setCellValueFactory(data -> new SimpleFloatProperty(data.getValue().getPrice()).asObject()); + colStation.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().station())); + colType.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().type())); + colFuel.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().fuel())); + colAmount.setCellValueFactory(data -> new SimpleDoubleProperty(data.getValue().amount()).asObject()); + colCapacity.setCellValueFactory(data -> new SimpleIntegerProperty(data.getValue().capacity()).asObject()); + colPrice.setCellValueFactory(data -> new SimpleFloatProperty(data.getValue().price()).asObject()); } /** @@ -124,184 +126,4 @@ public class OverviewTabController { } } - /** - * Glorified record class for the data rows from the table. - */ - public class FuelRow { - - String station; - String type; - String fuel; - double amount; - 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; - this.fuel = fuel; - this.amount = amount; - this.capacity = capacity; - this.price = price; - } - - } -} +} \ No newline at end of file diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/PriceTabController.java b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/PriceTabController.java index 27462f2..c429999 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/PriceTabController.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/PriceTabController.java @@ -1,7 +1,7 @@ package de.diejungsvondertanke.tankstelle.controllers; -import de.diejungsvondertanke.tankstelle.FuelStation; -import de.diejungsvondertanke.tankstelle.FuelType; +import de.diejungsvondertanke.tankstelle.core.FuelStation; +import de.diejungsvondertanke.tankstelle.core.FuelType; import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError; import javafx.fxml.FXML; import javafx.scene.control.TextField; @@ -38,7 +38,6 @@ public class PriceTabController { private void save() { FuelStation station = parentController.getSelectedStation(); FuelType type = parentController.comboFuelTypes.getValue(); - if (station == null) { parentController.showError("Select a station."); return; @@ -54,10 +53,10 @@ public class PriceTabController { txtPrice.clear(); parentController.refreshStationNames(); - } catch (NumberFormatException ex) { + } catch (NumberFormatException e) { parentController.showError("Invalid number."); - } catch (NoSuchFuelTypeError ex) { - parentController.showError("Fuel type not selected or unavailable."); + } catch (NoSuchFuelTypeError e) { + parentController.showError(e.getMessage()); } } } diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/ResultTabController.java b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/ResultTabController.java index d9c9ecb..97dd4fc 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/ResultTabController.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/ResultTabController.java @@ -1,8 +1,10 @@ package de.diejungsvondertanke.tankstelle.controllers; -import de.diejungsvondertanke.tankstelle.FuelStation; -import de.diejungsvondertanke.tankstelle.FuelType; -import de.diejungsvondertanke.tankstelle.Main; +import de.diejungsvondertanke.tankstelle.core.FuelStation; +import de.diejungsvondertanke.tankstelle.core.FuelType; +import de.diejungsvondertanke.tankstelle.core.Main; +import de.diejungsvondertanke.tankstelle.error.FuelTypeException; +import de.diejungsvondertanke.tankstelle.error.NoFuelTypeSelectedError; import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError; import javafx.fxml.FXML; import javafx.scene.control.ListView; @@ -64,8 +66,8 @@ public class ResultTabController { FuelStation fs = Main.getHighestPrice(type); parentController.appendOutput("Highest price for %s: %s" .formatted(type, parentController.getDisplayName(fs))); - } catch (NoSuchFuelTypeError ex) { - parentController.showError("Fuel type unavailable."); + } catch (FuelTypeException e) { + parentController.showError(e.getMessage()); } } @@ -77,13 +79,14 @@ public class ResultTabController { try { FuelStation fs = Main.getHighestAccumulatedValue(); parentController.appendOutput("Highest total value: " + parentController.getDisplayName(fs)); - } catch (NoSuchFuelTypeError ex) { - parentController.showError("Calculation error."); + } catch (NoSuchFuelTypeError e) { + parentController.showError(e.getMessage()); } } /** - * + * Calculate and display the lowest and highest stock for a selected + * {@link FuelType} */ @FXML private void handleStock() { @@ -96,8 +99,8 @@ public class ResultTabController { - Highest: %s - Lowest: %s """.formatted(type, parentController.getDisplayName(max), parentController.getDisplayName(min))); - } catch (NoSuchFuelTypeError e) { - parentController.showError("Fuel type unavailable."); + } catch (FuelTypeException e) { + parentController.showError(e.getMessage()); } } @@ -115,7 +118,12 @@ public class ResultTabController { .map(i -> Main.fuelStations.get(i)) .toArray(FuelStation[]::new); - float total = Main.getTotalStockLevelOfFuel(type, stations); - parentController.appendOutput("Total for %s: %.2f L".formatted(type, total)); + float total; + try { + total = Main.getTotalStockLevelOfFuel(type, stations); + parentController.appendOutput("Total for %s: %.2f L".formatted(type, total)); + } catch (NoFuelTypeSelectedError e) { + parentController.showError(e.getMessage()); + } } } diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/SearchTabController.java b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/SearchTabController.java index 1a9d121..bf97366 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/SearchTabController.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/SearchTabController.java @@ -1,8 +1,8 @@ package de.diejungsvondertanke.tankstelle.controllers; -import de.diejungsvondertanke.tankstelle.FuelStation; -import de.diejungsvondertanke.tankstelle.FuelType; -import de.diejungsvondertanke.tankstelle.Main; +import de.diejungsvondertanke.tankstelle.core.FuelStation; +import de.diejungsvondertanke.tankstelle.core.FuelType; +import de.diejungsvondertanke.tankstelle.core.Main; import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError; import javafx.fxml.FXML; diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/StockTabController.java b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/StockTabController.java index 778d6cd..732077c 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/StockTabController.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/StockTabController.java @@ -1,8 +1,8 @@ package de.diejungsvondertanke.tankstelle.controllers; -import de.diejungsvondertanke.tankstelle.Fuel; -import de.diejungsvondertanke.tankstelle.FuelStation; -import de.diejungsvondertanke.tankstelle.FuelType; +import de.diejungsvondertanke.tankstelle.core.Fuel; +import de.diejungsvondertanke.tankstelle.core.FuelStation; +import de.diejungsvondertanke.tankstelle.core.FuelType; import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError; import javafx.fxml.FXML; import javafx.scene.control.RadioButton; @@ -42,17 +42,17 @@ public class StockTabController { if (f.FUEL_TYPE == type) return f.CAPACITY; } - throw new NoSuchFuelTypeError("Fuel type not available"); + throw new NoSuchFuelTypeError("This fuel station does not have this type of fuel"); } /** - * Save stock changes to the selected fuel type for the selected station + * Save stock changes to the selected fuel type for the selected station and + * give the user some feedback */ @FXML private void save() { FuelStation station = parentController.getSelectedStation(); FuelType type = parentController.comboFuelTypes.getValue(); - if (station == null) { parentController.showError("Select a station."); return; @@ -65,7 +65,9 @@ public class StockTabController { if (rbAbsolute.isSelected()) { if (value < 0 || value > capacity) { - parentController.showError("Invalid amount."); + parentController.showError( + "Invalid amount. The stored amount cannot exceed the capacity (%dL) and must be greater or equal to 0" + .formatted(capacity)); return; } station.set_stored_amount(value, type); @@ -75,7 +77,9 @@ public class StockTabController { } else { double updated = current + value; if (updated < 0 || updated > capacity) { - parentController.showError("Out of capacity bounds."); + parentController.showError( + "Invalid amount. The stored amount cannot exceed the capacity (%dL) and must be greater or equal to 0" + .formatted(capacity)); return; } station.add_stored_amount(value, type); @@ -86,8 +90,8 @@ public class StockTabController { txtAmount.clear(); - } catch (Exception ex) { - parentController.showError(ex.getMessage()); + } catch (Exception e) { + parentController.showError(e.getMessage()); } } } diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/UnderstaffedTabController.java b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/UnderstaffedTabController.java index 55e4a01..4488ba9 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/UnderstaffedTabController.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/UnderstaffedTabController.java @@ -2,8 +2,8 @@ package de.diejungsvondertanke.tankstelle.controllers; import java.io.IOException; -import de.diejungsvondertanke.tankstelle.FuelStation; -import de.diejungsvondertanke.tankstelle.Main; +import de.diejungsvondertanke.tankstelle.core.FuelStation; +import de.diejungsvondertanke.tankstelle.core.Main; import javafx.fxml.FXML; import javafx.scene.control.TextField; @@ -37,21 +37,23 @@ public class UnderstaffedTabController { try { if (Main.isPINCorrect(pin.getText())) { - try { - if (Integer.parseInt(staffCount.getText()) <= Main.getTotalNumberOfEmployees()) { + int staffCountInt = Integer.parseInt(staffCount.getText()); + if (staffCountInt <= Main.getTotalNumberOfEmployees()) { + if (staffCountInt <= Main.getTotalNumberOfEmployees()) { String out = ""; for (FuelStation station : Main .getFuelStationListWhenUnderstaffed(Short.parseShort(staffCount.getText()))) { out += "\n - %s".formatted(parentController.getDisplayName(station)); } parentController.appendOutput("Fuel stations that can be operated:" + out); - } else { - parentController.appendOutput("You don't have that many employees!"); - } - } catch (Exception e) { + } else + parentController.showError("You can not have a negative employee count!"); + } else { + parentController.showError("You don't have that many employees!\nYou have %d." + .formatted(Main.getTotalNumberOfEmployees())); } } else { - parentController.appendOutput("invalid PIN"); + parentController.showError("Invalid PIN"); } } catch (IOException e) { } diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/Fuel.java b/src/main/java/de/diejungsvondertanke/tankstelle/core/Fuel.java similarity index 98% rename from src/main/java/de/diejungsvondertanke/tankstelle/Fuel.java rename to src/main/java/de/diejungsvondertanke/tankstelle/core/Fuel.java index 91a502e..4a25d1a 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/Fuel.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/core/Fuel.java @@ -1,4 +1,4 @@ -package de.diejungsvondertanke.tankstelle; +package de.diejungsvondertanke.tankstelle.core; /** * A fuel object. Contains fuel type, price per litre, stored fuel amount and diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/FuelStation.java b/src/main/java/de/diejungsvondertanke/tankstelle/core/FuelStation.java similarity index 99% rename from src/main/java/de/diejungsvondertanke/tankstelle/FuelStation.java rename to src/main/java/de/diejungsvondertanke/tankstelle/core/FuelStation.java index ea74a37..cc05f98 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/FuelStation.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/core/FuelStation.java @@ -1,4 +1,4 @@ -package de.diejungsvondertanke.tankstelle; +package de.diejungsvondertanke.tankstelle.core; import java.util.ArrayList; diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/FuelType.java b/src/main/java/de/diejungsvondertanke/tankstelle/core/FuelType.java similarity index 85% rename from src/main/java/de/diejungsvondertanke/tankstelle/FuelType.java rename to src/main/java/de/diejungsvondertanke/tankstelle/core/FuelType.java index 0912284..71c0016 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/FuelType.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/core/FuelType.java @@ -1,4 +1,4 @@ -package de.diejungsvondertanke.tankstelle; +package de.diejungsvondertanke.tankstelle.core; /** * Possible {@link Fuel fuel} types @@ -41,4 +41,8 @@ public enum FuelType { public String toString() { return name; } + + public static FuelType toEnum(String name) { + return FuelType.valueOf(name); + } } diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/LargeFuelStation.java b/src/main/java/de/diejungsvondertanke/tankstelle/core/LargeFuelStation.java similarity index 96% rename from src/main/java/de/diejungsvondertanke/tankstelle/LargeFuelStation.java rename to src/main/java/de/diejungsvondertanke/tankstelle/core/LargeFuelStation.java index ed4ab66..cea33aa 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/LargeFuelStation.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/core/LargeFuelStation.java @@ -1,4 +1,4 @@ -package de.diejungsvondertanke.tankstelle; +package de.diejungsvondertanke.tankstelle.core; /** * Large {@link FuelStation fuel station} diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/Main.java b/src/main/java/de/diejungsvondertanke/tankstelle/core/Main.java similarity index 94% rename from src/main/java/de/diejungsvondertanke/tankstelle/Main.java rename to src/main/java/de/diejungsvondertanke/tankstelle/core/Main.java index a895b39..7530930 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/Main.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/core/Main.java @@ -1,4 +1,4 @@ -package de.diejungsvondertanke.tankstelle; +package de.diejungsvondertanke.tankstelle.core; import java.io.BufferedReader; import java.io.IOException; @@ -6,6 +6,7 @@ import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; +import de.diejungsvondertanke.tankstelle.error.NoFuelTypeSelectedError; import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError; import de.diejungsvondertanke.tankstelle.ui.JFX; @@ -116,10 +117,13 @@ public class Main { * * @author Nils Göbbert */ - public static FuelStation getHighestPrice(FuelType fuelType) throws NoSuchFuelTypeError { + public static FuelStation getHighestPrice(FuelType fuelType) throws NoSuchFuelTypeError, NoFuelTypeSelectedError { FuelStation highestStation = null; float highestPrice = Float.NEGATIVE_INFINITY; + if (fuelType == null) + throw new NoFuelTypeSelectedError(); + for (FuelStation fuelStation : fuelStations) { try { float price = fuelStation.get_price(fuelType); @@ -128,7 +132,6 @@ public class Main { highestStation = fuelStation; } } catch (NoSuchFuelTypeError e) { - } } @@ -174,10 +177,12 @@ public class Main { * * @author Nils Göbbert */ - public static FuelStation getHighestStoredAmount(FuelType fuelType) throws NoSuchFuelTypeError { + public static FuelStation getHighestStoredAmount(FuelType fuelType) + throws NoSuchFuelTypeError, NoFuelTypeSelectedError { FuelStation highestStation = null; double highestAmount = Double.NEGATIVE_INFINITY; - + if (fuelType == null) + throw new NoFuelTypeSelectedError(); for (FuelStation fuelStation : fuelStations) { try { double amount = fuelStation.getStored_amount(fuelType); @@ -209,9 +214,12 @@ public class Main { * * @author Nils Göbbert */ - public static FuelStation getLowestStoredAmount(FuelType fuelType) throws NoSuchFuelTypeError { + public static FuelStation getLowestStoredAmount(FuelType fuelType) + throws NoSuchFuelTypeError, NoFuelTypeSelectedError { FuelStation lowestStation = null; double lowestAmount = Double.POSITIVE_INFINITY; + if (fuelType == null) + throw new NoFuelTypeSelectedError(); for (FuelStation fuelStation : fuelStations) { try { @@ -343,8 +351,11 @@ public class Main { * * @author Leander Schnurrer */ - public static float getTotalStockLevelOfFuel(FuelType fuelType, FuelStation[] fuelStations) { + public static float getTotalStockLevelOfFuel(FuelType fuelType, FuelStation[] fuelStations) + throws NoFuelTypeSelectedError { float sum = 0f; + if (fuelType == null) + throw new NoFuelTypeSelectedError(); for (FuelStation fuelStation : fuelStations) { for (Fuel fuel : fuelStation.fuels) { if (fuel.FUEL_TYPE == fuelType) { diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/MediumFuelStation.java b/src/main/java/de/diejungsvondertanke/tankstelle/core/MediumFuelStation.java similarity index 96% rename from src/main/java/de/diejungsvondertanke/tankstelle/MediumFuelStation.java rename to src/main/java/de/diejungsvondertanke/tankstelle/core/MediumFuelStation.java index 2ce9cc4..7a15b9f 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/MediumFuelStation.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/core/MediumFuelStation.java @@ -1,4 +1,4 @@ -package de.diejungsvondertanke.tankstelle; +package de.diejungsvondertanke.tankstelle.core; /** * Medium {@link FuelStation fuel station} diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/Size.java b/src/main/java/de/diejungsvondertanke/tankstelle/core/Size.java similarity index 91% rename from src/main/java/de/diejungsvondertanke/tankstelle/Size.java rename to src/main/java/de/diejungsvondertanke/tankstelle/core/Size.java index b406081..461dc11 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/Size.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/core/Size.java @@ -1,4 +1,4 @@ -package de.diejungsvondertanke.tankstelle; +package de.diejungsvondertanke.tankstelle.core; /** * The size of a {@link FuelStation fuel station}. Is more or less decorative, diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/SmallFuelStation.java b/src/main/java/de/diejungsvondertanke/tankstelle/core/SmallFuelStation.java similarity index 96% rename from src/main/java/de/diejungsvondertanke/tankstelle/SmallFuelStation.java rename to src/main/java/de/diejungsvondertanke/tankstelle/core/SmallFuelStation.java index 3abce91..e8002d6 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/SmallFuelStation.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/core/SmallFuelStation.java @@ -1,4 +1,4 @@ -package de.diejungsvondertanke.tankstelle; +package de.diejungsvondertanke.tankstelle.core; /** * Small {@link FuelStation fuel station} diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/error/FuelTypeException.java b/src/main/java/de/diejungsvondertanke/tankstelle/error/FuelTypeException.java new file mode 100644 index 0000000..22b6885 --- /dev/null +++ b/src/main/java/de/diejungsvondertanke/tankstelle/error/FuelTypeException.java @@ -0,0 +1,21 @@ +package de.diejungsvondertanke.tankstelle.error; + +import de.diejungsvondertanke.tankstelle.core.FuelType; + +/** + * Generic {@link FuelType} error class + * + * @author Robin Cheney + */ +public abstract class FuelTypeException extends Exception { + /** + * Throws a {@link NoFuelTypeSelectedError} + * + * @param message Message to throw with this error + * + * @author Robin Cheney + */ + public FuelTypeException(String message) { + super(message); + } +} diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/error/NoFuelTypeSelectedError.java b/src/main/java/de/diejungsvondertanke/tankstelle/error/NoFuelTypeSelectedError.java new file mode 100644 index 0000000..002befc --- /dev/null +++ b/src/main/java/de/diejungsvondertanke/tankstelle/error/NoFuelTypeSelectedError.java @@ -0,0 +1,29 @@ +package de.diejungsvondertanke.tankstelle.error; + +/** + * This Error is thrown on the attempt to get the selected fuel type whenever + * there is none selected + * + * @author Robin Cheney + */ +public class NoFuelTypeSelectedError extends FuelTypeException { + /** + * Throws a {@link NoFuelTypeSelectedError} + * + * @param message Message to throw with this error + * + * @author Robin Cheney + */ + public NoFuelTypeSelectedError(String message) { + super(message); + } + + /** + * Throws a {@link NoFuelTypeSelectedError} + * + * @author Robin Cheney + */ + public NoFuelTypeSelectedError() { + super("No fuel type selected"); + } +} diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/error/NoSuchFuelTypeError.java b/src/main/java/de/diejungsvondertanke/tankstelle/error/NoSuchFuelTypeError.java index 8c8851e..935272c 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/error/NoSuchFuelTypeError.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/error/NoSuchFuelTypeError.java @@ -6,7 +6,7 @@ package de.diejungsvondertanke.tankstelle.error; * * @author Robin Cheney */ -public class NoSuchFuelTypeError extends Exception { +public class NoSuchFuelTypeError extends FuelTypeException { /** * Throws a {@link NoSuchFuelTypeError} * @@ -24,6 +24,6 @@ public class NoSuchFuelTypeError extends Exception { * @author Robin Cheney */ public NoSuchFuelTypeError() { - super(); + super("This fuel station does not have this type of fuel"); } } diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/ui/FuelRow.java b/src/main/java/de/diejungsvondertanke/tankstelle/ui/FuelRow.java new file mode 100644 index 0000000..8243111 --- /dev/null +++ b/src/main/java/de/diejungsvondertanke/tankstelle/ui/FuelRow.java @@ -0,0 +1,10 @@ +package de.diejungsvondertanke.tankstelle.ui; + +/** + * Glorified record class for the data rows from the table. This is only used + * for the table in the "Overview" tab in the ui + * + * @author Robin Cheney + */ +public record FuelRow(String station, String type, String fuel, double amount, int capacity, float price) { +} \ No newline at end of file diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index a5e6182..8eaeebf 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -8,5 +8,5 @@ module tankstelle { opens de.diejungsvondertanke.tankstelle.controllers to javafx.fxml, javafx.graphics; - exports de.diejungsvondertanke.tankstelle; + exports de.diejungsvondertanke.tankstelle.core; } diff --git a/src/main/resources/ui/FuelStationUI.fxml b/src/main/resources/ui/FuelStationUI.fxml index 5c470b9..d53b3e5 100644 --- a/src/main/resources/ui/FuelStationUI.fxml +++ b/src/main/resources/ui/FuelStationUI.fxml @@ -39,12 +39,12 @@ - - - + + + diff --git a/src/main/resources/ui/UnderstaffedTab.fxml b/src/main/resources/ui/UnderstaffedTab.fxml index f1c01d7..3f27bc9 100644 --- a/src/main/resources/ui/UnderstaffedTab.fxml +++ b/src/main/resources/ui/UnderstaffedTab.fxml @@ -19,7 +19,7 @@ -