Ejemplo n.º 1
0
 private void highlightUsages() {
   if (mySearchResults.getEditor() == null) return;
   if (mySearchResults.getMatchesCount() >= mySearchResults.getMatchesLimit()) return;
   for (FindResult range : mySearchResults.getOccurrences()) {
     TextAttributes attributes =
         EditorColorsManager.getInstance()
             .getGlobalScheme()
             .getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES);
     if (range.getLength() == 0) {
       attributes = attributes.clone();
       attributes.setEffectType(EffectType.BOXED);
       attributes.setEffectColor(attributes.getBackgroundColor());
     }
     if (mySearchResults.isExcluded(range)) {
       highlightRange(range, strikout(attributes), myHighlighters);
     } else {
       highlightRange(range, attributes, myHighlighters);
     }
   }
   updateInSelectionHighlighters();
   if (!myListeningSelection) {
     mySearchResults.getEditor().getSelectionModel().addSelectionListener(this);
     myListeningSelection = true;
   }
 }
Ejemplo n.º 2
0
 private void paintBorder(RangeHighlighterEx rangeHighlighter, TextAttributes textAttributes) {
   paintBorder(
       textAttributes.getEffectColor(),
       rangeHighlighter.getAffectedAreaStartOffset(),
       rangeHighlighter.getAffectedAreaEndOffset(),
       textAttributes.getEffectType());
 }
  private void writeAttributes(Element attrElements) throws WriteExternalException {
    List<TextAttributesKey> list = new ArrayList<TextAttributesKey>(myAttributesMap.keySet());
    Collections.sort(list);

    for (TextAttributesKey key : list) {
      TextAttributes defaultAttr =
          myParentScheme != null ? myParentScheme.getAttributes(key) : new TextAttributes();
      TextAttributesKey baseKey = key.getFallbackAttributeKey();
      TextAttributes defaultFallbackAttr =
          baseKey != null && myParentScheme instanceof AbstractColorsScheme
              ? ((AbstractColorsScheme) myParentScheme).getFallbackAttributes(baseKey)
              : null;
      TextAttributes value = myAttributesMap.get(key);
      if (!value.equals(defaultAttr) || defaultAttr == defaultFallbackAttr) {
        Element element = new Element(OPTION_ELEMENT);
        element.setAttribute(NAME_ATTR, key.getExternalName());
        if (baseKey == null || !value.isFallbackEnabled()) {
          Element valueElement = new Element(VALUE_ELEMENT);
          value.writeExternal(valueElement);
          element.addContent(valueElement);
          attrElements.addContent(element);
        } else if (defaultAttr != defaultFallbackAttr) {
          element.setAttribute(BASE_ATTRIBUTES_ATTR, baseKey.getExternalName());
          attrElements.addContent(element);
        }
      }
    }
  }
  public static void printToConsole(
      @NotNull final LanguageConsoleImpl console,
      @NotNull final String string,
      @NotNull final ConsoleViewContentType mainType,
      @Nullable ConsoleViewContentType additionalType) {
    final TextAttributes mainAttributes = mainType.getAttributes();
    final TextAttributes attributes;
    if (additionalType == null) {
      attributes = mainAttributes;
    } else {
      attributes = additionalType.getAttributes().clone();
      attributes.setBackgroundColor(mainAttributes.getBackgroundColor());
    }

    Application application = ApplicationManager.getApplication();
    if (application.isDispatchThread()) {
      console.printToHistory(string, attributes);
    } else {
      application.invokeLater(
          new Runnable() {
            public void run() {
              console.printToHistory(string, attributes);
            }
          },
          ModalityState.stateForComponent(console.getComponent()));
    }
  }
  public void execute(final String line, final int textEndOffset) {
    myResult = null;
    myInfo = parseExceptionLine(line);
    if (myInfo == null) {
      return;
    }

    myMethod = myInfo.getSecond().substring(line);

    final int lparenthIndex = myInfo.third.getStartOffset();
    final int rparenthIndex = myInfo.third.getEndOffset();
    final String fileAndLine = line.substring(lparenthIndex + 1, rparenthIndex).trim();

    final int colonIndex = fileAndLine.lastIndexOf(':');
    if (colonIndex < 0) return;

    final String lineString = fileAndLine.substring(colonIndex + 1);
    try {
      final int lineNumber = Integer.parseInt(lineString);
      myClass = findPositionClass(line);
      myFile =
          myClass == null ? null : (PsiFile) myClass.getContainingFile().getNavigationElement();
      if (myFile == null) {
        // try find the file with the required name
        PsiFile[] files =
            PsiShortNamesCache.getInstance(myProject)
                .getFilesByName(fileAndLine.substring(0, colonIndex).trim());
        if (files.length > 0) {
          myFile = files[0];
        }
      }
      if (myFile == null) return;

      /*
       IDEADEV-4976: Some scramblers put something like SourceFile mock instead of real class name.
      final String filePath = fileAndLine.substring(0, colonIndex).replace('/', File.separatorChar);
      final int slashIndex = filePath.lastIndexOf(File.separatorChar);
      final String shortFileName = slashIndex < 0 ? filePath : filePath.substring(slashIndex + 1);
      if (!file.getName().equalsIgnoreCase(shortFileName)) return null;
      */

      final int textStartOffset = textEndOffset - line.length();

      final int highlightStartOffset = textStartOffset + lparenthIndex + 1;
      final int highlightEndOffset = textStartOffset + rparenthIndex;
      final VirtualFile virtualFile = myFile.getVirtualFile();

      HyperlinkInfo linkInfo = new MyHyperlinkInfo(myProject, virtualFile, lineNumber);

      TextAttributes attributes = HYPERLINK_ATTRIBUTES.clone();
      if (!ProjectRootManager.getInstance(myProject).getFileIndex().isInContent(virtualFile)) {
        Color color = UIUtil.getInactiveTextColor();
        attributes.setForegroundColor(color);
        attributes.setEffectColor(color);
      }
      myResult = new Filter.Result(highlightStartOffset, highlightEndOffset, linkInfo, attributes);
    } catch (NumberFormatException e) {
      //
    }
  }
  private void migrateErrorStripeColorFrom14(
      @NotNull TextAttributesKey name, @NotNull TextAttributes attr) {
    if (myVersion >= 141 || myParentScheme == null) return;

    Couple<Color> m = DEFAULT_STRIPE_COLORS.get(name.getExternalName());
    if (m != null && Comparing.equal(m.first, attr.getErrorStripeColor())) {
      attr.setErrorStripeColor(m.second);
    }
  }
