Java Code Examples for com.intellij.ide.ui.UISettings#setupAntialiasing()

The following examples show how to use com.intellij.ide.ui.UISettings#setupAntialiasing() . 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: MoreTabsIcon.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void paintIcon(final Component c, Graphics graphics) {
  if (myCounter <= 0) return;
  final Rectangle moreRect = getIconRec();

  if (moreRect == null) return;

  int iconY = getIconY(moreRect);
  int iconX = getIconX(moreRect);
  graphics.setFont(UIUtil.getLabelFont().deriveFont((float)Math.min(8, UIUtil.getButtonFont().getSize())));
  int width = graphics.getFontMetrics().stringWidth(String.valueOf(myCounter));
  iconX -= width / 2 + 1;

  icon.paintIcon(c, graphics, iconX, iconY);
  Graphics g = graphics.create();
  try {
    UISettings.setupAntialiasing(g);
    UIUtil.drawStringWithHighlighting(g, String.valueOf(myCounter), iconX + getIconWidth() + 2, iconY + getIconHeight() - 5, JBColor.BLACK, ColorUtil.withPreAlpha(JBColor.WHITE, .9));
  }
  finally {
    g.dispose();
  }
}
 
Example 2
Source File: EditorComponentImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
  myApplication.editorPaintStart();

  try {
    Graphics2D gg = (Graphics2D)g;
    UIUtil.setupComposite(gg);
    if (myEditor.useEditorAntialiasing()) {
      EditorUIUtil.setupAntialiasing(gg);
    }
    else {
      UISettings.setupAntialiasing(gg);
    }
    gg.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, myEditor.myFractionalMetricsHintValue);
    AffineTransform origTx = PaintUtil.alignTxToInt(gg, PaintUtil.insets2offset(getInsets()), true, false, PaintUtil.RoundingMode.CEIL);
    myEditor.paint(gg);
    if (origTx != null) gg.setTransform(origTx);
  }
  finally {
    myApplication.editorPaintFinish();
  }
}
 
Example 3
Source File: DialogWrapperPeerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void paint(Graphics g) {
  if (!SystemInfo.isMac || UIUtil.isUnderAquaLookAndFeel()) {  // avoid rendering problems with non-aqua (alloy) LaFs under mac
    // actually, it's a bad idea to globally enable this for dialog graphics since renderers, for example, may not
    // inherit graphics so rendering hints won't be applied and trees or lists may render ugly.
    UISettings.setupAntialiasing(g);
  }

  super.paint(g);
}
 
Example 4
Source File: MultiLineLabelUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void drawString(Graphics g, String s, int accChar, int textX, int textY) {
  UISettings.setupAntialiasing(g);
  if (s.indexOf('\n') == -1)
    BasicGraphicsUtils.drawString(g, s, accChar, textX, textY);
  else {
    String[] strs = splitStringByLines(s);
    int height = g.getFontMetrics().getHeight();
    // Only the first line can have the accel char
    BasicGraphicsUtils.drawString(g, strs[0], accChar, textX, textY);
    for (int i = 1; i < strs.length; i++) {
      g.drawString(strs[i], textX, textY + (height * i));
    }
  }
}
 
Example 5
Source File: BreadcrumbsComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void repaint(@Nonnull final Graphics2D g2, @Nonnull final List<? extends Crumb> crumbList, @Nonnull final Painter painter, final int height) {
  UISettings.setupAntialiasing(g2);

  //final int height = myImage.getHeight();
  final int pageOffset = getPageOffset();

  for (final Crumb each : crumbList) {
    if (each.getOffset() >= pageOffset && each.getOffset() < pageOffset + myPageWidth) {
      each.paint(g2, painter, height, pageOffset);
    }
  }
}
 
Example 6
Source File: ConsoleGutterComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void paint(Graphics g) {
  Rectangle clip = g.getClipBounds();
  if (clip.height <= 0 || maxContentWidth == 0) {
    return;
  }

  if (atLineStart) {
    // don't paint in the overlapped region
    if (clip.x >= maxContentWidth) {
      return;
    }

    g.setColor(editor.getBackgroundColor());
    g.fillRect(clip.x, clip.y, Math.min(clip.width, maxContentWidth - clip.x), clip.height);
  }

  UISettings.setupAntialiasing(g);

  Graphics2D g2 = (Graphics2D)g;
  Object hint = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
  if (!UIUtil.isJreHiDPI(g2)) {
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
  }

  try {
    paintAnnotations(g, clip);
  }
  finally {
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, hint);
  }
}
 
