source: branches/2.2/jabberit_messenger/java_source/src/nu/fw/jeti/ui/Jeti.java @ 3102

Revision 3102, 22.0 KB checked in by amuller, 14 years ago (diff)

Ticket #986 - Efetuado merge para o Branch 2.2( atualizacao do modulo)

  • Property svn:executable set to *
Line 
1/*
2 *      Jeti, a Java Jabber client, Copyright (C) 2001 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/IM me at jeti@jabber.org
21 */
22
23package nu.fw.jeti.ui;
24
25import java.awt.*;
26import java.awt.event.ActionEvent;
27import java.awt.event.ActionListener;
28import java.awt.event.KeyEvent;
29import java.awt.event.WindowEvent;
30import java.net.MalformedURLException;
31import java.net.URL;
32import java.util.*;
33import java.util.List;
34
35import javax.swing.*;
36import javax.swing.border.TitledBorder;
37import javax.swing.event.PopupMenuEvent;
38import javax.swing.event.PopupMenuListener;
39import javax.swing.text.DefaultEditorKit;
40import javax.swing.text.JTextComponent;
41import javax.swing.tree.TreeModel;
42
43import nu.fw.jeti.backend.Start;
44import nu.fw.jeti.backend.roster.JIDStatusGroup;
45import nu.fw.jeti.backend.roster.PrimaryJIDStatus;
46import nu.fw.jeti.events.PreferenceListener;
47import nu.fw.jeti.events.PresenceListener;
48import nu.fw.jeti.events.RosterListener;
49import nu.fw.jeti.events.StatusChangeListener;
50import nu.fw.jeti.images.StatusIcons;
51import nu.fw.jeti.jabber.Backend;
52import nu.fw.jeti.jabber.JID;
53import nu.fw.jeti.jabber.JIDStatus;
54import nu.fw.jeti.jabber.UnknownJIDStatus;
55import nu.fw.jeti.jabber.elements.*;
56import nu.fw.jeti.plugins.PluginsInfo;
57import nu.fw.jeti.plugins.RosterMenuListener;
58import nu.fw.jeti.ui.models.RosterTreeModel;
59import nu.fw.jeti.util.*;
60
61
62/**
63 * @author E.S. de Boer
64 */
65
66public class Jeti extends JPanel implements PresenceListener, StatusChangeListener, PreferenceListener
67{
68        private RosterTree onlinePanel;
69        //private RosterTree offlinePanel;
70        private JPopupMenu popupMenu;
71    private JMenu popdownMenu;
72        private JToggleButton btnJeti;
73    private StatusButton btnStatus;
74        private JPanel pnlMenuButtons;
75        private JPanel empty = new JPanel();
76        private JScrollPane jScrollPaneTop;
77        private JPanel pnlRoster;
78        private JSplitPane jSplitPane1;
79        private JScrollPane scrollPaneBottom;
80        private ServerTree serverPanel;
81        private int status;
82        private String message = "";
83        private List menuItems;
84        private JetiFrame jetiFrame;
85        private JetiDialog jetiDialog;
86        private boolean heightInvalid=true;
87        private Map rosterMenuItems= new HashMap(10);
88        private ChatWindows chatWindows;
89        private Image backgroundImage;
90
91        private Backend backend;
92
93    private static final String TITLE = "Jeti"+Start.OS2;
94
95        public Jeti(Backend backend,Container container)
96        {
97
98                if(container!=null)backend.setMain(this,null,null);
99                else
100                {
101                        jetiFrame = new JetiFrame();
102                        backend.setMain(this,jetiFrame,jetiFrame);
103                        if(Preferences.getBoolean("jeti","showNotInTaskbar",false))
104                        {
105                                jetiFrame.setIconImage(StatusIcons.getOfflineIcon().getImage());
106                                jetiDialog = new JetiDialog(jetiFrame);
107                                backend.setMain(this,jetiDialog,null);
108                        }
109                }
110                this.backend = backend;
111                               
112                backend.addListener(PresenceListener.class, this);
113                backend.addListener(StatusChangeListener.class, this);
114                backend.addListener(PreferenceListener.class, this);
115
116                RosterTreeModel model = new RosterTreeModel();
117                backend.addListener(RosterListener.class, model);
118               
119                // Exibe a lista de Contato
120                TreeModel onlineModel = model;
121
122                if (UIManager.getLookAndFeel().isNativeLookAndFeel())
123                {
124                        System.out.println("using mac hack");
125                    onlineModel = new TreeModelFilter(model, new OnlineSelector());
126                }
127               
128            onlinePanel = new RosterTree(backend, this, true, onlineModel);
129               
130                serverPanel = new ServerTree(backend, this);
131                chatWindows = new ChatWindows(backend);
132                refreshBackgroundImage();
133        }
134
135        public void init()
136        {
137                setLayout(new BorderLayout());
138                btnStatus = new StatusButton(backend, this);
139                pnlMenuButtons = new JPanel();
140                jScrollPaneTop = new JScrollPane();
141                pnlRoster = new JPanel();
142                jSplitPane1 = new JSplitPane();
143                scrollPaneBottom = new JScrollPane();
144                boolean opaque = Preferences.getBoolean("jeti","bmw",true);
145                pnlRoster.setBackground(new Color(255,255,255));
146                onlinePanel.setBackground(new Color(255,255,255));
147                serverPanel.setBackground(new Color(255,255,255));
148                jScrollPaneTop.setOpaque(opaque);
149                jScrollPaneTop.getViewport().setOpaque(opaque);
150                scrollPaneBottom.setOpaque(opaque);
151                scrollPaneBottom.getViewport().setOpaque(opaque);
152                empty.setBackground(new Color(255,255,255));
153                Font bold =(UIManager.getFont("TitledBorder.font").deriveFont(Font.BOLD));
154                scrollPaneBottom.setMinimumSize(new Dimension(22, 0));
155                jScrollPaneTop.getViewport().add(pnlRoster, null);
156                pnlMenuButtons.setLayout(new BoxLayout(pnlMenuButtons, BoxLayout.X_AXIS));
157               
158                if (Preferences.getBoolean("jeti","menutop",false))
159                {
160            createJetiMenu();
161        }
162               
163                pnlMenuButtons.add(btnStatus, null);
164               
165                add(jScrollPaneTop, BorderLayout.CENTER);
166                add(pnlMenuButtons, java.awt.BorderLayout.SOUTH);
167
168                pnlRoster.setLayout(new BorderLayout());
169                pnlRoster.add(onlinePanel, BorderLayout.CENTER);
170               
171
172                if(jetiDialog!=null)jetiDialog.init(this);
173                else if(jetiFrame!=null)jetiFrame.init(this);
174               
175                int divLoc = Preferences.getInteger("jeti","dividerLocation",-10);
176                if(divLoc == -10) jSplitPane1.setDividerLocation(0.75);
177                else jSplitPane1.setDividerLocation(divLoc);
178               
179                initMenu();
180               
181                updateLF();
182        }
183
184    private void createJetiMenu()
185    {
186        JMenuBar menuBar = new JMenuBar();
187        popdownMenu = new JMenu(TITLE);
188        popdownMenu.setMnemonic('J');
189        menuBar.add(popdownMenu);
190        jetiFrame.setJMenuBar(menuBar);
191    }
192
193    private void createBtnJeti()
194    {
195                btnJeti = new JToggleButton(TITLE);
196                btnJeti.setMnemonic('J');
197        btnJeti.setMaximumSize(new Dimension(500, 23));
198                btnJeti.setMargin(new Insets(0, 0, 0, 0));
199                btnJeti.addActionListener(new java.awt.event.ActionListener()
200                {
201                        public void actionPerformed(ActionEvent e)
202                        {
203               
204                                if (heightInvalid)
205                                {
206                                        popupMenu.show(Jeti.this, 0, 0);
207                                        popupMenu.setVisible(false);
208                            heightInvalid = false;
209                        }
210                                popupMenu.show(Jeti.this, btnJeti.getX(), btnJeti.getY() + pnlMenuButtons.getY() - popupMenu.getHeight() );
211                        }
212                });
213        popupMenu = new JPopupMenu();
214        popupMenu.addPopupMenuListener(new PopupMenuListener()
215        {
216       
217            public void popupMenuWillBecomeInvisible(PopupMenuEvent e)
218            {
219                btnJeti.setSelected(false);
220            }
221            public void popupMenuWillBecomeVisible(PopupMenuEvent e)
222            {}
223            public void popupMenuCanceled(PopupMenuEvent e)
224            {}
225        });
226    }
227
228        public void close()
229        {
230                if(chatWindows.askIfClose())
231                {
232                        saveOpenGroups();
233                        Container w = backend.getMainWindow();
234                        if(w!=null && w instanceof Window)((Window)w).dispose();
235                        System.out.println("Exiting, closing connection please wait....");
236                        //todo disconnect backend.disconnect(); and exit instead of only exit
237                        backend.exit();
238                        backend=null;
239                }
240        }
241
242        private void startChat(final boolean message)
243        {
244                final JDialog dialog = new JDialog(backend.getMainFrame());
245                if(message)dialog.setTitle(I18N.gettext("main.main.jetimenu.Message"));
246                else dialog.setTitle(I18N.gettext("main.main.jetimenu.Chat"));
247                final JIDInput jidInput = new JIDInput(backend);
248                JButton btnOK = new JButton(I18N.gettext("OK"));
249                btnOK.addActionListener(new ActionListener()
250                {
251                        public void actionPerformed(ActionEvent e)
252                        {
253                                JID jid  = jidInput.createJID();
254                                if(jid==null)return;
255                                if(message) new SendMessage(backend,jid,jid.getUser()).setVisible(true);
256                                else startChat(jid);
257                                dialog.dispose();
258                        }
259                });
260                JButton btnCancel = new JButton();
261                dialog.getRootPane().setDefaultButton(btnOK);
262                dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
263               
264                Action cancelAction = new AbstractAction(I18N.gettext("Cancel"))
265                {
266                        public void actionPerformed(ActionEvent e)
267                        {
268                                dialog.dispose();
269                        }
270                };
271                Utils.addCancelButton(dialog, btnCancel, cancelAction);
272                Box panel1 = Box.createVerticalBox();
273                panel1.add(Box.createHorizontalGlue());
274                JPanel jPanel1 = new JPanel();
275                jPanel1.add(btnOK);
276                jPanel1.add(btnCancel);
277                panel1.add(jidInput);
278                panel1.add(jPanel1);
279                dialog.getContentPane().add(panel1, BorderLayout.CENTER);
280                dialog.pack();
281                dialog.setLocationRelativeTo(this);
282                dialog.setVisible(true);
283        }
284       
285        public void startChat(JID jid)
286        {
287                if (jid == null)
288                        return;
289                chatWindows.chat(new UnknownJIDStatus(jid));
290        }
291       
292        public void startChatResource(JIDStatus jidstatus)
293        {
294                chatWindows.chatResource(jidstatus);
295        }
296       
297        public void chat(JIDStatus jidStatus)
298        {
299                chatWindows.chat(jidStatus);
300        }
301       
302        public JPanel createChatPanel(JIDStatus jidStatus)
303        {
304                return chatWindows.createChatPanel(jidStatus);
305        }
306       
307        public void addToMenu(JMenuItem menuItem)
308        {
309                if( menuItems == null )
310                        menuItems = new LinkedList();
311                menuItems.add(menuItem);
312                initMenu();
313        }
314       
315        public Map getRosterMenuItems()
316        {
317                return rosterMenuItems;
318        }
319       
320        public void removeFromMenu(JMenuItem menuItem)
321        {
322                menuItems.remove(menuItem);
323                if(menuItems.isEmpty()) menuItems = null;
324                initMenu();
325        }
326
327        public void addToRosterMenu(String name, RosterMenuListener listener)
328        {
329                onlinePanel.addToMenu(name, listener);
330                //offlinePanel.addToMenu(name, listener);
331                rosterMenuItems.put(name,listener);
332        }
333       
334        public void removeFromRosterMenu(String name)
335        {
336                onlinePanel.removeFromMenu(name);
337                //offlinePanel.removeFromMenu(name);
338                rosterMenuItems.remove(name);
339        }
340       
341        public void addToOnlineRosterMenu(String name, RosterMenuListener listener)
342        {
343                onlinePanel.addToMenu(name, listener);
344                rosterMenuItems.put(name,listener);
345        }
346       
347        public void removeFromOnlineRosterMenu(String name)
348        {
349                onlinePanel.removeFromMenu(name);
350                rosterMenuItems.remove(name);
351        }
352       
353        public void addToOfflineRosterMenu(String name, RosterMenuListener listener)
354        {
355                //offlinePanel.addToMenu(name, listener);
356        }
357       
358        public void removeFromOfflineRosterMenu(String name)
359        {
360                //offlinePanel.removeFromMenu(name);
361        }
362
363    private void addMenuItem(JMenuItem item)
364    {
365        if (popupMenu != null)
366        {
367            popupMenu.add(item);
368        }
369        else
370        {
371            popdownMenu.add(item);
372        }
373    }
374
375        private void initMenu()
376        {
377                //JETI menu
378        if ( popdownMenu == null && popupMenu == null )
379            return;
380
381        if ( popdownMenu != null )
382            popdownMenu.removeAll();
383        else
384            popupMenu.removeAll();
385               
386        JMenuItem menuItem = null;
387                JMenu subMenu = null;
388               
389                if(Preferences.getBoolean("jeti","jetimenuShowMessage",true))
390                {
391                        menuItem = new JMenuItem(I18N.gettext("main.main.jetimenu.Message")+"...");
392                        I18N.setMnemonic("main.main.jetimenu.Message",menuItem); 
393                        menuItem.addActionListener(new java.awt.event.ActionListener()
394                        {
395                                public void actionPerformed(ActionEvent e)
396                                {
397                                        startChat(true); 
398                                }
399                        });
400                addMenuItem(menuItem);
401                }
402               
403                if(Preferences.getBoolean("jeti","jetimenuShowChat",true))
404                {
405                        menuItem = new JMenuItem(I18N.gettext("main.main.jetimenu.Chat")+"...");
406                        I18N.setMnemonic("main.main.jetimenu.Chat",menuItem);
407                        menuItem.addActionListener(new java.awt.event.ActionListener()
408                        {
409                                public void actionPerformed(ActionEvent e)
410                                {
411                                        startChat(false);
412                                }
413                        });
414                addMenuItem(menuItem);
415                }
416               
417                if(Preferences.getBoolean("jeti","jetimenuShowAddContact",true))
418                {
419                        menuItem = new JMenuItem(I18N.gettext("main.main.jetimenu.Add_Contact")+"...");
420                        I18N.setMnemonic("main.main.jetimenu.Add_Contact",menuItem);
421                        menuItem.addActionListener(new java.awt.event.ActionListener()
422                        {
423                                public void actionPerformed(ActionEvent e)
424                                {
425                                        new AddContact(backend).setVisible(true);
426                                }
427                        });
428                addMenuItem(menuItem);
429                }
430               
431                //add plugin menus
432                if( menuItems != null )
433                {
434                        for(Iterator i = menuItems.iterator();i.hasNext();)
435                        {
436                                JMenuItem item = (JMenuItem)i.next();
437                addMenuItem(item);
438                        }
439                }
440               
441                menuItem = new JMenuItem();
442               
443                if(Preferences.getBoolean("jeti","jetimenuShowLog",true))
444                {
445                I18N.setTextAndMnemonic("main.main.jetimenu.Show_Log",menuItem,true);
446                        menuItem.addActionListener(new java.awt.event.ActionListener()
447                        {
448                                public void actionPerformed(ActionEvent e)
449                                {
450                                        serverPanel.clearError();
451                                        new LogWindow(backend).setVisible(true);
452                                }
453                        });
454                        addMenuItem(menuItem);
455                }
456       
457        menuItem = new JMenuItem();
458                I18N.setTextAndMnemonic("main.main.jetimenu.About",menuItem,true);
459                menuItem.addActionListener(new java.awt.event.ActionListener()
460                {
461                        public void actionPerformed(ActionEvent e)
462                        {
463                                new AboutWindow().setVisible(true);
464                        }
465                });
466        addMenuItem(menuItem);
467        if(Preferences.getBoolean("jeti","jetimenuShowExit",true))
468        {
469                        final JMenuItem menuItem2 = new JMenuItem(I18N.gettext("main.main.jetimenu.Exit"));
470                        I18N.setMnemonic("main.main.jetimenu.Exit",menuItem2);
471                        menuItem2.addActionListener(new java.awt.event.ActionListener()
472                        {
473                                public void actionPerformed(ActionEvent e)
474                                {
475                                        //menuItem2.removeActionListener(this);
476                                        close();
477                                }
478                        });
479                addMenuItem(menuItem2);
480        }
481                heightInvalid=true;
482        }
483
484        protected void saveOpenGroups()
485        {
486                List groups = onlinePanel.getOpenGroups();
487                if(groups != null)      backend.send(new InfoQuery("set",new IQPrivate(new JetiPrivateRosterExtension((String[]) groups.toArray(new String[] {})))));
488        }
489       
490        public void openGroups(final JetiPrivateRosterExtension extension)
491        {
492                SwingUtilities.invokeLater(new Runnable()
493                {
494               
495                        public void run()
496                        {
497                                onlinePanel.openGroups(extension);
498                                serverPanel.openGroups();
499                        }
500                });
501        }
502       
503        public void updateLF()
504        {
505        if (popupMenu != null)
506        {
507            SwingUtilities.updateComponentTreeUI(popupMenu);
508        }
509       
510        if (popdownMenu != null)
511        {
512            SwingUtilities.updateComponentTreeUI(popdownMenu);
513        }
514        btnStatus.updateLF();
515                onlinePanel.updateLF();
516                //offlinePanel.updateLF();
517                serverPanel.updateLF();
518        }
519       
520        public void changeOFFlinePanel(boolean show)
521        {
522                if(show)
523                {
524                        pnlRoster.remove(empty);
525                        //pnlRoster.add(offlinePanel, BorderLayout.CENTER);
526                }
527                else
528                {
529                        //pnlRoster.remove(offlinePanel);
530                        pnlRoster.add(empty, BorderLayout.CENTER);
531                }
532                pnlRoster.validate();
533                pnlRoster.repaint();
534        }
535       
536       
537        /**
538         *  translate the main display if another locale is choosen
539         */
540        public void translate()
541        {
542                preferencesChanged();
543                onlinePanel.createPopupMenu();
544                onlinePanel.setBorder(new TitledBorder(BorderFactory.createEmptyBorder(), I18N.gettext("main.main.List_Contacts")));
545        }
546       
547        public void refreshBackgroundImage()
548        {
549                String image = Preferences.getString("jeti", "backgroundImage", null);
550               
551                if(image != null)
552                {
553                        if(Start.applet)
554                        {
555                                try
556                                {
557                                        URL url= new URL(image);
558                                        backgroundImage = new ImageIcon(url).getImage();
559                                }
560                                catch(MalformedURLException e)
561                                {
562                                        e.printStackTrace();
563                                }
564                        }
565                        else backgroundImage = new ImageIcon(image).getImage();
566                }
567                repaint();
568        }
569
570        public void preferencesChanged()
571        {
572                initMenu(); //remake options
573                StatusButton.reloadMessages();
574        }
575       
576        /*--------------------Status Change events----------------------------------*/
577        public void presenceChanged(Presence presence)
578        {
579                JIDStatus jidStatus = backend.getJIDStatus(presence.getFrom());
580                String nick = null;
581                if (jidStatus != null) nick = jidStatus.getNick();
582                if (nick == null) nick = presence.getFrom().getUser();
583                if(jetiFrame!=null) jetiFrame.initTimer(nick,Presence.toLongShow(presence.getShow()));
584                //beep();
585                //chatWindows.presenceChanged(presence);
586        }
587       
588        public void ownPresenceChanged(int astatus, String amessage)
589        {
590                this.status = astatus;
591                this.message = amessage;
592        btnStatus.ownPresenceChanged(status, message);
593        Runnable updateAComponent = new Runnable()
594        {
595            public void run()
596            {
597                if( jetiFrame != null )
598                {
599                    ImageIcon icon = StatusIcons.getStatusIcon(status);
600                    jetiFrame.setIconImage(icon.getImage());
601                }
602            }
603        };
604        SwingUtilities.invokeLater(updateAComponent);
605        }
606       
607        public void connectionChanged(boolean online)
608        {
609                if ( online )
610                {
611                        if( jetiFrame != null)
612                                jetiFrame.setTitle(TITLE);
613                        onlinePanel.setVisible(true);
614                        serverPanel.setVisible(true);
615                }
616                else
617                {
618                        btnStatus.connectionOffline();
619            Runnable updateAComponent = new Runnable() {
620                public void run() {
621                        onlinePanel.setVisible(false);
622                        serverPanel.setVisible(false);
623                    if(jetiFrame!=null) {
624                                                jetiFrame.setTitle(I18N.gettext("main.main.Offline"));
625                                                jetiFrame.setIconImage(
626                            StatusIcons.getOfflineIcon().getImage());
627                    }
628                }
629            };
630            SwingUtilities.invokeLater(updateAComponent);
631                }
632        }
633
634        public void exit()
635        {
636                //if size of main window changed save
637                Window w = jetiDialog == null ? (Window)jetiFrame : (Window)jetiDialog;
638               
639                if( w != null )
640                {
641                        Preferences.putInteger("jeti","height",w.getHeight());
642                        Preferences.putInteger("jeti","width",w.getWidth());
643                        Preferences.putInteger("jeti","posX",w.getX());
644                        Preferences.putInteger("jeti","posY",w.getY());
645                        Preferences.putInteger("jeti","dividerLocation",jSplitPane1.getDividerLocation());
646                        Preferences.save();
647                }
648                chatWindows.exit();
649        }
650       
651        public void paint (Graphics g)
652        {
653                super.paint(g);
654                if(backgroundImage!=null)
655                {
656                        if(Preferences.getBoolean("jeti","backgroundImageScaled",true))
657                        {
658                                g.drawImage(backgroundImage, 0, 0,getWidth(),getHeight(), null);
659                        }
660                        else
661                        {
662                                g.drawImage(backgroundImage, 0, 0,null);
663                        }
664                }
665                paintChildren(g);
666        }
667
668        static {
669                JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP).addActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 1),new DefaultEditorKit.PasteAction());
670                JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP).addActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 2),new DefaultEditorKit.CopyAction());
671                JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP).addActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 1),new DefaultEditorKit.CutAction());
672                Action findAction = new FindAction();
673                JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP).addActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_F, 2),findAction);
674                JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP).addActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0),findAction);
675        }
676       
677        //only for filetransfer drag&drop
678        public RosterTree getOnlinePanel()
679        {
680        return onlinePanel;
681    }
682
683static class JetiDialog extends JDialog
684{
685        public JetiDialog(JFrame frame)
686        {
687                super(frame);
688        }
689
690        public void init(final Jeti jeti)
691        {
692                setContentPane(jeti);
693                this.setTitle(TITLE);
694                if (PluginsInfo.isPluginLoaded("systemtray")) setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
695                else
696                {
697                        addWindowListener(new java.awt.event.WindowAdapter()
698                        {
699                                public void windowClosing(WindowEvent e)
700                                {
701                                        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
702                                        jeti.close();
703                                }
704                        });
705                }
706               
707                int heigth = Preferences.getInteger("jeti","height",0);
708                int width = Preferences.getInteger("jeti","width",0);
709                if( heigth ==0 || width == 0) pack();
710                else setSize(width,heigth);
711                int x = Preferences.getInteger("jeti","posX",50);
712                int y = Preferences.getInteger("jeti","posY",50);
713                int screenX = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
714                int screenY = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
715                if(x>screenX) x=50;
716                if(y>screenY) y=50;
717                setLocation(x,y);
718        }
719}
720
721
722static class JetiFrame extends JFrame
723{
724        private TitleTimer timer = new TitleTimer(this, TITLE);
725       
726       
727        public void init(final Jeti jeti)
728        {
729                setContentPane(jeti);
730                setIconImage(StatusIcons.getOfflineIcon().getImage());
731                this.setTitle(TITLE);
732                if (PluginsInfo.isPluginLoaded("systemtray")) setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
733                else
734                {
735                        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
736                        addWindowListener(new java.awt.event.WindowAdapter()
737                        {
738                                public void windowClosing(WindowEvent e)
739                                {
740                                        jeti.close();
741                                }
742                        });
743                }
744               
745                int heigth = Preferences.getInteger("jeti","height",0);
746                int width = Preferences.getInteger("jeti","width",0);
747                if( heigth ==0 || width == 0) pack();
748                else setSize(width,heigth);
749                int x = Preferences.getInteger("jeti","posX",50);
750                int y = Preferences.getInteger("jeti","posY",50);
751                int screenX = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
752                int screenY = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
753                if(x>screenX) x=50;
754                if(y>screenY) y=50;
755                setLocation(x,y);
756        }
757       
758        public void initTimer(String nick, String status)
759        {
760                timer.init(nick,status);
761        }
762}
763
764        static class OnlineSelector implements TreeModelSelector
765        {
766        public boolean isVisible(Object o)
767        {
768                        if (o instanceof JIDStatus)
769                        {
770                return ((JIDStatus)o).isOnline();
771            }
772                        else if (o instanceof PrimaryJIDStatus)
773                        {
774                return ((PrimaryJIDStatus)o).getJIDPrimaryStatus().isOnline();
775            }
776                        else if (o instanceof JIDStatusGroup)
777                        {
778                                return (((JIDStatusGroup)o).getOnlines() > 0);
779                        }
780            return false;
781        }
782    }
783
784    static  class OfflineSelector implements TreeModelSelector
785    {
786        public boolean isVisible(Object o)
787        {
788                        if (o instanceof JIDStatus)
789                        {
790                return !((JIDStatus)o).isOnline();
791            }
792                        else if (o instanceof PrimaryJIDStatus)
793                        {
794                return ((PrimaryJIDStatus)o).isAJIDstatusOffline();
795            }
796                        else if (o instanceof JIDStatusGroup)
797                        {
798                                return true;
799            }
800            return true;
801        }
802    }
803}
804/*
805 * Overrides for emacs
806 * Local variables:
807 * tab-width: 4
808 * End:
809 */
Note: See TracBrowser for help on using the repository browser.