From 2d621bbe701e359804d5c68ec2d31f14326f920f Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 5 Nov 2022 18:49:21 +0400 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=83=D1=81=D0=BB=D0=BE=D0=B6=D0=BD=D0=B5=D0=BD=D0=BD=D0=BE?= =?UTF-8?q?=D0=B9=20=D1=87=D0=B0=D1=81=D1=82=D0=B8=204=20=D0=BB=D0=B0?= =?UTF-8?q?=D0=B1=D1=8B=20=D0=B2=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D1=8B,=20=D1=82=D1=80=D0=B5=D0=B1=D1=83=D0=B5=D1=82=D1=81?= =?UTF-8?q?=D1=8F=20=D1=87=D0=B8=D1=81=D1=82=D0=BA=D0=B0,=20=D1=80=D0=B5?= =?UTF-8?q?=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=BD=D0=B3=20=D0=B8?= =?UTF-8?q?=20=D1=83=D1=82=D0=BE=D1=87=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D1=82=D1=80=D0=B5=D0=B1=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B9=20?= =?UTF-8?q?=D0=BA=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrawningObjectLocomotive.java | 3 +++ FormLocomotive.java | 5 +++++ FormMapWithSetLocomotives.java | 22 ++++++++++++++++++++++ MapWithSetLocomotivesGeneric.java | 17 +++++++++++++++-- MapsCollection.java | 7 +++++++ 5 files changed, 52 insertions(+), 2 deletions(-) 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; + } }