1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60: import ;
61:
62: import ;
63: import ;
64: import ;
65: import ;
66: import ;
67: import ;
68: import ;
69: import ;
70: import ;
71: import ;
72: import ;
73: import ;
74: import ;
75: import ;
76: import ;
77: import ;
78: import ;
79: import ;
80: import ;
81: import ;
82: import ;
83: import ;
84:
85: public abstract class JTextComponent extends JComponent
86: implements Scrollable, Accessible
87: {
88:
91:
92: public class AccessibleJTextComponent extends AccessibleJComponent
93: implements AccessibleText, CaretListener, DocumentListener
94: {
95: private static final long serialVersionUID = 7664188944091413696L;
96:
97:
100: public AccessibleJTextComponent()
101: {
102:
103: }
104:
105:
109: public int getCaretPosition()
110: {
111: return 0;
112: }
113:
114:
118: public String getSelectedText()
119: {
120: return null;
121: }
122:
123:
127: public int getSelectionStart()
128: {
129: return 0;
130: }
131:
132:
136: public int getSelectionEnd()
137: {
138: return 0;
139: }
140:
141:
145: public void caretUpdate(CaretEvent value0)
146: {
147:
148: }
149:
150:
154: public AccessibleStateSet getAccessibleStateSet()
155: {
156: return null;
157: }
158:
159:
163: public AccessibleRole getAccessibleRole()
164: {
165: return null;
166: }
167:
168:
172: public AccessibleText getAccessibleText()
173: {
174: return null;
175: }
176:
177:
181: public void insertUpdate(DocumentEvent value0)
182: {
183:
184: }
185:
186:
190: public void removeUpdate(DocumentEvent value0)
191: {
192:
193: }
194:
195:
199: public void changedUpdate(DocumentEvent value0)
200: {
201:
202: }
203:
204:
209: public int getIndexAtPoint(Point value0)
210: {
211: return 0;
212: }
213:
214:
218: Rectangle getRootEditorRect()
219: {
220: return null;
221: }
222:
223:
228: public Rectangle getCharacterBounds(int value0)
229: {
230: return null;
231: }
232:
233:
237: public int getCharCount()
238: {
239: return 0;
240: }
241:
242:
247: public AttributeSet getCharacterAttribute(int value0)
248: {
249: return null;
250: }
251:
252:
258: public String getAtIndex(int value0, int value1)
259: {
260: return null;
261: }
262:
263:
269: public String getAfterIndex(int value0, int value1)
270: {
271: return null;
272: }
273:
274:
280: public String getBeforeIndex(int value0, int value1)
281: {
282: return null;
283: }
284: }
285:
286: public static class KeyBinding
287: {
288: public KeyStroke key;
289: public String actionName;
290:
291:
297: public KeyBinding(KeyStroke key, String actionName)
298: {
299: this.key = key;
300: this.actionName = actionName;
301: }
302: }
303:
304:
334:
335: private class KeymapWrapper extends InputMap
336: {
337: Keymap map;
338:
339: public KeymapWrapper(Keymap k)
340: {
341: map = k;
342: }
343:
344: public int size()
345: {
346: return map.getBoundKeyStrokes().length + super.size();
347: }
348:
349: public Object get(KeyStroke ks)
350: {
351: Action mapped = null;
352: Keymap m = map;
353: while(mapped == null && m != null)
354: {
355: mapped = m.getAction(ks);
356: if (mapped == null && ks.getKeyEventType() == KeyEvent.KEY_TYPED)
357: mapped = m.getDefaultAction();
358: if (mapped == null)
359: m = m.getResolveParent();
360: }
361:
362: if (mapped == null)
363: return super.get(ks);
364: else
365: return mapped;
366: }
367:
368: public KeyStroke[] keys()
369: {
370: KeyStroke[] superKeys = super.keys();
371: KeyStroke[] mapKeys = map.getBoundKeyStrokes();
372: KeyStroke[] bothKeys = new KeyStroke[superKeys.length + mapKeys.length];
373: for (int i = 0; i < superKeys.length; ++i)
374: bothKeys[i] = superKeys[i];
375: for (int i = 0; i < mapKeys.length; ++i)
376: bothKeys[i + superKeys.length] = mapKeys[i];
377: return bothKeys;
378: }
379:
380: public KeyStroke[] allKeys()
381: {
382: KeyStroke[] superKeys = super.allKeys();
383: KeyStroke[] mapKeys = map.getBoundKeyStrokes();
384: int skl = 0;
385: int mkl = 0;
386: if (superKeys != null)
387: skl = superKeys.length;
388: if (mapKeys != null)
389: mkl = mapKeys.length;
390: KeyStroke[] bothKeys = new KeyStroke[skl + mkl];
391: for (int i = 0; i < skl; ++i)
392: bothKeys[i] = superKeys[i];
393: for (int i = 0; i < mkl; ++i)
394: bothKeys[i + skl] = mapKeys[i];
395: return bothKeys;
396: }
397: }
398:
399: private class KeymapActionMap extends ActionMap
400: {
401: Keymap map;
402:
403: public KeymapActionMap(Keymap k)
404: {
405: map = k;
406: }
407:
408: public Action get(Object cmd)
409: {
410: if (cmd instanceof Action)
411: return (Action) cmd;
412: else
413: return super.get(cmd);
414: }
415:
416: public int size()
417: {
418: return map.getBoundKeyStrokes().length + super.size();
419: }
420:
421: public Object[] keys()
422: {
423: Object[] superKeys = super.keys();
424: Object[] mapKeys = map.getBoundKeyStrokes();
425: Object[] bothKeys = new Object[superKeys.length + mapKeys.length];
426: for (int i = 0; i < superKeys.length; ++i)
427: bothKeys[i] = superKeys[i];
428: for (int i = 0; i < mapKeys.length; ++i)
429: bothKeys[i + superKeys.length] = mapKeys[i];
430: return bothKeys;
431: }
432:
433: public Object[] allKeys()
434: {
435: Object[] superKeys = super.allKeys();
436: Object[] mapKeys = map.getBoundKeyStrokes();
437: Object[] bothKeys = new Object[superKeys.length + mapKeys.length];
438: for (int i = 0; i < superKeys.length; ++i)
439: bothKeys[i] = superKeys[i];
440: for (int i = 0; i < mapKeys.length; ++i)
441: bothKeys[i + superKeys.length] = mapKeys[i];
442: return bothKeys;
443: }
444:
445: }
446:
447: static class DefaultKeymap implements Keymap
448: {
449: String name;
450: Keymap parent;
451: Hashtable map;
452: Action defaultAction;
453:
454: public DefaultKeymap(String name)
455: {
456: this.name = name;
457: this.map = new Hashtable();
458: }
459:
460: public void addActionForKeyStroke(KeyStroke key, Action a)
461: {
462: map.put(key, a);
463: }
464:
465:
474: public Action getAction(KeyStroke key)
475: {
476: if (map.containsKey(key))
477: return (Action) map.get(key);
478: else if (parent != null)
479: return parent.getAction(key);
480: else
481: return null;
482: }
483:
484: public Action[] getBoundActions()
485: {
486: Action [] ret = new Action[map.size()];
487: Enumeration e = map.elements();
488: int i = 0;
489: while (e.hasMoreElements())
490: {
491: ret[i++] = (Action) e.nextElement();
492: }
493: return ret;
494: }
495:
496: public KeyStroke[] getBoundKeyStrokes()
497: {
498: KeyStroke [] ret = new KeyStroke[map.size()];
499: Enumeration e = map.keys();
500: int i = 0;
501: while (e.hasMoreElements())
502: {
503: ret[i++] = (KeyStroke) e.nextElement();
504: }
505: return ret;
506: }
507:
508: public Action getDefaultAction()
509: {
510: return defaultAction;
511: }
512:
513: public KeyStroke[] getKeyStrokesForAction(Action a)
514: {
515: int i = 0;
516: Enumeration e = map.keys();
517: while (e.hasMoreElements())
518: {
519: if (map.get(e.nextElement()).equals(a))
520: ++i;
521: }
522: KeyStroke [] ret = new KeyStroke[i];
523: i = 0;
524: e = map.keys();
525: while (e.hasMoreElements())
526: {
527: KeyStroke k = (KeyStroke) e.nextElement();
528: if (map.get(k).equals(a))
529: ret[i++] = k;
530: }
531: return ret;
532: }
533:
534: public String getName()
535: {
536: return name;
537: }
538:
539: public Keymap getResolveParent()
540: {
541: return parent;
542: }
543:
544: public boolean isLocallyDefined(KeyStroke key)
545: {
546: return map.containsKey(key);
547: }
548:
549: public void removeBindings()
550: {
551: map.clear();
552: }
553:
554: public void removeKeyStrokeBinding(KeyStroke key)
555: {
556: map.remove(key);
557: }
558:
559: public void setDefaultAction(Action a)
560: {
561: defaultAction = a;
562: }
563:
564: public void setResolveParent(Keymap p)
565: {
566: parent = p;
567: }
568: }
569:
570: class DefaultTransferHandler extends TransferHandler
571: {
572: public boolean canImport(JComponent component, DataFlavor[] flavors)
573: {
574: JTextComponent textComponent = (JTextComponent) component;
575:
576: if (! (textComponent.isEnabled()
577: && textComponent.isEditable()
578: && flavors != null))
579: return false;
580:
581: for (int i = 0; i < flavors.length; ++i)
582: if (flavors[i].equals(DataFlavor.stringFlavor))
583: return true;
584:
585: return false;
586: }
587:
588: public void exportToClipboard(JComponent component, Clipboard clipboard,
589: int action)
590: {
591: JTextComponent textComponent = (JTextComponent) component;
592: int start = textComponent.getSelectionStart();
593: int end = textComponent.getSelectionEnd();
594:
595: if (start == end)
596: return;
597:
598: try
599: {
600:
601: String data = textComponent.getDocument().getText(start, end);
602: StringSelection selection = new StringSelection(data);
603: clipboard.setContents(selection, null);
604:
605:
606: if (action == MOVE)
607: doc.remove(start, end - start);
608: }
609: catch (BadLocationException e)
610: {
611:
612: }
613: }
614:
615: public int getSourceActions()
616: {
617: return NONE;
618: }
619:
620: public boolean importData(JComponent component, Transferable transferable)
621: {
622: DataFlavor flavor = null;
623: DataFlavor[] flavors = transferable.getTransferDataFlavors();
624:
625: if (flavors == null)
626: return false;
627:
628: for (int i = 0; i < flavors.length; ++i)
629: if (flavors[i].equals(DataFlavor.stringFlavor))
630: flavor = flavors[i];
631:
632: if (flavor == null)
633: return false;
634:
635: try
636: {
637: JTextComponent textComponent = (JTextComponent) component;
638: String data = (String) transferable.getTransferData(flavor);
639: textComponent.replaceSelection(data);
640: return true;
641: }
642: catch (IOException e)
643: {
644:
645: }
646: catch (UnsupportedFlavorException e)
647: {
648:
649: }
650:
651: return false;
652: }
653: }
654:
655: private static final long serialVersionUID = -8796518220218978795L;
656:
657: public static final String DEFAULT_KEYMAP = "default";
658: public static final String FOCUS_ACCELERATOR_KEY = "focusAcceleratorKey";
659:
660: private static DefaultTransferHandler defaultTransferHandler;
661: private static Hashtable keymaps = new Hashtable();
662: private Keymap keymap;
663: private char focusAccelerator = '\0';
664: private NavigationFilter navigationFilter;
665:
666:
678: public static Keymap getKeymap(String n)
679: {
680: return (Keymap) keymaps.get(n);
681: }
682:
683:
694: public static Keymap removeKeymap(String n)
695: {
696: Keymap km = (Keymap) keymaps.get(n);
697: keymaps.remove(n);
698: return km;
699: }
700:
701:
717: public static Keymap addKeymap(String n, Keymap parent)
718: {
719: Keymap k = new DefaultKeymap(n);
720: k.setResolveParent(parent);
721: if (n != null)
722: keymaps.put(n, k);
723: return k;
724: }
725:
726:
734: public Keymap getKeymap()
735: {
736: return keymap;
737: }
738:
739:
748: public void setKeymap(Keymap k)
749: {
750:
751:
752:
753:
754:
755:
756:
757:
758:
759:
760:
761: KeymapWrapper kw = (k == null ? null : new KeymapWrapper(k));
762: InputMap childInputMap = getInputMap(JComponent.WHEN_FOCUSED);
763: if (childInputMap == null)
764: setInputMap(JComponent.WHEN_FOCUSED, kw);
765: else
766: {
767: while (childInputMap.getParent() != null
768: && !(childInputMap.getParent() instanceof KeymapWrapper)
769: && !(childInputMap.getParent() instanceof InputMapUIResource))
770: childInputMap = childInputMap.getParent();
771:
772:
773: if (childInputMap.getParent() == null)
774: childInputMap.setParent(kw);
775:
776:
777:
778: else if (childInputMap.getParent() instanceof KeymapWrapper)
779: {
780: if (kw == null)
781: childInputMap.setParent(childInputMap.getParent().getParent());
782: else
783: {
784: kw.setParent(childInputMap.getParent().getParent());
785: childInputMap.setParent(kw);
786: }
787: }
788:
789:
790:
791: else if (childInputMap.getParent() instanceof InputMapUIResource)
792: {
793: if (kw != null)
794: {
795: kw.setParent(childInputMap.getParent());
796: childInputMap.setParent(kw);
797: }
798: }
799: }
800:
801:
802:
803: KeymapActionMap kam = (k == null ? null : new KeymapActionMap(k));
804: ActionMap childActionMap = getActionMap();
805: if (childActionMap == null)
806: setActionMap(kam);
807: else
808: {
809: while (childActionMap.getParent() != null
810: && !(childActionMap.getParent() instanceof KeymapActionMap)
811: && !(childActionMap.getParent() instanceof ActionMapUIResource))
812: childActionMap = childActionMap.getParent();
813:
814:
815: if (childActionMap.getParent() == null)
816: childActionMap.setParent(kam);
817:
818:
819:
820: else if (childActionMap.getParent() instanceof KeymapActionMap)
821: {
822: if (kam == null)
823: childActionMap.setParent(childActionMap.getParent().getParent());
824: else
825: {
826: kam.setParent(childActionMap.getParent().getParent());
827: childActionMap.setParent(kam);
828: }
829: }
830:
831:
832:
833: else if (childActionMap.getParent() instanceof ActionMapUIResource)
834: {
835: if (kam != null)
836: {
837: kam.setParent(childActionMap.getParent());
838: childActionMap.setParent(kam);
839: }
840: }
841: }
842:
843:
844:
845: Keymap old = keymap;
846: keymap = k;
847: firePropertyChange("keymap", old, k);
848: }
849:
850:
866: public static void loadKeymap(Keymap map,
867: JTextComponent.KeyBinding[] bindings,
868: Action[] actions)
869: {
870: Hashtable acts = new Hashtable(actions.length);
871: for (int i = 0; i < actions.length; ++i)
872: acts.put(actions[i].getValue(Action.NAME), actions[i]);
873: for (int i = 0; i < bindings.length; ++i)
874: if (acts.containsKey(bindings[i].actionName))
875: map.addActionForKeyStroke(bindings[i].key, (Action) acts.get(bindings[i].actionName));
876: }
877:
878:
891: public Action[] getActions()
892: {
893: return getUI().getEditorKit(this).getActions();
894: }
895:
896:
897: Document doc;
898: Caret caret;
899: boolean editable;
900:
901: private Highlighter highlighter;
902: private Color caretColor;
903: private Color disabledTextColor;
904: private Color selectedTextColor;
905: private Color selectionColor;
906: private Insets margin;
907: private boolean dragEnabled;
908:
909:
912: public JTextComponent()
913: {
914: Keymap defkeymap = getKeymap(DEFAULT_KEYMAP);
915: if (defkeymap == null)
916: {
917: defkeymap = addKeymap(DEFAULT_KEYMAP, null);
918: defkeymap.setDefaultAction(new DefaultEditorKit.DefaultKeyTypedAction());
919: }
920:
921: setFocusable(true);
922: setEditable(true);
923: enableEvents(AWTEvent.KEY_EVENT_MASK);
924: updateUI();
925: }
926:
927: public void setDocument(Document newDoc)
928: {
929: Document oldDoc = doc;
930: doc = newDoc;
931: firePropertyChange("document", oldDoc, newDoc);
932: revalidate();
933: repaint();
934: }
935:
936: public Document getDocument()
937: {
938: return doc;
939: }
940:
941:
946: public AccessibleContext getAccessibleContext()
947: {
948: return null;
949: }
950:
951: public void setMargin(Insets m)
952: {
953: margin = m;
954: }
955:
956: public Insets getMargin()
957: {
958: return margin;
959: }
960:
961: public void setText(String text)
962: {
963: try
964: {
965: if (doc instanceof AbstractDocument)
966: ((AbstractDocument) doc).replace(0, doc.getLength(), text, null);
967: else
968: {
969: doc.remove(0, doc.getLength());
970: doc.insertString(0, text, null);
971: }
972: }
973: catch (BadLocationException e)
974: {
975:
976: }
977: }
978:
979:
986: public String getText()
987: {
988: if (doc == null)
989: return null;
990:
991: try
992: {
993: return doc.getText(0, doc.getLength());
994: }
995: catch (BadLocationException e)
996: {
997:
998: return "";
999: }
1000: }
1001:
1002:
1012: public String getText(int offset, int length)
1013: throws BadLocationException
1014: {
1015: return getDocument().getText(offset, length);
1016: }
1017:
1018:
1025: public String getSelectedText()
1026: {
1027: try
1028: {
1029: return doc.getText(getSelectionStart(), getSelectionEnd());
1030: }
1031: catch (BadLocationException e)
1032: {
1033:
1034: return null;
1035: }
1036: }
1037:
1038:
1044: public String getUIClassID()
1045: {
1046: return "TextComponentUI";
1047: }
1048:
1049:
1052: protected String paramString()
1053: {
1054:
1055: return super.paramString();
1056: }
1057:
1058:
1063: public TextUI getUI()
1064: {
1065: return (TextUI) ui;
1066: }
1067:
1068:
1073: public void setUI(TextUI newUI)
1074: {
1075: super.setUI(newUI);
1076: }
1077:
1078:
1082: public void updateUI()
1083: {
1084: setUI((TextUI) UIManager.getUI(this));
1085: }
1086:
1087: public Dimension getPreferredScrollableViewportSize()
1088: {
1089: return getPreferredSize();
1090: }
1091:
1092: public int getScrollableUnitIncrement(Rectangle visible, int orientation,
1093: int direction)
1094: {
1095:
1096: if (orientation == SwingConstants.HORIZONTAL)
1097: return visible.width / 10;
1098: else if (orientation == SwingConstants.VERTICAL)
1099: return visible.height / 10;
1100: else
1101: throw new IllegalArgumentException("orientation must be either "
1102: + "javax.swing.SwingConstants.VERTICAL "
1103: + "or "
1104: + "javax.swing.SwingConstants.HORIZONTAL"
1105: );
1106: }
1107:
1108: public int getScrollableBlockIncrement(Rectangle visible, int orientation,
1109: int direction)
1110: {
1111:
1112: if (orientation == SwingConstants.HORIZONTAL)
1113: return visible.width;
1114: else if (orientation == SwingConstants.VERTICAL)
1115: return visible.height;
1116: else
1117: throw new IllegalArgumentException("orientation must be either "
1118: + "javax.swing.SwingConstants.VERTICAL "
1119: + "or "
1120: + "javax.swing.SwingConstants.HORIZONTAL"
1121: );
1122: }
1123:
1124:
1129: public boolean isEditable()
1130: {
1131: return editable;
1132: }
1133:
1134:
1139: public void setEditable(boolean newValue)
1140: {
1141: if (editable == newValue)
1142: return;
1143:
1144: boolean oldValue = editable;
1145: editable = newValue;
1146: firePropertyChange("editable", oldValue, newValue);
1147: }
1148:
1149:
1154: public Caret getCaret()
1155: {
1156: return caret;
1157: }
1158:
1159:
1164: public void setCaret(Caret newCaret)
1165: {
1166: if (caret != null)
1167: caret.deinstall(this);
1168:
1169: Caret oldCaret = caret;
1170: caret = newCaret;
1171:
1172: if (caret != null)
1173: caret.install(this);
1174:
1175: firePropertyChange("caret", oldCaret, newCaret);
1176: }
1177:
1178: public Color getCaretColor()
1179: {
1180: return caretColor;
1181: }
1182:
1183: public void setCaretColor(Color newColor)
1184: {
1185: Color oldCaretColor = caretColor;
1186: caretColor = newColor;
1187: firePropertyChange("caretColor", oldCaretColor, newColor);
1188: }
1189:
1190: public Color getDisabledTextColor()
1191: {
1192: return disabledTextColor;
1193: }
1194:
1195: public void setDisabledTextColor(Color newColor)
1196: {
1197: Color oldColor = disabledTextColor;
1198: disabledTextColor = newColor;
1199: firePropertyChange("disabledTextColor", oldColor, newColor);
1200: }
1201:
1202: public Color getSelectedTextColor()
1203: {
1204: return selectedTextColor;
1205: }
1206:
1207: public void setSelectedTextColor(Color newColor)
1208: {
1209: Color oldColor = selectedTextColor;
1210: selectedTextColor = newColor;
1211: firePropertyChange("selectedTextColor", oldColor, newColor);
1212: }
1213:
1214: public Color getSelectionColor()
1215: {
1216: return selectionColor;
1217: }
1218:
1219: public void setSelectionColor(Color newColor)
1220: {
1221: Color oldColor = selectionColor;
1222: selectionColor = newColor;
1223: firePropertyChange("selectionColor", oldColor, newColor);
1224: }
1225:
1226:
1231: public int getCaretPosition()
1232: {
1233: return caret.getDot();
1234: }
1235:
1236:
1241: public void setCaretPosition(int position)
1242: {
1243: if (doc == null)
1244: return;
1245:
1246: if (position < 0 || position > doc.getLength())
1247: throw new IllegalArgumentException();
1248:
1249: caret.setDot(position);
1250: }
1251:
1252:
1256: public void moveCaretPosition(int position)
1257: {
1258: if (doc == null)
1259: return;
1260:
1261: if (position < 0 || position > doc.getLength())
1262: throw new IllegalArgumentException();
1263:
1264: caret.moveDot(position);
1265: }
1266:
1267: public Highlighter getHighlighter()
1268: {
1269: return highlighter;
1270: }
1271:
1272: public void setHighlighter(Highlighter newHighlighter)
1273: {
1274: if (highlighter != null)
1275: highlighter.deinstall(this);
1276:
1277: Highlighter oldHighlighter = highlighter;
1278: highlighter = newHighlighter;
1279:
1280: if (highlighter != null)
1281: highlighter.install(this);
1282:
1283: firePropertyChange("highlighter", oldHighlighter, newHighlighter);
1284: }
1285:
1286:
1291: public int getSelectionStart()
1292: {
1293: return Math.min(caret.getDot(), caret.getMark());
1294: }
1295:
1296:
1301: public void setSelectionStart(int start)
1302: {
1303: select(start, getSelectionEnd());
1304: }
1305:
1306:
1311: public int getSelectionEnd()
1312: {
1313: return Math.max(caret.getDot(), caret.getMark());
1314: }
1315:
1316:
1321: public void setSelectionEnd(int end)
1322: {
1323: select(getSelectionStart(), end);
1324: }
1325:
1326:
1332: public void select(int start, int end)
1333: {
1334: int length = doc.getLength();
1335:
1336: start = Math.max(start, 0);
1337: start = Math.min(start, length);
1338:
1339: end = Math.max(end, start);
1340: end = Math.min(end, length);
1341:
1342: setCaretPosition(start);
1343: moveCaretPosition(end);
1344: }
1345:
1346:
1349: public void selectAll()
1350: {
1351: select(0, doc.getLength());
1352: }
1353:
1354: public synchronized void replaceSelection(String content)
1355: {
1356: int dot = caret.getDot();
1357: int mark = caret.getMark();
1358:
1359:
1360: if (content == null)
1361: {
1362: caret.setDot(dot);
1363: return;
1364: }
1365:
1366: try
1367: {
1368: int start = getSelectionStart();
1369: int end = getSelectionEnd();
1370:
1371:
1372: if (dot != mark)
1373: doc.remove(start, end - start);
1374:
1375:
1376: doc.insertString(start, content, null);
1377:
1378:
1379: setCaretPosition(start + content.length());
1380: }
1381: catch (BadLocationException e)
1382: {
1383:
1384: }
1385: }
1386:
1387: public boolean getScrollableTracksViewportHeight()
1388: {
1389: if (getParent() instanceof JViewport)
1390: return ((JViewport) getParent()).getHeight() > getPreferredSize().height;
1391:
1392: return false;
1393: }
1394:
1395: public boolean getScrollableTracksViewportWidth()
1396: {
1397: if (getParent() instanceof JViewport)
1398: return ((JViewport) getParent()).getWidth() > getPreferredSize().width;
1399:
1400: return false;
1401: }
1402:
1403:
1408: public void addCaretListener(CaretListener listener)
1409: {
1410: listenerList.add(CaretListener.class, listener);
1411: }
1412:
1413:
1418: public void removeCaretListener(CaretListener listener)
1419: {
1420: listenerList.remove(CaretListener.class, listener);
1421: }
1422:
1423:
1428: public CaretListener[] getCaretListeners()
1429: {
1430: return (CaretListener[]) getListeners(CaretListener.class);
1431: }
1432:
1433:
1439: protected void fireCaretUpdate(CaretEvent event)
1440: {
1441: CaretListener[] listeners = getCaretListeners();
1442:
1443: for (int index = 0; index < listeners.length; ++index)
1444: listeners[index].caretUpdate(event);
1445: }
1446:
1447:
1452: public void addInputMethodListener(InputMethodListener listener)
1453: {
1454: listenerList.add(InputMethodListener.class, listener);
1455: }
1456:
1457:
1462: public void removeInputMethodListener(InputMethodListener listener)
1463: {
1464: listenerList.remove(InputMethodListener.class, listener);
1465: }
1466:
1467:
1472: public InputMethodListener[] getInputMethodListeners()
1473: {
1474: return (InputMethodListener[]) getListeners(InputMethodListener.class);
1475: }
1476:
1477: public Rectangle modelToView(int position) throws BadLocationException
1478: {
1479: return getUI().modelToView(this, position);
1480: }
1481:
1482: public boolean getDragEnabled()
1483: {
1484: return dragEnabled;
1485: }
1486:
1487: public void setDragEnabled(boolean enabled)
1488: {
1489: dragEnabled = enabled;
1490: }
1491:
1492: public int viewToModel(Point pt)
1493: {
1494: return getUI().viewToModel(this, pt);
1495: }
1496:
1497: public void copy()
1498: {
1499: doTransferAction("copy", TransferHandler.getCopyAction());
1500: }
1501:
1502: public void cut()
1503: {
1504: doTransferAction("cut", TransferHandler.getCutAction());
1505: }
1506:
1507: public void paste()
1508: {
1509: doTransferAction("paste", TransferHandler.getPasteAction());
1510: }
1511:
1512: private void doTransferAction(String name, Action action)
1513: {
1514:
1515: if (getTransferHandler() == null)
1516: {
1517: if (defaultTransferHandler == null)
1518: defaultTransferHandler = new DefaultTransferHandler();
1519:
1520: setTransferHandler(defaultTransferHandler);
1521: }
1522:
1523:
1524: ActionEvent event = new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
1525: action.getValue(Action.NAME).toString());
1526: action.actionPerformed(event);
1527: }
1528:
1529: public void setFocusAccelerator(char newKey)
1530: {
1531: if (focusAccelerator == newKey)
1532: return;
1533:
1534: char oldKey = focusAccelerator;
1535: focusAccelerator = newKey;
1536: firePropertyChange(FOCUS_ACCELERATOR_KEY, oldKey, newKey);
1537: }
1538:
1539: public char getFocusAccelerator()
1540: {
1541: return focusAccelerator;
1542: }
1543:
1544:
1547: public NavigationFilter getNavigationFilter()
1548: {
1549: return navigationFilter;
1550: }
1551:
1552:
1555: public void setNavigationFilter(NavigationFilter filter)
1556: {
1557: navigationFilter = filter;
1558: }
1559:
1560:
1577: public void read(Reader input, Object streamDescription)
1578: throws IOException
1579: {
1580: if (streamDescription != null)
1581: {
1582: Document d = getDocument();
1583: if (d != null)
1584: d.putProperty(Document.StreamDescriptionProperty, streamDescription);
1585: }
1586:
1587: StringBuffer b = new StringBuffer();
1588: int c;
1589:
1590:
1591: while ((c = input.read()) >= 0)
1592: b.append((char) c);
1593:
1594: setText(b.toString());
1595: }
1596:
1597:
1605: public void write(Writer output)
1606: throws IOException
1607: {
1608: output.write(getText());
1609: }
1610:
1611:
1621: public String getToolTipText(MouseEvent ev)
1622: {
1623: return getUI().getToolTipText(this, ev.getPoint());
1624: }
1625: }