Mochalov D.V. Hard LabWork04 #4

Closed
b0n3l3sS wants to merge 6 commits from LabWork04 into LabWork03
5 changed files with 52 additions and 2 deletions
Showing only changes of commit 2d621bbe70 - Show all commits

View File

@ -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)
{

View File

@ -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();

View File

@ -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);
}

View File

@ -1,5 +1,6 @@
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.LinkedList;
public class MapWithSetLocomotivesGeneric
<T extends IDrawningObject, U extends AbstractMap>
@ -14,7 +15,16 @@ public class MapWithSetLocomotivesGeneric
private final int _placeSizeHeight = 90;
/// Набор объектов
private final SetLocomotivesGeneric<T> _setLocomotives;
//TODO переделал на public, узнать так ли вообще надо?
public final SetLocomotivesGeneric<T> _setLocomotives;
// Список удаленных объектов
LinkedList<DrawningObjectLocomotive> 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()

View File

@ -4,6 +4,7 @@ import java.util.HashMap;
public class MapsCollection {
/// Словарь (хранилище) с картами
final HashMap<String, MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap>> _mapStorages;
/// Возвращение списка названий карт
public ArrayList<String> keys() {
return new ArrayList<String>(_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;
}
}