001/* Represents an undo or redo action. 002 003 Copyright (c) 2003-2014 The Regents of the University of California. 004 All rights reserved. 005 Permission is hereby granted, without written agreement and without 006 license or royalty fees, to use, copy, modify, and distribute this 007 software and its documentation for any purpose, provided that the above 008 copyright notice and the following two paragraphs appear in all copies 009 of this software. 010 011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015 SUCH DAMAGE. 016 017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022 ENHANCEMENTS, OR MODIFICATIONS. 023 024 PT_COPYRIGHT_VERSION_2 025 COPYRIGHTENDKEY 026 */ 027package ptolemy.kernel.undo; 028 029import java.util.LinkedList; 030import java.util.List; 031 032/////////////////////////////////////////////////////////////////// 033//// UndoActionsList 034 035/** 036 This class contains a sequential list of UndoAction instances that 037 can be executed in order. 038 039 @author Edward A. Lee 040 @version $Id$ 041 @since Ptolemy II 8.0 042 @Pt.ProposedRating Yellow (eal) 043 @Pt.AcceptedRating Red (cxh) 044 */ 045public class UndoActionsList implements UndoAction { 046 047 /** Create an undo action with the specified action 048 * to be executed first. 049 * @param firstAction The action to execute first. 050 */ 051 public UndoActionsList(UndoAction firstAction) { 052 _actionList = new LinkedList<UndoAction>(); 053 _actionList.add(firstAction); 054 } 055 056 /////////////////////////////////////////////////////////////////// 057 //// public methods //// 058 059 /** Append a new entry to the list. 060 * @param action The entry to append. 061 */ 062 public void add(UndoAction action) { 063 _actionList.add(action); 064 } 065 066 /** Execute the action. */ 067 @Override 068 public void execute() throws Exception { 069 for (UndoAction action : _actionList) { 070 action.execute(); 071 } 072 } 073 074 @Override 075 public String toString() { 076 StringBuffer result = new StringBuffer("Action List:\n"); 077 for (UndoAction action : _actionList) { 078 result.append(action.toString()); 079 result.append("\n"); 080 } 081 result.append("\nEnd of action list.\n"); 082 return result.toString(); 083 } 084 085 /////////////////////////////////////////////////////////////////// 086 //// private variables //// 087 088 /** The list of actions to execute. */ 089 private List<UndoAction> _actionList; 090}