豆沙包

…… …… 所学 所写 所想 所做 所悟…… ……

SWT中的Sytem Tray相关处理

         SWT已经提供了对部分平台(比如window)上的系统托盘的支持。但支持得还不够好,我最近需要在一个聊天工具实现Balloon效果(粘附于系统托盘上的一个消息气泡效果,在IM软件中普遍被支持),查一下SWT API,到目前为上并没有提供支持。但一个好消息是在月底交要出来的3.2M6中,将对部分API做调整,增加对Balloon的支持。

Milestone Plan  3.2  M6 March  31 2006   

 Implement custom draw 
for  table and tree 
Implement 
native  drag source effects  for  cursor 
Implement ImageTransfer support 
Implement Balloon tooltips 
Implement Accessibility on Mac OS X 

     这儿是EclipseZone上的一个针对这一效果的文章:TrayIcons and ToolTips  http://www.eclipsezone.com/eclipse/forums/t66093.rhtml


甚至在官方网站上,已经提供了这一个API的Snippet

//http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet225.java
/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * 
http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 ******************************************************************************
*/

package org.eclipse.swt.snippets;
  
/*
 * Tooltip example snippet: create a balloon tooltip for a tray item
 *
 * For a list of all SWT example snippets see
 * 
http://www.eclipse.org/swt/snippets/
 * 
 * @since 3.0
 
*/

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class Snippet225 {

public static void main(String[] args) {
    Display display 
= new Display();
    Shell shell 
= new Shell(display);
    Image image 
= null;
    
final ToolTip tip = new ToolTip(shell, SWT.BALLOON | SWT.ICON_INFORMATION);
    tip.setMessage(
"Here is message for the user. When the message is too long it wraps. I should say something cool but nothing comes to my mind.");
    Tray tray 
= display.getSystemTray();
    
if (tray != null{
        TrayItem item 
= new TrayItem(tray, SWT.NONE);
        image 
= new Image(display, Snippet225.class.getResourceAsStream("eclipse.png"));
        item.setImage(image);
        tip.setText(
"Notification from a tray item");
        item.setToolTip(tip);
    }
 else {
        tip.setText(
"Notification from anywhere");
        tip.setLocation(
400400);
    }

    Button button 
= new Button (shell, SWT.PUSH);
    button.setText(
"Press for balloon tip");
    button.addListener(SWT.Selection, 
new Listener() {
        
public void handleEvent(Event event) {
            tip.setVisible(
true);
        }

    }
);
    button.pack();
    shell.setBounds(
5050300200);
    shell.open();
    
while (!shell.isDisposed()) {
        
if (!display.readAndDispatch()) display.sleep();
    }

    
if (image != null) image.dispose();
    display.dispose();
}

}

除此之外,也有其它的第三方API实现了此一效果。是由www.novocode.com提供的BalloonWindow。其API可在上述的网站中获得。

posted on 2006-03-19 16:36 carob 阅读(867) 评论(0)  编辑  收藏 所属分类: Eclipse


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


网站导航: