熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

開發Eclipse下的自定義控件[5]

2013-11-23 20:43:57  來源: Java開源技術 

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;
  }
 }

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


From:http://tw.wingwit.com/Article/program/Java/ky/201311/28983.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.