Karamushko M.K Lab work 5 #5

Closed
maxKarme wants to merge 2 commits from lab5_hard into lab4_hard
9 changed files with 701 additions and 19 deletions

View File

@ -51,6 +51,21 @@ class DrawingAircraft
_airFighterHeight = airFighterHeight;
}
public void setEngines(IDrawingEngines engines) {
drawingEngines = engines;
}
public IDrawingEngines getEngines() {
return drawingEngines;
}
public void setColor(Color color) {
AirFighter.BodyColor = color;
}
public Color getColor() {
return AirFighter.BodyColor;
}
public void SetPosition(int x, int y, int width, int height)
{

View File

@ -16,6 +16,11 @@ public class DrawingEngines implements IDrawingEngines {
else enginesCount = EnginesCount.Four;
}
@Override
public void setColor(Color color) {
this.color = color;
}
public void draw(Graphics2D g, int startPosX, int startPosY) {
g.setPaint(color);
g.fillOval(startPosX + 80, startPosY + 10, 30, 15);

View File

@ -12,6 +12,11 @@ public class DrawingModernAircraft extends DrawingAircraft
super(speed, weight, bodyColor, 195, 166);
AirFighter = new EntityModernAircraft(speed, weight, bodyColor, dopColor, dopWings, rockets);
}
public void setDopColor(Color color) {
((EntityModernAircraft)AirFighter).DopColor = color;
}
@Override
public void DrawTransport(Graphics2D g)
{

View File

@ -16,6 +16,11 @@ public class DrawingTruncatedEngines implements IDrawingEngines {
else enginesCount = EnginesCount.Four;
}
@Override
public void setColor(Color color) {
this.color = color;
}
public void draw(Graphics2D g, int startPosX, int startPosY) {
g.setPaint(color);
g.fillArc(startPosX + 90, startPosY + 10, 30, 15, 90, 180);

View File

@ -16,6 +16,11 @@ public class DrawingWavyEngines implements IDrawingEngines {
else enginesCount = EnginesCount.Four;
}
@Override
public void setColor(Color color) {
this.color = color;
}
private void drawEngine(Graphics2D g, int x, int y) {
g.setColor(color);
g.fillRect(x, y, 21, 10);

478
FormAircraftConfig.form Normal file
View File

@ -0,0 +1,478 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormAircraftConfig">
<grid id="27dc6" binding="mainPane" 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>
<xy x="20" y="20" width="813" height="425"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="11ed" 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"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="6bdf" layout-manager="GridLayoutManager" row-count="2" 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"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="b99b4" layout-manager="GridLayoutManager" row-count="4" 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="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/>
<border type="none" title="Параметры самолета"/>
<children>
<grid id="bf610" binding="colorsPane" 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="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="250" height="130"/>
<preferred-size width="250" height="130"/>
<maximum-size width="250" height="130"/>
</grid>
</constraints>
<properties/>
<border type="none" title="Цвета"/>
<children>
<grid id="b0657" 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"/>
</constraints>
<properties>
<background color="-4389370"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="454fe" 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="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<background color="-7414"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="acb3b" 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="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<background color="-16408064"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="e10ed" 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="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<background color="-14474274"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="6a752" 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"/>
</constraints>
<properties>
<background color="-1"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="4650b" 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"/>
</constraints>
<properties>
<background color="-5723992"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="37a23" 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"/>
</constraints>
<properties>
<background color="-16777216"/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="6424" 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"/>
</constraints>
<properties>
<background color="-5166919"/>
</properties>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
<hspacer id="acd9a">
<constraints>
<grid row="1" 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>
<grid id="f9e1b" layout-manager="GridLayoutManager" row-count="3" 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="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="130" height="-1"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="290f9" class="javax.swing.JSpinner" binding="spinnerSpeed">
<constraints>
<grid row="0" column="1" 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>
<component id="76346" class="javax.swing.JSpinner" binding="spinnerWeight">
<constraints>
<grid row="1" column="1" 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>
<component id="f3384" class="javax.swing.JLabel">
<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="28dee" class="javax.swing.JLabel">
<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>
</children>
</grid>
<vspacer id="15d55">
<constraints>
<grid row="0" 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="7ab15" 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="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="add02" 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"/>
</constraints>
<properties/>
<border type="line"/>
<children>
<component id="30e35" class="javax.swing.JLabel" binding="labelBase">
<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>
<font size="16"/>
<horizontalAlignment value="0"/>
<horizontalTextPosition value="0"/>
<text value="Простой"/>
</properties>
</component>
</children>
</grid>
<grid id="28265" 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"/>
</constraints>
<properties/>
<border type="line"/>
<children>
<component id="72db3" class="javax.swing.JLabel" binding="labelAdvanced">
<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>
<font size="16"/>
<horizontalAlignment value="0"/>
<horizontalTextPosition value="0"/>
<text value="Продвинутый"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<grid id="12688" layout-manager="GridLayoutManager" row-count="2" 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="2" 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/>
<border type="none"/>
<children>
<component id="e5986" class="javax.swing.JCheckBox" binding="checkboxDopWings">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Дополнительные крылья"/>
</properties>
</component>
<component id="cfe9b" class="javax.swing.JCheckBox" binding="checkboxRockets">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="ракеты"/>
</properties>
</component>
</children>
</grid>
<vspacer id="18b96">
<constraints>
<grid row="3" 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>
</children>
</grid>
<grid id="6e579" layout-manager="GridLayoutManager" row-count="2" 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"/>
</constraints>
<properties/>
<border type="none" title="Параметры двигателей"/>
<children>
<grid id="b79df" 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="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="8c10b" class="javax.swing.JLabel">
<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="609e1" class="javax.swing.JSpinner" binding="spinnerEnginesCount">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<maximum-size width="100" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
</children>
</grid>
<grid id="83f65" 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="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"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="28e30" 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"/>
</constraints>
<properties/>
<border type="line"/>
<children>
<component id="f884f" class="javax.swing.JLabel" binding="labelTruncatedEngine">
<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>
<font size="16"/>
<horizontalAlignment value="0"/>
<text value="Усеченный"/>
</properties>
</component>
</children>
</grid>
<grid id="96986" 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"/>
</constraints>
<properties/>
<border type="line"/>
<children>
<component id="492da" class="javax.swing.JLabel" binding="labelWavyEngine">
<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>
<font size="16"/>
<horizontalAlignment value="0"/>
<text value="Волнистый"/>
</properties>
</component>
</children>
</grid>
<grid id="5bd24" 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"/>
</constraints>
<properties/>
<border type="line"/>
<children>
<component id="43319" class="javax.swing.JLabel" binding="labelBaseEngine">
<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>
<font size="16"/>
<horizontalAlignment value="0"/>
<text value="Простой"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</children>
</grid>
</children>
</grid>
</children>
</grid>
<grid id="1e193" layout-manager="GridLayoutManager" row-count="3" 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="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="300" height="-1"/>
</grid>
</constraints>
<properties/>
<border type="none" title="Превью"/>
<children>
<grid id="c4ea7" 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="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="b8c0b" binding="panelBaseColor" 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="-1" height="50"/>
<maximum-size width="-1" height="50"/>
</grid>
</constraints>
<properties/>
<border type="line"/>
<children>
<component id="b477" class="javax.swing.JLabel">
<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>
<font size="16"/>
<horizontalAlignment value="0"/>
<text value="Цвет"/>
</properties>
</component>
</children>
</grid>
<grid id="e2d48" binding="panelDopColor" 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="-1" height="50"/>
<maximum-size width="-1" height="50"/>
</grid>
</constraints>
<properties/>
<border type="line"/>
<children>
<component id="13ad3" class="javax.swing.JLabel">
<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>
<font size="16"/>
<horizontalAlignment value="0"/>
<text value="Доп. цвет"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<grid id="74d53" binding="panelDraw" layout-manager="CardLayout" hgap="0" vgap="0">
<constraints>
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="-1" height="300"/>
</grid>
</constraints>
<properties/>
<border type="line"/>
<children/>
</grid>
<component id="14b28" class="javax.swing.JButton" binding="buttonAdd">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Добавить"/>
</properties>
</component>
<component id="7f448" class="javax.swing.JButton" binding="buttonCancel">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Отмена"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>

171
FormAircraftConfig.java Normal file
View File

@ -0,0 +1,171 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.function.Consumer;
public class FormAircraftConfig implements Form {
private JPanel mainPane;
private JSpinner spinnerSpeed;
private JSpinner spinnerWeight;
private JPanel colorsPane;
private JCheckBox checkboxDopWings;
private JCheckBox checkboxRockets;
private JSpinner spinnerEnginesCount;
private JButton buttonAdd;
private JButton buttonCancel;
private JPanel panelRed;
private JPanel panelYellow;
private JPanel panelGreen;
private JPanel panelBlue;
private JPanel panelWhite;
private JPanel panelGray;
private JPanel panelBlack;
private JPanel panelPurple;
private JPanel panelBaseColor;
private JPanel panelDopColor;
private JPanel panelDraw;
private JLabel labelBase;
private JLabel labelAdvanced;
private JLabel labelTruncatedEngine;
private JLabel labelWavyEngine;
private JLabel labelBaseEngine;
private JFrame jframe = getFrame();
private DrawingAircraft aircraft;
private boolean isMousePressed = false;
private Canvas canv = new Canvas(this);
private ArrayList<Consumer<DrawingAircraft>> listeners = new ArrayList<>();
private JFrame getFrame() {
JFrame frame = new JFrame();
frame.setVisible(true);
frame.setBounds(300, 100, 800, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
return frame;
}
public void addListener(Consumer<DrawingAircraft> l) {
listeners.add(l);
}
public void run() {
jframe.add(mainPane);
panelDraw.add(canv);
buttonAdd.addActionListener(e -> {
jframe.dispose();
for(var l : listeners) l.accept(aircraft);
});
buttonCancel.addActionListener(e -> jframe.dispose());
MouseAdapter mouseHandler = new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
super.mouseEntered(e);
jframe.setCursor(new Cursor(Cursor.HAND_CURSOR));
}
@Override
public void mouseExited(MouseEvent e) {
super.mouseExited(e);
if(!isMousePressed) jframe.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
@Override
public void mousePressed(MouseEvent e) {
super.mousePressed(e);
isMousePressed = true;
jframe.setCursor(new Cursor(Cursor.HAND_CURSOR));
}
@Override
public void mouseReleased(MouseEvent e) {
super.mouseReleased(e);
isMousePressed = false;
jframe.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
drop((JComponent) e.getSource());
canv.repaint();
}
};
spinnerSpeed.setModel(new SpinnerNumberModel(100, 70, 200, 1));
spinnerWeight.setModel(new SpinnerNumberModel(700, 600, 1500, 1));
spinnerEnginesCount.setModel(new SpinnerNumberModel(4, 2, 6, 2));
panelRed.addMouseListener(mouseHandler);
panelYellow.addMouseListener(mouseHandler);
panelGreen.addMouseListener(mouseHandler);
panelBlue.addMouseListener(mouseHandler);
panelWhite.addMouseListener(mouseHandler);
panelGray.addMouseListener(mouseHandler);
panelBlack.addMouseListener(mouseHandler);
panelPurple.addMouseListener(mouseHandler);
labelBase.addMouseListener(mouseHandler);
labelAdvanced.addMouseListener(mouseHandler);
labelTruncatedEngine.addMouseListener(mouseHandler);
labelWavyEngine.addMouseListener(mouseHandler);
labelBaseEngine.addMouseListener(mouseHandler);
}
private void drop(JComponent elem) {
if(elem instanceof JPanel panel) {
if(aircraft == null) return;
if(panelBaseColor.getMousePosition() != null) {
aircraft.setColor(panel.getBackground());
aircraft.getEngines().setColor(panel.getBackground());
}
if(panelDopColor.getMousePosition() != null && aircraft instanceof DrawingModernAircraft advanced) {
advanced.setDopColor(panel.getBackground());
}
}
Point test = panelDraw.getMousePosition();
if(elem instanceof JLabel label && test != null) {
int speed = (int)spinnerSpeed.getValue();
int weight = (int)spinnerWeight.getValue();
int enginesCount = (int)spinnerEnginesCount.getValue();
if(label == labelBase) {
aircraft = new DrawingAircraft(speed, weight, Color.WHITE);
aircraft.SetPosition(20, 40, canv.getWidth(), canv.getHeight());
aircraft.getEngines().setCount(enginesCount);
aircraft.getEngines().setColor(Color.WHITE);
}
if(label == labelAdvanced) {
aircraft = new DrawingModernAircraft(speed, weight, Color.WHITE, Color.BLACK,
checkboxDopWings.isSelected(), checkboxRockets.isSelected());
aircraft.SetPosition(10, 10, canv.getWidth(), canv.getHeight());
aircraft.getEngines().setCount(enginesCount);
aircraft.getEngines().setColor(Color.WHITE);
}
if(aircraft == null) return;
if(label == labelBaseEngine) {
aircraft.setEngines(new DrawingEngines(enginesCount, aircraft.getColor()));
}
if(label == labelTruncatedEngine) {
aircraft.setEngines(new DrawingTruncatedEngines(enginesCount, aircraft.getColor()));
}
if(label == labelWavyEngine) {
aircraft.setEngines(new DrawingWavyEngines(enginesCount, aircraft.getColor()));
}
}
}
@Override
public void Draw(Graphics2D g) {
if(aircraft == null) return;
aircraft.DrawTransport(g);
}
}

View File

@ -114,27 +114,24 @@ public class FormMapWithSetAircrafts implements Form {
return;
}
FormAircraft dialog = new FormAircraft();
dialog.run();
dialog.setSize(800, 500);
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
FormAircraftConfig formConfig = new FormAircraftConfig();
formConfig.run();
dialog.setVisible(true);
formConfig.addListener(drawingAircraft -> {
if(drawingAircraft == null) return;
if (dialog.getSelectedAircraft() == null) return;
DrawingObjectAircraft aircraft = new DrawingObjectAircraft(dialog.getSelectedAircraft());
if (_mapsCollection.getMap(listBoxMaps.getSelectedValue().toString()).addAircraft(aircraft) != -1)
{
JOptionPane.showMessageDialog(jFrame, "Объект добавлен");
img = _mapsCollection.getMap(listBoxMaps.getSelectedValue().toString()).ShowSet();
canv.repaint();
}
else
{
JOptionPane.showMessageDialog(jFrame, "Не удалось добавить объект");
}
DrawingObjectAircraft aircraft = new DrawingObjectAircraft(drawingAircraft);
if (_mapsCollection.getMap(listBoxMaps.getSelectedValue().toString()).addAircraft(aircraft) != -1)
{
JOptionPane.showMessageDialog(jFrame, "Объект добавлен");
img = _mapsCollection.getMap(listBoxMaps.getSelectedValue().toString()).ShowSet();
canv.repaint();
}
else
{
JOptionPane.showMessageDialog(jFrame, "Не удалось добавить объект");
}
});
});
buttonRemoveAircraft.addActionListener(e -> {

View File

@ -2,5 +2,6 @@ import java.awt.*;
public interface IDrawingEngines {
void setCount(int count);
void setColor(Color color);
void draw(Graphics2D g, int x, int y);
}