Фикс для работы удаления и отрисовки объекта
This commit is contained in:
parent
deab7a4c3f
commit
25b615e736
@ -1,9 +1,10 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingPlane {
|
||||
public class DrawingPlane extends JPanel {
|
||||
public EntityPlane EntityPlane;
|
||||
protected IDrawingEngines _drawingEngines;
|
||||
protected int _pictureWidth;
|
||||
|
@ -14,7 +14,7 @@
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="7baef" binding="GroupBoxInstruments" layout-manager="GridLayoutManager" row-count="10" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="7baef" binding="GroupBoxInstruments" layout-manager="GridLayoutManager" row-count="11" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints border-constraint="East"/>
|
||||
<properties/>
|
||||
@ -122,6 +122,14 @@
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="a5c67" class="javax.swing.JButton" binding="buttonShowRemovedPlanes">
|
||||
<constraints>
|
||||
<grid row="10" column="0" 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>
|
||||
</children>
|
||||
|
@ -5,10 +5,12 @@ import javax.swing.event.ListSelectionEvent;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.Objects;
|
||||
import java.util.Stack;
|
||||
|
||||
public class FormPlaneCollection {
|
||||
final PlanesGenericStorage _storage;
|
||||
FrameDoubleParametrized _frameDoubleParametrized;
|
||||
FrameStormtrooper _frameRemovedPlanes;
|
||||
private JPanel PanelWrapper;
|
||||
private JPanel GroupBoxInstruments;
|
||||
private JPanel PictureBoxCollection;
|
||||
@ -22,7 +24,9 @@ public class FormPlaneCollection {
|
||||
private JList listBoxStorages;
|
||||
private JButton buttonRemoveStorage;
|
||||
private JPanel storagesPanel;
|
||||
private JButton buttonShowRemovedPlanes;
|
||||
public DrawingPlane SelectedPlane;
|
||||
Stack<DrawingPlane> _removedPlanes;
|
||||
|
||||
|
||||
public JPanel getPanelWrapper() {
|
||||
@ -32,6 +36,7 @@ public class FormPlaneCollection {
|
||||
public FormPlaneCollection() {
|
||||
PictureBoxCollection.setPreferredSize(new Dimension(600, 500));
|
||||
_storage = new PlanesGenericStorage(600, 500);
|
||||
_removedPlanes = new Stack<>();
|
||||
buttonAddPlane.addActionListener(this::buttonAddPlaneClicked);
|
||||
buttonRemovePlane.addActionListener(this::buttonRemovePlaneClicked);
|
||||
buttonRefreshCollection.addActionListener(this::buttonRefreshCollectionClicked);
|
||||
@ -39,6 +44,7 @@ public class FormPlaneCollection {
|
||||
buttonAddStorage.addActionListener(this::buttonAddStorageClicked);
|
||||
buttonRemoveStorage.addActionListener(this::buttonRemoveStorageClicked);
|
||||
listBoxStorages.addListSelectionListener(this::listBoxObjectsSelectedIndexChanged);
|
||||
buttonShowRemovedPlanes.addActionListener(this::buttonShowRemovedPlanesClicked);
|
||||
}
|
||||
|
||||
private void ReloadObjects() {
|
||||
@ -101,8 +107,8 @@ public class FormPlaneCollection {
|
||||
|
||||
FrameStormtrooper frameStormtrooper = new FrameStormtrooper();
|
||||
frameStormtrooper.setVisible(true);
|
||||
frameStormtrooper._formPlaneCollection.buttonSelectPlane.addActionListener(ev -> {
|
||||
SelectedPlane = frameStormtrooper._formPlaneCollection._drawingPlane;
|
||||
frameStormtrooper._formStromtrooper.buttonSelectPlane.addActionListener(ev -> {
|
||||
SelectedPlane = frameStormtrooper._formStromtrooper._drawingPlane;
|
||||
frameStormtrooper.dispose();
|
||||
if (SelectedPlane != null) {
|
||||
if (obj.Add(SelectedPlane) > -1) {
|
||||
@ -152,7 +158,9 @@ public class FormPlaneCollection {
|
||||
if (n == 1) {
|
||||
return;
|
||||
}
|
||||
if (obj.Sub(pos) != null) {
|
||||
DrawingPlane removedPlane = obj.Sub(pos);
|
||||
if (removedPlane != null) {
|
||||
_removedPlanes.push(removedPlane);
|
||||
refreshPictureBox();
|
||||
JOptionPane.showMessageDialog(this.getPanelWrapper(),
|
||||
"Объект удален",
|
||||
@ -178,6 +186,20 @@ public class FormPlaneCollection {
|
||||
_frameDoubleParametrized.setVisible(true);
|
||||
}
|
||||
|
||||
public void buttonShowRemovedPlanesClicked(ActionEvent e) {
|
||||
if (_removedPlanes.empty()) {
|
||||
JOptionPane.showMessageDialog(this.getPanelWrapper(),
|
||||
"Нет удаленных объектов",
|
||||
"Инфо",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
_frameRemovedPlanes = new FrameStormtrooper();
|
||||
_frameRemovedPlanes._formStromtrooper._drawingPlane = _removedPlanes.pop();
|
||||
_frameRemovedPlanes.setVisible(true);
|
||||
_frameRemovedPlanes._formStromtrooper.Draw();
|
||||
}
|
||||
|
||||
public void refreshPictureBox() {
|
||||
if (listBoxStorages.getSelectedIndex() == -1) {
|
||||
return;
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ProjectStormtrooper.FormStormtrooper">
|
||||
<grid id="27dc6" binding="pictureBox" layout-manager="GridLayoutManager" row-count="5" column-count="7" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="pictureBox" custom-create="true" layout-manager="GridLayoutManager" row-count="5" column-count="7" 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="900" height="500"/>
|
||||
|
@ -3,6 +3,7 @@ package ProjectStormtrooper;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import javax.swing.JColorChooser;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.Random;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
@ -10,27 +11,43 @@ public class FormStormtrooper extends JDialog {
|
||||
public DrawingPlane _drawingPlane;
|
||||
AbstractStrategy _abstractStrategy;
|
||||
private JButton buttonCreateStormtrooper;
|
||||
private JPanel pictureBox;
|
||||
private JComponent pictureBox;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonUp;
|
||||
private JButton buttonLeft;
|
||||
private JButton buttonRight;
|
||||
public JButton buttonRight;
|
||||
private JButton buttonCreatePlane;
|
||||
private JComboBox comboBoxStrategy;
|
||||
private JButton buttonStep;
|
||||
public JButton buttonSelectPlane;
|
||||
|
||||
public JPanel getPictureBox() {
|
||||
public JComponent getPictureBox() {
|
||||
return pictureBox;
|
||||
}
|
||||
|
||||
private class Canvas extends JPanel{
|
||||
public Canvas(){
|
||||
}
|
||||
public void paintComponent (Graphics g){
|
||||
if (_drawingPlane == null){
|
||||
return;
|
||||
}
|
||||
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
g2d.setColor(getBackground());
|
||||
g2d.fillRect(0, 0, getWidth(), getHeight());
|
||||
super.paintComponents(g);
|
||||
_drawingPlane.DrawTransport(g2d);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
public FormStormtrooper() {
|
||||
buttonUp.setName("buttonUp");
|
||||
buttonDown.setName("buttonDown");
|
||||
buttonLeft.setName("buttonLeft");
|
||||
buttonRight.setName("buttonRight");
|
||||
|
||||
|
||||
buttonCreateStormtrooper.addActionListener(e -> {
|
||||
Random random = new Random();
|
||||
|
||||
@ -100,8 +117,13 @@ public class FormStormtrooper extends JDialog {
|
||||
}
|
||||
});
|
||||
|
||||
buttonUp.addActionListener(this::buttonMoveClickedListener);
|
||||
buttonDown.addActionListener(this::buttonMoveClickedListener);
|
||||
buttonLeft.addActionListener(this::buttonMoveClickedListener);
|
||||
buttonRight.addActionListener(this::buttonMoveClickedListener);
|
||||
}
|
||||
|
||||
ActionListener buttonMoveClickedListener = e -> {
|
||||
public void buttonMoveClickedListener(ActionEvent e) {
|
||||
String buttonName = ((JButton) e.getSource()).getName();
|
||||
|
||||
switch (buttonName) {
|
||||
@ -117,25 +139,14 @@ public class FormStormtrooper extends JDialog {
|
||||
case ("buttonRight") -> {
|
||||
_drawingPlane.MoveTransport(EnumDirectionType.Right);
|
||||
}
|
||||
default -> _drawingPlane.MoveTransport(EnumDirectionType.Right);
|
||||
}
|
||||
|
||||
Draw();
|
||||
};
|
||||
|
||||
buttonUp.addActionListener(buttonMoveClickedListener);
|
||||
buttonDown.addActionListener(buttonMoveClickedListener);
|
||||
buttonLeft.addActionListener(buttonMoveClickedListener);
|
||||
buttonRight.addActionListener(buttonMoveClickedListener);
|
||||
}
|
||||
|
||||
public void Draw() {
|
||||
if (_drawingPlane == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Graphics g = pictureBox.getGraphics();
|
||||
pictureBox.paint(g);
|
||||
_drawingPlane.DrawTransport(g);
|
||||
pictureBox.repaint();
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
@ -144,5 +155,7 @@ public class FormStormtrooper extends JDialog {
|
||||
"MoveToRightBottom"
|
||||
};
|
||||
comboBoxStrategy = new JComboBox(strategiesList);
|
||||
pictureBox = new Canvas();
|
||||
pictureBox.setBounds(new Rectangle(400, 300));
|
||||
}
|
||||
}
|
||||
|
@ -3,13 +3,13 @@ package ProjectStormtrooper;
|
||||
import javax.swing.*;
|
||||
|
||||
public class FrameStormtrooper extends JFrame {
|
||||
public FormStormtrooper _formPlaneCollection;
|
||||
public FormStormtrooper _formStromtrooper;
|
||||
public FrameStormtrooper() {
|
||||
super();
|
||||
setTitle("Штурмовик");
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
_formPlaneCollection = new FormStormtrooper();
|
||||
setContentPane(_formPlaneCollection.getPictureBox());
|
||||
_formStromtrooper = new FormStormtrooper();
|
||||
setContentPane(_formStromtrooper.getPictureBox());
|
||||
setDefaultLookAndFeelDecorated(false);
|
||||
setLocation(300, 100);
|
||||
pack();
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Stack;
|
||||
|
||||
public class PlanesGenericCollection<T extends DrawingPlane, U extends IMoveableObject> {
|
||||
private int _pictureWidth;
|
||||
|
@ -33,4 +33,10 @@ public class PlanesGenericStorage {
|
||||
return _planeStorages.get(ind);
|
||||
return null;
|
||||
}
|
||||
public DrawingObjectPlane GetByDoubleParameter(String storageName, int planeIndex) {
|
||||
if (_planeStorages.containsKey(storageName)) {
|
||||
return _planeStorages.get(storageName).GetU(planeIndex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user