Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
0f25143372 |
@ -2,7 +2,7 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectModuleManager">
|
<component name="ProjectModuleManager">
|
||||||
<modules>
|
<modules>
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/ProjectGasolineTankerHard.iml" filepath="$PROJECT_DIR$/.idea/ProjectGasolineTankerHard.iml" />
|
<module fileurl="file://$PROJECT_DIR$/1 lab hard.iml" filepath="$PROJECT_DIR$/1 lab hard.iml" />
|
||||||
</modules>
|
</modules>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
Binary file not shown.
Before Width: | Height: | Size: 808 B |
Binary file not shown.
Before Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.2 KiB |
@ -1,146 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public abstract class AbstractMap {
|
|
||||||
private IDrawingObject _drawingObject = null;
|
|
||||||
protected int[][] _map = null;
|
|
||||||
protected int _width;
|
|
||||||
protected int _height;
|
|
||||||
protected float _size_x;
|
|
||||||
protected float _size_y;
|
|
||||||
protected final Random _random = new Random();
|
|
||||||
protected final int _freeRoad = 0;
|
|
||||||
protected final int _barrier = 1;
|
|
||||||
|
|
||||||
public BufferedImage CreateMap(int width, int height, IDrawingObject drawingObject)
|
|
||||||
{
|
|
||||||
_width = width;
|
|
||||||
_height = height;
|
|
||||||
_drawingObject = drawingObject;
|
|
||||||
GenerateMap();
|
|
||||||
while (!SetObjectOnMap())
|
|
||||||
{
|
|
||||||
GenerateMap();
|
|
||||||
}
|
|
||||||
return DrawMapWithObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
public BufferedImage MoveObject(Direction direction)
|
|
||||||
{
|
|
||||||
if (true)
|
|
||||||
{
|
|
||||||
_drawingObject.MoveObject(direction);
|
|
||||||
}
|
|
||||||
float[] cortege = _drawingObject.GetCurrentPosition();
|
|
||||||
if (CheckLand(cortege[0],cortege[1],cortege[2],cortege[3])!= 0)
|
|
||||||
{
|
|
||||||
_drawingObject.MoveObject(SetOppositDirection(direction));
|
|
||||||
}
|
|
||||||
return DrawMapWithObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean SetObjectOnMap()
|
|
||||||
{
|
|
||||||
if (_drawingObject==null || _map == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
int x = _random.nextInt(10);
|
|
||||||
int y = _random.nextInt(10);
|
|
||||||
_drawingObject.SetObject(x, y, _width, _height);
|
|
||||||
|
|
||||||
float[] dim = _drawingObject.GetCurrentPosition();
|
|
||||||
|
|
||||||
while (CheckLand(dim[0], dim[1], dim[2], dim[3]) != 2)
|
|
||||||
{
|
|
||||||
int res;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
res = CheckLand(dim[0], dim[1], dim[2], dim[3]);
|
|
||||||
if (res == 0)
|
|
||||||
{
|
|
||||||
_drawingObject.SetObject((int)dim[0], (int)dim[1], _width, _height);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dim[0] += _size_x;
|
|
||||||
}
|
|
||||||
} while (res != 2);
|
|
||||||
dim[0] = x;
|
|
||||||
dim[1] += _size_y;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private BufferedImage DrawMapWithObject()
|
|
||||||
{
|
|
||||||
BufferedImage bmp = new BufferedImage(_width, _height,BufferedImage.TYPE_INT_RGB);
|
|
||||||
if (_drawingObject == null || _map == null)
|
|
||||||
{
|
|
||||||
return bmp;
|
|
||||||
}
|
|
||||||
Graphics gr = bmp.getGraphics();
|
|
||||||
for (int i = 0; i < _map.length; ++i)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < _map[i].length; ++j)
|
|
||||||
{
|
|
||||||
if (_map[i][j] == _freeRoad)
|
|
||||||
{
|
|
||||||
DrawBarrierPart(gr, i, j);
|
|
||||||
}
|
|
||||||
else if (_map[i][j] == _barrier)
|
|
||||||
{
|
|
||||||
DrawRoadPart(gr, i, j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_drawingObject.DrawingObject(gr);
|
|
||||||
return bmp;
|
|
||||||
}
|
|
||||||
private int CheckLand(float Left, float Right, float Top, float Bottom)
|
|
||||||
{
|
|
||||||
int RUi = (int)(Left / _size_x);
|
|
||||||
int RUj = (int)(Right / _size_y);
|
|
||||||
int LDi = (int)(Top / _size_x);
|
|
||||||
int LDj = (int)(Bottom / _size_y);
|
|
||||||
|
|
||||||
if (RUi < 0 || RUj < 0 || LDi >= _map[0].length || LDj >= _map.length)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
for (int x = RUi; x <= LDi; x++)
|
|
||||||
{
|
|
||||||
for (int y = RUj; y <= LDj; y++)
|
|
||||||
{
|
|
||||||
if (_map[x][y] == _barrier)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
private Direction SetOppositDirection(Direction dir)
|
|
||||||
{
|
|
||||||
switch (dir)
|
|
||||||
{
|
|
||||||
case Up:
|
|
||||||
return Direction.Down;
|
|
||||||
case Down:
|
|
||||||
return Direction.Up;
|
|
||||||
case Left:
|
|
||||||
return Direction.Right;
|
|
||||||
case Right:
|
|
||||||
return Direction.Left;
|
|
||||||
case None:
|
|
||||||
return Direction.None;
|
|
||||||
}
|
|
||||||
return Direction.None;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void GenerateMap();
|
|
||||||
protected abstract void DrawBarrierPart(Graphics gr, int i, int j);
|
|
||||||
protected abstract void DrawRoadPart(Graphics gr, int i, int j);
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
import java.util.ArrayList;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public class Action<T> {
|
|
||||||
private final ArrayList<Consumer<T>> listeners = new ArrayList<>();
|
|
||||||
|
|
||||||
public void addListener(Consumer<T> listener) {
|
|
||||||
listeners.add(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void emit(T gasolineTanker) {
|
|
||||||
for (var listener : listeners) {
|
|
||||||
listener.accept(gasolineTanker);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
import java.util.Random;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
public class CreaterGeneric <T extends EntityGasolineTanker, U extends IDrawningObjectWheels>{
|
|
||||||
ArrayList<T> GasolineTanker;
|
|
||||||
ArrayList<U> Wheels;
|
|
||||||
int GasolineTankerCount=0;
|
|
||||||
int WheelsCount=0;
|
|
||||||
public CreaterGeneric(int gasolineTankerCount,int wheelsCount){
|
|
||||||
GasolineTanker=new ArrayList<>(gasolineTankerCount);
|
|
||||||
Wheels=new ArrayList<>(wheelsCount);
|
|
||||||
}
|
|
||||||
public int Add(T gasolineTanker){
|
|
||||||
if(GasolineTankerCount<=GasolineTanker.size()){
|
|
||||||
GasolineTanker.add(gasolineTanker);
|
|
||||||
GasolineTankerCount++;
|
|
||||||
return GasolineTankerCount-1;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
public int Add(U wheels){
|
|
||||||
if(WheelsCount<=Wheels.size()){
|
|
||||||
Wheels.add(wheels);
|
|
||||||
WheelsCount++;
|
|
||||||
return WheelsCount-1;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
public DrawingGasolineTanker NewGasolineTankerCreating()
|
|
||||||
{
|
|
||||||
Random rand=new Random();
|
|
||||||
T gasolineTanker = (GasolineTanker.get(rand.nextInt(GasolineTankerCount)));
|
|
||||||
U wheel = (Wheels.get(rand.nextInt(WheelsCount)));
|
|
||||||
if(gasolineTanker instanceof EntityImprovedGasolineTanker){
|
|
||||||
return new DrawingImprovedGasolineTanker(gasolineTanker,wheel);
|
|
||||||
}
|
|
||||||
return new DrawingGasolineTanker(gasolineTanker,wheel);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +1,6 @@
|
|||||||
public enum Direction {
|
public enum Direction {
|
||||||
Up(1),
|
Up,
|
||||||
Down(2),
|
Down,
|
||||||
Left(3),
|
Left,
|
||||||
Right(4),
|
Right;
|
||||||
None(0);
|
|
||||||
Direction(int value){}
|
|
||||||
}
|
}
|
||||||
|
57
src/DrawingField.java
Normal file
57
src/DrawingField.java
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class DrawingField extends JPanel {
|
||||||
|
private final FormGasolineTanker field;
|
||||||
|
DrawingGasolineTanker _gasolineTanker;
|
||||||
|
public DrawingField(FormGasolineTanker field) {
|
||||||
|
this.field = field;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void paintComponent(Graphics g) {
|
||||||
|
super.paintComponent(g);
|
||||||
|
Graphics2D g2 =(Graphics2D)g;
|
||||||
|
if (_gasolineTanker!=null)
|
||||||
|
_gasolineTanker.DrawTransport(g2);
|
||||||
|
else return;
|
||||||
|
}
|
||||||
|
public void UpButtonAction(){
|
||||||
|
if (_gasolineTanker!=null)
|
||||||
|
_gasolineTanker.MoveTransport(Direction.Up);
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
public void DownButtonAction(){
|
||||||
|
if (_gasolineTanker!=null)
|
||||||
|
_gasolineTanker.MoveTransport(Direction.Down);
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
public void RightButtonAction(){
|
||||||
|
if (_gasolineTanker!=null)
|
||||||
|
_gasolineTanker.MoveTransport(Direction.Right);
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
public void LeftButtonAction(){
|
||||||
|
if (_gasolineTanker!=null)
|
||||||
|
_gasolineTanker.MoveTransport(Direction.Left);
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
public void CreateButtonAction(){
|
||||||
|
Random rnd=new Random();
|
||||||
|
_gasolineTanker=new DrawingGasolineTanker();
|
||||||
|
_gasolineTanker.Init(rnd.nextInt(50)+10,rnd.nextInt(100)+500,new Color(rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256)));
|
||||||
|
_gasolineTanker.SetPosition(rnd.nextInt(100)+10,rnd.nextInt(100)+10,getWidth(),getHeight());
|
||||||
|
field.SpeedLabel.setText("Speed: "+_gasolineTanker.getGasolineTanker().getSpeed());
|
||||||
|
field.WeightLabel.setText("Weight: "+_gasolineTanker.getGasolineTanker().getWeight());
|
||||||
|
field.BodyColorLabel.setText("Color: "+Integer.toHexString(_gasolineTanker.getGasolineTanker().getBodyColor().getRGB()).substring(2));
|
||||||
|
}
|
||||||
|
public void ResizeField(){
|
||||||
|
if (_gasolineTanker!=null)
|
||||||
|
_gasolineTanker.ChangeBorders(getWidth(),getHeight());
|
||||||
|
else return;
|
||||||
|
}
|
||||||
|
}
|
@ -1,80 +1,25 @@
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawingGasolineTanker {
|
public class DrawingGasolineTanker {
|
||||||
protected EntityGasolineTanker GasolineTanker;
|
public EntityGasolineTanker GasolineTanker;
|
||||||
public EntityGasolineTanker getGasolineTanker() {
|
public EntityGasolineTanker getGasolineTanker() {
|
||||||
return GasolineTanker;
|
return GasolineTanker;
|
||||||
}
|
}
|
||||||
protected IDrawningObjectWheels Wheels;
|
public DrawingWheels Wheels;
|
||||||
private CountWheels _wheels;
|
private int _startPosX;
|
||||||
protected int _startPosX;
|
private int _startPosY;
|
||||||
protected int _startPosY;
|
|
||||||
private Integer _pictureWidth = null;
|
private Integer _pictureWidth = null;
|
||||||
private Integer _pictureHeight = null;
|
private Integer _pictureHeight = null;
|
||||||
private int _gasolineTankerWidth = 160;
|
private final int _gasolineTankerWidth = 160;
|
||||||
private int _gasolineTankerHeight = 70;
|
private final int _gasolineTankerHeight = 55;
|
||||||
|
|
||||||
public DrawingGasolineTanker(int speed, float weight, Color bodyColor, int wheelsForm)
|
public void Init(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
GasolineTanker = new EntityGasolineTanker(speed, weight, bodyColor);
|
GasolineTanker = new EntityGasolineTanker();
|
||||||
Wheels= GetFormOfWheels(wheelsForm);
|
GasolineTanker.Init(speed, weight, bodyColor);
|
||||||
|
Wheels = new DrawingWheels();
|
||||||
Wheels.SetCountWheels((int)(2 + Math.random() + Math.random()*2));
|
Wheels.SetCountWheels((int)(2 + Math.random() + Math.random()*2));
|
||||||
}
|
}
|
||||||
public DrawingGasolineTanker(int speed, float weight, Color bodyColor, IDrawningObjectWheels wheelsForm)
|
|
||||||
{
|
|
||||||
GasolineTanker = new EntityGasolineTanker(speed, weight, bodyColor);
|
|
||||||
Wheels= wheelsForm;
|
|
||||||
}
|
|
||||||
public DrawingGasolineTanker(int speed, float weight,int countwheel, Color bodyColor)
|
|
||||||
{
|
|
||||||
GasolineTanker = new EntityGasolineTanker(speed, weight, bodyColor);
|
|
||||||
Wheels= GetFormOfWheels((int)(2 + Math.random() + Math.random()*2));
|
|
||||||
Wheels.SetCountWheels(countwheel);
|
|
||||||
}
|
|
||||||
public DrawingGasolineTanker(EntityGasolineTanker gasolineTanker,IDrawningObjectWheels wheels)
|
|
||||||
{
|
|
||||||
GasolineTanker = gasolineTanker;
|
|
||||||
Wheels = wheels;
|
|
||||||
}
|
|
||||||
public void SetWheels(IDrawningObjectWheels wheels){
|
|
||||||
Wheels = wheels;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetBodyColor(Color color){
|
|
||||||
GasolineTanker= new EntityGasolineTanker(GasolineTanker.getSpeed(), GasolineTanker.getWeight(), color);
|
|
||||||
}
|
|
||||||
public IDrawningObjectWheels GetWheels(){
|
|
||||||
return Wheels;
|
|
||||||
}
|
|
||||||
public IDrawningObjectWheels GetFormOfWheels(int FormOfWheel){
|
|
||||||
OrnamentForm temp = null;
|
|
||||||
for (OrnamentForm form:OrnamentForm.values()) {
|
|
||||||
if(form.Value==FormOfWheel){
|
|
||||||
temp = form;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(temp==null)
|
|
||||||
return null;
|
|
||||||
switch (temp){
|
|
||||||
case NoneOrnament:
|
|
||||||
return new DrawingWheels(_wheels);
|
|
||||||
case GrayOrnament:
|
|
||||||
return new DrawingOrnamentWheelsFirst(_wheels);
|
|
||||||
case RedOrnament:
|
|
||||||
return new DrawingOrnamentWheelsSecond(_wheels);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected DrawingGasolineTanker(int speed, float weight, Color bodyColor,int gasolineTankerWidth, int gasolineTankerHeight)
|
|
||||||
{
|
|
||||||
GasolineTanker = new EntityGasolineTanker(speed, weight, bodyColor);
|
|
||||||
Wheels= new DrawingWheels(_wheels);
|
|
||||||
Wheels.SetCountWheels((int)(2 + Math.random() + Math.random()*2));
|
|
||||||
_gasolineTankerWidth=gasolineTankerWidth;
|
|
||||||
_pictureHeight=gasolineTankerHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetPosition(int x, int y, int width, int height)
|
public void SetPosition(int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
@ -125,7 +70,6 @@ public class DrawingGasolineTanker {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawTransport(Graphics g)
|
public void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (_startPosX < 0 || _startPosY < 0 || _pictureHeight== null || _pictureWidth== null)
|
if (_startPosX < 0 || _startPosY < 0 || _pictureHeight== null || _pictureWidth== null)
|
||||||
@ -159,7 +103,6 @@ public class DrawingGasolineTanker {
|
|||||||
g2.drawRect(_startPosX + 120, _startPosY + 10, 25, 25);
|
g2.drawRect(_startPosX + 120, _startPosY + 10, 25, 25);
|
||||||
g2.fillRect(_startPosX + 120, _startPosY + 10, 25, 25);
|
g2.fillRect(_startPosX + 120, _startPosY + 10, 25, 25);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ChangeBorders(int width,int height)
|
public void ChangeBorders(int width,int height)
|
||||||
{
|
{
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
@ -179,12 +122,4 @@ public class DrawingGasolineTanker {
|
|||||||
_startPosY = _pictureHeight - _gasolineTankerHeight;
|
_startPosY = _pictureHeight - _gasolineTankerHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public float[] GetCurrentPosition() {
|
|
||||||
float[] dim = new float[4];
|
|
||||||
dim[0] = _startPosX;
|
|
||||||
dim[1] =_startPosY;
|
|
||||||
dim[2] = _startPosX + _gasolineTankerWidth;
|
|
||||||
dim[3] = _startPosY + _gasolineTankerHeight;
|
|
||||||
return dim;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,72 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class DrawingImprovedGasolineTanker extends DrawingGasolineTanker {
|
|
||||||
|
|
||||||
public DrawingImprovedGasolineTanker(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean antena,int wheelForm) {
|
|
||||||
super(speed, weight, bodyColor, 160, 70);
|
|
||||||
GasolineTanker=new EntityImprovedGasolineTanker(speed,weight,bodyColor,dopColor,bodyKit,antena);
|
|
||||||
Wheels= GetFormOfWheels(wheelForm);
|
|
||||||
Wheels.SetCountWheels((int)(2 + Math.random() + Math.random()*2));
|
|
||||||
}
|
|
||||||
public DrawingImprovedGasolineTanker(int speed, float weight,int countwheels, Color bodyColor, Color dopColor, boolean bodyKit,boolean antena) {
|
|
||||||
super(speed, weight, bodyColor, 120, 50);
|
|
||||||
GasolineTanker=new EntityImprovedGasolineTanker(speed,weight,bodyColor,dopColor,bodyKit,antena);
|
|
||||||
Wheels.SetCountWheels(countwheels);
|
|
||||||
}
|
|
||||||
public DrawingImprovedGasolineTanker(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean antena,IDrawningObjectWheels wheelForm) {
|
|
||||||
super(speed, weight, bodyColor, 160, 70);
|
|
||||||
GasolineTanker=new EntityImprovedGasolineTanker(speed,weight,bodyColor,dopColor,bodyKit,antena);
|
|
||||||
Wheels= wheelForm;
|
|
||||||
}
|
|
||||||
public DrawingImprovedGasolineTanker(EntityGasolineTanker gasolineTanker,IDrawningObjectWheels wheels) {
|
|
||||||
super(gasolineTanker,wheels);
|
|
||||||
GasolineTanker=gasolineTanker;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void SetBodyColor(Color color){
|
|
||||||
var gasolineTanker=(EntityImprovedGasolineTanker) GasolineTanker;
|
|
||||||
GasolineTanker=new EntityImprovedGasolineTanker(gasolineTanker.getSpeed(),gasolineTanker.getWeight(),color,gasolineTanker.GetDopColor(), gasolineTanker.GetBodyKit(), gasolineTanker.GetAntena());
|
|
||||||
}
|
|
||||||
public void SetDopColor(Color color){
|
|
||||||
var gasolineTanker=(EntityImprovedGasolineTanker) GasolineTanker;
|
|
||||||
GasolineTanker=new EntityImprovedGasolineTanker(gasolineTanker.getSpeed(),gasolineTanker.getWeight(),gasolineTanker.getBodyColor(),color, gasolineTanker.GetBodyKit(), gasolineTanker.GetAntena());
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void DrawTransport(Graphics g) {
|
|
||||||
|
|
||||||
if (! (GasolineTanker instanceof EntityImprovedGasolineTanker))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityImprovedGasolineTanker improvedGasolineTanker = (EntityImprovedGasolineTanker)GasolineTanker;
|
|
||||||
Graphics2D g2 = (Graphics2D) g;
|
|
||||||
|
|
||||||
int [] x1 ={_startPosX+25,_startPosX+65,_startPosX+75,_startPosX+25,_startPosX+25};
|
|
||||||
int [] y1 ={_startPosY,_startPosY,_startPosY+5,_startPosY+5,_startPosY};
|
|
||||||
int [] x2 ={_startPosX+25,_startPosX+75,_startPosX+65,_startPosX+25,_startPosX+25};
|
|
||||||
int [] y2 ={_startPosY+45,_startPosY+45,_startPosY+50,_startPosY+50,_startPosY+45};
|
|
||||||
|
|
||||||
if (improvedGasolineTanker.BodyKit)
|
|
||||||
{
|
|
||||||
g2.setColor(improvedGasolineTanker.GetDopColor());
|
|
||||||
g2.drawRect(_startPosX + 25, _startPosY + 5, 100, 35);
|
|
||||||
g2.fillRect(_startPosX + 25, _startPosY + 5, 100, 35);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
_startPosX += 10;
|
|
||||||
_startPosY += 5;
|
|
||||||
super.DrawTransport(g);
|
|
||||||
_startPosX -= 10;
|
|
||||||
_startPosY -= 5;
|
|
||||||
|
|
||||||
if (improvedGasolineTanker.Antena)
|
|
||||||
{
|
|
||||||
g2.setColor(Color.RED);
|
|
||||||
g2.drawRect(_startPosX + 130, _startPosY + 5, 10, 5);
|
|
||||||
g2.fillRect(_startPosX + 130, _startPosY + 5, 10, 5);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class DrawingObjectGasolineTanker implements IDrawingObject {
|
|
||||||
|
|
||||||
private DrawingGasolineTanker _gasolineTanker;
|
|
||||||
|
|
||||||
public DrawingObjectGasolineTanker(DrawingGasolineTanker gasolineTanker)
|
|
||||||
{
|
|
||||||
_gasolineTanker= gasolineTanker;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float Step() {
|
|
||||||
if(_gasolineTanker != null && _gasolineTanker.GasolineTanker != null)
|
|
||||||
return _gasolineTanker.GasolineTanker.Step;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void SetObject(int x, int y, int width, int height) {
|
|
||||||
_gasolineTanker.SetPosition(x,y,width,height);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void MoveObject(Direction direction) {
|
|
||||||
_gasolineTanker.MoveTransport(direction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void DrawingObject(Graphics g) {
|
|
||||||
_gasolineTanker.DrawTransport(g);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float[] GetCurrentPosition() {
|
|
||||||
if(_gasolineTanker!=null)
|
|
||||||
return _gasolineTanker.GetCurrentPosition();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String GetInfo() {
|
|
||||||
if(_gasolineTanker==null)
|
|
||||||
return null;
|
|
||||||
return ExtentionGasolineTanker.GetDataForSave(_gasolineTanker);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IDrawingObject Create(String data){
|
|
||||||
return new DrawingObjectGasolineTanker(ExtentionGasolineTanker.CreateDrawingGasolineTanker(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
public DrawingGasolineTanker GetGasolineTanker() {
|
|
||||||
return _gasolineTanker;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class DrawingOrnamentWheelsFirst implements IDrawningObjectWheels{
|
|
||||||
private CountWheels _wheels;
|
|
||||||
|
|
||||||
public DrawingOrnamentWheelsFirst(CountWheels wheels){
|
|
||||||
_wheels=wheels;
|
|
||||||
}
|
|
||||||
public DrawingOrnamentWheelsFirst(int count) {
|
|
||||||
SetCountWheels(count);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void SetCountWheels(int count) {
|
|
||||||
for (CountWheels temp: CountWheels.values())
|
|
||||||
if (temp.getCountWheels() == count){
|
|
||||||
_wheels=temp;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void DrawWheels(Graphics2D g, int _startPosX, int _startPosY) {
|
|
||||||
if (_wheels.getCountWheels() == 2) {
|
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
|
||||||
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
|
||||||
g.setColor(Color.GRAY);
|
|
||||||
g.drawOval(_startPosX + 130, _startPosY + 45, 20, 5);
|
|
||||||
g.drawOval(_startPosX + 10, _startPosY + 45, 20, 5);
|
|
||||||
}
|
|
||||||
if (_wheels.getCountWheels() == 3) {
|
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
|
||||||
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
|
||||||
g.drawOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
|
||||||
g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
|
||||||
g.setColor(Color.GRAY);
|
|
||||||
g.drawOval(_startPosX + 130, _startPosY + 45, 20, 5);
|
|
||||||
g.drawOval(_startPosX + 30, _startPosY + 45, 20, 5);
|
|
||||||
g.drawOval(_startPosX + 10, _startPosY + 45, 20, 5);
|
|
||||||
}
|
|
||||||
if (_wheels.getCountWheels() == 4) {
|
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
|
||||||
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
|
||||||
g.drawOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
|
||||||
g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
|
||||||
g.drawOval(_startPosX + 50, _startPosY + 35, 20, 20);
|
|
||||||
g.fillOval(_startPosX + 50, _startPosY + 35, 20, 20);
|
|
||||||
g.setColor(Color.GRAY);
|
|
||||||
g.drawOval(_startPosX + 130, _startPosY + 45, 20, 5);
|
|
||||||
g.drawOval(_startPosX + 50, _startPosY + 45, 20, 5);
|
|
||||||
g.drawOval(_startPosX + 30, _startPosY + 45, 20, 5);
|
|
||||||
g.drawOval(_startPosX + 10, _startPosY + 45, 20, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String GetCount() {
|
|
||||||
return Integer.toString(_wheels.getCountWheels());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class DrawingOrnamentWheelsSecond implements IDrawningObjectWheels{
|
|
||||||
private CountWheels _wheels;
|
|
||||||
|
|
||||||
public DrawingOrnamentWheelsSecond(CountWheels wheels){
|
|
||||||
_wheels=wheels;
|
|
||||||
}
|
|
||||||
public DrawingOrnamentWheelsSecond(int count) {
|
|
||||||
SetCountWheels(count);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void SetCountWheels(int count) {
|
|
||||||
for (CountWheels temp: CountWheels.values())
|
|
||||||
if (temp.getCountWheels() == count){
|
|
||||||
_wheels=temp;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void DrawWheels(Graphics2D g, int _startPosX, int _startPosY) {
|
|
||||||
|
|
||||||
if (_wheels.getCountWheels() == 2) {
|
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
|
||||||
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
|
||||||
g.setColor(Color.RED);
|
|
||||||
g.drawOval(_startPosX + 130, _startPosY + 45, 20, 5);
|
|
||||||
g.drawOval(_startPosX + 10, _startPosY + 45, 20, 5);
|
|
||||||
}
|
|
||||||
if (_wheels.getCountWheels() == 3) {
|
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
|
||||||
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
|
||||||
g.drawOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
|
||||||
g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
|
||||||
g.setColor(Color.RED);
|
|
||||||
g.drawOval(_startPosX + 130, _startPosY + 45, 20, 5);
|
|
||||||
g.drawOval(_startPosX + 30, _startPosY + 45, 20, 5);
|
|
||||||
g.drawOval(_startPosX + 10, _startPosY + 45, 20, 5);
|
|
||||||
}
|
|
||||||
if (_wheels.getCountWheels() == 4) {
|
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
|
||||||
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
|
||||||
g.drawOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
|
||||||
g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
|
||||||
g.drawOval(_startPosX + 50, _startPosY + 35, 20, 20);
|
|
||||||
g.fillOval(_startPosX + 50, _startPosY + 35, 20, 20);
|
|
||||||
g.setColor(Color.RED);
|
|
||||||
g.drawOval(_startPosX + 130, _startPosY + 45, 20, 5);
|
|
||||||
g.drawOval(_startPosX + 50, _startPosY + 45, 20, 5);
|
|
||||||
g.drawOval(_startPosX + 30, _startPosY + 45, 20, 5);
|
|
||||||
g.drawOval(_startPosX + 10, _startPosY + 45, 20, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String GetCount() {
|
|
||||||
return Integer.toString(_wheels.getCountWheels());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +1,8 @@
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawingWheels implements IDrawningObjectWheels{
|
public class DrawingWheels {
|
||||||
|
|
||||||
private CountWheels _wheels = null;
|
private CountWheels _wheels;
|
||||||
|
|
||||||
public DrawingWheels(CountWheels wheels) {
|
|
||||||
_wheels=wheels;
|
|
||||||
}
|
|
||||||
public DrawingWheels(int count) {
|
|
||||||
SetCountWheels(count);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetCountWheels(int Count){
|
public void SetCountWheels(int Count){
|
||||||
for (CountWheels temp: CountWheels.values())
|
for (CountWheels temp: CountWheels.values())
|
||||||
@ -20,19 +13,21 @@ public class DrawingWheels implements IDrawningObjectWheels{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void DrawWheels(Graphics2D g,int _startPosX, int _startPosY) {
|
public void DrawWheels(Graphics2D g,int _startPosX, int _startPosY) {
|
||||||
if (_wheels.getCountWheels() == 2) {
|
switch (_wheels.getCountWheels())
|
||||||
|
{
|
||||||
|
case 2:
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||||
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||||
}
|
break;
|
||||||
if (_wheels.getCountWheels() == 3) {
|
case 3:
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||||
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||||
g.drawOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
g.drawOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
||||||
g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
||||||
}
|
break;
|
||||||
if (_wheels.getCountWheels() == 4){
|
case 4:
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
g.drawOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||||
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
g.fillOval(_startPosX + 10, _startPosY + 35, 20, 20);
|
||||||
@ -40,11 +35,7 @@ public class DrawingWheels implements IDrawningObjectWheels{
|
|||||||
g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
g.fillOval(_startPosX + 30, _startPosY + 35, 20, 20);
|
||||||
g.drawOval(_startPosX + 50, _startPosY + 35, 20, 20);
|
g.drawOval(_startPosX + 50, _startPosY + 35, 20, 20);
|
||||||
g.fillOval(_startPosX + 50, _startPosY + 35, 20, 20);
|
g.fillOval(_startPosX + 50, _startPosY + 35, 20, 20);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String GetCount() {
|
|
||||||
return Integer.toString(_wheels.getCountWheels());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -14,15 +14,15 @@ public class EntityGasolineTanker {
|
|||||||
public Color getBodyColor() {
|
public Color getBodyColor() {
|
||||||
return BodyColor;
|
return BodyColor;
|
||||||
}
|
}
|
||||||
public int Step;
|
public float Step;
|
||||||
|
|
||||||
public EntityGasolineTanker(int speed, float weight, Color bodyColor){
|
public void Init(int speed, float weight, Color bodyColor){
|
||||||
|
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
Speed = speed <= 0 ? rnd.nextInt(50)+10 : speed;
|
Speed = speed <= 0 ? rnd.nextInt(50)+10 : speed;
|
||||||
Weight = weight <= 0 ? rnd.nextInt(100)+500 : weight;
|
Weight = weight <= 0 ? rnd.nextInt(100)+500 : weight;
|
||||||
BodyColor = bodyColor;
|
BodyColor = bodyColor;
|
||||||
Step = Speed * 5000/ (int)Weight;
|
Step = Speed * 100/ (int)Weight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class EntityImprovedGasolineTanker extends EntityGasolineTanker{
|
|
||||||
public Color DopColor;
|
|
||||||
public Color GetDopColor() {
|
|
||||||
return DopColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean BodyKit ;
|
|
||||||
public boolean GetBodyKit () {
|
|
||||||
return BodyKit ;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean Antena ;
|
|
||||||
public boolean GetAntena () {
|
|
||||||
return Antena ;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityImprovedGasolineTanker(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean antena){
|
|
||||||
super(speed,weight,bodyColor);
|
|
||||||
DopColor = dopColor;
|
|
||||||
BodyKit = bodyKit;
|
|
||||||
Antena = antena;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class ExtentionGasolineTanker {
|
|
||||||
private static final char _separatorForObject=':';
|
|
||||||
|
|
||||||
public static DrawingGasolineTanker CreateDrawingGasolineTanker(String info){
|
|
||||||
String[] strs = info.split(Character.toString(_separatorForObject));
|
|
||||||
|
|
||||||
int spd=Integer.parseInt(strs[0]);
|
|
||||||
float wght = Float.parseFloat(strs[1]);
|
|
||||||
Color bodyClr=new Color(Integer.parseInt(strs[2]));
|
|
||||||
IDrawningObjectWheels wheels = switch(strs[3]) {
|
|
||||||
case "DrawingWheels" -> new DrawingWheels(Integer.parseInt(strs[4]));
|
|
||||||
case "DrawingOrnamentWheelsFirst" -> new DrawingOrnamentWheelsFirst(Integer.parseInt(strs[4]));
|
|
||||||
case "DrawingOrnamentWheelsSecond" -> new DrawingOrnamentWheelsSecond(Integer.parseInt(strs[4]));
|
|
||||||
default -> null;
|
|
||||||
};
|
|
||||||
if (strs.length==5){
|
|
||||||
EntityGasolineTanker ent=new EntityGasolineTanker(spd,wght,bodyClr);
|
|
||||||
return new DrawingGasolineTanker(ent,wheels);
|
|
||||||
}
|
|
||||||
if(strs.length==8){
|
|
||||||
Color dopClr=new Color(Integer.parseInt(strs[5]));
|
|
||||||
boolean bdkit=Boolean.parseBoolean(strs[6]);
|
|
||||||
boolean ant=Boolean.parseBoolean(strs[7]);
|
|
||||||
EntityImprovedGasolineTanker ent = new EntityImprovedGasolineTanker(spd,wght,bodyClr,dopClr,bdkit,ant);
|
|
||||||
return new DrawingImprovedGasolineTanker(ent,wheels);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetDataForSave(DrawingGasolineTanker drawingGasolineTanker){
|
|
||||||
var gasolineTanker = drawingGasolineTanker.GasolineTanker;
|
|
||||||
var str = ""+gasolineTanker.getSpeed()+_separatorForObject+gasolineTanker.getWeight()+_separatorForObject+gasolineTanker.getBodyColor().getRGB()+_separatorForObject+drawingGasolineTanker.GetWheels().getClass().getSimpleName()+_separatorForObject+drawingGasolineTanker.GetWheels().GetCount();
|
|
||||||
if(!(gasolineTanker instanceof EntityImprovedGasolineTanker adv)){
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
return str+_separatorForObject+adv.GetDopColor().getRGB()+_separatorForObject+adv.GetBodyKit()+_separatorForObject+adv.GetAntena();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,230 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormCreater">
|
|
||||||
<grid id="27dc6" binding="PictureBox" layout-manager="GridLayoutManager" row-count="2" 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="1076" height="604"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<grid id="1ddce" layout-manager="GridLayoutManager" row-count="3" 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="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="bevel-lowered" title="Setting"/>
|
|
||||||
<children>
|
|
||||||
<grid id="4fd6c" layout-manager="GridLayoutManager" row-count="5" 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="2d416" layout-manager="GridLayoutManager" row-count="2" 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>
|
|
||||||
<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="bevel-lowered" title="Characteristics gasoline tanker"/>
|
|
||||||
<children>
|
|
||||||
<component id="5f2c7" class="javax.swing.JLabel" binding="SetSpeedLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Speed:"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="460f9" class="javax.swing.JTextField" binding="SpeedTextField">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
|
||||||
<preferred-size width="150" height="-1"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
</component>
|
|
||||||
<component id="8647d" class="javax.swing.JTextField" binding="WeightTextField">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
|
||||||
<preferred-size width="150" height="-1"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
</component>
|
|
||||||
<component id="635c7" class="javax.swing.JLabel" binding="SetWeightLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Weight:"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<grid id="f3a26" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="bevel-lowered" title="Improved"/>
|
|
||||||
<children>
|
|
||||||
<component id="a7785" class="javax.swing.JCheckBox" binding="BodyKitCheckBox">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Barrel"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="42af0" class="javax.swing.JCheckBox" binding="AntennaCheckBox">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Bulb"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<grid id="7b130" layout-manager="GridLayoutManager" row-count="2" 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="2" 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="bevel-lowered" title="Type gasoline tanker"/>
|
|
||||||
<children>
|
|
||||||
<component id="da325" class="javax.swing.JRadioButton" binding="BasicRadioButton">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Simple"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="a537c" class="javax.swing.JRadioButton" binding="AdvancedRadioButton">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Improved"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<grid id="b3fe8" layout-manager="GridLayoutManager" row-count="3" 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="3" 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="bevel-lowered" title="Count wheels"/>
|
|
||||||
<children>
|
|
||||||
<component id="c0d0c" class="javax.swing.JRadioButton" binding="TwoRadioButton">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="2"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="ffc90" class="javax.swing.JRadioButton" binding="ThreeRadioButton">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="3"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="eb57" class="javax.swing.JRadioButton" binding="FourRadioButton">
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="4"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<grid id="99a4b" layout-manager="GridLayoutManager" row-count="3" 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="4" 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="bevel-lowered" title="Color ornament"/>
|
|
||||||
<children>
|
|
||||||
<component id="acf86" class="javax.swing.JRadioButton" binding="NotOrnament">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Not ornament"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="52ce4" class="javax.swing.JRadioButton" binding="RedOrnament">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Red ornament"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="4f3ee" class="javax.swing.JRadioButton" binding="GrayOrnament">
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Gray ornament"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<component id="8917a" class="javax.swing.JButton" binding="ChooseButton">
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Choose"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="5c309" class="javax.swing.JButton" binding="ShowGasolineTankerButton">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" 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="Show"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<grid id="1063d" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<grid id="cc2a8" 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>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
</form>
|
|
@ -1,134 +0,0 @@
|
|||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class FormCreater extends JDialog{
|
|
||||||
private JButton ChooseButton;
|
|
||||||
private JButton ShowGasolineTankerButton;
|
|
||||||
private JTextField SpeedTextField;
|
|
||||||
private JTextField WeightTextField;
|
|
||||||
private JCheckBox BodyKitCheckBox;
|
|
||||||
private JCheckBox AntennaCheckBox;
|
|
||||||
private JRadioButton BasicRadioButton;
|
|
||||||
private JRadioButton AdvancedRadioButton;
|
|
||||||
private JRadioButton TwoRadioButton;
|
|
||||||
private JRadioButton ThreeRadioButton;
|
|
||||||
private JRadioButton FourRadioButton;
|
|
||||||
private JRadioButton NotOrnament;
|
|
||||||
private JRadioButton RedOrnament;
|
|
||||||
private JRadioButton GrayOrnament;
|
|
||||||
private JLabel SetSpeedLabel;
|
|
||||||
private JLabel SetWeightLabel;
|
|
||||||
private JPanel PictureBox;
|
|
||||||
CountWheels wheels=null;
|
|
||||||
IDrawningObjectWheels fwheels=null;
|
|
||||||
private final CreaterGeneric<EntityGasolineTanker,IDrawningObjectWheels> createrGeneric=new CreaterGeneric<>(40,40);
|
|
||||||
private DrawingGasolineTanker _gasolineTanker;
|
|
||||||
private DrawingGasolineTanker selectedGasolineTanker;
|
|
||||||
|
|
||||||
ImageIcon spriteUp =new ImageIcon((new ImageIcon("Material\\KeyUp.png")).
|
|
||||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
|
||||||
ImageIcon spriteDown =new ImageIcon((new ImageIcon("Material\\KeyDown.png")).
|
|
||||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
|
||||||
ImageIcon spriteLeft =new ImageIcon((new ImageIcon("Material\\KeyLeft.png")).
|
|
||||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
|
||||||
ImageIcon spriteRight =new ImageIcon((new ImageIcon("Material\\KeyRight.png")).
|
|
||||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
|
||||||
public FormCreater(){
|
|
||||||
setTitle("Gasoline tanker");
|
|
||||||
setContentPane(PictureBox);
|
|
||||||
setResizable(false);
|
|
||||||
setSize(1000,500);
|
|
||||||
ShowWindow();
|
|
||||||
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void paint(Graphics g) {
|
|
||||||
super.paint(g);
|
|
||||||
Graphics2D g2d = (Graphics2D) PictureBox.getGraphics();
|
|
||||||
if (_gasolineTanker != null) {
|
|
||||||
_gasolineTanker.DrawTransport(g2d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void ShowWindow(){
|
|
||||||
|
|
||||||
TwoRadioButton.addActionListener(e -> {
|
|
||||||
wheels=CountWheels.Two;
|
|
||||||
});
|
|
||||||
ThreeRadioButton.addActionListener(e -> {
|
|
||||||
wheels=CountWheels.Three;
|
|
||||||
});
|
|
||||||
FourRadioButton.addActionListener(e -> {
|
|
||||||
wheels=CountWheels.Four;
|
|
||||||
});
|
|
||||||
|
|
||||||
NotOrnament.addActionListener(e -> {
|
|
||||||
if(wheels==null){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fwheels=new DrawingWheels(wheels);
|
|
||||||
if(fwheels==null)
|
|
||||||
return;
|
|
||||||
fwheels.SetCountWheels(wheels.getCountWheels());
|
|
||||||
createrGeneric.Add(fwheels);
|
|
||||||
});
|
|
||||||
|
|
||||||
RedOrnament.addActionListener(e -> {
|
|
||||||
if(wheels==null){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fwheels=new DrawingOrnamentWheelsSecond(wheels);
|
|
||||||
if(fwheels==null)
|
|
||||||
return;
|
|
||||||
fwheels.SetCountWheels(wheels.getCountWheels());
|
|
||||||
createrGeneric.Add(fwheels);
|
|
||||||
});
|
|
||||||
|
|
||||||
GrayOrnament.addActionListener(e -> {
|
|
||||||
if(wheels==null){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fwheels=new DrawingOrnamentWheelsFirst(wheels);
|
|
||||||
if(fwheels==null)
|
|
||||||
return;
|
|
||||||
fwheels.SetCountWheels(wheels.getCountWheels());
|
|
||||||
createrGeneric.Add(fwheels);
|
|
||||||
});
|
|
||||||
|
|
||||||
BasicRadioButton.addActionListener(e -> {
|
|
||||||
Color color=JColorChooser.showDialog(this,"Select body color",Color.WHITE);
|
|
||||||
if(Integer.parseInt(SpeedTextField.getText())==0 || Integer.parseInt(WeightTextField.getText())==0 || color==null){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
createrGeneric.Add(new EntityGasolineTanker(Integer.parseInt(SpeedTextField.getText()),Integer.parseInt(WeightTextField.getText()),color));
|
|
||||||
});
|
|
||||||
|
|
||||||
AdvancedRadioButton.addActionListener(e -> {
|
|
||||||
Color color1=JColorChooser.showDialog(this,"Select body color",Color.WHITE);
|
|
||||||
if(Integer.parseInt(SpeedTextField.getText())==0 || Integer.parseInt(WeightTextField.getText())==0 || color1==null){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Color color2=JColorChooser.showDialog(this,"Select modification color",Color.WHITE);
|
|
||||||
if(color2==null){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
createrGeneric.Add(new EntityImprovedGasolineTanker(Integer.parseInt(SpeedTextField.getText()),Integer.parseInt(WeightTextField.getText()),
|
|
||||||
color1,color2, BodyKitCheckBox.isSelected(),AntennaCheckBox.isSelected()));
|
|
||||||
});
|
|
||||||
|
|
||||||
ShowGasolineTankerButton.addActionListener(e -> {
|
|
||||||
Random rand=new Random();
|
|
||||||
_gasolineTanker=createrGeneric.NewGasolineTankerCreating();
|
|
||||||
_gasolineTanker.SetPosition(rand.nextInt(100),rand.nextInt(100),getWidth(),getHeight());
|
|
||||||
repaint();
|
|
||||||
});
|
|
||||||
ChooseButton.addActionListener(e -> {
|
|
||||||
selectedGasolineTanker=_gasolineTanker;
|
|
||||||
dispose();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
public DrawingGasolineTanker getSelectedGasolineTanker() {
|
|
||||||
return selectedGasolineTanker;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,178 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormGasolineTanker">
|
|
||||||
<grid id="27dc6" binding="PictureBox" layout-manager="GridLayoutManager" row-count="3" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<xy x="20" y="20" width="664" height="400"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<grid id="1123e" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" column="0" row-span="1" col-span="6" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<component id="f81fa" class="javax.swing.JLabel" binding="SpeedLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Speed:"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<hspacer id="802bb">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="3" 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="7d7fb" class="javax.swing.JLabel" binding="WeightLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Weight:"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="ea175" class="javax.swing.JLabel" binding="BodyColorLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Color:"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<grid id="8a6df" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<component id="6c4ce" class="javax.swing.JButton" binding="ButtonCreate">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" 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="Create"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="76111" class="javax.swing.JButton" binding="ButtonCreateModif">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="1" 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="Improved create"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<grid id="39656" 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>
|
|
||||||
<grid row="1" column="4" 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="e39ac" class="javax.swing.JButton" binding="ButtonLeft">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value=""/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="c212c" class="javax.swing.JButton" binding="ButtonDown">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value=""/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="1b9e6" class="javax.swing.JButton" binding="ButtonRight">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value=""/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="39d04" class="javax.swing.JButton" binding="ButtonUp">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="1" 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>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<vspacer id="74357">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
</vspacer>
|
|
||||||
<hspacer id="94433">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
</hspacer>
|
|
||||||
<grid id="d5026" 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="5" 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>
|
|
||||||
<hspacer id="bfaf3">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" 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>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<grid id="b1e67" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<hspacer id="1fab3">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" 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>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<grid id="b72a1" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<component id="d037b" class="javax.swing.JButton" binding="ButtonSelect">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" 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="Button"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
</form>
|
|
@ -2,108 +2,118 @@ import javax.swing.*;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ComponentAdapter;
|
import java.awt.event.ComponentAdapter;
|
||||||
import java.awt.event.ComponentEvent;
|
import java.awt.event.ComponentEvent;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class FormGasolineTanker extends JFrame{
|
public class FormGasolineTanker extends JFrame{
|
||||||
private int Width;
|
private int Width;
|
||||||
private int Height;
|
private int Height;
|
||||||
DrawingGasolineTanker SelectedGasolineTanker;
|
|
||||||
private JButton ButtonDown;
|
|
||||||
private JButton ButtonRight;
|
|
||||||
private JButton ButtonLeft;
|
|
||||||
private JButton ButtonUp;
|
|
||||||
private JButton ButtonCreate;
|
|
||||||
private JButton ButtonCreateModif;
|
|
||||||
public JLabel SpeedLabel;
|
|
||||||
public JLabel WeightLabel;
|
|
||||||
public JLabel BodyColorLabel;
|
|
||||||
private JPanel PictureBox;
|
|
||||||
private JButton ButtonSelect;
|
|
||||||
private DrawingGasolineTanker _gasolineTanker=null;
|
|
||||||
|
|
||||||
|
JPanel BottomPanel = new JPanel();
|
||||||
|
JPanel CreatePanel = new JPanel();
|
||||||
|
JPanel BottomAndCreatePanel = new JPanel();
|
||||||
|
JPanel DimentionPanel = new JPanel();
|
||||||
|
JPanel UPanel = new JPanel();
|
||||||
|
JPanel DPanel = new JPanel();
|
||||||
|
JPanel LRPanel = new JPanel();
|
||||||
|
|
||||||
|
JLabel SpeedLabel = new JLabel("Speed: ");
|
||||||
|
JLabel WeightLabel = new JLabel("Weight: ");
|
||||||
|
JLabel BodyColorLabel = new JLabel("Color: ");
|
||||||
|
|
||||||
|
DrawingField field = new DrawingField(this);
|
||||||
|
|
||||||
|
JButton ButtonCreate=new JButton("Create");
|
||||||
|
|
||||||
|
Icon iconUp = new ImageIcon("C:\\Users\\kashi\\OneDrive\\Материал\\KeyUp.png");
|
||||||
|
JButton ButtonUp=new JButton(iconUp);
|
||||||
|
|
||||||
|
Icon iconDown = new ImageIcon("C:\\Users\\kashi\\OneDrive\\Материал\\KeyDown.png");
|
||||||
|
JButton ButtonDown=new JButton(iconDown);
|
||||||
|
|
||||||
|
Icon iconRight = new ImageIcon("C:\\Users\\kashi\\OneDrive\\Материал\\KeyRight.png");
|
||||||
|
JButton ButtonRight=new JButton(iconRight);
|
||||||
|
|
||||||
|
Icon iconLeft = new ImageIcon("C:\\Users\\kashi\\OneDrive\\Материал\\KeyLeft.png");
|
||||||
|
JButton ButtonLeft=new JButton(iconLeft);
|
||||||
public FormGasolineTanker(){
|
public FormGasolineTanker(){
|
||||||
setTitle("Gasoline Tanker");
|
super("Gasoline Tanker");
|
||||||
setContentPane(PictureBox);
|
setSize(800,600);
|
||||||
setSize(1000,500);
|
Width=getWidth();
|
||||||
setResizable(false);
|
Height=getHeight();
|
||||||
ShowWindow();
|
ShowWindow();
|
||||||
|
RefreshWindow();
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageIcon spriteUp =new ImageIcon((new ImageIcon("Material\\KeyUp.png")).
|
public void ShowWindow(){
|
||||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
|
||||||
ImageIcon spriteDown =new ImageIcon((new ImageIcon("Material\\KeyDown.png")).
|
|
||||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
|
||||||
ImageIcon spriteLeft =new ImageIcon((new ImageIcon("Material\\KeyLeft.png")).
|
|
||||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
|
||||||
ImageIcon spriteRight =new ImageIcon((new ImageIcon("Material\\KeyRight.png")).
|
|
||||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
|
||||||
|
|
||||||
private void SetData() {
|
Dimension dimen=new Dimension(30,30);
|
||||||
Random rand=new Random();
|
|
||||||
_gasolineTanker.SetPosition(rand.nextInt(100)+10,rand.nextInt(100)+10,getWidth(),getHeight());
|
|
||||||
SpeedLabel.setText("Скорость: "+_gasolineTanker.getGasolineTanker().getSpeed());
|
|
||||||
WeightLabel.setText("Вес: "+_gasolineTanker.getGasolineTanker().getWeight());
|
|
||||||
BodyColorLabel.setText("Цвет: "+Integer.toHexString(_gasolineTanker.getGasolineTanker().getBodyColor().getRGB()).substring(2));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
ButtonUp.setPreferredSize(dimen);
|
||||||
public void paint(Graphics g) {
|
|
||||||
super.paint(g);
|
|
||||||
|
|
||||||
if (_gasolineTanker != null) {
|
|
||||||
PictureBox.paintComponents(PictureBox.getGraphics());
|
|
||||||
_gasolineTanker.DrawTransport(g);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void ShowWindow(){
|
|
||||||
|
|
||||||
ButtonCreate.addActionListener(e -> {
|
|
||||||
Random rand=new Random();
|
|
||||||
_gasolineTanker=new DrawingGasolineTanker(rand.nextInt(50)+10,rand.nextInt(3000)+20000,new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)),rand.nextInt(3));
|
|
||||||
SetData();
|
|
||||||
repaint();
|
|
||||||
});
|
|
||||||
ButtonCreateModif.addActionListener(e -> {
|
|
||||||
Random rand=new Random();
|
|
||||||
_gasolineTanker = new DrawingImprovedGasolineTanker(rand.nextInt(50) + 10, rand.nextInt(3000) + 20000, new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)),
|
|
||||||
new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)), rand.nextBoolean(), rand.nextBoolean(),rand.nextInt(3));
|
|
||||||
SetData();
|
|
||||||
repaint();
|
|
||||||
});
|
|
||||||
ButtonUp.setIcon(spriteUp);
|
|
||||||
ButtonUp.addActionListener(e->{
|
ButtonUp.addActionListener(e->{
|
||||||
if(_gasolineTanker == null)
|
field.UpButtonAction();
|
||||||
return;
|
|
||||||
_gasolineTanker.MoveTransport(Direction.Up);
|
|
||||||
repaint();
|
repaint();
|
||||||
});
|
});
|
||||||
ButtonLeft.setIcon(spriteLeft);
|
|
||||||
ButtonLeft.addActionListener(e -> {
|
ButtonDown.setPreferredSize(dimen);
|
||||||
if(_gasolineTanker == null)
|
|
||||||
return;
|
|
||||||
_gasolineTanker.MoveTransport(Direction.Left);
|
|
||||||
repaint();;
|
|
||||||
});
|
|
||||||
ButtonRight.setIcon(spriteRight);
|
|
||||||
ButtonRight.addActionListener(e -> {
|
|
||||||
if(_gasolineTanker == null)
|
|
||||||
return;
|
|
||||||
_gasolineTanker.MoveTransport(Direction.Right);
|
|
||||||
repaint();
|
|
||||||
});
|
|
||||||
ButtonDown.setIcon(spriteDown);
|
|
||||||
ButtonDown.addActionListener(e->{
|
ButtonDown.addActionListener(e->{
|
||||||
if(_gasolineTanker == null)
|
field.DownButtonAction();
|
||||||
return;
|
|
||||||
_gasolineTanker.MoveTransport(Direction.Down);
|
|
||||||
repaint();
|
repaint();
|
||||||
});
|
});
|
||||||
ButtonSelect.addActionListener(e -> {
|
|
||||||
SelectedGasolineTanker=GetDrawingGasolineTanker();
|
ButtonRight.setPreferredSize(dimen);
|
||||||
JOptionPane.showMessageDialog(PictureBox, "Gasoline tanker added.");
|
ButtonRight.addActionListener(e->{
|
||||||
|
field.RightButtonAction();
|
||||||
|
repaint();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ButtonLeft.setPreferredSize(dimen);
|
||||||
|
ButtonLeft.addActionListener(e->{
|
||||||
|
field.LeftButtonAction();
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
LRPanel.setLayout(new FlowLayout(FlowLayout.CENTER,50,0));
|
||||||
|
LRPanel.setBackground(new Color(0,0,0,0));
|
||||||
|
LRPanel.add(ButtonLeft);
|
||||||
|
LRPanel.add(ButtonRight);
|
||||||
|
|
||||||
|
UPanel.setLayout(new FlowLayout());
|
||||||
|
UPanel.setBackground(new Color(0,0,0,0));
|
||||||
|
UPanel.add(ButtonUp);
|
||||||
|
|
||||||
|
DPanel.setLayout(new FlowLayout());
|
||||||
|
DPanel.setBackground(new Color(0,0,0,0));
|
||||||
|
DPanel.add(ButtonDown);
|
||||||
|
|
||||||
|
DimentionPanel.setLayout(new BoxLayout(DimentionPanel,BoxLayout.Y_AXIS));
|
||||||
|
DimentionPanel.setBackground(new Color(0,0,0,0));
|
||||||
|
DimentionPanel.add(UPanel);
|
||||||
|
DimentionPanel.add(LRPanel);
|
||||||
|
DimentionPanel.add(DPanel);
|
||||||
|
add(DimentionPanel);
|
||||||
|
|
||||||
|
CreatePanel.setLayout(new FlowLayout());
|
||||||
|
CreatePanel.setBackground(new Color(0,0,0,0));
|
||||||
|
CreatePanel.add(ButtonCreate);
|
||||||
|
ButtonCreate.addActionListener(e->{
|
||||||
|
field.CreateButtonAction();
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
BottomPanel.setLayout(new FlowLayout());
|
||||||
|
BottomPanel.setBackground(new Color(0,0,0,0));
|
||||||
|
BottomPanel.add(SpeedLabel);
|
||||||
|
BottomPanel.add(WeightLabel);
|
||||||
|
BottomPanel.add(BodyColorLabel);
|
||||||
|
|
||||||
|
BottomAndCreatePanel.setLayout(new BoxLayout(BottomAndCreatePanel,BoxLayout.Y_AXIS));
|
||||||
|
BottomAndCreatePanel.setBackground(new Color(0,0,0,0));
|
||||||
|
BottomAndCreatePanel.add(CreatePanel);
|
||||||
|
BottomAndCreatePanel.add(BottomPanel);
|
||||||
|
|
||||||
|
add(BottomAndCreatePanel);
|
||||||
|
add(field);
|
||||||
|
|
||||||
addComponentListener(new ComponentAdapter() {
|
addComponentListener(new ComponentAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void componentResized(ComponentEvent e) {
|
public void componentResized(ComponentEvent e) {
|
||||||
@ -111,21 +121,15 @@ public class FormGasolineTanker extends JFrame{
|
|||||||
Width=getWidth();
|
Width=getWidth();
|
||||||
Height=getHeight();
|
Height=getHeight();
|
||||||
|
|
||||||
if (_gasolineTanker!=null)
|
field.ResizeField();
|
||||||
_gasolineTanker.ChangeBorders(getWidth(),getHeight());
|
|
||||||
else return;
|
|
||||||
repaint();
|
repaint();
|
||||||
setBounds(0,0,Width,Height);
|
RefreshWindow();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public DrawingGasolineTanker GetDrawingGasolineTanker() {
|
public void RefreshWindow(){
|
||||||
return _gasolineTanker;
|
field.setBounds(0,0,Width,Height);
|
||||||
|
BottomAndCreatePanel.setBounds(-220,Height-110,Width,80);
|
||||||
|
DimentionPanel.setBounds(Width-170,Height-170,190,140);
|
||||||
}
|
}
|
||||||
public void SetDrawingGasolineTanker(DrawingGasolineTanker gasolineTanker) {
|
|
||||||
_gasolineTanker=gasolineTanker;
|
|
||||||
SetData();
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,296 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormGasolineTankerConfig">
|
|
||||||
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="3" 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="683" height="400"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<grid id="db96d" binding="PreviewPanel" layout-manager="GridLayoutManager" row-count="3" 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>
|
|
||||||
<grid row="0" 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="bevel-lowered" title="Preview panel"/>
|
|
||||||
<children>
|
|
||||||
<component id="98c7d" class="javax.swing.JButton" binding="ButtonAdd">
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Add"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="af43b" class="javax.swing.JButton" binding="ButtonCancel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" column="1" 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="Cancel"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<grid id="f7965" binding="PictureBox" 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="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="bevel-lowered" title="GasolineTanker">
|
|
||||||
<title-color color="-4473925"/>
|
|
||||||
</border>
|
|
||||||
<children/>
|
|
||||||
</grid>
|
|
||||||
<component id="e10c4" class="javax.swing.JLabel" binding="BodyColorLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Body color label"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="fee47" class="javax.swing.JLabel" binding="DopColorLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Dop color label"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<grid id="cfb8f" binding="GroupBoxConfig" 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/>
|
|
||||||
<border type="bevel-lowered" title="Setting"/>
|
|
||||||
<children>
|
|
||||||
<grid id="1aae6" binding="ColorPanel" 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="3" row-span="5" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="bevel-lowered" title="Color"/>
|
|
||||||
<children>
|
|
||||||
<grid id="494da" binding="RedPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<background color="-65536"/>
|
|
||||||
</properties>
|
|
||||||
<border type="none"/>
|
|
||||||
<children/>
|
|
||||||
</grid>
|
|
||||||
<grid id="cd417" binding="OrangePanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<background color="-35072"/>
|
|
||||||
</properties>
|
|
||||||
<border type="none"/>
|
|
||||||
<children/>
|
|
||||||
</grid>
|
|
||||||
<grid id="f8d12" binding="YellowPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<background color="-256"/>
|
|
||||||
<enabled value="false"/>
|
|
||||||
<foreground color="-256"/>
|
|
||||||
</properties>
|
|
||||||
<border type="none"/>
|
|
||||||
<children/>
|
|
||||||
</grid>
|
|
||||||
<grid id="6a27a" binding="PinkPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<background color="-65336"/>
|
|
||||||
</properties>
|
|
||||||
<border type="none"/>
|
|
||||||
<children/>
|
|
||||||
</grid>
|
|
||||||
<grid id="d6e6e" binding="GreenPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<background color="-16711936"/>
|
|
||||||
</properties>
|
|
||||||
<border type="none"/>
|
|
||||||
<children/>
|
|
||||||
</grid>
|
|
||||||
<grid id="2a24b" binding="BluePanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<background color="-16776991"/>
|
|
||||||
</properties>
|
|
||||||
<border type="none"/>
|
|
||||||
<children/>
|
|
||||||
</grid>
|
|
||||||
<grid id="42ead" binding="CianPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<background color="-16711681"/>
|
|
||||||
</properties>
|
|
||||||
<border type="none"/>
|
|
||||||
<children/>
|
|
||||||
</grid>
|
|
||||||
<grid id="7bdaf" binding="GrayPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<background color="-8355712"/>
|
|
||||||
</properties>
|
|
||||||
<border type="none"/>
|
|
||||||
<children/>
|
|
||||||
</grid>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<component id="543d0" class="javax.swing.JLabel" binding="BaseGasolineTankerLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="5" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Base GT"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="f0188" class="javax.swing.JLabel" binding="ImprovedGasolineTankerLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="5" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Improved GT"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="66d4f" class="javax.swing.JLabel" binding="SpeedLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Speed:"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="99004" class="javax.swing.JLabel" binding="WeightLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Weight:"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="2ceae" class="javax.swing.JSpinner" binding="SpinnerSpeed">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
</component>
|
|
||||||
<component id="a01ac" class="javax.swing.JCheckBox" binding="CheckBoxAntenna">
|
|
||||||
<constraints>
|
|
||||||
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Bulb"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="93301" class="javax.swing.JCheckBox" binding="checkBoxBodyKit">
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Barrel"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="bda53" class="javax.swing.JSpinner" binding="SpinnerWeight">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
</component>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<grid id="e549b" layout-manager="GridLayoutManager" row-count="1" 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="2" 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="bevel-lowered" title="Wheels"/>
|
|
||||||
<children>
|
|
||||||
<component id="db027" class="javax.swing.JLabel" binding="CountWheelsLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Count wheels"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="96436" class="javax.swing.JSpinner" binding="SpinnerWheels">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
</component>
|
|
||||||
<grid id="2dbf5" binding="TypeWheels" layout-manager="GridLayoutManager" row-count="1" 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="2" 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="bevel-lowered" title="Type wheels"/>
|
|
||||||
<children>
|
|
||||||
<component id="3e6d9" class="javax.swing.JLabel" binding="WheelsLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
|
||||||
<preferred-size width="68" height="16"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Not ornament"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="32f00" class="javax.swing.JLabel" binding="WheelsFirstLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="First ornament"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="75188" class="javax.swing.JLabel" binding="WheelsSecondLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Second ornament"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
</form>
|
|
@ -1,153 +0,0 @@
|
|||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.FocusEvent;
|
|
||||||
import java.awt.event.MouseAdapter;
|
|
||||||
import java.awt.event.MouseEvent;
|
|
||||||
import java.awt.event.WindowEvent;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public class FormGasolineTankerConfig extends JFrame{
|
|
||||||
private final Action<DrawingGasolineTanker> event = new Action<>();
|
|
||||||
private DrawingGasolineTanker gasolineTanker;
|
|
||||||
CountWheels wheels;
|
|
||||||
private IDrawningObjectWheels _wheel=null;
|
|
||||||
private JPanel MainPanel;
|
|
||||||
private JPanel PreviewPanel;
|
|
||||||
private JButton ButtonAdd;
|
|
||||||
private JButton ButtonCancel;
|
|
||||||
private JLabel BodyColorLabel;
|
|
||||||
private JLabel DopColorLabel;
|
|
||||||
private JPanel PictureBox;
|
|
||||||
private JPanel GroupBoxConfig;
|
|
||||||
private JSpinner SpinnerWheels;
|
|
||||||
private JLabel CountWheelsLabel;
|
|
||||||
private JPanel TypeWheels;
|
|
||||||
private JLabel WheelsLabel;
|
|
||||||
private JLabel WheelsFirstLabel;
|
|
||||||
private JLabel WheelsSecondLabel;
|
|
||||||
private JPanel ColorPanel;
|
|
||||||
private JSpinner SpinnerSpeed;
|
|
||||||
private JCheckBox CheckBoxAntenna;
|
|
||||||
private JCheckBox checkBoxBodyKit;
|
|
||||||
private JSpinner SpinnerWeight;
|
|
||||||
private JPanel RedPanel;
|
|
||||||
private JPanel OrangePanel;
|
|
||||||
private JPanel YellowPanel;
|
|
||||||
private JPanel CianPanel;
|
|
||||||
private JPanel PinkPanel;
|
|
||||||
private JPanel GreenPanel;
|
|
||||||
private JPanel BluePanel;
|
|
||||||
private JPanel GrayPanel;
|
|
||||||
private JLabel BaseGasolineTankerLabel;
|
|
||||||
private JLabel ImprovedGasolineTankerLabel;
|
|
||||||
private JLabel SpeedLabel;
|
|
||||||
private JLabel WeightLabel;
|
|
||||||
|
|
||||||
public FormGasolineTankerConfig(){
|
|
||||||
this.setTitle("Create object");
|
|
||||||
this.setSize(900,500);
|
|
||||||
this.setContentPane(MainPanel);
|
|
||||||
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
|
||||||
|
|
||||||
WheelsLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
|
||||||
WheelsFirstLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
|
||||||
WheelsFirstLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
|
||||||
BodyColorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
|
||||||
DopColorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
|
||||||
BaseGasolineTankerLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
|
||||||
ImprovedGasolineTankerLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
|
||||||
|
|
||||||
SpinnerWheels.setModel(new SpinnerNumberModel(2, 2, 4, 1));
|
|
||||||
SpinnerWeight.setModel(new SpinnerNumberModel(100, 100, 1000, 10));
|
|
||||||
SpinnerSpeed.setModel(new SpinnerNumberModel(10000, 10000, 20000, 100));
|
|
||||||
|
|
||||||
var dragAdapter = new MouseAdapter() {
|
|
||||||
@Override
|
|
||||||
public void mousePressed(MouseEvent e) {
|
|
||||||
super.mouseReleased(e);
|
|
||||||
setCursor(new Cursor(Cursor.HAND_CURSOR));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseReleased(MouseEvent e) {
|
|
||||||
super.mouseReleased(e);
|
|
||||||
dispatchDrop((JComponent) e.getSource());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
RedPanel.addMouseListener(dragAdapter);
|
|
||||||
GreenPanel.addMouseListener(dragAdapter);
|
|
||||||
BluePanel.addMouseListener(dragAdapter);
|
|
||||||
YellowPanel.addMouseListener(dragAdapter);
|
|
||||||
OrangePanel.addMouseListener(dragAdapter);
|
|
||||||
GrayPanel.addMouseListener(dragAdapter);
|
|
||||||
CianPanel.addMouseListener(dragAdapter);
|
|
||||||
PinkPanel.addMouseListener(dragAdapter);
|
|
||||||
|
|
||||||
BaseGasolineTankerLabel.addMouseListener(dragAdapter);
|
|
||||||
ImprovedGasolineTankerLabel.addMouseListener(dragAdapter);
|
|
||||||
WheelsLabel.addMouseListener(dragAdapter);
|
|
||||||
WheelsFirstLabel.addMouseListener(dragAdapter);
|
|
||||||
WheelsSecondLabel.addMouseListener(dragAdapter);
|
|
||||||
|
|
||||||
ButtonAdd.addActionListener(e -> {
|
|
||||||
event.emit(gasolineTanker);
|
|
||||||
dispose();
|
|
||||||
});
|
|
||||||
ButtonCancel.addActionListener(e -> dispose());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addListener(Consumer<DrawingGasolineTanker> listener) {
|
|
||||||
event.addListener(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void dispatchDrop(JComponent droppedComponent) {
|
|
||||||
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
|
||||||
if (droppedComponent == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (droppedComponent instanceof JPanel panel) {
|
|
||||||
if (BodyColorLabel.getMousePosition() != null) {
|
|
||||||
gasolineTanker.SetBodyColor(panel.getBackground());
|
|
||||||
}
|
|
||||||
if (DopColorLabel.getMousePosition() != null && gasolineTanker instanceof DrawingImprovedGasolineTanker advanced) {
|
|
||||||
advanced.SetDopColor(panel.getBackground());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (droppedComponent instanceof JLabel label && PictureBox.getMousePosition() != null) {
|
|
||||||
int speed = (Integer) SpinnerSpeed.getValue();
|
|
||||||
int weight = (Integer) SpinnerWeight.getValue();
|
|
||||||
int countWheels = (Integer) SpinnerWheels.getValue();
|
|
||||||
boolean antenna = CheckBoxAntenna.isSelected();
|
|
||||||
boolean bodyKit = checkBoxBodyKit.isSelected();
|
|
||||||
|
|
||||||
|
|
||||||
if (label == BaseGasolineTankerLabel) {
|
|
||||||
gasolineTanker = new DrawingGasolineTanker(speed, weight, countWheels,Color.WHITE);
|
|
||||||
} else if (label == ImprovedGasolineTankerLabel) {
|
|
||||||
gasolineTanker = new DrawingImprovedGasolineTanker(speed, weight,countWheels, Color.WHITE, Color.WHITE, bodyKit, antenna);
|
|
||||||
} else if (gasolineTanker != null && label == WheelsLabel) {
|
|
||||||
gasolineTanker.SetWheels(new DrawingWheels(countWheels));
|
|
||||||
} else if (gasolineTanker != null && label == WheelsFirstLabel) {
|
|
||||||
gasolineTanker.SetWheels(new DrawingOrnamentWheelsFirst(countWheels));
|
|
||||||
} else if (gasolineTanker != null && label == WheelsSecondLabel) {
|
|
||||||
gasolineTanker.SetWheels(new DrawingOrnamentWheelsSecond(countWheels));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void paint(Graphics g) {
|
|
||||||
super.paint(g);
|
|
||||||
if (gasolineTanker != null) {
|
|
||||||
g = PictureBox.getGraphics();
|
|
||||||
gasolineTanker.SetPosition(10, 10, PictureBox.getWidth(), PictureBox.getHeight());
|
|
||||||
gasolineTanker.DrawTransport((Graphics2D) g);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createUIComponents() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,220 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMapWithSetGasolineTanker">
|
|
||||||
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<xy x="20" y="20" width="668" height="652"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<grid id="42b0" binding="GroupBoxTools" layout-manager="GridLayoutManager" row-count="10" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="bevel-lowered" title=" Tools"/>
|
|
||||||
<children>
|
|
||||||
<grid id="bc845" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<vspacer id="9ecc2">
|
|
||||||
<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>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<vspacer id="f144d">
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" 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="f5a9c" class="javax.swing.JButton" binding="ButtonAddGasolineTanker">
|
|
||||||
<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"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Add GL"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="ceb03" class="javax.swing.JTextField" binding="TextBoxPosition">
|
|
||||||
<constraints>
|
|
||||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
|
||||||
<preferred-size width="150" height="-1"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
</component>
|
|
||||||
<component id="c29a2" class="javax.swing.JButton" binding="ButtonRemoveGasolineTanker">
|
|
||||||
<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"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Remove GL"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<vspacer id="76e51">
|
|
||||||
<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"/>
|
|
||||||
</constraints>
|
|
||||||
</vspacer>
|
|
||||||
<component id="42b8e" class="javax.swing.JButton" binding="ButtonShowStorage">
|
|
||||||
<constraints>
|
|
||||||
<grid row="7" 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="Storage"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="62dd6" class="javax.swing.JButton" binding="ButtonShowOnMap">
|
|
||||||
<constraints>
|
|
||||||
<grid row="8" 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="Map"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<grid id="13e89" binding="MapPanel" layout-manager="GridLayoutManager" row-count="5" 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="bevel-lowered" title="Maps" title-justification="1" title-position="2"/>
|
|
||||||
<children>
|
|
||||||
<component id="52e81" class="javax.swing.JComboBox" binding="СomboBoxSelectorMap">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<model>
|
|
||||||
<item value="Simple map"/>
|
|
||||||
<item value="Long map"/>
|
|
||||||
</model>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="db334" class="javax.swing.JTextField" binding="TextFieldMap">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
|
||||||
<preferred-size width="150" height="-1"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
</component>
|
|
||||||
<component id="e500c" class="javax.swing.JButton" binding="CreateMapButton">
|
|
||||||
<constraints>
|
|
||||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Create map"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="8b172" class="javax.swing.JButton" binding="DeleteMapButton">
|
|
||||||
<constraints>
|
|
||||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Delete map"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="10e77" class="javax.swing.JList" binding="ListBoxMaps">
|
|
||||||
<constraints>
|
|
||||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
|
||||||
<preferred-size width="150" height="50"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
</component>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<component id="fdb6d" class="javax.swing.JButton" binding="ButtonShowDeleted">
|
|
||||||
<constraints>
|
|
||||||
<grid row="9" 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="Show deleted GL"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<grid id="c9878" 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>
|
|
||||||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<component id="cac88" class="javax.swing.JButton" binding="ButtonLeft">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value=""/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="bd727" class="javax.swing.JButton" binding="ButtonDown">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value=""/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="1ff1c" class="javax.swing.JButton" binding="ButtonRight">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value=""/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="b4d3c" class="javax.swing.JButton" binding="ButtonUp">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="1" 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>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<grid id="ad00b" binding="PictureBox" 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="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/>
|
|
||||||
</grid>
|
|
||||||
<hspacer id="29fed">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" 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="91c98" 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="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<vspacer id="43d2a">
|
|
||||||
<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>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
</form>
|
|
@ -1,316 +0,0 @@
|
|||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Optional;
|
|
||||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
|
||||||
|
|
||||||
public class FormMapWithSetGasolineTanker extends JFrame{
|
|
||||||
private JPanel GroupBoxTools;
|
|
||||||
private JComboBox СomboBoxSelectorMap;
|
|
||||||
private JButton ButtonAddGasolineTanker;
|
|
||||||
private JButton ButtonRemoveGasolineTanker;
|
|
||||||
private JButton ButtonShowStorage;
|
|
||||||
private JButton ButtonShowOnMap;
|
|
||||||
private JButton ButtonLeft;
|
|
||||||
private JButton ButtonDown;
|
|
||||||
private JButton ButtonRight;
|
|
||||||
private JButton ButtonUp;
|
|
||||||
private JPanel MainPanel;
|
|
||||||
private JTextField TextBoxPosition;
|
|
||||||
private JPanel PictureBox;
|
|
||||||
private JPanel MapPanel;
|
|
||||||
private JTextField TextFieldMap;
|
|
||||||
private JButton CreateMapButton;
|
|
||||||
private JButton DeleteMapButton;
|
|
||||||
private JButton ButtonShowDeleted;
|
|
||||||
private JList ListBoxMaps;
|
|
||||||
private Image bufferedImage;
|
|
||||||
private JMenuBar MenuBar;
|
|
||||||
|
|
||||||
private MapsCollection _mapsCollection;
|
|
||||||
private final HashMap<String,AbstractMap> _mapsDict=new HashMap<String,AbstractMap>(){
|
|
||||||
{
|
|
||||||
put("Simple map",new SimpleMap());
|
|
||||||
put("Long map",new LongMap());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private MapWithSetGasolineTankerGeneric<DrawingObjectGasolineTanker,AbstractMap> _mapGasolineTankerCollectionGeneric;
|
|
||||||
|
|
||||||
ImageIcon spriteUp =new ImageIcon((new ImageIcon("Material\\KeyUp.png")).
|
|
||||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
|
||||||
ImageIcon spriteDown =new ImageIcon((new ImageIcon("Material\\KeyDown.png")).
|
|
||||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
|
||||||
ImageIcon spriteLeft =new ImageIcon((new ImageIcon("Material\\KeyLeft.png")).
|
|
||||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
|
||||||
ImageIcon spriteRight =new ImageIcon((new ImageIcon("Material\\KeyRight.png")).
|
|
||||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
|
||||||
public FormMapWithSetGasolineTanker(){
|
|
||||||
setTitle("Gasoline tanker");
|
|
||||||
setContentPane(MainPanel);
|
|
||||||
setResizable(false);
|
|
||||||
setSize(1000,685);
|
|
||||||
ShowWindow();
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
setVisible(true);
|
|
||||||
_mapsCollection=new MapsCollection(getWidth(),getHeight());
|
|
||||||
СomboBoxSelectorMap.removeAllItems();
|
|
||||||
for(String elem:_mapsDict.keySet()){
|
|
||||||
СomboBoxSelectorMap.addItem(elem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void paint(Graphics g) {
|
|
||||||
super.paint(g);
|
|
||||||
|
|
||||||
if (bufferedImage != null) {
|
|
||||||
PictureBox.paintComponents(bufferedImage.getGraphics());
|
|
||||||
PictureBox.getGraphics().drawImage(bufferedImage, 0, 0, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ReloadMaps()
|
|
||||||
{
|
|
||||||
int index = ListBoxMaps.getSelectedIndex();
|
|
||||||
ListBoxMaps.setListData(_mapsCollection.Keys().toArray(new String[0]));
|
|
||||||
|
|
||||||
if (ListBoxMaps.getModel().getSize() > 0 && (index == -1 || index >= ListBoxMaps.getModel().getSize()))
|
|
||||||
{
|
|
||||||
ListBoxMaps.setSelectedIndex(0);
|
|
||||||
}
|
|
||||||
else if (ListBoxMaps.getModel().getSize() > 0 && index > -1 && index < ListBoxMaps.getModel().getSize())
|
|
||||||
{
|
|
||||||
ListBoxMaps.setSelectedIndex(index);
|
|
||||||
}
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ShowWindow(){
|
|
||||||
|
|
||||||
MenuBar=new JMenuBar();
|
|
||||||
|
|
||||||
JMenu fileMenu =new JMenu("File");
|
|
||||||
MenuBar.add(fileMenu);
|
|
||||||
|
|
||||||
JMenuItem SaveMenuItem = new JMenuItem("Save");
|
|
||||||
SaveMenuItem.addActionListener(e -> {
|
|
||||||
JFileChooser dialog = new JFileChooser();
|
|
||||||
dialog.setFileFilter(new FileNameExtensionFilter("txt", "txt"));
|
|
||||||
dialog.showSaveDialog(this);
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (_mapsCollection.SaveData(dialog.getSelectedFile().getAbsolutePath())) {
|
|
||||||
JOptionPane.showMessageDialog(this, "Save was successful", "Outcome", JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
} else {
|
|
||||||
JOptionPane.showMessageDialog(this, "\n" + "Not preserved", "Outcome", JOptionPane.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
} catch (IOException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
fileMenu.add(SaveMenuItem);
|
|
||||||
|
|
||||||
JMenuItem LoadMenuItem = new JMenuItem("Load");
|
|
||||||
LoadMenuItem.addActionListener(e -> {
|
|
||||||
JFileChooser dialog = new JFileChooser();
|
|
||||||
dialog.setFileFilter(new FileNameExtensionFilter("txt", "txt"));
|
|
||||||
dialog.showOpenDialog(this);
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (_mapsCollection.LoadData(dialog.getSelectedFile().getAbsolutePath())) {
|
|
||||||
ReloadMaps();
|
|
||||||
JOptionPane.showMessageDialog(this, "Download successful", "Outcome", JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
} else {
|
|
||||||
JOptionPane.showMessageDialog(this, "\n" + "Didn't load", "Outcome", JOptionPane.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
} catch (IOException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
fileMenu.add(LoadMenuItem);
|
|
||||||
|
|
||||||
JMenuItem SaveMapMenuItem = new JMenuItem("Save maps");
|
|
||||||
SaveMapMenuItem.addActionListener(e -> {
|
|
||||||
JFileChooser dialog = new JFileChooser();
|
|
||||||
dialog.setFileFilter(new FileNameExtensionFilter("txt", "txt"));
|
|
||||||
dialog.showSaveDialog(this);
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (_mapsCollection.SaveMap((String) Optional.ofNullable(ListBoxMaps.getSelectedValue()).orElse(""), dialog.getSelectedFile().getAbsolutePath())) {
|
|
||||||
JOptionPane.showMessageDialog(this, "\n" + "Save was successful", "Outcome", JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
} else {
|
|
||||||
JOptionPane.showMessageDialog(this, "Not preserved", "Outcome", JOptionPane.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
} catch (IOException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
fileMenu.add(SaveMapMenuItem);
|
|
||||||
|
|
||||||
JMenuItem LoadMapMenuItem = new JMenuItem("Load maps");
|
|
||||||
LoadMapMenuItem.addActionListener(e -> {
|
|
||||||
JFileChooser dialog = new JFileChooser();
|
|
||||||
dialog.setFileFilter(new FileNameExtensionFilter("txt", "txt"));
|
|
||||||
dialog.showOpenDialog(this);
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (_mapsCollection.LoadMap(dialog.getSelectedFile().getAbsolutePath())) {
|
|
||||||
ReloadMaps();
|
|
||||||
JOptionPane.showMessageDialog(this, "Download successful", "Outcome", JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
} else {
|
|
||||||
JOptionPane.showMessageDialog(this, "\n" + "Didn't load", "Outcome", JOptionPane.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
} catch (IOException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
fileMenu.add(LoadMapMenuItem);
|
|
||||||
|
|
||||||
setJMenuBar(MenuBar);
|
|
||||||
|
|
||||||
ListBoxMaps.addListSelectionListener(e -> {
|
|
||||||
if(ListBoxMaps.getSelectedIndex()==-1)
|
|
||||||
return;
|
|
||||||
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet();
|
|
||||||
repaint();
|
|
||||||
});
|
|
||||||
|
|
||||||
DeleteMapButton.addActionListener(e -> {
|
|
||||||
if (ListBoxMaps.getSelectedIndex() == -1)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(JOptionPane.showConfirmDialog(this,"Delete map "+ListBoxMaps.getSelectedValue().toString()+"?",
|
|
||||||
"Removal",JOptionPane.YES_NO_OPTION)==0)
|
|
||||||
{
|
|
||||||
_mapsCollection.DelMap(ListBoxMaps.getSelectedValue().toString());
|
|
||||||
ReloadMaps();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
CreateMapButton.addActionListener(e -> {
|
|
||||||
if (СomboBoxSelectorMap.getSelectedIndex() == -1 || TextFieldMap.getText()==null || TextFieldMap.getText().equals(""))
|
|
||||||
{
|
|
||||||
JOptionPane.showMessageDialog(this,"\n" + "Not all data is complete","Error",JOptionPane.ERROR_MESSAGE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!_mapsDict.containsKey(СomboBoxSelectorMap.getSelectedItem()))
|
|
||||||
{
|
|
||||||
JOptionPane.showMessageDialog(this,"No such card","Error",JOptionPane.ERROR_MESSAGE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_mapsCollection.AddMap(TextFieldMap.getText(), _mapsDict.get(СomboBoxSelectorMap.getSelectedItem().toString()));
|
|
||||||
ReloadMaps();
|
|
||||||
});
|
|
||||||
|
|
||||||
ButtonShowOnMap.addActionListener(e -> {
|
|
||||||
if (ListBoxMaps.getSelectedIndex() ==-1)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowOnMap();
|
|
||||||
repaint();
|
|
||||||
});
|
|
||||||
|
|
||||||
ButtonShowStorage.addActionListener(e -> {
|
|
||||||
if (ListBoxMaps.getSelectedIndex() ==-1)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet();
|
|
||||||
repaint();
|
|
||||||
});
|
|
||||||
|
|
||||||
ButtonAddGasolineTanker.addActionListener(e -> {
|
|
||||||
if (ListBoxMaps.getSelectedIndex() ==-1)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
FormGasolineTankerConfig dialog=new FormGasolineTankerConfig();
|
|
||||||
dialog.addListener(obj -> {
|
|
||||||
if (obj!=null) {
|
|
||||||
DrawingObjectGasolineTanker gasolineTanker = new DrawingObjectGasolineTanker(obj);
|
|
||||||
|
|
||||||
if (_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).plus(gasolineTanker) >= 0) {
|
|
||||||
JOptionPane.showMessageDialog(this, "Object added", "Success", JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet();
|
|
||||||
repaint();
|
|
||||||
} else {
|
|
||||||
JOptionPane.showMessageDialog(this, "\n" + "Failed to add object", "Error", JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
dialog.setVisible(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
ButtonRemoveGasolineTanker.addActionListener(e -> {
|
|
||||||
String txt=TextBoxPosition.getText();
|
|
||||||
if (txt==null||ListBoxMaps.getSelectedIndex() ==-1)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int result = JOptionPane.showConfirmDialog(
|
|
||||||
this,
|
|
||||||
"Delete object?",
|
|
||||||
"Removal",
|
|
||||||
JOptionPane.YES_NO_CANCEL_OPTION);
|
|
||||||
if (result!=0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int pos = Integer.parseInt(txt);
|
|
||||||
if(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).minus(pos)!=null){
|
|
||||||
JOptionPane.showMessageDialog(this, "Object removed", "Success", JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet();
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
JOptionPane.showMessageDialog(this,"Failed to delete object","\n" + "Error",JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ButtonShowDeleted.addActionListener(e -> {
|
|
||||||
if (ListBoxMaps.getSelectedIndex()==-1)
|
|
||||||
return;
|
|
||||||
DrawingObjectGasolineTanker gasolineTanker=(DrawingObjectGasolineTanker)_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).GetGasolineTankerInDeleted();
|
|
||||||
if(gasolineTanker!=null){
|
|
||||||
FormGasolineTanker dialog=new FormGasolineTanker();
|
|
||||||
dialog.SetDrawingGasolineTanker(gasolineTanker.GetGasolineTanker());
|
|
||||||
dialog.setSize(1200,700);
|
|
||||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
|
||||||
dialog.setVisible(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ButtonUp.setIcon(spriteUp);
|
|
||||||
ButtonUp.addActionListener(e -> {
|
|
||||||
if (ListBoxMaps.getSelectedIndex() !=-1) {
|
|
||||||
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).MoveObject(Direction.Up);
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ButtonDown.setIcon(spriteDown);
|
|
||||||
ButtonDown.addActionListener(e -> {
|
|
||||||
if (ListBoxMaps.getSelectedIndex() !=-1) {
|
|
||||||
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).MoveObject(Direction.Down);
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ButtonRight.setIcon(spriteRight);
|
|
||||||
ButtonRight.addActionListener(e -> {
|
|
||||||
if (ListBoxMaps.getSelectedIndex() !=-1) {
|
|
||||||
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).MoveObject(Direction.Right);
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ButtonLeft.setIcon(spriteLeft);
|
|
||||||
ButtonLeft.addActionListener(e -> {
|
|
||||||
if (ListBoxMaps.getSelectedIndex() !=-1) {
|
|
||||||
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).MoveObject(Direction.Left);
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public interface IDrawingObject {
|
|
||||||
public float Step=0;
|
|
||||||
void SetObject(int x, int y, int width, int height);
|
|
||||||
void MoveObject(Direction direction);
|
|
||||||
void DrawingObject(Graphics g);
|
|
||||||
float[] GetCurrentPosition();
|
|
||||||
String GetInfo();
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public interface IDrawningObjectWheels {
|
|
||||||
void SetCountWheels(int count);
|
|
||||||
void DrawWheels(Graphics2D g, int _startPosX, int _startPosY);
|
|
||||||
String GetCount();
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class LongMap extends AbstractMap{
|
|
||||||
@Override
|
|
||||||
protected void GenerateMap()
|
|
||||||
{
|
|
||||||
_map = new int[100][100];
|
|
||||||
_size_x = (float)_width / _map[0].length;
|
|
||||||
_size_y = (float)_height / _map[1].length;
|
|
||||||
int counter = 0;
|
|
||||||
for (int i = 0; i < _map[0].length; ++i)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < _map[1].length; ++j)
|
|
||||||
{
|
|
||||||
_map[i][j] = _freeRoad;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (counter < 5)
|
|
||||||
{
|
|
||||||
int xStart = _random.nextInt(0, 100);
|
|
||||||
int xEnd = _random.nextInt(80, 100);
|
|
||||||
|
|
||||||
for (int i = xStart; i <= xEnd; ++i)
|
|
||||||
{
|
|
||||||
_map[i] [xStart] = _barrier;
|
|
||||||
}
|
|
||||||
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void DrawBarrierPart(Graphics gr, int i, int j) {
|
|
||||||
gr.setColor(Color.GRAY);
|
|
||||||
gr.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void DrawRoadPart(Graphics gr, int i, int j) {
|
|
||||||
gr.setColor(Color.BLACK);
|
|
||||||
gr.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,5 @@
|
|||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
new FormMapWithSetGasolineTanker();
|
new FormGasolineTanker();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,152 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.util.ArrayDeque;
|
|
||||||
|
|
||||||
public class MapWithSetGasolineTankerGeneric <T extends IDrawingObject,U extends AbstractMap>{
|
|
||||||
private final int _pictureWidth;
|
|
||||||
private final int _pictureHeight;
|
|
||||||
private final int _placeSizeWidth = 210;
|
|
||||||
private final int _placeSizeHeight = 90;
|
|
||||||
public final SetGasolineTankerGeneric<T> _setGasolineTanker;
|
|
||||||
private final ArrayDeque<T> DeletedGasolineTanker;
|
|
||||||
private final U _map;
|
|
||||||
|
|
||||||
public MapWithSetGasolineTankerGeneric(int picWidth,int picHeight, U map)
|
|
||||||
{
|
|
||||||
int width = picWidth / _placeSizeWidth;
|
|
||||||
int height = picHeight/_placeSizeHeight;
|
|
||||||
_setGasolineTanker = new SetGasolineTankerGeneric<>(width * height);
|
|
||||||
_pictureWidth = picWidth;
|
|
||||||
_pictureHeight = picHeight;
|
|
||||||
_map = map;
|
|
||||||
DeletedGasolineTanker = new ArrayDeque<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public U GetMap(){
|
|
||||||
return _map;
|
|
||||||
}
|
|
||||||
public int plus(T gasolineTanker)
|
|
||||||
{
|
|
||||||
return _setGasolineTanker.Insert(gasolineTanker);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T minus(int position)
|
|
||||||
{
|
|
||||||
T gasolineTanker=_setGasolineTanker.Remove(position);
|
|
||||||
DeletedGasolineTanker.push(gasolineTanker);
|
|
||||||
return gasolineTanker;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Image ShowSet()
|
|
||||||
{
|
|
||||||
BufferedImage bmp = new BufferedImage(_pictureWidth, _pictureWidth,BufferedImage.TYPE_INT_ARGB);
|
|
||||||
Graphics gr = bmp.getGraphics();
|
|
||||||
DrawBackground(gr);
|
|
||||||
DrawGasolineTanker(gr);
|
|
||||||
return bmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Image ShowOnMap()
|
|
||||||
{
|
|
||||||
Shaking();
|
|
||||||
for (IDrawingObject gasolineTanker : _setGasolineTanker)
|
|
||||||
{
|
|
||||||
return _map.CreateMap(_pictureWidth, _pictureHeight, gasolineTanker);
|
|
||||||
}
|
|
||||||
return new BufferedImage(_pictureWidth, _pictureHeight,1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Image MoveObject(Direction direction)
|
|
||||||
{
|
|
||||||
if (_map != null)
|
|
||||||
{
|
|
||||||
return _map.MoveObject(direction);
|
|
||||||
}
|
|
||||||
return new BufferedImage(_pictureWidth, _pictureHeight,1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Shaking()
|
|
||||||
{
|
|
||||||
int j = _setGasolineTanker.Count() - 1;
|
|
||||||
for (int i = 0; i < _setGasolineTanker.Count(); i++)
|
|
||||||
{
|
|
||||||
if (_setGasolineTanker.Get(i) == null)
|
|
||||||
{
|
|
||||||
for (; j > i; j--)
|
|
||||||
{
|
|
||||||
T gasolineTanker = _setGasolineTanker.Get(j);
|
|
||||||
if (gasolineTanker != null)
|
|
||||||
{
|
|
||||||
_setGasolineTanker.Insert(gasolineTanker, i);
|
|
||||||
_setGasolineTanker.Remove(j);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (j <= i)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DrawBackground(Graphics gr)
|
|
||||||
{
|
|
||||||
Graphics2D g=(Graphics2D)gr;
|
|
||||||
|
|
||||||
Color brush=Color.BLACK;
|
|
||||||
Stroke penWide = new BasicStroke(5);
|
|
||||||
Stroke penThin = new BasicStroke(1);
|
|
||||||
|
|
||||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
|
||||||
{
|
|
||||||
g.setColor(brush);
|
|
||||||
g.setStroke(penWide);
|
|
||||||
g.drawLine(i * _placeSizeWidth + 10, j * _placeSizeHeight + 2, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + 2);
|
|
||||||
g.drawLine(i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + 2, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.9) + 10, j * _placeSizeHeight + 2 + 20);
|
|
||||||
g.drawLine(i * _placeSizeWidth + (int)(_placeSizeWidth * 0.9) + 10, j * _placeSizeHeight + 2 + 20, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.9) + 10, j * _placeSizeHeight + 2 + 20);
|
|
||||||
g.setStroke(penThin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DrawGasolineTanker(Graphics gr)
|
|
||||||
{
|
|
||||||
int width = _pictureWidth / _placeSizeWidth;
|
|
||||||
int height = _pictureHeight / _placeSizeHeight;
|
|
||||||
|
|
||||||
for (int i = 0; i < _setGasolineTanker.Count(); i++)
|
|
||||||
{
|
|
||||||
if (_setGasolineTanker.Get(i) != null)
|
|
||||||
{
|
|
||||||
_setGasolineTanker.Get(i).SetObject(i % width * _placeSizeWidth, (height - 1 - i / width) * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
|
||||||
_setGasolineTanker.Get(i).DrawingObject(gr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public T GetGasolineTankerArrayDeque(int i){
|
|
||||||
return _setGasolineTanker.Get(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T GetGasolineTankerInDeleted() {
|
|
||||||
if(DeletedGasolineTanker.isEmpty())
|
|
||||||
return null;
|
|
||||||
return DeletedGasolineTanker.pop();
|
|
||||||
}
|
|
||||||
public String GetData(char separatorType,char separatorData){
|
|
||||||
String data=""+_map.getClass().getSimpleName()+separatorType;
|
|
||||||
for (var gasolineTanker : _setGasolineTanker){
|
|
||||||
data+=gasolineTanker.GetInfo()+separatorData;
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void LoadData(String[] records){
|
|
||||||
for (int i=records.length-1;i>=0;i--){
|
|
||||||
_setGasolineTanker.Insert((T) DrawingObjectGasolineTanker.Create(records[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,150 +0,0 @@
|
|||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
public class MapsCollection {
|
|
||||||
private final HashMap<String,MapWithSetGasolineTankerGeneric<DrawingObjectGasolineTanker,AbstractMap>> _mapStorages;
|
|
||||||
private final int _pictureWidth;
|
|
||||||
private final int _pictureHeight;
|
|
||||||
private final char separatorDict='|';
|
|
||||||
private final char separatorData=';';
|
|
||||||
|
|
||||||
public MapsCollection(int pictureWidth,int pictureHeight){
|
|
||||||
_mapStorages=new HashMap<>();
|
|
||||||
_pictureWidth=pictureWidth;
|
|
||||||
_pictureHeight=pictureHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> Keys(){
|
|
||||||
return new ArrayList<>(_mapStorages.keySet());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddMap(String name, AbstractMap map){
|
|
||||||
if (_mapStorages.containsKey(name)){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
_mapStorages.put(name,new MapWithSetGasolineTankerGeneric<>(_pictureWidth,_pictureHeight,map));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DelMap(String name){
|
|
||||||
_mapStorages.remove(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MapWithSetGasolineTankerGeneric<DrawingObjectGasolineTanker,AbstractMap> get(String name){
|
|
||||||
if (_mapStorages.containsKey(name)){
|
|
||||||
return _mapStorages.get(name);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
|
||||||
public boolean SaveData(String filename) throws IOException {
|
|
||||||
|
|
||||||
File file = new File(filename);
|
|
||||||
|
|
||||||
if (file.exists())
|
|
||||||
file.delete();
|
|
||||||
|
|
||||||
file.createNewFile();
|
|
||||||
|
|
||||||
try (PrintWriter writer = new PrintWriter(file)) {
|
|
||||||
writer.println("MapsCollection");
|
|
||||||
|
|
||||||
for (var storage : _mapStorages.entrySet()) {
|
|
||||||
writer.println(String.format("%s%c%s", storage.getKey(), separatorDict, storage.getValue().GetData(separatorDict, separatorData)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean LoadData(String filename) throws IOException {
|
|
||||||
|
|
||||||
File file = new File(filename);
|
|
||||||
|
|
||||||
if (!file.exists())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
|
||||||
String currentLine = reader.readLine();
|
|
||||||
|
|
||||||
if (currentLine == null || !currentLine.contains("MapsCollection"))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
_mapStorages.clear();
|
|
||||||
|
|
||||||
while ((currentLine = reader.readLine()) != null) {
|
|
||||||
var elements = currentLine.split(String.format("\\%c", separatorDict));
|
|
||||||
AbstractMap map = switch (elements[1]) {
|
|
||||||
case "SimpleMap" -> new SimpleMap();
|
|
||||||
case "LongMap" -> new LongMap();
|
|
||||||
default -> null;
|
|
||||||
};
|
|
||||||
_mapStorages.put(elements[0], new MapWithSetGasolineTankerGeneric<>(_pictureWidth, _pictureHeight, map));
|
|
||||||
_mapStorages.get(elements[0]).LoadData(elements[2].split(separatorData + "\n?"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
|
||||||
public boolean SaveMap(String mapName, String filename) throws IOException {
|
|
||||||
File file = new File(filename);
|
|
||||||
|
|
||||||
if (file.exists())
|
|
||||||
file.delete();
|
|
||||||
|
|
||||||
file.createNewFile();
|
|
||||||
|
|
||||||
MapWithSetGasolineTankerGeneric<DrawingObjectGasolineTanker, AbstractMap> map = _mapStorages.getOrDefault(mapName, null);
|
|
||||||
|
|
||||||
if (map == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
try (PrintWriter writer = new PrintWriter(file)) {
|
|
||||||
writer.println("Map");
|
|
||||||
writer.println(mapName);
|
|
||||||
writer.println(map.GetMap().getClass().getSimpleName());
|
|
||||||
for (var gasolineTanker : map._setGasolineTanker.GetGasolineTanker()) {
|
|
||||||
writer.println(gasolineTanker.GetInfo());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean LoadMap(String filename) throws IOException {
|
|
||||||
File file = new File(filename);
|
|
||||||
|
|
||||||
if (!file.exists())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
|
||||||
String currentLine = reader.readLine();
|
|
||||||
|
|
||||||
if (currentLine == null || !currentLine.contains("Map"))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
String mapName = reader.readLine();
|
|
||||||
|
|
||||||
MapWithSetGasolineTankerGeneric<DrawingObjectGasolineTanker, AbstractMap> map;
|
|
||||||
if (_mapStorages.containsKey(mapName)) {
|
|
||||||
map = _mapStorages.get(mapName);
|
|
||||||
if (!map.GetMap().getClass().getSimpleName().equals(reader.readLine())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
map._setGasolineTanker.Clear();
|
|
||||||
} else {
|
|
||||||
map = switch (reader.readLine()) {
|
|
||||||
case "SimpleMap" -> new MapWithSetGasolineTankerGeneric<>(_pictureWidth, _pictureHeight, new SimpleMap());
|
|
||||||
case "LongMap" -> new MapWithSetGasolineTankerGeneric<>(_pictureWidth, _pictureHeight, new LongMap());
|
|
||||||
default -> null;
|
|
||||||
};
|
|
||||||
_mapStorages.put(mapName, map);
|
|
||||||
}
|
|
||||||
while ((currentLine = reader.readLine()) != null) {
|
|
||||||
map._setGasolineTanker.Insert((DrawingObjectGasolineTanker) DrawingObjectGasolineTanker.Create(currentLine));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
public enum OrnamentForm {
|
|
||||||
NoneOrnament(0),
|
|
||||||
GrayOrnament(1),
|
|
||||||
RedOrnament(2);
|
|
||||||
public final int Value;
|
|
||||||
OrnamentForm(int i) {
|
|
||||||
Value=i;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Objects;
|
|
||||||
public class SetGasolineTankerGeneric <T extends Object> implements Iterable<T>{
|
|
||||||
private final ArrayList<T> _places;
|
|
||||||
public int Count() {
|
|
||||||
return _places.size();
|
|
||||||
}
|
|
||||||
private final int _maxCount;
|
|
||||||
public SetGasolineTankerGeneric(int count)
|
|
||||||
{
|
|
||||||
_maxCount=count;
|
|
||||||
_places = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Insert(T gasolineTanker)
|
|
||||||
{
|
|
||||||
if (_places.size()+1>=_maxCount)
|
|
||||||
return -1;
|
|
||||||
_places.add(0,gasolineTanker);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Insert(T gasolineTanker, int position)
|
|
||||||
{
|
|
||||||
if (position>=_maxCount||position<0)
|
|
||||||
return -1;
|
|
||||||
if (_places.size()+1>=_maxCount)
|
|
||||||
return -1;
|
|
||||||
_places.add(position,gasolineTanker);
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T Remove(int position)
|
|
||||||
{
|
|
||||||
if (position>=_maxCount||position<0)
|
|
||||||
return null;
|
|
||||||
T deleted=_places.get(position);
|
|
||||||
_places.remove(position);
|
|
||||||
return deleted;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T Get(int position)
|
|
||||||
{
|
|
||||||
if (position>=_maxCount||position<0)
|
|
||||||
return null;
|
|
||||||
return _places.get(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Set(int position,T gasolineTanker){
|
|
||||||
if (position >= _maxCount||position<0)
|
|
||||||
return;
|
|
||||||
Insert(gasolineTanker,position);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public Iterator<T> iterator(){
|
|
||||||
return _places.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Iterable<T> GetGasolineTanker(){ return ()-> _places.stream().filter(Objects::nonNull).iterator();}
|
|
||||||
public void Clear(){
|
|
||||||
_places.clear();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class SimpleMap extends AbstractMap {
|
|
||||||
@Override
|
|
||||||
protected void DrawBarrierPart(Graphics gr, int i, int j) {
|
|
||||||
gr.setColor(Color.GRAY);
|
|
||||||
gr.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void DrawRoadPart(Graphics gr, int i, int j) {
|
|
||||||
gr.setColor(Color.BLACK);
|
|
||||||
gr.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void GenerateMap() {
|
|
||||||
_map = new int[100][100];
|
|
||||||
_size_x = (float) (_width / _map.length);
|
|
||||||
_size_y = (float) (_height / _map[0].length);
|
|
||||||
int counter = 0;
|
|
||||||
for (int i = 0; i < _map.length; ++i) {
|
|
||||||
for (int j = 0; j < _map[i].length; ++j) {
|
|
||||||
_map[i][j] = _freeRoad;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (counter < 50) {
|
|
||||||
int x = _random.nextInt(99);
|
|
||||||
int y = _random.nextInt(99);
|
|
||||||
if (_map[x][y] == _freeRoad) {
|
|
||||||
_map[x][y] = _barrier;
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user