Example 7
Source File: InlineProgressIndicator.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void paintComponent(final Graphics g) {
  if (myCompact) {
    super.paintComponent(g);
    return;
  }

  final GraphicsConfig c = GraphicsUtil.setupAAPainting(g);
  UISettings.setupAntialiasing(g);

  int arc = 8;
  Color bg = getBackground();
  final Rectangle bounds = myProcessName.getBounds();
  final Rectangle label = SwingUtilities.convertRectangle(myProcessName.getParent(), bounds, this);

  g.setColor(UIUtil.getPanelBackground());
  g.fillRoundRect(0, 0, getWidth() - 1, getHeight() - 1, arc, arc);

  if (!UIUtil.isUnderDarcula()) {
    bg = ColorUtil.toAlpha(bg.darker().darker(), 230);
    g.setColor(bg);

    g.fillRoundRect(0, 0, getWidth() - 1, getHeight() - 1, arc, arc);

    g.setColor(UIUtil.getPanelBackground());
    g.fillRoundRect(0, getHeight() / 2, getWidth() - 1, getHeight() / 2, arc, arc);
    g.fillRect(0, (int)label.getMaxY() + 1, getWidth() - 1, getHeight() / 2);
  }
  else {
    bg = bg.brighter();
    g.setColor(bg);
    g.drawLine(0, (int)label.getMaxY() + 1, getWidth() - 1, (int)label.getMaxY() + 1);
  }

  g.setColor(bg);
  g.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, arc, arc);

  c.restore();
}
 
Example 8
Source File: TextPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void paintComponent(final Graphics g) {
  String s = getText();
  int panelWidth = getWidth();
  int panelHeight = getHeight();
  Color background = getBackground();
  if (background != null && isOpaque()) {
    g.setColor(background);
    g.fillRect(0, 0, panelWidth, panelHeight);
  }
  if (s == null) return;

  Graphics2D g2 = (Graphics2D)g;
  g2.setFont(getFont());
  UISettings.setupAntialiasing(g);

  Rectangle bounds = new Rectangle(panelWidth, panelHeight);
  int x = getTextX(g2);
  int maxWidth = panelWidth - x - getInsets().right;
  FontMetrics fm = g.getFontMetrics();
  int textWidth = fm.stringWidth(s);
  if (textWidth > maxWidth) {
    s = truncateText(s, bounds, fm, new Rectangle(), new Rectangle(), maxWidth);
  }

  int y = UIUtil.getStringY(s, bounds, g2);
  Color foreground = isEnabled() ? getForeground() : UIUtil.getInactiveTextColor();
  g2.setColor(foreground);
  g2.drawString(s, x, y);
}
 
Example 9
Source File: ActionButtonUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void paintTextButton(Graphics g, ActionButtonWithText c) {
  AnAction action = c.getAction();

  Icon icon = c.getIcon();
  FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, c.getFont());
  Rectangle viewRect = new Rectangle(c.getSize());
  Insets i = c.getInsets();
  viewRect.x += i.left;
  viewRect.y += i.top;
  viewRect.width -= (i.right + viewRect.x);
  viewRect.height -= (i.bottom + viewRect.y);

  Rectangle iconRect = new Rectangle();
  Rectangle textRect = new Rectangle();
  String text = SwingUtilities
          .layoutCompoundLabel(c, fm, c.getText(), icon, SwingConstants.CENTER, c.horizontalTextAlignment(), SwingConstants.CENTER,
                               SwingConstants.TRAILING, viewRect, iconRect, textRect, c.iconTextSpace());
  int state = c.getPopState();

  if (state != ActionButtonComponent.NORMAL) {
    paintBackground(c, g, c.getSize(), state);
  }

  icon.paintIcon(null, g, iconRect.x, iconRect.y);

  UISettings.setupAntialiasing(g);
  g.setColor(c.isButtonEnabled() ? c.getForeground() : UIUtil.getInactiveTextColor());
  SwingUtilities2.drawStringUnderlineCharAt(c, g, text, getMnemonicCharIndex(c, action, text), textRect.x, textRect.y + fm.getAscent());
}
 
Example 10
Source File: EditorEmptyTextPainter.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void paintEmptyText(@Nonnull final JComponent splitters, @Nonnull Graphics g) {
  UISettings.setupAntialiasing(g);
  g.setColor(new JBColor(Gray._80, Gray._160));
  g.setFont(JBUI.Fonts.label(16f));
  UIUtil.TextPainter painter = new UIUtil.TextPainter().withLineSpacing(1.8f);
  advertiseActions(splitters, painter);
  painter.draw(g, (width, height) -> {
    Dimension s = splitters.getSize();
    int w = (s.width - width) / 2;
    int h = (int)(s.height * heightRatio());
    return Couple.of(w, h);
  });
}
 
