Перенесена база лаб6
This commit is contained in:
parent
1d30c011aa
commit
9f39107385
@ -1,4 +1,5 @@
|
||||
import java.awt.*;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawningLocomotive {
|
||||
@ -177,9 +178,9 @@ public class DrawningLocomotive {
|
||||
IDrawningExtra drawningExtra = null;
|
||||
EntityLocomotive Locomotive = null;
|
||||
String[] strs = info.split(Character.toString(_separatorForObject));
|
||||
if (strs[5] == "Simple") drawningExtra = new ExtraWheelsDraw(Integer.parseInt(strs[6]), Locomotive.getBodyColor());
|
||||
if (strs[5] == "Star") drawningExtra = new ExtraStarWheelDraw(Integer.parseInt(strs[6]), Locomotive.getBodyColor());
|
||||
if (strs[5] == "Round") drawningExtra = new ExtraRoundWheelDraw(Integer.parseInt(strs[6]), Locomotive.getBodyColor());
|
||||
if (strs[5].equals("Simple")) drawningExtra = new ExtraWheelsDraw(Integer.parseInt(strs[6]), new Color(Integer.parseInt(strs[2]), Integer.parseInt(strs[3]), Integer.parseInt(strs[4])));
|
||||
if (strs[5].equals("Star")) drawningExtra = new ExtraStarWheelDraw(Integer.parseInt(strs[6]), new Color(Integer.parseInt(strs[2]), Integer.parseInt(strs[3]), Integer.parseInt(strs[4])));
|
||||
if (Objects.equals(strs[5], "Round")) drawningExtra = new ExtraRoundWheelDraw(Integer.parseInt(strs[6]), new Color(Integer.parseInt(strs[2]), Integer.parseInt(strs[3]), Integer.parseInt(strs[4])));
|
||||
if (drawningExtra == null) return null;
|
||||
if (strs.length == 7)
|
||||
{
|
||||
|
@ -6,11 +6,11 @@ public class ExtraRoundWheelDraw implements IDrawningExtra{
|
||||
private Color color;
|
||||
public void setExtraNum(int num) {
|
||||
switch (num) {
|
||||
case 0: {
|
||||
case 3: {
|
||||
wheelsCount = WheelsCount.Three;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
case 4: {
|
||||
wheelsCount = WheelsCount.Four;
|
||||
break;
|
||||
}
|
||||
|
@ -6,11 +6,11 @@ public class ExtraStarWheelDraw implements IDrawningExtra{
|
||||
private Color color;
|
||||
public void setExtraNum(int num) {
|
||||
switch (num) {
|
||||
case 0: {
|
||||
case 3: {
|
||||
wheelsCount = WheelsCount.Three;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
case 4: {
|
||||
wheelsCount = WheelsCount.Four;
|
||||
break;
|
||||
}
|
||||
|
@ -108,7 +108,6 @@ public class FormLocomotive extends JComponent{
|
||||
super.repaint();
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
|
||||
new FormMapWithSetLocomotives();
|
||||
}
|
||||
}
|
||||
|
@ -263,7 +263,35 @@ public class FormMapWithSetLocomotives extends JComponent {
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
});
|
||||
statusPanel.add(showDeletedButton);
|
||||
|
||||
JFileChooser fileChooser = new JFileChooser();
|
||||
JButton saveButton = new JButton("Save");
|
||||
saveButton.addActionListener(e -> {
|
||||
fileChooser.setDialogTitle("Saving");
|
||||
int result = fileChooser.showSaveDialog(FormMapWithSetLocomotives.this);
|
||||
if (result == JFileChooser.APPROVE_OPTION ) {
|
||||
if (_mapsCollection.SaveData(fileChooser.getSelectedFile().getAbsolutePath())) {
|
||||
JOptionPane.showMessageDialog(null, "Save success");
|
||||
}
|
||||
else JOptionPane.showMessageDialog(null, "Save failed");
|
||||
}
|
||||
|
||||
});
|
||||
statusPanel.add(saveButton);
|
||||
JButton loadButton = new JButton("Load");
|
||||
loadButton.addActionListener(e -> {
|
||||
fileChooser.setDialogTitle("Loading");
|
||||
int result = fileChooser.showSaveDialog(FormMapWithSetLocomotives.this);
|
||||
if (result == JFileChooser.APPROVE_OPTION ) {
|
||||
if (_mapsCollection.LoadData(fileChooser.getSelectedFile().getAbsolutePath())) {
|
||||
JOptionPane.showMessageDialog(null, "Load success");
|
||||
}
|
||||
else JOptionPane.showMessageDialog(null, "Load failed");
|
||||
}
|
||||
ReloadMaps();
|
||||
repaint();
|
||||
});
|
||||
statusPanel.add(loadButton);
|
||||
|
||||
formFrame.getContentPane().add(this);
|
||||
formFrame.setVisible(true);
|
||||
|
@ -180,7 +180,6 @@ public class MapWithSetLocomotivesGeneric
|
||||
/// Получение данных в виде строки
|
||||
public String GetData(char separatorType, char separatorData)
|
||||
{
|
||||
//string data = $"{_map.GetType().Name}{separatorType}";
|
||||
String data = ""+ _map.getClass() + separatorType;
|
||||
for (var locomotive : _setLocomotives.GetLocomotives())
|
||||
{
|
||||
|
@ -15,7 +15,7 @@ public class MapsCollection {
|
||||
/// Высота окна отрисовки
|
||||
private final int _pictureHeight;
|
||||
// Сепараторы
|
||||
private final char separatorDict = '|';
|
||||
private final String separatorDict = "\\|";
|
||||
private final char separatorData = ';';
|
||||
/// Конструктор
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
@ -60,7 +60,7 @@ public class MapsCollection {
|
||||
try(BufferedWriter bw = new BufferedWriter(new FileWriter(filename))) {
|
||||
bw.write("MapsCollection\n");
|
||||
for (var storage : _mapStorages.entrySet()) {
|
||||
bw.write("" + storage.getKey() + separatorDict + storage.getValue().GetData(separatorDict, separatorData) + "\n");
|
||||
bw.write("" + storage.getKey() + separatorDict + storage.getValue().GetData(separatorDict.charAt(0), separatorData) + "\n");
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
@ -86,18 +86,18 @@ public class MapsCollection {
|
||||
|
||||
_mapStorages.clear();
|
||||
while ((curLine = br.readLine()) != null) {
|
||||
var elems = curLine.split(Character.toString(separatorDict));
|
||||
var elems = curLine.split(separatorDict);
|
||||
AbstractMap map = null;
|
||||
|
||||
switch (elems[1])
|
||||
{ //TODO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
case "SimpleMap":
|
||||
case "class SimpleMap":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "SpikeMap":
|
||||
case "class SpikeMap":
|
||||
map = new SpikeMap();
|
||||
break;
|
||||
case "RailMap":
|
||||
case "class RailMap":
|
||||
map = new RailMap();
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user