Ejemplo n.º 7
0
 @Override
 public boolean equals(final TextAttributes attributes1, final TextAttributes attributes2) {
   Color effectColor = attributes1.getEffectColor();
   EffectType effectType = attributes1.getEffectType();
   return effectColor != null
       && effectColor.equals(attributes2.getEffectColor())
       && (EffectType.BOXED == effectType || EffectType.ROUNDED_BOX == effectType)
       && effectType == attributes2.getEffectType();
 }
 @Override
 public TextAttributes getTextAttributes() {
   TextAttributes ta = myIterators[0].iterator.getTextAttributes();
   myMergedAttributes.setAttributes(
       ta.getForegroundColor(), ta.getBackgroundColor(), null, null, null, ta.getFontType());
   for (int i = 1; i < overlappingRangesCount; i++) {
     merge(myIterators[i].iterator.getTextAttributes());
   }
   return myMergedAttributes;
 }
  private void readScheme(Element node) {
    myDeprecatedBackgroundColor = null;
    if (!SCHEME_ELEMENT.equals(node.getName())) {
      return;
    }

    setName(node.getAttributeValue(NAME_ATTR));
    int readVersion = Integer.parseInt(node.getAttributeValue(VERSION_ATTR, "0"));
    if (readVersion > CURR_VERSION) {
      throw new IllegalStateException("Unsupported color scheme version: " + readVersion);
    }

    myVersion = readVersion;
    String isDefaultScheme = node.getAttributeValue(DEFAULT_SCHEME_ATTR);
    boolean isDefault = isDefaultScheme != null && Boolean.parseBoolean(isDefaultScheme);
    if (!isDefault) {
      myParentScheme =
          DefaultColorSchemesManager.getInstance()
              .getScheme(node.getAttributeValue(PARENT_SCHEME_ATTR, DEFAULT_SCHEME_NAME));
    }

    for (final Object o : node.getChildren()) {
      Element childNode = (Element) o;
      String childName = childNode.getName();
      if (OPTION_ELEMENT.equals(childName)) {
        readSettings(childNode, isDefault);
      } else if (EDITOR_FONT.equals(childName)) {
        readFontSettings(childNode, myFontPreferences, isDefault);
      } else if (CONSOLE_FONT.equals(childName)) {
        readFontSettings(childNode, myConsoleFontPreferences, isDefault);
      } else if (COLORS_ELEMENT.equals(childName)) {
        readColors(childNode);
      } else if (ATTRIBUTES_ELEMENT.equals(childName)) {
        readAttributes(childNode);
      }
    }

    if (myDeprecatedBackgroundColor != null) {
      TextAttributes textAttributes = myAttributesMap.get(HighlighterColors.TEXT);
      if (textAttributes == null) {
        textAttributes =
            new TextAttributes(
                Color.black, myDeprecatedBackgroundColor, null, EffectType.BOXED, Font.PLAIN);
        myAttributesMap.put(HighlighterColors.TEXT, textAttributes);
      } else {
        textAttributes.setBackgroundColor(myDeprecatedBackgroundColor);
      }
    }

    if (myConsoleFontPreferences.getEffectiveFontFamilies().isEmpty()) {
      myFontPreferences.copyTo(myConsoleFontPreferences);
    }

    initFonts();
  }
  private void highlightInjectedSyntax(
      @NotNull PsiFile injectedPsi, @NotNull HighlightInfoHolder holder) {
    List<Trinity<IElementType, SmartPsiElementPointer<PsiLanguageInjectionHost>, TextRange>>
        tokens = InjectedLanguageUtil.getHighlightTokens(injectedPsi);
    if (tokens == null) return;

    final Language injectedLanguage = injectedPsi.getLanguage();
    Project project = injectedPsi.getProject();
    SyntaxHighlighter syntaxHighlighter =
        SyntaxHighlighterFactory.getSyntaxHighlighter(
            injectedLanguage, project, injectedPsi.getVirtualFile());
    final TextAttributes defaultAttrs = myGlobalScheme.getAttributes(HighlighterColors.TEXT);

    for (Trinity<IElementType, SmartPsiElementPointer<PsiLanguageInjectionHost>, TextRange> token :
        tokens) {
      ProgressManager.checkCanceled();
      IElementType tokenType = token.getFirst();
      PsiLanguageInjectionHost injectionHost = token.getSecond().getElement();
      if (injectionHost == null) continue;
      TextRange textRange = token.getThird();
      TextAttributesKey[] keys = syntaxHighlighter.getTokenHighlights(tokenType);
      if (textRange.getLength() == 0) continue;

      TextRange annRange = textRange.shiftRight(injectionHost.getTextRange().getStartOffset());
      // force attribute colors to override host' ones
      TextAttributes attributes = null;
      for (TextAttributesKey key : keys) {
        TextAttributes attrs2 = myGlobalScheme.getAttributes(key);
        if (attrs2 != null) {
          attributes = attributes == null ? attrs2 : TextAttributes.merge(attributes, attrs2);
        }
      }
      TextAttributes forcedAttributes;
      if (attributes == null || attributes.isEmpty() || attributes.equals(defaultAttrs)) {
        forcedAttributes = TextAttributes.ERASE_MARKER;
      } else {
        HighlightInfo info =
            HighlightInfo.newHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT)
                .range(annRange)
                .textAttributes(TextAttributes.ERASE_MARKER)
                .createUnconditionally();
        holder.add(info);

        forcedAttributes =
            new TextAttributes(
                attributes.getForegroundColor(),
                attributes.getBackgroundColor(),
                attributes.getEffectColor(),
                attributes.getEffectType(),
                attributes.getFontType());
      }

      HighlightInfo info =
          HighlightInfo.newHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT)
              .range(annRange)
              .textAttributes(forcedAttributes)
              .createUnconditionally();
      holder.add(info);
    }
  }
 protected TextAttributes getFallbackAttributes(TextAttributesKey fallbackKey) {
   if (fallbackKey == null) return null;
   TextAttributes fallbackAttributes = getDirectlyDefinedAttributes(fallbackKey);
   if (fallbackAttributes != null) {
     if (!fallbackAttributes.isFallbackEnabled()
         || fallbackKey.getFallbackAttributeKey() == null) {
       return fallbackAttributes;
     }
   }
   return getFallbackAttributes(fallbackKey.getFallbackAttributeKey());
 }
