From d9c0fbf63c3ab415bd2dd1e5bd643353f0d7d8a0 Mon Sep 17 00:00:00 2001 From: Hells Hound Date: Wed, 14 Dec 2022 00:27:44 +0400 Subject: [PATCH 1/4] =?UTF-8?q?7=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/AircraftCarrier_Hard.iml | 1 + AircraftCarrier_Hard.iml | 21 +++++ log4j.properties | 28 +++++++ messages | 8 ++ src/FormMapWithSetWarships.java | 133 ++++++++++++++++++------------ src/MapsCollection.java | 12 +-- src/SetWarshipsGeneric.java | 3 +- src/StorageOverflowException.java | 16 ++++ src/WarshipNotFoundException.java | 16 ++++ src/log4j.xml | 19 +++++ 10 files changed, 199 insertions(+), 58 deletions(-) create mode 100644 AircraftCarrier_Hard.iml create mode 100644 log4j.properties create mode 100644 messages create mode 100644 src/StorageOverflowException.java create mode 100644 src/WarshipNotFoundException.java create mode 100644 src/log4j.xml diff --git a/.idea/AircraftCarrier_Hard.iml b/.idea/AircraftCarrier_Hard.iml index c90834f..43191f2 100644 --- a/.idea/AircraftCarrier_Hard.iml +++ b/.idea/AircraftCarrier_Hard.iml @@ -7,5 +7,6 @@ + \ No newline at end of file diff --git a/AircraftCarrier_Hard.iml b/AircraftCarrier_Hard.iml new file mode 100644 index 0000000..b4ed4c2 --- /dev/null +++ b/AircraftCarrier_Hard.iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/log4j.properties b/log4j.properties new file mode 100644 index 0000000..88a9ad0 --- /dev/null +++ b/log4j.properties @@ -0,0 +1,28 @@ +log4j.logger.FormMapWithSetWarshipGeneric=INFO, fileAppender, adminAppender + +log4j.additivity.FormMapWithSetWarshipGeneric=false +log4j.additivity.FormMapWithSetWarshipGenericAdmin=false + +log4j.appender.fileAppender.threshold=INFO +log4j.appender.adminAppender.threshold=INFO + +log4j.appender.fileAppender=org.apache.log4j.RollingFileAppender +log4j.appender.fileAppender.File=user.log +log4j.appender.fileAppender.MaxFileSize=1MB +log4j.appender.fileAppender.MaxBackupIndex=1 +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.layout.ConversionPattern=%-5p %c{1}:%L - %m %d{dd-MM-yyyy}%n +log4j.appender.fileAppender.filter.a=org.apache.log4j.varia.LevelRangeFilter +log4j.appender.fileAppender.filter.a.LevelMin=INFO +log4j.appender.fileAppender.filter.a.LevelMax=INFO +log4j.appender.fileAppender.filter.a.AcceptOnMatch=TRUE + +log4j.appender.adminAppender=org.apache.log4j.RollingFileAppender +log4j.appender.adminAppender.File=admin.log +log4j.appender.adminAppender.MaxFileSize=1MB +log4j.appender.adminAppender.MaxBackupIndex=1 +log4j.appender.adminAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.adminAppender.layout.ConversionPattern=%-5p %c{1}:%L - %m %d{dd-MM-yyyy}%n +log4j.appender.adminAppender.filter.a=org.apache.log4j.varia.LevelRangeFilter +log4j.appender.adminAppender.filter.a.LevelMin=WARN +log4j.appender.adminAppender.filter.a.AcceptOnMatch=TRUE \ No newline at end of file diff --git a/messages b/messages new file mode 100644 index 0000000..711e221 --- /dev/null +++ b/messages @@ -0,0 +1,8 @@ +2022-12-14 00:20:19 INFO FormMapWithSetTractorsGeneric:195 - Переход на карту: 1 +2022-12-14 00:20:19 INFO FormMapWithSetTractorsGeneric:228 - Добавлена карта: 1 + INFO FormMapWithSetTractorsGeneric:195 - Переход на карту: 1 2022-12-14 + INFO FormMapWithSetTractorsGeneric:228 - Добавлена карта: 1 2022-12-14 + INFO FormMapWithSetTractorsGeneric:195 - Переход на карту: 1 2022-12-14 + INFO FormMapWithSetTractorsGeneric:228 - Добавлена карта: 1 2022-12-14 + INFO FormMapWithSetTractorsGeneric:195 - Переход на карту: 1 14-12-2022 + INFO FormMapWithSetTractorsGeneric:228 - Добавлена карта: 1 14-12-2022 diff --git a/src/FormMapWithSetWarships.java b/src/FormMapWithSetWarships.java index d360886..52b1b82 100644 --- a/src/FormMapWithSetWarships.java +++ b/src/FormMapWithSetWarships.java @@ -7,6 +7,7 @@ import java.io.File; import java.util.HashMap; import java.util.function.Consumer; +import org.apache.log4j.*; public class FormMapWithSetWarships extends JFrame{ private JPanel mainPanel; private JPanel PictureBox; @@ -41,6 +42,8 @@ public class FormMapWithSetWarships extends JFrame{ put("LineMap", new LineMap()); }}; + private Logger _logger; + public FormMapWithSetWarships(){ InitializeComponent(); } @@ -71,6 +74,7 @@ public class FormMapWithSetWarships extends JFrame{ } private void InitializeComponent(){ + _logger = Logger.getLogger("FormMapWithSetTractorsGeneric"); setContentPane(mainPanel); setTitle("Warship"); setSize(935, 693); @@ -104,14 +108,14 @@ public class FormMapWithSetWarships extends JFrame{ fs.setDialogTitle("Save"); int result = fs.showSaveDialog(null); if (result == JFileChooser.APPROVE_OPTION) { - File selectedFile = fs.getSelectedFile(); - if (_mapsCollection.SaveData(selectedFile.getPath())) - { + try { + File selectedFile = fs.getSelectedFile(); + _mapsCollection.SaveData(selectedFile.getPath()); + _logger.info("Успешное сохранение в файл: "+selectedFile.getPath()); JOptionPane.showMessageDialog(null, "Сохранение прошло успешно", "Результат",JOptionPane.INFORMATION_MESSAGE); - } - else - { - JOptionPane.showMessageDialog(null, "Не сохранилось", "Результат",JOptionPane.ERROR_MESSAGE); + } catch (Exception ex) { + _logger.error("Данные не сохранились: "+ex.getMessage()); + JOptionPane.showMessageDialog(null, "Не сохранилось: "+ex.getMessage(), "Результат",JOptionPane.ERROR_MESSAGE); } } }); @@ -126,15 +130,15 @@ public class FormMapWithSetWarships extends JFrame{ fs.setDialogTitle("Load"); int result = fs.showSaveDialog(null); if (result == JFileChooser.APPROVE_OPTION) { - File selectedFile = fs.getSelectedFile(); - if (_mapsCollection.LoadData(selectedFile.getPath())) - { + try { + File selectedFile = fs.getSelectedFile(); + _mapsCollection.LoadData(selectedFile.getPath()); ReloadMaps(); + _logger.info("Успешная загрузка из файла: "+selectedFile.getPath()); JOptionPane.showMessageDialog(null, "Загрузка прошла успешно", "Результат",JOptionPane.INFORMATION_MESSAGE); - } - else - { - JOptionPane.showMessageDialog(null, "Не удалось загрузить", "Результат",JOptionPane.ERROR_MESSAGE); + } catch(Exception ex) { + _logger.error("Не загрузилось: "+ex.getMessage()); + JOptionPane.showMessageDialog(null, "Не загрузилось: "+ex.getMessage(), "Результат",JOptionPane.ERROR_MESSAGE); } } }); @@ -149,14 +153,14 @@ public class FormMapWithSetWarships extends JFrame{ fs.setDialogTitle("SaveMap"); int result = fs.showSaveDialog(null); if (result == JFileChooser.APPROVE_OPTION) { - File selectedFile = fs.getSelectedFile(); - if (_mapsCollection.SaveMap(selectedFile.getPath(), ListBoxMaps.getSelectedValue().toString())) - { + try { + File selectedFile = fs.getSelectedFile(); + _mapsCollection.SaveMap(selectedFile.getPath(), ListBoxMaps.getSelectedValue().toString()); + _logger.info("Успешное сохранение карты в файл: "+selectedFile.getPath()); JOptionPane.showMessageDialog(null, "Сохранение карты прошло успешно", "Результат",JOptionPane.INFORMATION_MESSAGE); - } - else - { - JOptionPane.showMessageDialog(null, "Не сохранилась карта", "Результат",JOptionPane.ERROR_MESSAGE); + } catch(Exception ex) { + _logger.error("Не сохранилась карта: "+ex.getMessage()); + JOptionPane.showMessageDialog(null, "Не сохранилась карта: "+ex.getMessage(), "Результат",JOptionPane.ERROR_MESSAGE); } } }); @@ -171,15 +175,15 @@ public class FormMapWithSetWarships extends JFrame{ fs.setDialogTitle("LoadMap"); int result = fs.showSaveDialog(null); if (result == JFileChooser.APPROVE_OPTION) { - File selectedFile = fs.getSelectedFile(); - if (_mapsCollection.LoadMap(selectedFile.getPath())) - { - JOptionPane.showMessageDialog(null, "Загрузка карты прошла успешно", "Результат",JOptionPane.INFORMATION_MESSAGE); + try { + File selectedFile = fs.getSelectedFile(); + _mapsCollection.LoadMap(selectedFile.getPath()); + JOptionPane.showMessageDialog(null, "Загрузка карты прошла успешно", "Результат", JOptionPane.INFORMATION_MESSAGE); ReloadMaps(); - } - else - { - JOptionPane.showMessageDialog(null, "Не загрузилась карта", "Результат",JOptionPane.ERROR_MESSAGE); + _logger.info("Успешная загрузка карты из файла: "+selectedFile.getPath()); + }catch(Exception ex) { + _logger.error("Не загрузилась карта: "+ex.getMessage()); + JOptionPane.showMessageDialog(null, "Не загрузилась карта", "Результат", JOptionPane.ERROR_MESSAGE); } } }); @@ -188,6 +192,7 @@ public class FormMapWithSetWarships extends JFrame{ if(ListBoxMaps.getSelectedIndex() == -1) return; bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet(); + _logger.log(Level.INFO,"Переход на карту: " + ListBoxMaps.getSelectedValue().toString()); repaint(); }); @@ -199,6 +204,7 @@ public class FormMapWithSetWarships extends JFrame{ if(JOptionPane.showConfirmDialog(this,"Удалить карту " + ListBoxMaps.getSelectedValue().toString() + "?", "Удаление",JOptionPane.YES_NO_OPTION) == 0) { + _logger.info("Удалена карта: " + ListBoxMaps.getSelectedValue().toString()); _mapsCollection.DelMap(ListBoxMaps.getSelectedValue().toString()); ReloadMaps(); } @@ -207,16 +213,19 @@ public class FormMapWithSetWarships extends JFrame{ CreateMapButton.addActionListener(e -> { if (СomboBoxSelectorMap.getSelectedIndex() == -1 || TextFieldMap.getText() == null || TextFieldMap.getText().equals("")) { + _logger.info("Не все данные были заполнены при добавлении карты"); JOptionPane.showMessageDialog(this,"Не все данные заполнены","Ошибка",JOptionPane.ERROR_MESSAGE); return; } if (!_mapsDict.containsKey(СomboBoxSelectorMap.getSelectedItem())) { + _logger.info("Нет карты с названием: " + СomboBoxSelectorMap.getSelectedItem()); JOptionPane.showMessageDialog(this,"Нет такой карты","Ошибка",JOptionPane.ERROR_MESSAGE); return; } _mapsCollection.AddMap(TextFieldMap.getText(), _mapsDict.get(СomboBoxSelectorMap.getSelectedItem().toString())); ReloadMaps(); + _logger.info("Добавлена карта: " + TextFieldMap.getText()); }); deletedWarshipButtom.addActionListener(e -> { @@ -235,20 +244,31 @@ public class FormMapWithSetWarships extends JFrame{ ButtonAddWarship.addActionListener(e -> { FormWarshipConfig formWarshipConfig = new FormWarshipConfig(); formWarshipConfig.AddEvent(newWarship ->{ - if(ListBoxMaps.getSelectedIndex() == -1){ - return; - } - if(newWarship != null){ - DrawingObjectWarship warship = new DrawingObjectWarship(newWarship); - if (_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).Plus(warship) >= 0) { - JOptionPane.showMessageDialog(null, "Объект добавлен"); - bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet(); - repaint(); + try{ + if(ListBoxMaps.getSelectedIndex() == -1){ + return; } - else { - JOptionPane.showMessageDialog(null, "Не удалось добавить объект"); + if(newWarship != null){ + DrawingObjectWarship warship = new DrawingObjectWarship(newWarship); + if (_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).Plus(warship) >= 0) { + _logger.info("Добавлен объект: " + warship); + JOptionPane.showMessageDialog(null, "Объект добавлен"); + bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet(); + repaint(); + } + else { + _logger.info("Не удалось добавить объект: " + warship); + JOptionPane.showMessageDialog(null, "Не удалось добавить объект"); + } } + }catch (StorageOverflowException ex){ + _logger.warn("Ошибка переполнения хранилища: " + ex.getMessage()); + JOptionPane.showMessageDialog(null, "Ошибка переполнения хранилища: " + ex.getMessage()); + }catch (Exception ex){ + _logger.fatal("Неизвестная ошибка добавления: " + ex.getMessage()); + JOptionPane.showMessageDialog(null, "Неизвестная ошибка: " + ex.getMessage()); } + }); formWarshipConfig.setSize(1000, 450); formWarshipConfig.setVisible(true); @@ -270,17 +290,28 @@ public class FormMapWithSetWarships extends JFrame{ return; } int pos = Integer.parseInt(TextBoxPosition.getText()); - if (_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).Minus(pos)!=null) - { - JOptionPane.showMessageDialog(this, - "Объект удален","Успех",JOptionPane.INFORMATION_MESSAGE); - bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet(); - repaint(); - } - else - { - JOptionPane.showMessageDialog(this, - "Не удалось удалить объект","Ошибка",JOptionPane.INFORMATION_MESSAGE); + try { + var deletedWarship = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).Minus(pos); + if (deletedWarship != null) + { + _logger.info("Удален объект: " + deletedWarship); + JOptionPane.showMessageDialog(this, + "Объект удален","Успех",JOptionPane.INFORMATION_MESSAGE); + bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet(); + repaint(); + } + else + { + _logger.info("Не удалось удалить объект по позиции: " + pos); + JOptionPane.showMessageDialog(this, + "Не удалось удалить объект","Ошибка",JOptionPane.INFORMATION_MESSAGE); + } + }catch (WarshipNotFoundException ex){ + _logger.warn("Ошибка удаления: " + ex.getMessage()); + JOptionPane.showMessageDialog(null, "Ошибка удаления: " + ex.getMessage()); + }catch (Exception ex){ + _logger.fatal("Неизвестная ошибка удаления: " + ex.getMessage()); + JOptionPane.showMessageDialog(null, "Неизвестная ошибка: " + ex.getMessage()); } }); diff --git a/src/MapsCollection.java b/src/MapsCollection.java index a16a686..7510f36 100644 --- a/src/MapsCollection.java +++ b/src/MapsCollection.java @@ -49,7 +49,7 @@ public class MapsCollection { return null; } - public boolean SaveData(String filename) { + public void SaveData(String filename) { File file = new File(filename); if (file.exists()) { @@ -64,21 +64,20 @@ public class MapsCollection { } catch (IOException e) { throw new RuntimeException(e); } - return true; } - public boolean LoadData(String filename) + public void LoadData(String filename)throws FileNotFoundException { if (!(new File(filename).exists())) { - return false; + throw new FileNotFoundException("Файл не найден"); } try (BufferedReader br = new BufferedReader(new FileReader(filename))) { String str = ""; if ((str = br.readLine()) == null || !str.contains("MapsCollection")) { - return false; + throw new IllegalArgumentException("Формат данных в файле неправильный"); } //очищаем записи _mapStorages.clear(); @@ -100,8 +99,9 @@ public class MapsCollection { } } catch (IOException e) { throw new RuntimeException(e); + }catch (StorageOverflowException e) { + throw new RuntimeException(e); } - return true; } //Сохранение отдельного объекта класса-хранилища diff --git a/src/SetWarshipsGeneric.java b/src/SetWarshipsGeneric.java index a281a76..6ec697a 100644 --- a/src/SetWarshipsGeneric.java +++ b/src/SetWarshipsGeneric.java @@ -22,7 +22,7 @@ public class SetWarshipsGeneric implements Iterable{ public int Insert(T warship, int position) { if (position < 0 || position >= _maxCount) - return -1; + throw new StorageOverflowException(_maxCount); _places.add(position, warship); return position; } @@ -32,6 +32,7 @@ public class SetWarshipsGeneric implements Iterable{ if (position >= _maxCount || position < 0) return null; T deleted = _places.get(position); + if(deleted == null) throw new WarshipNotFoundException(position); _places.remove(position); return deleted; } diff --git a/src/StorageOverflowException.java b/src/StorageOverflowException.java new file mode 100644 index 0000000..d8323e4 --- /dev/null +++ b/src/StorageOverflowException.java @@ -0,0 +1,16 @@ +public class StorageOverflowException extends RuntimeException{ + public StorageOverflowException(){ + } + public StorageOverflowException(String message){ + super(message); + } + public StorageOverflowException(String message,Throwable exception){ + super(message,exception); + } + protected StorageOverflowException(Throwable exception){ + super(exception); + } + public StorageOverflowException(int count){ + super("В наборе превышено допустимое количество: " + count); + } +} diff --git a/src/WarshipNotFoundException.java b/src/WarshipNotFoundException.java new file mode 100644 index 0000000..59625ca --- /dev/null +++ b/src/WarshipNotFoundException.java @@ -0,0 +1,16 @@ +public class WarshipNotFoundException extends RuntimeException{ + public WarshipNotFoundException(){ + } + public WarshipNotFoundException(String message){ + super(message); + } + public WarshipNotFoundException(String message,Throwable exception){ + super(message,exception); + } + public WarshipNotFoundException(Throwable exception){ + super(exception); + } + public WarshipNotFoundException(int i){ + super("Не найден объект по позиции " + i); + } +} diff --git a/src/log4j.xml b/src/log4j.xml new file mode 100644 index 0000000..b7708ff --- /dev/null +++ b/src/log4j.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file -- 2.25.1 From 441001a425ab693f50e52610d7f7f1935bbeb60a Mon Sep 17 00:00:00 2001 From: Inohara Date: Fri, 16 Dec 2022 12:06:53 +0400 Subject: [PATCH 2/4] =?UTF-8?q?7=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F(=D0=B1=D0=B5=D0=B7=20?= =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B3=D0=BE=D0=B2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/AircraftCarrier_Hard.iml | 18 ++++++++++++ messages | 8 ------ src/FormMapWithSetWarships.form | 2 +- src/FormMapWithSetWarships.java | 13 ++++++--- src/Main.java | 4 ++- src/MapWithSetWarshipsGeneric.java | 7 +++-- src/SetWarshipsGeneric.java | 2 +- src/log4j.xml | 46 ++++++++++++++++++------------ 8 files changed, 63 insertions(+), 37 deletions(-) delete mode 100644 messages diff --git a/.idea/AircraftCarrier_Hard.iml b/.idea/AircraftCarrier_Hard.iml index 43191f2..5c48835 100644 --- a/.idea/AircraftCarrier_Hard.iml +++ b/.idea/AircraftCarrier_Hard.iml @@ -7,6 +7,24 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/messages b/messages deleted file mode 100644 index 711e221..0000000 --- a/messages +++ /dev/null @@ -1,8 +0,0 @@ -2022-12-14 00:20:19 INFO FormMapWithSetTractorsGeneric:195 - Переход на карту: 1 -2022-12-14 00:20:19 INFO FormMapWithSetTractorsGeneric:228 - Добавлена карта: 1 - INFO FormMapWithSetTractorsGeneric:195 - Переход на карту: 1 2022-12-14 - INFO FormMapWithSetTractorsGeneric:228 - Добавлена карта: 1 2022-12-14 - INFO FormMapWithSetTractorsGeneric:195 - Переход на карту: 1 2022-12-14 - INFO FormMapWithSetTractorsGeneric:228 - Добавлена карта: 1 2022-12-14 - INFO FormMapWithSetTractorsGeneric:195 - Переход на карту: 1 14-12-2022 - INFO FormMapWithSetTractorsGeneric:228 - Добавлена карта: 1 14-12-2022 diff --git a/src/FormMapWithSetWarships.form b/src/FormMapWithSetWarships.form index d727893..a3e5af9 100644 --- a/src/FormMapWithSetWarships.form +++ b/src/FormMapWithSetWarships.form @@ -3,7 +3,7 @@ - + diff --git a/src/FormMapWithSetWarships.java b/src/FormMapWithSetWarships.java index 52b1b82..68f7a69 100644 --- a/src/FormMapWithSetWarships.java +++ b/src/FormMapWithSetWarships.java @@ -7,7 +7,7 @@ import java.io.File; import java.util.HashMap; import java.util.function.Consumer; -import org.apache.log4j.*; +import org.apache.log4j.Logger; public class FormMapWithSetWarships extends JFrame{ private JPanel mainPanel; private JPanel PictureBox; @@ -44,6 +44,11 @@ public class FormMapWithSetWarships extends JFrame{ private Logger _logger; + public FormMapWithSetWarships(Logger logger){ + this(); + this._logger=logger;; + } + public FormMapWithSetWarships(){ InitializeComponent(); } @@ -74,10 +79,10 @@ public class FormMapWithSetWarships extends JFrame{ } private void InitializeComponent(){ - _logger = Logger.getLogger("FormMapWithSetTractorsGeneric"); + setContentPane(mainPanel); setTitle("Warship"); - setSize(935, 693); + setSize(554, 548); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setVisible(true); @@ -192,7 +197,7 @@ public class FormMapWithSetWarships extends JFrame{ if(ListBoxMaps.getSelectedIndex() == -1) return; bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet(); - _logger.log(Level.INFO,"Переход на карту: " + ListBoxMaps.getSelectedValue().toString()); + _logger.info("Переход на карту "+ListBoxMaps.getSelectedValue()); repaint(); }); diff --git a/src/Main.java b/src/Main.java index 17772ee..30cfb47 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,5 +1,7 @@ + +import org.apache.log4j.*; public class Main { public static void main(String[] args) { - new FormMapWithSetWarships(); + new FormMapWithSetWarships(LogManager.getLogger(Main.class)); } } diff --git a/src/MapWithSetWarshipsGeneric.java b/src/MapWithSetWarshipsGeneric.java index 61d7031..2e54a1e 100644 --- a/src/MapWithSetWarshipsGeneric.java +++ b/src/MapWithSetWarshipsGeneric.java @@ -116,14 +116,15 @@ public class MapWithSetWarshipsGeneric implements Iterable{ public int Insert(T warship, int position) { - if (position < 0 || position >= _maxCount) + if (position < 0 || position >= _maxCount || getCount() >= _maxCount) throw new StorageOverflowException(_maxCount); _places.add(position, warship); return position; diff --git a/src/log4j.xml b/src/log4j.xml index b7708ff..782b52b 100644 --- a/src/log4j.xml +++ b/src/log4j.xml @@ -1,19 +1,27 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + [%-5level] %msg (%d{dd.MM.yyyy})%n + + + + + + + + [%-5level] %msg (%d{dd.MM.yyyy})%n + + + + + + + + + + + + \ No newline at end of file -- 2.25.1 From 67cef9624749eb249adf4559d1545084b3154354 Mon Sep 17 00:00:00 2001 From: Ino Date: Fri, 16 Dec 2022 16:39:54 +0400 Subject: [PATCH 3/4] =?UTF-8?q?7=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=81=20=D1=80=D0=B0?= =?UTF-8?q?=D1=8E=D0=BE=D1=82=D0=B0=D1=8E=D1=89=D0=B8=D0=BC=20=D0=BB=D0=BE?= =?UTF-8?q?=D0=B3=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/AircraftCarrier_Hard.iml | 20 +---------- admin.log | 2 ++ src/FormMapWithSetWarships.java | 13 +++---- src/Main.java | 2 +- src/SetWarshipsGeneric.java | 3 +- log4j.properties => src/log4j.properties | 6 ++-- src/log4j.xml | 27 -------------- user.log | 45 ++++++++++++++++++++++++ 8 files changed, 59 insertions(+), 59 deletions(-) create mode 100644 admin.log rename log4j.properties => src/log4j.properties (82%) delete mode 100644 src/log4j.xml create mode 100644 user.log diff --git a/.idea/AircraftCarrier_Hard.iml b/.idea/AircraftCarrier_Hard.iml index 5c48835..a7557b1 100644 --- a/.idea/AircraftCarrier_Hard.iml +++ b/.idea/AircraftCarrier_Hard.iml @@ -7,24 +7,6 @@ - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/admin.log b/admin.log new file mode 100644 index 0000000..487acf3 --- /dev/null +++ b/admin.log @@ -0,0 +1,2 @@ +WARN FormMapWithSetWarships:267 - Ошибка переполнения хранилища: В наборе превышено допустимое количество: 8 16-12-2022 +WARN FormMapWithSetWarships:312 - Ошибка удаления: Не найден объект по позиции 7 16-12-2022 diff --git a/src/FormMapWithSetWarships.java b/src/FormMapWithSetWarships.java index 68f7a69..132dafd 100644 --- a/src/FormMapWithSetWarships.java +++ b/src/FormMapWithSetWarships.java @@ -7,6 +7,7 @@ import java.io.File; import java.util.HashMap; import java.util.function.Consumer; +import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Logger; public class FormMapWithSetWarships extends JFrame{ private JPanel mainPanel; @@ -44,11 +45,6 @@ public class FormMapWithSetWarships extends JFrame{ private Logger _logger; - public FormMapWithSetWarships(Logger logger){ - this(); - this._logger=logger;; - } - public FormMapWithSetWarships(){ InitializeComponent(); } @@ -79,6 +75,7 @@ public class FormMapWithSetWarships extends JFrame{ } private void InitializeComponent(){ + _logger = Logger.getLogger("FormMapWithSetWarships"); setContentPane(mainPanel); setTitle("Warship"); @@ -86,7 +83,7 @@ public class FormMapWithSetWarships extends JFrame{ setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setVisible(true); - _mapsCollection = new MapsCollection(getWidth(), getHeight()); + _mapsCollection = new MapsCollection(getWidth() - 300, getHeight()-300); СomboBoxSelectorMap.removeAllItems(); for(String elem:_mapsDict.keySet()){ СomboBoxSelectorMap.addItem(elem); @@ -101,8 +98,8 @@ public class FormMapWithSetWarships extends JFrame{ Icon iconRight = new ImageIcon("src\\Images\\ArrowRight.jpg"); ButtonRight.setIcon(iconRight); - File root = new File("D://2.1//RPP"); - + File root = new File("C://Цуканова//2.1//RPP"); + //D://2.1//RPP //сохранение saveToolStripMenuItem.addActionListener(e -> { JFileChooser fs = new JFileChooser(); diff --git a/src/Main.java b/src/Main.java index 30cfb47..39ac691 100644 --- a/src/Main.java +++ b/src/Main.java @@ -2,6 +2,6 @@ import org.apache.log4j.*; public class Main { public static void main(String[] args) { - new FormMapWithSetWarships(LogManager.getLogger(Main.class)); + new FormMapWithSetWarships(); } } diff --git a/src/SetWarshipsGeneric.java b/src/SetWarshipsGeneric.java index 7e40fa0..0b27bd3 100644 --- a/src/SetWarshipsGeneric.java +++ b/src/SetWarshipsGeneric.java @@ -31,8 +31,9 @@ public class SetWarshipsGeneric implements Iterable{ { if (position >= _maxCount || position < 0) return null; + + if(position >= getCount()) throw new WarshipNotFoundException(position); T deleted = _places.get(position); - if(deleted == null) throw new WarshipNotFoundException(position); _places.remove(position); return deleted; } diff --git a/log4j.properties b/src/log4j.properties similarity index 82% rename from log4j.properties rename to src/log4j.properties index 88a9ad0..1a541b2 100644 --- a/log4j.properties +++ b/src/log4j.properties @@ -1,7 +1,7 @@ -log4j.logger.FormMapWithSetWarshipGeneric=INFO, fileAppender, adminAppender +log4j.logger.FormMapWithSetWarships=INFO, fileAppender, adminAppender -log4j.additivity.FormMapWithSetWarshipGeneric=false -log4j.additivity.FormMapWithSetWarshipGenericAdmin=false +log4j.additivity.FormMapWithSetWarships=false +log4j.additivity.FormMapWithSetWarshipsAdmin=false log4j.appender.fileAppender.threshold=INFO log4j.appender.adminAppender.threshold=INFO diff --git a/src/log4j.xml b/src/log4j.xml deleted file mode 100644 index 782b52b..0000000 --- a/src/log4j.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - [%-5level] %msg (%d{dd.MM.yyyy})%n - - - - - - - - [%-5level] %msg (%d{dd.MM.yyyy})%n - - - - - - - - - - - - \ No newline at end of file diff --git a/user.log b/user.log new file mode 100644 index 0000000..aacaaf8 --- /dev/null +++ b/user.log @@ -0,0 +1,45 @@ +INFO FormMapWithSetWarships:198 - Переход на карту q 16-12-2022 +INFO FormMapWithSetWarships:231 - Добавлена карта: q 16-12-2022 +INFO FormMapWithSetWarships:197 - Переход на карту 1 16-12-2022 +INFO FormMapWithSetWarships:230 - Добавлена карта: 1 16-12-2022 +INFO FormMapWithSetWarships:256 - Добавлен объект: DrawingObjectWarship@3e80c31e 16-12-2022 +INFO FormMapWithSetWarships:256 - Добавлен объект: DrawingObjectWarship@45e72059 16-12-2022 +INFO FormMapWithSetWarships:256 - Добавлен объект: DrawingObjectWarship@66c19385 16-12-2022 +INFO FormMapWithSetWarships:256 - Добавлен объект: DrawingObjectWarship@b719186 16-12-2022 +INFO FormMapWithSetWarships:256 - Добавлен объект: DrawingObjectWarship@1e80be29 16-12-2022 +INFO FormMapWithSetWarships:256 - Добавлен объект: DrawingObjectWarship@18c57ba3 16-12-2022 +INFO FormMapWithSetWarships:256 - Добавлен объект: DrawingObjectWarship@189a8839 16-12-2022 +INFO FormMapWithSetWarships:256 - Добавлен объект: DrawingObjectWarship@2ee29701 16-12-2022 +INFO FormMapWithSetWarships:116 - Успешное сохранение в файл: C:\Цуканова\2.1\RPP\save.txt 16-12-2022 +INFO FormMapWithSetWarships:197 - Переход на карту 1 16-12-2022 +INFO FormMapWithSetWarships:139 - Успешная загрузка из файла: C:\Цуканова\2.1\RPP\save.txt 16-12-2022 +INFO FormMapWithSetWarships:299 - Удален объект: DrawingObjectWarship@7a6980df 16-12-2022 +INFO FormMapWithSetWarships:299 - Удален объект: DrawingObjectWarship@66bb9ebe 16-12-2022 +INFO FormMapWithSetWarships:307 - Не удалось удалить объект по позиции: 8 16-12-2022 +INFO FormMapWithSetWarships:197 - Переход на карту 1 16-12-2022 +INFO FormMapWithSetWarships:230 - Добавлена карта: 1 16-12-2022 +INFO FormMapWithSetWarships:197 - Переход на карту 1 16-12-2022 +INFO FormMapWithSetWarships:139 - Успешная загрузка из файла: C:\Цуканова\2.1\RPP\save.txt 16-12-2022 +INFO FormMapWithSetWarships:307 - Не удалось удалить объект по позиции: 8 16-12-2022 +INFO FormMapWithSetWarships:299 - Удален объект: DrawingObjectWarship@4b7ca985 16-12-2022 +INFO FormMapWithSetWarships:197 - Переход на карту 1 16-12-2022 +INFO FormMapWithSetWarships:139 - Успешная загрузка из файла: C:\Цуканова\2.1\RPP\save.txt 16-12-2022 +INFO FormMapWithSetWarships:295 - Удален объект: DrawingObjectWarship@4e4aa9fb 16-12-2022 +INFO FormMapWithSetWarships:295 - Удален объект: DrawingObjectWarship@6327b9c7 16-12-2022 +INFO FormMapWithSetWarships:197 - Переход на карту 1 16-12-2022 +INFO FormMapWithSetWarships:139 - Успешная загрузка из файла: C:\Цуканова\2.1\RPP\save.txt 16-12-2022 +INFO FormMapWithSetWarships:299 - Удален объект: DrawingObjectWarship@31c1257f 16-12-2022 +INFO FormMapWithSetWarships:299 - Удален объект: DrawingObjectWarship@4bb6e7e1 16-12-2022 +INFO FormMapWithSetWarships:197 - Переход на карту 1 16-12-2022 +INFO FormMapWithSetWarships:139 - Успешная загрузка из файла: C:\Цуканова\2.1\RPP\save.txt 16-12-2022 +INFO FormMapWithSetWarships:299 - Удален объект: DrawingObjectWarship@588d198d 16-12-2022 +INFO FormMapWithSetWarships:197 - Переход на карту 1 16-12-2022 +INFO FormMapWithSetWarships:139 - Успешная загрузка из файла: C:\Цуканова\2.1\RPP\save.txt 16-12-2022 +INFO FormMapWithSetWarships:299 - Удален объект: DrawingObjectWarship@570e663f 16-12-2022 +INFO FormMapWithSetWarships:307 - Не удалось удалить объект по позиции: 8 16-12-2022 +INFO FormMapWithSetWarships:197 - Переход на карту 1 16-12-2022 +INFO FormMapWithSetWarships:139 - Успешная загрузка из файла: C:\Цуканова\2.1\RPP\save.txt 16-12-2022 +INFO FormMapWithSetWarships:299 - Удален объект: DrawingObjectWarship@19004d94 16-12-2022 +INFO FormMapWithSetWarships:197 - Переход на карту 1 16-12-2022 +INFO FormMapWithSetWarships:139 - Успешная загрузка из файла: C:\Цуканова\2.1\RPP\save.txt 16-12-2022 +INFO FormMapWithSetWarships:299 - Удален объект: DrawingObjectWarship@82b8a3b 16-12-2022 -- 2.25.1 From 102ea87a72b52386fa00f127626c9aab271983c3 Mon Sep 17 00:00:00 2001 From: Inohara Date: Fri, 23 Dec 2022 10:30:05 +0400 Subject: [PATCH 4/4] =?UTF-8?q?7=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/AircraftCarrier_Hard.iml | 10 +++++++++- admin.log | 4 ++++ src/FormMapWithSetWarships.java | 4 ++-- user.log | 17 +++++++++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/.idea/AircraftCarrier_Hard.iml b/.idea/AircraftCarrier_Hard.iml index a7557b1..8c380ed 100644 --- a/.idea/AircraftCarrier_Hard.iml +++ b/.idea/AircraftCarrier_Hard.iml @@ -7,6 +7,14 @@ - + + + + + + + + + \ No newline at end of file diff --git a/admin.log b/admin.log index 487acf3..f14a307 100644 --- a/admin.log +++ b/admin.log @@ -1,2 +1,6 @@ WARN FormMapWithSetWarships:267 - Ошибка переполнения хранилища: В наборе превышено допустимое количество: 8 16-12-2022 WARN FormMapWithSetWarships:312 - Ошибка удаления: Не найден объект по позиции 7 16-12-2022 +WARN FormMapWithSetWarships:267 - Ошибка переполнения хранилища: В наборе превышено допустимое количество: 8 22-12-2022 +WARN FormMapWithSetWarships:312 - Ошибка удаления: Не найден объект по позиции 7 22-12-2022 +WARN FormMapWithSetWarships:267 - Ошибка переполнения хранилища: В наборе превышено допустимое количество: 8 23-12-2022 +WARN FormMapWithSetWarships:312 - Ошибка удаления: Не найден объект по позиции 7 23-12-2022 diff --git a/src/FormMapWithSetWarships.java b/src/FormMapWithSetWarships.java index 132dafd..b7c25d5 100644 --- a/src/FormMapWithSetWarships.java +++ b/src/FormMapWithSetWarships.java @@ -98,8 +98,8 @@ public class FormMapWithSetWarships extends JFrame{ Icon iconRight = new ImageIcon("src\\Images\\ArrowRight.jpg"); ButtonRight.setIcon(iconRight); - File root = new File("C://Цуканова//2.1//RPP"); - //D://2.1//RPP + File root = new File("//D://2.1//RPP"); + //сохранение saveToolStripMenuItem.addActionListener(e -> { JFileChooser fs = new JFileChooser(); diff --git a/user.log b/user.log index aacaaf8..2d5711c 100644 --- a/user.log +++ b/user.log @@ -43,3 +43,20 @@ INFO FormMapWithSetWarships:299 - Удален объект: DrawingObjectWarsh INFO FormMapWithSetWarships:197 - Переход на карту 1 16-12-2022 INFO FormMapWithSetWarships:139 - Успешная загрузка из файла: C:\Цуканова\2.1\RPP\save.txt 16-12-2022 INFO FormMapWithSetWarships:299 - Удален объект: DrawingObjectWarship@82b8a3b 16-12-2022 +INFO FormMapWithSetWarships:197 - Переход на карту 1 22-12-2022 +INFO FormMapWithSetWarships:230 - Добавлена карта: 1 22-12-2022 +INFO FormMapWithSetWarships:256 - Добавлен объект: DrawingObjectWarship@67e5c95e 22-12-2022 +INFO FormMapWithSetWarships:256 - Добавлен объект: DrawingObjectWarship@53b0b97e 22-12-2022 +INFO FormMapWithSetWarships:256 - Добавлен объект: DrawingObjectWarship@60de88b1 22-12-2022 +INFO FormMapWithSetWarships:256 - Добавлен объект: DrawingObjectWarship@2d7d7e83 22-12-2022 +INFO FormMapWithSetWarships:256 - Добавлен объект: DrawingObjectWarship@70dc116d 22-12-2022 +INFO FormMapWithSetWarships:256 - Добавлен объект: DrawingObjectWarship@2fac792d 22-12-2022 +INFO FormMapWithSetWarships:256 - Добавлен объект: DrawingObjectWarship@3ad217e 22-12-2022 +INFO FormMapWithSetWarships:256 - Добавлен объект: DrawingObjectWarship@3021da19 22-12-2022 +INFO FormMapWithSetWarships:116 - Успешное сохранение в файл: D:\2.1\RPP\save.txt 22-12-2022 +INFO FormMapWithSetWarships:197 - Переход на карту 1 22-12-2022 +INFO FormMapWithSetWarships:139 - Успешная загрузка из файла: D:\2.1\RPP\save.txt 22-12-2022 +INFO FormMapWithSetWarships:299 - Удален объект: DrawingObjectWarship@2bf32df0 22-12-2022 +INFO FormMapWithSetWarships:197 - Переход на карту 1 23-12-2022 +INFO FormMapWithSetWarships:139 - Успешная загрузка из файла: D:\2.1\RPP\save.txt 23-12-2022 +INFO FormMapWithSetWarships:299 - Удален объект: DrawingObjectWarship@1651d65b 23-12-2022 -- 2.25.1