Java Code Examples for javax.swing.event.DocumentEvent#EventType

The following examples show how to use javax.swing.event.DocumentEvent#EventType . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DocumentUtilities.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Get string representation of an offset for debugging purposes
 * in form "offset[line:column]". Both lines and columns start counting from 1
 * like in the editor's status bar. Tabs are expanded when counting the column.
 *
 * @param sb valid string builder to which text will be appended or null in which case
 *  the method itself will create a string builder and it will return it.
 * @param evt non-null document event.
 * @return non-null string builder to which the description was added.
 * @since 1.27
 */
public static StringBuilder appendEvent(StringBuilder sb, DocumentEvent evt) {
    if (sb == null) {
        sb = new StringBuilder(100);
    }
    DocumentEvent.EventType type = evt.getType();
    sb.append(type).append(", ");
    appendOffset(sb, evt.getDocument(), evt.getOffset());
    sb.append(", l=").append(evt.getLength());
    // Possibly append the modification text
    String modText;
    if ((modText = getModificationText(evt)) != null) {
        sb.append(", modText=\"");
        CharSequenceUtilities.debugText(sb, modText);
        sb.append('"');
    }
    return sb;
}
 
Example 2
Source File: BaseDocumentEvent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Construct document event instance.
   * @param offset position in the document where the insert/remove/change
   *   occured
   * @param length number of the characters affected by the event
   * @param type type of the event - INSERT/REMOVE/CHANGE
   */
   public BaseDocumentEvent(BaseDocument doc, int offset, int length,
                            DocumentEvent.EventType type) {
       ((AbstractDocument)doc).super(offset, length, type);

hasBeenDone2 = true;
alive2 = true;
       inProgress2 = true;
   }
 
Example 3
Source File: BaseDocument.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected BaseDocumentEvent createDocumentEvent(int pos, int length,
        DocumentEvent.EventType type) {
    return new BaseDocumentEvent(this, pos, length, type);
}
 
Example 4
Source File: BaseDocument.java    From netbeans with Apache License 2.0 4 votes vote down vote up
final BaseDocumentEvent getDocumentEvent(int pos, int length, DocumentEvent.EventType type, AttributeSet attribs) {
    BaseDocumentEvent bde = createDocumentEvent(pos, length, type);
    bde.attachChangeAttribs(attribs);
    return bde;
}
 
Example 5
Source File: GuardedDocument.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected @Override BaseDocumentEvent createDocumentEvent(int offset, int length,
        DocumentEvent.EventType type) {
    return new GuardedDocumentEvent(this, offset, length, type);
}
 
Example 6
Source File: GuardedDocumentEvent.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public GuardedDocumentEvent(GuardedDocument doc, int offset, int length,
                            DocumentEvent.EventType type) {
    super(doc, offset, length, type);
}
 
Example 7
Source File: SearchableOptionsRegistrar.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public abstract ConfigurableHit getConfigurables(final Configurable[] allConfigurables,
                                                   final DocumentEvent.EventType type,
                                                   final Set<Configurable> configurables,
                                                   final String option,
                                                   final Project project);
 