Ejemplo n.º 12
0
 @Nullable
 public Color getPolygonColor(Editor editor) {
   if (isApplied()) {
     return getLegendColor(editor.getColorsScheme());
   } else if (isInlineWrapper()) {
     return getBgColorForFragmentContainingInlines((EditorEx) editor);
   } else {
     TextAttributes attributes = getTextAttributes(editor);
     return attributes == null ? null : attributes.getBackgroundColor();
   }
 }
Ejemplo n.º 13
0
 @Nullable
 private Color getBgColorForFragmentContainingInlines(@NotNull EditorEx editor) {
   TextAttributes originalAttrs = getTextAttributes(editor.getColorsScheme());
   if (originalAttrs == null) {
     return null;
   }
   Color fg = originalAttrs.getBackgroundColor();
   if (fg == null) {
     return null;
   }
   Color bg = editor.getBackgroundColor();
   return getMiddleColor(fg, bg, MIDDLE_COLOR_FACTOR);
 }
Ejemplo n.º 14
0
 /** Patches attributes to be visible under debugger active line */
 @SuppressWarnings("UseJBColor")
 public static TextAttributes patchAttributesColor(
     TextAttributes attributes, @NotNull TextRange range, @NotNull Editor editor) {
   if (attributes.getForegroundColor() == null && attributes.getEffectColor() == null)
     return attributes;
   MarkupModel model =
       DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false);
   if (model != null) {
     if (!((MarkupModelEx) model)
         .processRangeHighlightersOverlappingWith(
             range.getStartOffset(),
             range.getEndOffset(),
             highlighter -> {
               if (highlighter.isValid()
                   && highlighter.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) {
                 TextAttributes textAttributes = highlighter.getTextAttributes();
                 if (textAttributes != null) {
                   Color color = textAttributes.getBackgroundColor();
                   return !(color != null
                       && color.getBlue() > 128
                       && color.getRed() < 128
                       && color.getGreen() < 128);
                 }
               }
               return true;
             })) {
       TextAttributes clone = attributes.clone();
       clone.setForegroundColor(Color.orange);
       clone.setEffectColor(Color.orange);
       return clone;
     }
   }
   return attributes;
 }
 public void advance() {
   if (mySegmentIterator.atEnd()) {
     myRangeIterator.advance();
     TextAttributes textAttributes = myRangeIterator.getTextAttributes();
     myCurrentFontStyle = textAttributes == null ? Font.PLAIN : textAttributes.getFontType();
     myCurrentForegroundColor =
         textAttributes == null ? null : textAttributes.getForegroundColor();
     myCurrentBackgroundColor =
         textAttributes == null ? null : textAttributes.getBackgroundColor();
     mySegmentIterator.reset(
         myRangeIterator.getRangeStart(), myRangeIterator.getRangeEnd(), myCurrentFontStyle);
   }
   mySegmentIterator.advance();
 }
  public static RangeHighlighter highlightRangeComment(
      Comment.Range range, Editor editor, Project project) {
    CharSequence charsSequence = editor.getMarkupModel().getDocument().getCharsSequence();

    RangeUtils.Offset offset = RangeUtils.rangeToTextOffset(charsSequence, range);

    TextAttributes attributes = new TextAttributes();
    attributes.setBackgroundColor(JBColor.YELLOW);
    ArrayList<RangeHighlighter> highlighters = Lists.newArrayList();
    HighlightManager highlightManager = HighlightManager.getInstance(project);
    highlightManager.addRangeHighlight(
        editor, offset.start, offset.end, attributes, false, highlighters);
    return highlighters.get(0);
  }
 static {
   DEFINED_CONSTANTS_ATTR.setForegroundColor(Color.MAGENTA);
   UPVAL_ATTR.setFontType(SimpleTextAttributes.STYLE_ITALIC);
   LONGSTRING_ATTR.setBackgroundColor(new Color(0xD0, 0xD0, 0xD0));
   GLOBAL_VAR_ATTR.setForegroundColor(new Color(128, 0, 0));
   LOCAL_VAR_ATTR.setForegroundColor(new Color(0, 153, 153));
   PARAMETER_ATTR.setForegroundColor(new Color(153, 102, 255));
   LUADOC_ATTR.setForegroundColor(new Color(64, 95, 189));
   LUADOC_TAG_ATTR.setForegroundColor(new Color(64, 95, 189));
   LUADOC_VALUE_ATTR.setForegroundColor(new Color(64, 95, 189));
 }
