What technology to use to write systray front-end to webapp?

Go To StackoverFlow.com

2

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:

  • The systray itself? Java Swing?
  • Communication between the server and the systray? Webservice? RSS feed? Spring remoting? JMX Notifications?

regards,

Wim

2009-06-16 18:44
by Wim Deblauwe
What would be the target version of the JRE ? v.6 has extensive systray support. I would have the systray app poll a status page via scraping. (cause it is simple and it would work) : - Ande TURNER 2009-06-16 19:09


3

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();
    }
    
2009-06-16 20:00
by David Rabinowitz
I have extensive Swing experience but no SWT experience. Would it make sense to move to SWT for this - Wim Deblauwe 2009-06-17 10:51
From a technological perspective, no. As far as I understand, all you want is a small monitoring application for your server. I don't believe that learning new technology just for this will be the best use of your time (unless you want to use it as an educational project) - David Rabinowitz 2009-06-17 11:00


1

With Adobe AIR and BlazeDS or LCDS you can easily build this type of application.

2009-06-16 19:20
by James Ward
Yes, but I forgot an important requirement. The systray should also be able to start an arbitrary application. I have read that you cannot start an application from AIR because of sandbox restrictions - Wim Deblauwe 2009-06-17 10:52
Maybe something like Merapi will help with that - James Ward 2009-06-17 17:48
Thanks for that, seems interesting. This is the link if people are wondering: http://merapiproject.net - Wim Deblauwe 2009-06-18 07:53


0

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.

2009-06-16 19:26
by Birger
Well, rather "just one single executable for every single platform you want to support" and probably one single set of source as well as the native APIs for systray icons are everything but standardized - Fredrik 2009-06-16 19:30


0

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.

2009-06-16 19:54
by Robert Munteanu
Thanks for the input. I am hoping to still get some more answers on the communication between server and systray par - Wim Deblauwe 2009-06-17 10:54
Would any additions to my answer help? Additional info about your needs would help - Robert Munteanu 2009-06-17 11:31
Yes, what do you mean by XML REST like service? Are there any things in Spring or any other library that would help with that - Wim Deblauwe 2009-06-18 07:54
Ads