Example 8
Source File: OptionsEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
public Promise<?> update(DocumentEvent.EventType type, boolean adjustSelection, boolean now) {
  if (!myUpdateEnabled) return Promises.rejectedPromise();

  final String text = mySearch.getText();
  if (getFilterText().length() == 0) {
    myContext.setHoldingFilter(false);
    myFiltered = null;
  }
  else {
    myContext.setHoldingFilter(true);
    myHits = myIndex.getConfigurables(myConfigurables, type, myFiltered, text, myProject);
    myFiltered = myHits.getAll();
  }

  if (myFiltered != null && myFiltered.isEmpty()) {
    mySearch.getTextEditor().setBackground(LightColors.RED);
  }
  else {
    mySearch.getTextEditor().setBackground(UIUtil.getTextFieldBackground());
  }


  final Configurable current = getContext().getCurrentConfigurable();

  boolean shouldMoveSelection = true;

  if (myHits != null && (myHits.getNameFullHits().contains(current) || myHits.getContentHits().contains(current))) {
    shouldMoveSelection = false;
  }

  if (shouldMoveSelection && type != DocumentEvent.EventType.INSERT && (myFiltered == null || myFiltered.contains(current))) {
    shouldMoveSelection = false;
  }

  Configurable toSelect = adjustSelection ? current : null;
  if (shouldMoveSelection && myHits != null) {
    if (!myHits.getNameHits().isEmpty()) {
      toSelect = suggestToSelect(myHits.getNameHits(), myHits.getNameFullHits());
    }
    else if (!myHits.getContentHits().isEmpty()) {
      toSelect = suggestToSelect(myHits.getContentHits(), null);
    }
  }

  updateSpotlight(false);

  if ((myFiltered == null || !myFiltered.isEmpty()) && toSelect == null && myLastSelected != null) {
    toSelect = myLastSelected;
    myLastSelected = null;
  }

  if (toSelect == null && current != null) {
    myLastSelected = current;
  }

  final Promise<?> callback = fireUpdate(adjustSelection ? myTree.findNodeFor(toSelect) : null, adjustSelection, now);

  myFilterDocumentWasChanged = true;

  return callback;
}
 
Example 9
Source File: SearchableOptionsRegistrarImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public ConfigurableHit getConfigurables(Configurable[] allConfigurables, final DocumentEvent.EventType type, Set<Configurable> configurables, String option, Project project) {

  final ConfigurableHit hits = new ConfigurableHit();
  final Set<Configurable> contentHits = hits.getContentHits();

  Set<String> options = getProcessedWordsWithoutStemming(option);
  if (configurables == null) {
    contentHits.addAll(SearchUtil.expandGroup(allConfigurables));
  }
  else {
    contentHits.addAll(configurables);
  }

  String optionToCheck = option.trim().toLowerCase();
  for (Configurable each : contentHits) {
    if (each.getDisplayName() == null) continue;
    final String displayName = each.getDisplayName().toLowerCase();
    final List<String> allWords = StringUtil.getWordsIn(displayName);
    if (displayName.contains(optionToCheck)) {
      hits.getNameFullHits().add(each);
      hits.getNameHits().add(each);
    }
    for (String eachWord : allWords) {
      if (eachWord.startsWith(optionToCheck)) {
        hits.getNameHits().add(each);
        break;
      }
    }

    if (options.isEmpty()) {
      hits.getNameHits().add(each);
      hits.getNameFullHits().add(each);
    }
  }

  final Set<Configurable> currentConfigurables = new HashSet<>(contentHits);
  if (options.isEmpty()) { //operate with substring
    String[] components = REG_EXP.split(optionToCheck);
    if (components.length > 0) {
      Collections.addAll(options, components);
    }
    else {
      options.add(option);
    }
  }
  Set<String> helpIds = null;
  for (String opt : options) {
    final Set<OptionDescription> optionIds = getAcceptableDescriptions(opt);
    if (optionIds == null) {
      contentHits.clear();
      return hits;
    }
    final Set<String> ids = new HashSet<>();
    for (OptionDescription id : optionIds) {
      ids.add(id.getConfigurableId());
    }
    if (helpIds == null) {
      helpIds = ids;
    }
    helpIds.retainAll(ids);
  }
  if (helpIds != null) {
    for (Iterator<Configurable> it = contentHits.iterator(); it.hasNext(); ) {
      Configurable configurable = it.next();
      if (CodeStyleFacade.getInstance(project).isUnsuitableCodeStyleConfigurable(configurable)) {
        it.remove();
        continue;
      }
      if (!(configurable instanceof SearchableConfigurable && helpIds.contains(((SearchableConfigurable)configurable).getId()))) {
        it.remove();
      }
    }
  }
  if (currentConfigurables.equals(contentHits) && !(configurables == null && type == DocumentEvent.EventType.CHANGE)) {
    return getConfigurables(allConfigurables, DocumentEvent.EventType.CHANGE, null, option, project);
  }
  return hits;
}