лаб6
This commit is contained in:
parent
ef26efb807
commit
1f5fa9eb6f
@ -8,4 +8,7 @@ public interface ICollectionGenericObjects<T>
|
|||||||
int Insert(T obj);
|
int Insert(T obj);
|
||||||
T Remove(int position);
|
T Remove(int position);
|
||||||
T Get(int position);
|
T Get(int position);
|
||||||
|
CollectionType GetCollectionType();
|
||||||
|
Iterable<T> GetItems();
|
||||||
|
void ClearCollection();
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package CollectionGenericObjects;
|
package CollectionGenericObjects;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
public class ListGenericObjects<T> implements ICollectionGenericObjects<T> {
|
public class ListGenericObjects<T> implements ICollectionGenericObjects<T> {
|
||||||
private List<T> _collection;
|
private List<T> _collection;
|
||||||
|
private CollectionType collectionType = CollectionType.List;
|
||||||
private int _maxCount;
|
private int _maxCount;
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return _collection.size();
|
return _collection.size();
|
||||||
@ -18,6 +18,10 @@ public class ListGenericObjects<T> implements ICollectionGenericObjects<T> {
|
|||||||
_collection = new ArrayList<T>();
|
_collection = new ArrayList<T>();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
public CollectionType GetCollectionType() {
|
||||||
|
return collectionType;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
public T Get(int position)
|
public T Get(int position)
|
||||||
{
|
{
|
||||||
if (position >= getCount() || position < 0) return null;
|
if (position >= getCount() || position < 0) return null;
|
||||||
@ -38,4 +42,35 @@ public class ListGenericObjects<T> implements ICollectionGenericObjects<T> {
|
|||||||
_collection.remove(position);
|
_collection.remove(position);
|
||||||
return obj;
|
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,10 +3,12 @@ package CollectionGenericObjects;
|
|||||||
import Drawnings.DrawingBaseStormtrooper;
|
import Drawnings.DrawingBaseStormtrooper;
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T>{
|
public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T>{
|
||||||
private T[] _collection = null;
|
private T[] _collection = null;
|
||||||
|
private CollectionType collectionType = CollectionType.Massive;
|
||||||
private int Count;
|
private int Count;
|
||||||
public void SetMaxCount(int size) {
|
public void SetMaxCount(int size) {
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
@ -17,6 +19,10 @@ public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
public CollectionType GetCollectionType() {
|
||||||
|
return collectionType;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return Count;
|
return Count;
|
||||||
}
|
}
|
||||||
@ -47,4 +53,35 @@ public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T>{
|
|||||||
if (position >= getCount() || position < 0) return null;
|
if (position >= getCount() || position < 0) return null;
|
||||||
return (T) _collection[position];
|
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,7 +1,11 @@
|
|||||||
package CollectionGenericObjects;
|
package CollectionGenericObjects;
|
||||||
import java.util.*;
|
import Drawnings.DrawingBaseStormtrooper;
|
||||||
|
import Drawnings.ExtentionDrawingBaseStormtrooper;
|
||||||
|
|
||||||
public class StorageCollection<T> {
|
import java.util.*;
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
public class StorageCollection<T extends DrawingBaseStormtrooper> {
|
||||||
private Map<String, ICollectionGenericObjects<T>> _storages;
|
private Map<String, ICollectionGenericObjects<T>> _storages;
|
||||||
public StorageCollection()
|
public StorageCollection()
|
||||||
{
|
{
|
||||||
@ -35,5 +39,154 @@ public class StorageCollection<T> {
|
|||||||
return _storages.get(name).Remove(position);
|
return _storages.get(name).Remove(position);
|
||||||
return null;
|
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,4 +1,7 @@
|
|||||||
package Drawnings;
|
package Drawnings;
|
||||||
|
import Drawnings.Engines.DrawingEngines;
|
||||||
|
import Drawnings.Engines.DrawingOvalEngines;
|
||||||
|
import Drawnings.Engines.DrawingTriangleEngines;
|
||||||
import Drawnings.Engines.IDrawingEngines;
|
import Drawnings.Engines.IDrawingEngines;
|
||||||
import Entities.*;
|
import Entities.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@ -136,4 +139,17 @@ public class DrawingBaseStormtrooper {
|
|||||||
Polygon poly = new Polygon(arrX, arrY, 3);
|
Polygon poly = new Polygon(arrX, arrY, 3);
|
||||||
g.fillPolygon(poly);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,11 @@ public class DrawingEngines implements IDrawingEngines {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@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) {
|
public void DrawEngines(Graphics g, int x, int y, Color bodyColor) {
|
||||||
g.setColor(bodyColor);
|
g.setColor(bodyColor);
|
||||||
g.fillRect(x, y, 10, 10);
|
g.fillRect(x, y, 10, 10);
|
||||||
|
@ -15,6 +15,11 @@ public class DrawingOvalEngines implements IDrawingEngines {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@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) {
|
public void DrawEngines(Graphics g, int x, int y, Color bodyColor) {
|
||||||
g.setColor(bodyColor);
|
g.setColor(bodyColor);
|
||||||
g.fillOval(x, y, 10, 10);
|
g.fillOval(x, y, 10, 10);
|
||||||
|
@ -15,6 +15,11 @@ public class DrawingTriangleEngines implements IDrawingEngines {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@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) {
|
public void DrawEngines(Graphics g, int x, int y, Color bodyColor) {
|
||||||
g.setColor(bodyColor);
|
g.setColor(bodyColor);
|
||||||
Point[] Nose = new Point[3];
|
Point[] Nose = new Point[3];
|
||||||
@ -35,6 +40,7 @@ public class DrawingTriangleEngines implements IDrawingEngines {
|
|||||||
DrawEngines(g,x + 64, y + 30,bodyColor);
|
DrawEngines(g,x + 64, y + 30,bodyColor);
|
||||||
DrawEngines(g,x + 62, y + 121,bodyColor);
|
DrawEngines(g,x + 62, y + 121,bodyColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawSixEngines(Graphics g, int x, int y, Color bodyColor){
|
public void drawSixEngines(Graphics g, int x, int y, Color bodyColor){
|
||||||
drawFourEngines(g,x,y,bodyColor);
|
drawFourEngines(g,x,y,bodyColor);
|
||||||
|
@ -4,6 +4,7 @@ import java.awt.*;
|
|||||||
|
|
||||||
public interface IDrawingEngines {
|
public interface IDrawingEngines {
|
||||||
void setAmountOfEngines(int amount);
|
void setAmountOfEngines(int amount);
|
||||||
|
int getNumberFromString(String numberString);
|
||||||
|
|
||||||
NumberOfEngines getNumberOfEngines();
|
NumberOfEngines getNumberOfEngines();
|
||||||
|
|
||||||
|
@ -18,6 +18,11 @@ public enum NumberOfEngines {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getNumber(){
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean contains(int amount){
|
public static boolean contains(int amount){
|
||||||
NumberOfEngines [] num = NumberOfEngines.values();
|
NumberOfEngines [] num = NumberOfEngines.values();
|
||||||
for(int i =0 ; i <num.length;i++){
|
for(int i =0 ; i <num.length;i++){
|
||||||
|
@ -0,0 +1,78 @@
|
|||||||
|
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,28 +1,49 @@
|
|||||||
package Entities;
|
package Entities;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class EntityBaseStormtrooper
|
public class EntityBaseStormtrooper
|
||||||
{
|
{
|
||||||
private int Speed;
|
private Integer Speed;
|
||||||
public void setSpeed(int speed){
|
public void setSpeed(int speed){
|
||||||
Speed = speed;
|
Speed = speed;
|
||||||
}
|
}
|
||||||
private float Weight;
|
public Integer getSpeed() {return Speed;}
|
||||||
public void setWeight ( float weight){
|
private Double Weight;
|
||||||
|
public void setWeight (double weight){
|
||||||
Weight= weight;
|
Weight= weight;
|
||||||
}
|
}
|
||||||
|
public Double getWeight() {return Weight;}
|
||||||
private Color BodyColor;
|
private Color BodyColor;
|
||||||
public void setBodyColor (Color bodyColor){
|
public void setBodyColor (Color bodyColor){
|
||||||
BodyColor = bodyColor;
|
BodyColor = bodyColor;
|
||||||
}
|
}
|
||||||
public Color getBodyColor() {return BodyColor;}
|
public Color getBodyColor() {return BodyColor;}
|
||||||
public double Step;
|
public double Step;
|
||||||
public EntityBaseStormtrooper(int speed, float weight, Color bodyColor)
|
public EntityBaseStormtrooper(int speed, double weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Speed = speed;
|
Speed = speed;
|
||||||
Weight = weight;
|
Weight = weight;
|
||||||
BodyColor = bodyColor;
|
BodyColor = bodyColor;
|
||||||
Step=speed*100/weight;
|
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,6 +1,8 @@
|
|||||||
package Entities;
|
package Entities;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class EntityStormtrooper extends EntityBaseStormtrooper{
|
public class EntityStormtrooper extends EntityBaseStormtrooper{
|
||||||
private Color AdditionalColor;
|
private Color AdditionalColor;
|
||||||
public void setAdditionalColor(Color additionalColor){
|
public void setAdditionalColor(Color additionalColor){
|
||||||
@ -28,7 +30,7 @@ public class EntityStormtrooper extends EntityBaseStormtrooper{
|
|||||||
Engines = engines;
|
Engines = engines;
|
||||||
}
|
}
|
||||||
public boolean getEngines() {return Engines;}
|
public boolean getEngines() {return Engines;}
|
||||||
public EntityStormtrooper(int speed, float weight, Color bodyColor, Color additionalColor, boolean rockets, boolean bombs, boolean engines)
|
public EntityStormtrooper(int speed, double weight, Color bodyColor, Color additionalColor, boolean rockets, boolean bombs, boolean engines)
|
||||||
{
|
{
|
||||||
super(speed,weight,bodyColor);
|
super(speed,weight,bodyColor);
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
@ -36,4 +38,21 @@ public class EntityStormtrooper extends EntityBaseStormtrooper{
|
|||||||
Bombs = bombs;
|
Bombs = bombs;
|
||||||
Engines = engines;
|
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]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,12 @@ public class FormStormtrooperCollection extends JFrame {
|
|||||||
private JButton RefreshButton = new JButton("Обновить");
|
private JButton RefreshButton = new JButton("Обновить");
|
||||||
private JComboBox ComboBoxCollections = new JComboBox(new String[]{"", "Хранилище"});
|
private JComboBox ComboBoxCollections = new JComboBox(new String[]{"", "Хранилище"});
|
||||||
private JFormattedTextField TextField;
|
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) {
|
public FormStormtrooperCollection(String title, Dimension dimension) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
@ -53,8 +59,8 @@ public class FormStormtrooperCollection extends JFrame {
|
|||||||
createButton.addActionListener(new ActionListener() {
|
createButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (_company==null) return;
|
if (_company == null) return;
|
||||||
FormStormtrooperConfig form = new FormStormtrooperConfig("",new Dimension(800,300));
|
FormStormtrooperConfig form = new FormStormtrooperConfig("", new Dimension(800, 300));
|
||||||
form.setCompany(_company);
|
form.setCompany(_company);
|
||||||
form.Init();
|
form.Init();
|
||||||
}
|
}
|
||||||
@ -63,7 +69,7 @@ public class FormStormtrooperCollection extends JFrame {
|
|||||||
removeButton.addActionListener(new ActionListener() {
|
removeButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (_company == null || TextField.getText() == null ) {
|
if (_company == null || TextField.getText() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int pos = parseInt(TextField.getText());
|
int pos = parseInt(TextField.getText());
|
||||||
@ -202,23 +208,55 @@ public class FormStormtrooperCollection extends JFrame {
|
|||||||
form.Init(stormtrooper);
|
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();
|
ButtonGroup radioButtonsGroup = new ButtonGroup();
|
||||||
JLabel labelCollectionName = new JLabel("Название коллекции");
|
JLabel labelCollectionName = new JLabel("Название коллекции");
|
||||||
radioButtonsGroup.add(radioButtonMassive);
|
radioButtonsGroup.add(radioButtonMassive);
|
||||||
radioButtonsGroup.add(radioButtonList);
|
radioButtonsGroup.add(radioButtonList);
|
||||||
_canvasStormtrooper.setBounds(0, 0, getWidth() - 200, getHeight());
|
_canvasStormtrooper.setBounds(0, 0, getWidth() - 200, getHeight());
|
||||||
labelCollectionName.setBounds(getWidth()-190, 10, 150, 20);
|
labelCollectionName.setBounds(getWidth() - 190, 10, 150, 20);
|
||||||
textBoxCollection.setBounds(getWidth()-190,35,150,25);
|
textBoxCollection.setBounds(getWidth() - 190, 35, 150, 25);
|
||||||
radioButtonMassive.setBounds(getWidth()-190, 60, 75, 20);
|
radioButtonMassive.setBounds(getWidth() - 190, 60, 75, 20);
|
||||||
radioButtonList.setBounds(getWidth()-105, 60, 75, 20);
|
radioButtonList.setBounds(getWidth() - 105, 60, 75, 20);
|
||||||
buttonAddCollection.setBounds(getWidth()-190, 85, 150, 20);
|
buttonAddCollection.setBounds(getWidth() - 190, 85, 150, 20);
|
||||||
listBoxCollection.setBounds(getWidth()-190, 115, 150, 70);
|
listBoxCollection.setBounds(getWidth() - 190, 115, 150, 70);
|
||||||
buttonRemoveCollection.setBounds(getWidth()-190, 195, 150, 20);
|
buttonRemoveCollection.setBounds(getWidth() - 190, 195, 150, 20);
|
||||||
ComboBoxCollections.setBounds(getWidth() - 190, 225, 150, 20);
|
ComboBoxCollections.setBounds(getWidth() - 190, 225, 150, 20);
|
||||||
buttonCreateCompany.setBounds(getWidth()-190, 255, 150, 20);
|
buttonCreateCompany.setBounds(getWidth() - 190, 255, 150, 20);
|
||||||
createButton.setBounds(getWidth() - 190, 325, 150, 30);
|
createButton.setBounds(getWidth() - 190, 325, 150, 30);
|
||||||
RandomButton.setBounds(getWidth() - 190, 365, 150, 30);
|
RandomButton.setBounds(getWidth() - 190, 365, 150, 30);
|
||||||
removeObjectsButton.setBounds(getWidth()-190, 505, 150, 30);
|
removeObjectsButton.setBounds(getWidth() - 190, 505, 150, 30);
|
||||||
TextField.setBounds(getWidth() - 190, 545, 150, 30);
|
TextField.setBounds(getWidth() - 190, 545, 150, 30);
|
||||||
removeButton.setBounds(getWidth() - 190, 585, 150, 30);
|
removeButton.setBounds(getWidth() - 190, 585, 150, 30);
|
||||||
GoToCheckButton.setBounds(getWidth() - 190, 625, 150, 30);
|
GoToCheckButton.setBounds(getWidth() - 190, 625, 150, 30);
|
||||||
@ -242,8 +280,72 @@ public class FormStormtrooperCollection extends JFrame {
|
|||||||
add(GoToCheckButton);
|
add(GoToCheckButton);
|
||||||
add(RandomButton);
|
add(RandomButton);
|
||||||
add(RefreshButton);
|
add(RefreshButton);
|
||||||
|
fileMenu.add(loadItem);
|
||||||
|
fileMenu.add(saveItem);
|
||||||
|
fileMenu.add(loadCollection);
|
||||||
|
fileMenu.add(saveCollection);
|
||||||
|
fileMenu.addSeparator();
|
||||||
|
menuBar.add(fileMenu);
|
||||||
|
setJMenuBar(menuBar);
|
||||||
setVisible(true);
|
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() {
|
private void RerfreshListBoxItems() {
|
||||||
DefaultListModel<String> list = new DefaultListModel<String>();
|
DefaultListModel<String> list = new DefaultListModel<String>();
|
||||||
for (String name : _storageCollection.Keys()) {
|
for (String name : _storageCollection.Keys()) {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import Drawnings.Engines.NumberOfEngines;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
Loading…
Reference in New Issue
Block a user