diff --git a/FormMapWithSetBoats.java b/FormMapWithSetBoats.java index a08b182..c6b4b01 100644 --- a/FormMapWithSetBoats.java +++ b/FormMapWithSetBoats.java @@ -1,6 +1,14 @@ import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.image.BufferedImage; +import java.util.HashMap; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; public class FormMapWithSetBoats extends JFrame { diff --git a/MapWithSetBoatsGeneric.java b/MapWithSetBoatsGeneric.java index 771d160..b36e8e9 100644 --- a/MapWithSetBoatsGeneric.java +++ b/MapWithSetBoatsGeneric.java @@ -1,5 +1,6 @@ import java.awt.*; import java.awt.image.BufferedImage; +import java.util.LinkedList; public class MapWithSetBoatsGeneric { @@ -9,9 +10,12 @@ public class MapWithSetBoatsGeneric _setBoats; private U _map; + private LinkedList _deletedBoats; + public MapWithSetBoatsGeneric(int picWidth, int picHeight, U map) { + _deletedBoats = new LinkedList<>(); int width = picWidth / _placeSizeWidth; int height = picHeight / _placeSizeHeight; _setBoats = new SetBoatsGeneric(width * height); @@ -27,7 +31,9 @@ public class MapWithSetBoatsGeneric > _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 MapWithSetBoatsGeneric<>(_pictureWidth,_pictureHeight,Map)); + } + } + public void DelMap(String name) + { + _mapStorages.remove(name); + } + public MapWithSetBoatsGeneric Get(String ind) + { + if(_mapStorages.containsKey(ind)) + { + return _mapStorages.get(ind); + } + return null; + } + public DrawningObjectBoat Get(String name, int ind) { + if (_mapStorages.containsKey(name)) + { + return _mapStorages.get(name).GetSelectedBoat(ind); + } + return null; + } +} diff --git a/SetBoatsGeneric.java b/SetBoatsGeneric.java index 255c57e..513f301 100644 --- a/SetBoatsGeneric.java +++ b/SetBoatsGeneric.java @@ -1,44 +1,54 @@ +import java.util.ArrayList; +import java.util.Iterator; public class SetBoatsGeneric { - private T[] _places; - + private ArrayList _places; + private final int _maxCount; public int Count() { - return _places.length; + return _places.size(); } public SetBoatsGeneric(int count) { - _places = (T[]) (new Object[count]); + _maxCount=count; + _places = new ArrayList<>(); } public int Insert(T boat) { - for (int i = 0; i < _places.length; i++) { - if (_places[i] == null) { - _places[i] = boat; - return i; - } - } - return -1; + return Insert(boat, 0); + } public int Insert(T boat, 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] = boat; + if (position < 0 || position > Count() || _maxCount == Count()) return -1; + _places.add(position,boat); 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(); } }