Ejemplo n.º 18
0
 @Nullable
 public TextAttributes getTextAttributes(@NotNull Editor editor) {
   TextAttributes originalAttrs = getTextAttributes(editor.getColorsScheme());
   if (originalAttrs == null) {
     return null;
   }
   TextAttributes overridingAttributes = new TextAttributes();
   if (myApplied) {
     overridingAttributes.setBackgroundColor(((EditorEx) editor).getBackgroundColor());
   } else if (myInlineWrapper) {
     overridingAttributes.setBackgroundColor(
         getBgColorForFragmentContainingInlines((EditorEx) editor));
   }
   return TextAttributes.merge(originalAttrs, overridingAttributes);
 }
 private void merge(TextAttributes attributes) {
   Color myBackground = myMergedAttributes.getBackgroundColor();
   if (myBackground == null || myDefaultBackground.equals(myBackground)) {
     myMergedAttributes.setBackgroundColor(attributes.getBackgroundColor());
   }
   Color myForeground = myMergedAttributes.getForegroundColor();
   if (myForeground == null || myDefaultForeground.equals(myForeground)) {
     myMergedAttributes.setForegroundColor(attributes.getForegroundColor());
   }
   if (myMergedAttributes.getFontType() == Font.PLAIN) {
     myMergedAttributes.setFontType(attributes.getFontType());
   }
 }
 private void findNextSuitableRange() {
   myNextAttributes = null;
   while (myIterator.hasNext()) {
     RangeHighlighterEx highlighter = myIterator.next();
     if (highlighter == null
         || !highlighter.isValid()
         || !isInterestedInLayer(highlighter.getLayer())) {
       continue;
     }
     // LINES_IN_RANGE highlighters are not supported currently
     myNextStart = Math.max(highlighter.getStartOffset(), myStartOffset);
     myNextEnd = Math.min(highlighter.getEndOffset(), myEndOffset);
     if (myNextStart >= myEndOffset) {
       break;
     }
     if (myNextStart < myCurrentEnd) {
       continue; // overlapping ranges withing document markup model are not supported currently
     }
     TextAttributes attributes = null;
     Object tooltip = highlighter.getErrorStripeTooltip();
     if (tooltip instanceof HighlightInfo) {
       HighlightInfo info = (HighlightInfo) tooltip;
       TextAttributesKey key = info.forcedTextAttributesKey;
       if (key == null) {
         HighlightInfoType type = info.type;
         key = type.getAttributesKey();
       }
       if (key != null) {
         attributes = myColorsScheme.getAttributes(key);
       }
     }
     if (attributes == null) {
       continue;
     }
     Color foreground = attributes.getForegroundColor();
     Color background = attributes.getBackgroundColor();
     if ((foreground == null || myDefaultForeground.equals(foreground))
         && (background == null || myDefaultBackground.equals(background))
         && attributes.getFontType() == Font.PLAIN) {
       continue;
     }
     myNextAttributes = attributes;
     break;
   }
 }
