Added functionality to check whether changed data is saved when exiting the program

This commit is contained in:
2026-04-10 12:04:01 +03:00
parent 54dbfbabf4
commit fd488d8c9e
3 changed files with 36 additions and 8 deletions

View File

@ -52,7 +52,10 @@ public class Project implements Iterable<Entity>, EntityDrawboxChangedListener,
* */
public static final String DEFAULT_XML_PATH = "res/"; //TODO: make an actual path to example objecttypes in the root of the project
public static final String DEFAULT_XML_FILENAME = "objecttypes.xml";
/**
* Переменная которая отслеживает, были ли произведены изменения XML-Dom-дерева.
* */
public static boolean changeOfXmlDOM = false;
static Project thisProject;
private List <Entity> listEntity = new ArrayList<Entity>();
private String path = DEFAULT_XML_PATH;
@ -249,6 +252,7 @@ public class Project implements Iterable<Entity>, EntityDrawboxChangedListener,
hitboxProperty.setAttribute("default", "Rectangle 0 0 0 0"); // empty, no hitbox yet
objecttypeElement.appendChild(hitboxProperty);
changeOfXmlDOM = true;
//printXMlToConsole(); //DEBUG!
}
@ -298,10 +302,11 @@ public class Project implements Iterable<Entity>, EntityDrawboxChangedListener,
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(new FileOutputStream(getXMLPath() + getXMLFileName()));
transformer.transform(source, result);
JOptionPane.showMessageDialog(null, "Бугага, сохранилось!", "Success", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, "Бугагашеньки, сохранилось!", "Success", JOptionPane.INFORMATION_MESSAGE);
} catch (TransformerException | FileNotFoundException e) {
JOptionPane.showMessageDialog(null, "Saving project is unsuccsessfull! Erorr is: "+e, "Project save unsuccsesfull", JOptionPane.ERROR_MESSAGE);
}
changeOfXmlDOM = false;
}
public void PrintEntitys() {
@ -361,6 +366,7 @@ public class Project implements Iterable<Entity>, EntityDrawboxChangedListener,
}
}
}
changeOfXmlDOM = true;
}
/**
@ -381,6 +387,7 @@ public class Project implements Iterable<Entity>, EntityDrawboxChangedListener,
}
}
}
changeOfXmlDOM = true;
}
private Node getEntityXMLNodeByName(String name) { //returns entitie's objecttype node