185186187188189190191192193194195
GapContent gc = new GapContent(); // regular insert try { gc.insertString(0, "ABC"); // ignoring undo/redo here - see insertUndo.java } catch (BadLocationException e) { // ignore - checks below will fail if this happens
198199200201202203204205206207208
// insert at location before start boolean pass = false; try { gc.insertString(-1, "XYZ"); } catch (BadLocationException e) { pass = true; }
214215216217218219220221222223224
harness.check(pass); // insert at index of last character - this is OK try { gc.insertString(3, "XYZ"); } catch (BadLocationException e) { // ignore }
226227228229230231232233234235236
// Insert at index of last character + 1. This appends the new string to // the existing string. (This works since 1.5 of the RI) try { gc.insertString(7, "XYZ"); } catch (BadLocationException e) { pass = false; }
238239240241242243244245246247248
// insert at index of last character + 2 pass = false; try { gc.insertString(gc.length() + 1, "XYZ"); } catch (BadLocationException e) { pass = true; }
250251252253254255256257258259260
// insert empty string int length = gc.length(); try { gc.insertString(0, ""); } catch (BadLocationException e) { // ignore }
262263264265266267268269270271272
// insert null string pass = false; try { gc.insertString(0, null); } catch (BadLocationException e) { // ignore }
283284285286287288289290291292293
int posValue = -1; try { GapContent gc = new GapContent(); 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);
292293294295296297298299300301302
// 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) {
7071727374757677787980
harness.check(pass); // add some more text try { gc.insertString(0, "ABCDEFG"); } catch (BadLocationException e) { } harness.check(gc.length(), 8);