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).

Line 
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/**
16 * @author Alexandre Correia
17 *
18 */
19
20public class StatusIcons
21{
22        private static Map statusIcons;
23        private SAXParser parser;
24
25        public StatusIcons()
26    {
27                if( statusIcons == null )
28                {
29                        statusIcons = new HashMap();
30
31                        String urlString = getClass().getResource("StatusIcons.class").toString();
32                        try
33                        {
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                        {
40                                e.printStackTrace();
41                        }
42                        catch(NullPointerException e)
43                        {
44                                System.err.println("nu/fw/jeti/images/Status.cfg or images.cfg missing");
45                        }
46                }
47        }
48       
49        public static ImageIcon getOfflineIcon()
50        {
51                return getStatusIcon(Presence.UNAVAILABLE ,"default");
52        }
53       
54        public static ImageIcon getStatusIcon(int show)
55        {
56                return getStatusIcon(show,"");
57        }
58
59        /** verander
60         * calls getImageIcon(show) whith the default imageset
61         * @param show
62         * @return ImageIcon
63         */
64        public static ImageIcon getImageIcon(String show)
65        {
66                return getStatusIcon(show,"images");
67        }
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         */
75        public static ImageIcon getStatusIcon(int show,String type)
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       
90        public static ImageIcon getStatusIcon(JIDStatus jidStatus)
91        {
92                return getStatusIcon(jidStatus.getShow(),jidStatus.getType());
93        }
94       
95        private static ImageIcon getStatusIcon(String show,String type)
96        {
97
98                if ( !statusIcons.containsKey(type) )
99                        type = "default";
100               
101                ImageIcon icon = (ImageIcon)((Map)statusIcons.get(type)).get(show);
102               
103                if (icon == null)
104                        icon = (ImageIcon)((Map)statusIcons.get("default")).get(show);
105               
106                return icon;
107        }
108
109        private void readImages(BufferedReader data,URL file)
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                {
122                        e.printStackTrace();
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        {
132                StringBuffer buffer = new StringBuffer();
133               
134                while( true )
135                {
136                        int in2 = data.read();
137                        if( in2 == -1) throw new EOFException();
138                        char ca =(char)in2;
139                        if ( ca == ' ')
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        {
150                return new ImageIcon( new URL(file + data.readLine()) );
151        }
152}
153
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.