|
@@ -53,6 +53,7 @@ public class Control {
|
|
|
private final HolonCanvasController holonCanvasController;
|
|
|
private String autosaveDir = "";
|
|
|
private String categoryDir = "";
|
|
|
+ private int rand;
|
|
|
|
|
|
/**
|
|
|
* Constructor.
|
|
@@ -87,6 +88,7 @@ public class Control {
|
|
|
// deleteDirectory(dest);
|
|
|
autoSave.mkdirs();
|
|
|
category.mkdirs();
|
|
|
+ createAutoRandom();
|
|
|
try {
|
|
|
autoSave();
|
|
|
} catch (IOException e) {
|
|
@@ -95,6 +97,17 @@ public class Control {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Generate random number, so that every instance of the program has unique
|
|
|
+ * save files
|
|
|
+ */
|
|
|
+ private void createAutoRandom() {
|
|
|
+ rand = (int) (Math.random() * 1000);
|
|
|
+ while (new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
|
|
|
+ rand = (int) Math.random() * 1000;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Delete a Directory.
|
|
|
*
|
|
@@ -108,10 +121,11 @@ public class Control {
|
|
|
if (files[i].isDirectory()) {
|
|
|
deleteDirectory(files[i]);
|
|
|
} else {
|
|
|
- files[i].delete();
|
|
|
+ if(files[i].getName().contains(""+rand))
|
|
|
+ files[i].delete();
|
|
|
}
|
|
|
}
|
|
|
- path.delete();
|
|
|
+ //path.delete();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -167,7 +181,8 @@ public class Control {
|
|
|
|
|
|
/**
|
|
|
* init default category and objects.
|
|
|
- * @throws IOException
|
|
|
+ *
|
|
|
+ * @throws IOException
|
|
|
*/
|
|
|
public void resetCategorys() throws IOException {
|
|
|
categoryController.initCategories();
|
|
@@ -179,7 +194,7 @@ public class Control {
|
|
|
*
|
|
|
* @param cat
|
|
|
* name of the new Category
|
|
|
- * @throws IOException
|
|
|
+ * @throws IOException
|
|
|
*/
|
|
|
public void addCategory(String cat) throws IOException {
|
|
|
categoryController.addNewCategory(cat);
|
|
@@ -197,7 +212,7 @@ public class Control {
|
|
|
* Array of Elements
|
|
|
* @param img
|
|
|
* the image Path
|
|
|
- * @throws IOException
|
|
|
+ * @throws IOException
|
|
|
*/
|
|
|
public void addObject(Category cat, String obj, ArrayList<HolonElement> ele, String img) throws IOException {
|
|
|
categoryController.addNewHolonObject(cat, obj, ele, img);
|
|
@@ -223,7 +238,7 @@ public class Control {
|
|
|
* Category
|
|
|
* @param obj
|
|
|
* New Object Name
|
|
|
- * @throws IOException
|
|
|
+ * @throws IOException
|
|
|
*/
|
|
|
public void addSwitch(Category cat, String obj) throws IOException {
|
|
|
categoryController.addNewHolonSwitch(cat, obj, "/Images/switch-on.png");
|
|
@@ -235,7 +250,7 @@ public class Control {
|
|
|
*
|
|
|
* @param cat
|
|
|
* the Category
|
|
|
- * @throws IOException
|
|
|
+ * @throws IOException
|
|
|
*/
|
|
|
public void deleteCategory(String cat) throws IOException {
|
|
|
categoryController.deleteCategory(cat);
|
|
@@ -249,7 +264,7 @@ public class Control {
|
|
|
* the Category
|
|
|
* @param obj
|
|
|
* the Object
|
|
|
- * @throws IOException
|
|
|
+ * @throws IOException
|
|
|
*/
|
|
|
public void delObjectCategory(String cat, String obj) throws IOException {
|
|
|
categoryController.deleteObject(cat, obj);
|
|
@@ -501,20 +516,21 @@ public class Control {
|
|
|
* the Path
|
|
|
* @throws IOException
|
|
|
* exception
|
|
|
- * @throws ArchiveException
|
|
|
+ * @throws ArchiveException
|
|
|
*/
|
|
|
public void loadFile(String path) throws IOException, ArchiveException, ZipException {
|
|
|
loadController.readSave(path);
|
|
|
saveCategory();
|
|
|
autoSave();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Reads the Json File from Autosave
|
|
|
+ *
|
|
|
* @param path
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public void loadAutoSave(String path) throws IOException {
|
|
|
+ public void loadAutoSave(String path) throws IOException {
|
|
|
loadController.readJson(path);
|
|
|
}
|
|
|
|
|
@@ -533,7 +549,7 @@ public class Control {
|
|
|
* current Timestep.
|
|
|
*/
|
|
|
public void calculateStateForCurrentTimeStep() {
|
|
|
- //simulationManager.reset();
|
|
|
+ // simulationManager.reset();
|
|
|
simulationManager.calculateStateForTimeStep(model.getCurIteration());
|
|
|
}
|
|
|
|
|
@@ -544,15 +560,15 @@ public class Control {
|
|
|
* current Iteration
|
|
|
*/
|
|
|
public void calculateStateForTimeStep(int x) {
|
|
|
- //simulationManager.reset();
|
|
|
+ // simulationManager.reset();
|
|
|
simulationManager.calculateStateForTimeStep(x);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * resets the whole State of the simulation
|
|
|
- * including a reset of all Edges to the default "is working" state
|
|
|
+ * resets the whole State of the simulation including a reset of all Edges
|
|
|
+ * to the default "is working" state
|
|
|
*/
|
|
|
- public void resetSimulation(){
|
|
|
+ public void resetSimulation() {
|
|
|
setIsSimRunning(false);
|
|
|
simulationManager.resetSimulation();
|
|
|
}
|
|
@@ -575,12 +591,13 @@ public class Control {
|
|
|
*/
|
|
|
public void autoSave() throws IOException {
|
|
|
autoSaveController.increaseAutoSaveNr();
|
|
|
- saveController.writeAutosave(autosaveDir + autoSaveController.getAutoSaveNr());
|
|
|
+ saveController.writeAutosave(autosaveDir + rand + autoSaveController.getAutoSaveNr());
|
|
|
if (autoSaveController.allowed()) {
|
|
|
- new File(autosaveDir + (autoSaveController.getAutoSaveNr() - globalController.getNumbersOfSaves())).delete();
|
|
|
+ new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr() - globalController.getNumbersOfSaves()))
|
|
|
+ .delete();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void saveCategory() throws IOException {
|
|
|
saveController.writeCategory(categoryDir + "Category.json");
|
|
|
}
|
|
@@ -592,10 +609,10 @@ public class Control {
|
|
|
*/
|
|
|
public String getUndoSave() {
|
|
|
autoSaveController.decreaseAutoSaveNr();
|
|
|
- if (!new File(autosaveDir + (autoSaveController.getAutoSaveNr())).exists()) {
|
|
|
+ if (!new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
|
|
|
autoSaveController.increaseAutoSaveNr();
|
|
|
}
|
|
|
- return autosaveDir + (autoSaveController.getAutoSaveNr());
|
|
|
+ return autosaveDir + rand + (autoSaveController.getAutoSaveNr());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -605,14 +622,12 @@ public class Control {
|
|
|
*/
|
|
|
public String getRedoSave() {
|
|
|
autoSaveController.increaseAutoSaveNr();
|
|
|
- if (!new File(autosaveDir + (autoSaveController.getAutoSaveNr())).exists()) {
|
|
|
+ if (!new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
|
|
|
autoSaveController.decreaseAutoSaveNr();
|
|
|
}
|
|
|
- return autosaveDir + (autoSaveController.getAutoSaveNr());
|
|
|
+ return autosaveDir + rand + (autoSaveController.getAutoSaveNr());
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* Getter for Model.
|
|
|
*
|
|
@@ -883,11 +898,12 @@ public class Control {
|
|
|
public void copy(CpsUpperNode upperNode) {
|
|
|
clipboardController.copy(upperNode);
|
|
|
}
|
|
|
-
|
|
|
- public void paste(CpsUpperNode upperNode, Point point) throws JsonParseException, UnsupportedFlavorException, IOException {
|
|
|
+
|
|
|
+ public void paste(CpsUpperNode upperNode, Point point)
|
|
|
+ throws JsonParseException, UnsupportedFlavorException, IOException {
|
|
|
clipboardController.paste(upperNode, point);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void cut(CpsUpperNode upperNode) {
|
|
|
clipboardController.cut(upperNode);
|
|
|
}
|
|
@@ -905,7 +921,7 @@ public class Control {
|
|
|
}
|
|
|
|
|
|
public int getTotalElements(ArrayList<AbstractCpsObject> arrayList) {
|
|
|
- return holonCanvasController.getTotalElements(arrayList) ;
|
|
|
+ return holonCanvasController.getTotalElements(arrayList);
|
|
|
}
|
|
|
|
|
|
public int getTotalProducers(ArrayList<AbstractCpsObject> arrayList) {
|
|
@@ -915,6 +931,7 @@ public class Control {
|
|
|
public int getActiveElements(ArrayList<AbstractCpsObject> arrayList) {
|
|
|
return holonCanvasController.getActiveElements(arrayList);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* Set the Background Image;
|
|
|
*
|
|
@@ -928,25 +945,25 @@ public class Control {
|
|
|
* Image custom height
|
|
|
*/
|
|
|
public void setBackgroundImage(String imagePath, int mode, int width, int height) {
|
|
|
- canvasController.setBackgroundImage(imagePath, mode, width, height);
|
|
|
+ canvasController.setBackgroundImage(imagePath, mode, width, height);
|
|
|
}
|
|
|
-
|
|
|
- public void setFlexiblePane(FlexiblePane fp){
|
|
|
+
|
|
|
+ public void setFlexiblePane(FlexiblePane fp) {
|
|
|
simulationManager.setFlexiblePane(fp);
|
|
|
}
|
|
|
-
|
|
|
- public void setGraphTable(Hashtable<String, StatisticGraphPanel> gT){
|
|
|
+
|
|
|
+ public void setGraphTable(Hashtable<String, StatisticGraphPanel> gT) {
|
|
|
model.setGraphTable(gT);
|
|
|
}
|
|
|
-
|
|
|
- public Hashtable<String, StatisticGraphPanel> getGraphTable(){
|
|
|
+
|
|
|
+ public Hashtable<String, StatisticGraphPanel> getGraphTable() {
|
|
|
return model.getGraphTable();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Sets if the Simulation is running
|
|
|
*/
|
|
|
- public void setIsSimRunning(boolean isRunning){
|
|
|
+ public void setIsSimRunning(boolean isRunning) {
|
|
|
globalController.setIsSimRunning(isRunning);
|
|
|
}
|
|
|
|