From 12d639e3dfa3889060be1f4324f654f8ee81268f Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Wed, 14 Dec 2022 15:30:36 +0400 Subject: [PATCH] complete --- DrawningObjectPlane.java | 3 + FormMapWithSetPlanes.form | 284 ++++++++++++++++++++--------------- FormPlane.java | 16 +- Main.java | 3 +- MapWithSetPlanesGeneric.java | 19 ++- MapsCollection.java | 44 ++++++ SetPlanesGeneric.java | 58 ++++--- 7 files changed, 275 insertions(+), 152 deletions(-) create mode 100644 MapsCollection.java diff --git a/DrawningObjectPlane.java b/DrawningObjectPlane.java index 1353dd5..86c7ca0 100644 --- a/DrawningObjectPlane.java +++ b/DrawningObjectPlane.java @@ -35,4 +35,7 @@ public class DrawningObjectPlane implements IDrawningObject { return _plane.GetCurrentPosition(); return null; } + public DrawningPlane GetDrawningObjectPlane() { + return _plane; + } } diff --git a/FormMapWithSetPlanes.form b/FormMapWithSetPlanes.form index 6e0d047..749be9b 100644 --- a/FormMapWithSetPlanes.form +++ b/FormMapWithSetPlanes.form @@ -1,164 +1,200 @@
- + - + - + - + + + + + - + + + - + + + + + + - - - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FormPlane.java b/FormPlane.java index 8ef35b8..1435036 100644 --- a/FormPlane.java +++ b/FormPlane.java @@ -50,7 +50,8 @@ public class FormPlane extends JDialog{ JLabelWeight.setText("Вес: " + _plane.GetPlane().GetWeight() + " "); JLabelColor.setText(("Цвет: " + _plane.GetPlane().GetBodyColor() + " ")); } - public FormPlane() { + + private void CreateWindow(){ add(Mainpanel); Box LabelBox = Box.createHorizontalBox(); LabelBox.setMinimumSize(new Dimension(1, 20)); @@ -121,5 +122,18 @@ public class FormPlane extends JDialog{ dispose(); }); } + public FormPlane() { + super(new Frame("Самолёт")); + CreateWindow(); + setModal(true); + getContentPane().add(Mainpanel); + } + public FormPlane(DrawningObjectPlane plane){ + super(new Frame("Корабль")); + CreateWindow(); + setModal(true); + _plane = plane.GetDrawningObjectPlane(); + getContentPane().add(Mainpanel); + } } diff --git a/Main.java b/Main.java index f163727..f38f398 100644 --- a/Main.java +++ b/Main.java @@ -4,8 +4,7 @@ public class Main { public static void main(String[] args) { JFrame frame = new JFrame("Самолёт"); -// frame.setContentPane(new FormMapWithSetPlanes().Mainpanel); - frame.setContentPane(new FormParam().MainPanel); + frame.setContentPane(new FormMapWithSetPlanes().Mainpanel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocation(500, 200); frame.pack(); diff --git a/MapWithSetPlanesGeneric.java b/MapWithSetPlanesGeneric.java index 09c9602..556df29 100644 --- a/MapWithSetPlanesGeneric.java +++ b/MapWithSetPlanesGeneric.java @@ -1,5 +1,6 @@ import java.awt.*; import java.awt.image.BufferedImage; +import java.util.LinkedList; public class MapWithSetPlanesGeneric { @@ -9,9 +10,11 @@ public class MapWithSetPlanesGeneric _setPlanes; private U _map; + private LinkedList _deletedPlanes; public MapWithSetPlanesGeneric(int picWidth, int picHeight, U map) { + _deletedPlanes = new LinkedList<>(); int width = picWidth / _placeSizeWidth; int height = picHeight / _placeSizeHeight; _setPlanes = new SetPlanesGeneric(width * height); @@ -27,7 +30,9 @@ public class MapWithSetPlanesGeneric > _mapStorages; + public ArrayList Keys() + { + return new ArrayList<>(_mapStorages.keySet()); + } + private final int _pictureWidth; + private final int _pictureHeight; + public MapsCollection(int pictureWidth,int pictureHeight) + { + _mapStorages=new HashMap<>(); + _pictureWidth=pictureWidth; + _pictureHeight=pictureHeight; + } + public void AddMap(String Name, AbstractMap Map) + { + if(!_mapStorages.containsKey(Name)) + { + _mapStorages.put(Name,new MapWithSetPlanesGeneric<>(_pictureWidth,_pictureHeight,Map)); + } + } + public void DelMap(String name) + { + _mapStorages.remove(name); + } + public MapWithSetPlanesGeneric Get(String ind) + { + if(_mapStorages.containsKey(ind)) + { + return _mapStorages.get(ind); + } + return null; + } + public DrawningObjectPlane Get(String name, int ind) { + if (_mapStorages.containsKey(name)) + { + return _mapStorages.get(name).GetSelectedPlane(ind); + } + return null; + } +} diff --git a/SetPlanesGeneric.java b/SetPlanesGeneric.java index 7eb7932..896a50c 100644 --- a/SetPlanesGeneric.java +++ b/SetPlanesGeneric.java @@ -1,44 +1,54 @@ -public class SetPlanesGeneric { - private T[] _places; +import java.util.ArrayList; +import java.util.Iterator; +public class SetPlanesGeneric implements Iterable { + private ArrayList _places; + private final int _maxCount; public int Count() { - return _places.length; + return _places.size(); } public SetPlanesGeneric(int count) { - _places = (T[]) (new Object[count]); + _maxCount=count; + _places = new ArrayList<>(); } public int Insert(T plane) { - for (int i = 0; i < _places.length; i++) { - if (_places[i] == null) { - _places[i] = plane; - return i; - } - } - return -1; + return Insert(plane, 0); } public int Insert(T plane, int position) { - int index = position; - - while (_places[index] != null && index < _places.length) index++; - - if (index == _places.length) return -1; - for (int i = index; i > position; --i) _places[i] = _places[i - 1]; - - _places[position] = plane; + if (position < 0 || position > Count() || _maxCount == Count()) return -1; + _places.add(position,plane); return position; } public T Remove(int position) { - if (position >= _places.length) return null; - T res = _places[position]; - _places[position] = null; - return res; + if (position >= Count() || position < 0) + { + return null; + } + T ship = (T) _places.get(position); + _places.remove(ship); + return ship; } public T Get(int position) { - return _places[position]; + if (position >= Count() || position<0) + { + return null; + } + return _places.get(position); + } + public void Set(int position,T value) + { + if (position < _maxCount || position >= 0) + { + Insert(value,position); + } + } + @Override + public Iterator iterator() { + return _places.iterator(); } } \ No newline at end of file