diff --git a/DrawningObjectLocomotive.java b/DrawningObjectLocomotive.java index 38617df..2695ed0 100644 --- a/DrawningObjectLocomotive.java +++ b/DrawningObjectLocomotive.java @@ -2,6 +2,9 @@ import java.awt.*; public class DrawningObjectLocomotive implements IDrawningObject { private DrawningLocomotive _locomotive = null; + public DrawningLocomotive GetDrawningLocomotive() { + return _locomotive; + } public DrawningObjectLocomotive(DrawningLocomotive locomotive) { diff --git a/FormLocomotive.java b/FormLocomotive.java index 8d7b5ee..eb1cb24 100644 --- a/FormLocomotive.java +++ b/FormLocomotive.java @@ -8,6 +8,11 @@ public class FormLocomotive extends JComponent{ public DrawningLocomotive getSelectedLocomotive() { return SelectedLocomotive; } + public void SetLocomotive(DrawningObjectLocomotive locomotive){ + // TODO добавлен геттер в drawningobjectlocomotive + _locomotive = locomotive.GetDrawningLocomotive(); + repaint(); + } public FormLocomotive(JDialog caller) { Panel statusPanel = new Panel(); diff --git a/FormMapWithSetLocomotives.java b/FormMapWithSetLocomotives.java index a5f185d..fe5e7ae 100644 --- a/FormMapWithSetLocomotives.java +++ b/FormMapWithSetLocomotives.java @@ -286,6 +286,28 @@ public class FormMapWithSetLocomotives extends JComponent { }); statusPanel.add(showGalleryButton); + // Кнопка показа удаленных объектов + JButton showDeletedButton = new JButton("Show Deleted"); + showDeletedButton.addActionListener(e -> { + // По отдельной кнопке вызывать форму работы с объектом (из + //первой лабораторной), передавая туда элемент из коллекции + //удаленных, если там есть + DrawningObjectLocomotive locomotive = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).getDeleted(); + if (locomotive != null) { + JDialog dialog = new JDialog(formFrame, "Deleted", true); + FormLocomotive formLocomotive = new FormLocomotive(dialog); + // TODO чтобы передать локомотив в форму добавляем метод в formlocomotive + formLocomotive.SetLocomotive(locomotive); + dialog.setSize(800, 500); + dialog.setContentPane(formLocomotive); + dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + dialog.setVisible(true); + + } + + }); + statusPanel.add(showDeletedButton); + formFrame.getContentPane().add(this); formFrame.setVisible(true); } diff --git a/MapWithSetLocomotivesGeneric.java b/MapWithSetLocomotivesGeneric.java index 699eb1d..c9c8eec 100644 --- a/MapWithSetLocomotivesGeneric.java +++ b/MapWithSetLocomotivesGeneric.java @@ -1,5 +1,6 @@ import java.awt.*; import java.awt.image.BufferedImage; +import java.util.LinkedList; public class MapWithSetLocomotivesGeneric @@ -14,7 +15,16 @@ public class MapWithSetLocomotivesGeneric private final int _placeSizeHeight = 90; /// Набор объектов - private final SetLocomotivesGeneric _setLocomotives; + //TODO переделал на public, узнать так ли вообще надо? + public final SetLocomotivesGeneric _setLocomotives; + + // Список удаленных объектов + LinkedList deletedLocomotives = new LinkedList<>(); + + public DrawningObjectLocomotive getDeleted() { + if (deletedLocomotives.isEmpty()) return null; + return deletedLocomotives.removeFirst(); + } /// Карта private final U _map; /// Конструктор @@ -36,7 +46,10 @@ public class MapWithSetLocomotivesGeneric /// Удаление public T Minus(int position) { - return this._setLocomotives.Remove(position); + T temp = this._setLocomotives.Remove(position); + if (temp == null) return null; + if (temp instanceof DrawningObjectLocomotive) deletedLocomotives.add((DrawningObjectLocomotive) temp); + return temp; } /// Вывод всего набора объектов public BufferedImage ShowSet() diff --git a/MapsCollection.java b/MapsCollection.java index a6428f4..a041983 100644 --- a/MapsCollection.java +++ b/MapsCollection.java @@ -4,6 +4,7 @@ import java.util.HashMap; public class MapsCollection { /// Словарь (хранилище) с картами final HashMap> _mapStorages; + /// Возвращение списка названий карт public ArrayList keys() { return new ArrayList(_mapStorages.keySet()); @@ -38,4 +39,10 @@ public class MapsCollection { if (_mapStorages.containsKey(ind)) return _mapStorages.get(ind); return null; } + // Доп.индексатор из задания + // TODO поле setlocomotives в mapwithsetlocomotivesgeneric было изменено на public + public DrawningObjectLocomotive Get (String name, int position) { + if (_mapStorages.containsKey(name)) return _mapStorages.get(name)._setLocomotives.Get(position); + else return null; + } }