Changeset 744
- Timestamp:
- 01/24/14 10:10:59 (10 years ago)
- Location:
- trunk/src/org/expeditee
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/agents/Format.java
r740 r744 163 163 */ 164 164 start.setChanged(true); 165 start.addToUndo (changedItems);165 start.addToUndoMove(changedItems); 166 166 FrameGraphics.requestRefresh(true); 167 167 return null; -
trunk/src/org/expeditee/agents/HFormat.java
r742 r744 48 48 49 49 System.out.println(changedItems); 50 start.addToUndo (changedItems);50 start.addToUndoMove(changedItems); 51 51 return null; 52 52 } -
trunk/src/org/expeditee/gui/Frame.java
r740 r744 94 94 private boolean _saved = false; 95 95 96 private static final class History { 97 public enum Type { 98 deletion, 99 movement 100 } 101 public final List<Item> items; 102 public final Type type; 103 104 public History(Collection<Item> items, Type type) { 105 this.items = new LinkedList<Item>(items); 106 this.type = type; 107 } 108 109 public String toString() { 110 return this.type.toString() + ":\n" + this.items.toString(); 111 } 112 } 113 96 114 // list of deleted items that can be restored 97 private Stack<List<Item>> _undo = new Stack<List<Item>>(); 115 private Stack<History> _undo = new Stack<History>(); 116 private Stack<History> _redo = new Stack<History>(); 98 117 99 118 // basically just a list of smaller objects? … … 892 911 893 912 /** 894 * Adds the given list of Items to the undo stack. This is the same as895 * calling addToUndo() for each Item in the list.896 * 897 * @param items 898 * The List of Items to add to the undo stack.899 */ 900 p ublic void addToUndo(Collection<Item> items) {913 * Adds the given History event to the stack. 914 * 915 * @param stack The stack to add to 916 * @param items The items to put in the event 917 * @param type The type of event that occurred 918 */ 919 private void addToUndo(Collection<Item> items, History.Type type) { 901 920 if (items.size() < 1) 902 921 return; 903 922 904 // System.out.println("Added: " + items); 905 906 _undo.push(new LinkedList<Item>(items)); 923 System.out.println("Added: " + items); 924 925 _undo.push(new History(items, type)); 926 } 927 928 public void addToUndoDelete(Collection<Item> items) { 929 addToUndo(items, History.Type.deletion); 930 } 931 public void addToUndoMove(Collection<Item> items) { 932 addToUndo(items, History.Type.movement); 907 933 } 908 934 909 935 public void undo() { 910 List<Item> undo = null;911 936 boolean bReparse = false; 912 937 boolean bRecalculate = false; … … 915 940 return; 916 941 917 undo = _undo.pop();942 History undo = _undo.pop(); 918 943 919 // System.out.println("Undoing: " + undo); 920 921 for(Item i : undo) { 922 // if the change was to characteristics 923 if(i.isVisible() && _body.contains(i)) { 924 _body.set(_body.indexOf(i), i); 925 // the item was deleted 926 } else { 927 _body.add(i); 944 System.out.println("Undoing: " + undo); 945 946 switch(undo.type) { 947 case deletion: 948 _redo.push(undo); 949 for(Item i : undo.items) { 950 _body.add(i); 928 951 bReparse |= i.hasOverlay(); 929 952 bRecalculate |= i.recalculateWhenChanged(); … … 935 958 i.setOffset(0, 0); 936 959 } 937 } 960 } 961 break; 962 case movement: 963 List<Item> changed = new LinkedList<Item>(_body); 964 changed.retainAll(undo.items); 965 _redo.push(new History(changed, History.Type.movement)); 966 for(Item i : undo.items) { 967 int index; 968 if(i.isVisible() && (index = _body.indexOf(i)) != -1) { 969 _body.set(index, i); 970 } 971 } 972 break; 973 } 974 change(); 975 FrameMouseActions.getInstance().refreshHighlights(); 976 if (bReparse) { 977 FrameUtils.Parse(this, false, false); 978 } else { 979 notifyObservers(bRecalculate); 980 } 981 // always request a refresh otherwise filled shapes 982 // that were broken by a deletion and then reconnected by the undo 983 // don't get filled until the user otherwise causes them to redraw 984 FrameGraphics.requestRefresh(false); 985 FrameGraphics.Repaint(); 986 ItemUtils.EnclosedCheck(_body); 987 } 988 989 public void redo() { 990 boolean bReparse = false; 991 boolean bRecalculate = false; 992 993 if (_redo.size() <= 0) 994 return; 995 996 History redo = _redo.pop(); 997 998 System.out.println("Redoing: " + redo); 999 1000 switch(redo.type) { 1001 case deletion: 1002 _undo.push(redo); 1003 for(Item i : redo.items) { 1004 _body.remove(i); 1005 bReparse |= i.hasOverlay(); 1006 bRecalculate |= i.recalculateWhenChanged(); 1007 if (i instanceof Line) { 1008 Line line = (Line) i; 1009 line.getStartItem().removeLine(line); 1010 line.getEndItem().removeLine(line); 1011 } else { 1012 i.setOffset(0, 0); 1013 } 1014 } 1015 break; 1016 case movement: 1017 List<Item> changed = new LinkedList<Item>(_body); 1018 changed.retainAll(redo.items); 1019 _undo.push(new History(changed, History.Type.movement)); 1020 for(Item i : redo.items) { 1021 int index; 1022 if(i.isVisible() && (index = _body.indexOf(i)) != -1) { 1023 _body.set(index, i); 1024 } 1025 } 1026 break; 938 1027 } 939 1028 change(); … … 1477 1566 } 1478 1567 _body.removeAll(newBody); 1479 addToUndo (_body);1568 addToUndoDelete(_body); 1480 1569 _body = newBody; 1481 1570 change(); -
trunk/src/org/expeditee/gui/FrameKeyboardActions.java
r740 r744 817 817 break; 818 818 case KeyEvent.VK_Z: 819 DisplayIO.getCurrentFrame().undo(); 819 if(isShiftDown) { 820 DisplayIO.getCurrentFrame().redo(); 821 } else { 822 DisplayIO.getCurrentFrame().undo(); 823 } 820 824 return; 821 825 case KeyEvent.VK_D: -
trunk/src/org/expeditee/gui/FrameMouseActions.java
r740 r744 1675 1675 inWindow = false; 1676 1676 // System.out.println("Left window"); 1677 if(FreeItems.itemsAttachedToCursor()) 1678 ItemSelection.cut(); 1677 if(FreeItems.itemsAttachedToCursor()) { 1678 boolean cut = true; 1679 for(Item i : FreeItems.getInstance()) { 1680 for(Item j : i.getAllConnected()) { 1681 if(!FreeItems.getInstance().contains(j)) { 1682 cut = false; 1683 break; 1684 } 1685 } 1686 } 1687 if(cut) { 1688 ItemSelection.cut(); 1689 } 1690 } 1679 1691 } 1680 1692 … … 2599 2611 // otherwise this is an undo command 2600 2612 } else { 2601 DisplayIO.getCurrentFrame().undo(); 2613 if(isControlDown()) { 2614 DisplayIO.getCurrentFrame().redo(); 2615 } else { 2616 DisplayIO.getCurrentFrame().undo(); 2617 } 2602 2618 } 2603 2619 return; … … 2669 2685 SessionStats.DeletedItems(toUndo); 2670 2686 if (parent != null) { 2671 parent.addToUndo (toUndo);2687 parent.addToUndoDelete(toUndo); 2672 2688 parent.removeAllItems(toUndo); // toDelete.getConnected() 2673 2689 } … … 2755 2771 // the current frame as well as the overlay frame 2756 2772 Frame currentFrame = DisplayIO.getCurrentFrame(); 2757 currentFrame.addToUndo (itemList);2773 currentFrame.addToUndoDelete(itemList); 2758 2774 itemList.clear(); 2759 2775 if (bReparse) { -
trunk/src/org/expeditee/gui/Help.java
r717 r744 129 129 break; 130 130 case background: 131 if((other & cursor) == 0) return "Undo last delete"; 131 if((other & cursor) == 0) { 132 if((mod & control) != 0) return "Redo"; 133 return "Undo"; 134 } 132 135 break; 133 136 }
Note:
See TracChangeset
for help on using the changeset viewer.