Eliseev E.E. LabWork05 #5

Closed
ElEgEv wants to merge 5 commits from LabWork05 into LabWork04
8 changed files with 846 additions and 79 deletions

View File

@ -2,11 +2,14 @@ import java.awt.*;
public class DrawingAirbus extends DrawingPlane
{
private Color addColor;
//Конструктор
public DrawingAirbus(int speed, int weight, Color corpusColor, Color addColor, boolean addCompartment, boolean addEngine)
public DrawingAirbus(int speed, int weight, Color corpusColor, int countWindow, Color addColor, boolean addCompartment, boolean addEngine)
{
super(speed, weight, corpusColor, 70, 30);
super(speed, weight, corpusColor, countWindow, 70, 30);
Plane = new EntityAirbus(speed, weight, corpusColor, addColor, addCompartment, addEngine);
this.addColor = addColor;
}
//Второй конструктор
@ -16,6 +19,22 @@ public class DrawingAirbus extends DrawingPlane
Plane = plane;
}
public void SetAddColor(Color color)
{
var temp = (EntityAirbus) Plane;
Plane = new EntityAirbus(temp.GetSpeed(), temp.GetWeight(), temp.GetColor(), color,
temp.AddCompartment(), temp.AddEngine());
addColor = color;
}
@Override
public void SetColor(Color color)
{
var temp = (EntityAirbus) Plane;
addColor = addColor == null ? Color.WHITE : addColor;
Plane = new EntityAirbus(temp.GetSpeed(), temp.GetWeight(), color, addColor, temp.AddCompartment(), temp.AddEngine());
}
@Override
public void DrawTransport(Graphics g)
{
@ -35,21 +54,23 @@ public class DrawingAirbus extends DrawingPlane
_startPosY -= 5;
//дополнительный пассажирский отсек
if (airbus.AddСompartment)
if (airbus.AddCompartment())
{
g2d.setPaint(airbus.AddColor);
g2d.setPaint(airbus.AddColor());
g2d.fillRect((int)_startPosX + 30, (int)_startPosY + 12, 14, 3);
g2d.setPaint(Color.BLACK);
g2d.drawRect((int)_startPosX + 30, (int)_startPosY + 12, 14, 3);
}
//дополнительный двигатель
if (airbus.AddEngine)
if (airbus.AddEngine())
{
g2d.setPaint(airbus.AddColor);
g2d.setPaint(airbus.AddColor());
g2d.fillOval((int)_startPosX + 24, (int)_startPosY + 22, 10, 5);
g2d.setPaint(Color.BLACK);
g2d.drawOval((int)_startPosX + 24, (int)_startPosY + 22, 10, 5);
}
super.repaint();
}
}

View File

