Undo with Memento pattern vs swing undo

I was tempted to add this question to the end of http://forum.java.sun.com/thread.jsp?forum=425&thread=440740&tstart=0&trange=15 but I've had a poor response in the past by adding a question to the end of an existing thread.
I am working on a project with a rather poor implementation of undo where every Action has to extend an UndoableAction and a copy of the Action itself is stored on the undo queue. This gives me the following problems -
1. Only Actions are undoable, not events such as scolling the display area.
2. We can't make use of an other Action hierarchy other than one with an UndoableAction ancestor.
I'm familiar with the idea of implementing undo/redo using the memento pattern.
My plan is to modify this code so that Actions record current state in a Memento and store that memento in an undo queue instead. Events such as scrolling can then create and store mementos also.
In my plans to implement this someone brought up the swing undo mechanism. I've had little success in finding how to implement swing undo on anything other than a simple text field. It also seems to be something that is based around the control rather than the model.
We have various complex models to keep in synch plus several views onto those models. It seems simpler to me to generate mementos on Actions that effect the model (at least it's something I understand). When a memento gets undone all views listening to model changes will update anyway.
Can anyone see an argument to use swing undo in preference? If so can anyone point me to a better example for implementing swing undo on anything other than text edit controls.
Thanks
Bob.

I don't know much about the Swing undo but it seems unlikely that it would handle anything complex. It would only be able to keep track of changes in the graphical representation of you data, not the model behind it.

Similar Messages

  • A gap between letters started to show in my indesgn files. tried to undo with tracking, the paragraph settings. nothing helped. it ruins the fluent view of the document. how can i restore the program so that doesn't happen?

    a gap between letters started to show in my indesign files. tried to undo with tracking, then with the paragraph settings. nothing helped. it ruins the fluent view of the document. how can i restore the program so that doesn't happen?
    for example: say i write a paragraph. then, in a weird some sort of way an involuntary gap suddenly appears between different letters of random words(i did not recognize any pattern to the gap appearing) throughout the entire paragraph. once i've double clicked on that paragraph, and made a minor change, lets say tapped a 'space' key, and then clicked ctrl+z to undo, it has aligned(or fixed) the entire paragraph and made it look ok again. i've tried numerous ways to undo the entire thing, but cannot find the reason. i've been working for a few years and there's no reason why this thing all of a sudden should happen right now.
    if anyone has stumbled on something like that and can advise, i would welcome it.
    MNS-KG
    Vadim

    yep...i'm typing with hebrew. i'll make a printscreen with the settings you've asked for@:
    if you look closely you'll see that almost every line has a single letter apart. in hebrew there is no usually a singe letter structured words.

  • How to manage Undo with multiple models linked together

    Hello,
    I'm writing a java desktop application using MVC model. I'm using javax.swing.undo.UndoManager and related classes to manage the undo/redo capabilities. I know how to use it but I can't see how to implement it in a clean way when I have several models linked together. I hope someone can help...
    I have 2 models M1 and M2. M2 depends on M1, so M2 listens to M1 changes.
    Each model has its own view V1 and V2.
    Model's methods which change the model's state create an UndoableEdit to restore the previous model's state.
    UndoableEdits are combined together in a CompoundEdit created by the controller.
    Upon a user action on V1:
    1. M1 change
    => add UndoableEdit to current CompoundEdit
    => notify V1
    => notify M2
    2. M2 change
    => add UndoableEdit to current CompoundEdit
    => notify V2
    When we undo the CompoundEdit:
    1. Undo M2 change
    => notify V2
    2. Undo M1 change
    => notify V1
    => notify M2 !! PROBLEM
    3. M2 change !! PROBLEM
    => notify V2 !! PROBLEM
    And this is my problem: when undoing change on M1, I need to notify listeners (V1 and M2), but in this case M2 should not be notified because M2 has already restored its previous state in the CompoundEdit undo chain.
    A solution might be to inhibit M2 listener if we're inside a undo/redo, but I feel it's not clean and not sure it will always work... Is there another way to solve this ? Or is it my architecture which is wrong ?
    Thank you.
    Edited by: gibi_31 on Aug 19, 2010 3:08 AM
    Edited by: gibi_31 on Aug 19, 2010 3:11 AM

    Hello,
    Upon a user action on V1:
    1. M1 change
    => add UndoableEdit to current CompoundEdit
    => notify V1
    => notify M2
    2. M2 change
    => add UndoableEdit to current CompoundEditWhy?
    Do you need to be able to undo the M2 change alone in any other case than undoing M1's change?
    And if you don't add M2 change to the compound edit, doesn't the M2 update triggered by undoing the the M1 undo the M2 state automatically (thus performing the M2 undo)?
    And this is my problem: when undoing change on M1, I need to notify listeners (V1 and M2), but in this case M2 should not be notified because M2 has already restored its previous state in the CompoundEdit undo chain.
    A solution might be to inhibit M2 listener if we're inside a undo/redo, but I feel it's not clean and not sure it will always work...I agree it looks unclean (and quite dangerous actually if the app ever needs to support some form of multi-threaded model changes).
    Regards,
    J.

  • HELP PLEASE!  I logged in with my iCloud account and merged her contacts with mine how can I undo this If i log out her contacts erase and stay on my iPhone and visa versa

    HELP PLEASE!  I logged in with my iCloud account and merged her contacts with mine how can I undo this If i log out her contacts erase and stay on my iPhone and visa versa

    One of you will need to migrate to a separate iCloud account, then you can delete the other person's data from each account.
    To migrate to a new account, start by saving an photo stream photos that are not in your camera roll to your camera roll.  To do this, open your my photo stream album, tap Select, tap the photos, tap the share icon (box with upward pointing errow), then tap Save to Camera Roll.  Then go to Settings>iCloud, tap Delete Account, choose Keep on My iPhone when prompted, provide the account password to turn off Find My iPhone when prompted, then sign in with a different Apple ID to create the new account and choose Merge to upload your data.
    You can then each to to your iCloud accounts on icloud.com from your computer and delete the other person's data from your account.

  • Memento pattern for databas operation

    Hi I'm a french student and I have a problem using the memento pattern
    I have to undo or redo database transaction
    but i, don't really understand how it works
    I've got another problem with the undo menuitem
    If someone know an interesting website or can explain me how i've got to do ...
    Thanks

    Memento is only part of the solution to this problem, you probably also need to use the command pattern to for each action/command, a chain of responsibility to mange your undo & redo stack and memento to hold the details.
    http://www.burn-rubber.demon.co.uk/articles/memento.doc
    http://directory.google.com/Top/Computers/Programming/Methodologies/Patterns_and_Anti-Patterns/

  • My 24" iMac display suddenly shows blank screen with funny pattern

    My 24" iMac display suddenly shows blank screen with funny pattern after bootup. Anyone know the cause? http://twitpic.com/51hih7 http://twitpic.com/51hihw http://twitpic.com/51hiiv

    My 24" iMac display suddenly shows blank screen with funny pattern after bootup. Anyone know the cause? http://twitpic.com/51hih7 http://twitpic.com/51hihw http://twitpic.com/51hiiv

  • How can I replace a color with a pattern fill?

    Hi everyone, thanks for any responses in advance!
    I've created quite a detailed design that works with 4 pixels per cm and 16 colors, canvas size 120x170cm. I'm wanting to replace all of a single color with a pattern, is there a way to do this?
    I can replace a color with another flat color by using adjustments etc... but I want to fill the entire of one color area with a pattern instead. The only way I can think to do this would be to use the magic wand tool to select every pixel of the same color, then create a new layer and overlay with a fill of the desired pattern, however as the design is so detailed it would take me an awful long time to select each color!
    Can anyone suggest a quicker more efficiant way to do this?
    Thanks!

    Select --> Color Range
    Mylenium

  • Firefox application quits unexpectedly on various websites with no pattern: firefox-bin [770]

    Firefox application quits unexpectedly on various websites with no pattern. Part of the error message details reads "firefox-bin [770]"
    It started happening this AM after I visited facebook and got an invite from someone I don't know. I didn't reply. Ever since, I can only browse Safari but for a few pages until it quits.
    Please help.
    Thank you.

    Run /Utilities/Console and click 'All Messages' top left - look for the entries around the quit times and see if they give any pointers why the apps are quitting ? If you're not sure what the lines mean copy and post (just those not the whole log) here.
    There may also be some clues in /Library/Logs/Crash Reporter nameofapplication_date

  • Problem of navigation with UI Patterns

    Hi,
    I have developed one CAF(Entity Services) application & configured with UI Patterns by using following liink.
    http://localhost:50100/webdynpro/dispatcher/sap.com/cafUIconfigbrowser/ConfigBrowser
    now i am getting two view pages as follows
    1)For Create Employee
    http://localhost:50100/webdynpro/dispatcher/sap.com/cafUIptn~objecteditor/ObjectEditor?app.parameter1=&app.parameter2=N&app.configName=createEmployee
    2)For Search Employee
    http://localhost:50100/webdynpro/dispatcher/sap.com/cafUIptn~objectselector/ObjectSelector?app.configName=employeeSelector
    Now i want to navigate from one view page to another , or i want to send  or reterive data to & from database by implementing user defined buttons.
    can i do this thing by using UI Patterns.plz reply back ASAP.
    Thank You very much
    Pawan Mishra

    Hi,
    I have developed one CAF(Entity Services) application & configured with UI Patterns by using following liink.
    http://localhost:50100/webdynpro/dispatcher/sap.com/cafUIconfigbrowser/ConfigBrowser
    now i am getting two view pages as follows
    1)For Create Employee
    http://localhost:50100/webdynpro/dispatcher/sap.com/cafUIptn~objecteditor/ObjectEditor?app.parameter1=&app.parameter2=N&app.configName=createEmployee
    2)For Search Employee
    http://localhost:50100/webdynpro/dispatcher/sap.com/cafUIptn~objectselector/ObjectSelector?app.configName=employeeSelector
    Now i want to navigate from one view page to another , or i want to send  or reterive data to & from database by implementing user defined buttons.
    can i do this thing by using UI Patterns.plz reply back ASAP.
    Thank You very much
    Pawan Mishra

  • Filling an object with a pattern without distortion?

    I have this camo pattern:
    wich already tiles seemlessy but when i turn it into a swatch it won't tile. it distorts the pattern and blows it up instead of using it as is and tiling:
    what is the problem here? can i scale it in some option menu? can i control the orientation? im creating a vector based logo, is this the right way to go about filling the object with this pattern?
    i want it to be scaled and tiled. what is the best way to go about it? what would u do? thanks in advance

    yup i thought so. it HAS to be vector based.
    it does not have to be vector, it can be jpeg or gif, but it has to be embedded...as for not using it in a logo, Scott can explain that.
    255x247 px
    the object is any size as its a vector. How are u filling yours? photoshop then a clipping mask?
    I meant the size of the camo image in relation to your vector object, not the actual size in pixels.
    in this sample I grabbed a GIF, embedded it, dragged it to the swatches palette, sent the image to back, then filled both the small object and the big object with the gif-embedded swatch, just to illustrate what happens with the size position.

  • Match hex 00 or NULL with Match pattern function

    Hi, I am using Match pattern funciton to match NULL character and 0000 character in a string (hex display).
    Someone told mu use the following regular expression:
    ^[\00]*, and [\00]*$ , and he said:
                    \00 is Hex 00
                    \0 un-defined
    But I read some stuffs about regular  expression that \0x00 is Hex 00, \00 is Octal 000.I want to know what meaning the \00 is.
    Please refer to the attached trim00.vi.
    Solved!
    Go to Solution.
    Attachments:
    trim00.vi ‏7 KB
    trim00.vi ‏7 KB

    Match Pattern and Match Regular Expression are two different functions. With Match Pattern the string ^[\00]* matches any number of null characters starting at the beginning of the string, while the string [\00]*$ matches any number of null characters starting at the end of the string. Check the help for the Match Pattern function for more info.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Validate String with a pattern

    How can we validate the string with a pattern?
    eg. Value should always be of the format C-DDD,
    where C is a character (A-Z or a-z) and
              D represents a digit(0-9)
    Valid forms are A-001, A-987, Z-098 and
    not valid forms are A-01, 1-A01, 1- 0A0, A-A01, A-0001
    Say internal table contains values like this.
    F1     F2      F3
    1     00001  A-001
    2     00001  A-A01
    3     00001  B-909
    4     00001  Z-01
    5     00001  k-0001
    Valid records are 1 and 3.

    Hi,
    you can use regular expressions for this, e.g.:
      FIND ALL OCCURRENCES OF REGEX '[a-z,A-Z]-[0-9]{3}[ [:blank:] ]'
           IN TABLE t_data
           RESPECTING CASE
           RESULTS t_results.
    Note that in the above example all fields in the table will be checked. If this is not practical for your use you can use a LOOP and FIND on the table field.
    Note that line 5 in your example also matches the pattern you have given. If you really do not want to see this as valid you will have to use the pattern: '[A-Z]-[0-9][ [:blank:] ]'. The addition of [ [:blank:] ] is only needed if your field is longer than the pattern, i.e. 5 characters.
    Good luck,
    Gert.
    Edit: This will also be pretty efficient.
    Edited by: Gert Beukema on Jul 15, 2008 10:36 AM

  • Undo Block Allocation Algorithm in Automatic Undo Management

    Hi,
    Can someone please explain me the Undo Block allocation algorithm in Automatic Undo Management??
    I need to tune my Undo tablespace in my Prod database.
    regards,
    Arul Sekar

    Hi,
    Thanks for the link provided.....
    But the link which has been provided does not contain the details about the Undo block allocation alogorithm in AUM.
    Can you please help me in this regard??
    regards,
    Arul Sekar

  • Fill shape with a pattern

    Hi,
    I am drawing some shapes using java.awt.Shape, java.awt.geom.Area and java.awt.geom.GeneralPath and would like to know whether it's possible to fill these closed shapes with a color - or even better - with a pattern.
    Thanks!

    er, yes, why not?
    http://java.sun.com/docs/books/tutorial/2d/geometry/strokeandfill.html
    -Puce

  • Problem with a pattern

    I have a problem with a pattern.
    I want to put a patter to validate an e-mail but i don´t find the way to do it

    Hi Veloki,
    You can drag and drop custom "email Adress" object from Custom Object Library. It includes the script for email validation in the validate event of email area.
    // Validate the email address.
    var r = new RegExp("^[a-z0-9_\\-\\.]+\\@[a-z0-9_\\-\\.]+\\.[a-z]{2,3}$"); // Create a new Regular Expression Object.
    // Set the regular expression to look for an email address in general form.
    var result = r.test(this.rawValue); // Test the rawValue of the current object to see
    // if it fits the general form of an email address.
    if (result == true) // If it fits the general form,
    true; // all is well.
    else // Otherwise,
    false; // fail the validation.
    Asiye

Maybe you are looking for