Java Code Examples for com.intellij.util.ui.UIUtil#isJreHiDPI()

The following examples show how to use com.intellij.util.ui.UIUtil#isJreHiDPI() . 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: 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 2
Source File: RecentProjectPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean rectInListCoordinatesContains(Rectangle listCellBounds, Point p) {

    int realCloseButtonInset = UIUtil.isJreHiDPI(myRootPanel) ? (int)(closeButtonInset * JBUI.sysScale(myRootPanel)) : closeButtonInset;

    Rectangle closeButtonRect =
            new Rectangle(myCloseButtonForEditor.getX() - realCloseButtonInset, myCloseButtonForEditor.getY() - realCloseButtonInset, myCloseButtonForEditor.getWidth() + realCloseButtonInset * 2,
                          myCloseButtonForEditor.getHeight() + realCloseButtonInset * 2);

    Rectangle rectInListCoordinates = new Rectangle(new Point(closeButtonRect.x + listCellBounds.x, closeButtonRect.y + listCellBounds.y), closeButtonRect.getSize());
    return rectInListCoordinates.contains(p);
  }
 
Example 3
Source File: AWTIconLoaderFacade.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Creates new icon with the filter applied.
 */
@Nullable
public static Icon filterIcon(@Nonnull Icon icon, RGBImageFilter filter, @Nullable Component ancestor) {
  if (icon instanceof DesktopLazyImageImpl) icon = ((DesktopLazyImageImpl)icon).getOrComputeIcon();
  if (icon == null) return null;

  if (!isGoodSize(icon)) {
    LOG.error(icon); // # 22481
    return EMPTY_ICON;
  }
  if (icon instanceof CachedImageIcon) {
    icon = ((CachedImageIcon)icon).asDisabledIcon();
  }
  else {
    final float scale;
    if (icon instanceof JBUI.ScaleContextAware) {
      scale = (float)((JBUI.ScaleContextAware)icon).getScale(SYS_SCALE);
    }
    else {
      scale = UIUtil.isJreHiDPI() ? JBUI.sysScale(ancestor) : 1f;
    }
    @SuppressWarnings("UndesirableClassUsage") BufferedImage image = new BufferedImage((int)(scale * icon.getIconWidth()), (int)(scale * icon.getIconHeight()), BufferedImage.TYPE_INT_ARGB);
    final Graphics2D graphics = image.createGraphics();

    graphics.setColor(UIUtil.TRANSPARENT_COLOR);
    graphics.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight());
    graphics.scale(scale, scale);
    icon.paintIcon(LabelHolder.ourFakeComponent, graphics, 0, 0);

    graphics.dispose();

    Image img = ImageUtil.filter(image, filter);
    if (UIUtil.isJreHiDPI()) img = RetinaImage.createFrom(img, scale, null);

    icon = new JBImageIcon(img);
  }
  return icon;
}
 
Example 4
Source File: TipUIUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static void updateImages(StringBuilder text, ClassLoader tipLoader, JEditorPane browser) {
  final boolean dark = StyleManager.get().getCurrentStyle().isDark();

  IdeFrame af = IdeFrameUtil.findActiveRootIdeFrame();
  Component comp = af != null ? TargetAWT.to(af.getWindow()) : browser;
  int index = text.indexOf("<img", 0);
  while (index != -1) {
    final int end = text.indexOf(">", index + 1);
    if (end == -1) return;
    final String img = text.substring(index, end + 1).replace('\r', ' ').replace('\n', ' ');
    final int srcIndex = img.indexOf("src=");
    final int endIndex = img.indexOf(".png", srcIndex);
    if (endIndex != -1) {
      String path = img.substring(srcIndex + 5, endIndex);
      if (!path.endsWith("_dark") && !path.endsWith("@2x")) {
        boolean hidpi = JBUI.isPixHiDPI(comp);
        path += (hidpi ? "@2x" : "") + (dark ? "_dark" : "") + ".png";
        URL url = ResourceUtil.getResource(tipLoader, "/tips/", path);
        if (url != null) {
          String newImgTag = "<img src=\"" + path + "\" ";
          try {
            BufferedImage image = ImageIO.read(url.openStream());
            int w = image.getWidth();
            int h = image.getHeight();
            if (UIUtil.isJreHiDPI(comp)) {
              // compensate JRE scale
              float sysScale = JBUI.sysScale(comp);
              w = (int)(w / sysScale);
              h = (int)(h / sysScale);
            }
            else {
              // compensate image scale
              float imgScale = hidpi ? 2f : 1f;
              w = (int)(w / imgScale);
              h = (int)(h / imgScale);
            }
            // fit the user scale
            w = (int)(JBUI.scale((float)w));
            h = (int)(JBUI.scale((float)h));

            newImgTag += "width=\"" + w + "\" height=\"" + h + "\"";
          }
          catch (Exception ignore) {
            newImgTag += "width=\"400\" height=\"200\"";
          }
          newImgTag += "/>";
          text.replace(index, end + 1, newImgTag);
        }
      }
    }
    index = text.indexOf("<img", index + 1);
  }
}