sysperfana/analyzetoolext/com.nokia.s60tools.analyzetool/src/com/nokia/s60tools/analyzetool/ui/actions/FileActionHistory.java
changeset 1 1050670c6980
child 6 f65f740e69f9
equal deleted inserted replaced
0:5ad7ad99af01 1:1050670c6980
       
     1 /*
       
     2  * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  Definitions for the class FileActionHistory
       
    15  *
       
    16  */
       
    17 
       
    18 package com.nokia.s60tools.analyzetool.ui.actions;
       
    19 
       
    20 import java.util.AbstractList;
       
    21 import java.util.ArrayList;
       
    22 import java.util.Iterator;
       
    23 
       
    24 /**
       
    25  * Contains history of what files are opened.
       
    26  *
       
    27  * @author kihe
       
    28  *
       
    29  */
       
    30 public class FileActionHistory {
       
    31 
       
    32 	/** File name. */
       
    33 	private String fileName;
       
    34 
       
    35 	/** List of opened files. */
       
    36 	private final AbstractList<String> fileNameHistory;
       
    37 
       
    38 	/** How many files to displayed. */
       
    39 	private final int howManyItems;
       
    40 
       
    41 	/**
       
    42 	 * Constructor.
       
    43 	 *
       
    44 	 * @param howMany
       
    45 	 *            How many file to display
       
    46 	 */
       
    47 	public FileActionHistory(final int howMany) {
       
    48 		fileNameHistory = new ArrayList<String>();
       
    49 		howManyItems = howMany;
       
    50 	}
       
    51 
       
    52 	/**
       
    53 	 * Gets history items.
       
    54 	 *
       
    55 	 * @return List of history items
       
    56 	 */
       
    57 	public final AbstractList<String> getItems() {
       
    58 		AbstractList<String> tmpFileList = new ArrayList<String>();
       
    59 		Iterator<String> iterFiles = fileNameHistory.iterator();
       
    60 		int index = 0;
       
    61 		while (iterFiles.hasNext() && index < howManyItems) {
       
    62 			tmpFileList.add(iterFiles.next());
       
    63 			index++;
       
    64 		}
       
    65 		return tmpFileList;
       
    66 	}
       
    67 
       
    68 	/**
       
    69 	 * Checks is list empty.
       
    70 	 *
       
    71 	 * @return True if list is empty otherwise False
       
    72 	 */
       
    73 	public final boolean isEmpty() {
       
    74 		return fileNameHistory.isEmpty();
       
    75 	}
       
    76 
       
    77 	/**
       
    78 	 * Removes file name from the list.
       
    79 	 *
       
    80 	 * @param usedFileName
       
    81 	 *            Used file
       
    82 	 */
       
    83 	public final void removeFileName(final String usedFileName) {
       
    84 		if (fileNameHistory.contains(usedFileName)) {
       
    85 			fileNameHistory.remove(usedFileName);
       
    86 			removeFileName(usedFileName);
       
    87 		}
       
    88 	}
       
    89 
       
    90 	/**
       
    91 	 * Sets file location and name.
       
    92 	 *
       
    93 	 * @param pathAndName
       
    94 	 *            File location and name
       
    95 	 */
       
    96 	public final void setFileName(final String pathAndName) {
       
    97 		if (!("").equals(pathAndName)) {
       
    98 			// if list already contains same file name remove it
       
    99 			if (fileNameHistory.contains(pathAndName)) {
       
   100 				removeFileName(pathAndName);
       
   101 
       
   102 			}
       
   103 			fileName = pathAndName;
       
   104 
       
   105 			// add file name to history list
       
   106 			fileNameHistory.add(0, fileName);
       
   107 		}
       
   108 	}
       
   109 }