Undo Redo action in a texteditor using a stack in a JTextPane


acu

Joined
May 12, 2009
Messages
2
Reaction score
0
Hi

I' implementing a text editor and supposed to implement the undo and redo actions using a linked list stack.

I've implemented the stack as follows

class Node{

public Node next;
public Node prev;
public Object contents;

public Node(Node prev,Node next,Object contents){
this.prev=prev;
this.next=next;
this.contents=contents;

}
}


class Sll{
static Node head1, tail1, head2, tail2;
static int count=0;

public static void MkStk1(Object obj){

if(tail1==null){
head1=tail1=new Node(null,null,obj);
count++;
}

else{
tail1.next=new Node(tail1,null,obj);
tail1=tail1.next;
count++;
}

if(count==100){
head1=head1.next;
}


}

public static void Pop1(){
//undo the previous action
Object o=tail1.contents;
tail1=tail1.prev;

int count2=0;

if(tail2==null){
head2=tail2=new Node(null,null,o);
count2++;
}

else{
tail2.next=new Node(tail2,null,o);
tail2=tail2.next;
count2++;
}

if(count==100){
head2=head2.next;
}
}


public static void Pop2(){

Object o=tail2.contents;
//do the redo action with o

tail2=tail2.prev;


}


one stack is used to store all the changes happening in the JTextPane
and the other is to store all the undone actions
all the changes happening in the text pane are hoped to passed to the MkStk() method as objects.

But how am I to detect all the changes happening in the text pane?
How to undo the performed action(Eg- fonts, sizes,underlinig,styles, alignments)?
How to push these actions as objects to the stack?

Cheers
acu
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top