1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.monkeyrunner.recorder; 17 18 import com.google.common.collect.Lists; 19 20 import com.android.monkeyrunner.recorder.actions.Action; 21 22 import java.io.File; 23 import java.io.FileNotFoundException; 24 import java.io.PrintWriter; 25 import java.util.List; 26 27 import javax.swing.AbstractListModel; 28 29 /** 30 * List model for managing actions. 31 */ 32 public class ActionListModel extends AbstractListModel { 33 private List<Action> actionList = Lists.newArrayList(); 34 35 /** 36 * Add the specified action to the end of the list 37 * @param a the action to add. 38 */ add(Action a)39 public void add(Action a) { 40 actionList.add(a); 41 int newIndex = actionList.size() - 1; 42 this.fireIntervalAdded(this, newIndex, newIndex); 43 } 44 45 @Override getElementAt(int arg0)46 public Object getElementAt(int arg0) { 47 return actionList.get(arg0).getDisplayName(); 48 } 49 50 51 @Override getSize()52 public int getSize() { 53 return actionList.size(); 54 } 55 56 /** 57 * Serialize all the stored actions to the specified file. 58 * 59 * @param selectedFile the file to write to 60 * @throws FileNotFoundException if the file can't be created. 61 */ export(File selectedFile)62 public void export(File selectedFile) throws FileNotFoundException { 63 PrintWriter out = new PrintWriter(selectedFile); 64 for (Action a : actionList) { 65 out.println(a.serialize()); 66 } 67 out.close(); 68 } 69 }