Готовая лаба hard 6
This commit is contained in:
parent
585712ebf9
commit
354f9a97d0
@ -17,11 +17,11 @@ public class ExtensionDrawingPlane {
|
||||
),
|
||||
width, height
|
||||
);
|
||||
if (strs[5] == "DrawingEnginesSimple") {
|
||||
if (Objects.equals(strs[5], "DrawingEnginesSimple")) {
|
||||
drawingPlane._drawingEngines = new DrawingEnginesSimple();
|
||||
} else if (strs[5] == "DrawingEnginesPyramid") {
|
||||
} else if (Objects.equals(strs[5], "DrawingEnginesPyramid")) {
|
||||
drawingPlane._drawingEngines = new DrawingEnginesPyramid();
|
||||
} else if (strs[5] == "DrawingEnginesEllipse") {
|
||||
} else if (Objects.equals(strs[5], "DrawingEnginesEllipse")) {
|
||||
drawingPlane._drawingEngines = new DrawingEnginesEllipse();
|
||||
}
|
||||
drawingPlane.SetEnginesCount(Integer.parseInt(strs[6]));
|
||||
@ -70,8 +70,8 @@ public class ExtensionDrawingPlane {
|
||||
plane.BodyColor.getRed() + separatorForObject +
|
||||
plane.BodyColor.getGreen() + separatorForObject +
|
||||
plane.BodyColor.getBlue() + separatorForObject +
|
||||
drawingPlane._drawingEngines.getClass() + separatorForObject +
|
||||
drawingPlane._drawingEngines.GetEnumEnginesCount().count;
|
||||
(drawingPlane._drawingEngines.GetEnumEnginesCount() == null ? "null" : drawingPlane._drawingEngines.getClass()) + separatorForObject +
|
||||
(drawingPlane._drawingEngines.GetEnumEnginesCount() == null ? "0" : drawingPlane._drawingEngines.GetEnumEnginesCount().count);
|
||||
if (!(plane instanceof EntityStormtrooper stormtrooper)) {
|
||||
return str;
|
||||
}
|
||||
|
@ -85,8 +85,46 @@ public class FormPlaneCollection {
|
||||
}
|
||||
}
|
||||
);
|
||||
JMenuItem openItemSingle = new JMenuItem("Загрузить коллекцию");
|
||||
openItemSingle.addActionListener(
|
||||
e -> {
|
||||
JFileChooser fileChooser = new JFileChooser();
|
||||
fileChooser.setFileFilter(new FileNameExtensionFilter("Текстовые файлы (*.txt)", "txt"));
|
||||
fileChooser.setDialogTitle("Выберите файл для загрузки данных");
|
||||
if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
File selectedFile = fileChooser.getSelectedFile();
|
||||
if (_storage.LoadDataSingle(selectedFile.getAbsolutePath())) {
|
||||
JOptionPane.showMessageDialog(null, "Загрузка прошла успешно", "Результат", JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "Не загрузилось", "Результат", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
ReloadObjects();
|
||||
}
|
||||
);
|
||||
JMenuItem saveItemSingle = new JMenuItem("Сохранить коллекцию");
|
||||
saveItemSingle.addActionListener(
|
||||
e -> {
|
||||
if (listBoxStorages.getSelectedValue() == null) {
|
||||
JOptionPane.showMessageDialog(null, "Коллекция не выбрана", "Ошибка", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
JFileChooser fileChooser = new JFileChooser();
|
||||
fileChooser.setFileFilter(new FileNameExtensionFilter("Текстовые файлы (*.txt)", "txt"));
|
||||
fileChooser.setDialogTitle("Выберите файл для сохранения данных");
|
||||
if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
File selectedFile = fileChooser.getSelectedFile();
|
||||
if (_storage.SaveDataSingle(selectedFile.getAbsolutePath(), (String) listBoxStorages.getSelectedValue()))
|
||||
JOptionPane.showMessageDialog(null, "Сохранение прошло успешно", "Результат", JOptionPane.INFORMATION_MESSAGE);
|
||||
else
|
||||
JOptionPane.showMessageDialog(null, "Не сохранилось", "Результат", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
);
|
||||
fileMenu.add(openItem);
|
||||
fileMenu.add(saveItem);
|
||||
fileMenu.add(openItemSingle);
|
||||
fileMenu.add(saveItemSingle);
|
||||
menuBar.add(fileMenu);
|
||||
return menuBar;
|
||||
}
|
||||
|
@ -11,9 +11,7 @@ import java.io.IOException;
|
||||
public class PlanesGenericStorage {
|
||||
final HashMap<String, PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>> _planeStorages;
|
||||
private static final String _separatorForKeyValue = "@";
|
||||
private static final String _separatorForKeyValueSingle = "@@";
|
||||
private static final String _separatorRecords = ";";
|
||||
private static final String _separatorRecordsSingle = ";;";
|
||||
private static final String _separatorForObject = ":";
|
||||
private static final String _separatorForObjectSingle = "::";
|
||||
private static final String _keyword = "PlanesStorage";
|
||||
@ -103,19 +101,17 @@ public class PlanesGenericStorage {
|
||||
for (String elem : plainsStrings) {
|
||||
DrawingPlane plane = ExtensionDrawingPlane.CreateDrawingPlane(
|
||||
elem,
|
||||
_separatorForObject,
|
||||
_separatorForObjectSingle,
|
||||
_pictureWidth,
|
||||
_pictureHeight
|
||||
);
|
||||
if (plane == null || collection.Add(plane) == -1)
|
||||
return false;
|
||||
}
|
||||
|
||||
_planeStorages.put(key, collection);
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user