GapContent.UndoRemove changes = null; if (content instanceof GapContent) changes = (GapContent.UndoRemove) temp;  if (changes != null && !(start == end)) {  ElementEdit edit = new ElementEdit (root, start, removed, added); event.addEdit(edit); }
  public void remove(int offset, int length) throws BadLocationException  {    DefaultDocumentEvent event =      new DefaultDocumentEvent(offset, length,			       DocumentEvent.EventType.REMOVE);        // Here we set up the parameters for an ElementChange, if one    // needs to be added to the DocumentEvent later    Element root = getDefaultRootElement();    int start = root.getElementIndex(offset);    int end = root.getElementIndex(offset + length);        Element[] removed = new Element[end - start + 1];    for (int i = start; i <= end; i++)      removed[i - start] = root.getElement(i);        removeUpdate(event);    Element[] added = new Element[1];    added[0] = root.getElement(start);    boolean shouldFire = content.getString(offset, length).length() != 0;        writeLock();    UndoableEdit temp = content.remove(offset, length);    writeUnlock();        postRemoveUpdate(event);        GapContent.UndoRemove changes = null;    if (content instanceof GapContent)      changes = (GapContent.UndoRemove) temp;    if (changes != null && !(start == end))      {        // We need to add an ElementChange to our DocumentEvent        ElementEdit edit = new ElementEdit (root, start, removed, added);        event.addEdit(edit);      }        if (shouldFire)    fireRemoveUpdate(event);  }