source: 3thparty/jmessenger/src/nu/fw/jeti/jabber/elements/IQLast.java @ 3952

Revision 3952, 2.0 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #1710 - Adicao do codigo fonte java do componente jmessenger(jabberit_messenger)

  • Property svn:executable set to *
Line 
1package nu.fw.jeti.jabber.elements;
2
3import java.text.DateFormat;
4import java.text.MessageFormat;
5import java.util.Calendar;
6
7import javax.swing.JOptionPane;
8
9import nu.fw.jeti.jabber.Backend;
10import nu.fw.jeti.util.I18N;
11import nu.fw.jeti.util.Popups;
12
13/**
14 * @author E.S. de Boer
15 *
16 *
17 */
18public class IQLast extends Extension implements IQExtension
19{
20        private String seconds;
21       
22        public IQLast(){}
23       
24        public IQLast(String seconds)
25        {
26                this.seconds = seconds;
27        }
28
29        public String getSeconds(){return seconds;}
30       
31        public void execute(InfoQuery iq,Backend backend)
32        {
33                if (iq.getType().equals("get"))
34                {
35                        //TODO idle time??
36                        //sendTime(infoQuery.getFrom(),infoQuery.getID());
37                }
38                else if (iq.getType().equals("result"))
39                {
40                        lastSeenPopup(iq.getFrom().toStringNoResource(), getSeconds());
41                }
42                else if (iq.getType().equals("error"))
43                {
44                        Popups.errorPopup(iq.getErrorDescription(), I18N.gettext("main.error.Last_Seen_Error"));
45                }
46        }
47       
48        private void lastSeenPopup(String jid,String seconds)
49        {
50                int second = 0;
51                try{
52                        second = Integer.parseInt(seconds);
53                }
54                catch (NumberFormatException e)
55                {
56                        Popups.popup(MessageFormat.format(I18N.gettext("main.popup.{0}_was_last_seen_{1}_seconds_ago"),new Object[]{jid,seconds})  ,"main.popup.Last_Seen",JOptionPane.INFORMATION_MESSAGE);   
57                }
58                Calendar calendar = Calendar.getInstance();
59                //calendar.clear();   
60                calendar.add(Calendar.SECOND,-second);
61                         
62                DateFormat dateFormat = DateFormat.getDateTimeInstance();
63                Popups.popup(MessageFormat.format(I18N.gettext("main.popup.{0}_was_last_seen_on_{1}"),new Object[]{jid, dateFormat.format(calendar.getTime())}),I18N.gettext("main.popup.Last_Seen"),JOptionPane.INFORMATION_MESSAGE);
64                //JOptionPane.showMessageDialog(main,display  +"\n Time: " + time + "\n Timezone: " + timezone ,jid + "Time",javax.swing.JOptionPane.INFORMATION_MESSAGE);
65
66        }
67
68        public void appendToXML(StringBuffer xml)
69        {
70                xml.append("<query xmlns=\"jabber:iq:last\"");
71                appendAttribute(xml,"seconds",seconds);
72                xml.append("/>");
73        }
74}
75/*
76 * Overrides for emacs
77 * Local variables:
78 * tab-width: 4
79 * End:
80 */
Note: See TracBrowser for help on using the repository browser.