本文整理汇总了Java中javax.accessibility.AccessibleText类的典型用法代码示例。如果您正苦于以下问题:Java AccessibleText类的具体用法?Java AccessibleText怎么用?Java AccessibleText使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AccessibleText类属于javax.accessibility包,在下文中一共展示了AccessibleText类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCharacterIndexAtPosition
import javax.accessibility.AccessibleText; //导入依赖的package包/类
static int getCharacterIndexAtPosition(final Accessible a, final Component c, final int x, final int y) {
if (a == null) return 0;
return CAccessibility.invokeAndWait(new Callable<Integer>() {
public Integer call() throws Exception {
final AccessibleContext ac = a.getAccessibleContext();
if (ac == null) return null;
final AccessibleText at = ac.getAccessibleText();
if (at == null) return null;
// (x, y) passed in as java screen coords - (0, 0) at upper-left corner of screen.
// Convert to java component-local coords
final Point componentLocation = ac.getAccessibleComponent().getLocationOnScreen();
final int localX = x - (int)componentLocation.getX();
final int localY = y - (int)componentLocation.getY();
return at.getIndexAtPoint(new Point(localX, localY));
}
}, c);
}
示例2: getSelectedTextRange
import javax.accessibility.AccessibleText; //导入依赖的package包/类
static int[] getSelectedTextRange(final Accessible a, final Component c) {
if (a == null) return new int[2];
return CAccessibility.invokeAndWait(new Callable<int[]>() {
public int[] call() {
final AccessibleContext ac = a.getAccessibleContext();
if (ac == null) return new int[2];
final AccessibleText at = ac.getAccessibleText();
if (at == null) return new int[2];
final int[] ret = new int[2];
ret[0] = at.getSelectionStart();
ret[1] = at.getSelectionEnd();
return ret;
}
}, c);
}
示例3: getLink
import javax.accessibility.AccessibleText; //导入依赖的package包/类
protected String getLink(Point p) {
final AccessibleContext aC = getAccessibleContext();
if (aC instanceof AccessibleJLabel) {
final AccessibleJLabel aL = (AccessibleJLabel) aC;
final AccessibleText aT = aL.getAccessibleText();
if (aT == null) {
return null;
}
final int index = aL.getIndexAtPoint(p);
for (final LinkDescriptor entry : listLinks) {
if (index >= entry.getStart() && index <= entry.getEnd()) {
return entry.getUrl();
}
}
}
return null;
}
示例4: getAccessibleText
import javax.accessibility.AccessibleText; //导入依赖的package包/类
public AccessibleText getAccessibleText() {
if (pane == null) {
//Cheat just a bit here - will do for now - the text is
//there, more or less where it should be, and a screen
//reader should be able to find it; exact bounds don't
//make much difference
pane = new JEditorPane();
pane.setBounds (panel.getBounds());
pane.getAccessibleContext().getAccessibleText();
pane.setFont (panel.getFont());
CellRendererPane cell = new CellRendererPane();
cell.add (pane);
}
pane.setText(getText());
pane.selectAll();
pane.validate();
return pane.getAccessibleContext().getAccessibleText();
}
示例5: getAfterIndex
import javax.accessibility.AccessibleText; //导入依赖的package包/类
public String getAfterIndex(int part, int index) {
int offset = 0;
switch (part) {
case AccessibleText.CHARACTER:
return (index == document.getLength()) ? null : getCharacter(index + 1);
case AccessibleText.WORD:
try {
offset = getWordEnd(index) + 1;
offset = getWordEnd(offset + 1);
} catch (final BadLocationException e) {
return null;
}
return getWord(offset);
case AccessibleText.SENTENCE:
// not implemented yet
default:
return null;
}
}
示例6: getBeforeIndex
import javax.accessibility.AccessibleText; //导入依赖的package包/类
public String getBeforeIndex(int part, int index) {
int offset = 0;
switch (part) {
case AccessibleText.CHARACTER:
return (index == 0) ? null : getCharacter(index - 1);
case AccessibleText.WORD:
try {
offset = getWordStart(index) - 1;
offset = getWordStart(offset - 1);
} catch (final BadLocationException e) {
return null;
}
return (offset < 0) ? null : getWord(offset);
case AccessibleText.SENTENCE:
BreakIterator bi = BreakIterator.getSentenceInstance();
bi.setText(getText());
offset = bi.preceding(index);
offset = bi.previous() + 1;
return (offset < 0) ? null : getLine(offset);
default:
return null;
}
}
示例7: mouseClicked
import javax.accessibility.AccessibleText; //导入依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
Point point = e.getPoint();
AccessibleText at = (AccessibleText) label.getAccessibleContext();
int pos = at.getIndexAtPoint(point);
AttributeSet as = at.getCharacterAttribute(pos);
if (label.isEnabled() && as.getAttribute(HTML.Tag.A) != null) {
label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
SimpleAttributeSet attr=(SimpleAttributeSet)as.getAttribute(HTML.Tag.A);
String href=(String)attr.getAttribute(HTML.Attribute.HREF);
fireActionPerformed(
new ActionEvent(label,ActionEvent.ACTION_PERFORMED,href));
} else {
label.setCursor(Cursor.getDefaultCursor());
}
}
示例8: getBeforeIndex
import javax.accessibility.AccessibleText; //导入依赖的package包/类
public String getBeforeIndex(final int part, final int index) {
int offset = 0;
switch (part) {
case AccessibleText.CHARACTER:
return (index == 0) ? null : getCharacter(index - 1);
case AccessibleText.WORD:
try {
offset = TextUtils.getWordStart(textKit, index) - 1;
} catch (final BadLocationException e) {
return null;
}
return (offset < 0) ? null : getWord(offset);
case AccessibleText.SENTENCE:
Element elem = TextUtils.getParagraphElement(document, index);
offset = elem.getStartOffset() - 1;
return (offset < 0) ? null : getLine(offset);
default:
return null;
}
}
示例9: getAfterIndex
import javax.accessibility.AccessibleText; //导入依赖的package包/类
public String getAfterIndex(final int part, final int index) {
int offset = 0;
switch (part) {
case AccessibleText.CHARACTER:
return (index == document.getLength()) ? null
: getCharacter(index + 1);
case AccessibleText.WORD:
try {
offset = TextUtils.getWordEnd(textKit, index)
+ 1;
} catch (final BadLocationException e) {
return null;
}
return getWord(offset);
case AccessibleText.SENTENCE:
Element elem = TextUtils.getParagraphElement(document, index);
offset = elem.getEndOffset() + 1;
return (offset < 0) ? null : getLine(offset);
default:
return null;
}
}