сделанная работа
This commit is contained in:
parent
cece533ed5
commit
04338dc298
@ -0,0 +1,16 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
public enum CollectionType {
|
||||
None(0),
|
||||
Massive(1),
|
||||
List(2);
|
||||
|
||||
final private int collectionTypeValue;
|
||||
|
||||
CollectionType(int value){
|
||||
collectionTypeValue = value;
|
||||
}
|
||||
public int getCollectionTypeValue() {
|
||||
return collectionTypeValue;
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import Drawnings.DrawningBoat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ListGenericCollection<T extends DrawningBoat> implements ICollectionGenericObjects<T> {
|
||||
private final ArrayList<T> _collection;
|
||||
public ListGenericCollection() {
|
||||
_collection = new ArrayList<>();
|
||||
}
|
||||
private int maxCount;
|
||||
public int count;
|
||||
@Override
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
@Override
|
||||
public void setMaxCount(int count) {
|
||||
maxCount = count;
|
||||
}
|
||||
@Override
|
||||
public int insert(T obj) {
|
||||
return insert(obj, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insert(T obj, int index) {
|
||||
if (index > maxCount || index < 0 || index > count){
|
||||
return -1;
|
||||
}
|
||||
if(index == count){
|
||||
_collection.add(obj);
|
||||
}
|
||||
else {
|
||||
_collection.add(index, obj);
|
||||
}
|
||||
count = _collection.size();
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T remove(int index) {
|
||||
if (index > maxCount || index < 0 || index >= count){
|
||||
return null;
|
||||
}
|
||||
count = _collection.size() - 1;
|
||||
return _collection.remove(index);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(int index) {
|
||||
if (index >= count){
|
||||
return null;
|
||||
}
|
||||
return _collection.get(index);
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package CollectionGenericObjects;
|
||||
|
||||
import Drawnings.DrawningBoat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class StorageCollection<T extends DrawningBoat> {
|
||||
private final HashMap<String, ICollectionGenericObjects<T>> _storages;
|
||||
public final ArrayList<String> keys;
|
||||
|
||||
public StorageCollection() {
|
||||
_storages = new HashMap<>();
|
||||
keys = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addCollection(String name, CollectionType collectionType){
|
||||
if (_storages.containsKey(name) || name.isEmpty()){
|
||||
return;
|
||||
}
|
||||
switch (collectionType){
|
||||
case None:
|
||||
return;
|
||||
case Massive:
|
||||
_storages.put(name, new MassiveGenericObjects<>());
|
||||
keys.add(name);
|
||||
break;
|
||||
case List:
|
||||
_storages.put(name, new ListGenericCollection<>());
|
||||
keys.add(name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void delCollection(String name){
|
||||
_storages.remove(name);
|
||||
keys.remove(name);
|
||||
}
|
||||
|
||||
public ICollectionGenericObjects<T> getCollection(String name){
|
||||
return _storages.get(name);
|
||||
}
|
||||
|
||||
public T getObjectFromChooseCollection(String name, int ind){
|
||||
return this.getCollection(name).get(ind);
|
||||
}
|
||||
|
||||
}
|
@ -89,6 +89,8 @@ public class DrawningAbstractCompany extends JComponent {
|
||||
if (boat == null) {
|
||||
return;
|
||||
}
|
||||
JFrame.setDefaultLookAndFeelDecorated(false);
|
||||
JFrame frame = new JFrame("Катамаран");
|
||||
FormCatamaran formCatamaran = new FormCatamaran();
|
||||
formCatamaran.setDrawningBoat(boat);
|
||||
formCatamaran.OpenFrame();
|
||||
|
@ -1,12 +1,18 @@
|
||||
package Forms;
|
||||
|
||||
import CollectionGenericObjects.CollectionType;
|
||||
import CollectionGenericObjects.StorageCollection;
|
||||
import Drawnings.DrawningAbstractCompany;
|
||||
import Drawnings.DrawningBoat;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.NumberFormatter;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
public class FormBoatCollection extends JFrame {
|
||||
final private JFrame jFrameCollectionBoats = new JFrame();
|
||||
@ -34,6 +40,34 @@ public class FormBoatCollection extends JFrame {
|
||||
final private JPanel addFromConstructorPanel = new JPanel();
|
||||
final private JButton addFromConstructorButton = new JButton("Добавить из констркутора");
|
||||
|
||||
final JRadioButton massiveRadioButton = new JRadioButton("Массив");
|
||||
final JRadioButton listRadioButton = new JRadioButton("Лист");
|
||||
final JPanel radioButtonsPanel = new JPanel();
|
||||
|
||||
final JButton addCollectionButton = new JButton("Добавить коллекцию");
|
||||
final JPanel addCollectionPanel = new JPanel();
|
||||
|
||||
|
||||
final JButton createCompanyButton = new JButton("Создать компанию");
|
||||
final JPanel createCompanyPanel = new JPanel();
|
||||
|
||||
|
||||
final JButton deleteCollectionButton = new JButton("Удалить коллекцию");
|
||||
final JPanel deleteCollectionPanel = new JPanel();
|
||||
|
||||
DefaultListModel<String> listModel = new DefaultListModel<>();
|
||||
JList<String> collectionsList = new JList<>(listModel);
|
||||
final JPanel collectionsListPanel = new JPanel();
|
||||
|
||||
final JTextField setCollectionName = new JTextField();
|
||||
final JLabel setCollectionNameLabel = new JLabel("Название коллекции:");
|
||||
final JPanel setCollectionNamePanel = new JPanel();
|
||||
|
||||
final private ArrayList<Component> listOfDownPanel = new ArrayList<>();
|
||||
|
||||
final private JButton goGoToCheckFromRubbishBinButton = new JButton("<html><center>Отправить на тест<br> объект из мусорки</html>");
|
||||
final private JPanel goGoToCheckFromRubbishBinPanel = new JPanel();
|
||||
|
||||
public void OpenFrame() {
|
||||
|
||||
jFrameCollectionBoats.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
@ -48,33 +82,68 @@ public class FormBoatCollection extends JFrame {
|
||||
labelPanel.add(toolsNameLabel);
|
||||
|
||||
comboBoxPanel.setLayout(new BorderLayout());
|
||||
comboBoxPanel.setSize(new Dimension(130, 30));
|
||||
comboBoxPanel.setSize(new Dimension(170, 25));
|
||||
comboBoxPanel.add(comboBoxSelectorCompany, BorderLayout.CENTER);
|
||||
|
||||
addBoatPanel.setLayout(new BorderLayout());
|
||||
addBoatPanel.setSize(170, 40);
|
||||
addBoatPanel.setSize(170, 25);
|
||||
addBoatPanel.add(buttonAddBoat, BorderLayout.CENTER);
|
||||
|
||||
addCatamaranPanel.setLayout(new BorderLayout());
|
||||
addCatamaranPanel.setSize(170, 40);
|
||||
addCatamaranPanel.setSize(170, 25);
|
||||
addCatamaranPanel.add(buttonAddCatamaran, BorderLayout.CENTER);
|
||||
|
||||
removePanel.setLayout(new BorderLayout());
|
||||
removePanel.setSize(170, 40);
|
||||
removePanel.setSize(170, 25);
|
||||
removePanel.add(buttonRemove, BorderLayout.CENTER);
|
||||
|
||||
goToCheckPanel.setLayout(new BorderLayout());
|
||||
goToCheckPanel.setSize(170, 40);
|
||||
goToCheckPanel.setSize(170, 25);
|
||||
goToCheckPanel.add(goToCheckButton, BorderLayout.CENTER);
|
||||
|
||||
refreshPanel.setLayout(new BorderLayout());
|
||||
refreshPanel.setSize(170, 40);
|
||||
refreshPanel.setSize(170, 25);
|
||||
refreshPanel.add(refreshButton, BorderLayout.CENTER);
|
||||
|
||||
addFromConstructorPanel.setLayout(new BorderLayout());
|
||||
addFromConstructorPanel.setSize(170, 40);
|
||||
addFromConstructorPanel.setSize(170, 25);
|
||||
addFromConstructorPanel.add(addFromConstructorButton, BorderLayout.CENTER);
|
||||
|
||||
setCollectionNamePanel.setLayout(new BorderLayout());
|
||||
setCollectionNamePanel.setSize(170, 45);
|
||||
setCollectionNamePanel.add(setCollectionNameLabel, BorderLayout.NORTH);
|
||||
setCollectionNamePanel.add(setCollectionName, BorderLayout.SOUTH);
|
||||
|
||||
radioButtonsPanel.setLayout(new BorderLayout());
|
||||
radioButtonsPanel.setSize(170, 25);
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
group.add(massiveRadioButton);
|
||||
group.add(listRadioButton);
|
||||
radioButtonsPanel.add(massiveRadioButton, BorderLayout.WEST);
|
||||
radioButtonsPanel.add(listRadioButton, BorderLayout.EAST);
|
||||
|
||||
addCollectionPanel.setLayout(new BorderLayout());
|
||||
addCollectionPanel.setSize(170, 30);
|
||||
addCollectionPanel.add(addCollectionButton, BorderLayout.CENTER);
|
||||
|
||||
collectionsListPanel.setLayout(new BorderLayout());
|
||||
collectionsListPanel.setSize(170, 100);
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane(collectionsList);
|
||||
collectionsListPanel.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
deleteCollectionPanel.setLayout(new BorderLayout());
|
||||
deleteCollectionPanel.setSize(170, 30);
|
||||
deleteCollectionPanel.add(deleteCollectionButton, BorderLayout.CENTER);
|
||||
|
||||
createCompanyPanel.setLayout(new BorderLayout());
|
||||
createCompanyPanel.setSize(170, 30);
|
||||
createCompanyPanel.add(createCompanyButton, BorderLayout.CENTER);
|
||||
|
||||
goGoToCheckFromRubbishBinPanel.setLayout(new BorderLayout());
|
||||
goGoToCheckFromRubbishBinPanel.setSize(170, 50);
|
||||
goGoToCheckFromRubbishBinPanel.add(goGoToCheckFromRubbishBinButton, BorderLayout.CENTER);
|
||||
|
||||
NumberFormat format = NumberFormat.getInstance();
|
||||
NumberFormatter formatter = new NumberFormatter(format);
|
||||
formatter.setValueClass(Integer.class);
|
||||
@ -86,12 +155,18 @@ public class FormBoatCollection extends JFrame {
|
||||
JTextField textBoxPosition = new JFormattedTextField(formatter);
|
||||
JPanel textBoxPanel = new JPanel();
|
||||
textBoxPanel.setLayout(new BorderLayout());
|
||||
textBoxPanel.setSize(170, 40);
|
||||
textBoxPanel.setSize(170, 25);
|
||||
textBoxPanel.add(textBoxPosition, BorderLayout.CENTER);
|
||||
|
||||
jFrameCollectionBoats.add(toolsPanel);
|
||||
jFrameCollectionBoats.add(labelPanel);
|
||||
jFrameCollectionBoats.add(setCollectionNamePanel);
|
||||
jFrameCollectionBoats.add(radioButtonsPanel);
|
||||
jFrameCollectionBoats.add(addCollectionPanel);
|
||||
jFrameCollectionBoats.add(collectionsListPanel);
|
||||
jFrameCollectionBoats.add(deleteCollectionPanel);
|
||||
jFrameCollectionBoats.add(comboBoxPanel);
|
||||
jFrameCollectionBoats.add(createCompanyPanel);
|
||||
jFrameCollectionBoats.add(addBoatPanel);
|
||||
jFrameCollectionBoats.add(addCatamaranPanel);
|
||||
jFrameCollectionBoats.add(textBoxPanel);
|
||||
@ -99,33 +174,48 @@ public class FormBoatCollection extends JFrame {
|
||||
jFrameCollectionBoats.add(goToCheckPanel);
|
||||
jFrameCollectionBoats.add(refreshPanel);
|
||||
jFrameCollectionBoats.add(addFromConstructorPanel);
|
||||
jFrameCollectionBoats.add(goGoToCheckFromRubbishBinPanel);
|
||||
jFrameCollectionBoats.add(_company);
|
||||
|
||||
listOfDownPanel.add(buttonAddBoat);
|
||||
listOfDownPanel.add(buttonAddCatamaran);
|
||||
listOfDownPanel.add(addFromConstructorButton);
|
||||
listOfDownPanel.add(textBoxPosition);
|
||||
listOfDownPanel.add(buttonRemove);
|
||||
listOfDownPanel.add(goToCheckButton);
|
||||
listOfDownPanel.add(goGoToCheckFromRubbishBinButton);
|
||||
listOfDownPanel.add(refreshButton);
|
||||
|
||||
setEnableComponentsOfList(listOfDownPanel, false);
|
||||
jFrameCollectionBoats.addComponentListener(new ComponentAdapter() {
|
||||
public void componentResized(ComponentEvent componentEvent) {
|
||||
|
||||
labelPanel.setLocation(jFrameCollectionBoats.getWidth() - 210, 0);
|
||||
toolsPanel.setLocation(jFrameCollectionBoats.getWidth() - 233, 0);
|
||||
comboBoxPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 30);
|
||||
addBoatPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 70);
|
||||
addCatamaranPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 120);
|
||||
textBoxPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 220);
|
||||
removePanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 260);
|
||||
goToCheckPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 300);
|
||||
refreshPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 340);
|
||||
addFromConstructorPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 170);
|
||||
setCollectionNamePanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 30);
|
||||
radioButtonsPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 78);
|
||||
addCollectionPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 103);
|
||||
collectionsListPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 137);
|
||||
deleteCollectionPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, 227);
|
||||
comboBoxPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, jFrameCollectionBoats.getHeight() - 400);
|
||||
createCompanyPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, jFrameCollectionBoats.getHeight() - 370);
|
||||
goToCheckPanel.setLocation(jFrameCollectionBoats.getWidth() - 200,
|
||||
jFrameCollectionBoats.getHeight() - 320);
|
||||
goGoToCheckFromRubbishBinPanel.setLocation(jFrameCollectionBoats.getWidth() - 200,
|
||||
jFrameCollectionBoats.getHeight() - 295);
|
||||
addBoatPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, jFrameCollectionBoats.getHeight() - 241);
|
||||
addCatamaranPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, jFrameCollectionBoats.getHeight() - 214);
|
||||
addFromConstructorPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, jFrameCollectionBoats.getHeight() - 187);
|
||||
textBoxPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, jFrameCollectionBoats.getHeight() - 146);
|
||||
removePanel.setLocation(jFrameCollectionBoats.getWidth() - 200, jFrameCollectionBoats.getHeight() - 119);
|
||||
|
||||
refreshPanel.setLocation(jFrameCollectionBoats.getWidth() - 200, jFrameCollectionBoats.getHeight() - 67);
|
||||
toolsPanel.setSize(new Dimension(10, jFrameCollectionBoats.getHeight()));
|
||||
|
||||
jFrameCollectionBoats.repaint();
|
||||
}
|
||||
});
|
||||
|
||||
comboBoxSelectorCompany.addActionListener(e -> {
|
||||
|
||||
_company.collectionComboBox_SelectedIndexChanged(comboBoxSelectorCompany,
|
||||
jFrameCollectionBoats.getWidth() - 233, jFrameCollectionBoats.getHeight());
|
||||
jFrameCollectionBoats.repaint();
|
||||
|
||||
});
|
||||
buttonAddBoat.addActionListener(e -> {
|
||||
_company.createObject(0, jFrameCollectionBoats);
|
||||
jFrameCollectionBoats.repaint();
|
||||
@ -136,11 +226,16 @@ public class FormBoatCollection extends JFrame {
|
||||
});
|
||||
|
||||
buttonRemove.addActionListener(e -> {
|
||||
int pos = -1;
|
||||
if (!textBoxPosition.getText().isEmpty()) {
|
||||
if (Integer.parseInt(textBoxPosition.getText()) <= 99
|
||||
&& Integer.parseInt(textBoxPosition.getText()) >= 0) {
|
||||
int pos = Integer.parseInt(textBoxPosition.getText());
|
||||
_company.deleteButtonAction(pos, jFrameCollectionBoats);
|
||||
int inputPos = Integer.parseInt(textBoxPosition.getText());
|
||||
if (inputPos <= 99 && inputPos >= 0) {
|
||||
pos = inputPos;
|
||||
}
|
||||
}
|
||||
if (pos != -1) {
|
||||
if(_company.deleteButtonAction(pos, jFrameCollectionBoats)) {
|
||||
goGoToCheckFromRubbishBinButton.setEnabled(true);
|
||||
}
|
||||
}
|
||||
jFrameCollectionBoats.repaint();
|
||||
@ -153,11 +248,46 @@ public class FormBoatCollection extends JFrame {
|
||||
_company.goToCheckButtonAction();
|
||||
jFrameCollectionBoats.repaint();
|
||||
});
|
||||
goGoToCheckFromRubbishBinButton.addActionListener(e -> {
|
||||
goGoToCheckFromRubbishBinButton.setEnabled(_company.goToCheckFromRubbishBinAction());
|
||||
jFrameCollectionBoats.repaint();
|
||||
});
|
||||
createCompanyButton.addActionListener(e -> {
|
||||
boolean res = _company.collectionComboBox_SelectedIndexChanged(jFrameCollectionBoats, collectionsList, comboBoxSelectorCompany,
|
||||
jFrameCollectionBoats.getWidth() - 233, jFrameCollectionBoats.getHeight());
|
||||
setEnableComponentsOfList(listOfDownPanel, res);
|
||||
jFrameCollectionBoats.repaint();
|
||||
});
|
||||
addFromConstructorButton.addActionListener(e -> {
|
||||
_company.getObjFromConstructor(jFrameCollectionBoats);
|
||||
});
|
||||
addCollectionButton.addActionListener(e -> {
|
||||
StorageCollection<DrawningBoat> result = _company.addCollectionButtonAction(jFrameCollectionBoats, setCollectionName,
|
||||
massiveRadioButton, listRadioButton);
|
||||
updateCollectionsList(result);
|
||||
});
|
||||
deleteCollectionButton.addActionListener(e -> {
|
||||
StorageCollection<DrawningBoat> result = _company.deleteCollectionButtonAction(jFrameCollectionBoats, collectionsList);
|
||||
updateCollectionsList(result);
|
||||
});
|
||||
|
||||
jFrameCollectionBoats.setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
private void updateCollectionsList(StorageCollection<DrawningBoat> storageCollection) {
|
||||
if (storageCollection == null) {
|
||||
return;
|
||||
}
|
||||
listModel.clear();
|
||||
ArrayList<String> keys = storageCollection.keys;
|
||||
for (String key : keys) {
|
||||
listModel.addElement(key);
|
||||
}
|
||||
}
|
||||
private void setEnableComponentsOfList(ArrayList<Component> list, boolean type) {
|
||||
for(var i: list) {
|
||||
i.setEnabled(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user