Настройка работы всплывающего окна.

This commit is contained in:
Programmist73 2022-11-07 10:19:28 +04:00
parent faae3cf525
commit 612001e1db
6 changed files with 181 additions and 105 deletions

View File

@ -4,6 +4,11 @@ public class DrawningObjectPlane implements IDrawningObject
{ {
private DrawingPlane _plane = null; private DrawingPlane _plane = null;
public DrawingPlane GetDrawingObjectPlane()
{
return _plane;
}
public DrawningObjectPlane(DrawingPlane plane){ _plane = plane; } public DrawningObjectPlane(DrawingPlane plane){ _plane = plane; }
@Override @Override

View File

@ -207,7 +207,7 @@
<text value="Добавить карту"/> <text value="Добавить карту"/>
</properties> </properties>
</component> </component>
<component id="9a389" class="javax.swing.JList" binding="ListBoxMaps"> <component id="9a389" class="javax.swing.JList" binding="ListBoxMaps" custom-create="true">
<constraints> <constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false"> <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="220" height="100"/> <minimum-size width="220" height="100"/>
@ -215,7 +215,9 @@
<maximum-size width="220" height="100"/> <maximum-size width="220" height="100"/>
</grid> </grid>
</constraints> </constraints>
<properties/> <properties>
<selectionMode value="2"/>
</properties>
</component> </component>
<component id="81eff" class="javax.swing.JButton" binding="ButtonDeleteMap"> <component id="81eff" class="javax.swing.JButton" binding="ButtonDeleteMap">
<constraints> <constraints>

View File

@ -31,9 +31,6 @@ public class FormMapWithSetPlanesGeneric {
private JPanel GroupBoxMap; private JPanel GroupBoxMap;
private JButton ButtonShowDelete; private JButton ButtonShowDelete;
//объект от класса карты с набором объектов
private MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap> _mapPlanesCollectionGeneric;
//объект от коллекции карт //объект от коллекции карт
private final MapsCollection _mapsCollection; private final MapsCollection _mapsCollection;
@ -49,11 +46,11 @@ public class FormMapWithSetPlanesGeneric {
{ {
/*super("Хранилище");*/ /*super("Хранилище");*/
CreateWindow(); CreateWindow();
_mapsCollection = new MapsCollection(PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight()); _mapsCollection = new MapsCollection(730, 650);
ComboBoxSelectorMap.removeAllItems(); ComboBoxSelectorMap.removeAllItems();
for (String element : _mapsHashMap.keySet())
{ for (String elem : _mapsHashMap.keySet()) {
ComboBoxSelectorMap.addItem(element); ComboBoxSelectorMap.addItem(elem);
} }
} }
@ -62,12 +59,12 @@ public class FormMapWithSetPlanesGeneric {
{ {
int index = ListBoxMaps.getSelectedIndex(); int index = ListBoxMaps.getSelectedIndex();
DefaultListModel<String> model = (DefaultListModel<String>) ListBoxMaps.getModel(); DefaultListModel<String> model = (DefaultListModel<String>)ListBoxMaps.getModel();
model.removeAllElements(); model.removeAllElements();
for (int i = 0; i < _mapsCollection.Keys.size(); i++) for (int i = 0; i < _mapsCollection.Keys().size(); i++)
{ {
model.addElement(_mapsCollection.Keys.get(i)); model.addElement(_mapsCollection.Keys().get(i));
} }
if (ListBoxMaps.getModel().getSize() > 0 && (index == -1 || index >= ListBoxMaps.getModel().getSize())) if (ListBoxMaps.getModel().getSize() > 0 && (index == -1 || index >= ListBoxMaps.getModel().getSize()))
@ -115,7 +112,22 @@ public class FormMapWithSetPlanesGeneric {
ButtonAddMap.addActionListener(new ActionListener() { ButtonAddMap.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if(ComboBoxSelectorMap.getSelectedIndex() == -1 || TextBoxNewMapName.getText().isEmpty())
{
JOptionPane.showMessageDialog(null, "Не все данные заполнены", "Ошибка", JOptionPane.ERROR_MESSAGE);
return;
}
if(!_mapsHashMap.containsKey(ComboBoxSelectorMap.getSelectedItem()))
{
JOptionPane.showMessageDialog(null, "Данная карта отсутсвует", "Ошибка", JOptionPane.ERROR_MESSAGE);
return;
}
_mapsCollection.AddMap(TextBoxNewMapName.getText(), _mapsHashMap.get(ComboBoxSelectorMap.getSelectedItem().toString()));
ReloadMaps();
} }
}); });
@ -123,7 +135,17 @@ public class FormMapWithSetPlanesGeneric {
ButtonDeleteMap.addActionListener(new ActionListener() { ButtonDeleteMap.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if(ListBoxMaps.getSelectedIndex() == -1)
{
return;
}
if(JOptionPane.showConfirmDialog(null, "Удалить карту" + ListBoxMaps.getSelectedValue().toString() + "?",
"Удаление", JOptionPane.YES_NO_OPTION) == 0)
{
_mapsCollection.DelMap(ListBoxMaps.getSelectedValue().toString());
ReloadMaps();
}
} }
}); });
@ -131,7 +153,12 @@ public class FormMapWithSetPlanesGeneric {
ListBoxMaps.addListSelectionListener(new ListSelectionListener() { ListBoxMaps.addListSelectionListener(new ListSelectionListener() {
@Override @Override
public void valueChanged(ListSelectionEvent e) { public void valueChanged(ListSelectionEvent e) {
if(ListBoxMaps.getSelectedIndex() == -1)
{
return;
}
UpdateWindow(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
} }
}); });
@ -139,7 +166,23 @@ public class FormMapWithSetPlanesGeneric {
ButtonShowDelete.addActionListener(new ActionListener() { ButtonShowDelete.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if(ListBoxMaps.getSelectedIndex() == -1)
{
return;
}
DrawningObjectPlane plane = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).GetPlaneInDelete();
if(plane == null)
{
JOptionPane.showMessageDialog(null, "Список пуст", "Ошибка", JOptionPane.ERROR_MESSAGE);
return;
}
FormPlane form = new FormPlane(plane);
form.setSize(500, 300);
form.setVisible(true);
} }
}); });
@ -147,7 +190,7 @@ public class FormMapWithSetPlanesGeneric {
ButtonAddPlane.addActionListener(new ActionListener() { ButtonAddPlane.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if(_mapPlanesCollectionGeneric == null) if(_mapsCollection == null)
{ {
return; return;
} }
@ -158,10 +201,10 @@ public class FormMapWithSetPlanesGeneric {
form.setModal(true); form.setModal(true);
DrawningObjectPlane plane = new DrawningObjectPlane(form.GetSelectedShip()); DrawningObjectPlane plane = new DrawningObjectPlane(form.GetSelectedShip());
if(_mapPlanesCollectionGeneric.Add(plane) != -1) if(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).Add(plane) != -1)
{ {
JOptionPane.showMessageDialog(null,"Объект добавлен"); JOptionPane.showMessageDialog(null,"Объект добавлен");
UpdateWindow(_mapPlanesCollectionGeneric.ShowSet()); UpdateWindow(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
} }
else else
{ {
@ -181,17 +224,18 @@ public class FormMapWithSetPlanesGeneric {
int result = JOptionPane.showConfirmDialog(null,"Удалить объект?","Удаление", int result = JOptionPane.showConfirmDialog(null,"Удалить объект?","Удаление",
JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE); JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
if(result==JOptionPane.NO_OPTION)
if(result == JOptionPane.NO_OPTION)
{ {
return; return;
} }
int pos = Integer.parseInt(MaskedTextBoxPosition.getText()); int pos = Integer.parseInt(MaskedTextBoxPosition.getText());
if(_mapPlanesCollectionGeneric.Delete(pos) != null) if(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).Delete(pos) != null)
{ {
JOptionPane.showMessageDialog(null,"Объект удалён"); JOptionPane.showMessageDialog(null,"Объект удалён");
UpdateWindow(_mapPlanesCollectionGeneric.ShowSet()); UpdateWindow(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
} }
else else
{ {
@ -204,12 +248,12 @@ public class FormMapWithSetPlanesGeneric {
ButtonShowStorage.addActionListener(new ActionListener() { ButtonShowStorage.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if(_mapPlanesCollectionGeneric == null) if(_mapsCollection == null)
{ {
return; return;
} }
UpdateWindow(_mapPlanesCollectionGeneric.ShowSet()); UpdateWindow(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
} }
}); });
@ -217,19 +261,19 @@ public class FormMapWithSetPlanesGeneric {
ButtonShowOnMap.addActionListener(new ActionListener() { ButtonShowOnMap.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (_mapPlanesCollectionGeneric == null) if (_mapsCollection == null)
{ {
return; return;
} }
UpdateWindow(_mapPlanesCollectionGeneric.ShowOnMap()); UpdateWindow(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowOnMap());
} }
}); });
ButtonUp.addActionListener(new ActionListener() { ButtonUp.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if(_mapPlanesCollectionGeneric == null) if(_mapsCollection== null)
{ {
return; return;
} }
@ -239,7 +283,7 @@ public class FormMapWithSetPlanesGeneric {
JLabel imageWithMapAndObject = new JLabel(); JLabel imageWithMapAndObject = new JLabel();
imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize()); imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize());
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1)); imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
imageWithMapAndObject.setIcon(new ImageIcon(_mapPlanesCollectionGeneric.MoveObject((Direction.Up)))); imageWithMapAndObject.setIcon(new ImageIcon(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).MoveObject((Direction.Up))));
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER); PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
PictureBoxPlane.revalidate(); PictureBoxPlane.revalidate();
@ -250,7 +294,7 @@ public class FormMapWithSetPlanesGeneric {
ButtonLeft.addActionListener(new ActionListener() { ButtonLeft.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if(_mapPlanesCollectionGeneric == null) if(_mapsCollection == null)
{ {
return; return;
} }
@ -260,7 +304,7 @@ public class FormMapWithSetPlanesGeneric {
JLabel imageWithMapAndObject = new JLabel(); JLabel imageWithMapAndObject = new JLabel();
imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize()); imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize());
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1)); imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
imageWithMapAndObject.setIcon(new ImageIcon(_mapPlanesCollectionGeneric.MoveObject((Direction.Left)))); imageWithMapAndObject.setIcon(new ImageIcon(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).MoveObject((Direction.Left))));
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER); PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
PictureBoxPlane.revalidate(); PictureBoxPlane.revalidate();
@ -271,7 +315,7 @@ public class FormMapWithSetPlanesGeneric {
ButtonDown.addActionListener(new ActionListener() { ButtonDown.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if(_mapPlanesCollectionGeneric == null) if(_mapsCollection == null)
{ {
return; return;
} }
@ -281,7 +325,7 @@ public class FormMapWithSetPlanesGeneric {
JLabel imageWithMapAndObject = new JLabel(); JLabel imageWithMapAndObject = new JLabel();
imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize()); imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize());
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1)); imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
imageWithMapAndObject.setIcon(new ImageIcon(_mapPlanesCollectionGeneric.MoveObject((Direction.Down)))); imageWithMapAndObject.setIcon(new ImageIcon(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).MoveObject((Direction.Down))));
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER); PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
PictureBoxPlane.revalidate(); PictureBoxPlane.revalidate();
@ -292,7 +336,7 @@ public class FormMapWithSetPlanesGeneric {
ButtonRight.addActionListener(new ActionListener() { ButtonRight.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if(_mapPlanesCollectionGeneric == null) if(_mapsCollection == null)
{ {
return; return;
} }
@ -302,7 +346,7 @@ public class FormMapWithSetPlanesGeneric {
JLabel imageWithMapAndObject = new JLabel(); JLabel imageWithMapAndObject = new JLabel();
imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize()); imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize());
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1)); imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
imageWithMapAndObject.setIcon(new ImageIcon(_mapPlanesCollectionGeneric.MoveObject((Direction.Right)))); imageWithMapAndObject.setIcon(new ImageIcon(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).MoveObject((Direction.Right))));
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER); PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
PictureBoxPlane.revalidate(); PictureBoxPlane.revalidate();
@ -310,40 +354,6 @@ public class FormMapWithSetPlanesGeneric {
} }
}); });
//выпадающий список с вариантами карт
ComboBoxSelectorMap.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
AbstractMap map = null;
ComboBoxSelectorMap = (JComboBox)e.getSource();
String item = (String)ComboBoxSelectorMap.getSelectedItem();
switch(item)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Буря в пустыне":
map = new DesertStormMap();
break;
case "Звёздные войны":
map = new StarWarsMap();
break;
}
if(map != null)
{
_mapPlanesCollectionGeneric = new MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap>(
PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight(), map);
}
else
{
_mapPlanesCollectionGeneric = null;
}
}
});
//
MaskedTextBoxPosition.addKeyListener(new KeyAdapter() { MaskedTextBoxPosition.addKeyListener(new KeyAdapter() {
@Override @Override
public void keyTyped(KeyEvent e) { public void keyTyped(KeyEvent e) {
@ -355,4 +365,9 @@ public class FormMapWithSetPlanesGeneric {
} }
}); });
} }
private void createUIComponents() {
DefaultListModel<String> defListMod = new DefaultListModel<String>();
ListBoxMaps = new JList(defListMod);
}
} }