@ -5,42 +5,6 @@ import java.util.Random;
public class DrawingPlane extends JPanel
{
protected EntityPlane Plane; //класс-сущность
public IAdditionalDrawingObject _airplaneWindow; //для дополнительной отрисовки
public void SetAddEnum()
{
Random rnd = new Random();
int numbEnum = rnd.nextInt(1, 4);
_airplaneWindow.SetAddEnum(numbEnum);
}
public void SetFormEnum()
{
Random rnd = new Random();
int numbEnum = rnd.nextInt(1, 4);
if(numbEnum == 1)
{
_airplaneWindow = new DrawingAirplaneWindow();
}
if(numbEnum == 2)
{
_airplaneWindow = new DrawingTriangleAirplaneWindow();
}
if(numbEnum == 3)
{
_airplaneWindow = new DrawingRectAirplaneWindow();
}
}
public EntityPlane GetPlane()
{
return Plane;
}
protected float _startPosX; //левая координата отрисовки
protected float _startPosY; //верхняя координата отрисовки
private Integer _pictureWidth = null; //ширина окна отрисовки
@ -48,18 +12,52 @@ public class DrawingPlane extends JPanel
protected int _airbusWidth = 50; //ширина отрисовки самолёта
protected int _airbusHeight = 16; //высота отрисовки самолёта
//конструктор
public DrawingPlane(int speed, float weight, Color corpusColor)
protected EntityPlane Plane; //класс-сущность
public IAdditionalDrawingObject _airplaneWindow; //для дополнительной отрисовки
public void SetColor(Color color)
{
Plane = new EntityPlane(speed, weight, corpusColor);
SetFormEnum();
SetAddEnum();
Plane = new EntityPlane(Plane.GetSpeed(), Plane.GetWeight(), color);
}
public void SetTypeWindow(int countWindow, IAdditionalDrawingObject window)
{
_airplaneWindow = window;
_airplaneWindow.SetAddEnum(countWindow);
}
public EntityPlane GetPlane()
{
return Plane;
}
//конструктор
public DrawingPlane(int speed, float weight, Color corpusColor, int planeWidth, int planeHeight)
public DrawingPlane(int speed, float weight, Color corpusColor, int countWindow)
{
this(speed, weight, corpusColor);
Random rnd = new Random();
int randomTypeWindow = rnd.nextInt(3);
Plane = new EntityPlane(speed, weight, corpusColor);
if(randomTypeWindow == 1)
{
_airplaneWindow = new DrawingAirplaneWindow();
}
else if(randomTypeWindow == 2)
{
_airplaneWindow = new DrawingRectAirplaneWindow();
}
else
{
_airplaneWindow = new DrawingTriangleAirplaneWindow();
}
_airplaneWindow.SetAddEnum(countWindow);
}
//конструктор
public DrawingPlane(int speed, float weight, Color corpusColor, int countWindow, int planeWidth, int planeHeight)
{
this(speed, weight, corpusColor, countWindow);
_airbusWidth = planeWidth;
_airbusHeight = planeHeight;
}

View File

@ -3,20 +3,32 @@ import java.awt.*;
public class EntityAirbus extends EntityPlane
{
//Дополнительный цвет
public Color AddColor;
public Color addColor;
public Color AddColor()
{
return addColor;
}
//Признак наличия дополнительно пассажирского отсека
public boolean AddСompartment;
public boolean addСompartment;
public boolean AddCompartment()
{
return addСompartment;
}
//Признак наличия дополнительных двигателей
public boolean AddEngine;
public boolean addEngine;
public boolean AddEngine()
{
return addEngine;
}
//Инициализация свойств
public EntityAirbus(int speed, float weight, Color corpusColor, Color addColor, boolean addCompartment, boolean addEngine)
{
super(speed, weight, corpusColor);
AddColor = addColor;
AddСompartment = addCompartment;
AddEngine = addEngine;
this.addColor = addColor;
this.addСompartment = addCompartment;
this.addEngine = addEngine;
}
}

View File

@ -10,7 +10,7 @@ import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.util.HashMap;
public class FormMapWithSetPlanesGeneric {
public class FormMapWithSetPlanesGeneric extends JFrame{
public JPanel MainPanel;
private JPanel PictureBoxPlane;
private JPanel GroupBoxTools;
@ -44,6 +44,7 @@ public class FormMapWithSetPlanesGeneric {
public FormMapWithSetPlanesGeneric()
{
super("Хранилище");
CreateWindow();
_mapsCollection = new MapsCollection(730, 650);
ComboBoxSelectorMap.removeAllItems();
@ -186,30 +187,36 @@ public class FormMapWithSetPlanesGeneric {
}
});
//добавление самолёта
//добавление самолёта с использованием делегата
ButtonAddPlane.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(ListBoxMaps.getSelectedIndex() == -1)
{
return;
}
FormPlaneConfig form = new FormPlaneConfig();
FormPlane form = new FormPlane();
form.setSize(700,400);
form.AddEvent(newPlane ->{
if(ListBoxMaps.getSelectedIndex() == -1)
{
return;
}
if(newPlane != null)
{
DrawningObjectPlane plane = new DrawningObjectPlane(newPlane);
if(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).Add(plane) != -1)
{
JOptionPane.showMessageDialog(null, "Объект добавлен");
UpdateWindow(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
}
else
{
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
}
}
});
form.setSize(975, 360);
form.setVisible(true);
form.setModal(true);
DrawningObjectPlane plane = new DrawningObjectPlane(form.GetSelectedShip());
if(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).Add(plane) != -1)
{
JOptionPane.showMessageDialog(null,"Объект добавлен");
UpdateWindow(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
}
else
{
JOptionPane.showMessageDialog(null,"Не удалось добавить объект");
}
}
});
@ -359,7 +366,8 @@ public class FormMapWithSetPlanesGeneric {
public void keyTyped(KeyEvent e) {
char c = e.getKeyChar();
if ((c < '0') || (c > '9')) {
if ((c < '0') || (c > '9'))
{
e.consume();
}
}

View File

@ -134,7 +134,7 @@ public class FormPlane extends JDialog
Color colorSimple = JColorChooser.showDialog(null, "Выберите цвет", null);
_plane = new DrawingPlane(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
colorSimple);
colorSimple, rnd.nextInt(3));
SetData();
@ -156,7 +156,7 @@ public class FormPlane extends JDialog
Color colorModif = JColorChooser.showDialog(null, "Выберите цвет", null);
_plane = new DrawingAirbus(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
colorSimple, colorModif, rnd.nextBoolean(), rnd.nextBoolean());
colorSimple, rnd.nextInt(3), colorModif, rnd.nextBoolean(), rnd.nextBoolean());
SetData();

