반응형

javax.accessibility.AccessibleComponent는 Java Access Bridge API의 일부로, Java 애플리케이션의 시각적 구성 요소의 접근성 정보를 제공하는 인터페이스입니다
이 인터페이스는 javax.swing.JComponent와 java.awt.Component 인터페이스를 상속하며, 시각적 구성 요소의 접근성 정보를 제공하는 메서드를 포함하고 있습니다.

AccessibleComponent 인터페이스의 주요 메서드는 다음과 같습니다.

- getAccessibleAt(int x, int y) : 지정된 좌표에 있는 시각적 구성 요소의 접근성 객체를 반환합니다.
- getAccessibleChild(int i) : 이 구성 요소의 자식 중 지정된 인덱스에 해당하는 접근성 객체를 반환합니다.
- getAccessibleChildrenCount() : 이 구성 요소의 자식 접근성 객체 수를 반환합니다.
- getAccessibleParent() : 이 구성 요소의 부모 접근성 객체를 반환합니다.
- getAccessibleIndexInParent() : 이 구성 요소가 부모의 몇 번째 자식인지를 나타내는 인덱스를 반환합니다.
- getAccessibleStateSet() : 이 구성 요소의 상태 정보를 나타내는 AccessibleStateSet 객체를 반환합니다.
- getAccessibleRelationSet() : 이 구성 요소와 관련된 AccessibleRelationSet 객체를 반환합니다.

AccessibleComponent 인터페이스를 구현하는 클래스는 시각적 구성 요소의 접근성 정보를 제공하는 기능을 제공합니다
예를 들어, 다음은 JButton 클래스를 상속하여 AccessibleComponent 인터페이스를 구현한 LocalizedButton 클래스의 예제 코드입니다.

 

import java.awt.Graphics;
import java.awt.Insets;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleComponent;
import javax.swing.JButton;

public class LocalizedButton extends JButton implements AccessibleComponent {

  private static final long serialVersionUID = 1L;

  public LocalizedButton(String text) {
    super(text);
  }

  @Override
  public Accessible getAccessibleAt(int x, int y) {
    return super.getAccessibleAt(x, y);
  }

  @Override
  public Accessible getAccessibleChild(int i) {
    return super.getAccessibleChild(i);
  }

  @Override
  public int getAccessibleChildrenCount() {
    return super.getAccessibleChildrenCount();
  }

  @Override
  public AccessibleComponent getAccessibleComponent() {
    return this;
  }

  @Override
  public Accessible getAccessibleParent() {
    return super.getAccessibleParent();
  }

  @Override
  public int getAccessibleIndexInParent() {
    return super.getAccessibleIndexInParent();
  }

  @Override
  public int getAccessibleSelectionEnd() {
    return super.getAccessibleSelectionEnd();
  }

  @Override
  public int getAccessibleSelectionStart() {
    return super.getAccessibleSelectionStart();
  }

  @Override
  public AccessibleTable getAccessibleTable() {
    return super.getAccessibleTable();
  }

  @Override
  public AccessibleText getAccessibleText() {
    return super.getAccessibleText();
  }

  @Override
  public AccessibleStateSet getAccessibleStateSet() {
    return super.getAccessibleStateSet();
  }
  
}


위의 코드에서는 LocalizedButton 클래스가 JButton을 상속하면서 AccessibleComponent 인터페이스를 구현하도록 지정됩니다
그러므로 LocalizedButton 클래스는 JButton과 AccessibleComponent 인터페이스의 모든 기능을 사용할 수 있습니다.

또한, LocalizedButton 클래스는 AccessibleComponent 인터페이스에서 제공하는 모든 메서드를 구현하고 있습니다
그러므로 LocalizedButton 클래스의 객체는 접근성 클라이언트가 요청할 수 있는 모든 정보를 제공합니다.

