KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > SimpleEdit


1 /*
2  * SimpleEdit.java
3  *
4  * Copyright (C) 1998-2003 Peter Graves
5  * $Id: SimpleEdit.java,v 1.4 2003/08/01 17:28:47 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j;
23
24 public final class SimpleEdit
25 {
26     public static final int MOVE = 1;
27     public static final int SCROLL_CARET = 2;
28     public static final int LINE_EDIT = 3;
29     public static final int INSERT_LINE_SEP = 4;
30     public static final int DELETE_LINE_SEP = 5;
31     public static final int INSERT_STRING = 6;
32     public static final int FOLD = 7;
33
34     public static boolean addUndo(Editor editor, int type)
35     {
36         final Buffer buffer = editor.getBuffer();
37         if (!buffer.supportsUndo())
38             return true; // Not an error.
39
if (editor.getDot() == null)
40             return true; // Not an error.
41
if (buffer.needsRenumbering())
42             buffer.renumber();
43         switch (type) {
44             case MOVE:
45                 buffer.addEdit(new UndoMove(editor));
46                 break;
47             case SCROLL_CARET:
48                 buffer.addEdit(new UndoScrollCaret(editor));
49                 break;
50             case LINE_EDIT:
51                 buffer.addEdit(new UndoLineEdit(editor));
52                 break;
53             case INSERT_LINE_SEP:
54                 buffer.addEdit(new UndoInsertLineSeparator(editor));
55                 break;
56             case DELETE_LINE_SEP:
57                 buffer.addEdit(new UndoDeleteLineSeparator(editor));
58                 break;
59             case INSERT_STRING:
60                 buffer.addEdit(new UndoInsertString(editor));
61                 break;
62             case FOLD:
63                 buffer.addEdit(new UndoFold(editor));
64                 break;
65             default:
66                 Debug.bug();
67                 buffer.getUndoManager().discardAllEdits();
68                 break;
69         }
70         return true;
71     }
72 }
73
Popular Tags