source: trunk/jabberit_messenger/java_source/src/nu/fw/jeti/images/StatusIcons.java @ 1091

Revision 1091, 3.6 KB checked in by alexandrecorreia, 15 years ago (diff)

Ticket #571 - Removido o arquivo rostericons.xml, usado pelo applet(Java).

RevLine 
[1014]1package nu.fw.jeti.images;
2
3import java.io.*;
4import java.net.MalformedURLException;
5import java.net.URL;
6import java.util.*;
7
8import javax.swing.Icon;
9import javax.swing.ImageIcon;
10import javax.xml.parsers.SAXParser;
11
12import nu.fw.jeti.jabber.JIDStatus;
13import nu.fw.jeti.jabber.elements.Presence;
14
15/**
[1091]16 * @author Alexandre Correia
17 *
[1014]18 */
19
20public class StatusIcons
21{
22        private static Map statusIcons;
23        private SAXParser parser;
24
[1091]25        public StatusIcons()
[1014]26    {
27                if( statusIcons == null )
28                {
[1091]29                        statusIcons = new HashMap();
30
31                        String urlString = getClass().getResource("StatusIcons.class").toString();
32                        try
[1014]33                        {
[1091]34                                urlString = urlString.substring(0,urlString.lastIndexOf("StatusIcons.class"));
35                                readImages(new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("status.cfg"))),new URL(urlString));
36                                readImages(new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("images.cfg"))),new URL(urlString));
37                        }
38                        catch(MalformedURLException e)
39                        {
[1014]40                                e.printStackTrace();
41                        }
[1091]42                        catch(NullPointerException e)
[1014]43                        {
[1091]44                                System.err.println("nu/fw/jeti/images/Status.cfg or images.cfg missing");
[1014]45                        }
46                }
47        }
48       
[1091]49        public static ImageIcon getOfflineIcon()
[1014]50        {
[1091]51                return getStatusIcon(Presence.UNAVAILABLE ,"default");
[1014]52        }
53       
[1091]54        public static ImageIcon getStatusIcon(int show)
[1014]55        {
[1091]56                return getStatusIcon(show,"");
[1014]57        }
58
59        /** verander
60         * calls getImageIcon(show) whith the default imageset
61         * @param show
62         * @return ImageIcon
63         */
[1091]64        public static ImageIcon getImageIcon(String show)
65        {
66                return getStatusIcon(show,"images");
67        }
[1014]68
69        /**
70         * returns a status icon
71         * @param show one of chat,available,dnd,away,xa or unavailable
72         * @param type which image set
73         * @return ImageIcon
74         */
[1091]75        public static ImageIcon getStatusIcon(int show,String type)
[1014]76        {
77                switch (show)
78                {
79                        case Presence.FREE_FOR_CHAT: return  getStatusIcon("status/chat",type);
80                        case Presence.AWAY: return  getStatusIcon("status/away",type);
81                        case Presence.XA: return  getStatusIcon("status/xa",type);
82                        case Presence.DND: return  getStatusIcon("status/dnd",type);
83                        case Presence.UNAVAILABLE: return  getStatusIcon("status/offline",type);
84                        case Presence.INVISIBLE: return  getStatusIcon("status/invisible",type);
85                        case Presence.NONE: return  getStatusIcon("status/ask",type);
86                        default: return getStatusIcon("status/online",type);
87                }       
88        }
89       
[1091]90        public static ImageIcon getStatusIcon(JIDStatus jidStatus)
[1014]91        {
92                return getStatusIcon(jidStatus.getShow(),jidStatus.getType());
93        }
94       
[1091]95        private static ImageIcon getStatusIcon(String show,String type)
[1014]96        {
[1091]97
98                if ( !statusIcons.containsKey(type) )
99                        type = "default";
100               
[1014]101                ImageIcon icon = (ImageIcon)((Map)statusIcons.get(type)).get(show);
[1091]102               
103                if (icon == null)
104                        icon = (ImageIcon)((Map)statusIcons.get("default")).get(show);
105               
[1014]106                return icon;
107        }
108
[1091]109        private void readImages(BufferedReader data,URL file)
[1014]110        {
111            try
112                {
113                        Map map = new HashMap();
114                        statusIcons.put(data.readLine(),map);
115                        while(true)
116                        {
117                                readSmilie(data,file,map);
118                        }
119                }
120                catch(EOFException e)
121                {
[1091]122                        e.printStackTrace();
[1014]123                }
124                catch (IOException e2)
125                {
126                    e2.printStackTrace();
127                }
128        }
129
130        private void readSmilie(BufferedReader data,URL file,Map current) throws IOException
131        {
[1091]132                StringBuffer buffer = new StringBuffer();
133               
134                while( true )
[1014]135                {
136                        int in2 = data.read();
[1091]137                        if( in2 == -1) throw new EOFException();
[1014]138                        char ca =(char)in2;
[1091]139                        if ( ca == ' ')
[1014]140                        {
141                                current.put(new String(buffer),readImage(data,file));
142                                return;
143                        }
144                        buffer.append(ca);
145                }
146        }
147
148        private Icon readImage(BufferedReader data,URL file) throws IOException
149        {
[1091]150                return new ImageIcon( new URL(file + data.readLine()) );
[1014]151        }
152}
[1091]153
[1014]154/*
155 * Overrides for emacs
156 * Local variables:
157 * tab-width: 4
158 * End:
159 */
Note: See TracBrowser for help on using the repository browser.