]> Git Server - tankstelle.git/commitdiff
GUI für Tankstellen mit bestimmten Wert im speziellen Attribut hinzugefügt
authorSergej Pavlenko <sergepav0@gmail.com>
Sat, 22 Nov 2025 23:44:13 +0000 (00:44 +0100)
committerSergej Pavlenko <sergepav0@gmail.com>
Sat, 22 Nov 2025 23:44:13 +0000 (00:44 +0100)
src/main/java/de/diejungsvondertanke/tankstelle/FuelStationUI.java
src/main/java/de/diejungsvondertanke/tankstelle/Main.java

index 2d1a7c4a08f3817b8a6a07883461ef541893a5af..c9336980428c5a15d485c192cefb253b54168c2b 100644 (file)
@@ -30,8 +30,7 @@ public class FuelStationUI extends JFrame {
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         setSize(800, 600);
         setLocationRelativeTo(null);
-        setIconImage(new ImageIcon(
-                Main.class.getResource("/icon/AppIcon.png")).getImage());
+        setIconImage(new ImageIcon(Main.class.getResource("/icon/AppIcon.png")).getImage());
         initComponents();
     }
 
@@ -256,7 +255,6 @@ public class FuelStationUI extends JFrame {
         panel.add(lblPrice, gbc);
         gbc.gridx = 1;
         panel.add(txtPrice, gbc);
-
         gbc.gridx = 0;
         gbc.gridy = 1;
         gbc.gridwidth = 2;
@@ -345,17 +343,14 @@ public class FuelStationUI extends JFrame {
         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);
@@ -378,10 +373,12 @@ public class FuelStationUI extends JFrame {
      * @author Sergej Pavlenko
      */
     private JPanel createSearchPanel() {
-        JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+        JPanel panel = new JPanel();
+        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
 
-        JButton btnListFuelStations = new JButton("Show fuel stations with chosen fuel type");
-        btnListFuelStations.addActionListener(e -> {
+        JPanel searchFuelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+        JButton btnFuelStationsList = new JButton("Show fuel stations with chosen fuel type");
+        btnFuelStationsList.addActionListener(e -> {
             FuelType type = (FuelType) comboFuelTypes.getSelectedItem();
             StringBuilder sb = new StringBuilder();
             sb.append("Fuel station with fuel type ").append(type).append(":\n");
@@ -395,7 +392,108 @@ public class FuelStationUI extends JFrame {
             appendOutput(sb.toString());
         });
 
-        panel.add(btnListFuelStations);
+        searchFuelPanel.add(btnFuelStationsList);
+        panel.add(searchFuelPanel);
+
+        panel.add(new JSeparator(SwingConstants.HORIZONTAL));
+
+        JPanel searchSpecialAttributePanel = new JPanel(new GridBagLayout());
+        GridBagConstraints gbc = new GridBagConstraints();
+        gbc.insets = new Insets(5, 5, 5, 5);
+        gbc.fill = GridBagConstraints.HORIZONTAL;
+        gbc.anchor = GridBagConstraints.WEST;
+
+        JLabel lblTitle = new JLabel("Search special attribute:");
+        JLabel lblInfo = new JLabel("<html>Small: number of vending machines<br>" + "Medium: retail space(m²)<br>" + "Large: supermarket-company<html>");
+        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 lblSpecialAttributeValue = new JLabel("Special attribute value:");
+        JTextField txtSpecialAttributeValue = new JTextField(15);
+        JButton btnSearchSpecialAttribute = new JButton("Show fuel stations with chosen special attribute");
+
+        btnSearchSpecialAttribute.addActionListener(e -> {
+            String input = txtSpecialAttributeValue.getText().trim();
+            if (input.isEmpty()) {
+                showError("Please enter a special attribute value.");
+                return;
+            }
+
+            FuelStation[] result = new FuelStation[0];
+
+            try {
+                if (rbSmall.isSelected()) {
+                    short vendingMachines = Short.parseShort(input);
+                    result = Main.getFuelStations(vendingMachines);
+                } else if (rbMedium.isSelected()) {
+                    float retailSpace = Float.parseFloat(input.replace(",", "."));
+                    result = Main.getFuelStations(retailSpace);
+                } else if (rbLarge.isSelected()) {
+                    result = Main.getFuelStations(input);
+                }
+
+                StringBuilder stringBuilder = new StringBuilder();
+                stringBuilder.append("Search for special attribute:\n");
+
+                if (rbSmall.isSelected()) {
+                    stringBuilder.append("Small fuel station with " + input + " vending machines:\n");
+                } else if (rbMedium.isSelected()) {
+                    stringBuilder.append("Medium fuel station with " + input + "m² retail space:\n");
+                } else  if (rbLarge.isSelected()) {
+                    stringBuilder.append("Large fuel station with " + input + " as supermarket-company:\n");
+                }
+
+                if (result.length == 0) {
+                    stringBuilder.append("No fitting fuel stations found.");
+                } else  {
+                    stringBuilder.append("Found fitting fuel stations with chosen special attribute:\n");
+                    for (FuelStation station : result) {
+                        stringBuilder.append(" - " + getDisplayName(station) + "\n");
+                    }
+                }
+
+                txtSpecialAttributeValue.setText("");
+                appendOutput(stringBuilder.toString());
+            }  catch (NumberFormatException ex) {
+                showError("Please enter a valid number.");
+            }
+        });
+
+        int y = 0;
+        gbc.gridx = 0; gbc.gridy = y;
+        gbc.gridwidth = 2;
+        searchSpecialAttributePanel.add(lblTitle, gbc);
+        y++;
+        gbc.gridx = 0; gbc.gridy = y;
+        gbc.gridwidth = 2;
+        searchSpecialAttributePanel.add(lblInfo, gbc);
+        y++;
+        gbc.gridx = 0; gbc.gridy = y;
+        gbc.gridwidth = 1;
+        searchSpecialAttributePanel.add(rbSmall, gbc);
+        gbc.gridx = 1;
+        searchSpecialAttributePanel.add(rbMedium, gbc);
+        gbc.gridx = 2;
+        searchSpecialAttributePanel.add(rbLarge, gbc);
+        y++;
+        gbc.gridx = 0; gbc.gridy = y;
+        searchSpecialAttributePanel.add(lblSpecialAttributeValue, gbc);
+        gbc.gridx = 1;
+        gbc.gridwidth = 2;
+        searchSpecialAttributePanel.add(txtSpecialAttributeValue, gbc);
+        y++;
+        gbc.gridx = 0; gbc.gridy = y;
+        gbc.gridwidth = 3;
+        searchSpecialAttributePanel.add(btnSearchSpecialAttribute, gbc);
+
+        panel.add(searchSpecialAttributePanel);
+
         return panel;
     }
 
@@ -455,7 +553,6 @@ public class FuelStationUI extends JFrame {
         gbc.gridy = y;
         gbc.gridwidth = 3;
         panel.add(new JLabel("Type of new fuel station:"), gbc);
-
         y++;
         gbc.gridy = y;
         gbc.gridwidth = 1;
@@ -464,7 +561,6 @@ public class FuelStationUI extends JFrame {
         panel.add(rbMedium, gbc);
         gbc.gridx = 2;
         panel.add(rbLarge, gbc);
-
         y++;
         gbc.gridx = 0;
         gbc.gridy = y;
@@ -472,13 +568,11 @@ public class FuelStationUI extends JFrame {
         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);
index 0e0d38c377c023631112292058f9a49b0517cda5..f465f71207056a396160029166a3a9bba3bb9f38 100644 (file)
@@ -34,7 +34,7 @@ public class Main {
     /**
      * Main method
      * 
-     * @param args Program arguments (not in use)
+     * @param args Program arguments
      */
     public static void main(String[] args) {
         javax.swing.SwingUtilities.invokeLater(() -> {