Eliseev E.E. LabWork08 #8
@ -181,6 +181,31 @@ public abstract class AbstractMap
|
||||
return bmp;
|
||||
}
|
||||
|
||||
//сравнение
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
AbstractMap other = (AbstractMap)obj;
|
||||
if (other == null || _map != other._map || _height != other._height || _width != other._width
|
||||
|| _size_x != other._size_x || _size_y != other._size_y || getClass() != other.getClass())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for(int i = 0; i < _map.length; i++)
|
||||
{
|
||||
for(int j = 0; j < _map[i].length; j++)
|
||||
{
|
||||
if (_map[i][j] != other._map[i][j])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract void GenerateMap();
|
||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||
|
@ -10,6 +10,9 @@ public class DrawingAirbus extends DrawingPlane
|
||||
super(speed, weight, corpusColor, countWindow, 70, 30);
|
||||
Plane = new EntityAirbus(speed, weight, corpusColor, addColor, addCompartment, addEngine);
|
||||
this.addColor = addColor;
|
||||
|
||||
fields = new Object[]{speed, weight, corpusColor, _airplaneWindow.getClass().getSimpleName(), countWindow,
|
||||
addCompartment, addCompartment};
|
||||
}
|
||||
|
||||
//Второй конструктор
|
||||
@ -73,4 +76,4 @@ public class DrawingAirbus extends DrawingPlane
|
||||
|
||||
super.repaint();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.Color;
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingPlane extends JPanel
|
||||
public class DrawingPlane extends JPanel implements Iterable<Object>, Iterator<Object>
|
||||
{
|
||||
protected float _startPosX; //левая координата отрисовки
|
||||
protected float _startPosY; //верхняя координата отрисовки
|
||||
@ -15,6 +16,11 @@ public class DrawingPlane extends JPanel
|
||||
protected EntityPlane Plane; //класс-сущность
|
||||
public IAdditionalDrawingObject _airplaneWindow; //для дополнительной отрисовки
|
||||
|
||||
private int currentIndex = 0;
|
||||
protected Object[] fields;
|
||||
|
||||
public int _countWindows; //для сравнения при вставке
|
||||
|
||||
public void SetColor(Color color)
|
||||
{
|
||||
Plane = new EntityPlane(Plane.GetSpeed(), Plane.GetWeight(), color);
|
||||
@ -24,6 +30,7 @@ public class DrawingPlane extends JPanel
|
||||
{
|
||||
_airplaneWindow = window;
|
||||
_airplaneWindow.SetAddEnum(countWindow);
|
||||
_countWindows = countWindow;
|
||||
}
|
||||
|
||||
public EntityPlane GetPlane()
|
||||
@ -52,6 +59,7 @@ public class DrawingPlane extends JPanel
|
||||
}
|
||||
|
||||
_airplaneWindow.SetAddEnum(countWindow);
|
||||
fields = new Object[]{speed, weight, corpusColor, _airplaneWindow.getClass().getSimpleName(), countWindow};
|
||||
}
|
||||
|
||||
//кол-во иллюминаторов
|
||||
@ -72,6 +80,9 @@ public class DrawingPlane extends JPanel
|
||||
{
|
||||
Plane = plane;
|
||||
_airplaneWindow = countWindow;
|
||||
|
||||
fields = new Object[]{plane.GetSpeed(), plane.GetWeight(),
|
||||
plane.GetColor(), _airplaneWindow.getClass().getSimpleName(), _countWindows};
|
||||
}
|
||||
|
||||
//установка координат позиции самолёта
|
||||
@ -225,4 +236,19 @@ public class DrawingPlane extends JPanel
|
||||
{
|
||||
return new float[]{_startPosX, _startPosY, _startPosX + _airbusWidth, _startPosY + _airbusHeight};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator iterator() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return currentIndex < fields.length && fields[currentIndex] != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object next() {
|
||||
return fields[currentIndex++];
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import java.awt.*;
|
||||
import java.util.Objects;
|
||||
|
||||
public class DrawningObjectPlane implements IDrawningObject
|
||||
{
|
||||
@ -11,6 +12,11 @@ public class DrawningObjectPlane implements IDrawningObject
|
||||
|
||||
public DrawningObjectPlane(DrawingPlane plane){ _plane = plane; }
|
||||
|
||||
public DrawingPlane GetPlane()
|
||||
{
|
||||
return _plane;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float Step()
|
||||
{
|
||||
@ -60,6 +66,73 @@ public class DrawningObjectPlane implements IDrawningObject
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if(obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var otherPlane = (DrawningObjectPlane) obj;
|
||||
|
||||
if(otherPlane == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var plane = _plane.Plane;
|
||||
var otherPlanePlane = otherPlane._plane.Plane;
|
||||
|
||||
|
||||
if(plane.getClass().getSimpleName() != otherPlanePlane.getClass().getSimpleName())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(plane.GetSpeed() != otherPlanePlane.GetSpeed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(plane.GetWeight() != otherPlanePlane.GetWeight())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(plane.GetColor().getRGB() != otherPlanePlane.GetColor().getRGB())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(_plane._airplaneWindow.getClass().getSimpleName() != otherPlane._plane._airplaneWindow.getClass().getSimpleName())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(_plane._countWindows != otherPlane._plane._countWindows)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (plane instanceof EntityAirbus entitySuperAirbus && otherPlanePlane instanceof EntityAirbus otherEntitySuperAirbus)
|
||||
{
|
||||
if(entitySuperAirbus.AddEngine() != otherEntitySuperAirbus.AddEngine())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(entitySuperAirbus.AddCompartment() != otherEntitySuperAirbus.AddCompartment())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return entitySuperAirbus.AddColor().getRGB() == otherEntitySuperAirbus.AddColor().getRGB();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static IDrawningObject Create(String data)
|
||||
{
|
||||
return new DrawningObjectPlane(ExtentionPlane.CreateDrawingPlane(data));
|
||||
|
@ -3,7 +3,7 @@
|
||||
<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="683"/>
|
||||
<xy x="20" y="20" width="994" height="713"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
@ -18,9 +18,16 @@
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
<children>
|
||||
<scrollpane id="6113d">
|
||||
<constraints border-constraint="East"/>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</scrollpane>
|
||||
</children>
|
||||
</grid>
|
||||
<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">
|
||||
<grid id="4871f" binding="GroupBoxTools" layout-manager="GridLayoutManager" row-count="20" 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="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">
|
||||
@ -34,7 +41,7 @@
|
||||
<children>
|
||||
<component id="d0967" class="javax.swing.JButton" binding="ButtonLeft">
|
||||
<constraints>
|
||||
<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">
|
||||
<grid row="19" 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 +53,7 @@
|
||||
</component>
|
||||
<component id="d9af3" class="javax.swing.JButton" binding="ButtonDown">
|
||||
<constraints>
|
||||
<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">
|
||||
<grid row="19" 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 +65,7 @@
|
||||
</component>
|
||||
<component id="9e43" class="javax.swing.JButton" binding="ButtonRight">
|
||||
<constraints>
|
||||
<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">
|
||||
<grid row="19" 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 +77,7 @@
|
||||
</component>
|
||||
<component id="4d1dd" class="javax.swing.JButton" binding="ButtonUp">
|
||||
<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="18" 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 +89,7 @@
|
||||
</component>
|
||||
<component id="67190" class="javax.swing.JButton" binding="ButtonShowOnMap">
|
||||
<constraints>
|
||||
<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">
|
||||
<grid row="16" 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 +101,7 @@
|
||||
</component>
|
||||
<component id="28576" class="javax.swing.JButton" binding="ButtonShowStorage">
|
||||
<constraints>
|
||||
<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">
|
||||
<grid row="14" 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"/>
|
||||
@ -106,7 +113,7 @@
|
||||
</component>
|
||||
<component id="7119" class="javax.swing.JButton" binding="ButtonAddPlane">
|
||||
<constraints>
|
||||
<grid row="6" 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="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"/>
|
||||
@ -118,7 +125,7 @@
|
||||
</component>
|
||||
<component id="6f119" class="javax.swing.JTextField" binding="MaskedTextBoxPosition">
|
||||
<constraints>
|
||||
<grid row="7" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<grid row="10" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="220" height="30"/>
|
||||
<preferred-size width="220" height="30"/>
|
||||
<maximum-size width="220" height="30"/>
|
||||
@ -131,7 +138,7 @@
|
||||
</component>
|
||||
<component id="d75e9" class="javax.swing.JButton" binding="ButtonRemovePlane">
|
||||
<constraints>
|
||||
<grid row="8" 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,22 +150,22 @@
|
||||
</component>
|
||||
<vspacer id="f972a">
|
||||
<constraints>
|
||||
<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"/>
|
||||
<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"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<vspacer id="65c78">
|
||||
<constraints>
|
||||
<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"/>
|
||||
<grid row="15" 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="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"/>
|
||||
<grid row="17" 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">
|
||||
<constraints>
|
||||
<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"/>
|
||||
<grid row="8" 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" binding="GroupBoxMap" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
@ -235,7 +242,7 @@
|
||||
</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">
|
||||
<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">
|
||||
<minimum-size width="220" height="30"/>
|
||||
<preferred-size width="220" height="30"/>
|
||||
<maximum-size width="220" height="30"/>
|
||||
@ -245,6 +252,35 @@
|
||||
<text value="Посмотреть удалённый самолёт"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="75db3" class="javax.swing.JButton" binding="ButtonSortByType">
|
||||
<constraints>
|
||||
<grid row="6" 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>
|
||||
<vspacer id="5ec73">
|
||||
<constraints>
|
||||
<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>
|
||||
<component id="beb6c" class="javax.swing.JButton" binding="ButtonSortByColor">
|
||||
<constraints>
|
||||
<grid row="7" 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>
|
||||
<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">
|
||||
|
@ -38,6 +38,8 @@ public class FormMapWithSetPlanesGeneric extends JFrame{
|
||||
private JMenuItem MenuItemSaveData;
|
||||
private JMenuItem MenuItemLoadOneMapData;
|
||||
private JMenuItem MenuItemSaveOneMapData;
|
||||
private JButton ButtonSortByType;
|
||||
private JButton ButtonSortByColor;
|
||||
|
||||
//объект от коллекции карт
|
||||
private final MapsCollection _mapsCollection;
|
||||
@ -134,11 +136,11 @@ public class FormMapWithSetPlanesGeneric extends JFrame{
|
||||
|
||||
if(ComboBoxSelectorMap.getSelectedIndex() == -1)
|
||||
{
|
||||
logger.log(Level.ERROR, "При добавлении карты " + ComboBoxSelectorMap.getSelectedIndex() + "не была выбрана карта");
|
||||
logger.log(Level.ERROR, "При добавлении карты " + ComboBoxSelectorMap.getSelectedIndex() + " не была выбрана карта");
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.log(Level.ERROR, "При добавлении карты " + ComboBoxSelectorMap.getSelectedIndex() + "не была названа карта");
|
||||
logger.log(Level.ERROR, "При добавлении карты " + ComboBoxSelectorMap.getSelectedIndex() + " не была названа карта");
|
||||
}
|
||||
|
||||
return;
|
||||
@ -438,6 +440,34 @@ public class FormMapWithSetPlanesGeneric extends JFrame{
|
||||
}
|
||||
});
|
||||
|
||||
//сортировка по типу
|
||||
ButtonSortByType.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(ListBoxMaps.getSelectedIndex() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).Sort(new PlaneCompareByType());
|
||||
UpdateWindow(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
|
||||
}
|
||||
});
|
||||
|
||||
//сортировка по цвету
|
||||
ButtonSortByColor.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(ListBoxMaps.getSelectedIndex() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).Sort(new PlaneCompareByColor());
|
||||
UpdateWindow(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
|
||||
}
|
||||
});
|
||||
|
||||
//обработка нажатия загрузки всех карт
|
||||
MenuItemLoadData.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
@ -457,7 +487,7 @@ public class FormMapWithSetPlanesGeneric extends JFrame{
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Ошибка загрузки данных" + ex.getMessage(),
|
||||
JOptionPane.showMessageDialog(null, "Ошибка загрузки данных " + ex.getMessage(),
|
||||
"Результат", JOptionPane.ERROR_MESSAGE);
|
||||
logger.log(Level.ERROR, "Ошибка загрузки: " + ex.getMessage());
|
||||
}
|
||||
@ -483,7 +513,7 @@ public class FormMapWithSetPlanesGeneric extends JFrame{
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не сохранилось" + ex.getMessage(),
|
||||
JOptionPane.showMessageDialog(null, "Не сохранилось " + ex.getMessage(),
|
||||
"Результат", JOptionPane.ERROR_MESSAGE);
|
||||
logger.log(Level.ERROR,"Ошибка сохранения: " + ex.getMessage());
|
||||
}
|
||||
|
@ -239,4 +239,4 @@ public class FormPlane extends JDialog
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class MapWithSetPlanesGeneric <T extends IDrawningObject, U extends AbstractMap>
|
||||
public class MapWithSetPlanesGeneric <T extends IDrawningObject, U extends AbstractMap> implements Comparable<MapWithSetPlanesGeneric<T,U>>
|
||||
{
|
||||
//ширина окна отрисовки
|
||||
private final int _pictureWidth;
|
||||
@ -109,6 +110,31 @@ public class MapWithSetPlanesGeneric <T extends IDrawningObject, U extends Abstr
|
||||
}
|
||||
}
|
||||
|
||||
//сортировка
|
||||
public void Sort(Comparator<T> comparer)
|
||||
{
|
||||
_setPlanes.SortSet(comparer);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int compareTo(MapWithSetPlanesGeneric<T, U> o) {
|
||||
if (o == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (this == o)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Integer temp1 = _setPlanes.Count();
|
||||
Integer temp2 = o._setPlanes.Count();
|
||||
|
||||
return temp1.compareTo(temp2);
|
||||
}
|
||||
|
||||
//"взламываем" набор, чтобы все элементы оказались в начале
|
||||
private void Shaking() throws StorageOverflowException, PlaneNotFoundException {
|
||||
int j = _setPlanes.Count() - 1;
|
||||
|
80
Project/src/PlaneCompareByColor.java
Normal file
80
Project/src/PlaneCompareByColor.java
Normal file
@ -0,0 +1,80 @@
|
||||
import java.awt.*;
|
||||
import java.util.Comparator;
|
||||
|
||||
public class PlaneCompareByColor implements Comparator<IDrawningObject>
|
||||
{
|
||||
@Override
|
||||
public int compare(IDrawningObject x, IDrawningObject y)
|
||||
{
|
||||
if (x == null && y == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (x == null && y != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (x != null && y == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
DrawningObjectPlane xPlane = (DrawningObjectPlane)x;
|
||||
DrawningObjectPlane yPlane = (DrawningObjectPlane)y;
|
||||
|
||||
if (xPlane == null && yPlane == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (xPlane == null && yPlane != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (xPlane != null && yPlane == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
var xEntityPlane = xPlane.GetPlane().Plane;
|
||||
var yEntityPlane = yPlane.GetPlane().Plane;
|
||||
|
||||
Integer colorCompare1 = xEntityPlane.GetColor().getRGB();
|
||||
Integer colorCompare2 = yEntityPlane.GetColor().getRGB();
|
||||
var colorCompare = colorCompare1.compareTo(colorCompare2);
|
||||
|
||||
if (colorCompare != 0)
|
||||
{
|
||||
return colorCompare;
|
||||
}
|
||||
|
||||
if (xEntityPlane instanceof EntityAirbus xAirbus && yEntityPlane instanceof EntityAirbus yAirbus)
|
||||
{
|
||||
Integer dopColorCompare1 = xAirbus.AddColor().getRGB();
|
||||
Integer dopColorCompare2 = yAirbus.AddColor().getRGB();
|
||||
var addColorCompare = dopColorCompare1.compareTo(dopColorCompare2);
|
||||
|
||||
if(addColorCompare != 0)
|
||||
{
|
||||
return addColorCompare;
|
||||
}
|
||||
}
|
||||
|
||||
Integer speedCompare1 = xPlane.GetPlane().Plane.GetSpeed();
|
||||
Integer speedCompare2 = yPlane.GetPlane().Plane.GetSpeed();
|
||||
var speedCompare = speedCompare1.compareTo(speedCompare2);
|
||||
|
||||
if(speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
|
||||
Float weightCompare1 = xPlane.GetPlane().Plane.GetWeight();
|
||||
Float weightCompare2 = yPlane.GetPlane().Plane.GetWeight();
|
||||
|
||||
return weightCompare1.compareTo(weightCompare2);
|
||||
}
|
||||
}
|
83
Project/src/PlaneCompareByType.java
Normal file
83
Project/src/PlaneCompareByType.java
Normal file
@ -0,0 +1,83 @@
|
||||
import java.util.Comparator;
|
||||
import java.util.Objects;
|
||||
|
||||
public class PlaneCompareByType implements Comparator<IDrawningObject>
|
||||
{
|
||||
@Override
|
||||
public int compare(IDrawningObject x, IDrawningObject y)
|
||||
{
|
||||
if (x == null && y == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (x == null && y != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (x != null && y == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
DrawningObjectPlane xPlane = (DrawningObjectPlane)x;
|
||||
DrawningObjectPlane yPlane = (DrawningObjectPlane)y;
|
||||
|
||||
if (xPlane == null && yPlane == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (xPlane == null && yPlane != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (xPlane != null && yPlane == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if(!Objects.equals(xPlane.GetPlane().getClass(), yPlane.GetPlane().getClass()))
|
||||
{
|
||||
if(xPlane.GetPlane().getClass().getSimpleName() == "DrawingPlane")
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
String xStyleWindows = xPlane.GetPlane()._airplaneWindow.getClass().getSimpleName();
|
||||
String yStyleWindows = yPlane.GetPlane()._airplaneWindow.getClass().getSimpleName();
|
||||
int styleCompare = xStyleWindows.compareTo(yStyleWindows);
|
||||
|
||||
if(styleCompare != 0){
|
||||
return styleCompare;
|
||||
}
|
||||
|
||||
Integer xCountWindows = xPlane.GetPlane()._countWindows;
|
||||
Integer yCountWindows = yPlane.GetPlane()._countWindows;
|
||||
int countWindowsCompare = xCountWindows.compareTo(yCountWindows);
|
||||
|
||||
if(countWindowsCompare != 0){
|
||||
return countWindowsCompare;
|
||||
}
|
||||
|
||||
Integer speedCompare1 = xPlane.GetPlane().Plane.GetSpeed();
|
||||
Integer speedCompare2 = yPlane.GetPlane().Plane.GetSpeed();
|
||||
var speedCompare = speedCompare1.compareTo(speedCompare2);
|
||||
|
||||
if(speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
|
||||
Float weightCompare1 = xPlane.GetPlane().Plane.GetWeight();
|
||||
Float weightCompare2 = yPlane.GetPlane().Plane.GetWeight();
|
||||
|
||||
return weightCompare1.compareTo(weightCompare2);
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class SetPlanesGeneric<T extends Object> implements Iterable<T>
|
||||
@ -29,6 +30,12 @@ public class SetPlanesGeneric<T extends Object> implements Iterable<T>
|
||||
|
||||
//добавление объекта в набор на конкретную позицию
|
||||
public int Insert(T plane, int position) throws StorageOverflowException {
|
||||
//проверка на наличие такого же объекта
|
||||
if(_places.contains(plane))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
//проверка на переполнение хранилища
|
||||
if(_maxCount == Count())
|
||||
{
|
||||
@ -50,7 +57,7 @@ public class SetPlanesGeneric<T extends Object> implements Iterable<T>
|
||||
public T Remove(int position) throws PlaneNotFoundException
|
||||
{
|
||||
// проверка позиции
|
||||
if (position >= _places.size() || position < 0)
|
||||
if (position >= Count() || position < 0)
|
||||
{
|
||||
throw new PlaneNotFoundException(position);
|
||||
}
|
||||
@ -88,6 +95,17 @@ public class SetPlanesGeneric<T extends Object> implements Iterable<T>
|
||||
Insert(value, position);
|
||||
}
|
||||
|
||||
//сортировка набора объектов
|
||||
public void SortSet(Comparator<T> comparer)
|
||||
{
|
||||
if(comparer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_places.sort(comparer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user