Java 类com.intellij.util.ui.ImageUtil 实例源码

项目:intellij-ce-playground    文件:RecentProjectsManagerBase.java   
protected static Icon getSmallApplicationIcon() {
  if (ourSmallAppIcon == null) {
    try {
      Icon appIcon = IconLoader.findIcon(ApplicationInfoEx.getInstanceEx().getIconUrl());

      if (appIcon != null) {
        if (appIcon.getIconWidth() == JBUI.scale(16) && appIcon.getIconHeight() == JBUI.scale(16)) {
          ourSmallAppIcon = appIcon;
        } else {
          BufferedImage image = ImageUtil.toBufferedImage(IconUtil.toImage(appIcon));
          image = Scalr.resize(image, Scalr.Method.ULTRA_QUALITY, UIUtil.isRetina() ? 32 : JBUI.scale(16));
          ourSmallAppIcon = toRetinaAwareIcon(image);
        }
      }
    }
    catch (Exception e) {//
    }
    if (ourSmallAppIcon == null) {
      ourSmallAppIcon = EmptyIcon.ICON_16;
    }
  }

  return ourSmallAppIcon;
}
项目:intellij-ce-playground    文件:IconLoader.java   
@Override
public Icon scale(float scaleFactor) {
  if (scaleFactor == 1f) {
    return this;
  }
  if (scaledIcons == null) {
    scaledIcons = new HashMap<Float, Icon>(1);
  }

  Icon result = scaledIcons.get(scaleFactor);
  if (result != null) {
    return result;
  }

  final Image image = ImageUtil.filter(ImageLoader.loadFromUrl(myUrl, UIUtil.isUnderDarcula(), scaleFactor >= 1.5f), filter);
  if (image != null) {
    int width = (int)(getIconWidth() * scaleFactor);
    int height = (int)(getIconHeight() * scaleFactor);
    final BufferedImage resizedImage = Scalr.resize(ImageUtil.toBufferedImage(image), Scalr.Method.ULTRA_QUALITY, width, height);
    result = getIcon(resizedImage);
    scaledIcons.put(scaleFactor, result);
    return result;
  }

  return this;
}
项目:consulo    文件:IconLoader.java   
/**
 * Retrieves the orig icon based on the pixScale, then scale it by the instanceScale.
 */
public ImageIcon getOrScaleIcon(float pixScale, float instanceScale, boolean allowFloatScaling) {
  float effectiveScale = pixScale * instanceScale;
  ImageIcon icon = SoftReference.dereference(scaledIconsCache.get(effectiveScale));
  if (icon != null) {
    return icon;
  }

  Image image = getOrLoadOrigImage(pixScale, allowFloatScaling);
  if (image == null) return null;

  image = ImageUtil.scaleImage(image, instanceScale);
  icon = checkIcon(image, myUrl);
  scaledIconsCache.put(effectiveScale, new SoftReference<ImageIcon>(icon));
  return icon;
}
项目:consulo    文件:JBHiDPIScaledImage.java   
/**
 * Returns JBHiDPIScaledImage of the same structure scaled by the provided factor.
 *
 * @param scaleFactor the scale factor
 * @return scaled instance
 */