View File

@ -21,8 +21,10 @@ public class FormPlane extends JDialog
private JLabel LabelWeight = new JLabel(); private JLabel LabelWeight = new JLabel();
private JLabel LabelColor = new JLabel(); private JLabel LabelColor = new JLabel();
protected DrawingPlane plane; protected DrawingPlane _plane;
protected DrawingPlane _selectedPlane; protected DrawingPlane _selectedPlane;
private int PictureBoxPlaneWidth;
private int PictureBoxPlaneHeight;
public DrawingPlane GetSelectedShip() public DrawingPlane GetSelectedShip()
{ {
@ -38,7 +40,7 @@ public class FormPlane extends JDialog
gr.setColor(new Color(238, 238, 238)); gr.setColor(new Color(238, 238, 238));
gr.fillRect(0, 0, PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight()); gr.fillRect(0, 0, PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
if (plane.GetPlane() != null) { if (_plane.GetPlane() != null) {
_plane.DrawTransport(gr); _plane.DrawTransport(gr);
JLabel imageOfLogo = new JLabel(); JLabel imageOfLogo = new JLabel();
imageOfLogo.setPreferredSize(PictureBoxPlane.getSize()); imageOfLogo.setPreferredSize(PictureBoxPlane.getSize());
@ -50,18 +52,46 @@ public class FormPlane extends JDialog
validate(); validate();
} }
//создание всплывающего окна //создание всплывающего окна (первый конструктор)
public FormPlane() public FormPlane()
{ {
super(new Frame("Airbus")); super(new Frame("Аэробус"));
CreateWindow(); CreateWindow();
setModal(true); setModal(true);
getContentPane().add(MainPanel); getContentPane().add(MainPanel);
} }
//второй конструктор
protected FormPlane(DrawningObjectPlane plane)
{
super(new Frame("Аэробус"));
CreateWindow();
setModal(true);
_plane = plane.GetDrawingObjectPlane();
SetData();
}
public DrawingPlane GetSelectedPlane()
{
return _selectedPlane;
}
public void SetData()
{
Random rnd = new Random();
_plane.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100),
PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
LabelSpeed.setText("Скорость: " + _plane.GetPlane().GetSpeed() + " ");
LabelWeight.setText("Вес: " + _plane.GetPlane().GetWeight() + " ");
LabelColor.setText("Цвет: r = " + _plane.GetPlane().GetColor().getRed() + " g = " + _plane.GetPlane().GetColor().getGreen() +
" b = " + _plane.GetPlane().GetColor().getBlue());
PictureBoxPlane.add(_plane, BorderLayout.CENTER);
}
public void CreateWindow() public void CreateWindow()
{ {
setModal(true); /*setModal(true);*/
//создание строки отображения скорости, веса и цвета объекта //создание строки отображения скорости, веса и цвета объекта
Box LableBox = Box.createHorizontalBox(); Box LableBox = Box.createHorizontalBox();
@ -71,6 +101,10 @@ public class FormPlane extends JDialog
LableBox.add(LabelColor); LableBox.add(LabelColor);
StatusStrip.add(LableBox); StatusStrip.add(LableBox);
PictureBoxPlane.setBackground(Color.WHITE);
setPreferredSize(new Dimension(1000, 700));
getContentPane().add(MainPanel);
try try
{ {
Image img = ImageIO.read(getClass().getResource("resourses/Up.png")); Image img = ImageIO.read(getClass().getResource("resourses/Up.png"));
@ -87,46 +121,56 @@ public class FormPlane extends JDialog
System.out.println(ex.getMessage()); System.out.println(ex.getMessage());
} }
_selectedPlane = plane; _selectedPlane = _plane;
ButtonCreate.addActionListener(new ActionListener() { ButtonCreate.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
try
{
PictureBoxPlane.remove(_plane);
}
catch (Exception c){ }
Random rnd = new Random(); Random rnd = new Random();
Color colorSimple = JColorChooser.showDialog(null, "Выберите цвет", null); Color colorSimple = JColorChooser.showDialog(null, "Выберите цвет", null);
plane = new DrawingPlane(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), _plane = new DrawingPlane(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
colorSimple); colorSimple);
plane.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100),
PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
LabelSpeed.setText("Скорость: " + plane.GetPlane().GetSpeed() + " "); SetData();
LabelWeight.setText("Вес: " + plane.GetPlane().GetWeight() + " ");
LabelColor.setText("Цвет: r = " + plane.GetPlane().GetColor().getRed() + " g = " + plane.GetPlane().GetColor().getGreen() +
" b = " + plane.GetPlane().GetColor().getBlue());
Draw(plane); Draw(_plane);
} }
}); });
ButtonCreateModif.addActionListener(new ActionListener() { ButtonCreateModif.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
try
{
PictureBoxPlane.remove(_plane);
}
catch (Exception c){ }
Random rnd = new Random(); Random rnd = new Random();
Color colorSimple = JColorChooser.showDialog(null, "Выберите цвет", null); Color colorSimple = JColorChooser.showDialog(null, "Выберите цвет", null);
Color colorModif = JColorChooser.showDialog(null, "Выберите цвет", null); Color colorModif = JColorChooser.showDialog(null, "Выберите цвет", null);
plane = new DrawingAirbus(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), _plane = new DrawingAirbus(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
colorSimple, colorModif, rnd.nextBoolean(), rnd.nextBoolean()); colorSimple, colorModif, rnd.nextBoolean(), rnd.nextBoolean());
plane.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100),
PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
LabelSpeed.setText("Скорость: " + plane.GetPlane().GetSpeed() + " "); SetData();
LabelWeight.setText("Вес: " + plane.GetPlane().GetWeight() + " ");
LabelColor.setText("Цвет: r = " + plane.GetPlane().GetColor().getRed() + " g = " + plane.GetPlane().GetColor().getGreen() +
" b = " + plane.GetPlane().GetColor().getBlue());
Draw(plane); Draw(_plane);
}
});
ButtonSelectPlane.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_selectedPlane = _plane;
dispose();
} }
}); });
@ -135,48 +179,56 @@ public class FormPlane extends JDialog
public void componentResized(ComponentEvent e) { public void componentResized(ComponentEvent e) {
super.componentResized(e); super.componentResized(e);
if(plane != null) if(_plane == null)
{ {
plane.ChangeBorders(PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight()); return;
PictureBoxPlane.revalidate();
Draw(plane);
} }
_plane.ChangeBorders(PictureBoxPlaneWidth, PictureBoxPlaneHeight);
try
{
PictureBoxPlane.remove(_plane);
}
catch (Exception c){ }
PictureBoxPlane.add(_plane, BorderLayout.CENTER);
} }
}); });
ButtonUp.addActionListener(new ActionListener() { ButtonUp.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
plane.MoveTransport(Direction.Up); _plane.MoveTransport(Direction.Up);
PictureBoxPlane.revalidate(); PictureBoxPlane.revalidate();
Draw(plane); Draw(_plane);
} }
}); });
ButtonLeft.addActionListener(new ActionListener() { ButtonLeft.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
plane.MoveTransport(Direction.Left); _plane.MoveTransport(Direction.Left);
PictureBoxPlane.revalidate(); PictureBoxPlane.revalidate();
Draw(plane); Draw(_plane);
} }
}); });
ButtonDown.addActionListener(new ActionListener() { ButtonDown.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
plane.MoveTransport(Direction.Down); _plane.MoveTransport(Direction.Down);
PictureBoxPlane.revalidate(); PictureBoxPlane.revalidate();
Draw(plane); Draw(_plane);
} }
}); });
ButtonRight.addActionListener(new ActionListener() { ButtonRight.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
plane.MoveTransport(Direction.Right); _plane.MoveTransport(Direction.Right);
PictureBoxPlane.revalidate(); PictureBoxPlane.revalidate();
Draw(plane); Draw(_plane);
} }
}); });
@ -184,7 +236,7 @@ public class FormPlane extends JDialog
ButtonSelectPlane.addActionListener(new ActionListener() { ButtonSelectPlane.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
_selectedPlane = plane; _selectedPlane = _plane;
dispose(); dispose();
} }
}); });

