source: trunk/jabberit_messenger/java_source/src/nu/fw/jeti/ui/Jeti.java @ 1001

Revision 1001, 22.5 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) 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                if(Preferences.getBoolean("jeti","jetimenuShowOptions",true))
458        {
459                        menuItem = new JMenuItem(I18N.gettext("main.main.jetimenu.Options")+"...");
460                        I18N.setMnemonic("main.main.jetimenu.Options",menuItem);
461                        menuItem.addActionListener(new java.awt.event.ActionListener()
462                        {
463                                public void actionPerformed(ActionEvent e)
464                                {
465                                        new OptionsWindow(backend).setVisible(true);
466                                }
467                        });
468                    addMenuItem(menuItem);
469        }
470       
471        menuItem = new JMenuItem();
472                I18N.setTextAndMnemonic("main.main.jetimenu.About",menuItem,true);
473                menuItem.addActionListener(new java.awt.event.ActionListener()
474                {
475                        public void actionPerformed(ActionEvent e)
476                        {
477                                new AboutWindow().setVisible(true);
478                        }
479                });
480        addMenuItem(menuItem);
481        if(Preferences.getBoolean("jeti","jetimenuShowExit",true))
482        {
483                        final JMenuItem menuItem2 = new JMenuItem(I18N.gettext("main.main.jetimenu.Exit"));
484                        I18N.setMnemonic("main.main.jetimenu.Exit",menuItem2);
485                        menuItem2.addActionListener(new java.awt.event.ActionListener()
486                        {
487                                public void actionPerformed(ActionEvent e)
488                                {
489                                        //menuItem2.removeActionListener(this);
490                                        close();
491                                }
492                        });
493                addMenuItem(menuItem2);
494        }
495                heightInvalid=true;
496        }
497
498        protected void saveOpenGroups()
499        {
500                List groups = onlinePanel.getOpenGroups();
501                if(groups != null)      backend.send(new InfoQuery("set",new IQPrivate(new JetiPrivateRosterExtension((String[]) groups.toArray(new String[] {})))));
502        }
503       
504        public void openGroups(final JetiPrivateRosterExtension extension)
505        {
506                SwingUtilities.invokeLater(new Runnable()
507                {
508               
509                        public void run()
510                        {
511                                onlinePanel.openGroups(extension);
512                                serverPanel.openGroups();
513                        }
514                });
515        }
516       
517        public void updateLF()
518        {
519        if (popupMenu != null)
520        {
521            SwingUtilities.updateComponentTreeUI(popupMenu);
522        }
523       
524        if (popdownMenu != null)
525        {
526            SwingUtilities.updateComponentTreeUI(popdownMenu);
527        }
528        btnStatus.updateLF();
529                onlinePanel.updateLF();
530                //offlinePanel.updateLF();
531                serverPanel.updateLF();
532        }
533       
534        public void changeOFFlinePanel(boolean show)
535        {
536                if(show)
537                {
538                        pnlRoster.remove(empty);
539                        //pnlRoster.add(offlinePanel, BorderLayout.CENTER);
540                }
541                else
542                {
543                        //pnlRoster.remove(offlinePanel);
544                        pnlRoster.add(empty, BorderLayout.CENTER);
545                }
546                pnlRoster.validate();
547                pnlRoster.repaint();
548        }
549       
550       
551        /**
552         *  translate the main display if another locale is choosen
553         */
554        public void translate()
555        {
556                preferencesChanged();
557                onlinePanel.createPopupMenu();
558                onlinePanel.setBorder(new TitledBorder(BorderFactory.createEmptyBorder(), I18N.gettext("main.main.List_Contacts")));
559        }
560       
561        public void refreshBackgroundImage()
562        {
563                String image = Preferences.getString("jeti", "backgroundImage", null);
564               
565                if(image != null)
566                {
567                        if(Start.applet)
568                        {
569                                try
570                                {
571                                        URL url= new URL(image);
572                                        backgroundImage = new ImageIcon(url).getImage();
573                                }
574                                catch(MalformedURLException e)
575                                {
576                                        e.printStackTrace();
577                                }
578                        }
579                        else backgroundImage = new ImageIcon(image).getImage();
580                }
581                repaint();
582        }
583
584        public void preferencesChanged()
585        {
586                initMenu(); //remake options
587                StatusButton.reloadMessages();
588        }
589       
590        /*--------------------Status Change events----------------------------------*/
591        public void presenceChanged(Presence presence)
592        {
593                JIDStatus jidStatus = backend.getJIDStatus(presence.getFrom());
594                String nick = null;
595                if (jidStatus != null) nick = jidStatus.getNick();
596                if (nick == null) nick = presence.getFrom().getUser();
597                if(jetiFrame!=null) jetiFrame.initTimer(nick,Presence.toLongShow(presence.getShow()));
598                //beep();
599                //chatWindows.presenceChanged(presence);
600        }
601       
602        public void ownPresenceChanged(int astatus, String amessage)
603        {
604                this.status = astatus;
605                this.message = amessage;
606        btnStatus.ownPresenceChanged(status, message);
607        Runnable updateAComponent = new Runnable()
608        {
609            public void run()
610            {
611                if( jetiFrame != null )
612                {
613                    ImageIcon icon = StatusIcons.getStatusIcon(status);
614                    jetiFrame.setIconImage(icon.getImage());
615                }
616            }
617        };
618        SwingUtilities.invokeLater(updateAComponent);
619        }
620       
621        public void connectionChanged(boolean online)
622        {
623                if ( online )
624                {
625                        if( jetiFrame != null)
626                                jetiFrame.setTitle(TITLE);
627                        onlinePanel.setVisible(true);
628                        serverPanel.setVisible(true);
629                }
630                else
631                {
632                        btnStatus.connectionOffline();
633            Runnable updateAComponent = new Runnable() {
634                public void run() {
635                        onlinePanel.setVisible(false);
636                        serverPanel.setVisible(false);
637                    if(jetiFrame!=null) {
638                                                jetiFrame.setTitle(I18N.gettext("main.main.Offline"));
639                                                jetiFrame.setIconImage(
640                            StatusIcons.getOfflineIcon().getImage());
641                    }
642                }
643            };
644            SwingUtilities.invokeLater(updateAComponent);
645                }
646        }
647
648        public void exit()
649        {
650                //if size of main window changed save
651                Window w = jetiDialog == null ? (Window)jetiFrame : (Window)jetiDialog;
652               
653                if( w != null )
654                {
655                        Preferences.putInteger("jeti","height",w.getHeight());
656                        Preferences.putInteger("jeti","width",w.getWidth());
657                        Preferences.putInteger("jeti","posX",w.getX());
658                        Preferences.putInteger("jeti","posY",w.getY());
659                        Preferences.putInteger("jeti","dividerLocation",jSplitPane1.getDividerLocation());
660                        Preferences.save();
661                }
662                chatWindows.exit();
663        }
664       
665        public void paint (Graphics g)
666        {
667                super.paint(g);
668                if(backgroundImage!=null)
669                {
670                        if(Preferences.getBoolean("jeti","backgroundImageScaled",true))
671                        {
672                                g.drawImage(backgroundImage, 0, 0,getWidth(),getHeight(), null);
673                        }
674                        else
675                        {
676                                g.drawImage(backgroundImage, 0, 0,null);
677                        }
678                }
679                paintChildren(g);
680        }
681
682        static {
683                JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP).addActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 1),new DefaultEditorKit.PasteAction());
684                JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP).addActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 2),new DefaultEditorKit.CopyAction());
685                JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP).addActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 1),new DefaultEditorKit.CutAction());
686                Action findAction = new FindAction();
687                JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP).addActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_F, 2),findAction);
688                JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP).addActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0),findAction);
689        }
690       
691        //only for filetransfer drag&drop
692        public RosterTree getOnlinePanel()
693        {
694        return onlinePanel;
695    }
696
697static class JetiDialog extends JDialog
698{
699        public JetiDialog(JFrame frame)
700        {
701                super(frame);
702        }
703
704        public void init(final Jeti jeti)
705        {
706                setContentPane(jeti);
707                this.setTitle(TITLE);
708                if (PluginsInfo.isPluginLoaded("systemtray")) setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
709                else
710                {
711                        addWindowListener(new java.awt.event.WindowAdapter()
712                        {
713                                public void windowClosing(WindowEvent e)
714                                {
715                                        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
716                                        jeti.close();
717                                }
718                        });
719                }
720               
721                int heigth = Preferences.getInteger("jeti","height",0);
722                int width = Preferences.getInteger("jeti","width",0);
723                if( heigth ==0 || width == 0) pack();
724                else setSize(width,heigth);
725                int x = Preferences.getInteger("jeti","posX",50);
726                int y = Preferences.getInteger("jeti","posY",50);
727                int screenX = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
728                int screenY = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
729                if(x>screenX) x=50;
730                if(y>screenY) y=50;
731                setLocation(x,y);
732        }
733}
734
735
736static class JetiFrame extends JFrame
737{
738        private TitleTimer timer = new TitleTimer(this, TITLE);
739       
740       
741        public void init(final Jeti jeti)
742        {
743                setContentPane(jeti);
744                setIconImage(StatusIcons.getOfflineIcon().getImage());
745                this.setTitle(TITLE);
746                if (PluginsInfo.isPluginLoaded("systemtray")) setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
747                else
748                {
749                        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
750                        addWindowListener(new java.awt.event.WindowAdapter()
751                        {
752                                public void windowClosing(WindowEvent e)
753                                {
754                                        jeti.close();
755                                }
756                        });
757                }
758               
759                int heigth = Preferences.getInteger("jeti","height",0);
760                int width = Preferences.getInteger("jeti","width",0);
761                if( heigth ==0 || width == 0) pack();
762                else setSize(width,heigth);
763                int x = Preferences.getInteger("jeti","posX",50);
764                int y = Preferences.getInteger("jeti","posY",50);
765                int screenX = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
766                int screenY = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
767                if(x>screenX) x=50;
768                if(y>screenY) y=50;
769                setLocation(x,y);
770        }
771       
772        public void initTimer(String nick, String status)
773        {
774                timer.init(nick,status);
775        }
776}
777
778        static class OnlineSelector implements TreeModelSelector
779        {
780        public boolean isVisible(Object o)
781        {
782                        if (o instanceof JIDStatus)
783                        {
784                return ((JIDStatus)o).isOnline();
785            }
786                        else if (o instanceof PrimaryJIDStatus)
787                        {
788                return ((PrimaryJIDStatus)o).getJIDPrimaryStatus().isOnline();
789            }
790                        else if (o instanceof JIDStatusGroup)
791                        {
792                                return (((JIDStatusGroup)o).getOnlines() > 0);
793                        }
794            return false;
795        }
796    }
797
798    static  class OfflineSelector implements TreeModelSelector
799    {
800        public boolean isVisible(Object o)
801        {
802                        if (o instanceof JIDStatus)
803                        {
804                return !((JIDStatus)o).isOnline();
805            }
806                        else if (o instanceof PrimaryJIDStatus)
807                        {
808                return ((PrimaryJIDStatus)o).isAJIDstatusOffline();
809            }
810                        else if (o instanceof JIDStatusGroup)
811                        {
812                                return true;
813            }
814            return true;
815        }
816    }
817}
818/*
819 * Overrides for emacs
820 * Local variables:
821 * tab-width: 4
822 * End:
823 */
Note: See TracBrowser for help on using the repository browser.