public JBHiDPIScaledImage scale(float scaleFactor) {
  Image img = myImage == null ? this: myImage;

  int w = (int)(scaleFactor * getRealWidth(null));
  int h = (int)(scaleFactor * getRealHeight(null));
  if (w <= 0 || h <= 0) return this;

  Image scaled = Scalr.resize(ImageUtil.toBufferedImage(img), Scalr.Method.QUALITY, w, h);

  int newUserWidth = (int)(w / this.myScale);
  int newUserHeight = (int)(h / this.myScale);

  if (myImage != null) {
    return new JBHiDPIScaledImage(scaled, newUserWidth, newUserHeight, getType());
  }
  JBHiDPIScaledImage newImg = new JBHiDPIScaledImage(newUserWidth, newUserHeight, getType());
  Graphics2D g = newImg.createGraphics();
  g.drawImage(scaled, 0, 0, newUserWidth, newUserHeight, 0, 0, scaled.getWidth(null), scaled.getHeight(null), null);
  g.dispose();
  return newImg;
}
项目:consulo    文件:ImageLoader.java   
@Nonnull
public static Image scaleImage(Image image, float scale) {
  if (scale == 1.0) return image;

  if (image instanceof JBHiDPIScaledImage) {
    return ((JBHiDPIScaledImage)image).scale(scale);
  }
  int w = image.getWidth(null);
  int h = image.getHeight(null);
  if (w <= 0 || h <= 0) {
    return image;
  }
  int width = (int)(scale * w);
  int height = (int)(scale * h);
  // Using "QUALITY" instead of "ULTRA_QUALITY" results in images that are less blurry
  // because ultra quality performs a few more passes when scaling, which introduces blurriness
  // when the scaling factor is relatively small (i.e. <= 3.0f) -- which is the case here.
  return Scalr.resize(ImageUtil.toBufferedImage(image), Scalr.Method.QUALITY, width, height);
}
项目:intellij-ce-playground    文件:RecentProjectsManagerBase.java   
private static BufferedImage loadAndScaleImage(File file) {
  try {
    Image img = ImageLoader.loadFromUrl(file.toURL());
    return Scalr.resize(ImageUtil.toBufferedImage(img), Scalr.Method.ULTRA_QUALITY, UIUtil.isRetina() ? 32 : JBUI.scale(16));
  }
  catch (MalformedURLException e) {//
  }
  return null;
}
项目:intellij-ce-playground    文件:IconLoader.java   
@NotNull
private synchronized Icon getRealIcon() {
  if (isLoaderDisabled() && (myRealIcon == null || dark != USE_DARK_ICONS || scale != SCALE || filter != IMAGE_FILTER)) return EMPTY_ICON;

  if (dark != USE_DARK_ICONS || scale != SCALE || filter != IMAGE_FILTER) {
    myRealIcon = null;
    dark = USE_DARK_ICONS;
    scale = SCALE;
    filter = IMAGE_FILTER;
  }
  Object realIcon = myRealIcon;
  if (realIcon instanceof Icon) return (Icon)realIcon;

  Icon icon;
  if (realIcon instanceof Reference) {
    icon = ((Reference<Icon>)realIcon).get();
    if (icon != null) return icon;
  }

  Image image = ImageUtil.filter(ImageLoader.loadFromUrl(myUrl), filter);
  icon = checkIcon(image, myUrl);

  if (icon != null) {
    if (icon.getIconWidth() < 50 && icon.getIconHeight() < 50) {
      realIcon = icon;
    }
    else {
      realIcon = new SoftReference<Icon>(icon);
    }
    myRealIcon = realIcon;
  }

  return icon == null ? EMPTY_ICON : icon;
}
项目:intellij-ce-playground    文件:ImageLoader.java   
@NotNull
private static Image scaleImage(Image image, float scale) {
  int width = (int)(scale * image.getWidth(null));
  int height = (int)(scale * image.getHeight(null));
  // Using "QUALITY" instead of "ULTRA_QUALITY" results in images that are less blurry
  // because ultra quality performs a few more passes when scaling, which introduces blurriness
  // when the scaling factor is relatively small (i.e. <= 3.0f) -- which is the case here.
  return Scalr.resize(ImageUtil.toBufferedImage(image), Scalr.Method.QUALITY, width, height);
}
项目:consulo    文件:ImageLoader.java   
public ImageConverterChain withFilter(final ImageFilter filter) {
  return with(new ImageConverter() {
    @Override
    public Image convert(Image source, ImageDesc desc) {
      return ImageUtil.filter(source, filter);
    }
  });
}
项目:consulo    文件:FrameWrapper.java   
public void show(boolean restoreBounds) {
  myFocusedCallback = new ActionCallback();

  if (myProject != null) {
    IdeFocusManager.getInstance(myProject).typeAheadUntil(myFocusedCallback);
  }

  final Window frame = getFrame();

  if (myStatusBar != null) {
    myStatusBar.install((IdeFrame)frame);
  }

  if (frame instanceof JFrame) {
    ((JFrame)frame).setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  } else {
    ((JDialog)frame).setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  }

  UIUtil.resetRootPaneAppearance(((RootPaneContainer)frame).getRootPane());

  final WindowAdapter focusListener = new WindowAdapter() {
    @Override
    public void windowOpened(WindowEvent e) {
      IdeFocusManager fm = IdeFocusManager.getInstance(myProject);
      JComponent toFocus = getPreferredFocusedComponent();
      if (toFocus == null) {
        toFocus = fm.getFocusTargetFor(myComponent);
      }

      if (toFocus != null) {
        fm.requestFocus(toFocus, true).notify(myFocusedCallback);
      } else {
        myFocusedCallback.setRejected();
      }
    }
  };
  frame.addWindowListener(focusListener);
  if (ModalityPerProjectEAPDescriptor.is()) {
    frame.setAlwaysOnTop(true);
  }
  Disposer.register(this, new Disposable() {
    @Override
    public void dispose() {
      frame.removeWindowListener(focusListener);
    }
  });
  if (myCloseOnEsc) addCloseOnEsc((RootPaneContainer)frame);
  ((RootPaneContainer)frame).getContentPane().add(myComponent, BorderLayout.CENTER);
  if (frame instanceof JFrame) {
    ((JFrame)frame).setTitle(myTitle);
  } else {
    ((JDialog)frame).setTitle(myTitle);
  }
  if (myImages != null) {
    // unwrap the image before setting as frame's icon
    frame.setIconImages(ContainerUtil.map(myImages, ImageUtil::toBufferedImage));
  }
  else {
    AppUIUtil.updateWindowIcon(myFrame);
  }

  if (restoreBounds) {
    loadFrameState();
  }

  myFocusWatcher = new FocusWatcher();
  myFocusWatcher.install(myComponent);
  myShown = true;
  frame.setVisible(true);
}