Compare commits
No commits in common. "a180fa3b0a4eee89d8c6970689d6b6be22e26c94" and "506a4eb234df123f1ede895fe4d16e9a0ce8bf28" have entirely different histories.
a180fa3b0a
...
506a4eb234
@ -1,17 +0,0 @@
|
|||||||
package ProjectElectricLocomotive.src.CollectionGenericObjects;
|
|
||||||
|
|
||||||
public enum CollectionType
|
|
||||||
{
|
|
||||||
None(0),
|
|
||||||
Massive (1),
|
|
||||||
List (2);
|
|
||||||
private final int Value;
|
|
||||||
|
|
||||||
CollectionType(int value) {
|
|
||||||
Value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int GetCountDeck() {
|
|
||||||
return Value;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
package ProjectElectricLocomotive.src.CollectionGenericObjects;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ListGenericObjects<T> implements ICollectionGenericObjects<T> {
|
|
||||||
private final List<T> collection;
|
|
||||||
|
|
||||||
private int maxCount;
|
|
||||||
|
|
||||||
public int getCount() {
|
|
||||||
return collection.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaxCount(int value) {
|
|
||||||
if (value > 0) {
|
|
||||||
maxCount = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ListGenericObjects() {
|
|
||||||
collection = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public T get(int position) {
|
|
||||||
if (position < 0 || position >= collection.size()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return collection.get(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int insert(T obj) {
|
|
||||||
return insert(obj, collection.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
public int insert(T obj, int position) {
|
|
||||||
if (maxCount == collection.size() || position < 0 || position > collection.size()) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
collection.add(position, obj);
|
|
||||||
return collection.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
public T remove(int position) {
|
|
||||||
if (position < 0 || position >= collection.size()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return collection.remove(position);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +1,8 @@
|
|||||||
package ProjectElectricLocomotive.src.CollectionGenericObjects;
|
package ProjectElectricLocomotive.src.CollectionGenericObjects;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T>
|
public class MassiveGenericObjects<T extends Object> implements ICollectionGenericObjects<T>
|
||||||
{
|
{
|
||||||
private T[] _collection;
|
private T[] _collection;
|
||||||
|
|
||||||
@ -13,24 +12,14 @@ public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMaxCount(int value) {
|
public void setMaxCount(int maxCount) {
|
||||||
if (value > 0) {
|
if (maxCount > 0) {
|
||||||
if (_collection.length > 0) {
|
_collection = (T[]) new Object[maxCount];
|
||||||
if (value > _collection.length) {
|
|
||||||
T[] newArray = Arrays.copyOf(_collection, value);
|
|
||||||
_collection = newArray;
|
|
||||||
} else if (value < _collection.length) {
|
|
||||||
T[] newArray = Arrays.copyOf(_collection, value);
|
|
||||||
_collection = newArray;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
_collection = (T[]) new Object[value];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MassiveGenericObjects() {
|
public MassiveGenericObjects() {
|
||||||
_collection = (T[]) new Object[0];
|
_collection = (T[]) new Object[0]; // Create an empty array of type T
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public int insert(T obj) {
|
public int insert(T obj) {
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
package ProjectElectricLocomotive.src.CollectionGenericObjects;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class StorageCollection<T extends Object> {
|
|
||||||
|
|
||||||
private final Map<String, ICollectionGenericObjects<T>> storage;
|
|
||||||
|
|
||||||
|
|
||||||
public List<String> getKeys() {
|
|
||||||
return new ArrayList<>(storage.keySet());
|
|
||||||
}
|
|
||||||
|
|
||||||
public StorageCollection() {
|
|
||||||
storage = new HashMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addCollection(String name, CollectionType collectionType) {
|
|
||||||
if (name == null || storage.containsKey(name)) return;
|
|
||||||
if (collectionType == CollectionType.Massive) {
|
|
||||||
storage.put(name, new MassiveGenericObjects<>());
|
|
||||||
} else if (collectionType == CollectionType.List) {
|
|
||||||
storage.put(name, new ListGenericObjects<>());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public T GetShip(String name, int ind){
|
|
||||||
if (name == null || !storage.containsKey(name)) return null;
|
|
||||||
return storage.get(name).get(ind);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void delCollection(String name) {
|
|
||||||
if(!storage.containsKey(name)) return;
|
|
||||||
storage.remove(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ICollectionGenericObjects<T> get(String name) {
|
|
||||||
return storage.get(name);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +1,10 @@
|
|||||||
package ProjectElectricLocomotive.src.Forms;
|
package ProjectElectricLocomotive.src.Forms;
|
||||||
|
|
||||||
import ProjectElectricLocomotive.src.CollectionGenericObjects.*;
|
import ProjectElectricLocomotive.src.CollectionGenericObjects.AbstractCompany;
|
||||||
|
import ProjectElectricLocomotive.src.CollectionGenericObjects.LocomotiveDepotService;
|
||||||
|
import ProjectElectricLocomotive.src.CollectionGenericObjects.MassiveGenericObjects;
|
||||||
import ProjectElectricLocomotive.src.Drawnings.DrawingElectricLocomotive;
|
import ProjectElectricLocomotive.src.Drawnings.DrawingElectricLocomotive;
|
||||||
import ProjectElectricLocomotive.src.Drawnings.DrawingLocomotive;
|
import ProjectElectricLocomotive.src.Drawnings.DrawingLocomotive;
|
||||||
import java.util.Queue;
|
|
||||||
import java.util.Stack;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@ -15,18 +15,17 @@ public class DrawingLocomotiveCollection extends JPanel
|
|||||||
private final FormLocomotiveCollection field;
|
private final FormLocomotiveCollection field;
|
||||||
private AbstractCompany _company = null;
|
private AbstractCompany _company = null;
|
||||||
|
|
||||||
private Stack<DrawingLocomotive> delLocomotive;
|
|
||||||
private final StorageCollection<DrawingLocomotive> storageCollection;
|
|
||||||
|
|
||||||
public DrawingLocomotiveCollection(FormLocomotiveCollection field) {
|
public DrawingLocomotiveCollection(FormLocomotiveCollection field) {
|
||||||
this.field = field;
|
this.field = field;
|
||||||
|
|
||||||
storageCollection = new StorageCollection<DrawingLocomotive>();
|
|
||||||
delLocomotive = new Stack<DrawingLocomotive>();
|
|
||||||
}
|
}
|
||||||
void comboBoxSelectorCompany_SelectedIndexChanged(String text)
|
void comboBoxSelectorCompany_SelectedIndexChanged(String text)
|
||||||
{
|
{
|
||||||
field.manageBox.setEnabled(false);
|
switch (text)
|
||||||
|
{
|
||||||
|
case "Хранилище":
|
||||||
|
_company = new LocomotiveDepotService(field.pictureBox.getWidth(), field.pictureBox.getHeight(), new MassiveGenericObjects<DrawingLocomotive>());
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertNewLocomotive(DrawingLocomotive _drawingLocomotive)
|
public void insertNewLocomotive(DrawingLocomotive _drawingLocomotive)
|
||||||
@ -93,11 +92,7 @@ public class DrawingLocomotiveCollection extends JPanel
|
|||||||
int pos = Integer.parseInt(maskedTextField.getText());
|
int pos = Integer.parseInt(maskedTextField.getText());
|
||||||
int choice = JOptionPane.showConfirmDialog(null, "Удалить объект?", "Удаление", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
int choice = JOptionPane.showConfirmDialog(null, "Удалить объект?", "Удаление", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||||
if (choice == JOptionPane.NO_OPTION) return;
|
if (choice == JOptionPane.NO_OPTION) return;
|
||||||
DrawingLocomotive obj = _company.remove(_company, pos);
|
if (_company.remove(_company, pos) != null) {
|
||||||
|
|
||||||
|
|
||||||
if (obj != null) {
|
|
||||||
delLocomotive.add(obj);
|
|
||||||
JOptionPane.showMessageDialog(null, "Объект удален");
|
JOptionPane.showMessageDialog(null, "Объект удален");
|
||||||
field.pictureBox.setIcon(new ImageIcon(_company.show(field.pictureBox)));
|
field.pictureBox.setIcon(new ImageIcon(_company.show(field.pictureBox)));
|
||||||
} else {
|
} else {
|
||||||
@ -124,63 +119,5 @@ public class DrawingLocomotiveCollection extends JPanel
|
|||||||
if (_company == null) return;
|
if (_company == null) return;
|
||||||
field.pictureBox.setIcon(new ImageIcon(_company.show(field.pictureBox)));
|
field.pictureBox.setIcon(new ImageIcon(_company.show(field.pictureBox)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ButtonCollectionAdd_Click() {
|
|
||||||
if (field.collectionTextBox.getText().isEmpty() || (!field.radioButtonList.isSelected() && !field.radioButtonMassive.isSelected()) || (field.radioButtonList.isSelected() && field.radioButtonMassive.isSelected())) {
|
|
||||||
JOptionPane.showMessageDialog(null, "Не все данные заполнены", "Ошибка", JOptionPane.ERROR_MESSAGE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CollectionType collectionType = field.radioButtonList.isSelected() ? CollectionType.List : CollectionType.Massive;
|
|
||||||
storageCollection.addCollection(field.collectionTextBox.getText(), collectionType);
|
|
||||||
refreshListBoxItems();
|
|
||||||
}
|
|
||||||
public void ButtonCollectionRemove_Click()
|
|
||||||
{
|
|
||||||
if (field.listBoxCollection.getSelectedIndex() < 0) {
|
|
||||||
JOptionPane.showMessageDialog(null, "Коллекция не выбрана", "Ошибка", JOptionPane.ERROR_MESSAGE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int dialogResult = JOptionPane.showConfirmDialog(null, "Удалить коллекцию?", "Удаление", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
|
||||||
if (dialogResult == JOptionPane.YES_OPTION) {
|
|
||||||
storageCollection.delCollection(field.listBoxCollection.getSelectedValue());
|
|
||||||
refreshListBoxItems();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void refreshListBoxItems() {
|
|
||||||
DefaultListModel<String> listModel = new DefaultListModel<>();
|
|
||||||
for (String key : storageCollection.getKeys()) {
|
|
||||||
listModel.addElement(key);
|
|
||||||
}
|
|
||||||
field.listBoxCollection.setModel(listModel);
|
|
||||||
}
|
|
||||||
public void ButtonCreateCompany_Click() {
|
|
||||||
if (field.listBoxCollection.getSelectedIndex() < 0) {
|
|
||||||
JOptionPane.showMessageDialog(null, "Коллекция не выбрана", "Ошибка", JOptionPane.ERROR_MESSAGE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ICollectionGenericObjects<DrawingLocomotive> collection = storageCollection.get(field.listBoxCollection.getSelectedValue());
|
|
||||||
if (collection == null) {
|
|
||||||
JOptionPane.showMessageDialog(null, "Коллекция не проинициализирована", "Ошибка", JOptionPane.ERROR_MESSAGE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (field.comboBoxSelectorCompany.getSelectedItem().toString()) {
|
|
||||||
case "Хранилище":
|
|
||||||
_company = new LocomotiveDepotService(field.pictureBox.getWidth(), field.pictureBox.getHeight(), collection);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
field.setPanelEnabled(true);
|
|
||||||
refreshListBoxItems();
|
|
||||||
}
|
|
||||||
public void ButtonCheckDel()
|
|
||||||
{
|
|
||||||
if(delLocomotive.isEmpty()) return;
|
|
||||||
FormElectricLocomotive form = new FormElectricLocomotive(delLocomotive.peek());
|
|
||||||
delLocomotive.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,29 +9,16 @@ import java.text.ParseException;
|
|||||||
public class FormLocomotiveCollection extends JFrame {
|
public class FormLocomotiveCollection extends JFrame {
|
||||||
protected int Width;
|
protected int Width;
|
||||||
private int Height;
|
private int Height;
|
||||||
private JPanel storageBox;
|
|
||||||
protected JPanel manageBox;
|
|
||||||
private JPanel groupBoxTools;
|
private JPanel groupBoxTools;
|
||||||
private JButton buttonAddElectricLocomotive;
|
private JButton buttonAddElectricLocomotive;
|
||||||
private JButton buttonAddLocomotive;
|
private JButton buttonAddLocomotive;
|
||||||
protected JComboBox<String> comboBoxSelectorCompany;
|
private JComboBox<String> comboBoxSelectorCompany;
|
||||||
private JButton buttonRefresh;
|
private JButton buttonRefresh;
|
||||||
private JButton buttonGoToCheck;
|
private JButton buttonGoToCheck;
|
||||||
private JButton buttonRemoveLocomotive;
|
private JButton buttonRemoveLocomotive;
|
||||||
private JButton buttonCreateSpecialLocomotive;
|
private JButton buttonCreateSpecialLocomotive;
|
||||||
private JFormattedTextField maskedTextBoxPosition;
|
private JFormattedTextField maskedTextBoxPosition;
|
||||||
|
|
||||||
protected JTextField collectionTextBox;
|
|
||||||
|
|
||||||
protected JLabel pictureBox;
|
protected JLabel pictureBox;
|
||||||
protected JLabel nameCollection;
|
|
||||||
protected JButton buttonAddCollection;
|
|
||||||
protected JButton ButtonGoToCheckRemoved;
|
|
||||||
protected JList<String> listBoxCollection;
|
|
||||||
protected JButton buttonRemoveCollection;
|
|
||||||
protected JButton buttonAddCompany;
|
|
||||||
protected JRadioButton radioButtonList;
|
|
||||||
protected JRadioButton radioButtonMassive;
|
|
||||||
|
|
||||||
DrawingLocomotiveCollection field = new DrawingLocomotiveCollection(this);
|
DrawingLocomotiveCollection field = new DrawingLocomotiveCollection(this);
|
||||||
|
|
||||||
@ -48,26 +35,15 @@ public class FormLocomotiveCollection extends JFrame {
|
|||||||
|
|
||||||
private void initComponents() {
|
private void initComponents() {
|
||||||
groupBoxTools = new JPanel();
|
groupBoxTools = new JPanel();
|
||||||
storageBox = new JPanel();
|
|
||||||
manageBox = new JPanel();
|
|
||||||
buttonAddElectricLocomotive = new JButton("Добавление электровоза");
|
buttonAddElectricLocomotive = new JButton("Добавление электровоза");
|
||||||
buttonAddLocomotive = new JButton("Добавление локомотива");
|
buttonAddLocomotive = new JButton("Добавление локомотива");
|
||||||
comboBoxSelectorCompany = new JComboBox<>();
|
comboBoxSelectorCompany = new JComboBox<>();
|
||||||
buttonAddCollection = new JButton("Добавить коллекцию");
|
|
||||||
buttonRefresh = new JButton("Обновить");
|
buttonRefresh = new JButton("Обновить");
|
||||||
buttonGoToCheck = new JButton("Передать на тесты");
|
buttonGoToCheck = new JButton("Передать на тесты");
|
||||||
ButtonGoToCheckRemoved = new JButton("Тест локомотива из удаленных");
|
|
||||||
buttonRemoveLocomotive = new JButton("Удалить локомотив");
|
buttonRemoveLocomotive = new JButton("Удалить локомотив");
|
||||||
buttonCreateSpecialLocomotive = new JButton("Сгенерировать локомотив");
|
buttonCreateSpecialLocomotive = new JButton("Сгенерировать локомотив");
|
||||||
maskedTextBoxPosition = createMaskedTextField();
|
maskedTextBoxPosition = createMaskedTextField();
|
||||||
pictureBox = new JLabel();
|
pictureBox = new JLabel();
|
||||||
nameCollection = new JLabel("Название коллекции");
|
|
||||||
collectionTextBox = new JTextField();
|
|
||||||
listBoxCollection = new JList<>();
|
|
||||||
buttonRemoveCollection = new JButton("Удалить коллекцию");
|
|
||||||
radioButtonList = new JRadioButton("Список");
|
|
||||||
radioButtonMassive = new JRadioButton("Массив");
|
|
||||||
buttonAddCompany = new JButton("Создать компанию");
|
|
||||||
|
|
||||||
comboBoxSelectorCompany.addActionListener(e -> {
|
comboBoxSelectorCompany.addActionListener(e -> {
|
||||||
field.comboBoxSelectorCompany_SelectedIndexChanged((String) comboBoxSelectorCompany.getSelectedItem());
|
field.comboBoxSelectorCompany_SelectedIndexChanged((String) comboBoxSelectorCompany.getSelectedItem());
|
||||||
@ -100,55 +76,19 @@ public class FormLocomotiveCollection extends JFrame {
|
|||||||
field.ButtonCreateSpecialLocomotive_Click();
|
field.ButtonCreateSpecialLocomotive_Click();
|
||||||
repaint();
|
repaint();
|
||||||
});
|
});
|
||||||
buttonAddCollection.addActionListener(e->
|
|
||||||
{
|
|
||||||
field.ButtonCollectionAdd_Click();
|
|
||||||
repaint();
|
|
||||||
});
|
|
||||||
buttonRemoveCollection.addActionListener(e->
|
|
||||||
{
|
|
||||||
field.ButtonCollectionRemove_Click();
|
|
||||||
repaint();
|
|
||||||
});
|
|
||||||
buttonAddCompany.addActionListener(e->
|
|
||||||
{
|
|
||||||
field.ButtonCreateCompany_Click();
|
|
||||||
repaint();
|
|
||||||
});
|
|
||||||
ButtonGoToCheckRemoved.addActionListener(e->
|
|
||||||
{
|
|
||||||
field.ButtonCheckDel();
|
|
||||||
repaint();
|
|
||||||
});
|
|
||||||
|
|
||||||
storageBox.setLayout(new GridLayout(9, 1));
|
|
||||||
storageBox.add(nameCollection);
|
|
||||||
storageBox.add(radioButtonList);
|
|
||||||
storageBox.add(radioButtonMassive);
|
|
||||||
storageBox.add(collectionTextBox);
|
|
||||||
storageBox.add(buttonAddCollection);
|
|
||||||
storageBox.add(listBoxCollection);
|
|
||||||
storageBox.add(buttonRemoveCollection);
|
|
||||||
storageBox.add(comboBoxSelectorCompany);
|
|
||||||
storageBox.add(buttonAddCompany);
|
|
||||||
|
|
||||||
groupBoxTools.setBorder(BorderFactory.createTitledBorder("Инструменты"));
|
groupBoxTools.setBorder(BorderFactory.createTitledBorder("Инструменты"));
|
||||||
groupBoxTools.setLayout(new GridLayout(2, 1));
|
groupBoxTools.setLayout(new GridLayout(8, 1));
|
||||||
|
groupBoxTools.add(comboBoxSelectorCompany);
|
||||||
|
groupBoxTools.add(buttonAddLocomotive);
|
||||||
|
groupBoxTools.add(buttonAddElectricLocomotive);
|
||||||
|
groupBoxTools.add(maskedTextBoxPosition);
|
||||||
|
groupBoxTools.add(buttonRemoveLocomotive);
|
||||||
|
groupBoxTools.add(buttonGoToCheck);
|
||||||
|
groupBoxTools.add(buttonCreateSpecialLocomotive);
|
||||||
|
|
||||||
groupBoxTools.add(storageBox);
|
groupBoxTools.add(buttonRefresh);
|
||||||
|
|
||||||
manageBox.setLayout(new GridLayout(8, 1));
|
|
||||||
|
|
||||||
manageBox.add(buttonAddLocomotive);
|
|
||||||
manageBox.add(buttonAddElectricLocomotive);
|
|
||||||
manageBox.add(maskedTextBoxPosition);
|
|
||||||
manageBox.add(buttonRemoveLocomotive);
|
|
||||||
manageBox.add(ButtonGoToCheckRemoved);
|
|
||||||
manageBox.add(buttonGoToCheck);
|
|
||||||
manageBox.add(buttonCreateSpecialLocomotive);
|
|
||||||
manageBox.add(buttonRefresh);
|
|
||||||
groupBoxTools.add(manageBox);
|
|
||||||
setPanelEnabled(false);
|
|
||||||
|
|
||||||
add(groupBoxTools);
|
add(groupBoxTools);
|
||||||
add(pictureBox);
|
add(pictureBox);
|
||||||
@ -169,12 +109,6 @@ public class FormLocomotiveCollection extends JFrame {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPanelEnabled(boolean enabled) {
|
|
||||||
for (Component component : manageBox.getComponents()) {
|
|
||||||
component.setEnabled(enabled);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private JFormattedTextField createMaskedTextField() {
|
private JFormattedTextField createMaskedTextField() {
|
||||||
try {
|
try {
|
||||||
MaskFormatter formatter = new MaskFormatter("##");
|
MaskFormatter formatter = new MaskFormatter("##");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user