Java 类com.intellij.util.ImageLoader 实例源码

项目:intellij-ce-playground    文件:IdeBackgroundUtil.java   
public static void initFramePainters(@NotNull PaintersHelper painters) {
  PaintersHelper.initWallpaperPainter("idea.wallpaper.ide", painters);

  ApplicationInfoEx appInfo = ApplicationInfoEx.getInstanceEx();
  String path = UIUtil.isUnderDarcula()? appInfo.getEditorBackgroundImageUrl() : null;
  URL url = path == null ? null : appInfo.getClass().getResource(path);
  Image centerImage = url == null ? null : ImageLoader.loadFromUrl(url);

  if (centerImage != null) {
    painters.addPainter(PaintersHelper.newImagePainter(centerImage, PaintersHelper.FillType.TOP_CENTER, 1.0f, JBUI.insets(10, 0, 0, 0)), null);
  }
  painters.addPainter(new AbstractPainter() {
    EditorEmptyTextPainter p = ServiceManager.getService(EditorEmptyTextPainter.class);

    @Override
    public boolean needsRepaint() {
      return true;
    }

    @Override
    public void executePaint(Component component, Graphics2D g) {
      p.paintEmptyText((JComponent)component, g);
    }
  }, null);

}
项目:intellij-ce-playground    文件:LogFilter.java   
public Icon getIcon() {
  if (myIcon != null) {
    return myIcon;
  }
  if (myIconPath != null && new File(FileUtil.toSystemDependentName(myIconPath)).exists()) {
    Image image = null;
    try {
      image = ImageLoader.loadFromStream(VfsUtilCore.convertToURL(VfsUtil.pathToUrl(myIconPath)).openStream());
    }
    catch (IOException e) {
      LOG.debug(e);
    }

    if (image != null){
      return IconLoader.getIcon(image);
    }
  }
  //return IconLoader.getIcon("/ant/filter.png");
  return null;
}
项目: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;
}
项目:intellij-ce-playground    文件:CoverageLineMarkerRenderer.java   
public void paint(Editor editor, Graphics g, Rectangle r) {
  final TextAttributes color = editor.getColorsScheme().getAttributes(myKey);
  Color bgColor = color.getBackgroundColor();
  if (bgColor == null) {
    bgColor = color.getForegroundColor();
  }
  if (editor.getSettings().isLineNumbersShown() || ((EditorGutterComponentEx)editor.getGutter()).isAnnotationsShown()) {
    if (bgColor != null) {
      bgColor = ColorUtil.toAlpha(bgColor, 150);
    }
  }
  if (bgColor != null) {
    g.setColor(bgColor);
  }
  g.fillRect(r.x, r.y, r.width, r.height);
  final LineData lineData = getLineData(editor.xyToLogicalPosition(new Point(0, r.y)).line);
  if (lineData != null && lineData.isCoveredByOneTest()) {
    g.drawImage( ImageLoader.loadFromResource("/gutter/unique.png"), r.x, r.y, 8, 8, editor.getComponent());
  }
}
项目:tools-idea    文件:LogFilter.java   
public Icon getIcon() {
  if (myIcon != null) {
    return myIcon;
  }
  if (myIconPath != null && new File(FileUtil.toSystemDependentName(myIconPath)).exists()) {
    Image image = null;
    try {
      image = ImageLoader.loadFromStream(VfsUtil.convertToURL(VfsUtil.pathToUrl(myIconPath)).openStream());
    }
    catch (IOException e) {
      LOG.debug(e);
    }

    if (image != null){
      return IconLoader.getIcon(image);
    }
  }
  //return IconLoader.getIcon("/ant/filter.png");
  return null;
}
项目:consulo    文件:CoverageLineMarkerRenderer.java   
public void paint(Editor editor, Graphics g, Rectangle r) {
  final TextAttributes color = editor.getColorsScheme().getAttributes(myKey);
  Color bgColor = color.getBackgroundColor();
  if (bgColor == null) {
    bgColor = color.getForegroundColor();
  }
  if (editor.getSettings().isLineNumbersShown() || ((EditorGutterComponentEx)editor.getGutter()).isAnnotationsShown()) {
    if (bgColor != null) {
      bgColor = ColorUtil.toAlpha(bgColor, 150);
    }
  }
  if (bgColor != null) {
    g.setColor(bgColor);
  }
  g.fillRect(r.x, r.y, r.width, r.height);
  final LineData lineData = getLineData(editor.xyToLogicalPosition(new Point(0, r.y)).line);
  if (lineData != null && lineData.isCoveredByOneTest()) {
    g.drawImage( ImageLoader.loadFromResource("/gutter/unique.png"), r.x, r.y, 8, 8, editor.getComponent());
  }
}
项目:consulo    文件:LogFilter.java   
public Icon getIcon() {
  if (myIcon != null) {
    return myIcon;
  }
  if (myIconPath != null && new File(FileUtil.toSystemDependentName(myIconPath)).exists()) {
    Image image = null;
    try {
      image = ImageLoader.loadFromStream(VfsUtil.convertToURL(VfsUtil.pathToUrl(myIconPath)).openStream());
    }
    catch (IOException e) {
      LOG.debug(e);
    }

    if (image != null){
      return IconLoader.getIcon(image);
    }
  }
  //return IconLoader.getIcon("/ant/filter.png");
  return null;
}
项目:classic-icon-idea    文件:ClassicIcon.java   
@NotNull
static List<Image> loadImages(@Nullable Project project) {
  List<Image> ret = ContainerUtil.newArrayListWithCapacity(2);
  Image custom = tryLoadCustom(project);
  if (custom != null) {
    ret.add(custom);
  } else {
    String iconName = getIconName();
    ret.add(ImageLoader.loadFromResource("/ch/retomerz/" + iconName + ".png", ClassicIcon.class));
    ret.add(ImageLoader.loadFromResource("/ch/retomerz/" + iconName + "_128.png", ClassicIcon.class));
  }
  return ret;
}
项目:intellij-ce-playground    文件:DiffWindowBase.java   
protected void init() {
  if (myWrapper != null) return;

  myProcessor = createProcessor();

  String dialogGroupKey = myProcessor.getContextUserData(DiffUserDataKeys.DIALOG_GROUP_KEY);
  if (dialogGroupKey == null) dialogGroupKey = "DiffContextDialog";

  myWrapper = new WindowWrapperBuilder(DiffUtil.getWindowMode(myHints), new MyPanel(myProcessor.getComponent()))
    .setProject(myProject)
    .setParent(myHints.getParent())
    .setDimensionServiceKey(dialogGroupKey)
    .setOnShowCallback(new Runnable() {
      @Override
      public void run() {
        myProcessor.updateRequest();
        myProcessor.requestFocus(); // TODO: not needed for modal dialogs. Make a flag in WindowWrapperBuilder ?
      }
    })
    .build();
  myWrapper.setImage(ImageLoader.loadFromResource("/diff/Diff.png"));
  Disposer.register(myWrapper, myProcessor);

  new DumbAwareAction() {
    public void actionPerformed(final AnActionEvent e) {
      myWrapper.close();
    }
  }.registerCustomShortcutSet(CommonShortcuts.getCloseActiveWindow(), myProcessor.getComponent(), myWrapper);
}
项目:intellij-ce-playground    文件:HistoryDialog.java   
protected HistoryDialog(@NotNull Project project, IdeaGateway gw, VirtualFile f, boolean doInit) {
  super(project);
  myProject = project;
  myGateway = gw;
  myFile = f;

  setProject(project);
  setDimensionKey(getPropertiesKey());
  setImage(ImageLoader.loadFromResource("/diff/Diff.png"));
  closeOnEsc();

  if (doInit) init();
}
项目:intellij-ce-playground    文件:DiffUtil.java   
public static void initDiffFrame(Project project, @NotNull FrameWrapper frameWrapper, @NotNull final DiffViewer diffPanel, final JComponent mainComponent) {
  frameWrapper.setComponent(mainComponent);
  frameWrapper.setProject(project);
  frameWrapper.setImage(ImageLoader.loadFromResource("/diff/Diff.png"));
  frameWrapper.setPreferredFocusedComponent(diffPanel.getPreferredFocusedComponent());
  frameWrapper.closeOnEsc();
}
项目: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    文件:CustomActionsSchema.java   
private void initActionIcons() {
  ActionManager actionManager = ActionManager.getInstance();
  for (String actionId : myIconCustomizations.keySet()) {
    final AnAction anAction = actionManager.getAction(actionId);
    if (anAction != null) {
      Icon icon;
      final String iconPath = myIconCustomizations.get(actionId);
      if (iconPath != null && new File(FileUtil.toSystemDependentName(iconPath)).exists()) {
        Image image = null;
        try {
          image = ImageLoader.loadFromStream(VfsUtilCore.convertToURL(VfsUtil.pathToUrl(iconPath)).openStream());
        }
        catch (IOException e) {
          LOG.debug(e);
        }
        icon = image == null ? null : new JBImageIcon(image);
      }
      else {
        icon = AllIcons.Toolbar.Unknown;
      }
      anAction.getTemplatePresentation().setIcon(icon);
      anAction.getTemplatePresentation().setDisabledIcon(IconLoader.getDisabledIcon(icon));
      anAction.setDefaultIcon(false);
    }
  }
  final IdeFrameImpl frame = WindowManagerEx.getInstanceEx().getFrame(null);
  if (frame != null) {
    frame.updateView();
  }
}
项目: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    文件:ApplicationInfoImpl.java   
@Nullable
public Icon getProgressTailIcon() {
  if (myProgressTailIcon == null && myProgressTailIconName != null) {
    try {
      final URL url = getClass().getResource(myProgressTailIconName);
      final Image image = ImageLoader.loadFromUrl(url, false);
      if (image != null) {
        myProgressTailIcon = new ImageIcon(image);
      }
    } catch (Exception ignore) {}
  }
  return myProgressTailIcon;
}
项目:intellij-ce-playground    文件:LoadingIcon.java   
@NotNull
static LoadingIcon create(int width, int height) {
  Image image = ImageLoader.loadFromResource(LOADING_ICON);
  if (image == null) {
    LOG.error("Couldn't load image: " + LOADING_ICON);
    return createEmpty(width, height);
  }
  return new LoadingIcon(image);
}
项目:tools-idea    文件:HistoryDialog.java   
protected HistoryDialog(@NotNull Project project, IdeaGateway gw, VirtualFile f, boolean doInit) {
  super(project);
  myProject = project;
  myGateway = gw;
  myFile = f;

  setProject(project);
  setDimensionKey(getPropertiesKey());
  setImage(ImageLoader.loadFromResource("/diff/Diff.png"));
  closeOnEsc();

  if (doInit) init();
}
项目:tools-idea    文件:DiffUtil.java   
public static void initDiffFrame(Project project, FrameWrapper frameWrapper, final DiffViewer diffPanel, final JComponent mainComponent) {
  frameWrapper.setComponent(mainComponent);
  frameWrapper.setProject(project);
  frameWrapper.setImage(ImageLoader.loadFromResource("/diff/Diff.png"));
  frameWrapper.setPreferredFocusedComponent(diffPanel.getPreferredFocusedComponent());
  frameWrapper.closeOnEsc();
}
项目:tools-idea    文件:CustomActionsSchema.java   
private void initActionIcons() {
  ActionManager actionManager = ActionManager.getInstance();
  for (String actionId : myIconCustomizations.keySet()) {
    final AnAction anAction = actionManager.getAction(actionId);
    if (anAction != null) {
      Icon icon;
      final String iconPath = myIconCustomizations.get(actionId);
      if (iconPath != null && new File(FileUtil.toSystemDependentName(iconPath)).exists()) {
        Image image = null;
        try {
          image = ImageLoader.loadFromStream(VfsUtil.convertToURL(VfsUtil.pathToUrl(iconPath)).openStream());
        }
        catch (IOException e) {
          LOG.debug(e);
        }
        icon = image != null ? IconLoader.getIcon(image) : null;
      }
      else {
        icon = AllIcons.Toolbar.Unknown;
      }
      if (anAction.getTemplatePresentation() != null) {
        anAction.getTemplatePresentation().setIcon(icon);
        anAction.setDefaultIcon(false);
      }
    }
  }
  final IdeFrameImpl frame = WindowManagerEx.getInstanceEx().getFrame(null);
  if (frame != null) {
    frame.updateView();
  }
}
项目:tools-idea    文件:IconLoader.java   
/**
 * Gets (creates if necessary) disabled icon based on the passed one.
 *
 * @return <code>ImageIcon</code> constructed from disabled image of passed icon.
 */
