PIbd -21 Bakalskaya E.D. LabWork4 Hard #7
@ -21,7 +21,8 @@ public class FormElectricLocomotive {
|
||||
public DrawingLocomotive SelectedLocomotive;
|
||||
public boolean IsSelect = false;
|
||||
|
||||
public JPanel getPictureBox() {
|
||||
public JPanel getPictureBox()
|
||||
{
|
||||
return pictureBox;
|
||||
}
|
||||
public FormElectricLocomotive()
|
||||
|
@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ProjectElectricLocomotive.FormLocomotiveCollections">
|
||||
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="708" height="464"/>
|
||||
<xy x="20" y="20" width="634" height="464"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
@ -12,9 +12,9 @@
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="true">
|
||||
<minimum-size width="450" height="400"/>
|
||||
<preferred-size width="450" height="400"/>
|
||||
<maximum-size width="450" height="400"/>
|
||||
<minimum-size width="400" height="300"/>
|
||||
<preferred-size width="400" height="300"/>
|
||||
<maximum-size width="400" height="300"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
@ -122,6 +122,14 @@
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="ab73" class="javax.swing.JButton" binding="Button_OpenFormRemovedLocomotives">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Открыть удаленный локо"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
@ -3,11 +3,11 @@ package ProjectElectricLocomotive;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import java.awt.*;
|
||||
import java.util.Stack;
|
||||
|
||||
//готовая лаба 3
|
||||
|
||||
public class FormLocomotiveCollections {
|
||||
FrameDopClassParameters frameDopClassParameters;
|
||||
private JPanel MainPanel;
|
||||
private JPanel pictureBoxCollections;
|
||||
private JPanel Instruments;
|
||||
@ -20,19 +20,24 @@ public class FormLocomotiveCollections {
|
||||
private JButton ButtonAddObject;
|
||||
private JList listBoxStorage;
|
||||
private JButton ButtonRemoveObject;
|
||||
private JButton Button_OpenFormRemovedLocomotives;
|
||||
public DrawingLocomotive loco;
|
||||
private DefaultListModel<String> listModel;
|
||||
final LocomotivesGenericStorage _storage;
|
||||
LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> _locomotives;
|
||||
FrameElectricLocomotive _frameRemovedLocomotives;
|
||||
|
||||
private Stack<DrawingLocomotive> stackRemoveObjects;
|
||||
FrameDopClassParameters frameDopClassParameters;
|
||||
// LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> _locomotives;
|
||||
public JPanel getPictureBoxCollections() {
|
||||
return MainPanel;
|
||||
}
|
||||
|
||||
|
||||
public FormLocomotiveCollections() {
|
||||
_locomotives = new LocomotiveGenericCollection<>(400, 300);
|
||||
_storage = new LocomotivesGenericStorage(pictureBoxCollections.getWidth(), pictureBoxCollections.getHeight());
|
||||
//_locomotives = new LocomotiveGenericCollection<>(400, 300);
|
||||
_storage = new LocomotivesGenericStorage(/*pictureBoxCollections.getWidth(), pictureBoxCollections.getHeight()*/400,300);
|
||||
stackRemoveObjects = new Stack<>();
|
||||
listBoxStorage.addListSelectionListener(this::listBoxObjectsSelectedIndexChanged);
|
||||
|
||||
ButtonAddObject.addActionListener(e ->
|
||||
{
|
||||
@ -68,8 +73,8 @@ public class FormLocomotiveCollections {
|
||||
}
|
||||
FrameElectricLocomotive frameElectricLocomotive = new FrameElectricLocomotive();
|
||||
frameElectricLocomotive.setVisible(true);
|
||||
frameElectricLocomotive._formLocomotiveCollection.ButtonSelectLocomotive.addActionListener(e2 -> {
|
||||
loco = frameElectricLocomotive._formLocomotiveCollection._drawingLocomotive;
|
||||
frameElectricLocomotive._formElectricLocomotive.ButtonSelectLocomotive.addActionListener(e2 -> {
|
||||
loco = frameElectricLocomotive._formElectricLocomotive._drawingLocomotive;
|
||||
frameElectricLocomotive.dispose();
|
||||
if (loco != null) {
|
||||
//проверяем, удалось ли нам загрузить объект
|
||||
@ -90,6 +95,40 @@ public class FormLocomotiveCollections {
|
||||
});
|
||||
|
||||
ButtonRemoveLocomotive.addActionListener(e -> {
|
||||
/*if (listBoxStorage.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
var obj = _storage.get(listBoxStorage.getSelectedValue().toString());
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
int pos = 0;
|
||||
try {
|
||||
pos = Integer.parseInt(textFieldNumber.getText());
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Неверное значение",
|
||||
"Ошибка",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
DrawingLocomotive deletedLoco = obj.SubOverload(pos);
|
||||
if (deletedLoco != null) {
|
||||
// logic for push deleted loco in stack
|
||||
stackRemoveObjects.push(deletedLoco);
|
||||
Refresh();
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Объект удален",
|
||||
"Успех",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Не удалось удалить объект",
|
||||
"Ошибка",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}*/
|
||||
|
||||
if (listBoxStorage.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
@ -100,32 +139,62 @@ public class FormLocomotiveCollections {
|
||||
int pos;
|
||||
try {
|
||||
pos = Integer.parseInt(textFieldNumber.getText());
|
||||
DrawingLocomotive deletedLoco = obj.SubOverload(pos);
|
||||
if (_locomotives.SubOverload(pos) != null) {
|
||||
// logic for push deleted loco in stack
|
||||
Refresh();
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Объект удален",
|
||||
"Успех",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Не удалось удалить объект",
|
||||
"Ошибка",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
} catch (NumberFormatException ex) {
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Неверное значение",
|
||||
"Ошибка",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
Object[] options = {"Да", "Нет"};
|
||||
int n = JOptionPane.showOptionDialog(this.getPictureBoxCollections(),
|
||||
"Удалить объект?",
|
||||
"Все серьезно",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
options[0]
|
||||
);
|
||||
if (n == 1) {
|
||||
return;
|
||||
}
|
||||
DrawingLocomotive removedPlane = obj.SubOverload(pos);
|
||||
if (removedPlane != null) {
|
||||
stackRemoveObjects.push(removedPlane);
|
||||
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Объект удален",
|
||||
"Успех",
|
||||
JOptionPane.INFORMATION_MESSAGE);Refresh();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Не удалось удалить объект",
|
||||
"Ошибка",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
ButtonRefreshCollection.addActionListener(e -> {
|
||||
Refresh();
|
||||
});
|
||||
|
||||
Button_OpenFormRemovedLocomotives.addActionListener(e -> {
|
||||
if(stackRemoveObjects.empty()) {
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Вы ничего не удалили, кажется...",
|
||||
"ой",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
_frameRemovedLocomotives = new FrameElectricLocomotive();
|
||||
_frameRemovedLocomotives._formElectricLocomotive._drawingLocomotive = stackRemoveObjects.pop();
|
||||
_frameRemovedLocomotives.setVisible(true);
|
||||
_frameRemovedLocomotives._formElectricLocomotive.Draw();
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void ReloadObjects() {
|
||||
@ -139,6 +208,10 @@ public class FormLocomotiveCollections {
|
||||
listBoxStorage.invalidate();
|
||||
}
|
||||
|
||||
private void listBoxObjectsSelectedIndexChanged(ListSelectionEvent e) {
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void Refresh() {
|
||||
if (listBoxStorage.getSelectedIndex() == -1) {
|
||||
return;
|
||||
@ -149,6 +222,6 @@ public class FormLocomotiveCollections {
|
||||
}
|
||||
Graphics g = pictureBoxCollections.getGraphics();
|
||||
pictureBoxCollections.paint(g);
|
||||
_locomotives.ShowLocomotives(g);
|
||||
obj.ShowLocomotives(g);
|
||||
}
|
||||
}
|
||||
|
@ -3,13 +3,13 @@ package ProjectElectricLocomotive;
|
||||
import javax.swing.*;
|
||||
|
||||
public class FrameElectricLocomotive extends JFrame {
|
||||
public FormElectricLocomotive _formLocomotiveCollection;
|
||||
public FormElectricLocomotive _formElectricLocomotive;
|
||||
public FrameElectricLocomotive() {
|
||||
super();
|
||||
setTitle("Электролокомотив");
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
_formLocomotiveCollection = new FormElectricLocomotive();
|
||||
setContentPane(_formLocomotiveCollection.getPictureBox());
|
||||
_formElectricLocomotive = new FormElectricLocomotive();
|
||||
setContentPane(_formElectricLocomotive.getPictureBox());
|
||||
setDefaultLookAndFeelDecorated(false);
|
||||
setLocation(500, 200);
|
||||
pack();
|
||||
|
@ -52,7 +52,6 @@ public class LocomotivesGenericStorage {
|
||||
/// <returns></returns>
|
||||
public LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> get(String ind)
|
||||
{
|
||||
// TODO Продумать логику получения набора
|
||||
if (_locomotiveStorage.keySet().contains(ind))
|
||||
{
|
||||
return _locomotiveStorage.get(ind);
|
||||
|
Loading…
x
Reference in New Issue
Block a user