source: trunk/jabberit_messenger/java_source/src/nu/fw/jeti/images/RosterIconsHandler.java @ 1014

Revision 1014, 3.0 KB checked in by alexandrecorreia, 15 years ago (diff)

Ticket #552 - Inclusão do projeto Java referente ao applet do módulo.

Line 
1/*
2 *      Jeti, a Java Jabber client, Copyright (C) 2002 E.S. de Boer 
3 *
4 *  This program is free software; you can redistribute it and/or modify
5 *  it under the terms of the GNU General Public License as published by
6 *  the Free Software Foundation; either version 2 of the License, or
7 *  (at your option) any later version.
8 *
9 *  This program is distributed in the hope that it will be useful,
10 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
11 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 *      GNU General Public License for more details.
13 *
14 *  You should have received a copy of the GNU General Public License
15 *  along with this program; if not, write to the Free Software
16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 *
18 *      For questions, comments etc,
19 *      use the website at http://jeti.jabberstudio.org
20 *  or mail me at eric@jeti.tk
21 * 
22 *
23 */
24
25package nu.fw.jeti.images;
26
27import java.net.MalformedURLException;
28import java.net.URL;
29import java.util.HashMap;
30import java.util.Map;
31
32import javax.swing.Icon;
33import javax.swing.ImageIcon;
34
35import org.xml.sax.helpers.DefaultHandler;
36
37//29-12-2004
38
39/**
40 * @author E.S. de Boer
41 */
42public class RosterIconsHandler extends DefaultHandler
43{
44        private StringBuffer text = new StringBuffer();
45        private Map iconSet = new HashMap();
46        private Map rosterIcons;
47        private Icon icon;
48        private String name;
49        private String sort;
50        private String type;   
51        private URL path;
52        private Object[] data;
53
54        public RosterIconsHandler(URL path,Map icons,String type)
55    {
56                this.type=type;
57                this.path = path;
58                this.rosterIcons = icons;
59        }
60
61        public RosterIconsHandler(URL path,Object[] data)
62        {
63                this.path = path;
64                this.data = data;
65        }
66
67        public void endDocument()
68        {
69                if(data == null)
70                {
71                        rosterIcons.put(type,iconSet);
72                }
73                else data[0] = name;
74        }
75
76        public void endElement(String namespaceURI,String sName,String qName)
77        {
78                String text = this.text.toString().trim();
79                if(qName.equals("name")) name = text;
80                if(data!=null)
81                {
82                        if(qName.equals("description")) data[2] = text;
83                        //else if(qName.equals("version")) data[3] = text;
84                }
85                else
86                {
87                        if(qName.equals("x")) sort = text;
88                        if(qName.equals("graphic")) readImage(text);//old
89                        else if(qName.equals("object")) readImage(text);//new
90                        else if(qName.equals("icon"))
91                        {
92                                iconSet.put(sort,icon);
93                        }
94                }
95                this.text = new StringBuffer();
96        }
97
98        public void characters(char buf[], int offset, int Len)
99        {
100                   text.append(buf, offset, Len);
101        }
102
103        private void readImage(String resource)
104        {
105                URL picURL = null;
106                if(path==null)picURL = getClass().getClassLoader().getResource("msn_messenger-6.0/"+resource);
107                else
108                {
109                try
110                {
111                    picURL = new URL(path + resource);
112                }
113                catch (MalformedURLException ex)
114                {
115                                //System.err.println(resource +" not found");
116                        //webstart
117                }
118                }
119                if(picURL ==null) System.err.println(resource +" not found");
120                else icon =new ImageIcon(picURL);
121        }
122}
123/*
124 * Overrides for emacs
125 * Local variables:
126 * tab-width: 4
127 * End:
128 */
Note: See TracBrowser for help on using the repository browser.