@Nullable
public static Icon getDisabledIcon(Icon icon) {
  if (icon instanceof LazyIcon) icon = ((LazyIcon)icon).getOrComputeIcon();
  if (icon == null) return null;

  Icon disabledIcon = ourIcon2DisabledIcon.get(icon);
  if (disabledIcon == null) {
    if (!isGoodSize(icon)) {
      LOG.error(icon); // # 22481
      return EMPTY_ICON;
    }
    final int scale = UIUtil.isRetina() ? 2 : 1;
    @SuppressWarnings("UndesirableClassUsage")
    BufferedImage image = new BufferedImage(scale*icon.getIconWidth(), 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 = createDisabled(image);
    if (UIUtil.isRetina()) img = RetinaImage.createFrom(img, 2, ImageLoader.ourComponent);

    disabledIcon = new MyImageIcon(img);
    ourIcon2DisabledIcon.put(icon, disabledIcon);
  }
  return disabledIcon;
}
项目:tools-idea    文件:IconLoader.java   
@NotNull
private synchronized Icon getRealIcon() {
  if (isLoaderDisabled()) return EMPTY_ICON;

  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 = ImageLoader.loadFromUrl(myUrl);
  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;
}
项目:consulo    文件:DiffWindowBase.java   
protected void init() {
  if (myWrapper != null) return;

  myProcessor = createProcessor();

  String dialogGroupKey = myProcessor.getContextUserData(DiffUserDataKeys.DIALOG_GROUP_KEY);
  if (dialogGroupKey == null) dialogGroupKey = "DiffContextDialog";

  myWrapper = new WindowWrapperBuilder(DiffUtil.getWindowMode(myHints), new MyPanel(myProcessor.getComponent()))
          .setProject(myProject)
          .setParent(myHints.getParent())
          .setDimensionServiceKey(dialogGroupKey)
          .setOnShowCallback(new Runnable() {
            @Override
            public void run() {
              myProcessor.updateRequest();
              myProcessor.requestFocus(); // TODO: not needed for modal dialogs. Make a flag in WindowWrapperBuilder ?
            }
          })
          .build();
  myWrapper.setImage(ImageLoader.loadFromResource("/diff/Diff.png"));
  Disposer.register(myWrapper, myProcessor);

  new DumbAwareAction() {
    public void actionPerformed(final AnActionEvent e) {
      myWrapper.close();
    }
  }.registerCustomShortcutSet(CommonShortcuts.getCloseActiveWindow(), myProcessor.getComponent());
}
项目:consulo    文件:HistoryDialog.java   
protected HistoryDialog(@Nonnull Project project, IdeaGateway gw, VirtualFile f, boolean doInit) {
  super(project);
  myProject = project;
  myGateway = gw;
  myFile = f;

  setProject(project);
  setDimensionKey(getPropertiesKey());
  setImage(ImageLoader.loadFromResource("/diff/Diff.png"));
  closeOnEsc();

  if (doInit) init();
}
项目:consulo    文件:IdeBackgroundUtil.java   
public static void initFramePainters(@Nonnull IdeGlassPaneImpl glassPane) {
  PaintersHelper painters = glassPane.getNamedPainters(FRAME_PROP);
  PaintersHelper.initWallpaperPainter(FRAME_PROP, painters);

  ApplicationInfoEx appInfo = ApplicationInfoEx.getInstanceEx();
  String path = /*UIUtil.isUnderDarcula()? appInfo.getEditorBackgroundImageUrl() : */null;
  URL url = path == null ? null : appInfo.getClass().getResource(path);
  Image centerImage = url == null ? null : ImageLoader.loadFromUrl(url);

  if (centerImage != null) {
    painters.addPainter(PaintersHelper.newImagePainter(centerImage, PaintersHelper.Fill.PLAIN, PaintersHelper.Place.TOP_CENTER, 1.0f, JBUI.insets(10, 0, 0, 0)), null);
  }
  painters.addPainter(new AbstractPainter() {
    EditorEmptyTextPainter p = EditorEmptyTextPainter.ourInstance;

    @Override
    public boolean needsRepaint() {
      return true;
    }

    @Override
    public void executePaint(Component component, Graphics2D g) {
      p.paintEmptyText((JComponent)component, g);
    }
  }, null);

}
项目:consulo    文件:DiffUtil.java   
public static void initDiffFrame(Project project, @Nonnull FrameWrapper frameWrapper, @Nonnull final DiffViewer diffPanel, final JComponent mainComponent) {
  frameWrapper.setComponent(mainComponent);
  frameWrapper.setProject(project);
  frameWrapper.setImage(ImageLoader.loadFromResource("/diff/Diff.png"));
  frameWrapper.setPreferredFocusedComponent(diffPanel.getPreferredFocusedComponent());
  frameWrapper.closeOnEsc();
}
项目:consulo    文件:CustomActionsSchema.java   
private void initActionIcons() {
  ActionManager actionManager = ActionManager.getInstance();
  for (String actionId : myIconCustomizations.keySet()) {
    final AnAction anAction = actionManager.getAction(actionId);
    if (anAction != null) {
      Icon icon;
      final String iconPath = myIconCustomizations.get(actionId);
      if (iconPath != null && new File(FileUtil.toSystemDependentName(iconPath)).exists()) {
        Image image = null;
        try {
          image = ImageLoader.loadFromStream(VfsUtil.convertToURL(VfsUtil.pathToUrl(iconPath)).openStream());
        }
        catch (IOException e) {
          LOG.debug(e);
        }
        icon = image != null ? IconLoader.getIcon(image) : null;
      }
      else {
        icon = AllIcons.Toolbar.Unknown;
      }
      if (anAction.getTemplatePresentation() != null) {
        anAction.getTemplatePresentation().setIcon(icon);
        anAction.setDefaultIcon(false);
      }
    }
  }
  final IdeFrameEx frame = WindowManagerEx.getInstanceEx().getIdeFrame(null);
  if (frame != null) {
    frame.updateView();
  }
}
项目:consulo    文件:IconLoader.java   
/**
 * Retrieves the orig image based on the pixScale.
 */
private Image getOrLoadOrigImage(float pixScale, boolean allowFloatScaling) {
  boolean needRetinaImage = (pixScale > 1.0f);
  Image image = SoftReference.dereference(origImagesCache.get(needRetinaImage));
  if (image != null) return image;

  image = ImageLoader.loadFromUrl(myUrl, allowFloatScaling, myFilters, pixScale);
  if (image == null) return null;
  origImagesCache.put(needRetinaImage, new SoftReference<Image>(image));
  return image;
}
项目:consulo    文件:LoadingIcon.java   
@Nonnull
static LoadingIcon create(int width, int height) {
  Image image = ImageLoader.loadFromResource(LOADING_ICON);
  if (image == null) {
    LOG.error("Couldn't load image: " + LOADING_ICON);
    return createEmpty(width, height);
  }
  return new LoadingIcon(image);
}
项目:intellij-ce-playground    文件:PaintersHelper.java   
private static AbstractPainter newWallpaperPainter(@NotNull final String propertyName) {
  return new ImagePainter() {
    Image image;
    float alpha;
    Insets insets;
    FillType fillType;

    String current;

    @Override
    public void executePaint(Component component, Graphics2D g) {
      String value = StringUtil.notNullize(System.getProperty(propertyName), propertyName + ".png");
      if (!Comparing.equal(value, current)) {
        current = value;
        image = scaled = null;
        insets = JBUI.emptyInsets();
        String[] parts = value.split(",");
        try {
          alpha = StringUtil.parseInt(parts.length > 1 ? parts[1]: "", 10) / 100f;
          try {
            fillType =  FillType.valueOf(parts.length > 2 ? parts[2].toUpperCase(Locale.ENGLISH) : "");
          }
          catch (IllegalArgumentException e) {
            fillType = FillType.SCALE;
          }
          String filePath = parts[0];

          URL url = filePath.contains("://") ? new URL(filePath) :
                    (FileUtil.isAbsolutePlatformIndependent(filePath)
                     ? new File(filePath)
                     : new File(PathManager.getConfigPath(), filePath)).toURI().toURL();
          image = ImageLoader.loadFromUrl(url);
        }
        catch (Exception ignored) {
        }
      }
      if (image == null) return;
      executePaint(g, component, image, fillType, alpha, insets);
    }
  };
}
项目:intellij-ce-playground    文件:CustomizableActionsPanel.java   
protected boolean doSetIcon(DefaultMutableTreeNode node, @Nullable String path, Component component) {
  if (StringUtil.isNotEmpty(path) && !new File(path).isFile()) {
    Messages
      .showErrorDialog(component, IdeBundle.message("error.file.not.found.message", path), IdeBundle.message("title.choose.action.icon"));
    return false;
  }

  String actionId = getActionId(node);
  if (actionId == null) return false;

  final AnAction action = ActionManager.getInstance().getAction(actionId);
  if (action != null) {
    if (StringUtil.isNotEmpty(path)) {
      Image image = null;
      try {
        image = ImageLoader.loadFromStream(VfsUtilCore.convertToURL(VfsUtil.pathToUrl(path.replace(File.separatorChar,
                                                                                                   '/'))).openStream());
      }
      catch (IOException e) {
        LOG.debug(e);
      }
      Icon icon = new File(path).exists() ? IconLoader.getIcon(image) : null;
      if (icon != null) {
        if (icon.getIconWidth() >  EmptyIcon.ICON_18.getIconWidth() || icon.getIconHeight() > EmptyIcon.ICON_18.getIconHeight()) {
          Messages.showErrorDialog(component, IdeBundle.message("custom.icon.validation.message"), IdeBundle.message("title.choose.action.icon"));
          return false;
        }
        node.setUserObject(Pair.create(actionId, icon));
        mySelectedSchema.addIconCustomization(actionId, path);
      }
    }
    else {
      node.setUserObject(Pair.create(actionId, null));
      mySelectedSchema.removeIconCustomization(actionId);
      final DefaultMutableTreeNode nodeOnToolbar = findNodeOnToolbar(actionId);
      if (nodeOnToolbar != null){
        editToolbarIcon(actionId, nodeOnToolbar);
        node.setUserObject(nodeOnToolbar.getUserObject());
      }
    }
    return true;
  }
  return false;
}
项目:tools-idea    文件:IconLineMarkerProvider.java   
private ImageIcon loadIcon(VirtualFile file, int scale) throws IOException {
  return new ImageIcon(ImageLoader.loadFromStream(file.getInputStream(), scale));
}
项目:tools-idea    文件:CustomizableActionsPanel.java   
protected boolean doSetIcon(DefaultMutableTreeNode node, @Nullable String path, Component component) {
  if (StringUtil.isNotEmpty(path) && !new File(path).isFile()) {
    Messages
      .showErrorDialog(component, IdeBundle.message("error.file.not.found.message", path), IdeBundle.message("title.choose.action.icon"));
    return false;
  }

  String actionId = getActionId(node);
  if (actionId == null) return false;

  final AnAction action = ActionManager.getInstance().getAction(actionId);
  if (action != null && action.getTemplatePresentation() != null) {
    if (StringUtil.isNotEmpty(path)) {
      Image image = null;
      try {
        image = ImageLoader.loadFromStream(VfsUtil.convertToURL(VfsUtil.pathToUrl(path.replace(File.separatorChar,
                                                                                                      '/'))).openStream());
      }
      catch (IOException e) {
        LOG.debug(e);
      }
      Icon icon = new File(path).exists() ? IconLoader.getIcon(image) : null;
      if (icon != null) {
        if (icon.getIconWidth() >  EmptyIcon.ICON_18.getIconWidth() || icon.getIconHeight() > EmptyIcon.ICON_18.getIconHeight()) {
          Messages.showErrorDialog(component, IdeBundle.message("custom.icon.validation.message"), IdeBundle.message("title.choose.action.icon"));
          return false;
        }
        node.setUserObject(Pair.create(actionId, icon));
        mySelectedSchema.addIconCustomization(actionId, path);
      }
    }
    else {
      node.setUserObject(Pair.create(actionId, null));
      mySelectedSchema.removeIconCustomization(actionId);
      final DefaultMutableTreeNode nodeOnToolbar = findNodeOnToolbar(actionId);
      if (nodeOnToolbar != null){
        editToolbarIcon(actionId, nodeOnToolbar);
        node.setUserObject(nodeOnToolbar.getUserObject());
      }
    }
    return true;
  }
  return false;
}
项目:consulo    文件:URLDictionatyLoader.java   
@Override
public Image get(Object o) {
  return myImages.computeIfAbsent((URL) o, ImageLoader::loadFromUrl);
}
项目:consulo    文件:CustomizableActionsPanel.java   
protected boolean doSetIcon(DefaultMutableTreeNode node, @Nullable String path, Component component) {
  if (StringUtil.isNotEmpty(path) && !new File(path).isFile()) {
    Messages
      .showErrorDialog(component, IdeBundle.message("error.file.not.found.message", path), IdeBundle.message("title.choose.action.icon"));
    return false;
  }

  String actionId = getActionId(node);
  if (actionId == null) return false;

  final AnAction action = ActionManager.getInstance().getAction(actionId);
  if (action != null && action.getTemplatePresentation() != null) {
    if (StringUtil.isNotEmpty(path)) {
      Image image = null;
      try {
        image = ImageLoader.loadFromStream(VfsUtil.convertToURL(VfsUtil.pathToUrl(path.replace(File.separatorChar,
                                                                                               '/'))).openStream());
      }
      catch (IOException e) {
        LOG.debug(e);
      }
      Icon icon = new File(path).exists() ? IconLoader.getIcon(image) : null;
      if (icon != null) {
        if (icon.getIconWidth() >  EmptyIcon.ICON_18.getIconWidth() || icon.getIconHeight() > EmptyIcon.ICON_18.getIconHeight()) {
          Messages.showErrorDialog(component, IdeBundle.message("custom.icon.validation.message"), IdeBundle.message("title.choose.action.icon"));
          return false;
        }
        node.setUserObject(Pair.create(actionId, icon));
        mySelectedSchema.addIconCustomization(actionId, path);
      }
    }
    else {
      node.setUserObject(Pair.create(actionId, null));
      mySelectedSchema.removeIconCustomization(actionId);
      final DefaultMutableTreeNode nodeOnToolbar = findNodeOnToolbar(actionId);
      if (nodeOnToolbar != null){
        editToolbarIcon(actionId, nodeOnToolbar);
        node.setUserObject(nodeOnToolbar.getUserObject());
      }
    }
    return true;
  }
  return false;
}
项目:consulo    文件:ImageUtil.java   
/**
 * Scales the image taking into account its HiDPI awareness.
 */
public static Image scaleImage(Image image, float scale) {
  return ImageLoader.scaleImage(image, scale);
}