From 2040af37fc080b1b42d8f6ad2b6723d68a951c94 Mon Sep 17 00:00:00 2001 From: DjonniStorm Date: Sun, 12 May 2024 01:21:57 +0400 Subject: [PATCH 1/7] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=964=20(1=20=D1=87=D0=B0=D1=81=D1=82=D1=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CollectionType.java | 7 + .../ListGenericObjects.java | 56 ++++++ .../StorageCollection.java | 39 ++++ .../src/FormCleaningCarCollection.form | 186 +++++++++++++----- .../src/FormCleaningCarCollection.java | 110 +++++++++-- 5 files changed, 335 insertions(+), 63 deletions(-) create mode 100644 ProjectCleaningCar/src/CollectionGenericObjects/CollectionType.java create mode 100644 ProjectCleaningCar/src/CollectionGenericObjects/ListGenericObjects.java create mode 100644 ProjectCleaningCar/src/CollectionGenericObjects/StorageCollection.java diff --git a/ProjectCleaningCar/src/CollectionGenericObjects/CollectionType.java b/ProjectCleaningCar/src/CollectionGenericObjects/CollectionType.java new file mode 100644 index 0000000..edf6a6e --- /dev/null +++ b/ProjectCleaningCar/src/CollectionGenericObjects/CollectionType.java @@ -0,0 +1,7 @@ +package CollectionGenericObjects; + +public enum CollectionType { + None, + Massive, + List; +} diff --git a/ProjectCleaningCar/src/CollectionGenericObjects/ListGenericObjects.java b/ProjectCleaningCar/src/CollectionGenericObjects/ListGenericObjects.java new file mode 100644 index 0000000..46a5122 --- /dev/null +++ b/ProjectCleaningCar/src/CollectionGenericObjects/ListGenericObjects.java @@ -0,0 +1,56 @@ +package CollectionGenericObjects; + +import java.util.ArrayList; +import java.util.List; + +public class ListGenericObjects implements ICollectionGenericObjects { + private List _collection; + private int _maxCount; + @Override + public int Count() { + return _collection.size(); + } + + @Override + public void SetMaxCount(int value, Class type) { + if (value > 0) { + _maxCount = value; + } + } + public ListGenericObjects() { + _collection = new ArrayList(); + } + + @Override + public int Insert(T obj) { + if (Count() == _maxCount) return -1; + _collection.add(obj); + return Count(); + } + + @Override + public int Insert(T obj, int position) { + if (Count() == _maxCount) return -1; + if (position >= Count() || position < 0) return -1; + _collection.add(position, obj); + return 0; + } + + @Override + public T Remove(int position) { + if (position >= _maxCount || position < 0) { + return null; + } + T myObj = _collection.get(position); + _collection.remove(position); + return myObj; + } + + @Override + public T Get(int position) { + if (position >= Count() || position < 0) { + return null; + } + return _collection.get(position); + } +} diff --git a/ProjectCleaningCar/src/CollectionGenericObjects/StorageCollection.java b/ProjectCleaningCar/src/CollectionGenericObjects/StorageCollection.java new file mode 100644 index 0000000..409a6fa --- /dev/null +++ b/ProjectCleaningCar/src/CollectionGenericObjects/StorageCollection.java @@ -0,0 +1,39 @@ +package CollectionGenericObjects; + +import java.util.*; + +public class StorageCollection { + private Map> _storages; + public Set Keys() { + return _storages.keySet(); + } + public StorageCollection() { + _storages = new HashMap<>(); + } + public void AddCollection(String name, CollectionType collectionType) { + if (name == null || _storages.containsKey(name)) { + return; + } + switch (collectionType) { + case None: + return; + case Massive: + _storages.put(name, new MassiveGenericObjects()); + return; + case List: + _storages.put(name, new ListGenericObjects()); + return; + } + } + public void DelCollection(String name) { + if (_storages.containsKey(name)) { + _storages.remove(name); + } + } + public ICollectionGenericObjects GetCollectionObject(String name) { + if (_storages.containsKey(name)) { + return _storages.get(name); + } + return null; + } +} diff --git a/ProjectCleaningCar/src/FormCleaningCarCollection.form b/ProjectCleaningCar/src/FormCleaningCarCollection.form index dfd4ce9..238db41 100644 --- a/ProjectCleaningCar/src/FormCleaningCarCollection.form +++ b/ProjectCleaningCar/src/FormCleaningCarCollection.form @@ -3,12 +3,12 @@ - + - + @@ -16,41 +16,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -58,30 +26,148 @@ - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + + - + - + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ProjectCleaningCar/src/FormCleaningCarCollection.java b/ProjectCleaningCar/src/FormCleaningCarCollection.java index 6e6ee2f..a49f36f 100644 --- a/ProjectCleaningCar/src/FormCleaningCarCollection.java +++ b/ProjectCleaningCar/src/FormCleaningCarCollection.java @@ -1,6 +1,4 @@ -import CollectionGenericObjects.AbstractCompany; -import CollectionGenericObjects.AutoParkService; -import CollectionGenericObjects.MassiveGenericObjects; +import CollectionGenericObjects.*; import Drawnings.DrawningCleaningCar; import Drawnings.DrawningTruck; @@ -10,13 +8,14 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.ParseException; -import java.util.Arrays; +import java.util.Objects; import java.util.Random; import static java.lang.Integer.parseInt; public class FormCleaningCarCollection extends JFrame{ private AbstractCompany _company = null; + private StorageCollection _storageCollection; private JPanel panel; private JPanel tools; private JComboBox comboBoxSelectorCompany; @@ -28,6 +27,16 @@ public class FormCleaningCarCollection extends JFrame{ private JButton buttonGoToCheck; private JButton buttonRefresh; private JButton buttonAdditionalCollection; + private JPanel panelStorage; + private JLabel labelCollectionName; + private JTextField textBoxCollectionName; + private JRadioButton radioButtonMassive; + private JRadioButton radioButtonList; + private JButton buttonCollectionAdd; + private JList listBoxCollection; + private JButton buttonCollectionDel; + private JButton buttonCreateCompany; + private JPanel panelCompanyTools; public FormCleaningCarCollection() { setTitle("Коллекция уборочных машин"); @@ -36,7 +45,7 @@ public class FormCleaningCarCollection extends JFrame{ setDefaultCloseOperation(EXIT_ON_CLOSE); add(panel); - + _storageCollection = new StorageCollection<>(); tools.setBackground(new Color(220, 220, 220)); tools.setBorder(BorderFactory.createTitledBorder("Инструменты")); @@ -58,6 +67,8 @@ public class FormCleaningCarCollection extends JFrame{ return finalMaskFormatter; } }); + ButtonGroup group = new ButtonGroup(); + group.add(radioButtonList); group.add(radioButtonMassive); Init(); } private void Init() { @@ -65,14 +76,7 @@ public class FormCleaningCarCollection extends JFrame{ comboBoxSelectorCompany.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - switch (comboBoxSelectorCompany.getSelectedItem().toString()) { - case "Автопарк": - _company = new AutoParkService(pictureBox.getWidth(), pictureBox.getHeight(), new MassiveGenericObjects()); - System.out.println(pictureBox + "/" + pictureBox.getWidth() + "/" + pictureBox.getHeight()); - - break; - } - System.out.println(comboBoxSelectorCompany.getSelectedItem().toString()); + panelCompanyTools.setEnabled(false); } }); @@ -138,6 +142,74 @@ public class FormCleaningCarCollection extends JFrame{ formAdditionalCollection.SetCompany(_company); } }); + //ButtonCollectionAdd_Click + buttonCollectionAdd.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (textBoxCollectionName.getText().isEmpty() || (!radioButtonMassive.isSelected() && !radioButtonList.isSelected())) { + JOptionPane.showMessageDialog(null, "Не все данные заполнены"); + return; + } + CollectionType collectionType = CollectionType.None; + if (radioButtonMassive.isSelected()) { + collectionType = CollectionType.Massive; + } + else if (radioButtonList.isSelected()) { + collectionType = CollectionType.List; + } + _storageCollection.AddCollection(textBoxCollectionName.getText(), collectionType); + RefreshListBoxItems(); + } + }); + //ButtonCollectionDel_Click + buttonCollectionDel.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (listBoxCollection.getSelectedIndex() < 0 || listBoxCollection.getSelectedValue() == null) + { + JOptionPane.showMessageDialog(null, "Коллекция не выбрана"); + return; + } + + switch (JOptionPane.showConfirmDialog(null, "Удалить коллекцию?", "Удаление", JOptionPane.YES_NO_OPTION)) { + case 1: + return; + case 0: + _storageCollection.DelCollection(listBoxCollection.getSelectedValue().toString()); + break; + } + _storageCollection.DelCollection(listBoxCollection.getSelectedValue().toString()); + RefreshListBoxItems(); + } + }); + //ButtonCreateCompany_Click + buttonCreateCompany.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (listBoxCollection.getSelectedIndex() < 0 || listBoxCollection.getSelectedValue() == null) + { + JOptionPane.showMessageDialog(null, "Коллекция не выбрана"); + return; + } + + ICollectionGenericObjects collection = _storageCollection.GetCollectionObject(listBoxCollection.getSelectedValue().toString()); + if (collection == null) + { + JOptionPane.showMessageDialog(null, "Коллекция не проинициализирована"); + return; + } + + switch (comboBoxSelectorCompany.getSelectedItem().toString()) + { + case "Автопарк": + _company = new AutoParkService(pictureBox.getWidth(), pictureBox.getHeight(), collection); + break; + } + + panelCompanyTools.setEnabled(true); + RefreshListBoxItems(); + } + }); } private void CreateObject(String type) { if (_company == null) return; @@ -180,4 +252,16 @@ public class FormCleaningCarCollection extends JFrame{ // Method method = Component.class.getSuperclass().getDeclaredMethod("repaint"); // method.setAccessible(true); // method.invoke(method); + private void RefreshListBoxItems() + { + listBoxCollection.removeAll(); + DefaultListModel list = new DefaultListModel(); + for (String name : _storageCollection.Keys()) { + if (!Objects.equals(name, "")) + { + list.addElement(name); + } + } + listBoxCollection.setModel(list); + } } -- 2.25.1 From a0fbbbb129644cb46c8d7c520431b111c013d4e9 Mon Sep 17 00:00:00 2001 From: DjonniStorm Date: Sun, 12 May 2024 16:15:45 +0400 Subject: [PATCH 2/7] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=964=20(2=20=D1=87=D0=B0=D1=81=D1=82=D1=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ListGenericObjects.java | 2 +- .../MassiveGenericObjects.java | 3 +- ProjectCleaningCar/src/FormCleaningCar.java | 2 +- .../src/FormCleaningCarCollection.form | 10 ++++++- .../src/FormCleaningCarCollection.java | 28 ++++++++++++++++++- 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/ProjectCleaningCar/src/CollectionGenericObjects/ListGenericObjects.java b/ProjectCleaningCar/src/CollectionGenericObjects/ListGenericObjects.java index 46a5122..afd056a 100644 --- a/ProjectCleaningCar/src/CollectionGenericObjects/ListGenericObjects.java +++ b/ProjectCleaningCar/src/CollectionGenericObjects/ListGenericObjects.java @@ -31,7 +31,7 @@ public class ListGenericObjects implements ICollectionGenericObjects { @Override public int Insert(T obj, int position) { if (Count() == _maxCount) return -1; - if (position >= Count() || position < 0) return -1; + if (position > Count() || position < 0) return -1; _collection.add(position, obj); return 0; } diff --git a/ProjectCleaningCar/src/CollectionGenericObjects/MassiveGenericObjects.java b/ProjectCleaningCar/src/CollectionGenericObjects/MassiveGenericObjects.java index 6ef1ba4..546b046 100644 --- a/ProjectCleaningCar/src/CollectionGenericObjects/MassiveGenericObjects.java +++ b/ProjectCleaningCar/src/CollectionGenericObjects/MassiveGenericObjects.java @@ -7,7 +7,8 @@ public class MassiveGenericObjects implements ICollectionGenericObjects{ @Override public void SetMaxCount(int value, Class type) { if (value > 0) { - _collection = (T[]) Array.newInstance(type, value); + if (_collection == null) + _collection = (T[]) Array.newInstance(type, value); } } @Override diff --git a/ProjectCleaningCar/src/FormCleaningCar.java b/ProjectCleaningCar/src/FormCleaningCar.java index 3dea35b..bffaff9 100644 --- a/ProjectCleaningCar/src/FormCleaningCar.java +++ b/ProjectCleaningCar/src/FormCleaningCar.java @@ -12,7 +12,7 @@ import java.util.List; import java.util.LinkedList; public class FormCleaningCar extends JFrame { - protected DrawningTruck _drawningTruck; + private DrawningTruck _drawningTruck; private JPanel pictureBox; private JButton buttonRight; private JButton buttonLeft; diff --git a/ProjectCleaningCar/src/FormCleaningCarCollection.form b/ProjectCleaningCar/src/FormCleaningCarCollection.form index 238db41..643c437 100644 --- a/ProjectCleaningCar/src/FormCleaningCarCollection.form +++ b/ProjectCleaningCar/src/FormCleaningCarCollection.form @@ -8,7 +8,7 @@ - + @@ -168,6 +168,14 @@ + + + + + + + + diff --git a/ProjectCleaningCar/src/FormCleaningCarCollection.java b/ProjectCleaningCar/src/FormCleaningCarCollection.java index a49f36f..1e43b7b 100644 --- a/ProjectCleaningCar/src/FormCleaningCarCollection.java +++ b/ProjectCleaningCar/src/FormCleaningCarCollection.java @@ -8,6 +8,7 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.ParseException; +import java.util.LinkedList; import java.util.Objects; import java.util.Random; @@ -16,6 +17,7 @@ import static java.lang.Integer.parseInt; public class FormCleaningCarCollection extends JFrame{ private AbstractCompany _company = null; private StorageCollection _storageCollection; + private LinkedList _resurrected; private JPanel panel; private JPanel tools; private JComboBox comboBoxSelectorCompany; @@ -37,6 +39,7 @@ public class FormCleaningCarCollection extends JFrame{ private JButton buttonCollectionDel; private JButton buttonCreateCompany; private JPanel panelCompanyTools; + private JButton buttonResurrected; public FormCleaningCarCollection() { setTitle("Коллекция уборочных машин"); @@ -46,6 +49,7 @@ public class FormCleaningCarCollection extends JFrame{ add(panel); _storageCollection = new StorageCollection<>(); + _resurrected = new LinkedList<>(); tools.setBackground(new Color(220, 220, 220)); tools.setBorder(BorderFactory.createTitledBorder("Инструменты")); @@ -69,6 +73,9 @@ public class FormCleaningCarCollection extends JFrame{ }); ButtonGroup group = new ButtonGroup(); group.add(radioButtonList); group.add(radioButtonMassive); + for (Component i : panelCompanyTools.getComponents()) { + i.setBackground(Color.GRAY); + } Init(); } private void Init() { @@ -77,6 +84,9 @@ public class FormCleaningCarCollection extends JFrame{ @Override public void actionPerformed(ActionEvent e) { panelCompanyTools.setEnabled(false); + for (Component i : panelCompanyTools.getComponents()) { + i.setBackground(Color.GRAY); + } } }); @@ -92,6 +102,8 @@ public class FormCleaningCarCollection extends JFrame{ switch (JOptionPane.showConfirmDialog(null, "Удалить?", "Удаление", JOptionPane.YES_NO_OPTION)) { case 0: int pos = parseInt(maskedTextBox.getText()); + DrawningTruck truck = _company._collection.Get(pos); + if (truck != null) _resurrected.add(truck); if (_company._collection.Remove(pos) != null) { JOptionPane.showMessageDialog(null, "Объект удалён"); repaint(); @@ -207,9 +219,23 @@ public class FormCleaningCarCollection extends JFrame{ } panelCompanyTools.setEnabled(true); + for (Component i : panelCompanyTools.getComponents()) { + i.setBackground(buttonCreateCompany.getBackground()); + } RefreshListBoxItems(); } }); + buttonResurrected.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (_resurrected.peek() != null) { + FormCleaningCar form = new FormCleaningCar(); + System.out.println(_resurrected.peek()); + form.SetTruck(_resurrected.pop()); + System.out.println(_resurrected.peek()); + } + } + }); } private void CreateObject(String type) { if (_company == null) return; @@ -227,7 +253,7 @@ public class FormCleaningCarCollection extends JFrame{ break; default: return; } - if (_company._collection.Insert(drawningTruck, 0) != -1) { + if (_company._collection.Insert(drawningTruck) != -1) { JOptionPane.showMessageDialog(null, "Объект добавлен"); repaint(); } else { -- 2.25.1 From 5ad501877540d563bcb7529df70c0a85a6dace37 Mon Sep 17 00:00:00 2001 From: DjonniStorm Date: Mon, 3 Jun 2024 18:08:25 +0400 Subject: [PATCH 3/7] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=964=20(=D0=B2=D1=80=D0=BE=D0=B4=D0=B5=20=D0=B3?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2=D0=BE)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StorageCollection.java | 6 ++++ .../src/FormCleaningCarCollection.form | 34 ++++++++++++------- .../src/FormCleaningCarCollection.java | 30 +++++++++++++--- ProjectCleaningCar/src/Main.java | 10 ------ 4 files changed, 52 insertions(+), 28 deletions(-) diff --git a/ProjectCleaningCar/src/CollectionGenericObjects/StorageCollection.java b/ProjectCleaningCar/src/CollectionGenericObjects/StorageCollection.java index 409a6fa..3da3891 100644 --- a/ProjectCleaningCar/src/CollectionGenericObjects/StorageCollection.java +++ b/ProjectCleaningCar/src/CollectionGenericObjects/StorageCollection.java @@ -36,4 +36,10 @@ public class StorageCollection { } return null; } + + public T Remove(String name, int position){ + if(_storages.containsKey(name)) + return _storages.get(name).Remove(position); + return null; + } } diff --git a/ProjectCleaningCar/src/FormCleaningCarCollection.form b/ProjectCleaningCar/src/FormCleaningCarCollection.form index 643c437..1e585e4 100644 --- a/ProjectCleaningCar/src/FormCleaningCarCollection.form +++ b/ProjectCleaningCar/src/FormCleaningCarCollection.form @@ -8,7 +8,7 @@ - + @@ -100,7 +100,7 @@ - + @@ -144,7 +144,7 @@ - + @@ -152,7 +152,7 @@ - + @@ -160,22 +160,30 @@ - + + + + + + + + + + + + + + + + + - - - - - - - - diff --git a/ProjectCleaningCar/src/FormCleaningCarCollection.java b/ProjectCleaningCar/src/FormCleaningCarCollection.java index 1e43b7b..9ce9971 100644 --- a/ProjectCleaningCar/src/FormCleaningCarCollection.java +++ b/ProjectCleaningCar/src/FormCleaningCarCollection.java @@ -40,6 +40,7 @@ public class FormCleaningCarCollection extends JFrame{ private JButton buttonCreateCompany; private JPanel panelCompanyTools; private JButton buttonResurrected; + private JButton buttonIndex; public FormCleaningCarCollection() { setTitle("Коллекция уборочных машин"); @@ -55,12 +56,10 @@ public class FormCleaningCarCollection extends JFrame{ tools.setBorder(BorderFactory.createTitledBorder("Инструменты")); comboBoxSelectorCompany.addItem(new String("")); comboBoxSelectorCompany.addItem(new String("Автопарк")); - //mask MaskFormatter maskFormatter = null; try { maskFormatter = new MaskFormatter("##"); maskFormatter.setPlaceholder("00"); - //это intellij } catch (ParseException e) { throw new RuntimeException(e); } @@ -236,6 +235,30 @@ public class FormCleaningCarCollection extends JFrame{ } } }); + buttonIndex.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (listBoxCollection.getSelectedValue() == null || listBoxCollection.getSelectedIndex() < 0 + || _company == null || maskedTextBox.getText() == null) return; + int pos = parseInt(maskedTextBox.getText()); + switch (JOptionPane.showConfirmDialog(null, "Удалить?", "Удаление", JOptionPane.YES_NO_OPTION)) { + case 0: + DrawningTruck truck = _storageCollection.Remove(listBoxCollection.getSelectedValue().toString(), pos); + if (truck != null) { + _resurrected.add(truck); + JOptionPane.showMessageDialog(null, "Объект удалён"); + repaint(); + + } else { + JOptionPane.showMessageDialog(null, "Не удалось удалить объект"); + } + break; + case 1: + default: + return; + } + } + }); } private void CreateObject(String type) { if (_company == null) return; @@ -275,9 +298,6 @@ public class FormCleaningCarCollection extends JFrame{ _company.Show(e); } public static void Show() {for (Frame i : Frame.getFrames()) {if (!i.isActive()) {i.repaint();}}} -// Method method = Component.class.getSuperclass().getDeclaredMethod("repaint"); -// method.setAccessible(true); -// method.invoke(method); private void RefreshListBoxItems() { listBoxCollection.removeAll(); diff --git a/ProjectCleaningCar/src/Main.java b/ProjectCleaningCar/src/Main.java index 66d8817..aff5e87 100644 --- a/ProjectCleaningCar/src/Main.java +++ b/ProjectCleaningCar/src/Main.java @@ -1,16 +1,6 @@ -import javax.swing.*; -import java.awt.*; class Main { public static void main(String[] args) { -// JFrame.setDefaultLookAndFeelDecorated(false); -// JFrame frame = new JFrame("Project Cleaning Car"); -// frame.setContentPane(new FormCleaningCarCollection().pictureBox); -// frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); -// frame.setLocation(200, 200); -// frame.pack(); -// frame.setSize(1000, 600); -// frame.setVisible(true); FormCleaningCarCollection form = new FormCleaningCarCollection(); form.setVisible(true); } -- 2.25.1 From 863d9dddcbf57d28a74421025afc7d138bc56785 Mon Sep 17 00:00:00 2001 From: DjonniStorm Date: Mon, 3 Jun 2024 19:10:21 +0400 Subject: [PATCH 4/7] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=964=20(=D0=BF=D0=BE=D0=BF=D1=8B=D1=82=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=80=D0=B5=D1=88=D0=B8=D1=82=D1=8C=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=84=D0=BB=D0=B8=D0=BA=D1=82=20=D1=81=D0=BB=D0=B8=D1=8F?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectCleaningCar/src/FormCleaningCarCollection.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ProjectCleaningCar/src/FormCleaningCarCollection.java b/ProjectCleaningCar/src/FormCleaningCarCollection.java index 9ce9971..67e5059 100644 --- a/ProjectCleaningCar/src/FormCleaningCarCollection.java +++ b/ProjectCleaningCar/src/FormCleaningCarCollection.java @@ -298,6 +298,8 @@ public class FormCleaningCarCollection extends JFrame{ _company.Show(e); } public static void Show() {for (Frame i : Frame.getFrames()) {if (!i.isActive()) {i.repaint();}}} + // Method method = Component.class.getSuperclass().getDeclaredMethod("repaint"); + // method.setAccessible(true); private void RefreshListBoxItems() { listBoxCollection.removeAll(); -- 2.25.1 From 000a7f87a4702d54b4822a5f7839e6d7e3903715 Mon Sep 17 00:00:00 2001 From: DjonniStorm Date: Mon, 3 Jun 2024 19:11:34 +0400 Subject: [PATCH 5/7] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=964=20(=D0=BF=D0=BE=D0=BF=D1=8B=D1=82=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=80=D0=B5=D1=88=D0=B8=D1=82=D1=8C=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=84=D0=BB=D0=B8=D0=BA=D1=82=20=D1=81=D0=BB=D0=B8=D1=8F?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=202)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectCleaningCar/src/FormCleaningCarCollection.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ProjectCleaningCar/src/FormCleaningCarCollection.java b/ProjectCleaningCar/src/FormCleaningCarCollection.java index 67e5059..6940590 100644 --- a/ProjectCleaningCar/src/FormCleaningCarCollection.java +++ b/ProjectCleaningCar/src/FormCleaningCarCollection.java @@ -297,9 +297,6 @@ public class FormCleaningCarCollection extends JFrame{ e.fillRect(0,0, pictureBox.getWidth(), pictureBox.getHeight()); _company.Show(e); } - public static void Show() {for (Frame i : Frame.getFrames()) {if (!i.isActive()) {i.repaint();}}} - // Method method = Component.class.getSuperclass().getDeclaredMethod("repaint"); - // method.setAccessible(true); private void RefreshListBoxItems() { listBoxCollection.removeAll(); @@ -312,4 +309,5 @@ public class FormCleaningCarCollection extends JFrame{ } listBoxCollection.setModel(list); } + public static void Show() {for (Frame i : Frame.getFrames()) {if (!i.isActive()) {i.repaint();}}} } -- 2.25.1 From 399dd73064110dcb24840db73e1e9ef37e3f5094 Mon Sep 17 00:00:00 2001 From: DjonniStorm Date: Mon, 3 Jun 2024 19:25:46 +0400 Subject: [PATCH 6/7] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=964=20(=D0=BF=D0=BE=D0=BF=D1=8B=D1=82=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=80=D0=B5=D1=88=D0=B8=D1=82=D1=8C=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=84=D0=BB=D0=B8=D0=BA=D1=82=20=D1=81=D0=BB=D0=B8=D1=8F?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=203)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/FormCleaningCarCollection.java | 245 +++++++++--------- 1 file changed, 121 insertions(+), 124 deletions(-) diff --git a/ProjectCleaningCar/src/FormCleaningCarCollection.java b/ProjectCleaningCar/src/FormCleaningCarCollection.java index 6940590..6e7e5ee 100644 --- a/ProjectCleaningCar/src/FormCleaningCarCollection.java +++ b/ProjectCleaningCar/src/FormCleaningCarCollection.java @@ -8,6 +8,7 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.ParseException; +import java.util.Arrays; import java.util.LinkedList; import java.util.Objects; import java.util.Random; @@ -41,7 +42,6 @@ public class FormCleaningCarCollection extends JFrame{ private JPanel panelCompanyTools; private JButton buttonResurrected; private JButton buttonIndex; - public FormCleaningCarCollection() { setTitle("Коллекция уборочных машин"); setSize(1000, 600); @@ -56,10 +56,12 @@ public class FormCleaningCarCollection extends JFrame{ tools.setBorder(BorderFactory.createTitledBorder("Инструменты")); comboBoxSelectorCompany.addItem(new String("")); comboBoxSelectorCompany.addItem(new String("Автопарк")); + //mask MaskFormatter maskFormatter = null; try { maskFormatter = new MaskFormatter("##"); maskFormatter.setPlaceholder("00"); + //это intellij } catch (ParseException e) { throw new RuntimeException(e); } @@ -70,11 +72,6 @@ public class FormCleaningCarCollection extends JFrame{ return finalMaskFormatter; } }); - ButtonGroup group = new ButtonGroup(); - group.add(radioButtonList); group.add(radioButtonMassive); - for (Component i : panelCompanyTools.getComponents()) { - i.setBackground(Color.GRAY); - } Init(); } private void Init() { @@ -101,8 +98,6 @@ public class FormCleaningCarCollection extends JFrame{ switch (JOptionPane.showConfirmDialog(null, "Удалить?", "Удаление", JOptionPane.YES_NO_OPTION)) { case 0: int pos = parseInt(maskedTextBox.getText()); - DrawningTruck truck = _company._collection.Get(pos); - if (truck != null) _resurrected.add(truck); if (_company._collection.Remove(pos) != null) { JOptionPane.showMessageDialog(null, "Объект удалён"); repaint(); @@ -153,113 +148,113 @@ public class FormCleaningCarCollection extends JFrame{ formAdditionalCollection.SetCompany(_company); } }); - //ButtonCollectionAdd_Click - buttonCollectionAdd.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if (textBoxCollectionName.getText().isEmpty() || (!radioButtonMassive.isSelected() && !radioButtonList.isSelected())) { - JOptionPane.showMessageDialog(null, "Не все данные заполнены"); - return; - } - CollectionType collectionType = CollectionType.None; - if (radioButtonMassive.isSelected()) { - collectionType = CollectionType.Massive; - } - else if (radioButtonList.isSelected()) { - collectionType = CollectionType.List; - } - _storageCollection.AddCollection(textBoxCollectionName.getText(), collectionType); - RefreshListBoxItems(); - } - }); - //ButtonCollectionDel_Click - buttonCollectionDel.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if (listBoxCollection.getSelectedIndex() < 0 || listBoxCollection.getSelectedValue() == null) - { - JOptionPane.showMessageDialog(null, "Коллекция не выбрана"); - return; - } - - switch (JOptionPane.showConfirmDialog(null, "Удалить коллекцию?", "Удаление", JOptionPane.YES_NO_OPTION)) { - case 1: - return; - case 0: - _storageCollection.DelCollection(listBoxCollection.getSelectedValue().toString()); - break; - } - _storageCollection.DelCollection(listBoxCollection.getSelectedValue().toString()); - RefreshListBoxItems(); - } - }); - //ButtonCreateCompany_Click - buttonCreateCompany.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if (listBoxCollection.getSelectedIndex() < 0 || listBoxCollection.getSelectedValue() == null) - { - JOptionPane.showMessageDialog(null, "Коллекция не выбрана"); - return; - } - - ICollectionGenericObjects collection = _storageCollection.GetCollectionObject(listBoxCollection.getSelectedValue().toString()); - if (collection == null) - { - JOptionPane.showMessageDialog(null, "Коллекция не проинициализирована"); - return; - } - - switch (comboBoxSelectorCompany.getSelectedItem().toString()) - { - case "Автопарк": - _company = new AutoParkService(pictureBox.getWidth(), pictureBox.getHeight(), collection); - break; - } - - panelCompanyTools.setEnabled(true); - for (Component i : panelCompanyTools.getComponents()) { - i.setBackground(buttonCreateCompany.getBackground()); - } - RefreshListBoxItems(); - } - }); - buttonResurrected.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if (_resurrected.peek() != null) { - FormCleaningCar form = new FormCleaningCar(); - System.out.println(_resurrected.peek()); - form.SetTruck(_resurrected.pop()); - System.out.println(_resurrected.peek()); - } - } - }); - buttonIndex.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if (listBoxCollection.getSelectedValue() == null || listBoxCollection.getSelectedIndex() < 0 - || _company == null || maskedTextBox.getText() == null) return; - int pos = parseInt(maskedTextBox.getText()); - switch (JOptionPane.showConfirmDialog(null, "Удалить?", "Удаление", JOptionPane.YES_NO_OPTION)) { - case 0: - DrawningTruck truck = _storageCollection.Remove(listBoxCollection.getSelectedValue().toString(), pos); - if (truck != null) { - _resurrected.add(truck); - JOptionPane.showMessageDialog(null, "Объект удалён"); - repaint(); - - } else { - JOptionPane.showMessageDialog(null, "Не удалось удалить объект"); - } - break; - case 1: - default: - return; - } - } - }); } + //ButtonCollectionAdd_Click + buttonCollectionAdd.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (textBoxCollectionName.getText().isEmpty() || (!radioButtonMassive.isSelected() && !radioButtonList.isSelected())) { + JOptionPane.showMessageDialog(null, "Не все данные заполнены"); + return; + } + CollectionType collectionType = CollectionType.None; + if (radioButtonMassive.isSelected()) { + collectionType = CollectionType.Massive; + } + else if (radioButtonList.isSelected()) { + collectionType = CollectionType.List; + } + _storageCollection.AddCollection(textBoxCollectionName.getText(), collectionType); + RefreshListBoxItems(); + } + }); + //ButtonCollectionDel_Click + buttonCollectionDel.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (listBoxCollection.getSelectedIndex() < 0 || listBoxCollection.getSelectedValue() == null) + { + JOptionPane.showMessageDialog(null, "Коллекция не выбрана"); + return; + } + + switch (JOptionPane.showConfirmDialog(null, "Удалить коллекцию?", "Удаление", JOptionPane.YES_NO_OPTION)) { + case 1: + return; + case 0: + _storageCollection.DelCollection(listBoxCollection.getSelectedValue().toString()); + break; + } + _storageCollection.DelCollection(listBoxCollection.getSelectedValue().toString()); + RefreshListBoxItems(); + } + }); + //ButtonCreateCompany_Click + buttonCreateCompany.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (listBoxCollection.getSelectedIndex() < 0 || listBoxCollection.getSelectedValue() == null) + { + JOptionPane.showMessageDialog(null, "Коллекция не выбрана"); + return; + } + + ICollectionGenericObjects collection = _storageCollection.GetCollectionObject(listBoxCollection.getSelectedValue().toString()); + if (collection == null) + { + JOptionPane.showMessageDialog(null, "Коллекция не проинициализирована"); + return; + } + + switch (comboBoxSelectorCompany.getSelectedItem().toString()) + { + case "Автопарк": + _company = new AutoParkService(pictureBox.getWidth(), pictureBox.getHeight(), collection); + break; + } + + panelCompanyTools.setEnabled(true); + for (Component i : panelCompanyTools.getComponents()) { + i.setBackground(buttonCreateCompany.getBackground()); + } + RefreshListBoxItems(); + } + }); + buttonResurrected.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (_resurrected.peek() != null) { + FormCleaningCar form = new FormCleaningCar(); + System.out.println(_resurrected.peek()); + form.SetTruck(_resurrected.pop()); + System.out.println(_resurrected.peek()); + } + } + }); + buttonIndex.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (listBoxCollection.getSelectedValue() == null || listBoxCollection.getSelectedIndex() < 0 + || _company == null || maskedTextBox.getText() == null) return; + int pos = parseInt(maskedTextBox.getText()); + switch (JOptionPane.showConfirmDialog(null, "Удалить?", "Удаление", JOptionPane.YES_NO_OPTION)) { + case 0: + DrawningTruck truck = _storageCollection.Remove(listBoxCollection.getSelectedValue().toString(), pos); + if (truck != null) { + _resurrected.add(truck); + JOptionPane.showMessageDialog(null, "Объект удалён"); + repaint(); + + } else { + JOptionPane.showMessageDialog(null, "Не удалось удалить объект"); + } + break; + case 1: + default: + return; + } + } + }); private void CreateObject(String type) { if (_company == null) return; Random random = new Random(); @@ -276,7 +271,7 @@ public class FormCleaningCarCollection extends JFrame{ break; default: return; } - if (_company._collection.Insert(drawningTruck) != -1) { + if (_company._collection.Insert(drawningTruck, 0) != -1) { JOptionPane.showMessageDialog(null, "Объект добавлен"); repaint(); } else { @@ -288,15 +283,6 @@ public class FormCleaningCarCollection extends JFrame{ Color colorChooser = JColorChooser.showDialog(this, "Выберите цвет", color); return colorChooser; } - @Override - public void paint(Graphics g) { - super.paint(g); - if (_company == null) return; - Graphics e = pictureBox.getGraphics(); - e.setColor(pictureBox.getBackground()); - e.fillRect(0,0, pictureBox.getWidth(), pictureBox.getHeight()); - _company.Show(e); - } private void RefreshListBoxItems() { listBoxCollection.removeAll(); @@ -309,5 +295,16 @@ public class FormCleaningCarCollection extends JFrame{ } listBoxCollection.setModel(list); } + @Override + public void paint(Graphics g) { + super.paint(g); + if (_company == null) return; + Graphics e = pictureBox.getGraphics(); + e.setColor(pictureBox.getBackground()); + e.fillRect(0,0, pictureBox.getWidth(), pictureBox.getHeight()); + _company.Show(e); + } public static void Show() {for (Frame i : Frame.getFrames()) {if (!i.isActive()) {i.repaint();}}} +// Method method = Component.class.getSuperclass().getDeclaredMethod("repaint"); +// method.setAccessible(true); } -- 2.25.1 From 4d36c0c65cb62ff4f1d0b5257087f756051a51f6 Mon Sep 17 00:00:00 2001 From: DjonniStorm Date: Mon, 3 Jun 2024 21:09:22 +0400 Subject: [PATCH 7/7] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=964=20(=D0=B2=D0=BE=D1=82=20=D0=B1=D1=8B=20?= =?UTF-8?q?=D0=B1=D0=B5=D0=B7=20=D0=BA=D0=BE=D0=BD=D1=84=D0=BB=D0=B8=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D0=B2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdditionalCollection.java | 2 +- .../src/FormCleaningCarCollection.java | 198 +++++++++--------- 2 files changed, 97 insertions(+), 103 deletions(-) diff --git a/ProjectCleaningCar/src/CollectionGenericObjects/AdditionalCollection.java b/ProjectCleaningCar/src/CollectionGenericObjects/AdditionalCollection.java index 4560618..2875f51 100644 --- a/ProjectCleaningCar/src/CollectionGenericObjects/AdditionalCollection.java +++ b/ProjectCleaningCar/src/CollectionGenericObjects/AdditionalCollection.java @@ -13,7 +13,7 @@ import java.util.Random; public class AdditionalCollection { public T[] _collectionEntity; public U[] _collectionWheels; - public AdditionalCollection(int value, Class type1, Class type2) { + public AdditionalCollection(int value, Class type1, Class type2) { _collectionEntity = (T[]) Array.newInstance(type1, value); _collectionWheels = (U[]) Array.newInstance(type2, value); } diff --git a/ProjectCleaningCar/src/FormCleaningCarCollection.java b/ProjectCleaningCar/src/FormCleaningCarCollection.java index 6e7e5ee..4f04f2d 100644 --- a/ProjectCleaningCar/src/FormCleaningCarCollection.java +++ b/ProjectCleaningCar/src/FormCleaningCarCollection.java @@ -98,7 +98,9 @@ public class FormCleaningCarCollection extends JFrame{ switch (JOptionPane.showConfirmDialog(null, "Удалить?", "Удаление", JOptionPane.YES_NO_OPTION)) { case 0: int pos = parseInt(maskedTextBox.getText()); - if (_company._collection.Remove(pos) != null) { + DrawningTruck truck = _company._collection.Remove(pos); + if (truck != null) { + _resurrected.addFirst(truck); JOptionPane.showMessageDialog(null, "Объект удалён"); repaint(); @@ -140,121 +142,113 @@ public class FormCleaningCarCollection extends JFrame{ buttonAdditionalCollection.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - if (_company == null) - { + if (_company == null) { return; } FormAdditionalCollection formAdditionalCollection = new FormAdditionalCollection(); formAdditionalCollection.SetCompany(_company); } }); - } - //ButtonCollectionAdd_Click + //ButtonCollectionAdd_Click buttonCollectionAdd.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if (textBoxCollectionName.getText().isEmpty() || (!radioButtonMassive.isSelected() && !radioButtonList.isSelected())) { - JOptionPane.showMessageDialog(null, "Не все данные заполнены"); - return; + @Override + public void actionPerformed(ActionEvent e) { + if (textBoxCollectionName.getText().isEmpty() || (!radioButtonMassive.isSelected() && !radioButtonList.isSelected())) { + JOptionPane.showMessageDialog(null, "Не все данные заполнены"); + return; + } + CollectionType collectionType = CollectionType.None; + if (radioButtonMassive.isSelected()) { + collectionType = CollectionType.Massive; + } else if (radioButtonList.isSelected()) { + collectionType = CollectionType.List; + } + _storageCollection.AddCollection(textBoxCollectionName.getText(), collectionType); + RefreshListBoxItems(); } - CollectionType collectionType = CollectionType.None; - if (radioButtonMassive.isSelected()) { - collectionType = CollectionType.Massive; - } - else if (radioButtonList.isSelected()) { - collectionType = CollectionType.List; - } - _storageCollection.AddCollection(textBoxCollectionName.getText(), collectionType); - RefreshListBoxItems(); - } - }); - //ButtonCollectionDel_Click + }); + //ButtonCollectionDel_Click buttonCollectionDel.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if (listBoxCollection.getSelectedIndex() < 0 || listBoxCollection.getSelectedValue() == null) - { - JOptionPane.showMessageDialog(null, "Коллекция не выбрана"); - return; - } - - switch (JOptionPane.showConfirmDialog(null, "Удалить коллекцию?", "Удаление", JOptionPane.YES_NO_OPTION)) { - case 1: + @Override + public void actionPerformed(ActionEvent e) { + if (listBoxCollection.getSelectedIndex() < 0 || listBoxCollection.getSelectedValue() == null) { + JOptionPane.showMessageDialog(null, "Коллекция не выбрана"); return; - case 0: - _storageCollection.DelCollection(listBoxCollection.getSelectedValue().toString()); - break; + } + + switch (JOptionPane.showConfirmDialog(null, "Удалить коллекцию?", "Удаление", JOptionPane.YES_NO_OPTION)) { + case 1: + return; + case 0: + _storageCollection.DelCollection(listBoxCollection.getSelectedValue().toString()); + break; + } + _storageCollection.DelCollection(listBoxCollection.getSelectedValue().toString()); + RefreshListBoxItems(); } - _storageCollection.DelCollection(listBoxCollection.getSelectedValue().toString()); - RefreshListBoxItems(); - } - }); - //ButtonCreateCompany_Click + }); + //ButtonCreateCompany_Click buttonCreateCompany.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if (listBoxCollection.getSelectedIndex() < 0 || listBoxCollection.getSelectedValue() == null) - { - JOptionPane.showMessageDialog(null, "Коллекция не выбрана"); - return; - } - - ICollectionGenericObjects collection = _storageCollection.GetCollectionObject(listBoxCollection.getSelectedValue().toString()); - if (collection == null) - { - JOptionPane.showMessageDialog(null, "Коллекция не проинициализирована"); - return; - } - - switch (comboBoxSelectorCompany.getSelectedItem().toString()) - { - case "Автопарк": - _company = new AutoParkService(pictureBox.getWidth(), pictureBox.getHeight(), collection); - break; - } - - panelCompanyTools.setEnabled(true); - for (Component i : panelCompanyTools.getComponents()) { - i.setBackground(buttonCreateCompany.getBackground()); - } - RefreshListBoxItems(); - } - }); - buttonResurrected.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if (_resurrected.peek() != null) { - FormCleaningCar form = new FormCleaningCar(); - System.out.println(_resurrected.peek()); - form.SetTruck(_resurrected.pop()); - System.out.println(_resurrected.peek()); - } - } - }); - buttonIndex.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if (listBoxCollection.getSelectedValue() == null || listBoxCollection.getSelectedIndex() < 0 - || _company == null || maskedTextBox.getText() == null) return; - int pos = parseInt(maskedTextBox.getText()); - switch (JOptionPane.showConfirmDialog(null, "Удалить?", "Удаление", JOptionPane.YES_NO_OPTION)) { - case 0: - DrawningTruck truck = _storageCollection.Remove(listBoxCollection.getSelectedValue().toString(), pos); - if (truck != null) { - _resurrected.add(truck); - JOptionPane.showMessageDialog(null, "Объект удалён"); - repaint(); - - } else { - JOptionPane.showMessageDialog(null, "Не удалось удалить объект"); - } - break; - case 1: - default: + @Override + public void actionPerformed(ActionEvent e) { + if (listBoxCollection.getSelectedIndex() < 0 || listBoxCollection.getSelectedValue() == null) { + JOptionPane.showMessageDialog(null, "Коллекция не выбрана"); return; + } + + ICollectionGenericObjects collection = _storageCollection.GetCollectionObject(listBoxCollection.getSelectedValue().toString()); + if (collection == null) { + JOptionPane.showMessageDialog(null, "Коллекция не проинициализирована"); + return; + } + + switch (comboBoxSelectorCompany.getSelectedItem().toString()) { + case "Автопарк": + _company = new AutoParkService(pictureBox.getWidth(), pictureBox.getHeight(), collection); + break; + } + + panelCompanyTools.setEnabled(true); + for (Component i : panelCompanyTools.getComponents()) { + i.setBackground(buttonCreateCompany.getBackground()); + } + RefreshListBoxItems(); } - } - }); + }); + buttonResurrected.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (_resurrected.peek() != null) { + FormCleaningCar form = new FormCleaningCar(); + form.SetTruck(_resurrected.pop()); + } + } + }); + buttonIndex.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (listBoxCollection.getSelectedValue() == null || listBoxCollection.getSelectedIndex() < 0 + || _company == null || maskedTextBox.getText() == null) return; + int pos = parseInt(maskedTextBox.getText()); + switch (JOptionPane.showConfirmDialog(null, "Удалить?", "Удаление", JOptionPane.YES_NO_OPTION)) { + case 0: + DrawningTruck truck = _storageCollection.Remove(listBoxCollection.getSelectedValue().toString(), pos); + if (truck != null) { + _resurrected.addFirst(truck); + JOptionPane.showMessageDialog(null, "Объект удалён"); + repaint(); + + } else { + JOptionPane.showMessageDialog(null, "Не удалось удалить объект"); + } + break; + case 1: + default: + return; + } + } + }); + } private void CreateObject(String type) { if (_company == null) return; Random random = new Random(); -- 2.25.1