View File

@ -44,9 +44,9 @@ public class MapWithSetPlanesGeneric <T extends IDrawningObject, U extends Abstr
public T Delete(int position) public T Delete(int position)
{ {
_deletePlane.add(_setPlanes.Get(position)); T temp = _setPlanes.Remove(position);
_deletePlane.add(temp);
return _setPlanes.Remove(position); return temp;
} }
//вывод всего набора объектов //вывод всего набора объектов
@ -217,7 +217,7 @@ public class MapWithSetPlanesGeneric <T extends IDrawningObject, U extends Abstr
return _setPlanes.Get(index); return _setPlanes.Get(index);
} }
public T GetTractorInDelete() public T GetPlaneInDelete()
{ {
if(_deletePlane.isEmpty()) if(_deletePlane.isEmpty())
{ {

View File

@ -7,7 +7,10 @@ public class MapsCollection
public HashMap<String, MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap>> _mapStorage; public HashMap<String, MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap>> _mapStorage;
//возвращение списка названий карт //возвращение списка названий карт
public List<String> Keys; public ArrayList<String> Keys()
{
return new ArrayList<>(_mapStorage.keySet());
}
//ширина окна отрисовки //ширина окна отрисовки
private final int _pictureWidth; private final int _pictureWidth;
@ -18,7 +21,6 @@ public class MapsCollection
//конструктор //конструктор
public MapsCollection(int pictureWidth, int pictureHeight) public MapsCollection(int pictureWidth, int pictureHeight)
{ {
Keys = new ArrayList<String>(_mapStorage.keySet());
_mapStorage = new HashMap<>(); _mapStorage = new HashMap<>();
_pictureWidth = pictureWidth; _pictureWidth = pictureWidth;
_pictureHeight = pictureHeight; _pictureHeight = pictureHeight;