亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

在RCP中實現系統托盤功能

系統 1550 0
在RCP中實現系統托盤功能
在RCP中加入系統托盤功能,類似msn和QQ。功能就不說了。
在RCP的WorkbenchWindowAdvisor的postWindowOpen()中創建系統托盤,另外要override preWindowShellClose()方法,否則按程序右上角的X,整個程序就會被關閉,重寫后實現程序最小化的功能。

ApplicationWorkbenchWindowAdvisor.java

<!--CTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt--><style type="text/css"> <!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }--> </style> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <!-- ======================================================== --><!-- = Java Sourcecode to HTML automatically converted code = --><!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = --><!-- = Further information: http://www.java2html.de = -->
<!-- start source code --> <!-- end source code -->
/**
*ApplicationWorkbenchWindowAdvisor.java
*/
package com.mi.pwdgate;

import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.IWorkbenchPreferenceConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;

import com.mi.pwdgate.util.SystemTrayMaster;

publicclass ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor{

private SystemTrayMastertrayMaster;
/*
*(non-Javadoc)
*
*@seeorg.eclipse.ui.application.WorkbenchWindowAdvisor#postWindowOpen()
*/
public void postWindowOpen(){
createSystemTray();
}

private void createSystemTray(){
trayMaster= new SystemTrayMaster();
trayMaster.createSystemTray();
}

/*
*(non-Javadoc)
*
*@seeorg.eclipse.ui.application.WorkbenchWindowAdvisor#preWindowShellClose()
*/
public boolean preWindowShellClose(){
trayMaster.minimizeWindow();
returnfalse ;
}
}
<!--CTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt--><style type="text/css"> <!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }--> </style> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <!-- ======================================================== --><!-- = Java Sourcecode to HTML automatically converted code = --><!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = --><!-- = Further information: http://www.java2html.de = -->
<!-- start source code -->

/**
*SystemTrayMaster.java
*/
package com.mi.pwdgate.util;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
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.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tray;
import org.eclipse.swt.widgets.TrayItem;
import org.eclipse.ui.PlatformUI;

/**
*@authormoneyice2006-5-9
*/
publicclass SystemTrayMaster implements SelectionListener,Listener{
privatefinalclass RestoreWindowListener extends SelectionAdapter{
public void widgetSelected(SelectionEvente){
restoreWindow();
}
}

private Menumenu;

private MenuItem[]menuItems=new MenuItem[0];

private RestoreWindowListenerrestoreWindowListener;

public SystemTrayMaster(){
this .restoreWindowListener= new RestoreWindowListener();
}

//ClosestheApplication
protected void closeApplication(){
PlatformUI.getWorkbench().close();
}

//clickthetray
public void widgetSelected(SelectionEvente){
}

//doubleclickthetray
public void widgetDefaultSelected(SelectionEvente){
restoreWindow();
}

//Getssystemshell
private ShellgetShell(){
return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
}

//MinimizestheWindow
public void minimizeWindow(){
getShell().setMinimized( true );
getShell().setVisible( false );
}

//Restoresthewindow
protected void restoreWindow(){
Shellshell=PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getShell();
shell.open();
shell.setMinimized( false );
shell.forceActive();
shell.forceFocus();
}

public void showMenu(){
clearItems();
MenuItemopenItem;
MenuItemcloseItem;
openItem= new MenuItem( this .menu,SWT.PUSH);
closeItem= new MenuItem( this .menu,SWT.NONE);
closeItem.setText("Close");
closeItem.addSelectionListener( new SelectionAdapter(){
public void widgetSelected(SelectionEvente){
closeApplication();
}
});
this .menuItems= new MenuItem[]{openItem,closeItem};

openItem.setText("OpenPasswordGate");
openItem.addSelectionListener( this .restoreWindowListener);
this .menu.setVisible( true );
}

private void clearItems(){
for ( int i=0;i< this .menuItems.length;i++){
MenuItemitem= this .menuItems[i];
item.removeSelectionListener( this .restoreWindowListener);
this .menuItems[i].dispose();
}
}

public void handleEvent(Eventevent){
showMenu();
}

public void createSystemTray(){
//Getssystemtray
Traytray=Display.getDefault().getSystemTray();
//Createstrayitem
TrayItemitem= new TrayItem(tray,SWT.NONE);
item.setText("PasswordGate");
item.setToolTipText("PasswordGate");
//Setsimagefortray
Imageimage=ImageShop.get("default");
item.setImage(image);

item.addSelectionListener( this );
item.addListener(SWT.MenuDetect, this );

menu= new Menu(getShell(),SWT.POP_UP);
}
}

?¨??o???§è???????????

在RCP中實現系統托盤功能


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 国产在视频线精品www666 | 性欧美一级毛片在线播放 | 国产精品2020在线看亚瑟 | 亚洲综合色网站 | 久久99热久久精品在线6 | 九色视频极品论坛区 | 青青影院一区二区免费视频 | 中文字幕亚洲高清综合 | 亚洲国产精品视频在线观看 | 香蕉人在线香蕉人在线 | 国产精品久久久久久久久久98 | 国产欧美视频在线观看 | 欧美日韩黄色大片 | 国产精品第三页在线看 | 在线观看深夜观看网站免费 | 好吊妞精品视频 | 国产最新网站 | 久久久久国产一级毛片高清板 | 成人欧美一区二区三区黑人3p | 国产成人永久在线播放 | 亚洲毛片一级带毛片基地 | 久久精品国产亚洲婷婷 | 久久性生活视频 | 久久成人国产精品二三区 | 免费一级特黄欧美大片勹久久网 | 毛片一| 亚洲精品久久片久久 | 国产三级做爰在线观看∵ | 国产原创中文字幕 | 国产片91人成在线观看 | 久久国产综合尤物免费观看 | 欧美最猛性xxxxx短视频 | 北岛玲日韩精品一区二区三区 | 免费视频99 | 天天干天天干天天干天天 | 国产欧美亚洲精品一区 | 婷婷丝袜 | 日韩精品国产自在久久现线拍 | 欧美一级网 | 女人18一级特级毛片免费看 | 毛片网子 |