隨筆 - 6  文章 - 129  trackbacks - 0
          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿(14)

          隨筆檔案(6)

          文章分類(467)

          文章檔案(423)

          相冊(cè)

          收藏夾(18)

          JAVA

          搜索

          •  

          積分與排名

          • 積分 - 829280
          • 排名 - 49

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          package testrcp.app;

          import org.eclipse.jface.action.MenuManager;
          import org.eclipse.swt.SWT;
          import org.eclipse.swt.graphics.Image;
          import org.eclipse.swt.graphics.Point;
          import org.eclipse.swt.graphics.Rectangle;
          import org.eclipse.swt.widgets.Display;
          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.application.ActionBarAdvisor;
          import org.eclipse.ui.application.IActionBarConfigurer;
          import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
          import org.eclipse.ui.application.WorkbenchWindowAdvisor;

          public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {

           private TrayItem trayItem;//系統(tǒng)托盤對(duì)象
           private Image trayImage;//系統(tǒng)托盤圖標(biāo)對(duì)象
           /** 程序的菜單條 */
           private ApplicationActionBarAdvisor actionBarAdvisor;
           
              public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
                  super(configurer);
              }
              /** 創(chuàng)建菜單條對(duì)象 */
              public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) {
                  actionBarAdvisor = new ApplicationActionBarAdvisor(configurer);
               return actionBarAdvisor;
              }
             
              /** 打開窗口前調(diào)用該方法,對(duì)窗口初始化設(shè)置 */
              public void preWindowOpen() {
                  IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
                  configurer.setInitialSize(new Point(600, 400));
                  configurer.setShowCoolBar(true);//工具欄
                  configurer.setShowStatusLine(false);//狀態(tài)欄
                 
                  configurer.setShowPerspectiveBar(true);//透視圖
                  configurer.setShowProgressIndicator(true);//進(jìn)度條
                 
                  final IWorkbenchWindow window = super.getWindowConfigurer().getWindow();
                  /** 創(chuàng)建系統(tǒng)托盤 */
                  trayItem = initTrayItem(window);
                  /** 如果支持系統(tǒng)托盤,則創(chuàng)建托盤的菜單 */
                  if(trayItem != null) {
                   createPopupMenu(window);
                  }
              }
             
              /**
            * 創(chuàng)建系統(tǒng)托盤菜單
            *
            * @param window
            *            工作臺(tái)窗口對(duì)象
            */
              private void createPopupMenu(final IWorkbenchWindow window) {
            trayItem.addListener(SWT.MenuDetect, new Listener() {

             @Override
             public void handleEvent(Event event) {
              MenuManager trayMenu = new MenuManager();
              Menu menu = trayMenu.createContextMenu(window.getShell());
              /**
               * 調(diào)用fillTrayItem方法創(chuàng)建系統(tǒng)托盤對(duì)象,可以直接利用菜單欄中的操作 而不需要,重新創(chuàng)建操作
               */
              actionBarAdvisor.fillTrayItem(trayMenu);
              menu.setVisible(true);
             }
             
            });
            
           }

           /**
            * 初始化系統(tǒng)托盤對(duì)象
            *
            * @param window
            *            工作臺(tái)窗口對(duì)象
            * @return 該程序所對(duì)應(yīng)的系統(tǒng)托盤對(duì)象
            */
           private TrayItem initTrayItem(IWorkbenchWindow window) {
            final Tray tray = Display.getCurrent().getSystemTray();
            if(tray == null)
             return null;
            TrayItem trayItem = new TrayItem(tray, SWT.NONE);
            trayImage = Activator.getImageDescriptor("icons/logo.gif").createImage();
            trayItem.setImage(trayImage);
            trayItem.setToolTipText("System Tray");
            
            return trayItem;
           }

           @Override
           public void postWindowOpen() {
            //窗口居中顯示
            Shell shell = getWindowConfigurer().getWindow().getShell();
            Rectangle screenSize = Display.getDefault().getClientArea();
            Rectangle frameSize = shell.getBounds();
            shell.setLocation((screenSize.width - frameSize.width)/2, (screenSize.height - frameSize.height)/2);
           }
             
           /** 釋放窗口,釋放系統(tǒng)托盤 */
           public void dispose() {
            if (trayImage != null) {
             trayImage.dispose();
             trayItem.dispose();
            }
           }

          }



          posted on 2008-12-05 23:42 Ke 閱讀(919) 評(píng)論(0)  編輯  收藏 所屬分類: eclipse RCP
          主站蜘蛛池模板: 和龙市| 始兴县| 华阴市| 盐山县| 霍邱县| 祁连县| 菏泽市| 新田县| 江川县| 临沧市| 北流市| 抚宁县| 镇宁| 望都县| 八宿县| 措勤县| 瑞金市| 定陶县| 城市| 庆城县| 宜城市| 慈溪市| 靖远县| 江北区| 介休市| 泾阳县| 榆树市| 个旧市| 东港市| 华蓥市| 综艺| 龙游县| 习水县| 泰顺县| 台山市| 江油市| 五华县| 鄂州市| 汶上县| 天门市| 砀山县|