国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
Feeling - BlogJavaSWT 的易訪問性(Accessibility)
SWT 的易訪問性(Accessibility)
最近由于項目的需要,研究了一下SWT的Accessibility。關(guān)于Accessibility,這是一個很難纏的search,給殘疾人用的東東,正常人基本上不會用到,網(wǎng)上文章少之又少。可以查閱到的一篇來自于IBM developerWorks的文章:使用 Eclipse 創(chuàng)建易訪問的應(yīng)用程序:介紹易訪問性是一個總括的術(shù)語,它包括生成使具有各種殘疾的人易用的產(chǎn)品所涉及的所有東西和人。美國已經(jīng)立法,不符合Accessibility規(guī)范的軟件不能夠在政府部門銷售。在美國,創(chuàng)建易訪問的應(yīng)用程序的主要商業(yè)(對比人道主義)驅(qū)動力是 Rehabilitation Act 1998年的修正法案,稱為 Section 508。Section 508 要求聯(lián)邦機構(gòu)使他們的信息技術(shù)對帶有殘疾的人易于訪問。
Eclipse擁有一個包含 API:org.eclipse.swt.accessibility 的易訪問性包。Eclipse 3.0 易訪問性特征是基于MSAA 1.3 程序設(shè)計模型所提供的功能。您可以將 Eclipse 中的 Accessible 對象聯(lián)系到每個控件上,并且org.eclipse.swt.accessibility 接口中的方法集對應(yīng) 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相關(guān)代碼,只能總結(jié)一部分規(guī)律:
一般的復(fù)雜控件是沒有必要定義Accessibility的。
如果是模擬實現(xiàn)一個比較簡單的基本控件,比如Combo,Label,Spinner等,有必要定義Accessibility。
所有的自定義控件都要實現(xiàn)AccessibleControlListener接口。
所有的包含文本框的控件都要實現(xiàn)AccessibleTextListener接口。
設(shè)置AccessibleListener的getHelp( )最好是給控件加上Tooltip,因為Wineyes這些屏幕閱讀器閱讀都是根據(jù)Tooltip,無視getHelp( )的設(shè)置。
設(shè)置AccessibleListener的getName( ),一般來說,可以設(shè)置為這個控件相關(guān)聯(lián)的Label的Text或者該控件上的某部分文字,自己斟酌考慮設(shè)置。
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 三人行,必有我?guī)熝?閱讀(1171) |評論 (4)編輯 收藏
擴展Eclipse視圖彈出菜單(二)
上一篇文章我們知道了Eclipse彈出菜單的基本用法。其實Eclipse的彈出菜單可以用來做很多文章,簡單一點的根據(jù)文件類別,我們可以進行不同的文件操作,比如Ant的build.xml我們可以用來build,Java文件我們可以用JavaEditor打開,這些基于文件類型的操作我們都可以很容易的實現(xiàn)。但是還有一種情況,如果文件類型一樣,我們想進行不同的操作,該怎么實現(xiàn)呢?實際上這樣的應(yīng)用很多,比如同樣是Java文件,含有main方法的Java文件有Run和Debug的選項,其它的都沒有。還有現(xiàn)在的框架都是基于XML文件進行配置的,如果一個項目使用了多個框架,我們怎么根據(jù)不同的XML文件進行框架的區(qū)分呢?答案就是enablement的test。
<!ELEMENT EMPTY>
<!ATTLIST test
property CDATA #REQUIRED
args     CDATA #IMPLIED
value    CDATA #IMPLIED>
This element is used to evaluatethe property state of the object in focus. The set of testableproperties can be extended using the propery tester extension point. Thetest expression returns EvaluationResult.NOT_LOADED if teh propertytester 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>
我們需要檢測在當(dāng)前情況下是否需要顯示這個菜單項,使用擴展點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正好對應(yīng)test的property。
至于檢測的邏輯我們在advancedpopupmenus.popup.actions.VisablePropertyTester中實現(xiàn),這個類必須繼承自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開發(fā)的配置文件,我們可以這樣寫:
<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"),相應(yīng)的我們的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;
}
}
這樣根據(jù)不同的xml SystemID,我們就能夠知道到底這是哪一種框架的配置文件了
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
在awt/swing程序中添加swt (Browser控件的使用)【轉(zhuǎn)】 - Picses...
SWT實現(xiàn)彈出日歷控件
Swt常用控件中文教程
JAVA.SWT/JFace: SWT高級控件之SWT的高級應(yīng)用
SWT 和 JFace, 第 2 部分: 簡介
Eclicpse3.1.1下配置SWT,打包發(fā)布SWT程序,轉(zhuǎn)EXE
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服