LabWork04 is done.

This commit is contained in:
Yuee Shiness 2022-12-05 18:41:18 +04:00
parent 65ee7b9c39
commit 5a56586e50
10 changed files with 283 additions and 73 deletions

View File

@ -7,6 +7,6 @@ import javax.swing.*;
public class App
{
public static void main(String[] args) {
new FormAirport();
FormMapWithSetAircrafts form = new FormMapWithSetAircrafts();
}
}

View File

@ -8,12 +8,11 @@ public class DrawingAircraft
public EntityAircraft Plane;
private IDrawingEngines _engines;
protected int _startPosX;
protected int _startPosY;
private Integer _pictureWidth = null;
private Integer _pictureHeight = null;
public Integer _pictureWidth = null;
public Integer _pictureHeight = null;
protected final int _aircraftWidth = 100;
protected final int _aircraftHeight = 120;

View File

@ -3,12 +3,17 @@ package Classes;
import java.awt.*;
public class DrawingObjectAircraft implements IDrawingObject {
private DrawingAircraft _aircraft = null;
private DrawingAircraft _aircraft;
public DrawingObjectAircraft(DrawingAircraft aircraft)
{
_aircraft = aircraft;
}
public DrawingAircraft getAircraft()
{
return _aircraft;
}
@Override
public float getStep()
{

View File

@ -40,6 +40,11 @@ public class MapWithSetAircraftsGeneric <T extends IDrawingObject,U extends Abst
return map._setAircrafts.Remove(position);
}
public T getAircraft(MapWithSetAircraftsGeneric<T, U> map, int position)
{
return map._setAircrafts.get(position);
}
public Image showSet()
{
BufferedImage img = new BufferedImage(_pictureWidth,_pictureHeight,BufferedImage.TYPE_INT_ARGB);

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

View File

@ -57,7 +57,7 @@ public class SetAircraftsGeneric<T>
public T get(int position)
{
if (position < _maxCount && position >= 0)
if (position < _maxCount && position >= 0 && position < getCount())
{
return _places.get(position);
}

View File

@ -7,8 +7,6 @@ import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.util.Random;
public class FormAirFighter extends JDialog
@ -47,7 +45,7 @@ public class FormAirFighter extends JDialog
_aircraft.MoveTransport(Direction.Down);
}
}
Draw();
repaint();
}
private void SetData()
@ -57,6 +55,7 @@ public class FormAirFighter extends JDialog
_aircraft.SetPosition(
rnd.nextInt(0, 100),
rnd.nextInt(0, 100),
Form.getWidth(),
Form.getHeight()
);
@ -64,6 +63,20 @@ public class FormAirFighter extends JDialog
weightLabel.setText("Weight: " + _aircraft.Plane.getWeight());
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() {
Random rnd = new Random();
@ -74,7 +87,7 @@ public class FormAirFighter extends JDialog
SetData();
Draw();
repaint();
}
private void CreateModifiedEntity()
@ -87,7 +100,7 @@ public class FormAirFighter extends JDialog
_aircraft = new DrawingMilitaryAircraft(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
color, dopColor, rnd.nextBoolean(), rnd.nextBoolean());
SetData();
Draw();
repaint();
}
private void selectAircraft()
@ -101,21 +114,13 @@ public class FormAirFighter extends JDialog
private void resizeWindow() {
_aircraft.ChangeBorders(pictureBox.getWidth(), pictureBox.getHeight());
Draw();
}
private void Draw() {
Graphics2D graphics = (Graphics2D) pictureBox.getGraphics();
graphics.clearRect(0, 0, pictureBox.getWidth(), pictureBox.getHeight());
pictureBox.paintComponents(graphics);
_aircraft.DrawTransport(graphics);
repaint();
}
public FormAirFighter() {
setContentPane(Form);
// action move //
ActionListener listener = this::moveButtonClick;
moveRight.addActionListener(listener);
@ -123,16 +128,26 @@ public class FormAirFighter extends JDialog
moveLeft.addActionListener(listener);
moveUp.addActionListener(listener);
btnCreate.addActionListener(e -> CreateEntity());
btnModification.addActionListener(e -> CreateModifiedEntity());
SelectButton.addActionListener(e -> selectAircraft());
/*Form.addComponentListener(new ComponentAdapter() {
}
public FormAirFighter(DrawingAircraft aircraft)
{
this();
_aircraft = aircraft;
SetData(_aircraft._pictureWidth, aircraft._pictureHeight);
repaint();
}
@Override
public void componentResized(ComponentEvent e) {
super.componentResized(e);
resizeWindow();
public void paint(Graphics g) {
super.paint(g);
Graphics2D graphics = (Graphics2D) pictureBox.getGraphics();
if(_aircraft != null)
{
_aircraft.DrawTransport(graphics);
}
});*/
}
}

