1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44:
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53:
54: import ;
55: import ;
56:
57:
66: public class DefaultEditorKit extends EditorKit
67: {
68: static class SelectionPreviousWordAction
69: extends TextAction
70: {
71: SelectionPreviousWordAction()
72: {
73: super(selectionPreviousWordAction);
74: }
75:
76: public void actionPerformed(ActionEvent event)
77: {
78: try
79: {
80: JTextComponent t = getTextComponent(event);
81:
82: if (t != null)
83: {
84: int offs = Utilities.getPreviousWord(t, t.getCaretPosition());
85:
86: Caret c = t.getCaret();
87: c.moveDot(offs);
88: c.setMagicCaretPosition(t.modelToView(offs).getLocation());
89: }
90: }
91: catch(BadLocationException ble)
92: {
93:
94: }
95: }
96: }
97:
98: static class SelectionNextWordAction
99: extends TextAction
100: {
101: SelectionNextWordAction()
102: {
103: super(selectionNextWordAction);
104: }
105:
106: public void actionPerformed(ActionEvent event)
107: {
108: try
109: {
110: JTextComponent t = getTextComponent(event);
111:
112: if (t != null)
113: {
114: int offs = Utilities.getNextWord(t, t.getCaretPosition());
115:
116: Caret c = t.getCaret();
117: c.moveDot(offs);
118: c.setMagicCaretPosition(t.modelToView(offs).getLocation());
119: }
120: }
121: catch(BadLocationException ble)
122: {
123:
124: }
125: }
126: }
127:
128: static class SelectionBeginWordAction extends TextAction
129: {
130: SelectionBeginWordAction()
131: {
132: super(selectionBeginWordAction);
133: }
134:
135: public void actionPerformed(ActionEvent event)
136: {
137: try
138: {
139: JTextComponent t = getTextComponent(event);
140:
141: if (t != null)
142: {
143: int offs = Utilities.getWordStart(t, t.getCaretPosition());
144:
145: Caret c = t.getCaret();
146: c.moveDot(offs);
147: c.setMagicCaretPosition(t.modelToView(offs).getLocation());
148: }
149: }
150: catch(BadLocationException ble)
151: {
152:
153: }
154: }
155: }
156:
157: static class SelectionEndWordAction extends TextAction
158: {
159: SelectionEndWordAction()
160: {
161: super(selectionEndWordAction);
162: }
163:
164: public void actionPerformed(ActionEvent event)
165: {
166: try
167: {
168: JTextComponent t = getTextComponent(event);
169:
170: if (t != null)
171: {
172: int offs = Utilities.getWordEnd(t, t.getCaretPosition());
173:
174: Caret c = t.getCaret();
175: c.moveDot(offs);
176: c.setMagicCaretPosition(t.modelToView(offs).getLocation());
177: }
178: }
179: catch(BadLocationException ble)
180: {
181:
182: }
183: }
184: }
185:
186: static class BeginWordAction extends TextAction
187: {
188: BeginWordAction()
189: {
190: super(beginWordAction);
191: }
192:
193: public void actionPerformed(ActionEvent event)
194: {
195: try
196: {
197: JTextComponent t = getTextComponent(event);
198:
199: if (t != null)
200: {
201: int offs = Utilities.getWordStart(t, t.getCaretPosition());
202:
203: Caret c = t.getCaret();
204: c.setDot(offs);
205: c.setMagicCaretPosition(t.modelToView(offs).getLocation());
206: }
207: }
208: catch(BadLocationException ble)
209: {
210:
211: }
212: }
213: }
214:
215: static class EndWordAction extends TextAction
216: {
217: EndWordAction()
218: {
219: super(endWordAction);
220: }
221:
222: public void actionPerformed(ActionEvent event)
223: {
224: try
225: {
226: JTextComponent t = getTextComponent(event);
227:
228: if (t != null)
229: {
230: int offs = Utilities.getWordEnd(t, t.getCaretPosition());
231:
232: Caret c = t.getCaret();
233: c.setDot(offs);
234: c.setMagicCaretPosition(t.modelToView(offs).getLocation());
235: }
236: }
237: catch(BadLocationException ble)
238: {
239:
240: }
241: }
242: }
243:
244: static class PreviousWordAction
245: extends TextAction
246: {
247: PreviousWordAction()
248: {
249: super(previousWordAction);
250: }
251:
252: public void actionPerformed(ActionEvent event)
253: {
254: try
255: {
256: JTextComponent t = getTextComponent(event);
257:
258: if (t != null)
259: {
260: int offs = Utilities.getPreviousWord(t, t.getCaretPosition());
261:
262: Caret c = t.getCaret();
263: c.setDot(offs);
264: c.setMagicCaretPosition(t.modelToView(offs).getLocation());
265: }
266: }
267: catch(BadLocationException ble)
268: {
269:
270: }
271: }
272: }
273:
274: static class NextWordAction
275: extends TextAction
276: {
277: NextWordAction()
278: {
279: super(nextWordAction);
280: }
281:
282: public void actionPerformed(ActionEvent event)
283: {
284: try
285: {
286: JTextComponent t = getTextComponent(event);
287:
288: if (t != null)
289: {
290: int offs = Utilities.getNextWord(t, t.getCaretPosition());
291:
292: Caret c = t.getCaret();
293: c.setDot(offs);
294: c.setMagicCaretPosition(t.modelToView(offs).getLocation());
295: }
296: }
297: catch(BadLocationException ble)
298: {
299:
300: }
301: }
302: }
303:
304: static class SelectAllAction
305: extends TextAction
306: {
307: SelectAllAction()
308: {
309: super(selectAllAction);
310: }
311:
312: public void actionPerformed(ActionEvent event)
313: {
314: JTextComponent t = getTextComponent(event);
315: int offs = t.getDocument().getLength();
316: Caret c = t.getCaret();
317: c.setDot(0);
318: c.moveDot(offs);
319:
320: try
321: {
322: c.setMagicCaretPosition(t.modelToView(offs).getLocation());
323: }
324: catch(BadLocationException ble)
325: {
326:
327: }
328: }
329: }
330:
331: static class SelectionBeginAction
332: extends TextAction
333: {
334: SelectionBeginAction()
335: {
336: super(selectionBeginAction);
337: }
338:
339: public void actionPerformed(ActionEvent event)
340: {
341: JTextComponent t = getTextComponent(event);
342: Caret c = t.getCaret();
343: c.moveDot(0);
344: try
345: {
346: c.setMagicCaretPosition(t.modelToView(0).getLocation());
347: }
348: catch(BadLocationException ble)
349: {
350:
351: }
352: }
353: }
354:
355: static class SelectionEndAction
356: extends TextAction
357: {
358: SelectionEndAction()
359: {
360: super(selectionEndAction);
361: }
362:
363: public void actionPerformed(ActionEvent event)
364: {
365: JTextComponent t = getTextComponent(event);
366: int offs = t.getDocument().getLength();
367: Caret c = t.getCaret();
368: c.moveDot(offs);
369: try
370: {
371: c.setMagicCaretPosition(t.modelToView(offs).getLocation());
372: }
373: catch(BadLocationException ble)
374: {
375:
376: }
377: }
378: }
379:
380: static class SelectionBeginLineAction
381: extends TextAction
382: {
383:
384: SelectionBeginLineAction()
385: {
386: super(selectionBeginLineAction);
387: }
388:
389: public void actionPerformed(ActionEvent event)
390: {
391: JTextComponent t = getTextComponent(event);
392: Caret c = t.getCaret();
393: try
394: {
395: int offs = Utilities.getRowStart(t, c.getDot());
396: c.setMagicCaretPosition(t.modelToView(offs).getLocation());
397: }
398: catch(BadLocationException ble)
399: {
400:
401: }
402:
403: }
404: }
405:
406: static class SelectionEndLineAction
407: extends TextAction
408: {
409: SelectionEndLineAction()
410: {
411: super(selectionEndLineAction);
412: }
413:
414: public void actionPerformed(ActionEvent event)
415: {
416: JTextComponent t = getTextComponent(event);
417: Caret c = t.getCaret();
418: try
419: {
420: int offs = Utilities.getRowEnd(t, c.getDot());
421: c.setMagicCaretPosition(t.modelToView(offs).getLocation());
422: }
423: catch(BadLocationException ble)
424: {
425:
426: }
427:
428: }
429: }
430:
431: static class SelectLineAction extends TextAction
432: {
433: SelectLineAction()
434: {
435: super(selectLineAction);
436: }
437:
438: public void actionPerformed(ActionEvent event)
439: {
440: JTextComponent t = getTextComponent(event);
441: Caret c = t.getCaret();
442: try
443: {
444: int offs1 = Utilities.getRowStart(t, c.getDot());
445: int offs2 = Utilities.getRowEnd(t, c.getDot());
446:
447: c.setDot(offs2);
448: c.moveDot(offs1);
449:
450: c.setMagicCaretPosition(t.modelToView(offs2).getLocation());
451: }
452: catch(BadLocationException ble)
453: {
454:
455: }
456: }
457: }
458:
459: static class SelectWordAction extends TextAction
460: {
461: SelectWordAction()
462: {
463: super(selectWordAction);
464: }
465:
466: public void actionPerformed(ActionEvent event)
467: {
468: JTextComponent t = getTextComponent(event);
469: Caret c = t.getCaret();
470: int dot = c.getDot();
471:
472: try
473: {
474: int wordStart = Utilities.getWordStart(t, dot);
475:
476: if (dot == wordStart)
477: {
478:
479: c.setDot(wordStart);
480: c.moveDot(Utilities.getWordEnd(t, wordStart));
481: }
482: else
483: {
484:
485:
486: int nextWord = Utilities.getNextWord(t, dot);
487: int previousWord = Utilities.getPreviousWord(t, dot);
488: int previousWordEnd = Utilities.getWordEnd(t, previousWord);
489:
490:
491:
492: if (dot >= previousWordEnd && dot <= nextWord)
493: {
494: c.setDot(previousWordEnd);
495: c.moveDot(nextWord);
496: }
497: else
498: {
499:
500: c.setDot(previousWord);
501: c.moveDot(previousWordEnd);
502: }
503: }
504:
505:
506:
507: if (c.getDot() != dot)
508: c.setMagicCaretPosition(t.modelToView(c.getDot()).getLocation());
509:
510: }
511: catch(BadLocationException ble)
512: {
513:
514: }
515: }
516: }
517:
518: static class SelectionDownAction
519: extends TextAction.VerticalMovementAction
520: {
521: SelectionDownAction()
522: {
523: super(selectionDownAction, SwingConstants.SOUTH);
524: }
525:
526: protected void actionPerformedImpl(Caret c, int offs)
527: {
528: c.moveDot(offs);
529: }
530:
531: }
532:
533: static class SelectionUpAction
534: extends TextAction.VerticalMovementAction
535: {
536: SelectionUpAction()
537: {
538: super(selectionUpAction, SwingConstants.NORTH);
539: }
540:
541: protected void actionPerformedImpl(Caret c, int offs)
542: {
543: c.moveDot(offs);
544: }
545:
546: }
547:
548: static class SelectionForwardAction
549: extends TextAction.HorizontalMovementAction
550: {
551: SelectionForwardAction()
552: {
553: super(selectionForwardAction, SwingConstants.EAST);
554: }
555:
556: protected void actionPerformedImpl(Caret c, int offs)
557: {
558: c.moveDot(offs);
559: }
560: }
561:
562: static class SelectionBackwardAction
563: extends TextAction.HorizontalMovementAction
564: {
565: SelectionBackwardAction()
566: {
567: super(selectionBackwardAction, SwingConstants.WEST);
568: }
569:
570: protected void actionPerformedImpl(Caret c, int offs)
571: {
572: c.moveDot(offs);
573: }
574: }
575:
576: static class DownAction
577: extends TextAction.VerticalMovementAction
578: {
579: DownAction()
580: {
581: super(downAction, SwingConstants.SOUTH);
582: }
583:
584: protected void actionPerformedImpl(Caret c, int offs)
585: {
586: c.setDot(offs);
587: }
588: }
589:
590: static class UpAction
591: extends TextAction.VerticalMovementAction
592: {
593: UpAction()
594: {
595: super(upAction, SwingConstants.NORTH);
596: }
597:
598: protected void actionPerformedImpl(Caret c, int offs)
599: {
600: c.setDot(offs);
601: }
602:
603: }
604:
605: static class ForwardAction
606: extends TextAction.HorizontalMovementAction
607: {
608: ForwardAction()
609: {
610: super(forwardAction, SwingConstants.EAST);
611: }
612:
613: protected void actionPerformedImpl(Caret c, int offs)
614: {
615: c.setDot(offs);
616: }
617:
618: }
619:
620: static class BackwardAction
621: extends TextAction.HorizontalMovementAction
622: {
623: BackwardAction()
624: {
625: super(backwardAction, SwingConstants.WEST);
626: }
627:
628: protected void actionPerformedImpl(Caret c, int offs)
629: {
630: c.setDot(offs);
631: }
632:
633: }
634:
635: static class DeletePrevCharAction
636: extends TextAction
637: {
638: DeletePrevCharAction()
639: {
640: super(deletePrevCharAction);
641: }
642:
643: public void actionPerformed(ActionEvent event)
644: {
645: JTextComponent t = getTextComponent(event);
646: if (t != null)
647: {
648: try
649: {
650: int pos = t.getSelectionStart();
651: int len = t.getSelectionEnd() - pos;
652:
653: if (len > 0)
654: t.getDocument().remove(pos, len);
655: else if (pos > 0)
656: {
657: pos--;
658: t.getDocument().remove(pos, 1);
659: Caret c = t.getCaret();
660: c.setDot(pos);
661: c.setMagicCaretPosition(t.modelToView(pos).getLocation());
662: }
663: }
664: catch (BadLocationException e)
665: {
666:
667: }
668: }
669: }
670: }
671:
672: static class DeleteNextCharAction
673: extends TextAction
674: {
675: DeleteNextCharAction()
676: {
677: super(deleteNextCharAction);
678: }
679:
680: public void actionPerformed(ActionEvent event)
681: {
682: JTextComponent t = getTextComponent(event);
683: if (t != null)
684: {
685: try
686: {
687: int pos = t.getSelectionStart();
688: int len = t.getSelectionEnd() - pos;
689:
690: if (len > 0)
691: t.getDocument().remove(pos, len);
692: else if (pos < t.getDocument().getLength())
693: t.getDocument().remove(pos, 1);
694:
695: Caret c = t.getCaret();
696: c.setDot(pos);
697: c.setMagicCaretPosition(t.modelToView(pos).getLocation());
698: }
699: catch (BadLocationException e)
700: {
701:
702: }
703: }
704: }
705: }
706:
707: static class EndLineAction
708: extends TextAction
709: {
710: EndLineAction()
711: {
712: super(endLineAction);
713: }
714:
715: public void actionPerformed(ActionEvent event)
716: {
717: JTextComponent t = getTextComponent(event);
718: try
719: {
720: int offs = Utilities.getRowEnd(t, t.getCaretPosition());
721:
722: if (offs > -1)
723: {
724: Caret c = t.getCaret();
725: c.setDot(offs);
726: c.setMagicCaretPosition(t.modelToView(offs).getLocation());
727: }
728: }
729: catch (BadLocationException ble)
730: {
731:
732: }
733: }
734: }
735:
736: static class BeginLineAction
737: extends TextAction
738: {
739: BeginLineAction()
740: {
741: super(beginLineAction);
742: }
743:
744: public void actionPerformed(ActionEvent event)
745: {
746: JTextComponent t = getTextComponent(event);
747: try
748: {
749: int offs = Utilities.getRowStart(t, t.getCaretPosition());
750:
751: if (offs > -1)
752: {
753: Caret c = t.getCaret();
754: c.setDot(offs);
755: c.setMagicCaretPosition(t.modelToView(offs).getLocation());
756: }
757: }
758: catch (BadLocationException ble)
759: {
760:
761: }
762: }
763: }
764:
765: static class BeginAction extends TextAction
766: {
767:
768: BeginAction()
769: {
770: super(beginAction);
771: }
772:
773: public void actionPerformed(ActionEvent event)
774: {
775: JTextComponent t = getTextComponent(event);
776: Caret c = t.getCaret();
777: c.setDot(0);
778: try
779: {
780: c.setMagicCaretPosition(t.modelToView(0).getLocation());
781: }
782: catch(BadLocationException ble)
783: {
784:
785: }
786: }
787: }
788:
789: static class EndAction extends TextAction
790: {
791:
792: EndAction()
793: {
794: super(endAction);
795: }
796:
797: public void actionPerformed(ActionEvent event)
798: {
799: JTextComponent t = getTextComponent(event);
800: int offs = t.getDocument().getLength();
801: Caret c = t.getCaret();
802: c.setDot(offs);
803: try
804: {
805: c.setMagicCaretPosition(t.modelToView(offs).getLocation());
806: }
807: catch(BadLocationException ble)
808: {
809:
810: }
811: }
812: }
813:
814:
819: public static class BeepAction extends TextAction
820: {
821:
824: public BeepAction()
825: {
826: super(beepAction);
827: }
828:
829:
834: public void actionPerformed(ActionEvent event)
835: {
836: Toolkit.getDefaultToolkit().beep();
837: }
838: }
839:
840:
847: public static class CopyAction extends TextAction
848: {
849:
850:
853: public CopyAction()
854: {
855: super(copyAction);
856: }
857:
858:
863: public void actionPerformed(ActionEvent event)
864: {
865: getTextComponent(event).copy();
866: }
867: }
868:
869:
870:
878: public static class CutAction extends TextAction
879: {
880:
881:
884: public CutAction()
885: {
886: super(cutAction);
887: }
888:
889:
894: public void actionPerformed(ActionEvent event)
895: {
896: getTextComponent(event).cut();
897: }
898: }
899:
900:
907: public static class PasteAction extends TextAction
908: {
909:
910:
913: public PasteAction()
914: {
915: super(pasteAction);
916: }
917:
918:
923: public void actionPerformed(ActionEvent event)
924: {
925: getTextComponent(event).paste();
926: }
927: }
928:
929:
939: public static class DefaultKeyTypedAction
940: extends TextAction
941: {
942:
943:
946: public DefaultKeyTypedAction()
947: {
948: super(defaultKeyTypedAction);
949: }
950:
951:
956: public void actionPerformed(ActionEvent event)
957: {
958:
959:
960:
961: int cp = event.getActionCommand().codePointAt(0);
962: if (Character.isISOControl(cp))
963: return;
964:
965: JTextComponent t = getTextComponent(event);
966: if (t != null && t.isEnabled() && t.isEditable())
967: t.replaceSelection(event.getActionCommand());
968: }
969: }
970:
971:
976: public static class InsertBreakAction extends TextAction
977: {
978:
979:
982: public InsertBreakAction()
983: {
984: super(insertBreakAction);
985: }
986:
987:
992: public void actionPerformed(ActionEvent event)
993: {
994: JTextComponent t = getTextComponent(event);
995: t.replaceSelection("\n");
996: }
997: }
998:
999:
1003:
1004:
1005: public static class InsertContentAction extends TextAction
1006: {
1007:
1008:
1011: public InsertContentAction()
1012: {
1013: super(insertContentAction);
1014: }
1015:
1016:
1021: public void actionPerformed(ActionEvent event)
1022: {
1023:
1024:
1025: }
1026: }
1027:
1028:
1031: public static class InsertTabAction extends TextAction
1032: {
1033:
1034:
1037: public InsertTabAction()
1038: {
1039: super(insertTabAction);
1040: }
1041:
1042:
1047: public void actionPerformed(ActionEvent event)
1048: {
1049: JTextComponent t = getTextComponent(event);
1050: t.replaceSelection("\t");
1051: }
1052: }
1053:
1054:
1057: private static final long serialVersionUID = 9017245433028523428L;
1058:
1059:
1065: public static final String backwardAction = "caret-backward";
1066:
1067:
1072: public static final String beepAction = "beep";
1073:
1074:
1080: public static final String beginAction = "caret-begin";
1081:
1082:
1088: public static final String beginLineAction = "caret-begin-line";
1089:
1090:
1096: public static final String beginParagraphAction = "caret-begin-paragraph";
1097:
1098:
1104: public static final String beginWordAction = "caret-begin-word";
1105:
1106:
1112: public static final String copyAction = "copy-to-clipboard";
1113:
1114:
1120: public static final String cutAction = "cut-to-clipboard";
1121:
1122:
1128: public static final String defaultKeyTypedAction = "default-typed";
1129:
1130:
1136: public static final String deleteNextCharAction = "delete-next";
1137:
1138:
1144: public static final String deletePrevCharAction = "delete-previous";
1145:
1146:
1151: public static final String downAction = "caret-down";
1152:
1153:
1159: public static final String endAction = "caret-end";
1160:
1161:
1167: public static final String endLineAction = "caret-end-line";
1168:
1169:
1173: public static final String EndOfLineStringProperty = "__EndOfLine__";
1174:
1175:
1181: public static final String endParagraphAction = "caret-end-paragraph";
1182:
1183:
1189: public static final String endWordAction = "caret-end-word";
1190:
1191:
1197: public static final String forwardAction = "caret-forward";
1198:
1199:
1204: public static final String insertBreakAction = "insert-break";
1205:
1206:
1211: public static final String insertContentAction = "insert-content";
1212:
1213:
1218: public static final String insertTabAction = "insert-tab";
1219:
1220:
1226: public static final String nextWordAction = "caret-next-word";
1227:
1228:
1233: public static final String pageDownAction = "page-down";
1234:
1235:
1240: public static final String pageUpAction = "page-up";
1241:
1242:
1248: public static final String pasteAction = "paste-from-clipboard";
1249:
1250:
1256: public static final String previousWordAction = "caret-previous-word";
1257:
1258:
1264: public static final String readOnlyAction = "set-read-only";
1265:
1266:
1271: public static final String selectAllAction = "select-all";
1272:
1273:
1279: public static final String selectionBackwardAction = "selection-backward";
1280:
1281:
1287: public static final String selectionBeginAction = "selection-begin";
1288:
1289:
1295: public static final String selectionBeginLineAction = "selection-begin-line";
1296:
1297:
1303: public static final String selectionBeginParagraphAction =
1304: "selection-begin-paragraph";
1305:
1306:
1312: public static final String selectionBeginWordAction = "selection-begin-word";
1313:
1314:
1320: public static final String selectionDownAction = "selection-down";
1321:
1322:
1328: public static final String selectionEndAction = "selection-end";
1329:
1330:
1336: public static final String selectionEndLineAction = "selection-end-line";
1337:
1338:
1344: public static final String selectionEndParagraphAction =
1345: "selection-end-paragraph";
1346:
1347:
1353: public static final String selectionEndWordAction = "selection-end-word";
1354:
1355:
1361: public static final String selectionForwardAction = "selection-forward";
1362:
1363:
1369: public static final String selectionNextWordAction = "selection-next-word";
1370:
1371:
1377: public static final String selectionPreviousWordAction =
1378: "selection-previous-word";
1379:
1380:
1386: public static final String selectionUpAction = "selection-up";
1387:
1388:
1394: public static final String selectLineAction = "select-line";
1395:
1396:
1402: public static final String selectParagraphAction = "select-paragraph";
1403:
1404:
1410: public static final String selectWordAction = "select-word";
1411:
1412:
1417: public static final String upAction = "caret-up";
1418:
1419:
1425: public static final String writableAction = "set-writable";
1426:
1427:
1430: public DefaultEditorKit()
1431: {
1432:
1433: }
1434:
1435:
1439: private static Action[] defaultActions =
1440: new Action[] {
1441:
1442: new BeepAction(),
1443: new CopyAction(),
1444: new CutAction(),
1445: new DefaultKeyTypedAction(),
1446: new InsertBreakAction(),
1447: new InsertContentAction(),
1448: new InsertTabAction(),
1449: new PasteAction(),
1450:
1451:
1452: new DeleteNextCharAction(),
1453: new DeletePrevCharAction(),
1454:
1455: new BeginLineAction(),
1456: new SelectionBeginLineAction(),
1457:
1458: new EndLineAction(),
1459: new SelectionEndLineAction(),
1460:
1461: new BackwardAction(),
1462: new SelectionBackwardAction(),
1463:
1464: new ForwardAction(),
1465: new SelectionForwardAction(),
1466:
1467: new UpAction(),
1468: new SelectionUpAction(),
1469:
1470: new DownAction(),
1471: new SelectionDownAction(),
1472:
1473: new NextWordAction(),
1474: new SelectionNextWordAction(),
1475:
1476: new PreviousWordAction(),
1477: new SelectionPreviousWordAction(),
1478:
1479: new BeginAction(),
1480: new SelectionBeginAction(),
1481:
1482: new EndAction(),
1483: new SelectionEndAction(),
1484:
1485: new BeginWordAction(),
1486: new SelectionBeginWordAction(),
1487:
1488: new EndWordAction(),
1489: new SelectionEndWordAction(),
1490:
1491: new SelectAllAction(),
1492: new SelectLineAction(),
1493: new SelectWordAction()
1494: };
1495:
1496:
1502: public Caret createCaret()
1503: {
1504: return new DefaultCaret();
1505: }
1506:
1507:
1514: public Document createDefaultDocument()
1515: {
1516: return new PlainDocument();
1517: }
1518:
1519:
1524: public Action[] getActions()
1525: {
1526: return defaultActions;
1527: }
1528:
1529:
1536: public String getContentType()
1537: {
1538: return "text/plain";
1539: }
1540:
1541:
1551: public ViewFactory getViewFactory()
1552: {
1553: return null;
1554: }
1555:
1556:
1569: public void read(InputStream in, Document document, int offset)
1570: throws BadLocationException, IOException
1571: {
1572: read(new InputStreamReader(in), document, offset);
1573: }
1574:
1575:
1588: public void read(Reader in, Document document, int offset)
1589: throws BadLocationException, IOException
1590: {
1591: BufferedReader reader = new BufferedReader(in);
1592:
1593: String line;
1594: StringBuffer content = new StringBuffer();
1595:
1596: while ((line = reader.readLine()) != null)
1597: {
1598: content.append(line);
1599: content.append("\n");
1600: }
1601:
1602: document.insertString(offset, content.substring(0, content.length() - 1),
1603: SimpleAttributeSet.EMPTY);
1604: }
1605:
1606:
1622: public void write(OutputStream out, Document document, int offset, int len)
1623: throws BadLocationException, IOException
1624: {
1625: write(new OutputStreamWriter(out), document, offset, len);
1626: }
1627:
1628:
1643: public void write(Writer out, Document document, int offset, int len)
1644: throws BadLocationException, IOException
1645: {
1646:
1647: if (offset < 0 || offset > document.getLength())
1648: throw new BadLocationException("Tried to write to invalid location",
1649: offset);
1650:
1651:
1652: if (offset + len > document.getLength())
1653: len = document.getLength() - offset;
1654:
1655: out.write(document.getText(offset, len));
1656: }
1657: }