豆沙包

          …… …… 所學 所寫 所想 所做 所悟…… ……

          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(
          400,?400);
          ????}

          ????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(
          50,?50,?300,?200);
          ????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 閱讀(879) 評論(0)  編輯  收藏 所屬分類: Eclipse


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 呼和浩特市| 安化县| 平远县| 广平县| 平昌县| 磐安县| 项城市| 垣曲县| 明溪县| 黄冈市| 砚山县| 湟源县| 盘锦市| 黄浦区| 钟祥市| 莱芜市| 临清市| 泰州市| 抚州市| 滁州市| 辉南县| 闻喜县| 青河县| 玉田县| 庄河市| 泸定县| 田阳县| 兰溪市| 呼伦贝尔市| 体育| 醴陵市| 林西县| 郁南县| 高平市| 湘潭市| 贺兰县| 喀喇沁旗| 利津县| 北碚区| 霍城县| 元江|