2022-10-31 19:31:33 +04:00
|
|
|
|
/*
|
|
|
|
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
|
|
|
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
|
|
|
|
|
*/
|
|
|
|
|
package AirBomberPackage;
|
|
|
|
|
import java.awt.*;
|
2022-11-13 17:26:04 +04:00
|
|
|
|
import javax.swing.DefaultListModel;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.LinkedList;
|
2022-10-31 19:31:33 +04:00
|
|
|
|
import javax.swing.*;
|
2022-11-13 17:26:04 +04:00
|
|
|
|
|
2022-10-31 19:31:33 +04:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @author Андрей
|
|
|
|
|
*/
|
|
|
|
|
public class JFrameMapWithSetAirBombers extends javax.swing.JFrame {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates new form JFrameMapWithSetAirBombers
|
|
|
|
|
*/
|
|
|
|
|
public JFrameMapWithSetAirBombers() {
|
|
|
|
|
initComponents();
|
2022-11-13 17:26:04 +04:00
|
|
|
|
_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);
|
2022-10-31 19:31:33 +04:00
|
|
|
|
}
|
2022-11-13 17:26:04 +04:00
|
|
|
|
private HashMap<String, AbstractMap> _mapsDict = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
private MapsCollection _mapsCollection;
|
|
|
|
|
|
|
|
|
|
private LinkedList<DrawingObjectAirBomber> deletedAirBombers = new LinkedList<>();
|
2022-10-31 19:31:33 +04:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This method is called from within the constructor to initialize the form.
|
|
|
|
|
* WARNING: Do NOT modify this code. The content of this method is always
|
|
|
|
|
* regenerated by the Form Editor.
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
|
|
|
|
private void initComponents() {
|
|
|
|
|
|
|
|
|
|
airBomberCanvas = new AirBomberPackage.CanvasMy();
|
|
|
|
|
comboBoxSelectorMap = new javax.swing.JComboBox<>();
|
|
|
|
|
buttonAddAirBomber = new javax.swing.JButton();
|
|
|
|
|
maskedTextBoxPosition = new javax.swing.JFormattedTextField();
|
|
|
|
|
buttonRemoveAirBomber = new javax.swing.JButton();
|
|
|
|
|
buttonShowStorage = new javax.swing.JButton();
|
|
|
|
|
buttonShowOnMap = new javax.swing.JButton();
|
|
|
|
|
leftButton = new javax.swing.JButton();
|
|
|
|
|
downButton = new javax.swing.JButton();
|
|
|
|
|
rightButton = new javax.swing.JButton();
|
|
|
|
|
upButton = new javax.swing.JButton();
|
|
|
|
|
jLabel1 = new javax.swing.JLabel();
|
2022-11-13 17:26:04 +04:00
|
|
|
|
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();
|
2022-10-31 19:31:33 +04:00
|
|
|
|
|
|
|
|
|
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
|
|
|
|
|
|
|
|
|
buttonAddAirBomber.setText("Добавить бомбардировщик");
|
|
|
|
|
buttonAddAirBomber.setToolTipText("");
|
|
|
|
|
buttonAddAirBomber.addActionListener(new java.awt.event.ActionListener() {
|
|
|
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
|
|
buttonAddAirBomberActionPerformed(evt);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
maskedTextBoxPosition.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##")));
|
|
|
|
|
} catch (java.text.ParseException ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buttonRemoveAirBomber.setText("Удалить бомбардировщик");
|
|
|
|
|
buttonRemoveAirBomber.setToolTipText("");
|
|
|
|
|
buttonRemoveAirBomber.addActionListener(new java.awt.event.ActionListener() {
|
|
|
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
|
|
buttonRemoveAirBomberActionPerformed(evt);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
buttonShowStorage.setText("Посмотреть хранилище");
|
|
|
|
|
buttonShowStorage.addActionListener(new java.awt.event.ActionListener() {
|
|
|
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
|
|
buttonShowStorageActionPerformed(evt);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
buttonShowOnMap.setText("Посмотреть карту");
|
|
|
|
|
buttonShowOnMap.addActionListener(new java.awt.event.ActionListener() {
|
|
|
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
|
|
buttonShowOnMapActionPerformed(evt);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
leftButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowLeft.png"))); // NOI18N
|
|
|
|
|
leftButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
|
|
|
|
|
leftButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
|
|
|
|
leftButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
|
|
|
|
leftButton.setName("buttonLeft"); // NOI18N
|
|
|
|
|
leftButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
|
|
|
|
leftButton.addActionListener(new java.awt.event.ActionListener() {
|
|
|
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
|
|
moveButtonActionPerformed(evt);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
downButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowDown.png"))); // NOI18N
|
|
|
|
|
downButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
|
|
|
|
downButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
|
|
|
|
downButton.setName("buttonDown"); // NOI18N
|
|
|
|
|
downButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
|
|
|
|
downButton.addActionListener(new java.awt.event.ActionListener() {
|
|
|
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
|
|
moveButtonActionPerformed(evt);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rightButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowRight.png"))); // NOI18N
|
|
|
|
|
rightButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
|
|
|
|
rightButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
|
|
|
|
rightButton.setName("buttonRight"); // NOI18N
|
|
|
|
|
rightButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
|
|
|
|
rightButton.addActionListener(new java.awt.event.ActionListener() {
|
|
|
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
|
|
moveButtonActionPerformed(evt);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
upButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowUp.png"))); // NOI18N
|
|
|
|
|
upButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
|
|
|
|
upButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
|
|
|
|
upButton.setName("buttonUp"); // NOI18N
|
|
|
|
|
upButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
|
|
|
|
upButton.addActionListener(new java.awt.event.ActionListener() {
|
|
|
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
|
|
moveButtonActionPerformed(evt);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
jLabel1.setText("Инструменты");
|
|
|
|
|
|
2022-11-13 17:26:04 +04:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2022-10-31 19:31:33 +04:00
|
|
|
|
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)
|
2022-11-13 17:26:04 +04:00
|
|
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 59, Short.MAX_VALUE)
|
2022-10-31 19:31:33 +04:00
|
|
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
|
|
|
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
|
|
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
2022-11-13 17:26:04 +04:00
|
|
|
|
.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)))
|
2022-10-31 19:31:33 +04:00
|
|
|
|
.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)
|
|
|
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
|
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
|
|
|
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
|
|
|
.addGroup(layout.createSequentialGroup()
|
|
|
|
|
.addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
|
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
|
|
|
.addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
|
|
|
|
.addGap(62, 62, 62))))
|
|
|
|
|
);
|
|
|
|
|
layout.setVerticalGroup(
|
|
|
|
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
|
|
|
.addComponent(airBomberCanvas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
|
|
|
.addGroup(layout.createSequentialGroup()
|
|
|
|
|
.addGap(15, 15, 15)
|
|
|
|
|
.addComponent(jLabel1)
|
|
|
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
2022-11-13 17:26:04 +04:00
|
|
|
|
.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)
|
2022-10-31 19:31:33 +04:00
|
|
|
|
.addComponent(comboBoxSelectorMap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
2022-11-13 17:26:04 +04:00
|
|
|
|
.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)
|
2022-10-31 19:31:33 +04:00
|
|
|
|
.addComponent(buttonAddAirBomber)
|
2022-11-13 17:26:04 +04:00
|
|
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
2022-10-31 19:31:33 +04:00
|
|
|
|
.addComponent(maskedTextBoxPosition, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
2022-11-13 17:26:04 +04:00
|
|
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
2022-10-31 19:31:33 +04:00
|
|
|
|
.addComponent(buttonRemoveAirBomber)
|
2022-11-13 17:26:04 +04:00
|
|
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
2022-10-31 19:31:33 +04:00
|
|
|
|
.addComponent(buttonShowStorage)
|
2022-11-13 17:26:04 +04:00
|
|
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
2022-10-31 19:31:33 +04:00
|
|
|
|
.addComponent(buttonShowOnMap)
|
2022-11-13 17:26:04 +04:00
|
|
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
2022-10-31 19:31:33 +04:00
|
|
|
|
.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)
|
|
|
|
|
.addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
|
|
|
.addComponent(leftButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
|
|
|
.addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
|
|
|
|
.addContainerGap())
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
pack();
|
|
|
|
|
}// </editor-fold>//GEN-END:initComponents
|
|
|
|
|
|
|
|
|
|
private void moveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveButtonActionPerformed
|
|
|
|
|
String name = ((JButton) evt.getSource()).getName();
|
|
|
|
|
Direction dir = Direction.NONE;
|
|
|
|
|
switch (name)
|
|
|
|
|
{
|
|
|
|
|
case "buttonUp":
|
|
|
|
|
dir = Direction.UP;
|
|
|
|
|
break;
|
|
|
|
|
case "buttonDown":
|
|
|
|
|
dir = Direction.DOWN;
|
|
|
|
|
break;
|
|
|
|
|
case "buttonLeft":
|
|
|
|
|
dir = Direction.LEFT;
|
|
|
|
|
break;
|
|
|
|
|
case "buttonRight":
|
|
|
|
|
dir = Direction.RIGHT;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-11-13 17:26:04 +04:00
|
|
|
|
airBomberCanvas.getGraphics().drawImage(_mapsCollection.Get(listBoxMaps.getSelectedValue()).MoveObject(dir), 0, 0, null);
|
2022-10-31 19:31:33 +04:00
|
|
|
|
}//GEN-LAST:event_moveButtonActionPerformed
|
|
|
|
|
|
|
|
|
|
private void buttonAddAirBomberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddAirBomberActionPerformed
|
2022-11-13 17:26:04 +04:00
|
|
|
|
if (listBoxMaps.getSelectedIndex() == -1){
|
2022-10-31 19:31:33 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-11-15 13:03:57 +04:00
|
|
|
|
JFrameAirBomberConfig airBomberConfig = new JFrameAirBomberConfig();
|
|
|
|
|
airBomberConfig.addEvent(airBomber -> {_mapsCollection.Get(listBoxMaps.getSelectedValue()).add(new DrawingObjectAirBomber(airBomber));
|
|
|
|
|
airBomberCanvas.getGraphics().drawImage(_mapsCollection.Get(listBoxMaps.getSelectedValue()).ShowSet(), 0, 0, null);});
|
|
|
|
|
airBomberConfig.setVisible(true);
|
2022-10-31 19:31:33 +04:00
|
|
|
|
}//GEN-LAST:event_buttonAddAirBomberActionPerformed
|
|
|
|
|
|
|
|
|
|
private void buttonRemoveAirBomberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRemoveAirBomberActionPerformed
|
2022-11-13 17:26:04 +04:00
|
|
|
|
if (listBoxMaps.getSelectedIndex() == -1){
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-10-31 19:31:33 +04:00
|
|
|
|
if (maskedTextBoxPosition.getText().isBlank() || maskedTextBoxPosition.getText().isEmpty())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var res = JOptionPane.showConfirmDialog((Component) this, (Object) "Удалить объект?", "Удаление", JOptionPane.OK_CANCEL_OPTION);
|
|
|
|
|
if (res == JOptionPane.CANCEL_OPTION)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int pos = Integer.parseInt(maskedTextBoxPosition.getText());
|
2022-11-13 17:26:04 +04:00
|
|
|
|
DrawingObjectAirBomber deletedAirBomber = _mapsCollection.Get(listBoxMaps.getSelectedValue()).remove(pos);
|
|
|
|
|
if (deletedAirBomber != null)
|
2022-10-31 19:31:33 +04:00
|
|
|
|
{
|
2022-11-13 17:26:04 +04:00
|
|
|
|
deletedAirBombers.add(deletedAirBomber);
|
2022-10-31 19:31:33 +04:00
|
|
|
|
JOptionPane.showMessageDialog(null,"Объект удален");
|
2022-11-13 17:26:04 +04:00
|
|
|
|
airBomberCanvas.getGraphics().drawImage(_mapsCollection.Get(listBoxMaps.getSelectedValue()).ShowSet(), 0, 0, null);
|
2022-10-31 19:31:33 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
JOptionPane.showMessageDialog(null,"Не удалось удалить объект!");
|
|
|
|
|
}
|
|
|
|
|
}//GEN-LAST:event_buttonRemoveAirBomberActionPerformed
|
|
|
|
|
|
|
|
|
|
private void buttonShowStorageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonShowStorageActionPerformed
|
2022-11-13 17:26:04 +04:00
|
|
|
|
if (listBoxMaps.getSelectedIndex() == -1){
|
2022-10-31 19:31:33 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-11-13 17:26:04 +04:00
|
|
|
|
airBomberCanvas.getGraphics().drawImage(_mapsCollection.Get(listBoxMaps.getSelectedValue()).ShowSet(), 0, 0, null);
|
2022-10-31 19:31:33 +04:00
|
|
|
|
}//GEN-LAST:event_buttonShowStorageActionPerformed
|
|
|
|
|
|
|
|
|
|
private void buttonShowOnMapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonShowOnMapActionPerformed
|
2022-11-13 17:26:04 +04:00
|
|
|
|
if (listBoxMaps.getSelectedIndex() == -1){
|
2022-10-31 19:31:33 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-11-13 17:26:04 +04:00
|
|
|
|
airBomberCanvas.getGraphics().drawImage(_mapsCollection.Get(listBoxMaps.getSelectedValue()).ShowOnMap(), 0, 0, null);
|
2022-10-31 19:31:33 +04:00
|
|
|
|
}//GEN-LAST:event_buttonShowOnMapActionPerformed
|
2022-11-13 17:26:04 +04:00
|
|
|
|
|
|
|
|
|
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
|
2022-10-31 19:31:33 +04:00
|
|
|
|
|
2022-11-13 17:26:04 +04:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-31 19:31:33 +04:00
|
|
|
|
/**
|
|
|
|
|
* @param args the command line arguments
|
|
|
|
|
*/
|
|
|
|
|
public static void main(String args[]) {
|
|
|
|
|
/* Set the Nimbus look and feel */
|
|
|
|
|
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
|
|
|
|
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
|
|
|
|
|
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
|
|
|
|
|
*/
|
|
|
|
|
try {
|
|
|
|
|
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
|
|
|
|
|
if ("Nimbus".equals(info.getName())) {
|
|
|
|
|
javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (ClassNotFoundException ex) {
|
|
|
|
|
java.util.logging.Logger.getLogger(JFrameMapWithSetAirBombers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
|
|
|
|
} catch (InstantiationException ex) {
|
|
|
|
|
java.util.logging.Logger.getLogger(JFrameMapWithSetAirBombers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
|
|
|
|
} catch (IllegalAccessException ex) {
|
|
|
|
|
java.util.logging.Logger.getLogger(JFrameMapWithSetAirBombers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
|
|
|
|
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
|
|
|
|
|
java.util.logging.Logger.getLogger(JFrameMapWithSetAirBombers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
|
|
|
|
}
|
|
|
|
|
//</editor-fold>
|
|
|
|
|
|
|
|
|
|
/* Create and display the form */
|
|
|
|
|
java.awt.EventQueue.invokeLater(new Runnable() {
|
|
|
|
|
public void run() {
|
|
|
|
|
new JFrameMapWithSetAirBombers().setVisible(true);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
|
|
|
|
private AirBomberPackage.CanvasMy airBomberCanvas;
|
|
|
|
|
private javax.swing.JButton buttonAddAirBomber;
|
2022-11-13 17:26:04 +04:00
|
|
|
|
private javax.swing.JButton buttonAddMap;
|
|
|
|
|
private javax.swing.JButton buttonDeleteMap;
|
2022-10-31 19:31:33 +04:00
|
|
|
|
private javax.swing.JButton buttonRemoveAirBomber;
|
2022-11-13 17:26:04 +04:00
|
|
|
|
private javax.swing.JButton buttonShowDeleted;
|
2022-10-31 19:31:33 +04:00
|
|
|
|
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;
|
2022-11-13 17:26:04 +04:00
|
|
|
|
private javax.swing.JLabel jLabel2;
|
|
|
|
|
private javax.swing.JScrollPane jScrollPane1;
|
2022-10-31 19:31:33 +04:00
|
|
|
|
private javax.swing.JButton leftButton;
|
2022-11-13 17:26:04 +04:00
|
|
|
|
private javax.swing.JList<String> listBoxMaps;
|
2022-10-31 19:31:33 +04:00
|
|
|
|
private javax.swing.JFormattedTextField maskedTextBoxPosition;
|
|
|
|
|
private javax.swing.JButton rightButton;
|
2022-11-13 17:26:04 +04:00
|
|
|
|
private javax.swing.JTextField textBoxNewMapName;
|
2022-10-31 19:31:33 +04:00
|
|
|
|
private javax.swing.JButton upButton;
|
|
|
|
|
// End of variables declaration//GEN-END:variables
|
|
|
|
|
}
|