lab#5
This commit is contained in:
parent
557d46293b
commit
36f0b0ffc6
@ -2,16 +2,31 @@ import java.awt.*;
|
||||
|
||||
public class DrawingContainerShip extends DrawingShip
|
||||
{
|
||||
public DrawingContainerShip(int speed, float weight, Color bodyColor, Color dopColor, boolean crane, boolean containers)
|
||||
private Color dopColor;
|
||||
public DrawingContainerShip(int speed, float weight, Color bodyColor,int numdeck,Color dopColor,boolean crane,boolean containers)
|
||||
{
|
||||
super(speed,weight,bodyColor,130,45);
|
||||
super(speed,weight,bodyColor,numdeck,130,45);
|
||||
Ship = new EntityContainerShip(speed, weight, bodyColor, dopColor, crane, containers);
|
||||
this.dopColor=dopColor;
|
||||
}
|
||||
protected DrawingContainerShip(EntityShip ship,IAdditionalDrawingObject deck)
|
||||
{
|
||||
super(ship,deck);
|
||||
Ship=ship;
|
||||
}
|
||||
public void SetDopColor(Color color)
|
||||
{
|
||||
var temp = (EntityContainerShip) Ship;
|
||||
Ship=new EntityContainerShip(temp.GetSpeed(),temp.GetWeight(),temp.GetBodyColor(),color,temp.GetCrane(),temp.GetContainers());
|
||||
dopColor=color;
|
||||
}
|
||||
@Override
|
||||
public void SetColor(Color color)
|
||||
{
|
||||
var temp = (EntityContainerShip) Ship;
|
||||
dopColor = dopColor==null? Color.WHITE : dopColor;
|
||||
Ship=new EntityContainerShip(temp.GetSpeed(),temp.GetWeight(),color,dopColor,temp.GetCrane(),temp.GetContainers());
|
||||
}
|
||||
@Override
|
||||
public void DrawTransport(Graphics g) {
|
||||
if (!(GetShip() instanceof EntityContainerShip containerShip))
|
||||
|
@ -13,6 +13,7 @@ public class DrawingObjectShip implements IDrawingObject {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public DrawingShip GetDrawingObjectShip() {
|
||||
return _ship;
|
||||
}
|
||||
|
@ -1,27 +1,27 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
public class DrawingShip extends JPanel {
|
||||
import java.util.Set;
|
||||
|
||||
public class DrawingShip extends JComponent{
|
||||
protected EntityShip Ship;
|
||||
public IAdditionalDrawingObject Deck;
|
||||
public void SetEnum() {
|
||||
Random r = new Random();
|
||||
int numbEnum = r.nextInt(1, 4);
|
||||
Deck.SetAddEnum(numbEnum);
|
||||
}
|
||||
public void SetFormEnum()
|
||||
protected IAdditionalDrawingObject Deck;
|
||||
public void SetColor(Color color)
|
||||
{
|
||||
Random r = new Random();
|
||||
int numbEnum = r.nextInt(1, 4);
|
||||
if (numbEnum == 1) {
|
||||
Deck = new DrawingDeck();
|
||||
}
|
||||
if (numbEnum == 2) {
|
||||
Deck = new DrawingOvalDeck();
|
||||
}
|
||||
if (numbEnum == 3) {
|
||||
Deck=new DrawingTrapezDeck();
|
||||
}
|
||||
Ship=new EntityShip(Ship.GetSpeed(),Ship.GetWeight(),color);
|
||||
}
|
||||
public IAdditionalDrawingObject GetDeck()
|
||||
{
|
||||
return Deck;
|
||||
}
|
||||
public void SetFormEnum(int decksnum,IAdditionalDrawingObject deck)
|
||||
{
|
||||
Deck=deck;
|
||||
Deck.SetAddEnum(decksnum);
|
||||
}
|
||||
public void SetDeck(IAdditionalDrawingObject deck)
|
||||
{
|
||||
Deck=deck;
|
||||
}
|
||||
public EntityShip GetShip() {
|
||||
return Ship;
|
||||
@ -32,14 +32,25 @@ public class DrawingShip extends JPanel {
|
||||
private Integer _pictureHeight = null;
|
||||
private int _shipWidth = 100;
|
||||
private int _shipHeight = 60;
|
||||
public DrawingShip(int speed, float weight, Color bodycolor) {
|
||||
public DrawingShip(int speed, float weight, Color bodycolor,int numdeck) {
|
||||
Ship = new EntityShip(speed, weight, bodycolor);
|
||||
SetFormEnum();
|
||||
SetEnum();
|
||||
Deck = new DrawingTrapezDeck();
|
||||
Random r = new Random();
|
||||
int numbEnum = r.nextInt(1, 4);
|
||||
if (numbEnum == 1) {
|
||||
Deck=new DrawingDeck();
|
||||
}
|
||||
if (numbEnum == 2) {
|
||||
Deck = new DrawingOvalDeck();
|
||||
}
|
||||
if (numbEnum == 3) {
|
||||
Deck = new DrawingTrapezDeck();
|
||||
}
|
||||
Deck.SetAddEnum(numdeck);
|
||||
}
|
||||
public DrawingShip(int speed,float weight,Color bodyColor,int shipWidth,int shipHeight)
|
||||
public DrawingShip(int speed,float weight,Color bodyColor,int numdeck,int shipWidth,int shipHeight)
|
||||
{
|
||||
this(speed,weight,bodyColor);
|
||||
this(speed,weight,bodyColor, numdeck);
|
||||
_shipWidth = shipWidth;
|
||||
_shipHeight = shipHeight;
|
||||
}
|
||||
|
@ -24,9 +24,9 @@ public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
private JButton ButtonRight;
|
||||
private JTextField maskedTextBoxPosition;
|
||||
private JTextField textBoxNewMapName;
|
||||
private int picWidth=600;
|
||||
private final int picWidth=600;
|
||||
|
||||
private int picHeight=400;
|
||||
private final int picHeight=400;
|
||||
private JButton ButtonAddMap;
|
||||
private JList ListBoxMaps;
|
||||
private JButton ButtonDeleteMap;
|
||||
@ -89,24 +89,24 @@ public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
ButtonAddShip.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (ListBoxMaps.getSelectedIndex() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormShip form = new FormShip();
|
||||
form.setSize(1000,700);
|
||||
form.setVisible(true);
|
||||
form.setModal(true);
|
||||
DrawingObjectShip ship = new DrawingObjectShip(form.GetSelectedShip());
|
||||
if(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).Add(ship)!=-1)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,"Объект добавлен");
|
||||
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
|
||||
}
|
||||
FormShipConfig formShipConfig = new FormShipConfig();
|
||||
formShipConfig.AddEvent(newShip -> {
|
||||
if (ListBoxMaps.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
if (newShip != null) {
|
||||
DrawingObjectShip ship = new DrawingObjectShip(newShip);
|
||||
if (_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).Add(ship) != -1) {
|
||||
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
||||
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
formShipConfig.setSize(850, 300);
|
||||
formShipConfig.setVisible(true);
|
||||
}
|
||||
});
|
||||
ListBoxMaps.addListSelectionListener(new ListSelectionListener() {
|
||||
|
@ -28,6 +28,11 @@ public class FormShip extends JDialog{
|
||||
{
|
||||
return SelectedShip;
|
||||
}
|
||||
public int SetEnum() {
|
||||
Random r = new Random();
|
||||
int numbEnum = r.nextInt(1, 4);
|
||||
return numbEnum;
|
||||
}
|
||||
public void Draw(DrawingShip _ship) {
|
||||
pictureBoxShip.removeAll();
|
||||
BufferedImage bmp = new BufferedImage(pictureBoxShip.getWidth(), pictureBoxShip.getHeight(),BufferedImage.TYPE_INT_RGB);
|
||||
@ -44,7 +49,7 @@ public class FormShip extends JDialog{
|
||||
}
|
||||
validate();
|
||||
}
|
||||
public FormShip(DrawingObjectShip ship)
|
||||
public FormShip(IDrawingObject ship)
|
||||
{
|
||||
super(new Frame("Корабль"));
|
||||
CreateWindow();
|
||||
@ -82,7 +87,7 @@ public class FormShip extends JDialog{
|
||||
public void actionPerformed(ActionEvent e){
|
||||
Random random = new Random();
|
||||
Color colorFirst = JColorChooser.showDialog(null, "Цвет", null);
|
||||
_ship=new DrawingShip(random.nextInt(100, 300), random.nextInt(1000, 2000), colorFirst);
|
||||
_ship=new DrawingShip(random.nextInt(100, 300), random.nextInt(1000, 2000), colorFirst,SetEnum());
|
||||
_ship.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), pictureBoxShip.getWidth(), pictureBoxShip.getHeight());
|
||||
JLabelSpeed.setText("Cкорость: " + _ship.GetShip().GetSpeed() + " ");
|
||||
JLabelWeight.setText("Вес: " + _ship.GetShip().GetWeight() + " ");
|
||||
@ -141,7 +146,7 @@ public class FormShip extends JDialog{
|
||||
Random random = new Random();
|
||||
Color colorFirst = JColorChooser.showDialog(null, "Цвет", null);
|
||||
Color colorSecond = JColorChooser.showDialog(null, "Цвет", null);
|
||||
_ship=new DrawingContainerShip(random.nextInt(100, 300), random.nextInt(1000, 2000), colorFirst,colorSecond,random.nextBoolean(),random.nextBoolean());
|
||||
_ship=new DrawingContainerShip(random.nextInt(100, 300), random.nextInt(1000, 2000), colorFirst,SetEnum(),colorSecond,random.nextBoolean(),random.nextBoolean());
|
||||
_ship.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), pictureBoxShip.getWidth(), pictureBoxShip.getHeight());
|
||||
JLabelSpeed.setText("Cкорость: " + _ship.GetShip().GetSpeed() + " ");
|
||||
JLabelWeight.setText("Вес: " + _ship.GetShip().GetWeight() + " ");
|
||||
|
338
FormShipConfig.form
Normal file
338
FormShipConfig.form
Normal file
@ -0,0 +1,338 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormShipConfig">
|
||||
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="817" height="235"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="a93c3" binding="groupBoxConfig" layout-manager="GridLayoutManager" row-count="6" column-count="7" 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="20c7b" class="javax.swing.JLabel" binding="labelSpeed">
|
||||
<constraints>
|
||||
<grid row="0" 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="Скорость:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="71d6d" class="javax.swing.JLabel" binding="labelWeight">
|
||||
<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="Вес:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="86605" class="javax.swing.JLabel" binding="labelDecks">
|
||||
<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"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Кол-во палуб"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="fafb1" class="javax.swing.JSpinner" binding="numericUpDownWeight">
|
||||
<constraints>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="d10b0" class="javax.swing.JSpinner" binding="numericUpDownSpeed">
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="1d879" class="javax.swing.JCheckBox" binding="checkBoxContainers">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Признак наличия контейнеров"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="260be" class="javax.swing.JCheckBox" binding="checkBoxCrane">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<selected value="false"/>
|
||||
<text value="Признак наличия крана"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="16924" class="javax.swing.JSpinner" binding="numericUpDownDecks">
|
||||
<constraints>
|
||||
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<grid id="84403" binding="groupBoxColors" layout-manager="GridLayoutManager" row-count="2" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="4" row-span="5" 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="d0af" 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="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="50" height="50"/>
|
||||
<preferred-size width="50" height="50"/>
|
||||
<maximum-size width="50" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-65536"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="82d65" 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="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="50" height="50"/>
|
||||
<preferred-size width="50" height="50"/>
|
||||
<maximum-size width="50" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-16776961"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="4dbde" 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="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="50" height="50"/>
|
||||
<preferred-size width="50" height="50"/>
|
||||
<maximum-size width="50" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-1"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="ceff3" binding="PanelYellow" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="50" height="50"/>
|
||||
<preferred-size width="50" height="50"/>
|
||||
<maximum-size width="50" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-256"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="3f75a" 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="0" 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="50" height="50"/>
|
||||
<preferred-size width="50" height="50"/>
|
||||
<maximum-size width="50" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-16777216"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="f0c28" 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="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="50" height="50"/>
|
||||
<preferred-size width="50" height="50"/>
|
||||
<maximum-size width="50" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-16711936"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="a5386" 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="2" 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="50" height="50"/>
|
||||
<preferred-size width="50" height="50"/>
|
||||
<maximum-size width="50" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-8388480"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="6dfcb" binding="PanelCyan" 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="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="50" height="50"/>
|
||||
<preferred-size width="50" height="50"/>
|
||||
<maximum-size width="50" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-16711681"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="f7d3d" class="javax.swing.JLabel" binding="labelOvalDeck">
|
||||
<constraints>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Овальные"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b2419" class="javax.swing.JLabel" binding="labelSimpleDeck">
|
||||
<constraints>
|
||||
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Прямоугольные"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="f794a" class="javax.swing.JLabel" binding="labelTrapezDeck">
|
||||
<constraints>
|
||||
<grid row="5" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Трапецевидные"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="25253" class="javax.swing.JLabel" binding="LabelSimple">
|
||||
<constraints>
|
||||
<grid row="5" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Простой"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="a676a" class="javax.swing.JLabel" binding="LabelModif">
|
||||
<constraints>
|
||||
<grid row="5" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Модифицированный"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="a4b06" binding="groupBoxPicture" 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="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="1ef24" class="javax.swing.JLabel" binding="LabelBaseColor">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="60" height="40"/>
|
||||
<preferred-size width="60" height="40"/>
|
||||
<maximum-size width="60" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<horizontalAlignment value="0"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<text value="Цвет"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="a449a" class="javax.swing.JLabel" binding="LabelDecksForm">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="60" height="40"/>
|
||||
<preferred-size width="60" height="40"/>
|
||||
<maximum-size width="60" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<horizontalAlignment value="0"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<text value="Форма"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="54f48" class="javax.swing.JLabel" binding="LabelDopColor">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="60" height="40"/>
|
||||
<preferred-size width="60" height="40"/>
|
||||
<maximum-size width="60" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<horizontalAlignment value="0"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<text value="Доп. цвет"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="22645">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="1" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<grid id="d89ad" binding="pictureBox" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<hspacer id="5f509">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="838d1" class="javax.swing.JButton" binding="buttonAdd">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Добавить"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="2e1d9" class="javax.swing.JButton" binding="buttonCancel">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Отмена"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
246
FormShipConfig.java
Normal file
246
FormShipConfig.java
Normal file
@ -0,0 +1,246 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class FormShipConfig extends JFrame {
|
||||
public JPanel mainPanel;
|
||||
DrawingShip _ship;
|
||||
Consumer<DrawingShip> EventAddShip;
|
||||
private JPanel groupBoxConfig;
|
||||
private JLabel labelSpeed;
|
||||
private JSpinner numericUpDownSpeed;
|
||||
private JLabel labelWeight;
|
||||
private JSpinner numericUpDownWeight;
|
||||
private JCheckBox checkBoxContainers;
|
||||
private JCheckBox checkBoxCrane;
|
||||
private JPanel groupBoxColors;
|
||||
private JPanel PanelRed;
|
||||
private JPanel PanelBlue;
|
||||
private JPanel PanelWhite;
|
||||
private JPanel PanelYellow;
|
||||
private JPanel PanelBlack;
|
||||
private JPanel PanelGreen;
|
||||
private JPanel PanelPurple;
|
||||
private JPanel PanelCyan;
|
||||
private JLabel LabelSimple;
|
||||
private JLabel LabelModif;
|
||||
private JLabel LabelBaseColor;
|
||||
private JLabel LabelDopColor;
|
||||
private JPanel pictureBox;
|
||||
private JButton buttonAdd;
|
||||
private JButton buttonCancel;
|
||||
private JSpinner numericUpDownDecks;
|
||||
private JLabel labelDecks;
|
||||
private JLabel labelOvalDeck;
|
||||
private JLabel labelTrapezDeck;
|
||||
private JLabel labelSimpleDeck;
|
||||
private JLabel LabelDecksForm;
|
||||
private JPanel groupBoxPicture;
|
||||
Object ObjFDnD = null;
|
||||
Object TargetObjFDnD = null;
|
||||
public FormShipConfig()
|
||||
{
|
||||
super("Корабль");
|
||||
CreateWindow();
|
||||
|
||||
}
|
||||
public void Draw(DrawingShip _ship)
|
||||
{
|
||||
pictureBox.removeAll();
|
||||
BufferedImage bmp = new BufferedImage(pictureBox.getWidth(), pictureBox.getHeight(),BufferedImage.TYPE_INT_RGB);
|
||||
Graphics gr = bmp.getGraphics();
|
||||
gr.setColor(new Color(238, 238, 238));
|
||||
gr.fillRect(0, 0, pictureBox.getWidth(), pictureBox.getHeight());
|
||||
if (_ship != null) {
|
||||
_ship.DrawTransport(gr);
|
||||
JLabel imageOfLoco = new JLabel();
|
||||
imageOfLoco.setPreferredSize(pictureBox.getSize());
|
||||
imageOfLoco.setMinimumSize(new Dimension(1, 1));
|
||||
imageOfLoco.setIcon(new ImageIcon(bmp));
|
||||
pictureBox.add(imageOfLoco,BorderLayout.CENTER);
|
||||
}
|
||||
revalidate();
|
||||
}
|
||||
public void AddEvent(Consumer<DrawingShip> ev){EventAddShip = ev;}
|
||||
public void CreateWindow() {
|
||||
setPreferredSize(new Dimension(720, 200));
|
||||
getContentPane().add(mainPanel);
|
||||
PanelBlack.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
PanelBlue.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
PanelRed.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
PanelYellow.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
PanelCyan.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
PanelPurple.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
PanelWhite.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
PanelGreen.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
LabelSimple.setText("Простой");
|
||||
LabelModif.setText("Модифицированный");
|
||||
LabelSimple.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
LabelModif.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
LabelBaseColor.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
LabelDopColor.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
labelSimpleDeck.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
labelTrapezDeck.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
labelOvalDeck.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
LabelDecksForm.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
numericUpDownSpeed.setModel(new SpinnerNumberModel(100, 100, 1000, 1));
|
||||
numericUpDownWeight.setModel(new SpinnerNumberModel(100, 100, 1000, 1));
|
||||
numericUpDownDecks.setModel(new SpinnerNumberModel(1, 1, 3, 1));
|
||||
MouseAdapter drag = new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
setCursor(new Cursor(Cursor.HAND_CURSOR));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
Drop((JComponent) e.getSource());
|
||||
}
|
||||
};
|
||||
MouseAdapter defCursor = new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
}
|
||||
};
|
||||
AdditDeckDropObject(labelOvalDeck);
|
||||
AdditDeckDropObject(labelSimpleDeck);
|
||||
AdditDeckDropObject(labelTrapezDeck);
|
||||
AdditDeckDropTarget(LabelDecksForm);
|
||||
pictureBox.addMouseListener(defCursor);
|
||||
LabelBaseColor.addMouseListener(defCursor);
|
||||
LabelDopColor.addMouseListener(defCursor);
|
||||
PanelRed.addMouseListener(drag);
|
||||
PanelBlack.addMouseListener(drag);
|
||||
PanelBlue.addMouseListener(drag);
|
||||
PanelYellow.addMouseListener(drag);
|
||||
PanelCyan.addMouseListener(drag);
|
||||
PanelWhite.addMouseListener(drag);
|
||||
PanelPurple.addMouseListener(drag);
|
||||
PanelGreen.addMouseListener(drag);
|
||||
LabelSimple.addMouseListener(drag);
|
||||
LabelModif.addMouseListener(drag);
|
||||
buttonAdd.addActionListener(e -> {
|
||||
EventAddShip.accept(_ship);
|
||||
dispose();
|
||||
});
|
||||
buttonCancel.addActionListener(e -> dispose());
|
||||
}
|
||||
void AdditDeckDropTarget(JComponent obj){
|
||||
obj.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {super.mouseEntered(e);
|
||||
Deck_DragEnter(obj);
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {super.mouseExited(e);
|
||||
DragExit();
|
||||
}
|
||||
});
|
||||
}
|
||||
void AdditDeckDropObject(JComponent obj){
|
||||
obj.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {super.mousePressed(e);
|
||||
Deck_MouseDown(obj);
|
||||
}
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {super.mouseReleased(e);
|
||||
Deck_DragDrop();
|
||||
}
|
||||
});
|
||||
}
|
||||
public void Drop(JComponent dropditem)
|
||||
{
|
||||
if(dropditem==null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(dropditem instanceof JPanel panel)
|
||||
{
|
||||
if(_ship == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(LabelBaseColor.getMousePosition()!=null)
|
||||
{
|
||||
_ship.SetColor(panel.getBackground());
|
||||
Draw(_ship);
|
||||
revalidate();
|
||||
}
|
||||
if(LabelDopColor.getMousePosition()!=null && _ship instanceof DrawingContainerShip containerShip)
|
||||
{
|
||||
containerShip.SetDopColor(panel.getBackground());
|
||||
Draw(_ship);
|
||||
revalidate();
|
||||
}
|
||||
}
|
||||
if(dropditem instanceof JLabel jLabel && pictureBox.getMousePosition()!=null)
|
||||
{
|
||||
int speed = (int)numericUpDownSpeed.getValue();
|
||||
int weight=(int)numericUpDownWeight.getValue();
|
||||
int NumDecks=(int)numericUpDownDecks.getValue();
|
||||
boolean crane= checkBoxCrane.isSelected();
|
||||
boolean containers= checkBoxContainers.isSelected();
|
||||
if(jLabel == LabelSimple)
|
||||
{
|
||||
_ship=new DrawingShip(speed,weight,Color.WHITE,NumDecks);
|
||||
Draw(_ship);
|
||||
revalidate();
|
||||
}
|
||||
else if(jLabel==LabelModif)
|
||||
{
|
||||
_ship=new DrawingContainerShip(speed,weight,Color.WHITE,NumDecks,Color.WHITE,crane,containers);
|
||||
Draw(_ship);
|
||||
revalidate();
|
||||
}
|
||||
if(_ship != null)
|
||||
{
|
||||
_ship.SetPosition(20,50,pictureBox.getWidth(),pictureBox.getHeight());
|
||||
Draw(_ship);
|
||||
revalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
void Deck_MouseDown(Object sender) {
|
||||
IAdditionalDrawingObject Deck;
|
||||
switch (((JLabel)sender).getText()){
|
||||
case "Овальные":
|
||||
Deck = new DrawingOvalDeck();
|
||||
break;
|
||||
case "Трапецевидные":
|
||||
Deck = new DrawingTrapezDeck();
|
||||
break;
|
||||
case "Прямоугольные":
|
||||
Deck = new DrawingDeck();
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
Deck.SetAddEnum((int)numericUpDownDecks.getValue());
|
||||
ObjFDnD = Deck;
|
||||
}
|
||||
void Deck_DragEnter(Object sender){
|
||||
if(ObjFDnD!=null&& IAdditionalDrawingObject.class.isAssignableFrom(ObjFDnD.getClass())){
|
||||
setCursor(new Cursor(Cursor.HAND_CURSOR));
|
||||
TargetObjFDnD = sender;
|
||||
}
|
||||
}
|
||||
void Deck_DragDrop(){
|
||||
if(TargetObjFDnD==null) {return;}
|
||||
_ship.SetFormEnum((int)numericUpDownDecks.getValue(),(IAdditionalDrawingObject)ObjFDnD);
|
||||
DragExit();
|
||||
ObjFDnD = null;
|
||||
}
|
||||
void DragExit(){
|
||||
if(ObjFDnD!=null&&TargetObjFDnD!=null) {
|
||||
setCursor(Cursor.getDefaultCursor());
|
||||
Draw(_ship);
|
||||
TargetObjFDnD = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -6,4 +6,5 @@ public interface IDrawingObject {
|
||||
void MoveObject(Direction direction);
|
||||
void DrawingObject(Graphics g);
|
||||
float[] GetCurrentPosition();
|
||||
public DrawingShip GetDrawingObjectShip();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user