Java 类com.intellij.ui.SimpleColoredComponent 实例源码

项目:intellij-ce-playground    文件:UnknownFileTypeDiffRequest.java   
@NotNull
@Override
public JComponent getComponent(@NotNull final DiffContext context) {
  final SimpleColoredComponent label = new SimpleColoredComponent();
  label.append("Can't show diff for unknown file type. ",
               new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, UIUtil.getInactiveTextColor()));
  if (myFileName != null) {
    label.append("Associate", SimpleTextAttributes.LINK_ATTRIBUTES, new Runnable() {
      @Override
      public void run() {
        DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, new Runnable() {
          @Override
          public void run() {
            FileType type = FileTypeChooser.associateFileType(myFileName);
            if (type != null) onSuccess(context);
          }
        });
      }
    });
    LinkMouseListenerBase.installSingleTagOn(label);
  }
  return DiffUtil.createMessagePanel(label);
}
项目:intellij-ce-playground    文件:SpeedSearchUtil.java   
public static void appendFragmentsForSpeedSearch(@NotNull JComponent speedSearchEnabledComponent,
                                                 @NotNull String text,
                                                 @NotNull SimpleTextAttributes attributes,
                                                 boolean selected,
                                                 @NotNull SimpleColoredComponent simpleColoredComponent) {
  final SpeedSearchSupply speedSearch = SpeedSearchSupply.getSupply(speedSearchEnabledComponent);
  if (speedSearch != null) {
    final Iterable<TextRange> fragments = speedSearch.matchingFragments(text);
    if (fragments != null) {
      final Color fg = attributes.getFgColor();
      final Color bg = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
      final int style = attributes.getStyle();
      final SimpleTextAttributes plain = new SimpleTextAttributes(style, fg);
      final SimpleTextAttributes highlighted = new SimpleTextAttributes(bg, fg, null, style | SimpleTextAttributes.STYLE_SEARCH_MATCH);
      appendColoredFragments(simpleColoredComponent, text, fragments, plain, highlighted);
      return;
    }
  }
  simpleColoredComponent.append(text, attributes);
}
项目:intellij-ce-playground    文件:SpeedSearchUtil.java   
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);
  }
}
项目:intellij-ce-playground    文件:LinkMouseListenerBase.java   
public static void installSingleTagOn(@NotNull SimpleColoredComponent component) {
  new LinkMouseListenerBase<Object>() {
    @Nullable
    @Override
    protected Object getTagAt(@NotNull MouseEvent e) {
      //noinspection unchecked
      return ((SimpleColoredComponent)e.getSource()).getFragmentTagAt(e.getX());
    }

    @Override
    protected void handleTagClick(@Nullable Object tag, @NotNull MouseEvent event) {
      if (tag != null) {
        if (tag instanceof Consumer) {
          //noinspection unchecked
          ((Consumer<MouseEvent>)tag).consume(event);
        }
        else {
          ((Runnable)tag).run();
        }
      }
    }
  }.installOn(component);
}
项目:intellij-ce-playground    文件:FixedHotfixGroupElement.java   
public FixedHotfixGroupElement(String name, Object data, VirtualFile file) {
  super(name, data, file);
  myCustomizeColoredTreeCellRenderer = new CustomizeColoredTreeCellRenderer() {
    public void customizeCellRenderer(SimpleColoredComponent renderer,
                                      JTree tree,
                                      Object value,
                                      boolean selected,
                                      boolean expanded,
                                      boolean leaf,
                                      int row,
                                      boolean hasFocus) {
      renderer.setIcon(AllIcons.General.Information);
      renderer.append("Fixed: ", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
      final String[] text = getText();
      final String checkedText = ((text != null) && (text.length > 0)) ? text[0] : "";
      renderer.append(checkedText, SimpleTextAttributes.REGULAR_ATTRIBUTES);
    }
  };
}
项目:intellij-ce-playground    文件:HotfixGroupElement.java   
public HotfixGroupElement(final String name, final Object data, final VirtualFile file, final Consumer<HotfixGate> hotfix,
                          final String fixDescription, final MutableErrorTreeView view) {
  super(name, data, file);
  myHotfix = hotfix;
  myFixDescription = fixDescription;
  myView = view;
  myLeftTreeCellRenderer = new CustomizeColoredTreeCellRenderer() {
    public void customizeCellRenderer(SimpleColoredComponent renderer,
                                      JTree tree,
                                      Object value,
                                      boolean selected,
                                      boolean expanded,
                                      boolean leaf,
                                      int row,
                                      boolean hasFocus) {
      renderer.setIcon(AllIcons.General.Error);

      final String[] text = getText();
      final String errorText = ((text != null) && (text.length > 0)) ? text[0] : "";
      renderer.append("Error: " + errorText, SimpleTextAttributes.REGULAR_ATTRIBUTES);
    }
  };
  myRightTreeCellRenderer = new MyRightRenderer();
}
项目:intellij-ce-playground    文件:SetValueInplaceEditor.java   
private SetValueInplaceEditor(final XValueNodeImpl node, @NotNull final String nodeName) {
  super(node, "setValue");
  myValueNode = node;
  myModifier = myValueNode.getValueContainer().getModifier();

  myEditorPanel = new JPanel();
  myEditorPanel.setLayout(new BorderLayout(0, 0));
  SimpleColoredComponent nameLabel = new SimpleColoredComponent();
  nameLabel.setIcon(getNode().getIcon());
  nameLabel.append(nodeName, XDebuggerUIConstants.VALUE_NAME_ATTRIBUTES);
  XValuePresentation presentation = node.getValuePresentation();
  if (presentation != null) {
    XValuePresentationUtil.appendSeparator(nameLabel, presentation.getSeparator());
  }
  myEditorPanel.add(nameLabel, BorderLayout.WEST);

  myEditorPanel.add(myExpressionEditor.getComponent(), BorderLayout.CENTER);
}
项目:intellij-ce-playground    文件:ShowUsagesTableCellRenderer.java   
private void appendGroupText(final GroupNode node, JPanel panel, Color fileBgColor) {
  UsageGroup group = node == null ? null : node.getGroup();
  if (group == null) return;
  GroupNode parentGroup = (GroupNode)node.getParent();
  appendGroupText(parentGroup, panel, fileBgColor);
  if (node.canNavigateToSource()) {
    SimpleColoredComponent renderer = new SimpleColoredComponent();

    renderer.setIcon(group.getIcon(false));
    SimpleTextAttributes attributes = deriveAttributesWithColor(SimpleTextAttributes.REGULAR_ATTRIBUTES, fileBgColor);
    renderer.append(group.getText(myUsageView), attributes);
    renderer.append(" ", attributes);
    renderer.setIpad(new Insets(0,0,0,0));
    renderer.setBorder(null);
    panel.add(renderer);
  }
}
项目:intellij-ce-playground    文件:AbstractFindUsagesDialog.java   
@Override
protected JComponent createNorthPanel() {
  JPanel panel = new JPanel(new GridBagLayout());
  GridBagConstraints gbConstraints = new GridBagConstraints();

  gbConstraints.insets = new Insets(0, 0, UIUtil.DEFAULT_VGAP, 0);
  gbConstraints.fill = GridBagConstraints.NONE;
  gbConstraints.weightx = 1;
  gbConstraints.weighty = 1;
  gbConstraints.anchor = GridBagConstraints.WEST;
  final SimpleColoredComponent coloredComponent = new SimpleColoredComponent();
  coloredComponent.setIpad(new Insets(0,0,0,0));
  coloredComponent.setMyBorder(null);
  configureLabelComponent(coloredComponent);
  panel.add(coloredComponent, gbConstraints);

  return panel;
}
项目:intellij-ce-playground    文件:PyModuleFindUsagesHandler.java   
@NotNull
@Override
public AbstractFindUsagesDialog getFindUsagesDialog(boolean isSingleFile, boolean toShowInNewTab, boolean mustOpenInNewTab) {
  return new CommonFindUsagesDialog(myElement,
                                    getProject(),
                                    getFindUsagesOptions(),
                                    toShowInNewTab,
                                    mustOpenInNewTab,
                                    isSingleFile,
                                    this) {
    @Override
    public void configureLabelComponent(@NotNull final SimpleColoredComponent coloredComponent) {
      coloredComponent.append(myElement instanceof PsiDirectory ? "Package " : "Module ");
      coloredComponent.append(myElement.getName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
    }
  };
}
项目:intellij-ce-playground    文件:RadGridLayoutComponent.java   
@Override
public void decorateTree(SimpleColoredComponent renderer, AttributeWrapper wrapper) {
  XmlTag tag = getTag();
  StringBuilder value = new StringBuilder(" (");

  String namespace = getGridLayoutNamespace(this);

  String rowCount = tag.getAttributeValue(ATTR_ROW_COUNT, namespace);
  value.append(StringUtil.isEmpty(rowCount) ? "?" : rowCount).append(", ");

  String columnCount = tag.getAttributeValue(ATTR_COLUMN_COUNT, namespace);
  value.append(StringUtil.isEmpty(columnCount) ? "?" : columnCount).append(", ");

  value.append(isHorizontal() ? VALUE_HORIZONTAL : VALUE_VERTICAL);

  renderer.append(value.append(")").toString(), wrapper.getAttribute(SimpleTextAttributes.REGULAR_ATTRIBUTES));
}
项目:tools-idea    文件:SpeedSearchUtil.java   
public static void appendFragmentsForSpeedSearch(@NotNull final JComponent speedSearchEnabledComponent, @NotNull final String text,
                                                 @NotNull final SimpleTextAttributes attributes, final boolean selected,
                                                 @NotNull final SimpleColoredComponent simpleColoredComponent) {
  final SpeedSearchSupply speedSearch = SpeedSearchSupply.getSupply(speedSearchEnabledComponent);
  if (speedSearch != null) {
    final Iterable<TextRange> fragments = speedSearch.matchingFragments(text);
    if (fragments != null) {
      final Color fg = attributes.getFgColor();
      final Color bg = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
      final int style = attributes.getStyle();
      final SimpleTextAttributes plain = new SimpleTextAttributes(style, fg);
      final SimpleTextAttributes highlighted = new SimpleTextAttributes(bg, fg, null, style | SimpleTextAttributes.STYLE_SEARCH_MATCH);
      appendColoredFragments(simpleColoredComponent, text, fragments, plain, highlighted);
      return;
    }
  }
  simpleColoredComponent.append(text, attributes);
}
项目:tools-idea    文件:SpeedSearchUtil.java   
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);
  }
}
项目:tools-idea    文件:FixedHotfixGroupElement.java   
public FixedHotfixGroupElement(String name, Object data, VirtualFile file) {
  super(name, data, file);
  myCustomizeColoredTreeCellRenderer = new CustomizeColoredTreeCellRenderer() {
    public void customizeCellRenderer(SimpleColoredComponent renderer,
                                      JTree tree,
                                      Object value,
                                      boolean selected,
                                      boolean expanded,
                                      boolean leaf,
                                      int row,
                                      boolean hasFocus) {
      renderer.setIcon(AllIcons.General.Information);
      renderer.append("Fixed: ", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
      final String[] text = getText();
      final String checkedText = ((text != null) && (text.length > 0)) ? text[0] : "";
      renderer.append(checkedText, SimpleTextAttributes.REGULAR_ATTRIBUTES);
    }
  };
}
项目:tools-idea    文件:HotfixGroupElement.java   
public HotfixGroupElement(final String name, final Object data, final VirtualFile file, final Consumer<HotfixGate> hotfix,
                          final String fixDescription, final MutableErrorTreeView view) {
  super(name, data, file);
  myHotfix = hotfix;
  myFixDescription = fixDescription;
  myView = view;
  myLeftTreeCellRenderer = new CustomizeColoredTreeCellRenderer() {
    public void customizeCellRenderer(SimpleColoredComponent renderer,
                                      JTree tree,
                                      Object value,
                                      boolean selected,
                                      boolean expanded,
                                      boolean leaf,
                                      int row,
                                      boolean hasFocus) {
      renderer.setIcon(AllIcons.General.Error);

      final String[] text = getText();
      final String errorText = ((text != null) && (text.length > 0)) ? text[0] : "";
      renderer.append("Error: " + errorText, SimpleTextAttributes.REGULAR_ATTRIBUTES);
    }
  };
  myRightTreeCellRenderer = new MyRightRenderer();
}
项目:tools-idea    文件:ArrangementStandardSettingsManager.java   
public ArrangementStandardSettingsManager(@NotNull ArrangementStandardSettingsAware delegate,
                                          @NotNull ArrangementColorsProvider colorsProvider)
{
  myDelegate = delegate;
  myColorsProvider = colorsProvider;
  myMutexes = delegate.getMutexes();
  myDefaultSettings = delegate.getDefaultSettings();

  SimpleColoredComponent renderer = new SimpleColoredComponent();
  myGroupingTokens = delegate.getSupportedGroupingTokens();
  if (myGroupingTokens != null) {
    parseWidths(myGroupingTokens, renderer);
    buildWeights(myGroupingTokens);
  }

  myMatchingTokens = delegate.getSupportedMatchingTokens();
  if (myMatchingTokens != null) {
    parseWidths(myMatchingTokens, renderer);
    buildWeights(myMatchingTokens);
  }
}
项目:tools-idea    文件:SetValueInplaceEditor.java   
public SetValueInplaceEditor(final XValueNodeImpl node, @NotNull final String nodeName) {
  super(node, "setValue");
  myValueNode = node;
  myModifier = myValueNode.getValueContainer().getModifier();

  myEditorPanel = new JPanel();
  myEditorPanel.setLayout(new BorderLayout(0, 0));
  SimpleColoredComponent nameLabel = new SimpleColoredComponent();
  nameLabel.setIcon(getNode().getIcon());
  nameLabel.append(nodeName, XDebuggerUIConstants.VALUE_NAME_ATTRIBUTES);
  final String separator = node.getSeparator();
  if (separator != null) {
    nameLabel.append(separator, SimpleTextAttributes.REGULAR_ATTRIBUTES);
  }

  myEditorPanel.add(nameLabel, BorderLayout.WEST);

  myEditorPanel.add(myExpressionEditor.getComponent(), BorderLayout.CENTER);
  final String value = myModifier != null ? myModifier.getInitialValueEditorText() : null;
  myExpressionEditor.setText(value != null ? value : "");
  myExpressionEditor.selectAll();
}
项目:tools-idea    文件:ApplyPatchDifferentiatedDialog.java   
public void decorate(Change change, SimpleColoredComponent component, boolean isShowFlatten) {
  if (change instanceof FilePatchInProgress.PatchChange) {
    final FilePatchInProgress.PatchChange patchChange = (FilePatchInProgress.PatchChange) change;
    if (! isShowFlatten) {
      // add change subpath
      final TextFilePatch filePatch = patchChange.getPatchInProgress().getPatch();
      final String patchPath = filePatch.getAfterName() == null ? filePatch.getBeforeName() : filePatch.getAfterName();
      component.append("   ");
      component.append("["+ patchPath + "]", SimpleTextAttributes.GRAY_ATTRIBUTES);
    }
    if (patchChange.getPatchInProgress().getCurrentStrip() > 0) {
      component.append(" stripped " + patchChange.getPatchInProgress().getCurrentStrip(), SimpleTextAttributes.GRAY_ITALIC_ATTRIBUTES);
    }
    final String text;
    if (FilePatchStatus.ADDED.equals(patchChange.getPatchInProgress().getStatus())) {
      text = "(Added)";
    } else if (FilePatchStatus.DELETED.equals(patchChange.getPatchInProgress().getStatus())) {
      text = "(Deleted)";
    } else {
      text = "(Modified)";
    }
    component.append("   ");
    component.append(text, SimpleTextAttributes.GRAY_ATTRIBUTES);
  }
}
项目:tools-idea    文件:ShowUsagesTableCellRenderer.java   
private void appendGroupText(final GroupNode node, JPanel panel, Color fileBgColor) {
  UsageGroup group = node == null ? null : node.getGroup();
  if (group == null) return;
  GroupNode parentGroup = (GroupNode)node.getParent();
  appendGroupText(parentGroup, panel, fileBgColor);
  if (node.canNavigateToSource()) {
    SimpleColoredComponent renderer = new SimpleColoredComponent();

    renderer.setIcon(group.getIcon(false));
    SimpleTextAttributes attributes = deriveAttributesWithColor(SimpleTextAttributes.REGULAR_ATTRIBUTES, fileBgColor);
    renderer.append(group.getText(myUsageView), attributes);
    renderer.append(" ", attributes);
    renderer.setIpad(new Insets(0,0,0,0));
    renderer.setBorder(null);
    panel.add(renderer);
  }
}
项目:tools-idea    文件:AbstractFindUsagesDialog.java   
@Override
protected JComponent createNorthPanel() {
  JPanel panel = new JPanel(new GridBagLayout());
  GridBagConstraints gbConstraints = new GridBagConstraints();

  gbConstraints.insets = new Insets(0, 0, UIUtil.DEFAULT_VGAP, 0);
  gbConstraints.fill = GridBagConstraints.NONE;
  gbConstraints.weightx = 1;
  gbConstraints.weighty = 1;
  gbConstraints.anchor = GridBagConstraints.WEST;
  final SimpleColoredComponent coloredComponent = new SimpleColoredComponent();
  coloredComponent.setIpad(new Insets(0,0,0,0));
  coloredComponent.setMyBorder(null);
  configureLabelComponent(coloredComponent);
  panel.add(coloredComponent, gbConstraints);

  return panel;
}
项目:cordovastudio    文件:RadGridLayoutComponent.java   
@Override
public void decorateTree(SimpleColoredComponent renderer, AttributeWrapper wrapper) {
    XmlTag tag = getTag();
    StringBuilder value = new StringBuilder(" (");

    String namespace = getGridLayoutNamespace(this);

    String rowCount = tag.getAttributeValue(ATTR_ROW_COUNT, namespace);
    value.append(StringUtil.isEmpty(rowCount) ? "?" : rowCount).append(", ");

    String columnCount = tag.getAttributeValue(ATTR_COLUMN_COUNT, namespace);
    value.append(StringUtil.isEmpty(columnCount) ? "?" : columnCount).append(", ");

    value.append(isHorizontal() ? VALUE_HORIZONTAL : VALUE_VERTICAL);

    renderer.append(value.append(")").toString(), wrapper.getAttribute(SimpleTextAttributes.REGULAR_ATTRIBUTES));
}
项目:dagger-intellij-plugin    文件:ShowUsagesTableCellRenderer.java   
private void appendGroupText(final GroupNode node, JPanel panel, Color fileBgColor) {
  UsageGroup group = node == null ? null : node.getGroup();
  if (group == null) return;
  GroupNode parentGroup = (GroupNode) node.getParent();
  appendGroupText(parentGroup, panel, fileBgColor);
  if (node.canNavigateToSource()) {
    SimpleColoredComponent renderer = new SimpleColoredComponent();

    renderer.setIcon(group.getIcon(false));
    SimpleTextAttributes attributes =
        deriveAttributesWithColor(SimpleTextAttributes.REGULAR_ATTRIBUTES, fileBgColor);
    renderer.append(group.getText(myUsageView), attributes);
    renderer.append(" ", attributes);
    renderer.setIpad(new Insets(0, 0, 0, 0));
    renderer.setBorder(null);
    panel.add(renderer);
  }
}
项目:consulo    文件:UnknownFileTypeDiffRequest.java   
@Nonnull
@Override
public JComponent getComponent(@Nonnull final DiffContext context) {
  final SimpleColoredComponent label = new SimpleColoredComponent();
  label.setTextAlign(SwingConstants.CENTER);
  label.append("Can't show diff for unknown file type. ",
               new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, UIUtil.getInactiveTextColor()));
  if (myFileName != null) {
    label.append("Associate", SimpleTextAttributes.LINK_ATTRIBUTES, new Runnable() {
      @Override
      public void run() {
        FileType type = FileTypeChooser.associateFileType(myFileName);
        if (type != null) onSuccess(context);
      }
    });
    LinkMouseListenerBase.installSingleTagOn(label);
  }
  return JBUI.Panels.simplePanel(label).withBorder(JBUI.Borders.empty(5));
}
项目:consulo    文件:SpeedSearchUtil.java   
public static void appendFragmentsForSpeedSearch(@Nonnull JComponent speedSearchEnabledComponent,
                                                 @Nonnull String text,
                                                 @Nonnull SimpleTextAttributes attributes,
                                                 boolean selected,
                                                 @Nonnull SimpleColoredComponent simpleColoredComponent) {
  final SpeedSearchSupply speedSearch = SpeedSearchSupply.getSupply(speedSearchEnabledComponent);
  if (speedSearch != null) {
    final Iterable<TextRange> fragments = speedSearch.matchingFragments(text);
    if (fragments != null) {
      final Color fg = attributes.getFgColor();
      final Color bg = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
      final int style = attributes.getStyle();
      final SimpleTextAttributes plain = new SimpleTextAttributes(style, fg);
      final SimpleTextAttributes highlighted = new SimpleTextAttributes(bg, fg, null, style | SimpleTextAttributes.STYLE_SEARCH_MATCH);
      appendColoredFragments(simpleColoredComponent, text, fragments, plain, highlighted);
      return;
    }
  }
  simpleColoredComponent.append(text, attributes);
}
项目:consulo    文件:SpeedSearchUtil.java   
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);
  }
}
项目:consulo    文件:RectanglePainter.java   
public void paint(@Nonnull Graphics2D g2, @Nonnull String text, int paddingX, int paddingY, @Nonnull Color color) {
  GraphicsConfig config = GraphicsUtil.setupAAPainting(g2);
  g2.setFont(getLabelFont());
  g2.setStroke(new BasicStroke(1.5f));

  FontMetrics fontMetrics = g2.getFontMetrics();
  int width = fontMetrics.stringWidth(text) + 2 * TEXT_PADDING_X;
  int height = fontMetrics.getHeight() + TOP_TEXT_PADDING + BOTTOM_TEXT_PADDING;

  g2.setColor(color);
  if (mySquare) {
    g2.fillRect(paddingX, paddingY, width, height);
  }
  else {
    g2.fill(new RoundRectangle2D.Double(paddingX, paddingY, width, height, LABEL_ARC, LABEL_ARC));
  }

  g2.setColor(JBColor.BLACK);
  int x = paddingX + TEXT_PADDING_X;
  int y = paddingY + SimpleColoredComponent.getTextBaseLine(fontMetrics, height);
  g2.drawString(text, x, y);

  config.restore();
}
项目:consulo    文件:LinkMouseListenerBase.java   
public static void installSingleTagOn(@Nonnull SimpleColoredComponent component) {
  new LinkMouseListenerBase<Consumer<MouseEvent>>() {
    @Nullable
    @Override
    protected Consumer<MouseEvent> getTagAt(@Nonnull MouseEvent e) {
      //noinspection unchecked
      return (Consumer<MouseEvent>)((SimpleColoredComponent)e.getSource()).getFragmentTagAt(e.getX());
    }

    @Override
    protected void handleTagClick(@Nullable Consumer<MouseEvent> tag, @Nonnull MouseEvent event) {
      if (tag != null) {
        tag.consume(event);
      }
    }
  }.installOn(component);
}
项目:consulo    文件:FixedHotfixGroupElement.java   
public FixedHotfixGroupElement(String name, Object data, VirtualFile file) {
  super(name, data, file);
  myCustomizeColoredTreeCellRenderer = new CustomizeColoredTreeCellRenderer() {
    public void customizeCellRenderer(SimpleColoredComponent renderer,
                                      JTree tree,
                                      Object value,
                                      boolean selected,
                                      boolean expanded,
                                      boolean leaf,
                                      int row,
                                      boolean hasFocus) {
      renderer.setIcon(AllIcons.General.Information);
      renderer.append("Fixed: ", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
      final String[] text = getText();
      final String checkedText = ((text != null) && (text.length > 0)) ? text[0] : "";
      renderer.append(checkedText, SimpleTextAttributes.REGULAR_ATTRIBUTES);
    }
  };
}
项目:consulo    文件:HotfixGroupElement.java   
public HotfixGroupElement(final String name, final Object data, final VirtualFile file, final Consumer<HotfixGate> hotfix,
                          final String fixDescription, final MutableErrorTreeView view) {
  super(name, data, file);
  myHotfix = hotfix;
  myFixDescription = fixDescription;
  myView = view;
  myLeftTreeCellRenderer = new CustomizeColoredTreeCellRenderer() {
    public void customizeCellRenderer(SimpleColoredComponent renderer,
                                      JTree tree,
                                      Object value,
                                      boolean selected,
                                      boolean expanded,
                                      boolean leaf,
                                      int row,
                                      boolean hasFocus) {
      renderer.setIcon(AllIcons.General.Error);

      final String[] text = getText();
      final String errorText = ((text != null) && (text.length > 0)) ? text[0] : "";
      renderer.append("Error: " + errorText, SimpleTextAttributes.REGULAR_ATTRIBUTES);
    }
  };
  myRightTreeCellRenderer = new MyRightRenderer();
}
项目:consulo    文件:IdeNotificationArea.java   
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
  UISettings.setupAntialiasing(g);

  Font originalFont = g.getFont();
  Color originalColor = g.getColor();
  g.setFont(myFont);

  x += (getIconWidth() - myWidth) / 2;
  y += SimpleColoredComponent.getTextBaseLine(g.getFontMetrics(), getIconHeight());

  if (SystemInfo.isLinux) {
    if (myStr.length() == 1) {
      x--;
    }
  }
  else if (myStr.length() == 2) {
    x++;
  }

  g.setColor(myTextColor);
  g.drawString(myStr, x, y);

  g.setFont(originalFont);
  g.setColor(originalColor);
}
项目:consulo    文件:SetValueInplaceEditor.java   
private SetValueInplaceEditor(final XValueNodeImpl node, @Nonnull final String nodeName) {
  super(node, "setValue");
  myValueNode = node;
  myModifier = myValueNode.getValueContainer().getModifier();

  SimpleColoredComponent nameLabel = new SimpleColoredComponent();
  nameLabel.getIpad().right = 0;
  nameLabel.getIpad().left = 0;
  nameLabel.setIcon(myNode.getIcon());
  nameLabel.append(nodeName, XDebuggerUIConstants.VALUE_NAME_ATTRIBUTES);
  XValuePresentation presentation = node.getValuePresentation();
  if (presentation != null) {
    XValuePresentationUtil.appendSeparator(nameLabel, presentation.getSeparator());
  }
  myNameOffset = nameLabel.getPreferredSize().width;
  myEditorPanel = JBUI.Panels.simplePanel(myExpressionEditor.getComponent());
}
项目:consulo    文件:ShowUsagesTableCellRenderer.java   
private void appendGroupText(final GroupNode node, JPanel panel, Color fileBgColor) {
  UsageGroup group = node == null ? null : node.getGroup();
  if (group == null) return;
  GroupNode parentGroup = (GroupNode)node.getParent();
  appendGroupText(parentGroup, panel, fileBgColor);
  if (node.canNavigateToSource()) {
    SimpleColoredComponent renderer = new SimpleColoredComponent();

    renderer.setIcon(group.getIcon(false));
    SimpleTextAttributes attributes = deriveAttributesWithColor(SimpleTextAttributes.REGULAR_ATTRIBUTES, fileBgColor);
    renderer.append(group.getText(myUsageView), attributes);
    renderer.append(" ", attributes);
    renderer.setIpad(new Insets(0,0,0,0));
    renderer.setBorder(null);
    panel.add(renderer);
  }
}
项目:consulo    文件:AbstractFindUsagesDialog.java   
@Override
protected JComponent createNorthPanel() {
  JPanel panel = new JPanel(new GridBagLayout());
  GridBagConstraints gbConstraints = new GridBagConstraints();

  gbConstraints.insets = new Insets(0, 0, UIUtil.DEFAULT_VGAP, 0);
  gbConstraints.fill = GridBagConstraints.NONE;
  gbConstraints.weightx = 1;
  gbConstraints.weighty = 1;
  gbConstraints.anchor = GridBagConstraints.WEST;
  final SimpleColoredComponent coloredComponent = new SimpleColoredComponent();
  coloredComponent.setIpad(new Insets(0,0,0,0));
  coloredComponent.setMyBorder(null);
  configureLabelComponent(coloredComponent);
  panel.add(coloredComponent, gbConstraints);

  return panel;
}
项目:otto-intellij-plugin    文件:ShowUsagesTableCellRenderer.java   
private void appendGroupText(final GroupNode node, JPanel panel, Color fileBgColor) {
  UsageGroup group = node == null ? null : node.getGroup();
  if (group == null) return;
  GroupNode parentGroup = (GroupNode)node.getParent();
  appendGroupText(parentGroup, panel, fileBgColor);
  if (node.canNavigateToSource()) {
    SimpleColoredComponent renderer = new SimpleColoredComponent();

    renderer.setIcon(group.getIcon(false));
    SimpleTextAttributes attributes = deriveAttributesWithColor(SimpleTextAttributes.REGULAR_ATTRIBUTES, fileBgColor);
    renderer.append(group.getText(myUsageView), attributes);
    renderer.append(" ", attributes);
    renderer.setIpad(new Insets(0,0,0,0));
    renderer.setBorder(null);
    panel.add(renderer);
  }
}
项目:intellij-ce-playground    文件:ChooseLibrariesDialogBase.java   
protected LibraryDescriptor(final Project project, final NodeDescriptor parentDescriptor, final Library element) {
  super(project, parentDescriptor, element);
  final CellAppearanceEx appearance = OrderEntryAppearanceService.getInstance().forLibrary(project, element, false);
  final SimpleColoredComponent coloredComponent = new SimpleColoredComponent();
  appearance.customize(coloredComponent);
  final PresentationData templatePresentation = getTemplatePresentation();
  templatePresentation.setIcon(coloredComponent.getIcon());
  templatePresentation.addText(notEmpty(appearance.getText()), SimpleTextAttributes.REGULAR_ATTRIBUTES);
}
项目:intellij-ce-playground    文件:CompositeAppearance.java   
public void customize(@NotNull SimpleColoredComponent component) {
  synchronized (mySections) {
    for (TextSection section : mySections) {
      final TextAttributes attributes = section.getTextAttributes();
      component.append(section.getText(), SimpleTextAttributes.fromTextAttributes(attributes));
    }
    component.setIcon(myIcon);
  }
}
项目:intellij-ce-playground    文件:BaseTextCommentCellAppearance.java   
public void customize(@NotNull final SimpleColoredComponent component) {
  component.setIcon(getIcon());
  component.append(getPrimaryText(), myTextAttributes);
  final String secondaryText = getSecondaryText();
  if (!StringUtil.isEmptyOrSpaces(secondaryText)) {
    component.append(" (" + secondaryText + ")", myCommentAttributes);
  }
}
项目:intellij-ce-playground    文件:SpeedSearchUtil.java   
public static void appendColoredFragments(final SimpleColoredComponent simpleColoredComponent,
                                          final String text,
                                          Iterable<TextRange> colored,
                                          final SimpleTextAttributes plain, final SimpleTextAttributes highlighted) {
  final List<Pair<String, Integer>> searchTerms = new ArrayList<Pair<String, Integer>>();
  for (TextRange fragment : colored) {
    searchTerms.add(Pair.create(fragment.substring(text), fragment.getStartOffset()));
  }

  final int[] lastOffset = {0};
  ContainerUtil.process(searchTerms, new Processor<Pair<String, Integer>>() {
    @Override
    public boolean process(Pair<String, Integer> pair) {
      if (pair.second > lastOffset[0]) {
        simpleColoredComponent.append(text.substring(lastOffset[0], pair.second), plain);
      }

      simpleColoredComponent.append(text.substring(pair.second, pair.second + pair.first.length()), highlighted);
      lastOffset[0] = pair.second + pair.first.length();
      return true;
    }
  });

  if (lastOffset[0] < text.length()) {
    simpleColoredComponent.append(text.substring(lastOffset[0]), plain);
  }
}
项目:intellij-ce-playground    文件:TextLabelPainter.java   
protected Rectangle paint(@NotNull Graphics2D g2,
                          @NotNull String text,
                          int paddingX,
                          int paddingY,
                          int textPadding,
                          @NotNull Color color) {
  g2.setFont(getFont());
  g2.setStroke(new BasicStroke(1.5f));
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

  FontMetrics fontMetrics = g2.getFontMetrics();
  int width = fontMetrics.stringWidth(text) + 2 * TEXT_PADDING_X + textPadding;
  int height = fontMetrics.getHeight() + TOP_TEXT_PADDING + BOTTOM_TEXT_PADDING;

  g2.setColor(color);
  if (mySquare) {
    g2.fillRect(paddingX, paddingY, width, height);
  }
  else {
    g2.fill(new RoundRectangle2D.Double(paddingX, paddingY, width, height, LABEL_ARC, LABEL_ARC));
  }

  g2.setColor(JBColor.BLACK);
  int x = paddingX + textPadding + TEXT_PADDING_X;
  int y = paddingY + SimpleColoredComponent.getTextBaseLine(fontMetrics, height);
  g2.drawString(text, x, y);

  return new Rectangle(x, y, width, height);
}
项目:intellij-ce-playground    文件:ErrorViewStructure.java   
private MyNavigatableWithDataElement(final Project project,
                                     @NotNull ErrorTreeElementKind kind,
                                     GroupingElement parent,
                                     String[] message,
                                     @NotNull final VirtualFile vf,
                                     String exportText,
                                     String rendererTextPrefix) {
  super(kind, parent, message, new OpenFileDescriptor(project, vf, -1, -1), exportText, rendererTextPrefix);
  myVf = vf;
  myCustomizeColoredTreeCellRenderer = new CustomizeColoredTreeCellRenderer() {
    @Override
    public void customizeCellRenderer(SimpleColoredComponent renderer,
                                      JTree tree,
                                      Object value,
                                      boolean selected,
                                      boolean expanded,
                                      boolean leaf,
                                      int row,
                                      boolean hasFocus) {
      final Icon icon = myVf.getFileType().getIcon();
      renderer.setIcon(icon);
      final String[] messages = getText();
      final String text = messages == null || messages.length == 0 ? vf.getPath() : messages[0];
      renderer.append(text);
    }
  };
}