Abazov A. A. LabWork#04 #4

Closed
Andrey_Abazov wants to merge 1 commits from Lab04 into Lab03
7 changed files with 391 additions and 125 deletions

View File

@ -40,6 +40,10 @@ public class DrawingObjectAirBomber implements IDrawingObject {
_airBomber.SetPosition(x, y, width, height);
}
public DrawingAirBomber getAirBomber(){
return _airBomber;
}
@Override
public void DrawingObject(Graphics2D g)
{

View File

@ -5,7 +5,6 @@
package AirBomberPackage;
import java.awt.*;
import javax.swing.*;
import javax.swing.JOptionPane;
import java.util.Random;
/**
@ -22,6 +21,14 @@ public class JFrameAirBomber extends javax.swing.JDialog {
initComponents();
}
public JFrameAirBomber(JFrame parent, DrawingObjectAirBomber airBomber) {
super(parent, "Бомбардировщик", true);
initComponents();
_airBomber = airBomber.getAirBomber();
SetData();
Draw();
}
private DrawingAirBomber _airBomber;
private EnginesType enginesType = EnginesType.RECTANGLE;
private DrawingAirBomber _airBomberResult;
@ -327,7 +334,7 @@ public class JFrameAirBomber extends javax.swing.JDialog {
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new JFrameDopGenerics().setVisible(true);
new JFrameMapWithSetAirBombers().setVisible(true);
}
});
}

View File

@ -25,19 +25,29 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="airBomberCanvas" min="-2" pref="664" max="-2" attributes="0"/>
<EmptySpace pref="25" max="32767" attributes="0"/>
<EmptySpace pref="59" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="comboBoxSelectorMap" max="32767" attributes="0"/>
<Component id="buttonAddAirBomber" max="32767" attributes="0"/>
<Component id="maskedTextBoxPosition" max="32767" attributes="0"/>
<Component id="buttonRemoveAirBomber" max="32767" attributes="0"/>
<Component id="buttonShowStorage" max="32767" attributes="0"/>
<Component id="buttonShowOnMap" alignment="1" max="32767" attributes="0"/>
<Group type="103" alignment="0" groupAlignment="1" attributes="0">
<Component id="buttonDeleteMap" min="-2" pref="188" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="buttonAddAirBomber" max="32767" attributes="0"/>
<Component id="maskedTextBoxPosition" max="32767" attributes="0"/>
<Component id="buttonRemoveAirBomber" max="32767" attributes="0"/>
<Component id="buttonShowStorage" max="32767" attributes="0"/>
<Component id="buttonShowOnMap" alignment="1" max="32767" attributes="0"/>
</Group>
<Component id="jScrollPane1" alignment="1" min="-2" pref="188" max="-2" attributes="0"/>
<Component id="buttonAddMap" alignment="1" min="-2" pref="188" max="-2" attributes="0"/>
<Component id="comboBoxSelectorMap" alignment="1" min="-2" pref="188" max="-2" attributes="0"/>
<Component id="textBoxNewMapName" alignment="1" min="-2" pref="188" max="-2" attributes="0"/>
<Component id="buttonShowDeleted" alignment="1" min="-2" pref="188" max="-2" attributes="0"/>
</Group>
<Group type="103" alignment="0" groupAlignment="1" attributes="0">
<Component id="jLabel2" min="-2" pref="75" max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="23" max="-2" attributes="0"/>
</Group>
@ -65,18 +75,30 @@
<EmptySpace min="-2" pref="15" max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="textBoxNewMapName" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="comboBoxSelectorMap" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="60" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="buttonAddMap" min="-2" pref="35" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="78" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="buttonDeleteMap" min="-2" pref="34" max="-2" attributes="0"/>
<EmptySpace pref="45" max="32767" attributes="0"/>
<Component id="buttonShowDeleted" min="-2" pref="36" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="buttonAddAirBomber" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="38" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="maskedTextBoxPosition" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="buttonRemoveAirBomber" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="96" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="buttonShowStorage" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="12" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="buttonShowOnMap" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="108" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="upButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
@ -99,17 +121,9 @@
<Component class="javax.swing.JComboBox" name="comboBoxSelectorMap">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="3">
<StringItem index="0" value="&#x41f;&#x440;&#x43e;&#x441;&#x442;&#x430;&#x44f; &#x43a;&#x430;&#x440;&#x442;&#x430;"/>
<StringItem index="1" value="&#x413;&#x43e;&#x440;&#x43e;&#x434;&#x441;&#x43a;&#x430;&#x44f; &#x43a;&#x430;&#x440;&#x442;&#x430;"/>
<StringItem index="2" value="&#x41b;&#x438;&#x43d;&#x435;&#x439;&#x43d;&#x430;&#x44f; &#x43a;&#x430;&#x440;&#x442;&#x430;"/>
</StringArray>
<StringArray count="0"/>
</Property>
<Property name="selectedIndex" type="int" value="-1"/>
</Properties>
<Events>
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="comboBoxSelectorMapItemStateChanged"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
@ -243,5 +257,59 @@
<Property name="text" type="java.lang.String" value="&#x418;&#x43d;&#x441;&#x442;&#x440;&#x443;&#x43c;&#x435;&#x43d;&#x442;&#x44b;"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="text" type="java.lang.String" value="&#x41a;&#x430;&#x440;&#x442;&#x44b;"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="textBoxNewMapName">
</Component>
<Component class="javax.swing.JButton" name="buttonAddMap">
<Properties>
<Property name="text" type="java.lang.String" value="&#x414;&#x43e;&#x431;&#x430;&#x432;&#x438;&#x442;&#x44c; &#x43a;&#x430;&#x440;&#x442;&#x443;"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonAddMapActionPerformed"/>
</Events>
</Component>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JList" name="listBoxMaps">
<Properties>
<Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor">
<StringArray count="0"/>
</Property>
<Property name="selectionMode" type="int" value="0"/>
</Properties>
<Events>
<EventHandler event="valueChanged" listener="javax.swing.event.ListSelectionListener" parameters="javax.swing.event.ListSelectionEvent" handler="listBoxMapsValueChanged"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JButton" name="buttonDeleteMap">
<Properties>
<Property name="text" type="java.lang.String" value="&#x423;&#x434;&#x430;&#x43b;&#x438;&#x442;&#x44c; &#x43a;&#x430;&#x440;&#x442;&#x443;"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonDeleteMapActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="buttonShowDeleted">
<Properties>
<Property name="text" type="java.lang.String" value="&#x41f;&#x43e;&#x43a;&#x430;&#x437;&#x430;&#x442;&#x44c; &#x443;&#x434;&#x430;&#x43b;&#x451;&#x43d;&#x43d;&#x44b;&#x439;"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonShowDeletedActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>

View File

@ -4,7 +4,11 @@
*/
package AirBomberPackage;
import java.awt.*;
import javax.swing.DefaultListModel;
import java.util.HashMap;
import java.util.LinkedList;
import javax.swing.*;
/**
*
* @author Андрей
@ -16,8 +20,22 @@ public class JFrameMapWithSetAirBombers extends javax.swing.JFrame {
*/
public JFrameMapWithSetAirBombers() {
initComponents();
_mapsDict.put("Простая карта", new SimpleMap());
_mapsDict.put("Городская карта", new CityMap());
_mapsDict.put("Линейная карта", new LineMap());
_mapsCollection = new MapsCollection(airBomberCanvas.getWidth(),airBomberCanvas.getHeight());
DefaultComboBoxModel defaultcombModel = new DefaultComboBoxModel();
comboBoxSelectorMap.setModel(defaultcombModel);
for (var elem : _mapsDict.keySet()){
comboBoxSelectorMap.addItem(elem);
}
comboBoxSelectorMap.setSelectedIndex(-1);
}
private MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap> _mapAirBombersCollectionGeneric;
private HashMap<String, AbstractMap> _mapsDict = new HashMap<>();
private MapsCollection _mapsCollection;
private LinkedList<DrawingObjectAirBomber> deletedAirBombers = new LinkedList<>();
/**
* This method is called from within the constructor to initialize the form.
@ -40,17 +58,16 @@ public class JFrameMapWithSetAirBombers extends javax.swing.JFrame {
rightButton = new javax.swing.JButton();
upButton = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
textBoxNewMapName = new javax.swing.JTextField();
buttonAddMap = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
listBoxMaps = new javax.swing.JList<>();
buttonDeleteMap = new javax.swing.JButton();
buttonShowDeleted = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
comboBoxSelectorMap.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Простая карта", "Городская карта", "Линейная карта" }));
comboBoxSelectorMap.setSelectedIndex(-1);
comboBoxSelectorMap.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
comboBoxSelectorMapItemStateChanged(evt);
}
});
buttonAddAirBomber.setText("Добавить бомбардировщик");
buttonAddAirBomber.setToolTipText("");
buttonAddAirBomber.addActionListener(new java.awt.event.ActionListener() {
@ -134,24 +151,63 @@ public class JFrameMapWithSetAirBombers extends javax.swing.JFrame {
jLabel1.setText("Инструменты");
jLabel2.setText("Карты");
buttonAddMap.setText("Добавить карту");
buttonAddMap.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonAddMapActionPerformed(evt);
}
});
listBoxMaps.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
listBoxMaps.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
listBoxMapsValueChanged(evt);
}
});
jScrollPane1.setViewportView(listBoxMaps);
buttonDeleteMap.setText("Удалить карту");
buttonDeleteMap.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonDeleteMapActionPerformed(evt);
}
});
buttonShowDeleted.setText("Показать удалённый");
buttonShowDeleted.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonShowDeletedActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(airBomberCanvas, javax.swing.GroupLayout.PREFERRED_SIZE, 664, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 59, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(comboBoxSelectorMap, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(buttonAddAirBomber, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(maskedTextBoxPosition)
.addComponent(buttonRemoveAirBomber, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(buttonShowStorage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(buttonShowOnMap, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jLabel1))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(buttonDeleteMap, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(buttonAddAirBomber, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(maskedTextBoxPosition)
.addComponent(buttonRemoveAirBomber, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(buttonShowStorage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(buttonShowOnMap, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(buttonAddMap, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(comboBoxSelectorMap, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(textBoxNewMapName, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(buttonShowDeleted, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1)))
.addGap(23, 23, 23))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(leftButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
@ -171,18 +227,30 @@ public class JFrameMapWithSetAirBombers extends javax.swing.JFrame {
.addGap(15, 15, 15)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(textBoxNewMapName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(comboBoxSelectorMap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(60, 60, 60)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonAddMap, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonDeleteMap, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE)
.addComponent(buttonShowDeleted, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonAddAirBomber)
.addGap(38, 38, 38)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(maskedTextBoxPosition, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonRemoveAirBomber)
.addGap(96, 96, 96)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonShowStorage)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonShowOnMap)
.addGap(108, 108, 108)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
@ -213,50 +281,22 @@ public class JFrameMapWithSetAirBombers extends javax.swing.JFrame {
dir = Direction.RIGHT;
break;
}
airBomberCanvas.getGraphics().drawImage(_mapAirBombersCollectionGeneric.MoveObject(dir), 0, 0, null);
airBomberCanvas.getGraphics().drawImage(_mapsCollection.Get(listBoxMaps.getSelectedValue()).MoveObject(dir), 0, 0, null);
}//GEN-LAST:event_moveButtonActionPerformed
private void comboBoxSelectorMapItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboBoxSelectorMapItemStateChanged
AbstractMap map = null;
switch (comboBoxSelectorMap.getSelectedIndex())
{
case 0:
map = new SimpleMap();
break;
case 1:
map = new CityMap();
break;
case 2:
map = new LineMap();
break;
}
if (map != null)
{
_mapAirBombersCollectionGeneric = new MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap>(
airBomberCanvas.getWidth(), airBomberCanvas.getHeight(), map);
airBomberCanvas.getGraphics().drawImage(_mapAirBombersCollectionGeneric.ShowSet(), 0, 0, null);
}
else
{
_mapAirBombersCollectionGeneric = null;
}
}//GEN-LAST:event_comboBoxSelectorMapItemStateChanged
private void buttonAddAirBomberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddAirBomberActionPerformed
if (_mapAirBombersCollectionGeneric == null)
{
if (listBoxMaps.getSelectedIndex() == -1){
return;
}
JFrameAirBomber form = new JFrameAirBomber(this);
DrawingAirBomber selectedAirBomber = form.run();
if (selectedAirBomber != null)
{
DrawingObjectAirBomber objectAirBomber = new DrawingObjectAirBomber(selectedAirBomber);
if (_mapAirBombersCollectionGeneric.add(objectAirBomber) != -1)
if (_mapsCollection.Get(listBoxMaps.getSelectedValue()).add(objectAirBomber) != -1)
{
JOptionPane.showMessageDialog(this, "Объект добавлен");
airBomberCanvas.getGraphics().drawImage(_mapAirBombersCollectionGeneric.ShowSet(), 0, 0, null);
airBomberCanvas.getGraphics().drawImage(_mapsCollection.Get(listBoxMaps.getSelectedValue()).ShowSet(), 0, 0, null);
}
else
{
@ -266,6 +306,9 @@ public class JFrameMapWithSetAirBombers extends javax.swing.JFrame {
}//GEN-LAST:event_buttonAddAirBomberActionPerformed
private void buttonRemoveAirBomberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRemoveAirBomberActionPerformed
if (listBoxMaps.getSelectedIndex() == -1){
return;
}
if (maskedTextBoxPosition.getText().isBlank() || maskedTextBoxPosition.getText().isEmpty())
{
return;
@ -276,10 +319,12 @@ public class JFrameMapWithSetAirBombers extends javax.swing.JFrame {
return;
}
int pos = Integer.parseInt(maskedTextBoxPosition.getText());
if (_mapAirBombersCollectionGeneric.remove(pos) != null)
DrawingObjectAirBomber deletedAirBomber = _mapsCollection.Get(listBoxMaps.getSelectedValue()).remove(pos);
if (deletedAirBomber != null)
{
deletedAirBombers.add(deletedAirBomber);
JOptionPane.showMessageDialog(null,"Объект удален");
airBomberCanvas.getGraphics().drawImage(_mapAirBombersCollectionGeneric.ShowSet(), 0, 0, null);
airBomberCanvas.getGraphics().drawImage(_mapsCollection.Get(listBoxMaps.getSelectedValue()).ShowSet(), 0, 0, null);
}
else
{
@ -288,21 +333,78 @@ public class JFrameMapWithSetAirBombers extends javax.swing.JFrame {
}//GEN-LAST:event_buttonRemoveAirBomberActionPerformed
private void buttonShowStorageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonShowStorageActionPerformed
if (_mapAirBombersCollectionGeneric == null)
{
if (listBoxMaps.getSelectedIndex() == -1){
return;
}
airBomberCanvas.getGraphics().drawImage(_mapAirBombersCollectionGeneric.ShowSet(), 0, 0, null);
airBomberCanvas.getGraphics().drawImage(_mapsCollection.Get(listBoxMaps.getSelectedValue()).ShowSet(), 0, 0, null);
}//GEN-LAST:event_buttonShowStorageActionPerformed
private void buttonShowOnMapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonShowOnMapActionPerformed
if (_mapAirBombersCollectionGeneric == null)
{
if (listBoxMaps.getSelectedIndex() == -1){
return;
}
airBomberCanvas.getGraphics().drawImage(_mapAirBombersCollectionGeneric.ShowOnMap(), 0, 0, null);
airBomberCanvas.getGraphics().drawImage(_mapsCollection.Get(listBoxMaps.getSelectedValue()).ShowOnMap(), 0, 0, null);
}//GEN-LAST:event_buttonShowOnMapActionPerformed
private void buttonAddMapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddMapActionPerformed
if (comboBoxSelectorMap.getSelectedIndex() == -1 || textBoxNewMapName.getText().isBlank()){
JOptionPane.showMessageDialog(this, "Не все данные заполнены!");
return;
}
if (!_mapsDict.containsKey((String) comboBoxSelectorMap.getSelectedItem())){
JOptionPane.showMessageDialog(this, "Нет такой карты!");
return;
}
_mapsCollection.AddMap(textBoxNewMapName.getText(), _mapsDict.get((String) comboBoxSelectorMap.getSelectedItem()));
ReloadMaps();
}//GEN-LAST:event_buttonAddMapActionPerformed
private void buttonDeleteMapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDeleteMapActionPerformed
if (listBoxMaps.getSelectedIndex() == -1){
return;
}
if (JOptionPane.showConfirmDialog(this, (Object) ("Удалить карту " + listBoxMaps.getSelectedValue() + "?") , "Удаление", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION){
_mapsCollection.DelMap(listBoxMaps.getSelectedValue());
ReloadMaps();
}
}//GEN-LAST:event_buttonDeleteMapActionPerformed
private void buttonShowDeletedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonShowDeletedActionPerformed
if (deletedAirBombers.isEmpty()){
return;
}
JFrameAirBomber form = new JFrameAirBomber(this, deletedAirBombers.poll());
form.run();
}//GEN-LAST:event_buttonShowDeletedActionPerformed
private void listBoxMapsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listBoxMapsValueChanged
if (listBoxMaps.getSelectedIndex() == -1){
return;
}
airBomberCanvas.getGraphics().drawImage(_mapsCollection.Get(listBoxMaps.getSelectedValue()).ShowSet(), 0, 0, null);
}//GEN-LAST:event_listBoxMapsValueChanged
private void ReloadMaps()
{
int index = listBoxMaps.getSelectedIndex();
DefaultListModel listBoxMapsModel = new DefaultListModel();
listBoxMapsModel.clear();
for (int i = 0; i < _mapsCollection.getKeys().size(); i++)
{
listBoxMapsModel.addElement(_mapsCollection.getKeys().get(i));
}
listBoxMaps.setModel(listBoxMapsModel);
if (listBoxMapsModel.size() > 0 && (index == -1 || index >= listBoxMapsModel.size()))
{
listBoxMaps.setSelectedIndex(0);
}
else if (listBoxMapsModel.size() > 0 && index > -1 && index < listBoxMapsModel.size())
{
listBoxMaps.setSelectedIndex(index);
}
}
/**
* @param args the command line arguments
*/
@ -341,15 +443,22 @@ public class JFrameMapWithSetAirBombers extends javax.swing.JFrame {
// Variables declaration - do not modify//GEN-BEGIN:variables
private AirBomberPackage.CanvasMy airBomberCanvas;
private javax.swing.JButton buttonAddAirBomber;
private javax.swing.JButton buttonAddMap;
private javax.swing.JButton buttonDeleteMap;
private javax.swing.JButton buttonRemoveAirBomber;
private javax.swing.JButton buttonShowDeleted;
private javax.swing.JButton buttonShowOnMap;
private javax.swing.JButton buttonShowStorage;
private javax.swing.JComboBox<String> comboBoxSelectorMap;
private javax.swing.JButton downButton;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JButton leftButton;
private javax.swing.JList<String> listBoxMaps;
private javax.swing.JFormattedTextField maskedTextBoxPosition;
private javax.swing.JButton rightButton;
private javax.swing.JTextField textBoxNewMapName;
private javax.swing.JButton upButton;
// End of variables declaration//GEN-END:variables
}

View File

@ -26,6 +26,10 @@ public class MapWithSetAirBombersGeneric <T extends IDrawingObject, U extends Ab
_map = map;
}
public SetAirBombersGeneric<T> getSetAirBombers(){
return _setAirBombers;
}
public int add(T airBomber){
return _setAirBombers.Insert(airBomber);
}
@ -46,7 +50,7 @@ public class MapWithSetAirBombersGeneric <T extends IDrawingObject, U extends Ab
public BufferedImage ShowOnMap()
{
Shaking();
for (int i = 0; i < _setAirBombers.Count; i++)
for (int i = 0; i < _setAirBombers.getCount(); i++)
{
var airBomber = _setAirBombers.Get(i);
if (airBomber != null)
@ -68,8 +72,8 @@ public class MapWithSetAirBombersGeneric <T extends IDrawingObject, U extends Ab
private void Shaking()
{
int j = _setAirBombers.Count - 1;
for (int i = 0; i < _setAirBombers.Count; i++)
int j = _setAirBombers.getCount() - 1;
for (int i = 0; i < _setAirBombers.getCount(); i++)
{
if (_setAirBombers.Get(i) == null)
{
@ -112,7 +116,7 @@ public class MapWithSetAirBombersGeneric <T extends IDrawingObject, U extends Ab
private void DrawAirBombers(Graphics2D g)
{
int numOfObjectsInRow = _pictureWidth / _placeSizeWidth;
for (int i = 0; i < _setAirBombers.Count; i++)
for (int i = 0; i < _setAirBombers.getCount(); i++)
{
if (_setAirBombers.Get(i) != null){
_setAirBombers.Get(i).SetObject((numOfObjectsInRow - (i % numOfObjectsInRow) - 1) * _placeSizeWidth, (i / numOfObjectsInRow) * _placeSizeHeight, _pictureWidth, _pictureHeight);

View File

@ -0,0 +1,79 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package AirBomberPackage;
import java.util.HashMap;
import java.util.ArrayList;
/**
*
* @author Андрей
*/
public class MapsCollection {
/// <summary>
/// Словарь (хранилище) с картами
/// </summary>
HashMap<String, MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap>> _mapStorages;
/// <summary>
/// Возвращение списка названий карт
/// </summary>
public ArrayList<String> getKeys(){
ArrayList<String> keys = new ArrayList<>(_mapStorages.keySet());
return keys;
}
/// <summary>
/// Ширина окна отрисовки
/// </summary>
private int _pictureWidth;
/// <summary>
/// Высота окна отрисовки
/// </summary>
private int _pictureHeight;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="pictureWidth"></param>
/// <param name="pictureHeight"></param>
public MapsCollection(int pictureWidth, int pictureHeight)
{
_mapStorages = new HashMap<String, MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
/// <summary>
/// Добавление карты
/// </summary>
/// <param name="name">Название карты</param>
/// <param name="map">Карта</param>
public boolean AddMap(String name, AbstractMap map)
{
if (_mapStorages.containsKey(name))
{
return false;
}
_mapStorages.put(name, new MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap>(_pictureWidth, _pictureHeight, map));
return true;
}
/// <summary>
/// Удаление карты
/// </summary>
/// <param name="name">Название карты</param>
public void DelMap(String name)
{
if (_mapStorages.containsKey(name))
{
_mapStorages.remove(name);
}
}
public MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap> Get(String ind){
if (_mapStorages.containsKey(ind)) return _mapStorages.get(ind);
else return null;
}
public DrawingObjectAirBomber Get(String ind, int index){
if (!_mapStorages.containsKey(ind)) return null;
MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap> map = _mapStorages.get(ind);
return map.getSetAirBombers().Get(index);
}
}

View File

@ -4,6 +4,8 @@
*/
package AirBomberPackage;
import java.util.ArrayList;
/**
*
* @author Андрей
@ -12,19 +14,23 @@ public class SetAirBombersGeneric<T> {
/// <summary>
/// Массив объектов, которые храним
/// </summary>
private T[] _places;
private ArrayList<T> _places;
/// <summary>
/// Количество объектов в массиве
/// </summary>
public int Count;
private int _maxCount;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="count"></param>
public SetAirBombersGeneric(int count)
{
_places = (T[]) new Object[count];
Count = count;
_places = new ArrayList<T>(count);
_maxCount = count;
}
public int getCount(){
return _places.size();
}
/// <summary>
/// Добавление объекта в набор
@ -43,30 +49,11 @@ public class SetAirBombersGeneric<T> {
/// <returns></returns>
public int Insert(T airBomber, int position)
{
if (position >= _places.length)
if (position < 0 || position >= _maxCount)
{
return -1;
}
if (_places[position] != null)
{
int indexNull = -1;
for (int i = position; i < _places.length; i++)
{
if (_places[i] == null)
{
indexNull = i;
break;
}
}
if (indexNull == -1) return -1;
for (int i = indexNull; i > position; i--)
{
T tmp = _places[i];
_places[i] = _places[i - 1];
_places[i - 1] = tmp;
}
}
_places[position] = airBomber;
_places.add(position, airBomber);
return position;
}
/// <summary>
@ -76,12 +63,12 @@ public class SetAirBombersGeneric<T> {
/// <returns></returns>
public T Remove(int position)
{
if (position >= _places.length)
if (position <0 || position >= _maxCount)
{
return null;
}
T removedObject = _places[position];
_places[position] = null;
}
T removedObject = _places.get(position);
_places.remove(position);
return removedObject;
}
/// <summary>
@ -91,10 +78,18 @@ public class SetAirBombersGeneric<T> {
/// <returns></returns>
public T Get(int position)
{
if (position >= _places.length)
if (position >= _maxCount || position < 0)
{
return null;
}
return _places[position];
return _places.get(position);
}
public void Set(int position, T value){
if (position >= _maxCount || position < 0)
{
return;
}
_places.set(position, value);
}
}