在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 -->
/** *ApplicationWorkbenchWindowAdvisor.java */ packagecom.mi.pwdgate;
importorg.eclipse.swt.graphics.Point; importorg.eclipse.ui.IWorkbenchPreferenceConstants; importorg.eclipse.ui.PlatformUI; importorg.eclipse.ui.application.ActionBarAdvisor; importorg.eclipse.ui.application.IActionBarConfigurer; importorg.eclipse.ui.application.IWorkbenchWindowConfigurer; importorg.eclipse.ui.application.WorkbenchWindowAdvisor;
importcom.mi.pwdgate.util.SystemTrayMaster;
publicclassApplicationWorkbenchWindowAdvisorextendsWorkbenchWindowAdvisor{
privateSystemTrayMastertrayMaster; /* *(non-Javadoc) * *@seeorg.eclipse.ui.application.WorkbenchWindowAdvisor#postWindowOpen() */ publicvoidpostWindowOpen(){ createSystemTray(); }
privatevoidcreateSystemTray(){ trayMaster=newSystemTrayMaster(); trayMaster.createSystemTray(); }
/* *(non-Javadoc) * *@seeorg.eclipse.ui.application.WorkbenchWindowAdvisor#preWindowShellClose() */ publicbooleanpreWindowShellClose(){ trayMaster.minimizeWindow(); returnfalse; } } |
<!-- end source code -->
<!--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 */ packagecom.mi.pwdgate.util;
importorg.eclipse.swt.SWT; importorg.eclipse.swt.events.SelectionAdapter; importorg.eclipse.swt.events.SelectionEvent; importorg.eclipse.swt.events.SelectionListener; importorg.eclipse.swt.graphics.Image; importorg.eclipse.swt.widgets.Display; importorg.eclipse.swt.widgets.Event; importorg.eclipse.swt.widgets.Listener; importorg.eclipse.swt.widgets.Menu; importorg.eclipse.swt.widgets.MenuItem; importorg.eclipse.swt.widgets.Shell; importorg.eclipse.swt.widgets.Tray; importorg.eclipse.swt.widgets.TrayItem; importorg.eclipse.ui.PlatformUI;
/** *@authormoneyice2006-5-9 */ publicclassSystemTrayMasterimplementsSelectionListener,Listener{ privatefinalclassRestoreWindowListenerextendsSelectionAdapter{ publicvoidwidgetSelected(SelectionEvente){ restoreWindow(); } }
privateMenumenu;
privateMenuItem[]menuItems=new MenuItem[0];
privateRestoreWindowListenerrestoreWindowListener;
publicSystemTrayMaster(){ this.restoreWindowListener=newRestoreWindowListener(); }
//ClosestheApplication protectedvoidcloseApplication(){ PlatformUI.getWorkbench().close(); }
//clickthetray publicvoidwidgetSelected(SelectionEvente){ }
//doubleclickthetray publicvoidwidgetDefaultSelected(SelectionEvente){ restoreWindow(); }
//Getssystemshell privateShellgetShell(){ returnPlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); }
//MinimizestheWindow publicvoidminimizeWindow(){ getShell().setMinimized(true); getShell().setVisible(false); }
//Restoresthewindow protectedvoidrestoreWindow(){ Shellshell=PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getShell(); shell.open(); shell.setMinimized(false); shell.forceActive(); shell.forceFocus(); }
publicvoidshowMenu(){ clearItems(); MenuItemopenItem; MenuItemcloseItem; openItem=newMenuItem(this.menu,SWT.PUSH); closeItem=newMenuItem(this.menu,SWT.NONE); closeItem.setText("Close"); closeItem.addSelectionListener(newSelectionAdapter(){ publicvoidwidgetSelected(SelectionEvente){ closeApplication(); } }); this.menuItems=newMenuItem[]{openItem,closeItem};
openItem.setText("OpenPasswordGate"); openItem.addSelectionListener(this.restoreWindowListener); this.menu.setVisible(true); }
privatevoidclearItems(){ for(inti=0;i<this.menuItems.length;i++){ MenuItemitem=this.menuItems[i]; item.removeSelectionListener(this.restoreWindowListener); this.menuItems[i].dispose(); } }
publicvoidhandleEvent(Eventevent){ showMenu(); }
publicvoidcreateSystemTray(){ //Getssystemtray Traytray=Display.getDefault().getSystemTray(); //Createstrayitem TrayItemitem=newTrayItem(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=newMenu(getShell(),SWT.POP_UP); } }
|
ç¨åºæ§è¡åææ
![]()
分享到:
相关推荐
通过以上步骤,可以实现一个完整的RCP应用程序的系统托盘功能,使得程序在不占用桌面空间的情况下,仍然可以方便地被用户访问和控制。同时,通过右键菜单可以提供更多的操作选项,增强了用户体验。
- **系统托盘和定时提示**:系统托盘图标和定时气泡提示可以增强应用的用户体验,提醒用户有关信息或操作。 - **图片缓冲处理**:为了提高性能,RCP系统常使用图片缓冲技术,减少图像加载时间。 - **品牌化应用程序*...
通过在系统托盘中添加应用的图标,可以方便地让用户在最小化或切换到其他应用时,仍能快速访问到你的应用或接收通知。实现这一功能通常需要在插件中注册一个托盘图标,并处理相关的事件监听。 总结而言,掌握RCP...
- **介绍**: 在Eclipse RCP中添加系统托盘图标以提高应用的可用性。 - **实现**: 通过定义贡献点并实现IStatusLineManagerListener接口。 #### 5. 视图 - **概念**: 视图是在Eclipse RCP中用于展示数据的不同窗口。...
- **插件**:在Eclipse RCP中,每个功能模块都被封装成一个独立的插件。这些插件包含了实现特定功能所需的所有代码和资源。 - **扩展**:插件可以通过扩展来增加新的功能或者改变现有功能的行为。扩展是一种动态的...
- 如何在RCP程序中添加和管理系统托盘图标及其交互。 5. **视图** - **添加示例视图**:创建基本的视图,并将其添加到RCP应用程序中。 - **添加自定义视图**:指导创建和集成自定义视图到RCP环境中。 - **向...
系统托盘是放置在屏幕右下角(Windows系统)的一个小图标区域,RCP应用程序可以通过此区域显示图标并提供快捷方式。实现系统托盘的关键步骤如下: 1. **定义托盘图标**:在插件中定义托盘图标的资源。 2. **注册托盘...
- 在项目中定义编辑器的实现类。 - 配置插件元数据以支持该编辑器。 **6.4 调用编辑器** - **调用方式**: - 通过菜单项或其他方式启动编辑器。 **6.5 实例:文本编辑器实现** - **实现细节**: - 创建新的...
在 Eclipse RCP 中,可以通过贡献到系统托盘来使应用程序能够在后台运行。 #### 10. 视图 ##### 10.1. 向应用添加视图 视图是 Eclipse RCP 中的主要组件之一,提供了用户界面的一部分功能。可以通过创建视图插件并...
11. **系统托盘(Tray)**:在系统托盘中添加图标,并处理相关的用户交互。 12. **闪屏(Splash Screen)**:设计和实现应用程序启动时显示的闪屏。 13. **产品绑定(Product Binding)**:创建产品的捆绑版本,包括...
- **实现**:在Windows系统中创建系统托盘图标,提供对应用的快速访问。 #### 十九、添加状态行 ##### 20.1 设置状态行 - **状态行组件**:在主窗口底部添加状态行组件。 ##### 20.2 共享状态行 - **共享状态行**...
- **与桌面操作系统的紧密集成**:例如拖放(DnD)功能、系统托盘图标等。 - **易于部署和服务器集中管理**:这有助于降低总体拥有成本(TCO)。 - **利用本地文件系统和其他设备**:如打印机、读卡器等。 - **利用...
4 系统托盘 ............................................................................................................................................ 37 5 视图 .........................................
这可能意味着在某些用户环境中,由于软件bug或其他系统兼容性问题,RcpChat 的图标未能正确显示在任务栏的系统托盘区域。 从标签 "RcpChat" 我们可以推测,RcpChat 是该软件的项目名称或者是产品的简称,可能是...