we have an internal webapplication running on tomcat, build on Spring. The webapplication front-end is build with Flex.
I would like to create a cross-platform systray application that allows to go the home page of the application and displays alerts when certain things happen in the server.
What would you think is the best technology for:
regards,
Wim
If you want to stay with Java you have two options:
Use Swing/AWT. Make sure you are using Java 6 and above (you can install it with your application), since it has support for system tray (from the API):
TrayIcon trayIcon = null;
if (SystemTray.isSupported()) {
// get the SystemTray instance
SystemTray tray = SystemTray.getSystemTray();
// load an image
Image image = Toolkit.getDefaultToolkit.getImage("");
// create a action listener to listen for default action executed on
// the tray icon
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
// execute default action of the application
// ...
}
};
// create a popup menu
PopupMenu popup = new PopupMenu();
// create menu item for the default action
MenuItem defaultItem = new MenuItem("");
defaultItem.addActionListener(listener);
popup.add(defaultItem);
// / ... add other items
// construct a TrayIcon
trayIcon = new TrayIcon(image, "Tray Demo", popup);
// set the TrayIcon properties
trayIcon.addActionListener(listener);
// ...
// add the tray image
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.err.println(e);
}
// ...
} else {
// disable tray option in your application or
// perform other actions
// ...
}
// ...
// some time later
// the application state has changed - update the image
if (trayIcon != null) {
trayIcon.setImage(updatedImage);
}
// ...
Use SWT/JFace. Here is an example (taken from here):
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
Image image = new Image(display, 16, 16);
final Tray tray = display.getSystemTray();
if (tray == null) {
System.out.println("The system tray is not available");
} else {
final TrayItem item = new TrayItem(tray, SWT.NONE);
item.setToolTipText("SWT TrayItem");
item.addListener(SWT.Show, new Listener() {
public void handleEvent(Event event) {
System.out.println("show");
}
});
item.addListener(SWT.Hide, new Listener() {
public void handleEvent(Event event) {
System.out.println("hide");
}
});
item.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
System.out.println("selection");
}
});
item.addListener(SWT.DefaultSelection, new Listener() {
public void handleEvent(Event event) {
System.out.println("default selection");
}
});
final Menu menu = new Menu(shell, SWT.POP_UP);
for (int i = 0; i < 8; i++) {
MenuItem mi = new MenuItem(menu, SWT.PUSH);
mi.setText("Item" + i);
mi.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
System.out.println("selection " + event.widget);
}
});
if (i == 0)
menu.setDefaultItem(mi);
}
item.addListener(SWT.MenuDetect, new Listener() {
public void handleEvent(Event event) {
menu.setVisible(true);
}
});
item.setImage(image);
}
shell.setBounds(50, 50, 300, 200);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
image.dispose();
display.dispose();
}
With Adobe AIR and BlazeDS or LCDS you can easily build this type of application.
I would go for FreePascal. It compiles natively to windows / mac / linux and because of this you do not depend on any other framework (.net, java, air) to be installed. Just one single executable and that's it.
I agree with James: if you have an investment and know-how in Flex, it makes sense to extend that with Air.
As for the payload - if you simply need to 'pop up' notifications from time to time, RSS is the way to go. Otherwise, roll you own XML REST-like service, since it's easy to set up and will give you flexibility in the long run.