Сдано
This commit is contained in:
parent
baf8f83855
commit
4a7d61a167
@ -69,38 +69,7 @@ public class FormMonorailCollection {
|
||||
listBoxStorages.setSelectedIndex(index);
|
||||
}
|
||||
|
||||
public boolean LoadCollection(File f) throws FileNotFoundException {
|
||||
if(!f.exists())
|
||||
return false;
|
||||
StringBuilder bufferTextFromFile =new StringBuilder();
|
||||
Scanner s = new Scanner(f);
|
||||
while(s.hasNext())
|
||||
bufferTextFromFile.append(s.next() + "\n");
|
||||
s.close();
|
||||
var strs = bufferTextFromFile.toString().split("\n");
|
||||
if(strs == null || strs.length == 0)
|
||||
return false;
|
||||
if (!strs[0].startsWith("MonorailCollection"))
|
||||
return false;
|
||||
String collectionName = strs[1];
|
||||
MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail> collection = new MonorailGenericCollection<>(pictureBoxWidth, pictureBoxHeight);
|
||||
String[] monorailsInfo = strs[2].split(Character.toString(MonorailGenericCollection._separatorRecords));
|
||||
for(int i = monorailsInfo.length-1; i >= 0; i--){
|
||||
String data = monorailsInfo[i];
|
||||
DrawningMonorail monorail = ExtentionDrawningMonorail.CreateDrawningMonorail(data,
|
||||
MonorailGenericCollection._separatorForObject, pictureBoxWidth, pictureBoxHeight);
|
||||
if (monorail != null)
|
||||
{
|
||||
if (!(collection.Insert(monorail)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
_storage.AddSetFromFile(collectionName, collection);
|
||||
ReloadObjects();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public FormMonorailCollection(){
|
||||
JMenuBar menuFile = new JMenuBar();
|
||||
@ -224,8 +193,7 @@ public class FormMonorailCollection {
|
||||
if(ret == JFileChooser.APPROVE_OPTION){
|
||||
File file = fc.getSelectedFile();
|
||||
try {
|
||||
LoadCollection(file);
|
||||
canv._storage =_storage;
|
||||
_storage.LoadCollection(file);
|
||||
ReloadObjects();
|
||||
canv.repaint();
|
||||
} catch (IOException ex) {
|
||||
|
@ -25,7 +25,7 @@ public class MonorailGenericCollection<T extends DrawningMonorail, U extends IMo
|
||||
|
||||
private final int _placeSizeHeight = 50;
|
||||
|
||||
private final SetGeneric<T> _collection;
|
||||
private SetGeneric<T> _collection;
|
||||
public ArrayList<T> GetMonorails(){
|
||||
return _collection.GetMonorails(_collection.Count);
|
||||
}
|
||||
@ -126,4 +126,8 @@ public class MonorailGenericCollection<T extends DrawningMonorail, U extends IMo
|
||||
DrawObjects(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
public void Clear(){
|
||||
_collection = new SetGeneric<>(_pictureWidth * _pictureHeight);
|
||||
}
|
||||
}
|
||||
|
@ -78,6 +78,42 @@ public class MonorailGenericStorage {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean LoadCollection(File f) throws FileNotFoundException {
|
||||
if(!f.exists())
|
||||
return false;
|
||||
StringBuilder bufferTextFromFile =new StringBuilder();
|
||||
Scanner s = new Scanner(f);
|
||||
while(s.hasNext())
|
||||
bufferTextFromFile.append(s.next() + "\n");
|
||||
s.close();
|
||||
var strs = bufferTextFromFile.toString().split("\n");
|
||||
if(strs == null || strs.length == 0)
|
||||
return false;
|
||||
if (!strs[0].startsWith("MonorailCollection"))
|
||||
return false;
|
||||
String collectionName = strs[1];
|
||||
MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail> collection = GetCollection(collectionName);
|
||||
if(collection == null)
|
||||
collection = new MonorailGenericCollection<>(_pictureWidth, _pictureHeight);
|
||||
else
|
||||
collection.Clear();
|
||||
String[] monorailsInfo = strs[2].split(Character.toString(MonorailGenericCollection._separatorRecords));
|
||||
for(int i = monorailsInfo.length-1; i >= 0; i--){
|
||||
String data = monorailsInfo[i];
|
||||
DrawningMonorail monorail = ExtentionDrawningMonorail.CreateDrawningMonorail(data,
|
||||
MonorailGenericCollection._separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (monorail != null)
|
||||
{
|
||||
if (!(collection.Insert(monorail)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
AddSetFromFile(collectionName, collection);
|
||||
return true;
|
||||
}
|
||||
public List<String> Keys(){
|
||||
if(_monorailStorages == null)
|
||||
return null;
|
||||
@ -124,4 +160,8 @@ public class MonorailGenericStorage {
|
||||
public DrawningMonorail Get(String collectionName, int position){
|
||||
return _monorailStorages.get(collectionName).Get(position);
|
||||
}
|
||||
|
||||
public MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail> GetCollection(String collectionName){
|
||||
return _monorailStorages.get(collectionName);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user