I've an ArrayList of Line Objects called 'lines'. I made my own line class to draw lines with some constraints. It involves selecting two points in a panel and a line is drawn connecting the two points. Everytime a line is created, it is added to the 'lines'. The lines are drawn in a panel.
The paint function in my panel looks like this:
public void paintComponent(Graphics g){
super.paintComponent(g);
for(final Line r:lines){
r.paint((Graphics2D)g);
}
}
And everytime two points are clicked on the panel, a new line is created.
class Board extends JPanel{
public void placeLine(){
Point p1,p2;
JLabel l1,l2;
...
lines.add(new Line(p1,p2,l1,l2));
this.repaint();
}
public void deleteLine(Line l){
lines.remove(l);
}
}
I want to create an UndoAbleEdit in this, and everytime i give undo, the undo method must revert to the last action(i.e.creating a line or deleting a line). I've tried undo for events in JTextArea but i couldn't figure out how to build a custom undo for event changes in ArrayLists. Suggest an example for doing this.
And i'm really sorry for not posting it as an SSCCE.. It is a huge project and it is almost impossible to create an SSCCE.