Package com.fiveht.tick.ui.menu

Source Code of com.fiveht.tick.ui.menu.AboutMenuItem

/*
* Copyright (C) 2012 FiveHT Media Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package com.fiveht.tick.ui.menu;

import com.fiveht.tick.Metadata;
import com.fiveht.tick.ui.Icons;
import com.fiveht.tick.ui.View;
import com.fiveht.tick.ui.icon.Category;
import com.fiveht.tick.ui.icon.Size;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JEditorPane;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkEvent.EventType;
import javax.swing.event.HyperlinkListener;

/**
*
* @author Nathan Crause
*/
public class AboutMenuItem extends JMenuItem implements ActionListener {
   
    private View view;

    public AboutMenuItem(View view) {
        super("About", Icons.get(Size._16x16, Category.STATUS, "dialog-information.png"));
       
        this.view = view;
       
        init();
    }
   
    private void init() {
        setToolTipText("About this application");
        setMnemonic(KeyEvent.VK_A);
        addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JEditorPane pane = new JEditorPane("text/html",
                "<html>"
                + "<body>"
                + "<h1>Tick Java Desktop</h1>"
                + "<p>version: " + Metadata.VERSION + "</p>"
                + "<p><strong>The Tickspot&reg; Desktop Application for Java&reg;</strong></p>"
                + "<p>Copyright &copy; 2012 <a href=\"http://www.fiveht.com/\">FiveHT Media Ltd</a>.</p>"
                + "<p>This software is released under the <a href=\"http://www.gnu.org/licenses/gpl-3.0.html\">GNU General Public License version 3</a>.</p>"
                + "</body>"
                + "</html>");
       
        pane.setEditable(false);
        pane.setOpaque(false);
        pane.setBackground(new Color(0, 0, 0, 0));
        pane.addHyperlinkListener(new HyperlinkListener() {
            @Override
            public void hyperlinkUpdate(HyperlinkEvent e) {
                if (e.getEventType() == EventType.ACTIVATED) {
                    try {
                        Desktop.getDesktop().browse(e.getURL().toURI());
                    }
                    catch (Exception ex) {
                        Logger.getLogger(AboutMenuItem.class.getName()).log(Level.SEVERE, null, ex);
                       
                        JOptionPane.showMessageDialog(view, ex, "Exception", JOptionPane.ERROR_MESSAGE);
                    }
                }
            }
        });
       
        JOptionPane.showMessageDialog(view, pane, "About Tick Java Desktop", JOptionPane.INFORMATION_MESSAGE, new ImageIcon(AboutMenuItem.class.getResource("/com/fiveht/tick/icons/clock-medium.png")));
    }
   
}
TOP

Related Classes of com.fiveht.tick.ui.menu.AboutMenuItem

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.