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();
}
panel.add(lblPrice, gbc);
gbc.gridx = 1;
panel.add(txtPrice, gbc);
-
gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridwidth = 2;
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);
* @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");
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;
}
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(rbMedium, gbc);
gbc.gridx = 2;
panel.add(rbLarge, gbc);
-
y++;
gbc.gridx = 0;
gbc.gridy = y;
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);