Ejemplo n.º 21
0
  public TextAttributes getTextAttributes() {
    if (myTextAttributes == null) {
      myTextAttributes = new TextAttributes();
      myTextAttributes.setBackgroundColor(
          myEditor.getColorsScheme().getColor(EditorColors.CARET_ROW_COLOR));
    }

    return myTextAttributes;
  }
Ejemplo n.º 22
0
 protected TextAttributes convertAttributes(@NotNull TextAttributesKey[] keys) {
   TextAttributes attrs = myScheme.getAttributes(HighlighterColors.TEXT);
   for (TextAttributesKey key : keys) {
     TextAttributes attrs2 = myScheme.getAttributes(key);
     if (attrs2 != null) {
       attrs = TextAttributes.merge(attrs, attrs2);
     }
   }
   return attrs;
 }
Ejemplo n.º 23
0
  @Nullable
  public Color getErrorStripeMarkColor(
      @NotNull PsiElement element,
      @Nullable final EditorColorsScheme colorsScheme) { // if null global scheme will be used
    if (forcedTextAttributes != null) {
      return forcedTextAttributes.getErrorStripeColor();
    }
    EditorColorsScheme scheme = getColorsScheme(colorsScheme);
    if (forcedTextAttributesKey != null) {
      TextAttributes forcedTextAttributes = scheme.getAttributes(forcedTextAttributesKey);
      if (forcedTextAttributes != null) {
        final Color errorStripeColor = forcedTextAttributes.getErrorStripeColor();
        // let's copy above behaviour of forcedTextAttributes stripe color, but I'm not sure that
        // the behaviour is correct in general
        if (errorStripeColor != null) {
          return errorStripeColor;
        }
      }
    }

    if (getSeverity() == HighlightSeverity.ERROR) {
      return scheme.getAttributes(CodeInsightColors.ERRORS_ATTRIBUTES).getErrorStripeColor();
    }
    if (getSeverity() == HighlightSeverity.WARNING) {
      return scheme.getAttributes(CodeInsightColors.WARNINGS_ATTRIBUTES).getErrorStripeColor();
    }
    if (getSeverity() == HighlightSeverity.INFO) {
      return scheme.getAttributes(CodeInsightColors.INFO_ATTRIBUTES).getErrorStripeColor();
    }
    if (getSeverity() == HighlightSeverity.WEAK_WARNING) {
      return scheme.getAttributes(CodeInsightColors.WEAK_WARNING_ATTRIBUTES).getErrorStripeColor();
    }
    if (getSeverity() == HighlightSeverity.GENERIC_SERVER_ERROR_OR_WARNING) {
      return scheme
          .getAttributes(CodeInsightColors.GENERIC_SERVER_ERROR_OR_WARNING)
          .getErrorStripeColor();
    }

    TextAttributes attributes = getAttributesByType(element, type, scheme);
    return attributes == null ? null : attributes.getErrorStripeColor();
  }
