2022-12-05 23:37:38 +04:00
|
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
|
|
2022-10-25 01:58:38 +04:00
|
|
|
|
import javax.swing.*;
|
2022-11-21 01:04:53 +04:00
|
|
|
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
2022-10-25 01:58:38 +04:00
|
|
|
|
import javax.swing.text.DefaultFormatterFactory;
|
|
|
|
|
import javax.swing.text.MaskFormatter;
|
|
|
|
|
import java.awt.*;
|
2022-11-21 01:04:53 +04:00
|
|
|
|
import java.io.IOException;
|
2022-10-25 01:58:38 +04:00
|
|
|
|
import java.text.ParseException;
|
2022-11-05 18:38:20 +04:00
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Optional;
|
2022-11-05 19:18:29 +04:00
|
|
|
|
import java.util.Stack;
|
2022-10-25 01:58:38 +04:00
|
|
|
|
|
|
|
|
|
public class FormMapWithSetArtilleries extends JFrame {
|
2022-11-21 01:04:53 +04:00
|
|
|
|
private JMenuBar menuBar;
|
2022-10-25 01:58:38 +04:00
|
|
|
|
private JPanel pictureBox;
|
|
|
|
|
private JPanel toolsGroup;
|
|
|
|
|
private JLabel toolsLabel;
|
2022-11-05 18:38:20 +04:00
|
|
|
|
private JComboBox<String> comboBoxMapSelector;
|
2022-10-25 01:58:38 +04:00
|
|
|
|
private JButton buttonAddArtillery;
|
|
|
|
|
private JPanel paneArtilleries;
|
|
|
|
|
private JFormattedTextField textBoxPosition;
|
|
|
|
|
private JButton buttonRemoveArtillery;
|
|
|
|
|
private JButton buttonShowStorage;
|
|
|
|
|
private JButton buttonUp;
|
|
|
|
|
private JButton buttonDown;
|
|
|
|
|
private JButton buttonLeft;
|
|
|
|
|
private JButton buttonRight;
|
|
|
|
|
private JButton buttonShowOnMap;
|
2022-11-05 18:38:20 +04:00
|
|
|
|
private JLabel mapsLabel;
|
|
|
|
|
private JTextField textFieldMapName;
|
|
|
|
|
private JButton buttonAddMap;
|
|
|
|
|
private JList<String> listBoxMaps;
|
|
|
|
|
private JPanel mapsGroup;
|
|
|
|
|
private JButton buttonDeleteMap;
|
2022-11-05 19:18:29 +04:00
|
|
|
|
private JButton buttonShowDeleted;
|
2022-10-25 01:58:38 +04:00
|
|
|
|
|
|
|
|
|
private Image bufferedImage;
|
2022-11-05 18:38:20 +04:00
|
|
|
|
private final HashMap<String, AbstractMap> _mapsDict = new HashMap<>() {{
|
|
|
|
|
put("Простая карта", new SimpleMap());
|
|
|
|
|
put("Лесная карта", new ForestMap());
|
|
|
|
|
}};
|
|
|
|
|
private final MapsCollection _mapsCollection;
|
2022-11-05 19:18:29 +04:00
|
|
|
|
private final Stack<IDrawingObject> deletedObjects = new Stack<>();
|
2022-10-25 01:58:38 +04:00
|
|
|
|
|
2022-12-05 23:37:38 +04:00
|
|
|
|
private Logger logger;
|
|
|
|
|
|
|
|
|
|
public FormMapWithSetArtilleries(Logger logger) {
|
|
|
|
|
this();
|
|
|
|
|
this.logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-25 01:58:38 +04:00
|
|
|
|
public FormMapWithSetArtilleries() {
|
|
|
|
|
this.setTitle("Artillery");
|
|
|
|
|
this.setContentPane(paneArtilleries);
|
2022-11-05 18:38:20 +04:00
|
|
|
|
this.setSize(640, 530);
|
|
|
|
|
this.setVisible(true);
|
2022-10-25 01:58:38 +04:00
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
textBoxPosition.setFormatterFactory(new DefaultFormatterFactory(new MaskFormatter("##")));
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-05 18:38:20 +04:00
|
|
|
|
_mapsCollection = new MapsCollection(pictureBox.getWidth(), pictureBox.getHeight());
|
2022-10-25 01:58:38 +04:00
|
|
|
|
|
2022-11-21 01:04:53 +04:00
|
|
|
|
menuBar = new JMenuBar();
|
|
|
|
|
|
|
|
|
|
JMenu fileMenu = new JMenu("Файл");
|
|
|
|
|
menuBar.add(fileMenu);
|
|
|
|
|
|
|
|
|
|
JMenuItem saveMenuItem = new JMenuItem("Сохранить");
|
|
|
|
|
saveMenuItem.addActionListener(e -> {
|
|
|
|
|
JFileChooser dialog = new JFileChooser();
|
|
|
|
|
dialog.setFileFilter(new FileNameExtensionFilter("TXT file", "txt"));
|
|
|
|
|
dialog.showSaveDialog(this);
|
|
|
|
|
|
|
|
|
|
try {
|
2022-12-05 23:00:06 +04:00
|
|
|
|
_mapsCollection.saveData(dialog.getSelectedFile().getAbsolutePath());
|
2022-12-05 23:37:38 +04:00
|
|
|
|
logger.info("Сохранение в файл \"" + dialog.getSelectedFile().getAbsolutePath() + "\"");
|
2022-12-05 23:00:06 +04:00
|
|
|
|
JOptionPane.showMessageDialog(this, "Сохранение прошло успешно", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
2022-12-05 23:37:38 +04:00
|
|
|
|
logger.error("Ошибка сохранения в файл: " + ex.getMessage());
|
2022-12-05 23:00:06 +04:00
|
|
|
|
JOptionPane.showMessageDialog(this, "Не сохранилось: " + ex.getMessage(), "Провал", JOptionPane.INFORMATION_MESSAGE);
|
2022-11-21 01:04:53 +04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
fileMenu.add(saveMenuItem);
|
|
|
|
|
|
|
|
|
|
JMenuItem loadMenuItem = new JMenuItem("Загрузить");
|
|
|
|
|
loadMenuItem.addActionListener(e -> {
|
|
|
|
|
JFileChooser dialog = new JFileChooser();
|
|
|
|
|
dialog.setFileFilter(new FileNameExtensionFilter("TXT file", "txt"));
|
|
|
|
|
dialog.showOpenDialog(this);
|
|
|
|
|
|
|
|
|
|
try {
|
2022-12-05 23:00:06 +04:00
|
|
|
|
_mapsCollection.loadData(dialog.getSelectedFile().getAbsolutePath());
|
|
|
|
|
reloadMaps();
|
2022-12-05 23:37:38 +04:00
|
|
|
|
logger.info("Загрузка из файла \"" + dialog.getSelectedFile().getAbsolutePath() + "\"");
|
2022-12-05 23:00:06 +04:00
|
|
|
|
JOptionPane.showMessageDialog(this, "Загрузка прошла успешно", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
} catch (Exception ex) {
|
2022-12-05 23:37:38 +04:00
|
|
|
|
logger.error("Ошибка загрузки из файла: " + ex.getMessage());
|
2022-12-05 23:00:06 +04:00
|
|
|
|
JOptionPane.showMessageDialog(this, "Не загрузилось: " + ex.getMessage(), "Провал", JOptionPane.INFORMATION_MESSAGE);
|
2022-11-21 01:04:53 +04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
fileMenu.add(loadMenuItem);
|
|
|
|
|
|
2022-11-21 01:48:43 +04:00
|
|
|
|
JMenuItem saveMapMenuItem = new JMenuItem("Сохранить карту");
|
|
|
|
|
saveMapMenuItem.addActionListener(e -> {
|
|
|
|
|
JFileChooser dialog = new JFileChooser();
|
|
|
|
|
dialog.setFileFilter(new FileNameExtensionFilter("TXT file", "txt"));
|
|
|
|
|
dialog.showSaveDialog(this);
|
|
|
|
|
|
|
|
|
|
try {
|
2022-12-05 23:00:06 +04:00
|
|
|
|
_mapsCollection.saveMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse(""), dialog.getSelectedFile().getAbsolutePath());
|
2022-12-05 23:37:38 +04:00
|
|
|
|
logger.info("Сохранение карты в файл \"" + dialog.getSelectedFile().getAbsolutePath() + "\"");
|
2022-12-05 23:00:06 +04:00
|
|
|
|
JOptionPane.showMessageDialog(this, "Сохранение прошло успешно", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
} catch (Exception ex) {
|
2022-12-05 23:37:38 +04:00
|
|
|
|
logger.error("Ошибка сохранения карты в файл: " + ex.getMessage());
|
2022-12-05 23:00:06 +04:00
|
|
|
|
JOptionPane.showMessageDialog(this, "Не сохранилось: " + ex.getMessage(), "Провал", JOptionPane.INFORMATION_MESSAGE);
|
2022-11-21 01:48:43 +04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
fileMenu.add(saveMapMenuItem);
|
|
|
|
|
|
|
|
|
|
JMenuItem loadMapMenuItem = new JMenuItem("Загрузить карту");
|
|
|
|
|
loadMapMenuItem.addActionListener(e -> {
|
|
|
|
|
JFileChooser dialog = new JFileChooser();
|
|
|
|
|
dialog.setFileFilter(new FileNameExtensionFilter("TXT file", "txt"));
|
|
|
|
|
dialog.showOpenDialog(this);
|
|
|
|
|
|
|
|
|
|
try {
|
2022-12-05 23:00:06 +04:00
|
|
|
|
_mapsCollection.loadMap(dialog.getSelectedFile().getAbsolutePath());
|
|
|
|
|
reloadMaps();
|
2022-12-05 23:37:38 +04:00
|
|
|
|
logger.info("Загрузка карты из файла \"" + dialog.getSelectedFile().getAbsolutePath() + "\"");
|
2022-12-05 23:00:06 +04:00
|
|
|
|
JOptionPane.showMessageDialog(this, "Загрузка прошла успешно", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
} catch (Exception ex) {
|
2022-12-05 23:37:38 +04:00
|
|
|
|
logger.error("Ошибка загрузки карты из файла: " + ex.getMessage());
|
2022-12-05 23:00:06 +04:00
|
|
|
|
JOptionPane.showMessageDialog(this, "Не загрузилось: " + ex.getMessage(), "Провал", JOptionPane.INFORMATION_MESSAGE);
|
2022-11-21 01:48:43 +04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
fileMenu.add(loadMapMenuItem);
|
|
|
|
|
|
2022-11-21 01:04:53 +04:00
|
|
|
|
setJMenuBar(menuBar);
|
|
|
|
|
|
2022-11-05 18:38:20 +04:00
|
|
|
|
comboBoxMapSelector.removeAllItems();
|
|
|
|
|
for (var key : _mapsDict.keySet()) {
|
|
|
|
|
comboBoxMapSelector.addItem(key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buttonAddMap.addActionListener(e -> {
|
|
|
|
|
if (comboBoxMapSelector.getSelectedIndex() == -1 || textFieldMapName.getText() == null || textFieldMapName.getText().isEmpty()) {
|
2022-12-05 23:37:38 +04:00
|
|
|
|
logger.warn("Не удалось добавить карту: Не все данные заполнены");
|
2022-11-05 18:38:20 +04:00
|
|
|
|
JOptionPane.showMessageDialog(this, "Не все данные заполнены", "Ошибка", JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!_mapsDict.containsKey((String)comboBoxMapSelector.getSelectedItem())) {
|
2022-12-05 23:37:38 +04:00
|
|
|
|
logger.warn("Не удалось добавить карту: Нет такой карты");
|
2022-11-05 18:38:20 +04:00
|
|
|
|
JOptionPane.showMessageDialog(this, "Нет такой карты", "Ошибка", JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_mapsCollection.addMap(textFieldMapName.getText(), _mapsDict.get((String)comboBoxMapSelector.getSelectedItem()));
|
|
|
|
|
reloadMaps();
|
2022-12-05 23:42:43 +04:00
|
|
|
|
logger.info("Добавлена карта \"" + textFieldMapName.getText() + "\" типа " + (String)comboBoxMapSelector.getSelectedItem());
|
2022-11-05 18:38:20 +04:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
buttonDeleteMap.addActionListener(e -> {
|
|
|
|
|
if (listBoxMaps.getSelectedIndex() == -1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (JOptionPane.showConfirmDialog(this, "Удалить карту " + listBoxMaps.getSelectedValue() + "?", "Удаление", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
|
|
|
|
_mapsCollection.deleteMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse(""));
|
2022-12-05 23:37:38 +04:00
|
|
|
|
logger.info("Удалена карта \"" + listBoxMaps.getSelectedValue() + "\"");
|
2022-11-05 18:38:20 +04:00
|
|
|
|
reloadMaps();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
listBoxMaps.addListSelectionListener(e -> {
|
|
|
|
|
if (listBoxMaps.getSelectedValue() != null) {
|
|
|
|
|
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).showSet();
|
|
|
|
|
repaint();
|
2022-12-05 23:37:38 +04:00
|
|
|
|
logger.info("Переход на карту \"" + listBoxMaps.getSelectedValue() + "\"");
|
2022-10-25 01:58:38 +04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
buttonAddArtillery.addActionListener(e -> {
|
2022-11-06 20:33:15 +04:00
|
|
|
|
FormArtilleryConfig form = new FormArtilleryConfig();
|
|
|
|
|
form.addListener(artillery -> {
|
|
|
|
|
if (listBoxMaps.getSelectedIndex() == -1) {
|
|
|
|
|
return;
|
2022-10-25 01:58:38 +04:00
|
|
|
|
}
|
2022-11-06 20:33:15 +04:00
|
|
|
|
|
|
|
|
|
if (artillery != null) {
|
2022-12-05 23:00:06 +04:00
|
|
|
|
try {
|
|
|
|
|
DrawingObjectArtillery objectArtillery = new DrawingObjectArtillery(artillery);
|
|
|
|
|
if (_mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).addArtillery(objectArtillery) != -1) {
|
|
|
|
|
JOptionPane.showMessageDialog(this, "Объект добавлен", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).showSet();
|
|
|
|
|
repaint();
|
2022-12-05 23:37:38 +04:00
|
|
|
|
logger.info("Добавлен новый объект");
|
2022-12-05 23:00:06 +04:00
|
|
|
|
} else {
|
2022-12-05 23:37:38 +04:00
|
|
|
|
logger.warn("Не удалось добавить объект");
|
2022-12-05 23:00:06 +04:00
|
|
|
|
JOptionPane.showMessageDialog(this, "Не удалось добавить объект", "Провал", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
}
|
|
|
|
|
} catch (StorageOverflowException ex) {
|
2022-12-05 23:37:38 +04:00
|
|
|
|
logger.warn("Ошибка переполнения хранилища: " + ex.getMessage());
|
2022-12-05 23:00:06 +04:00
|
|
|
|
JOptionPane.showMessageDialog(this, "Ошибка переполнения хранилища: " + ex.getMessage(), "Провал", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
} catch (Exception ex) {
|
2022-12-05 23:37:38 +04:00
|
|
|
|
logger.fatal("Неизвестная ошибка: " + ex.getMessage());
|
2022-12-05 23:00:06 +04:00
|
|
|
|
JOptionPane.showMessageDialog(this, "Неизвестная ошибка: " + ex.getMessage(), "Провал", JOptionPane.INFORMATION_MESSAGE);
|
2022-11-06 20:33:15 +04:00
|
|
|
|
}
|
2022-10-25 01:58:38 +04:00
|
|
|
|
}
|
2022-11-06 20:33:15 +04:00
|
|
|
|
});
|
|
|
|
|
form.setVisible(true);
|
2022-10-25 01:58:38 +04:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
buttonRemoveArtillery.addActionListener(e -> {
|
|
|
|
|
String text = textBoxPosition.getText();
|
|
|
|
|
if (text == null || text.isEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (JOptionPane.showConfirmDialog(this, "Удалить объект?", "Удаление", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int position = Integer.parseInt(text);
|
|
|
|
|
|
2022-12-05 23:00:06 +04:00
|
|
|
|
try {
|
|
|
|
|
IDrawingObject deleted = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).removeArtilleryAt(position);
|
|
|
|
|
if (deleted != null) {
|
|
|
|
|
deletedObjects.push(deleted);
|
|
|
|
|
JOptionPane.showMessageDialog(this, "Объект удалён", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).showSet();
|
|
|
|
|
repaint();
|
2022-12-05 23:37:38 +04:00
|
|
|
|
logger.info("Удалён объект");
|
2022-12-05 23:00:06 +04:00
|
|
|
|
} else {
|
2022-12-05 23:37:38 +04:00
|
|
|
|
logger.warn("Не удалось удалить объект по позиции " + position + ". Объект равен null");
|
2022-12-05 23:00:06 +04:00
|
|
|
|
JOptionPane.showMessageDialog(this, "Не удалось удалить объект", "Провал", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
}
|
|
|
|
|
} catch (ArtilleryNotFoundException ex) {
|
2022-12-05 23:37:38 +04:00
|
|
|
|
logger.warn("Ошибка удаления: " + ex.getMessage());
|
2022-12-05 23:00:06 +04:00
|
|
|
|
JOptionPane.showMessageDialog(this, "Не удалось найти артиллерию по позиции: " + ex.getMessage(), "Провал", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
} catch (Exception ex) {
|
2022-12-05 23:37:38 +04:00
|
|
|
|
logger.error("Неизвестная ошибка: " + ex.getMessage());
|
2022-12-05 23:00:06 +04:00
|
|
|
|
JOptionPane.showMessageDialog(this, "Неизвестная ошибка: " + ex.getMessage(), "Провал", JOptionPane.INFORMATION_MESSAGE);
|
2022-10-25 01:58:38 +04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
buttonShowStorage.addActionListener(e -> {
|
2022-11-05 18:38:20 +04:00
|
|
|
|
if (listBoxMaps.getSelectedIndex() == -1) {
|
2022-10-25 01:58:38 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-11-05 18:38:20 +04:00
|
|
|
|
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).showSet();
|
2022-10-25 01:58:38 +04:00
|
|
|
|
repaint();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
buttonShowOnMap.addActionListener(e -> {
|
2022-11-05 18:38:20 +04:00
|
|
|
|
if (listBoxMaps.getSelectedIndex() == -1) {
|
2022-10-25 01:58:38 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-11-05 18:38:20 +04:00
|
|
|
|
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).showOnMap();
|
2022-10-25 01:58:38 +04:00
|
|
|
|
repaint();
|
|
|
|
|
});
|
|
|
|
|
|
2022-11-05 19:18:29 +04:00
|
|
|
|
buttonShowDeleted.addActionListener(e -> {
|
|
|
|
|
if (!deletedObjects.empty()) {
|
|
|
|
|
DrawingObjectArtillery deleted = (DrawingObjectArtillery) deletedObjects.pop();
|
2022-11-08 16:32:08 +04:00
|
|
|
|
FormArtillery dialog = new FormArtillery(deleted.getArtillery());
|
2022-11-05 19:18:29 +04:00
|
|
|
|
dialog.setSize(800, 500);
|
|
|
|
|
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
|
|
|
|
|
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
|
|
|
|
|
|
|
|
|
dialog.setVisible(true);
|
2022-11-08 16:32:08 +04:00
|
|
|
|
} else {
|
|
|
|
|
JOptionPane.showMessageDialog(this, "Стек удалённых объектов пуст", "Провал", JOptionPane.INFORMATION_MESSAGE);
|
2022-11-05 19:18:29 +04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2022-10-25 01:58:38 +04:00
|
|
|
|
buttonLeft.addActionListener(e -> {
|
2022-11-05 18:38:20 +04:00
|
|
|
|
if (listBoxMaps.getSelectedIndex() != -1) {
|
|
|
|
|
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).moveObject(Direction.Left);
|
2022-10-25 01:58:38 +04:00
|
|
|
|
repaint();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
buttonRight.addActionListener(e -> {
|
2022-11-05 18:38:20 +04:00
|
|
|
|
if (listBoxMaps.getSelectedIndex() != -1) {
|
|
|
|
|
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).moveObject(Direction.Right);
|
2022-10-25 01:58:38 +04:00
|
|
|
|
repaint();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
buttonUp.addActionListener(e -> {
|
2022-11-05 18:38:20 +04:00
|
|
|
|
if (listBoxMaps.getSelectedIndex() != -1) {
|
|
|
|
|
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).moveObject(Direction.Up);
|
2022-10-25 01:58:38 +04:00
|
|
|
|
repaint();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
buttonDown.addActionListener(e -> {
|
2022-11-05 18:38:20 +04:00
|
|
|
|
if (listBoxMaps.getSelectedIndex() != -1) {
|
|
|
|
|
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).moveObject(Direction.Down);
|
2022-10-25 01:58:38 +04:00
|
|
|
|
repaint();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-05 18:38:20 +04:00
|
|
|
|
private void reloadMaps() {
|
|
|
|
|
int index = listBoxMaps.getSelectedIndex();
|
|
|
|
|
|
|
|
|
|
listBoxMaps.setListData(_mapsCollection.getKeys().toArray(new String[0]));
|
|
|
|
|
int size = listBoxMaps.getModel().getSize();
|
|
|
|
|
|
|
|
|
|
if (size > 0 && (index == -1 || index >= size)) {
|
|
|
|
|
listBoxMaps.setSelectedIndex(0);
|
|
|
|
|
} else if (index > -1 && index < size) {
|
|
|
|
|
listBoxMaps.setSelectedIndex(index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-25 01:58:38 +04:00
|
|
|
|
@Override
|
|
|
|
|
public void paint(Graphics g) {
|
|
|
|
|
super.paint(g);
|
|
|
|
|
|
|
|
|
|
if (bufferedImage != null) {
|
|
|
|
|
pictureBox.paintComponents(bufferedImage.getGraphics());
|
|
|
|
|
pictureBox.getGraphics().drawImage(bufferedImage, 0, 0, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|