View File

@ -44,7 +44,6 @@ public class FormAirport extends JFrame{
public FormAirport()
{
setContentPane(Form);
Random rnd = new Random();
parts = new EntityWithEngines<>();
int mod = 0;
@ -89,7 +88,6 @@ public class FormAirport extends JFrame{
});
setSize(new Dimension(600, 600));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}

View File

@ -2,7 +2,7 @@
<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">
<constraints>
<xy x="20" y="20" width="808" height="552"/>
<xy x="20" y="20" width="808" height="664"/>
</constraints>
<properties/>
<border type="none"/>
@ -20,7 +20,7 @@
</hspacer>
</children>
</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"/>
<constraints border-constraint="East"/>
<properties/>
@ -28,7 +28,7 @@
<children>
<component id="e569a" class="javax.swing.JComboBox" binding="comboBoxMapSelection">
<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>
<properties>
<model>
@ -39,7 +39,7 @@
</component>
<component id="d798e" class="javax.swing.JButton" binding="AddAircraftButton">
<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>
<properties>
<text value="Add aircraft"/>
@ -47,7 +47,7 @@
</component>
<component id="f4aba" class="javax.swing.JFormattedTextField" binding="maskedTextBoxPosition">
<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"/>
</grid>
</constraints>
@ -55,7 +55,7 @@
</component>
<component id="192c4" class="javax.swing.JButton" binding="DeleteAircraftButton">
<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>
<properties>
<text value="Delete aircraft"/>
@ -63,7 +63,7 @@
</component>
<component id="f84e6" class="javax.swing.JButton" binding="ShowHangarButton">
<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>
<properties>
<text value="Show hangar"/>
@ -71,7 +71,7 @@
</component>
<component id="1a170" class="javax.swing.JButton" binding="ShowMapButton">
<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>
<properties>
<text value="Show map"/>
@ -79,7 +79,7 @@
</component>
<component id="32298" class="javax.swing.JButton" binding="moveUp">
<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"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
@ -93,7 +93,7 @@
</component>
<component id="6a898" class="javax.swing.JButton" binding="moveLeft">
<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"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
@ -107,7 +107,7 @@
</component>
<component id="c514d" class="javax.swing.JButton" binding="moveDown">
<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"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
@ -121,7 +121,7 @@
</component>
<component id="a2ec2" class="javax.swing.JButton" binding="moveRight">
<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"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
@ -135,7 +135,54 @@
</component>
<vspacer id="5a9ee">
<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>
</vspacer>
</children>

View File

