454 lines
25 KiB
Java
454 lines
25 KiB
Java
/*
|
||
* 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.*;
|
||
import javax.swing.DefaultListModel;
|
||
import java.util.HashMap;
|
||
import java.util.LinkedList;
|
||
import javax.swing.*;
|
||
|
||
/**
|
||
*
|
||
* @author Андрей
|
||
*/
|
||
public class JFrameMapWithSetAirBombers extends javax.swing.JFrame {
|
||
|
||
/**
|
||
* Creates new form JFrameMapWithSetAirBombers
|
||
*/
|
||
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 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.
|
||
* 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();
|
||
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);
|
||
|
||
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("Инструменты");
|
||
|
||
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, 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.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)
|
||
.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)
|
||
.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)
|
||
.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)
|
||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||
.addComponent(maskedTextBoxPosition, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||
.addComponent(buttonRemoveAirBomber)
|
||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||
.addComponent(buttonShowStorage)
|
||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||
.addComponent(buttonShowOnMap)
|
||
.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)
|
||
.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;
|
||
}
|
||
airBomberCanvas.getGraphics().drawImage(_mapsCollection.Get(listBoxMaps.getSelectedValue()).MoveObject(dir), 0, 0, null);
|
||
}//GEN-LAST:event_moveButtonActionPerformed
|
||
|
||
private void buttonAddAirBomberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddAirBomberActionPerformed
|
||
if (listBoxMaps.getSelectedIndex() == -1){
|
||
return;
|
||
}
|
||
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);
|
||
}//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;
|
||
}
|
||
var res = JOptionPane.showConfirmDialog((Component) this, (Object) "Удалить объект?", "Удаление", JOptionPane.OK_CANCEL_OPTION);
|
||
if (res == JOptionPane.CANCEL_OPTION)
|
||
{
|
||
return;
|
||
}
|
||
int pos = Integer.parseInt(maskedTextBoxPosition.getText());
|
||
DrawingObjectAirBomber deletedAirBomber = _mapsCollection.Get(listBoxMaps.getSelectedValue()).remove(pos);
|
||
if (deletedAirBomber != null)
|
||
{
|
||
deletedAirBombers.add(deletedAirBomber);
|
||
JOptionPane.showMessageDialog(null,"Объект удален");
|
||
airBomberCanvas.getGraphics().drawImage(_mapsCollection.Get(listBoxMaps.getSelectedValue()).ShowSet(), 0, 0, null);
|
||
}
|
||
else
|
||
{
|
||
JOptionPane.showMessageDialog(null,"Не удалось удалить объект!");
|
||
}
|
||
}//GEN-LAST:event_buttonRemoveAirBomberActionPerformed
|
||
|
||
private void buttonShowStorageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonShowStorageActionPerformed
|
||
if (listBoxMaps.getSelectedIndex() == -1){
|
||
return;
|
||
}
|
||
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 (listBoxMaps.getSelectedIndex() == -1){
|
||
return;
|
||
}
|
||
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
|
||
*/
|
||
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;
|
||
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
|
||
}
|