Package javax.swing.text

Examples of javax.swing.text.StringContent$UndoPosRef


   * @param harness
   */
  public void testRemoveLast(TestHarness harness)
  {
    harness.checkPoint("testRemoveLast");
    StringContent sc = new StringContent();
    harness.check(sc.length(), 1);
   
    boolean pass = false;
    try
    {
      sc.remove(0, 1);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
View Full Code Here


   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)     
  {
    StringContent sc = new StringContent();
    harness.check(sc.length(), 1);
    try
    {
      sc.insertString(0, "ABC");
    }
    catch (BadLocationException e)
    {
      // ignore
    }
   
    // negative index
    boolean pass = false;
    try
    {
      sc.createPosition(-1);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // index of last char
    Position p = null;
    try
    {
      p = sc.createPosition(3);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(p.getOffset(), 3);
   
    // index of last char + 1
    try
    {
      p = sc.createPosition(4);
    }
    catch (BadLocationException e)
    {
    }
    harness.check(p.getOffset(), 4);
   
    // index of last char + 2
    pass = false;
    try
    {
      p = sc.createPosition(5);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
View Full Code Here

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

    StringContent sc = new StringContent();
    try
      {
        sc.insertString(0, "classpath");
        Position position = sc.createPosition(1);
        Position position2 = sc.createPosition(4);
        Position position3 = sc.createPosition(sc.length());
        h.check(1, position.getOffset(), "createPosition(1): Position.getOffset() should be 1 and is: " + position.getOffset());
        h.check(4, position2.getOffset(), "createPosition(4): Position2.getOffset() should be 4 and is: " + position2.getOffset());
        h.check(10, position3.getOffset(), "createPosition(10): Position3.getOffset() should be 10 and is: " + position3.getOffset());
        sc.insertString(2, "-");
        h.check(1, position.getOffset(), "Position.getOffset() should be 1 and is: " + position.getOffset());
        h.check(5, position2.getOffset(), "Position2.getOffset() should be 5 and is: " + position2.getOffset());
        h.check(11, position3.getOffset(), "Position3.getOffset() should be 11 and is: " + position3.getOffset());
        sc.insertString(1, "-");
        h.check(2, position.getOffset(), "Position.getOffset() should be 2 and is: " + position.getOffset());
        h.check(6, position2.getOffset(), "Position2.getOffset() should be 6 and is: " + position2.getOffset());
        h.check(12, position3.getOffset(), "Position3.getOffset() should be 12 and is: " + position3.getOffset());
        sc.remove(0, 2);
        h.check(0, position.getOffset(), "Position.getOffset() should be 0 and is: " + position.getOffset());
        h.check(4, position2.getOffset(), "Position2.getOffset() should be 4 and is: " + position2.getOffset());
        h.check(10, position3.getOffset(), "Position3.getOffset() should be 10 and is: " + position3.getOffset());
        sc.remove(0, 5);
        h.check(0, position.getOffset(), "Position.getOffset() should be 0 and is: " + position.getOffset());
        h.check("path\n", sc.getString(0, sc.length()), "getString(0, length()) should be 'path\\n' and is: " + sc.getString(0, sc.length()));
        h.check(0, position2.getOffset(), "Position.getOffset() should be 0 and is: " + position2.getOffset());
        h.check(5, position3.getOffset(), "Position3.getOffset() should be 5 and is: " + position3.getOffset());
        sc.insertString(0, "class");
        h.check(0, position.getOffset(), "Position.getOffset() should be 0 and is: " + position.getOffset());
        h.check("classpath\n", sc.getString(0, sc.length()), "getString(0, length()) should be 'classpath\\n' and is: " + sc.getString(0, sc.length()));
        h.check(0, position2.getOffset(), "Position.getOffset() should be 0 and is: " + position2.getOffset());
        h.check(sc.length(), position3.getOffset(), "Position3 should be 10 and is: " + position3.getOffset());
      }
    catch (BadLocationException ble)
      {
        h.fail("BadLocation! " + ble.getMessage());
      }
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");
      }
    try
      {
        sc = new StringContent();
        sc.insertString(0, "super classpath");
        h.check("super classpath\n", sc.getString(0, sc.length()), "insert 'super classpath': " + sc.getString(0, sc.length()));
        ue = sc.remove(0, 6);
        h.check("classpath\n", sc.getString(0, sc.length()), "insert 'super classpath': " + sc.getString(0, sc.length()));
        ue.undo();
        h.check("super classpath\n", sc.getString(0, sc.length()), "undo 'classpath': " + sc.getString(0, sc.length()));
        ue.undo();
        h.fail("should not be able to undo two times");
      }
    catch (BadLocationException ble)
      {
View Full Code Here

TOP

Related Classes of javax.swing.text.StringContent$UndoPosRef

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.