~ubuntu-branches/ubuntu/precise/classpath/precise

« back to all changes in this revision

Viewing changes to javax/swing/text/DefaultEditorKit.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2006-05-27 16:11:15 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060527161115-h6e39eposdt5snb6
Tags: 2:0.91-3
* Install header files to /usr/include/classpath.
* debian/control: classpath: Conflict with jamvm < 1.4.3 and
  cacao < 0.96 (Closes: #368172).

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
package javax.swing.text;
40
40
 
 
41
import java.awt.Point;
41
42
import java.awt.Toolkit;
42
43
import java.awt.event.ActionEvent;
 
44
 
43
45
import java.io.BufferedReader;
44
46
import java.io.IOException;
45
47
import java.io.InputStream;
61
63
 */
62
64
public class DefaultEditorKit extends EditorKit
63
65
{
 
66
  static class SelectionPreviousWordAction
 
67
      extends TextAction
 
68
  {
 
69
    SelectionPreviousWordAction()
 
70
    {
 
71
      super(selectionPreviousWordAction);
 
72
    }
 
73
 
 
74
    public void actionPerformed(ActionEvent event)
 
75
    {
 
76
      try
 
77
        {
 
78
          JTextComponent t = getTextComponent(event);
 
79
      
 
80
          if (t != null)
 
81
            {
 
82
              int offs = Utilities.getPreviousWord(t, t.getCaretPosition());
 
83
      
 
84
              Caret c = t.getCaret();
 
85
              c.moveDot(offs);
 
86
              c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 
87
            }
 
88
        }
 
89
      catch(BadLocationException ble)
 
90
        {
 
91
          // Can't happen.
 
92
        }
 
93
    }
 
94
  }
 
95
 
 
96
  static class SelectionNextWordAction
 
97
      extends TextAction
 
98
  {
 
99
    SelectionNextWordAction()
 
100
    {
 
101
      super(selectionNextWordAction);
 
102
    }
 
103
 
 
104
    public void actionPerformed(ActionEvent event)
 
105
    {
 
106
      try
 
107
        {
 
108
          JTextComponent t = getTextComponent(event);
 
109
      
 
110
          if (t != null)
 
111
            {
 
112
              int offs = Utilities.getNextWord(t, t.getCaretPosition());
 
113
      
 
114
              Caret c = t.getCaret();
 
115
              c.moveDot(offs);
 
116
              c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 
117
            }
 
118
        }
 
119
      catch(BadLocationException ble)
 
120
        {
 
121
          // Can't happen.
 
122
        }
 
123
    }
 
124
  }
 
125
 
 
126
  static class PreviousWordAction
 
127
      extends TextAction
 
128
  {
 
129
    PreviousWordAction()
 
130
    {
 
131
      super(previousWordAction);
 
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.getPreviousWord(t, t.getCaretPosition());
 
143
      
 
144
              Caret c = t.getCaret();
 
145
              c.setDot(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 NextWordAction
 
157
      extends TextAction
 
158
  {
 
159
    NextWordAction()
 
160
    {
 
161
      super(nextWordAction);
 
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.getNextWord(t, t.getCaretPosition());
 
173
      
 
174
              Caret c = t.getCaret();
 
175
              c.setDot(offs);
 
176
              c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 
177
            }
 
178
        }
 
179
      catch(BadLocationException ble)
 
180
        {
 
181
          // Can't happen.
 
182
        }
 
183
    }
 
184
  }
 
185
 
 
186
  static class SelectAllAction
 
187
      extends TextAction
 
188
  {
 
189
    SelectAllAction()
 
190
    {
 
191
      super(selectAllAction);
 
192
    }
 
193
 
 
194
    public void actionPerformed(ActionEvent event)
 
195
    {
 
196
      JTextComponent t = getTextComponent(event);
 
197
      int offs = t.getDocument().getLength();
 
198
      Caret c = t.getCaret();
 
199
      c.setDot(0);
 
200
      c.moveDot(offs);
 
201
      
 
202
      try
 
203
      {   
 
204
        c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 
205
      }
 
206
    catch(BadLocationException ble)
 
207
      {
 
208
        // Can't happen.
 
209
      }
 
210
    }
 
211
  }
 
212
 
 
213
  static class SelectionBeginAction
 
214
      extends TextAction
 
215
  {
 
216
    SelectionBeginAction()
 
217
    {
 
218
      super(selectionBeginAction);
 
219
    }
 
220
 
 
221
    public void actionPerformed(ActionEvent event)
 
222
    {
 
223
      JTextComponent t = getTextComponent(event);
 
224
      Caret c = t.getCaret();
 
225
      c.moveDot(0);
 
226
      try
 
227
        {   
 
228
          c.setMagicCaretPosition(t.modelToView(0).getLocation());
 
229
        }
 
230
      catch(BadLocationException ble)
 
231
        {
 
232
          // Can't happen.
 
233
        }
 
234
    }
 
235
  }
 
236
 
 
237
  static class SelectionEndAction
 
238
      extends TextAction
 
239
  {
 
240
    SelectionEndAction()
 
241
    {
 
242
      super(selectionEndAction);
 
243
    }
 
244
 
 
245
    public void actionPerformed(ActionEvent event)
 
246
    {
 
247
      JTextComponent t = getTextComponent(event);
 
248
      int offs = t.getDocument().getLength();
 
249
      Caret c = t.getCaret();
 
250
      c.moveDot(offs);
 
251
      try
 
252
        {   
 
253
          c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 
254
        }
 
255
      catch(BadLocationException ble)
 
256
        {
 
257
          // Can't happen.
 
258
        }
 
259
    }
 
260
  }
 
261
 
 
262
  static class SelectionEndLineAction
 
263
      extends TextAction
 
264
  {
 
265
    SelectionEndLineAction()
 
266
    {
 
267
      super(selectionEndLineAction);
 
268
    }
 
269
 
 
270
    public void actionPerformed(ActionEvent event)
 
271
    {
 
272
      JTextComponent t = getTextComponent(event);
 
273
     try
 
274
     {
 
275
       Point p = t.modelToView(t.getCaret().getDot()).getLocation();
 
276
       int cur = t.getCaretPosition();
 
277
       int y = p.y;
 
278
       int length = t.getDocument().getLength();
 
279
       while (y == p.y && cur < length)
 
280
         y = t.modelToView(++cur).getLocation().y;
 
281
       if (cur != length)
 
282
         cur--;
 
283
    
 
284
       Caret c = t.getCaret();
 
285
       c.moveDot(cur);
 
286
       c.setMagicCaretPosition(t.modelToView(cur).getLocation());
 
287
     }
 
288
     catch (BadLocationException ble)
 
289
     {
 
290
       // Nothing to do here
 
291
     }
 
292
    }
 
293
  }
 
294
 
 
295
  static class SelectionBeginLineAction
 
296
      extends TextAction
 
297
  {
 
298
    SelectionBeginLineAction()
 
299
    {
 
300
      super(selectionBeginLineAction);
 
301
    }
 
302
 
 
303
    public void actionPerformed(ActionEvent event)
 
304
    {
 
305
      JTextComponent t = getTextComponent(event);
 
306
      
 
307
      try
 
308
      {
 
309
        // TODO: There is a more efficent solution, but
 
310
        // viewToModel doesn't work properly.
 
311
        Point p = t.modelToView(t.getCaret().getDot()).getLocation();
 
312
        
 
313
        int cur = t.getCaretPosition();
 
314
        int y = p.y;
 
315
        
 
316
        while (y == p.y && cur > 0)
 
317
          y = t.modelToView(--cur).getLocation().y;
 
318
        if (cur != 0)
 
319
          cur++;
 
320
        
 
321
        Caret c = t.getCaret();
 
322
        c.moveDot(cur);
 
323
        c.setMagicCaretPosition(t.modelToView(cur).getLocation());
 
324
      }
 
325
      catch (BadLocationException ble)
 
326
      {
 
327
        // Do nothing here.
 
328
      }
 
329
    }
 
330
  }
 
331
 
 
332
  static class SelectionDownAction
 
333
      extends TextAction
 
334
  {
 
335
    SelectionDownAction()
 
336
    {
 
337
      super(selectionDownAction);
 
338
    }
 
339
 
 
340
    public void actionPerformed(ActionEvent event)
 
341
    {
 
342
      JTextComponent t = getTextComponent(event);
 
343
      try
 
344
        {
 
345
          if (t != null)
 
346
            {
 
347
              Caret c = t.getCaret();
 
348
              // The magic caret position may be null when the caret
 
349
              // has not moved yet.
 
350
              Point mcp = c.getMagicCaretPosition();
 
351
              int x = (mcp != null) ? mcp.x : 0;
 
352
              int pos = Utilities.getPositionBelow(t, t.getCaretPosition(), x);
 
353
              
 
354
              if (pos > -1)
 
355
                t.moveCaretPosition(pos);
 
356
            }
 
357
        }
 
358
      catch(BadLocationException ble) 
 
359
        {
 
360
          // FIXME: Swallowing allowed?
 
361
        }
 
362
    }
 
363
  }
 
364
 
 
365
  static class SelectionUpAction
 
366
      extends TextAction
 
367
  {
 
368
    SelectionUpAction()
 
369
    {
 
370
      super(selectionUpAction);
 
371
    }
 
372
 
 
373
    public void actionPerformed(ActionEvent event)
 
374
    {
 
375
      JTextComponent t = getTextComponent(event);
 
376
      try
 
377
        {
 
378
          if (t != null)
 
379
            {
 
380
              Caret c = t.getCaret();
 
381
              // The magic caret position may be null when the caret
 
382
              // has not moved yet.
 
383
              Point mcp = c.getMagicCaretPosition();
 
384
              int x = (mcp != null) ? mcp.x : 0;
 
385
              int pos = Utilities.getPositionAbove(t, t.getCaretPosition(), x);
 
386
              
 
387
              if (pos > -1)
 
388
                t.moveCaretPosition(pos);
 
389
            }
 
390
        }
 
391
      catch(BadLocationException ble) 
 
392
        {
 
393
          // FIXME: Swallowing allowed?
 
394
        }
 
395
    }
 
396
  }
 
397
 
 
398
  static class SelectionForwardAction
 
399
      extends TextAction
 
400
  {
 
401
    SelectionForwardAction()
 
402
    {
 
403
      super(selectionForwardAction);
 
404
    }
 
405
 
 
406
    public void actionPerformed(ActionEvent event)
 
407
    {
 
408
      JTextComponent t = getTextComponent(event);
 
409
      if (t != null)
 
410
        {
 
411
          int offs = t.getCaretPosition() + 1;
 
412
          
 
413
          if(offs <= t.getDocument().getLength())
 
414
            {
 
415
              Caret c = t.getCaret();
 
416
              c.moveDot(offs);
 
417
              try
 
418
                {
 
419
                  c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 
420
                }
 
421
              catch(BadLocationException ble)
 
422
              {
 
423
                // Can't happen.
 
424
              }
 
425
            }
 
426
        }
 
427
    }
 
428
  }
 
429
 
 
430
  static class SelectionBackwardAction
 
431
      extends TextAction
 
432
  {
 
433
    SelectionBackwardAction()
 
434
    {
 
435
      super(selectionBackwardAction);
 
436
    }
 
437
 
 
438
    public void actionPerformed(ActionEvent event)
 
439
    {
 
440
      JTextComponent t = getTextComponent(event);
 
441
      if (t != null)
 
442
        {
 
443
      int offs = t.getCaretPosition() - 1;
 
444
      
 
445
      if(offs >= 0)
 
446
        {
 
447
          Caret c = t.getCaret();
 
448
          c.moveDot(offs);
 
449
          try
 
450
            {
 
451
              c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 
452
            }
 
453
          catch(BadLocationException ble)
 
454
          {
 
455
            // Can't happen.
 
456
          }
 
457
        }
 
458
        }
 
459
    }
 
460
  }
 
461
 
 
462
  static class DownAction
 
463
      extends TextAction
 
464
  {
 
465
    DownAction()
 
466
    {
 
467
      super(downAction);
 
468
    }
 
469
 
 
470
    public void actionPerformed(ActionEvent event)
 
471
    {
 
472
      JTextComponent t = getTextComponent(event);
 
473
      try
 
474
        {
 
475
          if (t != null)
 
476
            {
 
477
              Caret c = t.getCaret();
 
478
              // The magic caret position may be null when the caret
 
479
              // has not moved yet.
 
480
              Point mcp = c.getMagicCaretPosition();
 
481
              int x = (mcp != null) ? mcp.x : 0;
 
482
              int pos = Utilities.getPositionBelow(t, t.getCaretPosition(), x);
 
483
              
 
484
              if (pos > -1)
 
485
                t.setCaretPosition(pos);
 
486
            }
 
487
        }
 
488
      catch(BadLocationException ble) 
 
489
        {
 
490
          // FIXME: Swallowing allowed?
 
491
        }
 
492
    }
 
493
  }
 
494
 
 
495
  static class UpAction
 
496
      extends TextAction
 
497
  {
 
498
    UpAction()
 
499
    {
 
500
      super(upAction);
 
501
    }
 
502
 
 
503
    public void actionPerformed(ActionEvent event)
 
504
    {
 
505
      JTextComponent t = getTextComponent(event);
 
506
      try
 
507
        {
 
508
          if (t != null)
 
509
            {
 
510
              Caret c = t.getCaret();
 
511
              // The magic caret position may be null when the caret
 
512
              // has not moved yet.
 
513
              Point mcp = c.getMagicCaretPosition();
 
514
              int x = (mcp != null) ? mcp.x : 0;
 
515
              int pos = Utilities.getPositionAbove(t, t.getCaretPosition(), x);
 
516
              
 
517
              if (pos > -1)
 
518
                t.setCaretPosition(pos);
 
519
            }
 
520
        }
 
521
      catch(BadLocationException ble) 
 
522
        {
 
523
          // FIXME: Swallowing allowed?
 
524
        }
 
525
    }
 
526
  }
 
527
 
 
528
  static class ForwardAction
 
529
      extends TextAction
 
530
  {
 
531
    ForwardAction()
 
532
    {
 
533
      super(forwardAction);
 
534
    }
 
535
 
 
536
    public void actionPerformed(ActionEvent event)
 
537
    {
 
538
      JTextComponent t = getTextComponent(event);
 
539
      if (t != null)
 
540
        {
 
541
          int offs = t.getCaretPosition() + 1;
 
542
          if (offs <= t.getDocument().getLength())
 
543
            {
 
544
              Caret c = t.getCaret();
 
545
              c.setDot(offs);
 
546
              
 
547
              try
 
548
                {
 
549
                  c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 
550
                }
 
551
              catch (BadLocationException ble)
 
552
                {
 
553
                  // Should not happen.
 
554
                }
 
555
            }
 
556
        }
 
557
      
 
558
    }
 
559
  }
 
560
 
 
561
  static class BackwardAction
 
562
      extends TextAction
 
563
  {
 
564
    BackwardAction()
 
565
    {
 
566
      super(backwardAction);
 
567
    }
 
568
 
 
569
    public void actionPerformed(ActionEvent event)
 
570
    {
 
571
      JTextComponent t = getTextComponent(event);
 
572
      if (t != null)
 
573
        {
 
574
          int offs = t.getCaretPosition() - 1;
 
575
          if (offs >= 0)
 
576
            {
 
577
              Caret c = t.getCaret();
 
578
              c.setDot(offs);
 
579
              
 
580
              try
 
581
                {
 
582
                  c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 
583
                }
 
584
              catch (BadLocationException ble)
 
585
                {
 
586
                  // Should not happen.
 
587
                }
 
588
            }
 
589
        }
 
590
    }
 
591
  }
 
592
 
 
593
  static class DeletePrevCharAction
 
594
      extends TextAction
 
595
  {
 
596
    DeletePrevCharAction()
 
597
    {
 
598
      super(deletePrevCharAction);
 
599
    }
 
600
 
 
601
    public void actionPerformed(ActionEvent event)
 
602
    {
 
603
      JTextComponent t = getTextComponent(event);
 
604
      if (t != null)
 
605
        {
 
606
          try
 
607
            {
 
608
              int pos = t.getSelectionStart();
 
609
              int len = t.getSelectionEnd() - pos;
 
610
              
 
611
              if (len > 0)
 
612
                  t.getDocument().remove(pos, len);
 
613
              else if (pos > 0)
 
614
                {
 
615
                  pos--;
 
616
                  t.getDocument().remove(pos, 1);
 
617
                  Caret c = t.getCaret();
 
618
                  c.setDot(pos);
 
619
                  c.setMagicCaretPosition(t.modelToView(pos).getLocation());
 
620
                }
 
621
            }
 
622
          catch (BadLocationException e)
 
623
            {
 
624
              // FIXME: we're not authorized to throw this.. swallow it?
 
625
            }
 
626
        }
 
627
    }
 
628
  }
 
629
 
 
630
  static class DeleteNextCharAction
 
631
      extends TextAction
 
632
  {
 
633
    DeleteNextCharAction()
 
634
    {
 
635
      super(deleteNextCharAction);
 
636
    }
 
637
 
 
638
    public void actionPerformed(ActionEvent event)
 
639
    {
 
640
      JTextComponent t = getTextComponent(event);
 
641
      if (t != null)
 
642
        {
 
643
          try
 
644
            {
 
645
              int pos = t.getSelectionStart();
 
646
              int len = t.getSelectionEnd() - pos;
 
647
              
 
648
              if (len > 0)
 
649
                  t.getDocument().remove(pos, len);
 
650
              else if (pos < t.getDocument().getLength())
 
651
                  t.getDocument().remove(pos, 1);
 
652
    
 
653
              Caret c = t.getCaret();
 
654
              c.setDot(pos);
 
655
              c.setMagicCaretPosition(t.modelToView(pos).getLocation());
 
656
            }
 
657
          catch (BadLocationException e)
 
658
            {
 
659
              // FIXME: we're not authorized to throw this.. swallow it?
 
660
            }
 
661
        }
 
662
    }
 
663
  }
 
664
 
 
665
  static class EndLineAction
 
666
      extends TextAction
 
667
  {
 
668
    EndLineAction()
 
669
    {
 
670
      super(endLineAction);
 
671
    }
 
672
 
 
673
    public void actionPerformed(ActionEvent event)
 
674
    {
 
675
      JTextComponent t = getTextComponent(event);
 
676
      try
 
677
     {
 
678
       int offs = Utilities.getRowEnd(t, t.getCaretPosition());
 
679
       
 
680
       if (offs > -1)
 
681
         {
 
682
           Caret c = t.getCaret();
 
683
           c.setDot(offs);
 
684
           c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 
685
         }
 
686
     }
 
687
     catch (BadLocationException ble)
 
688
     {
 
689
       // Nothing to do here
 
690
     }
 
691
    }
 
692
  }
 
693
 
 
694
  static class BeginLineAction
 
695
      extends TextAction
 
696
  {
 
697
    BeginLineAction()
 
698
    {
 
699
      super(beginLineAction);
 
700
    }
 
701
 
 
702
    public void actionPerformed(ActionEvent event)
 
703
    {
 
704
      JTextComponent t = getTextComponent(event);
 
705
      try
 
706
      {
 
707
        int offs = Utilities.getRowStart(t, t.getCaretPosition());
 
708
        
 
709
        if (offs > -1)
 
710
          {
 
711
            Caret c = t.getCaret();
 
712
            c.setDot(offs);
 
713
            c.setMagicCaretPosition(t.modelToView(offs).getLocation());
 
714
          }
 
715
      }
 
716
      catch (BadLocationException ble)
 
717
      {
 
718
        // Do nothing here.
 
719
      }
 
720
    }
 
721
  }
 
722
 
64
723
  /**
65
724
   * Creates a beep on the PC speaker.
66
725
   *
112
771
     */
113
772
    public void actionPerformed(ActionEvent event)
114
773
    {
115
 
      // FIXME: Implement me. Tookit.getSystemClipboard should be used
116
 
      // for that.
 
774
      getTextComponent(event).copy();
117
775
    }
118
776
  }
119
777
 
144
802
     */
145
803
    public void actionPerformed(ActionEvent event)
146
804
    {
147
 
      // FIXME: Implement me. Tookit.getSystemClipboard should be used
148
 
      // for that.
 
805
      getTextComponent(event).cut();
149
806
    }
150
807
  }
151
808
 
174
831
     */
175
832
    public void actionPerformed(ActionEvent event)
176
833
    {
177
 
      // FIXME: Implement me. Tookit.getSystemClipboard should be used
178
 
      // for that.
 
834
      getTextComponent(event).paste();
179
835
    }
180
836
  }
