java

位置:IT落伍者 >> java >> 浏览文章

开发Eclipse下的自定义控件[5]


发布日期:2024年07月09日
 
开发Eclipse下的自定义控件[5]

public void selectionChanged() {

Event event = new Event();

eventwidget = this;

SelectionEvent e = new SelectionEvent(event);

for (int i = ; i < selectionListenerssize(); i++) {

SelectionListener listener = (SelectionListener) selectionListenerselementAt(i);

listenerwidgetSelected(e);

}

}

现在辅助功能(Accessibility)也日益成为软件重要的部分它是的残疾人也能够方便的使用我们的软件美国已经立法不符合Accessibility规范的软件不能够在政府部门销售我们开发的控件也需要支持Accessibility下面的代码使我们的控件有Accessibility支持其中最重要的是getRole和getValue函数我们的控件是从Canvas继承我们在getRole函数中返回ACCROLE_LIST这样我们的控件才能让屏幕阅读软件将我们的控件作为列表控件对待

Accessible accessible = getAccessible();

accessibleaddAccessibleControlListener(new AccessibleControlAdapter() {

public void getRole(AccessibleControlEvent e) {

int role = ; int childID = echildID;

if (childID == ACCCHILDID_SELF) {

role = ACCROLE_LIST; }

else if (childID >= && childID < colorssize()) {

role = ACCROLE_LISTITEM;

}

edetail = role;

}

public void getValue(AccessibleControlEvent e){

int childID = echildID;

if (childID == ACCCHILDID_SELF) {

eresult = getText();

}

else if (childID >= && childID < colorssize()) {

eresult = (String)colorNamesget(childID);

}

}

public void getChildAtPoint(AccessibleControlEvent e) {

Point testPoint = toControl(new Point(ex ey));

int childID = ACCCHILDID_NONE;

childID = (testPointy cy)/lineHeight;

if (childID == ACCCHILDID_NONE) {

Rectangle location = getBounds();

locationheight = locationheight getClientArea()height;

if (locationcontains(testPoint)) {

childID = ACCCHILDID_SELF;

}

}

echildID = childID;

}

public void getLocation(AccessibleControlEvent e) {

Rectangle location = null;

int childID = echildID;

if (childID == ACCCHILDID_SELF) {

location = getBounds();

}

if (childID >= && childID < colorssize()) {

location = new Rectangle(cxchildID*lineHeight+cymaxXlineHeight);

}

if (location != null) {

Point pt = toDisplay(new Point(locationx locationy));

ex = ptx;

ey = pty;

ewidth = locationwidth;

eheight = locationheight;

}

}

[] [] [] [] [] []

               

上一篇:开发Eclipse下的自定义控件[3]

下一篇:开发Eclipse下的自定义控件[4]