001    /*
002     * Copyright (C) 2008-2009 Holger Arndt, A. Naegele and M. Bundschus
003     *
004     * This file is part of the Universal Java Matrix Package (UJMP).
005     * See the NOTICE file distributed with this work for additional
006     * information regarding copyright ownership and licensing.
007     *
008     * UJMP is free software; you can redistribute it and/or modify
009     * it under the terms of the GNU Lesser General Public License as
010     * published by the Free Software Foundation; either version 2
011     * of the License, or (at your option) any later version.
012     *
013     * UJMP is distributed in the hope that it will be useful,
014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016     * GNU Lesser General Public License for more details.
017     *
018     * You should have received a copy of the GNU Lesser General Public
019     * License along with UJMP; if not, write to the
020     * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
021     * Boston, MA  02110-1301  USA
022     */
023    
024    package org.jdmp.gui.tray;
025    
026    import java.awt.Image;
027    import java.awt.MenuItem;
028    import java.awt.PopupMenu;
029    import java.awt.Toolkit;
030    import java.awt.TrayIcon;
031    import java.awt.event.ActionEvent;
032    import java.awt.event.ActionListener;
033    import java.awt.event.MouseEvent;
034    import java.awt.event.MouseListener;
035    
036    import org.ujmp.gui.util.TaskQueue;
037    
038    public class DefaultTrayIcon extends TrayIcon implements ActionListener {
039    
040            private static Image image = Toolkit.getDefaultToolkit().getImage("jdmp16.png");
041    
042            public DefaultTrayIcon() {
043                    super(image);
044                    setToolTip("JDMP");
045    
046                    TaskQueue.addActionListener(this);
047    
048                    MouseListener mouseListener = new MouseListener() {
049    
050                            public void mouseClicked(MouseEvent e) {
051                                    if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
052                                            // Workspace.getInstance().showFrame();
053                                    }
054                            }
055    
056                            public void mouseEntered(MouseEvent e) {
057                            }
058    
059                            public void mouseExited(MouseEvent e) {
060                            }
061    
062                            public void mousePressed(MouseEvent e) {
063                            }
064    
065                            public void mouseReleased(MouseEvent e) {
066                            }
067                    };
068    
069                    PopupMenu popup = new PopupMenu();
070    
071                    MenuItem exitItem = new MenuItem("Exit");
072                    ActionListener exitListener = new ActionListener() {
073    
074                            public void actionPerformed(ActionEvent e) {
075                                    // new ExitAction().call();
076                            }
077                    };
078                    exitItem.addActionListener(exitListener);
079                    popup.add(exitItem);
080    
081                    setPopupMenu(popup);
082    
083                    ActionListener actionListener = new ActionListener() {
084                            public void actionPerformed(ActionEvent e) {
085                                    displayMessage("Action Event", "An Action Event Has Been Peformed!",
086                                                    TrayIcon.MessageType.INFO);
087                            }
088                    };
089    
090                    setImageAutoSize(true);
091                    addActionListener(actionListener);
092                    addMouseListener(mouseListener);
093    
094            }
095    
096            public void actionPerformed(ActionEvent e) {
097                    displayMessage("New task added", e.getActionCommand(), TrayIcon.MessageType.INFO);
098            }
099    
100    }