Browse Source

Autosave fix

Teh-Hai Julian Zheng 7 years ago
parent
commit
4bbcb4535f
3 changed files with 18 additions and 14 deletions
  1. 10 1
      src/ui/controller/Control.java
  2. 0 5
      src/ui/controller/LoadController.java
  3. 8 8
      src/ui/view/GUI.java

+ 10 - 1
src/ui/controller/Control.java

@@ -474,7 +474,7 @@ public class Control {
 	}
 
 	/**
-	 * Reads the the JSON File and load the state into the Model.
+	 * Reads the the Save File and load the state into the Model.
 	 * 
 	 * @param path
 	 *            the Path
@@ -485,6 +485,15 @@ public class Control {
 	public void loadFile(String path) throws IOException, ArchiveException, ZipException {
 		loadController.readSave(path);
 	}
+	
+	/**
+	 * Reads the Json File from Autosave
+	 * @param path
+	 * @throws IOException
+	 */
+	public void loadAutoSave(String path) throws IOException  {
+		loadController.readJson(path);
+	}
 
 	/**
 	 * Init the CategoryListener.

+ 0 - 5
src/ui/controller/LoadController.java

@@ -105,11 +105,6 @@ public class LoadController {
 	 */
 	public void readSave(String path) throws IOException, ArchiveException, ZipException {
 
-		if (path.contains("json")) {
-			readJson(path);
-			return;
-		}
-
 		File src = new File(path);
 		File folder = readArchive(path, src);
 		folder.deleteOnExit();

+ 8 - 8
src/ui/view/GUI.java

@@ -336,7 +336,7 @@ public class GUI<E> implements CategoryListener {
 			@Override
 			public void actionPerformed(ActionEvent e) {
 				try {
-					controller.loadFile(controller.getUndoSave());
+					controller.loadAutoSave(controller.getUndoSave());
 					canvas.repaint();
 					ArrayList<HolonElement> tempList = new ArrayList<>();
 					for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
@@ -353,7 +353,7 @@ public class GUI<E> implements CategoryListener {
 						}
 					}
 					unitGraph.empty();
-				} catch (IOException | ArchiveException eex) {
+				} catch (IOException  eex) {
 					// TODO Auto-generated catch block
 					eex.printStackTrace();
 				}
@@ -369,7 +369,7 @@ public class GUI<E> implements CategoryListener {
 			@Override
 			public void actionPerformed(ActionEvent e) {
 				try {
-					controller.loadFile(controller.getRedoSave());
+					controller.loadAutoSave(controller.getRedoSave());
 					canvas.repaint();
 					ArrayList<HolonElement> tempList = new ArrayList<>();
 					for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
@@ -386,7 +386,7 @@ public class GUI<E> implements CategoryListener {
 						}
 					}
 					unitGraph.empty();
-				} catch (IOException | ArchiveException ex) {
+				} catch (IOException  ex) {
 					// TODO Auto-generated catch block
 					ex.printStackTrace();
 				}
@@ -1648,7 +1648,7 @@ public class GUI<E> implements CategoryListener {
 
 			private void menuUndoActionPerformed(java.awt.event.ActionEvent evt) {
 				try {
-					controller.loadFile(controller.getUndoSave());
+					controller.loadAutoSave(controller.getUndoSave());
 					canvas.repaint();
 					ArrayList<HolonElement> tempList = new ArrayList<>();
 					for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
@@ -1665,7 +1665,7 @@ public class GUI<E> implements CategoryListener {
 						}
 					}
 					unitGraph.empty();
-				} catch (IOException | ArchiveException e) {
+				} catch (IOException  e) {
 					// TODO Auto-generated catch block
 					e.printStackTrace();
 				}
@@ -1684,7 +1684,7 @@ public class GUI<E> implements CategoryListener {
 
 			private void menuRedoActionPerformed(java.awt.event.ActionEvent evt) {
 				try {
-					controller.loadFile(controller.getRedoSave());
+					controller.loadAutoSave(controller.getRedoSave());
 					canvas.repaint();
 					ArrayList<HolonElement> tempList = new ArrayList<>();
 					for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
@@ -1701,7 +1701,7 @@ public class GUI<E> implements CategoryListener {
 						}
 					}
 					unitGraph.empty();
-				} catch (IOException | ArchiveException e) {
+				} catch (IOException  e) {
 					// TODO Auto-generated catch block
 					e.printStackTrace();
 				}