Compare commits
3 Commits
LabWorking
...
LabWorking
| Author | SHA1 | Date | |
|---|---|---|---|
| 89940488db | |||
| 6d230a8bb7 | |||
| 6e048994f4 |
11
ProjectMonorail/.idea/workspace.xml
generated
11
ProjectMonorail/.idea/workspace.xml
generated
@@ -5,11 +5,14 @@
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="39e7c520-e505-4e53-a269-c949d7c9f5d1" name="Changes" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/src/Scripts/Drawing/ExtentionDrawningMonorail.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" 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/ICollectionGenericObjects.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Scripts/CollectionGenericObjects/ICollectionGenericObjects.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Scripts/CollectionGenericObjects/ListGenericObjects.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Scripts/CollectionGenericObjects/ListGenericObjects.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Scripts/CollectionGenericObjects/MassiveGenericObjects.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Scripts/CollectionGenericObjects/MassiveGenericObjects.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Scripts/CollectionGenericObjects/StorageCollection.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Scripts/CollectionGenericObjects/StorageCollection.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/Entities/EntityModernMonorail.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Scripts/Entities/EntityModernMonorail.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Scripts/Entities/EntityMonorail.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Scripts/Entities/EntityMonorail.java" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -41,7 +44,7 @@
|
||||
"Application.Program.executor": "Run",
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"git-widget-placeholder": "LabWorking__4",
|
||||
"git-widget-placeholder": "LabWorking__6",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "C:/Учеба/AgarioGame"
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -7,4 +7,7 @@ public interface ICollectionGenericObjects<T>
|
||||
int Insert(T obj);
|
||||
T Remove(int position);
|
||||
T Get(int position);
|
||||
CollectionType GetCollectionType();
|
||||
Iterable<T> GetItems();
|
||||
void ClearCollection();
|
||||
}
|
||||
@@ -1,16 +1,24 @@
|
||||
package Scripts.CollectionGenericObjects;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
public class ListGenericObjects<T> implements ICollectionGenericObjects<T> {
|
||||
private List<T> _collection;
|
||||
private CollectionType collectionType = CollectionType.List;
|
||||
private int _maxCount;
|
||||
|
||||
public int getCount() {
|
||||
return _collection.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionType GetCollectionType() {
|
||||
return collectionType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SetMaxCount(int size) {
|
||||
if (size > 0) {
|
||||
@@ -45,4 +53,36 @@ public class ListGenericObjects<T> implements ICollectionGenericObjects<T> {
|
||||
_collection.remove(position);
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> GetItems() {
|
||||
return new Iterable<T>() {
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return new Iterator<T>() {
|
||||
private int currentIndex = 0;
|
||||
//нужен ли count
|
||||
private int count = 0;
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return currentIndex < getCount();
|
||||
}
|
||||
@Override
|
||||
public T next() {
|
||||
if (hasNext()) {
|
||||
count++;
|
||||
return _collection.get(currentIndex++);
|
||||
}
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
@Override
|
||||
public void ClearCollection() {
|
||||
for (T ship : _collection) {
|
||||
ship = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,13 @@ package Scripts.CollectionGenericObjects;
|
||||
import Scripts.Drawing.DrawingMonorail;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T>
|
||||
{
|
||||
private T[] _collection;
|
||||
private CollectionType collectionType = CollectionType.Massive;
|
||||
private int Count;
|
||||
public void SetMaxCount(int size) {
|
||||
if (size > 0) {
|
||||
@@ -17,6 +20,11 @@ public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T>
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionType GetCollectionType() {
|
||||
return collectionType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return Count;
|
||||
@@ -49,4 +57,36 @@ public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T>
|
||||
if (position >= getCount() || position < 0) return null;
|
||||
return (T) _collection[position];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> GetItems() {
|
||||
return new Iterable<T>() {
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return new Iterator<T>() {
|
||||
private int currentIndex = 0;
|
||||
//нужен ли count
|
||||
private int count = 0;
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return currentIndex < getCount();
|
||||
}
|
||||
@Override
|
||||
public T next() {
|
||||
if (hasNext()) {
|
||||
count++;
|
||||
return _collection[currentIndex++];
|
||||
}
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
@Override
|
||||
public void ClearCollection() {
|
||||
for (T ship : _collection) {
|
||||
ship = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package Scripts.CollectionGenericObjects;
|
||||
|
||||
import Scripts.Drawing.DrawingMonorail;
|
||||
import Scripts.Drawing.ExtentionDrawningMonorail;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class StorageCollection<T> {
|
||||
public class StorageCollection<T extends DrawingMonorail> {
|
||||
private Map<String, ICollectionGenericObjects<T>> _storages;
|
||||
public StorageCollection()
|
||||
{
|
||||
@@ -38,4 +42,154 @@ public class StorageCollection<T> {
|
||||
return null;
|
||||
}
|
||||
|
||||
private String _collectionKey = "CollectionsStorage";
|
||||
private String _collectionName = "StorageCollection";
|
||||
private String _separatorForKeyValueS = "|";
|
||||
private String _separatorForKeyValue = "\\|";
|
||||
private String _separatorItemsS = ";";
|
||||
private String _separatorItems = "\\;";
|
||||
public boolean SaveData(String filename) {
|
||||
if (_storages.isEmpty()) return false;
|
||||
File file = new File(filename);
|
||||
if (file.exists()) file.delete();
|
||||
try {
|
||||
file.createNewFile();
|
||||
FileWriter writer = new FileWriter(file);
|
||||
writer.write(_collectionKey);
|
||||
writer.write("\n");
|
||||
for (Map.Entry<String, ICollectionGenericObjects<T>> value : _storages.entrySet()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(value.getKey());
|
||||
sb.append(_separatorForKeyValueS);
|
||||
sb.append(value.getValue().GetCollectionType());
|
||||
sb.append(_separatorForKeyValueS);
|
||||
sb.append(value.getValue().getCount());
|
||||
sb.append(_separatorForKeyValueS);
|
||||
for (T monorail : value.getValue().GetItems()) {
|
||||
String data = ExtentionDrawningMonorail.GetDataForSave((DrawingMonorail) monorail);
|
||||
if (data.isEmpty()) continue;
|
||||
sb.append(data);
|
||||
sb.append(_separatorItemsS);
|
||||
}
|
||||
sb.append("\n");
|
||||
writer.write(String.valueOf(sb));
|
||||
}
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public boolean SaveOneCollection(String filename, String name) {
|
||||
if (_storages.isEmpty()) return false;
|
||||
File file = new File(filename);
|
||||
if (file.exists()) file.delete();
|
||||
try {
|
||||
file.createNewFile();
|
||||
FileWriter writer = new FileWriter(file);
|
||||
writer.write(_collectionName);
|
||||
writer.write("\n");
|
||||
ICollectionGenericObjects<T> value = _storages.get(name);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(name);
|
||||
sb.append(_separatorForKeyValueS);
|
||||
sb.append(value.GetCollectionType());
|
||||
sb.append(_separatorForKeyValueS);
|
||||
sb.append(value.getCount());
|
||||
sb.append(_separatorForKeyValueS);
|
||||
for (T monorail : value.GetItems()) {
|
||||
String data = ExtentionDrawningMonorail.GetDataForSave((DrawingMonorail) monorail);
|
||||
if (data.isEmpty()) continue;
|
||||
sb.append(data);
|
||||
sb.append(_separatorItemsS);
|
||||
}
|
||||
writer.append(sb);
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public boolean LoadData(String filename) {
|
||||
File file = new File(filename);
|
||||
if (!file.exists()) return false;
|
||||
try (BufferedReader fs = new BufferedReader(new FileReader(filename))) {
|
||||
String s = fs.readLine();
|
||||
if (s == null || s.isEmpty() || !s.startsWith(_collectionKey))
|
||||
return false;
|
||||
_storages.clear();
|
||||
s = "";
|
||||
while ((s = fs.readLine()) != null) {
|
||||
String[] record = s.split(_separatorForKeyValue);
|
||||
if (record.length != 4) {
|
||||
continue;
|
||||
}
|
||||
ICollectionGenericObjects<T> collection = CreateCollection(record[1]);
|
||||
if (collection == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
collection.SetMaxCount(Integer.parseInt(record[2]));
|
||||
String[] set = record[3].split(_separatorItems);
|
||||
for (String elem : set) {
|
||||
DrawingMonorail ship = ExtentionDrawningMonorail.CreateDrawingShip(elem);
|
||||
if (collection.Insert((T) ship) == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
_storages.put(record[0], collection);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
public boolean LoadOneCollection(String filename) {
|
||||
File file = new File(filename);
|
||||
if (!file.exists()) return false;
|
||||
try (BufferedReader fs = new BufferedReader(new FileReader(filename))) {
|
||||
String s = fs.readLine();
|
||||
if (s == null || s.isEmpty() || !s.startsWith(_collectionName))
|
||||
return false;
|
||||
if (_storages.containsKey(s)) {
|
||||
_storages.get(s).ClearCollection();
|
||||
}
|
||||
s = fs.readLine();
|
||||
String[] record = s.split(_separatorForKeyValue);
|
||||
if (record.length != 4) {
|
||||
return false;
|
||||
}
|
||||
ICollectionGenericObjects<T> collection = CreateCollection(record[1]);
|
||||
if (collection == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
collection.SetMaxCount(Integer.parseInt(record[2]));
|
||||
String[] set = record[3].split(_separatorItems);
|
||||
for (String elem : set) {
|
||||
DrawingMonorail monorail = ExtentionDrawningMonorail.CreateDrawingShip(elem);
|
||||
if (collection.Insert((T) monorail) == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
_storages.put(record[0], collection);
|
||||
return true;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
public ICollectionGenericObjects<T> CreateCollection(String s) {
|
||||
switch (s) {
|
||||
case "Massive":
|
||||
return new MassiveGenericObjects<T>();
|
||||
case "List":
|
||||
return new ListGenericObjects<T>();
|
||||
}
|
||||
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();
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package Scripts.Drawing;
|
||||
|
||||
import Scripts.Entities.EntityModernMonorail;
|
||||
import Scripts.Entities.EntityMonorail;
|
||||
import Scripts.Wheels.IDrawingWheels;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
public class ExtentionDrawningMonorail {
|
||||
private static String _separatorForObjectS = ":";
|
||||
private static String _separatorForObject = "\\:";
|
||||
public static DrawingMonorail CreateDrawingShip(String info) {
|
||||
String[] strs = info.split(_separatorForObject);
|
||||
EntityMonorail entityMonorail;
|
||||
IDrawingWheels wheels = null;
|
||||
if (strs.length == 8)
|
||||
{
|
||||
String s = strs[8];
|
||||
switch (s) {
|
||||
case "DrawingDecksType1":
|
||||
wheels = new DrawingDecksType1();
|
||||
case "DrawingDecksType2":
|
||||
wheels = new DrawingDecksType2();
|
||||
case "DrawingDecksType3":
|
||||
wheels = new DrawingDecksType3();
|
||||
}
|
||||
if (wheels != null) wheels.SetCountWheels(Integer.parseInt(strs[7]));
|
||||
}
|
||||
else if (strs.length == 6) {
|
||||
String s = strs[5];
|
||||
switch (s) {
|
||||
case "DrawingDecksType1":
|
||||
wheels = new DrawingDecksType1();
|
||||
case "DrawingDecksType2":
|
||||
wheels = new DrawingDecksType2();
|
||||
case "DrawingDecksType3":
|
||||
wheels = new DrawingDecksType3();
|
||||
}
|
||||
if (wheels != null) wheels.SetCountWheels(Integer.parseInt(strs[4]));
|
||||
}
|
||||
entityMonorail = EntityModernMonorail.CreateEntityModernMonorail(strs);
|
||||
if (entityMonorail != null)
|
||||
{
|
||||
return new DrawingModernMonorail((EntityModernMonorail) entityMonorail, wheels);
|
||||
}
|
||||
entityMonorail = EntityMonorail.CreateEntityMonorail(strs);
|
||||
if (entityMonorail != null)
|
||||
{
|
||||
return new DrawingMonorail(entityMonorail, wheels);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static String GetDataForSave(DrawingMonorail drawningMonorail)
|
||||
{
|
||||
if (drawningMonorail == null) return "";
|
||||
String[] array1 = drawningMonorail.getMonorail().GetStringRepresentation();
|
||||
String[] array2 = drawningMonorail.GetStringRepresentationDecks();
|
||||
if (array1 == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
Collections.addAll(list, array1);
|
||||
if (array2 == null) {
|
||||
Collections.addAll(list, "0", " ");
|
||||
}
|
||||
else Collections.addAll(list, array2);
|
||||
return String.join(_separatorForObjectS, list);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package Scripts.Entities;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
public class EntityModernMonorail extends EntityMonorail {
|
||||
@@ -12,6 +13,10 @@ public class EntityModernMonorail extends EntityMonorail {
|
||||
public boolean getMonorailTrack() {return _monorailTrack;}
|
||||
public boolean getCabin() {return _cabin;}
|
||||
|
||||
public void setAdditionalColor(Color value) {_additionalColor = _additionalColor;}
|
||||
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();
|
||||
@@ -22,7 +27,25 @@ public class EntityModernMonorail extends EntityMonorail {
|
||||
_monorailTrack = monorailTrack;
|
||||
_cabin = cabin;
|
||||
|
||||
Step = _speed * 100/ (int)_weight;
|
||||
Step = _speed * 100/ (float)_weight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] GetStringRepresentation()
|
||||
{
|
||||
return new String[]{"EntityModernMonorail", _speed.toString(), _weight.toString(),
|
||||
colorToHexString(getBodyColor()), colorToHexString(getAdditionalColor()),
|
||||
String.valueOf(_monorailTrack), String.valueOf(_cabin)};
|
||||
}
|
||||
|
||||
public static EntityModernMonorail CreateEntityModernMonorail(String[] strs)
|
||||
{
|
||||
if (strs.length != 10 || !Objects.equals(strs[0], "EntityModernMonorail"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new EntityModernMonorail(Integer.parseInt(strs[1]), Float.parseFloat(strs[2]), hexStringToColor(strs[3]),
|
||||
hexStringToColor(strs[4]), Boolean.parseBoolean(strs[5]), Boolean.parseBoolean(strs[6]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package Scripts.Entities;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
public class EntityMonorail {
|
||||
public float Step;
|
||||
protected int _speed;
|
||||
protected float _weight;
|
||||
protected Integer _speed;
|
||||
protected Float _weight;
|
||||
protected Color _bodyColor;
|
||||
|
||||
public int getSpeed() {
|
||||
@@ -19,12 +20,38 @@ 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;
|
||||
_weight = weight <= 0 ? rnd.nextInt(100)+500 : weight;
|
||||
_bodyColor = bodyColor;
|
||||
|
||||
Step = _speed * 100/ (int)_weight;
|
||||
Step = _speed * 100/ (float)_weight;
|
||||
}
|
||||
|
||||
public String[] GetStringRepresentation()
|
||||
{
|
||||
return new String[]{"EntityMonorail", _speed.toString(), _weight.toString(), colorToHexString(_bodyColor)};
|
||||
}
|
||||
|
||||
public static EntityMonorail CreateEntityMonorail(String[] strs)
|
||||
{
|
||||
if (strs.length != 6 || !Objects.equals(strs[0], "EntityMonorail"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new EntityMonorail(Integer.parseInt(strs[1]), Float.parseFloat(strs[2]), hexStringToColor(strs[3]));
|
||||
}
|
||||
|
||||
public static String colorToHexString(Color color) {
|
||||
return String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getBlue());
|
||||
}
|
||||
|
||||
public static Color hexStringToColor(String hexString) {
|
||||
return Color.decode(hexString);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ public class FormMonorailCollection extends JFrame{
|
||||
private JList listBoxCollection = new JList();
|
||||
private JButton buttonRemoveCollection = new JButton("Удалить");
|
||||
private JButton buttonCreateCompany = new JButton("Создать компанию");
|
||||
private JButton createButton = new JButton("Создать современный монорельс");;
|
||||
private JButton createModernButton = new JButton("Создать монорельс");
|
||||
private JButton createMonorailButton = new JButton("Создать монорельс");
|
||||
private JButton removeButton = new JButton("Удалить");
|
||||
private JButton removeObjectsButton = new JButton("Удаленные объекты");
|
||||
|
||||
@@ -96,16 +95,13 @@ public class FormMonorailCollection extends JFrame{
|
||||
}
|
||||
});
|
||||
|
||||
createModernButton.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();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -275,8 +271,7 @@ public class FormMonorailCollection extends JFrame{
|
||||
buttonRemoveCollection.setBounds(getWidth()-190, 195, 150, 20);
|
||||
ComboBoxCollections.setBounds(getWidth() - 190, 225, 150, 20);
|
||||
buttonCreateCompany.setBounds(getWidth()-190, 255, 150, 20);
|
||||
createModernButton.setBounds(getWidth() - 190, 285, 150, 30);
|
||||
createButton.setBounds(getWidth() - 190, 325, 150, 30);
|
||||
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);
|
||||
@@ -298,8 +293,7 @@ public class FormMonorailCollection extends JFrame{
|
||||
|
||||
add(_canvasMonorail);
|
||||
add(ComboBoxCollections);
|
||||
add(createModernButton);
|
||||
add(createButton);
|
||||
add(createMonorailButton);
|
||||
add(TextField);
|
||||
add(GoToCheckButton);
|
||||
add(RandomButton);
|
||||
|
||||
457
ProjectMonorail/src/Scripts/Forms/FormMonorailConfig.java
Normal file
457
ProjectMonorail/src/Scripts/Forms/FormMonorailConfig.java
Normal file
@@ -0,0 +1,457 @@
|
||||
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 labelDefaultEngines = new JLabel("Классические",SwingConstants.CENTER);
|
||||
private JLabel labelOvalEngines = new JLabel("Овальные", SwingConstants.CENTER);
|
||||
private JLabel labelTriangleEngines = 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));
|
||||
labelDefaultEngines.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
labelOvalEngines.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
labelTriangleEngines.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 labelEnginesMouseDown = new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
((JLabel) e.getComponent()).getTransferHandler().exportAsDrag(((JLabel) e.getComponent()), e, TransferHandler.COPY);
|
||||
}
|
||||
};
|
||||
|
||||
labelDefaultEngines.addMouseListener(labelEnginesMouseDown);
|
||||
labelOvalEngines.addMouseListener(labelEnginesMouseDown);
|
||||
labelTriangleEngines.addMouseListener(labelEnginesMouseDown);
|
||||
labelDefaultEngines.setTransferHandler(new TransferHandler() {
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {return TransferHandler.COPY;}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new WheelsTransferable(new DrawingWheels());
|
||||
}
|
||||
});
|
||||
labelOvalEngines.setTransferHandler(new TransferHandler() {
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {return TransferHandler.COPY;}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new WheelsTransferable(new DrawOrnamentOval());
|
||||
}
|
||||
});
|
||||
labelTriangleEngines.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;
|
||||
DrawingMonorail copyDrawingMonorail;
|
||||
if (_drawingMonorail instanceof DrawingModernMonorail)
|
||||
copyDrawingMonorail = new DrawingModernMonorail((EntityModernMonorail) _drawingMonorail.getMonorail(), _drawingMonorail.getWheels());
|
||||
else
|
||||
copyDrawingMonorail = new DrawingMonorail(_drawingMonorail.getMonorail(), _drawingMonorail.getWheels());
|
||||
company._collection.Insert(copyDrawingMonorail);
|
||||
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);
|
||||
labelDefaultEngines.setBounds(140, 210, 100, 40);
|
||||
labelOvalEngines.setBounds(250, 210, 100,40);
|
||||
labelTriangleEngines.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(labelDefaultEngines);
|
||||
add(labelDefaultEngines);
|
||||
add(labelOvalEngines);
|
||||
add(labelTriangleEngines);
|
||||
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