Package javax.swing.text

Examples of javax.swing.text.Position


    }
   
    void addRecord(String str, int removeLen) {
        // update the scrolling information for the panel
        ManualScrollEditorPane mspe = (ManualScrollEditorPane) logPane;
        Position pos = mspe.preModify();
        boolean atEnd = mspe.atEnd();

        // add the new text to the end of the current document
        try {
            final Document doc = logPane.getDocument();

            // if there is text to remove, remove it first
            if (removeLen > 0) {
                doc.remove(0, removeLen);
            }

            Position end = doc.getEndPosition();
            doc.insertString(end.getOffset() - 1, str, null);
        } catch (BadLocationException ble) {
            // should never happen
            logger.log(Level.WARNING, "Bad location", ble);
            return;
        }
View Full Code Here


      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
    {
View Full Code Here

    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

      gc.insertString(0, "foo\nbar\n");
    gc.remove(0, 4);

          // Gap starts at 0 now and the following Position
          // instance is created at the end of the gap.
          Position pos = gc.createPosition(0);

          // This insertion should not move the offset
          // of the Position object.
    gc.insertString(0, "z");

    posValue = pos.getOffset();
        }
      catch(BadLocationException ble)
        {
        }
      harness.check(posValue, 0);
View Full Code Here

  {
    harness.checkPoint("testSimple");
    GapContent c = new GapContent();
    try
      {
        Position p1 = c.createPosition(0);
        Position p2 = c.createPosition(1);
        harness.check(p1.getOffset(), 0);
        harness.check(p2.getOffset(), 1);

        c.insertString(0, "hello");
        harness.check(p1.getOffset(), 0);
        harness.check(p2.getOffset(), 6);

        c.remove(0, 5);
        harness.check(p1.getOffset(), 0);
        harness.check(p2.getOffset(), 1);
      }
    catch (BadLocationException ex)
      {
        harness.fail("BadLocationException");
        harness.debug(ex);
View Full Code Here

  {
    harness.checkPoint("testComplex");
    GapContent c = new GapContent();
    try
      {
        Position p1 = c.createPosition(0);
        Position p2 = c.createPosition(1);
        harness.check(p1.getOffset(), 0);
        harness.check(p2.getOffset(), 1);

        c.insertString(0, "abcdefghijklmno");
        harness.check(p1.getOffset(), 0);
        harness.check(p2.getOffset(), 16);

        c.insertString(5, "12345");
        harness.check(p1.getOffset(), 0);
        harness.check(p2.getOffset(), 21);
       
        PlainDocument doc = new PlainDocument();
        doc.insertString(0, "cdefgh", null);
        Position s = doc.createPosition(1);
        harness.check(s.getOffset(), 1);

        doc.insertString(0, "a", null);
        harness.check(s.getOffset(), 2);
        Position a = doc.createPosition(1);
        harness.check(a.getOffset(), 1);

        doc.insertString(1, "b", null);
        harness.check(s.getOffset(), 3);
        harness.check(a.getOffset(), 2);
      }
    catch (BadLocationException ex)
      {
        harness.fail("BadLocationException");
        harness.debug(ex);
View Full Code Here

    h.checkPoint("border case");
    try
      {
        PlainDocument doc = new PlainDocument();
        doc.insertString(0, "One Three Four", null);
        Position pos = doc.createPosition(4);
        doc.insertString(4, "Two ", null);
        h.check(pos.getOffset(), 8);
      }
    catch (BadLocationException ex)
      {
        h.fail("BadLocationException thrown")
      }
View Full Code Here

    {
      gc = new GapContent();
      gc.insertString(0, "abc\ndef\n");

      // create position on the 'd'.
      Position pos = gc.createPosition(4);

      // remove the 'd'
      gc.remove(4, 1);

      offset = pos.getOffset();
    }
    catch(BadLocationException ble)
    {
      // If that happens something is pretty odd
      offset = -1;
View Full Code Here

      pass = true;
    }
    harness.check(pass);
   
    // index of last char
    Position p = null;
    try
    {
      p = gc.createPosition(3);
    }
    catch (BadLocationException e)
    {
      pass = true;
    }
    harness.check(p.getOffset(), 3);
   
    // index of last char + 1
    try
    {
      p = gc.createPosition(4);
    }
    catch (BadLocationException e)
    {
    }
    harness.check(p.getOffset(), 4);
   
    // index of last char + 2
    pass = false;
    try
    {
View Full Code Here

    harness.checkPoint("testPositions");
    PlainDocument d = new PlainDocument();
    try
      {
        d.insertString(0, "ABC", null);
        Position p0 = d.createPosition(0);
        harness.check(p0.getOffset(), 0);
        Position p1 = d.createPosition(1);
        harness.check(p1.getOffset(), 1);
        Position p2 = d.createPosition(3);
        harness.check(p2.getOffset(), 3);
        Position p3 = d.createPosition(4);
        harness.check(p3.getOffset(), 4);
        
        d.insertString(1, "XYZ", null);
        harness.check(p0.getOffset(), 0);
        harness.check(p1.getOffset(), 4);
        harness.check(p2.getOffset(), 6);
        harness.check(p3.getOffset(), 7);
        
        d.remove(2, 3);
        harness.check(p0.getOffset(), 0);
        harness.check(p1.getOffset(), 2);
        harness.check(p2.getOffset(), 3);
        harness.check(p3.getOffset(), 4);     
      }
    catch (BadLocationException e)
      {
      }
  }
View Full Code Here

TOP

Related Classes of javax.swing.text.Position

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.