113 lines
4.2 KiB
Java
113 lines
4.2 KiB
Java
package ProjectStormtrooper;
|
||
|
||
import javax.swing.*;
|
||
import java.awt.*;
|
||
import java.awt.event.ActionEvent;
|
||
|
||
public class FormPlaneCollection {
|
||
PlanesGenericCollection<DrawingPlane, DrawingObjectPlane> _planes;
|
||
FrameDoubleParametrized _frameDoubleParametrized;
|
||
private JPanel PanelWrapper;
|
||
private JPanel GroupBoxInstruments;
|
||
private JPanel PictureBoxCollection;
|
||
private JButton buttonAddPlane;
|
||
private JTextField textFieldNumber;
|
||
private JButton buttonRemovePlane;
|
||
private JButton buttonRefreshCollection;
|
||
private JButton buttonOpenGenerateWindow;
|
||
public DrawingPlane SelectedPlane;
|
||
|
||
|
||
public JPanel getPanelWrapper() {
|
||
return PanelWrapper;
|
||
}
|
||
|
||
public FormPlaneCollection() {
|
||
PictureBoxCollection.setPreferredSize(new Dimension(600, 500));
|
||
_planes = new PlanesGenericCollection<>(600, 500);
|
||
buttonAddPlane.addActionListener(this::buttonAddPlaneClicked);
|
||
buttonRemovePlane.addActionListener(this::buttonRemovePlaneClicked);
|
||
buttonRefreshCollection.addActionListener(this::buttonRefreshCollectionClicked);
|
||
buttonOpenGenerateWindow.addActionListener(this::buttonOpenGenerateWindowClicked);
|
||
}
|
||
|
||
public void buttonAddPlaneClicked(ActionEvent e) {
|
||
FrameStormtrooper frameStormtrooper = new FrameStormtrooper();
|
||
frameStormtrooper.setVisible(true);
|
||
frameStormtrooper._formPlaneCollection.buttonSelectPlane.addActionListener(ev -> {
|
||
SelectedPlane = frameStormtrooper._formPlaneCollection._drawingPlane;
|
||
frameStormtrooper.dispose();
|
||
if (SelectedPlane != null) {
|
||
if (_planes.Add(SelectedPlane) > -1) {
|
||
refreshPictureBox();
|
||
JOptionPane.showMessageDialog(this.getPanelWrapper(),
|
||
"Объект добавлен",
|
||
"Успех",
|
||
JOptionPane.INFORMATION_MESSAGE);
|
||
} else {
|
||
JOptionPane.showMessageDialog(this.getPanelWrapper(),
|
||
"Не удалось добавить объект",
|
||
"Ошибка",
|
||
JOptionPane.ERROR_MESSAGE);
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
public void buttonRemovePlaneClicked(ActionEvent e) {
|
||
int pos;
|
||
try {
|
||
pos = Integer.parseInt(textFieldNumber.getText());
|
||
} catch (NumberFormatException ex) {
|
||
JOptionPane.showMessageDialog(this.getPanelWrapper(),
|
||
"Неверное значение",
|
||
"Ошибка",
|
||
JOptionPane.ERROR_MESSAGE);
|
||
return;
|
||
}
|
||
Object[] options = {"Да", "Нет"};
|
||
int n = JOptionPane.showOptionDialog(this.getPanelWrapper(),
|
||
"Удалить объект?",
|
||
"Все серьезно",
|
||
JOptionPane.YES_NO_OPTION,
|
||
JOptionPane.QUESTION_MESSAGE,
|
||
null,
|
||
options,
|
||
options[0]
|
||
);
|
||
if (n == 1) {
|
||
return;
|
||
}
|
||
if (_planes.Sub(pos) != null) {
|
||
refreshPictureBox();
|
||
JOptionPane.showMessageDialog(this.getPanelWrapper(),
|
||
"Объект удален",
|
||
"Успех",
|
||
JOptionPane.INFORMATION_MESSAGE);
|
||
} else {
|
||
JOptionPane.showMessageDialog(this.getPanelWrapper(),
|
||
"Не удалось удалить объект",
|
||
"Ошибка",
|
||
JOptionPane.ERROR_MESSAGE);
|
||
}
|
||
}
|
||
|
||
public void buttonRefreshCollectionClicked(ActionEvent e) {
|
||
refreshPictureBox();
|
||
}
|
||
|
||
public void buttonOpenGenerateWindowClicked(ActionEvent e) {
|
||
if (_frameDoubleParametrized != null) {
|
||
_frameDoubleParametrized.dispose();
|
||
}
|
||
_frameDoubleParametrized = new FrameDoubleParametrized();
|
||
_frameDoubleParametrized.setVisible(true);
|
||
}
|
||
|
||
public void refreshPictureBox() {
|
||
Graphics g = PictureBoxCollection.getGraphics();
|
||
PictureBoxCollection.paint(g);
|
||
_planes.ShowPlanes(g);
|
||
}
|
||
}
|