Compare commits
7 Commits
master
...
lab5-devel
Author | SHA1 | Date | |
---|---|---|---|
1b5f6fc87a | |||
feb5eccc7f | |||
|
0e2779eb1e | ||
525ba16a8a | |||
64bbb4ea6f | |||
d0aa5f7b0d | |||
738d5f9a46 |
BIN
ProjectElectroTrans/Drawnings.zip
Normal file
@ -3,6 +3,7 @@
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/Resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
|
BIN
ProjectElectroTrans/Resources/arrowDown.png
Normal file
After Width: | Height: | Size: 965 B |
BIN
ProjectElectroTrans/Resources/arrowLeft.png
Normal file
After Width: | Height: | Size: 1005 B |
BIN
ProjectElectroTrans/Resources/arrowRight.png
Normal file
After Width: | Height: | Size: 978 B |
BIN
ProjectElectroTrans/Resources/arrowUp.png
Normal file
After Width: | Height: | Size: 1012 B |
@ -0,0 +1,60 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import Drawnings.DrawningTrans;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class AbstractCompany {
|
||||
protected final int _placeSizeWidth = 210;
|
||||
protected final int _placeSizeHeight = 120;
|
||||
protected final int _pictureWidth;
|
||||
protected final int _pictureHeight;
|
||||
protected ICollectionGenericObjects<DrawningTrans> _collection = null;
|
||||
public int getMaxCount() {
|
||||
return _pictureWidth * _pictureHeight / (_placeSizeWidth*_placeSizeHeight);
|
||||
}
|
||||
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningTrans> collection) {
|
||||
this._pictureWidth = picWidth;
|
||||
this._pictureHeight = picHeight;
|
||||
this._collection = collection;
|
||||
int maxCount = getMaxCount();
|
||||
_collection.setMaxCount(maxCount);
|
||||
}
|
||||
public static int add(AbstractCompany company ,DrawningTrans trans) {
|
||||
if (company._collection == null) {
|
||||
return -1;
|
||||
}
|
||||
return company._collection.insert(trans);
|
||||
}
|
||||
|
||||
public static DrawningTrans remove(AbstractCompany company, int position) {
|
||||
if (company._collection == null) {
|
||||
return null;
|
||||
}
|
||||
return company._collection.remove(position);
|
||||
}
|
||||
public DrawningTrans getRandomObject() {
|
||||
if (_collection == null) {
|
||||
return null;
|
||||
}
|
||||
Random rnd = new Random();
|
||||
return _collection.get(rnd.nextInt(0, _collection.getCount() + 1));
|
||||
}
|
||||
public void show(Graphics g) {
|
||||
drawBackground(g);
|
||||
setObjectsPosition();
|
||||
if (_collection == null) {
|
||||
return;
|
||||
}
|
||||
for(int i = 0; i < _collection.getCount(); i++) {
|
||||
if(_collection.get(i) != null) {
|
||||
_collection.get(i).drawTrans(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected abstract void drawBackground(Graphics g);
|
||||
protected abstract void setObjectsPosition();
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
public enum CollectionType {
|
||||
None(0),
|
||||
Massive(1),
|
||||
List(2);
|
||||
|
||||
final private int collectionTypeValue;
|
||||
|
||||
CollectionType(int value){
|
||||
collectionTypeValue = value;
|
||||
}
|
||||
public int getCollectionTypeValue() {
|
||||
return collectionTypeValue;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import Drawnings.DrawningTrans;
|
||||
import Drawnings.DrawningElectroTrans;
|
||||
import Drawnings.IDrawWheels;
|
||||
import Entities.EntityTrans;
|
||||
import Entities.EntityElectroTrans;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
public class Constructor<T extends EntityTrans, U extends IDrawWheels> {
|
||||
private ArrayList<T> entitiesList = new ArrayList<>();
|
||||
private ArrayList<U> wheelsList = new ArrayList<>();
|
||||
public void addTrans(T obj) {
|
||||
entitiesList.add(obj);
|
||||
}
|
||||
public void addTrans(U obj) {
|
||||
wheelsList.add(obj);
|
||||
}
|
||||
|
||||
public DrawningTrans getRandomTrans() {
|
||||
Random rnd = new Random();
|
||||
int entityIndex = rnd.nextInt(0, 3);
|
||||
int wheelsIndex = rnd.nextInt(0, 3);
|
||||
|
||||
T entity = entitiesList.get(entityIndex);
|
||||
U wheels = wheelsList.get(wheelsIndex);
|
||||
|
||||
return (entity instanceof EntityElectroTrans) ?
|
||||
new DrawningElectroTrans((EntityElectroTrans) entity, wheels) :
|
||||
new DrawningTrans(entity, wheels);
|
||||
}
|
||||
|
||||
public String getEntityDescription(int index) {
|
||||
if (index < 0 || index >= entitiesList.size()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
T entity = entitiesList.get(index);
|
||||
String entityClassName = (entity instanceof EntityElectroTrans) ? "EntityElectroTrans" : "EntityTrans";
|
||||
|
||||
return String.format("<html><i><u>%s</u></i> = %s</html>", entityClassName, entity);
|
||||
}
|
||||
|
||||
public String getPaddlesDescription(int index) {
|
||||
if (index < 0 || index >= wheelsList.size()) {
|
||||
return null;
|
||||
}
|
||||
return wheelsList.get(index).toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import Drawnings.DrawningTrans;
|
||||
|
||||
public interface ICollectionGenericObjects<T extends DrawningTrans> {
|
||||
int getCount();
|
||||
|
||||
void setMaxCount(int count);
|
||||
|
||||
int insert(T obj);
|
||||
|
||||
int insert(T obj, int index);
|
||||
|
||||
T remove(int index);
|
||||
|
||||
T get(int index);
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import Drawnings.DrawningTrans;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ListGenericCollection<T extends DrawningTrans> implements ICollectionGenericObjects<T> {
|
||||
private final ArrayList<T> _collection;
|
||||
public ListGenericCollection() {
|
||||
_collection = new ArrayList<>();
|
||||
}
|
||||
private int maxCount;
|
||||
public int count;
|
||||
@Override
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
@Override
|
||||
public void setMaxCount(int count) {
|
||||
maxCount = count;
|
||||
}
|
||||
@Override
|
||||
public int insert(T obj) {
|
||||
return insert(obj, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insert(T obj, int index) {
|
||||
if (index > maxCount || index < 0 || index > count){
|
||||
return -1;
|
||||
}
|
||||
if(index == count){
|
||||
_collection.add(obj);
|
||||
}
|
||||
else {
|
||||
_collection.add(index, obj);
|
||||
}
|
||||
count = _collection.size();
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T remove(int index) {
|
||||
if (index > maxCount || index < 0 || index >= count){
|
||||
return null;
|
||||
}
|
||||
count = _collection.size() - 1;
|
||||
return _collection.remove(index);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(int index) {
|
||||
if (index >= count){
|
||||
return null;
|
||||
}
|
||||
return _collection.get(index);
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import Drawnings.DrawningTrans;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MassiveGenericObjects<T extends DrawningTrans> implements ICollectionGenericObjects<T> {
|
||||
private ArrayList<T> _collection;
|
||||
public MassiveGenericObjects() {
|
||||
_collection = new ArrayList<>();
|
||||
|
||||
}
|
||||
int maxCount = 0;
|
||||
int realSize = 0;
|
||||
@Override
|
||||
public int getCount() {
|
||||
return _collection.size();
|
||||
}
|
||||
@Override
|
||||
public int insert(T obj) {
|
||||
return insert(obj, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insert(T obj, int position) {
|
||||
if (position > maxCount|| position < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i = position; i < maxCount; i++) {
|
||||
if (_collection.get(i) == null) {
|
||||
_collection.set(i, obj);
|
||||
realSize++;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
for (int i = position; i > 0; i--) {
|
||||
if (_collection.get(i) == null) {
|
||||
_collection.set(i, obj);
|
||||
realSize++;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T remove(int position) {
|
||||
if (position < 0 || position >= maxCount) {
|
||||
return null;
|
||||
}
|
||||
if (_collection.get(position) != null) {
|
||||
T bf = _collection.get(position);
|
||||
_collection.set(position, null);
|
||||
--realSize;
|
||||
return bf;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(int position) {
|
||||
if (position >= 0 && position < _collection.size()) {
|
||||
return _collection.get(position);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxCount(int count) {
|
||||
if (count > 0) {
|
||||
if (!_collection.isEmpty()) {
|
||||
ArrayList<T> bfLoc = new ArrayList<>(count);
|
||||
bfLoc.addAll(0, _collection);
|
||||
_collection = bfLoc;
|
||||
for (int i = 0; i < count - maxCount; i++) {
|
||||
_collection.add(null);
|
||||
}
|
||||
} else {
|
||||
_collection = new ArrayList<>(count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
_collection.add(null);
|
||||
}
|
||||
|
||||
}
|
||||
maxCount = count;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import Drawnings.DrawningTrans;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class StorageCollection<T extends DrawningTrans> {
|
||||
private final HashMap<String, ICollectionGenericObjects<T>> _storages;
|
||||
public final ArrayList<String> keys;
|
||||
|
||||
public StorageCollection() {
|
||||
_storages = new HashMap<>();
|
||||
keys = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addCollection(String name, CollectionType collectionType){
|
||||
if (_storages.containsKey(name) || name.isEmpty()){
|
||||
return;
|
||||
}
|
||||
switch (collectionType){
|
||||
case None:
|
||||
return;
|
||||
case Massive:
|
||||
_storages.put(name, new MassiveGenericObjects<>());
|
||||
keys.add(name);
|
||||
break;
|
||||
case List:
|
||||
_storages.put(name, new ListGenericCollection<>());
|
||||
keys.add(name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void delCollection(String name){
|
||||
_storages.remove(name);
|
||||
keys.remove(name);
|
||||
}
|
||||
|
||||
public ICollectionGenericObjects<T> getCollection(String name){
|
||||
return _storages.get(name);
|
||||
}
|
||||
|
||||
public T getObjectFromChooseCollection(String name, int ind){
|
||||
return this.getCollection(name).get(ind);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import Drawnings.DrawningTrans;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TransSharingService extends AbstractCompany {
|
||||
private final List<Point> locCoord = new ArrayList<>();
|
||||
private int numRows, numCols;
|
||||
public TransSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningTrans> collection) {
|
||||
super(picWidth, picHeight, collection);
|
||||
_collection.setMaxCount(30);
|
||||
|
||||
}
|
||||
@Override
|
||||
protected void drawBackground(Graphics g) {
|
||||
Color backgroundColor = new Color(135, 206, 235);
|
||||
|
||||
g.setColor(backgroundColor);
|
||||
g.fillRect(0, 0, _pictureWidth, _pictureHeight);
|
||||
|
||||
g.setColor(new Color(165, 42, 42)); // Brown
|
||||
int offsetX = 10, offsetY = -5;
|
||||
int x = 1 + offsetX, y = _pictureHeight - _placeSizeHeight + offsetY;
|
||||
numRows = 0;
|
||||
while (y >= 0) {
|
||||
int numCols = 0;
|
||||
while (x + _placeSizeWidth <= _pictureWidth) {
|
||||
numCols++;
|
||||
g.drawLine(x, y, x + _placeSizeWidth / 2, y);
|
||||
g.drawLine(x, y, x, y + _placeSizeHeight + 4);
|
||||
locCoord.add(new Point(x, y));
|
||||
x += _placeSizeWidth + 2;
|
||||
}
|
||||
numRows++;
|
||||
x = 1 + offsetX;
|
||||
y -= _placeSizeHeight + 5 + offsetY;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setObjectsPosition() {
|
||||
if (locCoord == null || _collection == null) {
|
||||
return;
|
||||
}
|
||||
int row = numRows - 1, col = numCols;
|
||||
for (int i=0;i< _collection.getCount(); i++, col--) {
|
||||
if (_collection.get(i) != null) {
|
||||
_collection.get(i).setPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection.get(i).setPosition((int)locCoord.get(row*numCols - col).getX() + 5,
|
||||
(int)locCoord.get(row*numCols - col).getY() + 9);
|
||||
if (col == 1) {
|
||||
col = numCols + 1;
|
||||
row--;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
171
ProjectElectroTrans/src/Drawnings/DrawningAbstractCompany.java
Normal file
@ -0,0 +1,171 @@
|
||||
package Drawnings;
|
||||
|
||||
import CollectionGenericObjects.*;
|
||||
import Forms.FormConstructor;
|
||||
import Forms.FormElectroTrans;
|
||||
import Forms.FormTransConfig;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.Random;
|
||||
import java.util.Stack;
|
||||
|
||||
public class DrawningAbstractCompany extends JComponent {
|
||||
private AbstractCompany _company = null;
|
||||
DrawningTrans _drawningTrans;
|
||||
|
||||
// public void collectionComboBox_SelectedIndexChanged(JComboBox<String> obj, int width, int height) {
|
||||
private final StorageCollection<DrawningTrans> storageCollection = new StorageCollection<>();
|
||||
private Stack<DrawningTrans> rubbishBinStack = new Stack<>();
|
||||
|
||||
public boolean collectionComboBox_SelectedIndexChanged(JFrame frame, JList<String> collectionList, JComboBox<String> obj, int width, int height) {
|
||||
switch (obj.getSelectedIndex()) {
|
||||
case 1:
|
||||
if (collectionList.getSelectedIndex() == -1) {
|
||||
JOptionPane.showMessageDialog(frame, "Коллекция не выбрана");
|
||||
return false;
|
||||
}
|
||||
_company = new TransSharingService(width, height, storageCollection.getCollection(collectionList.getSelectedValue()));
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void createObject(JFrame obj) {
|
||||
if (_company == null) {
|
||||
return;
|
||||
}
|
||||
FormTransConfig formTransConfig = new FormTransConfig();
|
||||
formTransConfig.OpenFrame();
|
||||
formTransConfig.getButtonAdd().addActionListener(e -> {
|
||||
if (formTransConfig.getDrawningConfig().trans != null) {
|
||||
_drawningTrans = formTransConfig.getDrawningConfig().trans;
|
||||
if (AbstractCompany.add(_company, _drawningTrans) != -1) {
|
||||
JOptionPane.showMessageDialog(obj, "Объект добавлен");
|
||||
obj.repaint();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(obj, "Не удалось добавить объект");
|
||||
}
|
||||
formTransConfig.getjFrameTransConfig().dispatchEvent(new WindowEvent(formTransConfig.getjFrameTransConfig(), WindowEvent.WINDOW_CLOSING));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Color getColorR(JFrame obj, Random rnd) {
|
||||
Color color = new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256));
|
||||
if (obj == null) {
|
||||
return color;
|
||||
}
|
||||
JColorChooser colorChooser = new JColorChooser();
|
||||
colorChooser.setColor(color);
|
||||
return JColorChooser.showDialog(obj, "Выберите цвет", color);
|
||||
}
|
||||
|
||||
public boolean deleteButtonAction(int val, Frame obj) {
|
||||
if (_company == null) {
|
||||
return false;
|
||||
}
|
||||
int result = JOptionPane.showConfirmDialog(obj, "Удалить объект?", "Подтвердение", JOptionPane.YES_NO_OPTION);
|
||||
if (result == JOptionPane.YES_OPTION) {
|
||||
DrawningTrans deletableTrans = AbstractCompany.remove(_company, val);
|
||||
if (deletableTrans != null) {
|
||||
rubbishBinStack.add(deletableTrans);
|
||||
JOptionPane.showMessageDialog(obj, "Выполнено");
|
||||
return true;
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(obj, "Удаление не удалось");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void goToCheckButtonAction() {
|
||||
if (_company == null) {
|
||||
return;
|
||||
}
|
||||
DrawningTrans trans = null;
|
||||
int counter = 100;
|
||||
while (trans == null && counter > 0) {
|
||||
trans = _company.getRandomObject();
|
||||
--counter;
|
||||
}
|
||||
if (trans == null) {
|
||||
return;
|
||||
}
|
||||
createFormCatamaran(trans);
|
||||
}
|
||||
|
||||
public boolean goToCheckFromRubbishBinAction() {
|
||||
if (rubbishBinStack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
DrawningTrans trans = rubbishBinStack.pop();
|
||||
createFormCatamaran(trans);
|
||||
return !rubbishBinStack.isEmpty();
|
||||
}
|
||||
|
||||
public void createFormCatamaran(DrawningTrans trans) {
|
||||
FormElectroTrans formElectroTrans = new FormElectroTrans();
|
||||
formElectroTrans.setDrawningTrans(trans);
|
||||
formElectroTrans.OpenFrame();
|
||||
}
|
||||
|
||||
private DrawningTrans createObject;
|
||||
|
||||
public void getObjFromConstructor(JFrame obj) {
|
||||
if (_company == null) {
|
||||
return;
|
||||
}
|
||||
FormConstructor formConstructor = new FormConstructor();
|
||||
formConstructor.OpenFrame();
|
||||
|
||||
formConstructor.getAddButton().addActionListener(e -> {
|
||||
createObject = formConstructor.getConstructor().getObj();
|
||||
if (AbstractCompany.add(_company, createObject) != -1) {
|
||||
JOptionPane.showMessageDialog(obj, "Выполнено");
|
||||
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(obj, "Добавление не удалось");
|
||||
}
|
||||
obj.repaint();
|
||||
formConstructor.getjFrameConstructor().dispatchEvent(new WindowEvent(formConstructor.getjFrameConstructor(), WindowEvent.WINDOW_CLOSING));
|
||||
});
|
||||
}
|
||||
|
||||
public StorageCollection<DrawningTrans> addCollectionButtonAction(JFrame jFrameCollectionBoats, JTextField textFieldSetCollectionName, JRadioButton massiveRadioButton, JRadioButton listRadioButton) {
|
||||
|
||||
if (textFieldSetCollectionName.getText().isEmpty() || (!massiveRadioButton.isSelected() && !listRadioButton.isSelected())) {
|
||||
JOptionPane.showMessageDialog(jFrameCollectionBoats, "Не все элементы заполнены", "ERROR", JOptionPane.ERROR_MESSAGE);
|
||||
return null;
|
||||
}
|
||||
CollectionType collectionType = CollectionType.None;
|
||||
if (massiveRadioButton.isSelected()) collectionType = CollectionType.Massive;
|
||||
else if (listRadioButton.isSelected()) collectionType = CollectionType.List;
|
||||
storageCollection.addCollection(textFieldSetCollectionName.getText(), collectionType);
|
||||
return storageCollection;
|
||||
}
|
||||
|
||||
public StorageCollection<DrawningTrans> deleteCollectionButtonAction(JFrame jFrameCollectionLocomotive, JList<String> keysList) {
|
||||
if (keysList.getSelectedIndex() != -1) {
|
||||
int result = JOptionPane.showConfirmDialog(jFrameCollectionLocomotive, "Удалить объект?", "Подтверждение", JOptionPane.YES_NO_OPTION);
|
||||
if (result == JOptionPane.YES_OPTION) {
|
||||
storageCollection.delCollection(keysList.getSelectedValue());
|
||||
return storageCollection;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (_company == null) {
|
||||
return;
|
||||
}
|
||||
_company.show(g);
|
||||
}
|
||||
}
|
84
ProjectElectroTrans/src/Drawnings/DrawningConstructor.java
Normal file
@ -0,0 +1,84 @@
|
||||
package Drawnings;
|
||||
|
||||
import CollectionGenericObjects.Constructor;
|
||||
import Entities.EntityTrans;
|
||||
import Entities.EntityElectroTrans;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawningConstructor extends JComponent {
|
||||
|
||||
Constructor<EntityTrans, IDrawWheels> constructor = new Constructor<>();
|
||||
private DrawningTrans obj;
|
||||
|
||||
public DrawningTrans getObj() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
public DrawningConstructor() {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
EntityTrans _entityBoat = null;
|
||||
IDrawWheels _drawWheels = null;
|
||||
Random rnd = new Random();
|
||||
int wheelsType = rnd.nextInt(3);
|
||||
switch (wheelsType) {
|
||||
case 0:
|
||||
_drawWheels = new DrawningWheels();
|
||||
break;
|
||||
case 1:
|
||||
_drawWheels = new DrawningRectWheels();
|
||||
break;
|
||||
case 2:
|
||||
_drawWheels = new DrawningRectangleWheels();
|
||||
break;
|
||||
}
|
||||
int wheelsCount = rnd.nextInt(1, 4);
|
||||
_drawWheels.setNumber(wheelsCount);
|
||||
|
||||
int typeBoat = rnd.nextInt(0, 2);
|
||||
|
||||
switch (typeBoat) {
|
||||
case 0:
|
||||
_entityBoat = new EntityTrans(rnd.nextInt(70 - 30) + 30, rnd.nextInt(500 - 100) + 100,
|
||||
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)));
|
||||
break;
|
||||
case 1:
|
||||
_entityBoat = new EntityElectroTrans(rnd.nextInt(70 - 30) + 30, rnd.nextInt(500 - 100) + 100,
|
||||
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
|
||||
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
|
||||
rnd.nextBoolean(), rnd.nextBoolean());
|
||||
break;
|
||||
}
|
||||
constructor.addTrans(_entityBoat);
|
||||
constructor.addTrans(_drawWheels);
|
||||
}
|
||||
obj = constructor.getRandomTrans();
|
||||
|
||||
}
|
||||
|
||||
public void reCreateObj() {
|
||||
obj = constructor.getRandomTrans();
|
||||
}
|
||||
|
||||
public String getEntityString(int index) {
|
||||
return constructor.getEntityDescription(index);
|
||||
}
|
||||
|
||||
public String getWheelsString(int index) {
|
||||
return constructor.getPaddlesDescription(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (obj != null) {
|
||||
obj.setPosition(10, 30);
|
||||
obj.setPictureSize(400, 300);
|
||||
obj.drawTrans(g);
|
||||
}
|
||||
super.repaint();
|
||||
|
||||
}
|
||||
}
|
91
ProjectElectroTrans/src/Drawnings/DrawningElectroTrans.java
Normal file
@ -0,0 +1,91 @@
|
||||
package Drawnings;
|
||||
|
||||
import Entities.EntityElectroTrans;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningElectroTrans extends DrawningTrans {
|
||||
public DrawningElectroTrans(int speed, float weight, Color bodyColor, int wheelsType, Color additionalColor, boolean sail, boolean floaters) {
|
||||
super(speed, weight, bodyColor, wheelsType, 110, 80);
|
||||
entityTrans = new EntityElectroTrans(speed, weight, bodyColor, additionalColor, floaters, sail);
|
||||
}
|
||||
public DrawningElectroTrans(EntityElectroTrans entity, IDrawWheels wheels) {
|
||||
super(entity, wheels);
|
||||
}
|
||||
private void drawFloater(int y0, Color additionalColor, Graphics2D g2d)
|
||||
{
|
||||
g2d.setColor(additionalColor);
|
||||
g2d.setStroke(new BasicStroke(2));
|
||||
Point[] floater = new Point[]
|
||||
{
|
||||
new Point(_startPosX + 10, _startPosY + y0 + 6),
|
||||
new Point(_startPosX + 90, _startPosY + y0 + 6),
|
||||
new Point(_startPosX + 110, _startPosY + y0 + 3),
|
||||
new Point(_startPosX + 90, _startPosY + y0),
|
||||
new Point(_startPosX + 10, _startPosY + y0),
|
||||
|
||||
};
|
||||
Polygon floaterPolygon = new Polygon();
|
||||
for (Point point: floater) {
|
||||
floaterPolygon.addPoint(point.x, point.y);
|
||||
}
|
||||
g2d.fillPolygon(floaterPolygon);
|
||||
g2d.drawPolygon(floaterPolygon);
|
||||
}
|
||||
@Override
|
||||
public void drawTrans(Graphics g) {
|
||||
|
||||
if (entityTrans == null || !(entityTrans instanceof EntityElectroTrans entityElectroTrans) || _startPosX == null || _startPosY == null) {
|
||||
return;
|
||||
}
|
||||
super.drawTrans(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
|
||||
|
||||
Point[] electroTransHorns;
|
||||
if (entityElectroTrans.getHorns()) {
|
||||
electroTransHorns = new Point[]{
|
||||
new Point(_startPosX + 40, _startPosY + 10),
|
||||
new Point(_startPosX + 20, _startPosY),
|
||||
new Point(_startPosX + 60, _startPosY),
|
||||
|
||||
};
|
||||
} else {
|
||||
electroTransHorns = new Point[]{
|
||||
new Point(_startPosX + 40, _startPosY + 7),
|
||||
new Point(_startPosX + 20, _startPosY + 7),
|
||||
new Point(_startPosX + 60, _startPosY + 7),
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
Polygon electroTransHornsPolygon = new Polygon();
|
||||
for (Point point : electroTransHorns)
|
||||
electroTransHornsPolygon.addPoint(point.x, point.y);
|
||||
|
||||
g2d.setColor(entityElectroTrans.getAdditionalColor());
|
||||
g2d.drawPolygon(electroTransHornsPolygon);
|
||||
|
||||
|
||||
if (entityElectroTrans.getBattery()) {
|
||||
Point[] electroTransBattery = new Point[]{
|
||||
new Point(_startPosX + 25, _startPosY + 32),
|
||||
new Point(_startPosX + 25, _startPosY + 36),
|
||||
new Point(_startPosX + 22, _startPosY + 36),
|
||||
new Point(_startPosX + 22, _startPosY + 40),
|
||||
new Point(_startPosX + 25, _startPosY + 40),
|
||||
new Point(_startPosX + 25, _startPosY + 46),
|
||||
new Point(_startPosX + 58, _startPosY + 46),
|
||||
new Point(_startPosX + 58, _startPosY + 32),
|
||||
|
||||
};
|
||||
Polygon electroTransBatteryPolygon = new Polygon();
|
||||
for (Point point : electroTransBattery)
|
||||
electroTransBatteryPolygon.addPoint(point.x, point.y);
|
||||
|
||||
g2d.setColor(entityElectroTrans.getAdditionalColor());
|
||||
g2d.fillPolygon(electroTransBatteryPolygon);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
71
ProjectElectroTrans/src/Drawnings/DrawningFormCatamaran.java
Normal file
@ -0,0 +1,71 @@
|
||||
package Drawnings;
|
||||
|
||||
import MovementStrategy.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningFormCatamaran extends JComponent {
|
||||
DrawningTrans drawningTrans;
|
||||
|
||||
private int _pictureHeight = -1;
|
||||
private int _pictureWidth = -1;
|
||||
private AbstractStrategy _strategy;
|
||||
public void setDrawningTrans(DrawningTrans drawningTrans) {
|
||||
this.drawningTrans = drawningTrans;
|
||||
}
|
||||
|
||||
public boolean setPictureSize(int width, int height) {
|
||||
if (drawningTrans.GetHeight() > height || drawningTrans.GetWidth() > width)
|
||||
return false;
|
||||
_pictureHeight = height;
|
||||
_pictureWidth = width;
|
||||
return true;
|
||||
}
|
||||
public void buttonStrategyStep(JComboBox<String> comboBox) {
|
||||
if (drawningTrans == null)
|
||||
return;
|
||||
if (comboBox.isEnabled()) {
|
||||
switch (comboBox.getSelectedIndex()) {
|
||||
case 0:
|
||||
_strategy = new MoveToCenter();
|
||||
break;
|
||||
case 1:
|
||||
_strategy = new MoveToBorder();
|
||||
break;
|
||||
|
||||
default:
|
||||
_strategy = null;
|
||||
break;
|
||||
|
||||
}
|
||||
if (_strategy == null) {
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveableTrans(drawningTrans), _pictureWidth, _pictureHeight);
|
||||
}
|
||||
if (_strategy == null) {
|
||||
return;
|
||||
}
|
||||
comboBox.setEnabled(false);
|
||||
_strategy.MakeStep();
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish) {
|
||||
comboBox.setEnabled(true);
|
||||
_strategy = null;
|
||||
}
|
||||
|
||||
}
|
||||
public void MoveButtonsAction(MovementDirection direction) {
|
||||
if (drawningTrans == null)
|
||||
return;
|
||||
drawningTrans.moveTransport(direction);
|
||||
}
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (drawningTrans == null) {
|
||||
return;
|
||||
}
|
||||
drawningTrans.drawTrans(g);
|
||||
}
|
||||
}
|
32
ProjectElectroTrans/src/Drawnings/DrawningRectWheels.java
Normal file
@ -0,0 +1,32 @@
|
||||
package Drawnings;
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningRectWheels implements IDrawWheels {
|
||||
private WheelsCount _wheelsCount = WheelsCount.Two;
|
||||
|
||||
@Override
|
||||
public void setNumber(int wheelsCount) {
|
||||
for (WheelsCount value : WheelsCount.values()) {
|
||||
if (value.getEnumNumber() == wheelsCount) {
|
||||
_wheelsCount = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void drawWheels(Graphics2D g2d, Color color, int _startX, int _startY) {
|
||||
g2d.setColor(color);
|
||||
g2d.setStroke(new BasicStroke(4));
|
||||
int wheelDistance = 100 / _wheelsCount.getEnumNumber();
|
||||
for (int i = 0; i < _wheelsCount.getEnumNumber(); i++) {
|
||||
g2d.drawRect(_startX + 5 + i * wheelDistance, _startY + 46, 8, 8);
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
String buffer = "";
|
||||
buffer += "Тип: квадратные, Количество колес: " + _wheelsCount.getEnumNumber() * 2;
|
||||
return buffer;
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package Drawnings;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningRectangleWheels implements IDrawWheels {
|
||||
private WheelsCount _wheelsCount;
|
||||
|
||||
@Override
|
||||
public void setNumber(int wheelsCount) {
|
||||
for (WheelsCount value : WheelsCount.values()) {
|
||||
if (value.getEnumNumber() == wheelsCount) {
|
||||
_wheelsCount = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
_wheelsCount = WheelsCount.Two;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawWheels(Graphics2D g2d, Color color, int _startX, int _startY) {
|
||||
g2d.setColor(color);
|
||||
g2d.setStroke(new BasicStroke(4));
|
||||
int wheelDistance = 100 / _wheelsCount.getEnumNumber();
|
||||
for (int i = 0; i < _wheelsCount.getEnumNumber(); i++) {
|
||||
g2d.drawLine(_startX + 5 + i * wheelDistance - 4, (int) _startY + 44, _startX + 5 + i * wheelDistance + 4, (int) _startY + 44);
|
||||
g2d.drawLine(_startX + 5 + i * wheelDistance + 4, (int) _startY + 44, _startX + 5 + i * wheelDistance, (int) _startY + 48);
|
||||
g2d.drawLine(_startX + 5 + i * wheelDistance, (int) _startY + 48, _startX + 5 + i * wheelDistance - 4, (int) _startY + 44);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
String buffer = "";
|
||||
buffer += "Тип: прямоугольники, Количество колес: " + _wheelsCount.getEnumNumber() * 2;
|
||||
return buffer;
|
||||
}
|
||||
}
|
177
ProjectElectroTrans/src/Drawnings/DrawningTrans.java
Normal file
@ -0,0 +1,177 @@
|
||||
package Drawnings;
|
||||
|
||||
import Entities.EntityTrans;
|
||||
import MovementStrategy.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawningTrans {
|
||||
public EntityTrans entityTrans;
|
||||
|
||||
public EntityTrans getEntityTrans() {
|
||||
return entityTrans;
|
||||
}
|
||||
|
||||
private Integer _pictureWidth;
|
||||
private Integer _pictureHeight;
|
||||
protected Integer _startPosX;
|
||||
protected Integer _startPosY;
|
||||
private int _drawingBoatWidth = 107;
|
||||
private int _drawingBoatHeight = 80;
|
||||
|
||||
public Integer GetPosX() {
|
||||
return _startPosX;
|
||||
}
|
||||
|
||||
public Integer GetPosY() {
|
||||
return _startPosY;
|
||||
}
|
||||
|
||||
public int GetWidth() {
|
||||
return _drawingBoatWidth;
|
||||
}
|
||||
|
||||
public int GetHeight() {
|
||||
return _drawingBoatHeight;
|
||||
}
|
||||
|
||||
protected IDrawWheels drawWheels;
|
||||
|
||||
public IDrawWheels getDrawWheels() {
|
||||
return drawWheels;
|
||||
}
|
||||
|
||||
public void setDrawWheels(IDrawWheels drawWheels) {
|
||||
this.drawWheels = drawWheels;
|
||||
}
|
||||
|
||||
public DrawningTrans(int speed, float weight, Color bodyColor, int wheelsType) {
|
||||
entityTrans = new EntityTrans(speed, weight, bodyColor);
|
||||
_startPosY = null;
|
||||
_startPosX = null;
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
switch (wheelsType) {
|
||||
case 0:
|
||||
drawWheels = new DrawningWheels();
|
||||
break;
|
||||
case 1:
|
||||
drawWheels = new DrawningRectWheels();
|
||||
break;
|
||||
case 2:
|
||||
drawWheels = new DrawningRectangleWheels();
|
||||
break;
|
||||
}
|
||||
Random random = new Random();
|
||||
int wheelsCount = random.nextInt(2, 4);
|
||||
drawWheels.setNumber(wheelsCount);
|
||||
|
||||
}
|
||||
|
||||
protected DrawningTrans(int speed, float weight, Color bodyColor, int wheelsType, int boatWidth, int boatHeight) {
|
||||
this(speed, weight, bodyColor, wheelsType);
|
||||
_drawingBoatHeight = boatHeight;
|
||||
_drawingBoatWidth = boatWidth;
|
||||
|
||||
}
|
||||
|
||||
public DrawningTrans(EntityTrans _entityBoat, IDrawWheels _drawWheels) {
|
||||
entityTrans = _entityBoat;
|
||||
drawWheels = _drawWheels;
|
||||
}
|
||||
|
||||
public void setPosition(int x, int y) {
|
||||
if (_pictureHeight == null || _pictureWidth == null)
|
||||
return;
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
|
||||
if (_drawingBoatWidth + x > _pictureWidth || x < 0) {
|
||||
_startPosX = 0;
|
||||
}
|
||||
if (_drawingBoatHeight + y > _pictureHeight || y < 0) {
|
||||
_startPosY = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean setPictureSize(int width, int height) {
|
||||
|
||||
if (_drawingBoatHeight > height || _drawingBoatWidth > width)
|
||||
return false;
|
||||
_pictureHeight = height;
|
||||
_pictureWidth = width;
|
||||
|
||||
if (_startPosX != null && _startPosY != null) {
|
||||
if (_startPosX + _drawingBoatWidth > width)
|
||||
_startPosX = width - _drawingBoatWidth;
|
||||
if (_startPosY + _drawingBoatHeight > height)
|
||||
_startPosY = height - _drawingBoatHeight;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean moveTransport(MovementDirection direction) {
|
||||
if (entityTrans == null || _pictureWidth == null || _pictureHeight == null)
|
||||
return false;
|
||||
switch (direction) {
|
||||
case MovementDirection.Left:
|
||||
if (_startPosX - entityTrans.getStep() > 0)
|
||||
_startPosX -= (int) entityTrans.getStep();
|
||||
return true;
|
||||
case MovementDirection.Up:
|
||||
if (_startPosY - entityTrans.getStep() > 0)
|
||||
_startPosY -= (int) entityTrans.getStep();
|
||||
return true;
|
||||
case MovementDirection.Right:
|
||||
if (_startPosX + entityTrans.getStep() < _pictureWidth - _drawingBoatWidth)
|
||||
_startPosX += (int) entityTrans.getStep();
|
||||
return true;
|
||||
case MovementDirection.Down:
|
||||
if (_startPosY + entityTrans.getStep() < _pictureHeight - _drawingBoatHeight)
|
||||
_startPosY += (int) entityTrans.getStep();
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void drawTrans(Graphics g) {
|
||||
if (entityTrans == null || _startPosX == null || _startPosY == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
|
||||
Point[] electroTransBorders = new Point[]{
|
||||
new Point(_startPosX, _startPosY + 30),
|
||||
new Point(_startPosX + 10, _startPosY + 10),
|
||||
new Point(_startPosX + 70, _startPosY + 10),
|
||||
new Point(_startPosX + 80, _startPosY + 30),
|
||||
new Point(_startPosX + 80, _startPosY + 50),
|
||||
new Point(_startPosX, _startPosY + 50),
|
||||
};
|
||||
Polygon electroTransPolygon = new Polygon();
|
||||
for (Point point : electroTransBorders)
|
||||
electroTransPolygon.addPoint(point.x, point.y);
|
||||
|
||||
g2d.setColor(entityTrans.getBodyColor());
|
||||
g2d.drawPolygon(electroTransPolygon);
|
||||
|
||||
Point[] electroTransGlass = new Point[]{
|
||||
new Point(_startPosX + 2, _startPosY + 30),
|
||||
new Point(_startPosX + 10, _startPosY + 13),
|
||||
new Point(_startPosX + 70, _startPosY + 13),
|
||||
new Point(_startPosX + 78, _startPosY + 30),
|
||||
};
|
||||
|
||||
Polygon electroTransGlassPolygon = new Polygon();
|
||||
for (Point point : electroTransGlass)
|
||||
electroTransGlassPolygon.addPoint(point.x, point.y);
|
||||
|
||||
g2d.setColor(entityTrans.getBodyColor());
|
||||
g2d.drawPolygon(electroTransGlassPolygon);
|
||||
|
||||
drawWheels.drawWheels(g2d, entityTrans.getBodyColor(), _startPosX, _startPosY);
|
||||
}
|
||||
}
|
20
ProjectElectroTrans/src/Drawnings/DrawningTransConfig.java
Normal file
@ -0,0 +1,20 @@
|
||||
package Drawnings;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningTransConfig extends JComponent{
|
||||
public DrawningTrans trans = null;
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
if (trans == null) {
|
||||
return;
|
||||
}
|
||||
super.paintComponent(g);
|
||||
trans.setPosition(10, 10);
|
||||
trans.setPictureSize(200, 200);
|
||||
trans.drawTrans(g);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
31
ProjectElectroTrans/src/Drawnings/DrawningWheels.java
Normal file
@ -0,0 +1,31 @@
|
||||
package Drawnings;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningWheels implements IDrawWheels {
|
||||
private WheelsCount _wheelsCount;
|
||||
@Override
|
||||
public void setNumber(int wheelsCount) {
|
||||
for (WheelsCount value : WheelsCount.values()) {
|
||||
if (value.getEnumNumber() == wheelsCount) {
|
||||
_wheelsCount = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void drawWheels(Graphics2D g2d, Color color, int _startX, int _startY) {
|
||||
g2d.setColor(color);
|
||||
g2d.setStroke(new BasicStroke(4));
|
||||
int wheelDistance = 100 / _wheelsCount.getEnumNumber();
|
||||
for (int i = 0; i < _wheelsCount.getEnumNumber(); i++) {
|
||||
g2d.drawOval(_startX + 5 + i * wheelDistance, _startY + 46, 8, 8);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
String buffer = "";
|
||||
buffer += "Тип: обычные, Количество колес: " + _wheelsCount.getEnumNumber() * 2;
|
||||
return buffer;
|
||||
}
|
||||
}
|
8
ProjectElectroTrans/src/Drawnings/IDrawWheels.java
Normal file
@ -0,0 +1,8 @@
|
||||
package Drawnings;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawWheels {
|
||||
void setNumber(int x);
|
||||
void drawWheels(Graphics2D graphics2D, Color color, int _startX, int _startY);
|
||||
}
|
15
ProjectElectroTrans/src/Drawnings/WheelsCount.java
Normal file
@ -0,0 +1,15 @@
|
||||
package Drawnings;
|
||||
|
||||
public enum WheelsCount {
|
||||
Two(2),
|
||||
Three(3),
|
||||
Four(4);
|
||||
|
||||
final private int EnumNumber;
|
||||
WheelsCount(int enumNumber) {
|
||||
EnumNumber = enumNumber;
|
||||
}
|
||||
public int getEnumNumber() {
|
||||
return EnumNumber;
|
||||
}
|
||||
}
|
42
ProjectElectroTrans/src/Entities/EntityElectroTrans.java
Normal file
@ -0,0 +1,42 @@
|
||||
package Entities;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityElectroTrans extends EntityTrans {
|
||||
private Color AdditionalColor;
|
||||
public void setAdditionalColor(Color additionalColor) {
|
||||
AdditionalColor = additionalColor;
|
||||
}
|
||||
public Color getAdditionalColor() {
|
||||
return AdditionalColor;
|
||||
}
|
||||
private boolean Horns;
|
||||
public void setHorns(boolean horns) {
|
||||
Horns = horns;
|
||||
}
|
||||
public boolean getHorns() {
|
||||
return Horns;
|
||||
}
|
||||
private boolean Battery;
|
||||
public void setBattery(boolean battery) {
|
||||
Battery = battery;
|
||||
}
|
||||
public boolean getBattery() {
|
||||
return Battery;
|
||||
}
|
||||
public EntityElectroTrans(int speed, double weight, Color bodyColor ,Color additionalColor, boolean sail, boolean floaters) {
|
||||
super(speed, weight, bodyColor);
|
||||
AdditionalColor = additionalColor;
|
||||
Horns = sail;
|
||||
Battery = floaters;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
String buffer = super.toString();
|
||||
buffer += String.format(", Дополнительный цвет : RGB{%d, %d, %d}",
|
||||
this.AdditionalColor.getRed(), this.AdditionalColor.getGreen(), this.AdditionalColor.getBlue());
|
||||
buffer += ", Рога: " + this.Horns;
|
||||
buffer += ", Батарея: " + this.Battery;
|
||||
return buffer;
|
||||
}
|
||||
}
|
57
ProjectElectroTrans/src/Entities/EntityTrans.java
Normal file
@ -0,0 +1,57 @@
|
||||
package Entities;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityTrans {
|
||||
private int Speed;
|
||||
|
||||
public int getSpeed() {
|
||||
return Speed;
|
||||
}
|
||||
|
||||
public void setSpeed(int speed) {
|
||||
Speed = speed;
|
||||
}
|
||||
|
||||
private double Weight;
|
||||
|
||||
public void setWeight(double weight) {
|
||||
Weight = weight;
|
||||
}
|
||||
|
||||
public double getWeight() {
|
||||
return Weight;
|
||||
}
|
||||
|
||||
private Color BodyColor;
|
||||
|
||||
public void setBodyColor(Color bodyColor) {
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
|
||||
public Color getBodyColor() {
|
||||
return BodyColor;
|
||||
}
|
||||
|
||||
private double Step;
|
||||
|
||||
public double getStep() {
|
||||
return Speed * 100 / Weight;
|
||||
}
|
||||
|
||||
public EntityTrans(int speed, double weight, Color bodyColor) {
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String buffer = "";
|
||||
buffer += "Скорость: " + this.Speed;
|
||||
buffer += ", Вес: " + this.Weight;
|
||||
buffer += String.format(", Основной цвет : RGB{%d, %d, %d}",
|
||||
this.BodyColor.getRed(), this.BodyColor.getGreen(), this.BodyColor.getBlue());
|
||||
return buffer;
|
||||
}
|
||||
}
|
92
ProjectElectroTrans/src/Forms/FormConstructor.java
Normal file
@ -0,0 +1,92 @@
|
||||
package Forms;
|
||||
|
||||
import Drawnings.DrawningConstructor;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
|
||||
public class FormConstructor extends JFrame {
|
||||
private JFrame jFrameConstructor = new JFrame();
|
||||
public JFrame getjFrameConstructor() {
|
||||
return jFrameConstructor;
|
||||
}
|
||||
private JButton addButton = new JButton("Добавить объект");
|
||||
public JButton getAddButton() {
|
||||
return addButton;
|
||||
}
|
||||
public JButton reCreateButton = new JButton("Пересоздать");
|
||||
private final DrawningConstructor constructor = new DrawningConstructor();
|
||||
public DrawningConstructor getConstructor() {
|
||||
return constructor;
|
||||
}
|
||||
JPanel entitiesInfoPanel = new JPanel();
|
||||
JLabel firstEntityLabel = new JLabel();
|
||||
JLabel secondEntityLabel = new JLabel();
|
||||
JLabel thirdEntityLabel = new JLabel();
|
||||
|
||||
JPanel wheelsInfoPanel = new JPanel();
|
||||
JLabel firstPaddlesLabel = new JLabel();
|
||||
JLabel secondPaddlesLabel = new JLabel();
|
||||
JLabel thirdPaddlesLabel = new JLabel();
|
||||
|
||||
public void OpenFrame() {
|
||||
|
||||
Toolkit tolls = Toolkit.getDefaultToolkit();
|
||||
Dimension dimension = tolls.getScreenSize();
|
||||
jFrameConstructor.setBounds(dimension.width / 2 - 250, dimension.height / 2 - 250,
|
||||
800, 300);
|
||||
jFrameConstructor.setLayout(new BorderLayout());
|
||||
|
||||
firstEntityLabel.setText(constructor.getEntityString(0));
|
||||
secondEntityLabel.setText(constructor.getEntityString(1));
|
||||
thirdEntityLabel.setText(constructor.getEntityString(2));
|
||||
|
||||
entitiesInfoPanel.setLayout(new BoxLayout(entitiesInfoPanel, BoxLayout.Y_AXIS));
|
||||
entitiesInfoPanel.setBorder(BorderFactory.createTitledBorder("Entities"));
|
||||
entitiesInfoPanel.setSize(500, 130);
|
||||
entitiesInfoPanel.setLocation(150, 10);
|
||||
entitiesInfoPanel.add(firstEntityLabel);
|
||||
entitiesInfoPanel.add(secondEntityLabel);
|
||||
entitiesInfoPanel.add(thirdEntityLabel);
|
||||
|
||||
firstPaddlesLabel.setText(constructor.getWheelsString(0));
|
||||
secondPaddlesLabel.setText(constructor.getWheelsString(1));
|
||||
thirdPaddlesLabel.setText(constructor.getWheelsString(2));
|
||||
|
||||
|
||||
wheelsInfoPanel.setLayout(new BoxLayout(wheelsInfoPanel, BoxLayout.Y_AXIS));
|
||||
wheelsInfoPanel.setBorder(BorderFactory.createTitledBorder("Wheels"));
|
||||
wheelsInfoPanel.setSize(500, 130);
|
||||
wheelsInfoPanel.setLocation(150, 150);
|
||||
wheelsInfoPanel.add(firstPaddlesLabel);
|
||||
wheelsInfoPanel.add(secondPaddlesLabel);
|
||||
wheelsInfoPanel.add(thirdPaddlesLabel);
|
||||
|
||||
addButton.setBounds(0, jFrameConstructor.getHeight() - 105, 150, 50);
|
||||
reCreateButton.setBounds(0, jFrameConstructor.getHeight() - 135, 150, 30);
|
||||
|
||||
jFrameConstructor.add(wheelsInfoPanel);
|
||||
jFrameConstructor.add(entitiesInfoPanel);
|
||||
jFrameConstructor.add(addButton);
|
||||
jFrameConstructor.add(reCreateButton);
|
||||
jFrameConstructor.add(constructor);
|
||||
jFrameConstructor.revalidate();
|
||||
jFrameConstructor.repaint();
|
||||
|
||||
jFrameConstructor.addComponentListener(new ComponentAdapter() {
|
||||
public void componentResized(ComponentEvent componentEvent) {
|
||||
addButton.setLocation(0, jFrameConstructor.getSize().height - 105);
|
||||
reCreateButton.setLocation(0, jFrameConstructor.getSize().height - 135);
|
||||
}
|
||||
});
|
||||
reCreateButton.addActionListener(e -> {
|
||||
constructor.reCreateObj();
|
||||
jFrameConstructor.repaint();
|
||||
});
|
||||
|
||||
jFrameConstructor.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
113
ProjectElectroTrans/src/Forms/FormElectroTrans.java
Normal file
@ -0,0 +1,113 @@
|
||||
package Forms;
|
||||
|
||||
import Drawnings.*;
|
||||
import MovementStrategy.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
|
||||
|
||||
public class FormElectroTrans extends JFrame {
|
||||
final private JFrame JFrameElectroTrans = new JFrame();
|
||||
final private JButton buttonRight = new JButton(new ImageIcon("ProjectElectroTrans\\Resources\\30px_arrow_right.png"));
|
||||
final private JPanel RightPanel = new JPanel();
|
||||
final private JButton buttonDown = new JButton(new ImageIcon("ProjectElectroTrans\\Resources\\30px_arrow_down.png"));
|
||||
final private JPanel DownPanel = new JPanel();
|
||||
final private JButton buttonLeft = new JButton(new ImageIcon("ProjectElectroTrans\\Resources\\30px_arrow_left.png"));
|
||||
final private JPanel LeftPanel = new JPanel();
|
||||
final private JButton buttonUp = new JButton(new ImageIcon("ProjectElectroTrans\\Resources\\30px_arrow_up.png"));
|
||||
|
||||
final private JPanel UpPanel = new JPanel();
|
||||
final private String [] itemsComboBox = {
|
||||
"К центру",
|
||||
"К краю"
|
||||
};
|
||||
final private JComboBox<String> comboBoxStrategy =new JComboBox<>(itemsComboBox);
|
||||
final private JButton buttonStrategyStep = new JButton("Шаг");
|
||||
final private JPanel StrategyPanel = new JPanel(new BorderLayout());
|
||||
|
||||
final private DrawningFormCatamaran form = new DrawningFormCatamaran();
|
||||
public void setDrawningTrans(DrawningTrans boat) {form.setDrawningTrans(boat);}
|
||||
public void OpenFrame() {
|
||||
JFrameElectroTrans.setVisible(true);
|
||||
Toolkit tolls = Toolkit.getDefaultToolkit();
|
||||
Dimension dimension = tolls.getScreenSize();
|
||||
JFrameElectroTrans.setBounds(dimension.width / 2 - 250, dimension.height / 2 - 250,
|
||||
970, 700);
|
||||
JFrameElectroTrans.setTitle("Электропоезд");
|
||||
|
||||
comboBoxStrategy.setPreferredSize(new Dimension(100, 35));
|
||||
buttonStrategyStep.setPreferredSize(new Dimension(100, 35));
|
||||
StrategyPanel.setSize(100, 70);
|
||||
StrategyPanel.add(comboBoxStrategy, BorderLayout.NORTH);
|
||||
StrategyPanel.add(buttonStrategyStep, BorderLayout.SOUTH);
|
||||
|
||||
|
||||
UpPanel.setSize(30, 30);
|
||||
buttonUp.setPreferredSize(new Dimension(30, 30));
|
||||
UpPanel.add(buttonUp, BorderLayout.CENTER);
|
||||
|
||||
DownPanel.setSize(30, 30);
|
||||
buttonDown.setPreferredSize(new Dimension(30, 30));
|
||||
DownPanel.add(buttonDown, BorderLayout.CENTER);
|
||||
|
||||
RightPanel.setSize(30, 30);
|
||||
buttonRight.setPreferredSize(new Dimension(30, 30));
|
||||
RightPanel.add(buttonRight, BorderLayout.CENTER);
|
||||
|
||||
LeftPanel.setSize(30, 30);
|
||||
buttonLeft.setPreferredSize(new Dimension(30, 30));
|
||||
LeftPanel.add(buttonLeft, BorderLayout.CENTER);
|
||||
|
||||
JFrameElectroTrans.add(StrategyPanel);
|
||||
JFrameElectroTrans.add(UpPanel);
|
||||
JFrameElectroTrans.add(DownPanel);
|
||||
JFrameElectroTrans.add(RightPanel);
|
||||
JFrameElectroTrans.add(LeftPanel);
|
||||
JFrameElectroTrans.add(form);
|
||||
|
||||
JFrameElectroTrans.addComponentListener(new ComponentAdapter() {
|
||||
public void componentResized(ComponentEvent e) {
|
||||
StrategyPanel.setLocation(JFrameElectroTrans.getWidth() - 100, 0);
|
||||
UpPanel.setLocation(JFrameElectroTrans.getWidth() - 80, JFrameElectroTrans.getHeight()-100);
|
||||
DownPanel.setLocation(JFrameElectroTrans.getWidth() - 80, JFrameElectroTrans.getHeight()-70);
|
||||
RightPanel.setLocation(JFrameElectroTrans.getWidth() - 45, JFrameElectroTrans.getHeight()-70);
|
||||
LeftPanel.setLocation(JFrameElectroTrans.getWidth() - 115, JFrameElectroTrans.getHeight()-70);
|
||||
|
||||
form.setPictureSize(JFrameElectroTrans.getWidth(), JFrameElectroTrans.getHeight());
|
||||
JFrameElectroTrans.repaint();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
buttonUp.addActionListener(e -> {
|
||||
form.setPictureSize(JFrameElectroTrans.getWidth(), JFrameElectroTrans.getHeight());
|
||||
form.MoveButtonsAction(MovementDirection.Up);
|
||||
JFrameElectroTrans.repaint();
|
||||
});
|
||||
|
||||
buttonDown.addActionListener(e -> {
|
||||
form.setPictureSize(JFrameElectroTrans.getWidth(), JFrameElectroTrans.getHeight());
|
||||
form.MoveButtonsAction(MovementDirection.Down);
|
||||
JFrameElectroTrans.repaint();
|
||||
});
|
||||
buttonLeft.addActionListener(e -> {
|
||||
form.setPictureSize(JFrameElectroTrans.getWidth(), JFrameElectroTrans.getHeight());
|
||||
form.MoveButtonsAction(MovementDirection.Left);
|
||||
JFrameElectroTrans.repaint();
|
||||
});
|
||||
buttonRight.addActionListener(e -> {
|
||||
form.setPictureSize(JFrameElectroTrans.getWidth(), JFrameElectroTrans.getHeight());
|
||||
form.MoveButtonsAction(MovementDirection.Right);
|
||||
JFrameElectroTrans.repaint();
|
||||
});
|
||||
buttonStrategyStep.addActionListener(e -> {
|
||||
form.setPictureSize(JFrameElectroTrans.getWidth(), JFrameElectroTrans.getHeight());
|
||||
form.buttonStrategyStep(comboBoxStrategy);
|
||||
JFrameElectroTrans.repaint();
|
||||
});
|
||||
|
||||
}
|
||||
}
|
280
ProjectElectroTrans/src/Forms/FormTransCollection.java
Normal file
@ -0,0 +1,280 @@
|
||||
package Forms;
|
||||
|
||||
import CollectionGenericObjects.StorageCollection;
|
||||
import Drawnings.DrawningAbstractCompany;
|
||||
import Drawnings.DrawningTrans;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.NumberFormatter;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class FormTransCollection extends JFrame {
|
||||
final private JFrame jFrameCollectionTranss = new JFrame();
|
||||
final private DrawningAbstractCompany _company = new DrawningAbstractCompany();
|
||||
final private JButton refreshButton = new JButton("Обновить");
|
||||
final private JPanel refreshPanel = new JPanel();
|
||||
final private String[] listOfComboBox = {
|
||||
|
||||
"",
|
||||
"Хранилище"
|
||||
};
|
||||
final private JComboBox<String> comboBoxSelectorCompany = new JComboBox<>(listOfComboBox);
|
||||
final private JPanel comboBoxPanel = new JPanel();
|
||||
final private JPanel toolsPanel = new JPanel();
|
||||
final private JLabel toolsNameLabel = new JLabel("Инструменты");
|
||||
final private JPanel labelPanel = new JPanel();
|
||||
final private JButton buttonAddTrans = new JButton("Добавить поезд");
|
||||
final private JPanel addTransPanel = new JPanel();
|
||||
final private JButton buttonRemove = new JButton("Удалить поезд");
|
||||
final private JPanel removePanel = new JPanel();
|
||||
final private JButton goToCheckButton = new JButton("Отправит на тесты");
|
||||
final private JPanel goToCheckPanel = new JPanel();
|
||||
final private JPanel addFromConstructorPanel = new JPanel();
|
||||
final private JButton addFromConstructorButton = new JButton("Добавить из констркутора");
|
||||
|
||||
final JRadioButton massiveRadioButton = new JRadioButton("Массив");
|
||||
final JRadioButton listRadioButton = new JRadioButton("Лист");
|
||||
final JPanel radioButtonsPanel = new JPanel();
|
||||
|
||||
final JButton addCollectionButton = new JButton("Добавить коллекцию");
|
||||
final JPanel addCollectionPanel = new JPanel();
|
||||
|
||||
|
||||
final JButton createCompanyButton = new JButton("Создать компанию");
|
||||
final JPanel createCompanyPanel = new JPanel();
|
||||
|
||||
|
||||
final JButton deleteCollectionButton = new JButton("Удалить коллекцию");
|
||||
final JPanel deleteCollectionPanel = new JPanel();
|
||||
|
||||
DefaultListModel<String> listModel = new DefaultListModel<>();
|
||||
JList<String> collectionsList = new JList<>(listModel);
|
||||
final JPanel collectionsListPanel = new JPanel();
|
||||
|
||||
final JTextField setCollectionName = new JTextField();
|
||||
final JLabel setCollectionNameLabel = new JLabel("Название коллекции:");
|
||||
final JPanel setCollectionNamePanel = new JPanel();
|
||||
|
||||
final private ArrayList<Component> listOfDownPanel = new ArrayList<>();
|
||||
|
||||
final private JButton goGoToCheckFromRubbishBinButton = new JButton("<html><center>Отправить на тест<br> объект из мусорки</html>");
|
||||
final private JPanel goGoToCheckFromRubbishBinPanel = new JPanel();
|
||||
|
||||
public void OpenFrame() {
|
||||
|
||||
jFrameCollectionTranss.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
Toolkit tolls = Toolkit.getDefaultToolkit();
|
||||
Dimension dimension = tolls.getScreenSize();
|
||||
jFrameCollectionTranss.setBounds(dimension.width / 2 - 250, dimension.height / 2 - 250,
|
||||
1200, 665);
|
||||
jFrameCollectionTranss.setTitle("Коллекция поездов");
|
||||
|
||||
toolsPanel.setBackground(Color.BLACK);
|
||||
labelPanel.setSize(new Dimension(100, 20));
|
||||
labelPanel.add(toolsNameLabel);
|
||||
|
||||
comboBoxPanel.setLayout(new BorderLayout());
|
||||
comboBoxPanel.setSize(new Dimension(170, 25));
|
||||
comboBoxPanel.add(comboBoxSelectorCompany, BorderLayout.CENTER);
|
||||
|
||||
addTransPanel.setLayout(new BorderLayout());
|
||||
addTransPanel.setSize(170, 25);
|
||||
addTransPanel.add(buttonAddTrans, BorderLayout.CENTER);
|
||||
|
||||
removePanel.setLayout(new BorderLayout());
|
||||
removePanel.setSize(170, 25);
|
||||
removePanel.add(buttonRemove, BorderLayout.CENTER);
|
||||
|
||||
goToCheckPanel.setLayout(new BorderLayout());
|
||||
goToCheckPanel.setSize(170, 25);
|
||||
goToCheckPanel.add(goToCheckButton, BorderLayout.CENTER);
|
||||
|
||||
refreshPanel.setLayout(new BorderLayout());
|
||||
refreshPanel.setSize(170, 25);
|
||||
refreshPanel.add(refreshButton, BorderLayout.CENTER);
|
||||
|
||||
addFromConstructorPanel.setLayout(new BorderLayout());
|
||||
addFromConstructorPanel.setSize(170, 25);
|
||||
addFromConstructorPanel.add(addFromConstructorButton, BorderLayout.CENTER);
|
||||
|
||||
setCollectionNamePanel.setLayout(new BorderLayout());
|
||||
setCollectionNamePanel.setSize(170, 45);
|
||||
setCollectionNamePanel.add(setCollectionNameLabel, BorderLayout.NORTH);
|
||||
setCollectionNamePanel.add(setCollectionName, BorderLayout.SOUTH);
|
||||
|
||||
radioButtonsPanel.setLayout(new BorderLayout());
|
||||
radioButtonsPanel.setSize(170, 25);
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
group.add(massiveRadioButton);
|
||||
group.add(listRadioButton);
|
||||
radioButtonsPanel.add(massiveRadioButton, BorderLayout.WEST);
|
||||
radioButtonsPanel.add(listRadioButton, BorderLayout.EAST);
|
||||
|
||||
addCollectionPanel.setLayout(new BorderLayout());
|
||||
addCollectionPanel.setSize(170, 30);
|
||||
addCollectionPanel.add(addCollectionButton, BorderLayout.CENTER);
|
||||
|
||||
collectionsListPanel.setLayout(new BorderLayout());
|
||||
collectionsListPanel.setSize(170, 100);
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane(collectionsList);
|
||||
collectionsListPanel.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
deleteCollectionPanel.setLayout(new BorderLayout());
|
||||
deleteCollectionPanel.setSize(170, 30);
|
||||
deleteCollectionPanel.add(deleteCollectionButton, BorderLayout.CENTER);
|
||||
|
||||
createCompanyPanel.setLayout(new BorderLayout());
|
||||
createCompanyPanel.setSize(170, 30);
|
||||
createCompanyPanel.add(createCompanyButton, BorderLayout.CENTER);
|
||||
|
||||
goGoToCheckFromRubbishBinPanel.setLayout(new BorderLayout());
|
||||
goGoToCheckFromRubbishBinPanel.setSize(170, 50);
|
||||
goGoToCheckFromRubbishBinPanel.add(goGoToCheckFromRubbishBinButton, BorderLayout.CENTER);
|
||||
|
||||
NumberFormat format = NumberFormat.getInstance();
|
||||
NumberFormatter formatter = new NumberFormatter(format);
|
||||
formatter.setValueClass(Integer.class);
|
||||
formatter.setMinimum(0);
|
||||
formatter.setMaximum(100);
|
||||
formatter.setAllowsInvalid(true);
|
||||
formatter.setCommitsOnValidEdit(true);
|
||||
|
||||
JTextField textBoxPosition = new JFormattedTextField(formatter);
|
||||
JPanel textBoxPanel = new JPanel();
|
||||
textBoxPanel.setLayout(new BorderLayout());
|
||||
textBoxPanel.setSize(170, 25);
|
||||
textBoxPanel.add(textBoxPosition, BorderLayout.CENTER);
|
||||
|
||||
jFrameCollectionTranss.add(toolsPanel);
|
||||
jFrameCollectionTranss.add(labelPanel);
|
||||
jFrameCollectionTranss.add(setCollectionNamePanel);
|
||||
jFrameCollectionTranss.add(radioButtonsPanel);
|
||||
jFrameCollectionTranss.add(addCollectionPanel);
|
||||
jFrameCollectionTranss.add(collectionsListPanel);
|
||||
jFrameCollectionTranss.add(deleteCollectionPanel);
|
||||
jFrameCollectionTranss.add(comboBoxPanel);
|
||||
jFrameCollectionTranss.add(createCompanyPanel);
|
||||
jFrameCollectionTranss.add(addTransPanel);
|
||||
jFrameCollectionTranss.add(textBoxPanel);
|
||||
jFrameCollectionTranss.add(removePanel);
|
||||
jFrameCollectionTranss.add(goToCheckPanel);
|
||||
jFrameCollectionTranss.add(refreshPanel);
|
||||
jFrameCollectionTranss.add(addFromConstructorPanel);
|
||||
jFrameCollectionTranss.add(goGoToCheckFromRubbishBinPanel);
|
||||
jFrameCollectionTranss.add(_company);
|
||||
|
||||
listOfDownPanel.add(buttonAddTrans);
|
||||
listOfDownPanel.add(addFromConstructorButton);
|
||||
listOfDownPanel.add(textBoxPosition);
|
||||
listOfDownPanel.add(buttonRemove);
|
||||
listOfDownPanel.add(goToCheckButton);
|
||||
listOfDownPanel.add(goGoToCheckFromRubbishBinButton);
|
||||
listOfDownPanel.add(refreshButton);
|
||||
|
||||
setEnableComponentsOfList(listOfDownPanel, false);
|
||||
jFrameCollectionTranss.addComponentListener(new ComponentAdapter() {
|
||||
public void componentResized(ComponentEvent componentEvent) {
|
||||
|
||||
labelPanel.setLocation(jFrameCollectionTranss.getWidth() - 210, 0);
|
||||
toolsPanel.setLocation(jFrameCollectionTranss.getWidth() - 233, 0);
|
||||
setCollectionNamePanel.setLocation(jFrameCollectionTranss.getWidth() - 200, 30);
|
||||
radioButtonsPanel.setLocation(jFrameCollectionTranss.getWidth() - 200, 78);
|
||||
addCollectionPanel.setLocation(jFrameCollectionTranss.getWidth() - 200, 103);
|
||||
collectionsListPanel.setLocation(jFrameCollectionTranss.getWidth() - 200, 137);
|
||||
deleteCollectionPanel.setLocation(jFrameCollectionTranss.getWidth() - 200, 227);
|
||||
comboBoxPanel.setLocation(jFrameCollectionTranss.getWidth() - 200, jFrameCollectionTranss.getHeight() - 400);
|
||||
createCompanyPanel.setLocation(jFrameCollectionTranss.getWidth() - 200, jFrameCollectionTranss.getHeight() - 370);
|
||||
goToCheckPanel.setLocation(jFrameCollectionTranss.getWidth() - 200,
|
||||
jFrameCollectionTranss.getHeight() - 320);
|
||||
goGoToCheckFromRubbishBinPanel.setLocation(jFrameCollectionTranss.getWidth() - 200,
|
||||
jFrameCollectionTranss.getHeight() - 295);
|
||||
addTransPanel.setLocation(jFrameCollectionTranss.getWidth() - 200, jFrameCollectionTranss.getHeight() - 241);
|
||||
addFromConstructorPanel.setLocation(jFrameCollectionTranss.getWidth() - 200, jFrameCollectionTranss.getHeight() - 187);
|
||||
textBoxPanel.setLocation(jFrameCollectionTranss.getWidth() - 200, jFrameCollectionTranss.getHeight() - 146);
|
||||
removePanel.setLocation(jFrameCollectionTranss.getWidth() - 200, jFrameCollectionTranss.getHeight() - 119);
|
||||
|
||||
refreshPanel.setLocation(jFrameCollectionTranss.getWidth() - 200, jFrameCollectionTranss.getHeight() - 67);
|
||||
toolsPanel.setSize(new Dimension(10, jFrameCollectionTranss.getHeight()));
|
||||
|
||||
jFrameCollectionTranss.repaint();
|
||||
}
|
||||
});
|
||||
|
||||
buttonAddTrans.addActionListener(e -> {
|
||||
_company.createObject(jFrameCollectionTranss);
|
||||
jFrameCollectionTranss.repaint();
|
||||
});
|
||||
|
||||
buttonRemove.addActionListener(e -> {
|
||||
int pos = -1;
|
||||
|
||||
if (!textBoxPosition.getText().isEmpty()) {
|
||||
int inputPos = Integer.parseInt(textBoxPosition.getText());
|
||||
if (inputPos <= 99 && inputPos >= 0) {
|
||||
pos = inputPos;
|
||||
}
|
||||
}
|
||||
if (pos != -1) {
|
||||
if (_company.deleteButtonAction(pos, jFrameCollectionTranss)) {
|
||||
goGoToCheckFromRubbishBinButton.setEnabled(true);
|
||||
}
|
||||
jFrameCollectionTranss.repaint();
|
||||
}
|
||||
});
|
||||
|
||||
refreshButton.addActionListener(e -> {
|
||||
jFrameCollectionTranss.repaint();
|
||||
});
|
||||
goToCheckButton.addActionListener(e -> {
|
||||
_company.goToCheckButtonAction();
|
||||
jFrameCollectionTranss.repaint();
|
||||
});
|
||||
goGoToCheckFromRubbishBinButton.addActionListener(e -> {
|
||||
goGoToCheckFromRubbishBinButton.setEnabled(_company.goToCheckFromRubbishBinAction());
|
||||
jFrameCollectionTranss.repaint();
|
||||
});
|
||||
createCompanyButton.addActionListener(e -> {
|
||||
boolean res = _company.collectionComboBox_SelectedIndexChanged(jFrameCollectionTranss, collectionsList, comboBoxSelectorCompany,
|
||||
jFrameCollectionTranss.getWidth() - 233, jFrameCollectionTranss.getHeight());
|
||||
setEnableComponentsOfList(listOfDownPanel, res);
|
||||
jFrameCollectionTranss.repaint();
|
||||
});
|
||||
|
||||
addFromConstructorButton.addActionListener(e -> {
|
||||
_company.getObjFromConstructor(jFrameCollectionTranss);
|
||||
});
|
||||
addCollectionButton.addActionListener(e -> {
|
||||
StorageCollection<DrawningTrans> result = _company.addCollectionButtonAction(jFrameCollectionTranss, setCollectionName,
|
||||
massiveRadioButton, listRadioButton);
|
||||
updateCollectionsList(result);
|
||||
});
|
||||
deleteCollectionButton.addActionListener(e -> {
|
||||
StorageCollection<DrawningTrans> result = _company.deleteCollectionButtonAction(jFrameCollectionTranss, collectionsList);
|
||||
updateCollectionsList(result);
|
||||
});
|
||||
jFrameCollectionTranss.setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
private void updateCollectionsList(StorageCollection<DrawningTrans> storageCollection) {
|
||||
if (storageCollection == null) {
|
||||
return;
|
||||
}
|
||||
listModel.clear();
|
||||
ArrayList<String> keys = storageCollection.keys;
|
||||
for (String key : keys) {
|
||||
listModel.addElement(key);
|
||||
}
|
||||
}
|
||||
|
||||
private void setEnableComponentsOfList(ArrayList<Component> list, boolean type) {
|
||||
for (var i : list) {
|
||||
i.setEnabled(type);
|
||||
}
|
||||
}
|
||||
}
|
484
ProjectElectroTrans/src/Forms/FormTransConfig.java
Normal file
@ -0,0 +1,484 @@
|
||||
package Forms;
|
||||
|
||||
import Drawnings.*;
|
||||
import Entities.EntityTrans;
|
||||
import Entities.EntityElectroTrans;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.awt.event.*;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FormTransConfig extends JFrame {
|
||||
final private JFrame jFrameTransConfig = new JFrame();
|
||||
public JFrame getjFrameTransConfig() {
|
||||
return jFrameTransConfig;
|
||||
}
|
||||
final private DrawningTransConfig drawningConfig = new DrawningTransConfig();
|
||||
public DrawningTransConfig getDrawningConfig() {
|
||||
return drawningConfig;
|
||||
}
|
||||
|
||||
final private JSpinner spinnerSpeed = new JSpinner(new SpinnerNumberModel(100, 100, 1000, 100));
|
||||
final private JSpinner spinnerWeight = new JSpinner(new SpinnerNumberModel(100, 100, 1000, 100));
|
||||
final private JSpinner spinnerWheels = new JSpinner(new SpinnerNumberModel(2, 2, 4, 1));
|
||||
final private JCheckBox checkBoxSail = new JCheckBox();
|
||||
final private JCheckBox checkBoxFloaters = new JCheckBox();
|
||||
final private JPanel CheckBoxesPanel = new JPanel();
|
||||
final private JPanel SpinnersPanel = new JPanel();
|
||||
|
||||
final private JPanel PicturePanel = new JPanel();
|
||||
final private JLabel labelBodyColor = new JLabel("Основной цвет");
|
||||
final private JLabel labelAdditionalColor = new JLabel("Доп цвет");
|
||||
final private JPanel TransColorsPanel = new JPanel();
|
||||
final private JLabel labelTrans = new JLabel("Простой");
|
||||
final private JLabel labelCatamaran = new JLabel("Продвинутый");
|
||||
final private JPanel TypeTransPanel = new JPanel();
|
||||
|
||||
final private JPanel ColorsPanel = new JPanel();
|
||||
final private JPanel panelRed = new JPanel();
|
||||
final private JPanel panelGreen = new JPanel();
|
||||
final private JPanel panelBlue = new JPanel();
|
||||
final private JPanel panelYellow = new JPanel();
|
||||
final private JPanel panelWhite = new JPanel();
|
||||
final private JPanel panelBlack = new JPanel();
|
||||
final private JPanel panelGray = new JPanel();
|
||||
final private JPanel panelPink = new JPanel();
|
||||
final private JLabel labelColor = new JLabel("Цвет");
|
||||
final private JPanel labelColorPanel = new JPanel();
|
||||
final private JLabel labelDefaultWheels = new JLabel("Обычные");
|
||||
final private JLabel labelOvalWheels = new JLabel("Квадратные");
|
||||
final private JLabel labelRectanglesWheels = new JLabel("Треугольные");
|
||||
final private JPanel WheelsPanel = new JPanel();
|
||||
final private JLabel labelSpeed = new JLabel("Скорость:");
|
||||
final private JLabel labelWeight = new JLabel("Вес:");
|
||||
final private JLabel labelWheels = new JLabel("Колеса:");
|
||||
final private JLabel labelSail = new JLabel("Рога:");
|
||||
final private JLabel labelFloaters = new JLabel("Батареи:");
|
||||
|
||||
final private JButton buttonAdd = new JButton("Создать");
|
||||
final private JPanel buttonAddPanel = new JPanel();
|
||||
public JButton getButtonAdd() {
|
||||
return buttonAdd;
|
||||
}
|
||||
final private JButton buttonCancel = new JButton("Отмена");
|
||||
final private JPanel buttonCancelPanel = new JPanel();
|
||||
|
||||
|
||||
|
||||
public void OpenFrame() {
|
||||
jFrameTransConfig.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
Toolkit tolls = Toolkit.getDefaultToolkit();
|
||||
Dimension dimension = tolls.getScreenSize();
|
||||
jFrameTransConfig.setBounds(dimension.width / 2 - 250, dimension.height / 2 - 250,
|
||||
700, 330);
|
||||
jFrameTransConfig.setTitle("Создание объекта");
|
||||
|
||||
SpinnersPanel.setLayout(new GridLayout(3, 2));
|
||||
labelSpeed.setSize(new Dimension(50, 30));
|
||||
spinnerSpeed.setSize(new Dimension(120, 30));
|
||||
labelWeight.setSize(new Dimension(50, 30));
|
||||
spinnerWeight.setSize(new Dimension(120, 30));
|
||||
labelWheels.setSize(new Dimension(50, 30));
|
||||
spinnerWheels.setSize(new Dimension(120, 30));
|
||||
SpinnersPanel.setSize(new Dimension(170, 90));
|
||||
SpinnersPanel.add(labelSpeed);
|
||||
SpinnersPanel.add(spinnerSpeed);
|
||||
SpinnersPanel.add(labelWeight);
|
||||
SpinnersPanel.add(spinnerWeight);
|
||||
SpinnersPanel.add(labelWheels);
|
||||
SpinnersPanel.add(spinnerWheels);
|
||||
|
||||
CheckBoxesPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
CheckBoxesPanel.setSize(new Dimension(100, 90));
|
||||
CheckBoxesPanel.add(labelSail);
|
||||
CheckBoxesPanel.add(checkBoxSail);
|
||||
CheckBoxesPanel.add(labelFloaters);
|
||||
CheckBoxesPanel.add(checkBoxFloaters);
|
||||
|
||||
labelTrans.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
labelCatamaran.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
TypeTransPanel.setLayout(new BorderLayout());
|
||||
TypeTransPanel.setSize(new Dimension(140, 42));
|
||||
TypeTransPanel.add(labelTrans, BorderLayout.WEST);
|
||||
TypeTransPanel.add(labelCatamaran, BorderLayout.EAST);
|
||||
|
||||
PicturePanel.setSize(new Dimension(220, 130));
|
||||
PicturePanel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
|
||||
|
||||
labelBodyColor.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
labelAdditionalColor.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
TransColorsPanel.setLayout(new BorderLayout());
|
||||
TransColorsPanel.setSize(new Dimension(150, 50));
|
||||
TransColorsPanel.add(labelBodyColor, BorderLayout.WEST);
|
||||
TransColorsPanel.add(labelAdditionalColor, BorderLayout.EAST);
|
||||
|
||||
labelDefaultWheels.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
labelOvalWheels.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
labelRectanglesWheels.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
WheelsPanel.setLayout(new BorderLayout(5, 5));
|
||||
WheelsPanel.setSize(new Dimension(210, 42));
|
||||
WheelsPanel.add(labelDefaultWheels, BorderLayout.WEST);
|
||||
WheelsPanel.add(labelOvalWheels, BorderLayout.CENTER);
|
||||
WheelsPanel.add(labelRectanglesWheels, BorderLayout.EAST);
|
||||
|
||||
panelRed.setBackground(Color.RED);
|
||||
panelGreen.setBackground(Color.GREEN);
|
||||
panelBlue.setBackground(Color.BLUE);
|
||||
panelYellow.setBackground(Color.YELLOW);
|
||||
panelWhite.setBackground(Color.WHITE);
|
||||
panelBlack.setBackground(Color.BLACK);
|
||||
panelGray.setBackground(Color.GRAY);
|
||||
panelPink.setBackground(Color.PINK);
|
||||
|
||||
ColorsPanel.setLayout(new GridLayout(2, 4, 5, 5));
|
||||
ColorsPanel.setSize(new Dimension(150, 75));
|
||||
ColorsPanel.add(panelRed);
|
||||
ColorsPanel.add(panelGreen);
|
||||
ColorsPanel.add(panelBlue);
|
||||
ColorsPanel.add(panelYellow);
|
||||
ColorsPanel.add(panelWhite);
|
||||
ColorsPanel.add(panelBlack);
|
||||
ColorsPanel.add(panelGray);
|
||||
ColorsPanel.add(panelPink);
|
||||
|
||||
labelColorPanel.setLayout(new BorderLayout());
|
||||
labelColorPanel.setSize(new Dimension(70, 30));
|
||||
labelColorPanel.add(labelColor, BorderLayout.CENTER);
|
||||
|
||||
buttonAddPanel.setLayout(new BorderLayout());
|
||||
buttonAddPanel.setSize(new Dimension(90, 40));
|
||||
buttonAddPanel.add(buttonAdd, BorderLayout.CENTER);
|
||||
|
||||
buttonCancelPanel.setLayout(new BorderLayout());
|
||||
buttonCancelPanel.setSize(new Dimension(90, 40));
|
||||
buttonCancelPanel.add(buttonCancel, BorderLayout.CENTER);
|
||||
|
||||
jFrameTransConfig.setLayout(null);
|
||||
jFrameTransConfig.add(buttonCancelPanel);
|
||||
jFrameTransConfig.add(buttonAddPanel);
|
||||
jFrameTransConfig.add(WheelsPanel);
|
||||
jFrameTransConfig.add(CheckBoxesPanel);
|
||||
jFrameTransConfig.add(TypeTransPanel);
|
||||
jFrameTransConfig.add(labelColorPanel);
|
||||
jFrameTransConfig.add(ColorsPanel);
|
||||
jFrameTransConfig.add(PicturePanel);
|
||||
jFrameTransConfig.add(TransColorsPanel);
|
||||
jFrameTransConfig.add(SpinnersPanel);
|
||||
|
||||
|
||||
|
||||
jFrameTransConfig.addComponentListener(new ComponentAdapter() {
|
||||
public void componentResized(ComponentEvent e) {
|
||||
SpinnersPanel.setLocation(jFrameTransConfig.getWidth()-650, 10);
|
||||
CheckBoxesPanel.setLocation(jFrameTransConfig.getWidth()-650, 115);
|
||||
TypeTransPanel.setLocation(jFrameTransConfig.getWidth()-670, 235);
|
||||
TransColorsPanel.setLocation(jFrameTransConfig.getWidth()-237, 35);
|
||||
labelColorPanel.setLocation(jFrameTransConfig.getWidth()-390, 5);
|
||||
PicturePanel.setLocation(jFrameTransConfig.getWidth()-270, 95);
|
||||
ColorsPanel.setLocation(jFrameTransConfig.getWidth()-440, 35);
|
||||
WheelsPanel.setLocation(jFrameTransConfig.getWidth()-500, 235);
|
||||
buttonAddPanel.setLocation(jFrameTransConfig.getWidth()-225, 235);
|
||||
buttonCancelPanel.setLocation(jFrameTransConfig.getWidth()-125, 235);
|
||||
|
||||
jFrameTransConfig.repaint();
|
||||
}
|
||||
});
|
||||
MouseAdapter labelObjectsMouseDown = new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
((JLabel) e.getComponent()).getTransferHandler().exportAsDrag(((JLabel) e.getComponent()), e, TransferHandler.COPY);
|
||||
}
|
||||
};
|
||||
|
||||
TransferHandler labelObjectsTransferHandler = new TransferHandler() {
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {
|
||||
return TransferHandler.COPY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new StringSelection(((JLabel) c).getText());
|
||||
}
|
||||
};
|
||||
MouseAdapter labelWheelsMouseDown = new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
((JLabel) e.getComponent()).getTransferHandler().exportAsDrag(((JLabel) e.getComponent()), e, TransferHandler.COPY);
|
||||
}
|
||||
};
|
||||
labelTrans.addMouseListener(labelObjectsMouseDown);
|
||||
labelTrans.setTransferHandler(labelObjectsTransferHandler);
|
||||
labelCatamaran.addMouseListener(labelObjectsMouseDown);
|
||||
labelCatamaran.setTransferHandler(labelObjectsTransferHandler);
|
||||
|
||||
labelDefaultWheels.addMouseListener(labelWheelsMouseDown);
|
||||
labelRectanglesWheels.addMouseListener(labelWheelsMouseDown);
|
||||
labelOvalWheels.addMouseListener(labelWheelsMouseDown);
|
||||
|
||||
labelDefaultWheels.setTransferHandler(new TransferHandler() {
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {return TransferHandler.COPY;}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new WheelsTransferable(new DrawningWheels());
|
||||
}
|
||||
});
|
||||
labelOvalWheels.setTransferHandler(new TransferHandler() {
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {return TransferHandler.COPY;}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new WheelsTransferable(new DrawningRectWheels());
|
||||
}
|
||||
});
|
||||
labelRectanglesWheels.setTransferHandler(new TransferHandler() {
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {return TransferHandler.COPY;}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new WheelsTransferable(new DrawningRectangleWheels());
|
||||
}
|
||||
});
|
||||
PicturePanel.setTransferHandler(new TransferHandler() {
|
||||
@Override
|
||||
public boolean canImport(TransferHandler.TransferSupport support) {
|
||||
return support.isDataFlavorSupported(DataFlavor.stringFlavor)
|
||||
|| support.isDataFlavorSupported(WheelsTransferable.wheelsDataFlavor);
|
||||
}
|
||||
@Override
|
||||
public boolean importData(TransferHandler.TransferSupport support) {
|
||||
if (!canImport(support)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
|
||||
IDrawWheels wheels = new DrawningWheels();
|
||||
wheels.setNumber((int) spinnerWheels.getValue());
|
||||
switch (data) {
|
||||
case "Простой":
|
||||
drawningConfig.trans = new DrawningTrans(new EntityTrans((int) spinnerSpeed.getValue(), (int) spinnerWeight.getValue(), Color.WHITE), wheels);
|
||||
PicturePanel.repaint();
|
||||
return true;
|
||||
case "Продвинутый":
|
||||
drawningConfig.trans = new DrawningElectroTrans(new EntityElectroTrans((int) spinnerSpeed.getValue(), (int) spinnerWeight.getValue(),
|
||||
Color.WHITE, Color.BLACK, checkBoxSail.isSelected(), checkBoxFloaters.isSelected()), wheels);
|
||||
PicturePanel.repaint();
|
||||
return true;
|
||||
}
|
||||
}catch (UnsupportedFlavorException | IOException e) {}
|
||||
try {
|
||||
IDrawWheels drawWheels =
|
||||
(IDrawWheels) support.getTransferable().getTransferData(WheelsTransferable.wheelsDataFlavor);
|
||||
drawningConfig.trans.setDrawWheels(drawWheels);
|
||||
drawningConfig.trans.getDrawWheels().setNumber((int) spinnerWheels.getValue());
|
||||
|
||||
}catch (UnsupportedFlavorException | IOException e) {}
|
||||
PicturePanel.repaint();
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
PicturePanel.setLayout(new BorderLayout());
|
||||
PicturePanel.add(drawningConfig, BorderLayout.CENTER);
|
||||
|
||||
MouseAdapter colorMouseDown = new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
((JPanel) e.getComponent()).getTransferHandler().exportAsDrag(((JPanel) e.getComponent()), e, TransferHandler.COPY);
|
||||
}
|
||||
};
|
||||
panelBlack.addMouseListener(colorMouseDown);
|
||||
panelBlack.setTransferHandler(new ColorTransferHandler());
|
||||
panelBlue.addMouseListener(colorMouseDown);
|
||||
panelBlue.setTransferHandler(new ColorTransferHandler());
|
||||
panelGreen.addMouseListener(colorMouseDown);
|
||||
panelGreen.setTransferHandler(new ColorTransferHandler());
|
||||
panelGray.addMouseListener(colorMouseDown);
|
||||
panelGray.setTransferHandler(new ColorTransferHandler());
|
||||
panelPink.addMouseListener(colorMouseDown);
|
||||
panelPink.setTransferHandler(new ColorTransferHandler());
|
||||
panelRed.addMouseListener(colorMouseDown);
|
||||
panelRed.setTransferHandler(new ColorTransferHandler());
|
||||
panelYellow.addMouseListener(colorMouseDown);
|
||||
panelYellow.setTransferHandler(new ColorTransferHandler());
|
||||
panelWhite.addMouseListener(colorMouseDown);
|
||||
panelWhite.setTransferHandler(new ColorTransferHandler());
|
||||
|
||||
labelBodyColor.setTransferHandler(new TransferHandler() {
|
||||
@Override
|
||||
public boolean canImport(TransferHandler.TransferSupport support) {
|
||||
return support.isDataFlavorSupported(ColorTransferable.colorDataFlavor);
|
||||
}
|
||||
@Override
|
||||
public boolean importData(TransferSupport support) {
|
||||
try {
|
||||
Color color = (Color) support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor);
|
||||
if (drawningConfig.trans == null) return false;
|
||||
drawningConfig.trans.entityTrans.setBodyColor(color);
|
||||
return true;
|
||||
} catch (UnsupportedFlavorException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
labelAdditionalColor.setTransferHandler(new TransferHandler() {
|
||||
@Override
|
||||
public boolean canImport(TransferHandler.TransferSupport support) {
|
||||
if (!(drawningConfig.trans instanceof DrawningElectroTrans)) return false;
|
||||
return support.isDataFlavorSupported(ColorTransferable.colorDataFlavor);
|
||||
}
|
||||
@Override
|
||||
public boolean importData(TransferSupport support) {
|
||||
try {
|
||||
Color color = (Color) support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor);
|
||||
if (drawningConfig.trans == null) return false;
|
||||
if (drawningConfig.trans.entityTrans instanceof EntityElectroTrans catamaran) {
|
||||
catamaran.setAdditionalColor(color);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (UnsupportedFlavorException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
spinnerWheels.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
if (drawningConfig.trans == null) {
|
||||
return;
|
||||
}
|
||||
drawningConfig.trans.getDrawWheels().setNumber((int) spinnerWheels.getValue());
|
||||
PicturePanel.repaint();
|
||||
}
|
||||
});
|
||||
spinnerWeight.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
if (drawningConfig.trans == null) {
|
||||
return;
|
||||
}
|
||||
drawningConfig.trans.entityTrans.setWeight((int) spinnerWeight.getValue());
|
||||
PicturePanel.repaint();
|
||||
}
|
||||
});
|
||||
|
||||
spinnerSpeed.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
if (drawningConfig.trans == null) {
|
||||
return;
|
||||
}
|
||||
drawningConfig.trans.entityTrans.setSpeed((int) spinnerSpeed.getValue());
|
||||
PicturePanel.repaint();
|
||||
}
|
||||
});
|
||||
checkBoxSail.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
if (drawningConfig.trans == null) {
|
||||
return;
|
||||
}
|
||||
if (drawningConfig.trans.entityTrans instanceof EntityElectroTrans) {
|
||||
((EntityElectroTrans) drawningConfig.trans.entityTrans).setHorns(checkBoxSail.isSelected());
|
||||
PicturePanel.repaint();
|
||||
}
|
||||
}
|
||||
});
|
||||
checkBoxFloaters.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
if (drawningConfig.trans == null) {
|
||||
return;
|
||||
}
|
||||
if (drawningConfig.trans.entityTrans instanceof EntityElectroTrans) {
|
||||
((EntityElectroTrans) drawningConfig.trans.entityTrans).setBattery(checkBoxFloaters.isSelected());
|
||||
PicturePanel.repaint();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
buttonCancel.addActionListener(e -> {
|
||||
jFrameTransConfig.dispose();
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
jFrameTransConfig.setVisible(true);
|
||||
}
|
||||
|
||||
private class ColorTransferable implements Transferable {
|
||||
private Color color;
|
||||
private static final DataFlavor colorDataFlavor = new DataFlavor(Color.class, "Color");
|
||||
public ColorTransferable(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
@Override
|
||||
public DataFlavor[] getTransferDataFlavors() {
|
||||
return new DataFlavor[]{colorDataFlavor};
|
||||
}
|
||||
@Override
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||
return colorDataFlavor.equals(flavor);
|
||||
}
|
||||
@Override
|
||||
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
|
||||
if (isDataFlavorSupported(flavor)) {
|
||||
return color;
|
||||
} else {
|
||||
throw new UnsupportedFlavorException(flavor);
|
||||
}
|
||||
}
|
||||
}
|
||||
private class ColorTransferHandler extends TransferHandler {
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {
|
||||
return TransferHandler.COPY;
|
||||
}
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new ColorTransferable(c.getBackground());
|
||||
}
|
||||
}
|
||||
private class WheelsTransferable implements Transferable {
|
||||
private IDrawWheels wheels;
|
||||
private static final DataFlavor wheelsDataFlavor = new DataFlavor(IDrawWheels.class, "Wheels");
|
||||
public WheelsTransferable(IDrawWheels wheels) {
|
||||
this.wheels = wheels;
|
||||
this.wheels.setNumber((int) spinnerWheels.getValue());
|
||||
}
|
||||
@Override
|
||||
public DataFlavor[] getTransferDataFlavors() {
|
||||
return new DataFlavor[]{wheelsDataFlavor};
|
||||
}
|
||||
@Override
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||
return flavor.equals(wheelsDataFlavor);
|
||||
}
|
||||
@Override
|
||||
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
|
||||
if (isDataFlavorSupported(flavor)) {
|
||||
return wheels;
|
||||
} else {
|
||||
throw new UnsupportedFlavorException(flavor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,7 @@
|
||||
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
||||
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
||||
import Forms.FormTransCollection;
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
|
||||
// to see how IntelliJ IDEA suggests fixing it.
|
||||
System.out.println("Hello and welcome!");
|
||||
FormTransCollection formTransCollection = new FormTransCollection();
|
||||
formTransCollection.OpenFrame();
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public abstract class AbstractStrategy {
|
||||
private IMoveableObject _moveableObject;
|
||||
private StrategyStatus _state = StrategyStatus.NotInit;
|
||||
protected int FieldWidth;
|
||||
protected int FieldHeight;
|
||||
public StrategyStatus GetStatus() { return _state; }
|
||||
|
||||
public void SetData(IMoveableObject moveableObject, int width, int height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = StrategyStatus.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = StrategyStatus.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestination())
|
||||
{
|
||||
_state = StrategyStatus.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
|
||||
protected boolean MoveLeft() { return MoveTo(MovementDirection.Left); }
|
||||
protected boolean MoveRight() { return MoveTo(MovementDirection.Right); }
|
||||
protected boolean MoveUp() { return MoveTo(MovementDirection.Up); }
|
||||
protected boolean MoveDown() { return MoveTo(MovementDirection.Down); }
|
||||
|
||||
protected ObjectParameters GetObjectParameters() { return _moveableObject.GetObjectPosition(); }
|
||||
|
||||
protected int GetStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return _moveableObject.GetStep();
|
||||
}
|
||||
protected abstract void MoveToTarget();
|
||||
|
||||
protected abstract boolean IsTargetDestination();
|
||||
|
||||
private boolean MoveTo(MovementDirection directionType)
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_moveableObject.TryMoveObject(directionType))
|
||||
{
|
||||
_moveableObject.MoveObject(directionType);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public interface IMoveableObject {
|
||||
ObjectParameters GetObjectPosition();
|
||||
int GetStep();
|
||||
boolean TryMoveObject(MovementDirection direction);
|
||||
void MoveObject(MovementDirection direction);
|
||||
}
|
46
ProjectElectroTrans/src/MovementStrategy/MoveToBorder.java
Normal file
@ -0,0 +1,46 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public class MoveToBorder extends AbstractStrategy {
|
||||
@Override
|
||||
protected boolean IsTargetDestination()
|
||||
{
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) {
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder() + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder() + GetStep() >= FieldHeight;
|
||||
}
|
||||
@Override
|
||||
protected void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) {
|
||||
return;
|
||||
}
|
||||
int diffX = objParams.RightBorder() - FieldWidth;
|
||||
if (Math.abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
int diffY = objParams.DownBorder() - FieldHeight;
|
||||
if (Math.abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
48
ProjectElectroTrans/src/MovementStrategy/MoveToCenter.java
Normal file
@ -0,0 +1,48 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public class MoveToCenter extends AbstractStrategy {
|
||||
@Override
|
||||
protected boolean IsTargetDestination()
|
||||
{
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) {
|
||||
return false;
|
||||
}
|
||||
return (objParams.ObjectMiddleHorizontal() - GetStep() <= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleHorizontal() + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical() - GetStep() <= FieldHeight / 2 &&
|
||||
objParams.ObjectMiddleVertical() + GetStep() >= FieldHeight / 2);
|
||||
}
|
||||
@Override
|
||||
protected void MoveToTarget()
|
||||
{
|
||||
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var diffX = objParams.ObjectMiddleHorizontal() - FieldWidth / 2;
|
||||
if (Math.abs(diffX) > GetStep()) {
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.ObjectMiddleVertical() - FieldHeight / 2;
|
||||
if (Math.abs(diffY) > GetStep()) {
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
23
ProjectElectroTrans/src/MovementStrategy/MoveableTrans.java
Normal file
@ -0,0 +1,23 @@
|
||||
package MovementStrategy;
|
||||
import Drawnings.*;
|
||||
|
||||
public class MoveableTrans implements IMoveableObject {
|
||||
private DrawningTrans _trans = null;
|
||||
public MoveableTrans(DrawningTrans drawningTrans)
|
||||
{
|
||||
_trans = drawningTrans;
|
||||
}
|
||||
|
||||
public ObjectParameters GetObjectPosition()
|
||||
{
|
||||
if (_trans == null || _trans.getEntityTrans() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_trans.GetPosX(), _trans.GetPosY(), _trans.GetWidth(), _trans.GetHeight());
|
||||
}
|
||||
|
||||
public int GetStep() { return (int) _trans.getEntityTrans().getStep(); }
|
||||
public boolean TryMoveObject(MovementDirection direction) { return _trans.moveTransport(direction); }
|
||||
public void MoveObject(MovementDirection direction) { _trans.moveTransport(direction); }
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public enum MovementDirection {
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right;
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public class ObjectParameters {
|
||||
private int _x;
|
||||
private int _y;
|
||||
private int _width;
|
||||
private int _height;
|
||||
|
||||
public int LeftBorder() { return _x; }
|
||||
public int TopBorder() { return _y; }
|
||||
public int RightBorder() { return _x + _width; }
|
||||
public int DownBorder() { return _y + _height; }
|
||||
|
||||
public int ObjectMiddleHorizontal () { return _x + _width / 2; }
|
||||
public int ObjectMiddleVertical () { return _y + _height / 2; }
|
||||
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public enum StrategyStatus {
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
BIN
out/production/ProjectElectroTrans/Drawnings/DrawningTrans.class
Normal file
BIN
out/production/ProjectElectroTrans/Drawnings/IDrawWheels.class
Normal file
BIN
out/production/ProjectElectroTrans/Drawnings/WheelsCount.class
Normal file
BIN
out/production/ProjectElectroTrans/Entities/EntityTrans.class
Normal file
BIN
out/production/ProjectElectroTrans/Forms/FormConstructor$1.class
Normal file
BIN
out/production/ProjectElectroTrans/Forms/FormConstructor.class
Normal file
BIN
out/production/ProjectElectroTrans/Forms/FormElectroTrans.class
Normal file
BIN
out/production/ProjectElectroTrans/Main.class
Normal file
BIN
out/production/ProjectElectroTrans/arrowDown.png
Normal file
After Width: | Height: | Size: 965 B |
BIN
out/production/ProjectElectroTrans/arrowLeft.png
Normal file
After Width: | Height: | Size: 1005 B |
BIN
out/production/ProjectElectroTrans/arrowRight.png
Normal file
After Width: | Height: | Size: 978 B |
BIN
out/production/ProjectElectroTrans/arrowUp.png
Normal file
After Width: | Height: | Size: 1012 B |