Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2004

Tip: Looking for answers? Try searching our database.

How to skip some UndoableEvents in UndoableEditListener?

Thread view: 
Mark Baker - 03 Jan 2004 16:04 GMT
hi,

i'm writing a textbox (extends JTextPane) witch can handle syntax
highlighting. i handle colorization with doc.setCharacterAttributes.
my textbox also supports undo/redo but the problem is, that the
colorization-steps are also made undoable (but they shouldn't)!

here's my code-snippet:

private UndoManager undo = new UndoManager();
...
private final class UndoHandler implements UndoableEditListener {

    public void undoableEditHappened(UndoableEditEvent e) {
        ...
        undo.addEdit(e.getEdit());
        ...
    }
}

i have to skip the undo.addEdit(..) line if "e.getEdit()" is a
DefaultStyledDocument.AttributeUndoableEdit (i think!).

i tried different ways i.e. :
if (!(e.getEdit() instanceof
DefaultStyledDocument.AttributeUndoableEdit)) {
    undo.addEdit(e.getEdit());
}

but anytime i press my undo button, first the color-changes and then
the insert-changes become undone!

has anyone an idea?

Mark

PS: sorry, for my poor english! :)
Alan Moore - 04 Jan 2004 02:13 GMT
>hi,
>
[quoted text clipped - 29 lines]
>
>has anyone an idea?

As I undestand it, when you call e.getEdit(), you get back an instance
of DefaultDocumentEvent (which, in turn, may contain one or more
AttributeUndoableEdits).  So all you have to do is check the type of
the DefaultDocumentEvent:

   public void undoableEditHappened(UndoableEditEvent e) {
       UndoableEdit edit = e.getEdit();
       if (edit instanceof DefaultDocumentEvent &&
           ((DefaultDocumentEvent)edit).getType() ==
               DefaultDocumentEvent.EventType.CHANGE) {
           return;
       }
       undo.addEdit(edit);
   }
Mark Baker - 04 Jan 2004 18:42 GMT
> >hi,
> >
[quoted text clipped - 44 lines]
>         undo.addEdit(edit);
>     }

cool, i was a bit confused about all these event-things!
but finally it works, thanks a lot!

Mark


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.