@ -2,10 +2,11 @@ package Form;
import Classes.Direction;
import Classes.DrawingObjectAircraft;
import Classes.MapWithSetAircraftsGeneric;
import Classes.IDrawingObject;
import Classes.Maps.AbstractMap;
import Classes.Maps.NightSkyMap;
import Classes.Maps.SimpleMap;
import Classes.MapsCollection;
import javax.swing.*;
import javax.swing.text.DefaultFormatterFactory;
@ -13,9 +14,11 @@ import javax.swing.text.MaskFormatter;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
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
{
@ -32,45 +35,76 @@ public class FormMapWithSetAircrafts extends JFrame
private JButton moveLeft;
private JButton moveRight;
private JFormattedTextField maskedTextBoxPosition;
private JTextField newMapTextBox;
private JButton AddMapButton;
private JList listBoxMaps;
DefaultListModel listModel;
private JButton DeleteMapButton;
private JButton showDeletedAircrafts;
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()
{
if(_mapAircraftsCollectionGeneric == null)
if(listBoxMaps.getSelectedIndex() == -1)
{
return;
}
bufferedImage = _mapAircraftsCollectionGeneric.ShowOnMap();
bufferedImage = _mapsCollection.getMap((String) Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).ShowOnMap();
repaint();
}
private void indexChanged()
{
AbstractMap map = null;
switch (comboBoxMapSelection.getSelectedItem().toString()) {
case "1. Simple map" -> map = new SimpleMap();
case "2. NightSky map" -> map = new NightSkyMap();
}
if(map != null)
if(listBoxMaps.getSelectedValue() != null)
{
_mapAircraftsCollectionGeneric = new MapWithSetAircraftsGeneric<>(pictureBox.getWidth(),pictureBox.getHeight(),map);
}
else
{
_mapAircraftsCollectionGeneric = null;
bufferedImage = _mapsCollection.getMap((String) Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).showSet();
repaint();
}
}
private void addAircraft()
{
if(_mapAircraftsCollectionGeneric == null)
if(listBoxMaps.getSelectedIndex() == -1)
{
return;
}
FormAirFighter form = new FormAirFighter();
form = new FormAirFighter();
form.setSize(800,500);
form.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
form.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
@ -79,10 +113,10 @@ public class FormMapWithSetAircrafts extends JFrame
if(form.getSelectedAircraft() != null)
{
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);
bufferedImage = _mapAircraftsCollectionGeneric.showSet();
bufferedImage = _mapsCollection.getMap((String) Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).showSet();
repaint();
}
else
@ -94,7 +128,12 @@ public class FormMapWithSetAircrafts extends JFrame
private void DeleteAircraft()
{
if(maskedTextBoxPosition.getText().isEmpty())
String pos = maskedTextBoxPosition.getText();
if(listBoxMaps.getSelectedIndex() == -1)
{
return;
}
if(pos.isEmpty() || pos == null )
{
return;
}
@ -102,12 +141,17 @@ public class FormMapWithSetAircrafts extends JFrame
{
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.");
bufferedImage = _mapAircraftsCollectionGeneric.showSet();
bufferedImage = _mapsCollection.getMap((String) Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).showSet();
repaint();
}
else
@ -118,17 +162,17 @@ public class FormMapWithSetAircrafts extends JFrame
private void ShowHangar()
{
if(_mapAircraftsCollectionGeneric == null)
if(listBoxMaps.getSelectedIndex() == -1)
{
return;
}
bufferedImage = _mapAircraftsCollectionGeneric.showSet();
bufferedImage = _mapsCollection.getMap((String) Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).showSet();
repaint();
}
private void moveObject(ActionEvent event)
{
if (_mapAircraftsCollectionGeneric == null)
if(listBoxMaps.getSelectedIndex() == -1)
{
return;
}
@ -142,19 +186,53 @@ public class FormMapWithSetAircrafts extends JFrame
case "up" -> dir = Direction.Up;
case "down" -> dir = Direction.Down;
}
bufferedImage = _mapAircraftsCollectionGeneric.MoveObject(dir);
bufferedImage = _mapsCollection.getMap((String) Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).MoveObject(dir);
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()
{
this.setContentPane(Form);
this.setSize(800,600);
this.setVisible(true);
_mapsCollection = new MapsCollection(pictureBox.getWidth(),pictureBox.getHeight());
try {
maskedTextBoxPosition.setFormatterFactory(new DefaultFormatterFactory(new MaskFormatter("##")));
} catch (ParseException e) {
e.printStackTrace();
}
deletedAircrafts = new LinkedList<IDrawingObject>();
ActionListener listener = this::moveObject;
moveDown.addActionListener(listener);
moveUp.addActionListener(listener);
@ -162,10 +240,26 @@ public class FormMapWithSetAircrafts extends JFrame
moveLeft.addActionListener(listener);
ShowMapButton.addActionListener(e -> showMap());
comboBoxMapSelection.addActionListener(e -> indexChanged());
listBoxMaps.addListSelectionListener(e -> indexChanged());
AddAircraftButton.addActionListener(e -> addAircraft());
DeleteAircraftButton.addActionListener(e -> DeleteAircraft());
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) {