隨筆 - 6  文章 - 129  trackbacks - 0
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(14)

          隨筆檔案(6)

          文章分類(467)

          文章檔案(423)

          相冊

          收藏夾(18)

          JAVA

          搜索

          •  

          積分與排名

          • 積分 - 827240
          • 排名 - 49

          最新評論

          閱讀排行榜

          評論排行榜

          package hellorcp.tool;

          import org.eclipse.jface.action.Action;
          import org.eclipse.jface.action.IMenuManager;
          import org.eclipse.jface.action.MenuManager;
          import org.eclipse.swt.SWT;
          import org.eclipse.swt.events.ShellAdapter;
          import org.eclipse.swt.events.ShellEvent;
          import org.eclipse.swt.widgets.Event;
          import org.eclipse.swt.widgets.Listener;
          import org.eclipse.swt.widgets.Menu;
          import org.eclipse.swt.widgets.Shell;
          import org.eclipse.swt.widgets.Tray;
          import org.eclipse.swt.widgets.TrayItem;
          import org.eclipse.ui.IWorkbenchWindow;
          import org.eclipse.ui.PlatformUI;
          import org.eclipse.ui.plugin.AbstractUIPlugin;

          public class HookSysTray {

           private TrayItem trayItem;
           
           public HookSysTray() {
            
           }
           
           public void createSysTray(final IWorkbenchWindow window) {
            trayItem = initTrayItem(window);
            if(trayItem != null) {
             trayPopupMenu(window);
             trayMinimize(window);
            }
           }
           //最小化到穎P
           private void trayMinimize(final IWorkbenchWindow window) {
            // TODO Auto-generated method stub
            window.getShell().addShellListener(new ShellAdapter(){

             @Override
             public void shellIconified(ShellEvent e) {
              // TODO Auto-generated method stub
              window.getShell().setVisible(false);
             }
             
            });
            trayItem.addListener(SWT.Selection, new Listener(){

             public void handleEvent(Event event) {
              // TODO Auto-generated method stub
              Shell shell = window.getShell();
              if(!shell.isVisible()) {
               shell.setVisible(true);
               window.getShell().setMinimized(false);
              }
             }
             
            });
           }
           //穎P出菜?
           private void trayPopupMenu(final IWorkbenchWindow window) {
            // TODO Auto-generated method stub
            trayItem.addListener(SWT.MenuDetect, new Listener() {

             public void handleEvent(Event event) {
              // TODO Auto-generated method stub
              MenuManager trayMenu = new MenuManager();
              Menu menu = trayMenu.createContextMenu(window.getShell());
              fillTrayItem(trayMenu, window);
              menu.setVisible(true);
             }
            });
           }

           //造穎P菜霧
           private void fillTrayItem(IMenuManager trayMenu, final IWorkbenchWindow window) {
            Action exitSystem = new Action("退出系統[&E]",
          AbstractUIPlugin.imageDescriptorFromPlugin(
              IAppConstants.APPLICATION_ID, IImagekey.EXIT_STSTEN)) {

               @Override
               public void run() {
                // TODO Auto-generated method stub
                PlatformUI.getWorkbench().close();
               }
             
            };
            trayMenu.add(exitSystem);
           }
           //初始化
           private TrayItem initTrayItem(IWorkbenchWindow window) {
            // TODO Auto-generated method stub
            final Tray tray = window.getShell().getDisplay().getSystemTray();
            if(tray == null)
             return null;
            trayItem = new TrayItem(tray, SWT.NONE);
            trayItem.setImage(CacheImage.getInstance().getImage(
              IAppConstants.APPLICATION_ID, IImagekey.WINDOW_IMAGE));
            trayItem.setToolTipText(IAppConstants.APPLICATION_TITLE);
            return trayItem;
           }
           
           //最小化程式窗口
           public void windowMinimized(final Shell shell) {
            shell.setMinimized(true);
            shell.setVisible(false);
           }
           
           //
           public void disponse() {
            if(trayItem != null)
             trayItem.dispose();
           }
          }



          posted on 2008-12-05 23:56 Ke 閱讀(259) 評論(0)  編輯  收藏 所屬分類: eclipse RCP
          主站蜘蛛池模板: 辽源市| 中超| 元朗区| 荔波县| 宁陕县| 汉源县| 文安县| 绵阳市| 石台县| 瓮安县| 庆阳市| 葵青区| 潍坊市| 京山县| 民勤县| 汉沽区| 鞍山市| 临江市| 顺义区| 安多县| 金昌市| 汉阴县| 黄平县| 鹤山市| 南康市| 彭泽县| 若羌县| 任丘市| 呼图壁县| 泾源县| 伊通| 安义县| 民勤县| 勃利县| 运城市| 漠河县| 渭南市| 鄂托克旗| 遂宁市| 乐都县| 黎城县|