181
837
 
216
872
        return;
217
873
 
218
874
      JTextComponent t = getTextComponent(event);
219
 
      if (t != null)
220
 
        {
221
 
          try
222
 
            {
223
 
              t.getDocument().insertString(t.getCaret().getDot(),
224
 
                                           event.getActionCommand(), null);
225
 
            }
226
 
          catch (BadLocationException be)
227
 
            {
228
 
              // FIXME: we're not authorized to throw this.. swallow it?
229
 
            }
230
 
        }
231
 
    }
 
875
      if (t != null && t.isEnabled() && t.isEditable())
 
876
        t.replaceSelection(event.getActionCommand());
 
877
    }    
232
878
  }
233
879
 
234
880
  /**
309
955
     */
310
956
    public void actionPerformed(ActionEvent event)
311
957
    {
312
 
      // FIXME: Implement this.
 
958
      JTextComponent t = getTextComponent(event);
 
959
      t.replaceSelection("\t");
313
960
    }
314
961
  }
315
962
 
702
1349
  // to handle this.
703
1350
  private static Action[] defaultActions = 
704
1351
  new Action[] {
 
1352
    // These classes are public because they are so in the RI.            
705
1353
    new BeepAction(),
706
1354
    new CopyAction(),
707
1355
    new CutAction(),
710
1358
    new InsertContentAction(),
711
1359
    new InsertTabAction(),
712
1360
    new PasteAction(),
713
 
    new TextAction(deleteNextCharAction) 
714
 
    { 
715
 
      public void actionPerformed(ActionEvent event)
716
 
      {
717
 
        JTextComponent t = getTextComponent(event);
718
 
        if (t != null)
719
 
          {
720
 
            try
721
 
              {
722
 
                int pos = t.getCaret().getDot();
723
 
                if (pos < t.getDocument().getEndPosition().getOffset())
724
 
                  {
725
 
                    t.getDocument().remove(t.getCaret().getDot(), 1);
726
 
                  }
727
 
              }
728
 
            catch (BadLocationException e)
729
 
              {
730
 
                // FIXME: we're not authorized to throw this.. swallow it?
731
 
              }
732
 
          }
733
 
      }
734
 
    },
735
 
    new TextAction(deletePrevCharAction) 
736
 
    { 
737
 
      public void actionPerformed(ActionEvent event)
738
 
      {
739
 
        JTextComponent t = getTextComponent(event);
740
 
        if (t != null)
741
 
          {
742
 
            try
743
 
              {
744
 
                int pos = t.getCaret().getDot();
745
 
                if (pos > t.getDocument().getStartPosition().getOffset())
746
 
                  {
747
 
                    t.getDocument().remove(pos - 1, 1);
748
 
                    t.getCaret().setDot(pos - 1);
749
 
                  }
750
 
              }
751
 
            catch (BadLocationException e)
752
 
              {
753
 
                // FIXME: we're not authorized to throw this.. swallow it?
754
 
              }
755
 
          }
756
 
      }
757
 
    },
758
 
    new TextAction(backwardAction) 
759
 
    { 
760
 
      public void actionPerformed(ActionEvent event)
761
 
      {
762
 
        JTextComponent t = getTextComponent(event);
763
 
        if (t != null)
764
 
          {
765
 
            t.getCaret().setDot(Math.max(t.getCaret().getDot() - 1,
766
 
                                         t.getDocument().getStartPosition().getOffset()));
767
 
          }
768
 
      }
769
 
    },
770
 
    new TextAction(forwardAction) 
771
 
    { 
772
 
      public void actionPerformed(ActionEvent event)
773
 
      {
774
 
        JTextComponent t = getTextComponent(event);
775
 
        if (t != null)
776
 
          {
777
 
            t.getCaret().setDot(Math.min(t.getCaret().getDot() + 1,
778
 
                                         t.getDocument().getEndPosition().getOffset()));
779
 
          }
780
 
      }
781
 
    },
782
 
    new TextAction(selectionBackwardAction)
783
 
    {
784
 
      public void actionPerformed(ActionEvent event)
785
 
      {
786
 
        JTextComponent t = getTextComponent(event);
787
 
        if (t != null)
788
 
          {
789
 
            t.getCaret().moveDot(Math.max(t.getCaret().getDot() - 1,
790
 
                                          t.getDocument().getStartPosition().getOffset()));
791
 
          }
792
 
      }
793
 
    },
794
 
    new TextAction(selectionForwardAction)
795
 
    {
796
 
      public void actionPerformed(ActionEvent event)
797
 
      {
798
 
        JTextComponent t = getTextComponent(event);
799
 
        if (t != null)
800
 
          {
801
 
            t.getCaret().moveDot(Math.min(t.getCaret().getDot() + 1,
802
 
                                          t.getDocument().getEndPosition().getOffset()));
803
 
          }
804
 
      }
805
 
    },
 
1361
    
 
1362
    // These are (package-)private inner classes.
 
1363
    new DeleteNextCharAction(),
 
1364
    new DeletePrevCharAction(),
 
1365
 
 
1366
    new BeginLineAction(),
 
1367
    new SelectionBeginLineAction(),
 
1368
    
 
1369
    new EndLineAction(),
 
1370
    new SelectionEndLineAction(),
 
1371
    
 
1372
    new BackwardAction(),
 
1373
    new SelectionBackwardAction(),
 
1374
 
 
1375
    new ForwardAction(),
 
1376
    new SelectionForwardAction(),
 
1377
    
 
1378
    new UpAction(),
 
1379
    new SelectionUpAction(),
 
1380
 
 
1381
    new DownAction(),
 
1382
    new SelectionDownAction(),
 
1383
    
 
1384
    new NextWordAction(),
 
1385
    new SelectionNextWordAction(),
 
1386
 
 
1387
    new PreviousWordAction(),
 
1388
    new SelectionPreviousWordAction(),
 
1389
 
 
1390
    new SelectionBeginAction(),
 
1391
    new SelectionEndAction(),
 
1392
    new SelectAllAction(),
806
1393
  };
807
1394
 
808
1395
  /**
911
1498
        content.append("\n");
912
1499
      }
913
1500
    
914
 
    document.insertString(offset, content.toString(),
 
1501
    document.insertString(offset, content.substring(0, content.length() - 1),
915
1502
                          SimpleAttributeSet.EMPTY);
916
1503
  }
917
1504