StyledDocument Undo problem

I use StyledDocument in my program (text editor) and I have following exception:
javax.swing.text.StateInvariantError: GlyphView: Stale view: javax.swing.text.BadLocationException: Length must be positive
at javax.swing.text.GlyphView.getText(GlyphView.java:106)
at javax.swing.text.GlyphPainter1.getSpan(GlyphPainter1.java:43)
at javax.swing.text.GlyphView.getPreferredSpan(GlyphView.java:498)
at javax.swing.text.FlowView$LogicalView.getPreferredSpan(FlowView.java:679)
at javax.swing.text.FlowView.calculateMinorAxisRequirements(FlowView.java:214)
at javax.swing.text.BoxView.checkRequests(BoxView.java:913)
at javax.swing.text.BoxView.getMinimumSpan(BoxView.java:542)
at javax.swing.text.BoxView.calculateMinorAxisRequirements(BoxView.java:881)
at javax.swing.text.BoxView.checkRequests(BoxView.java:913)
at javax.swing.text.BoxView.setSpanOnAxis(BoxView.java:325)
at javax.swing.text.BoxView.layout(BoxView.java:682)
at javax.swing.text.BoxView.setSize(BoxView.java:379)
at javax.swing.plaf.basic.BasicTextUI$RootView.setSize(BasicTextUI.java:1599)
at javax.swing.plaf.basic.BasicTextUI.modelToView(BasicTextUI.java:935)
at javax.swing.plaf.basic.BasicTextUI.modelToView(BasicTextUI.java:911)
at javax.swing.text.JTextComponent.modelToView(JTextComponent.java:1118)
at Editor.Editor.caretUpdate(Editor.java:1204)
at Editor.Editor.caretUpdate(Editor.java:686)
at javax.swing.text.JTextComponent.fireCaretUpdate(JTextComponent.java:356)
at javax.swing.text.JTextComponent$MutableCaretEvent.fire(JTextComponent.java:3165)
at javax.swing.text.JTextComponent$MutableCaretEvent.stateChanged(JTextComponent.java:3187)
at javax.swing.text.DefaultCaret.fireStateChanged(DefaultCaret.java:638)
at javax.swing.text.DefaultCaret.changeCaretPosition(DefaultCaret.java:1010)
at javax.swing.text.DefaultCaret.handleSetDot(DefaultCaret.java:918)
at javax.swing.text.DefaultCaret.setDot(DefaultCaret.java:899)
at javax.swing.text.DefaultCaret$UpdateHandler.insertUpdate(DefaultCaret.java:1453)
at javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:184)
at Editor.OverwritableSyntaxDocument.fireInsertUpdate(OverwritableSyntaxDocument.java:52)
at javax.swing.text.AbstractDocument$DefaultDocumentEvent.undo(AbstractDocument.java:2797)
at javax.swing.undo.UndoManager.undoTo(UndoManager.java:210)
at javax.swing.undo.UndoManager.undo(UndoManager.java:275)
at Editor.Editor.actionPerformed(Editor.java:333)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:232)
at java.awt.Component.processMouseEvent(Component.java:5100)
at java.awt.Component.processEvent(Component.java:4897)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
That exception occurs only if I try to undo some editons in first line of StyledDocument
In other lines it works without any problems.
I use following implementation:
     public void undoableEditHappened(UndoableEditEvent e)
          UndoableEdit edit=e.getEdit();
          if(compoundEdit==null)
               compoundEdit=new CompoundEdit();
          if(edit instanceof AbstractDocument.DefaultDocumentEvent &&
               ((AbstractDocument.DefaultDocumentEvent)edit).getType()== AbstractDocument.DefaultDocumentEvent.EventType.CHANGE)
               compoundEdit.addEdit(edit);
          else
               compoundEdit.addEdit(edit);
               compoundEdit.end();
               undoManager.addEdit(edit);
               compoundEdit=null;
               //update undo/redo buttons
               buttonsUpdate();
     }I don't have ideas to solve this problem. Help me, please...

I don't have ideas to solve this problem. Help me, please...Based on the random code you posted, neither do I.
My my last posting in this thread will work for you:
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=637225

