Преглед на файлове

AutoSave done, except vor keyboard control

Jessey Widhalm преди 7 години
родител
ревизия
ceac0e086c
променени са 4 файла, в които са добавени 26 реда и са изтрити 18 реда
  1. 6 5
      src/ui/controller/AutoSaveController.java
  2. 18 5
      src/ui/controller/Control.java
  3. 2 2
      src/ui/model/Model.java
  4. 0 6
      src/ui/view/GUI.java

+ 6 - 5
src/ui/controller/AutoSaveController.java

@@ -5,25 +5,26 @@ import ui.model.Model;
 public class AutoSaveController {
 	private Model MODEL;
 	private int numberOfSaves = 20;
-	private int autoSaveNr = 0;
+	private int autoSaveNr, tmp = 0;
 	public AutoSaveController(Model model) {
 		this.MODEL = model;
 	}
 	
 	public void increaseAutoSaveNr(){
 		 autoSaveNr = MODEL.getAutoSaveNr()+1;
+		 tmp = MODEL.getAutoSaveNr();
 		if(autoSaveNr > numberOfSaves){
-			autoSaveNr = 1;
+			autoSaveNr = 0;
 		}
-		MODEL.setAutoSAveNr(autoSaveNr);
+		MODEL.setAutoSaveNr(autoSaveNr);
 	}
 	
 	public void decreaseAutoSaveNr() {
 		 autoSaveNr = MODEL.getAutoSaveNr()-1;
-		if(autoSaveNr <= 0){
+		if(autoSaveNr < 0){
 			autoSaveNr = numberOfSaves;
 		}
-		MODEL.setAutoSAveNr(autoSaveNr);
+		MODEL.setAutoSaveNr(autoSaveNr);
 	}
 	
 	public int getAutoSaveNr(){

+ 18 - 5
src/ui/controller/Control.java

@@ -72,6 +72,12 @@ public class Control {
 
 	public void addObject(Category cat, String obj, ArrayList<HolonElement> ele, String img) {
 		categoryController.addNewHolonObject(cat, obj, ele, img);
+		try {
+			autoSave();
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
 	}
 
 	public void addTransformer(Category cat, String obj) {
@@ -106,11 +112,6 @@ public class Control {
 		}
 	}
 
-	private void autoSave() throws IOException {
-		autoSaveController.increaseAutoSaveNr();
-		storeController.writeSaveFile(autoPath+autoSaveController.getAutoSaveNr());
-	}
-
 	public void removeEdgesOnCanvas(CpsEdge edge) {
 		canvasController.removeEdgesOnCanvas(edge);
 		try {
@@ -206,13 +207,25 @@ public class Control {
 		simulationManager.setCanvas(can);
 	}
 	
+
+	private void autoSave() throws IOException {
+		autoSaveController.increaseAutoSaveNr();
+		storeController.writeSaveFile(autoPath+autoSaveController.getAutoSaveNr());
+	}
+	
 	public String getUndoSave(){
 		autoSaveController.decreaseAutoSaveNr();
+		if(!new File(autoPath + (autoSaveController.getAutoSaveNr())).exists()){
+			autoSaveController.increaseAutoSaveNr();
+		}
 		return autoPath+(autoSaveController.getAutoSaveNr());
 	}
 	
 	public String getRedoSave(){
 		autoSaveController.increaseAutoSaveNr();
+		if(!new File(autoPath+(autoSaveController.getAutoSaveNr())).exists()){
+			autoSaveController.decreaseAutoSaveNr();
+		}
 		return autoPath+(autoSaveController.getAutoSaveNr());
 	}
 	

+ 2 - 2
src/ui/model/Model.java

@@ -27,7 +27,7 @@ public class Model {
 	private CpsEdge selectedEdge;
 
 	private int selectedID = 0;
-	private int autoSaveNr = 0;
+	private int autoSaveNr = -1;
 	// eventuell wenn Canvasgröße gewählt werden kann
 	private int HEIGHT;
 	private int WIDTH;
@@ -319,7 +319,7 @@ public class Model {
 		this.cvsObjIdx = cvsObjIdx;
 	}
 	
-	public void setAutoSAveNr(int autoSaveNr){
+	public void setAutoSaveNr(int autoSaveNr){
 		this.autoSaveNr = autoSaveNr;
 	}
 	

+ 0 - 6
src/ui/view/GUI.java

@@ -1009,9 +1009,6 @@ public class GUI<E> implements CategoryListener {
 							unitGraph.fillArrayofBooleans();
 						}
 					}
-					unitGraph.empty();
-					tree.repaint();
-
 				} catch (IOException e) {
 					// TODO Auto-generated catch block
 					e.printStackTrace();
@@ -1047,9 +1044,6 @@ public class GUI<E> implements CategoryListener {
 							unitGraph.fillArrayofBooleans();
 						}
 					}
-					unitGraph.empty();
-					tree.repaint();
-
 				} catch (IOException e) {
 					// TODO Auto-generated catch block
 					e.printStackTrace();