Package javax.swing.undo

Examples of javax.swing.undo.UndoableEdit


        } catch (NullPointerException e) {
        }
    }

    public void testCreatePositionBeforeUndo() throws BadLocationException {
        UndoableEdit ue = content.remove(3, 8);
        Position pos = content.createPosition(3);
        assertEquals(3, pos.getOffset());
        ue.undo();
        assertEquals(11, pos.getOffset());
        ue.redo();
        assertEquals(3, pos.getOffset());
    }
View Full Code Here


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

    public void testCreatePositionAfterUndone() throws BadLocationException {
        UndoableEdit ue = content.remove(3, 8);
        ue.undo();
        Position pos = content.createPosition(5);
        assertEquals(5, pos.getOffset());
        ue.redo();
        assertEquals(3, pos.getOffset());
        ue.undo();
        assertEquals(5, pos.getOffset());
    }
View Full Code Here

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

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

  public void test(TestHarness h)
  {
    h.checkPoint("StringContent -- InsertUndo");

    StringContent sc = new StringContent();
    UndoableEdit ue = null;
    UndoableEdit ue2 = null;
    UndoableEdit ue3 = null;
    try
      {
        h.checkPoint("StringContent -- insertString()");
        ue = sc.insertString(0, "path");
        h.check("path\n", sc.getString(0, sc.length()),
                "StringContent.insertString(): insert 'path' at 0");
        java.util.Locale.setDefault(java.util.Locale.US);
        String presentationName = ue.getPresentationName();
        h.check("", presentationName, "PresentationName should be '' and is: " + presentationName);
        String redoPresentationName = ue.getRedoPresentationName();
        h.check("Redo", redoPresentationName, "RedoPresentationName should be Redo and is: " + redoPresentationName);
        String undoPresentationName = ue.getUndoPresentationName();
        h.check("Undo", undoPresentationName, "UndoPresentationName should be Undo and is: " + undoPresentationName);
        h.check(false, ue.canRedo(), "canRedo? () (" + ue.canRedo() + ")");
        h.check(true, ue.canUndo(), "canUndo? () (" + ue.canUndo() + ")");
        ue.undo();
        h.check("\n", sc.getString(0, sc.length()),
                "Undo: should be '\\n' and is: " + sc.getString(0, sc.length()));
        h.check(true, ue.canRedo(), "canRedo? () (" + ue.canRedo() + ")");
        h.check(false, ue.canUndo(), "canUndo? () (" + ue.canUndo() + ")");
        ue.redo();
        h.check("path\n", sc.getString(0, sc.length()),
                "Redo: should be '\\n' and is: " + sc.getString(0, sc.length()));
        ue.die();
        h.debug("UndoableEdit.die() no more undo/redo");
        h.check(false, ue.canUndo(), "die, no more undo");
        h.check(false, ue.canRedo(), "die, no more redo");
        sc = new StringContent();
        ue = sc.insertString(0, "path");
        ue2 = sc.insertString(0, "class");
        h.check("classpath\n", sc.getString(0, sc.length()), "should be classpath and is: " + sc.getString(0, sc.length()));
        h.check(true, ue.canUndo(), "double undo can undo?");
        ue.undo();
        h.check("spath\n", sc.getString(0, sc.length()), "double undo: should be 'spath\\n' and is: " + sc.getString(0, sc.length()));
        ue2.undo();
        h.check("\n", sc.getString(0, sc.length()), "double undo: should be '\\n' and is: " + sc.getString(0, sc.length()));
        ue.redo();
        h.check("clas\n", sc.getString(0, sc.length()), "double undo: should be 'clas\\n' and is: " + sc.getString(0, sc.length()));
        ue2.redo();
        h.check("spathclas\n", sc.getString(0, sc.length()), "double undo: should be 'spathclas\\n' and is: " + sc.getString(0, sc.length()));
        ue3 = sc.insertString(9, "X");
        h.check("spathclasX\n", sc.getString(0, sc.length()), "add an X: should be 'spathclasX\\n' and is: " + sc.getString(0, sc.length()));
        ue.undo();
        h.check("hclasX\n", sc.getString(0, sc.length()), "undo first position: should be 'hclasX\\n' and is: " + sc.getString(0, sc.length()));
      }
    catch (BadLocationException ble)
      {
        h.fail("BadLocation! " + ble.getMessage());
      }
    try{
      ue3.undo();
      h.fail("should not be able to undo!");
    }
    catch (CannotUndoException cannot)
      {
        h.checkPoint("cannot undo");
View Full Code Here

  public void test(TestHarness h)
  {
    h.checkPoint("StringContent");

    StringContent sc = new StringContent();
    UndoableEdit ue = null;
    UndoableEdit ue2 = null;
    UndoableEdit ue3 = null;
    try
      {
        h.checkPoint("StringContent -- insertString()");
        sc.insertString(0, "path");
        h.check("path\n", sc.getString(0, sc.length()),
                "StringContent.insertString(): insert 'path' at 0");
        sc.insertString(0, "class");
        ue = sc.remove(1, 4);
        java.util.Locale.setDefault(java.util.Locale.US);
        String presentationName = ue.getPresentationName();
        h.check("", presentationName, "PresentationName should be '' and is: " + presentationName);
        String redoPresentationName = ue.getRedoPresentationName();
        h.check("Redo", redoPresentationName, "RedoPresentationName should be Redo and is: " + redoPresentationName);
        String undoPresentationName = ue.getUndoPresentationName();
        h.check("Undo", undoPresentationName, "UndoPresentationName should be Undo and is: " + undoPresentationName);
        h.check(false, ue.canRedo(), "canRedo? () (" + ue.canRedo() + ")");
        h.check(true, ue.canUndo(), "canUndo? () (" + ue.canUndo() + ")");
        h.check("cpath\n", sc.getString(0, sc.length()),
                "Remove path: getString should be class\\n and is: " + sc.getString(0, sc.length()));
        ue.undo();
        h.check("classpath\n", sc.getString(0, sc.length()),
                "Undo: getString should be classpath\\n and is: " + sc.getString(0, sc.length()));
        h.check(true, ue.canRedo(), "canRedo? () (" + ue.canRedo() + ")");
        h.check(false, ue.canUndo(), "canUndo? () (" + ue.canUndo() + ")");
        ue.redo();
        h.check("cpath\n", sc.getString(0, sc.length()),
                "Redo: getString should be cpath\\n and is : " + sc.getString(0, sc.length()));
        ue.die();
        h.debug("UndoableEdit.die() no more undo/redo");
        h.check(false, ue.canUndo(), "die, no more undo");
        h.check(false, ue.canRedo(), "die, no more redo");
        sc = new StringContent();
        sc.insertString(0, "classpathX");
        h.check("classpathX\n", sc.getString(0, sc.length()), "should be 'classpathX' and is: " + sc.getString(0, sc.length()));
        ue = sc.remove(3, 2);
        h.check("clapathX\n", sc.getString(0, sc.length()),
                "double undo: should be 'clapathX\\n' and is: " + sc.getString(0, sc.length()));
        ue2 = sc.remove(4, 2);
        h.check("claphX\n", sc.getString(0, sc.length()),
                "double undo: should be 'claphX\\n' and is: " + sc.getString(0, sc.length()));
        ue3 = sc.remove(0, 3);
        h.check(true, ue.canUndo(), "double undo can undo?");
        h.check("phX\n", sc.getString(0, sc.length()), "check remove: should be 'phX\\n' and is: " + sc.getString(0, sc.length()));
        ue.undo();
        h.check("phXss\n", sc.getString(0, sc.length()),
                "double undo: should be 'phXss\\n' and is: " + sc.getString(0, sc.length()));
        ue2.undo();
        h.check("phXsats\n", sc.getString(0, sc.length()), "should be 'phXsats\\n' and is: " + sc.getString(0, sc.length()));
        ue.redo();
        h.check("phXts\n", sc.getString(0, sc.length()), "double undo: should be 'phXts\\n' and is: " + sc.getString(0, sc.length()));
        ue3.undo();
        h.check("claphXts\n", sc.getString(0, sc.length()), "add an X: should be 'claphXts\\n' and is: " + sc.getString(0, sc.length()));
      }
    catch (BadLocationException ble)
      {
        h.fail("BadLocation! " + ble.getMessage());
      }
    try{
      ue3.undo();
      h.fail("should not be able to undo!");
    }
    catch (CannotUndoException cannot)
      {
        h.checkPoint("cannot undo");
View Full Code Here

  implements Testlet
{
  public void test(TestHarness harness)
  {
    TestUndoManager mgr;
    UndoableEdit edit;

    // Check #1.
    mgr = new TestUndoManager();
    edit = new AbstractUndoableEdit();
    mgr.undoableEditHappened(new UndoableEditEvent(this, edit));
View Full Code Here

    }
 
    public void actionPerformed( ActionEvent e )
    {
      Span      selSpan;
      UndoableEdit  edit;
      long      start, stop;
      Marker      mark;
      int        idx;

      if( !markVisible ) return;
View Full Code Here

    {
      final Point pt  = SwingUtilities.convertPoint( e.getComponent(), e.getPoint(), wavePanel );

      Span      span, span2;
      long      pos, start, stop;
      UndoableEdit  edit;
      int        idx;
      Marker      mark;

      span        = timelineVis; // doc.timeline.getVisibleSpan();
      span2    = timelineSel; // doc.timeline.getSelectionSpan();
View Full Code Here

    {
      final Point pt  = SwingUtilities.convertPoint( e.getComponent(), e.getPoint(), wavePanel );
     
      Span      span, span2;
      long      position;
      UndoableEdit  edit;
      
      span        = timelineVis; // doc.timeline.getVisibleSpan();
      span2    = timelineSel; // doc.timeline.getSelectionSpan();
      position    = span.getStart() + (long) (pt.getX() / getComponent().getWidth() *
                          span.getLength());
      position    = Math.max( 0, Math.min( timelineLen, position ));
      if( !hasStarted && !ctrlDrag ) {
        if( shiftDrag ) {
          if( span2.isEmpty() ) {
            span2 = new Span( timelinePos, timelinePos );
          }
          startPos = Math.abs( span2.getStart() - position ) >
                 Math.abs( span2.getStop() - position ) ?
                  span2.getStart() : span2.getStop();
          span2  = new Span( Math.min( startPos, position ),
                    Math.max( startPos, position ));
          edit  = TimelineVisualEdit.select( this, doc, span2 ).perform();
        } else {
          startPos = position;
          if( span2.isEmpty() ) {
            edit = TimelineVisualEdit.position( this, doc, position ).perform();
          } else {
            edit = new CompoundEdit();
            edit.addEdit( TimelineVisualEdit.select( this, doc, new Span() ).perform() );
            edit.addEdit( TimelineVisualEdit.position( this, doc, position ).perform() );
            ((CompoundEdit) edit).end();
          }
        }
      } else {
        if( ctrlDrag ) {
View Full Code Here

   *
   *  @synchronization  attempts exclusive on TRNS + GRP
   */
  public void mousePressed( MouseEvent e )
    {
    UndoableEdit  edit;
    List      collTracks;
 
    if( e.isAltDown() ) {
      selected = !selected;   // toggle item
      if( selected ) {    // select all
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.