Similar Messages

  • Text Layout Framework columncount Undo problem

    Text Layout Framework columncount Undo problem ::
        The number of times columncount is changed it gets applied to textflow
    and those number of operation is stored in undoStack(UndoManger).But when i
    undo it, it comes back to intial state, without undoin step by step.
    I have given my source code..
    Y so or any other alternative to achieve this..
    Thanx in advance..  
    <?xml version="1.0" encoding="utf-8"?>
    <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark"
    xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="init()">
        <fx:Script>
            <![CDATA[
                import flashx.textLayout.container.ContainerController;
                import flashx.textLayout.conversion.ITextImporter;
                import flashx.textLayout.conversion.TextConverter;
                import flashx.textLayout.edit.EditManager;
                import flashx.textLayout.edit.IEditManager;
                import flashx.textLayout.edit.ISelectionManager;
                import flashx.textLayout.edit.SelectionState;
                import flashx.textLayout.elements.InlineGraphicElement;
                import flashx.textLayout.elements.ParagraphElement;
                import flashx.textLayout.elements.TextFlow;
                import flashx.textLayout.events.SelectionEvent;
                import flashx.textLayout.events.StatusChangeEvent;
                import flashx.textLayout.formats.Direction;
                import flashx.textLayout.formats.TextLayoutFormat;
                import flashx.undo.UndoManager;
                import mx.collections.ArrayCollection;
                import mx.controls.Alert;
                import mx.controls.CheckBox;
                import mx.events.FlexEvent;
                import mx.events.SliderEvent;
                import spark.components.Group;
                import spark.components.TextArea;
                import spark.core.SpriteVisualElement;
                public var directions:ArrayCollection = new
    ArrayCollection(
                        {label:"Left-to-Right",
    data:Direction.LTR},
                        {label:"Right-to-Left",
    data:Direction.RTL}
                private var _textContainer:SpriteVisualElement = null;
                private static const textInput:XML = <TextFlow
    xmlns="http://ns.adobe.com/textLayout/2008">
                    <div>
                        <p><span>The Text Layout Framework is
    an extensible library, built on the new text engine in Adobe Flash Player 10,
    which delivers advanced, easy-to-integrate typographic and text layout features
    for rich, sophisticated and innovative typography on the web.
                    Some benefits provided by this framework
    include: 1) rich typographical controls, including kerning, ligatures,
    typographic case, digit case, digit width and discretionary hyphens
                    2) cut, copy, paste, undo and standard keyboard
    and mouse gestures for editing 3) selection, editing and flowing text across
    multiple columns and linked containers
                    4) bidirectional text, vertical text and over
    30 writing scripts including Arabic, Hebrew, Chinese, Japanese, Korean, Thai,
    Lao, Vietnamese, and others
                    5) vertical text, Tate-Chu-Yoko (horizontal
    within vertical text) and justifier for East Asian typography. Try editing this
    text and playing with the options below! Notice an inline image is also
    included.</span></p>
                    </div>
                    </TextFlow>;
                private var _textFlow:TextFlow;
                private function init():void {
                    _textContainer = new SpriteVisualElement();
                    canvas.addElement(_textContainer);
                    var importer:ITextImporter =
    TextConverter.getImporter(TextConverter.TEXT_LAYOUT_FORMAT);
                    _textFlow = importer.importToFlow(textInput);
                    _textFlow.flowComposer.addController(new
    ContainerController(_textContainer, canvas.width-40, canvas.height));
                    _textFlow.interactionManager = new
    EditManager(new UndoManager());
                    _textFlow.flowComposer.updateAllControllers();
                private function changeNoColumns(event:Event):void {
                    var tlf:TextLayoutFormat = new
    TextLayoutFormat();
                    tlf.columnCount = cols.value;
                    tlf.columnGap = 15;
                    tlf.direction = direction.selectedItem.data;
                    var em:EditManager =
    _textFlow.interactionManager as EditManager;
                    em.selectAll();
                    (_textFlow.interactionManager as
    EditManager).applyFormat(tlf,tlf,tlf);
                    _textFlow.flowComposer.updateAllControllers();
                protected function
    undo_clickHandler(event:MouseEvent):void
                    var em:EditManager =
    _textFlow.interactionManager as EditManager;
                    trace("Can undo " + em.undoManager.canUndo() +
    " can redo " + em.undoManager.canRedo());
                    em.undo();
                protected function
    redo_clickHandler(event:MouseEvent):void
                    var em:EditManager =
    _textFlow.interactionManager as EditManager;
                    trace("Can undo " + em.undoManager.canUndo() +
    " can redo " + em.undoManager.canRedo());
                    em.redo();
            ]]>
        </fx:Script>
        <s:Panel title="Text Layout Framework Sample" width="100%"
    height="100%">
            <s:layout>
                <s:VerticalLayout paddingTop="8" paddingLeft="8"/>
            </s:layout>
            <s:VGroup>
                <s:Group id="canvas" width="600" height="200" />
                <s:HGroup width="100%" verticalAlign="middle">
                    <s:Label text="# Columns:"/>
                    <s:NumericStepper id="cols"  minimum="1"
    maximum="20" snapInterval="1" change="changeNoColumns(event)" />
                    <s:Label text="Text Direction:"/>
                    <s:DropDownList id="direction"
    change="changeTextDirection(event)" dataProvider="{directions}"
    selectedItem="{directions[0]}"/>
                    <s:Button label="Undo"
    click="undo_clickHandler(event)"/>
                    <s:Button label="Redo"
    click="redo_clickHandler(event)"/>
                </s:HGroup>
            </s:VGroup>
        </s:Panel>
    </s:WindowedApplication>

    It cannot be reproduced with TLF 3.0 + SDK 4.5.

  • Strange Undo problem

    Hi, I'm using LR 2.2 and recently I've found that when I attempt to "Undo" something (Undo creative preset, Undo adjustment brush, Undo Grad filter) in Develop I get kicked out of the photo I'm working on, kicked out of the photo download group I'm working in and out into, the last time anyway, the first photo of the last group of photos I D/Led.
    Has anyone else seen this? My LR is pretty standard with the exception of having added the TTG XML Auto Index 1.51 engine to the Web module. Any suggestions?

    Same here, got the same problem. Still don't know what caused it. Sometimes undo works as it should, sometimes it just throws me out of developer module into library grid mode. Strange..

  • Still not fixed in CS6: Undo problem after Text Type + Move

    I have noticed this very annoying Photoshop problem still has not been addressed by Adobe.
    Breakdown:
    Type text
    Move text
    If you undo the move, it will not only undo the move - but the text you typed as well
    So technically it does 2 undos instead of just 1. Does this not irritate anybody else? It's so annoying.

    Type text
    Move text
    If you undo the move, it will not only undo the move - but the text you typed as well
    Between "Type Text" and "Move Text" are you clicking the Check Mark to commit text (or hitting Enter on numeric pad), then selecting the Move Tool to move the text?

  • Undo problem in DefaultStyledDocument!

    Just run this code, and you won't be able to type in the editor pane! What's the problem? Indeed the problem arose from the setCharacterAttributes(), and rejection of change events in the overriden implementation of undoableEditHappened from UndoManager. How can this be fixed? Please don't say I'm supposed to save all these change events and undo them as well.
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.event.*;
    import javax.swing.undo.UndoManager;
    public class pad {
        public static void main(String[] arguments) throws BadLocationException {
          JFrame pad = new JFrame();
          pad.setBounds(50, 50, 400, 300);
          pad.setVisible(true);
          JEditorPane editor = new JEditorPane();
          pad.getContentPane().add(editor);
          editor.setEditorKit(new StyledEditorKit());
          DefaultStyledDocument document = (DefaultStyledDocument) editor.getDocument();
          UndoManager undoManager = new UndoManager() {
           public void undoableEditHappened(UndoableEditEvent e) {
               // The problem arose from the rejection of change event here!
               if (((DocumentEvent) e.getEdit()).getType() == DocumentEvent.EventType.CHANGE)
                return;
               super.undoableEditHappened(e);
          document.addUndoableEditListener(undoManager);
          editor.replaceSelection("n\n");
          document.setCharacterAttributes(0, 1, SimpleAttributeSet.EMPTY, false);
          undoManager.undo();
    }

    Of course if you replace "n\n" with "1" or any string not ending with '\n', it works fine! The "n\n" is a typical input which causes the malfunctioning of the UndoManager, and which the user may type! All I do is highlighting the input. Then the user tries to undo the last typed entries 'n', & '\n'! I've rejected the highlighting change events so that I can undo the user's input at each undo.
    That's it! I didn't do anything wrong except not considering the change events!
    Anyway, thanks for your attention camickr!
    Regards,
    --Rasta                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Undo problem - erases more than last step!

    Hi,
    I've already been going through issues with my own computer (apparently due to an update in Windows my touchpad went haywire, and now using my tablet and mouse does it as well, where clicking and holding that click makes things drag), but somehow Photoshop Elements 7 is being buggy too.
    I only noticed it tonight. I will be drawing, and if I draw one line, pull the pen away, draw another connected line and press CTRL+Z or the undo arrow, it erases both lines and not just the previous one like usual. Sometimes CTRL+Z doesn't even work, and I've tested my keys to be responsive. I'm not sure if it is a problem with my computer or actually Photoshop Elem 7. Is there any knowledge of this issue?
    Thanks in advance.

    Click on the word Window and check undo history.
    You should then be able to go back one step at a time or at least see how elements is recording each pen step.

  • Styleddocument + filling problem

    hello everybody
    i've been trying to recreate the matrix code effect, like how the green characters move downwards on the screen
    some details about my code:
    - JFrame based form
    - using a JTextPane for displaying
    - StyledDocument
    but i'm kinda stuck at the moment when i want to make sure the effect can be shown:
    i would have to fill the whole JTextPane (from side to side and from top to bottom) with invisible characters (currently i'm using the char "e")
    but the problem is => i do not know how much characters can be placed next to each other so that the whole line is filled and that it does not continue on the next line
    example:
    |eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\n|     <= good!   (nevermind the linebreak, it's just to show that the line ends exactly after the last "e")
    |eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee|        <= bad!     as you can see the line does not end here due to too much characters on a line
    |eeeeeeeeeeee\n                 |
    ---------------------------------can anybody help me with this?
    thanks in advance!!
    - NeoSniperkiller

    Well, I don't know what the "matrix effect" is or whether a JTextPane is the best component for doing this. But assuming it is then you would need to use the FontMetrics of the component. You would also want to use a Monospaced font so that each character uses the same amount of space.

  • Syntax Highlighting and Undo Problem

    Hello Guys. I am working ona very simple type of Java Code Editor with syntax highlighting feature. It works fine as far as the syntax highlighting, cut, copy, paste etc are concerned but when I added Undo, Redo feature, it was not working as Undo Redo should. The UndoManager first removes the text attributes and finally the main Undo job. For example if I paste word public , the UndoManager will first remove the attributes and after about third or fouth click on the Undo button removes the pasted word.
    Please Help.

    Here's the complete demo code.
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.event.*;
    import javax.swing.text.rtf.*;
    import javax.swing.undo.*;
    class ColorTextInTextPane extends JFrame implements UndoableEditListener
         private Hashtable keywords,impclasses;
         JEditorPane edit;
         UndoManager undo;
         JButton undoIt, redoIt;
         JPanel southButtonPanel;
         MyDocument doc = new MyDocument();
         public ColorTextInTextPane()
              super("ColorTextInTextPane");
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              edit = new JEditorPane();
              edit.setEditorKit(new StyledEditorKit());
              edit.setEditable(true);
              doc.addUndoableEditListener(this);
              edit.setDocument(doc);
              JScrollPane scroll=new JScrollPane(edit);
              undo = new UndoManager();
              undoIt = new JButton("Undo");
              undoIt.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent ae)
                    undoAction(ae);
              redoIt = new JButton("Redo");
              redoIt.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent ae)
                    redoAction(ae);
              southButtonPanel = new JPanel();
              southButtonPanel.add(undoIt);
              southButtonPanel.add(redoIt);
              getContentPane().add(scroll);
              getContentPane().add(southButtonPanel, BorderLayout.SOUTH);
              setSize(300,300);
              setVisible(true);
              Object dummyObject = new Object();
              keywords = new Hashtable();
              keywords.put( "abstract", dummyObject );
              keywords.put( "boolean", dummyObject );
              keywords.put( "break", dummyObject );
              keywords.put( "byte", dummyObject );
              keywords.put( "byvalue", dummyObject );
              keywords.put( "case", dummyObject );
              keywords.put( "cast", dummyObject );
              keywords.put( "catch", dummyObject );
              keywords.put( "char", dummyObject );
              keywords.put( "class", dummyObject );
              keywords.put( "const", dummyObject );
              keywords.put( "continue", dummyObject );
              keywords.put( "default", dummyObject );
              keywords.put( "do", dummyObject );
              keywords.put( "double", dummyObject );
              keywords.put( "else", dummyObject );
              keywords.put( "extends", dummyObject );
              keywords.put( "false", dummyObject );
              keywords.put( "final", dummyObject );
              keywords.put( "finally", dummyObject );
              keywords.put( "float", dummyObject );
              keywords.put( "for", dummyObject );
              keywords.put( "future", dummyObject );
              keywords.put( "generic", dummyObject );
              keywords.put( "goto", dummyObject );
              keywords.put( "if", dummyObject );
              keywords.put( "implements", dummyObject );
              keywords.put( "import", dummyObject );
              keywords.put( "inner", dummyObject );
              keywords.put( "instanceof", dummyObject );
              keywords.put( "int", dummyObject );
              keywords.put( "interface", dummyObject );
              keywords.put( "long", dummyObject );
              keywords.put( "native", dummyObject );
              keywords.put( "new", dummyObject );
              keywords.put( "null", dummyObject );
              keywords.put( "operator", dummyObject );
              keywords.put( "outer", dummyObject );
              keywords.put( "package", dummyObject );
              keywords.put( "private", dummyObject );
              keywords.put( "protected", dummyObject );
              keywords.put( "public", dummyObject );
              keywords.put( "rest", dummyObject );
              keywords.put( "return", dummyObject );
              keywords.put( "short", dummyObject );
              keywords.put( "static", dummyObject );
              keywords.put( "super", dummyObject );
              keywords.put( "switch", dummyObject );
              keywords.put( "synchronized", dummyObject );
              keywords.put( "this", dummyObject );
              keywords.put( "throw", dummyObject );
              keywords.put( "throws", dummyObject );
              keywords.put( "transient", dummyObject );
              keywords.put( "true", dummyObject );
              keywords.put( "try", dummyObject );
              keywords.put( "var", dummyObject );
              keywords.put( "void", dummyObject );
              keywords.put( "volatile", dummyObject );
              keywords.put( "while", dummyObject );
              Object dummyObject1 = new Object();
              impclasses = new Hashtable();
              impclasses.put( "JFrame", dummyObject1);
              impclasses.put( "Applet", dummyObject1);
                    impclasses.put( "JApplet", dummyObject1);
                    impclasses.put( "JTextField", dummyObject1);
                    impclasses.put( "JLabel", dummyObject1);
                    impclasses.put( "JPanel", dummyObject1);
                    impclasses.put( "JButton", dummyObject1);
         public void undoableEditHappened(UndoableEditEvent ev) {
        undo.addEdit(ev.getEdit());
        updateMenu();
      void undoAction(ActionEvent e) {
        try {
          if (undo.canUndo())
            undo.undo();
          updateMenu();
        catch (CannotRedoException cre) {
      void redoAction(ActionEvent e)
        try {
          if (undo.canRedo())
            undo.redo();
          updateMenu();
        catch (CannotRedoException cre) {
      public void updateMenu()
        undoIt.setEnabled(undo.canUndo());
        redoIt.setEnabled(undo.canRedo());
         public static void main(String a[])
              new ColorTextInTextPane();
         class MyDocument extends DefaultStyledDocument
              DefaultStyledDocument doc;
              MutableAttributeSet normal;
              MutableAttributeSet keyword;
              MutableAttributeSet comment;
              MutableAttributeSet quote;
              MutableAttributeSet impclasses1;
              public MyDocument()
                   doc = this;
                   putProperty( DefaultEditorKit.EndOfLineStringProperty, "\n" );
                   normal = new SimpleAttributeSet();
                   StyleConstants.setForeground(normal, Color.black);
                   comment = new SimpleAttributeSet();
                   StyleConstants.setForeground(comment, Color.green);
                   StyleConstants.setItalic(comment, true);
                   keyword = new SimpleAttributeSet();
                   StyleConstants.setForeground(keyword, Color.blue);
                   StyleConstants.setBold(keyword, true);
                   quote = new SimpleAttributeSet();
                   StyleConstants.setForeground(quote, Color.red);
                   StyleConstants.setBold(quote, true);
                   impclasses1 = new SimpleAttributeSet();
                   StyleConstants.setForeground(impclasses1, Color.magenta);
                   StyleConstants.setBold(impclasses1, true);
              public void insertString(int offset, String str, AttributeSet a) throws BadLocationException
                   super.insertString(offset, str, a);
                   processChangedLines(offset, str.length());
              public void remove(int offset, int length) throws BadLocationException
                   super.remove(offset, length);
                   processChangedLines(offset, 0);
              public void processChangedLines(int offset, int length) throws BadLocationException
                   String content = doc.getText(0, doc.getLength());
                   Element root = doc.getDefaultRootElement();
                   int startLine = root.getElementIndex( offset );
                   int endLine = root.getElementIndex( offset + length );
                   for (int i = startLine; i <= endLine; i++)
                        int startOffset = root.getElement( i ).getStartOffset();
                        int endOffset = root.getElement( i ).getEndOffset();
                        applyHighlighting(content, startOffset, endOffset - 1);
              public void applyHighlighting(String content, int startOffset, int endOffset)
                   throws BadLocationException
                   int index;
                   int lineLength = endOffset - startOffset;
                   int contentLength = content.length();
                   if (endOffset >= contentLength)
                        endOffset = contentLength - 1;
                   //  set normal attributes for the line
                   doc.setCharacterAttributes(startOffset, lineLength, normal, true);
                   //  check for multi line comment
                   String multiLineStartDelimiter = "/*";
                   String multiLineEndDelimiter = "*/";
                   index = content.lastIndexOf( multiLineStartDelimiter, endOffset );
                   if (index > -1)
                        int index2 = content.indexOf( multiLineEndDelimiter, index );
                        if ( (index2 == -1) || (index2 > endOffset) )
                             doc.setCharacterAttributes(index, endOffset - index + 1, comment, false);
                             return;
                        else
                        if (index2 >= startOffset)
                             doc.setCharacterAttributes(index, index2 + 2 - index, comment, false);
                             return;
                   //  check for single line comment
                   String singleLineDelimiter = "//";
                   index = content.indexOf( singleLineDelimiter, startOffset );
                   if ( (index > -1) && (index < endOffset) )
                        doc.setCharacterAttributes(index, endOffset - index + 1, comment, false);
                        endOffset = index - 1;
                   //  check for tokens
                   checkForTokens(content, startOffset, endOffset);
              private void checkForTokens(String content, int startOffset, int endOffset)
                   while (startOffset <= endOffset)
                        //  find the start of a new token
                        while ( isDelimiter( content.substring(startOffset, startOffset + 1) ) )
                             if (startOffset < endOffset)
                                  startOffset++;
                             else
                                  return;
                        if ( isQuoteDelimiter( content.substring(startOffset, startOffset + 1) ) )
                             startOffset = getQuoteToken(content, startOffset, endOffset);
                        else
                             startOffset = getOtherToken(content, startOffset, endOffset);
              private boolean isDelimiter(String character)
                   String operands = ";:{}()[]+-/%<=>!&|^~*";
                 if (Character.isWhitespace( character.charAt(0) ) ||
                      operands.indexOf(character) != -1 )
                      return true;
                 else
                      return false;
              private boolean isQuoteDelimiter(String character)
                   String quoteDelimiters = "\"'";
                   if (quoteDelimiters.indexOf(character) == -1)
                      return false;
                 else
                      return true;
              private boolean isKeyword(String token)
                   Object o = keywords.get( token );
                   return o == null ? false : true;
              private boolean isimpclasses1(String token)
                   Object o = impclasses.get( token );
                   return o == null ? false : true;
              private int getQuoteToken(String content, int startOffset, int endOffset)
                   String quoteDelimiter = content.substring(startOffset, startOffset + 1);
                   String escapedDelimiter = "\\" + quoteDelimiter;
                   int index;
                   int endOfQuote = startOffset;
                   //  skip over the escaped quotes in this quote
                   index = content.indexOf(escapedDelimiter, endOfQuote + 1);
                   while ( (index > -1) && (index < endOffset) )
                        endOfQuote = index + 1;
                        index = content.indexOf(escapedDelimiter, endOfQuote);
                   // now find the matching delimiter
                   index = content.indexOf(quoteDelimiter, endOfQuote + 1);
                   if ( (index == -1) || (index > endOffset) )
                        endOfQuote = endOffset;
                   else
                        endOfQuote = index;
                   doc.setCharacterAttributes(startOffset, endOfQuote - startOffset + 1, quote, false);
                            //String token = content.substring(startOffset, endOfQuote + 1);
                            //System.out.println( "quote: " + token );
                   return endOfQuote + 1;
              private int getOtherToken(String content, int startOffset, int endOffset)
                 int endOfToken = startOffset + 1;
                   while ( endOfToken <= endOffset )
                        if ( isDelimiter( content.substring(endOfToken, endOfToken + 1) ) )
                             break;
                        endOfToken++;
                   String token = content.substring(startOffset, endOfToken);
                            //System.out.println( "found: " + token );
                   if ( isKeyword( token ) )
                        doc.setCharacterAttributes(startOffset, endOfToken - startOffset, keyword, false);
                   if(isimpclasses1 ( token) )
                        doc.setCharacterAttributes(startOffset, endOfToken - startOffset, impclasses1, false);
                   return endOfToken + 1;
    }

  • Undo problem in a java made notepad

    i have been working on notepad.i want to provide it features like that provided in MS-DOS TURBO C++.i.e. all the steps can be reversed.
    can anybody tell me how to solve this problem in easiest way.I HAVE TWO SOLUTIONS BUT THEY DON'T SATISFY MY MIND.THEY ARE CUMBERSOME

    i have been working on notepad.i want to provide it
    features like that provided in MS-DOS TURBO C++.i.e.
    all the steps can be reversed.
    can anybody tell me how to solve this problem in
    easiest way.I HAVE TWO SOLUTIONS BUT THEY DON'T
    SATISFY MY MIND.THEY ARE CUMBERSOMEWould you tell the solutions you have in your mind? It might be possible that I would be thinking of the same, but let's hear it from you. :)
    And post any code if you have written.

  • Why can't I undo a big mistake renaming folders--help my library's wrecked

    I was backing up a CD we bought for the kids to learn spanish. I multiple edited all of the album's details to call it spanish cd and after I pressed enter a box appeared that said it was processing, and to my horror all the names of my whole itunes library appeared momentarily as they got worked over. Now my whole library is called 'spanish cd' and no albums are together anymore. I tried to undo the action but cannot. Can anybody pLEEEZE help me. I feel that I will have to reload sixty + CDs. Help, help, help. SOS.
    Aidan. PS I tried to unchech boxes that say itunes should arrange folders as one entry on the forum seemed to be saying this causes 'undo' problems in other ways. NO result. Help!!!!
    Thankyou.

    iTunes does not have an undo feature and will not necessarily warn you that you are about to do something catastrophic.
    If you have the files on an iPod then you could recover them complete with correct tags using methods in this post from Zevoneer: http://discussions.apple.com/thread.jspa?messageID=6273675&#6273675
    Failing that, you could try MusicBrainz PicardTagger. This is supposed to be able to extract an audio fingerprint of your media files and compare them with a database to determine the correct tag info. It works best however when the files are still arranged in related groups.
    Unchecking the "Keep iTunes Music folder organised" option now is a horse & stable door scenario. If you'd done that before your mass edit a simple tagging tool could have rebuilt the album titles from each file's folder name.
    tt2

  • Crashing, no 'UNDO' when working with Chinese Text

    We have a number of users working in InDesign CS4 6.0.3 on Windows XP SP3. When they enter Chinese text into text boxes, frequently their UNDO command is no longer available. This basically renders files unusable. In addition to this, the application will frequently crash when working with Chinese text. The only workarounds that have sometimes worked include:
    1.       Switching keyboard mapping or just selecting English to see if it affects the Undo function.
    2.       Reset the preferences for InDesign.
    3.       UNDO problem occurred when jumping between web browser and InDesign. Workaround was to select a menu item from within InDesign - any menu item, it didn't matter - and the key command began working again.
    Has anybody else run into these problems?

    Peter, have you had any problems accessing the web pages for the Release Notes? After finally digging under about 3 layers of redundant links (annoying in and of itself), the final links to Release Notes for InDesign patches 6.0.4, 6.0.5, and 6.0.6 brought me to the following:
    InDesign 6.0.4 took me to InCopy 6.0.5
    InDesign 6.0.5 took me to InCopy 6.0.6
    InDesign 6.0.6 took me to InDesign Server CS5
    I got approval to install all patches on a person's computer, but now I can't even read the warnings before doing so!

  • Undo shortcut intermittently doesn't work

    Hi guys,
    On certain files §¶•ªªº––≠≠–º•¶§∞¢£™¡¡¡` ¡`` œ∑´®†¥¨ˆøππ“‘«
    PS CS5
    Mac 10.6.6
    16gb RAM

    Yep, it is fully updated.  I¹ve already tried throwing away my preferences,
    yet the ³undo² problem happened again.  I¹ve re-started, repaired
    permissions and etc. I should tell you that I can undo, just not with the
    keyboard shortcut.  Nor, when the shortcut problem comes up, will my mouse
    scroll wheel make the contents of a palette go north and south.  Another
    weird thing that has happened once or twice is that the image thumbnails in
    the layers palette have not displayed the mask, in both adjustment and image
    layers, after I¹ve used a brush of any kind.  Instead, the thumbnail of the
    mask will look like the gray and white checkerboard that transparent layers
    show.  I can get the thumbnail mask to come back if I click several times on
    adjacent thumbnails.  It kind of seems that PS is running too slowly to
    re-write the thumbnail immediately, which doesn¹t make sense because the
    MacPro is a 2.93ghz eight core running 16gb of RAM.  The file sizes I work
    on vary from 30mb to 500mb or so not too huge, though I think the ones
    that have the problems I¹ve described are on the larger side.  I¹ve got it
    set for 25 history states, which ought to be ok.
    Another odd thing.  I often have 2-4 images open at a time, and the problems
    will only be happening to one of those images. On all the other images the
    shortcuts, scroll wheel, thumbnails are all ok.  Any ideas what the hell is
    going on here?
    Thank you very much for your help,
    Todd Pearson
    http://www.toddpearsonphotography.com/
    c.pfaffenbichler2/24/11 11:56 [email protected]
    Is Photoshop fully updated?
    (boilerplate-text) As with all unexplainable Photoshop-problems you might try
    trashing the prefs (after making sure all customized presets like Actions,
    Patterns, Brushes etc. have been saved and making a note of the Preferences
    you¹ve changed) by pressing command-alt-shift on starting the program or
    starting from a new user-account.
    System Maintenance (repairing permissions, purging PRAM, running cron-scripts,
    cleaning caches, etc.) might also be beneficial, Onyx has been recommended for
    such tasks.
    http://www.apple.com/downloads/macosx/system_disk_utilities/onyx.html
    Weeding out bad fonts never seems to be a bad idea, either. (Validate your
    fonts in Font Book and remove the bad ones.)
    If 3rd party plug-ins are installed try disabling them to verify if one of
    those may be responsible for the problem.
    >

  • Ctrl-F key presses fill up undo buffer

    I recently discovered a perplexing issue in Final Cut Pro.
    The Ctrl-Fkey transport keys apparently are considered actions
    by FCP and hence occupy the undo buffer. Using these keys
    to shuttle the timeline will effectively wipe out any important actions
    previously stored in the undo buffer and replace them with blank
    key presses.
    Probably not many people use these keys for that purpose however,
    some devices do such as the Bella Professional editor's keyboard.
    It has a jog/shuttle wheel built in that is configured to use these
    very key presses.
    Is there anyone who has noticed this behavior or has been able
    to resolve it? Incidentally, to use these keys as FCP designates, one
    must turn off Keyboard Navigation in the Keyboard & Mouse pref panel
    since they are already assigned by the OS.
    Dual processor G5   Mac OS X (10.4.8)  

    Steve, the ShuttlePro looks like a terrific
    controller.
    To be honest I don't think the design of the shuttle knob is that great, and I don't end up using it as much as I thought I would. It's nothing like the real edit controller shuttles of yore.
    By speed select keys are you referring to the J and L
    keys or the Ctrl-Fkey's?
    I meant the key combos that set a specific speed. As above, thinking I would use the shuttle more I set them to speeds I would actually use - skipping ones that weren't useful to me. It was a lot of work which I'll go undo now...
    It WOULD be great to have slow frame by frame play
    (JK and KL) on the shuttle as well but like you've
    already said, apparently it is unique to those
    particular keys.
    As long as you map to the actual J K and L keys from buttons you can press individually, it works. It doesn't work with the ShuttlePro knob simply because they only allow one button press to be programmed for each position.
    My problem was that I had mapped the ShuttlePro buttons and their functions to new places on the keyboard. The JK and KL functions seem to only work when you're mapping to those actual keys. So I have J K & L mapped to buttons on the ShuttlePro (their default, actually) and it works great.
    What really disappoints me is that FCP doesn't support a range of playback speeds that would allow something approximating shuttle behavior.
    Thanks for bringing the Undo problem to our attention!

  • Corrupt project - how to go about fixing it?

    Hi all. I think I have a project which is slowly going corrupt. Anyone ever seen that?
    System: Dual 2-gig (late 2004 vintage), 2 gig RAM, OS 10.3.9, FCP 4.5/HD.
    What's happening is that while I'm editing, many anamalous things are happening. For instance, if I make an edit, and then want to undo it, sometimes the undo doesn't undo. Sometimes the mistake is still there...but it's not, really! I mean, the timeline shows the clip I mistakenly edited, even after I've hit CNTL-Z, and sometimes if I play that piece, the mistaken clip really is still there...but sometimes it's not; the clip that's present on the timeline isn't the one I'm watching...and when I highlight and delete the clip, voila, the clip that's supposed to be there magically reappears (on the timeline...I can usually always see the correct video). And sometimes when I do a "fit to fill", I not only get the fit to fill clip, it does an extra ripple insert, too. Usually this can be undone, but not all the time...
    I should add here that, despite all these anamolies, the timeline plays all the way through. It doesn't stop, freeze up, stutter, or exhibit any sort of playback problems.
    Now, before we go any further, DON'T tell me to trash my prefs. I've got FCP Rescue at my disposal, and have trashed and restored multiple times. Also, I do not get these sorts of problems happening with other projects I'm currently working on (well, sometimes the non-undo problem crops up, but not nearly as often). For these reasons, I'm thinking that something's up with this particular project.
    So earlier this evening I went into the Media Manager, selected choices to make new media to a drive with lotsa space, and to create a new project (to be saved in my FCP Projects folder on the system drive). Clicked OK, and off we went...spent three hours copying media, and then with 8 minutes left got the spinning beachball of death. My guess...FCP encountered whatever was corrupt, and couldn't make a new project.
    Anybody got any suggestions? I guess I can limp along, but I'm afraid something REALLY bad is gonna happen...

    Now, before we go any further, DON'T tell me to trash my prefs. I've got FCP Rescue at my disposal, and have trashed and restored multiple times.
    Before you go any further... you might try trashing the prefs and NOT restoring, in case you've got a glitch in the saved copy. Recreate your prefs when you open FCP.
    Might also look at any files that were not copied and see if any of them seem strange.
    Aside from that, you could try,
    Deleting all render files for the project and re-rendering
    Making the footage for the project offline, then reconnecting clips one at a time until you see the problem.
    rh

  • Purging queues in Oracle 8i

    Hi,
    I've got an old Oracle 8i (8.1.7.3.0) database that has some queues that have been running for years with retention_time=-1 so there are gigabytes of old messages taking up approx 200GB of disk space. Here's an example of how one of the queues looks:
    BEGIN DBMS_AQADM.CREATE_QUEUE(
    Queue_name => 'ABC.MY_Q',
    Queue_table => 'ABC.MY_Q_TAB',
    Queue_type => 0,
    Max_retries => 5,
    Retry_delay => 0,
    Retention_time => -1,
    dependency_tracking => FALSE,
    comment => 'My Queue);
    END;
    My question is how best to remove the old messages ? I'm quite happy to start afresh with zero messages in the queue tables. From the research I've done I've come up with these possibilities:
    1. Allter the queues to have a sensible retention time e.g.
    DBMS_AQADM.ALTER_QUEUE(
    Queue_name => 'ABC.MY_Q',
    Retention_time => 60 * 60 * 24 * 7);
    Question - will this automatically cause all older messages to be removed ? If yes, is it a slow operation for hundreds of millions of messages and does it require lots of undo tablespace ? If no, then what other steps are required to purge the data older than the new retention time ?
    2. Stop, drop, recreate and start the queues.
    Question - will this also be a slow operation for hundreds of millions of messages and does it require lots of undo tablespace ?
    3. Truncate the queue tables.
    Question - is this safe ? Will behind the scenes objects get screwed up ? Perhaps after truncating the tables I should drop and recreate the queues and queue tables ?
    Thanks in advance for your help,
    Colm
    Edited by: 802408 on 14-Oct-2010 08:52

    As i see it your only option is to drop and recreate, I'm assuming you don't want any of the messages that are held? If not then stop, drop and recreate with a sensible retention time.
    If you allow oracle to remove the messages you will still be left with a huge queue table as it will not reclaim the space.
    The drop operation should be quick and will not cause undo problems - assuming you don't want to try and keep any of the messages to put back on to the recreated queue.
    Do not manually truncate the queue tables - this is not supported and not recommended, if you are happy to do this then the best approach is to drop and recreate.
    Thanks
    Paul
    Edited by: PaulTill2508 on Oct 16, 2010 12:05 PM

Maybe you are looking for