if (SystemTray.isSupported()) {
// allow proper shutdown
System.setProperty("org.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES","false");
SystemTray tray = SystemTray.getSystemTray();
// create menu
PopupMenu popup = new PopupMenu();
//MenuItem mainPage = createMenuItem("Start Page", "http://"+getServerName()+":"+getServerPort()+"/");
//popup.add(mainPage);
//popup.addSeparator();
// launch browser action
MenuItem admin = createMenuItem("Administration","http://"+getServerName()+":"+getServerPort()+"/");
popup.add(admin);
// admin links
for(final Map.Entry<String,String> linkEntry : adminLinks.entrySet()) {
MenuItem entry = createMenuItem(linkEntry.getKey(),linkEntry.getValue());
popup.add(entry);
}
// shutdown action
MenuItem shutdown = new MenuItem("Shutdown");
try {
Class.forName("org.apache.catalina.mbeans.MBeanUtils");
ActionListener stopListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
performServerShutdown();
}
};
shutdown.addActionListener(stopListener);
} catch (ClassNotFoundException e) {
shutdown.setEnabled(false);
}
popup.add(shutdown);
if (!demoLinks.isEmpty()) {
popup.addSeparator();
}
for(final Map.Entry<String,String> linkEntry : demoLinks.entrySet()) {
boolean containsEntry = false;
for(int i = 0; i < popup.getItemCount(); i++) {
MenuItem item = popup.getItem(i);
if(item.getLabel().equals(linkEntry.getKey())) {
containsEntry = true;
break;
}
}
if(!containsEntry) {
MenuItem entry = createMenuItem(linkEntry.getKey(),linkEntry.getValue());
popup.add(entry);
}
}
popup.addSeparator();
MenuItem about = new MenuItem("About");
about.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
MessageDialog.show("Apache Marmotta",
"About Apache Marmotta \n",
"(c)2014 The Apache Software Foundation \n" +
"Visit http://marmotta.apache.org for further details");
}
});
popup.add(about);
MenuItem issues = createMenuItem("Issues Reports", "https://issues.apache.org/jira/browse/MARMOTTA");
popup.add(issues);
MenuItem homepage = createMenuItem("Project Homepage", "http://marmotta.apache.org");
popup.add(homepage);
// load icon image
try {
Image image = ImageIO.read(SystrayListener.class.getResource("systray.png"));
icon = new TrayIcon(image,"Apache Marmotta",popup);
icon.setImageAutoSize(true);
tray.add(icon);
} catch (IOException e) {
log.error("SYSTRAY: could not load the logo for system tray",e);
} catch (AWTException e) {
log.error("SYSTRAY: tray icon could not be added");