LabWork04 completed
This commit is contained in:
parent
392e97f71f
commit
e60990067a
@ -1,12 +1,16 @@
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawingObjectArtillery implements IDrawingObject {
|
public class DrawingObjectArtillery implements IDrawingObject {
|
||||||
private DrawingArtillery _artillery = null;
|
private DrawingArtillery _artillery;
|
||||||
|
|
||||||
public DrawingObjectArtillery(DrawingArtillery artillery) {
|
public DrawingObjectArtillery(DrawingArtillery artillery) {
|
||||||
_artillery = artillery;
|
_artillery = artillery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DrawingArtillery getArtillery() {
|
||||||
|
return _artillery;
|
||||||
|
}
|
||||||
|
|
||||||
public float getStep() {
|
public float getStep() {
|
||||||
if (_artillery != null && _artillery.artillery != null) {
|
if (_artillery != null && _artillery.artillery != null) {
|
||||||
return _artillery.artillery.getStep();
|
return _artillery.artillery.getStep();
|
||||||
|
@ -90,6 +90,12 @@ public class FormArtillery extends JDialog {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FormArtillery(DrawingArtillery artillery) {
|
||||||
|
this();
|
||||||
|
_artillery = artillery;
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
public DrawingArtillery getSelectedArtillery() {
|
public DrawingArtillery getSelectedArtillery() {
|
||||||
return selectedArtillery;
|
return selectedArtillery;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<grid id="27dc6" binding="paneArtilleries" 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="paneArtilleries" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<xy x="20" y="20" width="649" height="497"/>
|
<xy x="20" y="20" width="649" height="532"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties/>
|
<properties/>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
@ -17,7 +17,7 @@
|
|||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
<children/>
|
<children/>
|
||||||
</grid>
|
</grid>
|
||||||
<grid id="f232" binding="toolsGroup" layout-manager="GridLayoutManager" row-count="9" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="f232" binding="toolsGroup" layout-manager="GridLayoutManager" row-count="10" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
@ -81,7 +81,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="fb3e4" class="javax.swing.JButton" binding="buttonUp">
|
<component id="fb3e4" class="javax.swing.JButton" binding="buttonUp">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="7" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
<grid row="8" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
<minimum-size width="30" height="30"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -96,7 +96,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="328f6" class="javax.swing.JButton" binding="buttonDown">
|
<component id="328f6" class="javax.swing.JButton" binding="buttonDown">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="8" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
<grid row="9" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
<minimum-size width="30" height="30"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -110,7 +110,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="4f2dc" class="javax.swing.JButton" binding="buttonLeft">
|
<component id="4f2dc" class="javax.swing.JButton" binding="buttonLeft">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="8" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
<grid row="9" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
<minimum-size width="30" height="30"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -125,7 +125,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="bac06" class="javax.swing.JButton" binding="buttonRight">
|
<component id="bac06" class="javax.swing.JButton" binding="buttonRight">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="8" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
<grid row="9" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
<minimum-size width="30" height="30"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -204,6 +204,14 @@
|
|||||||
</component>
|
</component>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
|
<component id="490e6" class="javax.swing.JButton" binding="buttonShowDeleted">
|
||||||
|
<constraints>
|
||||||
|
<grid row="7" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Посмотреть удалённую артиллерию"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
</children>
|
</children>
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.event.ListSelectionEvent;
|
|
||||||
import javax.swing.event.ListSelectionListener;
|
|
||||||
import javax.swing.text.DefaultFormatterFactory;
|
import javax.swing.text.DefaultFormatterFactory;
|
||||||
import javax.swing.text.MaskFormatter;
|
import javax.swing.text.MaskFormatter;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
public class FormMapWithSetArtilleries extends JFrame {
|
public class FormMapWithSetArtilleries extends JFrame {
|
||||||
private JPanel pictureBox;
|
private JPanel pictureBox;
|
||||||
@ -29,6 +28,7 @@ public class FormMapWithSetArtilleries extends JFrame {
|
|||||||
private JList<String> listBoxMaps;
|
private JList<String> listBoxMaps;
|
||||||
private JPanel mapsGroup;
|
private JPanel mapsGroup;
|
||||||
private JButton buttonDeleteMap;
|
private JButton buttonDeleteMap;
|
||||||
|
private JButton buttonShowDeleted;
|
||||||
|
|
||||||
private Image bufferedImage;
|
private Image bufferedImage;
|
||||||
private final HashMap<String, AbstractMap> _mapsDict = new HashMap<>() {{
|
private final HashMap<String, AbstractMap> _mapsDict = new HashMap<>() {{
|
||||||
@ -36,6 +36,7 @@ public class FormMapWithSetArtilleries extends JFrame {
|
|||||||
put("Лесная карта", new ForestMap());
|
put("Лесная карта", new ForestMap());
|
||||||
}};
|
}};
|
||||||
private final MapsCollection _mapsCollection;
|
private final MapsCollection _mapsCollection;
|
||||||
|
private final Stack<IDrawingObject> deletedObjects = new Stack<>();
|
||||||
|
|
||||||
public FormMapWithSetArtilleries() {
|
public FormMapWithSetArtilleries() {
|
||||||
this.setTitle("Artillery");
|
this.setTitle("Artillery");
|
||||||
@ -126,7 +127,9 @@ public class FormMapWithSetArtilleries extends JFrame {
|
|||||||
|
|
||||||
int position = Integer.parseInt(text);
|
int position = Integer.parseInt(text);
|
||||||
|
|
||||||
if (_mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).removeArtilleryAt(position) != null) {
|
IDrawingObject deleted = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).removeArtilleryAt(position);
|
||||||
|
if (deleted != null) {
|
||||||
|
deletedObjects.push(deleted);
|
||||||
JOptionPane.showMessageDialog(this, "Объект удалён", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(this, "Объект удалён", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
||||||
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).showSet();
|
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).showSet();
|
||||||
repaint();
|
repaint();
|
||||||
@ -151,6 +154,18 @@ public class FormMapWithSetArtilleries extends JFrame {
|
|||||||
repaint();
|
repaint();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
buttonShowDeleted.addActionListener(e -> {
|
||||||
|
if (!deletedObjects.empty()) {
|
||||||
|
DrawingObjectArtillery deleted = (DrawingObjectArtillery) deletedObjects.pop();
|
||||||
|
FormArtillery dialog = new FormArtillery(deleted == null ? null : deleted.getArtillery());
|
||||||
|
dialog.setSize(800, 500);
|
||||||
|
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
|
||||||
|
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||||
|
|
||||||
|
dialog.setVisible(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
buttonLeft.addActionListener(e -> {
|
buttonLeft.addActionListener(e -> {
|
||||||
if (listBoxMaps.getSelectedIndex() != -1) {
|
if (listBoxMaps.getSelectedIndex() != -1) {
|
||||||
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).moveObject(Direction.Left);
|
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).moveObject(Direction.Left);
|
||||||
|
@ -2,7 +2,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class MapsCollection {
|
public class MapsCollection {
|
||||||
private final HashMap<String, MapWithSetArtilleriesGeneric<DrawingObjectArtillery, AbstractMap>> _mapsStorage;
|
private final HashMap<String, MapWithSetArtilleriesGeneric<IDrawingObject, AbstractMap>> _mapsStorage;
|
||||||
|
|
||||||
private final int _pictureWidth;
|
private final int _pictureWidth;
|
||||||
private final int _pictureHeight;
|
private final int _pictureHeight;
|
||||||
@ -27,7 +27,7 @@ public class MapsCollection {
|
|||||||
_mapsStorage.remove(name);
|
_mapsStorage.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapWithSetArtilleriesGeneric<DrawingObjectArtillery, AbstractMap> getMap(String name) {
|
public MapWithSetArtilleriesGeneric<IDrawingObject, AbstractMap> getMap(String name) {
|
||||||
return _mapsStorage.getOrDefault(name, null);
|
return _mapsStorage.getOrDefault(name, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user