1 7 8 package javax.swing; 9 10 import java.awt.*; 11 import java.awt.event.*; 12 13 import javax.swing.*; 14 import javax.swing.event.*; 15 import javax.swing.text.*; 16 import javax.swing.plaf.SpinnerUI ; 17 18 import java.util.*; 19 import java.beans.*; 20 import java.text.*; 21 import java.io.*; 22 import java.util.HashMap ; 23 import sun.text.resources.LocaleData; 24 25 import javax.accessibility.*; 26 27 28 101 public class JSpinner extends JComponent implements Accessible 102 { 103 107 private static final String uiClassID = "SpinnerUI"; 108 109 private static final Action DISABLED_ACTION = new DisabledAction(); 110 111 private transient SpinnerModel model; 112 private JComponent editor; 113 private ChangeListener modelListener; 114 private transient ChangeEvent changeEvent; 115 private boolean editorExplicitlySet = false; 116 117 118 122 public JSpinner(SpinnerModel model) { 123 this.model = model; 124 this.editor = createEditor(model); 125 setOpaque(true); 126 updateUI(); 127 } 128 129 130 134 public JSpinner() { 135 this(new SpinnerNumberModel ()); 136 } 137 138 139 144 public SpinnerUI getUI() { 145 return (SpinnerUI )ui; 146 } 147 148 149 155 public void setUI(SpinnerUI ui) { 156 super.setUI(ui); 157 } 158 159 160 168 public String getUIClassID() { 169 return uiClassID; 170 } 171 172 173 174 179 public void updateUI() { 180 setUI((SpinnerUI )UIManager.getUI(this)); 181 invalidate(); 182 } 183 184 185 210 protected JComponent createEditor(SpinnerModel model) { 211 if (model instanceof SpinnerDateModel ) { 212 return new DateEditor(this); 213 } 214 else if (model instanceof SpinnerListModel ) { 215 return new ListEditor(this); 216 } 217 else if (model instanceof SpinnerNumberModel ) { 218 return new NumberEditor(this); 219 } 220 else { 221 return new DefaultEditor(this); 222 } 223 } 224 225 226 248 public void setModel(SpinnerModel model) { 249 if (model == null) { 250 throw new IllegalArgumentException ("null model"); 251 } 252 if (!model.equals(this.model)) { 253 SpinnerModel oldModel = this.model; 254 this.model = model; 255 if (modelListener != null) { 256 this.model.addChangeListener(modelListener); 257 } 258 firePropertyChange("model", oldModel, model); 259 if (!editorExplicitlySet) { 260 setEditor(createEditor(model)); editorExplicitlySet = false; 262 } 263 repaint(); 264 revalidate(); 265 } 266 } 267 268 269 276 public SpinnerModel getModel() { 277 return model; 278 } 279 280 281 298 public Object getValue() { 299 return getModel().getValue(); 300 } 301 302 303 320 public void setValue(Object value) { 321 getModel().setValue(value); 322 } 323 324 325 342 public Object getNextValue() { 343 return getModel().getNextValue(); 344 } 345 346 347 351 private class ModelListener implements ChangeListener, Serializable { 352 public void stateChanged(ChangeEvent e) { 353 fireStateChanged(); 354 } 355 } 356 357 358 372 public void addChangeListener(ChangeListener listener) { 373 if (modelListener == null) { 374 modelListener = new ModelListener(); 375 getModel().addChangeListener(modelListener); 376 } 377 listenerList.add(ChangeListener.class, listener); 378 } 379 380 381 382 389 public void removeChangeListener(ChangeListener listener) { 390 listenerList.remove(ChangeListener.class, listener); 391 } 392 393 394 402 public ChangeListener[] getChangeListeners() { 403 return (ChangeListener[])listenerList.getListeners( 404 ChangeListener.class); 405 } 406 407 408 419 protected void fireStateChanged() { 420 Object [] listeners = listenerList.getListenerList(); 421 for (int i = listeners.length - 2; i >= 0; i -= 2) { 422 if (listeners[i] == ChangeListener.class) { 423 if (changeEvent == null) { 424 changeEvent = new ChangeEvent(this); 425 } 426 ((ChangeListener)listeners[i+1]).stateChanged(changeEvent); 427 } 428 } 429 } 430 431 432 451 public Object getPreviousValue() { 452 return getModel().getPreviousValue(); 453 } 454 455 456 475 public void setEditor(JComponent editor) { 476 if (editor == null) { 477 throw new IllegalArgumentException ("null editor"); 478 } 479 if (!editor.equals(this.editor)) { 480 JComponent oldEditor = this.editor; 481 this.editor = editor; 482 if (oldEditor instanceof DefaultEditor) { 483 ((DefaultEditor)oldEditor).dismiss(this); 484 } 485 editorExplicitlySet = true; 486 firePropertyChange("editor", oldEditor, editor); 487 revalidate(); 488 repaint(); 489 } 490 } 491 492 493 502 public JComponent getEditor() { 503 return editor; 504 } 505 506 507 516 public void commitEdit() throws ParseException { 517 JComponent editor = getEditor(); 518 if (editor instanceof DefaultEditor) { 519 ((DefaultEditor)editor).commitEdit(); 520 } 521 } 522 523 524 530 private void writeObject(ObjectOutputStream s) throws IOException { 531 s.defaultWriteObject(); 532 HashMap additionalValues = new HashMap (1); 533 SpinnerModel model = getModel(); 534 535 if (model instanceof Serializable) { 536 additionalValues.put("model", model); 537 } 538 s.writeObject(additionalValues); 539 540 if (getUIClassID().equals(uiClassID)) { 541 byte count = JComponent.getWriteObjCounter(this); 542 JComponent.setWriteObjCounter(this, --count); 543 if (count == 0 && ui != null) { 544 ui.installUI(this); 545 } 546 } 547 } 548 549 550 private void readObject(ObjectInputStream s) 551 throws IOException, ClassNotFoundException { 552 s.defaultReadObject(); 553 554 Map additionalValues = (Map )s.readObject(); 555 556 model = (SpinnerModel )additionalValues.get("model"); 557 } 558 559 560 589 public static class DefaultEditor extends JPanel 590 implements ChangeListener, PropertyChangeListener, LayoutManager 591 { 592 604 public DefaultEditor(JSpinner spinner) { 605 super(null); 606 607 JFormattedTextField ftf = new JFormattedTextField (); 608 ftf.setName("Spinner.formattedTextField"); 609 ftf.setValue(spinner.getValue()); 610 ftf.addPropertyChangeListener(this); 611 ftf.setEditable(false); 612 613 String toolTipText = spinner.getToolTipText(); 614 if (toolTipText != null) { 615 ftf.setToolTipText(toolTipText); 616 } 617 618 add(ftf); 619 620 setLayout(this); 621 spinner.addChangeListener(this); 622 623 ActionMap ftfMap = ftf.getActionMap(); 629 630 if (ftfMap != null) { 631 ftfMap.put("increment", DISABLED_ACTION); 632 ftfMap.put("decrement", DISABLED_ACTION); 633 } 634 } 635 636 637 645 public void dismiss(JSpinner spinner) { 646 spinner.removeChangeListener(this); 647 } 648 649 650 660 public JSpinner getSpinner() { 661 for (Component c = this; c != null; c = c.getParent()) { 662 if (c instanceof JSpinner ) { 663 return (JSpinner )c; 664 } 665 } 666 return null; 667 } 668 669 670 680 public JFormattedTextField getTextField() { 681 return (JFormattedTextField )getComponent(0); 682 } 683 684 685 694 public void stateChanged(ChangeEvent e) { 695 JSpinner spinner = (JSpinner )(e.getSource()); 696 getTextField().setValue(spinner.getValue()); 697 } 698 699 700 715 public void propertyChange(PropertyChangeEvent e) 716 { 717 JSpinner spinner = getSpinner(); 718 719 if (spinner == null) { 720 return; 722 } 723 724 Object source = e.getSource(); 725 String name = e.getPropertyName(); 726 if ((source instanceof JFormattedTextField ) && "value".equals(name)) { 727 Object lastValue = spinner.getValue(); 728 729 try { 731 spinner.setValue(getTextField().getValue()); 732 } catch (IllegalArgumentException iae) { 733 try { 735 ((JFormattedTextField )source).setValue(lastValue); 736 } catch (IllegalArgumentException iae2) { 737 } 741 } 742 } 743 } 744 745 746 754 public void addLayoutComponent(String name, Component child) { 755 } 756 757 758 764 public void removeLayoutComponent(Component child) { 765 } 766 767 768 771 private Dimension insetSize(Container parent) { 772 Insets insets = parent.getInsets(); 773 int w = insets.left + insets.right; 774 int h = insets.top + insets.bottom; 775 return new Dimension(w, h); 776 } 777 778 779 787 public Dimension preferredLayoutSize(Container parent) { 788 Dimension preferredSize = insetSize(parent); 789 if (parent.getComponentCount() > 0) { 790 Dimension childSize = getComponent(0).getPreferredSize(); 791 preferredSize.width += childSize.width; 792 preferredSize.height += childSize.height; 793 } 794 return preferredSize; 795 } 796 797 798 806 public Dimension minimumLayoutSize(Container parent) { 807 Dimension minimumSize = insetSize(parent); 808 if (parent.getComponentCount() > 0) { 809 Dimension childSize = getComponent(0).getMinimumSize(); 810 minimumSize.width += childSize.width; 811 minimumSize.height += childSize.height; 812 } 813 return minimumSize; 814 } 815 816 817 821 public void layoutContainer(Container parent) { 822 if (parent.getComponentCount() > 0) { 823 Insets insets = parent.getInsets(); 824 int w = parent.getWidth() - (insets.left + insets.right); 825 int h = parent.getHeight() - (insets.top + insets.bottom); 826 getComponent(0).setBounds(insets.left, insets.top, w, h); 827 } 828 } 829 830 838 public void commitEdit() throws ParseException { 839 JFormattedTextField ftf = getTextField(); 843 844 ftf.commitEdit(); 845 } 846 } 847 848 849 850 851 855 private static class DateEditorFormatter extends DateFormatter { 856 private final SpinnerDateModel model; 857 858 DateEditorFormatter(SpinnerDateModel model, DateFormat format) { 859 super(format); 860 this.model = model; 861 } 862 863 public void setMinimum(Comparable min) { 864 model.setStart(min); 865 } 866 867 public Comparable getMinimum() { 868 return model.getStart(); 869 } 870 871 public void setMaximum(Comparable max) { 872 model.setEnd(max); 873 } 874 875 public Comparable getMaximum() { 876 return model.getEnd(); 877 } 878 } 879 880 881 889 public static class DateEditor extends DefaultEditor 891 { 892 private static String getDefaultPattern(Locale loc) { 895 ResourceBundle r = LocaleData.getLocaleElements(loc); 896 String [] dateTimePatterns = r.getStringArray("DateTimePatterns"); 897 Object [] dateTimeArgs = {dateTimePatterns[DateFormat.SHORT], 898 dateTimePatterns[DateFormat.SHORT + 4]}; 899 return MessageFormat.format(dateTimePatterns[8], dateTimeArgs); 900 } 901 902 918 public DateEditor(JSpinner spinner) { 919 this(spinner, getDefaultPattern(spinner.getLocale())); 920 } 921 922 923 943 public DateEditor(JSpinner spinner, String dateFormatPattern) { 944 this(spinner, new SimpleDateFormat(dateFormatPattern, 945 spinner.getLocale())); 946 } 947 948 968 private DateEditor(JSpinner spinner, DateFormat format) { 969 super(spinner); 970 if (!(spinner.getModel() instanceof SpinnerDateModel )) { 971 throw new IllegalArgumentException ( 972 "model not a SpinnerDateModel"); 973 } 974 975 SpinnerDateModel model = (SpinnerDateModel )spinner.getModel(); 976 DateFormatter formatter = new DateEditorFormatter(model, format); 977 DefaultFormatterFactory factory = new DefaultFormatterFactory( 978 formatter); 979 JFormattedTextField ftf = getTextField(); 980 ftf.setEditable(true); 981 ftf.setFormatterFactory(factory); 982 983 987 try { 988 String maxString = formatter.valueToString(model.getStart()); 989 String minString = formatter.valueToString(model.getEnd()); 990 ftf.setColumns(Math.max(maxString.length(), 991 minString.length())); 992 } 993 catch (ParseException e) { 994 } 996 } 997 998 1007 public SimpleDateFormat getFormat() { 1008 return (SimpleDateFormat)((DateFormatter)(getTextField().getFormatter())).getFormat(); 1009 } 1010 1011 1012 1019 public SpinnerDateModel getModel() { 1020 return (SpinnerDateModel )(getSpinner().getModel()); 1021 } 1022 } 1023 1024 1025 1030 private static class NumberEditorFormatter extends NumberFormatter { 1031 private final SpinnerNumberModel model; 1032 1033 NumberEditorFormatter(SpinnerNumberModel model, NumberFormat format) { 1034 super(format); 1035 this.model = model; 1036 setValueClass(model.getValue().getClass()); 1037 } 1038 1039 public void setMinimum(Comparable min) { 1040 model.setMinimum(min); 1041 } 1042 1043 public Comparable getMinimum() { 1044 return model.getMinimum(); 1045 } 1046 1047 public void setMaximum(Comparable max) { 1048 model.setMaximum(max); 1049 } 1050 1051 public Comparable getMaximum() { 1052 return model.getMaximum(); 1053 } 1054 } 1055 1056 1057 1058 1066 public static class NumberEditor extends DefaultEditor 1068 { 1069 private static String getDefaultPattern(Locale locale) { 1072 ResourceBundle rb = LocaleData.getLocaleElements(locale); 1074 String [] all = rb.getStringArray("NumberPatterns"); 1075 return all[0]; 1076 } 1077 1078 1094 public NumberEditor(JSpinner spinner) { 1095 this(spinner, getDefaultPattern(spinner.getLocale())); 1096 } 1097 1098 1119 public NumberEditor(JSpinner spinner, String decimalFormatPattern) { 1120 this(spinner, new DecimalFormat(decimalFormatPattern)); 1121 } 1122 1123 1124 1143 private NumberEditor(JSpinner spinner, DecimalFormat format) { 1144 super(spinner); 1145 if (!(spinner.getModel() instanceof SpinnerNumberModel )) { 1146 throw new IllegalArgumentException ( 1147 "model not a SpinnerNumberModel"); 1148 } 1149 1150 SpinnerNumberModel model = (SpinnerNumberModel )spinner.getModel(); 1151 NumberFormatter formatter = new NumberEditorFormatter(model, 1152 format); 1153 DefaultFormatterFactory factory = new DefaultFormatterFactory( 1154 formatter); 1155 JFormattedTextField ftf = getTextField(); 1156 ftf.setEditable(true); 1157 ftf.setFormatterFactory(factory); 1158 ftf.setHorizontalAlignment(JTextField.RIGHT); 1159 1160 1164 try { 1165 String maxString = formatter.valueToString(model.getMinimum()); 1166 String minString = formatter.valueToString(model.getMaximum()); 1167 ftf.setColumns(Math.max(maxString.length(), 1168 minString.length())); 1169 } 1170 catch (ParseException e) { 1171 } 1173 1174 } 1175 1176 1177 1186 public DecimalFormat getFormat() { 1187 return (DecimalFormat)((NumberFormatter)(getTextField().getFormatter())).getFormat(); 1188 } 1189 1190 1191 1198 public SpinnerNumberModel getModel() { 1199 return (SpinnerNumberModel )(getSpinner().getModel()); 1200 } 1201 } 1202 1203 1204 1208 public static class ListEditor extends DefaultEditor 1209 { 1210 1225 public ListEditor(JSpinner spinner) { 1226 super(spinner); 1227 if (!(spinner.getModel() instanceof SpinnerListModel )) { 1228 throw new IllegalArgumentException ("model not a SpinnerListModel"); 1229 } 1230 getTextField().setEditable(true); 1231 getTextField().setFormatterFactory(new 1232 DefaultFormatterFactory(new ListFormatter())); 1233 } 1234 1235 1242 public SpinnerListModel getModel() { 1243 return (SpinnerListModel )(getSpinner().getModel()); 1244 } 1245 1246 1247 1253 private class ListFormatter extends 1254 JFormattedTextField.AbstractFormatter { 1255 private DocumentFilter filter; 1256 1257 public String valueToString(Object value) throws ParseException { 1258 if (value == null) { 1259 return ""; 1260 } 1261 return value.toString(); 1262 } 1263 1264 public Object stringToValue(String string) throws ParseException { 1265 return string; 1266 } 1267 1268 protected DocumentFilter getDocumentFilter() { 1269 if (filter == null) { 1270 filter = new Filter(); 1271 } 1272 return filter; 1273 } 1274 1275 1276 private class Filter extends DocumentFilter { 1277 public void replace(FilterBypass fb, int offset, int length, 1278 String string, AttributeSet attrs) throws 1279 BadLocationException { 1280 if (string != null && (offset + length) == 1281 fb.getDocument().getLength()) { 1282 Object next = getModel().findNextMatch( 1283 fb.getDocument().getText(0, offset) + 1284 string); 1285 String value = (next != null) ? next.toString() : null; 1286 1287 if (value != null) { 1288 fb.remove(0, offset + length); 1289 fb.insertString(0, value, null); 1290 getFormattedTextField().select(offset + 1291 string.length(), 1292 value.length()); 1293 return; 1294 } 1295 } 1296 super.replace(fb, offset, length, string, attrs); 1297 } 1298 1299 public void insertString(FilterBypass fb, int offset, 1300 String string, AttributeSet attr) 1301 throws BadLocationException { 1302 replace(fb, offset, 0, string, attr); 1303 } 1304 } 1305 } 1306 } 1307 1308 1309 1312 private static class DisabledAction implements Action { 1313 public Object getValue(String key) { 1314 return null; 1315 } 1316 public void putValue(String key, Object value) { 1317 } 1318 public void setEnabled(boolean b) { 1319 } 1320 public boolean isEnabled() { 1321 return false; 1322 } 1323 public void addPropertyChangeListener(PropertyChangeListener l) { 1324 } 1325 public void removePropertyChangeListener(PropertyChangeListener l) { 1326 } 1327 public void actionPerformed(ActionEvent ae) { 1328 } 1329 } 1330 1331 1335 1341 public AccessibleContext getAccessibleContext() { 1342 if (accessibleContext == null) { 1343 accessibleContext = new AccessibleJSpinner(); 1344 } 1345 return accessibleContext; 1346 } 1347 1348 1353 protected class AccessibleJSpinner extends AccessibleJComponent 1354 implements AccessibleValue, AccessibleAction, AccessibleText, 1355 AccessibleEditableText, ChangeListener { 1356 1357 private Object oldModelValue = null; 1358 1359 1362 protected AccessibleJSpinner() { 1363 oldModelValue = model.getValue(); 1365 JSpinner.this.addChangeListener(this); 1366 } 1367 1368 1374 public void stateChanged(ChangeEvent e) { 1375 if (e == null) { 1376 throw new NullPointerException (); 1377 } 1378 Object newModelValue = model.getValue(); 1379 firePropertyChange(ACCESSIBLE_VALUE_PROPERTY, 1380 oldModelValue, 1381 newModelValue); 1382 firePropertyChange(ACCESSIBLE_TEXT_PROPERTY, 1383 null, 1384 0); 1386 oldModelValue = newModelValue; 1387 } 1388 1389 1390 1391 1409 public AccessibleRole getAccessibleRole() { 1410 return AccessibleRole.SPIN_BOX; 1411 } 1412 1413 1418 public int getAccessibleChildrenCount() { 1419 if (editor.getAccessibleContext() != null) { 1421 return 1; 1422 } 1423 return 0; 1424 } 1425 1426 1436 public Accessible getAccessibleChild(int i) { 1437 if (i != 0) { 1439 return null; 1440 } 1441 if (editor.getAccessibleContext() != null) { 1442 return (Accessible)editor; 1443 } 1444 return null; 1445 } 1446 1447 1448 1449 1456 public AccessibleAction getAccessibleAction() { 1457 return this; 1458 } 1459 1460 1467 public AccessibleText getAccessibleText() { 1468 return this; 1469 } 1470 1471 1474 private AccessibleContext getEditorAccessibleContext() { 1475 if (editor instanceof DefaultEditor) { 1476 JTextField textField = ((DefaultEditor)editor).getTextField(); 1477 if (textField != null) { 1478 return textField.getAccessibleContext(); 1479 } 1480 } else if (editor instanceof Accessible) { 1481 return ((Accessible)editor).getAccessibleContext(); 1482 } 1483 return null; 1484 } 1485 1486 1489 private AccessibleText getEditorAccessibleText() { 1490 AccessibleContext ac = getEditorAccessibleContext(); 1491 if (ac != null) { 1492 return ac.getAccessibleText(); 1493 } 1494 return null; 1495 } 1496 1497 1500 private AccessibleEditableText getEditorAccessibleEditableText() { 1501 AccessibleText at = getEditorAccessibleText(); 1502 if (at instanceof AccessibleEditableText) { 1503 return (AccessibleEditableText)at; 1504 } 1505 return null; 1506 } 1507 1508 1515 public AccessibleValue getAccessibleValue() { 1516 return this; 1517 } 1518 1519 1520 1521 1528 public Number getCurrentAccessibleValue() { 1529 Object o = model.getValue(); 1530 if (o instanceof Number ) { 1531 return (Number )o; 1532 } 1533 return null; 1534 } 1535 1536 1543 public boolean setCurrentAccessibleValue(Number n) { 1544 try { 1546 model.setValue(n); 1547 return true; 1548 } catch (IllegalArgumentException iae) { 1549 } 1551 return false; 1552 } 1553 1554 1561 public Number getMinimumAccessibleValue() { 1562 if (model instanceof SpinnerNumberModel ) { 1563 SpinnerNumberModel numberModel = (SpinnerNumberModel )model; 1564 Object o = numberModel.getMinimum(); 1565 if (o instanceof Number ) { 1566 return (Number )o; 1567 } 1568 } 1569 return null; 1570 } 1571 1572 1579 public Number getMaximumAccessibleValue() { 1580 if (model instanceof SpinnerNumberModel ) { 1581 SpinnerNumberModel numberModel = (SpinnerNumberModel )model; 1582 Object o = numberModel.getMaximum(); 1583 if (o instanceof Number ) { 1584 return (Number )o; 1585 } 1586 } 1587 return null; 1588 } 1589 1590 1591 1592 1593 1594 1605 public int getAccessibleActionCount() { 1606 return 2; 1607 } 1608 1609 1616 public String getAccessibleActionDescription(int i) { 1617 if (i == 0) { 1618 return AccessibleAction.INCREMENT; 1619 } else if (i == 1) { 1620 return AccessibleAction.DECREMENT; 1621 } 1622 return null; 1623 } 1624 1625 1634 public boolean doAccessibleAction(int i) { 1635 if (i < 0 || i > 1) { 1636 return false; 1637 } 1638 Object o = null; 1639 if (i == 0) { 1640 o = getNextValue(); } else { 1642 o = getPreviousValue(); } 1644 try { 1646 model.setValue(o); 1647 return true; 1648 } catch (IllegalArgumentException iae) { 1649 } 1651 return false; 1652 } 1653 1654 1655 1656 1657 1658 1662 private boolean sameWindowAncestor(Component src, Component dest) { 1663 if (src == null || dest == null) { 1664 return false; 1665 } 1666 return SwingUtilities.getWindowAncestor(src) == 1667 SwingUtilities.getWindowAncestor(dest); 1668 } 1669 1670 1679 public int getIndexAtPoint(Point p) { 1680 AccessibleText at = getEditorAccessibleText(); 1681 if (at != null && sameWindowAncestor(JSpinner.this, editor)) { 1682 Point editorPoint = SwingUtilities.convertPoint(JSpinner.this, 1685 p, 1686 editor); 1687 if (editorPoint != null) { 1688 return at.getIndexAtPoint(editorPoint); 1689 } 1690 } 1691 return -1; 1692 } 1693 1694 1704 public Rectangle getCharacterBounds(int i) { 1705 AccessibleText at = getEditorAccessibleText(); 1706 if (at != null ) { 1707 Rectangle editorRect = at.getCharacterBounds(i); 1708 if (editorRect != null && 1709 sameWindowAncestor(JSpinner.this, editor)) { 1710 return SwingUtilities.convertRectangle(editor, 1712 editorRect, 1713 JSpinner.this); 1714 } 1715 } 1716 return null; 1717 } 1718 1719 1724 public int getCharCount() { 1725 AccessibleText at = getEditorAccessibleText(); 1726 if (at != null) { 1727 return at.getCharCount(); 1728 } 1729 return -1; 1730 } 1731 1732 1739 public int getCaretPosition() { 1740 AccessibleText at = getEditorAccessibleText(); 1741 if (at != null) { 1742 return at.getCaretPosition(); 1743 } 1744 return -1; 1745 } 1746 1747 1754 public String getAtIndex(int part, int index) { 1755 AccessibleText at = getEditorAccessibleText(); 1756 if (at != null) { 1757 return at.getAtIndex(part, index); 1758 } 1759 return null; 1760 } 1761 1762 1769 public String getAfterIndex(int part, int index) { 1770 AccessibleText at = getEditorAccessibleText(); 1771 if (at != null) { 1772 return at.getAfterIndex(part, index); 1773 } 1774 return null; 1775 } 1776 1777 1784 public String getBeforeIndex(int part, int index) { 1785 AccessibleText at = getEditorAccessibleText(); 1786 if (at != null) { 1787 return at.getBeforeIndex(part, index); 1788 } 1789 return null; 1790 } 1791 1792 1798 public AttributeSet getCharacterAttribute(int i) { 1799 AccessibleText at = getEditorAccessibleText(); 1800 if (at != null) { 1801 return at.getCharacterAttribute(i); 1802 } 1803 return null; 1804 } 1805 1806 1813 public int getSelectionStart() { 1814 AccessibleText at = getEditorAccessibleText(); 1815 if (at != null) { 1816 return at.getSelectionStart(); 1817 } 1818 return -1; 1819 } 1820 1821 1828 public int getSelectionEnd() { 1829 AccessibleText at = getEditorAccessibleText(); 1830 if (at != null) { 1831 return at.getSelectionEnd(); 1832 } 1833 return -1; 1834 } 1835 1836 1841 public String getSelectedText() { 1842 AccessibleText at = getEditorAccessibleText(); 1843 if (at != null) { 1844 return at.getSelectedText(); 1845 } 1846 return null; 1847 } 1848 1849 1850 1851 1852 1853 1854 1859 public void setTextContents(String s) { 1860 AccessibleEditableText at = getEditorAccessibleEditableText(); 1861 if (at != null) { 1862 at.setTextContents(s); 1863 } 1864 } 1865 1866 1873 public void insertTextAtIndex(int index, String s) { 1874 AccessibleEditableText at = getEditorAccessibleEditableText(); 1875 if (at != null) { 1876 at.insertTextAtIndex(index, s); 1877 } 1878 } 1879 1880 1887 public String getTextRange(int startIndex, int endIndex) { 1888 AccessibleEditableText at = getEditorAccessibleEditableText(); 1889 if (at != null) { 1890 return at.getTextRange(startIndex, endIndex); 1891 } 1892 return null; 1893 } 1894 1895 1901 public void delete(int startIndex, int endIndex) { 1902 AccessibleEditableText at = getEditorAccessibleEditableText(); 1903 if (at != null) { 1904 at.delete(startIndex, endIndex); 1905 } 1906 } 1907 1908 1914 public void cut(int startIndex, int endIndex) { 1915 AccessibleEditableText at = getEditorAccessibleEditableText(); 1916 if (at != null) { 1917 at.cut(startIndex, endIndex); 1918 } 1919 } 1920 1921 1927 public void paste(int startIndex) { 1928 AccessibleEditableText at = getEditorAccessibleEditableText(); 1929 if (at != null) { 1930 at.paste(startIndex); 1931 } 1932 } 1933 1934 1942 public void replaceText(int startIndex, int endIndex, String s) { 1943 AccessibleEditableText at = getEditorAccessibleEditableText(); 1944 if (at != null) { 1945 at.replaceText(startIndex, endIndex, s); 1946 } 1947 } 1948 1949 1955 public void selectText(int startIndex, int endIndex) { 1956 AccessibleEditableText at = getEditorAccessibleEditableText(); 1957 if (at != null) { 1958 at.selectText(startIndex, endIndex); 1959 } 1960 } 1961 1962 1970 public void setAttributes(int startIndex, int endIndex, AttributeSet as) { 1971 AccessibleEditableText at = getEditorAccessibleEditableText(); 1972 if (at != null) { 1973 at.setAttributes(startIndex, endIndex, as); 1974 } 1975 } 1976 } 1977} 1978 | Popular Tags |