This commit is contained in:
ArtemEmelyanov 2022-12-14 15:30:36 +04:00
parent 41c6423777
commit 12d639e3df
7 changed files with 275 additions and 152 deletions

View File

@ -35,4 +35,7 @@ public class DrawningObjectPlane implements IDrawningObject {
return _plane.GetCurrentPosition();
return null;
}
public DrawningPlane GetDrawningObjectPlane() {
return _plane;
}
}

View File

@ -1,164 +1,200 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMapWithSetPlanes">
<grid id="27dc6" binding="Mainpanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="Mainpanel" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="785" height="400"/>
<xy x="20" y="20" width="798" height="526"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="afa3d" binding="PictureBox" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
<grid id="9bb5a" binding="pictureBoxPlane" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="3" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="600" height="500"/>
<preferred-size width="600" height="500"/>
<maximum-size width="600" height="500"/>
</grid>
</constraints>
<properties/>
<properties>
<enabled value="true"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="e9a63" binding="groupBox" layout-manager="GridLayoutManager" row-count="10" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<hspacer id="b305e">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<grid id="4fa91" binding="GroupBoxTools" layout-manager="GridLayoutManager" row-count="8" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="150" height="-1"/>
</grid>
<grid row="1" column="1" row-span="3" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="f23ee" class="javax.swing.JButton" binding="buttonAdd">
<component id="cdb80" class="javax.swing.JButton" binding="ButtonAddPlane">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Добавить самолёт"/>
</properties>
</component>
<component id="2e61e" class="javax.swing.JComboBox" binding="comboBoxSelectorMap">
<component id="e5494" class="javax.swing.JTextField" binding="maskedTextBoxPosition">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<model/>
</properties>
</component>
<component id="5c428" class="javax.swing.JButton" binding="buttonRemove">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Удалить самолёт"/>
</properties>
</component>
<component id="e24b9" class="javax.swing.JButton" binding="buttonShowStorage">
<constraints>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Посмотреть Хранилище"/>
</properties>
</component>
<component id="ac087" class="javax.swing.JButton" binding="buttonShowOnMap">
<constraints>
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Посмотреть карту"/>
</properties>
</component>
<grid id="2821b" layout-manager="GridLayoutManager" row-count="2" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="9" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="6d803" class="javax.swing.JButton" binding="buttonLeft">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="c0db2" class="javax.swing.JButton" binding="buttonUp">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="ca0da" class="javax.swing.JButton" binding="buttonDown">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="c3e45" class="javax.swing.JButton" binding="buttonRight">
<constraints>
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<hspacer id="1f200">
<constraints>
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="f8b3b">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
<vspacer id="b833e">
<constraints>
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="181ac" class="javax.swing.JTextField" binding="textBoxPosition">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<vspacer id="53ec0">
<component id="8bb89" class="javax.swing.JButton" binding="ButtonDeletePlane">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Удалить самолёт"/>
</properties>
</component>
<component id="aa482" class="javax.swing.JButton" binding="ButtonShowStorage">
<constraints>
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Показать хранилище"/>
</properties>
</component>
<component id="9ebdc" class="javax.swing.JButton" binding="ButtonShowMap">
<constraints>
<grid row="4" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Показать карту"/>
</properties>
</component>
<component id="acbc" class="javax.swing.JButton" binding="ButtonUp">
<constraints>
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="a584e" class="javax.swing.JButton" binding="ButtonDown">
<constraints>
<grid row="7" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="e9fe6" class="javax.swing.JButton" binding="ButtonLeft">
<constraints>
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="25a22" class="javax.swing.JButton" binding="ButtonRight">
<constraints>
<grid row="7" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="6734a" class="javax.swing.JButton" binding="ButtonCheckDel">
<constraints>
<grid row="5" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Удаленные"/>
</properties>
</component>
</children>
</grid>
<grid id="d087c" binding="GroupBoxMaps" layout-manager="GridLayoutManager" row-count="7" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="124b6" class="javax.swing.JTextField" binding="textBoxNewMapName">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<vspacer id="3ed0f">
<constraints>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="a6919">
<component id="95ba3" class="javax.swing.JComboBox" binding="ComboBoxSelectorMap">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<model>
<item value="Простая карта"/>
<item value="Карта острова"/>
<item value="Карта скалы"/>
</model>
</properties>
</component>
<component id="fb777" class="javax.swing.JButton" binding="ButtonAddMap">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Добавить карту"/>
</properties>
</component>
<component id="a358a" class="javax.swing.JButton" binding="ButtonDeleteMap">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Удалить карту"/>
</properties>
</component>
<vspacer id="64e67">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="e221" class="javax.swing.JList" binding="ListBoxMaps" custom-create="true">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="50"/>
</grid>
</constraints>
<properties/>
</component>
</children>
</grid>
</children>

View File

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

View File

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

View File

@ -1,5 +1,6 @@
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.LinkedList;
public class MapWithSetPlanesGeneric <T extends IDrawningObject, U extends AbstractMap>
{
@ -9,9 +10,11 @@ public class MapWithSetPlanesGeneric <T extends IDrawningObject, U extends Abstr
private int _placeSizeHeight = 90;
private SetPlanesGeneric<T> _setPlanes;
private U _map;
private LinkedList<T> _deletedPlanes;
public MapWithSetPlanesGeneric(int picWidth, int picHeight, U map)
{
_deletedPlanes = new LinkedList<>();
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_setPlanes = new SetPlanesGeneric<T>(width * height);
@ -27,7 +30,9 @@ public class MapWithSetPlanesGeneric <T extends IDrawningObject, U extends Abstr
public T removePlane(int position)
{
return _setPlanes.Remove(position);
T plane = _setPlanes.Remove(position);
_deletedPlanes.offerFirst(plane);
return plane;
}
public BufferedImage ShowSet()
@ -135,4 +140,16 @@ public class MapWithSetPlanesGeneric <T extends IDrawningObject, U extends Abstr
}
}
}
public T GetSelectedPlane(int ind){
return _setPlanes.Get(ind);
}
public T GetPlanesDeleted()
{
if(_deletedPlanes.isEmpty())
{
return null;
}
return _deletedPlanes.removeFirst();
}
}

44
MapsCollection.java Normal file
View File

@ -0,0 +1,44 @@
import java.util.ArrayList;
import java.util.HashMap;
public class MapsCollection {
private final HashMap<String,MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap>> _mapStorages;
public ArrayList<String> 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<DrawningObjectPlane,AbstractMap> 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;
}
}

View File

@ -1,44 +1,54 @@
public class SetPlanesGeneric<T> {
private T[] _places;
import java.util.ArrayList;
import java.util.Iterator;
public class SetPlanesGeneric<T extends Object> implements Iterable<T> {
private ArrayList<T> _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<T> iterator() {
return _places.iterator();
}
}