62
64
public class DefaultEditorKit extends EditorKit
66
static class SelectionPreviousWordAction
69
SelectionPreviousWordAction()
71
super(selectionPreviousWordAction);
74
public void actionPerformed(ActionEvent event)
78
JTextComponent t = getTextComponent(event);
82
int offs = Utilities.getPreviousWord(t, t.getCaretPosition());
84
Caret c = t.getCaret();
86
c.setMagicCaretPosition(t.modelToView(offs).getLocation());
89
catch(BadLocationException ble)
96
static class SelectionNextWordAction
99
SelectionNextWordAction()
101
super(selectionNextWordAction);
104
public void actionPerformed(ActionEvent event)
108
JTextComponent t = getTextComponent(event);
112
int offs = Utilities.getNextWord(t, t.getCaretPosition());
114
Caret c = t.getCaret();
116
c.setMagicCaretPosition(t.modelToView(offs).getLocation());
119
catch(BadLocationException ble)
126
static class PreviousWordAction
131
super(previousWordAction);
134
public void actionPerformed(ActionEvent event)
138
JTextComponent t = getTextComponent(event);
142
int offs = Utilities.getPreviousWord(t, t.getCaretPosition());
144
Caret c = t.getCaret();
146
c.setMagicCaretPosition(t.modelToView(offs).getLocation());
149
catch(BadLocationException ble)
156
static class NextWordAction
161
super(nextWordAction);
164
public void actionPerformed(ActionEvent event)
168
JTextComponent t = getTextComponent(event);
172
int offs = Utilities.getNextWord(t, t.getCaretPosition());
174
Caret c = t.getCaret();
176
c.setMagicCaretPosition(t.modelToView(offs).getLocation());
179
catch(BadLocationException ble)
186
static class SelectAllAction
191
super(selectAllAction);
194
public void actionPerformed(ActionEvent event)
196
JTextComponent t = getTextComponent(event);
197
int offs = t.getDocument().getLength();
198
Caret c = t.getCaret();
204
c.setMagicCaretPosition(t.modelToView(offs).getLocation());
206
catch(BadLocationException ble)
213
static class SelectionBeginAction
216
SelectionBeginAction()
218
super(selectionBeginAction);
221
public void actionPerformed(ActionEvent event)
223
JTextComponent t = getTextComponent(event);
224
Caret c = t.getCaret();
228
c.setMagicCaretPosition(t.modelToView(0).getLocation());
230
catch(BadLocationException ble)
237
static class SelectionEndAction
242
super(selectionEndAction);
245
public void actionPerformed(ActionEvent event)
247
JTextComponent t = getTextComponent(event);
248
int offs = t.getDocument().getLength();
249
Caret c = t.getCaret();
253
c.setMagicCaretPosition(t.modelToView(offs).getLocation());
255
catch(BadLocationException ble)
262
static class SelectionEndLineAction
265
SelectionEndLineAction()
267
super(selectionEndLineAction);
270
public void actionPerformed(ActionEvent event)
272
JTextComponent t = getTextComponent(event);
275
Point p = t.modelToView(t.getCaret().getDot()).getLocation();
276
int cur = t.getCaretPosition();
278
int length = t.getDocument().getLength();
279
while (y == p.y && cur < length)
280
y = t.modelToView(++cur).getLocation().y;
284
Caret c = t.getCaret();
286
c.setMagicCaretPosition(t.modelToView(cur).getLocation());
288
catch (BadLocationException ble)
290
// Nothing to do here
295
static class SelectionBeginLineAction
298
SelectionBeginLineAction()
300
super(selectionBeginLineAction);
303
public void actionPerformed(ActionEvent event)
305
JTextComponent t = getTextComponent(event);
309
// TODO: There is a more efficent solution, but
310
// viewToModel doesn't work properly.
311
Point p = t.modelToView(t.getCaret().getDot()).getLocation();
313
int cur = t.getCaretPosition();
316
while (y == p.y && cur > 0)
317
y = t.modelToView(--cur).getLocation().y;
321
Caret c = t.getCaret();
323
c.setMagicCaretPosition(t.modelToView(cur).getLocation());
325
catch (BadLocationException ble)
332
static class SelectionDownAction
335
SelectionDownAction()
337
super(selectionDownAction);
340
public void actionPerformed(ActionEvent event)
342
JTextComponent t = getTextComponent(event);
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);
355
t.moveCaretPosition(pos);
358
catch(BadLocationException ble)
360
// FIXME: Swallowing allowed?
365
static class SelectionUpAction
370
super(selectionUpAction);
373
public void actionPerformed(ActionEvent event)
375
JTextComponent t = getTextComponent(event);
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);
388
t.moveCaretPosition(pos);
391
catch(BadLocationException ble)
393
// FIXME: Swallowing allowed?
398
static class SelectionForwardAction
401
SelectionForwardAction()
403
super(selectionForwardAction);
406
public void actionPerformed(ActionEvent event)
408
JTextComponent t = getTextComponent(event);
411
int offs = t.getCaretPosition() + 1;
413
if(offs <= t.getDocument().getLength())
415
Caret c = t.getCaret();
419
c.setMagicCaretPosition(t.modelToView(offs).getLocation());
421
catch(BadLocationException ble)
430
static class SelectionBackwardAction
433
SelectionBackwardAction()
435
super(selectionBackwardAction);
438
public void actionPerformed(ActionEvent event)
440
JTextComponent t = getTextComponent(event);
443
int offs = t.getCaretPosition() - 1;
447
Caret c = t.getCaret();
451
c.setMagicCaretPosition(t.modelToView(offs).getLocation());
453
catch(BadLocationException ble)
462
static class DownAction
470
public void actionPerformed(ActionEvent event)
472
JTextComponent t = getTextComponent(event);
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);
485
t.setCaretPosition(pos);
488
catch(BadLocationException ble)
490
// FIXME: Swallowing allowed?
495
static class UpAction
503
public void actionPerformed(ActionEvent event)
505
JTextComponent t = getTextComponent(event);
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);
518
t.setCaretPosition(pos);
521
catch(BadLocationException ble)
523
// FIXME: Swallowing allowed?
528
static class ForwardAction
533
super(forwardAction);
536
public void actionPerformed(ActionEvent event)
538
JTextComponent t = getTextComponent(event);
541
int offs = t.getCaretPosition() + 1;
542
if (offs <= t.getDocument().getLength())
544
Caret c = t.getCaret();
549
c.setMagicCaretPosition(t.modelToView(offs).getLocation());
551
catch (BadLocationException ble)
553
// Should not happen.
561
static class BackwardAction
566
super(backwardAction);
569
public void actionPerformed(ActionEvent event)
571
JTextComponent t = getTextComponent(event);
574
int offs = t.getCaretPosition() - 1;
577
Caret c = t.getCaret();
582
c.setMagicCaretPosition(t.modelToView(offs).getLocation());
584
catch (BadLocationException ble)
586
// Should not happen.
593
static class DeletePrevCharAction
596
DeletePrevCharAction()
598
super(deletePrevCharAction);
601
public void actionPerformed(ActionEvent event)
603
JTextComponent t = getTextComponent(event);
608
int pos = t.getSelectionStart();
609
int len = t.getSelectionEnd() - pos;
612
t.getDocument().remove(pos, len);
616
t.getDocument().remove(pos, 1);
617
Caret c = t.getCaret();
619
c.setMagicCaretPosition(t.modelToView(pos).getLocation());
622
catch (BadLocationException e)
624
// FIXME: we're not authorized to throw this.. swallow it?
630
static class DeleteNextCharAction
633
DeleteNextCharAction()
635
super(deleteNextCharAction);
638
public void actionPerformed(ActionEvent event)
640
JTextComponent t = getTextComponent(event);
645
int pos = t.getSelectionStart();
646
int len = t.getSelectionEnd() - pos;
649
t.getDocument().remove(pos, len);
650
else if (pos < t.getDocument().getLength())
651
t.getDocument().remove(pos, 1);
653
Caret c = t.getCaret();
655
c.setMagicCaretPosition(t.modelToView(pos).getLocation());
657
catch (BadLocationException e)
659
// FIXME: we're not authorized to throw this.. swallow it?
665
static class EndLineAction
670
super(endLineAction);
673
public void actionPerformed(ActionEvent event)
675
JTextComponent t = getTextComponent(event);
678
int offs = Utilities.getRowEnd(t, t.getCaretPosition());
682
Caret c = t.getCaret();
684
c.setMagicCaretPosition(t.modelToView(offs).getLocation());
687
catch (BadLocationException ble)
689
// Nothing to do here
694
static class BeginLineAction
699
super(beginLineAction);
702
public void actionPerformed(ActionEvent event)
704
JTextComponent t = getTextComponent(event);
707
int offs = Utilities.getRowStart(t, t.getCaretPosition());
711
Caret c = t.getCaret();
713
c.setMagicCaretPosition(t.modelToView(offs).getLocation());
716
catch (BadLocationException ble)
65
724
* Creates a beep on the PC speaker.
710
1358
new InsertContentAction(),
711
1359
new InsertTabAction(),
712
1360
new PasteAction(),
713
new TextAction(deleteNextCharAction)
715
public void actionPerformed(ActionEvent event)
717
JTextComponent t = getTextComponent(event);
722
int pos = t.getCaret().getDot();
723
if (pos < t.getDocument().getEndPosition().getOffset())
725
t.getDocument().remove(t.getCaret().getDot(), 1);
728
catch (BadLocationException e)
730
// FIXME: we're not authorized to throw this.. swallow it?
735
new TextAction(deletePrevCharAction)
737
public void actionPerformed(ActionEvent event)
739
JTextComponent t = getTextComponent(event);
744
int pos = t.getCaret().getDot();
745
if (pos > t.getDocument().getStartPosition().getOffset())
747
t.getDocument().remove(pos - 1, 1);
748
t.getCaret().setDot(pos - 1);
751
catch (BadLocationException e)
753
// FIXME: we're not authorized to throw this.. swallow it?
758
new TextAction(backwardAction)
760
public void actionPerformed(ActionEvent event)
762
JTextComponent t = getTextComponent(event);
765
t.getCaret().setDot(Math.max(t.getCaret().getDot() - 1,
766
t.getDocument().getStartPosition().getOffset()));
770
new TextAction(forwardAction)
772
public void actionPerformed(ActionEvent event)
774
JTextComponent t = getTextComponent(event);
777
t.getCaret().setDot(Math.min(t.getCaret().getDot() + 1,
778
t.getDocument().getEndPosition().getOffset()));
782
new TextAction(selectionBackwardAction)
784
public void actionPerformed(ActionEvent event)
786
JTextComponent t = getTextComponent(event);
789
t.getCaret().moveDot(Math.max(t.getCaret().getDot() - 1,
790
t.getDocument().getStartPosition().getOffset()));
794
new TextAction(selectionForwardAction)
796
public void actionPerformed(ActionEvent event)
798
JTextComponent t = getTextComponent(event);
801
t.getCaret().moveDot(Math.min(t.getCaret().getDot() + 1,
802
t.getDocument().getEndPosition().getOffset()));
1362
// These are (package-)private inner classes.
1363
new DeleteNextCharAction(),
1364
new DeletePrevCharAction(),
1366
new BeginLineAction(),
1367
new SelectionBeginLineAction(),
1369
new EndLineAction(),
1370
new SelectionEndLineAction(),
1372
new BackwardAction(),
1373
new SelectionBackwardAction(),
1375
new ForwardAction(),
1376
new SelectionForwardAction(),
1379
new SelectionUpAction(),
1382
new SelectionDownAction(),
1384
new NextWordAction(),
1385
new SelectionNextWordAction(),
1387
new PreviousWordAction(),
1388
new SelectionPreviousWordAction(),
1390
new SelectionBeginAction(),
1391
new SelectionEndAction(),
1392
new SelectAllAction(),