<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Feeling

        三人行,必有我師焉

       ::  :: 新隨筆 :: 聯系 ::  :: 管理 ::
      185 隨筆 :: 0 文章 :: 392 評論 :: 0 Trackbacks

    #

    Control類:

    toControl ( Point ?point)
    ??????????Returns a point which is the result of converting the argument, which is specified in display relative coordinates, to coordinates relative to the receiver.

    Point Display 的絕對值轉化為 Control 的相對值。

    toDisplay
    ( Point ?point)
    ??????????Returns a point which is the result of converting the argument, which is specified in coordinates relative to the receiver, to display relative coordinates.
    Point Control 的相對值轉化為 Display 的絕對值。

    Example:?
    ?Button button = new Button( s, SWT. BORDER );
    ?System. out .println( button.getLocation( ) ); //Point {0, 0} ?
    ?System. out .println( button.toDisplay( button.getLocation( ) ) ); //Point {70, 89} ?
    ?System. out .println( button.toControl( button.toDisplay( button.getLocation( ) ) ) ); //Point {0, 0}

    Device類:
    getDepth()
    ??????????Returns the bit depth of the screen, which is the number of bits it takes to represent the number of unique colors that the screen is currently capable of displaying.
    拿到操作系統的顏色深度。
    ?

    getDPI
    ()
    ??????????Returns a point whose x coordinate is the horizontal dots per inch of the display, and whose y coordinate is the vertical dots per inch of the display.
    拿到操作系統的DPI值。

    Example:
    ?System.out.println(Display.getDefault( ).getDepth( ));//32
    ?System.out.println(Display.getDefault( ).getDPI( ));//Point {96, 96}

    ?

    posted @ 2006-06-20 17:54 三人行,必有我師焉 閱讀(760) | 評論 (0)編輯 收藏

    最近由于項目的需要,研究了一下SWT的Accessibility。關于Accessibility,這是一個很難纏的search,給殘疾人用的東東,正常人基本上不會用到,網上文章少之又少。可以查閱到的一篇來自于IBM developerWorks的文章:使用 Eclipse 創建易訪問的應用程序:介紹

    易訪問性是一個總括的術語,它包括生成使具有各種殘疾的人易用的產品所涉及的所有東西和人。美國已經立法,不符合Accessibility規范的軟件不能夠在政府部門銷售。在美國,創建易訪問的應用程序的主要商業(對比人道主義)驅動力是 Rehabilitation Act 1998 年的修正法案,稱為 Section 508。Section 508 要求聯邦機構使他們的信息技術對帶有殘疾的人易于訪問。


    Eclipse 擁有一個包含 API:org.eclipse.swt.accessibility 的易訪問性包。Eclipse 3.0 易訪問性特征是基于 MSAA 1.3 程序設計模型所提供的功能。您可以將 Eclipse 中的 Accessible 對象聯系到每個控件上,并且 org.eclipse.swt.accessibility 接口中的方法集對應 MSAA 1.3 IAccessible 界面中的消息集。

     org.eclipse.swt.accessibility 的接口    

    Interface Summary
    AccessibleControlListener Classes that implement this interface provide methods that deal with the events that are generated when an accessibility client sends a message to a control.
    AccessibleListener Classes that implement this interface provide methods that deal with the events that are generated when an accessibility client sends a message to a control.
    AccessibleTextListener Classes that implement this interface provide methods that deal with the events that are generated when an accessibility client sends a message to a control.

    SWT 自身包含的控件中只有寥寥幾個用到了Accessibility,JFace里也不多。看了所有的Accessibility相關代碼,只能總結一部分規律:
    1. 一般的復雜控件是沒有必要定義Accessibility的。
    2. 如果是模擬實現一個比較簡單的基本控件,比如Combo,Label,Spinner等,有必要定義Accessibility。  
    3. 所有的自定義控件都要實現AccessibleControlListener接口。
    4. 所有的包含文本框的控件都要實現AccessibleTextListener接口。
    5. 設置AccessibleListener的getHelp( )最好是給控件加上Tooltip,因為Wineyes這些屏幕閱讀器閱讀都是根據Tooltip,無視getHelp( )的設置。
    6. 設置AccessibleListener的getName( ),一般來說,可以設置為這個控件相關聯的Label的Text或者該控件上的某部分文字,自己斟酌考慮設置。
    7. getKeyboardShortcut( ),考慮控件的快捷操作方式,如果需要的話。

    以下是CCombo的Accessibility代碼:

    void initAccessible() {
        AccessibleAdapter accessibleAdapter = new AccessibleAdapter () {
           publicvoid getName (AccessibleEvent e) {
               String name = null;
               Label label = getAssociatedLabel ();
               if (label != null) {
                  name = stripMnemonic (label.getText());
               }
               e.result = name;
           }
           publicvoid getKeyboardShortcut(AccessibleEvent e) {
               String shortcut = null;
               Label label = getAssociatedLabel ();
               if (label != null) {
                  String text = label.getText ();
                  if (text != null) {
                      char mnemonic = _findMnemonic (text);
                      if (mnemonic != '\0') {
                         shortcut = "Alt+"+mnemonic;
                      }
                  }
               }
               e.result = shortcut;
           }
           publicvoid getHelp (AccessibleEvent e) {
               e.result = getToolTipText ();
           }
        };
        getAccessible ().addAccessibleListener (accessibleAdapter);
        text.getAccessible ().addAccessibleListener (accessibleAdapter);
        list.getAccessible ().addAccessibleListener (accessibleAdapter);
        arrow.getAccessible ().addAccessibleListener (new AccessibleAdapter() {
           publicvoid getName (AccessibleEvent e) {
               e.result = isDropped () ? SWT.getMessage ("SWT_Close") : SWT.getMessage ("SWT_Open");
           }
           publicvoid getKeyboardShortcut (AccessibleEvent e) {
               e.result = "Alt+Down Arrow";
           }
           publicvoid getHelp (AccessibleEvent e) {
               e.result = getToolTipText ();
           }
        });
     
        getAccessible().addAccessibleTextListener (new AccessibleTextAdapter() {
           publicvoid getCaretOffset (AccessibleTextEvent e) {
               e.offset = text.getCaretPosition ();
           }
           publicvoid getSelectionRange(AccessibleTextEvent e) {
               Point sel = text.getSelection();
               e.offset = sel.x;
               e.length = sel.y - sel.x;
           }
        });
       
        getAccessible().addAccessibleControlListener (new AccessibleControlAdapter() {
           publicvoid getChildAtPoint (AccessibleControlEvent e) {
               Point testPoint = toControl (e.x, e.y);
               if (getBounds ().contains (testPoint)) {
                  e.childID = ACC.CHILDID_SELF;
               }
           }
          
           publicvoid getLocation (AccessibleControlEvent e) {
               Rectangle location = getBounds ();
               Point pt = toDisplay (location.x, location.y);
               e.x = pt.x;
               e.y = pt.y;
               e.width = location.width;
               e.height = location.height;
           }
          
           publicvoid getChildCount (AccessibleControlEvent e) {
               e.detail = 0;
           }
          
           publicvoid getRole (AccessibleControlEvent e) {
               e.detail = ACC.ROLE_COMBOBOX;
           }
          
           publicvoid getState (AccessibleControlEvent e) {
               e.detail = ACC.STATE_NORMAL;
           }
     
           publicvoid getValue (AccessibleControlEvent e) {
               e.result = getText ();
           }
        });
     
        text.getAccessible ().addAccessibleControlListener (new AccessibleControlAdapter () {
           publicvoid getRole (AccessibleControlEvent e) {
               e.detail = text.getEditable () ? ACC.ROLE_TEXT : ACC.ROLE_LABEL;
           }
        });
     
        arrow.getAccessible ().addAccessibleControlListener (new AccessibleControlAdapter() {
           publicvoid getDefaultAction (AccessibleControlEvent e) {
               e.result = isDropped () ? SWT.getMessage ("SWT_Close") : SWT.getMessage ("SWT_Open");
           }
        });
    }

    在SWT控件中,包含Accessibility功能的控件有:CCombo,CLabel,CTableFolder,StyledText。
    posted @ 2006-06-19 17:38 三人行,必有我師焉 閱讀(1977) | 評論 (4)編輯 收藏

    上一篇文章我們知道了Eclipse彈出菜單的基本用法。其實Eclipse的彈出菜單可以用來做很多文章,簡單一點的根據文件類別,我們可以進行不同的文件操作,比如Ant的build.xml我們可以用來build,Java文件我們可以用Java Editor打開,這些基于文件類型的操作我們都可以很容易的實現。但是還有一種情況,如果文件類型一樣,我們想進行不同的操作,該怎么實現呢?實際上這樣的應用很多,比如同樣是Java文件,含有main方法的Java文件有Run和Debug的選項,其它的都沒有。還有現在的框架都是基于XML文件進行配置的,如果一個項目使用了多個框架,我們怎么根據不同的XML文件進行框架的區分呢?答案就是enablement的test。

    <!ELEMENT test EMPTY>
    <!ATTLIST test
    property?CDATA #REQUIRED
    args?????CDATA #IMPLIED
    value????CDATA #IMPLIED>

    This element is used to evaluate the property state of the object in focus. The set of testable properties can be extended using the propery tester extension point. The test expression returns EvaluationResult.NOT_LOADED if teh property tester doing the actual testing isn't loaded yet.

    • property - the name of an object's property to test.
    • args - additional arguments passed to the property tester. Multiple arguments are seperated by commas. Each individual argument is converted into a Java base type using the same rules as defined for the value attribute of the test expression.
    • value - the expected value of the property. Can be omitted if the property is a boolean property. The test expression is supposed to return EvaluationResult.TRUE if the property matches the value and EvaluationResult.FALSE otherwise. The value attribute is converted into a Java base type using the following rules:
      • the string "true" is converted into Boolean.TRUE
      • the string "false" is converted into Boolean.FALSE
      • if the string contains a dot then the interpreter tries to convert the value into a Float object. If this fails the string is treated as a java.lang.String
      • if the string only consists of numbers then the interpreter converts the value in an Integer object.
      • in all other cases the string is treated as a java.lang.String
      • the conversion of the string into a Boolean, Float, or Integer can be suppressed by surrounding the string with single quotes. For example, the attribute value="'true'" is converted into the string "true"


    比如我們要讓含有main方法的Java文件它的右鍵彈出菜單包含一個額外的選項“This is main class”,需要編寫如下的Plugin.xml:

    < plugin >
    ???
    < extension
    ?????????
    point ="org.eclipse.ui.popupMenus" >

    ??????
    < objectContribution
    ????????
    id ="Advanced.PopupMenus"

    ????????objectClass
    ="java.lang.Object" >
    ?????
    < action? id ="Advanced.PopupMenus.Action"
    ????????label
    ="AdvancedPopupMenus"
    ????????style
    ="pulldown"
    ????????menubarPath
    ="additions"
    ????????class
    ="advancedpopupmenus.popup.actions.AdvancedPopupMenusAction" ?
    ????????enablesFor
    ="+" >

    ?????
    </ action >
    ?????
    < enablement >
    ??????????
    < test? property ="advancedpopupmenus.popup.visable" />
    ?????
    </ enablement > ??
    ?????
    </ objectContribution >

    ???
    </ extension >
    ???
    < extension? point ="org.eclipse.core.expressions.propertyTesters" >
    ???
    < propertyTester
    ???
    namespace ="advancedpopupmenus.popup"

    ???properties
    ="visable"
    ???type
    ="java.lang.Object"
    ???class
    ="advancedpopupmenus.popup.actions.VisablePropertyTester"
    ???id
    ="advancedpopupmenus.popup.propertyTesters.visable" > ??
    ???
    </ propertyTester >
    ??????
    ???
    </ extension >

    </ plugin >

    我們需要檢測在當前情況下是否需要顯示這個菜單項,使用擴展點 org.eclipse.core.expressions.propertyTesters
    <!ELEMENT propertyTester EMPTY>
    <!ATTLIST propertyTester
    id???????? CDATA #REQUIRED
    type?????? CDATA #REQUIRED
    namespace? CDATA #REQUIRED
    properties CDATA #REQUIRED
    class????? CDATA #REQUIRED>

    id - unique identifier for the property tester
    type - the type to be extended by this property tester
    namespace - a unique id determining the name space the properties are added to
    properties - a comma separated list of properties provided by this property tester
    class - the name of the class that implements the testing methods. The class must be public and extend org.eclipse.core.expressions.PropertyTester with a public 0-argument constructor.?

    這里只須注意
    propertyTester的namespace和properties正好對應test的property。

    至于檢測的邏輯我們在advancedpopupmenus.popup.actions.VisablePropertyTester中實現,這個類必須繼承自org.eclipse.core.expressions.PropertyTester

    package ?advancedpopupmenus.popup.actions;

    import
    ?org.eclipse.core.expressions.PropertyTester;
    import
    ?org.eclipse.jdt.core.IMethod;
    import
    ?org.eclipse.jdt.core.IType;
    import
    ?org.eclipse.jdt.core.JavaModelException;
    import
    ?org.eclipse.jdt.internal.core.CompilationUnit;

    public ? class ?VisablePropertyTester? extends
    ?PropertyTester
    {
    ????
    public ? boolean
    ?test(?Object?receiver,?String?property,?Object[]?args,
    ????????????Object?expectedValue?)
    ????{
    ????????
    if ?(? ! (?receiver? instanceof
    ?CompilationUnit?)?)
    ????????????
    return ? false
    ;
    ????????CompilationUnit?unit?
    =
    ?(CompilationUnit)?receiver;
    ????????
    try

    ????????{
    ????????????IType[]?types?
    = ?unit.getTypes(?);
    ????????????
    if ?(?types? == ? null
    ?)
    ????????????????
    return ? false
    ;
    ????????????
    for ?(? int ?i? = ? 0 ;?i? < ?types.length;?i ++
    ?)
    ????????????{
    ????????????????IMethod[]?methods?
    =
    ?types[i].getMethods(?);
    ????????????????
    if ?(?methods? == ? null
    ?)
    ????????????????????
    return ? false
    ;
    ????????????????
    for ?(? int ?j? = ? 0 ;?j? < ?methods.length;?j ++
    ?)
    ????????????????{
    ????????????????????
    if
    ?(?methods[j].isMainMethod(?)?)
    ????????????????????????
    return ? true
    ;
    ????????????????}
    ????????????}
    ????????}
    ????????
    catch
    ?(?JavaModelException?e?)
    ????????{
    ????????????e.printStackTrace(?);
    ????????}
    ????????
    return ? false
    ;
    ????}
    }

    我們只要判斷接受的Java文件中是否含有main方法,如果有,則返回True,沒有則返回False。

    如果我們是要接受一個Web開發的配置文件,我們可以這樣寫:

    < plugin >
    ???
    < extension
    ?????????
    point ="org.eclipse.ui.popupMenus" >

    ??????
    < objectContribution
    ????????
    id ="Advanced.PopupMenus"

    ????????objectClass
    ="org.eclipse.core.resources.IFile"
    ????????nameFilter
    ="*.xml" > ???
    ????????
    < action? id ="Advanced.PopupMenus.Action"

    ???????????label
    ="This?is?web?xml"
    ???????????style
    ="pulldown"
    ???????????menubarPath
    ="additions"
    ???????????class
    ="advancedpopupmenus.popup.actions.AdvancedPopupMenusAction" ????
    ???????????enablesFor
    ="+" >

    ????????
    </ action >
    ????????
    < enablement >
    ?????????????
    < test? property ="advancedpopupmenus.popup.visable" />
    ????????
    </ enablement > ??
    ?????
    </ objectContribution >

    ???
    </ extension >
    ???
    < extension? point ="org.eclipse.core.expressions.propertyTesters" >
    ??????
    < propertyTester
    ????????????
    namespace ="advancedpopupmenus.popup"

    ????????????properties
    ="visable"
    ????????????type
    ="org.eclipse.core.resources.IFile"
    ????????????class
    ="advancedpopupmenus.popup.actions.VisablePropertyTester"
    ????????????id
    ="advancedpopupmenus.popup.propertyTesters.visable" > ????????
    ??????
    </ propertyTester >
    ??????
    ???
    </ extension >

    </ plugin >

    注意和上一個例子不同的地方,objectClass,nameFileter和type(在上一個例子中,我們也可以使用objectClass="org.eclipse.core.resources.IFile" nameFilter ="*.java" ),相應的我們的VisablePropertyTester類也要做一些改動:

    package ?advancedpopupmenus.popup.actions;

    import
    ?javax.xml.parsers.DocumentBuilder;
    import
    ?javax.xml.parsers.DocumentBuilderFactory;
    import
    ?org.eclipse.core.expressions.PropertyTester;
    import
    ?org.eclipse.core.resources.IFile;
    import
    ?org.w3c.dom.Document;
    import
    ?org.w3c.dom.DocumentType;

    public ? class ?VisablePropertyTester? extends
    ?PropertyTester
    {
    ????
    public ? boolean
    ?test(?Object?receiver,?String?property,?Object[]?args,
    ????????????Object?expectedValue?)
    ????{
    ????????
    if ?(? ! (?receiver? instanceof
    ?IFile?)?)
    ????????????
    return ? false
    ;
    ????????IFile?xml?
    =
    ?(IFile)?receiver;
    ????????
    try

    ????????{
    ????????????DocumentBuilderFactory?dbf?
    = ?DocumentBuilderFactory.newInstance(?);
    ????????????DocumentBuilder?db?
    =
    ?dbf.newDocumentBuilder(?);
    ????????????Document?doc?
    =
    ?db.parse(?xml.getContents(?)?);
    ????????????DocumentType?type?
    =
    ?doc.getDoctype(?);
    ????????????
    if (type.getSystemId(?).equalsIgnoreCase(? " http://java.sun.com/j2ee/dtds/web-app_2_2.dtd " ?)) return ? true
    ;
    ????????}
    ????????
    catch
    ?(?Exception?e?)
    ????????{
    ????????????e.printStackTrace(?);
    ????????}????????
    ????????
    return ? false
    ;
    ????}
    }

    這樣根據不同的xml SystemID,我們就能夠知道到底這是哪一種框架的配置文件了。

    posted @ 2006-06-16 16:15 三人行,必有我師焉 閱讀(3211) | 評論 (5)編輯 收藏

    復雜布局的重用,比較容易實現的就是GridLayout,至于FormLayout,基本上如果相似度不是很大,很難重用。我們在實現很多Page的時候,優先考慮的都會是GridLayout。但GridLayout在界面元素改動較大的時候也擁有一些弊端,比之FormLayout要麻煩的多。

    當界面元素擁有上下文的時候,隨著其上下文的改變,要想界面元素按照新的上下文重新布局,總是讓人頭疼。因為首先能想到的方法就是隱藏掉不需要的元素,這樣會減少時間和代碼上的開銷。但是如果采用GridLayout布局的時候,一個Widget隱藏的時候,它仍然占用著界面空間,即使將它的hightHint和widthHint設置為0,依然不能解決問題,因為GridLayout通常設置了verticalSpacing和horizontalSpacing。

    現在想到的一個解決方案就是將界面元素重新洗牌。 界面元素的生成由Model里的各個元素來決定。界面的上下文都交由一個屬性控制層進行控制,它上承GUI界面,下接業務模型,屬于一個過渡的層次。該層可以裝飾業務模型,并附加上新的上下文,形成一個新的Model。根據這個新的Model,我們在界面上創造元素。如果Model僅僅只是值發生了變化,我們重新設置界面的值即可。如果Model發生了上下文的變化,比如不需要某個屬性了或者是增加一個屬性,我們就對整個界面進行重新洗牌,通過一個循環Dispose掉所有的Widget,然后根據新的上下文重新初始化界面元素,并進行賦值。由于MVC的分離,重新初始化界面是很容易的。對于不太復雜的Page,布局上的問題就可以迎刃而解,而且在時間上的開銷也不會體現得很明顯,至少并看不出顯示上的延遲。

    posted @ 2006-06-16 13:54 三人行,必有我師焉 閱讀(588) | 評論 (2)編輯 收藏

    這幾天閱讀GEF 相關的幾篇文章:

  • http://benisoft.com/cn/java/AShapeDiagramEditor_zh.htm
  • http://blog.popsoft.com/more.asp?name=saden5&id=6591
  • http://www.blog.edu.cn/user1/19180/archives/2005/372857.shtml

    看下來感覺不錯,有些收獲,尤其是createEditPart,兩個參數,EditPart是上下文,另一個是Model,有可能用到項目的Property Editor上面,根據上下文和傳入的Model來控制界面的顯示。GEF的這段代碼可以用來研究研究。

    public?classPartFactory?implementsEditPartFactory {
    ????
    public ?EditPart?createEditPart(EditPart?context,?Object?model)
    {
    ???????? EditPart?part
    = null
    ;
    ????????
    if (model instanceof
    Diagram)
    ????????????part
    = new
    DiagramPart();
    ???????
    ? else?if(model instanceof?RectangleModel)
    {
    ????????????part
    =?new
    RectanglePart();
    ??????? }

    ??????? part.setModel(model);
    ???????
    return ?part;
    ????}

    }

    至于GEF,感覺只要有入門文章,再看看項目上的代碼,上手很容易,如果要做出復雜的應用,還要在研究研究它的API。八進制的文章寫得基本上很清楚了,

    BTW:Eclipse 有些view是絕佳的查看代碼的工具,比如Type Hierarchy視圖,Call Hierarchy視圖都非常有用。真是不用不知道呀!??

  • posted @ 2006-06-15 18:15 三人行,必有我師焉 閱讀(546) | 評論 (1)編輯 收藏

    僅列出標題
    共9頁: 上一頁 1 2 3 4 5 6 7 8 9 
    GitHub |  開源中國社區 |  maven倉庫 |  文件格式轉換 
    主站蜘蛛池模板: 久久免费精彩视频| 免费一级大黄特色大片| 国产AV旡码专区亚洲AV苍井空| 国产成人3p视频免费观看| 两个人看的www免费| 亚洲日韩国产精品乱-久| 久久久久久亚洲精品不卡| **俄罗斯毛片免费| 色老头综合免费视频| 亚洲福利视频网站| 亚洲AV无码一区二区三区国产| 亚洲免费在线视频播放| 一个人看的www免费高清| 亚洲H在线播放在线观看H| 亚洲精品人成无码中文毛片| 99久久这里只精品国产免费 | 无码人妻AV免费一区二区三区| 亚洲精品无码专区| 亚洲国产综合91精品麻豆| 永久黄网站色视频免费直播| 久久青青草原国产精品免费| 亚洲av成人无码网站…| 亚洲三级中文字幕| 亚洲韩国精品无码一区二区三区| 性感美女视频在线观看免费精品| 中文字幕免费在线视频| 亚洲av无码片vr一区二区三区| 亚洲影院在线观看| 亚洲亚洲人成综合网络| 免费黄网在线观看| 成年人视频免费在线观看| 国产精品午夜免费观看网站| 亚洲偷偷自拍高清| 中文字幕亚洲色图| 亚洲无线码一区二区三区| 国产在线观看免费完整版中文版| 久久天天躁狠狠躁夜夜免费观看| 国产成人精品无码免费看| 国产精品福利片免费看| 特级av毛片免费观看| 亚洲GV天堂GV无码男同|