Ejemplo n.º 24
0
    @Override
    public boolean equals(final Object o) {
      if (this == o) return true;
      if (o == null || getClass() != o.getClass()) return false;

      final SeverityBasedTextAttributes that = (SeverityBasedTextAttributes) o;

      if (!myAttributes.equals(that.myAttributes)) return false;
      if (!myType.equals(that.myType)) return false;

      return true;
    }
  protected void updateImpl(PresentationData data) {
    super.updateImpl(data);
    String newName;
    if (myBuilder.getTodoTreeStructure().isPackagesShown()) {
      newName = getValue().getName();
    } else {
      newName =
          mySingleFileMode ? getValue().getName() : getValue().getVirtualFile().getPresentableUrl();
    }

    int nameEndOffset = newName.length();
    int todoItemCount;
    try {
      todoItemCount = myBuilder.getTodoTreeStructure().getTodoItemCount(getValue());
    } catch (IndexNotReadyException e) {
      return;
    }
    if (mySingleFileMode) {
      if (todoItemCount == 0) {
        newName = IdeBundle.message("node.todo.no.items.found", newName);
      } else {
        newName = IdeBundle.message("node.todo.found.items", newName, todoItemCount);
      }
    } else {
      newName = IdeBundle.message("node.todo.items", newName, todoItemCount);
    }

    myHighlightedRegions.clear();

    TextAttributes textAttributes = new TextAttributes();
    textAttributes.setForegroundColor(myColor);
    myHighlightedRegions.add(new HighlightedRegion(0, nameEndOffset, textAttributes));

    EditorColorsScheme colorsScheme = UsageTreeColorsScheme.getInstance().getScheme();
    myHighlightedRegions.add(
        new HighlightedRegion(
            nameEndOffset,
            newName.length(),
            colorsScheme.getAttributes(UsageTreeColors.NUMBER_OF_USAGES)));
  }
