001/*
002 * $Id: DefaultTipOfTheDayModel.java 3927 2011-02-22 16:34:11Z kleopatra $
003 *
004 * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
005 * Santa Clara, California 95054, U.S.A. All rights reserved.
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 * 
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015 * Lesser General Public License for more details.
016 * 
017 * You should have received a copy of the GNU Lesser General Public
018 * License along with this library; if not, write to the Free Software
019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
020 */
021package org.jdesktop.swingx.tips;
022
023import java.util.ArrayList;
024import java.util.Arrays;
025import java.util.Collection;
026import java.util.List;
027
028/**
029 * Default {@link org.jdesktop.swingx.tips.TipOfTheDayModel} implementation.<br>
030 * 
031 * @author <a href="mailto:fred@L2FProd.com">Frederic Lavigne</a>
032 */
033public class DefaultTipOfTheDayModel implements TipOfTheDayModel {
034
035    private List<Tip> tips = new ArrayList<Tip>();
036
037    public DefaultTipOfTheDayModel() {
038    }
039
040    public DefaultTipOfTheDayModel(Tip[] tips) {
041        this(Arrays.asList(tips));
042    }
043
044    public DefaultTipOfTheDayModel(Collection<Tip> tips) {
045        this.tips.addAll(tips);
046    }
047
048    @Override
049    public Tip getTipAt(int index) {
050        return tips.get(index);
051    }
052
053    @Override
054    public int getTipCount() {
055        return tips.size();
056    }
057
058    public void add(Tip tip) {
059        tips.add(tip);
060    }
061
062    public void remove(Tip tip) {
063        tips.remove(tip);
064    }
065
066    public Tip[] getTips() {
067        return tips.toArray(new Tip[tips.size()]);
068    }
069
070    public void setTips(Tip[] tips) {
071        this.tips.clear();
072        this.tips.addAll(Arrays.asList(tips));
073    }
074
075}