LabWork04 is done.
This commit is contained in:
parent
65ee7b9c39
commit
5a56586e50
2
App.java
2
App.java
@ -7,6 +7,6 @@ import javax.swing.*;
|
|||||||
public class App
|
public class App
|
||||||
{
|
{
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new FormAirport();
|
FormMapWithSetAircrafts form = new FormMapWithSetAircrafts();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,11 @@ public class DrawingAircraft
|
|||||||
public EntityAircraft Plane;
|
public EntityAircraft Plane;
|
||||||
private IDrawingEngines _engines;
|
private IDrawingEngines _engines;
|
||||||
|
|
||||||
|
|
||||||
protected int _startPosX;
|
protected int _startPosX;
|
||||||
protected int _startPosY;
|
protected int _startPosY;
|
||||||
|
|
||||||
private Integer _pictureWidth = null;
|
public Integer _pictureWidth = null;
|
||||||
private Integer _pictureHeight = null;
|
public Integer _pictureHeight = null;
|
||||||
|
|
||||||
protected final int _aircraftWidth = 100;
|
protected final int _aircraftWidth = 100;
|
||||||
protected final int _aircraftHeight = 120;
|
protected final int _aircraftHeight = 120;
|
||||||
|
@ -3,12 +3,17 @@ package Classes;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawingObjectAircraft implements IDrawingObject {
|
public class DrawingObjectAircraft implements IDrawingObject {
|
||||||
private DrawingAircraft _aircraft = null;
|
private DrawingAircraft _aircraft;
|
||||||
|
|
||||||
public DrawingObjectAircraft(DrawingAircraft aircraft)
|
public DrawingObjectAircraft(DrawingAircraft aircraft)
|
||||||
{
|
{
|
||||||
_aircraft = aircraft;
|
_aircraft = aircraft;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DrawingAircraft getAircraft()
|
||||||
|
{
|
||||||
|
return _aircraft;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public float getStep()
|
public float getStep()
|
||||||
{
|
{
|
||||||
|
@ -40,6 +40,11 @@ public class MapWithSetAircraftsGeneric <T extends IDrawingObject,U extends Abst
|
|||||||
return map._setAircrafts.Remove(position);
|
return map._setAircrafts.Remove(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T getAircraft(MapWithSetAircraftsGeneric<T, U> map, int position)
|
||||||
|
{
|
||||||
|
return map._setAircrafts.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
public Image showSet()
|
public Image showSet()
|
||||||
{
|
{
|
||||||
BufferedImage img = new BufferedImage(_pictureWidth,_pictureHeight,BufferedImage.TYPE_INT_ARGB);
|
BufferedImage img = new BufferedImage(_pictureWidth,_pictureHeight,BufferedImage.TYPE_INT_ARGB);
|
||||||
|
47
Classes/MapsCollection.java
Normal file
47
Classes/MapsCollection.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package Classes;
|
||||||
|
|
||||||
|
import Classes.Maps.AbstractMap;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class MapsCollection
|
||||||
|
{
|
||||||
|
final HashMap<String,MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap>> _mapsVault;
|
||||||
|
|
||||||
|
public ArrayList<String> Keys;
|
||||||
|
|
||||||
|
private final int _pictureWidth;
|
||||||
|
private final int _pictureHeight;
|
||||||
|
|
||||||
|
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
_mapsVault = new HashMap<String, MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap>>();
|
||||||
|
Keys = new ArrayList<>(_mapsVault.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddMap(String name, AbstractMap map)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!Keys.contains(name))
|
||||||
|
{
|
||||||
|
_mapsVault.put(name, new MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||||
|
}
|
||||||
|
Keys = new ArrayList<>(_mapsVault.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteMap(String name)
|
||||||
|
{
|
||||||
|
if (Keys.contains(name))
|
||||||
|
{
|
||||||
|
_mapsVault.remove(name);
|
||||||
|
}
|
||||||
|
Keys = new ArrayList<>(_mapsVault.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public MapWithSetAircraftsGeneric<DrawingObjectAircraft,AbstractMap> getMap(String ind)
|
||||||
|
{
|
||||||
|
return _mapsVault.getOrDefault(ind, null);
|
||||||
|
}
|
||||||
|
}
|
@ -57,7 +57,7 @@ public class SetAircraftsGeneric<T>
|
|||||||
|
|
||||||
public T get(int position)
|
public T get(int position)
|
||||||
{
|
{
|
||||||
if (position < _maxCount && position >= 0)
|
if (position < _maxCount && position >= 0 && position < getCount())
|
||||||
{
|
{
|
||||||
return _places.get(position);
|
return _places.get(position);
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,6 @@ import javax.swing.*;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.ComponentAdapter;
|
|
||||||
import java.awt.event.ComponentEvent;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class FormAirFighter extends JDialog
|
public class FormAirFighter extends JDialog
|
||||||
@ -47,7 +45,7 @@ public class FormAirFighter extends JDialog
|
|||||||
_aircraft.MoveTransport(Direction.Down);
|
_aircraft.MoveTransport(Direction.Down);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Draw();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetData()
|
private void SetData()
|
||||||
@ -57,6 +55,7 @@ public class FormAirFighter extends JDialog
|
|||||||
_aircraft.SetPosition(
|
_aircraft.SetPosition(
|
||||||
rnd.nextInt(0, 100),
|
rnd.nextInt(0, 100),
|
||||||
rnd.nextInt(0, 100),
|
rnd.nextInt(0, 100),
|
||||||
|
|
||||||
Form.getWidth(),
|
Form.getWidth(),
|
||||||
Form.getHeight()
|
Form.getHeight()
|
||||||
);
|
);
|
||||||
@ -64,6 +63,20 @@ public class FormAirFighter extends JDialog
|
|||||||
weightLabel.setText("Weight: " + _aircraft.Plane.getWeight());
|
weightLabel.setText("Weight: " + _aircraft.Plane.getWeight());
|
||||||
colorLabel.setText("Color: " + _aircraft.Plane.getBodyColor());
|
colorLabel.setText("Color: " + _aircraft.Plane.getBodyColor());
|
||||||
}
|
}
|
||||||
|
private void SetData(int width, int height)
|
||||||
|
{
|
||||||
|
Random rnd = new Random();
|
||||||
|
|
||||||
|
_aircraft.SetPosition(
|
||||||
|
rnd.nextInt(0, 100),
|
||||||
|
rnd.nextInt(0, 100),
|
||||||
|
width,
|
||||||
|
height
|
||||||
|
);
|
||||||
|
speedLabel.setText("Speed: " + _aircraft.Plane.getSpeed());
|
||||||
|
weightLabel.setText("Weight: " + _aircraft.Plane.getWeight());
|
||||||
|
colorLabel.setText("Color: " + _aircraft.Plane.getBodyColor());
|
||||||
|
}
|
||||||
|
|
||||||
private void CreateEntity() {
|
private void CreateEntity() {
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
@ -74,7 +87,7 @@ public class FormAirFighter extends JDialog
|
|||||||
|
|
||||||
SetData();
|
SetData();
|
||||||
|
|
||||||
Draw();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateModifiedEntity()
|
private void CreateModifiedEntity()
|
||||||
@ -87,7 +100,7 @@ public class FormAirFighter extends JDialog
|
|||||||
_aircraft = new DrawingMilitaryAircraft(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
_aircraft = new DrawingMilitaryAircraft(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||||
color, dopColor, rnd.nextBoolean(), rnd.nextBoolean());
|
color, dopColor, rnd.nextBoolean(), rnd.nextBoolean());
|
||||||
SetData();
|
SetData();
|
||||||
Draw();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void selectAircraft()
|
private void selectAircraft()
|
||||||
@ -101,21 +114,13 @@ public class FormAirFighter extends JDialog
|
|||||||
|
|
||||||
private void resizeWindow() {
|
private void resizeWindow() {
|
||||||
_aircraft.ChangeBorders(pictureBox.getWidth(), pictureBox.getHeight());
|
_aircraft.ChangeBorders(pictureBox.getWidth(), pictureBox.getHeight());
|
||||||
Draw();
|
repaint();
|
||||||
}
|
|
||||||
|
|
||||||
private void Draw() {
|
|
||||||
Graphics2D graphics = (Graphics2D) pictureBox.getGraphics();
|
|
||||||
graphics.clearRect(0, 0, pictureBox.getWidth(), pictureBox.getHeight());
|
|
||||||
pictureBox.paintComponents(graphics);
|
|
||||||
_aircraft.DrawTransport(graphics);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public FormAirFighter() {
|
public FormAirFighter() {
|
||||||
|
|
||||||
setContentPane(Form);
|
setContentPane(Form);
|
||||||
|
|
||||||
|
|
||||||
// action move //
|
// action move //
|
||||||
ActionListener listener = this::moveButtonClick;
|
ActionListener listener = this::moveButtonClick;
|
||||||
moveRight.addActionListener(listener);
|
moveRight.addActionListener(listener);
|
||||||
@ -123,16 +128,26 @@ public class FormAirFighter extends JDialog
|
|||||||
moveLeft.addActionListener(listener);
|
moveLeft.addActionListener(listener);
|
||||||
moveUp.addActionListener(listener);
|
moveUp.addActionListener(listener);
|
||||||
|
|
||||||
|
|
||||||
btnCreate.addActionListener(e -> CreateEntity());
|
btnCreate.addActionListener(e -> CreateEntity());
|
||||||
btnModification.addActionListener(e -> CreateModifiedEntity());
|
btnModification.addActionListener(e -> CreateModifiedEntity());
|
||||||
SelectButton.addActionListener(e -> selectAircraft());
|
SelectButton.addActionListener(e -> selectAircraft());
|
||||||
/*Form.addComponentListener(new ComponentAdapter() {
|
|
||||||
@Override
|
|
||||||
public void componentResized(ComponentEvent e) {
|
|
||||||
super.componentResized(e);
|
|
||||||
resizeWindow();
|
|
||||||
}
|
|
||||||
});*/
|
|
||||||
}
|
}
|
||||||
|
public FormAirFighter(DrawingAircraft aircraft)
|
||||||
|
{
|
||||||
|
this();
|
||||||
|
_aircraft = aircraft;
|
||||||
|
SetData(_aircraft._pictureWidth, aircraft._pictureHeight);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
super.paint(g);
|
||||||
|
Graphics2D graphics = (Graphics2D) pictureBox.getGraphics();
|
||||||
|
if(_aircraft != null)
|
||||||
|
{
|
||||||
|
_aircraft.DrawTransport(graphics);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,6 @@ public class FormAirport extends JFrame{
|
|||||||
public FormAirport()
|
public FormAirport()
|
||||||
{
|
{
|
||||||
setContentPane(Form);
|
setContentPane(Form);
|
||||||
|
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
parts = new EntityWithEngines<>();
|
parts = new EntityWithEngines<>();
|
||||||
int mod = 0;
|
int mod = 0;
|
||||||
@ -89,7 +88,6 @@ public class FormAirport extends JFrame{
|
|||||||
});
|
});
|
||||||
|
|
||||||
setSize(new Dimension(600, 600));
|
setSize(new Dimension(600, 600));
|
||||||
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="Form.FormMapWithSetAircrafts">
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="Form.FormMapWithSetAircrafts">
|
||||||
<grid id="27dc6" binding="Form" layout-manager="BorderLayout" hgap="0" vgap="0">
|
<grid id="27dc6" binding="Form" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||||
<constraints>
|
<constraints>
|
||||||
<xy x="20" y="20" width="808" height="552"/>
|
<xy x="20" y="20" width="808" height="664"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties/>
|
<properties/>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
@ -20,7 +20,7 @@
|
|||||||
</hspacer>
|
</hspacer>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
<grid id="4c74b" layout-manager="GridLayoutManager" row-count="9" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="4c74b" layout-manager="GridLayoutManager" row-count="15" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints border-constraint="East"/>
|
<constraints border-constraint="East"/>
|
||||||
<properties/>
|
<properties/>
|
||||||
@ -28,7 +28,7 @@
|
|||||||
<children>
|
<children>
|
||||||
<component id="e569a" class="javax.swing.JComboBox" binding="comboBoxMapSelection">
|
<component id="e569a" class="javax.swing.JComboBox" binding="comboBoxMapSelection">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="2" hsize-policy="2" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="2" hsize-policy="2" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<model>
|
<model>
|
||||||
@ -39,7 +39,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="d798e" class="javax.swing.JButton" binding="AddAircraftButton">
|
<component id="d798e" class="javax.swing.JButton" binding="AddAircraftButton">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
<grid row="7" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Add aircraft"/>
|
<text value="Add aircraft"/>
|
||||||
@ -47,7 +47,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="f4aba" class="javax.swing.JFormattedTextField" binding="maskedTextBoxPosition">
|
<component id="f4aba" class="javax.swing.JFormattedTextField" binding="maskedTextBoxPosition">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
<grid row="8" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||||
<preferred-size width="150" height="-1"/>
|
<preferred-size width="150" height="-1"/>
|
||||||
</grid>
|
</grid>
|
||||||
</constraints>
|
</constraints>
|
||||||
@ -55,7 +55,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="192c4" class="javax.swing.JButton" binding="DeleteAircraftButton">
|
<component id="192c4" class="javax.swing.JButton" binding="DeleteAircraftButton">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
<grid row="9" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Delete aircraft"/>
|
<text value="Delete aircraft"/>
|
||||||
@ -63,7 +63,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="f84e6" class="javax.swing.JButton" binding="ShowHangarButton">
|
<component id="f84e6" class="javax.swing.JButton" binding="ShowHangarButton">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="4" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
<grid row="10" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Show hangar"/>
|
<text value="Show hangar"/>
|
||||||
@ -71,7 +71,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="1a170" class="javax.swing.JButton" binding="ShowMapButton">
|
<component id="1a170" class="javax.swing.JButton" binding="ShowMapButton">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="5" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
<grid row="11" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Show map"/>
|
<text value="Show map"/>
|
||||||
@ -79,7 +79,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="32298" class="javax.swing.JButton" binding="moveUp">
|
<component id="32298" class="javax.swing.JButton" binding="moveUp">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="7" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="2" fill="0" indent="0" use-parent-layout="false">
|
<grid row="13" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="2" fill="0" indent="0" use-parent-layout="false">
|
||||||
<minimum-size width="30" height="30"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -93,7 +93,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="6a898" class="javax.swing.JButton" binding="moveLeft">
|
<component id="6a898" class="javax.swing.JButton" binding="moveLeft">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="0" indent="0" use-parent-layout="false">
|
<grid row="14" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="0" indent="0" use-parent-layout="false">
|
||||||
<minimum-size width="30" height="30"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -107,7 +107,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="c514d" class="javax.swing.JButton" binding="moveDown">
|
<component id="c514d" class="javax.swing.JButton" binding="moveDown">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="8" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="0" indent="0" use-parent-layout="false">
|
<grid row="14" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="0" indent="0" use-parent-layout="false">
|
||||||
<minimum-size width="30" height="30"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -121,7 +121,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="a2ec2" class="javax.swing.JButton" binding="moveRight">
|
<component id="a2ec2" class="javax.swing.JButton" binding="moveRight">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="8" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="0" indent="0" use-parent-layout="false">
|
<grid row="14" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="0" indent="0" use-parent-layout="false">
|
||||||
<minimum-size width="30" height="30"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -135,7 +135,54 @@
|
|||||||
</component>
|
</component>
|
||||||
<vspacer id="5a9ee">
|
<vspacer id="5a9ee">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
<grid row="12" column="1" 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="afff2" class="javax.swing.JTextField" binding="newMapTextBox">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" 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>
|
||||||
|
<component id="7184d" class="javax.swing.JButton" binding="AddMapButton">
|
||||||
|
<constraints>
|
||||||
|
<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="Add map"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="666a1" class="javax.swing.JList" binding="listBoxMaps">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="0" row-span="1" col-span="3" 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>
|
||||||
|
<component id="302" class="javax.swing.JButton" binding="DeleteMapButton">
|
||||||
|
<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="Delete map"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="310e8" class="javax.swing.JButton" binding="showDeletedAircrafts">
|
||||||
|
<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="Deleted"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<vspacer id="9b864">
|
||||||
|
<constraints>
|
||||||
|
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="-1" height="150"/>
|
||||||
|
</grid>
|
||||||
</constraints>
|
</constraints>
|
||||||
</vspacer>
|
</vspacer>
|
||||||
</children>
|
</children>
|
||||||
|
@ -2,10 +2,11 @@ package Form;
|
|||||||
|
|
||||||
import Classes.Direction;
|
import Classes.Direction;
|
||||||
import Classes.DrawingObjectAircraft;
|
import Classes.DrawingObjectAircraft;
|
||||||
import Classes.MapWithSetAircraftsGeneric;
|
import Classes.IDrawingObject;
|
||||||
import Classes.Maps.AbstractMap;
|
import Classes.Maps.AbstractMap;
|
||||||
import Classes.Maps.NightSkyMap;
|
import Classes.Maps.NightSkyMap;
|
||||||
import Classes.Maps.SimpleMap;
|
import Classes.Maps.SimpleMap;
|
||||||
|
import Classes.MapsCollection;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.text.DefaultFormatterFactory;
|
import javax.swing.text.DefaultFormatterFactory;
|
||||||
@ -13,9 +14,11 @@ import javax.swing.text.MaskFormatter;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.ComponentAdapter;
|
|
||||||
import java.awt.event.ComponentEvent;
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Queue;
|
||||||
|
|
||||||
public class FormMapWithSetAircrafts extends JFrame
|
public class FormMapWithSetAircrafts extends JFrame
|
||||||
{
|
{
|
||||||
@ -32,45 +35,76 @@ public class FormMapWithSetAircrafts extends JFrame
|
|||||||
private JButton moveLeft;
|
private JButton moveLeft;
|
||||||
private JButton moveRight;
|
private JButton moveRight;
|
||||||
private JFormattedTextField maskedTextBoxPosition;
|
private JFormattedTextField maskedTextBoxPosition;
|
||||||
|
private JTextField newMapTextBox;
|
||||||
|
private JButton AddMapButton;
|
||||||
|
private JList listBoxMaps;
|
||||||
|
|
||||||
|
DefaultListModel listModel;
|
||||||
|
private JButton DeleteMapButton;
|
||||||
|
private JButton showDeletedAircrafts;
|
||||||
|
|
||||||
public Image bufferedImage;
|
public Image bufferedImage;
|
||||||
|
|
||||||
private MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap> _mapAircraftsCollectionGeneric;
|
private final MapsCollection _mapsCollection;
|
||||||
|
public Queue<IDrawingObject> deletedAircrafts;
|
||||||
|
|
||||||
|
FormAirFighter form;
|
||||||
|
|
||||||
|
private final HashMap<String, AbstractMap> _mapsDict = new HashMap<>(){{
|
||||||
|
put("1. Simple map", new SimpleMap());
|
||||||
|
put("2. NightSky map", new NightSkyMap());
|
||||||
|
}};
|
||||||
|
|
||||||
|
private void RefreshMaps()
|
||||||
|
{
|
||||||
|
int index = listBoxMaps.getSelectedIndex();
|
||||||
|
|
||||||
|
listBoxMaps.removeAll();
|
||||||
|
|
||||||
|
listModel = new DefaultListModel();
|
||||||
|
for (int i = 0; i < _mapsCollection.Keys.size(); i++)
|
||||||
|
{
|
||||||
|
listModel.addElement(_mapsCollection.Keys.get(i));
|
||||||
|
|
||||||
|
}
|
||||||
|
listBoxMaps.setModel(listModel);
|
||||||
|
if (listBoxMaps.getModel().getSize() > 0 && (index == -1 || index >= listBoxMaps.getModel().getSize()))
|
||||||
|
{
|
||||||
|
listBoxMaps.setSelectedIndex(0);
|
||||||
|
}
|
||||||
|
else if (listBoxMaps.getModel().getSize() > 0 && index > -1 && index < listBoxMaps.getModel().getSize())
|
||||||
|
{
|
||||||
|
listBoxMaps.setSelectedIndex(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void showMap()
|
private void showMap()
|
||||||
{
|
{
|
||||||
if(_mapAircraftsCollectionGeneric == null)
|
if(listBoxMaps.getSelectedIndex() == -1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bufferedImage = _mapAircraftsCollectionGeneric.ShowOnMap();
|
bufferedImage = _mapsCollection.getMap((String) Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).ShowOnMap();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void indexChanged()
|
private void indexChanged()
|
||||||
{
|
{
|
||||||
AbstractMap map = null;
|
if(listBoxMaps.getSelectedValue() != null)
|
||||||
switch (comboBoxMapSelection.getSelectedItem().toString()) {
|
|
||||||
case "1. Simple map" -> map = new SimpleMap();
|
|
||||||
case "2. NightSky map" -> map = new NightSkyMap();
|
|
||||||
}
|
|
||||||
if(map != null)
|
|
||||||
{
|
{
|
||||||
_mapAircraftsCollectionGeneric = new MapWithSetAircraftsGeneric<>(pictureBox.getWidth(),pictureBox.getHeight(),map);
|
bufferedImage = _mapsCollection.getMap((String) Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).showSet();
|
||||||
}
|
repaint();
|
||||||
else
|
|
||||||
{
|
|
||||||
_mapAircraftsCollectionGeneric = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addAircraft()
|
private void addAircraft()
|
||||||
{
|
{
|
||||||
if(_mapAircraftsCollectionGeneric == null)
|
if(listBoxMaps.getSelectedIndex() == -1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FormAirFighter form = new FormAirFighter();
|
form = new FormAirFighter();
|
||||||
form.setSize(800,500);
|
form.setSize(800,500);
|
||||||
form.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
|
form.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
|
||||||
form.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
form.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||||
@ -79,10 +113,10 @@ public class FormMapWithSetAircrafts extends JFrame
|
|||||||
if(form.getSelectedAircraft() != null)
|
if(form.getSelectedAircraft() != null)
|
||||||
{
|
{
|
||||||
DrawingObjectAircraft aircraft = new DrawingObjectAircraft(form.SelectedAircraft);
|
DrawingObjectAircraft aircraft = new DrawingObjectAircraft(form.SelectedAircraft);
|
||||||
if (_mapAircraftsCollectionGeneric.addAircraft(_mapAircraftsCollectionGeneric,aircraft) != -1)
|
if (_mapsCollection.getMap((String) Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).addAircraft(_mapsCollection.getMap((String) Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")),aircraft) != -1)
|
||||||
{
|
{
|
||||||
JOptionPane.showMessageDialog(this, "Object was added", "Success", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(this, "Object was added", "Success", JOptionPane.INFORMATION_MESSAGE);
|
||||||
bufferedImage = _mapAircraftsCollectionGeneric.showSet();
|
bufferedImage = _mapsCollection.getMap((String) Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).showSet();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -94,7 +128,12 @@ public class FormMapWithSetAircrafts extends JFrame
|
|||||||
|
|
||||||
private void DeleteAircraft()
|
private void DeleteAircraft()
|
||||||
{
|
{
|
||||||
if(maskedTextBoxPosition.getText().isEmpty())
|
String pos = maskedTextBoxPosition.getText();
|
||||||
|
if(listBoxMaps.getSelectedIndex() == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(pos.isEmpty() || pos == null )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -102,12 +141,17 @@ public class FormMapWithSetAircrafts extends JFrame
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int position = Integer.parseInt(maskedTextBoxPosition.getText());
|
int position = Integer.parseInt(pos);
|
||||||
|
|
||||||
if(_mapAircraftsCollectionGeneric.removeAircraft(_mapAircraftsCollectionGeneric,position) != null)
|
if(_mapsCollection.getMap((String) Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).getAircraft(_mapsCollection.getMap((String) Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")),position) != null)
|
||||||
|
{
|
||||||
|
deletedAircrafts.add(_mapsCollection.getMap((String) Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).getAircraft(_mapsCollection.getMap((String) Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")),position));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_mapsCollection.getMap((String) Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).removeAircraft(_mapsCollection.getMap((String) Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")),position) != null)
|
||||||
{
|
{
|
||||||
JOptionPane.showMessageDialog(this,"Object is removed.");
|
JOptionPane.showMessageDialog(this,"Object is removed.");
|
||||||
bufferedImage = _mapAircraftsCollectionGeneric.showSet();
|
bufferedImage = _mapsCollection.getMap((String) Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).showSet();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -118,17 +162,17 @@ public class FormMapWithSetAircrafts extends JFrame
|
|||||||
|
|
||||||
private void ShowHangar()
|
private void ShowHangar()
|
||||||
{
|
{
|
||||||
if(_mapAircraftsCollectionGeneric == null)
|
if(listBoxMaps.getSelectedIndex() == -1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bufferedImage = _mapAircraftsCollectionGeneric.showSet();
|
bufferedImage = _mapsCollection.getMap((String) Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).showSet();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void moveObject(ActionEvent event)
|
private void moveObject(ActionEvent event)
|
||||||
{
|
{
|
||||||
if (_mapAircraftsCollectionGeneric == null)
|
if(listBoxMaps.getSelectedIndex() == -1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -142,19 +186,53 @@ public class FormMapWithSetAircrafts extends JFrame
|
|||||||
case "up" -> dir = Direction.Up;
|
case "up" -> dir = Direction.Up;
|
||||||
case "down" -> dir = Direction.Down;
|
case "down" -> dir = Direction.Down;
|
||||||
}
|
}
|
||||||
bufferedImage = _mapAircraftsCollectionGeneric.MoveObject(dir);
|
bufferedImage = _mapsCollection.getMap((String) Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).MoveObject(dir);
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addMap()
|
||||||
|
{
|
||||||
|
if (comboBoxMapSelection.getSelectedIndex() == -1 || newMapTextBox.getText() == null || newMapTextBox.getText().equals(""))
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(this, "Not all data is filled", "Error", JOptionPane.ERROR_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!_mapsDict.containsKey(comboBoxMapSelection.getSelectedItem()))
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(this, "There is no such map", "Error", JOptionPane.ERROR_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_mapsCollection.AddMap(newMapTextBox.getText(), _mapsDict.get(comboBoxMapSelection.getSelectedItem()));
|
||||||
|
RefreshMaps();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteMap()
|
||||||
|
{
|
||||||
|
if (listBoxMaps.getSelectedIndex() == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String str = String.format("Delete map %s?",listBoxMaps.getSelectedValue().toString());
|
||||||
|
if (JOptionPane.showConfirmDialog(this,str,"Deletion",JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
|
||||||
|
{
|
||||||
|
_mapsCollection.DeleteMap((String) Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse(""));
|
||||||
|
RefreshMaps();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public FormMapWithSetAircrafts()
|
public FormMapWithSetAircrafts()
|
||||||
{
|
{
|
||||||
|
this.setContentPane(Form);
|
||||||
|
this.setSize(800,600);
|
||||||
|
this.setVisible(true);
|
||||||
|
_mapsCollection = new MapsCollection(pictureBox.getWidth(),pictureBox.getHeight());
|
||||||
try {
|
try {
|
||||||
maskedTextBoxPosition.setFormatterFactory(new DefaultFormatterFactory(new MaskFormatter("##")));
|
maskedTextBoxPosition.setFormatterFactory(new DefaultFormatterFactory(new MaskFormatter("##")));
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deletedAircrafts = new LinkedList<IDrawingObject>();
|
||||||
ActionListener listener = this::moveObject;
|
ActionListener listener = this::moveObject;
|
||||||
moveDown.addActionListener(listener);
|
moveDown.addActionListener(listener);
|
||||||
moveUp.addActionListener(listener);
|
moveUp.addActionListener(listener);
|
||||||
@ -162,10 +240,26 @@ public class FormMapWithSetAircrafts extends JFrame
|
|||||||
moveLeft.addActionListener(listener);
|
moveLeft.addActionListener(listener);
|
||||||
|
|
||||||
ShowMapButton.addActionListener(e -> showMap());
|
ShowMapButton.addActionListener(e -> showMap());
|
||||||
comboBoxMapSelection.addActionListener(e -> indexChanged());
|
listBoxMaps.addListSelectionListener(e -> indexChanged());
|
||||||
AddAircraftButton.addActionListener(e -> addAircraft());
|
AddAircraftButton.addActionListener(e -> addAircraft());
|
||||||
DeleteAircraftButton.addActionListener(e -> DeleteAircraft());
|
DeleteAircraftButton.addActionListener(e -> DeleteAircraft());
|
||||||
ShowHangarButton.addActionListener(e -> ShowHangar());
|
ShowHangarButton.addActionListener(e -> ShowHangar());
|
||||||
|
AddMapButton.addActionListener(e -> addMap());
|
||||||
|
DeleteMapButton.addActionListener(e -> deleteMap());
|
||||||
|
showDeletedAircrafts.addActionListener(e -> {
|
||||||
|
if(deletedAircrafts.isEmpty())
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(this, "There are not any deleted aircrafts", "Error", JOptionPane.ERROR_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DrawingObjectAircraft deletedAircraft = (DrawingObjectAircraft)deletedAircrafts.remove();
|
||||||
|
form = new FormAirFighter(deletedAircraft.getAircraft());
|
||||||
|
form.setSize(800,500);
|
||||||
|
form.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
|
||||||
|
form.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||||
|
form.setVisible(true);
|
||||||
|
});
|
||||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paint(Graphics g) {
|
public void paint(Graphics g) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user