Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 30827fcb0d |
@@ -14,11 +14,6 @@ public class DrawingDeck extends JComponent implements IAdditionalDrawingObject{
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int GetDeckEnum()
|
||||
{
|
||||
return _decksEnum.GetAddEnum();
|
||||
}
|
||||
@Override
|
||||
public void DrawDeck(Color colorDeck, Graphics g,float _startPosX,float _startPosY)
|
||||
{
|
||||
super.paintComponent(g);
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingEntities <T extends EntityShip,U extends IAdditionalDrawingObject>{
|
||||
public Object[] _entities;
|
||||
public Object[] _decks;
|
||||
int entitiesCount = 0;
|
||||
int decksCount = 0;
|
||||
String indx;
|
||||
String indy;
|
||||
public DrawingEntities(int countE,int countD)
|
||||
{
|
||||
_entities=new Object[countE];
|
||||
_decks=new Object[countD];
|
||||
}
|
||||
public int Insert(T ship)
|
||||
{
|
||||
if(entitiesCount<_entities.length){
|
||||
_entities[entitiesCount] = ship;
|
||||
entitiesCount++;
|
||||
return entitiesCount-1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public int Insert(U deck)
|
||||
{
|
||||
if(decksCount<_decks.length){
|
||||
_decks[decksCount] = deck;
|
||||
decksCount++;
|
||||
return decksCount-1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public void SetIndexs(int ind1, int ind2)
|
||||
{
|
||||
indx=Integer.toString(ind1);
|
||||
indy=Integer.toString(ind2);
|
||||
}
|
||||
public DrawingShip CreateShip()
|
||||
{
|
||||
Random rnd = new Random();
|
||||
int indEnt=0;
|
||||
int indDeck=0;
|
||||
if(entitiesCount-1!=0 & decksCount-1!=0)
|
||||
{
|
||||
indDeck=rnd.nextInt(0,decksCount-1);
|
||||
indEnt=rnd.nextInt(0,entitiesCount-1);
|
||||
}
|
||||
T ship=(T)_entities[indEnt];
|
||||
U deck=(U)_decks[indDeck];
|
||||
SetIndexs(indEnt,indDeck);
|
||||
if(ship instanceof EntityLiner)
|
||||
{
|
||||
return new DrawingLiner(ship,deck);
|
||||
}
|
||||
return new DrawingShip(ship,deck);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,30 +2,10 @@ import java.awt.*;
|
||||
|
||||
public class DrawingLiner extends DrawingShip
|
||||
{
|
||||
private Color dopColor;
|
||||
public DrawingLiner(int speed, float weight, Color bodyColor,int numdeck,Color dopColor,boolean dopDeck,boolean pool)
|
||||
public DrawingLiner(int speed, float weight, Color bodyColor,Color dopColor,boolean dopDeck,boolean pool)
|
||||
{
|
||||
super(speed,weight,bodyColor,numdeck,130,45);
|
||||
super(speed,weight,bodyColor,130,45);
|
||||
Ship = new EntityLiner(speed, weight, bodyColor, dopColor, dopDeck, pool);
|
||||
this.dopColor=dopColor;
|
||||
}
|
||||
protected DrawingLiner(EntityShip ship,IAdditionalDrawingObject deck)
|
||||
{
|
||||
super(ship,deck);
|
||||
Ship=ship;
|
||||
}
|
||||
public void SetDopColor(Color color)
|
||||
{
|
||||
var temp = (EntityLiner) Ship;
|
||||
Ship=new EntityLiner(temp.GetSpeed(),temp.GetWeight(),temp.GetBodyColor(),color,temp.DopDeck,temp.Pool);
|
||||
dopColor=color;
|
||||
}
|
||||
@Override
|
||||
public void SetColor(Color color)
|
||||
{
|
||||
var temp = (EntityLiner) Ship;
|
||||
dopColor = dopColor==null? Color.WHITE : dopColor;
|
||||
Ship=new EntityLiner(temp.GetSpeed(),temp.GetWeight(),color,dopColor,temp.DopDeck,temp.Pool);
|
||||
}
|
||||
@Override
|
||||
public void DrawTransport(Graphics gr) {
|
||||
|
||||
@@ -14,10 +14,6 @@ public class DrawingObjectShip implements IDrawingObject {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public DrawingShip GetDrawingObjectShip() {
|
||||
return _ship;
|
||||
}
|
||||
@Override
|
||||
public void SetObject(int x, int y, int width, int height) {
|
||||
_ship.SetPosition(x,y,width,height);
|
||||
}
|
||||
@@ -35,18 +31,5 @@ public class DrawingObjectShip implements IDrawingObject {
|
||||
return _ship.GetCurrentPosition();
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String GetInfo()
|
||||
{
|
||||
if(_ship==null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return ExtentionShip.GetDataForSave(_ship);
|
||||
}
|
||||
public static IDrawingObject Create(String data)
|
||||
{
|
||||
return new DrawingObjectShip(ExtentionShip.CreateDrawingShip(data));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,11 +15,6 @@ public class DrawingOvalDeck extends JComponent implements IAdditionalDrawingObj
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int GetDeckEnum()
|
||||
{
|
||||
return _decksEnum.GetAddEnum();
|
||||
}
|
||||
@Override
|
||||
public void DrawDeck(Color colorDeck, Graphics g, float _startPosX, float _startPosY)
|
||||
{
|
||||
super.paintComponent(g);
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class DrawingShip extends JComponent{
|
||||
public class DrawingShip extends JPanel {
|
||||
protected EntityShip Ship;
|
||||
protected IAdditionalDrawingObject Deck;
|
||||
public void SetColor(Color color)
|
||||
{
|
||||
Ship=new EntityShip(Ship.GetSpeed(),Ship.GetWeight(),color);
|
||||
public IAdditionalDrawingObject Deck;
|
||||
public void SetEnum() {
|
||||
Random r = new Random();
|
||||
int numbEnum = r.nextInt(1, 4);
|
||||
Deck.SetAddEnum(numbEnum);
|
||||
}
|
||||
public IAdditionalDrawingObject GetDeck()
|
||||
public void SetFormEnum()
|
||||
{
|
||||
return Deck;
|
||||
}
|
||||
public void SetFormEnum(int decksnum,IAdditionalDrawingObject deck)
|
||||
{
|
||||
Deck=deck;
|
||||
Deck.SetAddEnum(decksnum);
|
||||
}
|
||||
public void SetDeck(IAdditionalDrawingObject deck)
|
||||
{
|
||||
Deck=deck;
|
||||
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 DrawingTriangleDeck();
|
||||
}
|
||||
}
|
||||
public EntityShip GetShip() {
|
||||
return Ship;
|
||||
@@ -32,35 +32,16 @@ public class DrawingShip extends JComponent{
|
||||
private Integer _pictureHeight = null;
|
||||
private int _ShipWidth = 120;
|
||||
private int _ShipHeight = 40;
|
||||
|
||||
public DrawingShip(int speed, float weight, Color bodycolor,int numdeck) {
|
||||
public DrawingShip(int speed, float weight, Color bodycolor) {
|
||||
Ship = new EntityShip(speed, weight, bodycolor);
|
||||
Deck = new DrawingTriangleDeck();
|
||||
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 DrawingTriangleDeck();
|
||||
}
|
||||
Deck.SetAddEnum(numdeck);
|
||||
|
||||
SetFormEnum();
|
||||
SetEnum();
|
||||
}
|
||||
public DrawingShip(int speed,float weight,Color bodyColor,int numdeck,int shipWidth,int shipHeight)
|
||||
public DrawingShip(int speed,float weight,Color bodyColor,int shipWidth,int shipHeight)
|
||||
{
|
||||
this(speed,weight,bodyColor,numdeck);
|
||||
this(speed,weight,bodyColor);
|
||||
_ShipWidth = shipWidth;
|
||||
_ShipHeight = shipHeight;
|
||||
|
||||
}
|
||||
protected DrawingShip(EntityShip ship,IAdditionalDrawingObject deck)
|
||||
{
|
||||
Ship=ship;
|
||||
Deck=deck;
|
||||
}
|
||||
public void SetPosition(int x, int y, int width, int height) {
|
||||
if (width <= _ShipWidth + x || height <= _ShipHeight + y || x < 0 || y < 0) {
|
||||
|
||||
@@ -14,11 +14,6 @@ public class DrawingTriangleDeck extends JComponent implements IAdditionalDrawin
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int GetDeckEnum()
|
||||
{
|
||||
return _decksEnum.GetAddEnum();
|
||||
}
|
||||
@Override
|
||||
public void DrawDeck(Color colorDeck, Graphics g,float _startPosX,float _startPosY)
|
||||
{
|
||||
super.paintComponent(g);
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class ExtentionShip {
|
||||
private static final char _separatorForObject=':';
|
||||
private static IAdditionalDrawingObject CreateDeck(String str,int num)
|
||||
{
|
||||
IAdditionalDrawingObject Deck=null;
|
||||
switch(str)
|
||||
{
|
||||
case "DrawingDeck":
|
||||
Deck=new DrawingDeck();
|
||||
break;
|
||||
case "DrawingTriangleDeck":
|
||||
Deck=new DrawingTriangleDeck();
|
||||
break;
|
||||
case "DrawingOvalDeck":
|
||||
Deck=new DrawingOvalDeck();
|
||||
break;
|
||||
}
|
||||
Deck.SetAddEnum(num);
|
||||
return Deck;
|
||||
}
|
||||
public static DrawingShip CreateDrawingShip(String info)
|
||||
{
|
||||
String[] strs = info.split(String.format("%s",_separatorForObject));
|
||||
if(strs.length==5)
|
||||
{
|
||||
DrawingShip ship = new DrawingShip(Integer.parseInt(strs[0]),Integer.parseInt(strs[1]), new Color(Integer.parseInt(strs[2])),Integer.parseInt(strs[3]));
|
||||
ship.SetDeck(CreateDeck(strs[4],Integer.parseInt(strs[3])));
|
||||
return ship;
|
||||
|
||||
}
|
||||
if(strs.length==8)
|
||||
{
|
||||
DrawingLiner liner=new DrawingLiner(Integer.parseInt(strs[0]),Integer.parseInt(strs[1]), new Color(Integer.parseInt(strs[2])),Integer.parseInt(strs[3]),new Color(Integer.parseInt(strs[5])),Boolean.parseBoolean(strs[6]),Boolean.parseBoolean(strs[7]));
|
||||
liner.SetDeck(CreateDeck(strs[4],Integer.parseInt(strs[3])));
|
||||
return liner;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static String GetDataForSave(DrawingShip drawingShip)
|
||||
{
|
||||
var ship = drawingShip.Ship;
|
||||
var str= String.format("%d%c%d%c%s%c%d%c%s",ship.GetSpeed(),_separatorForObject,(int)ship.GetWeight(),_separatorForObject,Integer.toString(ship.GetBodyColor().getRGB()),_separatorForObject,drawingShip.GetDeck().GetDeckEnum(),_separatorForObject,drawingShip.GetDeck().getClass().getSimpleName());
|
||||
if(!(ship instanceof EntityLiner liner))
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return String.format("%s%c%s%c%b%c%b",str,_separatorForObject,Integer.toString(liner.DopColor.getRGB()),_separatorForObject,liner.DopDeck,_separatorForObject,liner.Pool);
|
||||
}
|
||||
}
|
||||
118
src/FormMap.form
Normal file
118
src/FormMap.form
Normal file
@@ -0,0 +1,118 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMap">
|
||||
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="6" 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="500" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="4c171" binding="pictureBoxShip" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="6" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<toolbar id="7b4c1" binding="StatusStrip">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="6" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="-1" height="20"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="false"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</toolbar>
|
||||
<component id="d2f33" class="javax.swing.JButton" binding="ButtonCreateModif">
|
||||
<constraints>
|
||||
<grid row="2" column="0" 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="15603" class="javax.swing.JButton" binding="ButtonDown">
|
||||
<constraints>
|
||||
<grid row="2" column="4" 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="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="3510" class="javax.swing.JButton" binding="ButtonRight">
|
||||
<constraints>
|
||||
<grid row="2" column="5" 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="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="dd08b" class="javax.swing.JButton" binding="ButtonCreate">
|
||||
<constraints>
|
||||
<grid row="1" column="0" 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="37083" class="javax.swing.JButton" binding="ButtonUp">
|
||||
<constraints>
|
||||
<grid row="1" column="4" 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="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="7977">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="4a1" class="javax.swing.JComboBox" binding="ComboBoxSelectorMap">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<model>
|
||||
<item value="Простая карта"/>
|
||||
<item value="Карта море"/>
|
||||
</model>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="ed54d">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="87b9e" class="javax.swing.JButton" binding="ButtonLeft">
|
||||
<constraints>
|
||||
<grid row="2" 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="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
177
src/FormMap.java
Normal file
177
src/FormMap.java
Normal file
@@ -0,0 +1,177 @@
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.security.PublicKey;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormMap extends JFrame{
|
||||
private JButton ButtonCreateModif;
|
||||
private JButton ButtonLeft;
|
||||
private JButton ButtonDown;
|
||||
private JButton ButtonRight;
|
||||
private JButton ButtonUp;
|
||||
private JButton ButtonCreate;
|
||||
private JComboBox ComboBoxSelectorMap;
|
||||
private AbstractMap _abstractMap;
|
||||
private JPanel pictureBoxShip;
|
||||
private JToolBar StatusStrip;
|
||||
public JPanel MainPanel;
|
||||
private Random random = new Random();
|
||||
protected DrawingShip _ship;
|
||||
|
||||
private BufferedImage bufferImg = null;
|
||||
private JLabel JLabelSpeed = new JLabel();
|
||||
private JLabel JLabelWeight = new JLabel();
|
||||
private JLabel JLabelColor = new JLabel();
|
||||
|
||||
public void Draw() {
|
||||
pictureBoxShip.removeAll();
|
||||
BufferedImage bmp = new BufferedImage(pictureBoxShip.getWidth(), pictureBoxShip.getHeight(),BufferedImage.TYPE_INT_RGB);
|
||||
Graphics gr = bmp.getGraphics();
|
||||
gr.setColor(new Color(238, 238, 238));
|
||||
gr.fillRect(0, 0, pictureBoxShip.getWidth(), pictureBoxShip.getHeight());
|
||||
if (_ship != null) {
|
||||
_ship.DrawTransport(gr);
|
||||
JLabel imageOfLoco = new JLabel();
|
||||
imageOfLoco.setPreferredSize(pictureBoxShip.getSize());
|
||||
imageOfLoco.setMinimumSize(new Dimension(1, 1));
|
||||
imageOfLoco.setIcon(new ImageIcon(bmp));
|
||||
pictureBoxShip.add(imageOfLoco,BorderLayout.CENTER);
|
||||
}
|
||||
validate();
|
||||
}
|
||||
public void SetData(DrawingShip _ship)
|
||||
{
|
||||
pictureBoxShip.removeAll();
|
||||
JLabelSpeed.setText("Cкорость: " + _ship.GetShip().GetSpeed() + " ");
|
||||
JLabelWeight.setText("Вес: " + _ship.GetShip().GetWeight() + " ");
|
||||
JLabelColor.setText(("Цвет: " + _ship.GetShip().GetBodyColor() + " "));
|
||||
JLabel imageWithMapAndObject = new JLabel();
|
||||
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
|
||||
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||
imageWithMapAndObject.setIcon(new ImageIcon(_abstractMap.CreateMap(pictureBoxShip.getWidth(),pictureBoxShip.getHeight(), new DrawingObjectShip(_ship))));
|
||||
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||
pictureBoxShip.revalidate();
|
||||
}
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
Draw();
|
||||
}
|
||||
public FormMap() {
|
||||
_abstractMap = new SimpleMap();
|
||||
Box LabelBox = Box.createHorizontalBox();
|
||||
LabelBox.setMinimumSize(new Dimension(1, 20));
|
||||
LabelBox.add(JLabelSpeed);
|
||||
LabelBox.add(JLabelWeight);
|
||||
LabelBox.add(JLabelColor);
|
||||
StatusStrip.add(LabelBox);
|
||||
try {
|
||||
Image img = ImageIO.read(FormShip.class.getResource("Images/4.png"));
|
||||
ButtonUp.setIcon(new ImageIcon(img));
|
||||
img = ImageIO.read(FormShip.class.getResource("Images/2.png"));
|
||||
ButtonDown.setIcon(new ImageIcon(img));
|
||||
img = ImageIO.read(FormShip.class.getResource("Images/1.png"));
|
||||
ButtonLeft.setIcon(new ImageIcon(img));
|
||||
img = ImageIO.read(FormShip.class.getResource("Images/3.png"));
|
||||
ButtonRight.setIcon(new ImageIcon(img));
|
||||
} catch (Exception ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
_ship=new DrawingShip (random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
|
||||
ButtonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
var _ship=new DrawingShip(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
|
||||
_ship.SetPosition(random.nextInt(100, 500), random.nextInt(10, 100), pictureBoxShip.getWidth(), pictureBoxShip.getHeight());
|
||||
SetData(_ship);
|
||||
}
|
||||
});
|
||||
ButtonUp.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
pictureBoxShip.removeAll();
|
||||
JLabel imageWithMapAndObject = new JLabel();
|
||||
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
|
||||
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||
imageWithMapAndObject.setIcon(new ImageIcon(_abstractMap.MoveObject(Direction.Up)));
|
||||
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||
pictureBoxShip.revalidate();
|
||||
pictureBoxShip.repaint();
|
||||
}
|
||||
});
|
||||
ButtonDown.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
pictureBoxShip.removeAll();
|
||||
JLabel imageWithMapAndObject = new JLabel();
|
||||
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
|
||||
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||
imageWithMapAndObject.setIcon(new ImageIcon(_abstractMap.MoveObject(Direction.Down)));
|
||||
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||
pictureBoxShip.revalidate();
|
||||
pictureBoxShip.repaint();
|
||||
}
|
||||
});
|
||||
ButtonRight.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
pictureBoxShip.removeAll();
|
||||
JLabel imageWithMapAndObject = new JLabel();
|
||||
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
|
||||
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||
imageWithMapAndObject.setIcon(new ImageIcon(_abstractMap.MoveObject(Direction.Right)));
|
||||
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||
pictureBoxShip.revalidate();
|
||||
pictureBoxShip.repaint();
|
||||
}
|
||||
});
|
||||
ButtonLeft.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
pictureBoxShip.removeAll();
|
||||
JLabel imageWithMapAndObject = new JLabel();
|
||||
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
|
||||
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||
imageWithMapAndObject.setIcon(new ImageIcon(_abstractMap.MoveObject(Direction.Left)));
|
||||
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||
pictureBoxShip.revalidate();
|
||||
pictureBoxShip.repaint();
|
||||
|
||||
}
|
||||
});
|
||||
ButtonCreateModif.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
_ship=new DrawingLiner(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),random.nextBoolean(),random.nextBoolean());
|
||||
_ship.SetPosition(random.nextInt(100, 500), random.nextInt(10, 100), pictureBoxShip.getWidth(), pictureBoxShip.getHeight());
|
||||
SetData(_ship);
|
||||
}
|
||||
});
|
||||
|
||||
ComboBoxSelectorMap.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ComboBoxSelectorMap = (JComboBox)e.getSource();
|
||||
String item = (String)ComboBoxSelectorMap.getSelectedItem();
|
||||
switch (item) {
|
||||
case "Простая карта": {
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
}
|
||||
case "Карта море": {
|
||||
_abstractMap = new SeaMap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,249 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMapWithSetShipsGeneric">
|
||||
<grid id="27dc6" binding="Mainpanel" layout-manager="GridLayoutManager" row-count="6" 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="798" height="551"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="9bb5a" binding="pictureBoxShip" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="3" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="600" height="400"/>
|
||||
<preferred-size width="600" height="400"/>
|
||||
<maximum-size width="600" height="400"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<hspacer id="b305e">
|
||||
<constraints>
|
||||
<grid row="5" 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>
|
||||
<grid id="4fa91" binding="GroupBoxTools" layout-manager="GridLayoutManager" row-count="8" 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="3" column="1" row-span="3" 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="cdb80" class="javax.swing.JButton" binding="ButtonAddShip">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Добавить корабль"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="e5494" class="javax.swing.JTextField" binding="maskedTextBoxPosition">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="8bb89" class="javax.swing.JButton" binding="ButtonDeleteShip">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Удалить корабль"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="aa482" class="javax.swing.JButton" binding="ButtonShowStorage">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Показать хранилище"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="9ebdc" class="javax.swing.JButton" binding="ButtonShowMap">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Показать карту"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="acbc" class="javax.swing.JButton" binding="ButtonUp">
|
||||
<constraints>
|
||||
<grid row="6" 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="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="a584e" class="javax.swing.JButton" binding="ButtonDown">
|
||||
<constraints>
|
||||
<grid row="7" 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="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="e9fe6" class="javax.swing.JButton" binding="ButtonLeft">
|
||||
<constraints>
|
||||
<grid row="7" 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="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="25a22" class="javax.swing.JButton" binding="ButtonRight">
|
||||
<constraints>
|
||||
<grid row="7" 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="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="6734a" class="javax.swing.JButton" binding="ButtonCheckDel">
|
||||
<constraints>
|
||||
<grid row="5" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Удаленные"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="d087c" binding="GroupBoxMaps" layout-manager="GridLayoutManager" row-count="6" 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="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="124b6" class="javax.swing.JTextField" binding="textBoxNewMapName">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<vspacer id="3ed0f">
|
||||
<constraints>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="95ba3" class="javax.swing.JComboBox" binding="ComboBoxSelectorMap">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<model>
|
||||
<item value="Простая карта"/>
|
||||
<item value="Карта море"/>
|
||||
</model>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="fb777" class="javax.swing.JButton" binding="ButtonAddMap">
|
||||
<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="a358a" class="javax.swing.JButton" binding="ButtonDeleteMap">
|
||||
<constraints>
|
||||
<grid row="4" 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="e221" class="javax.swing.JList" binding="ListBoxMaps" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="e57df" class="javax.swing.JMenuBar" binding="MenuBar" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="8737a" class="javax.swing.JMenu" binding="MenuFile" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Файл"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="3edfc" class="javax.swing.JMenu" binding="MenuMap" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<text value="Карта"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="d9dfb" class="javax.swing.JMenuItem" binding="SaveToolStripMap">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<text value="Сохранить"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="510d5" class="javax.swing.JMenuItem" binding="LoadToolStripMap">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<text value="Загрузить"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="c2d9b" class="javax.swing.JMenuItem" binding="SaveToolStripMenu">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<text value="Сохранить"/>
|
||||
<verticalAlignment value="0"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="8b9ff" class="javax.swing.JMenuItem" binding="LoadToolStripMenu">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<text value="Загрузить"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -1,396 +0,0 @@
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
public JPanel Mainpanel;
|
||||
private JPanel pictureBoxShip;
|
||||
private JPanel GroupBoxTools;
|
||||
private JComboBox ComboBoxSelectorMap;
|
||||
private JButton ButtonAddShip;
|
||||
private JButton ButtonDeleteShip;
|
||||
private JButton ButtonShowStorage;
|
||||
private JButton ButtonShowMap;
|
||||
private JButton ButtonLeft;
|
||||
private JButton ButtonDown;
|
||||
private JButton ButtonUp;
|
||||
private JButton ButtonRight;
|
||||
private JTextField maskedTextBoxPosition;
|
||||
private JTextField textBoxNewMapName;
|
||||
private final int picWidth=600;
|
||||
|
||||
private final int picHeight=400;
|
||||
private JButton ButtonAddMap;
|
||||
private JList ListBoxMaps;
|
||||
private JButton ButtonDeleteMap;
|
||||
private JPanel GroupBoxMaps;
|
||||
private JButton ButtonCheckDel;
|
||||
private JMenuBar MenuBar;
|
||||
private JMenu MenuFile;
|
||||
private JMenuItem SaveToolStripMenu;
|
||||
private JMenuItem LoadToolStripMenu;
|
||||
private JMenu MenuMap;
|
||||
private JMenuItem SaveToolStripMap;
|
||||
private JMenuItem LoadToolStripMap;
|
||||
private MapWithSetShipsGeneric<DrawingObjectShip,AbstractMap> _mapShipsCollectionGeneric;
|
||||
private final HashMap<String,AbstractMap> _mapsDict = new HashMap<>(){{
|
||||
put("Простая карта",new SimpleMap());
|
||||
put("Карта море",new SeaMap());
|
||||
}};
|
||||
private final MapsCollection _mapsCollection;
|
||||
public void UpdateWindow(BufferedImage bmp)
|
||||
{
|
||||
pictureBoxShip.removeAll();
|
||||
JLabel imageWithMapAndObject = new JLabel();
|
||||
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
|
||||
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||
imageWithMapAndObject.setIcon(new ImageIcon(bmp));
|
||||
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||
pictureBoxShip.revalidate();
|
||||
}
|
||||
private void ReloadMaps(){
|
||||
int index = ListBoxMaps.getSelectedIndex();
|
||||
DefaultListModel<String> model1 = (DefaultListModel<String>) ListBoxMaps.getModel();
|
||||
model1.removeAllElements();
|
||||
for(int i=0;i<_mapsCollection.Keys().size();i++)
|
||||
{
|
||||
model1.addElement(_mapsCollection.Keys().get(i));
|
||||
}
|
||||
if (ListBoxMaps.getModel().getSize() > 0 && (index == -1 || index >= ListBoxMaps.getModel().getSize()))
|
||||
{
|
||||
ListBoxMaps.setSelectedIndex(0);
|
||||
}
|
||||
else if (ListBoxMaps.getModel().getSize() > 0 && index > -1 && index < ListBoxMaps.getModel().getSize())
|
||||
{
|
||||
ListBoxMaps.setSelectedIndex(index);
|
||||
}
|
||||
}
|
||||
public FormMapWithSetShipsGeneric()
|
||||
{
|
||||
_mapsCollection = new MapsCollection(picWidth, picHeight);
|
||||
ComboBoxSelectorMap.removeAllItems();
|
||||
for (String elem : _mapsDict.keySet()) {
|
||||
ComboBoxSelectorMap.addItem(elem);
|
||||
}
|
||||
try {
|
||||
Image img = ImageIO.read(FormShip.class.getResource("Images/4.png"));
|
||||
ButtonUp.setIcon(new ImageIcon(img));
|
||||
img = ImageIO.read(FormShip.class.getResource("Images/2.png"));
|
||||
ButtonDown.setIcon(new ImageIcon(img));
|
||||
img = ImageIO.read(FormShip.class.getResource("Images/1.png"));
|
||||
ButtonLeft.setIcon(new ImageIcon(img));
|
||||
img = ImageIO.read(FormShip.class.getResource("Images/3.png"));
|
||||
ButtonRight.setIcon(new ImageIcon(img));
|
||||
} catch (Exception ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
|
||||
ButtonAddShip.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
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() {
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
if (ListBoxMaps.getSelectedIndex() == -1)
|
||||
return;
|
||||
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
|
||||
}
|
||||
});
|
||||
ButtonDeleteShip.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (maskedTextBoxPosition.getText().isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
int result = JOptionPane.showConfirmDialog(null,"Удалить объект?","Удаление",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
|
||||
if(result==JOptionPane.NO_OPTION)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos=Integer.parseInt(maskedTextBoxPosition.getText());
|
||||
if(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).Delete(pos)!=null)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Объект удален");
|
||||
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
});
|
||||
ButtonShowStorage.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (ListBoxMaps.getSelectedIndex() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
|
||||
}
|
||||
});
|
||||
ButtonShowMap.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (ListBoxMaps.getSelectedIndex() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowOnMap());
|
||||
}
|
||||
});
|
||||
ButtonUp.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (ListBoxMaps.getSelectedIndex() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxShip.removeAll();
|
||||
JLabel imageWithMapAndObject = new JLabel();
|
||||
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
|
||||
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||
imageWithMapAndObject.setIcon(new ImageIcon(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).MoveObject(Direction.Up)));
|
||||
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||
pictureBoxShip.revalidate();
|
||||
pictureBoxShip.repaint();
|
||||
}
|
||||
});
|
||||
ButtonDown.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (ListBoxMaps.getSelectedIndex() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxShip.removeAll();
|
||||
JLabel imageWithMapAndObject = new JLabel();
|
||||
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
|
||||
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||
imageWithMapAndObject.setIcon(new ImageIcon(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).MoveObject(Direction.Down)));
|
||||
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||
pictureBoxShip.revalidate();
|
||||
pictureBoxShip.repaint();
|
||||
}
|
||||
});
|
||||
ButtonRight.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (ListBoxMaps.getSelectedIndex() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxShip.removeAll();
|
||||
JLabel imageWithMapAndObject = new JLabel();
|
||||
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
|
||||
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||
imageWithMapAndObject.setIcon(new ImageIcon(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).MoveObject(Direction.Right)));
|
||||
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||
pictureBoxShip.revalidate();
|
||||
pictureBoxShip.repaint();
|
||||
}
|
||||
});
|
||||
ButtonLeft.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (ListBoxMaps.getSelectedIndex() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxShip.removeAll();
|
||||
JLabel imageWithMapAndObject = new JLabel();
|
||||
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
|
||||
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||
imageWithMapAndObject.setIcon(new ImageIcon(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).MoveObject(Direction.Left)));
|
||||
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||
pictureBoxShip.revalidate();
|
||||
pictureBoxShip.repaint();
|
||||
|
||||
}
|
||||
});
|
||||
maskedTextBoxPosition.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
char c = e.getKeyChar();
|
||||
if ( ((c < '0') || (c > '9')) || maskedTextBoxPosition.getText().length() >= 2) {
|
||||
e.consume();
|
||||
}
|
||||
}
|
||||
});
|
||||
ButtonAddMap.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (ComboBoxSelectorMap.getSelectedIndex() == -1 || textBoxNewMapName.getText().isEmpty())
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,"Не все данные заполнены","Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
if(!_mapsDict.containsKey(ComboBoxSelectorMap.getSelectedItem()))
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,"Нет такой карты","Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
_mapsCollection.AddMap(textBoxNewMapName.getText(),_mapsDict.get(ComboBoxSelectorMap.getSelectedItem().toString()));
|
||||
ReloadMaps();
|
||||
}
|
||||
});
|
||||
ButtonDeleteMap.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (ListBoxMaps.getSelectedIndex() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(JOptionPane.showConfirmDialog(null,"Удалить карту"+ListBoxMaps.getSelectedValue().toString()+"?","Удаление",JOptionPane.YES_NO_OPTION)==0)
|
||||
{
|
||||
_mapsCollection.DelMap(ListBoxMaps.getSelectedValue().toString());
|
||||
ReloadMaps();
|
||||
}
|
||||
}
|
||||
});
|
||||
ButtonCheckDel.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (ListBoxMaps.getSelectedIndex() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
IDrawingObject ship=_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).GetShipsDeleted();
|
||||
if(ship==null)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,"Коллекция пуста","Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
FormShip formShip=new FormShip(ship);
|
||||
formShip.setSize(1000,800);
|
||||
formShip.setVisible(true);
|
||||
}
|
||||
});
|
||||
SaveToolStripMenu.addActionListener(new ActionListener(){
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser fc= new JFileChooser();
|
||||
int returnVal = fc.showSaveDialog(null);
|
||||
if(returnVal==JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
try {
|
||||
if (_mapsCollection.SaveData(fc.getSelectedFile().getPath())) {
|
||||
JOptionPane.showMessageDialog(null, "Сохранение прошло успешно", "Результат",JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не сохранилось", "Результат",JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
LoadToolStripMenu.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser fc= new JFileChooser();
|
||||
int returnVal = fc.showOpenDialog(null);
|
||||
if(returnVal==JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
try {
|
||||
if(_mapsCollection.LoadData(fc.getSelectedFile().getPath()))
|
||||
{
|
||||
ReloadMaps();
|
||||
JOptionPane.showMessageDialog(null, "Загрузка прошла успешно", "Результат",JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не загрузилось", "Результат",JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
SaveToolStripMap.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(ListBoxMaps.getSelectedIndex()==-1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
JFileChooser fc= new JFileChooser();
|
||||
int returnVal = fc.showSaveDialog(null);
|
||||
|
||||
if(returnVal==JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
try {
|
||||
if (_mapsCollection.SaveMapData(fc.getSelectedFile().getPath(),ListBoxMaps.getSelectedValue().toString())){
|
||||
JOptionPane.showMessageDialog(null, "Сохранение прошло успешно", "Результат",JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не сохранилось", "Результат",JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
LoadToolStripMap.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser fc= new JFileChooser();
|
||||
int returnVal = fc.showOpenDialog(null);
|
||||
if(returnVal==JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
try {
|
||||
if(_mapsCollection.LoadMapData(fc.getSelectedFile().getPath()))
|
||||
{
|
||||
ReloadMaps();
|
||||
JOptionPane.showMessageDialog(null, "Загрузка прошла успешно", "Результат",JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не загрузилось", "Результат",JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
DefaultListModel<String> dlm = new DefaultListModel<String>();
|
||||
ListBoxMaps = new JList(dlm);
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormParam">
|
||||
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="4" 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="500" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="7700e" binding="pictureBoxShip" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<component id="b960b" class="javax.swing.JButton" binding="ButtonCreate">
|
||||
<constraints>
|
||||
<grid row="1" column="0" 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="a44b0" class="javax.swing.JButton" binding="ButtonCreateModif">
|
||||
<constraints>
|
||||
<grid row="2" column="0" 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>
|
||||
<hspacer id="56304">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="31e01" class="javax.swing.JLabel" binding="LabelInfo">
|
||||
<constraints>
|
||||
<grid row="2" 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>
|
||||
<toolbar id="7a0ba" binding="StatusStrip">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="-1" height="20"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="false"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</toolbar>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -1,113 +0,0 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class FormParam extends JFrame{
|
||||
public JPanel MainPanel;
|
||||
private JPanel pictureBoxShip;
|
||||
private JButton ButtonCreate;
|
||||
private JButton ButtonCreateModif;
|
||||
private JToolBar StatusStrip;
|
||||
private JLabel LabelInfo;
|
||||
private JLabel JLabelSpeed = new JLabel();
|
||||
private JLabel JLabelWeight = new JLabel();
|
||||
private JLabel JLabelColor = new JLabel();
|
||||
private DrawingEntities<EntityShip,IAdditionalDrawingObject> _drawingEntities;
|
||||
private IAdditionalDrawingObject SetData()
|
||||
{
|
||||
Random random=new Random();
|
||||
int r = random.nextInt(3);
|
||||
if(r==0)
|
||||
{
|
||||
return new DrawingTriangleDeck();
|
||||
}
|
||||
if(r==1)
|
||||
{
|
||||
return new DrawingDeck();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new DrawingOvalDeck();
|
||||
}
|
||||
|
||||
}
|
||||
private void Draw(DrawingShip _ship) {
|
||||
pictureBoxShip.removeAll();
|
||||
Random random = new Random();
|
||||
BufferedImage bmp = new BufferedImage(pictureBoxShip.getWidth(), pictureBoxShip.getHeight(),BufferedImage.TYPE_INT_RGB);
|
||||
Graphics gr = bmp.getGraphics();
|
||||
gr.setColor(new Color(238, 238, 238));
|
||||
gr.fillRect(0, 0, pictureBoxShip.getWidth(), pictureBoxShip.getHeight());
|
||||
if (_ship != null) {
|
||||
_ship.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100),
|
||||
pictureBoxShip.getWidth(), pictureBoxShip.getHeight());
|
||||
_ship.DrawTransport(gr);
|
||||
JLabelSpeed.setText("Cкорость: " + _ship.GetShip().GetSpeed() + " ");
|
||||
JLabelWeight.setText("Вес: " + _ship.GetShip().GetWeight() + " ");
|
||||
JLabelColor.setText(("Цвет: " + _ship.GetShip().GetBodyColor() + " "));
|
||||
JLabel imageOfLoco = new JLabel();
|
||||
imageOfLoco.setPreferredSize(pictureBoxShip.getSize());
|
||||
imageOfLoco.setMinimumSize(new Dimension(1, 1));
|
||||
imageOfLoco.setIcon(new ImageIcon(bmp));
|
||||
pictureBoxShip.add(imageOfLoco,BorderLayout.CENTER);
|
||||
}
|
||||
validate();
|
||||
}
|
||||
public FormParam()
|
||||
{
|
||||
Box LabelBox = Box.createHorizontalBox();
|
||||
LabelBox.setMinimumSize(new Dimension(1, 20));
|
||||
LabelBox.add(JLabelSpeed);
|
||||
LabelBox.add(JLabelWeight);
|
||||
LabelBox.add(JLabelColor);
|
||||
StatusStrip.add(LabelBox);
|
||||
_drawingEntities=new DrawingEntities<>(10,10);
|
||||
ButtonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e){
|
||||
Random random = new Random();
|
||||
Color colorFirst = JColorChooser.showDialog(null, "Цвет", null);
|
||||
EntityShip ship=new EntityShip(random.nextInt(100,300), random.nextInt(1000,2000),colorFirst);
|
||||
IAdditionalDrawingObject deck = SetData();
|
||||
int DecksCount=random.nextInt(1,4);
|
||||
deck.SetAddEnum(DecksCount);
|
||||
if((_drawingEntities.Insert(ship)!=-1) & (_drawingEntities.Insert(deck)!=-1))
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,"Объект добавлен");
|
||||
Draw(_drawingEntities.CreateShip());
|
||||
LabelInfo.setText(_drawingEntities.indx+ " " + _drawingEntities.indy);
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
});
|
||||
ButtonCreateModif.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Random random = new Random();
|
||||
Color colorFirst = JColorChooser.showDialog(null, "Цвет", null);
|
||||
Color colorSecond = JColorChooser.showDialog(null, "Цвет", null);
|
||||
EntityLiner _ship=new EntityLiner(random.nextInt(100, 300), random.nextInt(1000, 2000), colorFirst,colorSecond,random.nextBoolean(),random.nextBoolean());
|
||||
IAdditionalDrawingObject deck = SetData();
|
||||
int DecksCount=random.nextInt(1,4);
|
||||
deck.SetAddEnum(DecksCount);
|
||||
if((_drawingEntities.Insert(_ship)!=-1) & (_drawingEntities.Insert(deck)!=-1))
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,"Объект добавлен");
|
||||
Draw(_drawingEntities.CreateShip());
|
||||
LabelInfo.setText(_drawingEntities.indx+ " " + _drawingEntities.indy);
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormShip">
|
||||
<grid id="27dc6" binding="Mainpanel" layout-manager="GridLayoutManager" row-count="4" column-count="9" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="Mainpanel" layout-manager="GridLayoutManager" row-count="4" 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>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
@@ -10,7 +10,7 @@
|
||||
<children>
|
||||
<component id="2ea16" class="javax.swing.JButton" binding="ButtonDown">
|
||||
<constraints>
|
||||
<grid row="2" column="7" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<grid row="2" column="5" 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="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@@ -22,7 +22,7 @@
|
||||
</component>
|
||||
<component id="4f60a" class="javax.swing.JButton" binding="ButtonLeft">
|
||||
<constraints>
|
||||
<grid row="2" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<grid row="2" column="4" 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="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@@ -34,7 +34,7 @@
|
||||
</component>
|
||||
<component id="4eb88" class="javax.swing.JButton" binding="ButtonRight">
|
||||
<constraints>
|
||||
<grid row="2" column="8" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<grid row="2" column="6" 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="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@@ -47,7 +47,7 @@
|
||||
</component>
|
||||
<component id="fb937" class="javax.swing.JButton" binding="ButtonUp">
|
||||
<constraints>
|
||||
<grid row="1" column="7" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<grid row="1" column="5" 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="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@@ -59,7 +59,7 @@
|
||||
</component>
|
||||
<toolbar id="e747d" binding="StatusStrip">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="9" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<grid row="3" column="0" row-span="1" col-span="7" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="-1" height="20"/>
|
||||
<preferred-size width="-1" height="20"/>
|
||||
<maximum-size width="-1" height="20"/>
|
||||
@@ -71,14 +71,19 @@
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</toolbar>
|
||||
<hspacer id="d6bea">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="4" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<hspacer id="d86ff">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="5" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="2" column="1" row-span="1" col-span="3" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<grid id="6b0b8" binding="pictureBoxShip" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="9" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="0" column="0" row-span="1" col-span="7" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
@@ -100,19 +105,6 @@
|
||||
<text value="Модификация"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="9abb1">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="4" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="8005c" class="javax.swing.JButton" binding="ButtonSelect">
|
||||
<constraints>
|
||||
<grid row="1" column="5" 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>
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
public class FormShip extends JDialog{
|
||||
public class FormShip extends JFrame{
|
||||
public JPanel Mainpanel;
|
||||
private Random random = new Random();
|
||||
private JButton ButtonCreate;
|
||||
@@ -16,20 +19,9 @@ public class FormShip extends JDialog{
|
||||
protected DrawingShip _ship;
|
||||
private JPanel pictureBoxShip;
|
||||
private JToolBar StatusStrip;
|
||||
private JButton ButtonSelect;
|
||||
private JLabel JLabelSpeed = new JLabel();
|
||||
private JLabel JLabelWeight = new JLabel();
|
||||
private JLabel JLabelColor = new JLabel();
|
||||
protected DrawingShip SelectedShip;
|
||||
public DrawingShip GetSelectedShip()
|
||||
{
|
||||
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);
|
||||
@@ -46,23 +38,8 @@ public class FormShip extends JDialog{
|
||||
}
|
||||
validate();
|
||||
}
|
||||
public FormShip(IDrawingObject ship)
|
||||
{
|
||||
super(new Frame("Лайнер"));
|
||||
CreateWindow();
|
||||
setModal(true);
|
||||
_ship=ship.GetDrawingObjectShip();
|
||||
getContentPane().add(Mainpanel);
|
||||
}
|
||||
public FormShip()
|
||||
{
|
||||
super(new Frame("Лайнер"));
|
||||
CreateWindow();
|
||||
setModal(true);
|
||||
getContentPane().add(Mainpanel);
|
||||
}
|
||||
public void CreateWindow() {
|
||||
setModal(true);
|
||||
|
||||
public FormShip() {
|
||||
Box LabelBox = Box.createHorizontalBox();
|
||||
LabelBox.setMinimumSize(new Dimension(1, 20));
|
||||
LabelBox.add(JLabelSpeed);
|
||||
@@ -81,13 +58,10 @@ public class FormShip extends JDialog{
|
||||
} catch (Exception ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
SelectedShip=_ship;
|
||||
ButtonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
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,SetEnum());
|
||||
_ship=new DrawingShip(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
|
||||
_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() + " ");
|
||||
@@ -143,10 +117,7 @@ public class FormShip extends JDialog{
|
||||
ButtonCreateModif.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Random random = new Random();
|
||||
Color colorFirst = JColorChooser.showDialog(null, "Цвет", null);
|
||||
Color colorSecond = JColorChooser.showDialog(null, "Цвет", null);
|
||||
_ship=new DrawingLiner(random.nextInt(100, 300), random.nextInt(1000, 2000), colorFirst,SetEnum(),colorSecond,random.nextBoolean(),random.nextBoolean());
|
||||
_ship=new DrawingLiner(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),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() + " ");
|
||||
@@ -154,13 +125,5 @@ public class FormShip extends JDialog{
|
||||
Draw(_ship);
|
||||
}
|
||||
});
|
||||
|
||||
ButtonSelect.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
SelectedShip=_ship;
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,338 +0,0 @@
|
||||
<?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="805" 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="checkBoxPool">
|
||||
<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="checkBoxDopDeck">
|
||||
<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="labelTriangleDeck">
|
||||
<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>
|
||||
@@ -1,247 +0,0 @@
|
||||
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 checkBoxPool;
|
||||
private JCheckBox checkBoxDopDeck;
|
||||
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 labelTriangleDeck;
|
||||
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));
|
||||
labelTriangleDeck.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(labelTriangleDeck);
|
||||
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 DrawingLiner liner)
|
||||
{
|
||||
liner.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 dopdeck=checkBoxDopDeck.isSelected();
|
||||
boolean pool=checkBoxPool.isSelected();
|
||||
|
||||
if(jLabel == LabelSimple)
|
||||
{
|
||||
_ship=new DrawingShip(speed,weight,Color.WHITE,NumDecks);
|
||||
Draw(_ship);
|
||||
revalidate();
|
||||
}
|
||||
else if(jLabel==LabelModif)
|
||||
{
|
||||
_ship=new DrawingLiner(speed,weight,Color.WHITE,NumDecks,Color.WHITE,dopdeck,pool);
|
||||
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 DrawingTriangleDeck();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,5 @@ import java.awt.*;
|
||||
|
||||
public interface IAdditionalDrawingObject {
|
||||
void SetAddEnum(int decksAmount);
|
||||
int GetDeckEnum();
|
||||
void DrawDeck(Color colorDeck, Graphics g, float _startPosX, float _startPosY);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,4 @@ public interface IDrawingObject {
|
||||
void MoveObject(Direction direction);
|
||||
void DrawingObject(Graphics g);
|
||||
float[] GetCurrentPosition();
|
||||
public DrawingShip GetDrawingObjectShip();
|
||||
String GetInfo();
|
||||
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ import javax.swing.*;
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
JFrame frame = new JFrame("Лайнер");
|
||||
frame.setContentPane(new FormMapWithSetShipsGeneric().Mainpanel);
|
||||
frame.setContentPane(new FormMap().MainPanel);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setLocation(500, 200);
|
||||
frame.pack();
|
||||
frame.setSize(800, 500);
|
||||
frame.setSize(500, 500);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,176 +0,0 @@
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class MapWithSetShipsGeneric<T extends IDrawingObject, U extends AbstractMap> {
|
||||
private final int _pictureWidth;
|
||||
private final int _pictureHeight;
|
||||
private final int _placeSizeWidth = 170;
|
||||
private final int _placeSizeHeight = 90;
|
||||
private final SetShipsGeneric<T> _setShips;
|
||||
private final U _map;
|
||||
private LinkedList<T> _deletedShips;
|
||||
public MapWithSetShipsGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
_deletedShips=new LinkedList<>();
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setShips = new SetShipsGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
public int Add(T ship)
|
||||
{
|
||||
return _setShips.Insert(ship);
|
||||
}
|
||||
public T Delete(int position)
|
||||
{
|
||||
T ship=_setShips.Remove(position);
|
||||
_deletedShips.add(ship);
|
||||
return ship;
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
_setShips.Clear();
|
||||
}
|
||||
public BufferedImage ShowSet()
|
||||
{
|
||||
BufferedImage bmp = new BufferedImage(_pictureWidth,_pictureHeight,BufferedImage.TYPE_INT_RGB);
|
||||
Graphics gr = bmp.getGraphics();
|
||||
DrawBackground(gr);
|
||||
DrawShips(gr);
|
||||
return bmp;
|
||||
}
|
||||
public BufferedImage ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for(var ship : _setShips)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth,_pictureHeight,ship);
|
||||
}
|
||||
return new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_RGB);
|
||||
}
|
||||
public BufferedImage MoveObject(Direction direction)
|
||||
{
|
||||
if (_map != null)
|
||||
{
|
||||
return _map.MoveObject(direction);
|
||||
}
|
||||
return new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_RGB);
|
||||
}
|
||||
private void Shaking()
|
||||
{
|
||||
int j = _setShips.Count() - 1;
|
||||
for (int i = 0; i < _setShips.Count(); i++)
|
||||
{
|
||||
if (_setShips.Get(i) == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var ship = _setShips.Get(j);
|
||||
if (ship != null)
|
||||
{
|
||||
_setShips.Insert(ship, i);
|
||||
_setShips.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void DrawBackground(Graphics gr)
|
||||
{
|
||||
Graphics2D g = (Graphics2D) gr;
|
||||
g.setColor(Color.BLUE);
|
||||
g.fillRect( 0, 0, _pictureWidth, _pictureHeight);
|
||||
Color c = new Color(89,51,5);
|
||||
g.setStroke(new BasicStroke(2));
|
||||
g.setColor(c);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{
|
||||
g.drawLine(i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2 + 40, j * _placeSizeHeight);
|
||||
}
|
||||
g.drawLine(i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
g.drawLine(i * _placeSizeWidth - 4, 0, i * _placeSizeWidth - 4, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
private void DrawShips(Graphics g)
|
||||
{
|
||||
int widthEl = _pictureWidth / _placeSizeWidth;
|
||||
int heightEl = _pictureHeight / _placeSizeHeight;
|
||||
int curWidth = 1;
|
||||
int curHeight = 0;
|
||||
for (int i = 0; i < _setShips.Count(); i++)
|
||||
{
|
||||
if(_setShips.Get(i)==null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
_setShips.Get(i).SetObject(_pictureWidth - _placeSizeWidth * curWidth - (_pictureWidth / 7),
|
||||
curHeight * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
||||
_setShips.Get(i).DrawingObject(g);
|
||||
|
||||
if (curWidth < widthEl)
|
||||
curWidth++;
|
||||
else
|
||||
{
|
||||
curWidth = 1;
|
||||
curHeight++;
|
||||
}
|
||||
if (curHeight > heightEl)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public String GetDataForMap(char separatorType,char separatorData,boolean IsInfoMap)
|
||||
{
|
||||
if(IsInfoMap)
|
||||
{
|
||||
StringBuilder data=new StringBuilder(String.format("%s%c",_map.getClass().getSimpleName(),separatorType));
|
||||
return data.toString();
|
||||
}
|
||||
StringBuilder data=new StringBuilder();
|
||||
for (var ship: _setShips)
|
||||
{
|
||||
data.append(String.format("%s%c",ship.GetInfo(),separatorData));
|
||||
}
|
||||
return data.toString();
|
||||
}
|
||||
public String GetData(char separatorType,char separatorData)
|
||||
{
|
||||
StringBuilder data=new StringBuilder(String.format("%s%c",_map.getClass().getSimpleName(),separatorType));
|
||||
for (var ship: _setShips)
|
||||
{
|
||||
data.append(String.format("%s%c",ship.GetInfo(),separatorData));
|
||||
}
|
||||
return data.toString();
|
||||
}
|
||||
public void LoadData(String[] records)
|
||||
{
|
||||
for(var rec:records)
|
||||
{
|
||||
_setShips.Insert((T) DrawingObjectShip.Create(rec));
|
||||
}
|
||||
}
|
||||
public T GetSelectedShip(int ind){
|
||||
return _setShips.Get(ind);
|
||||
}
|
||||
public T GetShipsDeleted()
|
||||
{
|
||||
if(_deletedShips.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _deletedShips.poll();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,165 +0,0 @@
|
||||
import java.io.*;
|
||||
import java.util.AbstractCollection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class MapsCollection {
|
||||
private final HashMap<String,MapWithSetShipsGeneric<IDrawingObject, AbstractMap>> _mapStorages;
|
||||
public ArrayList<String> Keys()
|
||||
{
|
||||
return new ArrayList<>(_mapStorages.keySet());
|
||||
}
|
||||
private final int _pictureWidth;
|
||||
private final int _pictureHeight;
|
||||
private final char separatorDict = '|';
|
||||
private final char separatorData = ';';
|
||||
|
||||
public MapsCollection(int pictureWidth,int pictureHeight)
|
||||
{
|
||||
_mapStorages=new HashMap<>();
|
||||
_pictureWidth=pictureWidth;
|
||||
_pictureHeight=pictureHeight;
|
||||
}
|
||||
public void AddMap(String Name, AbstractMap Map)
|
||||
{
|
||||
if(!_mapStorages.containsKey(Name))
|
||||
{
|
||||
_mapStorages.put(Name,new MapWithSetShipsGeneric<>(_pictureWidth,_pictureHeight,Map));
|
||||
}
|
||||
}
|
||||
public void DelMap(String name)
|
||||
{
|
||||
_mapStorages.remove(name);
|
||||
}
|
||||
public MapWithSetShipsGeneric<IDrawingObject,AbstractMap> Get(String ind)
|
||||
{
|
||||
if(_mapStorages.containsKey(ind))
|
||||
{
|
||||
return _mapStorages.get(ind);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public IDrawingObject Get(String name, int ind) {
|
||||
if (_mapStorages.containsKey(name))
|
||||
{
|
||||
return _mapStorages.get(name).GetSelectedShip(ind);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public boolean SaveData(String filename) throws IOException {
|
||||
File file = new File(filename);
|
||||
if(file.exists())
|
||||
{
|
||||
file.delete();
|
||||
}
|
||||
try(BufferedWriter fw = new BufferedWriter(new FileWriter(file)))
|
||||
{
|
||||
fw.write(String.format("MapsCollection%s",System.lineSeparator()));
|
||||
for(var storage:_mapStorages.keySet())
|
||||
{
|
||||
fw.write(String.format("%s%c%s%s",storage,separatorDict,_mapStorages.get(storage).GetData(separatorDict,separatorData),System.lineSeparator()));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public boolean LoadData(String filename) throws IOException {
|
||||
File file=new File(filename);
|
||||
if(!file.exists())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try(BufferedReader fr = new BufferedReader(new FileReader(file)))
|
||||
{
|
||||
String str="";
|
||||
if((str=fr.readLine())==null || !str.contains("MapsCollection"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_mapStorages.clear();
|
||||
while((str=fr.readLine())!=null)
|
||||
{
|
||||
var tempElem = str.split(String.format("\\%c",separatorDict));
|
||||
AbstractMap map =null;
|
||||
switch (tempElem[1])
|
||||
{
|
||||
case "SimpleMap":
|
||||
map=new SimpleMap();
|
||||
break;
|
||||
case "SeaMap":
|
||||
map=new SeaMap();
|
||||
break;
|
||||
}
|
||||
_mapStorages.put(tempElem[0],new MapWithSetShipsGeneric<IDrawingObject,AbstractMap>(_pictureWidth,_pictureHeight,map));
|
||||
if(tempElem.length==3)
|
||||
{
|
||||
_mapStorages.get(tempElem[0]).LoadData(tempElem[2].split(String.valueOf(separatorData)));
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public boolean SaveMapData(String filename,String Key)throws IOException
|
||||
{
|
||||
File file = new File(filename);
|
||||
if(file.exists())
|
||||
{
|
||||
file.delete();
|
||||
}
|
||||
try(BufferedWriter fw = new BufferedWriter(new FileWriter(file)))
|
||||
{
|
||||
fw.write(String.format("Map_Info:%s",System.lineSeparator()));
|
||||
var Map = _mapStorages.get(Key);
|
||||
fw.write(String.format("%s%c%s%s",Key,separatorDict,Map.GetDataForMap(separatorDict,separatorData,true),System.lineSeparator()));
|
||||
fw.write(String.format("Objects_In_Map_Info:%s",System.lineSeparator()));
|
||||
fw.write(String.format("%s%s",Map.GetDataForMap(separatorDict,separatorData,false),System.lineSeparator()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public boolean LoadMapData(String filename) throws IOException {
|
||||
File file=new File(filename);
|
||||
if(!file.exists())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try(BufferedReader fr = new BufferedReader(new FileReader(file)))
|
||||
{
|
||||
String str="";
|
||||
if((str=fr.readLine())==null || !str.contains("Map_Info:"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
str=fr.readLine();
|
||||
var tempElem = str.split(String.format("\\%c",separatorDict));
|
||||
|
||||
AbstractMap map =null;
|
||||
switch (tempElem[1])
|
||||
{
|
||||
case "SimpleMap":
|
||||
map=new SimpleMap();
|
||||
break;
|
||||
case "SeaMap":
|
||||
map=new SeaMap();
|
||||
break;
|
||||
}
|
||||
if(_mapStorages.containsKey(tempElem[0]))
|
||||
{
|
||||
MapWithSetShipsGeneric<IDrawingObject, AbstractMap> storage = _mapStorages.get(tempElem[0]);
|
||||
storage.Clear();
|
||||
}
|
||||
_mapStorages.put(tempElem[0], new MapWithSetShipsGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
String str_second=fr.readLine();
|
||||
if(!str_second.contains("Objects_In_Map_Info:"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
str_second= fr.readLine();
|
||||
str=str+str_second;
|
||||
System.out.println(str);
|
||||
tempElem = str.split(String.format("\\%c",separatorDict));
|
||||
if(tempElem.length==3) {
|
||||
_mapStorages.get(tempElem[0]).LoadData(tempElem[2].split(String.valueOf(separatorData)));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
public class SetShipsGeneric<T extends Object> implements Iterable<T>{
|
||||
private ArrayList<T> _places;
|
||||
private final int _maxCount;
|
||||
public int Count()
|
||||
{
|
||||
return _places.size();
|
||||
}
|
||||
public SetShipsGeneric(int count)
|
||||
{
|
||||
_maxCount=count;
|
||||
_places = new ArrayList<>();
|
||||
}
|
||||
public int Insert(T ship)
|
||||
{
|
||||
return Insert(ship, 0);
|
||||
}
|
||||
public int Insert(T ship, int position)
|
||||
{
|
||||
if (position < 0 || position > Count() || _maxCount == Count()) return -1;
|
||||
_places.add(position,ship);
|
||||
return position;
|
||||
}
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position >= Count() || position < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
T ship = (T) _places.get(position);
|
||||
_places.remove(ship);
|
||||
return ship;
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
_places.clear();
|
||||
}
|
||||
public T Get(int position)
|
||||
{
|
||||
if (position >= Count() || position<0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places.get(position);
|
||||
}
|
||||
public void Set(int position,T value)
|
||||
{
|
||||
if (position < _maxCount || position >= 0)
|
||||
{
|
||||
Insert(value,position);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return _places.iterator();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user