Example 11
Source File: DarculaButtonUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void paintContents(Graphics g, AbstractButton b) {
  FontMetrics fm = SwingUtilities2.getFontMetrics(b, g);
  boolean isDotButton = isSquare(b) && b.getIcon() == AllIcons.General.Ellipsis;
  String text = isDotButton ? "..." : b.getText();
  Icon icon = isDotButton ? null : b.getIcon();
  text = layout(b, text, icon, fm, b.getWidth(), b.getHeight());

  if (isSquare(b)) {
    if (b.getIcon() == AllIcons.General.Ellipsis) {
      UISettings.setupAntialiasing(g);
      paintText(g, b, textRect, text);
    }
    else if (b.getIcon() != null) {
      paintIcon(g, b, iconRect);
    }
  }
  else {
    // Paint the Icon
    if (b.getIcon() != null) {
      paintIcon(g, b, iconRect);
    }

    if (text != null && !text.isEmpty()) {
      View v = (View)b.getClientProperty(BasicHTML.propertyKey);
      if (v != null) {
        v.paint(g, textRect);
      }
      else {
        UISettings.setupAntialiasing(g);
        paintText(g, b, textRect, text);
      }
    }
  }
}
 
Example 12
Source File: ActionToolbarImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void paintComponent(final Graphics g) {
  if (getParent() == null) return;

  int gap = JBUIScale.scale(2);
  int center = JBUIScale.scale(3);
  int offset;
  if (myOrientation == SwingConstants.HORIZONTAL) {
    offset = ActionToolbarImpl.this.getHeight() - getMaxButtonHeight() - 1;
  }
  else {
    offset = ActionToolbarImpl.this.getWidth() - getMaxButtonWidth() - 1;
  }

  g.setColor(JBUI.CurrentTheme.CustomFrameDecorations.separatorForeground());
  if (myOrientation == SwingConstants.HORIZONTAL) {
    int y2 = ActionToolbarImpl.this.getHeight() - gap * 2 - offset;
    LinePainter2D.paint((Graphics2D)g, center, gap, center, y2);

    if (myText != null) {
      FontMetrics fontMetrics = getFontMetrics(getFont());
      int top = (getHeight() - fontMetrics.getHeight()) / 2;
      UISettings.setupAntialiasing(g);
      g.setColor(JBColor.foreground());
      g.drawString(myText, gap * 2 + center + gap, top + fontMetrics.getAscent());
    }
  }
  else {
    LinePainter2D.paint((Graphics2D)g, gap, center, ActionToolbarImpl.this.getWidth() - gap * 2 - offset, center);
  }
}
 
Example 13
Source File: ActionToolbarImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private int getTextWidth(@Nonnull FontMetrics fontMetrics, @Nonnull String text, @Nullable Graphics graphics) {
  if (graphics == null) {
    return fontMetrics.stringWidth(text);
  }
  else {
    Graphics g = graphics.create();
    try {
      UISettings.setupAntialiasing(g);
      return fontMetrics.getStringBounds(text, g).getBounds().width;
    }
    finally {
      g.dispose();
    }
  }
}
 
Example 14
Source File: FrameWrapperPeerFactoryImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void paint(Graphics g) {
  UISettings.setupAntialiasing(g);
  super.paint(g);
}
 
Example 15
Source File: MultiIconSimpleColoredComponent.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected void applyAdditionalHints(@NotNull Graphics2D g) {
  UISettings.setupAntialiasing(g);
}
 
