5 лабораторная
This commit is contained in:
parent
2b42c1f143
commit
d9307ecac7
@ -1,11 +1,12 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingAircraftCarrier extends DrawingWarship{
|
||||
|
||||
public DrawingAircraftCarrier(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean cabin, boolean superEngine)
|
||||
private Color dopColor;
|
||||
public DrawingAircraftCarrier(int speed, float weight, Color bodyColor, Color dopColor, int blocks, boolean bodyKit, boolean cabin, boolean superEngine)
|
||||
{
|
||||
super(speed, weight, bodyColor, 114, 40);
|
||||
super(speed, weight, bodyColor, blocks, 114, 40);
|
||||
Warship = new EntityAircraftCarrier(speed, weight, bodyColor, dopColor, bodyKit, cabin, superEngine);
|
||||
this.dopColor = dopColor;
|
||||
}
|
||||
|
||||
public DrawingAircraftCarrier(EntityWarship warship, IDrawingObjectBlock additionalObject) {
|
||||
@ -13,8 +14,21 @@ public class DrawingAircraftCarrier extends DrawingWarship{
|
||||
Warship = warship;
|
||||
}
|
||||
|
||||
public void SetDopColor(Color color) {
|
||||
var temp = (EntityAircraftCarrier) Warship;
|
||||
Warship = new EntityAircraftCarrier(temp.GetSpeed(), temp.GetWeight(), temp.GetBodyColor(), color, temp.GetBodyKit(), temp.GetCabin(), temp.GetSuperEngine());
|
||||
dopColor = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawTransport(Graphics gr){
|
||||
public void SetColor(Color color) {
|
||||
var temp = (EntityAircraftCarrier) Warship;
|
||||
dopColor = dopColor==null ? Color.WHITE : dopColor;
|
||||
Warship = new EntityAircraftCarrier(temp.GetSpeed(), temp.GetWeight(), color, dopColor, temp.GetBodyKit(), temp.GetCabin(), temp.GetSuperEngine());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics gr){
|
||||
if(!(Warship instanceof EntityAircraftCarrier))
|
||||
{
|
||||
return;
|
||||
@ -64,7 +78,7 @@ public class DrawingAircraftCarrier extends DrawingWarship{
|
||||
g2.drawOval(_startPosX, _startPosY + 30, 10, 10);
|
||||
}
|
||||
|
||||
super.DrawTransport(g2);
|
||||
super.paintComponent(gr);
|
||||
|
||||
if (aircraftCarrier.GetCabin())
|
||||
{
|
||||
@ -83,5 +97,6 @@ public class DrawingAircraftCarrier extends DrawingWarship{
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRect(_startPosX + 85, _startPosY + 13, 10, 14);
|
||||
}
|
||||
super.repaint();
|
||||
}
|
||||
}
|
@ -30,7 +30,7 @@ public class DrawingObjectWarship implements IDrawingObject {
|
||||
|
||||
@Override
|
||||
public void DrawingObject(Graphics g) {
|
||||
_warship.DrawTransport(g);
|
||||
_warship.paintComponent(g);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,7 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
public class DrawingWarship {
|
||||
public class DrawingWarship extends JComponent {
|
||||
protected EntityWarship Warship;
|
||||
public EntityWarship GetWarship(){return Warship;}
|
||||
protected IDrawingObjectBlock Blocks;
|
||||
@ -15,18 +16,26 @@ public class DrawingWarship {
|
||||
private int _warshipWidth = 114;
|
||||
private int _warshipHeight = 40;
|
||||
|
||||
public DrawingWarship(int speed, float weight, Color bodyColor, int blockForm)
|
||||
public DrawingWarship(int speed, float weight, Color bodyColor, int blockCount)
|
||||
{
|
||||
Warship = new EntityWarship(speed, weight, bodyColor);
|
||||
Blocks = GetFormOfBlock(blockForm);
|
||||
Blocks.SetBlockCount(BlockRandom());
|
||||
Random rnd = new Random();
|
||||
int randomForm = rnd.nextInt(3);
|
||||
if(randomForm == 0){
|
||||
Blocks = new DrawingBlocks(_block);
|
||||
}
|
||||
else if(randomForm == 1){
|
||||
Blocks = new DrawingRoundBlocks(_block);
|
||||
}
|
||||
else Blocks = new DrawingRoundRectangleBlocks(_block);
|
||||
Blocks.SetBlockCount(blockCount);
|
||||
}
|
||||
|
||||
protected DrawingWarship(int speed, float weight, Color bodyColor, int warshipWidth, int warshipHeight)
|
||||
protected DrawingWarship(int speed, float weight, Color bodyColor, int blocksCount, int warshipWidth, int warshipHeight)
|
||||
{
|
||||
Warship = new EntityWarship(speed, weight, bodyColor);
|
||||
Blocks = new DrawingBlocks(_block);
|
||||
Blocks.SetBlockCount(BlockRandom());
|
||||
Blocks.SetBlockCount(blocksCount);
|
||||
_warshipWidth = warshipWidth;
|
||||
_warshipHeight = warshipHeight;
|
||||
}
|
||||
@ -36,6 +45,15 @@ public class DrawingWarship {
|
||||
Blocks = block;
|
||||
}
|
||||
|
||||
public void SetBlocks(int blocksCount, IDrawingObjectBlock blocks){
|
||||
Blocks = blocks;
|
||||
Blocks.SetBlockCount(blocksCount);
|
||||
}
|
||||
|
||||
public void SetColor(Color color){
|
||||
Warship = new EntityWarship(Warship.GetSpeed(), Warship.GetWeight(), color);
|
||||
}
|
||||
|
||||
public int BlockRandom(){
|
||||
Random rnd = new Random();
|
||||
int count = rnd.nextInt(0,3);
|
||||
@ -45,27 +63,6 @@ public class DrawingWarship {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public IDrawingObjectBlock GetFormOfBlock(int FormOfBlock){
|
||||
BlockForm temp = null;
|
||||
for (BlockForm form:BlockForm.values()) {
|
||||
if(form.Value==FormOfBlock){
|
||||
temp = form;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(temp==null)
|
||||
return null;
|
||||
switch (temp){
|
||||
case Rect:
|
||||
return new DrawingBlocks(_block);
|
||||
case Round:
|
||||
return new DrawingRoundBlocks(_block);
|
||||
case RoundRectangle:
|
||||
return new DrawingRoundRectangleBlocks(_block);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
if (width >= x + _warshipWidth && height >= y + _warshipHeight && x >= 0 && y >= 0)
|
||||
@ -116,7 +113,8 @@ public class DrawingWarship {
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics gr){
|
||||
public void paintComponent(Graphics gr){
|
||||
super.paintComponent(gr);
|
||||
if (_startPosX < 0 || _startPosY < 0 || _pictureHeight == null || _pictureWidth == null)
|
||||
{
|
||||
return;
|
||||
@ -152,6 +150,7 @@ public class DrawingWarship {
|
||||
|
||||
//блоки
|
||||
Blocks.DrawBlocks(g2,_startPosX, _startPosY);
|
||||
super.repaint();
|
||||
}
|
||||
|
||||
public void ChangeBorders(int width, int height)
|
||||
|
@ -3,6 +3,7 @@ import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.HashMap;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class FormMapWithSetWarships extends JFrame{
|
||||
private JPanel mainPanel;
|
||||
@ -132,27 +133,25 @@ public class FormMapWithSetWarships extends JFrame{
|
||||
});
|
||||
|
||||
ButtonAddWarship.addActionListener(e -> {
|
||||
if(ListBoxMaps.getSelectedIndex() == -1){
|
||||
return;
|
||||
}
|
||||
FormWarshipCreator warshipCreator = new FormWarshipCreator();
|
||||
warshipCreator.setSize(1200,700);
|
||||
warshipCreator.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
|
||||
warshipCreator.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
warshipCreator.setVisible(true);
|
||||
if (warshipCreator.getSelectedWarship() != null) {
|
||||
DrawingObjectWarship warship = new DrawingObjectWarship(warshipCreator.getSelectedWarship());
|
||||
|
||||
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);
|
||||
FormWarshipConfig formWarshipConfig = new FormWarshipConfig();
|
||||
formWarshipConfig.AddEvent(newWarship ->{
|
||||
if(ListBoxMaps.getSelectedIndex() == -1){
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(newWarship != null){
|
||||
DrawingObjectWarship warship = new DrawingObjectWarship(newWarship);
|
||||
if (_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).Plus(warship) >= 0) {
|
||||
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
||||
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet();
|
||||
repaint();
|
||||
}
|
||||
else {
|
||||
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
});
|
||||
formWarshipConfig.setSize(1000, 450);
|
||||
formWarshipConfig.setVisible(true);
|
||||
});
|
||||
|
||||
ButtonRemoveWarship.addActionListener(e -> {
|
||||
|
@ -40,7 +40,7 @@ public class FormWarship extends JDialog {
|
||||
Graphics2D graphics = (Graphics2D) drawPanel.getGraphics();
|
||||
graphics.clearRect(0, 0, drawPanel.getWidth(), drawPanel.getHeight());
|
||||
drawPanel.paintComponents(graphics);
|
||||
_warship.DrawTransport(graphics);
|
||||
_warship.paintComponent(graphics);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,7 +49,7 @@ public class FormWarship extends JDialog {
|
||||
|
||||
if (_warship != null) {
|
||||
mainPanel.paintComponents(mainPanel.getGraphics());
|
||||
_warship.DrawTransport(g);
|
||||
_warship.paintComponent(g);
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ public class FormWarship extends JDialog {
|
||||
Random rnd = new Random();
|
||||
_warship = new DrawingAircraftCarrier(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), BlockRandom(),
|
||||
rnd.nextBoolean(), rnd.nextBoolean(), rnd.nextBoolean());
|
||||
SetData();
|
||||
Draw();
|
||||
@ -137,4 +137,13 @@ public class FormWarship extends JDialog {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public int BlockRandom(){
|
||||
Random rnd = new Random();
|
||||
int count = rnd.nextInt(0,3);
|
||||
if(count == 0) return 2;
|
||||
if(count == 1) return 4;
|
||||
if(count == 2) return 6;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
372
src/FormWarshipConfig.form
Normal file
372
src/FormWarshipConfig.form
Normal file
@ -0,0 +1,372 @@
|
||||
<?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="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="984" height="533"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="19d1e" binding="groupBoxConfig" layout-manager="GridLayoutManager" row-count="12" 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>
|
||||
<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="ada62" class="javax.swing.JLabel" binding="labelSpeed">
|
||||
<constraints>
|
||||
<grid row="2" 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="Speed"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="be9ce" class="javax.swing.JLabel" binding="labelWeight">
|
||||
<constraints>
|
||||
<grid row="3" 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="Weight"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="9c57c" class="javax.swing.JCheckBox" binding="checkBoxBodyKit">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="3" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Sign of a side platform"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="c9236" binding="groupBoxColors" layout-manager="GridLayoutManager" row-count="3" 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="2" column="2" row-span="7" 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 id="8803" 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="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-65536"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="474b9" 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="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="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-16753150"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="cbdc6" 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="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="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-16776999"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="8795d" binding="whitePanel" 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="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-1181441"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="8f241" 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="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="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-11776175"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="a4633" binding="blackPanel" 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="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-16777216"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="d67c9" 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="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="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-1024"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="c75ea" binding="purplePanel" 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="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-11009884"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<component id="48949" class="javax.swing.JLabel" binding="labelSimpleObject">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="100" height="20"/>
|
||||
<preferred-size width="100" height="20"/>
|
||||
<maximum-size width="100" height="20"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Simple"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="27b7d" class="javax.swing.JLabel" binding="labelModifiedObject">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="100" height="20"/>
|
||||
<preferred-size width="100" height="20"/>
|
||||
<maximum-size width="100" height="20"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Modified"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<hspacer id="a1a59">
|
||||
<constraints>
|
||||
<grid row="9" column="2" row-span="1" col-span="3" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="1f2e0" class="javax.swing.JCheckBox" binding="checkBoxSuperEngine">
|
||||
<constraints>
|
||||
<grid row="8" column="0" row-span="2" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Sign of super engine"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="73317" class="javax.swing.JSpinner" binding="speedSpinner">
|
||||
<constraints>
|
||||
<grid row="2" 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="a9d95" class="javax.swing.JSpinner" binding="weightSpinner">
|
||||
<constraints>
|
||||
<grid row="3" 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="fa2f1" class="javax.swing.JLabel" binding="paramLabel">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Settings"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="1792" class="javax.swing.JLabel" binding="colorLabel">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Colors"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c7b6d" class="javax.swing.JSpinner" binding="blocksSpinner">
|
||||
<constraints>
|
||||
<grid row="10" 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="b107c" class="javax.swing.JLabel" binding="labelBlocks">
|
||||
<constraints>
|
||||
<grid row="10" 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="Blocks"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="48680" class="javax.swing.JLabel" binding="labelRectangleBlocks">
|
||||
<constraints>
|
||||
<grid row="10" 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>
|
||||
<text value="Rectangle"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c6b0e" class="javax.swing.JLabel" binding="labelRoundRectangleBLocks">
|
||||
<constraints>
|
||||
<grid row="10" column="4" 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="RoundRectangle"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="fce3e" class="javax.swing.JLabel" binding="labelRoundBlocks">
|
||||
<constraints>
|
||||
<grid row="10" 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="Round"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="a34d0">
|
||||
<constraints>
|
||||
<grid row="11" column="0" row-span="1" col-span="5" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<vspacer id="4e2b9">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="5" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="4ecc1" class="javax.swing.JCheckBox" binding="checkBoxCabin">
|
||||
<constraints>
|
||||
<grid row="7" 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="Sign of cabin"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="b39ac" binding="panelObject" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="8cde0" binding="pictureBox" 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">
|
||||
<minimum-size width="300" height="300"/>
|
||||
<preferred-size width="300" height="300"/>
|
||||
<maximum-size width="300" height="300"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<component id="81f02" 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="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="70" height="30"/>
|
||||
<preferred-size width="70" height="30"/>
|
||||
<maximum-size width="70" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Color"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="d1a3b" class="javax.swing.JLabel" binding="labelDopColor">
|
||||
<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">
|
||||
<minimum-size width="70" height="30"/>
|
||||
<preferred-size width="70" height="30"/>
|
||||
<maximum-size width="70" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="DopColor"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="5b8b0" class="javax.swing.JLabel" binding="labelSetBlocks">
|
||||
<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">
|
||||
<minimum-size width="70" height="30"/>
|
||||
<preferred-size width="70" height="30"/>
|
||||
<maximum-size width="70" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Blocks"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="940fd" 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="Add"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="bb5c5" class="javax.swing.JButton" binding="buttonCancel">
|
||||
<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"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Delete"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
175
src/FormWarshipConfig.java
Normal file
175
src/FormWarshipConfig.java
Normal file
@ -0,0 +1,175 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class FormWarshipConfig extends JFrame {
|
||||
private JPanel mainPanel;
|
||||
private JPanel groupBoxConfig;
|
||||
private JLabel labelSpeed;
|
||||
private JLabel labelWeight;
|
||||
private JCheckBox checkBoxBodyKit;
|
||||
private JPanel groupBoxColors;
|
||||
private JPanel redPanel;
|
||||
private JPanel greenPanel;
|
||||
private JPanel bluePanel;
|
||||
private JPanel whitePanel;
|
||||
private JPanel grayPanel;
|
||||
private JPanel blackPanel;
|
||||
private JPanel yellowPanel;
|
||||
private JPanel purplePanel;
|
||||
private JLabel labelSimpleObject;
|
||||
private JLabel labelModifiedObject;
|
||||
private JCheckBox checkBoxSuperEngine;
|
||||
private JSpinner speedSpinner;
|
||||
private JSpinner weightSpinner;
|
||||
private JLabel paramLabel;
|
||||
private JLabel colorLabel;
|
||||
private JSpinner blocksSpinner;
|
||||
private JLabel labelBlocks;
|
||||
private JLabel labelRectangleBlocks;
|
||||
private JLabel labelRoundRectangleBLocks;
|
||||
private JLabel labelRoundBlocks;
|
||||
private JPanel panelObject;
|
||||
private JPanel pictureBox;
|
||||
private JLabel labelBaseColor;
|
||||
private JLabel labelDopColor;
|
||||
private JLabel labelSetBlocks;
|
||||
private JCheckBox checkBoxCabin;
|
||||
private JButton buttonAdd;
|
||||
private JButton buttonCancel;
|
||||
Consumer<DrawingWarship> EventAddWarship;
|
||||
DrawingWarship _warship;
|
||||
BlockCount _blocks;
|
||||
|
||||
public FormWarshipConfig(){
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void AddEvent(Consumer<DrawingWarship> ev) { EventAddWarship = ev; }
|
||||
|
||||
private void InitializeComponent(){
|
||||
setTitle("Warship");
|
||||
setSize(1000, 450);
|
||||
getContentPane().add(mainPanel);
|
||||
|
||||
labelSimpleObject.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||
labelModifiedObject.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||
labelBaseColor.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||
labelDopColor.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||
labelRectangleBlocks.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||
labelRoundBlocks.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||
labelRoundRectangleBLocks.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||
labelSetBlocks.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||
pictureBox.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||
|
||||
speedSpinner.setModel(new SpinnerNumberModel(100, 100, 1000, 1));
|
||||
weightSpinner.setModel(new SpinnerNumberModel(100, 100, 1000, 1));
|
||||
blocksSpinner.setModel(new SpinnerNumberModel(2, 2, 6, 2));
|
||||
|
||||
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));
|
||||
}
|
||||
};
|
||||
|
||||
pictureBox.addMouseListener(defCursor);
|
||||
labelBaseColor.addMouseListener(defCursor);
|
||||
labelDopColor.addMouseListener(defCursor);
|
||||
labelSetBlocks.addMouseListener(defCursor);
|
||||
|
||||
redPanel.addMouseListener(drag);
|
||||
greenPanel.addMouseListener(drag);
|
||||
bluePanel.addMouseListener(drag);
|
||||
yellowPanel.addMouseListener(drag);
|
||||
whitePanel.addMouseListener(drag);
|
||||
grayPanel.addMouseListener(drag);
|
||||
blackPanel.addMouseListener(drag);
|
||||
purplePanel.addMouseListener(drag);
|
||||
|
||||
labelSimpleObject.addMouseListener(drag);
|
||||
labelModifiedObject.addMouseListener(drag);
|
||||
labelRectangleBlocks.addMouseListener(drag);
|
||||
labelRoundBlocks.addMouseListener(drag);
|
||||
labelRoundRectangleBLocks.addMouseListener(drag);
|
||||
|
||||
buttonAdd.addActionListener(e -> {
|
||||
EventAddWarship.accept(_warship);
|
||||
dispose();
|
||||
});
|
||||
|
||||
buttonCancel.addActionListener(e -> dispose());
|
||||
}
|
||||
|
||||
public void Drop(JComponent droppedItem) {
|
||||
if (droppedItem == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (droppedItem instanceof JPanel panel) {
|
||||
if (_warship == null)
|
||||
return;
|
||||
|
||||
//Установка основного цвета
|
||||
if (labelBaseColor.getMousePosition() != null) {
|
||||
_warship.SetColor(panel.getBackground());
|
||||
}
|
||||
//Установка дополнительного цвета
|
||||
if (labelDopColor.getMousePosition() != null && _warship instanceof DrawingAircraftCarrier aircraftCarrier) {
|
||||
aircraftCarrier.SetDopColor(panel.getBackground());
|
||||
}
|
||||
}
|
||||
if (droppedItem instanceof JLabel label && pictureBox.getMousePosition() != null) {
|
||||
int speed = (int)speedSpinner.getValue();
|
||||
int weight = (int)weightSpinner.getValue();
|
||||
int blocks = (int)blocksSpinner.getValue();
|
||||
boolean bodyKit = checkBoxBodyKit.isSelected();
|
||||
boolean cabin = checkBoxCabin.isSelected();
|
||||
boolean superEngine = checkBoxSuperEngine.isSelected();
|
||||
//Обычный объект
|
||||
if (label == labelSimpleObject) {
|
||||
try { pictureBox.remove(_warship); } catch (Exception ex) { }
|
||||
_warship = new DrawingWarship(speed, weight, Color.WHITE, blocks);
|
||||
}
|
||||
//Модифицированный объект
|
||||
else if (label == labelModifiedObject) {
|
||||
try { pictureBox.remove(_warship); } catch (Exception ex) { }
|
||||
_warship = new DrawingAircraftCarrier(speed, weight, Color.WHITE, Color.WHITE, blocks, bodyKit, cabin, superEngine);
|
||||
}
|
||||
|
||||
if (_warship != null) {
|
||||
_warship.SetPosition(pictureBox.getWidth() - 200, pictureBox.getHeight() - 150, pictureBox.getWidth(), pictureBox.getHeight());
|
||||
pictureBox.add(_warship, BorderLayout.CENTER);
|
||||
revalidate();
|
||||
}
|
||||
|
||||
} else if (droppedItem instanceof JLabel label && labelSetBlocks.getMousePosition() != null && _warship != null) {
|
||||
//Квадратные блоки
|
||||
if (label == labelRectangleBlocks) {
|
||||
_warship.SetBlocks((int)blocksSpinner.getValue(), new DrawingBlocks(_blocks));
|
||||
}
|
||||
//Круглые блоки
|
||||
else if (label == labelRoundBlocks) {
|
||||
_warship.SetBlocks((int)blocksSpinner.getValue(), new DrawingRoundBlocks(_blocks));
|
||||
}
|
||||
//Закругленные блоки
|
||||
else if (label == labelRoundRectangleBLocks) {
|
||||
_warship.SetBlocks((int)blocksSpinner.getValue(), new DrawingRoundRectangleBlocks(_blocks));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -37,7 +37,7 @@ public class FormWarshipCreator extends JDialog{
|
||||
super.paint(g);
|
||||
Graphics2D g2d = (Graphics2D) PictureBox.getGraphics();
|
||||
if (_warship != null) {
|
||||
_warship.DrawTransport(g2d);
|
||||
_warship.paintComponents(g2d);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user