View File

@ -0,0 +1,417 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormPlaneConfig">
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="5" 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="1067" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="f1a57" binding="GroupBoxConfig" layout-manager="GridLayoutManager" row-count="6" 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="1" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none" title="Параметры"/>
<children>
<component id="dfd45" class="javax.swing.JLabel" binding="LabelModifiedObject">
<constraints>
<grid row="2" column="3" row-span="2" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="115" height="60"/>
<preferred-size width="115" height="60"/>
<maximum-size width="115" height="60"/>
</grid>
</constraints>
<properties>
<horizontalAlignment value="0"/>
<horizontalTextPosition value="0"/>
<text value="Продвинутый"/>
</properties>
</component>
<component id="f8990" class="javax.swing.JLabel" binding="LabelSimpleObject">
<constraints>
<grid row="2" column="2" row-span="2" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="115" height="60"/>
<preferred-size width="115" height="60"/>
<maximum-size width="115" height="60"/>
</grid>
</constraints>
<properties>
<horizontalAlignment value="0"/>
<text value="Простой"/>
</properties>
</component>
<grid id="292bd" binding="GroupBoxColors" 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="0" column="2" row-span="2" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none" title="Цвета"/>
<children>
<grid id="552b0" binding="PanelRed" layout-manager="GridLayoutManager" row-count="1" 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="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="40" height="40"/>
<preferred-size width="40" height="40"/>
<maximum-size width="40" height="40"/>
</grid>
</constraints>
<properties>
<background color="-65536"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="2be20" binding="PanelWhite" layout-manager="GridLayoutManager" row-count="1" 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="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="40" height="40"/>
<preferred-size width="40" height="40"/>
<maximum-size width="40" height="40"/>
</grid>
</constraints>
<properties>
<background color="-1"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="3404" binding="PanelGreen" layout-manager="GridLayoutManager" row-count="1" 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="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="40" height="40"/>
<preferred-size width="40" height="40"/>
<maximum-size width="40" height="40"/>
</grid>
</constraints>
<properties>
<background color="-16711936"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="2bbb8" binding="PanelGray" layout-manager="GridLayoutManager" row-count="1" 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="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="40" height="40"/>
<preferred-size width="40" height="40"/>
<maximum-size width="40" height="40"/>
</grid>
</constraints>
<properties>
<background color="-8355712"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="15e6" binding="PanelBlue" layout-manager="GridLayoutManager" row-count="1" 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="2" 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="40" height="40"/>
<preferred-size width="40" height="40"/>
<maximum-size width="40" height="40"/>
</grid>
</constraints>
<properties>
<background color="-16776961"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="ebb95" binding="PanelBlack" layout-manager="GridLayoutManager" row-count="1" 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="1" column="2" 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="40" height="40"/>
<preferred-size width="40" height="40"/>
<maximum-size width="40" height="40"/>
</grid>
</constraints>
<properties>
<background color="-16777216"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="15b" binding="PanelYellow" layout-manager="GridLayoutManager" row-count="1" 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="3" 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="40" height="40"/>
<preferred-size width="40" height="40"/>
<maximum-size width="40" height="40"/>
</grid>
</constraints>
<properties>
<background color="-256"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="23b87" binding="PanelPurple" layout-manager="GridLayoutManager" row-count="1" 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="1" column="3" 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="40" height="40"/>
<preferred-size width="40" height="40"/>
<maximum-size width="40" height="40"/>
</grid>
</constraints>
<properties>
<background color="-8388480"/>
</properties>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
<component id="d05e5" class="javax.swing.JLabel" binding="LabelSpeed">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Скорость:"/>
</properties>
</component>
<component id="b735d" class="javax.swing.JLabel" binding="LabelWeight">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Вес:"/>
</properties>
</component>
<component id="76e8b" class="javax.swing.JSpinner" binding="NumericUpDownWeight">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="100" height="30"/>
<preferred-size width="100" height="30"/>
<maximum-size width="100" height="30"/>
</grid>
</constraints>
<properties/>
</component>
<component id="edff1" class="javax.swing.JSpinner" binding="NumericUpDownSpeed">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="100" height="30"/>
<preferred-size width="100" height="30"/>
<maximum-size width="100" height="30"/>
</grid>
</constraints>
<properties/>
</component>
<component id="68d82" class="javax.swing.JCheckBox" binding="CheckBoxAddСompartment">
<constraints>
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Признак наличия дополнительного пассажирского отсека"/>
</properties>
</component>
<component id="70231" class="javax.swing.JCheckBox" binding="CheckBoxAddEngine">
<constraints>
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Признак наличия дополнительного двигателя"/>
</properties>
</component>
<grid id="26bf3" binding="GroubBoxSelectedCountWindow" layout-manager="GridLayoutManager" row-count="1" 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="4" column="0" row-span="1" col-span="4" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none" title="Количество иллюминаторов"/>
<children>
<component id="ba7f5" class="javax.swing.JSpinner" binding="NumericUpDownCountWindow">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<hspacer id="1d23b">
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="3e617">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="5f58d">
<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>
<grid id="5692c" binding="GroupBoxSelectPlaneWindow" layout-manager="GridLayoutManager" row-count="1" 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="5" column="0" row-span="1" col-span="4" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none" title="Выбор формы иллюминаторов"/>
<children>
<component id="df250" class="javax.swing.JLabel" binding="LabelSimpleWindow">
<constraints>
<grid row="0" column="0" 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>
<component id="d29b7" class="javax.swing.JLabel" binding="LabelRectWindow">
<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>
<component id="739f2" class="javax.swing.JLabel" binding="LabelTriangleWindow">
<constraints>
<grid row="0" column="2" 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>
</children>
</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">
<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"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="dc389" class="javax.swing.JLabel" binding="LabelBaseColor">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="120" height="40"/>
<preferred-size width="120" height="40"/>
<maximum-size width="120" height="40"/>
</grid>
</constraints>
<properties>
<horizontalAlignment value="0"/>
<horizontalTextPosition value="0"/>
<text value="Цвет"/>
<verticalAlignment value="0"/>
</properties>
</component>
<component id="d04af" class="javax.swing.JLabel" binding="LabelAddColor">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="120" height="40"/>
<preferred-size width="120" height="40"/>
<maximum-size width="120" height="40"/>
</grid>
</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"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
<component id="d1cce" class="javax.swing.JButton" binding="ButtonAddObject">
<constraints>
<grid row="2" column="2" 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="120" height="40"/>
<preferred-size width="120" height="40"/>
<maximum-size width="120" height="40"/>
</grid>
</constraints>
<properties>
<text value="Добавить"/>
</properties>
</component>
<component id="1a616" class="javax.swing.JButton" binding="ButtonCancel">
<constraints>
<grid row="2" column="3" 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="120" height="40"/>
<preferred-size width="120" height="40"/>
<maximum-size width="120" height="40"/>
</grid>
</constraints>
<properties>
<text value="Отмена"/>
</properties>
</component>
<vspacer id="b4118">
<constraints>
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false">
<minimum-size width="-1" height="10"/>
<preferred-size width="-1" height="10"/>
<maximum-size width="-1" height="10"/>
</grid>
</constraints>
</vspacer>
<vspacer id="e1b61">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false">
<minimum-size width="-1" height="10"/>
<preferred-size width="-1" height="10"/>
<maximum-size width="-1" height="10"/>
</grid>
</constraints>
</vspacer>
<hspacer id="f542d">
<constraints>
<grid row="1" column="0" 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>
<hspacer id="2e630">
<constraints>
<grid row="1" column="4" 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>
<buttonGroups>
<group name="ButtonGroup1">
<member id="3c6c4"/>
<member id="8a8c0"/>
<member id="abb84"/>
</group>
</buttonGroups>
</form>

