Compare commits
5 Commits
LabWorking
...
LabWorking
| Author | SHA1 | Date | |
|---|---|---|---|
| 5df6a9ad57 | |||
| 6d230a8bb7 | |||
| 6e048994f4 | |||
| d6544b387a | |||
| 0020757f27 |
38
ProjectMonorail/.idea/workspace.xml
generated
38
ProjectMonorail/.idea/workspace.xml
generated
@@ -5,16 +5,9 @@
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="39e7c520-e505-4e53-a269-c949d7c9f5d1" name="Changes" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/src/Scripts/Wheels/IDrawingWheels.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/ProjectMonorail/Scripts/Wheels/DrawingWheels.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjectMonorail/Scripts/Wheels/DrawingWheels.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Scripts/CollectionGenericObjects/AdditionalCollection.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Scripts/CollectionGenericObjects/AdditionalCollection.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Scripts/CollectionGenericObjects/DepotSharingService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Scripts/CollectionGenericObjects/DepotSharingService.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Scripts/Drawing/DrawingModernMonorail.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Scripts/Drawing/DrawingModernMonorail.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Scripts/Drawing/DrawingMonorail.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Scripts/Drawing/DrawingMonorail.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Scripts/Forms/FormAdditionalCollection.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Scripts/Forms/FormAdditionalCollection.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Scripts/Forms/FormMonorailCollection.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Scripts/Forms/FormMonorailCollection.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Scripts/Wheels/DrawingWheels.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Scripts/Wheels/DrawingWheels.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Scripts/Entities/EntityModernMonorail.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Scripts/Entities/EntityModernMonorail.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Scripts/Forms/FormMonorailConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Scripts/Forms/FormMonorailConfig.java" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -24,8 +17,8 @@
|
||||
<component name="FileTemplateManagerImpl">
|
||||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="Class" />
|
||||
<option value="Interface" />
|
||||
<option value="Class" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
@@ -41,16 +34,16 @@
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"Application.Program.executor": "Run",
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"git-widget-placeholder": "LabWorking__3",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "D:/Учеба/PIbd-11_Tarasov_V.D._Hard/ProjectMonorail"
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"Application.Program.executor": "Run",
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"git-widget-placeholder": "LabWorking__5",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "C:/Учеба/AgarioGame"
|
||||
}
|
||||
}]]></component>
|
||||
}</component>
|
||||
<component name="RunManager">
|
||||
<configuration name="Program" type="Application" factoryName="Application">
|
||||
<option name="MAIN_CLASS_NAME" value="Scripts.Program" />
|
||||
@@ -60,6 +53,13 @@
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
||||
<component name="SharedIndexes">
|
||||
<attachedChunks>
|
||||
<set>
|
||||
<option value="jdk-21.0.2-openjdk-21.0.2-4caba194b151-4f524021" />
|
||||
</set>
|
||||
</attachedChunks>
|
||||
</component>
|
||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
|
||||
Binary file not shown.
@@ -20,7 +20,7 @@ public abstract class AbstractCompany {
|
||||
_pictureHeight = picHeight;
|
||||
_collection = collection;
|
||||
System.out.println(_pictureHeight+" "+_pictureWidth+" "+_placeSizeHeight+" "+_placeSizeWidth);
|
||||
_collection.SetMaxCount(GetMaxCount(), (Class) DrawingMonorail.class);
|
||||
_collection.SetMaxCount(GetMaxCount());
|
||||
}
|
||||
//Перегрузок нет
|
||||
public DrawingMonorail GetRandomObject()
|
||||
|
||||
@@ -4,18 +4,17 @@ import Scripts.Drawing.DrawingModernMonorail;
|
||||
import Scripts.Drawing.DrawingMonorail;
|
||||
import Scripts.Entities.EntityModernMonorail;
|
||||
import Scripts.Entities.EntityMonorail;
|
||||
import Scripts.Wheels.DrawingWheels;
|
||||
import Scripts.Wheels.IDrawingWheels;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Random;
|
||||
|
||||
public class AdditionalCollection <T extends EntityMonorail, U extends IDrawingWheels>{
|
||||
public T[] _collectionEntity;
|
||||
public U[] _collectionWheels;
|
||||
public T[] CollectionEntity;
|
||||
public U[] CollectionWheels;
|
||||
public AdditionalCollection(int size, Class<T> type1, Class<T> type2) {
|
||||
_collectionEntity = (T[]) Array.newInstance(type1, size);
|
||||
_collectionWheels = (U[]) Array.newInstance(type2, size);
|
||||
CollectionEntity = (T[]) Array.newInstance(type1, size);
|
||||
CollectionWheels = (U[]) Array.newInstance(type2, size);
|
||||
CountEntities = size;
|
||||
CountWheels = size;
|
||||
}
|
||||
@@ -24,9 +23,9 @@ public class AdditionalCollection <T extends EntityMonorail, U extends IDrawingW
|
||||
public int Insert(T entity) {
|
||||
int index = 0;
|
||||
while (index < CountEntities) {
|
||||
if (_collectionEntity[index] == null)
|
||||
if (CollectionEntity[index] == null)
|
||||
{
|
||||
_collectionEntity[index] = entity;
|
||||
CollectionEntity[index] = entity;
|
||||
return index;
|
||||
}
|
||||
++index;
|
||||
@@ -36,9 +35,9 @@ public class AdditionalCollection <T extends EntityMonorail, U extends IDrawingW
|
||||
public int Insert(U decks) {
|
||||
int index = 0;
|
||||
while (index < CountWheels) {
|
||||
if (_collectionWheels[index] == null)
|
||||
if (CollectionWheels[index] == null)
|
||||
{
|
||||
_collectionWheels[index] = decks;
|
||||
CollectionWheels[index] = decks;
|
||||
return index;
|
||||
}
|
||||
++index;
|
||||
@@ -47,9 +46,9 @@ public class AdditionalCollection <T extends EntityMonorail, U extends IDrawingW
|
||||
}
|
||||
public DrawingMonorail CreateAdditionalCollectionStormtrooper() {
|
||||
Random random = new Random();
|
||||
if (_collectionEntity == null || _collectionWheels == null) return null;
|
||||
T entity = _collectionEntity[random.nextInt(CountEntities)];
|
||||
U wheels = _collectionWheels[random.nextInt(CountWheels)];
|
||||
if (CollectionEntity == null || CollectionWheels == null) return null;
|
||||
T entity = CollectionEntity[random.nextInt(CountEntities)];
|
||||
U wheels = CollectionWheels[random.nextInt(CountWheels)];
|
||||
DrawingMonorail drawingBaseStormtrooper = null;
|
||||
if (entity instanceof EntityModernMonorail) {
|
||||
drawingBaseStormtrooper = new DrawingModernMonorail((EntityModernMonorail)entity, wheels);
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package Scripts.CollectionGenericObjects;
|
||||
|
||||
public enum CollectionType {
|
||||
None,
|
||||
Massive,
|
||||
List
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public class DepotSharingService extends AbstractCompany {
|
||||
graphics.setColor(Color.BLACK);
|
||||
for (int i = 0; i < width; i++)
|
||||
{
|
||||
for (int j = 0; j < height + 1; ++j)
|
||||
for (int j = 0; j < height; ++j)
|
||||
{
|
||||
graphics.drawLine(i * _offsetX + i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth + i * _offsetX + i * _placeSizeWidth, j * _placeSizeHeight);
|
||||
graphics.drawLine(i * _offsetX + i * _placeSizeWidth, j * _placeSizeHeight, i * _offsetX + i * _placeSizeWidth, _placeSizeHeight + j * _placeSizeHeight);
|
||||
@@ -36,7 +36,7 @@ public class DepotSharingService extends AbstractCompany {
|
||||
|
||||
int currnetIndex = 0;
|
||||
|
||||
for (int j = height; j >= 0; j--) {
|
||||
for (int j = height - 1; j >= 0; j--) {
|
||||
for (int i = 0; i < width; i++, currnetIndex++) {
|
||||
if (_collection.Get(currnetIndex) == null) continue;
|
||||
|
||||
|
||||
@@ -3,9 +3,8 @@ package Scripts.CollectionGenericObjects;
|
||||
public interface ICollectionGenericObjects<T>
|
||||
{
|
||||
int getCount();
|
||||
void SetMaxCount(int count, Class<T> type);
|
||||
void SetMaxCount(int count);
|
||||
int Insert(T obj);
|
||||
int Insert(T obj, int position);
|
||||
T Remove(int position);
|
||||
T Get(int position);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package Scripts.CollectionGenericObjects;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ListGenericObjects<T> implements ICollectionGenericObjects<T> {
|
||||
private List<T> _collection;
|
||||
private int _maxCount;
|
||||
|
||||
public int getCount() {
|
||||
return _collection.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SetMaxCount(int size) {
|
||||
if (size > 0) {
|
||||
_maxCount = size;
|
||||
}
|
||||
}
|
||||
|
||||
public ListGenericObjects() {
|
||||
_collection = new ArrayList<T>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T Get(int position)
|
||||
{
|
||||
if (position >= getCount() || position < 0) return null;
|
||||
return _collection.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int Insert(T obj)
|
||||
{
|
||||
if (getCount() == _maxCount) return -1;
|
||||
_collection.add(obj);
|
||||
return getCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position >= getCount() || position < 0) return null;
|
||||
T obj = _collection.get(position);
|
||||
_collection.remove(position);
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,27 @@
|
||||
package Scripts.CollectionGenericObjects;
|
||||
|
||||
import Scripts.Drawing.DrawingMonorail;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T>
|
||||
{
|
||||
private T[] _collection;
|
||||
private int Count;
|
||||
public void SetMaxCount(int size, Class<T> type) {
|
||||
public void SetMaxCount(int size) {
|
||||
if (size > 0) {
|
||||
_collection = (T[]) Array.newInstance(type, size);
|
||||
Count = size;
|
||||
if (_collection == null) {
|
||||
_collection = (T[]) Array.newInstance((Class) DrawingMonorail.class, size);
|
||||
Count = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return Count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int Insert(T obj) {
|
||||
int index = 0;
|
||||
@@ -31,36 +37,6 @@ public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T>
|
||||
return -1;
|
||||
}
|
||||
@Override
|
||||
public int Insert(T obj, int position) {
|
||||
if (position >= getCount() || position < 0)
|
||||
return -1;
|
||||
if (_collection[position] == null) {
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
}
|
||||
int index = position + 1;
|
||||
while (index < getCount())
|
||||
{
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
_collection[index] = obj;
|
||||
return index;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
index = position - 1;
|
||||
while (index >= 0)
|
||||
{
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
_collection[index] = obj;
|
||||
return index;
|
||||
}
|
||||
--index;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@Override
|
||||
public T Remove(int position) {
|
||||
if (position >= getCount() || position < 0)
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package Scripts.CollectionGenericObjects;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class StorageCollection<T> {
|
||||
private Map<String, ICollectionGenericObjects<T>> _storages;
|
||||
public StorageCollection()
|
||||
{
|
||||
_storages = new HashMap<String, ICollectionGenericObjects<T>>();
|
||||
}
|
||||
public Set<String> Keys() {
|
||||
Set<String> keys = _storages.keySet();
|
||||
return keys;
|
||||
}
|
||||
public void SetCollectionObject(String name, CollectionType collectionType)
|
||||
{
|
||||
if (_storages.containsKey(name)) return;
|
||||
if (collectionType == CollectionType.None) return;
|
||||
else if (collectionType == CollectionType.Massive)
|
||||
_storages.put(name, new MassiveGenericObjects<T>());
|
||||
else if (collectionType == CollectionType.List)
|
||||
_storages.put(name, new ListGenericObjects<T>());
|
||||
}
|
||||
public void DelCollection(String name)
|
||||
{
|
||||
if (_storages.containsKey(name))
|
||||
_storages.remove(name);
|
||||
}
|
||||
public ICollectionGenericObjects<T> GetCollectionObject(String name) {
|
||||
if (_storages.containsKey(name))
|
||||
return _storages.get(name);
|
||||
return null;
|
||||
}
|
||||
|
||||
public T remove(String name, int position){
|
||||
if(_storages.containsKey(name))
|
||||
return _storages.get(name).Remove(position);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package Scripts.Drawing;
|
||||
|
||||
import Scripts.Entities.EntityModernMonorail;
|
||||
import Scripts.Entities.EntityMonorail;
|
||||
import Scripts.Wheels.DrawOrnament;
|
||||
import Scripts.Wheels.DrawingWheels;
|
||||
import Scripts.Wheels.IDrawingWheels;
|
||||
|
||||
@@ -14,10 +15,7 @@ public class DrawingModernMonorail extends DrawingMonorail {
|
||||
super(speed, weight, bodyColor, 190, 80);
|
||||
|
||||
_entityMonorail = new EntityModernMonorail(speed, weight, bodyColor, additionalColor, monorailTrack, cabin);
|
||||
_wheels = new DrawingWheels();
|
||||
Random rnd = new Random();
|
||||
_wheels.SetCountWheels(2 + rnd.nextInt(0, 3));
|
||||
_wheelsSeed = rnd.nextInt(0, 2);
|
||||
_wheels.SetOrnament(new DrawOrnament());
|
||||
}
|
||||
|
||||
public DrawingModernMonorail(EntityModernMonorail entityModernMonorail, IDrawingWheels wheels)
|
||||
@@ -25,10 +23,7 @@ public class DrawingModernMonorail extends DrawingMonorail {
|
||||
super((EntityMonorail)entityModernMonorail, 190, 80, wheels);
|
||||
|
||||
_entityMonorail = new EntityModernMonorail(entityModernMonorail.getSpeed(), entityModernMonorail.getWeight(), entityModernMonorail.getBodyColor(), entityModernMonorail.getAdditionalColor(), entityModernMonorail.getMonorailTrack(), entityModernMonorail.getMonorailTrack());
|
||||
_wheels = new DrawingWheels();
|
||||
Random rnd = new Random();
|
||||
_wheels.SetCountWheels(2 + rnd.nextInt(0, 3));
|
||||
_wheelsSeed = rnd.nextInt(0, 2);
|
||||
_wheels.SetOrnament(new DrawOrnament());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,8 +8,8 @@ import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingMonorail {
|
||||
protected EntityMonorail _entityMonorail;
|
||||
protected IDrawingWheels _wheels;
|
||||
public EntityMonorail _entityMonorail;
|
||||
public IDrawingWheels _wheels;
|
||||
|
||||
private Integer _pictureWidth = null;
|
||||
private Integer _pictureHeight = null;
|
||||
@@ -58,9 +58,6 @@ public class DrawingMonorail {
|
||||
{
|
||||
this(drawningMonorailWidth, drawningMonorailHeight);
|
||||
|
||||
_wheels = new DrawingWheels();
|
||||
_wheels.SetCountWheels(wheels.getCountWheels());
|
||||
|
||||
_entityMonorail = new EntityMonorail(entityMonorail.getSpeed(), entityMonorail.getWeight(), entityMonorail.getBodyColor());
|
||||
_wheels = new DrawingWheels();
|
||||
Random rnd = new Random();
|
||||
@@ -72,9 +69,6 @@ public class DrawingMonorail {
|
||||
{
|
||||
this(100, 40);
|
||||
|
||||
_wheels = new DrawingWheels();
|
||||
_wheels.SetCountWheels(wheels.getCountWheels());
|
||||
|
||||
_entityMonorail = new EntityMonorail(entityMonorail.getSpeed(), entityMonorail.getWeight(), entityMonorail.getBodyColor());
|
||||
_wheels = new DrawingWheels();
|
||||
Random rnd = new Random();
|
||||
|
||||
@@ -12,6 +12,10 @@ public class EntityModernMonorail extends EntityMonorail {
|
||||
public boolean getMonorailTrack() {return _monorailTrack;}
|
||||
public boolean getCabin() {return _cabin;}
|
||||
|
||||
public void setAdditionalColor(Color value) {_additionalColor = value;}
|
||||
public void setMonorailTrack(Boolean value) { _monorailTrack = value;}
|
||||
public void setCabin(Boolean value) { _cabin = value;}
|
||||
|
||||
public EntityModernMonorail(int speed, float weight, Color bodyColor, Color additionalColor, boolean monorailTrack, boolean cabin){
|
||||
super(speed, weight, bodyColor);
|
||||
Random rnd = new Random();
|
||||
|
||||
@@ -19,6 +19,10 @@ public class EntityMonorail {
|
||||
return _bodyColor;
|
||||
}
|
||||
|
||||
public void setSpeed(int value) {_speed = value; }
|
||||
public void setWeight(float value) {_weight = value;}
|
||||
public void setBodyColor(Color value) {_bodyColor = value;}
|
||||
|
||||
public EntityMonorail(int speed, float weight, Color bodyColor){
|
||||
Random rnd = new Random();
|
||||
_speed = speed <= 0 ? rnd.nextInt(50)+10 : speed;
|
||||
|
||||
@@ -105,7 +105,7 @@ public class FormAdditionalCollection extends JFrame {
|
||||
public void AddWheels() {
|
||||
for (int i = 0; i < _additionalCollection.CountWheels; i++) {
|
||||
random = new Random();
|
||||
EntityMonorail entity = _additionalCollection._collectionEntity[i];
|
||||
EntityMonorail entity = _additionalCollection.CollectionEntity[i];
|
||||
DrawingWheels drawingWheels = null;
|
||||
drawingWheels = new DrawingWheels();
|
||||
drawingWheels.SetCountWheels((int) ((Math.random() * 3) + 1) * 2);
|
||||
@@ -119,12 +119,12 @@ public class FormAdditionalCollection extends JFrame {
|
||||
this._company = company;
|
||||
String[] data1 = new String[_additionalCollection.CountEntities];
|
||||
for (int i = 0; i < _additionalCollection.CountEntities; i++) {
|
||||
EntityMonorail entity = _additionalCollection._collectionEntity[i];
|
||||
EntityMonorail entity = _additionalCollection.CollectionEntity[i];
|
||||
data1[i] = ToString(entity);
|
||||
}
|
||||
String[] data2 = new String[_additionalCollection.CountWheels];
|
||||
for (int i = 0; i < _additionalCollection.CountWheels; i++) {
|
||||
DrawingWheels wheels = _additionalCollection._collectionWheels[i];
|
||||
DrawingWheels wheels = _additionalCollection.CollectionWheels[i];
|
||||
data2[i] = ToString(wheels);
|
||||
}
|
||||
listEntity.setListData(data1);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package Scripts.Forms;
|
||||
|
||||
import Scripts.CollectionGenericObjects.AbstractCompany;
|
||||
import Scripts.CollectionGenericObjects.DepotSharingService;
|
||||
import Scripts.CollectionGenericObjects.MassiveGenericObjects;
|
||||
import Scripts.CollectionGenericObjects.*;
|
||||
import Scripts.Drawing.DrawingModernMonorail;
|
||||
import Scripts.Drawing.DrawingMonorail;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
@@ -18,9 +18,20 @@ public class FormMonorailCollection extends JFrame{
|
||||
private Dimension dimension;
|
||||
public static CanvasFormMonorailCollection<DrawingMonorail> _canvasMonorail = new CanvasFormMonorailCollection<DrawingMonorail>();
|
||||
private static AbstractCompany _company = null;
|
||||
private JButton CreateButton = new JButton("Создать современный монорельс");;
|
||||
private JButton CreateShipButton = new JButton("Создать монорельс");
|
||||
private JButton RemoveButton = new JButton("Удалить");
|
||||
|
||||
private Queue<DrawingMonorail> _collectionRemovedObjects = new LinkedList<DrawingMonorail>();
|
||||
private StorageCollection<DrawingMonorail> _storageCollection = new StorageCollection<DrawingMonorail>();
|
||||
private JTextField textBoxCollection = new JTextField();
|
||||
private JRadioButton radioButtonMassive = new JRadioButton("Массив");
|
||||
private JRadioButton radioButtonList = new JRadioButton("Список");
|
||||
private JButton buttonAddCollection = new JButton("Добавить");
|
||||
private JList listBoxCollection = new JList();
|
||||
private JButton buttonRemoveCollection = new JButton("Удалить");
|
||||
private JButton buttonCreateCompany = new JButton("Создать компанию");
|
||||
private JButton createMonorailButton = new JButton("Создать монорельс");
|
||||
private JButton removeButton = new JButton("Удалить");
|
||||
private JButton removeObjectsButton = new JButton("Удаленные объекты");
|
||||
|
||||
private JButton GoToCheckButton = new JButton("На проверку");
|
||||
private JButton RandomButton = new JButton("Случайные");
|
||||
private JButton RefreshButton = new JButton("Обновить");
|
||||
@@ -53,7 +64,7 @@ public class FormMonorailCollection extends JFrame{
|
||||
break;
|
||||
default: return;
|
||||
}
|
||||
if (_company._collection.Insert(drawingMonorail, 0) != -1) {
|
||||
if (_company._collection.Insert(drawingMonorail) != -1) {
|
||||
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
||||
canvasShow();
|
||||
}
|
||||
@@ -84,20 +95,17 @@ public class FormMonorailCollection extends JFrame{
|
||||
}
|
||||
});
|
||||
|
||||
CreateShipButton.addActionListener(new ActionListener() {
|
||||
createMonorailButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
CreateObject("DrawingMonorail");
|
||||
}
|
||||
});
|
||||
CreateButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
CreateObject("DrawingModernMonorail");
|
||||
if (_company == null) return;
|
||||
FormMonorailConfig form = new FormMonorailConfig("", new Dimension(800, 300));
|
||||
form.setCompany(_company);
|
||||
form.Init();
|
||||
}
|
||||
});
|
||||
|
||||
RemoveButton.addActionListener(new ActionListener() {
|
||||
removeButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_company == null || TextField.getText() == null) {
|
||||
@@ -106,12 +114,14 @@ public class FormMonorailCollection extends JFrame{
|
||||
int pos = parseInt(TextField.getText());
|
||||
int resultConfirmDialog = JOptionPane.showConfirmDialog(null, "Удалить", "Удаление", JOptionPane.YES_NO_OPTION);
|
||||
if (resultConfirmDialog == JOptionPane.NO_OPTION) return;
|
||||
if (_company._collection.Remove(pos) != null) {
|
||||
System.out.println(pos);
|
||||
|
||||
DrawingMonorail obj = _storageCollection.remove(listBoxCollection.getSelectedValue().toString(), pos);
|
||||
System.out.println(obj);
|
||||
if (obj != null) {
|
||||
JOptionPane.showMessageDialog(null, "Объект удален");
|
||||
_collectionRemovedObjects.add(obj);
|
||||
canvasShow();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
@@ -171,41 +181,135 @@ public class FormMonorailCollection extends JFrame{
|
||||
form.setCompany(_company);
|
||||
}
|
||||
});
|
||||
_canvasMonorail.setBounds(0, 0, getWidth()-200, getHeight());
|
||||
ComboBoxCollections.setBounds(getWidth()-190, 10, 150, 20);
|
||||
CreateShipButton.setBounds(getWidth()-190, 60, 150, 30);
|
||||
CreateButton.setBounds(getWidth()-190, 100, 150, 30);
|
||||
RandomButton.setBounds(getWidth()-190, 140, 150, 30);
|
||||
TextField.setBounds(getWidth()-190,200,150,30);
|
||||
RemoveButton.setBounds(getWidth()-190, 240, 150, 30);
|
||||
GoToCheckButton.setBounds(getWidth()-190, 280, 150, 30);
|
||||
RefreshButton.setBounds(getWidth()-190, getHeight()-90, 150, 30);
|
||||
|
||||
setSize(dimension.width,dimension.height);
|
||||
setLayout(null);
|
||||
add(_canvasMonorail);
|
||||
add(ComboBoxCollections);
|
||||
add(CreateShipButton);
|
||||
add(CreateButton);
|
||||
add(TextField);
|
||||
add(RemoveButton);
|
||||
add(GoToCheckButton);
|
||||
add(RandomButton);
|
||||
add(RefreshButton);
|
||||
setVisible(true);
|
||||
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
public void componentResized(ComponentEvent e) {
|
||||
_canvasMonorail.setBounds(0, 0, getWidth()-200, getHeight()-70);
|
||||
ComboBoxCollections.setBounds(getWidth()-190, 10, 150, 20);
|
||||
CreateShipButton.setBounds(getWidth()-190, 60, 150, 30);
|
||||
CreateButton.setBounds(getWidth()-190, 100, 150, 30);
|
||||
TextField.setBounds(getWidth()-190,200,150,30);
|
||||
RemoveButton.setBounds(getWidth()-190, 240, 150, 30);
|
||||
GoToCheckButton.setBounds(getWidth()-190, 280, 150, 30);
|
||||
RandomButton.setBounds(getWidth()-190, 140, 150, 30);
|
||||
RefreshButton.setBounds(getWidth()-190, getHeight()-90, 150, 30);
|
||||
buttonAddCollection.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (textBoxCollection.getText().isEmpty() || (!radioButtonMassive.isSelected()
|
||||
&& !radioButtonList.isSelected())) {
|
||||
JOptionPane.showMessageDialog(null, "Не все данные заполнены");
|
||||
return;
|
||||
}
|
||||
CollectionType collectionType = CollectionType.None;
|
||||
if (radioButtonMassive.isSelected()) {
|
||||
collectionType = CollectionType.Massive;
|
||||
} else if (radioButtonList.isSelected()) {
|
||||
collectionType = CollectionType.List;
|
||||
}
|
||||
_storageCollection.SetCollectionObject(textBoxCollection.getText(), collectionType);
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
});
|
||||
|
||||
buttonRemoveCollection.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (listBoxCollection.getSelectedIndex() < 0 || listBoxCollection.getSelectedValue() == null) {
|
||||
JOptionPane.showMessageDialog(null, "Коллекция не выбрана");
|
||||
return;
|
||||
}
|
||||
int resultConfirmDialog = JOptionPane.showConfirmDialog(null,
|
||||
"Удалить", "Удаление",
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
if (resultConfirmDialog == JOptionPane.NO_OPTION) return;
|
||||
_storageCollection.DelCollection(listBoxCollection.getSelectedValue().toString());
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
});
|
||||
|
||||
buttonCreateCompany.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (listBoxCollection.getSelectedIndex() < 0 || listBoxCollection.getSelectedValue() == null) {
|
||||
JOptionPane.showMessageDialog(null, "Коллекция не выбрана");
|
||||
return;
|
||||
}
|
||||
ICollectionGenericObjects<DrawingMonorail> collection =
|
||||
_storageCollection.GetCollectionObject(listBoxCollection.getSelectedValue().toString());
|
||||
if (collection == null) {
|
||||
JOptionPane.showMessageDialog(null, "Коллекция не проинициализирована");
|
||||
return;
|
||||
}
|
||||
switch (ComboBoxCollections.getSelectedItem().toString()) {
|
||||
case "Хранилище":
|
||||
_company = new DepotSharingService(getWidth() - 200, getHeight() - 110,
|
||||
collection);
|
||||
break;
|
||||
}
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
});
|
||||
|
||||
removeObjectsButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_collectionRemovedObjects.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(null, "Коллекция пуста");
|
||||
return;
|
||||
}
|
||||
DrawingMonorail drawingMonorail = null;
|
||||
drawingMonorail = _collectionRemovedObjects.remove();
|
||||
if (drawingMonorail == null) {
|
||||
return;
|
||||
}
|
||||
FormModernMonorail form = new FormModernMonorail();
|
||||
form.Init(drawingMonorail);
|
||||
}
|
||||
});
|
||||
|
||||
ButtonGroup radioButtonsGroup = new ButtonGroup();
|
||||
JLabel labelCollectionName = new JLabel("Название коллекции");
|
||||
radioButtonsGroup.add(radioButtonMassive);
|
||||
radioButtonsGroup.add(radioButtonList);
|
||||
_canvasMonorail.setBounds(0, 0, getWidth() - 200, getHeight());
|
||||
labelCollectionName.setBounds(getWidth()-190, 10, 150, 20);
|
||||
textBoxCollection.setBounds(getWidth()-190,35,150,25);
|
||||
radioButtonMassive.setBounds(getWidth()-190, 60, 75, 20);
|
||||
radioButtonList.setBounds(getWidth()-105, 60, 75, 20);
|
||||
buttonAddCollection.setBounds(getWidth()-190, 85, 150, 20);
|
||||
listBoxCollection.setBounds(getWidth()-190, 115, 150, 70);
|
||||
buttonRemoveCollection.setBounds(getWidth()-190, 195, 150, 20);
|
||||
ComboBoxCollections.setBounds(getWidth() - 190, 225, 150, 20);
|
||||
buttonCreateCompany.setBounds(getWidth()-190, 255, 150, 20);
|
||||
createMonorailButton.setBounds(getWidth() - 190, 285, 150, 30);
|
||||
RandomButton.setBounds(getWidth() - 190, 365, 150, 30);
|
||||
removeObjectsButton.setBounds(getWidth()-190, 505, 150, 30);
|
||||
TextField.setBounds(getWidth() - 190, 545, 150, 30);
|
||||
removeButton.setBounds(getWidth() - 190, 585, 150, 30);
|
||||
GoToCheckButton.setBounds(getWidth() - 190, 625, 150, 30);
|
||||
RefreshButton.setBounds(getWidth() - 190, 665, 150, 30);
|
||||
setSize(dimension.width, dimension.height);
|
||||
setLayout(null);
|
||||
|
||||
add(textBoxCollection);
|
||||
add(radioButtonMassive);
|
||||
add(radioButtonList);
|
||||
add(buttonAddCollection);
|
||||
add(listBoxCollection);
|
||||
add(buttonRemoveCollection);
|
||||
add(buttonCreateCompany);
|
||||
add(labelCollectionName);
|
||||
add(removeObjectsButton);
|
||||
|
||||
add(_canvasMonorail);
|
||||
add(ComboBoxCollections);
|
||||
add(createMonorailButton);
|
||||
add(TextField);
|
||||
add(GoToCheckButton);
|
||||
add(RandomButton);
|
||||
add(removeButton);
|
||||
add(RefreshButton);
|
||||
setVisible(true);
|
||||
}
|
||||
private void RerfreshListBoxItems() {
|
||||
DefaultListModel<String> list = new DefaultListModel<String>();
|
||||
for (String name : _storageCollection.Keys()) {
|
||||
if (name != "") {
|
||||
list.addElement(name);
|
||||
}
|
||||
}
|
||||
|
||||
listBoxCollection.setModel(list);
|
||||
}
|
||||
|
||||
}
|
||||
453
ProjectMonorail/src/Scripts/Forms/FormMonorailConfig.java
Normal file
453
ProjectMonorail/src/Scripts/Forms/FormMonorailConfig.java
Normal file
@@ -0,0 +1,453 @@
|
||||
package Scripts.Forms;
|
||||
|
||||
import Scripts.CollectionGenericObjects.AbstractCompany;
|
||||
import Scripts.Drawing.DrawingModernMonorail;
|
||||
import Scripts.Drawing.DrawingMonorail;
|
||||
import Scripts.Entities.EntityModernMonorail;
|
||||
import Scripts.Wheels.*;
|
||||
|
||||
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.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FormMonorailConfig extends JFrame {
|
||||
private String title;
|
||||
private Dimension dimension;
|
||||
private DrawingMonorail _drawingMonorail;
|
||||
private AbstractCompany company = null;
|
||||
private JLabel labelSpeed = new JLabel("Скорость");
|
||||
private JLabel labelWeight = new JLabel("Вес");
|
||||
private JLabel labelNumberOfWheels = new JLabel("Колеса");
|
||||
|
||||
private JLabel labelMonorail = new JLabel("Monorail", SwingConstants.CENTER);
|
||||
private JLabel labelModernMonorail = new JLabel("ModernMonorail", SwingConstants.CENTER);
|
||||
private JLabel labelColor = new JLabel("Цвета");
|
||||
private JLabel labelBodyColor = new JLabel("Основной цвет", SwingConstants.CENTER);
|
||||
private JLabel labelAdditionalColor = new JLabel("Дополнительный цвет", SwingConstants.CENTER);
|
||||
private JLabel labelWheels = new JLabel("Тип двигателей",SwingConstants.CENTER);
|
||||
private JLabel labelDefaultWheels = new JLabel("Классические",SwingConstants.CENTER);
|
||||
private JLabel labelOvalOrnament = new JLabel("Овальные", SwingConstants.CENTER);
|
||||
private JLabel labelTriangleOrnament = new JLabel("Треугольные", SwingConstants.CENTER);
|
||||
|
||||
private JSpinner spinnerSpeed = new JSpinner();
|
||||
private JSpinner spinnerWeight = new JSpinner();
|
||||
private JSpinner spinnerNumberOfWheels = new JSpinner();
|
||||
private JCheckBox checkBoxMonorailTrack = new JCheckBox("Имеет путь");
|
||||
private JCheckBox checkBoxCabin = new JCheckBox("Имеет кабину");
|
||||
private JComponent panelObject = new JPanel();
|
||||
private JPanel panelColorRed = new JPanel();
|
||||
private JPanel panelColorGreen = new JPanel();
|
||||
private JPanel panelColorBlue = new JPanel();
|
||||
private JPanel panelColorYellow = new JPanel();
|
||||
private JPanel panelColorBlack = new JPanel();
|
||||
private JPanel panelColorWhite = new JPanel();
|
||||
private JPanel panelColorGray = new JPanel();
|
||||
private JPanel panelColorCyan = new JPanel();
|
||||
private JButton buttonAdd = new JButton("Добавить");
|
||||
private JButton buttonCancel = new JButton("Отмена");
|
||||
|
||||
public FormMonorailConfig(String title, Dimension dimension) {
|
||||
this.title = title;
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
||||
public void Init() {
|
||||
SpinnerModel numSpeed = new SpinnerNumberModel(100, 100, 1000, 1);
|
||||
SpinnerModel numWeight = new SpinnerNumberModel(100, 100, 1000, 1);
|
||||
spinnerSpeed.setModel(numSpeed);
|
||||
spinnerWeight.setModel(numWeight);
|
||||
SpinnerModel numWheels = new SpinnerNumberModel(2, 2, 4, 1);
|
||||
spinnerNumberOfWheels.setModel(numWheels);
|
||||
panelObject = new Canvas();
|
||||
panelObject.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
|
||||
spinnerSpeed.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
if (_drawingMonorail == null) return;
|
||||
_drawingMonorail.getMonorail().setSpeed((int)spinnerSpeed.getValue());
|
||||
}
|
||||
});
|
||||
spinnerWeight.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
if (_drawingMonorail == null) return;
|
||||
_drawingMonorail.getMonorail().setWeight((int)spinnerWeight.getValue());
|
||||
}
|
||||
});
|
||||
|
||||
spinnerNumberOfWheels.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
if(_drawingMonorail ==null)return;
|
||||
_drawingMonorail._wheels.SetCountWheels((int) spinnerNumberOfWheels.getValue());
|
||||
panelObject.repaint();
|
||||
}
|
||||
});
|
||||
checkBoxMonorailTrack.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_drawingMonorail == null) return;
|
||||
if (_drawingMonorail.getMonorail() instanceof EntityModernMonorail entityModernMonorail) {
|
||||
entityModernMonorail.setMonorailTrack(checkBoxMonorailTrack.isSelected());
|
||||
panelObject.repaint();
|
||||
}
|
||||
}
|
||||
});
|
||||
checkBoxCabin.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_drawingMonorail == null) return;
|
||||
if (_drawingMonorail.getMonorail() instanceof EntityModernMonorail entityModernMonorail) {
|
||||
entityModernMonorail.setCabin(checkBoxCabin.isSelected());
|
||||
panelObject.repaint();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
labelMonorail.setBackground(Color.WHITE);
|
||||
labelModernMonorail.setBackground(Color.WHITE);
|
||||
labelMonorail.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
labelModernMonorail.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
labelBodyColor.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
labelAdditionalColor.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
labelDefaultWheels.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
labelOvalOrnament.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
labelTriangleOrnament.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
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());
|
||||
}
|
||||
};
|
||||
|
||||
labelMonorail.addMouseListener(labelObjectsMouseDown);
|
||||
labelMonorail.setTransferHandler(labelObjectsTransferHandler);
|
||||
labelModernMonorail.addMouseListener(labelObjectsMouseDown);
|
||||
labelModernMonorail.setTransferHandler(labelObjectsTransferHandler);
|
||||
|
||||
MouseAdapter labelWheelsMouseDown = new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
((JLabel) e.getComponent()).getTransferHandler().exportAsDrag(((JLabel) e.getComponent()), e, TransferHandler.COPY);
|
||||
}
|
||||
};
|
||||
|
||||
labelDefaultWheels.addMouseListener(labelWheelsMouseDown);
|
||||
labelOvalOrnament.addMouseListener(labelWheelsMouseDown);
|
||||
labelTriangleOrnament.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 DrawingWheels());
|
||||
}
|
||||
});
|
||||
labelOvalOrnament.setTransferHandler(new TransferHandler() {
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {return TransferHandler.COPY;}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new WheelsTransferable(new DrawOrnamentOval());
|
||||
}
|
||||
});
|
||||
labelTriangleOrnament.setTransferHandler(new TransferHandler() {
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {return TransferHandler.COPY;}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new WheelsTransferable(new DrawOrnamentTriangle());
|
||||
}
|
||||
});
|
||||
|
||||
panelObject.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)) {
|
||||
try {
|
||||
String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
|
||||
|
||||
switch (data) {
|
||||
case "Monorail":
|
||||
_drawingMonorail = new DrawingMonorail((int) spinnerSpeed.getValue(), (int) spinnerWeight.getValue(), Color.WHITE);
|
||||
break;
|
||||
case "ModernMonorail":
|
||||
_drawingMonorail = new DrawingModernMonorail((int) spinnerSpeed.getValue(), (int) spinnerWeight.getValue(),
|
||||
Color.DARK_GRAY, Color.BLACK, checkBoxMonorailTrack.isSelected(), checkBoxCabin.isSelected());
|
||||
break;
|
||||
}
|
||||
if (_drawingMonorail != null) {
|
||||
_drawingMonorail._wheels = new DrawingWheels();
|
||||
_drawingMonorail._wheels.SetCountWheels((int) spinnerNumberOfWheels.getValue());
|
||||
_drawingMonorail.SetPictureSize(400,150);
|
||||
_drawingMonorail.SetPosition(10,40);
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
catch (UnsupportedFlavorException | IOException e) {}
|
||||
try {
|
||||
IDrawingWheels wheels =
|
||||
(IDrawingWheels) support.getTransferable().getTransferData(WheelsTransferable.wheelsDataFlavor);
|
||||
_drawingMonorail._wheels = wheels;
|
||||
_drawingMonorail._wheels.SetCountWheels((int) spinnerNumberOfWheels.getValue());
|
||||
|
||||
}catch (UnsupportedFlavorException | IOException e) {}
|
||||
panelObject.repaint();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
JPanel[] colorPanels = {
|
||||
panelColorRed,
|
||||
panelColorGreen,
|
||||
panelColorBlue,
|
||||
panelColorYellow,
|
||||
panelColorWhite,
|
||||
panelColorBlack,
|
||||
panelColorGray,
|
||||
panelColorCyan,
|
||||
};
|
||||
panelColorRed.setBackground(Color.RED);
|
||||
panelColorGreen.setBackground(Color.GREEN);
|
||||
panelColorBlue.setBackground(Color.BLUE);
|
||||
panelColorYellow.setBackground(Color.YELLOW);
|
||||
panelColorWhite.setBackground(Color.WHITE);
|
||||
panelColorBlack.setBackground(Color.BLACK);
|
||||
panelColorGray.setBackground(Color.GRAY);
|
||||
panelColorCyan.setBackground(Color.CYAN);
|
||||
MouseAdapter colorMouseDown = new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
((JPanel) e.getComponent()).getTransferHandler().exportAsDrag(((JPanel) e.getComponent()), e, TransferHandler.COPY);
|
||||
}
|
||||
};
|
||||
for (var panelColor : colorPanels) {
|
||||
panelColor.addMouseListener(colorMouseDown);
|
||||
panelColor.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 (_drawingMonorail == null) return false;
|
||||
_drawingMonorail.getMonorail().setBodyColor(color);
|
||||
return true;
|
||||
} catch (UnsupportedFlavorException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
labelAdditionalColor.setTransferHandler(new TransferHandler() {
|
||||
@Override
|
||||
public boolean canImport(TransferHandler.TransferSupport support) {
|
||||
if (!(_drawingMonorail instanceof DrawingModernMonorail)) return false;
|
||||
return support.isDataFlavorSupported(ColorTransferable.colorDataFlavor);
|
||||
}
|
||||
@Override
|
||||
public boolean importData(TransferSupport support) {
|
||||
try {
|
||||
Color color = (Color) support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor);
|
||||
if (_drawingMonorail == null) return false;
|
||||
if (_drawingMonorail.getMonorail() instanceof EntityModernMonorail) {
|
||||
((EntityModernMonorail)_drawingMonorail.getMonorail()).setAdditionalColor(color);
|
||||
labelColor.setBackground(color);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (UnsupportedFlavorException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
buttonAdd.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_drawingMonorail == null) return;
|
||||
|
||||
company._collection.Insert(_drawingMonorail);
|
||||
FormMonorailCollection.canvasShow();
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
buttonCancel.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
labelSpeed.setBounds(8, 17, 75, 15);
|
||||
labelWeight.setBounds(8,43, 75, 15);
|
||||
labelNumberOfWheels.setBounds(8, 68, 75, 15);
|
||||
labelMonorail.setBounds(8,150,105,30);
|
||||
labelModernMonorail.setBounds(8,190,110,30);
|
||||
checkBoxMonorailTrack.setBounds(8,85,150,20);
|
||||
checkBoxCabin.setBounds(8,105,150,20);
|
||||
spinnerSpeed.setBounds(80,15, 60,20);
|
||||
spinnerWeight.setBounds(80,40, 60,20);
|
||||
spinnerNumberOfWheels.setBounds(80, 65,60,20);
|
||||
panelObject.setBounds(555,50,400,150);
|
||||
labelBodyColor.setBounds(500,5,100, 40);
|
||||
labelAdditionalColor.setBounds(605,5,170,40);
|
||||
labelWheels.setBounds(225,190,150,15);
|
||||
labelDefaultWheels.setBounds(140, 210, 100, 40);
|
||||
labelOvalOrnament.setBounds(250, 210, 100,40);
|
||||
labelTriangleOrnament.setBounds(360,210,100,40);
|
||||
labelColor.setBounds(200,10,50,15);
|
||||
panelColorRed.setBounds(200, 30, 40, 40);
|
||||
panelColorGreen.setBounds(250, 30, 40,40);
|
||||
panelColorBlue.setBounds(300,30,40,40);
|
||||
panelColorYellow.setBounds(350,30,40,40);
|
||||
panelColorWhite.setBounds(200, 80,40,40);
|
||||
panelColorBlack.setBounds(250,80,40,40);
|
||||
panelColorGray.setBounds(300,80,40,40);
|
||||
panelColorCyan.setBounds(350,80,40,40);
|
||||
buttonAdd.setBounds(515, 210, 110, 40);
|
||||
buttonCancel.setBounds(640, 210, 110, 40);
|
||||
setSize(dimension.width, dimension.height);
|
||||
setLayout(null);
|
||||
add(labelSpeed);
|
||||
add(labelWeight);
|
||||
add(labelNumberOfWheels);
|
||||
add(labelMonorail);
|
||||
add(labelModernMonorail);
|
||||
add(labelColor);
|
||||
add(labelBodyColor);
|
||||
add(labelAdditionalColor);
|
||||
add(labelDefaultWheels);
|
||||
add(labelDefaultWheels);
|
||||
add(labelOvalOrnament);
|
||||
add(labelTriangleOrnament);
|
||||
add(spinnerSpeed);
|
||||
add(spinnerWeight);
|
||||
add(spinnerNumberOfWheels);
|
||||
add(checkBoxMonorailTrack);
|
||||
add(checkBoxCabin);
|
||||
add(panelObject);
|
||||
add(panelColorRed);
|
||||
add(panelColorGreen);
|
||||
add(panelColorBlue);
|
||||
add(panelColorYellow);
|
||||
add(panelColorWhite);
|
||||
add(labelWheels);
|
||||
add(panelColorBlack);
|
||||
add(panelColorGray);
|
||||
add(panelColorCyan);
|
||||
add(buttonAdd);
|
||||
add(buttonCancel);
|
||||
setVisible(true);
|
||||
}
|
||||
public void setCompany(AbstractCompany company) {
|
||||
this.company = company;
|
||||
}
|
||||
private class Canvas extends JComponent {
|
||||
public Canvas() {
|
||||
}
|
||||
public void paintComponent(Graphics g) {
|
||||
if (_drawingMonorail == null) {
|
||||
return;
|
||||
}
|
||||
super.paintComponents(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
_drawingMonorail.DrawTransport(g2d);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
||||
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 IDrawingWheels wheels;
|
||||
private static final DataFlavor wheelsDataFlavor = new DataFlavor(IDrawingWheels.class, "Wheels");
|
||||
public WheelsTransferable(IDrawingWheels iDrawingWheels) {
|
||||
this.wheels = iDrawingWheels;
|
||||
}
|
||||
public WheelsTransferable(IOrnament ornament) {
|
||||
this.wheels = new DrawingWheels();
|
||||
wheels.SetOrnament(ornament);
|
||||
}
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
13
ProjectMonorail/src/Scripts/Forms/FormShipConfig.form
Normal file
13
ProjectMonorail/src/Scripts/Forms/FormShipConfig.form
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="Scripts.Forms.FormMonorailConfig">
|
||||
<grid id="27dc6" row-count="1" column-count="1" layout-manager="GridLayoutManager">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -7,14 +7,16 @@ import java.util.Random;
|
||||
|
||||
public class DrawingWheels implements IDrawingWheels{
|
||||
private CountWheels _wheels;
|
||||
private IOrnament _ornament;
|
||||
private int _seedOrnament;
|
||||
private IOrnament _ornament;
|
||||
|
||||
public void SetOrnament(IOrnament ornament) {
|
||||
_ornament = ornament;
|
||||
}
|
||||
|
||||
public void SetCountWheels(int Count){
|
||||
for (CountWheels temp: CountWheels.values())
|
||||
if (temp.getCountWheels() == Count){
|
||||
Random rnd = new Random();
|
||||
_seedOrnament = rnd.nextInt(0, 3);
|
||||
_wheels=temp;
|
||||
return;
|
||||
}
|
||||
@@ -29,18 +31,7 @@ public class DrawingWheels implements IDrawingWheels{
|
||||
}
|
||||
|
||||
public void DrawWheels(Graphics2D g,int startPosX[], int startPosY, Color color) {
|
||||
switch (_seedOrnament) {
|
||||
case 0:
|
||||
_ornament = new DrawOrnament();
|
||||
break;
|
||||
case 1:
|
||||
_ornament = new DrawOrnamentTriangle();
|
||||
break;
|
||||
case 2:
|
||||
_ornament = new DrawOrnamentOval();
|
||||
break;
|
||||
}
|
||||
|
||||
if (_ornament == null) _ornament = new DrawOrnament();
|
||||
for (int i = 0; i < startPosX.length; i++) {
|
||||
g.setColor(color);
|
||||
g.drawOval(startPosX[i], startPosY, 10, 10);
|
||||
|
||||
@@ -3,6 +3,7 @@ package Scripts.Wheels;
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawingWheels {
|
||||
public void SetOrnament(IOrnament ornament);
|
||||
public void SetCountWheels(int Count);
|
||||
public int getCountWheels();
|
||||
public void DrawWheels(Graphics2D g, int startPosX[], int startPosY, Color color);
|
||||
|
||||
Reference in New Issue
Block a user