1 7 8 package javax.swing; 9 10 import java.awt.Component ; 11 import java.awt.Font ; 12 import java.awt.Image ; 13 import java.awt.*; 14 import java.text.*; 15 import java.awt.geom.*; 16 17 import java.io.ObjectOutputStream ; 18 import java.io.ObjectInputStream ; 19 import java.io.IOException ; 20 21 import javax.swing.plaf.LabelUI ; 22 import javax.accessibility.*; 23 import javax.swing.text.*; 24 import javax.swing.text.html.*; 25 import javax.swing.plaf.basic.*; 26 import java.util.*; 27 28 29 84 public class JLabel extends JComponent implements SwingConstants , Accessible 85 { 86 90 private static final String uiClassID = "LabelUI"; 91 92 private int mnemonic = '\0'; 93 private int mnemonicIndex = -1; 94 95 private String text = ""; private Icon defaultIcon = null; 97 private Icon disabledIcon = null; 98 private boolean disabledIconSet = false; 99 100 private int verticalAlignment = CENTER; 101 private int horizontalAlignment = LEADING; 102 private int verticalTextPosition = CENTER; 103 private int horizontalTextPosition = TRAILING; 104 private int iconTextGap = 4; 105 106 protected Component labelFor = null; 107 108 118 static final String LABELED_BY_PROPERTY = "labeledBy"; 119 120 136 public JLabel(String text, Icon icon, int horizontalAlignment) { 137 setText(text); 138 setIcon(icon); 139 setHorizontalAlignment(horizontalAlignment); 140 updateUI(); 141 setAlignmentX(LEFT_ALIGNMENT); 142 } 143 144 158 public JLabel(String text, int horizontalAlignment) { 159 this(text, null, horizontalAlignment); 160 } 161 162 169 public JLabel(String text) { 170 this(text, null, LEADING); 171 } 172 173 187 public JLabel(Icon image, int horizontalAlignment) { 188 this(null, image, horizontalAlignment); 189 } 190 191 198 public JLabel(Icon image) { 199 this(null, image, CENTER); 200 } 201 202 210 public JLabel() { 211 this("", null, LEADING); 212 } 213 214 215 220 public LabelUI getUI() { 221 return (LabelUI )ui; 222 } 223 224 225 236 public void setUI(LabelUI ui) { 237 super.setUI(ui); 238 if (!disabledIconSet && disabledIcon != null) { 240 setDisabledIcon(null); 241 } 242 } 243 244 245 250 public void updateUI() { 251 setUI((LabelUI )UIManager.getUI(this)); 252 } 253 254 255 264 public String getUIClassID() { 265 return uiClassID; 266 } 267 268 269 275 public String getText() { 276 return text; 277 } 278 279 280 297 public void setText(String text) { 298 299 String oldAccessibleName = null; 300 if (accessibleContext != null) { 301 oldAccessibleName = accessibleContext.getAccessibleName(); 302 } 303 304 String oldValue = this.text; 305 this.text = text; 306 firePropertyChange("text", oldValue, text); 307 308 setDisplayedMnemonicIndex( 309 SwingUtilities.findDisplayedMnemonicIndex( 310 text, getDisplayedMnemonic())); 311 312 if ((accessibleContext != null) 313 && (accessibleContext.getAccessibleName() != oldAccessibleName)) { 314 accessibleContext.firePropertyChange( 315 AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY, 316 oldAccessibleName, 317 accessibleContext.getAccessibleName()); 318 } 319 if (text == null || oldValue == null || !text.equals(oldValue)) { 320 revalidate(); 321 repaint(); 322 } 323 } 324 325 326 332 public Icon getIcon() { 333 return defaultIcon; 334 } 335 336 353 public void setIcon(Icon icon) { 354 Icon oldValue = defaultIcon; 355 defaultIcon = icon; 356 357 362 if ((defaultIcon != oldValue) && !disabledIconSet) { 363 disabledIcon = null; 364 } 365 366 firePropertyChange("icon", oldValue, defaultIcon); 367 368 if ((accessibleContext != null) && (oldValue != defaultIcon)) { 369 accessibleContext.firePropertyChange( 370 AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY, 371 oldValue, defaultIcon); 372 } 373 374 378 if (defaultIcon != oldValue) { 379 if ((defaultIcon == null) || 380 (oldValue == null) || 381 (defaultIcon.getIconWidth() != oldValue.getIconWidth()) || 382 (defaultIcon.getIconHeight() != oldValue.getIconHeight())) { 383 revalidate(); 384 } 385 repaint(); 386 } 387 } 388 389 390 403 public Icon getDisabledIcon() { 404 if (!disabledIconSet && disabledIcon == null && defaultIcon != null) { 405 disabledIcon = UIManager.getLookAndFeel().getDisabledIcon(this, defaultIcon); 406 if (disabledIcon != null) { 407 firePropertyChange("disabledIcon", null, disabledIcon); 408 } 409 } 410 return disabledIcon; 411 } 412 413 414 428 public void setDisabledIcon(Icon disabledIcon) { 429 Icon oldValue = this.disabledIcon; 430 this.disabledIcon = disabledIcon; 431 disabledIconSet = (disabledIcon != null); 432 firePropertyChange("disabledIcon", oldValue, disabledIcon); 433 if (disabledIcon != oldValue) { 434 if (disabledIcon == null || oldValue == null || 435 disabledIcon.getIconWidth() != oldValue.getIconWidth() || 436 disabledIcon.getIconHeight() != oldValue.getIconHeight()) { 437 revalidate(); 438 } 439 if (!isEnabled()) { 440 repaint(); 441 } 442 } 443 } 444 445 446 460 public void setDisplayedMnemonic(int key) { 461 int oldKey = mnemonic; 462 mnemonic = key; 463 firePropertyChange("displayedMnemonic", oldKey, mnemonic); 464 465 setDisplayedMnemonicIndex( 466 SwingUtilities.findDisplayedMnemonicIndex(getText(), mnemonic)); 467 468 if (key != oldKey) { 469 revalidate(); 470 repaint(); 471 } 472 } 473 474 475 481 public void setDisplayedMnemonic(char aChar) { 482 int vk = (int) aChar; 483 if(vk >= 'a' && vk <='z') 484 vk -= ('a' - 'A'); 485 setDisplayedMnemonic(vk); 486 } 487 488 489 501 public int getDisplayedMnemonic() { 502 return mnemonic; 503 } 504 505 532 public void setDisplayedMnemonicIndex(int index) 533 throws IllegalArgumentException { 534 int oldValue = mnemonicIndex; 535 if (index == -1) { 536 mnemonicIndex = -1; 537 } else { 538 String text = getText(); 539 int textLength = (text == null) ? 0 : text.length(); 540 if (index < -1 || index >= textLength) { throw new IllegalArgumentException ("index == " + index); 542 } 543 } 544 mnemonicIndex = index; 545 firePropertyChange("displayedMnemonicIndex", oldValue, index); 546 if (index != oldValue) { 547 revalidate(); 548 repaint(); 549 } 550 } 551 552 560 public int getDisplayedMnemonicIndex() { 561 return mnemonicIndex; 562 } 563 564 574 protected int checkHorizontalKey(int key, String message) { 575 if ((key == LEFT) || 576 (key == CENTER) || 577 (key == RIGHT) || 578 (key == LEADING) || 579 (key == TRAILING)) { 580 return key; 581 } 582 else { 583 throw new IllegalArgumentException (message); 584 } 585 } 586 587 588 598 protected int checkVerticalKey(int key, String message) { 599 if ((key == TOP) || (key == CENTER) || (key == BOTTOM)) { 600 return key; 601 } 602 else { 603 throw new IllegalArgumentException (message); 604 } 605 } 606 607 608 616 public int getIconTextGap() { 617 return iconTextGap; 618 } 619 620 621 636 public void setIconTextGap(int iconTextGap) { 637 int oldValue = this.iconTextGap; 638 this.iconTextGap = iconTextGap; 639 firePropertyChange("iconTextGap", oldValue, iconTextGap); 640 if (iconTextGap != oldValue) { 641 revalidate(); 642 repaint(); 643 } 644 } 645 646 647 648 660 public int getVerticalAlignment() { 661 return verticalAlignment; 662 } 663 664 665 686 public void setVerticalAlignment(int alignment) { 687 if (alignment == verticalAlignment) return; 688 int oldValue = verticalAlignment; 689 verticalAlignment = checkVerticalKey(alignment, "verticalAlignment"); 690 firePropertyChange("verticalAlignment", oldValue, verticalAlignment); 691 repaint(); 692 } 693 694 695 709 public int getHorizontalAlignment() { 710 return horizontalAlignment; 711 } 712 713 738 public void setHorizontalAlignment(int alignment) { 739 if (alignment == horizontalAlignment) return; 740 int oldValue = horizontalAlignment; 741 horizontalAlignment = checkHorizontalKey(alignment, 742 "horizontalAlignment"); 743 firePropertyChange("horizontalAlignment", 744 oldValue, horizontalAlignment); 745 repaint(); 746 } 747 748 749 762 public int getVerticalTextPosition() { 763 return verticalTextPosition; 764 } 765 766 767 792 public void setVerticalTextPosition(int textPosition) { 793 if (textPosition == verticalTextPosition) return; 794 int old = verticalTextPosition; 795 verticalTextPosition = checkVerticalKey(textPosition, 796 "verticalTextPosition"); 797 firePropertyChange("verticalTextPosition", old, verticalTextPosition); 798 repaint(); 799 } 800 801 802 816 public int getHorizontalTextPosition() { 817 return horizontalTextPosition; 818 } 819 820 821 847 public void setHorizontalTextPosition(int textPosition) { 848 int old = horizontalTextPosition; 849 this.horizontalTextPosition = checkHorizontalKey(textPosition, 850 "horizontalTextPosition"); 851 firePropertyChange("horizontalTextPosition", 852 old, horizontalTextPosition); 853 repaint(); 854 } 855 856 857 864 public boolean imageUpdate(Image img, int infoflags, 865 int x, int y, int w, int h) { 866 if (!isShowing() || 869 !SwingUtilities.doesIconReferenceImage(getIcon(), img) && 870 !SwingUtilities.doesIconReferenceImage(disabledIcon, img)) { 871 872 return false; 873 } 874 return super.imageUpdate(img, infoflags, x, y, w, h); 875 } 876 877 878 882 private void writeObject(ObjectOutputStream s) throws IOException { 883 s.defaultWriteObject(); 884 if (getUIClassID().equals(uiClassID)) { 885 byte count = JComponent.getWriteObjCounter(this); 886 JComponent.setWriteObjCounter(this, --count); 887 if (count == 0 && ui != null) { 888 ui.installUI(this); 889 } 890 } 891 } 892 893 894 903 protected String paramString() { 904 String textString = (text != null ? 905 text : ""); 906 String defaultIconString = ((defaultIcon != null) 907 && (defaultIcon != this) ? 908 defaultIcon.toString() : ""); 909 String disabledIconString = ((disabledIcon != null) 910 && (disabledIcon != this) ? 911 disabledIcon.toString() : ""); 912 String labelForString = (labelFor != null ? 913 labelFor.toString() : ""); 914 String verticalAlignmentString; 915 if (verticalAlignment == TOP) { 916 verticalAlignmentString = "TOP"; 917 } else if (verticalAlignment == CENTER) { 918 verticalAlignmentString = "CENTER"; 919 } else if (verticalAlignment == BOTTOM) { 920 verticalAlignmentString = "BOTTOM"; 921 } else verticalAlignmentString = ""; 922 String horizontalAlignmentString; 923 if (horizontalAlignment == LEFT) { 924 horizontalAlignmentString = "LEFT"; 925 } else if (horizontalAlignment == CENTER) { 926 horizontalAlignmentString = "CENTER"; 927 } else if (horizontalAlignment == RIGHT) { 928 horizontalAlignmentString = "RIGHT"; 929 } else if (horizontalAlignment == LEADING) { 930 horizontalAlignmentString = "LEADING"; 931 } else if (horizontalAlignment == TRAILING) { 932 horizontalAlignmentString = "TRAILING"; 933 } else horizontalAlignmentString = ""; 934 String verticalTextPositionString; 935 if (verticalTextPosition == TOP) { 936 verticalTextPositionString = "TOP"; 937 } else if (verticalTextPosition == CENTER) { 938 verticalTextPositionString = "CENTER"; 939 } else if (verticalTextPosition == BOTTOM) { 940 verticalTextPositionString = "BOTTOM"; 941 } else verticalTextPositionString = ""; 942 String horizontalTextPositionString; 943 if (horizontalTextPosition == LEFT) { 944 horizontalTextPositionString = "LEFT"; 945 } else if (horizontalTextPosition == CENTER) { 946 horizontalTextPositionString = "CENTER"; 947 } else if (horizontalTextPosition == RIGHT) { 948 horizontalTextPositionString = "RIGHT"; 949 } else if (horizontalTextPosition == LEADING) { 950 horizontalTextPositionString = "LEADING"; 951 } else if (horizontalTextPosition == TRAILING) { 952 horizontalTextPositionString = "TRAILING"; 953 } else horizontalTextPositionString = ""; 954 955 return super.paramString() + 956 ",defaultIcon=" + defaultIconString + 957 ",disabledIcon=" + disabledIconString + 958 ",horizontalAlignment=" + horizontalAlignmentString + 959 ",horizontalTextPosition=" + horizontalTextPositionString + 960 ",iconTextGap=" + iconTextGap + 961 ",labelFor=" + labelForString + 962 ",text=" + textString + 963 ",verticalAlignment=" + verticalAlignmentString + 964 ",verticalTextPosition=" + verticalTextPositionString; 965 } 966 967 970 971 983 public Component getLabelFor() { 984 return labelFor; 985 } 986 987 1004 public void setLabelFor(Component c) { 1005 Component oldC = labelFor; 1006 labelFor = c; 1007 firePropertyChange("labelFor", oldC, c); 1008 1009 if (oldC instanceof JComponent ) { 1010 ((JComponent )oldC).putClientProperty(LABELED_BY_PROPERTY, null); 1011 } 1012 if (c instanceof JComponent ) { 1013 ((JComponent )c).putClientProperty(LABELED_BY_PROPERTY, this); 1014 } 1015 } 1016 1017 1025 public AccessibleContext getAccessibleContext() { 1026 if (accessibleContext == null) { 1027 accessibleContext = new AccessibleJLabel(); 1028 } 1029 return accessibleContext; 1030 } 1031 1032 1044 protected class AccessibleJLabel extends AccessibleJComponent 1045 implements AccessibleText, AccessibleExtendedComponent { 1046 1047 1054 public String getAccessibleName() { 1055 if (accessibleName != null) { 1056 return accessibleName; 1057 } else { 1058 if (JLabel.this.getText() == null) { 1059 return super.getAccessibleName(); 1060 } else { 1061 return JLabel.this.getText(); 1062 } 1063 } 1064 } 1065 1066 1073 public AccessibleRole getAccessibleRole() { 1074 return AccessibleRole.LABEL; 1075 } 1076 1077 1081 public AccessibleIcon [] getAccessibleIcon() { 1082 Icon icon = getIcon(); 1083 if (icon instanceof Accessible) { 1084 AccessibleContext ac = 1085 ((Accessible)icon).getAccessibleContext(); 1086 if (ac != null && ac instanceof AccessibleIcon) { 1087 return new AccessibleIcon[] { (AccessibleIcon)ac }; 1088 } 1089 } 1090 return null; 1091 } 1092 1093 1098 public AccessibleRelationSet getAccessibleRelationSet() { 1099 AccessibleRelationSet relationSet 1102 = super.getAccessibleRelationSet(); 1103 1104 if (!relationSet.contains(AccessibleRelation.LABEL_FOR)) { 1105 Component c = JLabel.this.getLabelFor(); 1106 if (c != null) { 1107 AccessibleRelation relation 1108 = new AccessibleRelation(AccessibleRelation.LABEL_FOR); 1109 relation.setTarget(c); 1110 relationSet.add(relation); 1111 } 1112 } 1113 return relationSet; 1114 } 1115 1116 1117 1118 1119 public AccessibleText getAccessibleText() { 1120 View view = (View)JLabel.this.getClientProperty("html"); 1121 if (view != null) { 1122 return this; 1123 } else { 1124 return null; 1125 } 1126 } 1127 1128 1137 public int getIndexAtPoint(Point p) { 1138 View view = (View) JLabel.this.getClientProperty("html"); 1139 if (view != null) { 1140 Rectangle r = getTextRectangle(); 1141 if (r == null) { 1142 return -1; 1143 } 1144 Rectangle2D.Float shape = 1145 new Rectangle2D.Float(r.x, r.y, r.width, r.height); 1146 Position.Bias bias[] = new Position.Bias[1]; 1147 return view.viewToModel(p.x, p.y, shape, bias); 1148 } else { 1149 return -1; 1150 } 1151 } 1152 1153 1163 public Rectangle getCharacterBounds(int i) { 1164 View view = (View) JLabel.this.getClientProperty("html"); 1165 if (view != null) { 1166 Rectangle r = getTextRectangle(); 1167 if (r == null) { 1168 return null; 1169 } 1170 Rectangle2D.Float shape = 1171 new Rectangle2D.Float(r.x, r.y, r.width, r.height); 1172 try { 1173 Shape charShape = 1174 view.modelToView(i, shape, Position.Bias.Forward); 1175 return charShape.getBounds(); 1176 } catch (BadLocationException e) { 1177 return null; 1178 } 1179 } else { 1180 return null; 1181 } 1182 } 1183 1184 1189 public int getCharCount() { 1190 View view = (View) JLabel.this.getClientProperty("html"); 1191 if (view != null) { 1192 Document d = view.getDocument(); 1193 if (d instanceof StyledDocument) { 1194 StyledDocument doc = (StyledDocument)d; 1195 return doc.getLength(); 1196 } 1197 } 1198 return accessibleContext.getAccessibleName().length(); 1199 } 1200 1201 1208 public int getCaretPosition() { 1209 return -1; 1211 } 1212 1213 1222 public String getAtIndex(int part, int index) { 1223 if (index < 0 || index >= getCharCount()) { 1224 return null; 1225 } 1226 switch (part) { 1227 case AccessibleText.CHARACTER: 1228 try { 1229 return getText(index, 1); 1230 } catch (BadLocationException e) { 1231 return null; 1232 } 1233 case AccessibleText.WORD: 1234 try { 1235 String s = getText(0, getCharCount()); 1236 BreakIterator words = BreakIterator.getWordInstance(getLocale()); 1237 words.setText(s); 1238 int end = words.following(index); 1239 return s.substring(words.previous(), end); 1240 } catch (BadLocationException e) { 1241 return null; 1242 } 1243 case AccessibleText.SENTENCE: 1244 try { 1245 String s = getText(0, getCharCount()); 1246 BreakIterator sentence = 1247 BreakIterator.getSentenceInstance(getLocale()); 1248 sentence.setText(s); 1249 int end = sentence.following(index); 1250 return s.substring(sentence.previous(), end); 1251 } catch (BadLocationException e) { 1252 return null; 1253 } 1254 default: 1255 return null; 1256 } 1257 } 1258 1259 1268 public String getAfterIndex(int part, int index) { 1269 if (index < 0 || index >= getCharCount()) { 1270 return null; 1271 } 1272 switch (part) { 1273 case AccessibleText.CHARACTER: 1274 if (index+1 >= getCharCount()) { 1275 return null; 1276 } 1277 try { 1278 return getText(index+1, 1); 1279 } catch (BadLocationException e) { 1280 return null; 1281 } 1282 case AccessibleText.WORD: 1283 try { 1284 String s = getText(0, getCharCount()); 1285 BreakIterator words = BreakIterator.getWordInstance(getLocale()); 1286 words.setText(s); 1287 int start = words.following(index); 1288 if (start == BreakIterator.DONE || start >= s.length()) { 1289 return null; 1290 } 1291 int end = words.following(start); 1292 if (end == BreakIterator.DONE || end >= s.length()) { 1293 return null; 1294 } 1295 return s.substring(start, end); 1296 } catch (BadLocationException e) { 1297 return null; 1298 } 1299 case AccessibleText.SENTENCE: 1300 try { 1301 String s = getText(0, getCharCount()); 1302 BreakIterator sentence = 1303 BreakIterator.getSentenceInstance(getLocale()); 1304 sentence.setText(s); 1305 int start = sentence.following(index); 1306 if (start == BreakIterator.DONE || start >= s.length()) { 1307 return null; 1308 } 1309 int end = sentence.following(start); 1310 if (end == BreakIterator.DONE || end >= s.length()) { 1311 return null; 1312 } 1313 return s.substring(start, end); 1314 } catch (BadLocationException e) { 1315 return null; 1316 } 1317 default: 1318 return null; 1319 } 1320 } 1321 1322 1331 public String getBeforeIndex(int part, int index) { 1332 if (index < 0 || index > getCharCount()-1) { 1333 return null; 1334 } 1335 switch (part) { 1336 case AccessibleText.CHARACTER: 1337 if (index == 0) { 1338 return null; 1339 } 1340 try { 1341 return getText(index-1, 1); 1342 } catch (BadLocationException e) { 1343 return null; 1344 } 1345 case AccessibleText.WORD: 1346 try { 1347 String s = getText(0, getCharCount()); 1348 BreakIterator words = BreakIterator.getWordInstance(getLocale()); 1349 words.setText(s); 1350 int end = words.following(index); 1351 end = words.previous(); 1352 int start = words.previous(); 1353 if (start == BreakIterator.DONE) { 1354 return null; 1355 } 1356 return s.substring(start, end); 1357 } catch (BadLocationException e) { 1358 return null; 1359 } 1360 case AccessibleText.SENTENCE: 1361 try { 1362 String s = getText(0, getCharCount()); 1363 BreakIterator sentence = 1364 BreakIterator.getSentenceInstance(getLocale()); 1365 sentence.setText(s); 1366 int end = sentence.following(index); 1367 end = sentence.previous(); 1368 int start = sentence.previous(); 1369 if (start == BreakIterator.DONE) { 1370 return null; 1371 } 1372 return s.substring(start, end); 1373 } catch (BadLocationException e) { 1374 return null; 1375 } 1376 default: 1377 return null; 1378 } 1379 } 1380 1381 1387 public AttributeSet getCharacterAttribute(int i) { 1388 View view = (View) JLabel.this.getClientProperty("html"); 1389 if (view != null) { 1390 Document d = view.getDocument(); 1391 if (d instanceof StyledDocument) { 1392 StyledDocument doc = (StyledDocument)d; 1393 Element elem = doc.getCharacterElement(i); 1394 if (elem != null) { 1395 return elem.getAttributes(); 1396 } 1397 } 1398 } 1399 return null; 1400 } 1401 1402 1409 public int getSelectionStart() { 1410 return -1; 1412 } 1413 1414 1421 public int getSelectionEnd() { 1422 return -1; 1424 } 1425 1426 1431 public String getSelectedText() { 1432 return null; 1434 } 1435 1436 1440 private String getText(int offset, int length) 1441 throws BadLocationException { 1442 1443 View view = (View) JLabel.this.getClientProperty("html"); 1444 if (view != null) { 1445 Document d = view.getDocument(); 1446 if (d instanceof StyledDocument) { 1447 StyledDocument doc = (StyledDocument)d; 1448 return doc.getText(offset, length); 1449 } 1450 } 1451 return null; 1452 } 1453 1454 1457 private Rectangle getTextRectangle() { 1458 1459 String text = JLabel.this.getText(); 1460 Icon icon = (JLabel.this.isEnabled()) ? JLabel.this.getIcon() : JLabel.this.getDisabledIcon(); 1461 1462 if ((icon == null) && (text == null)) { 1463 return null; 1464 } 1465 1466 Rectangle paintIconR = new Rectangle(); 1467 Rectangle paintTextR = new Rectangle(); 1468 Rectangle paintViewR = new Rectangle(); 1469 Insets paintViewInsets = new Insets(0, 0, 0, 0); 1470 1471 paintViewInsets = JLabel.this.getInsets(paintViewInsets); 1472 paintViewR.x = paintViewInsets.left; 1473 paintViewR.y = paintViewInsets.top; 1474 paintViewR.width = JLabel.this.getWidth() - (paintViewInsets.left + paintViewInsets.right); 1475 paintViewR.height = JLabel.this.getHeight() - (paintViewInsets.top + paintViewInsets.bottom); 1476 1477 Graphics g = JLabel.this.getGraphics(); 1478 if (g == null) { 1479 return null; 1480 } 1481 String clippedText = SwingUtilities.layoutCompoundLabel( 1482 (JComponent )JLabel.this, 1483 g.getFontMetrics(), 1484 text, 1485 icon, 1486 JLabel.this.getVerticalAlignment(), 1487 JLabel.this.getHorizontalAlignment(), 1488 JLabel.this.getVerticalTextPosition(), 1489 JLabel.this.getHorizontalTextPosition(), 1490 paintViewR, 1491 paintIconR, 1492 paintTextR, 1493 JLabel.this.getIconTextGap()); 1494 1495 return paintTextR; 1496 } 1497 1498 1500 1505 AccessibleExtendedComponent getAccessibleExtendedComponent() { 1506 return this; 1507 } 1508 1509 1515 public String getToolTipText() { 1516 return JLabel.this.getToolTipText(); 1517 } 1518 1519 1525 public String getTitledBorderText() { 1526 return super.getTitledBorderText(); 1527 } 1528 1529 1536 public AccessibleKeyBinding getAccessibleKeyBinding() { 1537 int mnemonic = JLabel.this.getDisplayedMnemonic(); 1538 if (mnemonic == 0) { 1539 return null; 1540 } 1541 return new LabelKeyBinding(mnemonic); 1542 } 1543 1544 class LabelKeyBinding implements AccessibleKeyBinding { 1545 int mnemonic; 1546 1547 LabelKeyBinding(int mnemonic) { 1548 this.mnemonic = mnemonic; 1549 } 1550 1551 1556 public int getAccessibleKeyBindingCount() { 1557 return 1; 1558 } 1559 1560 1585 public java.lang.Object getAccessibleKeyBinding(int i) { 1586 if (i != 0) { 1587 throw new IllegalArgumentException (); 1588 } 1589 return KeyStroke.getKeyStroke(mnemonic, 0); 1590 } 1591 } 1592 1593 } } 1595 | Popular Tags |