/** * Get the AccessibleValue associated with this object. In the * implementation of the Java Accessibility API for this class, * return this object, which is responsible for implementing the * AccessibleValue interface on behalf of itself. * * @return this object */ public AccessibleValue getAccessibleValue() { return this; } /** * Returns the number of Actions available in this object. The * default behavior of a button is to have one action - toggle * the button. * * @return 1, the number of Actions in this object */ public int getAccessibleActionCount() { return 1; } /** * Return a description of the specified action of the object. * * @param i zero-based index of the actions */ public String getAccessibleActionDescription(int i) { if (i == 0) { return UIManager.getString("AbstractButton.clickText"); } else { return null; } } /** * Perform the specified Action on the object * * @param i zero-based index of actions * @return true if the the action was performed; else false. */ public boolean doAccessibleAction(int i) { if (i == 0) { doClick(); return true; } else { return false; } } /** * Get the value of this object as a Number. * * @return An Integer of 0 if this isn't selected or an Integer of 1 if * this is selected. * @see AbstractButton#isSelected */ public Number getCurrentAccessibleValue() { if (isSelected()) { return Integer.valueOf(1); } else { return Integer.valueOf(0); } } /** * Set the value of this object as a Number. * * @return True if the value was set. */ public boolean setCurrentAccessibleValue(Number n) { // TIGER - 4422535 if (n == null) { return false; } int i = n.intValue(); if (i == 0) { setSelected(false); } else { setSelected(true); } return true; } /** * Get the minimum value of this object as a Number. * * @return an Integer of 0. */ public Number getMinimumAccessibleValue() { return Integer.valueOf(0); } /** * Get the maximum value of this object as a Number. * * @return An Integer of 1. */ public Number getMaximumAccessibleValue() { return Integer.valueOf(1); } /* AccessibleText ---------- */ public AccessibleText getAccessibleText() { View view = (View)AbstractButton.this.getClientProperty("html"); if (view != null) { return this; } else { return null; } } /** * Given a point in local coordinates, return the zero-based index * of the character under that Point. If the point is invalid, * this method returns -1. * * Note: the AbstractButton must have a valid size (e.g. have * been added to a parent container whose ancestor container * is a valid top-level window) for this method to be able * to return a meaningful value. * * @param p the Point in local coordinates * @return the zero-based index of the character under Point p; if * Point is invalid returns -1. * @since 1.3 */ public int getIndexAtPoint(Point p) { View view = (View) AbstractButton.this.getClientProperty("html"); if (view != null) { Rectangle r = getTextRectangle(); if (r == null) { return -1; } Rectangle2D.Float shape = new Rectangle2D.Float(r.x, r.y, r.width, r.height); Position.Bias bias[] = new Position.Bias[1]; return view.viewToModel(p.x, p.y, shape, bias); } else { return -1; } } /** * Determine the bounding box of the character at the given * index into the string. The bounds are returned in local * coordinates. If the index is invalid an empty rectangle is * returned. * * Note: the AbstractButton must have a valid size (e.g. have * been added to a parent container whose ancestor container * is a valid top-level window) for this method to be able * to return a meaningful value. * * @param i the index into the String * @return the screen coordinates of the character's the bounding box, * if index is invalid returns an empty rectangle. * @since 1.3 */ public Rectangle getCharacterBounds(int i) { View view = (View) AbstractButton.this.getClientProperty("html"); if (view != null) { Rectangle r = getTextRectangle(); if (r == null) { return null; } Rectangle2D.Float shape = new Rectangle2D.Float(r.x, r.y, r.width, r.height); try { Shape charShape = view.modelToView(i, shape, Position.Bias.Forward); return charShape.getBounds(); } catch (BadLocationException e) { return null; } } else { return null; } } /** * Return the number of characters (valid indicies) * * @return the number of characters * @since 1.3 */ public int getCharCount() { View view = (View) AbstractButton.this.getClientProperty("html"); if (view != null) { Document d = view.getDocument(); if (d instanceof StyledDocument) { StyledDocument doc = (StyledDocument)d; return doc.getLength(); } } return accessibleContext.getAccessibleName().length(); } /** * Return the zero-based offset of the caret. * * Note: That to the right of the caret will have the same index * value as the offset (the caret is between two characters). * @return the zero-based offset of the caret. * @since 1.3 */ public int getCaretPosition() { // There is no caret. return -1; } /** * Returns the String at a given index. * * @param part the AccessibleText.CHARACTER, AccessibleText.WORD, * or AccessibleText.SENTENCE to retrieve * @param index an index within the text >= 0 * @return the letter, word, or sentence, * null for an invalid index or part * @since 1.3 */ public String getAtIndex(int part, int index) { if (index < 0 || index >= getCharCount()) { return null; } switch (part) { case AccessibleText.CHARACTER: try { return getText(index, 1); } catch (BadLocationException e) { return null; } case AccessibleText.WORD: try { String s = getText(0, getCharCount()); BreakIterator words = BreakIterator.getWordInstance(getLocale()); words.setText(s); int end = words.following(index); return s.substring(words.previous(), end); } catch (BadLocationException e) { return null; } case AccessibleText.SENTENCE: try { String s = getText(0, getCharCount()); BreakIterator sentence = BreakIterator.getSentenceInstance(getLocale()); sentence.setText(s); int end = sentence.following(index); return s.substring(sentence.previous(), end); } catch (BadLocationException e) { return null; } default: return null; } } /** * Returns the String after a given index. * * @param part the AccessibleText.CHARACTER, AccessibleText.WORD, * or AccessibleText.SENTENCE to retrieve * @param index an index within the text >= 0 * @return the letter, word, or sentence, null for an invalid * index or part * @since 1.3 */ public String getAfterIndex(int part, int index) { if (index < 0 || index >= getCharCount()) { return null; } switch (part) { case AccessibleText.CHARACTER: if (index+1 >= getCharCount()) { return null; } try { return getText(index+1, 1); } catch (BadLocationException e) { return null; } case AccessibleText.WORD: try { String s = getText(0, getCharCount()); BreakIterator words = BreakIterator.getWordInstance(getLocale()); words.setText(s); int start = words.following(index); if (start == BreakIterator.DONE || start >= s.length()) { return null; } int end = words.following(start); if (end == BreakIterator.DONE || end >= s.length()) { return null; } return s.substring(start, end); } catch (BadLocationException e) { return null; } case AccessibleText.SENTENCE: try { String s = getText(0, getCharCount()); BreakIterator sentence = BreakIterator.getSentenceInstance(getLocale()); sentence.setText(s); int start = sentence.following(index); if (start == BreakIterator.DONE || start > s.length()) { return null; } int end = sentence.following(start); if (end == BreakIterator.DONE || end > s.length()) { return null; } return s.substring(start, end); } catch (BadLocationException e) { return null; } default: return null; } } /** * Returns the String before a given index. * * @param part the AccessibleText.CHARACTER, AccessibleText.WORD, * or AccessibleText.SENTENCE to retrieve * @param index an index within the text >= 0 * @return the letter, word, or sentence, null for an invalid index * or part * @since 1.3 */ public String getBeforeIndex(int part, int index) { if (index < 0 || index > getCharCount()-1) { return null; } switch (part) { case AccessibleText.CHARACTER: if (index == 0) { return null; } try { return getText(index-1, 1); } catch (BadLocationException e) { return null; } case AccessibleText.WORD: try { String s = getText(0, getCharCount()); BreakIterator words = BreakIterator.getWordInstance(getLocale()); words.setText(s); int end = words.following(index); end = words.previous(); int start = words.previous(); if (start == BreakIterator.DONE) { return null; } return s.substring(start, end); } catch (BadLocationException e) { return null; } case AccessibleText.SENTENCE: try { String s = getText(0, getCharCount()); BreakIterator sentence = BreakIterator.getSentenceInstance(getLocale()); sentence.setText(s); int end = sentence.following(index); end = sentence.previous(); int start = sentence.previous(); if (start == BreakIterator.DONE) { return null; } return s.substring(start, end); } catch (BadLocationException e) { return null; } default: return null; } } /** * Return the AttributeSet for a given character at a given index * * @param i the zero-based index into the text * @return the AttributeSet of the character * @since 1.3 */ public AttributeSet getCharacterAttribute(int i) { View view = (View) AbstractButton.this.getClientProperty("html"); if (view != null) { Document d = view.getDocument(); if (d instanceof StyledDocument) { StyledDocument doc = (StyledDocument)d; Element elem = doc.getCharacterElement(i); if (elem != null) { return elem.getAttributes(); } } } return null; } /** * Returns the start offset within the selected text. * If there is no selection, but there is * a caret, the start and end offsets will be the same. * * @return the index into the text of the start of the selection * @since 1.3 */ public int getSelectionStart() { // Text cannot be selected. return -1; } /** * Returns the end offset within the selected text. * If there is no selection, but there is * a caret, the start and end offsets will be the same. * * @return the index into teh text of the end of the selection * @since 1.3 */ public int getSelectionEnd() { // Text cannot be selected. return -1; } /** * Returns the portion of the text that is selected. * * @return the String portion of the text that is selected * @since 1.3 */ public String getSelectedText() { // Text cannot be selected. return null; } /* * Returns the text substring starting at the specified * offset with the specified length. */ private String getText(int offset, int length) throws BadLocationException { View view = (View) AbstractButton.this.getClientProperty("html"); if (view != null) { Document d = view.getDocument(); if (d instanceof StyledDocument) { StyledDocument doc = (StyledDocument)d; return doc.getText(offset, length); } } return null; } /* * Returns the bounding rectangle for the component text. */ private Rectangle getTextRectangle() { String text = AbstractButton.this.getText(); Icon icon = (AbstractButton.this.isEnabled()) ? AbstractButton.this.getIcon() : AbstractButton.this.getDisabledIcon(); if ((icon == null) && (text == null)) { return null; } Rectangle paintIconR = new Rectangle(); Rectangle paintTextR = new Rectangle(); Rectangle paintViewR = new Rectangle(); Insets paintViewInsets = new Insets(0, 0, 0, 0); paintViewInsets = AbstractButton.this.getInsets(paintViewInsets); paintViewR.x = paintViewInsets.left; paintViewR.y = paintViewInsets.top; paintViewR.width = AbstractButton.this.getWidth() - (paintViewInsets.left + paintViewInsets.right); paintViewR.height = AbstractButton.this.getHeight() - (paintViewInsets.top + paintViewInsets.bottom); String clippedText = SwingUtilities.layoutCompoundLabel( AbstractButton.this, getFontMetrics(getFont()), text, icon, AbstractButton.this.getVerticalAlignment(), AbstractButton.this.getHorizontalAlignment(), AbstractButton.this.getVerticalTextPosition(), AbstractButton.this.getHorizontalTextPosition(), paintViewR, paintIconR, paintTextR, 0); return paintTextR;Lines 2501–3000 of 3101. Previous lines Load more
/** * Get the AccessibleValue associated with this object. In the * implementation of the Java Accessibility API for this class, * return this object, which is responsible for implementing the * AccessibleValue interface on behalf of itself. * * @return this object */ public AccessibleValue getAccessibleValue() { return this; } /** * Returns the number of Actions available in this object. The * default behavior of a button is to have one action - toggle * the button. * * @return 1, the number of Actions in this object */ public int getAccessibleActionCount() { return 1; } /** * Return a description of the specified action of the object. * * @param i zero-based index of the actions */ public String getAccessibleActionDescription(int i) { if (i == 0) { return UIManager.getString("AbstractButton.clickText"); } else { return null; } } /** * Perform the specified Action on the object * * @param i zero-based index of actions * @return true if the the action was performed; else false. */ public boolean doAccessibleAction(int i) { if (i == 0) { doClick(); return true; } else { return false; } } /** * Get the value of this object as a Number. * * @return An Integer of 0 if this isn't selected or an Integer of 1 if * this is selected. * @see AbstractButton#isSelected */ public Number getCurrentAccessibleValue() { if (isSelected()) { return Integer.valueOf(1); } else { return Integer.valueOf(0); } } /** * Set the value of this object as a Number. * * @return True if the value was set. */ public boolean setCurrentAccessibleValue(Number n) { // TIGER - 4422535 if (n == null) { return false; } int i = n.intValue(); if (i == 0) { setSelected(false); } else { setSelected(true); } return true; } /** * Get the minimum value of this object as a Number. * * @return an Integer of 0. */ public Number getMinimumAccessibleValue() { return Integer.valueOf(0); } /** * Get the maximum value of this object as a Number. * * @return An Integer of 1. */ public Number getMaximumAccessibleValue() { return Integer.valueOf(1); } /* AccessibleText ---------- */ public AccessibleText getAccessibleText() { View view = (View)AbstractButton.this.getClientProperty("html"); if (view != null) { return this; } else { return null; } } /** * Given a point in local coordinates, return the zero-based index * of the character under that Point. If the point is invalid, * this method returns -1. * * Note: the AbstractButton must have a valid size (e.g. have * been added to a parent container whose ancestor container * is a valid top-level window) for this method to be able * to return a meaningful value. * * @param p the Point in local coordinates * @return the zero-based index of the character under Point p; if * Point is invalid returns -1. * @since 1.3 */ public int getIndexAtPoint(Point p) { View view = (View) AbstractButton.this.getClientProperty("html"); if (view != null) { Rectangle r = getTextRectangle(); if (r == null) { return -1; } Rectangle2D.Float shape = new Rectangle2D.Float(r.x, r.y, r.width, r.height); Position.Bias bias[] = new Position.Bias[1]; return view.viewToModel(p.x, p.y, shape, bias); } else { return -1; } } /** * Determine the bounding box of the character at the given * index into the string. The bounds are returned in local * coordinates. If the index is invalid an empty rectangle is * returned. * * Note: the AbstractButton must have a valid size (e.g. have * been added to a parent container whose ancestor container * is a valid top-level window) for this method to be able * to return a meaningful value. * * @param i the index into the String * @return the screen coordinates of the character's the bounding box, * if index is invalid returns an empty rectangle. * @since 1.3 */ public Rectangle getCharacterBounds(int i) { View view = (View) AbstractButton.this.getClientProperty("html"); if (view != null) { Rectangle r = getTextRectangle(); if (r == null) { return null; } Rectangle2D.Float shape = new Rectangle2D.Float(r.x, r.y, r.width, r.height); try { Shape charShape = view.modelToView(i, shape, Position.Bias.Forward); return charShape.getBounds(); } catch (BadLocationException e) { return null; } } else { return null; } } /** * Return the number of characters (valid indicies) * * @return the number of characters * @since 1.3 */ public int getCharCount() { View view = (View) AbstractButton.this.getClientProperty("html"); if (view != null) { Document d = view.getDocument(); if (d instanceof StyledDocument) { StyledDocument doc = (StyledDocument)d; return doc.getLength(); } } return accessibleContext.getAccessibleName().length(); } /** * Return the zero-based offset of the caret. * * Note: That to the right of the caret will have the same index * value as the offset (the caret is between two characters). * @return the zero-based offset of the caret. * @since 1.3 */ public int getCaretPosition() { // There is no caret. return -1; } /** * Returns the String at a given index. * * @param part the AccessibleText.CHARACTER, AccessibleText.WORD, * or AccessibleText.SENTENCE to retrieve * @param index an index within the text >= 0 * @return the letter, word, or sentence, * null for an invalid index or part * @since 1.3 */ public String getAtIndex(int part, int index) { if (index < 0 || index >= getCharCount()) { return null; } switch (part) { case AccessibleText.CHARACTER: try { return getText(index, 1); } catch (BadLocationException e) { return null; } case AccessibleText.WORD: try { String s = getText(0, getCharCount()); BreakIterator words = BreakIterator.getWordInstance(getLocale()); words.setText(s); int end = words.following(index); return s.substring(words.previous(), end); } catch (BadLocationException e) { return null; } case AccessibleText.SENTENCE: try { String s = getText(0, getCharCount()); BreakIterator sentence = BreakIterator.getSentenceInstance(getLocale()); sentence.setText(s); int end = sentence.following(index); return s.substring(sentence.previous(), end); } catch (BadLocationException e) { return null; } default: return null; } } /** * Returns the String after a given index. * * @param part the AccessibleText.CHARACTER, AccessibleText.WORD, * or AccessibleText.SENTENCE to retrieve * @param index an index within the text >= 0 * @return the letter, word, or sentence, null for an invalid * index or part * @since 1.3 */ public String getAfterIndex(int part, int index) { if (index < 0 || index >= getCharCount()) { return null; } switch (part) { case AccessibleText.CHARACTER: if (index+1 >= getCharCount()) { return null; } try { return getText(index+1, 1); } catch (BadLocationException e) { return null; } case AccessibleText.WORD: try { String s = getText(0, getCharCount()); BreakIterator words = BreakIterator.getWordInstance(getLocale()); words.setText(s); int start = words.following(index); if (start == BreakIterator.DONE || start >= s.length()) { return null; } int end = words.following(start); if (end == BreakIterator.DONE || end >= s.length()) { return null; } return s.substring(start, end); } catch (BadLocationException e) { return null; } case AccessibleText.SENTENCE: try { String s = getText(0, getCharCount()); BreakIterator sentence = BreakIterator.getSentenceInstance(getLocale()); sentence.setText(s); int start = sentence.following(index); if (start == BreakIterator.DONE || start > s.length()) { return null; } int end = sentence.following(start); if (end == BreakIterator.DONE || end > s.length()) { return null; } return s.substring(start, end); } catch (BadLocationException e) { return null; } default: return null; } } /** * Returns the String before a given index. * * @param part the AccessibleText.CHARACTER, AccessibleText.WORD, * or AccessibleText.SENTENCE to retrieve * @param index an index within the text >= 0 * @return the letter, word, or sentence, null for an invalid index * or part * @since 1.3 */ public String getBeforeIndex(int part, int index) { if (index < 0 || index > getCharCount()-1) { return null; } switch (part) { case AccessibleText.CHARACTER: if (index == 0) { return null; } try { return getText(index-1, 1); } catch (BadLocationException e) { return null; } case AccessibleText.WORD: try { String s = getText(0, getCharCount()); BreakIterator words = BreakIterator.getWordInstance(getLocale()); words.setText(s); int end = words.following(index); end = words.previous(); int start = words.previous(); if (start == BreakIterator.DONE) { return null; } return s.substring(start, end); } catch (BadLocationException e) { return null; } case AccessibleText.SENTENCE: try { String s = getText(0, getCharCount()); BreakIterator sentence = BreakIterator.getSentenceInstance(getLocale()); sentence.setText(s); int end = sentence.following(index); end = sentence.previous(); int start = sentence.previous(); if (start == BreakIterator.DONE) { return null; } return s.substring(start, end); } catch (BadLocationException e) { return null; } default: return null; } } /** * Return the AttributeSet for a given character at a given index * * @param i the zero-based index into the text * @return the AttributeSet of the character * @since 1.3 */ public AttributeSet getCharacterAttribute(int i) { View view = (View) AbstractButton.this.getClientProperty("html"); if (view != null) { Document d = view.getDocument(); if (d instanceof StyledDocument) { StyledDocument doc = (StyledDocument)d; Element elem = doc.getCharacterElement(i); if (elem != null) { return elem.getAttributes(); } } } return null; } /** * Returns the start offset within the selected text. * If there is no selection, but there is * a caret, the start and end offsets will be the same. * * @return the index into the text of the start of the selection * @since 1.3 */ public int getSelectionStart() { // Text cannot be selected. return -1; } /** * Returns the end offset within the selected text. * If there is no selection, but there is * a caret, the start and end offsets will be the same. * * @return the index into teh text of the end of the selection * @since 1.3 */ public int getSelectionEnd() { // Text cannot be selected. return -1; } /** * Returns the portion of the text that is selected. * * @return the String portion of the text that is selected * @since 1.3 */ public String getSelectedText() { // Text cannot be selected. return null; } /* * Returns the text substring starting at the specified * offset with the specified length. */ private String getText(int offset, int length) throws BadLocationException { View view = (View) AbstractButton.this.getClientProperty("html"); if (view != null) { Document d = view.getDocument(); if (d instanceof StyledDocument) { StyledDocument doc = (StyledDocument)d; return doc.getText(offset, length); } } return null; } /* * Returns the bounding rectangle for the component text. */ private Rectangle getTextRectangle() { String text = AbstractButton.this.getText(); Icon icon = (AbstractButton.this.isEnabled()) ? AbstractButton.this.getIcon() : AbstractButton.this.getDisabledIcon(); if ((icon == null) && (text == null)) { return null; } Rectangle paintIconR = new Rectangle(); Rectangle paintTextR = new Rectangle(); Rectangle paintViewR = new Rectangle(); Insets paintViewInsets = new Insets(0, 0, 0, 0); paintViewInsets = AbstractButton.this.getInsets(paintViewInsets); paintViewR.x = paintViewInsets.left; paintViewR.y = paintViewInsets.top; paintViewR.width = AbstractButton.this.getWidth() - (paintViewInsets.left + paintViewInsets.right); paintViewR.height = AbstractButton.this.getHeight() - (paintViewInsets.top + paintViewInsets.bottom); String clippedText = SwingUtilities.layoutCompoundLabel( AbstractButton.this, getFontMetrics(getFont()), text, icon, AbstractButton.this.getVerticalAlignment(), AbstractButton.this.getHorizontalAlignment(), AbstractButton.this.getVerticalTextPosition(), AbstractButton.this.getHorizontalTextPosition(), paintViewR, paintIconR, paintTextR, 0); return paintTextR;