随笔 - 6  文章 - 129  trackbacks - 0
<2024年12月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(14)

随笔档案(6)

文章分类(467)

文章档案(423)

相册

收藏夹(18)

JAVA

搜索

  •  

积分与排名

  • 积分 - 822222
  • 排名 - 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 阅读(250) 评论(0)  编辑  收藏 所属分类: eclipse RCP

只有注册用户登录后才能发表评论。


网站导航: