diff --git a/ProjectStormtrooper/FormPlaneCollection.form b/ProjectStormtrooper/FormPlaneCollection.form
index aba2572..7377d0e 100644
--- a/ProjectStormtrooper/FormPlaneCollection.form
+++ b/ProjectStormtrooper/FormPlaneCollection.form
@@ -14,7 +14,7 @@
-
+
@@ -22,7 +22,7 @@
-
+
@@ -30,12 +30,12 @@
-
+
-
+
@@ -43,7 +43,7 @@
-
+
@@ -51,7 +51,7 @@
-
+
@@ -59,22 +59,69 @@
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ProjectStormtrooper/FormPlaneCollection.java b/ProjectStormtrooper/FormPlaneCollection.java
index ce48a8a..81ece05 100644
--- a/ProjectStormtrooper/FormPlaneCollection.java
+++ b/ProjectStormtrooper/FormPlaneCollection.java
@@ -1,11 +1,13 @@
package ProjectStormtrooper;
import javax.swing.*;
+import javax.swing.event.ListSelectionEvent;
import java.awt.*;
import java.awt.event.ActionEvent;
+import java.util.Objects;
public class FormPlaneCollection {
- PlanesGenericCollection _planes;
+ final PlanesGenericStorage _storage;
FrameDoubleParametrized _frameDoubleParametrized;
private JPanel PanelWrapper;
private JPanel GroupBoxInstruments;
@@ -15,6 +17,11 @@ public class FormPlaneCollection {
private JButton buttonRemovePlane;
private JButton buttonRefreshCollection;
private JButton buttonOpenGenerateWindow;
+ private JTextField textFieldStorageName;
+ private JButton buttonAddStorage;
+ private JList listBoxStorages;
+ private JButton buttonRemoveStorage;
+ private JPanel storagesPanel;
public DrawingPlane SelectedPlane;
@@ -24,21 +31,81 @@ public class FormPlaneCollection {
public FormPlaneCollection() {
PictureBoxCollection.setPreferredSize(new Dimension(600, 500));
- _planes = new PlanesGenericCollection<>(600, 500);
+ _storage = new PlanesGenericStorage(600, 500);
buttonAddPlane.addActionListener(this::buttonAddPlaneClicked);
buttonRemovePlane.addActionListener(this::buttonRemovePlaneClicked);
buttonRefreshCollection.addActionListener(this::buttonRefreshCollectionClicked);
buttonOpenGenerateWindow.addActionListener(this::buttonOpenGenerateWindowClicked);
+ buttonAddStorage.addActionListener(this::buttonAddStorageClicked);
+ buttonRemoveStorage.addActionListener(this::buttonRemoveStorageClicked);
+ listBoxStorages.addListSelectionListener(this::listBoxObjectsSelectedIndexChanged);
+ }
+
+ private void ReloadObjects() {
+ int index = listBoxStorages.getSelectedIndex();
+ listBoxStorages.setListData(_storage.Keys().toArray());
+ if (listBoxStorages.getModel().getSize() > 0 && (index == -1 || index >= listBoxStorages.getModel().getSize())) {
+ listBoxStorages.setSelectedIndex(0);
+ } else if (listBoxStorages.getModel().getSize() > 0 && index > -1 && index < listBoxStorages.getModel().getSize()) {
+ listBoxStorages.setSelectedIndex(index);
+ }
+ listBoxStorages.invalidate();
+ }
+
+ private void buttonAddStorageClicked(ActionEvent e) {
+ String storageName = textFieldStorageName.getText();
+ if (Objects.equals(storageName, "")) {
+ JOptionPane.showMessageDialog(this.getPanelWrapper(),
+ "Введите название",
+ "Ошибка",
+ JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+ _storage.AddSet(storageName);
+ ReloadObjects();
+ }
+
+ private void listBoxObjectsSelectedIndexChanged(ListSelectionEvent e) {
+ refreshPictureBox();
+ }
+
+ private void buttonRemoveStorageClicked(ActionEvent e) {
+ if (listBoxStorages.getSelectedIndex() == -1) {
+ return;
+ }
+ Object[] options = {"Да", "Нет"};
+ int n = JOptionPane.showOptionDialog(this.getPanelWrapper(),
+ "Удалить объект?",
+ "Все серьезно",
+ JOptionPane.YES_NO_OPTION,
+ JOptionPane.QUESTION_MESSAGE,
+ null,
+ options,
+ options[0]
+ );
+ if (n == 1) {
+ return;
+ }
+ _storage.DelSet(listBoxStorages.getSelectedValue().toString());
+ ReloadObjects();
}
public void buttonAddPlaneClicked(ActionEvent e) {
+ if (listBoxStorages.getSelectedIndex() == -1) {
+ return;
+ }
+ var obj = _storage.Get(listBoxStorages.getSelectedValue().toString());
+ if (obj == null) {
+ return;
+ }
+
FrameStormtrooper frameStormtrooper = new FrameStormtrooper();
frameStormtrooper.setVisible(true);
frameStormtrooper._formPlaneCollection.buttonSelectPlane.addActionListener(ev -> {
SelectedPlane = frameStormtrooper._formPlaneCollection._drawingPlane;
frameStormtrooper.dispose();
if (SelectedPlane != null) {
- if (_planes.Add(SelectedPlane) > -1) {
+ if (obj.Add(SelectedPlane) > -1) {
refreshPictureBox();
JOptionPane.showMessageDialog(this.getPanelWrapper(),
"Объект добавлен",
@@ -55,6 +122,13 @@ public class FormPlaneCollection {
}
public void buttonRemovePlaneClicked(ActionEvent e) {
+ if (listBoxStorages.getSelectedIndex() == -1) {
+ return;
+ }
+ var obj = _storage.Get(listBoxStorages.getSelectedValue().toString());
+ if (obj == null) {
+ return;
+ }
int pos;
try {
pos = Integer.parseInt(textFieldNumber.getText());
@@ -78,7 +152,7 @@ public class FormPlaneCollection {
if (n == 1) {
return;
}
- if (_planes.Sub(pos) != null) {
+ if (obj.Sub(pos) != null) {
refreshPictureBox();
JOptionPane.showMessageDialog(this.getPanelWrapper(),
"Объект удален",
@@ -105,8 +179,15 @@ public class FormPlaneCollection {
}
public void refreshPictureBox() {
+ if (listBoxStorages.getSelectedIndex() == -1) {
+ return;
+ }
+ var obj = _storage.Get(listBoxStorages.getSelectedValue().toString());
+ if (obj == null) {
+ return;
+ }
Graphics g = PictureBoxCollection.getGraphics();
PictureBoxCollection.paint(g);
- _planes.ShowPlanes(g);
+ obj.ShowPlanes(g);
}
}
diff --git a/ProjectStormtrooper/PlanesGenericStorage.java b/ProjectStormtrooper/PlanesGenericStorage.java
index e015164..18f4864 100644
--- a/ProjectStormtrooper/PlanesGenericStorage.java
+++ b/ProjectStormtrooper/PlanesGenericStorage.java
@@ -7,8 +7,8 @@ import java.util.List;
public class PlanesGenericStorage {
final HashMap> _planeStorages;
- public ArrayList Keys() {
- return (ArrayList) _planeStorages.keySet().stream().toList();
+ public List Keys() {
+ return _planeStorages.keySet().stream().toList();
}
private final int _pictureWidth;