Example 16
Source File: MemoryUsagePanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
  boolean pressed = getModel().isPressed();
  boolean stateChanged = myWasPressed != pressed;
  myWasPressed = pressed;

  if (myBufferedImage == null || stateChanged) {
    Dimension size = getSize();
    Insets insets = getInsets();

    int barWidth = size.width - INDENT;
    myBufferedImage = ImageUtil.createImage(g, barWidth, size.height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = JBSwingUtilities.runGlobalCGTransform(this, myBufferedImage.createGraphics());
    UISettings.setupAntialiasing(g2);

    g2.setFont(getFont());
    int textHeight = g2.getFontMetrics().getAscent();

    Runtime rt = Runtime.getRuntime();
    long maxMem = rt.maxMemory();
    long allocatedMem = rt.totalMemory();
    long unusedMem = rt.freeMemory();
    long usedMem = allocatedMem - unusedMem;

    int usedBarLength = (int)(barWidth * usedMem / maxMem);
    int unusedBarLength = (int)(size.height * unusedMem / maxMem);

    // background
    g2.setColor(UIUtil.getPanelBackground());
    g2.fillRect(0, 0, barWidth, size.height);

    // gauge (used)
    g2.setColor(USED_COLOR);
    g2.fillRect(0, 0, usedBarLength, size.height);

    // gauge (unused)
    g2.setColor(UNUSED_COLOR);
    g2.fillRect(usedBarLength, 0, unusedBarLength, size.height);

    // label
    g2.setColor(pressed ? UIUtil.getLabelDisabledForeground() : JBColor.foreground());
    String text = UIBundle.message("memory.usage.panel.message.text", usedMem / MEGABYTE, maxMem / MEGABYTE);
    int textX = insets.left;
    int textY = insets.top + (size.height - insets.top - insets.bottom - textHeight) / 2 + textHeight - JBUIScale.scale(1);
    g2.drawString(text, textX, textY);

    g2.dispose();
  }

  UIUtil.drawImage(g, myBufferedImage, INDENT, 0, null);
}
 
Example 17
Source File: SimpleColoredComponent.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected void applyAdditionalHints(@Nonnull Graphics2D g) {
  UISettings.setupAntialiasing(g);
}
 
Example 18
Source File: DesktopIdeFrameImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void paint(@Nonnull Graphics g) {
  UISettings.setupAntialiasing(g);
  //noinspection Since15
  super.paint(g);
}
 
Example 19
Source File: TimeTrackerWidget.java    From DarkyenusTimeTracker with The Unlicense 4 votes vote down vote up
@Override
public void paintComponent(final Graphics g) {
    final int timeToShow = service.getTotalTimeSeconds();
    final String info = currentShowTimePattern().secondsToString(timeToShow);

    final Dimension size = getSize();
    final Insets insets = getInsets();

    final int totalBarLength = size.width - insets.left - insets.right;
    final int barHeight = Math.max(size.height, getFont().getSize() + 2);
    final int yOffset = (size.height - barHeight) / 2;
    final int xOffset = insets.left;

    final TimeTrackingStatus status = service.getStatus();
    if (mouseInside) {
        if (status == RUNNING) {
            g.setColor(COLOR_MENU_ON);
        } else {
            g.setColor(COLOR_MENU_OFF);
        }
    } else {
        switch (status) {
            case RUNNING:
                g.setColor(COLOR_ON);
                break;
            case IDLE:
                g.setColor(COLOR_IDLE);
                break;
            case STOPPED:
                g.setColor(COLOR_OFF);
                break;
        }
    }
    g.fillRect(insets.left, insets.bottom, totalBarLength, size.height - insets.bottom - insets.top);
    UISettings.setupAntialiasing(g);

    if (mouseInside) {
        // Draw controls
        g.setColor(JBUI.CurrentTheme.CustomFrameDecorations.separatorForeground());
        final int resumeStopWidth = resumeStopButtonWidth(totalBarLength);
        final int settingsWidth = totalBarLength - resumeStopWidth;

        g.drawLine(xOffset + resumeStopWidth, yOffset, xOffset + resumeStopWidth, yOffset + barHeight);

        Icon firstIcon = status == RUNNING ? STOP_ICON : START_ICON;
        firstIcon.paintIcon(this, g, xOffset + (resumeStopWidth - firstIcon.getIconWidth()) / 2, yOffset + (barHeight - firstIcon.getIconHeight())/2);
        SETTINGS_ICON.paintIcon(this, g, xOffset + resumeStopWidth + (settingsWidth - SETTINGS_ICON.getIconWidth()) / 2, yOffset + (barHeight - SETTINGS_ICON.getIconHeight())/2);
    } else {
        // Draw time text
        final Color fg = getModel().isPressed() ? UIUtil.getLabelDisabledForeground() : JBColor.foreground();
        g.setColor(fg);
        g.setFont(WIDGET_FONT);
        final FontMetrics fontMetrics = g.getFontMetrics();
        final int infoWidth = fontMetrics.charsWidth(info.toCharArray(), 0, info.length());
        final int infoHeight = fontMetrics.getAscent();
        g.drawString(info, xOffset + (totalBarLength - infoWidth) / 2, yOffset + infoHeight + (barHeight - infoHeight) / 2 - 1);
    }
}
 
Example 20
Source File: MultiIconSimpleColoredComponent.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected void applyAdditionalHints(@NotNull Graphics2D g) {
  UISettings.setupAntialiasing(g);
}