Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bc291cc897 | |||
| 5c220f9137 | |||
| 2d2c2e534e | |||
| e7eeab907a | |||
| 241c0d1b6e | |||
| 121852d4aa | |||
| ab6a88a7ea | |||
| 83aa36939d | |||
| 2ee60e7467 | |||
| b168da6f55 | |||
| 91789623d2 | |||
| 518b864351 | |||
| 4d2f245c10 | |||
| eff027d948 |
@@ -7,5 +7,14 @@
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/Downloads/apache-log4j-1.2.17/log4j-1.2.17.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
</component>
|
||||
</module>
|
||||
0
loginfo.log
Normal file
0
loginfo.log
Normal file
0
logwarn.log
Normal file
0
logwarn.log
Normal file
@@ -126,4 +126,39 @@ public abstract class AbstractMap {
|
||||
protected abstract void GenerateMap();
|
||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == null) {
|
||||
return false;
|
||||
}
|
||||
AbstractMap otherMap = (AbstractMap) other;
|
||||
if (otherMap == null) {
|
||||
return false;
|
||||
}
|
||||
if (_width != otherMap._width) {
|
||||
return false;
|
||||
}
|
||||
if (_height != otherMap._height) {
|
||||
return false;
|
||||
}
|
||||
if (_size_x != otherMap._size_x)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_size_y != otherMap._size_y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for(int i = 0; i < _map.length; i++)
|
||||
{
|
||||
for (int j = 0; j < _map[i].length; j++)
|
||||
{
|
||||
if (_map[i][j] != otherMap._map[i][j])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,11 @@ 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,17 +1,37 @@
|
||||
import java.awt.*;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class DrawingLiner extends DrawingShip
|
||||
{
|
||||
public DrawingLiner(int speed, float weight, Color bodyColor,Color dopColor,boolean dopDeck,boolean pool)
|
||||
private Color dopColor;
|
||||
public DrawingLiner(int speed, float weight, Color bodyColor,int numdeck,Color dopColor,boolean dopDeck,boolean pool)
|
||||
{
|
||||
super(speed,weight,bodyColor,130,45);
|
||||
super(speed,weight,bodyColor,numdeck,130,45);
|
||||
fields = new Object[]{ speed, weight, bodyColor,Deck,numdeck, dopColor, dopDeck, pool };
|
||||
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;
|
||||
fields[5]=dopColor;
|
||||
|
||||
}
|
||||
@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);
|
||||
fields[2]=color;
|
||||
}
|
||||
@Override
|
||||
public void DrawTransport(Graphics gr) {
|
||||
Graphics2D g2d = (Graphics2D) gr;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import java.awt.*;
|
||||
import java.util.Objects;
|
||||
|
||||
public class DrawingObjectShip implements IDrawingObject {
|
||||
private DrawingShip _ship = null;
|
||||
@@ -13,6 +14,7 @@ public class DrawingObjectShip implements IDrawingObject {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public DrawingShip GetDrawingObjectShip() {
|
||||
return _ship;
|
||||
}
|
||||
@@ -34,5 +36,73 @@ 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));
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object other)
|
||||
{
|
||||
if(other==null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(!(other instanceof DrawingObjectShip otherShip))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
EntityShip ship=_ship.Ship;
|
||||
EntityShip otherShipShip=otherShip._ship.Ship;
|
||||
if(!(ship.getClass().getSimpleName().equals(otherShipShip.getClass().getSimpleName())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(ship.GetSpeed() != otherShipShip.GetSpeed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(ship.GetWeight() != otherShipShip.GetWeight())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(ship.GetBodyColor().toString(), otherShipShip.GetBodyColor().toString()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(_ship.GetDeck().getClass()!=otherShip._ship.GetDeck().getClass())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(_ship.GetDeck().GetDeckEnum()!=otherShip._ship.GetDeck().GetDeckEnum())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(ship instanceof EntityLiner Liner && otherShipShip instanceof EntityLiner otherLiner)
|
||||
{
|
||||
if(!Objects.equals(Liner.DopColor.toString(), otherLiner.DopColor.toString()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(Liner.Pool != otherLiner.Pool)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(Liner.DopDeck != otherLiner.DopDeck)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,6 +15,11 @@ 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,34 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
public class DrawingShip extends JPanel {
|
||||
import java.util.Set;
|
||||
|
||||
public class DrawingShip extends JComponent implements Iterable<Object>, Iterator<Object> {
|
||||
protected EntityShip Ship;
|
||||
public IAdditionalDrawingObject Deck;
|
||||
public void SetEnum() {
|
||||
Random r = new Random();
|
||||
int numbEnum = r.nextInt(1, 4);
|
||||
Deck.SetAddEnum(numbEnum);
|
||||
}
|
||||
public void SetFormEnum()
|
||||
protected IAdditionalDrawingObject Deck;
|
||||
private int currentIndex = 0;
|
||||
protected Object[] fields;
|
||||
public void SetColor(Color color)
|
||||
{
|
||||
Random r = new Random();
|
||||
int numbEnum = r.nextInt(1, 4);
|
||||
if (numbEnum == 1) {
|
||||
Deck=new DrawingDeck();
|
||||
}
|
||||
if (numbEnum == 2) {
|
||||
Deck = new DrawingOvalDeck();
|
||||
}
|
||||
if (numbEnum == 3) {
|
||||
Deck=new DrawingTriangleDeck();
|
||||
}
|
||||
Ship=new EntityShip(Ship.GetSpeed(),Ship.GetWeight(),color);
|
||||
fields[2]=color;
|
||||
}
|
||||
public IAdditionalDrawingObject GetDeck()
|
||||
{
|
||||
return Deck;
|
||||
}
|
||||
public void SetFormEnum(int decksnum,IAdditionalDrawingObject deck)
|
||||
{
|
||||
Deck=deck;
|
||||
Deck.SetAddEnum(decksnum);
|
||||
fields[3]=Deck;
|
||||
fields[4]=Deck.GetDeckEnum();
|
||||
}
|
||||
public void SetDeck(IAdditionalDrawingObject deck)
|
||||
{
|
||||
Deck=deck;
|
||||
fields[3]=Deck;
|
||||
}
|
||||
public EntityShip GetShip() {
|
||||
return Ship;
|
||||
@@ -32,21 +39,37 @@ public class DrawingShip extends JPanel {
|
||||
private Integer _pictureHeight = null;
|
||||
private int _ShipWidth = 120;
|
||||
private int _ShipHeight = 40;
|
||||
public DrawingShip(int speed, float weight, Color bodycolor) {
|
||||
|
||||
public DrawingShip(int speed, float weight, Color bodycolor,int numdeck) {
|
||||
Ship = new EntityShip(speed, weight, bodycolor);
|
||||
SetFormEnum();
|
||||
SetEnum();
|
||||
Deck = new DrawingTriangleDeck();
|
||||
fields = new Object[]{speed, weight, bodycolor,Deck,numdeck};
|
||||
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);
|
||||
|
||||
}
|
||||
public DrawingShip(int speed,float weight,Color bodyColor,int shipWidth,int shipHeight)
|
||||
public DrawingShip(int speed,float weight,Color bodyColor,int numdeck,int shipWidth,int shipHeight)
|
||||
{
|
||||
this(speed,weight,bodyColor);
|
||||
this(speed,weight,bodyColor,numdeck);
|
||||
_ShipWidth = shipWidth;
|
||||
_ShipHeight = shipHeight;
|
||||
|
||||
}
|
||||
protected DrawingShip(EntityShip ship,IAdditionalDrawingObject deck)
|
||||
{
|
||||
Ship=ship;
|
||||
Deck=deck;
|
||||
fields = new Object[]{ ship.GetSpeed(), ship.GetWeight(), ship.GetBodyColor(),Deck,Deck.GetDeckEnum() };
|
||||
}
|
||||
public void SetPosition(int x, int y, int width, int height) {
|
||||
if (width <= _ShipWidth + x || height <= _ShipHeight + y || x < 0 || y < 0) {
|
||||
@@ -121,4 +144,22 @@ public class DrawingShip extends JPanel {
|
||||
{
|
||||
return new float[] {/*UP*/_startPosY, /*RIGHT*/ _startPosX + _ShipWidth, /*DOWN*/ _startPosY + _ShipHeight, /*LEFT*/ _startPosX};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Object> iterator()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return currentIndex < fields.length && fields[currentIndex] != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object next()
|
||||
{
|
||||
return fields[currentIndex++];
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,11 @@ 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);
|
||||
|
||||
51
src/ExtentionShip.java
Normal file
51
src/ExtentionShip.java
Normal file
@@ -0,0 +1,51 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
<?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="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<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="526"/>
|
||||
<xy x="20" y="20" width="798" height="601"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="9bb5a" binding="pictureBoxShip" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="3" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<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"/>
|
||||
@@ -22,20 +22,20 @@
|
||||
</grid>
|
||||
<hspacer id="b305e">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<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">
|
||||
<grid id="4fa91" binding="GroupBoxTools" layout-manager="GridLayoutManager" row-count="10" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="3" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<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"/>
|
||||
<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="Добавить корабль"/>
|
||||
@@ -43,7 +43,7 @@
|
||||
</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">
|
||||
<grid row="3" 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>
|
||||
@@ -51,7 +51,7 @@
|
||||
</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"/>
|
||||
<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="Удалить корабль"/>
|
||||
@@ -59,7 +59,7 @@
|
||||
</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"/>
|
||||
<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="Показать хранилище"/>
|
||||
@@ -67,7 +67,7 @@
|
||||
</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"/>
|
||||
<grid row="6" 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="Показать карту"/>
|
||||
@@ -75,7 +75,7 @@
|
||||
</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">
|
||||
<grid row="8" 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"/>
|
||||
@@ -87,7 +87,7 @@
|
||||
</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">
|
||||
<grid row="9" 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"/>
|
||||
@@ -99,7 +99,7 @@
|
||||
</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">
|
||||
<grid row="9" 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"/>
|
||||
@@ -111,7 +111,7 @@
|
||||
</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">
|
||||
<grid row="9" 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"/>
|
||||
@@ -123,25 +123,41 @@
|
||||
</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"/>
|
||||
<grid row="7" 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="4226" class="javax.swing.JButton" binding="ButtonSortByType">
|
||||
<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="2dae0" class="javax.swing.JButton" binding="ButtonSortByColor">
|
||||
<constraints>
|
||||
<grid row="1" 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="7" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<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="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<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="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<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>
|
||||
@@ -149,12 +165,12 @@
|
||||
</component>
|
||||
<vspacer id="3ed0f">
|
||||
<constraints>
|
||||
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
<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="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<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>
|
||||
@@ -165,7 +181,7 @@
|
||||
</component>
|
||||
<component id="fb777" class="javax.swing.JButton" binding="ButtonAddMap">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<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="Добавить карту"/>
|
||||
@@ -173,20 +189,15 @@
|
||||
</component>
|
||||
<component id="a358a" class="javax.swing.JButton" binding="ButtonDeleteMap">
|
||||
<constraints>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<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>
|
||||
<vspacer id="64e67">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="e221" class="javax.swing.JList" binding="ListBoxMaps" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<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>
|
||||
@@ -194,6 +205,61 @@
|
||||
</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>
|
||||
|
||||
@@ -6,7 +6,12 @@ import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.log4j.*;
|
||||
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
@@ -24,20 +29,29 @@ public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
private JButton ButtonRight;
|
||||
private JTextField maskedTextBoxPosition;
|
||||
private JTextField textBoxNewMapName;
|
||||
private int picWidth=600;
|
||||
|
||||
private int picHeight=400;
|
||||
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 JButton ButtonSortByType;
|
||||
private JButton ButtonSortByColor;
|
||||
private MapWithSetShipsGeneric<DrawingObjectShip,AbstractMap> _mapShipsCollectionGeneric;
|
||||
private final HashMap<String,AbstractMap> _mapsDict = new HashMap<>(){{
|
||||
put("Простая карта",new SimpleMap());
|
||||
put("Карта море",new SeaMap());
|
||||
}};
|
||||
private final MapsCollection _mapsCollection;
|
||||
private static Logger _logger = Logger.getLogger("FormMapWithSetShipsGeneric");
|
||||
public void UpdateWindow(BufferedImage bmp)
|
||||
{
|
||||
pictureBoxShip.removeAll();
|
||||
@@ -88,24 +102,35 @@ public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
ButtonAddShip.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (ListBoxMaps.getSelectedIndex() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormShip form = new FormShip();
|
||||
form.setSize(1000,700);
|
||||
form.setVisible(true);
|
||||
form.setModal(true);
|
||||
DrawingObjectShip ship = new DrawingObjectShip(form.GetSelectedShip());
|
||||
if(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).Add(ship)!=-1)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,"Объект добавлен");
|
||||
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
|
||||
}
|
||||
FormShipConfig formShipConfig = new FormShipConfig();
|
||||
formShipConfig.AddEvent(newShip -> {
|
||||
try
|
||||
{
|
||||
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, "Объект добавлен");
|
||||
_logger.log(Level.INFO,"Добавлен объект: "+ship);
|
||||
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "Не удалось добавить объект","Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||
_logger.log(Level.INFO,"Не удалось добавить объект:"+ship);
|
||||
}
|
||||
}
|
||||
}catch (StorageOverflowException ex)
|
||||
{
|
||||
_logger.log(Level.WARN,"Ошибка переполнения хранилища: "+ex.getMessage());
|
||||
JOptionPane.showMessageDialog(null, "Ошибка переполнения хранилища: "+ex.getMessage(),"Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(null, "Неизвестная ошибка: "+ex.getMessage(),"Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||
_logger.log(Level.FATAL,"Неизвестная ошибка: "+ex.getMessage());
|
||||
}
|
||||
});
|
||||
formShipConfig.setSize(850, 300);
|
||||
formShipConfig.setVisible(true);
|
||||
}
|
||||
});
|
||||
ListBoxMaps.addListSelectionListener(new ListSelectionListener() {
|
||||
@@ -114,6 +139,7 @@ public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
if (ListBoxMaps.getSelectedIndex() == -1)
|
||||
return;
|
||||
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
|
||||
_logger.log(Level.INFO, "Переход на карту: "+ListBoxMaps.getSelectedValue().toString());
|
||||
}
|
||||
});
|
||||
ButtonDeleteShip.addActionListener(new ActionListener() {
|
||||
@@ -129,14 +155,26 @@ public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
return;
|
||||
}
|
||||
int pos=Integer.parseInt(maskedTextBoxPosition.getText());
|
||||
if(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).Delete(pos)!=null)
|
||||
try
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Объект удален");
|
||||
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не удалось удалить объект");
|
||||
var delShip = _mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).Delete(pos);
|
||||
if(delShip!=null)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Объект удален");
|
||||
_logger.log(Level.INFO,"Объект удален"+delShip);
|
||||
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не удалось удалить объект","Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||
_logger.log(Level.INFO,"Не удалось удалить объект"+delShip);
|
||||
}
|
||||
} catch (ShipNotFoundException ex) {
|
||||
JOptionPane.showMessageDialog(null, "Ошибка удаления: "+ex.getMessage(),"Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||
_logger.log(Level.WARN,"Ошибка удаления: "+ex.getMessage());
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(null, "Неизвестная ошибка: "+ex.getMessage(),"Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||
_logger.log(Level.FATAL,"Неизвестная ошибка: "+ex.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -244,13 +282,16 @@ public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
if (ComboBoxSelectorMap.getSelectedIndex() == -1 || textBoxNewMapName.getText().isEmpty())
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,"Не все данные заполнены","Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||
_logger.log(Level.ERROR,"Не все данные заполнены");
|
||||
return;
|
||||
}
|
||||
if(!_mapsDict.containsKey(ComboBoxSelectorMap.getSelectedItem()))
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,"Нет такой карты","Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||
_logger.log(Level.ERROR,"Нет такой карты");
|
||||
}
|
||||
_mapsCollection.AddMap(textBoxNewMapName.getText(),_mapsDict.get(ComboBoxSelectorMap.getSelectedItem().toString()));
|
||||
_logger.log(Level.INFO,"Добавлена карта: "+textBoxNewMapName.getText());
|
||||
ReloadMaps();
|
||||
}
|
||||
});
|
||||
@@ -264,6 +305,7 @@ public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
if(JOptionPane.showConfirmDialog(null,"Удалить карту"+ListBoxMaps.getSelectedValue().toString()+"?","Удаление",JOptionPane.YES_NO_OPTION)==0)
|
||||
{
|
||||
_mapsCollection.DelMap(ListBoxMaps.getSelectedValue().toString());
|
||||
_logger.log(Level.INFO, "Удалена карта: "+ListBoxMaps.getSelectedValue().toString());
|
||||
ReloadMaps();
|
||||
}
|
||||
}
|
||||
@@ -275,7 +317,7 @@ public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
{
|
||||
return;
|
||||
}
|
||||
DrawingObjectShip ship=_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).GetShipsDeleted();
|
||||
IDrawingObject ship=_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).GetShipsDeleted();
|
||||
if(ship==null)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,"Коллекция пуста","Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||
@@ -286,6 +328,111 @@ public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
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 {
|
||||
File selectedFile=fc.getSelectedFile();
|
||||
_mapsCollection.SaveData(selectedFile.getPath());
|
||||
JOptionPane.showMessageDialog(null, "Сохранение прошло успешно", "Результат",JOptionPane.INFORMATION_MESSAGE);
|
||||
_logger.log(Level.INFO,"Сохранение прошло успешно");
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(null, "Не сохранилось: "+ex.getMessage(), "Результат",JOptionPane.ERROR_MESSAGE);
|
||||
_logger.log(Level.ERROR,"Не сохранилось: "+ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
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 {
|
||||
File selectedFile=fc.getSelectedFile();
|
||||
_mapsCollection.LoadData(selectedFile.getPath());
|
||||
ReloadMaps();
|
||||
JOptionPane.showMessageDialog(null, "Загрузка прошла успешно", "Результат",JOptionPane.INFORMATION_MESSAGE);
|
||||
_logger.log(Level.INFO,"Загрузка прошло успешно");
|
||||
} catch (FileNotFoundException | IllegalArgumentException ex ) {
|
||||
JOptionPane.showMessageDialog(null, "Не загрузилось: "+ex.getMessage(), "Результат",JOptionPane.ERROR_MESSAGE);
|
||||
_logger.log(Level.ERROR,"Не загрузилось: "+ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
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 {
|
||||
File selectedFile=fc.getSelectedFile();
|
||||
_mapsCollection.SaveMapData(selectedFile.getPath(),ListBoxMaps.getSelectedValue().toString());
|
||||
JOptionPane.showMessageDialog(null, "Сохранение прошло успешно", "Результат",JOptionPane.INFORMATION_MESSAGE);
|
||||
_logger.log(Level.INFO,"Сохранение прошло успешно");
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(null, "Не сохранилось: "+ex.getMessage(), "Результат",JOptionPane.ERROR_MESSAGE);
|
||||
_logger.log(Level.ERROR,"Не сохранилось: "+ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
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 {
|
||||
File selectedFile=fc.getSelectedFile();
|
||||
_mapsCollection.LoadMapData(selectedFile.getPath());
|
||||
ReloadMaps();
|
||||
JOptionPane.showMessageDialog(null, "Загрузка прошла успешно", "Результат",JOptionPane.INFORMATION_MESSAGE);
|
||||
_logger.log(Level.INFO,"Загрузка прошло успешно");
|
||||
} catch (FileNotFoundException | IllegalArgumentException ex ) {
|
||||
JOptionPane.showMessageDialog(null, "Не загрузилось: "+ex.getMessage(), "Результат",JOptionPane.ERROR_MESSAGE);
|
||||
_logger.log(Level.ERROR,"Не загрузилось: "+ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
ButtonSortByType.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (ListBoxMaps.getSelectedIndex() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).Sort(new ShipCompareByType());
|
||||
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
|
||||
}
|
||||
});
|
||||
ButtonSortByColor.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (ListBoxMaps.getSelectedIndex() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).Sort(new ShipCompareByColor());
|
||||
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
|
||||
@@ -25,6 +25,11 @@ public class FormShip extends JDialog{
|
||||
{
|
||||
return SelectedShip;
|
||||
}
|
||||
public int SetEnum() {
|
||||
Random r = new Random();
|
||||
int numbEnum = r.nextInt(1, 4);
|
||||
return numbEnum;
|
||||
}
|
||||
public void Draw(DrawingShip _ship) {
|
||||
pictureBoxShip.removeAll();
|
||||
BufferedImage bmp = new BufferedImage(pictureBoxShip.getWidth(), pictureBoxShip.getHeight(),BufferedImage.TYPE_INT_RGB);
|
||||
@@ -41,7 +46,7 @@ public class FormShip extends JDialog{
|
||||
}
|
||||
validate();
|
||||
}
|
||||
public FormShip(DrawingObjectShip ship)
|
||||
public FormShip(IDrawingObject ship)
|
||||
{
|
||||
super(new Frame("Лайнер"));
|
||||
CreateWindow();
|
||||
@@ -82,7 +87,7 @@ public class FormShip extends JDialog{
|
||||
public void actionPerformed(ActionEvent e){
|
||||
Random random = new Random();
|
||||
Color colorFirst = JColorChooser.showDialog(null, "Цвет", null);
|
||||
_ship=new DrawingShip(random.nextInt(100, 300), random.nextInt(1000, 2000), colorFirst);
|
||||
_ship=new DrawingShip(random.nextInt(100, 300), random.nextInt(1000, 2000), colorFirst,SetEnum());
|
||||
_ship.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), pictureBoxShip.getWidth(), pictureBoxShip.getHeight());
|
||||
JLabelSpeed.setText("Cкорость: " + _ship.GetShip().GetSpeed() + " ");
|
||||
JLabelWeight.setText("Вес: " + _ship.GetShip().GetWeight() + " ");
|
||||
@@ -141,7 +146,7 @@ public class FormShip extends JDialog{
|
||||
Random random = new Random();
|
||||
Color colorFirst = JColorChooser.showDialog(null, "Цвет", null);
|
||||
Color colorSecond = JColorChooser.showDialog(null, "Цвет", null);
|
||||
_ship=new DrawingLiner(random.nextInt(100, 300), random.nextInt(1000, 2000), colorFirst,colorSecond,random.nextBoolean(),random.nextBoolean());
|
||||
_ship=new DrawingLiner(random.nextInt(100, 300), random.nextInt(1000, 2000), colorFirst,SetEnum(),colorSecond,random.nextBoolean(),random.nextBoolean());
|
||||
_ship.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), pictureBoxShip.getWidth(), pictureBoxShip.getHeight());
|
||||
JLabelSpeed.setText("Cкорость: " + _ship.GetShip().GetSpeed() + " ");
|
||||
JLabelWeight.setText("Вес: " + _ship.GetShip().GetWeight() + " ");
|
||||
|
||||
338
src/FormShipConfig.form
Normal file
338
src/FormShipConfig.form
Normal file
@@ -0,0 +1,338 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormShipConfig">
|
||||
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="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>
|
||||
247
src/FormShipConfig.java
Normal file
247
src/FormShipConfig.java
Normal file
@@ -0,0 +1,247 @@
|
||||
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,5 +2,6 @@ import java.awt.*;
|
||||
|
||||
public interface IAdditionalDrawingObject {
|
||||
void SetAddEnum(int decksAmount);
|
||||
int GetDeckEnum();
|
||||
void DrawDeck(Color colorDeck, Graphics g, float _startPosX, float _startPosY);
|
||||
}
|
||||
|
||||
@@ -6,4 +6,7 @@ public interface IDrawingObject {
|
||||
void MoveObject(Direction direction);
|
||||
void DrawingObject(Graphics g);
|
||||
float[] GetCurrentPosition();
|
||||
public DrawingShip GetDrawingObjectShip();
|
||||
String GetInfo();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class MapWithSetShipsGeneric<T extends IDrawingObject, U extends AbstractMap> {
|
||||
public class MapWithSetShipsGeneric<T extends IDrawingObject, U extends AbstractMap> implements Comparable<MapWithSetShipsGeneric>{
|
||||
private final int _pictureWidth;
|
||||
private final int _pictureHeight;
|
||||
private final int _placeSizeWidth = 170;
|
||||
@@ -20,16 +21,18 @@ public class MapWithSetShipsGeneric<T extends IDrawingObject, U extends Abstrac
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
public int Add(T ship)
|
||||
{
|
||||
public int Add(T ship) throws StorageOverflowException {
|
||||
return _setShips.Insert(ship);
|
||||
}
|
||||
public T Delete(int position)
|
||||
{
|
||||
public T Delete(int position) throws ShipNotFoundException {
|
||||
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);
|
||||
@@ -38,8 +41,7 @@ public class MapWithSetShipsGeneric<T extends IDrawingObject, U extends Abstrac
|
||||
DrawShips(gr);
|
||||
return bmp;
|
||||
}
|
||||
public BufferedImage ShowOnMap()
|
||||
{
|
||||
public BufferedImage ShowOnMap(){
|
||||
Shaking();
|
||||
for(var ship : _setShips)
|
||||
{
|
||||
@@ -55,8 +57,7 @@ public class MapWithSetShipsGeneric<T extends IDrawingObject, U extends Abstrac
|
||||
}
|
||||
return new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_RGB);
|
||||
}
|
||||
private void Shaking()
|
||||
{
|
||||
private void Shaking(){
|
||||
int j = _setShips.Count() - 1;
|
||||
for (int i = 0; i < _setShips.Count(); i++)
|
||||
{
|
||||
@@ -67,8 +68,16 @@ public class MapWithSetShipsGeneric<T extends IDrawingObject, U extends Abstrac
|
||||
var ship = _setShips.Get(j);
|
||||
if (ship != null)
|
||||
{
|
||||
_setShips.Insert(ship, i);
|
||||
_setShips.Remove(j);
|
||||
try {
|
||||
_setShips.Insert(ship, i);
|
||||
} catch (StorageOverflowException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
try {
|
||||
_setShips.Remove(j);
|
||||
} catch (ShipNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -127,6 +136,35 @@ public class MapWithSetShipsGeneric<T extends IDrawingObject, U extends Abstrac
|
||||
|
||||
}
|
||||
}
|
||||
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) throws StorageOverflowException {
|
||||
for(var rec:records)
|
||||
{
|
||||
_setShips.Insert((T) DrawingObjectShip.Create(rec));
|
||||
}
|
||||
}
|
||||
public T GetSelectedShip(int ind){
|
||||
return _setShips.Get(ind);
|
||||
}
|
||||
@@ -138,5 +176,23 @@ public class MapWithSetShipsGeneric<T extends IDrawingObject, U extends Abstrac
|
||||
}
|
||||
return _deletedShips.poll();
|
||||
}
|
||||
public void Sort(Comparator<T> comparer)
|
||||
{
|
||||
_setShips.SortSet(comparer);
|
||||
}
|
||||
@Override
|
||||
public int compareTo(MapWithSetShipsGeneric o) {
|
||||
if (o == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (this == o)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
Integer temp1=(Integer) _setShips.Count();
|
||||
Integer temp2=(Integer) o._setShips.Count();
|
||||
return temp1.compareTo(temp2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
import java.io.*;
|
||||
import java.util.AbstractCollection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class MapsCollection {
|
||||
private final HashMap<String,MapWithSetShipsGeneric<DrawingObjectShip, AbstractMap>> _mapStorages;
|
||||
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<>();
|
||||
@@ -27,7 +31,7 @@ public class MapsCollection {
|
||||
{
|
||||
_mapStorages.remove(name);
|
||||
}
|
||||
public MapWithSetShipsGeneric<DrawingObjectShip,AbstractMap> Get(String ind)
|
||||
public MapWithSetShipsGeneric<IDrawingObject,AbstractMap> Get(String ind)
|
||||
{
|
||||
if(_mapStorages.containsKey(ind))
|
||||
{
|
||||
@@ -35,15 +39,130 @@ public class MapsCollection {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public DrawingObjectShip Get(String name, int ind) {
|
||||
public IDrawingObject Get(String name, int ind) {
|
||||
if (_mapStorages.containsKey(name))
|
||||
{
|
||||
return _mapStorages.get(name).GetSelectedShip(ind);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public void 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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
public void LoadData(String filename) throws FileNotFoundException {
|
||||
File file=new File(filename);
|
||||
if(!file.exists())
|
||||
{
|
||||
throw new FileNotFoundException("Файл не найден");
|
||||
}
|
||||
try(BufferedReader fr = new BufferedReader(new FileReader(file)))
|
||||
{
|
||||
String str="";
|
||||
if((str=fr.readLine())==null || !str.contains("MapsCollection"))
|
||||
{
|
||||
throw new IllegalArgumentException("Формат данных в файле неправильный");
|
||||
}
|
||||
_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)));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (StorageOverflowException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
public void 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()));
|
||||
}
|
||||
}
|
||||
public void LoadMapData(String filename) throws FileNotFoundException {
|
||||
File file=new File(filename);
|
||||
if(!file.exists())
|
||||
{
|
||||
throw new FileNotFoundException("Файл не найден");
|
||||
}
|
||||
try(BufferedReader fr = new BufferedReader(new FileReader(file)))
|
||||
{
|
||||
String str="";
|
||||
if((str=fr.readLine())==null || !str.contains("Map_Info:"))
|
||||
{
|
||||
throw new IllegalArgumentException("Формат данных в файле неправильный");
|
||||
}
|
||||
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:"))
|
||||
{
|
||||
throw new IllegalArgumentException("Формат данных в файле неправильный");
|
||||
}
|
||||
str_second= fr.readLine();
|
||||
str=str+str_second;
|
||||
tempElem = str.split(String.format("\\%c",separatorDict));
|
||||
if(tempElem.length==3) {
|
||||
_mapStorages.get(tempElem[0]).LoadData(tempElem[2].split(String.valueOf(separatorData)));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (StorageOverflowException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
public class SetShipsGeneric<T extends Object> implements Iterable<T>{
|
||||
private ArrayList<T> _places;
|
||||
@@ -12,26 +13,35 @@ public class SetShipsGeneric<T extends Object> implements Iterable<T>{
|
||||
_maxCount=count;
|
||||
_places = new ArrayList<>();
|
||||
}
|
||||
public int Insert(T ship)
|
||||
{
|
||||
public int Insert(T ship) throws StorageOverflowException {
|
||||
return Insert(ship, 0);
|
||||
}
|
||||
public int Insert(T ship, int position)
|
||||
{
|
||||
public int Insert(T ship, int position) throws StorageOverflowException {
|
||||
if (_places.contains(ship))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if(_maxCount == Count())
|
||||
{
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
}
|
||||
if (position < 0 || position > Count() || _maxCount == Count()) return -1;
|
||||
_places.add(position,ship);
|
||||
return position;
|
||||
}
|
||||
public T Remove(int position)
|
||||
{
|
||||
public T Remove(int position) throws ShipNotFoundException {
|
||||
if (position >= Count() || position < 0)
|
||||
{
|
||||
return null;
|
||||
throw new ShipNotFoundException(position);
|
||||
}
|
||||
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)
|
||||
@@ -40,8 +50,7 @@ public class SetShipsGeneric<T extends Object> implements Iterable<T>{
|
||||
}
|
||||
return _places.get(position);
|
||||
}
|
||||
public void Set(int position,T value)
|
||||
{
|
||||
public void Set(int position,T value) throws StorageOverflowException {
|
||||
if (position < _maxCount || position >= 0)
|
||||
{
|
||||
Insert(value,position);
|
||||
@@ -51,5 +60,13 @@ public class SetShipsGeneric<T extends Object> implements Iterable<T>{
|
||||
public Iterator<T> iterator() {
|
||||
return _places.iterator();
|
||||
}
|
||||
public void SortSet(Comparator<T> comparer)
|
||||
{
|
||||
if(comparer==null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_places.sort(comparer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
60
src/ShipCompareByColor.java
Normal file
60
src/ShipCompareByColor.java
Normal file
@@ -0,0 +1,60 @@
|
||||
import java.util.Comparator;
|
||||
|
||||
public class ShipCompareByColor implements Comparator<IDrawingObject> {
|
||||
@Override
|
||||
public int compare(IDrawingObject x,IDrawingObject y)
|
||||
{
|
||||
if (x == null && y == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (x == null && y != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (x != null && y == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
DrawingObjectShip xShip = (DrawingObjectShip) x;
|
||||
DrawingObjectShip yShip =(DrawingObjectShip) y;
|
||||
if (xShip == null && yShip == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (xShip == null && yShip != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (xShip != null && yShip == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
Integer xShipColor=xShip.GetDrawingObjectShip().Ship.GetBodyColor().getRGB();
|
||||
Integer yShipColor=yShip.GetDrawingObjectShip().Ship.GetBodyColor().getRGB();
|
||||
if (!xShipColor.equals(yShipColor))
|
||||
{
|
||||
return xShipColor.compareTo(yShipColor);
|
||||
}
|
||||
if (xShip.GetDrawingObjectShip().Ship instanceof EntityLiner xLiner && yShip.GetDrawingObjectShip().Ship instanceof EntityLiner yLiner)
|
||||
{
|
||||
Integer xShipDopColor = xLiner.DopColor.getRGB();
|
||||
Integer yShipDopColor = yLiner.DopColor.getRGB();
|
||||
var dopColorCompare = xShipDopColor.compareTo(yShipDopColor);
|
||||
if (dopColorCompare != 0)
|
||||
{
|
||||
return dopColorCompare;
|
||||
}
|
||||
}
|
||||
Integer temp1=(Integer)xShip.GetDrawingObjectShip().Ship.GetSpeed();
|
||||
Integer temp2=(Integer)yShip.GetDrawingObjectShip().Ship.GetSpeed();
|
||||
var speedCompare = (temp1.compareTo(temp2));
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
Float tempfl1=xShip.GetDrawingObjectShip().Ship.GetWeight();
|
||||
Float templfl2=yShip.GetDrawingObjectShip().Ship.GetWeight();
|
||||
return tempfl1.compareTo(templfl2);
|
||||
}
|
||||
}
|
||||
53
src/ShipCompareByType.java
Normal file
53
src/ShipCompareByType.java
Normal file
@@ -0,0 +1,53 @@
|
||||
import java.util.Comparator;
|
||||
import java.util.concurrent.DelayQueue;
|
||||
|
||||
public class ShipCompareByType implements Comparator<IDrawingObject> {
|
||||
@Override
|
||||
public int compare(IDrawingObject x,IDrawingObject y)
|
||||
{
|
||||
if(x==null && y==null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if(x == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if(y == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
DrawingObjectShip xShip = (DrawingObjectShip) x;
|
||||
DrawingObjectShip yShip =(DrawingObjectShip) y;
|
||||
if(!xShip.GetDrawingObjectShip().getClass().getSimpleName().equals(yShip.GetDrawingObjectShip().getClass().getSimpleName()))
|
||||
{
|
||||
if (xShip.GetDrawingObjectShip().getClass().getName().equals("DrawingShip"))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
var deckcompareX=xShip.GetDrawingObjectShip().GetDeck().getClass().getName();
|
||||
var deckcompareY=xShip.GetDrawingObjectShip().GetDeck().getClass().getName();
|
||||
if(!deckcompareX.equals(deckcompareY))
|
||||
{
|
||||
return deckcompareX.compareTo(deckcompareY);
|
||||
}
|
||||
Integer deckenumX=xShip.GetDrawingObjectShip().GetDeck().GetDeckEnum();
|
||||
Integer deckenumY=yShip.GetDrawingObjectShip().GetDeck().GetDeckEnum();
|
||||
if(!deckenumX.equals(deckenumY))
|
||||
{
|
||||
return deckenumX.compareTo(deckenumY);
|
||||
}
|
||||
Integer temp1=(Integer)xShip.GetDrawingObjectShip().Ship.GetSpeed();
|
||||
Integer temp2=(Integer)yShip.GetDrawingObjectShip().Ship.GetSpeed();
|
||||
var speedCompare = (temp1.compareTo(temp2));
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
Float tempfl1=xShip.GetDrawingObjectShip().Ship.GetWeight();
|
||||
Float templfl2=yShip.GetDrawingObjectShip().Ship.GetWeight();
|
||||
return tempfl1.compareTo(templfl2);
|
||||
}
|
||||
}
|
||||
14
src/ShipNotFoundException.java
Normal file
14
src/ShipNotFoundException.java
Normal file
@@ -0,0 +1,14 @@
|
||||
public class ShipNotFoundException extends Exception{
|
||||
public ShipNotFoundException(int i){
|
||||
super(String.format("%s%d","Не найден объект по позиции",i));
|
||||
}
|
||||
public ShipNotFoundException(){
|
||||
super();
|
||||
}
|
||||
public ShipNotFoundException(String message){
|
||||
super(message);
|
||||
}
|
||||
public ShipNotFoundException(String message,Exception ex){
|
||||
super(message,ex);
|
||||
}
|
||||
}
|
||||
14
src/StorageOverflowException.java
Normal file
14
src/StorageOverflowException.java
Normal file
@@ -0,0 +1,14 @@
|
||||
public class StorageOverflowException extends Exception {
|
||||
public StorageOverflowException(int count){
|
||||
super("В наборе превышено допустимое количество: "+count);
|
||||
}
|
||||
public StorageOverflowException(){
|
||||
super();
|
||||
}
|
||||
public StorageOverflowException(String message){
|
||||
super(message);
|
||||
}
|
||||
public StorageOverflowException(String message,Exception ex){
|
||||
super(message,ex);
|
||||
}
|
||||
}
|
||||
27
src/log4j.properties
Normal file
27
src/log4j.properties
Normal file
@@ -0,0 +1,27 @@
|
||||
log4j.logger.FormMapWithSetShipsGeneric=INFO, fileAppender,adminAppender
|
||||
|
||||
|
||||
log4j.additivity.file=false
|
||||
log4j.additivity.admin=false
|
||||
|
||||
log4j.appender.fileAppender=org.apache.log4j.RollingFileAppender
|
||||
log4j.appender.fileAppender.File=loginfo.log
|
||||
log4j.appender.fileAppender.MaxFileSize=1MB
|
||||
log4j.appender.fileAppender.MaxBackupIndex=1
|
||||
log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.fileAppender.filter.F1=org.apache.log4j.varia.LevelRangeFilter
|
||||
log4j.appender.fileAppender.filter.F1.LevelMin=INFO
|
||||
log4j.appender.fileAppender.filter.F1.LevelMax=INFO
|
||||
log4j.appender.fileAppender.filter.F1.AcceptOnMatch=true
|
||||
log4j.appender.fileAppender.layout.ConversionPattern=%-5p %c{1}:%L - %m %d{dd-MM-yyyy}%n
|
||||
|
||||
log4j.appender.adminAppender=org.apache.log4j.RollingFileAppender
|
||||
log4j.appender.adminAppender.File=logwarn.log
|
||||
log4j.appender.adminAppender.MaxFileSize=1MB
|
||||
log4j.appender.adminAppender.MaxBackupIndex=1
|
||||
log4j.appender.adminAppender.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.adminAppender.filter.F1=org.apache.log4j.varia.LevelRangeFilter
|
||||
log4j.appender.adminAppender.filter.F1.LevelMin=WARN
|
||||
log4j.appender.adminAppender.filter.F1.LevelMax=ERROR
|
||||
log4j.appender.adminAppender.filter.F1.AcceptOnMatch=true
|
||||
log4j.appender.adminAppender.layout.ConversionPattern=%-5p %c{1}:%L - %m %d{dd-MM-yyyy}%n
|
||||
Reference in New Issue
Block a user