LabWork7::hard_part::1 и 2 пункт усложненки.
This commit is contained in:
@@ -7,5 +7,14 @@
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/Downloads/apache-log4j-1.2.17/log4j-1.2.17.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
</component>
|
||||
</module>
|
||||
@@ -9,6 +9,9 @@ import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.log4j.*;
|
||||
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
@@ -27,7 +30,6 @@ public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
private JTextField maskedTextBoxPosition;
|
||||
private JTextField textBoxNewMapName;
|
||||
private final int picWidth=600;
|
||||
|
||||
private final int picHeight=400;
|
||||
private JButton ButtonAddMap;
|
||||
private JList ListBoxMaps;
|
||||
@@ -41,6 +43,7 @@ public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
private JMenu MenuMap;
|
||||
private JMenuItem SaveToolStripMap;
|
||||
private JMenuItem LoadToolStripMap;
|
||||
private static Logger _logger;
|
||||
private MapWithSetShipsGeneric<DrawingObjectShip,AbstractMap> _mapShipsCollectionGeneric;
|
||||
private final HashMap<String,AbstractMap> _mapsDict = new HashMap<>(){{
|
||||
put("Простая карта",new SimpleMap());
|
||||
@@ -76,6 +79,7 @@ public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
}
|
||||
public FormMapWithSetShipsGeneric()
|
||||
{
|
||||
_logger = Logger.getLogger(FormMapWithSetShipsGeneric.class.getName());
|
||||
_mapsCollection = new MapsCollection(picWidth, picHeight);
|
||||
ComboBoxSelectorMap.removeAllItems();
|
||||
for (String elem : _mapsDict.keySet()) {
|
||||
@@ -108,14 +112,20 @@ public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
DrawingObjectShip ship = new DrawingObjectShip(newShip);
|
||||
if (_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).Add(ship) != -1) {
|
||||
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
||||
_logger.log(Level.INFO,"Добавлен объект: "+ship);
|
||||
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "Не удалось добавить объект","Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||
_logger.log(Level.INFO,"Не удалось добавить объект:"+ship);
|
||||
}
|
||||
}
|
||||
}catch (StorageOverflowException ex)
|
||||
{
|
||||
_logger.log(Level.WARN,"Ошибка переполнения хранилища: "+ex.getMessage());
|
||||
JOptionPane.showMessageDialog(null, "Ошибка переполнения хранилища: "+ex.getMessage(),"Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(null, "Неизвестная ошибка: "+ex.getMessage(),"Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||
_logger.log(Level.FATAL,"Неизвестная ошибка: "+ex.getMessage());
|
||||
}
|
||||
});
|
||||
formShipConfig.setSize(850, 300);
|
||||
@@ -128,6 +138,7 @@ public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
if (ListBoxMaps.getSelectedIndex() == -1)
|
||||
return;
|
||||
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
|
||||
_logger.log(Level.INFO, "Переход на карту: "+ListBoxMaps.getSelectedValue().toString());
|
||||
}
|
||||
});
|
||||
ButtonDeleteShip.addActionListener(new ActionListener() {
|
||||
@@ -149,16 +160,20 @@ public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
if(delShip!=null)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Объект удален");
|
||||
_logger.log(Level.INFO,"Объект удален"+delShip);
|
||||
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не удалось удалить объект","Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||
_logger.log(Level.INFO,"Не удалось удалить объект"+delShip);
|
||||
}
|
||||
} catch (ShipNotFoundException ex) {
|
||||
JOptionPane.showMessageDialog(null, "Ошибка удаления: "+ex.getMessage(),"Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||
_logger.log(Level.WARN,"Ошибка удаления: "+ex.getMessage());
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(null, "Неизвестная ошибка: "+ex.getMessage(),"Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||
_logger.log(Level.FATAL,"Неизвестная ошибка: "+ex.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -266,13 +281,16 @@ public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
if (ComboBoxSelectorMap.getSelectedIndex() == -1 || textBoxNewMapName.getText().isEmpty())
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,"Не все данные заполнены","Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||
_logger.log(Level.ERROR,"Не все данные заполнены");
|
||||
return;
|
||||
}
|
||||
if(!_mapsDict.containsKey(ComboBoxSelectorMap.getSelectedItem()))
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,"Нет такой карты","Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||
_logger.log(Level.ERROR,"Нет такой карты");
|
||||
}
|
||||
_mapsCollection.AddMap(textBoxNewMapName.getText(),_mapsDict.get(ComboBoxSelectorMap.getSelectedItem().toString()));
|
||||
_logger.log(Level.INFO,"Добавлена карта: "+textBoxNewMapName.getText());
|
||||
ReloadMaps();
|
||||
}
|
||||
});
|
||||
@@ -286,6 +304,7 @@ public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
if(JOptionPane.showConfirmDialog(null,"Удалить карту"+ListBoxMaps.getSelectedValue().toString()+"?","Удаление",JOptionPane.YES_NO_OPTION)==0)
|
||||
{
|
||||
_mapsCollection.DelMap(ListBoxMaps.getSelectedValue().toString());
|
||||
_logger.log(Level.INFO, "Удалена карта: "+ListBoxMaps.getSelectedValue().toString());
|
||||
ReloadMaps();
|
||||
}
|
||||
}
|
||||
@@ -319,8 +338,10 @@ public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
File selectedFile=fc.getSelectedFile();
|
||||
_mapsCollection.SaveData(selectedFile.getPath());
|
||||
JOptionPane.showMessageDialog(null, "Сохранение прошло успешно", "Результат",JOptionPane.INFORMATION_MESSAGE);
|
||||
_logger.log(Level.INFO,"Сохранение прошло успешно");
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(null, "Не сохранилось: "+ex.getMessage(), "Результат",JOptionPane.ERROR_MESSAGE);
|
||||
_logger.log(Level.ERROR,"Не сохранилось: "+ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -337,8 +358,10 @@ public class FormMapWithSetShipsGeneric extends JFrame{
|
||||
_mapsCollection.LoadData(selectedFile.getPath());
|
||||
ReloadMaps();
|
||||
JOptionPane.showMessageDialog(null, "Загрузка прошла успешно", "Результат",JOptionPane.INFORMATION_MESSAGE);
|
||||
_logger.log(Level.INFO,"Загрузка прошло успешно");
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(null, "Не загрузилось: "+ex.getMessage(), "Результат",JOptionPane.ERROR_MESSAGE);
|
||||
_logger.log(Level.ERROR,"Не загрузилось: "+ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
12
src/log4j.properties
Normal file
12
src/log4j.properties
Normal file
@@ -0,0 +1,12 @@
|
||||
# Root logger option
|
||||
log4j.rootLogger=INFO, file
|
||||
|
||||
# Direct log messages to a log file
|
||||
log4j.appender.file=org.apache.log4j.RollingFileAppender
|
||||
|
||||
#Redirect to logs folder
|
||||
log4j.appender.file.File=log.txt
|
||||
log4j.appender.file.MaxFileSize=10MB
|
||||
log4j.appender.file.MaxBackupIndex=10
|
||||
log4j.appender.file.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
|
||||
Reference in New Issue
Block a user