lab3 ready
This commit is contained in:
parent
525ba16a8a
commit
0e2779eb1e
BIN
ProjectElectroTrans/Drawnings.zip
Normal file
BIN
ProjectElectroTrans/Drawnings.zip
Normal file
Binary file not shown.
71
ProjectElectroTrans/Drawnings/DrawningElectroTrans.java
Normal file
71
ProjectElectroTrans/Drawnings/DrawningElectroTrans.java
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
package Drawnings;
|
||||||
|
|
||||||
|
import Entities.EntityElectroTrans;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawningElectroTrans extends DrawningTrans {
|
||||||
|
private EntityElectroTrans entityElectroTrans;
|
||||||
|
|
||||||
|
public DrawningElectroTrans(int speed, float weight, Color bodyColor, int wheelsType, Color additionalColor, boolean horns, boolean battery) {
|
||||||
|
super(speed, weight, bodyColor, wheelsType, 110, 60);
|
||||||
|
entityElectroTrans = new EntityElectroTrans(speed, weight, bodyColor, additionalColor, horns, battery);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawTrans(Graphics g) {
|
||||||
|
if (entityElectroTrans == null || _startPosX == null || _startPosY == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.drawTrans(g);
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
|
||||||
|
Point[] electroTransHorns;
|
||||||
|
if (entityElectroTrans.getHorns()) {
|
||||||
|
electroTransHorns = new Point[]{
|
||||||
|
new Point(_startPosX + 40, _startPosY + 10),
|
||||||
|
new Point(_startPosX + 20, _startPosY),
|
||||||
|
new Point(_startPosX + 60, _startPosY),
|
||||||
|
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
electroTransHorns = new Point[]{
|
||||||
|
new Point(_startPosX + 40, _startPosY + 7),
|
||||||
|
new Point(_startPosX + 20, _startPosY + 7),
|
||||||
|
new Point(_startPosX + 60, _startPosY + 7),
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Polygon electroTransHornsPolygon = new Polygon();
|
||||||
|
for (Point point : electroTransHorns)
|
||||||
|
electroTransHornsPolygon.addPoint(point.x, point.y);
|
||||||
|
|
||||||
|
g2d.setColor(entityElectroTrans.getAdditionalColor());
|
||||||
|
g2d.drawPolygon(electroTransHornsPolygon);
|
||||||
|
|
||||||
|
|
||||||
|
if (entityElectroTrans.getBattery()) {
|
||||||
|
Point[] electroTransBattery = new Point[]{
|
||||||
|
new Point(_startPosX + 25, _startPosY + 32),
|
||||||
|
new Point(_startPosX + 25, _startPosY + 36),
|
||||||
|
new Point(_startPosX + 22, _startPosY + 36),
|
||||||
|
new Point(_startPosX + 22, _startPosY + 40),
|
||||||
|
new Point(_startPosX + 25, _startPosY + 40),
|
||||||
|
new Point(_startPosX + 25, _startPosY + 46),
|
||||||
|
new Point(_startPosX + 58, _startPosY + 46),
|
||||||
|
new Point(_startPosX + 58, _startPosY + 32),
|
||||||
|
|
||||||
|
};
|
||||||
|
Polygon electroTransBatteryPolygon = new Polygon();
|
||||||
|
for (Point point : electroTransBattery)
|
||||||
|
electroTransBatteryPolygon.addPoint(point.x, point.y);
|
||||||
|
|
||||||
|
g2d.setColor(entityElectroTrans.getAdditionalColor());
|
||||||
|
g2d.fillPolygon(electroTransBatteryPolygon);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
27
ProjectElectroTrans/Drawnings/DrawningRectWheels.java
Normal file
27
ProjectElectroTrans/Drawnings/DrawningRectWheels.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package Drawnings;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawningRectWheels implements IDrawWheels {
|
||||||
|
private WheelsCount wheelsCount;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNumber(int wheelCount) {
|
||||||
|
for (WheelsCount value : WheelsCount.values()) {
|
||||||
|
if (value.getEnumNumber() == wheelCount) {
|
||||||
|
wheelsCount = value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawWheels(Graphics2D g2d, Color color, int _startX, int _startY) {
|
||||||
|
g2d.setColor(color);
|
||||||
|
g2d.setStroke(new BasicStroke(4));
|
||||||
|
int wheelDistance = 100 / wheelsCount.getEnumNumber();
|
||||||
|
for (int i = 0; i < wheelsCount.getEnumNumber(); i++) {
|
||||||
|
g2d.drawRect(_startX + 5 + i * wheelDistance, _startY + 46, 8, 8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
149
ProjectElectroTrans/Drawnings/DrawningTrans.java
Normal file
149
ProjectElectroTrans/Drawnings/DrawningTrans.java
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
package Drawnings;
|
||||||
|
|
||||||
|
import Entities.*;
|
||||||
|
import MovementStrategy.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class DrawningTrans {
|
||||||
|
private final EntityTrans entityTran;
|
||||||
|
|
||||||
|
public EntityTrans getEntityTrans() {
|
||||||
|
return entityTran;
|
||||||
|
}
|
||||||
|
private Integer _pictureWidth;
|
||||||
|
private Integer _pictureHeight;
|
||||||
|
protected Integer _startPosX;
|
||||||
|
protected Integer _startPosY;
|
||||||
|
private int _drawingTransWidth = 110;
|
||||||
|
private int _drawingTransHeight = 60;
|
||||||
|
public int GetPosX(){return _startPosX;}
|
||||||
|
public int GetPosY(){return _startPosY;}
|
||||||
|
public int GetWidth(){return _drawingTransWidth;}
|
||||||
|
public int GetHeight(){return _drawingTransHeight;}
|
||||||
|
private IDrawWheels drawWheels;
|
||||||
|
|
||||||
|
public DrawningTrans(int speed, float weight, Color bodyColor, int wheelsType) {
|
||||||
|
entityTran = new EntityTrans(speed, weight, bodyColor);
|
||||||
|
_startPosY = null;
|
||||||
|
_startPosX = null;
|
||||||
|
_pictureWidth = null;
|
||||||
|
_pictureHeight = null;
|
||||||
|
switch (wheelsType) {
|
||||||
|
case 0:
|
||||||
|
drawWheels = new DrawningWheels();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
drawWheels = new DrawningTriangleWheels();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
drawWheels = new DrawningRectWheels();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Random random = new Random();
|
||||||
|
int wheelsCount = random.nextInt(1, 4);
|
||||||
|
System.out.print(wheelsCount);
|
||||||
|
drawWheels.setNumber(wheelsCount);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected DrawningTrans(int speed, float weight, Color bodyColor, int wheelsType, int transWidth, int transHeight) {
|
||||||
|
this(speed, weight, bodyColor, wheelsType);
|
||||||
|
_drawingTransHeight = transHeight;
|
||||||
|
_drawingTransWidth = transWidth;
|
||||||
|
|
||||||
|
}
|
||||||
|
public void setPosition(int x, int y) {
|
||||||
|
if (_pictureHeight == null || _pictureWidth == null)
|
||||||
|
return;
|
||||||
|
_startPosX = x;
|
||||||
|
_startPosY = y;
|
||||||
|
|
||||||
|
if (_drawingTransWidth + x > _pictureWidth || x < 0) {
|
||||||
|
_startPosX = 0;
|
||||||
|
}
|
||||||
|
if (_drawingTransHeight + y > _pictureHeight || y < 0) {
|
||||||
|
_startPosY = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public boolean setPictureSize(int width, int height) {
|
||||||
|
|
||||||
|
if (_drawingTransHeight > height || _drawingTransWidth > width)
|
||||||
|
return false;
|
||||||
|
_pictureHeight = height;
|
||||||
|
_pictureWidth = width;
|
||||||
|
|
||||||
|
if (_startPosX != null && _startPosY != null)
|
||||||
|
{
|
||||||
|
if (_startPosX + _drawingTransWidth > width)
|
||||||
|
_startPosX = width - _drawingTransWidth;
|
||||||
|
if (_startPosY + _drawingTransHeight > height)
|
||||||
|
_startPosY = height - _drawingTransHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean moveTransport(MovementDirection direction) {
|
||||||
|
if (entityTran == null || _pictureWidth == null || _pictureHeight == null)
|
||||||
|
return false;
|
||||||
|
switch (direction) {
|
||||||
|
case MovementDirection.Left:
|
||||||
|
if (_startPosX - entityTran.getStep() > 0)
|
||||||
|
_startPosX -= (int) entityTran.getStep();
|
||||||
|
return true;
|
||||||
|
case MovementDirection.Up:
|
||||||
|
if (_startPosY - entityTran.getStep() > 0)
|
||||||
|
_startPosY -= (int) entityTran.getStep();
|
||||||
|
return true;
|
||||||
|
case MovementDirection.Right:
|
||||||
|
if (_startPosX + entityTran.getStep() < _pictureWidth - _drawingTransWidth)
|
||||||
|
_startPosX += (int) entityTran.getStep();
|
||||||
|
return true;
|
||||||
|
case MovementDirection.Down:
|
||||||
|
if (_startPosY + entityTran.getStep() < _pictureHeight - _drawingTransHeight)
|
||||||
|
_startPosY += (int) entityTran.getStep();
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void drawTrans(Graphics g) {
|
||||||
|
if (entityTran == null || _startPosX == null || _startPosY == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
|
||||||
|
Point[] electroTransBorders = new Point[]{
|
||||||
|
new Point(_startPosX, _startPosY + 30),
|
||||||
|
new Point(_startPosX + 10, _startPosY + 10),
|
||||||
|
new Point(_startPosX + 70, _startPosY + 10),
|
||||||
|
new Point(_startPosX + 80, _startPosY + 30),
|
||||||
|
new Point(_startPosX + 80, _startPosY + 50),
|
||||||
|
new Point(_startPosX, _startPosY + 50),
|
||||||
|
};
|
||||||
|
Polygon electroTransPolygon = new Polygon();
|
||||||
|
for (Point point : electroTransBorders)
|
||||||
|
electroTransPolygon.addPoint(point.x, point.y);
|
||||||
|
|
||||||
|
g2d.setColor(entityTran.getBodyColor());
|
||||||
|
g2d.drawPolygon(electroTransPolygon);
|
||||||
|
|
||||||
|
Point[] electroTransGlass = new Point[]{
|
||||||
|
new Point(_startPosX + 2, _startPosY + 30),
|
||||||
|
new Point(_startPosX + 10, _startPosY + 13),
|
||||||
|
new Point(_startPosX + 70, _startPosY + 13),
|
||||||
|
new Point(_startPosX + 78, _startPosY + 30),
|
||||||
|
};
|
||||||
|
|
||||||
|
Polygon electroTransGlassPolygon = new Polygon();
|
||||||
|
for (Point point : electroTransGlass)
|
||||||
|
electroTransGlassPolygon.addPoint(point.x, point.y);
|
||||||
|
|
||||||
|
g2d.setColor(entityTran.getBodyColor());
|
||||||
|
g2d.drawPolygon(electroTransGlassPolygon);
|
||||||
|
|
||||||
|
drawWheels.drawWheels(g2d, entityTran.getBodyColor(), _startPosX, _startPosY);
|
||||||
|
}
|
||||||
|
}
|
27
ProjectElectroTrans/Drawnings/DrawningWheels.java
Normal file
27
ProjectElectroTrans/Drawnings/DrawningWheels.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package Drawnings;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawningWheels implements IDrawWheels {
|
||||||
|
private WheelsCount wheelsCount;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNumber(int wheelCount) {
|
||||||
|
for (WheelsCount value : WheelsCount.values()) {
|
||||||
|
if (value.getEnumNumber() == wheelCount) {
|
||||||
|
wheelsCount = value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawWheels(Graphics2D g2d, Color color, int _startX, int _startY) {
|
||||||
|
g2d.setColor(color);
|
||||||
|
g2d.setStroke(new BasicStroke(4));
|
||||||
|
int wheelDistance = 100 / wheelsCount.getEnumNumber();
|
||||||
|
for (int i = 0; i < wheelsCount.getEnumNumber(); i++) {
|
||||||
|
g2d.drawOval(_startX + 5 + i * wheelDistance, _startY + 46, 8, 8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
8
ProjectElectroTrans/Drawnings/IDrawWheels.java
Normal file
8
ProjectElectroTrans/Drawnings/IDrawWheels.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package Drawnings;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public interface IDrawWheels {
|
||||||
|
void setNumber(int x);
|
||||||
|
void drawWheels(Graphics2D graphics2D, Color color, int _startX, int _startY);
|
||||||
|
}
|
16
ProjectElectroTrans/Drawnings/WheelsCount.java
Normal file
16
ProjectElectroTrans/Drawnings/WheelsCount.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package Drawnings;
|
||||||
|
|
||||||
|
public enum WheelsCount {
|
||||||
|
Two(2),
|
||||||
|
Three(3),
|
||||||
|
Four(4);
|
||||||
|
|
||||||
|
final private int EnumNumber;
|
||||||
|
WheelsCount(int enumNumber) {
|
||||||
|
EnumNumber = enumNumber;
|
||||||
|
}
|
||||||
|
public int getEnumNumber() {
|
||||||
|
return EnumNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
package CollectionGenericObjects;
|
||||||
|
|
||||||
|
import Drawnings.DrawningTrans;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public abstract class AbstractCompany {
|
||||||
|
protected final int _placeSizeWidth = 210;
|
||||||
|
protected final int _placeSizeHeight = 120;
|
||||||
|
protected final int _pictureWidth;
|
||||||
|
protected final int _pictureHeight;
|
||||||
|
protected ICollectionGenericObjects<DrawningTrans> _collection = null;
|
||||||
|
public int getMaxCount() {
|
||||||
|
return _pictureWidth * _pictureHeight / (_placeSizeWidth*_placeSizeHeight);
|
||||||
|
}
|
||||||
|
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningTrans> collection) {
|
||||||
|
this._pictureWidth = picWidth;
|
||||||
|
this._pictureHeight = picHeight;
|
||||||
|
this._collection = collection;
|
||||||
|
int maxCount = getMaxCount();
|
||||||
|
_collection.setMaxCount(maxCount);
|
||||||
|
}
|
||||||
|
public static int add(AbstractCompany company ,DrawningTrans trans) {
|
||||||
|
if (company._collection == null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return company._collection.insert(trans);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DrawningTrans remove(AbstractCompany company, int position) {
|
||||||
|
if (company._collection == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return company._collection.remove(position);
|
||||||
|
}
|
||||||
|
public DrawningTrans getRandomObject() {
|
||||||
|
if (_collection == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Random rnd = new Random();
|
||||||
|
return _collection.get(rnd.nextInt(0, _collection.getCount() + 1));
|
||||||
|
}
|
||||||
|
public void show(Graphics g) {
|
||||||
|
drawBackground(g);
|
||||||
|
setObjectsPosition();
|
||||||
|
if (_collection == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for(int i = 0; i < _collection.getCount(); i++) {
|
||||||
|
if(_collection.get(i) != null) {
|
||||||
|
_collection.get(i).drawTrans(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected abstract void drawBackground(Graphics g);
|
||||||
|
protected abstract void setObjectsPosition();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
package CollectionGenericObjects;
|
||||||
|
|
||||||
|
import Drawnings.DrawningTrans;
|
||||||
|
import Drawnings.DrawningElectroTrans;
|
||||||
|
import Drawnings.IDrawWheels;
|
||||||
|
import Entities.EntityTrans;
|
||||||
|
import Entities.EntityElectroTrans;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class Constructor<T extends EntityTrans, U extends IDrawWheels> {
|
||||||
|
private ArrayList<T> entitiesList = new ArrayList<>();
|
||||||
|
private ArrayList<U> wheelsList = new ArrayList<>();
|
||||||
|
public void addTrans(T obj) {
|
||||||
|
entitiesList.add(obj);
|
||||||
|
}
|
||||||
|
public void addTrans(U obj) {
|
||||||
|
wheelsList.add(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawningTrans getRandomTrans() {
|
||||||
|
Random rnd = new Random();
|
||||||
|
int entityIndex = rnd.nextInt(0, 3);
|
||||||
|
int wheelsIndex = rnd.nextInt(0, 3);
|
||||||
|
|
||||||
|
T entity = entitiesList.get(entityIndex);
|
||||||
|
U wheels = wheelsList.get(wheelsIndex);
|
||||||
|
|
||||||
|
return (entity instanceof EntityElectroTrans) ?
|
||||||
|
new DrawningElectroTrans((EntityElectroTrans) entity, wheels) :
|
||||||
|
new DrawningTrans(entity, wheels);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEntityDescription(int index) {
|
||||||
|
if (index < 0 || index >= entitiesList.size()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
T entity = entitiesList.get(index);
|
||||||
|
String entityClassName = (entity instanceof EntityElectroTrans) ? "EntityElectroTrans" : "EntityTrans";
|
||||||
|
|
||||||
|
return String.format("<html><i><u>%s</u></i> = %s</html>", entityClassName, entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPaddlesDescription(int index) {
|
||||||
|
if (index < 0 || index >= wheelsList.size()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return wheelsList.get(index).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package CollectionGenericObjects;
|
||||||
|
|
||||||
|
import Drawnings.DrawningTrans;
|
||||||
|
|
||||||
|
public interface ICollectionGenericObjects<T extends DrawningTrans> {
|
||||||
|
int getCount();
|
||||||
|
|
||||||
|
void setMaxCount(int count);
|
||||||
|
|
||||||
|
int insert(T obj);
|
||||||
|
|
||||||
|
int insert(T obj, int index);
|
||||||
|
|
||||||
|
T remove(int index);
|
||||||
|
|
||||||
|
T get(int index);
|
||||||
|
}
|
@ -0,0 +1,91 @@
|
|||||||
|
package CollectionGenericObjects;
|
||||||
|
|
||||||
|
import Drawnings.DrawningTrans;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class MassiveGenericObjects<T extends DrawningTrans> implements ICollectionGenericObjects<T> {
|
||||||
|
private ArrayList<T> _collection;
|
||||||
|
public MassiveGenericObjects() {
|
||||||
|
_collection = new ArrayList<>();
|
||||||
|
|
||||||
|
}
|
||||||
|
int maxCount = 0;
|
||||||
|
int realSize = 0;
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return _collection.size();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public int insert(T obj) {
|
||||||
|
return insert(obj, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int insert(T obj, int position) {
|
||||||
|
if (position > maxCount|| position < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = position; i < maxCount; i++) {
|
||||||
|
if (_collection.get(i) == null) {
|
||||||
|
_collection.set(i, obj);
|
||||||
|
realSize++;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = position; i > 0; i--) {
|
||||||
|
if (_collection.get(i) == null) {
|
||||||
|
_collection.set(i, obj);
|
||||||
|
realSize++;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T remove(int position) {
|
||||||
|
if (position < 0 || position >= maxCount) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (_collection.get(position) != null) {
|
||||||
|
T bf = _collection.get(position);
|
||||||
|
_collection.set(position, null);
|
||||||
|
--realSize;
|
||||||
|
return bf;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T get(int position) {
|
||||||
|
if (position >= 0 && position < _collection.size()) {
|
||||||
|
return _collection.get(position);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMaxCount(int count) {
|
||||||
|
if (count > 0) {
|
||||||
|
if (!_collection.isEmpty()) {
|
||||||
|
ArrayList<T> bfLoc = new ArrayList<>(count);
|
||||||
|
bfLoc.addAll(0, _collection);
|
||||||
|
_collection = bfLoc;
|
||||||
|
for (int i = 0; i < count - maxCount; i++) {
|
||||||
|
_collection.add(null);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_collection = new ArrayList<>(count);
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
_collection.add(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
maxCount = count;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package CollectionGenericObjects;
|
||||||
|
|
||||||
|
import Drawnings.DrawningTrans;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TransSharingService extends AbstractCompany {
|
||||||
|
private final List<Point> locCoord = new ArrayList<>();
|
||||||
|
private int numRows, numCols;
|
||||||
|
public TransSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningTrans> collection) {
|
||||||
|
super(picWidth, picHeight, collection);
|
||||||
|
_collection.setMaxCount(30);
|
||||||
|
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void drawBackground(Graphics g) {
|
||||||
|
Color backgroundColor = new Color(135, 206, 235);
|
||||||
|
|
||||||
|
g.setColor(backgroundColor);
|
||||||
|
g.fillRect(0, 0, _pictureWidth, _pictureHeight);
|
||||||
|
|
||||||
|
g.setColor(new Color(165, 42, 42)); // Brown
|
||||||
|
int offsetX = 10, offsetY = -5;
|
||||||
|
int x = 1 + offsetX, y = _pictureHeight - _placeSizeHeight + offsetY;
|
||||||
|
numRows = 0;
|
||||||
|
while (y >= 0) {
|
||||||
|
int numCols = 0;
|
||||||
|
while (x + _placeSizeWidth <= _pictureWidth) {
|
||||||
|
numCols++;
|
||||||
|
g.drawLine(x, y, x + _placeSizeWidth / 2, y);
|
||||||
|
g.drawLine(x, y, x, y + _placeSizeHeight + 4);
|
||||||
|
locCoord.add(new Point(x, y));
|
||||||
|
x += _placeSizeWidth + 2;
|
||||||
|
}
|
||||||
|
numRows++;
|
||||||
|
x = 1 + offsetX;
|
||||||
|
y -= _placeSizeHeight + 5 + offsetY;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setObjectsPosition() {
|
||||||
|
if (locCoord == null || _collection == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int row = numRows - 1, col = numCols;
|
||||||
|
for (int i=0;i< _collection.getCount(); i++, col--) {
|
||||||
|
if (_collection.get(i) != null) {
|
||||||
|
_collection.get(i).setPictureSize(_pictureWidth, _pictureHeight);
|
||||||
|
_collection.get(i).setPosition((int)locCoord.get(row*numCols - col).getX() + 5,
|
||||||
|
(int)locCoord.get(row*numCols - col).getY() + 9);
|
||||||
|
if (col == 1) {
|
||||||
|
col = numCols + 1;
|
||||||
|
row--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
127
ProjectElectroTrans/src/Drawnings/DrawningAbstractCompany.java
Normal file
127
ProjectElectroTrans/src/Drawnings/DrawningAbstractCompany.java
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
package Drawnings;
|
||||||
|
|
||||||
|
import CollectionGenericObjects.AbstractCompany;
|
||||||
|
import CollectionGenericObjects.MassiveGenericObjects;
|
||||||
|
import CollectionGenericObjects.TransSharingService;
|
||||||
|
import Forms.FormConstructor;
|
||||||
|
import Forms.FormElectroTrans;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class DrawningAbstractCompany extends JComponent {
|
||||||
|
private AbstractCompany _company = null;
|
||||||
|
public void collectionComboBox_SelectedIndexChanged(JComboBox<String> obj, int width, int height) {
|
||||||
|
switch (obj.getSelectedIndex()) {
|
||||||
|
case 1:
|
||||||
|
_company = new TransSharingService(width, height, new MassiveGenericObjects<DrawningTrans>());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void createObject(int type, JFrame obj) {
|
||||||
|
if (_company == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DrawningTrans _drawningTrans;
|
||||||
|
Random random = new Random();
|
||||||
|
switch (type) {
|
||||||
|
case 0:
|
||||||
|
_drawningTrans = new DrawningTrans(random.nextInt(70 - 30) + 30, random.nextInt(500 - 100) + 100,
|
||||||
|
getColorR(obj, random), random.nextInt(3));
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
_drawningTrans = new DrawningElectroTrans(random.nextInt(70 - 30) + 30, random.nextInt(500 - 100) + 100,
|
||||||
|
getColorR(obj, random), random.nextInt(3),
|
||||||
|
getColorR(obj, random),
|
||||||
|
random.nextBoolean(), random.nextBoolean());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (AbstractCompany.add(_company, _drawningTrans) != -1) {
|
||||||
|
JOptionPane.showMessageDialog(obj, "Объект добавлен");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
JOptionPane.showMessageDialog(obj, "Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Color getColorR(JFrame obj, Random rnd) {
|
||||||
|
Color color = new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256));
|
||||||
|
if (obj == null) {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
JColorChooser colorChooser = new JColorChooser();
|
||||||
|
colorChooser.setColor(color);
|
||||||
|
return JColorChooser.showDialog(obj, "Выберите цвет", color);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteButtonAction(int val, Frame obj) {
|
||||||
|
if (_company == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int result = JOptionPane.showConfirmDialog(
|
||||||
|
obj,
|
||||||
|
"Удалить объект?",
|
||||||
|
"Подтвердение",
|
||||||
|
JOptionPane.YES_NO_OPTION);
|
||||||
|
if (result == JOptionPane.YES_OPTION) {
|
||||||
|
if (AbstractCompany.remove(_company, val) != null) {
|
||||||
|
JOptionPane.showMessageDialog(obj, "Выполнено");
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(obj, "Удаление не удалось");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void goToCheckButtonAction() {
|
||||||
|
if (_company == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DrawningTrans trans = null;
|
||||||
|
int counter = 100;
|
||||||
|
while (trans == null && counter > 0) {
|
||||||
|
trans = _company.getRandomObject();
|
||||||
|
--counter;
|
||||||
|
}
|
||||||
|
if (trans == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FormElectroTrans formElectroTrans = new FormElectroTrans();
|
||||||
|
formElectroTrans.setDrawningTrans(trans);
|
||||||
|
formElectroTrans.OpenFrame();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private DrawningTrans createObject;
|
||||||
|
public void getObjFromConstructor(JFrame obj) {
|
||||||
|
if (_company == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FormConstructor formConstructor = new FormConstructor();
|
||||||
|
formConstructor.OpenFrame();
|
||||||
|
|
||||||
|
formConstructor.getAddButton().addActionListener(e -> {
|
||||||
|
createObject = formConstructor.getConstructor().getObj();
|
||||||
|
if (AbstractCompany.add(_company, createObject) != -1) {
|
||||||
|
JOptionPane.showMessageDialog(obj, "Выполнено");
|
||||||
|
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(obj, "Добавление не удалось");
|
||||||
|
}
|
||||||
|
obj.repaint();
|
||||||
|
formConstructor.getjFrameConstructor().dispatchEvent(new WindowEvent(formConstructor.getjFrameConstructor(), WindowEvent.WINDOW_CLOSING));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void paintComponent(Graphics g) {
|
||||||
|
super.paintComponent(g);
|
||||||
|
if (_company == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_company.show(g);
|
||||||
|
}
|
||||||
|
}
|
84
ProjectElectroTrans/src/Drawnings/DrawningConstructor.java
Normal file
84
ProjectElectroTrans/src/Drawnings/DrawningConstructor.java
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
package Drawnings;
|
||||||
|
|
||||||
|
import CollectionGenericObjects.Constructor;
|
||||||
|
import Entities.EntityTrans;
|
||||||
|
import Entities.EntityElectroTrans;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class DrawningConstructor extends JComponent {
|
||||||
|
|
||||||
|
Constructor<EntityTrans, IDrawWheels> constructor = new Constructor<>();
|
||||||
|
private DrawningTrans obj;
|
||||||
|
|
||||||
|
public DrawningTrans getObj() {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawningConstructor() {
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
EntityTrans _entityBoat = null;
|
||||||
|
IDrawWheels _drawWheels = null;
|
||||||
|
Random rnd = new Random();
|
||||||
|
int wheelsType = rnd.nextInt(3);
|
||||||
|
switch (wheelsType) {
|
||||||
|
case 0:
|
||||||
|
_drawWheels = new DrawningWheels();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
_drawWheels = new DrawningRectWheels();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
_drawWheels = new DrawningRectangleWheels();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
int wheelsCount = rnd.nextInt(1, 4);
|
||||||
|
_drawWheels.setNumber(wheelsCount);
|
||||||
|
|
||||||
|
int typeBoat = rnd.nextInt(0, 2);
|
||||||
|
|
||||||
|
switch (typeBoat) {
|
||||||
|
case 0:
|
||||||
|
_entityBoat = new EntityTrans(rnd.nextInt(70 - 30) + 30, rnd.nextInt(500 - 100) + 100,
|
||||||
|
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)));
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
_entityBoat = new EntityElectroTrans(rnd.nextInt(70 - 30) + 30, rnd.nextInt(500 - 100) + 100,
|
||||||
|
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
|
||||||
|
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
|
||||||
|
rnd.nextBoolean(), rnd.nextBoolean());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
constructor.addTrans(_entityBoat);
|
||||||
|
constructor.addTrans(_drawWheels);
|
||||||
|
}
|
||||||
|
obj = constructor.getRandomTrans();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reCreateObj() {
|
||||||
|
obj = constructor.getRandomTrans();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEntityString(int index) {
|
||||||
|
return constructor.getEntityDescription(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWheelsString(int index) {
|
||||||
|
return constructor.getPaddlesDescription(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintComponent(Graphics g) {
|
||||||
|
super.paintComponent(g);
|
||||||
|
if (obj != null) {
|
||||||
|
obj.setPosition(10, 30);
|
||||||
|
obj.setPictureSize(400, 300);
|
||||||
|
obj.drawTrans(g);
|
||||||
|
}
|
||||||
|
super.repaint();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -5,20 +5,43 @@ import Entities.EntityElectroTrans;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawningElectroTrans extends DrawningTrans {
|
public class DrawningElectroTrans extends DrawningTrans {
|
||||||
private EntityElectroTrans entityElectroTrans;
|
public DrawningElectroTrans(int speed, float weight, Color bodyColor, int wheelsType, Color additionalColor, boolean sail, boolean floaters) {
|
||||||
|
super(speed, weight, bodyColor, wheelsType, 110, 80);
|
||||||
public DrawningElectroTrans(int speed, float weight, Color bodyColor, int paddlesType, Color additionalColor, boolean horns, boolean battery) {
|
entityTran = new EntityElectroTrans(speed, weight, bodyColor, additionalColor, floaters, sail);
|
||||||
super(speed, weight, bodyColor, paddlesType, 110, 60);
|
|
||||||
entityElectroTrans = new EntityElectroTrans(speed, weight, bodyColor, additionalColor, horns, battery);
|
|
||||||
}
|
}
|
||||||
|
public DrawningElectroTrans(EntityElectroTrans entity, IDrawWheels wheels) {
|
||||||
|
super(entity, wheels);
|
||||||
|
}
|
||||||
|
private void drawFloater(int y0, Color additionalColor, Graphics2D g2d)
|
||||||
|
{
|
||||||
|
g2d.setColor(additionalColor);
|
||||||
|
g2d.setStroke(new BasicStroke(2));
|
||||||
|
Point[] floater = new Point[]
|
||||||
|
{
|
||||||
|
new Point(_startPosX + 10, _startPosY + y0 + 6),
|
||||||
|
new Point(_startPosX + 90, _startPosY + y0 + 6),
|
||||||
|
new Point(_startPosX + 110, _startPosY + y0 + 3),
|
||||||
|
new Point(_startPosX + 90, _startPosY + y0),
|
||||||
|
new Point(_startPosX + 10, _startPosY + y0),
|
||||||
|
|
||||||
|
};
|
||||||
|
Polygon floaterPolygon = new Polygon();
|
||||||
|
for (Point point: floater) {
|
||||||
|
floaterPolygon.addPoint(point.x, point.y);
|
||||||
|
}
|
||||||
|
g2d.fillPolygon(floaterPolygon);
|
||||||
|
g2d.drawPolygon(floaterPolygon);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
public void drawTrans(Graphics g) {
|
public void drawTrans(Graphics g) {
|
||||||
if (entityElectroTrans == null || _startPosX == null || _startPosY == null) {
|
|
||||||
|
if (entityTran == null || !(entityTran instanceof EntityElectroTrans entityElectroTrans) || _startPosX == null || _startPosY == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
super.drawTrans(g);
|
super.drawTrans(g);
|
||||||
Graphics2D g2d = (Graphics2D) g;
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
|
||||||
|
|
||||||
Point[] electroTransHorns;
|
Point[] electroTransHorns;
|
||||||
if (entityElectroTrans.getHorns()) {
|
if (entityElectroTrans.getHorns()) {
|
||||||
electroTransHorns = new Point[]{
|
electroTransHorns = new Point[]{
|
||||||
@ -64,8 +87,5 @@ public class DrawningElectroTrans extends DrawningTrans {
|
|||||||
g2d.fillPolygon(electroTransBatteryPolygon);
|
g2d.fillPolygon(electroTransBatteryPolygon);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
71
ProjectElectroTrans/src/Drawnings/DrawningFormCatamaran.java
Normal file
71
ProjectElectroTrans/src/Drawnings/DrawningFormCatamaran.java
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
package Drawnings;
|
||||||
|
|
||||||
|
import MovementStrategy.*;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawningFormCatamaran extends JComponent {
|
||||||
|
DrawningTrans drawningTrans;
|
||||||
|
|
||||||
|
private int _pictureHeight = -1;
|
||||||
|
private int _pictureWidth = -1;
|
||||||
|
private AbstractStrategy _strategy;
|
||||||
|
public void setDrawningTrans(DrawningTrans drawningTrans) {
|
||||||
|
this.drawningTrans = drawningTrans;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean setPictureSize(int width, int height) {
|
||||||
|
if (drawningTrans.GetHeight() > height || drawningTrans.GetWidth() > width)
|
||||||
|
return false;
|
||||||
|
_pictureHeight = height;
|
||||||
|
_pictureWidth = width;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public void buttonStrategyStep(JComboBox<String> comboBox) {
|
||||||
|
if (drawningTrans == null)
|
||||||
|
return;
|
||||||
|
if (comboBox.isEnabled()) {
|
||||||
|
switch (comboBox.getSelectedIndex()) {
|
||||||
|
case 0:
|
||||||
|
_strategy = new MoveToCenter();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
_strategy = new MoveToBorder();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
_strategy = null;
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (_strategy == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_strategy.SetData(new MoveableTrans(drawningTrans), _pictureWidth, _pictureHeight);
|
||||||
|
}
|
||||||
|
if (_strategy == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
comboBox.setEnabled(false);
|
||||||
|
_strategy.MakeStep();
|
||||||
|
if (_strategy.GetStatus() == StrategyStatus.Finish) {
|
||||||
|
comboBox.setEnabled(true);
|
||||||
|
_strategy = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public void MoveButtonsAction(MovementDirection direction) {
|
||||||
|
if (drawningTrans == null)
|
||||||
|
return;
|
||||||
|
drawningTrans.moveTransport(direction);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void paintComponent(Graphics g) {
|
||||||
|
super.paintComponent(g);
|
||||||
|
if (drawningTrans == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
drawningTrans.drawTrans(g);
|
||||||
|
}
|
||||||
|
}
|
@ -1,27 +1,32 @@
|
|||||||
package Drawnings;
|
package Drawnings;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawningRectWheels implements IDrawWheels {
|
public class DrawningRectWheels implements IDrawWheels {
|
||||||
private WheelsCount wheelsCount;
|
private WheelsCount _wheelsCount = WheelsCount.Two;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setNumber(int wheelCount) {
|
public void setNumber(int wheelsCount) {
|
||||||
for (WheelsCount value : WheelsCount.values()) {
|
for (WheelsCount value : WheelsCount.values()) {
|
||||||
if (value.getEnumNumber() == wheelCount) {
|
if (value.getEnumNumber() == wheelsCount) {
|
||||||
wheelsCount = value;
|
_wheelsCount = value;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawWheels(Graphics2D g2d, Color color, int _startX, int _startY) {
|
public void drawWheels(Graphics2D g2d, Color color, int _startX, int _startY) {
|
||||||
g2d.setColor(color);
|
g2d.setColor(color);
|
||||||
g2d.setStroke(new BasicStroke(4));
|
g2d.setStroke(new BasicStroke(4));
|
||||||
int wheelDistance = 100 / wheelsCount.getEnumNumber();
|
int wheelDistance = 100 / _wheelsCount.getEnumNumber();
|
||||||
for (int i = 0; i < wheelsCount.getEnumNumber(); i++) {
|
for (int i = 0; i < _wheelsCount.getEnumNumber(); i++) {
|
||||||
g2d.drawRect(_startX + 5 + i * wheelDistance, _startY + 46, 8, 8);
|
g2d.drawRect(_startX + 5 + i * wheelDistance, _startY + 46, 8, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String buffer = "";
|
||||||
|
buffer += "Тип: квадратные, Количество колес: " + _wheelsCount.getEnumNumber() * 2;
|
||||||
|
return buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
package Drawnings;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawningRectangleWheels implements IDrawWheels {
|
||||||
|
private WheelsCount _wheelsCount;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNumber(int wheelsCount) {
|
||||||
|
for (WheelsCount value : WheelsCount.values()) {
|
||||||
|
if (value.getEnumNumber() == wheelsCount) {
|
||||||
|
_wheelsCount = value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawWheels(Graphics2D g2d, Color color, int _startX, int _startY) {
|
||||||
|
g2d.setColor(color);
|
||||||
|
g2d.setStroke(new BasicStroke(4));
|
||||||
|
int wheelDistance = 100 / _wheelsCount.getEnumNumber();
|
||||||
|
for (int i = 0; i < _wheelsCount.getEnumNumber(); i++) {
|
||||||
|
g2d.drawLine(_startX + 5 + i * wheelDistance - 4, (int) _startY + 44, _startX + 5 + i * wheelDistance + 4, (int) _startY + 44);
|
||||||
|
g2d.drawLine(_startX + 5 + i * wheelDistance + 4, (int) _startY + 44, _startX + 5 + i * wheelDistance, (int) _startY + 48);
|
||||||
|
g2d.drawLine(_startX + 5 + i * wheelDistance, (int) _startY + 48, _startX + 5 + i * wheelDistance - 4, (int) _startY + 44);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String buffer = "";
|
||||||
|
buffer += "Тип: прямоугольники, Количество колес: " + _wheelsCount.getEnumNumber() * 2;
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
}
|
@ -1,27 +1,26 @@
|
|||||||
package Drawnings;
|
package Drawnings;
|
||||||
|
|
||||||
import Entities.*;
|
import Entities.EntityTrans;
|
||||||
import MovementStrategy.*;
|
import MovementStrategy.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class DrawningTrans {
|
public class DrawningTrans {
|
||||||
private final EntityTrans entityTran;
|
public EntityTrans entityTran;
|
||||||
|
public EntityTrans getEntityTran() {
|
||||||
public EntityTrans getEntityTrans() {
|
|
||||||
return entityTran;
|
return entityTran;
|
||||||
}
|
}
|
||||||
private Integer _pictureWidth;
|
private Integer _pictureWidth;
|
||||||
private Integer _pictureHeight;
|
private Integer _pictureHeight;
|
||||||
protected Integer _startPosX;
|
protected Integer _startPosX;
|
||||||
protected Integer _startPosY;
|
protected Integer _startPosY;
|
||||||
private int _drawingTransWidth = 110;
|
private int _drawingBoatWidth = 107;
|
||||||
private int _drawingTransHeight = 60;
|
private int _drawingBoatHeight = 80;
|
||||||
public int GetPosX(){return _startPosX;}
|
public Integer GetPosX(){return _startPosX;}
|
||||||
public int GetPosY(){return _startPosY;}
|
public Integer GetPosY(){return _startPosY;}
|
||||||
public int GetWidth(){return _drawingTransWidth;}
|
public int GetWidth(){return _drawingBoatWidth;}
|
||||||
public int GetHeight(){return _drawingTransHeight;}
|
public int GetHeight(){return _drawingBoatHeight;}
|
||||||
private IDrawWheels drawWheels;
|
public IDrawWheels drawWheels;
|
||||||
|
|
||||||
public DrawningTrans(int speed, float weight, Color bodyColor, int wheelsType) {
|
public DrawningTrans(int speed, float weight, Color bodyColor, int wheelsType) {
|
||||||
entityTran = new EntityTrans(speed, weight, bodyColor);
|
entityTran = new EntityTrans(speed, weight, bodyColor);
|
||||||
@ -34,53 +33,55 @@ public class DrawningTrans {
|
|||||||
drawWheels = new DrawningWheels();
|
drawWheels = new DrawningWheels();
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
drawWheels = new DrawningTriangleWheels();
|
drawWheels = new DrawningRectWheels();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
drawWheels = new DrawningRectWheels();
|
drawWheels = new DrawningRectangleWheels();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
int wheelsCount = random.nextInt(2, 4);
|
int wheelsCount = random.nextInt(1,4);
|
||||||
System.out.print(wheelsCount);
|
|
||||||
drawWheels.setNumber(wheelsCount);
|
drawWheels.setNumber(wheelsCount);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DrawningTrans(int speed, float weight, Color bodyColor, int wheelsType, int transWidth, int transHeight) {
|
protected DrawningTrans(int speed, float weight, Color bodyColor, int wheelsType, int boatWidth, int boatHeight) {
|
||||||
this(speed, weight, bodyColor, wheelsType);
|
this(speed, weight, bodyColor, wheelsType);
|
||||||
_drawingTransHeight = transHeight;
|
_drawingBoatHeight = boatHeight;
|
||||||
_drawingTransWidth = transWidth;
|
_drawingBoatWidth = boatWidth;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public DrawningTrans(EntityTrans _entityBoat, IDrawWheels _drawPaddles) {
|
||||||
|
entityTran = _entityBoat;
|
||||||
|
drawWheels = _drawPaddles;
|
||||||
|
}
|
||||||
public void setPosition(int x, int y) {
|
public void setPosition(int x, int y) {
|
||||||
if (_pictureHeight == null || _pictureWidth == null)
|
if (_pictureHeight == null || _pictureWidth == null)
|
||||||
return;
|
return;
|
||||||
_startPosX = x;
|
_startPosX = x;
|
||||||
_startPosY = y;
|
_startPosY = y;
|
||||||
|
|
||||||
if (_drawingTransWidth + x > _pictureWidth || x < 0) {
|
if (_drawingBoatWidth + x > _pictureWidth || x < 0) {
|
||||||
_startPosX = 0;
|
_startPosX = 0;
|
||||||
}
|
}
|
||||||
if (_drawingTransHeight + y > _pictureHeight || y < 0) {
|
if (_drawingBoatHeight + y > _pictureHeight || y < 0) {
|
||||||
_startPosY = 0;
|
_startPosY = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public boolean setPictureSize(int width, int height) {
|
public boolean setPictureSize(int width, int height) {
|
||||||
|
|
||||||
if (_drawingTransHeight > height || _drawingTransWidth > width)
|
if (_drawingBoatHeight > height || _drawingBoatWidth > width)
|
||||||
return false;
|
return false;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
|
|
||||||
if (_startPosX != null && _startPosY != null)
|
if (_startPosX != null && _startPosY != null)
|
||||||
{
|
{
|
||||||
if (_startPosX + _drawingTransWidth > width)
|
if (_startPosX + _drawingBoatWidth > width)
|
||||||
_startPosX = width - _drawingTransWidth;
|
_startPosX = width - _drawingBoatWidth;
|
||||||
if (_startPosY + _drawingTransHeight > height)
|
if (_startPosY + _drawingBoatHeight > height)
|
||||||
_startPosY = height - _drawingTransHeight;
|
_startPosY = height - _drawingBoatHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,11 +98,11 @@ public class DrawningTrans {
|
|||||||
_startPosY -= (int) entityTran.getStep();
|
_startPosY -= (int) entityTran.getStep();
|
||||||
return true;
|
return true;
|
||||||
case MovementDirection.Right:
|
case MovementDirection.Right:
|
||||||
if (_startPosX + entityTran.getStep() < _pictureWidth - _drawingTransWidth)
|
if (_startPosX + entityTran.getStep() < _pictureWidth - _drawingBoatWidth)
|
||||||
_startPosX += (int) entityTran.getStep();
|
_startPosX += (int) entityTran.getStep();
|
||||||
return true;
|
return true;
|
||||||
case MovementDirection.Down:
|
case MovementDirection.Down:
|
||||||
if (_startPosY + entityTran.getStep() < _pictureHeight - _drawingTransHeight)
|
if (_startPosY + entityTran.getStep() < _pictureHeight - _drawingBoatHeight)
|
||||||
_startPosY += (int) entityTran.getStep();
|
_startPosY += (int) entityTran.getStep();
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
@ -146,4 +147,4 @@ public class DrawningTrans {
|
|||||||
|
|
||||||
drawWheels.drawWheels(g2d, entityTran.getBodyColor(), _startPosX, _startPosY);
|
drawWheels.drawWheels(g2d, entityTran.getBodyColor(), _startPosX, _startPosY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,25 +3,29 @@ package Drawnings;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawningWheels implements IDrawWheels {
|
public class DrawningWheels implements IDrawWheels {
|
||||||
private WheelsCount wheelsCount;
|
private WheelsCount _wheelsCount;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setNumber(int wheelCount) {
|
public void setNumber(int wheelsCount) {
|
||||||
for (WheelsCount value : WheelsCount.values()) {
|
for (WheelsCount value : WheelsCount.values()) {
|
||||||
if (value.getEnumNumber() == wheelCount) {
|
if (value.getEnumNumber() == wheelsCount) {
|
||||||
wheelsCount = value;
|
_wheelsCount = value;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawWheels(Graphics2D g2d, Color color, int _startX, int _startY) {
|
public void drawWheels(Graphics2D g2d, Color color, int _startX, int _startY) {
|
||||||
g2d.setColor(color);
|
g2d.setColor(color);
|
||||||
g2d.setStroke(new BasicStroke(4));
|
g2d.setStroke(new BasicStroke(4));
|
||||||
int wheelDistance = 100 / wheelsCount.getEnumNumber();
|
int wheelDistance = 100 / _wheelsCount.getEnumNumber();
|
||||||
for (int i = 0; i < wheelsCount.getEnumNumber(); i++) {
|
for (int i = 0; i < _wheelsCount.getEnumNumber(); i++) {
|
||||||
g2d.drawOval(_startX + 5 + i * wheelDistance, _startY + 46, 8, 8);
|
g2d.drawOval(_startX + 5 + i * wheelDistance, _startY + 46, 8, 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String buffer = "";
|
||||||
|
buffer += "Тип: обычные, Количество колес: " + _wheelsCount.getEnumNumber() * 2;
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
}
|
@ -12,5 +12,4 @@ public enum WheelsCount {
|
|||||||
public int getEnumNumber() {
|
public int getEnumNumber() {
|
||||||
return EnumNumber;
|
return EnumNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,36 +2,11 @@ package Entities;
|
|||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class EntityElectroTrans extends EntityTrans {
|
public class EntityElectroTrans extends EntityTrans {
|
||||||
private int Speed;
|
|
||||||
|
|
||||||
public EntityElectroTrans(int speed, double weight, Color bodyColor, Color additionalColor, boolean horns, boolean battery) {
|
|
||||||
super(speed, weight, bodyColor);
|
|
||||||
AdditionalColor = additionalColor;
|
|
||||||
Horns = horns;
|
|
||||||
Battery = battery;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSpeed() {
|
|
||||||
return Speed;
|
|
||||||
}
|
|
||||||
private double Weight;
|
|
||||||
public double getWeight() {
|
|
||||||
return Weight;
|
|
||||||
}
|
|
||||||
private Color BodyColor;
|
|
||||||
public Color getBodyColor() {
|
|
||||||
return BodyColor;
|
|
||||||
}
|
|
||||||
private Color AdditionalColor;
|
private Color AdditionalColor;
|
||||||
public Color getAdditionalColor() {
|
public Color getAdditionalColor() {
|
||||||
return AdditionalColor;
|
return AdditionalColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public double Step() {
|
|
||||||
return Speed*100/Weight;
|
|
||||||
}
|
|
||||||
private boolean Horns;
|
private boolean Horns;
|
||||||
public boolean getHorns() {
|
public boolean getHorns() {
|
||||||
return Horns;
|
return Horns;
|
||||||
@ -40,4 +15,19 @@ public class EntityElectroTrans extends EntityTrans {
|
|||||||
public boolean getBattery() {
|
public boolean getBattery() {
|
||||||
return Battery;
|
return Battery;
|
||||||
}
|
}
|
||||||
|
public EntityElectroTrans(int speed, double weight, Color bodyColor ,Color additionalColor, boolean sail, boolean floaters) {
|
||||||
|
super(speed, weight, bodyColor);
|
||||||
|
AdditionalColor = additionalColor;
|
||||||
|
Horns = sail;
|
||||||
|
Battery = floaters;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String buffer = super.toString();
|
||||||
|
buffer += String.format(", Дополнительный цвет : RGB{%d, %d, %d}",
|
||||||
|
this.AdditionalColor.getRed(), this.AdditionalColor.getGreen(), this.AdditionalColor.getBlue());
|
||||||
|
buffer += ", Рога: " + this.Horns;
|
||||||
|
buffer += ", Батарея: " + this.Battery;
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,20 +4,27 @@ import java.awt.*;
|
|||||||
|
|
||||||
public class EntityTrans {
|
public class EntityTrans {
|
||||||
private int Speed;
|
private int Speed;
|
||||||
|
|
||||||
public int getSpeed() {
|
public int getSpeed() {
|
||||||
return Speed;
|
return Speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private double Weight;
|
private double Weight;
|
||||||
|
|
||||||
public double getWeight() {
|
public double getWeight() {
|
||||||
return Weight;
|
return Weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Color BodyColor;
|
private Color BodyColor;
|
||||||
|
|
||||||
public Color getBodyColor() {
|
public Color getBodyColor() {
|
||||||
return BodyColor;
|
return BodyColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
private double Step;
|
private double Step;
|
||||||
|
|
||||||
public double getStep() {
|
public double getStep() {
|
||||||
return Speed*100/Weight;
|
return Speed * 100 / Weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityTrans(int speed, double weight, Color bodyColor) {
|
public EntityTrans(int speed, double weight, Color bodyColor) {
|
||||||
@ -25,4 +32,14 @@ public class EntityTrans {
|
|||||||
Weight = weight;
|
Weight = weight;
|
||||||
BodyColor = bodyColor;
|
BodyColor = bodyColor;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String buffer = "";
|
||||||
|
buffer += "Скорость: " + this.Speed;
|
||||||
|
buffer += ", Вес: " + this.Weight;
|
||||||
|
buffer += String.format(", Основной цвет : RGB{%d, %d, %d}",
|
||||||
|
this.BodyColor.getRed(), this.BodyColor.getGreen(), this.BodyColor.getBlue());
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,131 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormElectroTrans">
|
|
||||||
<grid id="27dc6" binding="PanelWrapper" 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>
|
|
||||||
<xy x="20" y="20" width="599" height="476"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<grid id="1ff9a" binding="PictureBox" layout-manager="GridLayoutManager" row-count="6" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<toolTipText value=""/>
|
|
||||||
</properties>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<vspacer id="7b40c">
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" column="0" row-span="2" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false">
|
|
||||||
<preferred-size width="88" height="14"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
|
||||||
</vspacer>
|
|
||||||
<hspacer id="e0b21">
|
|
||||||
<constraints>
|
|
||||||
<grid row="4" 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="a8c2" class="javax.swing.JButton" binding="buttonCreateElectroTrans">
|
|
||||||
<constraints>
|
|
||||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="1" indent="0" use-parent-layout="false">
|
|
||||||
<minimum-size width="150" height="30"/>
|
|
||||||
<preferred-size width="150" height="30"/>
|
|
||||||
<maximum-size width="150" height="30"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Создать электропоезд"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="79b3e" class="javax.swing.JButton" binding="buttonCreateTrans">
|
|
||||||
<constraints>
|
|
||||||
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="10" fill="0" indent="0" use-parent-layout="false">
|
|
||||||
<minimum-size width="150" height="30"/>
|
|
||||||
<preferred-size width="150" height="30"/>
|
|
||||||
<maximum-size width="150" height="30"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Создать поезд"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="fe25b" class="javax.swing.JButton" binding="buttonLeft">
|
|
||||||
<constraints>
|
|
||||||
<grid row="5" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" 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>
|
|
||||||
<icon value="arrowLeft.png"/>
|
|
||||||
<text value=""/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="3eabd" class="javax.swing.JButton" binding="buttonStrategyStep">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="3" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Шаг"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="86d84" class="javax.swing.JButton" binding="buttonRight">
|
|
||||||
<constraints>
|
|
||||||
<grid row="5" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" 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>
|
|
||||||
<icon value="arrowRight.png"/>
|
|
||||||
<text value=""/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="3dc0" class="javax.swing.JButton" binding="buttonDown">
|
|
||||||
<constraints>
|
|
||||||
<grid row="5" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" 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>
|
|
||||||
<icon value="arrowDown.png"/>
|
|
||||||
<text value=""/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="ccb2a" class="javax.swing.JButton" binding="buttonUp">
|
|
||||||
<constraints>
|
|
||||||
<grid row="4" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" 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>
|
|
||||||
<icon value="arrowUp.png"/>
|
|
||||||
<text value=""/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="988c8" class="javax.swing.JComboBox" binding="comboBoxStrategy">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="2" row-span="1" col-span="3" vsize-policy="0" hsize-policy="2" anchor="9" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<actionCommand value=""/>
|
|
||||||
<doubleBuffered value="false"/>
|
|
||||||
<toolTipText value=""/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
</form>
|
|
@ -1,183 +0,0 @@
|
|||||||
import Drawnings.DrawningElectroTrans;
|
|
||||||
import Drawnings.DrawningTrans;
|
|
||||||
import MovementStrategy.*;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class FormElectroTrans extends JFrame {
|
|
||||||
protected DrawningTrans _drawningTrans;
|
|
||||||
JPanel PanelWrapper;
|
|
||||||
private JPanel PictureBox;
|
|
||||||
private JButton buttonCreateElectroTrans;
|
|
||||||
private JButton buttonCreateTrans;
|
|
||||||
private JButton buttonRight;
|
|
||||||
private JButton buttonDown;
|
|
||||||
private JButton buttonLeft;
|
|
||||||
private JButton buttonUp;
|
|
||||||
private JComboBox comboBoxStrategy;
|
|
||||||
private JButton buttonStrategyStep;
|
|
||||||
private AbstractStrategy _strategy;
|
|
||||||
private List<JComponent> controls;
|
|
||||||
|
|
||||||
private void createObject(String type) {
|
|
||||||
Random random = new Random();
|
|
||||||
switch (type) {
|
|
||||||
case "Drawnings.DrawningTrans":
|
|
||||||
_drawningTrans = new DrawningTrans(random.nextInt(70 - 30) + 30, random.nextInt(500 - 100) + 100,
|
|
||||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), random.nextInt(3));
|
|
||||||
break;
|
|
||||||
case "Drawnings.DrawningElectroTrans":
|
|
||||||
_drawningTrans = new DrawningElectroTrans(random.nextInt(70 - 30) + 30, random.nextInt(500 - 100) + 100,
|
|
||||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), random.nextInt(3),
|
|
||||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
|
||||||
random.nextBoolean(), random.nextBoolean());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_drawningTrans.setPictureSize(PictureBox.getWidth(), PictureBox.getHeight());
|
|
||||||
_drawningTrans.setPosition(random.nextInt(25, 100),
|
|
||||||
random.nextInt(25, 100));
|
|
||||||
_strategy = null;
|
|
||||||
comboBoxStrategy.setEnabled(true);
|
|
||||||
|
|
||||||
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
public FormElectroTrans() {
|
|
||||||
buttonUp.setName("buttonUp");
|
|
||||||
buttonDown.setName("buttonDown");
|
|
||||||
buttonLeft.setName("buttonLeft");
|
|
||||||
buttonRight.setName("buttonRight");
|
|
||||||
|
|
||||||
InitializeControlsRepaintList();
|
|
||||||
|
|
||||||
buttonCreateElectroTrans.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
createObject("Drawnings.DrawningElectroTrans");
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
buttonCreateTrans.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
createObject("Drawnings.DrawningTrans");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ActionListener buttonMoveClickedListener = new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
String buttonName = ((JButton) e.getSource()).getName();
|
|
||||||
boolean result = false;
|
|
||||||
|
|
||||||
switch (buttonName) {
|
|
||||||
case "buttonUp": {
|
|
||||||
result = _drawningTrans.moveTransport(MovementDirection.Up);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "buttonDown": {
|
|
||||||
result = _drawningTrans.moveTransport(MovementDirection.Down);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "buttonLeft": {
|
|
||||||
result = _drawningTrans.moveTransport(MovementDirection.Left);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "buttonRight": {
|
|
||||||
result = _drawningTrans.moveTransport(MovementDirection.Right);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
if (result)
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
buttonRight.addActionListener(buttonMoveClickedListener);
|
|
||||||
buttonDown.addActionListener(buttonMoveClickedListener);
|
|
||||||
buttonLeft.addActionListener(buttonMoveClickedListener);
|
|
||||||
buttonUp.addActionListener(buttonMoveClickedListener);
|
|
||||||
|
|
||||||
comboBoxStrategy.addItem("К центру");
|
|
||||||
comboBoxStrategy.addItem("К краю");
|
|
||||||
buttonStrategyStep.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
if (_drawningTrans == null)
|
|
||||||
return;
|
|
||||||
if (comboBoxStrategy.isEnabled()) {
|
|
||||||
switch (comboBoxStrategy.getSelectedIndex()) {
|
|
||||||
case 0:
|
|
||||||
_strategy = new MoveToCenter();
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
_strategy = new MoveToBorder();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
_strategy = null;
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
if (_strategy == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_strategy.SetData(new MoveableTrans(_drawningTrans), PictureBox.getWidth(), PictureBox.getHeight());
|
|
||||||
}
|
|
||||||
if (_strategy == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_strategy.MakeStep();
|
|
||||||
Draw();
|
|
||||||
comboBoxStrategy.setEnabled(false);
|
|
||||||
|
|
||||||
if (_strategy.GetStatus() == StrategyStatus.Finish) {
|
|
||||||
comboBoxStrategy.setEnabled(true);
|
|
||||||
_strategy = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
private void Draw() {
|
|
||||||
if (_drawningTrans.getEntityTrans() == null)
|
|
||||||
return;
|
|
||||||
if (PictureBox.getWidth() == 0 || PictureBox.getHeight() == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Graphics g = PictureBox.getGraphics();
|
|
||||||
g.setColor(PictureBox.getBackground());
|
|
||||||
g.fillRect(0,0, PictureBox.getWidth(), PictureBox.getHeight());
|
|
||||||
_drawningTrans.drawTrans(g);
|
|
||||||
|
|
||||||
RepaintControls();
|
|
||||||
}
|
|
||||||
private void RepaintControls() {
|
|
||||||
for (JComponent control : controls) {
|
|
||||||
control.repaint();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void InitializeControlsRepaintList() {
|
|
||||||
controls = new LinkedList<>();
|
|
||||||
controls.add(buttonCreateElectroTrans);
|
|
||||||
controls.add(buttonCreateTrans);
|
|
||||||
controls.add(buttonUp);
|
|
||||||
controls.add(buttonDown);
|
|
||||||
controls.add(buttonLeft);
|
|
||||||
controls.add(buttonRight);
|
|
||||||
controls.add(comboBoxStrategy);
|
|
||||||
controls.add(buttonStrategyStep);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
92
ProjectElectroTrans/src/Forms/FormConstructor.java
Normal file
92
ProjectElectroTrans/src/Forms/FormConstructor.java
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
package Forms;
|
||||||
|
|
||||||
|
import Drawnings.DrawningConstructor;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
|
|
||||||
|
public class FormConstructor extends JFrame {
|
||||||
|
private JFrame jFrameConstructor = new JFrame();
|
||||||
|
public JFrame getjFrameConstructor() {
|
||||||
|
return jFrameConstructor;
|
||||||
|
}
|
||||||
|
private JButton addButton = new JButton("Добавить объект");
|
||||||
|
public JButton getAddButton() {
|
||||||
|
return addButton;
|
||||||
|
}
|
||||||
|
public JButton reCreateButton = new JButton("Пересоздать");
|
||||||
|
private final DrawningConstructor constructor = new DrawningConstructor();
|
||||||
|
public DrawningConstructor getConstructor() {
|
||||||
|
return constructor;
|
||||||
|
}
|
||||||
|
JPanel entitiesInfoPanel = new JPanel();
|
||||||
|
JLabel firstEntityLabel = new JLabel();
|
||||||
|
JLabel secondEntityLabel = new JLabel();
|
||||||
|
JLabel thirdEntityLabel = new JLabel();
|
||||||
|
|
||||||
|
JPanel wheelsInfoPanel = new JPanel();
|
||||||
|
JLabel firstPaddlesLabel = new JLabel();
|
||||||
|
JLabel secondPaddlesLabel = new JLabel();
|
||||||
|
JLabel thirdPaddlesLabel = new JLabel();
|
||||||
|
|
||||||
|
public void OpenFrame() {
|
||||||
|
|
||||||
|
Toolkit tolls = Toolkit.getDefaultToolkit();
|
||||||
|
Dimension dimension = tolls.getScreenSize();
|
||||||
|
jFrameConstructor.setBounds(dimension.width / 2 - 250, dimension.height / 2 - 250,
|
||||||
|
800, 300);
|
||||||
|
jFrameConstructor.setLayout(new BorderLayout());
|
||||||
|
|
||||||
|
firstEntityLabel.setText(constructor.getEntityString(0));
|
||||||
|
secondEntityLabel.setText(constructor.getEntityString(1));
|
||||||
|
thirdEntityLabel.setText(constructor.getEntityString(2));
|
||||||
|
|
||||||
|
entitiesInfoPanel.setLayout(new BoxLayout(entitiesInfoPanel, BoxLayout.Y_AXIS));
|
||||||
|
entitiesInfoPanel.setBorder(BorderFactory.createTitledBorder("Entities"));
|
||||||
|
entitiesInfoPanel.setSize(500, 130);
|
||||||
|
entitiesInfoPanel.setLocation(150, 10);
|
||||||
|
entitiesInfoPanel.add(firstEntityLabel);
|
||||||
|
entitiesInfoPanel.add(secondEntityLabel);
|
||||||
|
entitiesInfoPanel.add(thirdEntityLabel);
|
||||||
|
|
||||||
|
firstPaddlesLabel.setText(constructor.getWheelsString(0));
|
||||||
|
secondPaddlesLabel.setText(constructor.getWheelsString(1));
|
||||||
|
thirdPaddlesLabel.setText(constructor.getWheelsString(2));
|
||||||
|
|
||||||
|
|
||||||
|
wheelsInfoPanel.setLayout(new BoxLayout(wheelsInfoPanel, BoxLayout.Y_AXIS));
|
||||||
|
wheelsInfoPanel.setBorder(BorderFactory.createTitledBorder("Wheels"));
|
||||||
|
wheelsInfoPanel.setSize(500, 130);
|
||||||
|
wheelsInfoPanel.setLocation(150, 150);
|
||||||
|
wheelsInfoPanel.add(firstPaddlesLabel);
|
||||||
|
wheelsInfoPanel.add(secondPaddlesLabel);
|
||||||
|
wheelsInfoPanel.add(thirdPaddlesLabel);
|
||||||
|
|
||||||
|
addButton.setBounds(0, jFrameConstructor.getHeight() - 105, 150, 50);
|
||||||
|
reCreateButton.setBounds(0, jFrameConstructor.getHeight() - 135, 150, 30);
|
||||||
|
|
||||||
|
jFrameConstructor.add(wheelsInfoPanel);
|
||||||
|
jFrameConstructor.add(entitiesInfoPanel);
|
||||||
|
jFrameConstructor.add(addButton);
|
||||||
|
jFrameConstructor.add(reCreateButton);
|
||||||
|
jFrameConstructor.add(constructor);
|
||||||
|
jFrameConstructor.revalidate();
|
||||||
|
jFrameConstructor.repaint();
|
||||||
|
|
||||||
|
jFrameConstructor.addComponentListener(new ComponentAdapter() {
|
||||||
|
public void componentResized(ComponentEvent componentEvent) {
|
||||||
|
addButton.setLocation(0, jFrameConstructor.getSize().height - 105);
|
||||||
|
reCreateButton.setLocation(0, jFrameConstructor.getSize().height - 135);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
reCreateButton.addActionListener(e -> {
|
||||||
|
constructor.reCreateObj();
|
||||||
|
jFrameConstructor.repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
jFrameConstructor.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
113
ProjectElectroTrans/src/Forms/FormElectroTrans.java
Normal file
113
ProjectElectroTrans/src/Forms/FormElectroTrans.java
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
package Forms;
|
||||||
|
|
||||||
|
import Drawnings.*;
|
||||||
|
import MovementStrategy.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
|
|
||||||
|
|
||||||
|
public class FormElectroTrans extends JFrame {
|
||||||
|
final private JFrame JFrameElectroTrans = new JFrame();
|
||||||
|
final private JButton buttonRight = new JButton(new ImageIcon("ProjectElectroTrans\\Resources\\30px_arrow_right.png"));
|
||||||
|
final private JPanel RightPanel = new JPanel();
|
||||||
|
final private JButton buttonDown = new JButton(new ImageIcon("ProjectElectroTrans\\Resources\\30px_arrow_down.png"));
|
||||||
|
final private JPanel DownPanel = new JPanel();
|
||||||
|
final private JButton buttonLeft = new JButton(new ImageIcon("ProjectElectroTrans\\Resources\\30px_arrow_left.png"));
|
||||||
|
final private JPanel LeftPanel = new JPanel();
|
||||||
|
final private JButton buttonUp = new JButton(new ImageIcon("ProjectElectroTrans\\Resources\\30px_arrow_up.png"));
|
||||||
|
|
||||||
|
final private JPanel UpPanel = new JPanel();
|
||||||
|
final private String [] itemsComboBox = {
|
||||||
|
"К центру",
|
||||||
|
"К краю"
|
||||||
|
};
|
||||||
|
final private JComboBox<String> comboBoxStrategy =new JComboBox<>(itemsComboBox);
|
||||||
|
final private JButton buttonStrategyStep = new JButton("Шаг");
|
||||||
|
final private JPanel StrategyPanel = new JPanel(new BorderLayout());
|
||||||
|
|
||||||
|
final private DrawningFormCatamaran form = new DrawningFormCatamaran();
|
||||||
|
public void setDrawningTrans(DrawningTrans boat) {form.setDrawningTrans(boat);}
|
||||||
|
public void OpenFrame() {
|
||||||
|
JFrameElectroTrans.setVisible(true);
|
||||||
|
Toolkit tolls = Toolkit.getDefaultToolkit();
|
||||||
|
Dimension dimension = tolls.getScreenSize();
|
||||||
|
JFrameElectroTrans.setBounds(dimension.width / 2 - 250, dimension.height / 2 - 250,
|
||||||
|
970, 700);
|
||||||
|
JFrameElectroTrans.setTitle("Электропоезд");
|
||||||
|
|
||||||
|
comboBoxStrategy.setPreferredSize(new Dimension(100, 35));
|
||||||
|
buttonStrategyStep.setPreferredSize(new Dimension(100, 35));
|
||||||
|
StrategyPanel.setSize(100, 70);
|
||||||
|
StrategyPanel.add(comboBoxStrategy, BorderLayout.NORTH);
|
||||||
|
StrategyPanel.add(buttonStrategyStep, BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
|
||||||
|
UpPanel.setSize(30, 30);
|
||||||
|
buttonUp.setPreferredSize(new Dimension(30, 30));
|
||||||
|
UpPanel.add(buttonUp, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
DownPanel.setSize(30, 30);
|
||||||
|
buttonDown.setPreferredSize(new Dimension(30, 30));
|
||||||
|
DownPanel.add(buttonDown, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
RightPanel.setSize(30, 30);
|
||||||
|
buttonRight.setPreferredSize(new Dimension(30, 30));
|
||||||
|
RightPanel.add(buttonRight, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
LeftPanel.setSize(30, 30);
|
||||||
|
buttonLeft.setPreferredSize(new Dimension(30, 30));
|
||||||
|
LeftPanel.add(buttonLeft, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
JFrameElectroTrans.add(StrategyPanel);
|
||||||
|
JFrameElectroTrans.add(UpPanel);
|
||||||
|
JFrameElectroTrans.add(DownPanel);
|
||||||
|
JFrameElectroTrans.add(RightPanel);
|
||||||
|
JFrameElectroTrans.add(LeftPanel);
|
||||||
|
JFrameElectroTrans.add(form);
|
||||||
|
|
||||||
|
JFrameElectroTrans.addComponentListener(new ComponentAdapter() {
|
||||||
|
public void componentResized(ComponentEvent e) {
|
||||||
|
StrategyPanel.setLocation(JFrameElectroTrans.getWidth() - 100, 0);
|
||||||
|
UpPanel.setLocation(JFrameElectroTrans.getWidth() - 80, JFrameElectroTrans.getHeight()-100);
|
||||||
|
DownPanel.setLocation(JFrameElectroTrans.getWidth() - 80, JFrameElectroTrans.getHeight()-70);
|
||||||
|
RightPanel.setLocation(JFrameElectroTrans.getWidth() - 45, JFrameElectroTrans.getHeight()-70);
|
||||||
|
LeftPanel.setLocation(JFrameElectroTrans.getWidth() - 115, JFrameElectroTrans.getHeight()-70);
|
||||||
|
|
||||||
|
form.setPictureSize(JFrameElectroTrans.getWidth(), JFrameElectroTrans.getHeight());
|
||||||
|
JFrameElectroTrans.repaint();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonUp.addActionListener(e -> {
|
||||||
|
form.setPictureSize(JFrameElectroTrans.getWidth(), JFrameElectroTrans.getHeight());
|
||||||
|
form.MoveButtonsAction(MovementDirection.Up);
|
||||||
|
JFrameElectroTrans.repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonDown.addActionListener(e -> {
|
||||||
|
form.setPictureSize(JFrameElectroTrans.getWidth(), JFrameElectroTrans.getHeight());
|
||||||
|
form.MoveButtonsAction(MovementDirection.Down);
|
||||||
|
JFrameElectroTrans.repaint();
|
||||||
|
});
|
||||||
|
buttonLeft.addActionListener(e -> {
|
||||||
|
form.setPictureSize(JFrameElectroTrans.getWidth(), JFrameElectroTrans.getHeight());
|
||||||
|
form.MoveButtonsAction(MovementDirection.Left);
|
||||||
|
JFrameElectroTrans.repaint();
|
||||||
|
});
|
||||||
|
buttonRight.addActionListener(e -> {
|
||||||
|
form.setPictureSize(JFrameElectroTrans.getWidth(), JFrameElectroTrans.getHeight());
|
||||||
|
form.MoveButtonsAction(MovementDirection.Right);
|
||||||
|
JFrameElectroTrans.repaint();
|
||||||
|
});
|
||||||
|
buttonStrategyStep.addActionListener(e -> {
|
||||||
|
form.setPictureSize(JFrameElectroTrans.getWidth(), JFrameElectroTrans.getHeight());
|
||||||
|
form.buttonStrategyStep(comboBoxStrategy);
|
||||||
|
JFrameElectroTrans.repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
164
ProjectElectroTrans/src/Forms/FormTransCollection.java
Normal file
164
ProjectElectroTrans/src/Forms/FormTransCollection.java
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
package Forms;
|
||||||
|
|
||||||
|
import Drawnings.DrawningAbstractCompany;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.text.NumberFormatter;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
|
||||||
|
public class FormTransCollection extends JFrame {
|
||||||
|
final private JFrame jFrameCollectionTranss = new JFrame();
|
||||||
|
final private DrawningAbstractCompany _company = new DrawningAbstractCompany();
|
||||||
|
final private JButton refreshButton = new JButton("Обновить");
|
||||||
|
final private JPanel refreshPanel = new JPanel();
|
||||||
|
final private String[] listOfComboBox = {
|
||||||
|
|
||||||
|
"",
|
||||||
|
"Хранилище"
|
||||||
|
};
|
||||||
|
final private JComboBox<String> comboBoxSelectorCompany = new JComboBox<>(listOfComboBox);
|
||||||
|
final private JPanel comboBoxPanel = new JPanel();
|
||||||
|
final private JPanel toolsPanel = new JPanel();
|
||||||
|
final private JLabel toolsNameLabel = new JLabel("Инструменты");
|
||||||
|
final private JPanel labelPanel = new JPanel();
|
||||||
|
final private JButton buttonAddTrans = new JButton("Добавить поезд");
|
||||||
|
final private JButton buttonAddElectroTrans = new JButton("Добавить Электропоезд");
|
||||||
|
final private JPanel addTransPanel = new JPanel();
|
||||||
|
final private JPanel addElectroTransPanel = new JPanel();
|
||||||
|
final private JButton buttonRemove = new JButton("Удалить поезд");
|
||||||
|
final private JPanel removePanel = new JPanel();
|
||||||
|
final private JButton goToCheckButton = new JButton("Отправит на тесты");
|
||||||
|
final private JPanel goToCheckPanel = new JPanel();
|
||||||
|
final private JPanel addFromConstructorPanel = new JPanel();
|
||||||
|
final private JButton addFromConstructorButton = new JButton("Добавить из констркутора");
|
||||||
|
|
||||||
|
public void OpenFrame() {
|
||||||
|
|
||||||
|
jFrameCollectionTranss.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
Toolkit tolls = Toolkit.getDefaultToolkit();
|
||||||
|
Dimension dimension = tolls.getScreenSize();
|
||||||
|
jFrameCollectionTranss.setBounds(dimension.width / 2 - 250, dimension.height / 2 - 250,
|
||||||
|
1200, 665);
|
||||||
|
jFrameCollectionTranss.setTitle("Коллекция поездов");
|
||||||
|
|
||||||
|
toolsPanel.setBackground(Color.BLACK);
|
||||||
|
labelPanel.setSize(new Dimension(100, 20));
|
||||||
|
labelPanel.add(toolsNameLabel);
|
||||||
|
|
||||||
|
comboBoxPanel.setLayout(new BorderLayout());
|
||||||
|
comboBoxPanel.setSize(new Dimension(130, 30));
|
||||||
|
comboBoxPanel.add(comboBoxSelectorCompany, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
addTransPanel.setLayout(new BorderLayout());
|
||||||
|
addTransPanel.setSize(170, 40);
|
||||||
|
addTransPanel.add(buttonAddTrans, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
addElectroTransPanel.setLayout(new BorderLayout());
|
||||||
|
addElectroTransPanel.setSize(170, 40);
|
||||||
|
addElectroTransPanel.add(buttonAddElectroTrans, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
removePanel.setLayout(new BorderLayout());
|
||||||
|
removePanel.setSize(170, 40);
|
||||||
|
removePanel.add(buttonRemove, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
goToCheckPanel.setLayout(new BorderLayout());
|
||||||
|
goToCheckPanel.setSize(170, 40);
|
||||||
|
goToCheckPanel.add(goToCheckButton, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
refreshPanel.setLayout(new BorderLayout());
|
||||||
|
refreshPanel.setSize(170, 40);
|
||||||
|
refreshPanel.add(refreshButton, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
addFromConstructorPanel.setLayout(new BorderLayout());
|
||||||
|
addFromConstructorPanel.setSize(170, 40);
|
||||||
|
addFromConstructorPanel.add(addFromConstructorButton, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
NumberFormat format = NumberFormat.getInstance();
|
||||||
|
NumberFormatter formatter = new NumberFormatter(format);
|
||||||
|
formatter.setValueClass(Integer.class);
|
||||||
|
formatter.setMinimum(0);
|
||||||
|
formatter.setMaximum(100);
|
||||||
|
formatter.setAllowsInvalid(true);
|
||||||
|
formatter.setCommitsOnValidEdit(true);
|
||||||
|
|
||||||
|
JTextField textBoxPosition = new JFormattedTextField(formatter);
|
||||||
|
JPanel textBoxPanel = new JPanel();
|
||||||
|
textBoxPanel.setLayout(new BorderLayout());
|
||||||
|
textBoxPanel.setSize(170, 40);
|
||||||
|
textBoxPanel.add(textBoxPosition, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
jFrameCollectionTranss.add(toolsPanel);
|
||||||
|
jFrameCollectionTranss.add(labelPanel);
|
||||||
|
jFrameCollectionTranss.add(comboBoxPanel);
|
||||||
|
jFrameCollectionTranss.add(addTransPanel);
|
||||||
|
jFrameCollectionTranss.add(addElectroTransPanel);
|
||||||
|
jFrameCollectionTranss.add(textBoxPanel);
|
||||||
|
jFrameCollectionTranss.add(removePanel);
|
||||||
|
jFrameCollectionTranss.add(goToCheckPanel);
|
||||||
|
jFrameCollectionTranss.add(refreshPanel);
|
||||||
|
jFrameCollectionTranss.add(addFromConstructorPanel);
|
||||||
|
jFrameCollectionTranss.add(_company);
|
||||||
|
|
||||||
|
jFrameCollectionTranss.addComponentListener(new ComponentAdapter() {
|
||||||
|
public void componentResized(ComponentEvent componentEvent) {
|
||||||
|
labelPanel.setLocation(jFrameCollectionTranss.getWidth() - 210, 0);
|
||||||
|
toolsPanel.setLocation(jFrameCollectionTranss.getWidth() - 233, 0);
|
||||||
|
comboBoxPanel.setLocation(jFrameCollectionTranss.getWidth() - 200, 30);
|
||||||
|
addTransPanel.setLocation(jFrameCollectionTranss.getWidth() - 200, 70);
|
||||||
|
addElectroTransPanel.setLocation(jFrameCollectionTranss.getWidth() - 200, 120);
|
||||||
|
textBoxPanel.setLocation(jFrameCollectionTranss.getWidth() - 200, 220);
|
||||||
|
removePanel.setLocation(jFrameCollectionTranss.getWidth() - 200, 260);
|
||||||
|
goToCheckPanel.setLocation(jFrameCollectionTranss.getWidth() - 200, 300);
|
||||||
|
refreshPanel.setLocation(jFrameCollectionTranss.getWidth() - 200, 340);
|
||||||
|
addFromConstructorPanel.setLocation(jFrameCollectionTranss.getWidth() - 200, 170);
|
||||||
|
toolsPanel.setSize(new Dimension(10, jFrameCollectionTranss.getHeight()));
|
||||||
|
|
||||||
|
jFrameCollectionTranss.repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
comboBoxSelectorCompany.addActionListener(e -> {
|
||||||
|
|
||||||
|
_company.collectionComboBox_SelectedIndexChanged(comboBoxSelectorCompany,
|
||||||
|
jFrameCollectionTranss.getWidth() - 233, jFrameCollectionTranss.getHeight());
|
||||||
|
jFrameCollectionTranss.repaint();
|
||||||
|
|
||||||
|
});
|
||||||
|
buttonAddTrans.addActionListener(e -> {
|
||||||
|
_company.createObject(0, jFrameCollectionTranss);
|
||||||
|
jFrameCollectionTranss.repaint();
|
||||||
|
});
|
||||||
|
buttonAddElectroTrans.addActionListener(e -> {
|
||||||
|
_company.createObject(1, jFrameCollectionTranss);
|
||||||
|
jFrameCollectionTranss.repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonRemove.addActionListener(e -> {
|
||||||
|
if (!textBoxPosition.getText().isEmpty()) {
|
||||||
|
if (Integer.parseInt(textBoxPosition.getText()) <= 99
|
||||||
|
&& Integer.parseInt(textBoxPosition.getText()) >= 0) {
|
||||||
|
int pos = Integer.parseInt(textBoxPosition.getText());
|
||||||
|
_company.deleteButtonAction(pos, jFrameCollectionTranss);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jFrameCollectionTranss.repaint();
|
||||||
|
|
||||||
|
});
|
||||||
|
refreshButton.addActionListener(e -> {
|
||||||
|
jFrameCollectionTranss.repaint();
|
||||||
|
});
|
||||||
|
goToCheckButton.addActionListener(e -> {
|
||||||
|
_company.goToCheckButtonAction();
|
||||||
|
jFrameCollectionTranss.repaint();
|
||||||
|
});
|
||||||
|
addFromConstructorButton.addActionListener(e -> {
|
||||||
|
_company.getObjFromConstructor(jFrameCollectionTranss);
|
||||||
|
});
|
||||||
|
jFrameCollectionTranss.setVisible(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,19 +1,7 @@
|
|||||||
import javax.swing.*;
|
import Forms.FormTransCollection;
|
||||||
|
|
||||||
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
|
||||||
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
JFrame.setDefaultLookAndFeelDecorated(false);
|
FormTransCollection formTransCollection = new FormTransCollection();
|
||||||
JFrame frame = new JFrame("Элетроаоезд");
|
formTransCollection.OpenFrame();
|
||||||
frame.setContentPane(new FormElectroTrans().PanelWrapper);
|
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
frame.setLocation(500, 200);
|
|
||||||
frame.pack();
|
|
||||||
frame.setSize(700, 500);
|
|
||||||
frame.setVisible(true);
|
|
||||||
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
|
|
||||||
// to see how IntelliJ IDEA suggests fixing it.
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -38,6 +38,7 @@ public abstract class AbstractStrategy {
|
|||||||
protected boolean MoveRight() { return MoveTo(MovementDirection.Right); }
|
protected boolean MoveRight() { return MoveTo(MovementDirection.Right); }
|
||||||
protected boolean MoveUp() { return MoveTo(MovementDirection.Up); }
|
protected boolean MoveUp() { return MoveTo(MovementDirection.Up); }
|
||||||
protected boolean MoveDown() { return MoveTo(MovementDirection.Down); }
|
protected boolean MoveDown() { return MoveTo(MovementDirection.Down); }
|
||||||
|
|
||||||
protected ObjectParameters GetObjectParameters() { return _moveableObject.GetObjectPosition(); }
|
protected ObjectParameters GetObjectParameters() { return _moveableObject.GetObjectPosition(); }
|
||||||
|
|
||||||
protected int GetStep()
|
protected int GetStep()
|
||||||
@ -49,7 +50,9 @@ public abstract class AbstractStrategy {
|
|||||||
return _moveableObject.GetStep();
|
return _moveableObject.GetStep();
|
||||||
}
|
}
|
||||||
protected abstract void MoveToTarget();
|
protected abstract void MoveToTarget();
|
||||||
|
|
||||||
protected abstract boolean IsTargetDestination();
|
protected abstract boolean IsTargetDestination();
|
||||||
|
|
||||||
private boolean MoveTo(MovementDirection directionType)
|
private boolean MoveTo(MovementDirection directionType)
|
||||||
{
|
{
|
||||||
if (_state != StrategyStatus.InProgress)
|
if (_state != StrategyStatus.InProgress)
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
package MovementStrategy;
|
package MovementStrategy;
|
||||||
|
|
||||||
public class MoveToBorder extends AbstractStrategy {
|
public class MoveToBorder extends AbstractStrategy {
|
||||||
|
@Override
|
||||||
protected boolean IsTargetDestination()
|
protected boolean IsTargetDestination()
|
||||||
{
|
{
|
||||||
var objParams = GetObjectParameters();
|
var objParams = GetObjectParameters();
|
||||||
if (objParams == null) {
|
if (objParams == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return objParams.RightBorder() <= FieldWidth &&
|
return objParams.RightBorder() + GetStep() >= FieldWidth &&
|
||||||
objParams.RightBorder() + GetStep() >= FieldWidth &&
|
|
||||||
objParams.DownBorder() <= FieldHeight &&
|
|
||||||
objParams.DownBorder() + GetStep() >= FieldHeight;
|
objParams.DownBorder() + GetStep() >= FieldHeight;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
protected void MoveToTarget()
|
protected void MoveToTarget()
|
||||||
{
|
{
|
||||||
var objParams = GetObjectParameters();
|
var objParams = GetObjectParameters();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package MovementStrategy;
|
package MovementStrategy;
|
||||||
|
|
||||||
public class MoveToCenter extends AbstractStrategy {
|
public class MoveToCenter extends AbstractStrategy {
|
||||||
|
@Override
|
||||||
protected boolean IsTargetDestination()
|
protected boolean IsTargetDestination()
|
||||||
{
|
{
|
||||||
var objParams = GetObjectParameters();
|
var objParams = GetObjectParameters();
|
||||||
@ -12,6 +13,7 @@ public class MoveToCenter extends AbstractStrategy {
|
|||||||
objParams.ObjectMiddleVertical() - GetStep() <= FieldHeight / 2 &&
|
objParams.ObjectMiddleVertical() - GetStep() <= FieldHeight / 2 &&
|
||||||
objParams.ObjectMiddleVertical() + GetStep() >= FieldHeight / 2);
|
objParams.ObjectMiddleVertical() + GetStep() >= FieldHeight / 2);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
protected void MoveToTarget()
|
protected void MoveToTarget()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -43,4 +45,4 @@ public class MoveToCenter extends AbstractStrategy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
package MovementStrategy;
|
package MovementStrategy;
|
||||||
|
import Drawnings.*;
|
||||||
import Drawnings.DrawningTrans;
|
|
||||||
|
|
||||||
public class MoveableTrans implements IMoveableObject {
|
public class MoveableTrans implements IMoveableObject {
|
||||||
private DrawningTrans _trans = null;
|
private DrawningTrans _trans = null;
|
||||||
@ -11,14 +10,14 @@ public class MoveableTrans implements IMoveableObject {
|
|||||||
|
|
||||||
public ObjectParameters GetObjectPosition()
|
public ObjectParameters GetObjectPosition()
|
||||||
{
|
{
|
||||||
if (_trans == null || _trans.getEntityTrans() == null)
|
if (_trans == null || _trans.getEntityTran() == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new ObjectParameters(_trans.GetPosX(), _trans.GetPosY(), _trans.GetWidth(), _trans.GetHeight());
|
return new ObjectParameters(_trans.GetPosX(), _trans.GetPosY(), _trans.GetWidth(), _trans.GetHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetStep() { return (int) _trans.getEntityTrans().getStep(); }
|
public int GetStep() { return (int) _trans.getEntityTran().getStep(); }
|
||||||
public boolean TryMoveObject(MovementDirection direction) { return _trans.moveTransport(direction); }
|
public boolean TryMoveObject(MovementDirection direction) { return _trans.moveTransport(direction); }
|
||||||
public void MoveObject(MovementDirection direction) { _trans.moveTransport(direction); }
|
public void MoveObject(MovementDirection direction) { _trans.moveTransport(direction); }
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ public class ObjectParameters {
|
|||||||
public int RightBorder() { return _x + _width; }
|
public int RightBorder() { return _x + _width; }
|
||||||
public int DownBorder() { return _y + _height; }
|
public int DownBorder() { return _y + _height; }
|
||||||
|
|
||||||
|
|
||||||
public int ObjectMiddleHorizontal () { return _x + _width / 2; }
|
public int ObjectMiddleHorizontal () { return _x + _width / 2; }
|
||||||
public int ObjectMiddleVertical () { return _y + _height / 2; }
|
public int ObjectMiddleVertical () { return _y + _height / 2; }
|
||||||
|
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
out/production/ProjectElectroTrans/Drawnings/DrawningTrans.class
Normal file
BIN
out/production/ProjectElectroTrans/Drawnings/DrawningTrans.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
out/production/ProjectElectroTrans/Drawnings/IDrawWheels.class
Normal file
BIN
out/production/ProjectElectroTrans/Drawnings/IDrawWheels.class
Normal file
Binary file not shown.
BIN
out/production/ProjectElectroTrans/Drawnings/WheelsCount.class
Normal file
BIN
out/production/ProjectElectroTrans/Drawnings/WheelsCount.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
out/production/ProjectElectroTrans/Entities/EntityTrans.class
Normal file
BIN
out/production/ProjectElectroTrans/Entities/EntityTrans.class
Normal file
Binary file not shown.
BIN
out/production/ProjectElectroTrans/Forms/FormConstructor$1.class
Normal file
BIN
out/production/ProjectElectroTrans/Forms/FormConstructor$1.class
Normal file
Binary file not shown.
BIN
out/production/ProjectElectroTrans/Forms/FormConstructor.class
Normal file
BIN
out/production/ProjectElectroTrans/Forms/FormConstructor.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
out/production/ProjectElectroTrans/Forms/FormElectroTrans.class
Normal file
BIN
out/production/ProjectElectroTrans/Forms/FormElectroTrans.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
out/production/ProjectElectroTrans/Main.class
Normal file
BIN
out/production/ProjectElectroTrans/Main.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
out/production/ProjectElectroTrans/arrowDown.png
Normal file
BIN
out/production/ProjectElectroTrans/arrowDown.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 965 B |
BIN
out/production/ProjectElectroTrans/arrowLeft.png
Normal file
BIN
out/production/ProjectElectroTrans/arrowLeft.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1005 B |
BIN
out/production/ProjectElectroTrans/arrowRight.png
Normal file
BIN
out/production/ProjectElectroTrans/arrowRight.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 978 B |
BIN
out/production/ProjectElectroTrans/arrowUp.png
Normal file
BIN
out/production/ProjectElectroTrans/arrowUp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1012 B |
Loading…
Reference in New Issue
Block a user