public static void appendColoredFragmentForMatcher(@NotNull String text, SimpleColoredComponent component, @NotNull final SimpleTextAttributes attributes, Matcher matcher, Color selectedBg, boolean selected) { if (!(matcher instanceof MinusculeMatcher) || (Registry.is("ide.highlight.match.in.selected.only") && !selected)) { component.append(text, attributes); return; } final Iterable<TextRange> iterable = ((MinusculeMatcher)matcher).matchingFragments(text); if (iterable != null) { final Color fg = attributes.getFgColor(); final int style = attributes.getStyle(); final SimpleTextAttributes plain = new SimpleTextAttributes(style, fg); final SimpleTextAttributes highlighted = new SimpleTextAttributes(selectedBg, fg, null, style | SimpleTextAttributes.STYLE_SEARCH_MATCH); appendColoredFragments(component, text, iterable, plain, highlighted); } else { component.append(text, attributes); } }
public static void appendColoredFragmentForMatcher(@NotNull final String text, final SimpleColoredComponent component, @NotNull final SimpleTextAttributes attributes, final Matcher matcher, final Color selectedBg, final boolean selected) { if (!(matcher instanceof MinusculeMatcher) || (Registry.is("ide.highlight.match.in.selected.only") && !selected)) { component.append(text, attributes); return; } final Iterable<TextRange> iterable = ((MinusculeMatcher)matcher).matchingFragments(text); if (iterable != null) { final Color fg = attributes.getFgColor(); final int style = attributes.getStyle(); final SimpleTextAttributes plain = new SimpleTextAttributes(style, fg); final SimpleTextAttributes highlighted = new SimpleTextAttributes(selectedBg, fg, null, style | SimpleTextAttributes.STYLE_SEARCH_MATCH); appendColoredFragments(component, text, iterable, plain, highlighted); } else { component.append(text, attributes); } }
public static void appendColoredFragmentForMatcher(@Nonnull String text, SimpleColoredComponent component, @Nonnull final SimpleTextAttributes attributes, Matcher matcher, Color selectedBg, boolean selected) { if (!(matcher instanceof MinusculeMatcher) || (Registry.is("ide.highlight.match.in.selected.only") && !selected)) { component.append(text, attributes); return; } final Iterable<TextRange> iterable = ((MinusculeMatcher)matcher).matchingFragments(text); if (iterable != null) { final Color fg = attributes.getFgColor(); final int style = attributes.getStyle(); final SimpleTextAttributes plain = new SimpleTextAttributes(style, fg); final SimpleTextAttributes highlighted = new SimpleTextAttributes(selectedBg, fg, null, style | SimpleTextAttributes.STYLE_SEARCH_MATCH); appendColoredFragments(component, text, iterable, plain, highlighted); } else { component.append(text, attributes); } }
String ellipsizeText(@NotNull String text, Matcher matcher) { final int textLength = text.length(); if (textLength > MAX_LENGTH) { if (matcher instanceof MinusculeMatcher) { FList iterable = ((MinusculeMatcher) matcher).matchingFragments(text); if (iterable != null) { TextRange textRange = (TextRange) iterable.getHead(); int startOffset = textRange.getStartOffset(); int startIndex = 0; int endIndex = textLength; if (startOffset > ELLIPSIS_EXTRA_LENGTH) { startIndex = startOffset - ELLIPSIS_EXTRA_LENGTH; } if (textLength > startIndex + MAX_LENGTH) { endIndex = startIndex + MAX_LENGTH; } String ellipsizedText = text.substring(startIndex, endIndex); if (startIndex > 0) { ellipsizedText = DOTS + ellipsizedText; } if (endIndex < textLength) { ellipsizedText = ellipsizedText + DOTS; } return ellipsizedText; } } } return text; }
private void fillStructure(StructureViewTreeElement element, List<StructureViewTreeElement> elements, Matcher matcher) { final TreeElement[] children = element.getChildren(); check(); for (TreeElement child : children) { check(); if (child instanceof StructureViewTreeElement) { final String text = child.getPresentation().getPresentableText(); if (text != null && matcher.matches(text)) { elements.add((StructureViewTreeElement)child); } fillStructure((StructureViewTreeElement)child, elements, matcher); } } }
private int detectBestStatisticalPosition() { if (myModel instanceof Comparator) { return 0; } int best = 0; int bestPosition = 0; int bestMatch = Integer.MIN_VALUE; final int count = myListModel.getSize(); Matcher matcher = buildPatternMatcher(transformPattern(getTrimmedText())); final String statContext = statisticsContext(); for (int i = 0; i < count; i++) { final Object modelElement = myListModel.getElementAt(i); String text = EXTRA_ELEM.equals(modelElement) || NON_PREFIX_SEPARATOR.equals(modelElement) ? null : myModel.getFullName(modelElement); if (text != null) { String shortName = myModel.getElementName(modelElement); int match = shortName != null && matcher instanceof MinusculeMatcher ? ((MinusculeMatcher)matcher).matchingDegree(shortName) : Integer.MIN_VALUE; int stats = StatisticsManager.getInstance().getUseCount(new StatisticsInfo(statContext, text)); if (match > bestMatch || match == bestMatch && stats > best) { best = stats; bestPosition = i; bestMatch = match; } } } if (bestPosition < count - 1 && myListModel.getElementAt(bestPosition) == NON_PREFIX_SEPARATOR) { bestPosition++; } return bestPosition; }
public static List<Task> filterTasks(final String pattern, final List<Task> tasks) { final Matcher matcher = getMatcher(pattern); return ContainerUtil.mapNotNull(tasks, new NullableFunction<Task, Task>() { public Task fun(Task task) { return matcher.matches(task.getId()) || matcher.matches(task.getSummary()) ? task : null; } }); }
private static Matcher getMatcher(String pattern) { StringTokenizer tokenizer = new StringTokenizer(pattern, " "); StringBuilder builder = new StringBuilder(); while (tokenizer.hasMoreTokens()) { String word = tokenizer.nextToken(); builder.append('*'); builder.append(word); builder.append("* "); } return NameUtil.buildMatcher(builder.toString(), NameUtil.MatchingCaseSensitivity.NONE); }
private int detectBestStatisticalPosition() { if (myModel instanceof Comparator) { return 0; } int best = 0; int bestPosition = 0; int bestMatch = Integer.MIN_VALUE; final int count = myListModel.getSize(); Matcher matcher = buildPatternMatcher(transformPattern(myTextField.getText())); final String statContext = statisticsContext(); for (int i = 0; i < count; i++) { final Object modelElement = myListModel.getElementAt(i); String text = EXTRA_ELEM.equals(modelElement) || NON_PREFIX_SEPARATOR.equals(modelElement) ? null : myModel.getFullName(modelElement); if (text != null) { String shortName = myModel.getElementName(modelElement); int match = shortName != null && matcher instanceof MinusculeMatcher ? ((MinusculeMatcher)matcher).matchingDegree(shortName) : Integer.MIN_VALUE; int stats = StatisticsManager.getInstance().getUseCount(new StatisticsInfo(statContext, text)); if (match > bestMatch || match == bestMatch && stats > best) { best = stats; bestPosition = i; bestMatch = match; } } } if (bestPosition < count - 1 && myListModel.getElementAt(bestPosition) == NON_PREFIX_SEPARATOR) { bestPosition++; } return bestPosition; }
private static synchronized MultiMap<String, Trinity<Matcher, String, String>> getAllFileNames(List<Trinity<Matcher, String, String>> input, final GotoFileModel model) { LinkedMultiMap<String, Trinity<Matcher, String, String>> map = new LinkedMultiMap<String, Trinity<Matcher, String, String>>(); for (String name : model.getNames(false)) { ProgressManager.checkCanceled(); for (Trinity<Matcher, String, String> trinity : input) { if (trinity.first.matches(name)) { map.putValue(name, trinity); } } } return map; }
public static List<Task> getItems(final TaskManager myManager, String pattern, boolean cached, boolean autopopup) { final Matcher matcher = getMatcher(pattern); return ContainerUtil.mapNotNull(getTasks(pattern, cached, autopopup, myManager), new NullableFunction<Task, Task>() { public Task fun(Task task) { return matcher.matches(task.getId()) || matcher.matches(task.getSummary()) ? task : null; } }); }
@Override public void setPatternMatcher(Matcher matcher) { this.matcher = matcher; }
private LeftCellRenderer(Matcher matcher) { this.matcher = matcher; }
@Nullable public Matcher getMatcher() { return myMatcher; }
@Override public void setPatternMatcher(Matcher matcher) { myMatcher = matcher; }
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component cmp; PsiElement file; myLocationString = null; String pattern = "*" + myPopupField.getText(); Matcher matcher = NameUtil.buildMatcher(pattern, 0, true, true); if (isMoreItem(index)) { cmp = More.get(isSelected); } else if (value instanceof VirtualFile && myProject != null && ((((VirtualFile)value).isDirectory() && (file = PsiManager.getInstance(myProject).findDirectory((VirtualFile)value)) != null ) || (file = PsiManager.getInstance(myProject).findFile((VirtualFile)value)) != null)) { myFileRenderer.setPatternMatcher(matcher); cmp = myFileRenderer.getListCellRendererComponent(list, file, index, isSelected, cellHasFocus); } else if (value instanceof PsiElement) { myFileRenderer.setPatternMatcher(matcher); cmp = myFileRenderer.getListCellRendererComponent(list, value, index, isSelected, isSelected); } else if (value instanceof GotoActionModel.ActionWrapper) { cmp = myActionsRenderer.getListCellRendererComponent(list, new GotoActionModel.MatchedValue(((GotoActionModel.ActionWrapper)value), pattern), index, isSelected, isSelected); } else { cmp = super.getListCellRendererComponent(list, value, index, isSelected, isSelected); final JPanel p = new JPanel(new BorderLayout()); p.setBackground(UIUtil.getListBackground(isSelected)); p.add(cmp, BorderLayout.CENTER); cmp = p; } if (myLocationString != null || value instanceof BooleanOptionDescription) { final JPanel panel = new JPanel(new BorderLayout()); panel.setBackground(UIUtil.getListBackground(isSelected)); panel.add(cmp, BorderLayout.CENTER); final Component rightComponent; if (value instanceof BooleanOptionDescription) { final OnOffButton button = new OnOffButton(); button.setSelected(((BooleanOptionDescription)value).isOptionEnabled()); rightComponent = button; } else { rightComponent = myLocation.getListCellRendererComponent(list, value, index, isSelected, isSelected); } panel.add(rightComponent, BorderLayout.EAST); cmp = panel; } Color bg = cmp.getBackground(); if (bg == null) { cmp.setBackground(UIUtil.getListBackground(isSelected)); bg = cmp.getBackground(); } myMainPanel.setBorder(new CustomLineBorder(bg, 0, 0, 2, 0)); String title = getModel().titleIndex.getTitle(index); myMainPanel.removeAll(); if (title != null) { myTitle.setText(title); myMainPanel.add(createTitle(" " + title), BorderLayout.NORTH); } myMainPanel.add(cmp, BorderLayout.CENTER); if (cmp instanceof Accessible) { myMainPanel.setAccessible((Accessible)cmp); } final int width = myMainPanel.getPreferredSize().width; if (width > myPopupActualWidth) { myPopupActualWidth = width; //schedulePopupUpdate(); } return myMainPanel; }
@Override public void setPatternMatcher(final Matcher matcher) { myMatcher = matcher; }
public LeftRenderer(final String moduleName, Matcher matcher) { myModuleName = moduleName; myMatcher = matcher; }
public LeftRenderer(boolean renderLocation, Matcher matcher) { myRenderLocation = renderLocation; myMatcher = matcher; }
protected void rebuildList(final int pos, final int delay, @NotNull final ModalityState modalityState, @Nullable final Runnable postRunnable) { ApplicationManager.getApplication().assertIsDispatchThread(); if (!myInitialized) { return; } myAlarm.cancelAllRequests(); if (delay > 0) { myAlarm.addRequest(new Runnable() { @Override public void run() { rebuildList(pos, 0, modalityState, postRunnable); } }, delay, ModalityState.stateForComponent(myTextField)); return; } myListUpdater.cancelAll(); final CalcElementsThread calcElementsThread = myCalcElementsThread; if (calcElementsThread != null) { calcElementsThread.cancel(); } final String text = getTrimmedText(); if (!canShowListForEmptyPattern() && text.isEmpty()) { myListModel.clear(); hideList(); myTextFieldPanel.hideHint(); myCard.show(myCardContainer, CHECK_BOX_CARD); return; } ListCellRenderer cellRenderer = myList.getCellRenderer(); if (cellRenderer instanceof ExpandedItemListCellRendererWrapper) { cellRenderer = ((ExpandedItemListCellRendererWrapper)cellRenderer).getWrappee(); } if (cellRenderer instanceof MatcherHolder) { final String pattern = patternToLowerCase(transformPattern(text)); final Matcher matcher = buildPatternMatcher(isSearchInAnyPlace() ? "*" + pattern : pattern); ((MatcherHolder)cellRenderer).setPatternMatcher(matcher); } scheduleCalcElements(text, myCheckBox.isSelected(), modalityState, new Consumer<Set<?>>() { @Override public void consume(Set<?> elements) { ApplicationManager.getApplication().assertIsDispatchThread(); backgroundCalculationFinished(elements, pos); if (postRunnable != null) { postRunnable.run(); } } }); }
private static Matcher buildPatternMatcher(@NotNull String pattern) { return NameUtil.buildMatcher(pattern, NameUtil.MatchingCaseSensitivity.NONE); }
protected void rebuildList(final int pos, final int delay, @NotNull final ModalityState modalityState, @Nullable final Runnable postRunnable) { ApplicationManager.getApplication().assertIsDispatchThread(); if (!myInitialized) { return; } myListIsUpToDate = false; myAlarm.cancelAllRequests(); myListUpdater.cancelAll(); cancelCalcElementsThread(); final String text = myTextField.getText(); if (!canShowListForEmptyPattern() && (text == null || text.trim().isEmpty())) { myListModel.clear(); hideList(); myTextFieldPanel.hideHint(); myCard.show(myCardContainer, CHECK_BOX_CARD); return; } ListCellRenderer cellRenderer = myList.getCellRenderer(); if (cellRenderer instanceof ExpandedItemListCellRendererWrapper) { cellRenderer = ((ExpandedItemListCellRendererWrapper)cellRenderer).getWrappee(); } if (cellRenderer instanceof MatcherHolder) { final String pattern = transformPattern(text); final Matcher matcher = buildPatternMatcher(isSearchInAnyPlace() ? "*" + pattern : pattern); ((MatcherHolder)cellRenderer).setPatternMatcher(matcher); } final Runnable request = new Runnable() { @Override public void run() { scheduleCalcElements(text, myCheckBox.isSelected(), postRunnable == null, modalityState, new Consumer<Set<?>>() { @Override public void consume(Set<?> elements) { synchronized (myRebuildMutex) { ApplicationManager.getApplication().assertIsDispatchThread(); if (checkDisposed()) { return; } myListIsUpToDate = true; setElementsToList(pos, elements); myList.repaint(); chosenElementMightChange(); if (elements.isEmpty()) { myTextFieldPanel.hideHint(); } if (postRunnable != null) { postRunnable.run(); } } } }); } }; if (delay > 0) { myAlarm.addRequest(request, delay, ModalityState.stateForComponent(myTextField)); } else { request.run(); } }
private static Matcher buildPatternMatcher(@NotNull String pattern) { return NameUtil.buildMatcher(pattern, 0, true, true, pattern.toLowerCase().equals(pattern)); }