2009-06-16 48 views
2

我们有一个运行在tomcat上的内部web应用程序,基于Spring构建。 Web应用程序前端使用Flex构建。
我想创建一个跨平台的系统托盘应用程序,它允许进入应用程序的主页,并在服务器发生某些事情时显示警报。使用什么技术将systray前端编写到webapp?

你会觉得什么是最好的技术:

  • 系统托盘本身? Java Swing?
  • 服务器和系统托盘之间的通信?网络服务? RSS订阅?春季远程? JMX通知?

问候,

维姆

+0

什么是JRE的目标版本? v.6有广泛的系统支持。我会让系统托管应用程序通过刮取轮询状态页面。 (因为它很简单,它会工作):D – 2009-06-16 19:09:47

回答

3

如果你想留在Java中,你有两个选择:

  • 使用Swing/AWT。请确保您使用的是Java 6及以上(你可以用你的应用程序安装),因为它有系统托盘支持(从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); 
    } 
    // ... 
    
  • 使用SWT/JFace。下面是一个例子(从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(); 
    } 
    
1

使用Adobe AIR和BlazeDS或LCD,你可以轻松地构建这种类型的应用。

+0

是的,但我忘了一个重要的要求。系统托盘也应该能够启动任意应用程序。我已经读过,由于沙箱限制,您无法从AIR启动应用程序。 – 2009-06-17 10:52:38

+1

也许像Merapi这样的事情会对此有所帮助? – 2009-06-17 17:48:57

+0

谢谢你,看起来很有趣。这是链接,如果人们想知道的话:http://merapiproject.net/ – 2009-06-18 07:53:47

0

我会去FreePascal。它本地编译为windows/mac/linux,因此你不需要依赖任何其他框架(.net,java,air)来安装。只有一个可执行文件就是这样。

+2

好吧,而不是“你想支持的每个单一平台只有一个单一的可执行文件”,可能只有一组源代码以及系统托管的本地API图标是一切,但标准化。 – Fredrik 2009-06-16 19:30:51

0

我同意James:如果您在Flex中拥有投资和专有技术,那么使用Air可以扩展这一点。

至于有效载荷 - 如果你只是需要不时弹出通知,RSS是要走的路。否则,由于它很容易设置,所以您可以推出自己的类似于XML REST的服务,并且可以长期为您提供灵活性。