Undo/Redo JTextPane for some events

Hi,
I have quite a concern. Right now I'm building an sort of an IDE for my university class. I have the coloring of the words and everything is going fine. However I want to add Undo/Redo operations for the JTextPane. Even though you can create the UndoManager to manage the undo and redo. It catches the coloring of the words that happens every 1 second.
My question is how do I tell the undomanager that I only want to accept text as event for undo and redo and that it doesn't capture coloring as an undoable event.
regards,
Victor Pereira

http://java-sl.com/tip_merge_undo_edits.html
You can merge multiple undoable edits in one and join your text coloring events to real edits. See the link how to merge them.
Regards,
Stas

Similar Messages

  • Undo/Redo Actions for Your Music on Desktop

    Right now you can only use the undo/redo actions for playlists.
    Add the ability to undo/redo actions you make to "Your Music" in the desktop app.
    Menu bar:
    Edit --> Undo
    Edit --> Redo
    Maybe you accidentally removed a song from Your Music and you want to undo it.

    oh cool, this is over six months old and it still hasn't been addressed.

  • How To Provide More Informative Undo Presentation Names for Document Edits

    Hello,
    Hopefully, I can state this clearly enough where people will know what I'm talking about.
    I'm working on an app that makes use of JTextArea to provide display and editing capabilities for text files. I've registered an UndoableEditListener with the Document underlying the JTextArea, so that I can provide undo/redo capability for all the various edits.
    Here's my problem, the edits sent to my listener are of the type AbstractDocument.DefaultDocumentEvent, and so they provide very little information about exactly what sort of event has taken place. IIRC, everything (cut, paste, typing, etc.) shows up as an insert or a removal. I'd like to be able to provide a better presentation name (e.g, "Undo Cut", "Undo Paste", etc.) for my undoable events than is provided by the AbstractDocument.DefaultDocumentEvent , but I'm not sure how exactly to go about this. Do I create my own edits that operate directly on the Document, and avoid the AbstractDocument.DefaultDocumentEvent altogether, or is there some easier way? Anyone have any experience trying to do this? Thanks.
    - sixtyten

    That's exactly the problem: the information we need isn't available, and there's no way to reconstruct it, so let's have the client tell us what we need to know. What I'm proposing is an UndoManager that requires its client to notify it when an action is about to be performed, and again when the action is finished. Upon receiving the first notification, it creates a CompoundEdit with the presentation name that was provided in the notification. After that, any edits that come in via the undoableEditHappened() method get added to the CompoundEdit instead of directly to the undo stack. When it receives the second notification, the UndoManager ends the CompoundEdit and adds it to the undo stack. Here's a very simplistic example: public class SuperUndoManager extends UndoManager
      // basically just a CompoundEdit with a 'name' attribute.
      private NamedCompoundEdit currentEdit;
      public void beginCompoundEdit(String name)
        currentEdit = new NamedCompoundEdit(name);
      public void endCompoundEdit()
        currentEdit.end();
        addEdit(currentEdit);
      public void undoableEditHappened(UndoableEditEvent evt)
        currentEdit.addEdit(evt.getEdit());
    } The biggest problem is getting the clients (i.e., JTextComponents and the Actions defined in their EditorKits) to call these methods without having to do something drastic like replacing them all. I think it can be done (he said with a barely noticeable quaver in his voice).

  • Undo / Redo Feature in Swing

    Hi all,
    Iam working on swing project which uses Undo/Redo feature for drag and drop figure and delete,cut,copy,paste and all the feature which ever want to use, and iam using multiple internal frames so the feature Undo/Redo should be specific to perticular internal frame.
    Is any buddy already done such a kind of thing then pls help me, or if it's possible then pls send the code also.
    Regards
    Laxmikant

    Hi,
    you would have to create an UndoableEditListener for each object, undo/redo shall be perfomed. The listener then is connected to an instance of UndoManager to do the actual handling:  /** Listener for edits on a document. */
      private UndoableEditListener undoHandler = new UndoHandler();
      /** UndoManager that we add edits to. */
      private UndoManager undo = new UndoManager();
      /** inner class for handling undoable edit events */
      public class UndoHandler implements UndoableEditListener {
         * Messaged when the Document has created an edit, the edit is
         * added to <code>undo</code>, an instance of UndoManager.
        public void undoableEditHappened(UndoableEditEvent e) {
          undo.addEdit(e.getEdit());
      } This now can be registered with let's say a Document like thiseditor.getDocument().addUndoableEditListener(undoHandler); (editor is an instance of JEditorPane containing the document).
    Once you have this, you only need actions to perform undo or redo by calling the respective method of your instance of UndoManager undo() and redo().
    Hope that helps
    Ulrich

  • OpenSuse Undo/Redo doesn't work when click on web links

    OpenSuse 12.2 Firefox 17 Undo/Redo doesn’t work when click on link . All web pages have some problem. Undo/Redo working for web page "Find" text box. All web pages

    Clear Cookies & Cache
    * https://support.mozilla.com/en-US/kb/Template:clearCookiesCache
    Clear the Network Cache
    * https://support.mozilla.com/en-US/kb/How%20to%20clear%20the%20cache#w_clear-the-cache
    Troubleshooting extensions and themes
    * https://support.mozilla.com/en-US/kb/Troubleshooting%20extensions%20and%20themes
    Check and tell if its working.

  • Undo/redo bug

    Hi Adobe-ites!
    I recently changed all sorts of syntax and font properties to my installation of Flash Builder 4 in an effort to reduce long-term eye damage .
    Somehow, I inadvertently induced a nasty bug of some sort. I haven't totally wrapped my head around it's behavior, but basically - I lose code undo/redo functionality at some point while working on a given component or class. If I close the window for the component/class and reopen it, I get undo/redo functionality back. However, at some point while typing code, the functionality goes away. Any programmer can imagine how counter-productive this can be . Any one have any ideas what could be causing the issue and how to remedy?
    Many thanks,
    JJ

    Hi,
    Thanks for the adding comments in the issue https://bugs.adobe.com/jira/browse/FB-29897. The problem is faced whenever preferences are changed and there is an active editor opened.
    I have re-ropened the issue.
    -Radhakrishna

  • Duplicate alarms for calendar events on N9

    I noticed I get multiple alarms for calendar events on my N9. For some events, I get four times the same notification. I also sometimes get notifications for deleted events.
    I sync my calendar over bluetooth. Since I had some troubles setting up the sync, I deleted the calendar a few times and synced again. So I have the impression that the alarms of the events of the deleted calendars are still stored in some database. I guess this causes the same alarm to be triggered multiple times and alarms for deleted events to be displayed.
    Is there a way to re-generate the internal alarms database? 
    (I did already upgrade to PR1.1, this didn’t fix it.) 

    I used BT sync with Windows 7 (64 bit), because I was not able to do USB sync (as N9 is not supported by any Nokia PC sync soft). After that I had a real mess: Each event was multiplied to occur multiple times during a day, thoughout each week, throughour each year, e.g. for example meeting scheduled for 10am on October 20, 2011, occurred a number of times on the same day,  and each previous week until 2005 (when my calendar starts).  An event that was scheduled back in 2005 occurred each week throughout 2011.  The same thing happened to my Outlook. So you can imagine a mess that I got with my calendar after syncing with N9. Thanks that I had intact calendar on my Ipad and was able to restore my Outlook.  I had to to manually correct calendar on N9 (because any further attempts to sync with Outlook) resulted in the same mess.  When I say manually I mean that I deleted all entries (takes time) and re-entered only ones that I really needed (such as birthdays, other anniversaries and meetings from October 2011 forward).  After that I did not risk syncing N9 with Outlook anymore in expectation of a decent  sync software from Nokia (which I doubt will come, since even their latest soft Nokia Suite is not supporting N9 (although there some users were able to successfully sync with PC Suite, and some installed previous version of Ovi Suite, upgraded it to Nokia Suite and it works now for them -- but not for my very special N9).  Having fianlly lost confidence in Noikia I decided to become a happy user of iPhone (with all or at least most soft needed being put in place by Apple or 3rd parties).

  • Undo/Redo for Cut, Copy, Paste

    I am trying to implement Undo/Redo for Cut,Copy,Paste in a Treetable.
    I have to support undo/redo for multiple nodes being cut/copied. I am not sure how I should be going about implementing this. Any help will be greatly appreciated.
    Thanks

    If the class you are using doesn't support cut, copy, and paste already, usually what you do is store a list of actions in two lists. One for actions done, the other for redos (when there is an undo). Capture the data before and after each operation (you can create a KeyListener to listen for the events) and store that in a list. When undo is called, the last element on the list should be undone, either by taking it out of the list and reiterating through the elements still there, or implementing an undo method in the object you are trying to change. Then put that element on the redo list in case that is called. This works well with graphics and stuff, but I never tried to implement it in a tree with nodes and stuff, so that's about the most I can help with right now. I hope it helps some!
    -JBoeing

  • I have an external hard drive which has my i-photo on it & some movies from i-movie that I have on disk now. But for some reason my ehd has a caution symbol on it & I can't move my event to free up space on my hd so that I can export i-movie events. Help!

    I have an external hard drive which has my i-photo on it & some movies from i-movie that I have on disk now. But for some reason my ehd has a caution symbol on it & I can't move my event to free up space on my hd so that I can export i-movie events. Help!

    Usually the caution symbol means that it's formatted as a PC compatible format like NTFS or most likely FAT32. For iMovie to use it the ehd must be formatted Mac OS Extended. Then iMovie will show it without the caution symbol and you can drag/drop open any Event/Project from that hard drive.
    To find out if it's formatted as PC:
    Go to the desktop, holding down the Control key click on that ehd and in the pop-menu choose 'Get Info'
    Under Format: It will say whether or not it's Mac OS Extended (Journaled). The only way to undo a PC formatted ehd would be to copy everything off of it first, Erase/Format the drive using Disk Utility in the Applications>Utilities folder on your Mac, choosing the Mac OS Extended (Journaled) format in the pull-down menu there.

  • Keybindings for undo/redo buttons.

    I thought I knew how to do this, and I do seem to have this working fine for cut/copy/paste/select all keybindings CTRL X/C/V/A respectively.
    However I tried to do this for CTRL X and Y undo/redo and it's not working as I intended. Can anyone see what I'm doing wrong?
    I created a SSCCE based off the original example I was following from: [http://www.java2s.com/Code/Java/Swing-JFC/Undoredotextarea.htm]
    import java.awt.BorderLayout;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.KeyStroke;
    import javax.swing.event.UndoableEditEvent;
    import javax.swing.event.UndoableEditListener;
    import javax.swing.undo.CannotRedoException;
    import javax.swing.undo.UndoManager;
    public class UndoRedoTextArea extends JFrame implements KeyListener{
        private static final long serialVersionUID = 1L;
        protected JTextArea textArea = new JTextArea();
        protected UndoManager undoManager = new UndoManager();
        protected JButton undoButton = new JButton("Undo");
        protected JButton redoButton = new JButton("Redo");
        public UndoRedoTextArea() {
            super("Undo/Redo Demo");
            undoButton.setEnabled(false);
            redoButton.setEnabled(false);
            JPanel buttonPanel = new JPanel(new GridLayout());
            buttonPanel.add(undoButton);
            buttonPanel.add(redoButton);
            JScrollPane scroller = new JScrollPane(textArea);
            getContentPane().add(buttonPanel, BorderLayout.NORTH);
            getContentPane().add(scroller, BorderLayout.CENTER);
            textArea.getDocument().addUndoableEditListener(
                new UndoableEditListener() {
                    public void undoableEditHappened(UndoableEditEvent e) {
                        undoManager.addEdit(e.getEdit());
                        updateButtons();
            undoButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    try {
                        undoManager.undo();
                    } catch (CannotRedoException cre) {
                        cre.printStackTrace();
                    updateButtons();
            undoButton.addKeyListener(this);
            redoButton.addKeyListener(this);
            redoButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    try {
                        undoManager.redo();
                    } catch (CannotRedoException cre)  {
                        cre.printStackTrace();
                    updateButtons();
            setSize(400, 300);
            setVisible(true);
        public void updateButtons() {
            undoButton.setText(undoManager.getUndoPresentationName());
            redoButton.setText(undoManager.getRedoPresentationName());
            undoButton.setEnabled(undoManager.canUndo());
            redoButton.setEnabled(undoManager.canRedo());
        public static void main(String argv[]) {
            new UndoRedoTextArea();
        public void keyPressed(KeyEvent e){
            if (e.equals(KeyStroke.getKeyStroke
                (KeyEvent.VK_Z, InputEvent.CTRL_DOWN_MASK))){
                // undo
                try {
                    undoManager.undo();
                } catch (CannotRedoException cre)  {
                    cre.printStackTrace();
                updateButtons();
            else if (e.equals(KeyStroke.getKeyStroke
                    (KeyEvent.VK_Y, InputEvent.CTRL_DOWN_MASK))){
                // redo
                try  {
                    undoManager.redo();
                } catch (CannotRedoException cre) {
                    cre.printStackTrace();
                updateButtons();
        public void keyTyped(KeyEvent e){}
        public void keyReleased(KeyEvent e){}
    }Edited by: G-Unit on Oct 24, 2010 5:30 AM

    camickr wrote:
    So the way I posted in the second lump of code OK (3rd post) or did you mean something different? Why did you set the key bindings? Did I not state they would be created automatically? I think you need to reread my suggestion (and the tutorial).Because I don't get it, it says only Menu items can contain accelerators and buttons only get mnemonics. I'm not using menu items here, I only have a text pane and 2 buttons. So I set the actions for the InputMap in TextPane. For the buttons, I pretty much used the small bit of code using undoManager.
    I tried to set KEYSTROKE constructor for the action and simply add them to the buttons that way, but this didn't seem to have any response.
    Also I don't get how this could happen anyway if the TextPane has the focus.
    Not like the example using MNEMONICS.
        Action leftAction = new LeftAction(); //LeftAction code is shown later
        button = new JButton(leftAction)
        menuItem = new JMenuItem(leftAction);
    To create an Action object, you generally create a subclass of AbstractAction and then instantiate it. In your subclass, you must implement the actionPerformed method to react appropriately when the action event occurs. Here's an example of creating and instantiating an AbstractAction subclass:
        leftAction = new LeftAction("Go left", anIcon,
                     "This is the left button.",
                     new Integer(KeyEvent.VK_L));
        class LeftAction extends AbstractAction {
            public LeftAction(String text, ImageIcon icon,
                              String desc, Integer mnemonic) {
                super(text, icon);
                putValue(SHORT_DESCRIPTION, desc);
                putValue(MNEMONIC_KEY, mnemonic);
            public void actionPerformed(ActionEvent e) {
                displayResult("Action for first button/menu item", e);
        }This is what I attempted. No errors... It just doesn't work.
    public JPanel p()
        undoButton.addActionListener(new UndoAction(KeyStroke.getKeyStroke(KeyEvent.VK_Z, Event.CTRL_MASK)));
        panel.add(undoButton);
        return panel;
    private class UndoAction extends AbstractAction
         public UndoAction(KeyStroke keyStroke)
              putValue(ACCELERATOR_KEY, keyStroke);
         private static final long serialVersionUID = 1L;
         public void actionPerformed(ActionEvent e)
              try
                   if (undoManager.canUndo())
                        undoManager.undo();
              catch (CannotRedoException cre)
                   cre.printStackTrace();
              updateButtons();
    }Edited by: G-Unit on Oct 25, 2010 8:32 AM

  • Hoping for some help with a very frustrating issue!   I have been syncing my iPhone 5s and Outlook 2007 calendar and contacts with iCloud on my PC running Vista. All was well until the events I entered on the phone were showing up in Outlook, but not

    Hoping for some help with a very frustrating issue!
    I have been syncing calendar and contacts on my iPhone 5 and Outlook 2007 using iCloud  2.1.3 (my PC is running Vista). All was well until the events I entered on the phone were showing up in Outlook, but not the other way around. I’ve tried the usual recommended steps: deselecting calendar and contacts in the iCloud control panel and then re-selecting, signing out of the panel and back in, and repairing the Outlook installation in control panel.  I even uninstalled iCloud on the PC and downloaded it again (same version). 
    The furthest I’ve gotten is step 2 (and once, step 3) of 7 while performing “Outlook Setup For iCloud.” At that point I get, “Your setup couldn’t be started because of an unexpected error.”  After the first attempt at all this, all my calendar events disappeared from Outlook, although they are still in iCloud calendar and on my phone.
    Sound familiar?  Any ideas on how to solve this iCloud/Outlook issue?  Thanks much in advance!

    Hoping for some help with a very frustrating issue!
    I have been syncing calendar and contacts on my iPhone 5 and Outlook 2007 using iCloud  2.1.3 (my PC is running Vista). All was well until the events I entered on the phone were showing up in Outlook, but not the other way around. I’ve tried the usual recommended steps: deselecting calendar and contacts in the iCloud control panel and then re-selecting, signing out of the panel and back in, and repairing the Outlook installation in control panel.  I even uninstalled iCloud on the PC and downloaded it again (same version). 
    The furthest I’ve gotten is step 2 (and once, step 3) of 7 while performing “Outlook Setup For iCloud.” At that point I get, “Your setup couldn’t be started because of an unexpected error.”  After the first attempt at all this, all my calendar events disappeared from Outlook, although they are still in iCloud calendar and on my phone.
    Sound familiar?  Any ideas on how to solve this iCloud/Outlook issue?  Thanks much in advance!

  • ALV_grid oo: event "data_changed" on F4 in the line only for some fields

    Hi all,
    when I add a new line in ALV_Grid and I select the search help, for some fields
    the event "data_changed" has triggered even I have not finished to fill the entire fields on the line, and I don't need this.
    Opposite I have some fields which work fine and when I choose F4 the list of the
    possible values has showed without triggering "data_changed".
    Does anyboby know how is it possible?
    Since I'm new on ALV_grid oo, could you give a detailed answer?
    I thank You in advance.
                                                              Best Regards
                                                              Paolo

    I solved the problem int this way: 
    METHODS:
          handle_data_changed
              FOR EVENT data_changed
               OF cl_gui_alv_grid
              IMPORTING er_data_changed
              <u><i>e_onf4</i></u> e_onf4_before e_onf4_after.
      METHOD handle_data_changed.
    DATA: ls_good      TYPE lvc_s_modi.
    error_in_data = space.
    IF e_onf4 IS INITIAL.
      CALL METHOD check_righe_doppie  ( er_data_changed ).
      CALL METHOD update_delta_tables ( er_data_changed ).
      CALL METHOD semantic_checks     ( er_data_changed ).
    ENDIF.
      ENDMETHOD.                                  "handle_data_changed
    Message was edited by:
            Paolo Cavallini

  • LMS4.1 how to suppress operationallydown events for some interfaces

    Hi,
    Installed Cisco Prime LMS last week. Everthing seems to be running fine. We configured LMS to send e-mail for certain events. One of them is operationallydown/up events. There are some devices for which we only want to see those events for some of the interfaces. For example: there is a device with several ISDN interfaces. Those are used by business partners to dial-in. We expect those interfaces to go up and down several times per day. We don't want any events/e-mails for that. I can't seem to figure out how to configure that. If anyone can help me with that, it would be greatly appreciated.
    We come from LMS2.6, but didn't do an upgrade. It's a big leap, everything works different now.
    Regards,
    Arjan Hummel

    Operation down events a usually due to admin up, line protocol down interfaces. The only way to fix that is to put the interface admin down
    When you talk about BRI or PRI channels its a different story
    Look at NMSROOT/objects/smarts/conf/discovery/tpmgr-param.conf.
    Add a line like this, but with the sysobjectid of your device.
    IFDescrPattern-.1.3.6.1.4.1.9.1.1045 ~*Bearer*
    Something like this should work, but you need to rediscover the device.
    Cheers,
    Michel

  • I have an older phone, the Iphone 4.  For some reason, all of my calendar events are gone.  I can't see old, present or future events.  Help me please.  I need this information.

    I have an older phone, the Iphone 4.  For some reason, all of my calendar events are gone.  I can't see old, present or future events.  Help me please.  I need this information.

    Please please help me, if you know how.

  • HT2265 for some reason the only photos that do the random scrolling are events, can I include the albums from iphoto to scroll as well.   the know the albums have synced because i can view them in slideshow

    for some reason the only photos that do the random scrolling are photos in the events section of iphoto. is it possible to include the albums from iphoto to scroll as well.   the know the albums have synced because i can view them in slideshow  pls help

    Welcome to the Apple Community.
    I assume you are referring to the screensaver. You can change the photos used by the screensaver in the screensaver settings. Note if you have a large number of photos in the collection you choose for screensaver, not all of them will be used due to the limited storage available to the Apple TV.

Maybe you are looking for

  • How to get 'TextBlock' related to a paragraph element

    Hi I want to get the 'TextBlock'  related to the 'ParagraphElement' how i can get it, Some on has posted that var textBlock:TextBlock = paragraph.textBlock; but it's not make any sense ; also 'ParagraphElement' does't have 'textBlock' property. Thank

  • Total in Pivot Table

    Hi, I have built a pivot table where due to the large number of resort, I created an extra column and put the following formula CASE WHEN RCOUNT(1)<16 THEN '1-15' WHEN RCOUNT(1) <31 THEN '16-30' WHEN RCOUNT(1)<46 THEN '31-45' WHEN RCOUNT(1)<61 THEN '

  • Error problem

    Sir,         I have downloaded Adobe Photoshop.But there is a problem (error problem) and a message is being displayed........   Error extracting the product installer (error101). check for available disk space on your system and try downloading the

  • Sales order not editable after approval procedure

    Dear SAP, for a customer we need to find out a way to edit sales orders after approval. Example: User fills a sales order with more than 100 positions and had a typing error which is realized later. Next example: Customer wants the delivery condition

  • Js lightbox w/ flash = wmode = opaque = problems!

    I am currently building a flash site and want to incorporate a js lightbox to display artwork overtop the pages.  From what I have read, the only way to allow content over flash is to set wmode = opaque or transparent.  And that creates nothing but p