Zhimolostnova A.V. Hard lab work 5 #10
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_16" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
22
src/Action.java
Normal file
22
src/Action.java
Normal file
@ -0,0 +1,22 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Action<T> {
|
||||
private final ArrayList<Consumer<T>> listeners = new ArrayList<>();
|
||||
|
||||
public void addListener(Consumer<T> listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void emit(T warship) {
|
||||
for (var listener : listeners) {
|
||||
listener.accept(warship);
|
||||
}
|
||||
}
|
||||
}
|
@ -8,6 +8,11 @@ public class DrawingAdvancedWarship extends DrawingWarship {
|
||||
Blocks= GetFormOfBlock(blockForm);
|
||||
Blocks.SetBlockCount(2*(int)(Math.random()*3+1));
|
||||
}
|
||||
public DrawingAdvancedWarship(int speed, float weight,int countblock, Color bodyColor, Color dopColor, boolean Helipad,boolean Antenna, boolean Missile) {
|
||||
super(speed, weight, bodyColor, 120, 50);
|
||||
Warship=new EntityAdvancedWarship(speed,weight,bodyColor,dopColor,Helipad,Antenna,Missile);
|
||||
Blocks.SetBlockCount(countblock);
|
||||
}
|
||||
public DrawingAdvancedWarship(int speed, float weight, Color bodyColor, Color dopColor, boolean Helipad,boolean Antenna, boolean Missile,IDrawingObjectBlock blockForm) {
|
||||
super(speed, weight, bodyColor, 120, 50);
|
||||
Warship=new EntityAdvancedWarship(speed,weight,bodyColor,dopColor,Helipad,Antenna,Missile);
|
||||
@ -17,7 +22,15 @@ public class DrawingAdvancedWarship extends DrawingWarship {
|
||||
super(warship,block);
|
||||
Warship = warship;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SetBodyColor(Color color){
|
||||
var warship=(EntityAdvancedWarship) Warship;
|
||||
Warship=new EntityAdvancedWarship(warship.GetSpeed(),warship.GetWeight(),color,warship.GetDopColor(), warship.GetHelipad(), warship.GetAntenna(), warship.GetMissile());
|
||||
}
|
||||
public void SetDopColor(Color color){
|
||||
var warship=(EntityAdvancedWarship) Warship;
|
||||
Warship=new EntityAdvancedWarship(warship.GetSpeed(),warship.GetWeight(),warship.GetBodyColor(),color, warship.GetHelipad(), warship.GetAntenna(), warship.GetMissile());
|
||||
}
|
||||
@Override
|
||||
public void DrawTransport(Graphics g) {
|
||||
|
||||
|
@ -7,6 +7,9 @@ public class DrawingBlock implements IDrawingObjectBlock{
|
||||
public DrawingBlock(BlockCount block) {
|
||||
_block=block;
|
||||
}
|
||||
public DrawingBlock(int count) {
|
||||
SetBlockCount(count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SetBlockCount(int count){
|
||||
@ -16,6 +19,7 @@ public class DrawingBlock implements IDrawingObjectBlock{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawBlock(Graphics2D g,int _startPosX, int _startPosY) {
|
||||
if (_block.GetBlockCount() >= 2) {
|
||||
|
@ -6,6 +6,9 @@ public class DrawingRoundBlocks implements IDrawingObjectBlock{
|
||||
public DrawingRoundBlocks(BlockCount block){
|
||||
_block=block;
|
||||
}
|
||||
public DrawingRoundBlocks(int count) {
|
||||
SetBlockCount(count);
|
||||
}
|
||||
@Override
|
||||
public void SetBlockCount(int count) {
|
||||
for (BlockCount temp: BlockCount.values())
|
||||
|
@ -6,6 +6,9 @@ public class DrawingTriangleBlocks implements IDrawingObjectBlock{
|
||||
public DrawingTriangleBlocks(BlockCount block){
|
||||
_block=block;
|
||||
}
|
||||
public DrawingTriangleBlocks(int count) {
|
||||
SetBlockCount(count);
|
||||
}
|
||||
@Override
|
||||
public void SetBlockCount(int count) {
|
||||
for (BlockCount temp: BlockCount.values())
|
||||
|
@ -25,11 +25,25 @@ public class DrawingWarship {
|
||||
Warship = new EntityWarship(speed, weight, bodyColor);
|
||||
Blocks= blockForm;
|
||||
}
|
||||
public DrawingWarship(int speed, float weight,int countblock, Color bodyColor)
|
||||
{
|
||||
Warship = new EntityWarship(speed, weight, bodyColor);
|
||||
Blocks= GetFormOfBlock((int)(Math.random()*3+1));
|
||||
Blocks.SetBlockCount(countblock);
|
||||
}
|
||||
public DrawingWarship(EntityWarship warship,IDrawingObjectBlock block){
|
||||
Warship = warship;
|
||||
Blocks = block;
|
||||
}
|
||||
|
||||
public void SetBlocks(IDrawingObjectBlock block){
|
||||
Blocks=block;
|
||||
}
|
||||
|
||||
public void SetBodyColor(Color color){
|
||||
Warship= new EntityWarship(Warship.GetSpeed(), Warship.GetWeight(), color);
|
||||
}
|
||||
|
||||
public IDrawingObjectBlock GetFormOfBlock(int FormOfBlock){
|
||||
BlockForm temp = null;
|
||||
for (BlockForm form:BlockForm.values()) {
|
||||
|
@ -137,22 +137,21 @@ public class FormMapWithSetWarships extends JFrame{
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormCreater dialog=new FormCreater();
|
||||
dialog.setSize(1200,700);
|
||||
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
dialog.setVisible(true);
|
||||
if (dialog.getSelectedWarship()!=null) {
|
||||
DrawingObjectWarship warship = new DrawingObjectWarship(dialog.getSelectedWarship());
|
||||
FormWarshipConfig dialog=new FormWarshipConfig();
|
||||
dialog.addListener(obj -> {
|
||||
if (obj!=null) {
|
||||
DrawingObjectWarship warship = new DrawingObjectWarship(obj);
|
||||
|
||||
if (_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).plus(warship)>=0) {
|
||||
JOptionPane.showMessageDialog(this, "Объект добавлен", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
||||
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet();
|
||||
repaint();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this, "Не удалось добавить объект", "Ошибка",JOptionPane.INFORMATION_MESSAGE);
|
||||
if (_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).plus(warship)>=0) {
|
||||
JOptionPane.showMessageDialog(this, "Объект добавлен", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
||||
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet();
|
||||
repaint();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this, "Не удалось добавить объект", "Ошибка",JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.setVisible(true);
|
||||
});
|
||||
|
||||
ButtonRemoveWarship.addActionListener(e -> {
|
||||
|
328
src/FormWarshipConfig.form
Normal file
328
src/FormWarshipConfig.form
Normal file
@ -0,0 +1,328 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormWarshipConfig">
|
||||
<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="709" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="aa600" 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="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="bevel-lowered" title="Параметры"/>
|
||||
<children>
|
||||
<component id="e68a" class="javax.swing.JLabel" binding="SpeedLabel">
|
||||
<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="1a58c" 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="e34d" class="javax.swing.JLabel" binding="WeightLabel">
|
||||
<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="f70c0" 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="558f5" class="javax.swing.JCheckBox" binding="CheckBoxAntenna">
|
||||
<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="86810" class="javax.swing.JCheckBox" binding="CheckBoxHelipad">
|
||||
<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>
|
||||
<component id="45d13" class="javax.swing.JCheckBox" binding="CheckBoxMissile">
|
||||
<constraints>
|
||||
<grid row="4" 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="5cb60" binding="ColorPanel" 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="5" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="bevel-lowered" title="Цвета"/>
|
||||
<children>
|
||||
<grid id="8627c" binding="RedPanel" 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="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="60" height="24"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-65536"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="a4fe8" binding="OrangePanel" 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">
|
||||
<preferred-size width="60" height="24"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-35072"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="cec8c" binding="YellowPanel" 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">
|
||||
<preferred-size width="60" height="24"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-1536"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="d0a7" binding="CianPanel" 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">
|
||||
<preferred-size width="60" height="24"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-16711687"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="ef34" binding="PinkPanel" 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="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="60" height="24"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-65327"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="b9f70" binding="GreenPanel" 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">
|
||||
<preferred-size width="60" height="24"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-15859968"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="a648b" binding="BluePanel" 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="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="60" height="24"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-16767489"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="9a3a" binding="GrayPanel" 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">
|
||||
<preferred-size width="60" height="24"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-8814719"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="b1cf4" class="javax.swing.JLabel" binding="BaseWarshipLabel">
|
||||
<constraints>
|
||||
<grid row="5" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-1247489"/>
|
||||
<requestFocusEnabled value="false"/>
|
||||
<text value="Обычный корабль"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="86067" class="javax.swing.JLabel" binding="AdvancedWarshipLabel">
|
||||
<constraints>
|
||||
<grid row="5" column="3" 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>
|
||||
<grid id="f4894" 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="bevel-lowered" title="Ящики"/>
|
||||
<children>
|
||||
<component id="4f296" class="javax.swing.JLabel" binding="CountBlockLabel">
|
||||
<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="c34e2" class="javax.swing.JSpinner" binding="SpinnerBlock">
|
||||
<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>
|
||||
<requestFocusEnabled value="true"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="d475" binding="TypeBlock" 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="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="bevel-lowered" title="Форма ящиков"/>
|
||||
<children>
|
||||
<component id="43b49" class="javax.swing.JLabel" binding="RoundBlockLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="68" height="16"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Круглые"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c2216" class="javax.swing.JLabel" binding="TriangleBlockLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="1" 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="405bd" class="javax.swing.JLabel" binding="SquareBlockLabel">
|
||||
<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>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="10355" binding="PreviewPanel" 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="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="bevel-lowered" title="Предварительный просмотр"/>
|
||||
<children>
|
||||
<component id="5be86" class="javax.swing.JLabel" binding="BodyColorLabel">
|
||||
<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">
|
||||
<preferred-size width="74" height="49"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Цвет корпуса"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b5fda" class="javax.swing.JLabel" binding="DopColorLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="107" height="49"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Цвет модификаций"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="e8c69" binding="PictureBox" 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="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="200" height="200"/>
|
||||
<preferred-size width="200" height="251"/>
|
||||
<maximum-size width="200" height="200"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="bevel-lowered" title="Корабль"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<component id="687fc" 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="47914" 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>
|
151
src/FormWarshipConfig.java
Normal file
151
src/FormWarshipConfig.java
Normal file
@ -0,0 +1,151 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class FormWarshipConfig extends JFrame {
|
||||
private final Action<DrawingWarship> event = new Action<>();
|
||||
private DrawingWarship warship;
|
||||
BlockCount block;
|
||||
private IDrawingObjectBlock _block=null;
|
||||
private JPanel MainPanel;
|
||||
private JPanel GroupBoxConfig;
|
||||
private JSpinner SpinnerSpeed;
|
||||
private JSpinner SpinnerWeight;
|
||||
private JCheckBox CheckBoxAntenna;
|
||||
private JCheckBox CheckBoxHelipad;
|
||||
private JCheckBox CheckBoxMissile;
|
||||
private JLabel SpeedLabel;
|
||||
private JLabel WeightLabel;
|
||||
private JPanel ColorPanel;
|
||||
private JPanel RedPanel;
|
||||
private JPanel OrangePanel;
|
||||
private JPanel GreenPanel;
|
||||
private JPanel BluePanel;
|
||||
private JPanel YellowPanel;
|
||||
private JPanel CianPanel;
|
||||
private JPanel PinkPanel;
|
||||
private JPanel GrayPanel;
|
||||
private JLabel CountBlockLabel;
|
||||
private JSpinner SpinnerBlock;
|
||||
private JPanel TypeBlock;
|
||||
private JLabel SquareBlockLabel;
|
||||
private JLabel TriangleBlockLabel;
|
||||
private JLabel RoundBlockLabel;
|
||||
private JPanel PreviewPanel;
|
||||
private JLabel BodyColorLabel;
|
||||
private JLabel DopColorLabel;
|
||||
private JLabel BaseWarshipLabel;
|
||||
private JLabel AdvancedWarshipLabel;
|
||||
private JButton ButtonAdd;
|
||||
private JButton ButtonCancel;
|
||||
private JPanel PictureBox;
|
||||
|
||||
public FormWarshipConfig(){
|
||||
this.setTitle("Создание объекта");
|
||||
this.setSize(900,500);
|
||||
this.setContentPane(MainPanel);
|
||||
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
|
||||
SquareBlockLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||
TriangleBlockLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||
RoundBlockLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||
BodyColorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||
DopColorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||
BaseWarshipLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||
AdvancedWarshipLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||
|
||||
SpinnerBlock.setModel(new SpinnerNumberModel(2, 2, 6, 2));
|
||||
SpinnerSpeed.setModel(new SpinnerNumberModel(100, 100, 1000, 10));
|
||||
SpinnerSpeed.setModel(new SpinnerNumberModel(10000, 10000, 20000, 100));
|
||||
|
||||
var dragAdapter = new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
super.mouseReleased(e);
|
||||
setCursor(new Cursor(Cursor.HAND_CURSOR));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
super.mouseReleased(e);
|
||||
dispatchDrop((JComponent) e.getSource());
|
||||
}
|
||||
};
|
||||
|
||||
RedPanel.addMouseListener(dragAdapter);
|
||||
GreenPanel.addMouseListener(dragAdapter);
|
||||
BluePanel.addMouseListener(dragAdapter);
|
||||
YellowPanel.addMouseListener(dragAdapter);
|
||||
OrangePanel.addMouseListener(dragAdapter);
|
||||
GrayPanel.addMouseListener(dragAdapter);
|
||||
CianPanel.addMouseListener(dragAdapter);
|
||||
PinkPanel.addMouseListener(dragAdapter);
|
||||
|
||||
BaseWarshipLabel.addMouseListener(dragAdapter);
|
||||
AdvancedWarshipLabel.addMouseListener(dragAdapter);
|
||||
SquareBlockLabel.addMouseListener(dragAdapter);
|
||||
TriangleBlockLabel.addMouseListener(dragAdapter);
|
||||
RoundBlockLabel.addMouseListener(dragAdapter);
|
||||
|
||||
ButtonAdd.addActionListener(e -> {
|
||||
event.emit(warship);
|
||||
dispose();
|
||||
});
|
||||
ButtonCancel.addActionListener(e -> dispose());
|
||||
}
|
||||
|
||||
public void addListener(Consumer<DrawingWarship> listener) {
|
||||
event.addListener(listener);
|
||||
}
|
||||
|
||||
public void dispatchDrop(JComponent droppedComponent) {
|
||||
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
if (droppedComponent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (droppedComponent instanceof JPanel panel) {
|
||||
if (BodyColorLabel.getMousePosition() != null) {
|
||||
warship.SetBodyColor(panel.getBackground());
|
||||
}
|
||||
if (DopColorLabel.getMousePosition() != null && warship instanceof DrawingAdvancedWarship advanced) {
|
||||
advanced.SetDopColor(panel.getBackground());
|
||||
}
|
||||
}
|
||||
if (droppedComponent instanceof JLabel label && PictureBox.getMousePosition() != null) {
|
||||
int speed = (Integer) SpinnerSpeed.getValue();
|
||||
int weight = (Integer) SpinnerWeight.getValue();
|
||||
int countBlock = (Integer) SpinnerBlock.getValue();
|
||||
boolean antenna = CheckBoxAntenna.isSelected();
|
||||
boolean helipad = CheckBoxHelipad.isSelected();
|
||||
boolean missile = CheckBoxMissile.isSelected();
|
||||
|
||||
if (label == BaseWarshipLabel) {
|
||||
warship = new DrawingWarship(speed, weight, countBlock,Color.WHITE);
|
||||
} else if (label == AdvancedWarshipLabel) {
|
||||
warship = new DrawingAdvancedWarship(speed, weight,countBlock, Color.WHITE, Color.WHITE, helipad, antenna,missile);
|
||||
} else if (warship != null && label == SquareBlockLabel) {
|
||||
warship.SetBlocks(new DrawingBlock(countBlock));
|
||||
} else if (warship != null && label == TriangleBlockLabel) {
|
||||
warship.SetBlocks(new DrawingTriangleBlocks(countBlock));
|
||||
} else if (warship != null && label == RoundBlockLabel) {
|
||||
warship.SetBlocks(new DrawingRoundBlocks(countBlock));
|
||||
}
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
if (warship != null) {
|
||||
g = PictureBox.getGraphics();
|
||||
warship.SetPosition(10, 10, PictureBox.getWidth(), PictureBox.getHeight());
|
||||
warship.DrawTransport((Graphics2D) g);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user