001    /*
002     *  Copyright (C) 2003 Adam Olsen
003     *  This program is free software; you can redistribute it and/or modify
004     *  it under the terms of the GNU General Public License as published by
005     *  the Free Software Foundation; either version 1, or (at your option)
006     *  any later version.
007     *  This program is distributed in the hope that it will be useful,
008     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
009     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
010     *  GNU General Public License for more details.
011     *  You should have received a copy of the GNU General Public License
012     *  along with this program; if not, write to the Free Software
013     *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
014     */
015    package com.valhalla.jbother.jabber;
016    
017    import java.util.*;
018    import org.jivesoftware.smack.packet.Presence;
019    
020    import com.valhalla.jbother.*;
021    
022    /**
023     * Vector of user statuses (SelfStatuses)
024     *
025     * @author     Yury Soldak (tail)
026     * @created    November 11, 2004
027     * @see        com.valhalla.jbother.jabber.SelfStatus
028     */
029    public class SelfStatuses
030    {
031            private ResourceBundle resources = ResourceBundle.getBundle( "JBotherBundle", Locale.getDefault() );
032            private static SelfStatuses singleton = null;
033            private Vector content = new Vector();
034    
035            /**
036             * Gets the SelfStatuses singleton
037             *
038             * @return    the SelfStatuses singleton
039             */
040            public static SelfStatuses getInstance()
041            {
042                    if( singleton == null )
043                    {
044                            singleton = new SelfStatuses();
045                    }
046                    return singleton;
047            }
048    
049            /**
050             * Creates the SelfStatus
051             * Constructor is private, this is a singleton.  See the <code>getSingleton</code> method
052             */
053            private SelfStatuses()
054            {
055    
056                    SelfStatus offline = new SelfStatus( resources.getString( "offline" ), "offline", null );
057                    SelfStatus available = new SelfStatus( resources.getString( "available" ), "online", Presence.Mode.AVAILABLE );
058                    SelfStatus away = new SelfStatus( resources.getString( "away" ), "away", Presence.Mode.AWAY );
059                    SelfStatus chat = new SelfStatus( resources.getString( "chat" ), "ffc", Presence.Mode.CHAT );
060                    SelfStatus dnd = new SelfStatus( resources.getString( "dnd" ), "dnd", Presence.Mode.DO_NOT_DISTURB );
061                    SelfStatus xa = new SelfStatus( resources.getString( "xa" ), "xa", Presence.Mode.EXTENDED_AWAY );
062                    SelfStatus invisible = new SelfStatus( resources.getString( "invisible" ), "invisible", Presence.Mode.INVISIBLE );
063    
064                    content.add( offline );
065                    content.add( available );
066                    content.add( away );
067                    content.add( chat );
068                    content.add( dnd );
069                    content.add( xa );
070                    content.add( invisible );
071    
072            }
073    
074            /**
075             * Gets a self status for the specified string
076             *
077             * @param  title  the title of the status to get
078             * @return        the SelfStatus
079             */
080            public SelfStatus getStatus( String title )
081            {
082                    SelfStatus result = null;
083    
084                    Iterator statusIterator = content.iterator();
085                    while( statusIterator.hasNext() )
086                    {
087                            result = (SelfStatus)statusIterator.next();
088                            if( result.getTitle().equals( title ) )
089                            {
090                                    break;
091                            }
092                    }
093    
094                    return result;
095            }
096    
097            /**
098             * Gets a status for a mode
099             *
100             * @param  mode  the mode to get the self status for
101             * @return       the requested SelfStatus
102             */
103            public SelfStatus getStatus( Presence.Mode mode )
104            {
105                    SelfStatus result = null;
106    
107                    Iterator statusIterator = content.iterator();
108                    while( statusIterator.hasNext() )
109                    {
110                            result = (SelfStatus)statusIterator.next();
111                            if( result.getMode() != null && result.getMode().equals( mode ) )
112                            {
113                                    break;
114                            }
115                    }
116    
117                    return result;
118            }
119    
120            /**
121             * Gets all the self statuses
122             *
123             * @return    The content value
124             */
125            public Vector getContent()
126            {
127                    return content;
128            }
129    
130    }
131