Source for javax.swing.text.DefaultEditorKit

   1: /* DefaultEditorKit.java --
   2:    Copyright (C) 2002, 2004, 2005  Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package javax.swing.text;
  40: 
  41: import java.awt.Toolkit;
  42: import java.awt.event.ActionEvent;
  43: 
  44: import java.io.BufferedReader;
  45: import java.io.IOException;
  46: import java.io.InputStream;
  47: import java.io.InputStreamReader;
  48: import java.io.OutputStream;
  49: import java.io.OutputStreamWriter;
  50: import java.io.Reader;
  51: import java.io.Writer;
  52: 
  53: import javax.swing.Action;
  54: import javax.swing.SwingConstants;
  55: 
  56: /**
  57:  * The default implementation of {@link EditorKit}. This <code>EditorKit</code>
  58:  * a plain text <code>Document</code> and several commands that together
  59:  * make up a basic editor, like cut / copy + paste.
  60:  *
  61:  * @author original author unknown
  62:  * @author Roman Kennke (roman@kennke.org)
  63:  * @author Robert Schuster (robertschuster@fsfe.org)
  64:  */
  65: public class DefaultEditorKit extends EditorKit
  66: {
  67:   static class SelectionPreviousWordAction
  68:       extends TextAction
  69:   {
  70:     SelectionPreviousWordAction()
  71:     {
  72:       super(selectionPreviousWordAction);
  73:     }
  74: 
  75:     public void actionPerformed(ActionEvent event)
  76:     {
  77:       try
  78:         {
  79:           JTextComponent t = getTextComponent(event);
  80:       
  81:           if (t != null)
  82:             {
  83:               int offs = Utilities.getPreviousWord(t, t.getCaretPosition());
  84:       
  85:               Caret c = t.getCaret();
  86:               c.moveDot(offs);
  87:               c.setMagicCaretPosition(t.modelToView(offs).getLocation());
  88:             }
  89:         }
  90:       catch(BadLocationException ble)
  91:         {
  92:           // Can't happen.
  93:         }
  94:     }
  95:   }
  96: 
  97:   static class SelectionNextWordAction
  98:       extends TextAction
  99:   {
 100:     SelectionNextWordAction()
 101:     {
 102:       super(selectionNextWordAction);
 103:     }
 104: 
 105:     public void actionPerformed(ActionEvent event)
 106:     {
 107:       try
 108:         {
 109:           JTextComponent t = getTextComponent(event);
 110:       
 111:           if (t != null)
 112:             {
 113:               int offs = Utilities.getNextWord(t, t.getCaretPosition());
 114:       
 115:               Caret c = t.getCaret();
 116:               c.moveDot(offs);
 117:               c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 118:             }
 119:         }
 120:       catch(BadLocationException ble)
 121:         {
 122:           // Can't happen.
 123:         }
 124:     }
 125:   }
 126: 
 127:   static class SelectionBeginWordAction extends TextAction
 128:   {
 129:     SelectionBeginWordAction()
 130:     {
 131:       super(selectionBeginWordAction);
 132:     }
 133:   
 134:     public void actionPerformed(ActionEvent event)
 135:     {
 136:       try
 137:         {
 138:           JTextComponent t = getTextComponent(event);
 139:       
 140:           if (t != null)
 141:             {
 142:               int offs = Utilities.getWordStart(t, t.getCaretPosition());
 143:       
 144:               Caret c = t.getCaret();
 145:               c.moveDot(offs);
 146:               c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 147:             }
 148:         }
 149:       catch(BadLocationException ble)
 150:         {
 151:           // Can't happen.
 152:         }
 153:     }
 154:   }
 155:   
 156:   static class SelectionEndWordAction extends TextAction
 157:   {
 158:     SelectionEndWordAction()
 159:     {
 160:       super(selectionEndWordAction);
 161:     }
 162:   
 163:     public void actionPerformed(ActionEvent event)
 164:     {
 165:       try
 166:         {
 167:           JTextComponent t = getTextComponent(event);
 168:       
 169:           if (t != null)
 170:             {
 171:               int offs = Utilities.getWordEnd(t, t.getCaretPosition());
 172:       
 173:               Caret c = t.getCaret();
 174:               c.moveDot(offs);
 175:               c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 176:             }
 177:         }
 178:       catch(BadLocationException ble)
 179:         {
 180:           // Can't happen.
 181:         }
 182:     }
 183:   }
 184:   
 185:   static class BeginWordAction extends TextAction
 186:   {
 187:     BeginWordAction()
 188:     {
 189:       super(beginWordAction);
 190:     }
 191:   
 192:     public void actionPerformed(ActionEvent event)
 193:     {
 194:       try
 195:         {
 196:           JTextComponent t = getTextComponent(event);
 197:       
 198:           if (t != null)
 199:             {
 200:               int offs = Utilities.getWordStart(t, t.getCaretPosition());
 201:       
 202:               Caret c = t.getCaret();
 203:               c.setDot(offs);
 204:               c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 205:             }
 206:         }
 207:       catch(BadLocationException ble)
 208:         {
 209:           // Can't happen.
 210:         }
 211:     }
 212:   }
 213:   
 214:   static class EndWordAction extends TextAction
 215:   {
 216:     EndWordAction()
 217:     {
 218:       super(endWordAction);
 219:     }
 220:   
 221:     public void actionPerformed(ActionEvent event)
 222:     {
 223:       try
 224:         {
 225:           JTextComponent t = getTextComponent(event);
 226:       
 227:           if (t != null)
 228:             {
 229:               int offs = Utilities.getWordEnd(t, t.getCaretPosition());
 230:       
 231:               Caret c = t.getCaret();
 232:               c.setDot(offs);
 233:               c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 234:             }
 235:         }
 236:       catch(BadLocationException ble)
 237:         {
 238:           // Can't happen.
 239:         }
 240:     }
 241:   }
 242: 
 243:   static class PreviousWordAction
 244:       extends TextAction
 245:   {
 246:     PreviousWordAction()
 247:     {
 248:       super(previousWordAction);
 249:     }
 250: 
 251:     public void actionPerformed(ActionEvent event)
 252:     {
 253:       try
 254:         {
 255:           JTextComponent t = getTextComponent(event);
 256:       
 257:           if (t != null)
 258:             {
 259:               int offs = Utilities.getPreviousWord(t, t.getCaretPosition());
 260:       
 261:               Caret c = t.getCaret();
 262:               c.setDot(offs);
 263:               c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 264:             }
 265:         }
 266:       catch(BadLocationException ble)
 267:         {
 268:           // Can't happen.
 269:         }
 270:     }
 271:   }
 272: 
 273:   static class NextWordAction
 274:       extends TextAction
 275:   {
 276:     NextWordAction()
 277:     {
 278:       super(nextWordAction);
 279:     }
 280: 
 281:     public void actionPerformed(ActionEvent event)
 282:     {
 283:       try
 284:         {
 285:           JTextComponent t = getTextComponent(event);
 286:       
 287:           if (t != null)
 288:             {
 289:               int offs = Utilities.getNextWord(t, t.getCaretPosition());
 290:       
 291:               Caret c = t.getCaret();
 292:               c.setDot(offs);
 293:               c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 294:             }
 295:         }
 296:       catch(BadLocationException ble)
 297:         {
 298:           // Can't happen.
 299:         }
 300:     }
 301:   }
 302: 
 303:   static class SelectAllAction
 304:       extends TextAction
 305:   {
 306:     SelectAllAction()
 307:     {
 308:       super(selectAllAction);
 309:     }
 310: 
 311:     public void actionPerformed(ActionEvent event)
 312:     {
 313:       JTextComponent t = getTextComponent(event);
 314:       if (t != null)
 315:         {
 316:           int offs = t.getDocument().getLength();
 317:           Caret c = t.getCaret();
 318:           c.setDot(0);
 319:           c.moveDot(offs);
 320:           try
 321:             {   
 322:               c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 323:             }
 324:           catch(BadLocationException ble)
 325:             {
 326:               // Can't happen.
 327:             }
 328:         }
 329:     }
 330:   }
 331: 
 332:   static class SelectionBeginAction
 333:       extends TextAction
 334:   {
 335:     SelectionBeginAction()
 336:     {
 337:       super(selectionBeginAction);
 338:     }
 339: 
 340:     public void actionPerformed(ActionEvent event)
 341:     {
 342:       JTextComponent t = getTextComponent(event);
 343:       if (t != null)
 344:         {
 345:           Caret c = t.getCaret();
 346:           c.moveDot(0);
 347:           try
 348:             {   
 349:               c.setMagicCaretPosition(t.modelToView(0).getLocation());
 350:             }
 351:           catch(BadLocationException ble)
 352:             {
 353:               // Can't happen.
 354:             }
 355:         }
 356:     }
 357:   }
 358: 
 359:   static class SelectionEndAction
 360:       extends TextAction
 361:   {
 362:     SelectionEndAction()
 363:     {
 364:       super(selectionEndAction);
 365:     }
 366: 
 367:     public void actionPerformed(ActionEvent event)
 368:     {
 369:       JTextComponent t = getTextComponent(event);
 370:       if (t != null)
 371:         {
 372:           int offs = t.getDocument().getLength();
 373:           Caret c = t.getCaret();
 374:           c.moveDot(offs);
 375:           try
 376:             {   
 377:               c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 378:             }
 379:           catch(BadLocationException ble)
 380:             {
 381:               // Can't happen.
 382:             }
 383:         }
 384:     }
 385:   }
 386:   
 387:   static class SelectionBeginLineAction
 388:     extends TextAction
 389:   {
 390:     
 391:     SelectionBeginLineAction()
 392:     {
 393:       super(selectionBeginLineAction);
 394:     }
 395: 
 396:     public void actionPerformed(ActionEvent event)
 397:     {
 398:       JTextComponent t = getTextComponent(event);
 399:       if (t != null)
 400:         {
 401:           Caret c = t.getCaret();
 402:           try
 403:             {
 404:               int offs = Utilities.getRowStart(t, c.getDot());
 405:               c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 406:             }
 407:           catch(BadLocationException ble)
 408:             {
 409:               // Can't happen.
 410:             }
 411:         }
 412:     }
 413:   }
 414: 
 415:   static class SelectionEndLineAction
 416:       extends TextAction
 417:   {
 418:     SelectionEndLineAction()
 419:     {
 420:       super(selectionEndLineAction);
 421:     }
 422: 
 423:     public void actionPerformed(ActionEvent event)
 424:     {
 425:       JTextComponent t = getTextComponent(event);
 426:       if (t != null)
 427:         {
 428:           Caret c = t.getCaret();
 429:           try
 430:             {
 431:               int offs = Utilities.getRowEnd(t, c.getDot());
 432:               c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 433:             }
 434:           catch(BadLocationException ble)
 435:             {
 436:               // Can't happen.
 437:             }
 438:         }
 439:     }
 440:   }
 441:   
 442:   static class SelectLineAction extends TextAction
 443:   {
 444:     SelectLineAction()
 445:     {
 446:       super(selectLineAction);
 447:     }
 448:   
 449:     public void actionPerformed(ActionEvent event)
 450:     {
 451:       JTextComponent t = getTextComponent(event);
 452:       if (t != null)
 453:         {
 454:           Caret c = t.getCaret();
 455:           try
 456:             {
 457:               int offs1 = Utilities.getRowStart(t, c.getDot());
 458:               int offs2 = Utilities.getRowEnd(t, c.getDot());
 459:               c.setDot(offs2);
 460:               c.moveDot(offs1);
 461:               c.setMagicCaretPosition(t.modelToView(offs2).getLocation());
 462:             }
 463:           catch(BadLocationException ble)
 464:             {
 465:               // Can't happen.
 466:             }
 467:         }
 468:     }
 469:   }
 470:   
 471:   static class SelectWordAction extends TextAction
 472:   {
 473:     SelectWordAction()
 474:     {
 475:       super(selectWordAction);
 476:     }
 477:   
 478:     public void actionPerformed(ActionEvent event)
 479:     {
 480:       JTextComponent t = getTextComponent(event);
 481:       if (t != null)
 482:         {
 483:           Caret c = t.getCaret();
 484:           int dot = c.getDot();
 485:           try
 486:             {
 487:               int wordStart = Utilities.getWordStart(t, dot);
 488: 
 489:               if (dot == wordStart)
 490:                 {
 491:                   // Current cursor position is on the first character in a word.
 492:                   c.setDot(wordStart);
 493:                   c.moveDot(Utilities.getWordEnd(t, wordStart));
 494:                 }
 495:               else
 496:                 {
 497:                   // Current cursor position is not on the first character
 498:                   // in a word. 
 499:                   int nextWord = Utilities.getNextWord(t, dot);
 500:                   int previousWord = Utilities.getPreviousWord(t, dot);
 501:                   int previousWordEnd = Utilities.getWordEnd(t, previousWord);
 502:                   
 503:                   // Cursor position is in the space between two words. In such a
 504:                   // situation just select the space.
 505:                   if (dot >= previousWordEnd && dot <= nextWord)
 506:                     {
 507:                       c.setDot(previousWordEnd);
 508:                       c.moveDot(nextWord);
 509:                     }
 510:                   else
 511:                     {
 512:                       // Cursor position is inside a word. Just select it then.
 513:                       c.setDot(previousWord);
 514:                       c.moveDot(previousWordEnd);
 515:                     }
 516:                 }
 517: 
 518:               // If the position was updated change the magic caret position
 519:               // as well.
 520:               if (c.getDot() != dot)
 521:                 c.setMagicCaretPosition(t.modelToView(c.getDot()).getLocation());
 522:             }
 523:           catch(BadLocationException ble)
 524:             {
 525:               // Can't happen.
 526:             }
 527:         }
 528:     }
 529:   }
 530: 
 531:   static class SelectionDownAction
 532:       extends TextAction.VerticalMovementAction
 533:   {
 534:     SelectionDownAction()
 535:     {
 536:       super(selectionDownAction, SwingConstants.SOUTH);
 537:     }
 538: 
 539:     protected void actionPerformedImpl(Caret c, int offs)
 540:     {
 541:       c.moveDot(offs);
 542:     }
 543:     
 544:   }
 545: 
 546:   static class SelectionUpAction
 547:   extends TextAction.VerticalMovementAction
 548:   {
 549:     SelectionUpAction()
 550:     {
 551:       super(selectionUpAction, SwingConstants.NORTH);
 552:     }
 553: 
 554:     protected void actionPerformedImpl(Caret c, int offs)
 555:     {
 556:       c.moveDot(offs);
 557:     }
 558: 
 559:   }
 560: 
 561:   static class SelectionForwardAction
 562:       extends TextAction.HorizontalMovementAction
 563:   {
 564:     SelectionForwardAction()
 565:     {
 566:       super(selectionForwardAction, SwingConstants.EAST);
 567:     }
 568: 
 569:     protected void actionPerformedImpl(Caret c, int offs)
 570:     {
 571:       c.moveDot(offs);
 572:     }
 573:   }
 574: 
 575:   static class SelectionBackwardAction
 576:       extends TextAction.HorizontalMovementAction
 577:   {
 578:     SelectionBackwardAction()
 579:     {
 580:       super(selectionBackwardAction, SwingConstants.WEST);
 581:     }
 582: 
 583:     protected void actionPerformedImpl(Caret c, int offs)
 584:     {
 585:       c.moveDot(offs);
 586:     }
 587:   }
 588: 
 589:   static class DownAction
 590:       extends TextAction.VerticalMovementAction
 591:   {
 592:     DownAction()
 593:     {
 594:       super(downAction, SwingConstants.SOUTH);
 595:     }
 596: 
 597:     protected void actionPerformedImpl(Caret c, int offs)
 598:     {
 599:       c.setDot(offs);
 600:     }
 601:   }
 602: 
 603:   static class UpAction
 604:       extends TextAction.VerticalMovementAction
 605:   {
 606:     UpAction()
 607:     {
 608:       super(upAction, SwingConstants.NORTH);
 609:     }
 610: 
 611:     protected void actionPerformedImpl(Caret c, int offs)
 612:     {
 613:       c.setDot(offs);
 614:     }
 615:     
 616:   }
 617: 
 618:   static class ForwardAction
 619:       extends TextAction.HorizontalMovementAction
 620:   {
 621:     ForwardAction()
 622:     {
 623:       super(forwardAction, SwingConstants.EAST);
 624:     }
 625: 
 626:     protected void actionPerformedImpl(Caret c, int offs)
 627:     {
 628:       c.setDot(offs);
 629:     }
 630:     
 631:   }
 632: 
 633:   static class BackwardAction
 634:       extends TextAction.HorizontalMovementAction
 635:   {
 636:     BackwardAction()
 637:     {
 638:       super(backwardAction, SwingConstants.WEST);
 639:     }
 640: 
 641:     protected void actionPerformedImpl(Caret c, int offs)
 642:     {
 643:       c.setDot(offs);
 644:     }
 645:     
 646:   }
 647: 
 648:   static class DeletePrevCharAction
 649:       extends TextAction
 650:   {
 651:     DeletePrevCharAction()
 652:     {
 653:       super(deletePrevCharAction);
 654:     }
 655: 
 656:     public void actionPerformed(ActionEvent event)
 657:     {
 658:       JTextComponent t = getTextComponent(event);
 659:       if (t != null)
 660:         {
 661:           try
 662:             {
 663:               int pos = t.getSelectionStart();
 664:               int len = t.getSelectionEnd() - pos;
 665:               
 666:               if (len > 0)
 667:                   t.getDocument().remove(pos, len);
 668:               else if (pos > 0)
 669:                 {
 670:                   pos--;
 671:                   t.getDocument().remove(pos, 1);
 672:                   Caret c = t.getCaret();
 673:                   c.setDot(pos);
 674:                   c.setMagicCaretPosition(t.modelToView(pos).getLocation());
 675:                 }
 676:             }
 677:           catch (BadLocationException e)
 678:             {
 679:               // FIXME: we're not authorized to throw this.. swallow it?
 680:             }
 681:         }
 682:     }
 683:   }
 684: 
 685:   static class DeleteNextCharAction
 686:       extends TextAction
 687:   {
 688:     DeleteNextCharAction()
 689:     {
 690:       super(deleteNextCharAction);
 691:     }
 692: 
 693:     public void actionPerformed(ActionEvent event)
 694:     {
 695:       JTextComponent t = getTextComponent(event);
 696:       if (t != null)
 697:         {
 698:           try
 699:             {
 700:               int pos = t.getSelectionStart();
 701:               int len = t.getSelectionEnd() - pos;
 702:               
 703:               if (len > 0)
 704:                   t.getDocument().remove(pos, len);
 705:               else if (pos < t.getDocument().getLength())
 706:                   t.getDocument().remove(pos, 1);
 707:     
 708:               Caret c = t.getCaret();
 709:               c.setDot(pos);
 710:               c.setMagicCaretPosition(t.modelToView(pos).getLocation());
 711:             }
 712:           catch (BadLocationException e)
 713:             {
 714:               // FIXME: we're not authorized to throw this.. swallow it?
 715:             }
 716:         }
 717:     }
 718:   }
 719: 
 720:   static class EndLineAction
 721:       extends TextAction
 722:   {
 723:     EndLineAction()
 724:     {
 725:       super(endLineAction);
 726:     }
 727: 
 728:     public void actionPerformed(ActionEvent event)
 729:     {
 730:       JTextComponent t = getTextComponent(event);
 731:       if (t != null)
 732:         {
 733:           try
 734:             {
 735:               int offs = Utilities.getRowEnd(t, t.getCaretPosition());
 736:               if (offs > -1)
 737:                 {
 738:                   Caret c = t.getCaret();
 739:                   c.setDot(offs);
 740:                   c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 741:                 }
 742:             }
 743:           catch (BadLocationException ble)
 744:             {
 745:               // Nothing to do here
 746:             }
 747:         }
 748:     }
 749:   }
 750: 
 751:   static class BeginLineAction
 752:       extends TextAction
 753:   {
 754:     BeginLineAction()
 755:     {
 756:       super(beginLineAction);
 757:     }
 758: 
 759:     public void actionPerformed(ActionEvent event)
 760:     {
 761:       JTextComponent t = getTextComponent(event);
 762:       if (t != null)
 763:         {
 764:           try
 765:             {
 766:               int offs = Utilities.getRowStart(t, t.getCaretPosition());
 767:               if (offs > -1)
 768:                 {
 769:                   Caret c = t.getCaret();
 770:                   c.setDot(offs);
 771:                   c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 772:                 }
 773:             }
 774:           catch (BadLocationException ble)
 775:             {
 776:               // Do nothing here.
 777:             }
 778:         }
 779:     }
 780:   }
 781: 
 782:   static class BeginAction extends TextAction
 783:   {
 784:     
 785:     BeginAction()
 786:     {
 787:       super(beginAction);
 788:     }
 789: 
 790:     public void actionPerformed(ActionEvent event)
 791:     {
 792:       JTextComponent t = getTextComponent(event);
 793:       if (t != null)
 794:         {
 795:           Caret c = t.getCaret();
 796:           c.setDot(0);
 797:           try
 798:             {
 799:               c.setMagicCaretPosition(t.modelToView(0).getLocation());
 800:             }
 801:           catch(BadLocationException ble)
 802:             {
 803:               // Can't happen.
 804:             }
 805:         }
 806:     }
 807:   }
 808: 
 809:   static class EndAction extends TextAction
 810:   {
 811:       
 812:     EndAction()
 813:     {
 814:       super(endAction);
 815:     }
 816: 
 817:     public void actionPerformed(ActionEvent event)
 818:     {
 819:       JTextComponent t = getTextComponent(event);
 820:       if (t != null)
 821:         {
 822:           int offs = t.getDocument().getLength();
 823:           Caret c = t.getCaret();
 824:           c.setDot(offs);
 825:           try
 826:             {   
 827:               c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 828:             }
 829:           catch(BadLocationException ble)
 830:             {
 831:               // Can't happen.
 832:             }
 833:         }
 834:     }
 835:   }
 836:   
 837:   /**
 838:    * Creates a beep on the PC speaker.
 839:    *
 840:    * @see Toolkit#beep()
 841:    */
 842:   public static class BeepAction extends TextAction
 843:   {
 844:     /**
 845:      * Creates a new <code>BeepAction</code>.
 846:      */
 847:     public BeepAction()
 848:     {
 849:       super(beepAction);
 850:     }
 851: 
 852:     /**
 853:      * Performs the <code>Action</code>.
 854:      *
 855:      * @param event the action event describing the user action
 856:      */
 857:     public void actionPerformed(ActionEvent event)
 858:     {
 859:       Toolkit.getDefaultToolkit().beep();
 860:     }
 861:   }
 862: 
 863:   /**
 864:    * Copies the selected content into the system clipboard.
 865:    *
 866:    * @see Toolkit#getSystemClipboard()
 867:    * @see CutAction
 868:    * @see PasteAction
 869:    */
 870:   public static class CopyAction extends TextAction
 871:   {
 872: 
 873:     /**
 874:      * Create a new <code>CopyAction</code>.
 875:      */
 876:     public CopyAction()
 877:     {
 878:       super(copyAction);
 879:     }
 880: 
 881:     /**
 882:      * Performs the <code>Action</code>.
 883:      *
 884:      * @param event the action event describing the user action
 885:      */
 886:     public void actionPerformed(ActionEvent event)
 887:     {
 888:       JTextComponent target = getTextComponent(event);
 889:       if (target != null)
 890:         target.copy();
 891:     }
 892:   }
 893: 
 894: 
 895:   /**
 896:    * Copies the selected content into the system clipboard and deletes the
 897:    * selection.
 898:    *
 899:    * @see Toolkit#getSystemClipboard()
 900:    * @see CopyAction
 901:    * @see PasteAction
 902:    */
 903:   public static class CutAction extends TextAction
 904:   {
 905: 
 906:     /**
 907:      * Create a new <code>CutAction</code>.
 908:      */
 909:     public CutAction()
 910:     {
 911:       super(cutAction);
 912:     }
 913: 
 914:     /**
 915:      * Performs the <code>Action</code>.
 916:      *
 917:      * @param event the action event describing the user action
 918:      */
 919:     public void actionPerformed(ActionEvent event)
 920:     {
 921:       JTextComponent target = getTextComponent(event);
 922:       if (target != null)
 923:         target.cut();
 924:     }
 925:   }
 926: 
 927:   /**
 928:    * Copies content from the system clipboard into the editor.
 929:    *
 930:    * @see Toolkit#getSystemClipboard()
 931:    * @see CopyAction
 932:    * @see CutAction
 933:    */
 934:   public static class PasteAction extends TextAction
 935:   {
 936: 
 937:     /**
 938:      * Create a new <code>PasteAction</code>.
 939:      */
 940:     public PasteAction()
 941:     {
 942:       super(pasteAction);
 943:     }
 944: 
 945:     /**
 946:      * Performs the <code>Action</code>.
 947:      *
 948:      * @