Eliseev E.E. LabWork04 #4

Closed
ElEgEv wants to merge 14 commits from LabWork04 into LabWork03
3 changed files with 113 additions and 18 deletions
Showing only changes of commit faae3cf525 - Show all commits

View File

@ -20,7 +20,7 @@
<border type="none"/>
<children/>
</grid>
<grid id="4871f" binding="ButtonGroupPanel" layout-manager="GridLayoutManager" row-count="16" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="4871f" binding="GroupBoxTools" layout-manager="GridLayoutManager" row-count="17" 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="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
@ -34,7 +34,7 @@
<children>
<component id="d0967" class="javax.swing.JButton" binding="ButtonLeft">
<constraints>
<grid row="15" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false">
<grid row="16" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="45" height="45"/>
<preferred-size width="45" height="45"/>
<maximum-size width="45" height="45"/>
@ -46,7 +46,7 @@
</component>
<component id="d9af3" class="javax.swing.JButton" binding="ButtonDown">
<constraints>
<grid row="15" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<grid row="16" 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="45" height="45"/>
<preferred-size width="45" height="45"/>
<maximum-size width="45" height="45"/>
@ -58,7 +58,7 @@
</component>
<component id="9e43" class="javax.swing.JButton" binding="ButtonRight">
<constraints>
<grid row="15" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
<grid row="16" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="45" height="45"/>
<preferred-size width="45" height="45"/>
<maximum-size width="45" height="45"/>
@ -70,7 +70,7 @@
</component>
<component id="4d1dd" class="javax.swing.JButton" binding="ButtonUp">
<constraints>
<grid row="14" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<grid row="15" 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="45" height="45"/>
<preferred-size width="45" height="45"/>
<maximum-size width="45" height="45"/>
@ -82,7 +82,7 @@
</component>
<component id="67190" class="javax.swing.JButton" binding="ButtonShowOnMap">
<constraints>
<grid row="12" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<grid row="13" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="220" height="30"/>
<preferred-size width="220" height="30"/>
<maximum-size width="220" height="30"/>
@ -94,7 +94,7 @@
</component>
<component id="28576" class="javax.swing.JButton" binding="ButtonShowStorage">
<constraints>
<grid row="10" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" 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="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="220" height="30"/>
<preferred-size width="220" height="30"/>
<maximum-size width="220" height="30"/>
@ -143,17 +143,17 @@
</component>
<vspacer id="f972a">
<constraints>
<grid row="9" 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="10" 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="65c78">
<constraints>
<grid row="11" 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="12" 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="7d70b">
<constraints>
<grid row="13" 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="14" 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="d4b8a">
@ -161,7 +161,7 @@
<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"/>
</constraints>
</vspacer>
<grid id="fe895" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="fe895" binding="GroupBoxMap" layout-manager="GridLayoutManager" row-count="5" 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="0" row-span="5" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@ -207,7 +207,7 @@
<text value="Добавить карту"/>
</properties>
</component>
<component id="9a389" class="javax.swing.JList" binding="ListMaps">
<component id="9a389" class="javax.swing.JList" binding="ListBoxMaps">
<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">
<minimum-size width="220" height="100"/>
@ -231,6 +231,18 @@
</component>
</children>
</grid>
<component id="860bc" class="javax.swing.JButton" binding="ButtonShowDelete">
<constraints>
<grid row="9" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="220" height="30"/>
<preferred-size width="220" height="30"/>
<maximum-size width="220" height="30"/>
</grid>
</constraints>
<properties>
<text value="Посмотреть удалённый самолёт"/>
</properties>
</component>
</children>
</grid>
</children>

View File

@ -1,16 +1,19 @@
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.util.HashMap;
public class FormMapWithSetPlanesGeneric {
public JPanel MainPanel;
private JPanel PictureBoxPlane;
private JPanel ButtonGroupPanel;
private JPanel GroupBoxTools;
private JComboBox ComboBoxSelectorMap;
private JButton ButtonLeft;
private JButton ButtonDown;
@ -23,12 +26,60 @@ public class FormMapWithSetPlanesGeneric {
private JButton ButtonRemovePlane;
private JTextField TextBoxNewMapName;
private JButton ButtonAddMap;
private JList ListMaps;
private JList ListBoxMaps;
private JButton ButtonDeleteMap;
private JPanel GroupBoxMap;
private JButton ButtonShowDelete;
//объект от класса карты с набором объектов
private MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap> _mapPlanesCollectionGeneric;
//объект от коллекции карт
private final MapsCollection _mapsCollection;
//Для выпадающего списка
HashMap<String, AbstractMap> _mapsHashMap = new HashMap<>()
{{
put("Простая карта", new SimpleMap());
put("Буря в пустыне", new DesertStormMap());
put("Звёздные войны", new StarWarsMap());
}};
public FormMapWithSetPlanesGeneric()
{
/*super("Хранилище");*/
CreateWindow();
_mapsCollection = new MapsCollection(PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
ComboBoxSelectorMap.removeAllItems();
for (String element : _mapsHashMap.keySet())
{
ComboBoxSelectorMap.addItem(element);
}
}
//заполнение ListBoxMaps
private void ReloadMaps()
{
int index = ListBoxMaps.getSelectedIndex();
DefaultListModel<String> model = (DefaultListModel<String>) ListBoxMaps.getModel();
model.removeAllElements();
for (int i = 0; i < _mapsCollection.Keys.size(); i++)
{
model.addElement(_mapsCollection.Keys.get(i));
}
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);
}
}
//обновление отрисовки
public void UpdateWindow(BufferedImage bmp)
{
@ -41,7 +92,7 @@ public class FormMapWithSetPlanesGeneric {
PictureBoxPlane.revalidate();
}
public FormMapWithSetPlanesGeneric()
public void CreateWindow()
{
//загрузка изображений для кнопок
try
@ -60,6 +111,38 @@ public class FormMapWithSetPlanesGeneric {
System.out.println(ex.getMessage());
}
//добавить карту
ButtonAddMap.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
});
//удалить карту
ButtonDeleteMap.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
});
//список карт
ListBoxMaps.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
}
});
//Просмотр удалённых самолётов
ButtonShowDelete.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
});
//добавление самолёта
ButtonAddPlane.addActionListener(new ActionListener() {
@Override
@ -260,13 +343,13 @@ public class FormMapWithSetPlanesGeneric {
}
});
//
MaskedTextBoxPosition.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
char c = e.getKeyChar();
if ( ((c < '0') || (c > '9')) || MaskedTextBoxPosition.getText().length() >= 2) {
if ((c < '0') || (c > '9')) {
e.consume();
}
}

View File

@ -19,7 +19,7 @@ public class MapWithSetPlanesGeneric <T extends IDrawningObject, U extends Abstr
//набор объектов
private final SetPlanesGeneric<T> _setPlanes;
//набор удалённых объектов
//набор удалённых объектов (двусвязный список)
public final LinkedList<T> _deletePlane;
//карта