Morozov V.S LabWork03_Hard #3
50
RadarAirplane/src/AirplaneMixer.java
Normal file
50
RadarAirplane/src/AirplaneMixer.java
Normal file
@ -0,0 +1,50 @@
|
||||
import java.util.Random;
|
||||
|
||||
public class AirplaneMixer<T extends EntityAirPlane, U extends IDrawingPorthole> {
|
||||
private T[] airplanes;
|
||||
private U[] portholes;
|
||||
|
||||
public AirplaneMixer(int countAirplane, int countPortholes) {
|
||||
airplanes = (T[])(new EntityAirPlane[countAirplane]);
|
||||
portholes = (U[])(new IDrawingPorthole[countPortholes]);
|
||||
}
|
||||
|
||||
public int add(T a) {
|
||||
int index = 0;
|
||||
while(index < airplanes.length && airplanes[index] != null) index++;
|
||||
|
||||
if(index == airplanes.length) return -1;
|
||||
|
||||
airplanes[index] = a;
|
||||
return index;
|
||||
}
|
||||
|
||||
public int add(U e) {
|
||||
int index = 0;
|
||||
while(index < portholes.length && portholes[index] != null) index++;
|
||||
|
||||
if(index == portholes.length) return -1;
|
||||
|
||||
portholes[index] = e;
|
||||
return index;
|
||||
}
|
||||
|
||||
public DrawingEntityPlain constructAirplane(int width, int height) {
|
||||
Random rnd = new Random();
|
||||
|
||||
DrawingEntityPlain air;
|
||||
|
||||
T selectedAirplane = airplanes[rnd.nextInt(0, airplanes.length)];
|
||||
U selectedPortholes = portholes[rnd.nextInt(0, portholes.length)];
|
||||
|
||||
DrawingEntityPlain result;
|
||||
|
||||
if(selectedAirplane instanceof EntityRadarPlain) {
|
||||
result = new DrawingRadarPlain(selectedAirplane, selectedPortholes);
|
||||
}
|
||||
else result = new DrawingEntityPlain(selectedAirplane, selectedPortholes);
|
||||
|
||||
result.SetPosition(10, 10, width, height);
|
||||
return result;
|
||||
}
|
||||
}
|
@ -42,6 +42,11 @@ class DrawingEntityPlain
|
||||
_AirplaneWidth = airPlaneWidth;
|
||||
_AirplaneHeight = airPlaneHeight;
|
||||
}
|
||||
public DrawingEntityPlain(EntityAirPlane entityAirPlane, IDrawingPorthole iDrawingPorthole){
|
||||
Airplane = entityAirPlane;
|
||||
drawingPortholes = iDrawingPorthole;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
if (width < _AirplaneWidth || height < _AirplaneHeight) return;
|
||||
|
@ -7,6 +7,9 @@ public class DrawingRadarPlain extends DrawingEntityPlain
|
||||
super(speed, weight, bodyColor, 240, 150);
|
||||
Airplane = new EntityRadarPlain(speed, weight, bodyColor, dopColor, Radar, OilBox);
|
||||
}
|
||||
public DrawingRadarPlain(EntityAirPlane entityAirPlane, IDrawingPorthole iDrawingPorthole){
|
||||
super(entityAirPlane,iDrawingPorthole);
|
||||
}
|
||||
@Override
|
||||
public void DrawTransport(Graphics2D g)
|
||||
{
|
||||
|
@ -52,19 +52,17 @@
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="b5cf" layout-manager="GridLayoutManager" row-count="2" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="b5cf" layout-manager="GridLayoutManager" row-count="2" column-count="7" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="7" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-5833743"/>
|
||||
</properties>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<hspacer id="eb27d">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="df504" class="javax.swing.JButton" binding="createButton">
|
||||
@ -77,7 +75,7 @@
|
||||
</component>
|
||||
<component id="b31a8" class="javax.swing.JButton" binding="downButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<grid row="1" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@ -90,7 +88,7 @@
|
||||
</component>
|
||||
<component id="1d949" class="javax.swing.JButton" binding="leftButton" default-binding="true">
|
||||
<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">
|
||||
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@ -103,7 +101,7 @@
|
||||
</component>
|
||||
<component id="527d2" class="javax.swing.JButton" binding="rightButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<grid row="1" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@ -116,7 +114,7 @@
|
||||
</component>
|
||||
<component id="5bf4f" class="javax.swing.JButton" binding="upButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<grid row="0" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@ -127,8 +125,24 @@
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b6c27" class="javax.swing.JButton" binding="createModifButton">
|
||||
<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="9de16" class="javax.swing.JButton" binding="selectButton">
|
||||
<constraints>
|
||||
<grid row="1" column="3" 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>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
</form>
|
@ -1,11 +1,10 @@
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.LineBorder;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormAirPlane implements Form {
|
||||
public class FormAirPlane extends JDialog implements Form {
|
||||
private JButton createButton;
|
||||
private JButton upButton;
|
||||
private JButton rightButton;
|
||||
@ -16,22 +15,18 @@ public class FormAirPlane implements Form {
|
||||
private JLabel speedLabel;
|
||||
private JLabel weightLabel;
|
||||
private JLabel colorLabel;
|
||||
|
||||
private JButton createModifButton;
|
||||
private JButton selectButton;
|
||||
DrawingEntityPlain _airPlane;
|
||||
private DrawingEntityPlain selectedPlane;
|
||||
|
||||
|
||||
private JFrame jframe = getFrame();
|
||||
|
||||
private JFrame getFrame() {
|
||||
JFrame frame = new JFrame();
|
||||
frame.setVisible(true);
|
||||
frame.setBounds(300, 100, 800, 600);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
return frame;
|
||||
public DrawingEntityPlain getSelectedPlane() {
|
||||
return selectedPlane;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
jframe.add(mainPanel);
|
||||
add(mainPanel);
|
||||
Canvas canv = new Canvas(this);
|
||||
DrawPlace.add(canv);
|
||||
|
||||
@ -40,8 +35,11 @@ public class FormAirPlane implements Form {
|
||||
Dimension canvSize = canv.getSize();
|
||||
Random rnd = new Random();
|
||||
|
||||
_airPlane = new DrawingEntityPlain(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)));
|
||||
Color color = JColorChooser.showDialog(this, "Цвет", Color.BLACK);
|
||||
|
||||
if(color == null) color = Color.BLACK;
|
||||
|
||||
_airPlane = new DrawingEntityPlain(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), color);
|
||||
|
||||
_airPlane.SetPosition((int)rnd.nextInt(10, 100), (int)rnd.nextInt(10, 100), canvSize.width, canvSize.height);
|
||||
|
||||
@ -55,12 +53,42 @@ public class FormAirPlane implements Form {
|
||||
canv.repaint();
|
||||
});
|
||||
|
||||
jframe.addComponentListener(new ComponentAdapter() {
|
||||
createModifButton.addActionListener(e -> {
|
||||
|
||||
Dimension canvSize = canv.getSize();
|
||||
Random rnd = new Random();
|
||||
|
||||
Color color = JColorChooser.showDialog(this, "Цвет", Color.BLACK);
|
||||
Color dopColor = JColorChooser.showDialog(this, "Цвет", Color.BLACK);
|
||||
|
||||
if(color == null) color = Color.BLACK;
|
||||
if(dopColor == null) dopColor = Color.BLACK;
|
||||
|
||||
_airPlane = new DrawingRadarPlain(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
color, dopColor,
|
||||
rnd.nextInt(0, 2) == 1, rnd.nextInt(0, 2) == 1);
|
||||
|
||||
_airPlane.SetPosition((int)rnd.nextInt(10, 100), (int)rnd.nextInt(10, 100), canvSize.width, canvSize.height);
|
||||
|
||||
Color bodyColor = _airPlane.Airplane.BodyColor;
|
||||
String colorString = "(" + bodyColor.getRed() + ", " + bodyColor.getGreen() + ", " + bodyColor.getBlue() + ")";
|
||||
|
||||
speedLabel.setText("Скорость: " + _airPlane.Airplane.Speed + " ");
|
||||
weightLabel.setText("Вес: " + _airPlane.Airplane.Weight + " ");
|
||||
colorLabel.setText("Цвет: " + colorString);
|
||||
|
||||
canv.repaint();
|
||||
});
|
||||
|
||||
selectButton.addActionListener(e -> {
|
||||
selectedPlane = _airPlane;
|
||||
dispose();
|
||||
});
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
if(_airPlane == null) return;
|
||||
_airPlane.ChangeBorders(canv.getSize().width, canv.getSize().height);
|
||||
jframe.revalidate();
|
||||
}
|
||||
});
|
||||
|
||||
|
182
RadarAirplane/src/MapWithSetPlane.java
Normal file
182
RadarAirplane/src/MapWithSetPlane.java
Normal file
@ -0,0 +1,182 @@
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class MapWithSetPlane<T extends IDrawingObject, U extends AbstractMap>
|
||||
{
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
private int _placeSizeWidth = 210;
|
||||
private int _placeSizeHeight = 170;
|
||||
private SetPlaneGeneric<T> _setPlane;
|
||||
private U _map;
|
||||
|
||||
public MapWithSetPlane(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setPlane = new SetPlaneGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
|
||||
public int addAirPlane(T airplane)
|
||||
{
|
||||
return _setPlane.Insert(airplane);
|
||||
}
|
||||
|
||||
public T removeAirPlane(int position)
|
||||
{
|
||||
return _setPlane.Remove(position);
|
||||
}
|
||||
|
||||
public Image ShowSet()
|
||||
{
|
||||
BufferedImage img = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D gr = (Graphics2D) img.getGraphics();
|
||||
|
||||
DrawBackground(gr);
|
||||
DrawPlanes(gr);
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
public Image ShowOnMap()
|
||||
{
|
||||
BufferedImage img = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g = (Graphics2D) img.getGraphics();
|
||||
|
||||
Shaking();
|
||||
for (int i = 0; i < _setPlane.getCount(); i++)
|
||||
{
|
||||
var car = _setPlane.Get(i);
|
||||
if (car != null)
|
||||
{
|
||||
_map.CreateMap(_pictureWidth, _pictureHeight, car);
|
||||
_map.DrawMapWithObject(g);
|
||||
return img;
|
||||
}
|
||||
}
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
public Image MoveObject(Direction direction)
|
||||
{
|
||||
BufferedImage img = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g = (Graphics2D) img.getGraphics();
|
||||
|
||||
if (_map != null)
|
||||
{
|
||||
_map.MoveObject(direction);
|
||||
_map.DrawMapWithObject(g);
|
||||
}
|
||||
return img;
|
||||
}
|
||||
|
||||
private void Shaking()
|
||||
{
|
||||
int j = _setPlane.getCount() - 1;
|
||||
for (int i = 0; i < _setPlane.getCount(); i++)
|
||||
{
|
||||
if (_setPlane.Get(i) == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var car = _setPlane.Get(j);
|
||||
if (car != null)
|
||||
{
|
||||
_setPlane.Insert(car, i);
|
||||
_setPlane.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawBackground(Graphics2D g)
|
||||
{
|
||||
|
||||
|
||||
g.setPaint(new Color(160, 160, 160));
|
||||
g.fillRect(0, 0, _pictureWidth , _pictureHeight );
|
||||
|
||||
g.setPaint(Color.black);
|
||||
g.setStroke(new BasicStroke(3));
|
||||
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{
|
||||
g.drawLine(i * _placeSizeWidth, j * _placeSizeHeight, i *
|
||||
_placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
}
|
||||
g.drawLine( i * _placeSizeWidth, 0, i * _placeSizeWidth,
|
||||
(_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
}
|
||||
|
||||
g.setStroke(new BasicStroke(1));
|
||||
}
|
||||
|
||||
private void DrawPlanes(Graphics2D g)
|
||||
{
|
||||
int CountWidth = _pictureWidth / _placeSizeWidth;
|
||||
|
||||
int x = _pictureWidth - _placeSizeWidth - _placeSizeWidth/2 - _placeSizeWidth / 4;
|
||||
int y = _placeSizeHeight/4;
|
||||
|
||||
for (int k = 0; k < _setPlane.getCount(); k++)
|
||||
{
|
||||
if (_setPlane.Get(k) != null)
|
||||
{
|
||||
if ((k+1) % CountWidth != 0 || k ==0)
|
||||
{
|
||||
_setPlane.Get(k).SetObject(x, y, _pictureWidth, _pictureHeight);
|
||||
_setPlane.Get(k).DrawningObject(g);
|
||||
x -= _placeSizeWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
_setPlane.Get(k).SetObject(x, y, _pictureWidth, _pictureHeight);
|
||||
_setPlane.Get(k).DrawningObject(g);
|
||||
x = _pictureWidth - _placeSizeWidth - _placeSizeWidth / 2 - _placeSizeWidth / 4;
|
||||
y += _placeSizeHeight ;
|
||||
|
||||
}
|
||||
}
|
||||
if (_setPlane.Get(k) == null)
|
||||
{
|
||||
if ((k + 1) % CountWidth != 0 || k ==0)
|
||||
x -= _placeSizeWidth;
|
||||
else
|
||||
{
|
||||
x = _pictureWidth - _placeSizeWidth - _placeSizeWidth / 2 - _placeSizeWidth / 4;
|
||||
y += _placeSizeHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*int width = _pictureWidth / _placeSizeWidth;
|
||||
|
||||
for (int i = 0; i < _setPlane.getCount(); i++)
|
||||
{
|
||||
int x = i % width;
|
||||
int y = i / width;
|
||||
|
||||
T current =_setPlane.Get(i);
|
||||
|
||||
if(current == null) continue;
|
||||
|
||||
current.SetObject(x * _placeSizeWidth, y * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
||||
current.DrawningObject(g);
|
||||
}*/
|
||||
}
|
17
RadarAirplane/src/PortholeFabric.java
Normal file
17
RadarAirplane/src/PortholeFabric.java
Normal file
@ -0,0 +1,17 @@
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class PortholeFabric {
|
||||
public static IDrawingPorthole createRandom(Color color) {
|
||||
Random rnd = new Random();
|
||||
|
||||
int type = rnd.nextInt(0, 3);
|
||||
|
||||
return switch(type) {
|
||||
case 0 -> new DrawingPorthole(rnd.nextInt(1, 40), color);
|
||||
case 1 -> new DrawingSquarePorthole(rnd.nextInt(1, 40), color);
|
||||
case 2 -> new DrawingTrianglePorthole(rnd.nextInt(1, 40), color);
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
@ -3,6 +3,6 @@ import java.awt.*;
|
||||
|
||||
public class Program {
|
||||
public static void main(String[] args) {
|
||||
new formMap().run();
|
||||
new formPlaneGenerator().run();
|
||||
}
|
||||
}
|
50
RadarAirplane/src/SetPlaneGeneric.java
Normal file
50
RadarAirplane/src/SetPlaneGeneric.java
Normal file
@ -0,0 +1,50 @@
|
||||
public class SetPlaneGeneric<T>
|
||||
{
|
||||
private T[] _places;
|
||||
|
||||
public int getCount() {
|
||||
return _places.length;
|
||||
}
|
||||
|
||||
public SetPlaneGeneric(int count)
|
||||
{
|
||||
_places = (T[])(new Object[count]);
|
||||
}
|
||||
public int Insert(T plane)
|
||||
{
|
||||
for(int i = 0; i < _places.length; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
_places[i] = plane;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public int Insert(T plane, int position)
|
||||
{
|
||||
int index = position;
|
||||
|
||||
while (_places[index] != null && index < _places.length) index++;
|
||||
|
||||
if (index == _places.length) return -1;
|
||||
for (int i = index; i > position; --i) _places[i] = _places[i - 1];
|
||||
|
||||
_places[position] = plane;
|
||||
return position;
|
||||
}
|
||||
|
||||
public T Remove(int position)
|
||||
{
|
||||
if(position >= _places.length) return null;
|
||||
T res = _places[position];
|
||||
_places[position] = null;
|
||||
return res;
|
||||
}
|
||||
|
||||
public T Get(int position)
|
||||
{
|
||||
return _places[position];
|
||||
}
|
||||
}
|
163
RadarAirplane/src/formMapWithSetPlane.form
Normal file
163
RadarAirplane/src/formMapWithSetPlane.form
Normal file
@ -0,0 +1,163 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="formMapWithSetPlane">
|
||||
<grid id="27dc6" binding="MainPane" 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>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="afa3d" binding="drawPanel" layout-manager="CardLayout" hgap="0" vgap="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>
|
||||
<grid id="e9a63" layout-manager="GridLayoutManager" row-count="8" 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="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="f23ee" class="javax.swing.JButton" binding="buttonAdd">
|
||||
<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="2e61e" class="javax.swing.JComboBox" binding="comboBoxSelectorMap">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<model>
|
||||
<item value="Простая карта"/>
|
||||
<item value="Моя карта"/>
|
||||
</model>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="5c428" class="javax.swing.JButton" binding="buttonRemove">
|
||||
<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="Удалить"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="e24b9" class="javax.swing.JButton" binding="buttonShowStorage">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Посмотреть Хранилище"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ac087" class="javax.swing.JButton" binding="buttonShowOnMap">
|
||||
<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="Посмотреть карту"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="2821b" layout-manager="GridLayoutManager" row-count="2" 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="7" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="6d803" class="javax.swing.JButton" binding="leftButton">
|
||||
<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">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="Resources/left.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c0db2" class="javax.swing.JButton" binding="upButton">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="Resources/up.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ca0da" class="javax.swing.JButton" binding="downButton">
|
||||
<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">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="Resources/down.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c3e45" class="javax.swing.JButton" binding="rightButton">
|
||||
<constraints>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="Resources/right.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="1f200">
|
||||
<constraints>
|
||||
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<hspacer id="f8b3b">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
<vspacer id="b833e">
|
||||
<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="181ac" class="javax.swing.JTextField" binding="textBoxPosition">
|
||||
<constraints>
|
||||
<grid row="2" 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>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
175
RadarAirplane/src/formMapWithSetPlane.java
Normal file
175
RadarAirplane/src/formMapWithSetPlane.java
Normal file
@ -0,0 +1,175 @@
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.DefaultFormatterFactory;
|
||||
import javax.swing.text.MaskFormatter;
|
||||
import java.awt.*;
|
||||
import java.text.ParseException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class formMapWithSetPlane implements Form {
|
||||
private JPanel MainPane;
|
||||
private JButton buttonAdd;
|
||||
private JComboBox comboBoxSelectorMap;
|
||||
private JTextField textBoxPosition;
|
||||
private JButton buttonRemove;
|
||||
private JButton buttonShowStorage;
|
||||
private JButton buttonShowOnMap;
|
||||
private JButton upButton;
|
||||
private JButton leftButton;
|
||||
private JButton rightButton;
|
||||
private JButton downButton;
|
||||
private JPanel drawPanel;
|
||||
|
||||
|
||||
private MapWithSetPlane<DrawingObjectPlain, AbstractMap> _mapCarsCollectionGeneric;
|
||||
private Canvas canv = new Canvas(this);
|
||||
|
||||
JFrame jFrame = getFrame();
|
||||
Image img;
|
||||
|
||||
private JFrame getFrame() {
|
||||
JFrame frame = new JFrame();
|
||||
frame.setVisible(true);
|
||||
frame.setBounds(300, 100, 800, 600);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
return frame;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
jFrame.add(MainPane);
|
||||
drawPanel.add(canv);
|
||||
|
||||
comboBoxSelectorMap.setSelectedIndex(-1);
|
||||
|
||||
comboBoxSelectorMap.addActionListener(e -> {
|
||||
AbstractMap map = null;
|
||||
switch (comboBoxSelectorMap.getSelectedItem().toString())
|
||||
{
|
||||
case "Простая карта":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "Моя карта":
|
||||
map = new MyMap();
|
||||
break;
|
||||
}
|
||||
if (map != null)
|
||||
{
|
||||
Dimension canvSize = canv.getSize();
|
||||
_mapCarsCollectionGeneric = new MapWithSetPlane<DrawingObjectPlain, AbstractMap>(
|
||||
canvSize.width, canvSize.height, map);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mapCarsCollectionGeneric = null;
|
||||
}
|
||||
});
|
||||
|
||||
buttonAdd.addActionListener(e -> {
|
||||
if (_mapCarsCollectionGeneric == null) return;
|
||||
|
||||
FormAirPlane dialog = new FormAirPlane();
|
||||
dialog.run();
|
||||
dialog.setSize(800, 500);
|
||||
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
|
||||
dialog.setVisible(true);
|
||||
|
||||
if (dialog.getSelectedPlane() == null) return;
|
||||
|
||||
DrawingObjectPlain aircraft = new DrawingObjectPlain(dialog.getSelectedPlane());
|
||||
if (_mapCarsCollectionGeneric.addAirPlane(aircraft) != -1)
|
||||
{
|
||||
JOptionPane.showMessageDialog(jFrame, "Объект добавлен");
|
||||
img = _mapCarsCollectionGeneric.ShowSet();
|
||||
canv.repaint();
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(jFrame, "Не удалось добавить объект");
|
||||
}
|
||||
});
|
||||
|
||||
buttonRemove.addActionListener(e -> {
|
||||
if(_mapCarsCollectionGeneric == null) return;
|
||||
|
||||
String text = textBoxPosition.getText();
|
||||
if(text.isEmpty()) return;
|
||||
|
||||
if(JOptionPane.showConfirmDialog(
|
||||
jFrame,
|
||||
"Вы действительно хотите удалить объект?",
|
||||
"Удаление",
|
||||
JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) return;
|
||||
|
||||
int pos;
|
||||
try {
|
||||
pos = Integer.parseInt(text);
|
||||
} catch (Exception err) {
|
||||
return;
|
||||
}
|
||||
pos = Integer.parseInt(text);
|
||||
|
||||
if(_mapCarsCollectionGeneric.removeAirPlane(pos) != null) {
|
||||
JOptionPane.showMessageDialog(jFrame, "Объект удален");
|
||||
img = _mapCarsCollectionGeneric.ShowSet();
|
||||
canv.repaint();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(jFrame, "Не удалось удалить объект");
|
||||
}
|
||||
});
|
||||
|
||||
buttonShowStorage.addActionListener(e -> {
|
||||
if (_mapCarsCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
img = _mapCarsCollectionGeneric.ShowSet();
|
||||
canv.repaint();
|
||||
});
|
||||
|
||||
buttonShowOnMap.addActionListener(e -> {
|
||||
if (_mapCarsCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
img = _mapCarsCollectionGeneric.ShowOnMap();
|
||||
canv.repaint();
|
||||
});
|
||||
|
||||
leftButton.addActionListener(e -> {
|
||||
if(_mapCarsCollectionGeneric == null) return;
|
||||
img = _mapCarsCollectionGeneric.MoveObject(Direction.Left);
|
||||
canv.repaint();
|
||||
});
|
||||
|
||||
rightButton.addActionListener(e -> {
|
||||
if(_mapCarsCollectionGeneric == null) return;
|
||||
img = _mapCarsCollectionGeneric.MoveObject(Direction.Right);
|
||||
canv.repaint();
|
||||
});
|
||||
|
||||
upButton.addActionListener(e -> {
|
||||
if(_mapCarsCollectionGeneric == null) return;
|
||||
img = _mapCarsCollectionGeneric.MoveObject(Direction.Up);
|
||||
canv.repaint();
|
||||
});
|
||||
|
||||
downButton.addActionListener(e -> {
|
||||
|
||||
if(_mapCarsCollectionGeneric == null) return;
|
||||
img = _mapCarsCollectionGeneric.MoveObject(Direction.Down);
|
||||
canv.repaint();
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Draw(Graphics2D g) {
|
||||
if(img == null) return;
|
||||
g.drawImage(img, 0, 0, null);
|
||||
}
|
||||
}
|
29
RadarAirplane/src/formPlaneGenerator.form
Normal file
29
RadarAirplane/src/formPlaneGenerator.form
Normal file
@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="formPlaneGenerator">
|
||||
<grid id="27dc6" binding="mainPanel" 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>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="b9cac" class="javax.swing.JButton" binding="generateButton">
|
||||
<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>
|
||||
<grid id="d138" binding="drawPanel" layout-manager="CardLayout" hgap="0" vgap="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>
|
||||
</form>
|
76
RadarAirplane/src/formPlaneGenerator.java
Normal file
76
RadarAirplane/src/formPlaneGenerator.java
Normal file
@ -0,0 +1,76 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class formPlaneGenerator implements Form {
|
||||
private JButton generateButton;
|
||||
private JPanel drawPanel;
|
||||
private JPanel mainPanel;
|
||||
private Canvas canv = new Canvas(this);
|
||||
|
||||
private DrawingEntityPlain airplane;
|
||||
private AirplaneMixer<EntityAirPlane, IDrawingPorthole> mixer = new AirplaneMixer<>(10, 20);
|
||||
private JFrame jframe = getFrame();
|
||||
|
||||
private JFrame getFrame() {
|
||||
JFrame frame = new JFrame();
|
||||
frame.setVisible(true);
|
||||
frame.setBounds(300, 100, 400, 300);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
return frame;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
jframe.add(mainPanel);
|
||||
drawPanel.add(canv);
|
||||
|
||||
Random rnd = new Random();
|
||||
|
||||
for(int i = 0; i < 10; ++i) {
|
||||
if(rnd.nextBoolean()) {
|
||||
mixer.add(new EntityAirPlane(rnd.nextInt(100, 250), rnd.nextInt(1000, 2000),
|
||||
new Color(
|
||||
rnd.nextInt(0, 255),
|
||||
rnd.nextInt(0, 255),
|
||||
rnd.nextInt(0, 255)
|
||||
)));
|
||||
continue;
|
||||
}
|
||||
|
||||
mixer.add(new EntityRadarPlain(rnd.nextInt(100, 250), rnd.nextInt(1000, 2000),
|
||||
new Color(
|
||||
rnd.nextInt(0, 255),
|
||||
rnd.nextInt(0, 255),
|
||||
rnd.nextInt(0, 255)
|
||||
),
|
||||
new Color(
|
||||
rnd.nextInt(0, 255),
|
||||
rnd.nextInt(0, 255),
|
||||
rnd.nextInt(0, 255)
|
||||
),
|
||||
rnd.nextBoolean(), rnd.nextBoolean()
|
||||
));
|
||||
}
|
||||
|
||||
for(int i = 0; i < 20; ++i) {
|
||||
Color randomColor = new Color(
|
||||
rnd.nextInt(0, 255),
|
||||
rnd.nextInt(0, 255),
|
||||
rnd.nextInt(0, 255));
|
||||
|
||||
mixer.add(PortholeFabric.createRandom(randomColor));
|
||||
}
|
||||
|
||||
generateButton.addActionListener(e -> {
|
||||
Dimension canvSize = canv.getSize();
|
||||
airplane = mixer.constructAirplane(canvSize.width, canvSize.height);
|
||||
canv.repaint();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Draw(Graphics2D g) {
|
||||
if(airplane == null) return;
|
||||
airplane.DrawTransport(g);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user