Package javax.swing.undo

Examples of javax.swing.undo.UndoableEdit


      }
      if (sb.length() == 0) {
    // Nothing to insert, bail.
    return;
      }
      UndoableEdit cEdit = c.insertString(offset, sb.toString());

      // create event and build the element structure
      int length = sb.length();
      DefaultDocumentEvent evnt =
    new DefaultDocumentEvent(offset, length, DocumentEvent.EventType.INSERT);
View Full Code Here


    public UndoableEdit remove(int where, int nitems) throws BadLocationException {
  if (where + nitems >= length()) {
      throw new BadLocationException("Invalid remove", length() + 1);
  }
  String removedString = getString(where, nitems);
  UndoableEdit edit = new RemoveUndo(where, removedString);
  replace(where, nitems, empty, 0);
  return edit;
 
    }
View Full Code Here

        undoable.redo();
        assertEquals(3, pos.getOffset());
    }

    public void testCreatePositionAfterUndone() throws BadLocationException {
        UndoableEdit undoable;
        content = new StringContent(10);
        content.insertString(0, "0123456789");
        undoable = content.remove(3, 5);
        undoable.undo();
        Position pos = content.createPosition(5);
        assertEquals(5, pos.getOffset());
        undoable.redo();
        assertEquals(3, pos.getOffset());
        undoable.undo();
        assertEquals(5, pos.getOffset());
    }
View Full Code Here

        undoable.undo();
        assertEquals(5, pos.getOffset());
    }

    public void testCreatePositionAfterInsert() throws BadLocationException {
        UndoableEdit undoable;
        content = new StringContent(10);
        content.insertString(0, "0123456789");
        undoable = content.insertString(10, "big ");
        Position pos = content.createPosition(12);
        assertEquals(12, pos.getOffset());
        undoable.undo();
        assertEquals(10, pos.getOffset());
        undoable.redo();
        assertEquals(12, pos.getOffset());
    }
View Full Code Here

            });
        }
    }

    public void testInsertString_WithValidValues() throws BadLocationException {
        UndoableEdit ue = content.insertString(2, "^^^");
        assertNotNull(ue);
        content.getChars(0, content.length(), text);
        assertEquals(20, text.array.length);
        assertEquals("01^^^2345\n", content.getString(0, content.length()));
        ue.undo();
        assertEquals("012345\n", content.getString(0, content.length()));
        ue.redo();
        assertEquals("01^^^2345\n", content.getString(0, content.length()));
    }
View Full Code Here

            }
        });
    }

    public void testInsertString_UndoableEdit() throws BadLocationException {
        UndoableEdit undoable;
        final String redoName = isHarmony() ? "Redo addition" : "Redo";
        final String undoName = isHarmony() ? "Undo addition" : "Undo";
        undoable = content.insertString(0, "012345");
        assertEquals(redoName, undoable.getRedoPresentationName());
        assertEquals(undoName, undoable.getUndoPresentationName());
        assertTrue(undoable.isSignificant());
        assertFalse(undoable.canRedo());
        assertTrue(undoable.canUndo());
        undoable.undo();
        assertTrue(undoable.canRedo());
        assertFalse(undoable.canUndo());
        undoable.redo();
        assertFalse(undoable.canRedo());
        assertTrue(undoable.canUndo());
        assertFalse(undoable.addEdit(null));
        assertFalse(undoable.addEdit(undoable));
    }
View Full Code Here

        content = new StringContent();
        content.insertString(0, "012345^11111");
        content.getChars(0, content.length(), text);
        assertEquals(13, text.count);
        assertEquals(20, text.array.length);
        UndoableEdit undoable = content.remove(2, 0);
        content.getChars(0, content.length(), text);
        assertEquals(13, text.count);
        assertEquals(20, text.array.length);
        assertNotNull(undoable);
        assertEquals("012345^11111\n", content.getString(0, content.length()));
        undoable = content.remove(2, 5);
        content.getChars(0, content.length(), text);
        assertEquals(8, text.count);
        assertEquals(20, text.array.length);
        assertNotNull(undoable);
        assertEquals("0111111\n", content.getString(0, content.length()));
        undoable.undo();
        assertEquals("012345^11111\n", content.getString(0, content.length()));
        undoable.redo();
        assertEquals("0111111\n", content.getString(0, content.length()));
    }
View Full Code Here

        undoable.redo();
        assertEquals("0111111\n", content.getString(0, content.length()));
    }

    public void testRemove_UndoableEdit() throws BadLocationException {
        UndoableEdit undoable = content.remove(2, 3);
        final String redoName = isHarmony() ? "Redo deletion" : "Redo";
        final String undoName = isHarmony() ? "Undo deletion" : "Undo";
        assertEquals(redoName, undoable.getRedoPresentationName());
        assertEquals(undoName, undoable.getUndoPresentationName());
        assertTrue(undoable.isSignificant());
        assertFalse(undoable.canRedo());
        assertTrue(undoable.canUndo());
        assertEquals(redoName, undoable.getRedoPresentationName());
        assertEquals(undoName, undoable.getUndoPresentationName());
        assertTrue(undoable.isSignificant());
        assertFalse(undoable.canRedo());
        assertTrue(undoable.canUndo());
        undoable.undo();
        assertTrue(undoable.canRedo());
        assertFalse(undoable.canUndo());
        undoable.redo();
        assertFalse(undoable.canRedo());
        assertTrue(undoable.canUndo());
        assertFalse(undoable.addEdit(null));
        assertFalse(undoable.addEdit(undoable));
    }
View Full Code Here

        content = new StringContent();
        content.insertString(0, "012345^11111");
        content.getChars(0, content.length(), text);
        assertEquals(13, text.count);
        assertEquals(20, text.array.length);
        UndoableEdit ue = content.remove(2, 5);
        content.getChars(0, content.length(), text);
        assertEquals(8, text.count);
        assertEquals(20, text.array.length);
        assertNotNull(ue);
        assertEquals("0111111\n", content.getString(0, content.length()));
        ue.undo();
        assertEquals("012345^11111\n", content.getString(0, content.length()));
        ue.redo();
        assertEquals("0111111\n", content.getString(0, content.length()));
    }
View Full Code Here

        assertEquals("\n", text.toString());
        assertEquals(1, text.array.length);
    }

    public void testCreatePositionBeforeUndo() throws BadLocationException {
        UndoableEdit undoable;
        content = new StringContent(10);
        content.insertString(0, "0123456789");
        undoable = content.remove(3, 5);
        Position pos1 = content.createPosition(3);
        assertEquals(3, pos1.getOffset());
        undoable.undo();
        content = new StringContent(10);
        content.insertString(0, "0123456789");
        undoable = content.remove(3, 5);
        Position pos = content.createPosition(3);
        assertEquals(3, pos.getOffset());
        undoable.undo();
        assertEquals(8, pos.getOffset());
        undoable.redo();
        assertEquals(3, pos.getOffset());
    }
View Full Code Here

TOP

Related Classes of javax.swing.undo.UndoableEdit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.