Eliseev E.E. LabWork06 #6
9
Project/.idea/uiDesigner.xml
generated
9
Project/.idea/uiDesigner.xml
generated
@ -119,6 +119,15 @@
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JMenuBar" icon="" removable="true" auto-create-binding="false" can-attach-label="false" is-container="true">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="0" />
|
||||
</item>
|
||||
<item class="javax.swing.JMenu" icon="" removable="true" auto-create-binding="false" can-attach-label="false" is-container="true">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="0" />
|
||||
</item>
|
||||
<item class="javax.swing.JMenuItem" icon="" removable="true" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="0" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
@ -51,4 +51,9 @@ public class DrawingAirplaneWindow extends JComponent implements IAdditionalDraw
|
||||
g2d.drawOval((int)_startPosX + 27, (int)_startPosY + 11, 6, 4);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int GetAddEnum() {
|
||||
return _airplaneWindowEnum.GetAddEnum();
|
||||
}
|
||||
}
|
||||
|
@ -54,6 +54,11 @@ public class DrawingPlane extends JPanel
|
||||
_airplaneWindow.SetAddEnum(countWindow);
|
||||
}
|
||||
|
||||
//кол-во иллюминаторов
|
||||
public int GetWindows(){
|
||||
return _airplaneWindow.GetAddEnum();
|
||||
}
|
||||
|
||||
//конструктор
|
||||
public DrawingPlane(int speed, float weight, Color corpusColor, int countWindow, int planeWidth, int planeHeight)
|
||||
{
|
||||
|
@ -51,4 +51,9 @@ public class DrawingRectAirplaneWindow extends JComponent implements IAdditional
|
||||
g2d.drawRect((int)_startPosX + 27, (int)_startPosY + 11, 6, 4);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int GetAddEnum() {
|
||||
return _airplaneWindowEnum.GetAddEnum();
|
||||
}
|
||||
}
|
||||
|
@ -60,4 +60,9 @@ public class DrawingTriangleAirplaneWindow extends JComponent implements IAdditi
|
||||
g2d.drawPolygon(x_point, y_point, 3);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int GetAddEnum() {
|
||||
return _airplaneWindowEnum.GetAddEnum();
|
||||
}
|
||||
}
|
||||
|
@ -50,4 +50,18 @@ public class DrawningObjectPlane implements IDrawningObject
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String GetInfo()
|
||||
{
|
||||
if(_plane != null)
|
||||
{
|
||||
return ExtentionPlane.GetDataForSave(_plane);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IDrawningObject Create(String data)
|
||||
{
|
||||
return new DrawningObjectPlane(ExtentionPlane.CreateDrawingPlane(data));
|
||||
}
|
||||
}
|
||||
|
48
Project/src/ExtentionPlane.java
Normal file
48
Project/src/ExtentionPlane.java
Normal file
@ -0,0 +1,48 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class ExtentionPlane
|
||||
{
|
||||
//разделитель для записи информации по объекту в файл
|
||||
private static final char _separatorForObject = ':';
|
||||
|
||||
//создание объекта из строки
|
||||
public static DrawingPlane CreateDrawingPlane(String info)
|
||||
{
|
||||
String[] strs = info.split(String.valueOf(_separatorForObject));
|
||||
|
||||
//если простой самолёт
|
||||
if(strs.length == 4)
|
||||
{
|
||||
Color color = new Color(Integer.parseInt(strs[2]));
|
||||
return new DrawingPlane(Integer.parseInt(strs[0]), Float.valueOf(strs[1]), color, Integer.parseInt(strs[3]));
|
||||
}
|
||||
|
||||
//если аэробус
|
||||
if(strs.length == 7)
|
||||
{
|
||||
Color f_color = new Color(Integer.parseInt(strs[2]));
|
||||
Color s_color = new Color(Integer.parseInt(strs[4]));
|
||||
|
||||
return new DrawingAirbus(Integer.parseInt(strs[0]), Integer.parseInt(strs[1]), f_color, Integer.parseInt(strs[3]),
|
||||
s_color, Boolean.parseBoolean(strs[5]), Boolean.parseBoolean(strs[6]));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
//сохранение объекта в строку
|
||||
public static String GetDataForSave(DrawingPlane drawingPlane)
|
||||
{
|
||||
var plane = drawingPlane.Plane;
|
||||
var str = String.format("%d%c%d%c%d%c%d", plane.GetSpeed(), _separatorForObject, (int)plane.GetWeight(), _separatorForObject,
|
||||
plane.GetColor().getRGB(), _separatorForObject, drawingPlane.GetWindows());
|
||||
|
||||
//если объект не расширеный
|
||||
if(!(plane instanceof EntityAirbus airbus))
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
return str + String.format("%c%s%c%b%c%b", _separatorForObject, airbus.AddColor().getRGB(), _separatorForObject, airbus.AddEngine(), _separatorForObject, airbus.AddCompartment());
|
||||
}
|
||||
}
|
@ -1,19 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMapWithSetPlanesGeneric">
|
||||
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="994" height="654"/>
|
||||
<xy x="20" y="20" width="994" height="683"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="92d87" binding="PictureBoxPlane" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="730" height="650"/>
|
||||
<preferred-size width="730" height="650"/>
|
||||
<maximum-size width="730" height="650"/>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="730" height="680"/>
|
||||
<preferred-size width="730" height="680"/>
|
||||
<maximum-size width="730" height="680"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
@ -23,10 +23,10 @@
|
||||
<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">
|
||||
<minimum-size width="250" height="650"/>
|
||||
<preferred-size width="250" height="650"/>
|
||||
<maximum-size width="250" height="650"/>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="230" height="680"/>
|
||||
<preferred-size width="230" height="680"/>
|
||||
<maximum-size width="230" height="680"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
@ -247,6 +247,56 @@
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="bb85f" class="javax.swing.JMenuBar" binding="MenuBarSaveLoad" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="874ff" class="javax.swing.JMenu" binding="MenuChoiceOperation" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Файл"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="11ed2" class="javax.swing.JMenuItem" binding="MenuItemLoadData">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<text value="Загрузить"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="919f4" class="javax.swing.JMenuItem" binding="MenuItemSaveData">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<text value="Сохранить"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="885e8" class="javax.swing.JMenuItem" binding="MenuItemLoadOneMapData">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<text value="Загрузить карту"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ddbf9" class="javax.swing.JMenuItem" binding="MenuItemSaveOneMapData">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<text value="Сохранить карту"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<hspacer id="2b204">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
@ -30,6 +30,12 @@ public class FormMapWithSetPlanesGeneric extends JFrame{
|
||||
private JButton ButtonDeleteMap;
|
||||
private JPanel GroupBoxMap;
|
||||
private JButton ButtonShowDelete;
|
||||
private JMenuBar MenuBarSaveLoad;
|
||||
private JMenu MenuChoiceOperation;
|
||||
private JMenuItem MenuItemLoadData;
|
||||
private JMenuItem MenuItemSaveData;
|
||||
private JMenuItem MenuItemLoadOneMapData;
|
||||
private JMenuItem MenuItemSaveOneMapData;
|
||||
|
||||
//объект от коллекции карт
|
||||
private final MapsCollection _mapsCollection;
|
||||
@ -46,7 +52,7 @@ public class FormMapWithSetPlanesGeneric extends JFrame{
|
||||
{
|
||||
super("Хранилище");
|
||||
CreateWindow();
|
||||
_mapsCollection = new MapsCollection(730, 650);
|
||||
_mapsCollection = new MapsCollection(730, 700);
|
||||
ComboBoxSelectorMap.removeAllItems();
|
||||
|
||||
for (String elem : _mapsHashMap.keySet())
|
||||
@ -172,7 +178,7 @@ public class FormMapWithSetPlanesGeneric extends JFrame{
|
||||
return;
|
||||
}
|
||||
|
||||
DrawningObjectPlane plane = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).GetPlaneInDelete();
|
||||
DrawningObjectPlane plane = (DrawningObjectPlane)_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).GetPlaneInDelete();
|
||||
|
||||
if(plane == null)
|
||||
{
|
||||
@ -365,11 +371,106 @@ public class FormMapWithSetPlanesGeneric extends JFrame{
|
||||
public void keyTyped(KeyEvent e) {
|
||||
char c = e.getKeyChar();
|
||||
|
||||
if ((c < '0') || (c > '9')) {
|
||||
if ((c < '0') || (c > '9'))
|
||||
{
|
||||
e.consume();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//обработка нажатия загрузки всех карт
|
||||
MenuItemLoadData.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser jfc = new JFileChooser();
|
||||
int result = jfc.showOpenDialog(null);
|
||||
|
||||
if (result == JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
if (_mapsCollection.LoadData(jfc.getSelectedFile().getPath()))
|
||||
{
|
||||
ReloadMaps();
|
||||
JOptionPane.showMessageDialog(null,"Загрузка данных прошла успешно",
|
||||
"Результат", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Ошибка загрузки данных",
|
||||
"Результат", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//обработка нажатия сохранения всех карт
|
||||
MenuItemSaveData.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser jfc = new JFileChooser();
|
||||
int result = jfc.showSaveDialog(null);
|
||||
|
||||
if (result == JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
if (_mapsCollection.SaveData(jfc.getSelectedFile().getPath()))
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,"Сохранение прошло успешно",
|
||||
"Результат", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не сохранилось",
|
||||
"Результат", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//загрузка одной карты
|
||||
MenuItemLoadOneMapData.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser jfc = new JFileChooser();
|
||||
int result = jfc.showOpenDialog(null);
|
||||
|
||||
if (result == JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
if (_mapsCollection.LoadOneData(jfc.getSelectedFile().getPath()))
|
||||
{
|
||||
ReloadMaps();
|
||||
JOptionPane.showMessageDialog(null,"Загрузка данных прошла успешно",
|
||||
"Результат", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Ошибка загрузки данных",
|
||||
"Результат", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//сохранение одной карты
|
||||
MenuItemSaveOneMapData.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser jfc = new JFileChooser();
|
||||
int result = jfc.showSaveDialog(null);
|
||||
|
||||
if (result == JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
if (_mapsCollection.SaveOneData(jfc.getSelectedFile().getPath(), ListBoxMaps.getSelectedValue().toString()))
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,"Сохранение прошло успешно",
|
||||
"Результат", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не сохранилось",
|
||||
"Результат", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void createUIComponents()
|
||||
|
@ -298,7 +298,7 @@
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="4ef93" binding="PanelObject" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="4ef93" binding="PanelObject" layout-manager="GridLayoutManager" row-count="2" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
@ -335,16 +335,6 @@
|
||||
<text value="Доп. цвет"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="da776" class="javax.swing.JLabel" binding="LabelTypeWindow">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<horizontalAlignment value="0"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<text value="Форма"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="f0d81" binding="PictureBoxPlane" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
@ -353,6 +343,15 @@
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<hspacer id="8ca3b">
|
||||
<constraints>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="5" height="-1"/>
|
||||
<preferred-size width="5" height="-1"/>
|
||||
<maximum-size width="5" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="d1cce" class="javax.swing.JButton" binding="ButtonAddObject">
|
||||
|
@ -35,7 +35,6 @@ public class FormPlaneConfig extends JFrame{
|
||||
private JPanel GroubBoxSelectedCountWindow;
|
||||
private JSpinner NumericUpDownCountWindow;
|
||||
private JPanel MainPanel;
|
||||
private JLabel LabelTypeWindow;
|
||||
private JLabel LabelSimpleWindow;
|
||||
private JLabel LabelRectWindow;
|
||||
private JLabel LabelTriangleWindow;
|
||||
@ -47,7 +46,14 @@ public class FormPlaneConfig extends JFrame{
|
||||
//событие
|
||||
Consumer<DrawingPlane> EventAddPlane;
|
||||
|
||||
public void AddEvent(Consumer<DrawingPlane> ev){
|
||||
//объект для контролирования работы DnD
|
||||
Object dragObject;
|
||||
|
||||
//хранит в себе объект иллюминатор
|
||||
Object enterObject;
|
||||
|
||||
public void AddEvent(Consumer<DrawingPlane> ev)
|
||||
{
|
||||
EventAddPlane = ev;
|
||||
}
|
||||
|
||||
@ -86,7 +92,6 @@ public class FormPlaneConfig extends JFrame{
|
||||
|
||||
//рамки у Label
|
||||
LabelAddColor.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
LabelTypeWindow.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
LabelBaseColor.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
LabelModifiedObject.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
LabelSimpleObject.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
@ -123,7 +128,6 @@ public class FormPlaneConfig extends JFrame{
|
||||
PictureBoxPlane.addMouseListener(defCursor);
|
||||
LabelBaseColor.addMouseListener(defCursor);
|
||||
LabelAddColor.addMouseListener(defCursor);
|
||||
LabelTypeWindow.addMouseListener(defCursor);
|
||||
|
||||
PanelBlack.addMouseListener(drag);
|
||||
PanelPurple.addMouseListener(drag);
|
||||
@ -140,11 +144,20 @@ public class FormPlaneConfig extends JFrame{
|
||||
LabelRectWindow.addMouseListener(drag);
|
||||
LabelTriangleWindow.addMouseListener(drag);
|
||||
|
||||
//настройка DnD для перетаскивания формы иллюминаторов
|
||||
AdditWindowDropObject(LabelSimpleWindow);
|
||||
AdditWindowDropObject(LabelRectWindow);
|
||||
AdditWindowDropObject(LabelTriangleWindow);
|
||||
|
||||
AdditWindowDropTarget(PictureBoxPlane);
|
||||
|
||||
//передача объекта через событие
|
||||
ButtonAddObject.addActionListener(e -> {
|
||||
EventAddPlane.accept(_plane);
|
||||
dispose();
|
||||
});
|
||||
|
||||
//лямбда-выражение для закрытия формы
|
||||
ButtonCancel.addActionListener(e -> dispose());
|
||||
}
|
||||
|
||||
@ -215,27 +228,84 @@ public class FormPlaneConfig extends JFrame{
|
||||
revalidate();
|
||||
}
|
||||
}
|
||||
else if(dropItem instanceof JLabel label && LabelTypeWindow.getMousePosition() != null && _plane!=null)
|
||||
}
|
||||
|
||||
void AdditWindowDropTarget(JComponent obj)
|
||||
{
|
||||
obj.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {super.mouseEntered(e);
|
||||
Window_DragEnter(obj);
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {super.mouseExited(e);
|
||||
DragExit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void AdditWindowDropObject(JComponent obj)
|
||||
{
|
||||
obj.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {super.mousePressed(e);
|
||||
Window_MouseDown(obj);
|
||||
}
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {super.mouseReleased(e);
|
||||
Window_DragDrop();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Window_MouseDown(Object sender)
|
||||
{
|
||||
IAdditionalDrawingObject windows;
|
||||
switch (((JLabel)sender).getText()){
|
||||
case "Простая":
|
||||
windows = new DrawingAirplaneWindow();
|
||||
break;
|
||||
case "Треугольная":
|
||||
windows = new DrawingTriangleAirplaneWindow();
|
||||
break;
|
||||
case "Квадратная":
|
||||
windows = new DrawingRectAirplaneWindow();
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
enterObject = windows;
|
||||
}
|
||||
|
||||
void Window_DragEnter(Object sender)
|
||||
{
|
||||
if(enterObject != null && IAdditionalDrawingObject.class.isAssignableFrom(enterObject.getClass()) && _plane != null)
|
||||
{
|
||||
if(label == LabelSimpleWindow)
|
||||
{
|
||||
_plane.SetTypeWindow((int)NumericUpDownCountWindow.getValue(), new DrawingAirplaneWindow());
|
||||
Draw(_plane);
|
||||
}
|
||||
setCursor(new Cursor(Cursor.HAND_CURSOR));
|
||||
dragObject = sender;
|
||||
}
|
||||
}
|
||||
|
||||
if(label == LabelRectWindow)
|
||||
{
|
||||
_plane.SetTypeWindow((int)NumericUpDownCountWindow.getValue(), new DrawingRectAirplaneWindow());
|
||||
Draw(_plane);
|
||||
}
|
||||
void Window_DragDrop()
|
||||
{
|
||||
if(dragObject == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(label == LabelTriangleWindow)
|
||||
{
|
||||
_plane.SetTypeWindow((int)NumericUpDownCountWindow.getValue(), new DrawingTriangleAirplaneWindow());
|
||||
Draw(_plane);
|
||||
}
|
||||
_plane.SetTypeWindow((int)NumericUpDownCountWindow.getValue(), (IAdditionalDrawingObject)enterObject);
|
||||
DragExit();
|
||||
enterObject = null;
|
||||
}
|
||||
|
||||
repaint();
|
||||
void DragExit()
|
||||
{
|
||||
if(enterObject != null && dragObject != null)
|
||||
{
|
||||
setCursor(Cursor.getDefaultCursor());
|
||||
Draw(_plane);
|
||||
dragObject = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,4 +4,5 @@ public interface IAdditionalDrawingObject
|
||||
{
|
||||
void SetAddEnum(int airplaneWindow);
|
||||
void DrawAirplaneWindow(Color colorAirplaneWindow, Graphics g, float _startPosX, float _startPosY);
|
||||
int GetAddEnum();
|
||||
}
|
||||
|
@ -16,4 +16,7 @@ public interface IDrawningObject
|
||||
|
||||
//получение текущей позиции объекта
|
||||
float[] GetCurrentPosition();
|
||||
|
||||
//получение информации по объекту
|
||||
String GetInfo();
|
||||
}
|
||||
|
@ -17,13 +17,13 @@ public class MapWithSetPlanesGeneric <T extends IDrawningObject, U extends Abstr
|
||||
private final int _placeSizeHeight = 90;
|
||||
|
||||
//набор объектов
|
||||
private final SetPlanesGeneric<T> _setPlanes;
|
||||
private SetPlanesGeneric<T> _setPlanes;
|
||||
|
||||
//набор удалённых объектов (двусвязный список)
|
||||
public final LinkedList<T> _deletePlane;
|
||||
|
||||
//карта
|
||||
private final U _map;
|
||||
private U _map;
|
||||
|
||||
//конструктор
|
||||
public MapWithSetPlanesGeneric(int picWidth, int picHeight, U map)
|
||||
@ -90,6 +90,28 @@ public class MapWithSetPlanesGeneric <T extends IDrawningObject, U extends Abstr
|
||||
return new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_RGB);
|
||||
}
|
||||
|
||||
//получение данных в виде строки
|
||||
public String GetData(char separatorType, char separatorData)
|
||||
{
|
||||
String data = String.format("%s%c", _map.getClass().getName(), separatorType);
|
||||
|
||||
for (var plane : _setPlanes)
|
||||
{
|
||||
data += String.format("%s%c", plane.GetInfo(), separatorData);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
//Загрузка списка из массива строк
|
||||
public void LoadData(String[] records)
|
||||
{
|
||||
for (var rec : records)
|
||||
{
|
||||
_setPlanes.Insert((T)DrawningObjectPlane.Create(rec));
|
||||
}
|
||||
}
|
||||
|
||||
//"взламываем" набор, чтобы все элементы оказались в начале
|
||||
private void Shaking()
|
||||
{
|
||||
@ -212,6 +234,12 @@ public class MapWithSetPlanesGeneric <T extends IDrawningObject, U extends Abstr
|
||||
}
|
||||
}
|
||||
|
||||
//очистка и ключа, и значения по ключу
|
||||
public void Clear()
|
||||
{
|
||||
_setPlanes = null;
|
||||
}
|
||||
|
||||
public T GetPlaneInList(int index)
|
||||
{
|
||||
return _setPlanes.Get(index);
|
||||
|
@ -1,10 +1,12 @@
|
||||
import javax.swing.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
//класс для хранения коллекции карт
|
||||
public class MapsCollection
|
||||
{
|
||||
//словарь (хранилище) с картами
|
||||
public HashMap<String, MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap>> _mapStorage;
|
||||
public HashMap<String, MapWithSetPlanesGeneric<IDrawningObject, AbstractMap>> _mapStorage;
|
||||
|
||||
//возвращение списка названий карт
|
||||
public ArrayList<String> Keys()
|
||||
@ -18,6 +20,12 @@ public class MapsCollection
|
||||
//высота окна отрисовки
|
||||
private final int _pictureHeight;
|
||||
|
||||
//разделитель для записи информации по элементу словаря в файл
|
||||
private final char separatorDict = '|';
|
||||
|
||||
//разделитель для записи коллекции данных в файл
|
||||
private final char separatorData = ';';
|
||||
|
||||
//конструктор
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
@ -43,8 +51,178 @@ public class MapsCollection
|
||||
_mapStorage.remove(name);
|
||||
}
|
||||
|
||||
//сохранение информации по самолётам в ангарах в файл
|
||||
public Boolean SaveData(String filename)
|
||||
{
|
||||
File file = new File(filename);
|
||||
|
||||
if (file.exists())
|
||||
{
|
||||
file.delete();
|
||||
}
|
||||
|
||||
try (BufferedWriter writter = new BufferedWriter(new FileWriter(filename)))
|
||||
{
|
||||
writter.write(String.format("MapsCollection" + System.lineSeparator()));
|
||||
|
||||
for(Map.Entry<String, MapWithSetPlanesGeneric<IDrawningObject, AbstractMap>> entry : _mapStorage.entrySet())
|
||||
{
|
||||
writter.write("" + entry.getKey() + separatorDict + entry.getValue().GetData(separatorDict, separatorData) + "\n");
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(null, e.getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//загрузка нформации по по самолётам в ангарах из файла
|
||||
public Boolean LoadData(String filename)
|
||||
{
|
||||
File file = new File(filename);
|
||||
|
||||
if (!file.exists())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(filename)))
|
||||
{
|
||||
String str = "";
|
||||
|
||||
//если не содержит такую запись или пустой файл
|
||||
if ((str = reader.readLine()) == null || !str.contains("MapsCollection"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_mapStorage.clear();
|
||||
|
||||
while ((str = reader.readLine()) != null)
|
||||
{
|
||||
var element = str.split(String.format("\\%c", separatorDict));
|
||||
AbstractMap map = null;
|
||||
|
||||
switch (element[1])
|
||||
{
|
||||
case "SimpleMap":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "DesertStormMap":
|
||||
map = new DesertStormMap();
|
||||
break;
|
||||
case "StarWarsMap":
|
||||
map = new StarWarsMap();
|
||||
break;
|
||||
}
|
||||
|
||||
_mapStorage.put(element[0], new MapWithSetPlanesGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight,
|
||||
map));
|
||||
|
||||
_mapStorage.get(element[0]).LoadData(element[2].split(String.valueOf(separatorData)));
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, e.getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//сохранение информации по самолётам в ангарах в файл
|
||||
public Boolean SaveOneData(String filename, String mapName)
|
||||
{
|
||||
File file = new File(filename);
|
||||
|
||||
if (file.exists())
|
||||
{
|
||||
file.delete();
|
||||
}
|
||||
|
||||
try (BufferedWriter writter = new BufferedWriter(new FileWriter(filename)))
|
||||
{
|
||||
writter.write(String.format("SaveOneMap" + System.lineSeparator() + "Data of map:" + System.lineSeparator()));
|
||||
|
||||
for(Map.Entry<String, MapWithSetPlanesGeneric<IDrawningObject, AbstractMap>> entry : _mapStorage.entrySet())
|
||||
{
|
||||
if(entry.getKey() == mapName)
|
||||
|
||||
{
|
||||
writter.write("" + entry.getKey() + separatorDict + entry.getValue().GetData(separatorDict, separatorData) + "\n");
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(null, e.getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//загрузка информации по по самолётам в ангарах из файла
|
||||
public Boolean LoadOneData(String filename)
|
||||
{
|
||||
File file = new File(filename);
|
||||
|
||||
if (!file.exists())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(filename)))
|
||||
{
|
||||
String str = "";
|
||||
|
||||
//если не содержит такую запись или пустой файл
|
||||
if ((str = reader.readLine()) == null || !str.contains("SaveOneMap"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
while ((str = reader.readLine()) != null)
|
||||
{
|
||||
var element = str.split(String.format("\\%c", separatorDict));
|
||||
AbstractMap map = null;
|
||||
|
||||
//добавление в коллекцию с устранением лишнего слова в названии
|
||||
try {
|
||||
switch (element[1]) {
|
||||
case "SimpleMap":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "DesertStormMap":
|
||||
map = new DesertStormMap();
|
||||
break;
|
||||
case "StarWarsMap":
|
||||
map = new StarWarsMap();
|
||||
break;
|
||||
}
|
||||
|
||||
//если имя загружаемой карты есть в коллекции
|
||||
if (_mapStorage.get(element[0]) != null)
|
||||
{
|
||||
_mapStorage.get(element[0]).Clear();
|
||||
}
|
||||
|
||||
_mapStorage.put(element[0], new MapWithSetPlanesGeneric<IDrawningObject, AbstractMap>
|
||||
eegov
commented
И смысл проверки выше, если все равно проиходит затиранее? И смысл проверки выше, если все равно проиходит затиранее?
|
||||
(_pictureWidth, _pictureHeight, map));
|
||||
_mapStorage.get(element[0]).LoadData(element[2].split(String.valueOf(separatorData)));
|
||||
} catch (Exception ex) { }
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, e.getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//Доступ к аэродрому
|
||||
public MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap> get(String index)
|
||||
public MapWithSetPlanesGeneric<IDrawningObject, AbstractMap> get(String index)
|
||||
{
|
||||
if(_mapStorage.containsKey(index))
|
||||
{
|
||||
@ -54,7 +232,7 @@ public class MapsCollection
|
||||
return null;
|
||||
}
|
||||
|
||||
public DrawningObjectPlane Get(String name, int index)
|
||||
public IDrawningObject Get(String name, int index)
|
||||
{
|
||||
if(_mapStorage.containsKey(name))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user
Hash_Map.get(Object key_element)
Parameter: The method takes one parameter key_element of object type and refers to the key whose associated value is supposed to be fetched.