use of mudmap2.backend.WorldFileReader.current.WorldFileJSON in project mudmap2 by Neop.
the class WorldTab method save.
/**
* Saves the changes in the world
*/
public void save() {
if (!worldPanel.isPassive()) {
WorldFile worldFile = getWorld().getWorldFile();
if (worldFile == null) {
if (filename == null || filename.isEmpty() || (new File(filename)).exists()) {
// get new filename
int ret;
do {
JFileChooser fileChooser = new JFileChooser(Environment.getWorldsDir());
ret = fileChooser.showSaveDialog(this);
if (ret == JFileChooser.APPROVE_OPTION) {
filename = fileChooser.getSelectedFile().getAbsolutePath();
} else {
ret = JOptionPane.showConfirmDialog(this, "No file chosen: " + getWorld().getName() + " will not be saved!", "Saving world", JOptionPane.OK_CANCEL_OPTION);
if (ret == JOptionPane.OK_OPTION)
return;
}
} while (ret != JFileChooser.APPROVE_OPTION || ret != JOptionPane.OK_OPTION);
}
worldFile = new WorldFileDefault(filename);
getWorld().setWorldFile(worldFile);
}
// set meta data writer
if (worldFile.getWorldFileType() == WorldFileType.JSON) {
WorldFileJSON wfj = null;
if (worldFile instanceof WorldFileJSON) {
wfj = (WorldFileJSON) worldFile;
} else if (worldFile instanceof WorldFileDefault) {
wfj = (WorldFileJSON) ((WorldFileDefault) worldFile).getWorldFile();
}
if (wfj != null)
wfj.setMetaGetter(this);
}
// write world file
try {
worldFile.writeFile(getWorld());
WorldManager.putWorld(worldFile.getFilename(), getWorld());
} catch (IOException ex) {
Logger.getLogger(WorldTab.class.getName()).log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(getParent(), "Could not save world file " + worldFile.getFilename(), "Saving world file", JOptionPane.ERROR_MESSAGE);
}
}
showMessage("World saved");
}
use of mudmap2.backend.WorldFileReader.current.WorldFileJSON in project mudmap2 by Neop.
the class WorldFileDefaultTest method testReadWorldName.
/**
* Test of readWorldName method, of class WorldFileDefault.
*/
@Test
public void testReadWorldName() throws Exception {
System.out.println("readWorldName");
String worldName = "foobar";
World world = new World(worldName);
String wfjFile = folder.getRoot() + "/wfj";
String wfmm1File = folder.getRoot() + "/wfmm1";
try {
WorldFileJSON wfj = new WorldFileJSON(wfjFile);
wfj.writeFile(world);
WorldFileJSON wfmm1 = new WorldFileJSON(wfmm1File);
wfmm1.writeFile(world);
} catch (IOException ex) {
Logger.getLogger(WorldFileJSONTest.class.getName()).log(Level.SEVERE, null, ex);
fail("Could not create files for test");
}
try {
WorldFileDefault instance1 = new WorldFileDefault(wfjFile);
String result1 = instance1.readWorldName();
assertEquals(worldName, result1);
WorldFileDefault instance2 = new WorldFileDefault(wfmm1File);
String result2 = instance2.readWorldName();
assertEquals(worldName, result2);
} catch (Exception ex) {
Logger.getLogger(WorldFileJSONTest.class.getName()).log(Level.SEVERE, null, ex);
fail();
}
}
use of mudmap2.backend.WorldFileReader.current.WorldFileJSON in project mudmap2 by Neop.
the class WorldFileJSONTest method testCanRead.
/**
* Test of canRead method, of class WorldFileJSON.
*/
@Test
public void testCanRead() {
System.out.println("canRead");
World world = new World("foobar");
String wfjFile = folder.getRoot() + "/wfj";
try {
WorldFileJSON wfj = new WorldFileJSON(wfjFile);
wfj.writeFile(world);
} catch (IOException ex) {
Logger.getLogger(WorldFileJSONTest.class.getName()).log(Level.SEVERE, null, ex);
fail("Could not create files for test");
}
WorldFileJSON instancewfj = new WorldFileJSON(wfjFile);
Boolean result = instancewfj.canRead();
assertTrue(result);
}
use of mudmap2.backend.WorldFileReader.current.WorldFileJSON in project mudmap2 by Neop.
the class WorldFileJSONTest method testBackup.
/**
* Test of backup method, of class WorldFileJSON.
* @throws java.io.IOException
*/
@Test
public void testBackup() throws IOException {
System.out.println("backup");
try {
String wfjFile = folder.getRoot() + "/wfj";
WorldFileJSON instance = new WorldFileJSON(wfjFile);
// don't write world
// instance.writeFile(new World("Foo Bar"));
instance.backup();
File f1 = new File(wfjFile);
File f2 = new File(wfjFile + ".bak");
assertTrue(FileUtils.contentEquals(f1, f2));
} catch (FileNotFoundException ex) {
Logger.getLogger(WorldFileJSONTest.class.getName()).log(Level.SEVERE, null, ex);
fail();
}
try {
String wfjFile = folder.getRoot() + "/wfj";
WorldFileJSON instance = new WorldFileJSON(wfjFile);
// write world
instance.writeFile(new World("Foo Bar"));
instance.backup();
File f1 = new File(wfjFile);
File f2 = new File(wfjFile + ".bak");
assertTrue(FileUtils.contentEquals(f1, f2));
} catch (FileNotFoundException ex) {
Logger.getLogger(WorldFileJSONTest.class.getName()).log(Level.SEVERE, null, ex);
fail();
}
}
use of mudmap2.backend.WorldFileReader.current.WorldFileJSON in project mudmap2 by Neop.
the class WorldFileJSONTest method testGetWorldFileType.
/**
* Test of getWorldFileType method, of class WorldFileJSON.
*/
@Test
public void testGetWorldFileType() {
System.out.println("getWorldFileType");
WorldFileJSON instance = new WorldFileJSON(null);
WorldFileType result = instance.getWorldFileType();
assertEquals(WorldFileType.JSON, result);
}
Aggregations