浏览代码

control+z for undo, control+y for redo

Jessey Widhalm 8 年之前
父节点
当前提交
459c0aab5c
共有 1 个文件被更改,包括 56 次插入5 次删除
  1. 56 5
      src/ui/view/GUI.java

+ 56 - 5
src/ui/view/GUI.java

@@ -247,12 +247,63 @@ public class GUI<E> implements CategoryListener {
 		InputMap inputMap = contentPane.getInputMap(condition);
 		ActionMap actionMap = contentPane.getActionMap();
 
-		String zDown = "z";
-		inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_Z, 0), zDown);
-		actionMap.put(zDown, new AbstractAction() {
+		String cntrlZDown = "controlZ";
+		inputMap.put(KeyStroke.getKeyStroke("control Z" ), cntrlZDown);
+		actionMap.put(cntrlZDown, new AbstractAction() {
+			
 			@Override
-			public void actionPerformed(ActionEvent arg0) {
-				System.out.println("z");
+			public void actionPerformed(ActionEvent e) {
+				try {
+					controller.loadFile(controller.getUndoSave());
+					canvas.repaint();
+					ArrayList<HolonElement> tempList = new ArrayList<>();
+					for (CpsObject cps : model.getObjectsOnCanvas()) {
+						if (cps instanceof HolonObject) {
+							for (HolonElement h : ((HolonObject) cps).getElements()) {
+								tempList.add(h);
+								unitGraph.repaintWithNewElement(tempList);
+								unitGraph.fillArrayofValue();
+								tempList.remove(0);
+							}
+						} else if (cps instanceof HolonSwitch) {
+							unitGraph.repaintWithNewSwitch((HolonSwitch) cps);
+							unitGraph.fillArrayofBooleans();
+						}
+					}
+				} catch (IOException f) {
+					// TODO Auto-generated catch block
+					f.printStackTrace();
+				}
+			}
+		});
+		
+		String cntrlYDown = "controlY";
+		inputMap.put(KeyStroke.getKeyStroke("control Y" ), cntrlYDown);
+		actionMap.put(cntrlYDown, new AbstractAction() {
+			
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				try {
+					controller.loadFile(controller.getRedoSave());
+					canvas.repaint();
+					ArrayList<HolonElement> tempList = new ArrayList<>();
+					for (CpsObject cps : model.getObjectsOnCanvas()) {
+						if (cps instanceof HolonObject) {
+							for (HolonElement h : ((HolonObject) cps).getElements()) {
+								tempList.add(h);
+								unitGraph.repaintWithNewElement(tempList);
+								unitGraph.fillArrayofValue();
+								tempList.remove(0);
+							}
+						} else if (cps instanceof HolonSwitch) {
+							unitGraph.repaintWithNewSwitch((HolonSwitch) cps);
+							unitGraph.fillArrayofBooleans();
+						}
+					}
+				} catch (IOException f) {
+					// TODO Auto-generated catch block
+					f.printStackTrace();
+				}
 			}
 		});