001: /*
002: * SSHTools - Java SSH2 API
003: *
004: * Copyright (C) 2002-2003 Lee David Painter and Contributors.
005: *
006: * Contributions made by:
007: *
008: * Brett Smith
009: * Richard Pernavas
010: * Erwin Bolwidt
011: *
012: * This program is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU General Public License
014: * as published by the Free Software Foundation; either version 2
015: * of the License, or (at your option) any later version.
016: *
017: * This program is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with this program; if not, write to the Free Software
024: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
025: */
026: package com.sshtools.common.mru;
027:
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030:
031: import java.io.File;
032:
033: import javax.swing.AbstractListModel;
034:
035: /**
036: *
037: *
038: * @author $author$
039: * @version $Revision: 1.14 $
040: */
041: public class MRUListModel extends AbstractListModel {
042: private static Log log = LogFactory.getLog(MRUListModel.class);
043: private MRUList mru;
044:
045: /**
046: * Creates a new MRUListModel object.
047: */
048: public MRUListModel() {
049: super ();
050: setMRUList(new MRUList());
051: }
052:
053: /**
054: *
055: *
056: * @param f
057: */
058: public void add(File f) {
059: mru.insertElementAt(f, 0);
060:
061: for (int i = mru.size() - 1; i >= 1; i--) {
062: if (((File) mru.elementAt(i)).equals(f)) {
063: mru.removeElementAt(i);
064: }
065: }
066:
067: if (mru.size() > 15) {
068: for (int i = mru.size() - 1; i >= 15; i--) {
069: mru.removeElementAt(i);
070: }
071: }
072:
073: fireContentsChanged(this , 0, getSize() - 1);
074: }
075:
076: /**
077: *
078: *
079: * @param i
080: *
081: * @return
082: */
083: public Object getElementAt(int i) {
084: return mru.get(i);
085: }
086:
087: /**
088: *
089: *
090: * @return
091: */
092: public int getSize() {
093: return (mru == null) ? 0 : mru.size();
094: }
095:
096: /**
097: *
098: *
099: * @param mru
100: */
101: public void setMRUList(MRUList mru) {
102: this .mru = mru;
103: fireContentsChanged(this , 0, getSize());
104: }
105:
106: /**
107: *
108: *
109: * @return
110: */
111: public MRUList getMRUList() {
112: return mru;
113: }
114: }
|