Compare commits
1 Commits
LabWork6
...
LabWorking
| Author | SHA1 | Date | |
|---|---|---|---|
| 89940488db |
25
ProjectMonorail/.idea/workspace.xml
generated
25
ProjectMonorail/.idea/workspace.xml
generated
@@ -5,8 +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/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/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" />
|
||||
@@ -33,16 +39,16 @@
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"Application.Program.executor": "Run",
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"git-widget-placeholder": "LabWork6",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "C:/Учеба/AgarioGame"
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"Application.Program.executor": "Run",
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"git-widget-placeholder": "LabWorking__6",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "C:/Учеба/AgarioGame"
|
||||
}
|
||||
}</component>
|
||||
}]]></component>
|
||||
<component name="RunManager">
|
||||
<configuration name="Program" type="Application" factoryName="Application">
|
||||
<option name="MAIN_CLASS_NAME" value="Scripts.Program" />
|
||||
@@ -56,7 +62,6 @@
|
||||
<attachedChunks>
|
||||
<set>
|
||||
<option value="jdk-21.0.2-openjdk-21.0.2-4caba194b151-4f524021" />
|
||||
<option value="jdk-22-openjdk-22-3183f394aec4-bad0321e" />
|
||||
</set>
|
||||
</attachedChunks>
|
||||
</component>
|
||||
|
||||
Binary file not shown.
@@ -1,61 +0,0 @@
|
||||
package Scripts.CollectionAdditionalObjects;
|
||||
|
||||
import Scripts.Drawing.DrawingModernMonorail;
|
||||
import Scripts.Drawing.DrawingMonorail;
|
||||
import Scripts.Entities.EntityModernMonorail;
|
||||
import Scripts.Entities.EntityMonorail;
|
||||
import Scripts.Wheels.IDrawingWheels;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Random;
|
||||
|
||||
public class AdditionalCollections <T extends EntityMonorail, U extends IDrawingWheels>{
|
||||
public T[] _collectionEntity;
|
||||
public U[] _collectionDecks;
|
||||
public AdditionalCollections(int size, Class<T> type1, Class<T> type2) {
|
||||
_collectionEntity = (T[]) Array.newInstance(type1, size);
|
||||
_collectionDecks = (U[]) Array.newInstance(type2, size);
|
||||
CountEntities = size;
|
||||
CountDecks = size;
|
||||
}
|
||||
public int CountEntities;
|
||||
public int CountDecks;
|
||||
public int Insert(T entity) {
|
||||
int index = 0;
|
||||
while (index < CountEntities) {
|
||||
if (_collectionEntity[index] == null)
|
||||
{
|
||||
_collectionEntity[index] = entity;
|
||||
return index;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public int Insert(U decks) {
|
||||
int index = 0;
|
||||
while (index < CountDecks) {
|
||||
if (_collectionDecks[index] == null)
|
||||
{
|
||||
_collectionDecks[index] = decks;
|
||||
return index;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public DrawingMonorail CreateAdditionalCollectionMonorail() {
|
||||
Random random = new Random();
|
||||
if (_collectionEntity == null || _collectionDecks == null) return null;
|
||||
T entity = _collectionEntity[random.nextInt(CountEntities)];
|
||||
U wheels = _collectionDecks[random.nextInt(CountDecks)];
|
||||
DrawingMonorail drawingMonorail = null;
|
||||
if (entity instanceof EntityModernMonorail) {
|
||||
drawingMonorail = new DrawingModernMonorail((EntityModernMonorail) entity, wheels);
|
||||
}
|
||||
else {
|
||||
drawingMonorail = new DrawingMonorail(entity, wheels);
|
||||
}
|
||||
return drawingMonorail;
|
||||
}
|
||||
}
|
||||
@@ -7,13 +7,18 @@ import java.util.NoSuchElementException;
|
||||
|
||||
public class ListGenericObjects<T> implements ICollectionGenericObjects<T> {
|
||||
private List<T> _collection;
|
||||
private int _maxCount;
|
||||
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) {
|
||||
@@ -25,11 +30,6 @@ public class ListGenericObjects<T> implements ICollectionGenericObjects<T> {
|
||||
_collection = new ArrayList<T>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionType GetCollectionType() {
|
||||
return collectionType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T Get(int position)
|
||||
{
|
||||
|
||||
@@ -8,8 +8,8 @@ import java.util.NoSuchElementException;
|
||||
|
||||
public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T>
|
||||
{
|
||||
private CollectionType collectionType = CollectionType.Massive;
|
||||
private T[] _collection;
|
||||
private CollectionType collectionType = CollectionType.Massive;
|
||||
private int Count;
|
||||
public void SetMaxCount(int size) {
|
||||
if (size > 0) {
|
||||
@@ -24,6 +24,7 @@ public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T>
|
||||
public CollectionType GetCollectionType() {
|
||||
return collectionType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return Count;
|
||||
@@ -56,6 +57,7 @@ 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>() {
|
||||
|
||||
@@ -66,7 +66,7 @@ public class StorageCollection<T extends DrawingMonorail> {
|
||||
sb.append(value.getValue().getCount());
|
||||
sb.append(_separatorForKeyValueS);
|
||||
for (T monorail : value.getValue().GetItems()) {
|
||||
String data = ExtentionDrawningMonorail.GetDataForSave((DrawingMonorail)monorail);
|
||||
String data = ExtentionDrawningMonorail.GetDataForSave((DrawingMonorail) monorail);
|
||||
if (data.isEmpty()) continue;
|
||||
sb.append(data);
|
||||
sb.append(_separatorItemsS);
|
||||
@@ -132,8 +132,8 @@ public class StorageCollection<T extends DrawingMonorail> {
|
||||
collection.SetMaxCount(Integer.parseInt(record[2]));
|
||||
String[] set = record[3].split(_separatorItems);
|
||||
for (String elem : set) {
|
||||
DrawingMonorail drawingMonorail = ExtentionDrawningMonorail.CreateDrawingMonorail(elem);
|
||||
if (collection.Insert((T) drawingMonorail) == -1)
|
||||
DrawingMonorail ship = ExtentionDrawningMonorail.CreateDrawingShip(elem);
|
||||
if (collection.Insert((T) ship) == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -153,35 +153,29 @@ public class StorageCollection<T extends DrawingMonorail> {
|
||||
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;
|
||||
|
||||
if (_storages.containsKey(s)) {
|
||||
_storages.get(s).ClearCollection();
|
||||
|
||||
collection = _storages.get(s);
|
||||
|
||||
if (record[1] == "Massive" && collection instanceof ListGenericObjects<T> || record[1] == "List" && collection instanceof MassiveGenericObjects<T>) collection = CreateCollection(record[1]);
|
||||
ICollectionGenericObjects<T> collection = CreateCollection(record[1]);
|
||||
if (collection == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
collection = CreateCollection(record[1]);
|
||||
_storages.put(record[0], collection);
|
||||
}
|
||||
|
||||
collection.SetMaxCount(Integer.parseInt(record[2]));
|
||||
String[] set = record[3].split(_separatorItems);
|
||||
for (String elem : set) {
|
||||
DrawingMonorail drawingMonorail = ExtentionDrawningMonorail.CreateDrawingMonorail(elem);
|
||||
if (collection.Insert((T) drawingMonorail) == -1)
|
||||
DrawingMonorail monorail = ExtentionDrawningMonorail.CreateDrawingShip(elem);
|
||||
if (collection.Insert((T) monorail) == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
_storages.put(record[0], collection);
|
||||
return true;
|
||||
}
|
||||
catch (IOException e) {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package Scripts.Drawing;
|
||||
|
||||
import Scripts.Entities.EntityMonorail;
|
||||
import Scripts.Wheels.*;
|
||||
import Scripts.Wheels.DrawingWheels;
|
||||
import Scripts.Wheels.IDrawingWheels;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
@@ -233,17 +234,4 @@ public class DrawingMonorail {
|
||||
|
||||
_wheels.DrawWheels(g2, coordinatesX, _startPositionY + 30, _entityMonorail.getBodyColor());
|
||||
}
|
||||
|
||||
public String[] GetStringRepresentationDecks() {
|
||||
if (_wheels.GetOrnament() instanceof DrawOrnament) {
|
||||
return new String[]{String.valueOf(_wheels.getCountWheels()), "DrawingDecksType1"};
|
||||
}
|
||||
else if (_wheels.GetOrnament() instanceof DrawOrnamentOval) {
|
||||
return new String[]{String.valueOf(_wheels.getCountWheels()), "DrawingDecksType2"};
|
||||
}
|
||||
else if (_wheels.GetOrnament() instanceof DrawOrnamentTriangle) {
|
||||
return new String[]{String.valueOf(_wheels.getCountWheels()), "DrawingDecksType3"};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package Scripts.Drawing;
|
||||
|
||||
import Scripts.Entities.EntityModernMonorail;
|
||||
import Scripts.Entities.EntityMonorail;
|
||||
import Scripts.Wheels.*;
|
||||
import Scripts.Wheels.IDrawingWheels;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -10,20 +10,20 @@ import java.util.Collections;
|
||||
public class ExtentionDrawningMonorail {
|
||||
private static String _separatorForObjectS = ":";
|
||||
private static String _separatorForObject = "\\:";
|
||||
public static DrawingMonorail CreateDrawingMonorail(String info) {
|
||||
public static DrawingMonorail CreateDrawingShip(String info) {
|
||||
String[] strs = info.split(_separatorForObject);
|
||||
EntityMonorail entityMonorail;
|
||||
IDrawingWheels wheels = new DrawingWheels();
|
||||
IDrawingWheels wheels = null;
|
||||
if (strs.length == 8)
|
||||
{
|
||||
String s = strs[8];
|
||||
switch (s) {
|
||||
case "DrawingDecksType1":
|
||||
wheels.SetOrnament(new DrawOrnament());
|
||||
wheels = new DrawingDecksType1();
|
||||
case "DrawingDecksType2":
|
||||
wheels.SetOrnament(new DrawOrnamentOval());
|
||||
wheels = new DrawingDecksType2();
|
||||
case "DrawingDecksType3":
|
||||
wheels.SetOrnament(new DrawOrnamentTriangle());
|
||||
wheels = new DrawingDecksType3();
|
||||
}
|
||||
if (wheels != null) wheels.SetCountWheels(Integer.parseInt(strs[7]));
|
||||
}
|
||||
@@ -31,18 +31,18 @@ public class ExtentionDrawningMonorail {
|
||||
String s = strs[5];
|
||||
switch (s) {
|
||||
case "DrawingDecksType1":
|
||||
wheels.SetOrnament(new DrawOrnament());
|
||||
wheels = new DrawingDecksType1();
|
||||
case "DrawingDecksType2":
|
||||
wheels.SetOrnament(new DrawOrnamentOval());
|
||||
wheels = new DrawingDecksType2();
|
||||
case "DrawingDecksType3":
|
||||
wheels.SetOrnament(new DrawOrnamentTriangle());
|
||||
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);
|
||||
return new DrawingModernMonorail((EntityModernMonorail) entityMonorail, wheels);
|
||||
}
|
||||
entityMonorail = EntityMonorail.CreateEntityMonorail(strs);
|
||||
if (entityMonorail != null)
|
||||
|
||||
@@ -13,7 +13,7 @@ public class EntityModernMonorail extends EntityMonorail {
|
||||
public boolean getMonorailTrack() {return _monorailTrack;}
|
||||
public boolean getCabin() {return _cabin;}
|
||||
|
||||
public void setAdditionalColor(Color value) {_additionalColor = value;}
|
||||
public void setAdditionalColor(Color value) {_additionalColor = _additionalColor;}
|
||||
public void setMonorailTrack(Boolean value) { _monorailTrack = value;}
|
||||
public void setCabin(Boolean value) { _cabin = value;}
|
||||
|
||||
@@ -27,23 +27,20 @@ public class EntityModernMonorail extends EntityMonorail {
|
||||
_monorailTrack = monorailTrack;
|
||||
_cabin = cabin;
|
||||
|
||||
Step = _speed * 100/ (int)_weight;
|
||||
Step = _speed * 100/ (float)_weight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] GetStringRepresentation()
|
||||
{
|
||||
Integer speed = _speed;
|
||||
Float weight = _weight;
|
||||
|
||||
return new String[]{"EntityModernMonorail", speed.toString(), weight.toString(),
|
||||
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 (!Objects.equals(strs[0], "EntityModernMonorail"))
|
||||
if (strs.length != 10 || !Objects.equals(strs[0], "EntityModernMonorail"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ 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() {
|
||||
@@ -30,27 +30,27 @@ public class EntityMonorail {
|
||||
_weight = weight <= 0 ? rnd.nextInt(100)+500 : weight;
|
||||
_bodyColor = bodyColor;
|
||||
|
||||
Step = _speed * 100/ (int)_weight;
|
||||
Step = _speed * 100/ (float)_weight;
|
||||
}
|
||||
|
||||
public String[] GetStringRepresentation()
|
||||
{
|
||||
Integer speed = _speed;
|
||||
Float weight = _weight;
|
||||
|
||||
return new String[]{"EntityMonorail", speed.toString(), weight.toString(), colorToHexString(_bodyColor)};
|
||||
return new String[]{"EntityMonorail", _speed.toString(), _weight.toString(), colorToHexString(_bodyColor)};
|
||||
}
|
||||
|
||||
public static EntityMonorail CreateEntityMonorail(String[] strs)
|
||||
{
|
||||
if (!Objects.equals(strs[0], "EntityMonorail"))
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -37,14 +37,6 @@ public class FormMonorailCollection extends JFrame{
|
||||
private JButton RefreshButton = new JButton("Обновить");
|
||||
private JComboBox ComboBoxCollections = new JComboBox(new String[]{"", "Хранилище"});
|
||||
private JFormattedTextField TextField;
|
||||
private JFormattedTextField MaskedTextField;
|
||||
private JMenuBar menuBar = new JMenuBar();
|
||||
private JMenu fileMenu = new JMenu("File");
|
||||
private JMenuItem loadItem = new JMenuItem("Load");
|
||||
private JMenuItem saveItem = new JMenuItem("Save");
|
||||
private JMenuItem loadCollection = new JMenuItem("Load coll");
|
||||
private JMenuItem saveCollection = new JMenuItem("Save coll");
|
||||
|
||||
public FormMonorailCollection(String title, Dimension dimension) {
|
||||
this.title = title;
|
||||
this.dimension = dimension;
|
||||
@@ -225,37 +217,6 @@ public class FormMonorailCollection extends JFrame{
|
||||
}
|
||||
});
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
||||
buttonCreateCompany.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@@ -296,14 +257,6 @@ public class FormMonorailCollection extends JFrame{
|
||||
}
|
||||
});
|
||||
|
||||
fileMenu.add(loadItem);
|
||||
fileMenu.add(saveItem);
|
||||
fileMenu.add(loadCollection);
|
||||
fileMenu.add(saveCollection);
|
||||
fileMenu.addSeparator();
|
||||
menuBar.add(fileMenu);
|
||||
setJMenuBar(menuBar);
|
||||
|
||||
ButtonGroup radioButtonsGroup = new ButtonGroup();
|
||||
JLabel labelCollectionName = new JLabel("Название коллекции");
|
||||
radioButtonsGroup.add(radioButtonMassive);
|
||||
@@ -348,60 +301,6 @@ public class FormMonorailCollection extends JFrame{
|
||||
add(RefreshButton);
|
||||
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()) {
|
||||
|
||||
@@ -35,9 +35,9 @@ public class FormMonorailConfig extends JFrame {
|
||||
private JLabel labelBodyColor = new JLabel("Основной цвет", SwingConstants.CENTER);
|
||||
private JLabel labelAdditionalColor = new JLabel("Дополнительный цвет", SwingConstants.CENTER);
|
||||
private JLabel labelWheels = new JLabel("Тип двигателей",SwingConstants.CENTER);
|
||||
private JLabel labelDefaultWheels = new JLabel("Классические",SwingConstants.CENTER);
|
||||
private JLabel labelOvalOrnament = new JLabel("Овальные", SwingConstants.CENTER);
|
||||
private JLabel labelTriangleOrnament = new JLabel("Треугольные", SwingConstants.CENTER);
|
||||
private 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();
|
||||
@@ -121,9 +121,9 @@ public class FormMonorailConfig extends JFrame {
|
||||
labelModernMonorail.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
labelBodyColor.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
labelAdditionalColor.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
labelDefaultWheels.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
labelOvalOrnament.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
labelTriangleOrnament.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||
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) {
|
||||
@@ -146,17 +146,17 @@ public class FormMonorailConfig extends JFrame {
|
||||
labelModernMonorail.addMouseListener(labelObjectsMouseDown);
|
||||
labelModernMonorail.setTransferHandler(labelObjectsTransferHandler);
|
||||
|
||||
MouseAdapter labelWheelsMouseDown = new MouseAdapter() {
|
||||
MouseAdapter labelEnginesMouseDown = new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
((JLabel) e.getComponent()).getTransferHandler().exportAsDrag(((JLabel) e.getComponent()), e, TransferHandler.COPY);
|
||||
}
|
||||
};
|
||||
|
||||
labelDefaultWheels.addMouseListener(labelWheelsMouseDown);
|
||||
labelOvalOrnament.addMouseListener(labelWheelsMouseDown);
|
||||
labelTriangleOrnament.addMouseListener(labelWheelsMouseDown);
|
||||
labelDefaultWheels.setTransferHandler(new TransferHandler() {
|
||||
labelDefaultEngines.addMouseListener(labelEnginesMouseDown);
|
||||
labelOvalEngines.addMouseListener(labelEnginesMouseDown);
|
||||
labelTriangleEngines.addMouseListener(labelEnginesMouseDown);
|
||||
labelDefaultEngines.setTransferHandler(new TransferHandler() {
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {return TransferHandler.COPY;}
|
||||
|
||||
@@ -165,7 +165,7 @@ public class FormMonorailConfig extends JFrame {
|
||||
return new WheelsTransferable(new DrawingWheels());
|
||||
}
|
||||
});
|
||||
labelOvalOrnament.setTransferHandler(new TransferHandler() {
|
||||
labelOvalEngines.setTransferHandler(new TransferHandler() {
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {return TransferHandler.COPY;}
|
||||
|
||||
@@ -174,7 +174,7 @@ public class FormMonorailConfig extends JFrame {
|
||||
return new WheelsTransferable(new DrawOrnamentOval());
|
||||
}
|
||||
});
|
||||
labelTriangleOrnament.setTransferHandler(new TransferHandler() {
|
||||
labelTriangleEngines.setTransferHandler(new TransferHandler() {
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {return TransferHandler.COPY;}
|
||||
|
||||
@@ -300,8 +300,12 @@ public class FormMonorailConfig extends JFrame {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_drawingMonorail == null) return;
|
||||
|
||||
company._collection.Insert(_drawingMonorail);
|
||||
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();
|
||||
}
|
||||
@@ -326,9 +330,9 @@ public class FormMonorailConfig extends JFrame {
|
||||
labelBodyColor.setBounds(500,5,100, 40);
|
||||
labelAdditionalColor.setBounds(605,5,170,40);
|
||||
labelWheels.setBounds(225,190,150,15);
|
||||
labelDefaultWheels.setBounds(140, 210, 100, 40);
|
||||
labelOvalOrnament.setBounds(250, 210, 100,40);
|
||||
labelTriangleOrnament.setBounds(360,210,100,40);
|
||||
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);
|
||||
@@ -350,10 +354,10 @@ public class FormMonorailConfig extends JFrame {
|
||||
add(labelColor);
|
||||
add(labelBodyColor);
|
||||
add(labelAdditionalColor);
|
||||
add(labelDefaultWheels);
|
||||
add(labelDefaultWheels);
|
||||
add(labelOvalOrnament);
|
||||
add(labelTriangleOrnament);
|
||||
add(labelDefaultEngines);
|
||||
add(labelDefaultEngines);
|
||||
add(labelOvalEngines);
|
||||
add(labelTriangleEngines);
|
||||
add(spinnerSpeed);
|
||||
add(spinnerWeight);
|
||||
add(spinnerNumberOfWheels);
|
||||
|
||||
@@ -13,8 +13,6 @@ public class DrawingWheels implements IDrawingWheels{
|
||||
_ornament = ornament;
|
||||
}
|
||||
|
||||
public IOrnament GetOrnament() {return _ornament;}
|
||||
|
||||
public void SetCountWheels(int Count){
|
||||
for (CountWheels temp: CountWheels.values())
|
||||
if (temp.getCountWheels() == Count){
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.awt.*;
|
||||
|
||||
public interface IDrawingWheels {
|
||||
public void SetOrnament(IOrnament ornament);
|
||||
IOrnament GetOrnament();
|
||||
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