AccessibleComponent 인터페이스는 Java Access Bridge API에서 중요한 역할을 합니다
이 인터페이스를 구현하는 클래스는 Java 애플리케이션에서 시각적 구성 요소의 접근성 정보를 제공할 수 있으며, 시각적 구성 요소의 상태 및 속성을 변경할 수도 있습니다
따라서 Java Access Bridge API를 사용하는 개발자들은 AccessibleComponent 인터페이스를 효과적으로 활용하여 Java 애플리케이션의 접근성을 향상시킬 수 있습니다.

이 글의 추천 태그: javax.accessibility.AccessibleComponent, Java Access Bridge API, 접근성, 예제 코드
다음은 AccessibleComponent 인터페이스를 구현한 LocalizedButton 클래스의 예제 코드입니다.

 

import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleState;
import javax.accessibility.AccessibleStateSet;
import javax.accessibility.AccessibleRole;
import javax.accessibility.AccessibleComponent;
import javax.swing.JButton;

public class LocalizedButton extends JButton implements AccessibleComponent {
    private static final long serialVersionUID = 1L;
    
    private AccessibleContext accessibleContext;
    
    public LocalizedButton(String text) {
        super(text);
        accessibleContext = new LocalizedButtonAccessibleContext(this);
    }
    
    @Override
    public AccessibleContext getAccessibleContext() {
        return accessibleContext;
    }

    // AccessibleComponent 인터페이스의 메서드 구현
    @Override
    public void addFocusListener(java.awt.event.FocusListener listener) {
        getAccessibleContext().addFocusListener(listener);
    }

    @Override
    public void removeFocusListener(java.awt.event.FocusListener listener) {
        getAccessibleContext().removeFocusListener(listener);
    }

    @Override
    public AccessibleStateSet getAccessibleStateSet() {
        AccessibleStateSet states = new AccessibleStateSet();
        if (isFocusOwner()) {
            states.add(AccessibleState.FOCUSED);
        }
        if (isEnabled()) {
            states.add(AccessibleState.ENABLED);
        } else {
            states.add(AccessibleState.DISABLED);
        }
        if (isVisible()) {
            states.add(AccessibleState.VISIBLE);
        } else {
            states.add(AccessibleState.INVISIBLE);
        }
        if (isShowing()) {
            states.add(AccessibleState.SHOWING);
        } else {
            states.add(AccessibleState.HIDDEN);
        }
        return states;
    }

    @Override
    public AccessibleRole getAccessibleRole() {
        return AccessibleRole.PUSH_BUTTON;
    }

    @Override
    public Accessible getAccessibleParent() {
        return getParent();
    }

    @Override
    public int getAccessibleIndexInParent() {
        return getParent().getComponentZOrder(this);
    }

    @Override
    public int getAccessibleChildrenCount() {
        return 0;
    }

    @Override
    public Accessible getAccessibleChild(int i) {
        return null;
    }

    @Override
    public Locale getLocale() throws IllegalComponentStateException {
        return super.getLocale();
    }

    @Override
    public void setLocale(Locale locale) throws IllegalComponentStateException {
        super.setLocale(locale);
    }
}

class LocalizedButtonAccessibleContext extends AccessibleContext {
    private static final long serialVersionUID = 1L;

    private LocalizedButton localizedButton;
    
    public LocalizedButtonAccessibleContext(LocalizedButton localizedButton) {
        this.localizedButton = localizedButton;
    }
    
    @Override
    public String getAccessibleName() {
        return localizedButton.getText();
    }

    @Override
    public String getAccessibleDescription() {
        return null;
    }

    @Override
    public AccessibleRole getAccessibleRole() {
        return localizedButton.getAccessibleRole();
    }

    @Override
    public AccessibleStateSet getAccessibleStateSet() {
        return localizedButton.getAccessibleStateSet();
    }

    @Override
    public Accessible getAccessibleParent() {
        return localizedButton.getAccessibleParent();
    }

    @Override
    public int getAccessibleIndexInParent() {
        return localizedButton.getAccessibleIndexInParent();
    }

    @Override
    public int getAccessibleChildrenCount() {
        return localizedButton.getAccessibleChildrenCount();
    }
}

 

반응형

+ Recent posts