public void testIsReadLocked() throws Exception {
   PlainDocument doc = new PlainDocument();
   assertFalse(DocumentUtilities.isReadLocked(doc));
   doc.readLock();
   try {
     assertTrue(DocumentUtilities.isReadLocked(doc));
   } finally {
     doc.readUnlock();
   }
 }
 @Override
 public void performOperation(
     AnnotatedPluginDocument[] annotatedDocuments,
     ProgressListener progressListener,
     Options options,
     SequenceSelection sequenceSelection,
     OperationCallback callback)
     throws DocumentOperationException {
   try {
     String[] urnStrings = options.getValueAsString(URNS_OPTION_NAME).split("\n");
     List<URN> validUrns = new ArrayList<URN>();
     List<String> brokenUrns = new ArrayList<String>();
     List<URN> missingUrns = new ArrayList<URN>();
     for (String urnString : urnStrings) {
       try {
         String trimmedString = urnString.trim();
         if (trimmedString.isEmpty()) {
           continue;
         }
         URN urn = new URN(trimmedString);
         if (DocumentUtilities.getDocumentByURN(urn) == null) {
           missingUrns.add(urn);
           continue;
         }
         validUrns.add(urn);
       } catch (MalformedURNException e) {
         brokenUrns.add(urnString);
       }
     }
     if (!brokenUrns.isEmpty()) {
       if (!Dialogs.showContinueCancelDialog(
           "Some of the URNs you entered are invalid. They will be ignored:\n\n"
               + StringUtilities.join("\n", brokenUrns),
           "Invalid URNs",
           null,
           Dialogs.DialogIcon.INFORMATION)) {
         return;
       }
     }
     if (!missingUrns.isEmpty()) {
       if (!Dialogs.showContinueCancelDialog(
           "Some of the URNs you entered cannot be found. They will be ignored:\n\n"
               + StringUtilities.join("\n", missingUrns),
           "Missing URNs",
           null,
           Dialogs.DialogIcon.INFORMATION)) {
         return;
       }
     }
     DocumentUtilities.selectDocuments(validUrns);
   } finally {
     progressListener.setProgress(1.0);
   }
 }
  public void testGetText() throws Exception {
    PlainDocument doc = new PlainDocument();
    CharSequence text = DocumentUtilities.getText(doc);
    assertEquals(1, text.length());
    assertEquals('\n', text.charAt(0));

    text = DocumentUtilities.getText(doc);
    doc.insertString(0, "a\nb", null);
    for (int i = 0; i < doc.getLength() + 1; i++) {
      assertEquals(doc.getText(i, 1).charAt(0), text.charAt(i));
    }
  }
 public void testDebugOffset() throws Exception {
   PlainDocument doc = new PlainDocument(); // tabSize is 8
   //                   0123 45 678 90123456 789
   doc.insertString(0, "abc\na\tbc\nabcdefg\thij", null);
   assertEquals("0[1:1]", DocumentUtilities.debugOffset(doc, 0));
   assertEquals("5[2:2]", DocumentUtilities.debugOffset(doc, 5));
   assertEquals("6[2:9]", DocumentUtilities.debugOffset(doc, 6));
   assertEquals("7[2:10]", DocumentUtilities.debugOffset(doc, 7));
   assertEquals("16[3:8]", DocumentUtilities.debugOffset(doc, 16));
   assertEquals("17[3:9]", DocumentUtilities.debugOffset(doc, 17));
   assertEquals("19[3:11]", DocumentUtilities.debugOffset(doc, 19));
 }
  public void testIsWriteLocked() throws Exception {
    PlainDocument doc = new PlainDocument();
    assertFalse(DocumentUtilities.isWriteLocked(doc));
    doc.addDocumentListener(
        new DocumentListener() {
          public void insertUpdate(DocumentEvent evt) {
            assertTrue(DocumentUtilities.isWriteLocked(evt.getDocument()));
          }

          public void removeUpdate(DocumentEvent evt) {}

          public void changedUpdate(DocumentEvent evt) {}
        });
    doc.insertString(0, "test", null);
  }