Compare commits
No commits in common. "1f5fa9eb6f57c61cc5700498eae6b3d690147886" and "4ea097cdb5a65aa4264ef32b89a9f0456d7a80e4" have entirely different histories.
1f5fa9eb6f
...
4ea097cdb5
@ -8,7 +8,4 @@ public interface ICollectionGenericObjects<T>
|
||||
int Insert(T obj);
|
||||
T Remove(int position);
|
||||
T Get(int position);
|
||||
CollectionType GetCollectionType();
|
||||
Iterable<T> GetItems();
|
||||
void ClearCollection();
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
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();
|
||||
@ -18,10 +18,6 @@ public class ListGenericObjects<T> implements ICollectionGenericObjects<T> {
|
||||
_collection = new ArrayList<T>();
|
||||
}
|
||||
@Override
|
||||
public CollectionType GetCollectionType() {
|
||||
return collectionType;
|
||||
}
|
||||
@Override
|
||||
public T Get(int position)
|
||||
{
|
||||
if (position >= getCount() || position < 0) return null;
|
||||
@ -42,35 +38,4 @@ 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 stormtrooper : _collection) {
|
||||
stormtrooper = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,12 +3,10 @@ package CollectionGenericObjects;
|
||||
import Drawnings.DrawingBaseStormtrooper;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T>{
|
||||
private T[] _collection = null;
|
||||
private CollectionType collectionType = CollectionType.Massive;
|
||||
private int Count;
|
||||
public void SetMaxCount(int size) {
|
||||
if (size > 0) {
|
||||
@ -19,10 +17,6 @@ public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T>{
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public CollectionType GetCollectionType() {
|
||||
return collectionType;
|
||||
}
|
||||
@Override
|
||||
public int getCount() {
|
||||
return Count;
|
||||
}
|
||||
@ -53,35 +47,4 @@ 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 stormtrooper : _collection) {
|
||||
stormtrooper = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,7 @@
|
||||
package CollectionGenericObjects;
|
||||
import Drawnings.DrawingBaseStormtrooper;
|
||||
import Drawnings.ExtentionDrawingBaseStormtrooper;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class StorageCollection<T extends DrawingBaseStormtrooper> {
|
||||
public class StorageCollection<T> {
|
||||
private Map<String, ICollectionGenericObjects<T>> _storages;
|
||||
public StorageCollection()
|
||||
{
|
||||
@ -39,154 +35,5 @@ public class StorageCollection<T extends DrawingBaseStormtrooper> {
|
||||
return _storages.get(name).Remove(position);
|
||||
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 stormtrooper : value.getValue().GetItems()) {
|
||||
String data = ExtentionDrawingBaseStormtrooper.GetDataForSave((DrawingBaseStormtrooper) stormtrooper);
|
||||
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 stormtrooper : value.GetItems()) {
|
||||
String data = ExtentionDrawingBaseStormtrooper.GetDataForSave((DrawingBaseStormtrooper) stormtrooper);
|
||||
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) {
|
||||
DrawingBaseStormtrooper stormtrooper = ExtentionDrawingBaseStormtrooper.CreateDrawingBaseStomrtrooper(elem);
|
||||
if (collection.Insert((T) stormtrooper) == -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) {
|
||||
DrawingBaseStormtrooper stormtrooper = ExtentionDrawingBaseStormtrooper.CreateDrawingBaseStomrtrooper(elem);
|
||||
if (collection.Insert((T) stormtrooper) == -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;
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,4 @@
|
||||
package Drawnings;
|
||||
import Drawnings.Engines.DrawingEngines;
|
||||
import Drawnings.Engines.DrawingOvalEngines;
|
||||
import Drawnings.Engines.DrawingTriangleEngines;
|
||||
import Drawnings.Engines.IDrawingEngines;
|
||||
import Entities.*;
|
||||
import java.awt.*;
|
||||
@ -139,17 +136,4 @@ public class DrawingBaseStormtrooper {
|
||||
Polygon poly = new Polygon(arrX, arrY, 3);
|
||||
g.fillPolygon(poly);
|
||||
}
|
||||
public String[] GetStringRepresentationDecks() {
|
||||
if (drawingEngines instanceof DrawingEngines) {
|
||||
return new String[]{String.valueOf(drawingEngines.getNumberOfEngines()), "DrawingEngines"};
|
||||
}
|
||||
else if (drawingEngines instanceof DrawingOvalEngines) {
|
||||
return new String[]{String.valueOf(drawingEngines.getNumberOfEngines()), "DrawingOvalEngines"};
|
||||
}
|
||||
else if (drawingEngines instanceof DrawingTriangleEngines) {
|
||||
return new String[]{String.valueOf(drawingEngines.getNumberOfEngines()), "DrawingTriangleEngines"};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,25 @@ import java.awt.*;
|
||||
|
||||
public class DrawingStormtrooper extends DrawingBaseStormtrooper{
|
||||
|
||||
public DrawingStormtrooper(int speed, float weight, Color bodyColor, Color additionalColor,boolean rockets, boolean bombs, boolean engines) {
|
||||
public DrawingStormtrooper(int speed, float weight, Color bodyColor, Color additionalColor,boolean rockets, boolean bombs, boolean engines, int typeOfEngines) {
|
||||
EntityBaseStormtrooper = new EntityStormtrooper(speed, weight, bodyColor, additionalColor, rockets, bombs, engines);
|
||||
if(engines){
|
||||
switch(typeOfEngines){
|
||||
case 1:
|
||||
drawingEngines = new DrawingEngines();
|
||||
drawingEngines.setAmountOfEngines((int)((Math.random()*3)+1)*2);
|
||||
break;
|
||||
case 2:
|
||||
drawingEngines = new DrawingTriangleEngines();
|
||||
drawingEngines.setAmountOfEngines((int)((Math.random()*3)+1)*2);
|
||||
break;
|
||||
case 3:
|
||||
drawingEngines = new DrawingOvalEngines();
|
||||
drawingEngines.setAmountOfEngines((int)((Math.random()*3)+1)*2);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
_startPosX=null;
|
||||
_startPosY=null;
|
||||
_pictureWidth = null;
|
||||
|
@ -14,11 +14,6 @@ public class DrawingEngines implements IDrawingEngines {
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getNumberFromString(String numberString){
|
||||
NumberOfEngines number = NumberOfEngines.valueOf(numberString);
|
||||
return number.getNumber();
|
||||
}
|
||||
@Override
|
||||
public void DrawEngines(Graphics g, int x, int y, Color bodyColor) {
|
||||
g.setColor(bodyColor);
|
||||
g.fillRect(x, y, 10, 10);
|
||||
|
@ -15,11 +15,6 @@ public class DrawingOvalEngines implements IDrawingEngines {
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getNumberFromString(String numberString){
|
||||
NumberOfEngines number = NumberOfEngines.valueOf(numberString);
|
||||
return number.getNumber();
|
||||
}
|
||||
@Override
|
||||
public void DrawEngines(Graphics g, int x, int y, Color bodyColor) {
|
||||
g.setColor(bodyColor);
|
||||
g.fillOval(x, y, 10, 10);
|
||||
|
@ -15,11 +15,6 @@ public class DrawingTriangleEngines implements IDrawingEngines {
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getNumberFromString(String numberString){
|
||||
NumberOfEngines number = NumberOfEngines.valueOf(numberString);
|
||||
return number.getNumber();
|
||||
}
|
||||
@Override
|
||||
public void DrawEngines(Graphics g, int x, int y, Color bodyColor) {
|
||||
g.setColor(bodyColor);
|
||||
Point[] Nose = new Point[3];
|
||||
@ -40,7 +35,6 @@ public class DrawingTriangleEngines implements IDrawingEngines {
|
||||
DrawEngines(g,x + 64, y + 30,bodyColor);
|
||||
DrawEngines(g,x + 62, y + 121,bodyColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawSixEngines(Graphics g, int x, int y, Color bodyColor){
|
||||
drawFourEngines(g,x,y,bodyColor);
|
||||
|
@ -4,7 +4,6 @@ import java.awt.*;
|
||||
|
||||
public interface IDrawingEngines {
|
||||
void setAmountOfEngines(int amount);
|
||||
int getNumberFromString(String numberString);
|
||||
|
||||
NumberOfEngines getNumberOfEngines();
|
||||
|
||||
|
@ -18,11 +18,6 @@ public enum NumberOfEngines {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getNumber(){
|
||||
return value;
|
||||
}
|
||||
|
||||
public static boolean contains(int amount){
|
||||
NumberOfEngines [] num = NumberOfEngines.values();
|
||||
for(int i =0 ; i <num.length;i++){
|
||||
|
@ -1,78 +0,0 @@
|
||||
package Drawnings;
|
||||
|
||||
import Drawnings.Engines.*;
|
||||
import Entities.EntityBaseStormtrooper;
|
||||
import Entities.EntityStormtrooper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
public class ExtentionDrawingBaseStormtrooper {
|
||||
private static String _separatorForObjectS = ":";
|
||||
private static String _separatorForObject = "\\:";
|
||||
public static DrawingBaseStormtrooper CreateDrawingBaseStomrtrooper(String info) {
|
||||
String[] strs = info.split(_separatorForObject);
|
||||
EntityBaseStormtrooper stormtrooper;
|
||||
IDrawingEngines engines = null;
|
||||
if (strs.length == 10)
|
||||
{
|
||||
String s = strs[9];
|
||||
System.out.println(s);
|
||||
switch (s) {
|
||||
case "DrawingEngines":
|
||||
engines = new DrawingEngines();
|
||||
break;
|
||||
case "DrawingOvalEngines":
|
||||
engines = new DrawingOvalEngines();
|
||||
break;
|
||||
case "DrawingTriangleEngines":
|
||||
engines = new DrawingTriangleEngines();
|
||||
break;
|
||||
}
|
||||
if (engines != null) engines.setAmountOfEngines(engines.getNumberFromString(strs[8]));
|
||||
}
|
||||
else if (strs.length == 6) {
|
||||
String s = strs[5];
|
||||
switch (s) {
|
||||
case "DrawingEngines":
|
||||
engines = new DrawingEngines();
|
||||
break;
|
||||
case "DrawingOvalEngines":
|
||||
engines = new DrawingOvalEngines();
|
||||
break;
|
||||
case "DrawingTriangleEngines":
|
||||
engines = new DrawingTriangleEngines();
|
||||
break;
|
||||
}
|
||||
if (engines != null) engines.setAmountOfEngines(Integer.parseInt(strs[4]));
|
||||
}
|
||||
stormtrooper = EntityStormtrooper.CreateEntityStormtrooper(strs);
|
||||
if (stormtrooper != null)
|
||||
{
|
||||
return new DrawingStormtrooper((EntityStormtrooper) stormtrooper, engines);
|
||||
}
|
||||
stormtrooper = EntityBaseStormtrooper.CreateEntityBaseStormtrooper(strs);
|
||||
if (stormtrooper != null)
|
||||
{
|
||||
return new DrawingBaseStormtrooper(stormtrooper, engines);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static String GetDataForSave(DrawingBaseStormtrooper drawingBaseStormtrooper)
|
||||
{
|
||||
if (drawingBaseStormtrooper == null) return "";
|
||||
String[] array1 = drawingBaseStormtrooper.EntityBaseStormtrooper.GetStringRepresentation();
|
||||
String[] array2 = drawingBaseStormtrooper.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,49 +1,19 @@
|
||||
package Entities;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Objects;
|
||||
|
||||
public class EntityBaseStormtrooper
|
||||
{
|
||||
private Integer Speed;
|
||||
public void setSpeed(int speed){
|
||||
Speed = speed;
|
||||
}
|
||||
public Integer getSpeed() {return Speed;}
|
||||
private Double Weight;
|
||||
public void setWeight (double weight){
|
||||
Weight= weight;
|
||||
}
|
||||
public Double getWeight() {return Weight;}
|
||||
private int Speed;
|
||||
private float Weight;
|
||||
private Color BodyColor;
|
||||
public void setBodyColor (Color bodyColor){
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
public Color getBodyColor() {return BodyColor;}
|
||||
public double Step;
|
||||
public EntityBaseStormtrooper(int speed, double weight, Color bodyColor)
|
||||
public EntityBaseStormtrooper(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
Step=speed*100/weight;
|
||||
}
|
||||
public String[] GetStringRepresentation()
|
||||
{
|
||||
return new String[]{"EntityBaseStormtrooper", Speed.toString(), Weight.toString(), colorToHexString(BodyColor)};
|
||||
}
|
||||
public static EntityBaseStormtrooper CreateEntityBaseStormtrooper(String[] strs)
|
||||
{
|
||||
if (strs.length != 6 || !Objects.equals(strs[0], "EntityBaseStormtrooper"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new EntityBaseStormtrooper(Integer.parseInt(strs[1]), Double.parseDouble(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);
|
||||
}
|
||||
}
|
||||
|
@ -1,36 +1,22 @@
|
||||
package Entities;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Objects;
|
||||
|
||||
public class EntityStormtrooper extends EntityBaseStormtrooper{
|
||||
private Color AdditionalColor;
|
||||
public void setAdditionalColor(Color additionalColor){
|
||||
AdditionalColor = additionalColor;
|
||||
}
|
||||
public Color getAdditionalColor() {
|
||||
return AdditionalColor;
|
||||
}
|
||||
private boolean Rockets;
|
||||
public void setRockets ( boolean rockets){
|
||||
Rockets= rockets;
|
||||
}
|
||||
public boolean getRockets() {
|
||||
return Rockets;
|
||||
}
|
||||
private boolean Bombs;
|
||||
public void setBombs (boolean bombs){
|
||||
Bombs= bombs;
|
||||
}
|
||||
public boolean getBombs() {
|
||||
return Bombs;
|
||||
}
|
||||
private boolean Engines;
|
||||
public void setEngines (boolean engines){
|
||||
Engines = engines;
|
||||
}
|
||||
public boolean getEngines() {return Engines;}
|
||||
public EntityStormtrooper(int speed, double weight, Color bodyColor, Color additionalColor, boolean rockets, boolean bombs, boolean engines)
|
||||
public EntityStormtrooper(int speed, float weight, Color bodyColor, Color additionalColor, boolean rockets, boolean bombs, boolean engines)
|
||||
{
|
||||
super(speed,weight,bodyColor);
|
||||
AdditionalColor = additionalColor;
|
||||
@ -38,21 +24,4 @@ public class EntityStormtrooper extends EntityBaseStormtrooper{
|
||||
Bombs = bombs;
|
||||
Engines = engines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] GetStringRepresentation()
|
||||
{
|
||||
return new String[]{"EntityStormtrooper", getSpeed().toString(), getWeight().toString(),
|
||||
colorToHexString(getBodyColor()), colorToHexString(getAdditionalColor()),
|
||||
String.valueOf(Rockets), String.valueOf(Bombs),String.valueOf(Engines)};
|
||||
}
|
||||
public static EntityStormtrooper CreateEntityStormtrooper(String[] strs)
|
||||
{
|
||||
if (strs.length != 10 || !Objects.equals(strs[0], "EntityStormtrooper"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new EntityStormtrooper(Integer.parseInt(strs[1]), Double.parseDouble(strs[2]), hexStringToColor(strs[3]),
|
||||
hexStringToColor(strs[4]), Boolean.parseBoolean(strs[5]), Boolean.parseBoolean(strs[6]), Boolean.parseBoolean(strs[7]));
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ public class FormStormtrooperCollection extends JFrame {
|
||||
private JButton buttonRemoveCollection = new JButton("Удалить");
|
||||
private JButton buttonCreateCompany = new JButton("Создать компанию");
|
||||
private JButton createButton = new JButton("Создать бомбардировщик");
|
||||
private JButton createShipButton = new JButton("Создать базовый бомбардировщик");
|
||||
private JButton removeButton = new JButton("Удалить");
|
||||
private JButton removeObjectsButton = new JButton("Удаленные объекты");
|
||||
private JButton GoToCheckButton = new JButton("На проверку");
|
||||
@ -32,12 +33,6 @@ public class FormStormtrooperCollection extends JFrame {
|
||||
private JButton RefreshButton = new JButton("Обновить");
|
||||
private JComboBox ComboBoxCollections = new JComboBox(new String[]{"", "Хранилище"});
|
||||
private JFormattedTextField TextField;
|
||||
private JMenuBar menuBar = new JMenuBar();
|
||||
private JMenu fileMenu = new JMenu("Файл");
|
||||
private JMenuItem loadItem = new JMenuItem("Загрузить");
|
||||
private JMenuItem saveItem = new JMenuItem("Сохранить");
|
||||
private JMenuItem loadCollection = new JMenuItem("Загрузить коллекцию");
|
||||
private JMenuItem saveCollection = new JMenuItem("Сохранить коллекцию");
|
||||
|
||||
public FormStormtrooperCollection(String title, Dimension dimension) {
|
||||
this.title = title;
|
||||
@ -50,19 +45,59 @@ public class FormStormtrooperCollection extends JFrame {
|
||||
_canvasStormtrooper.repaint();
|
||||
}
|
||||
|
||||
private void CreateObject(String typeOfClass) {
|
||||
if (_company == null) return;
|
||||
int speed = (int) (Math.random() * 300 + 100);
|
||||
float weight = (float) (Math.random() * 3000 + 1000);
|
||||
Color bodyColor = getColor();
|
||||
DrawingBaseStormtrooper drawingBaseStormtrooper;
|
||||
switch (typeOfClass) {
|
||||
case "DrawingBaseStormtrooper":
|
||||
drawingBaseStormtrooper = new DrawingBaseStormtrooper(speed, weight, bodyColor);
|
||||
break;
|
||||
case "DrawingStormtrooper":
|
||||
Color additionalColor = getColor();
|
||||
boolean rockets = new Random().nextBoolean();
|
||||
boolean bombs = new Random().nextBoolean();
|
||||
boolean engines = new Random().nextBoolean();
|
||||
int typeOfEngine = ((int) ((Math.random() * 3) + 1));
|
||||
drawingBaseStormtrooper = new DrawingStormtrooper(speed, weight, bodyColor, additionalColor, rockets, bombs, engines, typeOfEngine);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
if (_company._collection.Insert(drawingBaseStormtrooper) != -1) {
|
||||
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
||||
canvasShow();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "Объект не удалось добавить");
|
||||
}
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
Color initializator = new Color((int) (Math.random() * 255 + 0), (int) (Math.random() * 255 + 0), (int) (Math.random() * 255 + 0));
|
||||
Color color = JColorChooser.showDialog(this, "Цвет", initializator);
|
||||
return color;
|
||||
}
|
||||
|
||||
public void Init() {
|
||||
setTitle(title);
|
||||
setMinimumSize(dimension);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
|
||||
TextField = new JFormattedTextField();
|
||||
|
||||
createShipButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
CreateObject("DrawingBaseStormtrooper");
|
||||
}
|
||||
});
|
||||
createButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_company == null) return;
|
||||
FormStormtrooperConfig form = new FormStormtrooperConfig("", new Dimension(800, 300));
|
||||
form.setCompany(_company);
|
||||
form.Init();
|
||||
CreateObject("DrawingStormtrooper");
|
||||
}
|
||||
});
|
||||
|
||||
@ -208,38 +243,6 @@ public class FormStormtrooperCollection extends JFrame {
|
||||
form.Init(stormtrooper);
|
||||
}
|
||||
});
|
||||
saveItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
SaveFile();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
loadItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
LoadFile();
|
||||
}
|
||||
});
|
||||
|
||||
saveCollection.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.out.println("Save coll");
|
||||
SaveCollection();
|
||||
}
|
||||
});
|
||||
|
||||
loadCollection.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.out.println("Load coll");
|
||||
LoadCollection();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ButtonGroup radioButtonsGroup = new ButtonGroup();
|
||||
JLabel labelCollectionName = new JLabel("Название коллекции");
|
||||
radioButtonsGroup.add(radioButtonMassive);
|
||||
@ -254,6 +257,7 @@ public class FormStormtrooperCollection extends JFrame {
|
||||
buttonRemoveCollection.setBounds(getWidth()-190, 195, 150, 20);
|
||||
ComboBoxCollections.setBounds(getWidth() - 190, 225, 150, 20);
|
||||
buttonCreateCompany.setBounds(getWidth()-190, 255, 150, 20);
|
||||
createShipButton.setBounds(getWidth() - 190, 285, 150, 30);
|
||||
createButton.setBounds(getWidth() - 190, 325, 150, 30);
|
||||
RandomButton.setBounds(getWidth() - 190, 365, 150, 30);
|
||||
removeObjectsButton.setBounds(getWidth()-190, 505, 150, 30);
|
||||
@ -274,78 +278,15 @@ public class FormStormtrooperCollection extends JFrame {
|
||||
add(removeObjectsButton);
|
||||
add(_canvasStormtrooper);
|
||||
add(ComboBoxCollections);
|
||||
add(createShipButton);
|
||||
add(createButton);
|
||||
add(TextField);
|
||||
add(removeButton);
|
||||
add(GoToCheckButton);
|
||||
add(RandomButton);
|
||||
add(RefreshButton);
|
||||
fileMenu.add(loadItem);
|
||||
fileMenu.add(saveItem);
|
||||
fileMenu.add(loadCollection);
|
||||
fileMenu.add(saveCollection);
|
||||
fileMenu.addSeparator();
|
||||
menuBar.add(fileMenu);
|
||||
setJMenuBar(menuBar);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private String SaveWindow() {
|
||||
FileDialog fileDialog = new FileDialog(this, "Save File", FileDialog.SAVE);
|
||||
fileDialog.setVisible(true);
|
||||
String directory = fileDialog.getDirectory();
|
||||
String file = fileDialog.getFile();
|
||||
if (directory == null || file == null) return null;
|
||||
return directory + file;
|
||||
}
|
||||
|
||||
private void SaveFile() {
|
||||
String filename = SaveWindow();
|
||||
if (_storageCollection.SaveData(filename)) {
|
||||
JOptionPane.showMessageDialog(null, "Сохранено");
|
||||
} else JOptionPane.showMessageDialog(null, "Ошибка сохранения");
|
||||
}
|
||||
|
||||
private void SaveCollection() {
|
||||
String filename = SaveWindow();
|
||||
if (filename == null) {
|
||||
JOptionPane.showMessageDialog(null, "Файл не выбран");
|
||||
return;
|
||||
}
|
||||
if (listBoxCollection.getSelectedIndex() < 0 || listBoxCollection.getSelectedValue() == null) {
|
||||
JOptionPane.showMessageDialog(null, "Коллекция не выбрана");
|
||||
}
|
||||
if (_storageCollection.SaveOneCollection(filename, listBoxCollection.getSelectedValue().toString())) {
|
||||
JOptionPane.showMessageDialog(null, "Коллекция сохранена");
|
||||
} else JOptionPane.showMessageDialog(null, "Ошибка сохранения");
|
||||
}
|
||||
|
||||
private String LoadWindow() {
|
||||
FileDialog fileDialog = new FileDialog(this, "Save File", FileDialog.LOAD);
|
||||
fileDialog.setVisible(true);
|
||||
String directory = fileDialog.getDirectory();
|
||||
String file = fileDialog.getFile();
|
||||
if (directory == null || file == null) return null;
|
||||
return directory + file;
|
||||
}
|
||||
|
||||
private void LoadFile() {
|
||||
String filename = LoadWindow();
|
||||
if (_storageCollection.LoadData(filename)) {
|
||||
JOptionPane.showMessageDialog(null, "Загрузка прошла успешно");
|
||||
RerfreshListBoxItems();
|
||||
} else JOptionPane.showMessageDialog(null, "Не загрузилось");
|
||||
|
||||
}
|
||||
|
||||
private void LoadCollection() {
|
||||
String filename = LoadWindow();
|
||||
if (_storageCollection.LoadOneCollection(filename)) {
|
||||
JOptionPane.showMessageDialog(null, "Коллекция загружена");
|
||||
RerfreshListBoxItems();
|
||||
} else JOptionPane.showMessageDialog(null, "Не загрузилось");
|
||||
}
|
||||
|
||||
private void RerfreshListBoxItems() {
|
||||
DefaultListModel<String> list = new DefaultListModel<String>();
|
||||
for (String name : _storageCollection.Keys()) {
|
||||
|
@ -1,467 +0,0 @@
|
||||
import CollectionGenericObjects.AbstractCompany;
|
||||
import Drawnings.*;
|
||||
import Drawnings.Engines.*;
|
||||
import Entities.EntityStormtrooper;
|
||||
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 FormStormtrooperConfig extends JFrame {
|
||||
private String title;
|
||||
private Dimension dimension;
|
||||
private DrawingBaseStormtrooper _stormtrooper;
|
||||
private AbstractCompany company = null;
|
||||
private JLabel labelSpeed = new JLabel("Скорость");
|
||||
private JLabel labelWeight = new JLabel("Вес");
|
||||
private JLabel labelNumberOfEngines = new JLabel("Двигатели");
|
||||
|
||||
private JLabel labelBaseStormtrooper = new JLabel("Самолет", SwingConstants.CENTER);
|
||||
private JLabel labelStormtrooper = new JLabel("Бомбардировщик", SwingConstants.CENTER);
|
||||
private JLabel labelColor = new JLabel("Цвета");
|
||||
private JLabel labelBodyColor = new JLabel("Основной цвет", SwingConstants.CENTER);
|
||||
private JLabel labelAdditionalColor = new JLabel("Дополнительный цвет", SwingConstants.CENTER);
|
||||
private JLabel labelEngines = 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 spinnerNumberOfEngines = new JSpinner();
|
||||
private JCheckBox checkBoxBombs = new JCheckBox("Имеет бомбы");
|
||||
private JCheckBox checkBoxRockets = new JCheckBox("Имеет ракеты");
|
||||
private JCheckBox checkBoxEngines = 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 FormStormtrooperConfig(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 numEngines = new SpinnerNumberModel(2, 2, 6, 2);
|
||||
spinnerNumberOfEngines.setModel(numEngines);
|
||||
panelObject = new Canvas();
|
||||
panelObject.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
|
||||
spinnerSpeed.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
if (_stormtrooper == null) return;
|
||||
_stormtrooper.EntityBaseStormtrooper.setSpeed((int)spinnerSpeed.getValue());
|
||||
}
|
||||
});
|
||||
spinnerWeight.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
if (_stormtrooper == null) return;
|
||||
_stormtrooper.EntityBaseStormtrooper.setWeight((int)spinnerWeight.getValue());
|
||||
}
|
||||
});
|
||||
|
||||
spinnerNumberOfEngines.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
if(_stormtrooper ==null)return;
|
||||
if(_stormtrooper.EntityBaseStormtrooper instanceof EntityStormtrooper stormtrooper){
|
||||
_stormtrooper.drawingEngines.setAmountOfEngines((int) spinnerNumberOfEngines.getValue());
|
||||
panelObject.repaint();
|
||||
}
|
||||
}
|
||||
});
|
||||
checkBoxBombs.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_stormtrooper == null) return;
|
||||
if (_stormtrooper.EntityBaseStormtrooper instanceof EntityStormtrooper stormtrooper) {
|
||||
stormtrooper.setBombs(checkBoxBombs.isSelected());
|
||||
panelObject.repaint();
|
||||
}
|
||||
}
|
||||
});
|
||||
checkBoxRockets.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_stormtrooper == null) return;
|
||||
if (_stormtrooper.EntityBaseStormtrooper instanceof EntityStormtrooper stormtrooper) {
|
||||
stormtrooper.setRockets(checkBoxRockets.isSelected());
|
||||
panelObject.repaint();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
checkBoxEngines.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(_stormtrooper == null)return;
|
||||
if(_stormtrooper.EntityBaseStormtrooper instanceof EntityStormtrooper stormtrooper){
|
||||
stormtrooper.setEngines(checkBoxEngines.isSelected());
|
||||
if(_stormtrooper instanceof DrawingStormtrooper stormtrooper1 && stormtrooper1.drawingEngines==null){
|
||||
stormtrooper1.drawingEngines=new DrawingEngines();
|
||||
stormtrooper1.drawingEngines.setAmountOfEngines((int) spinnerNumberOfEngines.getValue());
|
||||
}
|
||||
panelObject.repaint();
|
||||
}
|
||||
}
|
||||
});
|
||||
labelBaseStormtrooper.setBackground(Color.WHITE);
|
||||
labelStormtrooper.setBackground(Color.WHITE);
|
||||
labelBaseStormtrooper.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
labelStormtrooper.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());
|
||||
}
|
||||
};
|
||||
|
||||
labelBaseStormtrooper.addMouseListener(labelObjectsMouseDown);
|
||||
labelBaseStormtrooper.setTransferHandler(labelObjectsTransferHandler);
|
||||
labelStormtrooper.addMouseListener(labelObjectsMouseDown);
|
||||
labelStormtrooper.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 EnginesTransferable(new DrawingEngines());
|
||||
}
|
||||
});
|
||||
labelOvalEngines.setTransferHandler(new TransferHandler() {
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {return TransferHandler.COPY;}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new EnginesTransferable(new DrawingOvalEngines());
|
||||
}
|
||||
});
|
||||
labelTriangleEngines.setTransferHandler(new TransferHandler() {
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {return TransferHandler.COPY;}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new EnginesTransferable(new DrawingTriangleEngines());
|
||||
}
|
||||
});
|
||||
|
||||
panelObject.setTransferHandler(new TransferHandler() {
|
||||
@Override
|
||||
public boolean canImport(TransferHandler.TransferSupport support) {
|
||||
return support.isDataFlavorSupported(DataFlavor.stringFlavor)
|
||||
|| support.isDataFlavorSupported(EnginesTransferable.enginesDataFlavor);
|
||||
}
|
||||
@Override
|
||||
public boolean importData(TransferHandler.TransferSupport support) {
|
||||
if (canImport(support)) {
|
||||
try {
|
||||
String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
|
||||
switch (data) {
|
||||
case "Самолет":
|
||||
_stormtrooper = new DrawingBaseStormtrooper((int) spinnerSpeed.getValue(), (int) spinnerWeight.getValue(),
|
||||
Color.WHITE);
|
||||
break;
|
||||
case "Бомбардировщик":
|
||||
_stormtrooper = new DrawingStormtrooper((int) spinnerSpeed.getValue(), (int) spinnerWeight.getValue(),
|
||||
Color.WHITE, Color.BLACK, checkBoxBombs.isSelected(), checkBoxRockets.isSelected(),checkBoxEngines.isSelected());
|
||||
_stormtrooper.drawingEngines=new DrawingEngines();
|
||||
_stormtrooper.drawingEngines.setAmountOfEngines((int) spinnerNumberOfEngines.getValue());
|
||||
break;
|
||||
}
|
||||
if (_stormtrooper != null) {
|
||||
_stormtrooper.SetPictureSize(155,155);
|
||||
_stormtrooper.SetPosition(5,10);
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
catch (UnsupportedFlavorException | IOException e) {}
|
||||
try {
|
||||
IDrawingEngines engines =
|
||||
(IDrawingEngines) support.getTransferable().getTransferData(EnginesTransferable.enginesDataFlavor);
|
||||
_stormtrooper.drawingEngines = engines;
|
||||
_stormtrooper.drawingEngines.setAmountOfEngines((int) spinnerNumberOfEngines.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 (_stormtrooper == null) return false;
|
||||
_stormtrooper.EntityBaseStormtrooper.setBodyColor(color);
|
||||
return true;
|
||||
} catch (UnsupportedFlavorException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
labelAdditionalColor.setTransferHandler(new TransferHandler() {
|
||||
@Override
|
||||
public boolean canImport(TransferHandler.TransferSupport support) {
|
||||
if (!(_stormtrooper instanceof DrawingStormtrooper)) return false;
|
||||
return support.isDataFlavorSupported(ColorTransferable.colorDataFlavor);
|
||||
}
|
||||
@Override
|
||||
public boolean importData(TransferSupport support) {
|
||||
try {
|
||||
Color color = (Color) support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor);
|
||||
if (_stormtrooper == null) return false;
|
||||
if (_stormtrooper.EntityBaseStormtrooper instanceof EntityStormtrooper stormtrooper) {
|
||||
stormtrooper.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 (_stormtrooper == null) return;
|
||||
DrawingBaseStormtrooper copyStormtrooper;
|
||||
if (_stormtrooper instanceof DrawingStormtrooper)
|
||||
copyStormtrooper = new DrawingStormtrooper((EntityStormtrooper) _stormtrooper.EntityBaseStormtrooper, _stormtrooper.drawingEngines);
|
||||
else
|
||||
copyStormtrooper = new DrawingBaseStormtrooper(_stormtrooper.EntityBaseStormtrooper, _stormtrooper.drawingEngines);
|
||||
company._collection.Insert(copyStormtrooper);
|
||||
FormStormtrooperCollection.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);
|
||||
labelNumberOfEngines.setBounds(8, 68, 75, 15);
|
||||
labelBaseStormtrooper.setBounds(8,150,105,30);
|
||||
labelStormtrooper.setBounds(8,190,110,30);
|
||||
checkBoxBombs.setBounds(8,85,150,20);
|
||||
checkBoxRockets.setBounds(8,105,150,20);
|
||||
checkBoxEngines.setBounds(8,125,150,20);
|
||||
spinnerSpeed.setBounds(80,15, 60,20);
|
||||
spinnerWeight.setBounds(80,40, 60,20);
|
||||
spinnerNumberOfEngines.setBounds(80, 65,60,20);
|
||||
panelObject.setBounds(555,50,160,150);
|
||||
labelBodyColor.setBounds(500,5,100, 40);
|
||||
labelAdditionalColor.setBounds(605,5,170,40);
|
||||
labelEngines.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(labelNumberOfEngines);
|
||||
add(labelBaseStormtrooper);
|
||||
add(labelStormtrooper);
|
||||
add(labelColor);
|
||||
add(labelBodyColor);
|
||||
add(labelAdditionalColor);
|
||||
add(labelDefaultEngines);
|
||||
add(labelDefaultEngines);
|
||||
add(labelOvalEngines);
|
||||
add(labelTriangleEngines);
|
||||
add(spinnerSpeed);
|
||||
add(spinnerWeight);
|
||||
add(spinnerNumberOfEngines);
|
||||
add(checkBoxBombs);
|
||||
add(checkBoxRockets);
|
||||
add(checkBoxEngines);
|
||||
add(panelObject);
|
||||
add(panelColorRed);
|
||||
add(panelColorGreen);
|
||||
add(panelColorBlue);
|
||||
add(panelColorYellow);
|
||||
add(panelColorWhite);
|
||||
add(labelEngines);
|
||||
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 (_stormtrooper == null) {
|
||||
return;
|
||||
}
|
||||
super.paintComponents(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
_stormtrooper.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 EnginesTransferable implements Transferable {
|
||||
private IDrawingEngines engines;
|
||||
private static final DataFlavor enginesDataFlavor = new DataFlavor(IDrawingEngines.class, "Engines");
|
||||
public EnginesTransferable(IDrawingEngines engines) {
|
||||
this.engines = engines;
|
||||
}
|
||||
@Override
|
||||
public DataFlavor[] getTransferDataFlavors() {
|
||||
return new DataFlavor[]{enginesDataFlavor};
|
||||
}
|
||||
@Override
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||
return flavor.equals(enginesDataFlavor);
|
||||
}
|
||||
@Override
|
||||
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
|
||||
if (isDataFlavorSupported(flavor)) {
|
||||
return engines;
|
||||
} else {
|
||||
throw new UnsupportedFlavorException(flavor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
import Drawnings.Engines.NumberOfEngines;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class Main {
|
||||
|
Loading…
Reference in New Issue
Block a user