View File

@ -0,0 +1,311 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.util.function.Consumer;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.function.Consumer;
public class FormPlaneConfig extends JFrame{
private JButton ButtonAddObject;
private JButton ButtonCancel;
private JPanel GroupBoxConfig;
private JPanel PanelObject;
private JPanel GroupBoxColors;
private JPanel PanelRed;
private JPanel PanelGreen;
private JPanel PanelBlue;
private JPanel PanelYellow;
private JPanel PanelPurple;
private JPanel PanelBlack;
private JPanel PanelGray;
private JPanel PanelWhite;
private JLabel LabelSimpleObject;
private JLabel LabelModifiedObject;
private JLabel LabelBaseColor;
private JLabel LabelAddColor;
private JLabel LabelSpeed;
private JLabel LabelWeight;
private JSpinner NumericUpDownWeight;
private JSpinner NumericUpDownSpeed;
private JCheckBox CheckBoxAddСompartment;
private JCheckBox CheckBoxAddEngine;
private JPanel GroupBoxSelectPlaneWindow;
private JPanel GroubBoxSelectedCountWindow;
private JSpinner NumericUpDownCountWindow;
private JPanel MainPanel;
private JLabel LabelSimpleWindow;
private JLabel LabelRectWindow;
private JLabel LabelTriangleWindow;
private JPanel PictureBoxPlane;
//переменная-выбранный самолёт
DrawingPlane _plane;
//событие
Consumer<DrawingPlane> EventAddPlane;
//объект для контролирования работы DnD
Object dragObject;
//хранит в себе объект иллюминатор
Object enterObject;
public void AddEvent(Consumer<DrawingPlane> ev)
{
EventAddPlane = ev;
}
//конструктор
public FormPlaneConfig()
{
super("Самолёт");
CreateWindow();
}
public void Draw(DrawingPlane _plane)
{
PictureBoxPlane.removeAll();
BufferedImage bmp = new BufferedImage(250, 200, BufferedImage.TYPE_INT_RGB);
Graphics gr = bmp.getGraphics();
gr.setColor(new Color(238, 238, 238));
gr.fillRect(0, 0, 250, 200);
if (_plane.GetPlane() != null) {
_plane.DrawTransport(gr);
JLabel imageOfLogo = new JLabel();
imageOfLogo.setPreferredSize(PictureBoxPlane.getSize());
imageOfLogo.setMinimumSize(new Dimension(1, 1));
imageOfLogo.setIcon(new ImageIcon(bmp));
PictureBoxPlane.add(imageOfLogo, BorderLayout.CENTER);
}
validate();
}
public void CreateWindow()
{
setPreferredSize(new Dimension(1000, 700));
getContentPane().add(MainPanel);
//рамки у Label
LabelAddColor.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));
LabelSimpleWindow.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
LabelRectWindow.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
LabelTriangleWindow.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
//настройка значений у NumericUpDown
NumericUpDownSpeed.setModel(new SpinnerNumberModel(1000, 1000, 3000, 1));
NumericUpDownWeight.setModel(new SpinnerNumberModel(750, 100, 1500, 1));
NumericUpDownCountWindow.setModel(new SpinnerNumberModel(1, 1, 3, 1));
MouseAdapter drag = new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
setCursor(new Cursor(Cursor.HAND_CURSOR));
}
@Override
public void mouseReleased(MouseEvent e) {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
Drop((JComponent) e.getSource());
}
};
MouseAdapter defCursor = new MouseAdapter() {
@Override
public void mouseExited(MouseEvent e) {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
};
//настройки курсоров
PictureBoxPlane.addMouseListener(defCursor);
LabelBaseColor.addMouseListener(defCursor);
LabelAddColor.addMouseListener(defCursor);
PanelBlack.addMouseListener(drag);
PanelPurple.addMouseListener(drag);
PanelGray.addMouseListener(drag);
PanelGreen.addMouseListener(drag);
PanelRed.addMouseListener(drag);
PanelWhite.addMouseListener(drag);
PanelYellow.addMouseListener(drag);
PanelBlue.addMouseListener(drag);
LabelSimpleObject.addMouseListener(drag);
LabelModifiedObject.addMouseListener(drag);
LabelSimpleWindow.addMouseListener(drag);
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());
}
public void Drop(JComponent dropItem)
{
if(dropItem == null)
{
return;
}
if(dropItem instanceof JPanel panel)
{
if(_plane == null)
{
return;
}
if(LabelBaseColor.getMousePosition() != null)
{
_plane.SetColor(panel.getBackground());
Draw(_plane);
repaint();
}
if(LabelAddColor.getMousePosition() != null && _plane instanceof DrawingAirbus airbus)
{
airbus.SetAddColor(panel.getBackground());
Draw(_plane);
repaint();
}
}
if(dropItem instanceof JLabel label && PictureBoxPlane.getMousePosition() != null)
{
int speed = (int)NumericUpDownSpeed.getValue();
int weight = (int)NumericUpDownWeight.getValue();
int countWindow = (int)NumericUpDownCountWindow.getValue();
boolean addCompartment = CheckBoxAddСompartment.isSelected();
boolean addEngine = CheckBoxAddEngine.isSelected();
if(label == LabelSimpleObject)
{
try
{
_plane = new DrawingPlane(speed, weight, Color.WHITE, countWindow);
Draw(_plane);
repaint();
}
catch(Exception ex) { }
}
else if(label == LabelModifiedObject)
{
try
{
_plane = new DrawingAirbus(speed, weight, Color.WHITE, countWindow, Color.WHITE, addCompartment, addEngine);
Draw(_plane);
repaint();
}
catch (Exception ex) { };
}
if(_plane != null)
{
_plane.SetPosition(PictureBoxPlane.getWidth() - 200, PictureBoxPlane.getHeight() - 150, PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
PictureBoxPlane.add(_plane, BorderLayout.CENTER);
Draw(_plane);
repaint();
revalidate();
}
}
}
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)
{
setCursor(new Cursor(Cursor.HAND_CURSOR));
dragObject = sender;
}
}
void Window_DragDrop()
{
if(dragObject == null)
{
return;
}
_plane.SetTypeWindow((int)NumericUpDownCountWindow.getValue(), (IAdditionalDrawingObject)enterObject);
DragExit();
enterObject = null;
}
void DragExit()
{
if(enterObject != null && dragObject != null)
{
setCursor(Cursor.getDefaultCursor());
Draw(_plane);
dragObject = null;
}
}
}

View File

@ -1,6 +1,6 @@
import java.awt.*;
public interface IAdditionalDrawingObject
public interface IAdditionalDrawingObject
{
void SetAddEnum(int airplaneWindow);
void DrawAirplaneWindow(Color colorAirplaneWindow, Graphics g, float _startPosX, float _startPosY);