package view.componentes;
import util.*;
import controller.operating.GerenciadorOperacional;
import controller.operating.Strings;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.SwingUtilities;
public class IconTray {
public static SystemTray tray;
public static TrayIcon trayIcon;
public static void getInstance() {
tray = SystemTray.getSystemTray();
Imagem icone = new Imagem();
Image icon = icone.getIcone();
PopupMenu menu = new PopupMenu();
MenuItem itemAbrir = new MenuItem("Abrir");
itemAbrir.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
GerenciadorOperacional.setVisibleFramePrincipal(true);
}
});
MenuItem itemSair = new MenuItem("Sair");
itemSair.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
GerenciadorOperacional.encerrarPrograma();
}
});
menu.add(itemAbrir);
menu.addSeparator();
menu.add(itemSair);
trayIcon = new TrayIcon(icon, "Tooltip", menu);
try {
tray.add(trayIcon);
trayIcon.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
//if (e.getClickCount() == 2) {
if (SwingUtilities.isRightMouseButton(e)) {
//GerenciadorOperacional.setVisibleFramePrincipal(false);
//GerenciadorOperacional.encerrarPrograma();
} else {
if(GerenciadorOperacional.isVisibleFramePrincipal())
GerenciadorOperacional.setVisibleFramePrincipal(false);
else
GerenciadorOperacional.setVisibleFramePrincipal(true);
}
}
});
trayIcon.setToolTip(Strings.version);
trayIcon.displayMessage(Strings.version, Strings.release, TrayIcon.MessageType.NONE);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void endInstance() {
tray.remove(trayIcon);
}
}