Pibd-12 Pyzhov_E.A. LabWork04 Hard #5

Closed
pyzhov.egor wants to merge 7 commits from LabWork04 into LabWork03
2 changed files with 66 additions and 9 deletions
Showing only changes of commit eb8da47163 - Show all commits

View File

@ -10,16 +10,25 @@ import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowEvent;
import java.util.Random;
import java.util.Stack;
public class DrawningAbstractCompany extends JComponent {
private AbstractCompany _company = null;
public void collectionComboBox_SelectedIndexChanged(JComboBox<String> obj, int width, int height) {
private final StorageCollection<DrawningBoat> storageCollection = new StorageCollection<>();
private Stack<DrawningBoat> rubbishBinStack = new Stack<>();
public boolean collectionComboBox_SelectedIndexChanged(JFrame frame, JList<String> collectionList, JComboBox<String> obj, int width, int height) {
switch (obj.getSelectedIndex()) {
case 1:
_company = new BoatSharingService(width, height, new MassiveGenericObjects<DrawningBoat>());
break;
if (collectionList.getSelectedIndex() == -1) {
JOptionPane.showMessageDialog(frame,
"Коллекция не выбрана");
return false;
}
_company = new BoatSharingService(width, height,storageCollection.getCollection(collectionList.getSelectedValue()));
return true;
default:
break;
return false;
}
}
public void createObject(int type, JFrame obj) {
@ -59,9 +68,9 @@ public class DrawningAbstractCompany extends JComponent {
return JColorChooser.showDialog(obj, "Выберите цвет", color);
}
public void deleteButtonAction(int val, Frame obj) {
public boolean deleteButtonAction(int val, Frame obj) {
if (_company == null) {
return;
return false;
}
int result = JOptionPane.showConfirmDialog(
obj,
@ -69,12 +78,17 @@ public class DrawningAbstractCompany extends JComponent {
"Подтвердение",
JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.YES_OPTION) {
if (AbstractCompany.remove(_company, val) != null) {
DrawningBoat deletableBoat = AbstractCompany.remove(_company, val);
if (deletableBoat != null) {
rubbishBinStack.add(deletableBoat);
JOptionPane.showMessageDialog(obj, "Выполнено");
return true;
} else {
JOptionPane.showMessageDialog(obj, "Удаление не удалось");
return false;
}
}
return false;
}
public void goToCheckButtonAction() {
if (_company == null) {
@ -92,10 +106,24 @@ public class DrawningAbstractCompany extends JComponent {
JFrame.setDefaultLookAndFeelDecorated(false);
JFrame frame = new JFrame("Катамаран");
FormCatamaran formCatamaran = new FormCatamaran();
formCatamaran.setDrawningBoat(boat);
formCatamaran.OpenFrame();
frame.setContentPane(formCatamaran.PanelWrapper);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(500, 200);
formCatamaran.setBoat(boat);
frame.pack();
frame.setSize(1000, 725);
frame.setVisible(true);
public boolean goToCheckFromRubbishBinAction() {
if (rubbishBinStack.isEmpty()) {
return false;
}
DrawningBoat boat = rubbishBinStack.pop();
FormCatamaran formCatamaran1 = new FormCatamaran();
formCatamaran1.setBoat(boat);
createAndShowFrame("Катамаран", formCatamaran1.PanelWrapper);
return !rubbishBinStack.isEmpty();
}
private DrawningBoat createObject;
@ -118,6 +146,35 @@ public class DrawningAbstractCompany extends JComponent {
formConstructor.getjFrameConstructor().dispatchEvent(new WindowEvent(formConstructor.getjFrameConstructor(), WindowEvent.WINDOW_CLOSING));
});
}
public StorageCollection<DrawningBoat> addCollectionButtonAction(JFrame jFrameCollectionBoats, JTextField textFieldSetCollectionName,
JRadioButton massiveRadioButton, JRadioButton listRadioButton) {
if (textFieldSetCollectionName.getText().isEmpty() || (!massiveRadioButton.isSelected() && !listRadioButton.isSelected())) {
JOptionPane.showMessageDialog(jFrameCollectionBoats, "Не все элементы заполнены", "ERROR", JOptionPane.ERROR_MESSAGE);
return null;
}
CollectionType collectionType = CollectionType.None;
if (massiveRadioButton.isSelected())
collectionType = CollectionType.Massive;
else if (listRadioButton.isSelected())
collectionType = CollectionType.List;
storageCollection.addCollection(textFieldSetCollectionName.getText(), collectionType);
return storageCollection;
}
public StorageCollection<DrawningBoat> deleteCollectionButtonAction(JFrame jFrameCollectionLocomotive, JList<String> keysList) {
if (keysList.getSelectedIndex() != -1) {
int result = JOptionPane.showConfirmDialog( jFrameCollectionLocomotive, "Удалить объект?",
"Подтверждение", JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.YES_OPTION) {
storageCollection.delCollection(keysList.getSelectedValue());
return storageCollection;
}
}
return null;
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);