Ejemplo n.º 26
0
 /** Patches attributes to be visible under debugger active line */
 @SuppressWarnings("UseJBColor")
 private static TextAttributes patchAttributesColor(
     TextAttributes attributes, TextRange range, Editor editor) {
   int line = editor.offsetToLogicalPosition(range.getStartOffset()).line;
   for (RangeHighlighter highlighter : editor.getMarkupModel().getAllHighlighters()) {
     if (!highlighter.isValid()) continue;
     if (highlighter.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE
         && editor.offsetToLogicalPosition(highlighter.getStartOffset()).line == line) {
       TextAttributes textAttributes = highlighter.getTextAttributes();
       if (textAttributes != null) {
         Color color = textAttributes.getBackgroundColor();
         if (color != null
             && color.getBlue() > 128
             && color.getRed() < 128
             && color.getGreen() < 128) {
           TextAttributes clone = attributes.clone();
           clone.setForegroundColor(Color.orange);
           clone.setEffectColor(Color.orange);
           return clone;
         }
       }
     }
   }
   return attributes;
 }
Ejemplo n.º 27
0
  private static void highlightSearchLines(
      @NotNull Editor editor,
      @NotNull String pattern,
      int startLine,
      int endLine,
      boolean ignoreCase) {
    final TextAttributes color =
        editor.getColorsScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
    Collection<RangeHighlighter> highlighters = EditorData.getLastHighlights(editor);
    if (highlighters == null) {
      highlighters = new ArrayList<RangeHighlighter>();
      EditorData.setLastHighlights(editor, highlighters);
    }

    for (TextRange range : findAll(editor, pattern, startLine, endLine, ignoreCase)) {
      final RangeHighlighter highlighter =
          highlightMatch(editor, range.getStartOffset(), range.getEndOffset());
      highlighter.setErrorStripeMarkColor(color.getBackgroundColor());
      highlighter.setErrorStripeTooltip(pattern);
      highlighters.add(highlighter);
    }
  }
 @NotNull
 protected HighlightInfo.Builder getInfoBuilder(
     int colorIndex, @Nullable TextAttributesKey colorKey) {
   if (colorKey == null) {
     colorKey = DefaultLanguageHighlighterColors.LOCAL_VARIABLE;
   }
   return HighlightInfo.newHighlightInfo(RAINBOW_ELEMENT)
       .textAttributes(
           TextAttributes.fromFlyweight(
               myColorsScheme
                   .getAttributes(colorKey)
                   .getFlyweight()
                   .withForeground(calculateForeground(colorIndex))));
 }
Ejemplo n.º 29
0
 private void paintHighlighterAfterEndOfLine(Graphics2D g, RangeHighlighterEx highlighter) {
   if (!highlighter.isAfterEndOfLine()) {
     return;
   }
   int startOffset = highlighter.getStartOffset();
   int lineEndOffset = myDocument.getLineEndOffset(myDocument.getLineNumber(startOffset));
   if (myEditor.getFoldingModel().isOffsetCollapsed(lineEndOffset)) return;
   Point lineEnd = myView.offsetToXY(lineEndOffset, true, false);
   int x = lineEnd.x;
   int y = lineEnd.y;
   TextAttributes attributes = highlighter.getTextAttributes();
   paintBackground(g, attributes, x, y, myView.getPlainSpaceWidth());
   if (attributes != null
       && hasTextEffect(attributes.getEffectColor(), attributes.getEffectType())) {
     paintTextEffect(
         g,
         x,
         x + myView.getPlainSpaceWidth() - 1,
         y + myView.getAscent(),
         attributes.getEffectColor(),
         attributes.getEffectType());
   }
 }
Ejemplo n.º 30
0
 @NotNull
 private RangeHighlighter highlightRange(
     TextRange textRange, TextAttributes attributes, Set<RangeHighlighter> highlighters) {
   if (myInSmartUpdate) {
     for (RangeHighlighter highlighter : myHighlighters) {
       if (highlighter.isValid()
           && highlighter.getStartOffset() == textRange.getStartOffset()
           && highlighter.getEndOffset() == textRange.getEndOffset()) {
         if (attributes.equals(highlighter.getTextAttributes())) {
           highlighter.putUserData(MARKER_USED, YES);
           if (highlighters != myHighlighters) {
             highlighters.add(highlighter);
           }
           return highlighter;
         }
       }
     }
   }
   final RangeHighlighter highlighter = doHightlightRange(textRange, attributes, highlighters);
   if (myInSmartUpdate) {
     highlighter.putUserData(MARKER_USED, YES);
   }
   return highlighter;
 }