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

项目:intellij-ce-playground    文件:TipUIUtil.java   
@NotNull
public static JEditorPane createTipBrowser() {
  JEditorPane browser = new JEditorPane();
  browser.setEditable(false);
  browser.setBackground(UIUtil.getTextFieldBackground());
  browser.addHyperlinkListener(
    new HyperlinkListener() {
      public void hyperlinkUpdate(HyperlinkEvent e) {
        if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
          BrowserUtil.browse(e.getURL());
        }
      }
    }
  );
  URL resource = ResourceUtil.getResource(TipUIUtil.class, "/tips/css/", UIUtil.isUnderDarcula() ? "tips_darcula.css" : "tips.css");
  final StyleSheet styleSheet = UIUtil.loadStyleSheet(resource);
  HTMLEditorKit kit = new HTMLEditorKit() {
    @Override
    public StyleSheet getStyleSheet() {
      return styleSheet != null ? styleSheet : super.getStyleSheet();
    }
  };
  browser.setEditorKit(kit);
  return browser;
}
项目:eddy    文件:EddyPlugin.java   
public static Properties getProperties() {
  if (_properties == null) {
    _properties = new Properties();

    try {
      final String pathname = PathUtil.getJarPathForClass(EddyPlugin.class);
      final File path = new File(pathname);
      if (path.isDirectory()) {
        log("looking for resources in directory: " + pathname);
        _properties.load(new FileInputStream(new File(path, "eddy.properties")));
      } else {
        final URL url = ResourceUtil.getResource(EddyPlugin.class, "", "eddy.properties");
        _properties.load(url.openStream());
      }
    } catch (IOException e) {
      log("cannot read version information: " + e);
    }
  }
  return _properties;
}
项目:eddy    文件:EddyWidget.java   
static private void makeIcons() {
  final String pathname = PathUtil.getJarPathForClass(EddyWidget.class);
  final File path = new File(pathname);

  if (path.isDirectory()) {
    log("looking for resources in directory: " + pathname);
    eddyIcon = new ImageIcon(new File(path, "eddy-icon-16.png").getPath());
    eddyIconGray = new ImageIcon(new File(path, "eddy-icon-16-gray.png").getPath());
    eddyIconSleep = new ImageIcon(new File(path, "eddy-icon-16-sleep.png").getPath());
  } else {
    final URL colorurl = ResourceUtil.getResource(EddyWidget.class, "", "eddy-icon-16.png");
    final URL greyurl = ResourceUtil.getResource(EddyWidget.class, "", "eddy-icon-16-gray.png");
    final URL sleepurl = ResourceUtil.getResource(EddyWidget.class, "", "eddy-icon-16-sleep.png");
    eddyIcon = new ImageIcon(colorurl);
    eddyIconGray = new ImageIcon(greyurl);
    eddyIconSleep = new ImageIcon(sleepurl);
  }
}
项目:consulo    文件:TipUIUtil.java   
@Nonnull
public static JEditorPane createTipBrowser() {
  JEditorPane browser = new JEditorPane() {
    @Override
    public void setDocument(Document document) {
      super.setDocument(document);
      document.putProperty("imageCache", new URLDictionatyLoader());
    }
  };
  browser.setEditable(false);
  browser.setBackground(UIUtil.getTextFieldBackground());
  browser.addHyperlinkListener(e -> {
    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
      BrowserUtil.browse(e.getURL());
    }
  });
  URL resource = ResourceUtil.getResource(TipUIUtil.class, "/tips/css/", UIUtil.isUnderDarcula() ? "tips_darcula.css" : "tips.css");
  HTMLEditorKit kit = UIUtil.getHTMLEditorKit(false);
  kit.getStyleSheet().addStyleSheet(UIUtil.loadStyleSheet(resource));
  browser.setEditorKit(kit);
  return browser;
}
项目:bxfs    文件:BxCore.java   
@NotNull
public static String loadTemplate(String name) {
    try {
        return ResourceUtil.loadText(BitrixFramework.class.getResource("/pro/opcode/bitrix/resources/php/" + name + ".php"));
    } catch (IOException e){
        e.printStackTrace();
    }

    return "";
}
项目:intellij-ce-playground    文件:InspectionToolWrapper.java   
public String loadDescription() {
  final String description = getStaticDescription();
  if (description != null) return description;
  try {
    URL descriptionUrl = getDescriptionUrl();
    if (descriptionUrl == null) return null;
    return ResourceUtil.loadText(descriptionUrl);
  }
  catch (IOException ignored) { }

  return getTool().loadDescription();
}
项目:intellij-ce-playground    文件:InspectionProfileEntry.java   
@Nullable
public String loadDescription() {
  final String description = getStaticDescription();
  if (description != null) return description;

  try {
    URL descriptionUrl = getDescriptionUrl();
    if (descriptionUrl == null) return null;
    return ResourceUtil.loadText(descriptionUrl);
  }
  catch (IOException ignored) {
  }

  return null;
}
项目:intellij-ce-playground    文件:IdeResourcesTestCase.java   
public void testTipFilesPresent() {
  Collection<String> errors = ContainerUtil.newTreeSet();
  TipAndTrickBean[] tips = TipAndTrickBean.EP_NAME.getExtensions();
  assertNotEmpty(Arrays.asList(tips));
  for (TipAndTrickBean tip : tips) {
    URL url = ResourceUtil.getResource(tip.getPluginDescriptor().getPluginClassLoader(), "/tips/", tip.fileName);
    if (url == null) {
      errors.add(tip.fileName);
    }
  }
  assertEquals(tips.length + " tips are checked, the following files are missing:\n" + StringUtil.join(errors, "\n"), 0, errors.size());
}
项目:intellij-ce-playground    文件:SearchableOptionsRegistrarImpl.java   
public SearchableOptionsRegistrarImpl() {
  if (ApplicationManager.getApplication().isCommandLine() ||
      ApplicationManager.getApplication().isUnitTestMode()) return;
  try {
    //stop words
    final String text = ResourceUtil.loadText(ResourceUtil.getResource(SearchableOptionsRegistrarImpl.class, "/search/", "ignore.txt"));
    final String[] stopWords = text.split("[\\W]");
    ContainerUtil.addAll(myStopWords, stopWords);
  }
  catch (IOException e) {
    LOG.error(e);
  }

  loadExtensions();
}
项目:intellij-ce-playground    文件:TipUIUtil.java   
public static void openTipInBrowser(@Nullable TipAndTrickBean tip, JEditorPane browser) {
  if (tip == null) return;
  try {
    PluginDescriptor pluginDescriptor = tip.getPluginDescriptor();
    ClassLoader tipLoader = pluginDescriptor == null ? TipUIUtil.class.getClassLoader() :
                            ObjectUtils.notNull(pluginDescriptor.getPluginClassLoader(), TipUIUtil.class.getClassLoader());

    URL url = ResourceUtil.getResource(tipLoader, "/tips/", tip.fileName);

    if (url == null) {
      setCantReadText(browser, tip);
      return;
    }

    StringBuffer text = new StringBuffer(ResourceUtil.loadText(url));
    updateShortcuts(text);
    updateImages(text, tipLoader);
    String replaced = text.toString().replace("&productName;", ApplicationNamesInfo.getInstance().getFullProductName());
    String major = ApplicationInfo.getInstance().getMajorVersion();
    replaced = replaced.replace("&majorVersion;", major);
    String minor = ApplicationInfo.getInstance().getMinorVersion();
    replaced = replaced.replace("&minorVersion;", minor);
    replaced = replaced.replace("&majorMinorVersion;", major + ("0".equals(minor) ? "" : ("." + minor)));
    replaced = replaced.replace("&settingsPath;", CommonBundle.settingsActionPath());
    replaced = replaced.replaceFirst("<link rel=\"stylesheet\".*tips\\.css\">", ""); // don't reload the styles
    if (browser.getUI() == null) {
      browser.updateUI();
      boolean succeed = browser.getUI() != null;
      String message = "reinit JEditorPane.ui: " + (succeed ? "OK" : "FAIL") +
                       ", laf=" + LafManager.getInstance().getCurrentLookAndFeel();
      if (succeed) LOG.warn(message);
      else LOG.error(message);
    }
    adjustFontSize(((HTMLEditorKit)browser.getEditorKit()).getStyleSheet());
    browser.read(new StringReader(replaced), url);
  }
  catch (IOException e) {
    setCantReadText(browser, tip);
  }
}
项目:intellij-ce-playground    文件:DistributionService.java   
private void loadFromFile() {
  // TODO: pull current distribution data on demand
  try {
    String jsonString = ResourceUtil.loadText(ResourceUtil.getResource(this.getClass(), "wizardData", "distributions.json"));
    myDistributions = loadDistributionsFromJson(jsonString);
  } catch (IOException e) {
    LOG.error("Error while trying to load distributions file", e);
  }
}
项目:tools-idea    文件:InspectionToolWrapper.java   
public String loadDescription() {
  final String description = getStaticDescription();
  if (description != null) return description;
  try {
    URL descriptionUrl = getDescriptionUrl();
    if (descriptionUrl == null) return null;
    return ResourceUtil.loadText(descriptionUrl);
  }
  catch (IOException ignored) { }

  return getTool().loadDescription();
}
项目:tools-idea    文件:InspectionProfileEntry.java   
@Nullable
public String loadDescription() {
  final String description = getStaticDescription();
  if (description != null) return description;

  try {
    URL descriptionUrl = getDescriptionUrl();
    if (descriptionUrl == null) return null;
    return ResourceUtil.loadText(descriptionUrl);
  }
  catch (IOException ignored) { }

  return null;
}
项目:tools-idea    文件:SearchableOptionsRegistrarImpl.java   
public SearchableOptionsRegistrarImpl() {
  if (ApplicationManager.getApplication().isCommandLine() ||
      ApplicationManager.getApplication().isUnitTestMode()) return;
  try {
    //stop words
    final String text = ResourceUtil.loadText(ResourceUtil.getResource(SearchableOptionsRegistrarImpl.class, "/search/", "ignore.txt"));
    final String[] stopWords = text.split("[\\W]");
    ContainerUtil.addAll(myStopWords, stopWords);
  }
  catch (IOException e) {
    LOG.error(e);
  }
}
项目:tools-idea    文件:TipUIUtil.java   
public static void openTipInBrowser(String tipPath, JEditorPane browser, Class providerClass) {
  /* TODO: detect that file is not present
  if (!file.exists()) {
    browser.read(new StringReader("Tips for '" + feature.getDisplayName() + "' not found.  Make sure you installed IntelliJ IDEA correctly."), null);
    return;
  }
  */
  try {
    if (tipPath == null) return;
    if (providerClass == null) providerClass = TipUIUtil.class;
    URL url = ResourceUtil.getResource(providerClass, "/tips/", tipPath);

    if (url == null) {
      setCantReadText(browser, tipPath);
      return;
    }

    StringBuffer text = new StringBuffer(ResourceUtil.loadText(url));
    updateShortcuts(text);
    String replaced = text.toString().replace("&productName;", ApplicationNamesInfo.getInstance().getFullProductName());
    replaced = replaced.replace("&majorVersion;", ApplicationInfo.getInstance().getMajorVersion());
    replaced = replaced.replace("&minorVersion;", ApplicationInfo.getInstance().getMinorVersion());
    if (UIUtil.isUnderDarcula()) {
      replaced = replaced.replace("css/tips.css", "css/tips_darcula.css");
    }
    browser.read(new StringReader(replaced), url);
  }
  catch (IOException e) {
    setCantReadText(browser, tipPath);
  }
}
项目:consulo    文件:InspectionToolWrapper.java   
public String loadDescription() {
  final String description = getStaticDescription();
  if (description != null) return description;
  try {
    URL descriptionUrl = getDescriptionUrl();
    if (descriptionUrl == null) return null;
    return ResourceUtil.loadText(descriptionUrl);
  }
  catch (IOException ignored) { }

  return getTool().loadDescription();
}
项目:consulo    文件:InspectionProfileEntry.java   
@Nullable
public String loadDescription() {
  final String description = getStaticDescription();
  if (description != null) return description;

  try {
    URL descriptionUrl = getDescriptionUrl();
    if (descriptionUrl == null) return null;
    return ResourceUtil.loadText(descriptionUrl);
  }
  catch (IOException ignored) { }

  return null;
}
项目:consulo    文件:SearchableOptionsRegistrarImpl.java   
public SearchableOptionsRegistrarImpl() {
  if (ApplicationManager.getApplication().isCommandLine() ||
      ApplicationManager.getApplication().isUnitTestMode()) return;
  try {
    //stop words
    final String text = ResourceUtil.loadText(ResourceUtil.getResource(SearchableOptionsRegistrarImpl.class, "/search/", "ignore.txt"));
    final String[] stopWords = text.split("[\\W]");
    ContainerUtil.addAll(myStopWords, stopWords);
  }
  catch (IOException e) {
    LOG.error(e);
  }
}
项目:intellij-ce-playground    文件:InspectionToolWrapper.java   
@Nullable
protected URL superGetDescriptionUrl() {
  final String fileName = getDescriptionFileName();
  return ResourceUtil.getResource(getDescriptionContextClass(), "/inspectionDescriptions", fileName);
}
项目:intellij-ce-playground    文件:InspectionProfileEntry.java   
@Nullable
protected URL getDescriptionUrl() {
  final String fileName = getDescriptionFileName();
  if (fileName == null) return null;
  return ResourceUtil.getResource(getDescriptionContextClass(), "/inspectionDescriptions", fileName);
}
项目:intellij-ce-playground    文件:TipUIUtil.java   
private static void updateImages(StringBuffer text, ClassLoader tipLoader) {
    final boolean dark = UIUtil.isUnderDarcula();
    final boolean retina = UIUtil.isRetina();
//    if (!dark && !retina) {
//      return;
//    }

    String suffix = "";
    if (retina) suffix += "@2x";
    if (dark) suffix += "_dark";
    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")) {
          path += suffix + ".png";
          URL url = ResourceUtil.getResource(tipLoader, "/tips/", path);
          if (url != null) {
            String newImgTag = "<img src=\"" + path + "\" ";
            if (retina) {
              try {
                final BufferedImage image = ImageIO.read(url.openStream());
                final int w = image.getWidth() / 2;
                final int h = image.getHeight() / 2;
                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);
    }
  }
项目:intellij-ce-playground    文件:ResourceTextDescriptor.java   
@Override
public String getText() throws IOException {
  return ResourceUtil.loadText(myUrl);
}
项目:intellij-ce-playground    文件:DumpInspectionDescriptionsAction.java   
private static URL getDescriptionUrl(final InspectionToolWrapper toolWrapper) {
  final Class aClass = getInspectionClass(toolWrapper);
  return ResourceUtil.getResource(aClass, "/inspectionDescriptions", toolWrapper.getShortName() + ".html");
}
项目:tools-idea    文件:InspectionToolWrapper.java   
@Nullable
protected URL superGetDescriptionUrl() {
  final String fileName = getDescriptionFileName();
  return ResourceUtil.getResource(getDescriptionContextClass(), "/inspectionDescriptions", fileName);
}
项目:tools-idea    文件:InspectionProfileEntry.java   
@Nullable
protected URL getDescriptionUrl() {
  final String fileName = getDescriptionFileName();
  if (fileName == null) return null;
  return ResourceUtil.getResource(getDescriptionContextClass(), "/inspectionDescriptions", fileName);
}
项目:tools-idea    文件:ResourceTextDescriptor.java   
@Override
public String getText() throws IOException {
  return ResourceUtil.loadText(myUrl);
}
项目:tools-idea    文件:DumpInspectionDescriptionsAction.java   
private static URL getDescriptionUrl(final InspectionToolWrapper toolWrapper) {
  final Class aClass = getInspectionClass(toolWrapper);
  return ResourceUtil.getResource(aClass, "/inspectionDescriptions", toolWrapper.getShortName() + ".html");
}
项目:consulo    文件:InspectionToolWrapper.java   
@Nullable
protected URL superGetDescriptionUrl() {
  final String fileName = getDescriptionFileName();
  return ResourceUtil.getResource(getDescriptionContextClass(), "/inspectionDescriptions", fileName);
}
项目:consulo    文件:InspectionProfileEntry.java   
@Nullable
protected URL getDescriptionUrl() {
  final String fileName = getDescriptionFileName();
  if (fileName == null) return null;
  return ResourceUtil.getResource(getDescriptionContextClass(), "/inspectionDescriptions", fileName);
}
项目:consulo    文件:TipUIUtil.java   
public static void openTipInBrowser(@Nullable TipAndTrickBean tip, JEditorPane browser) {
  if (tip == null) return;
  try {
    PluginDescriptor pluginDescriptor = tip.getPluginDescriptor();
    ClassLoader tipLoader = pluginDescriptor == null
                            ? TipUIUtil.class.getClassLoader()
                            : ObjectUtils.notNull(pluginDescriptor.getPluginClassLoader(), TipUIUtil.class.getClassLoader());

    URL url = ResourceUtil.getResource(tipLoader, "/tips/", tip.fileName);

    if (url == null) {
      setCantReadText(browser, tip);
      return;
    }

    StringBuilder text = new StringBuilder(ResourceUtil.loadText(url));
    updateShortcuts(text);
    updateImages(text, tipLoader, browser);
    String replaced = text.toString().replace("&productName;", ApplicationNamesInfo.getInstance().getFullProductName());
    String major = ApplicationInfo.getInstance().getMajorVersion();
    replaced = replaced.replace("&majorVersion;", major);
    String minor = ApplicationInfo.getInstance().getMinorVersion();
    replaced = replaced.replace("&minorVersion;", minor);
    replaced = replaced.replace("&majorMinorVersion;", major + ("0".equals(minor) ? "" : ("." + minor)));
    replaced = replaced.replace("&settingsPath;", CommonBundle.settingsActionPath());
    replaced = replaced.replaceFirst("<link rel=\"stylesheet\".*tips\\.css\">", ""); // don't reload the styles
    if (browser.getUI() == null) {
      browser.updateUI();
      boolean succeed = browser.getUI() != null;
      String message = "reinit JEditorPane.ui: " + (succeed ? "OK" : "FAIL") + ", laf=" + LafManager.getInstance().getCurrentLookAndFeel();
      if (succeed) {
        LOG.warn(message);
      }
      else {
        LOG.error(message);
      }
    }
    browser.read(new StringReader(replaced), url);
  }
  catch (IOException e) {
    setCantReadText(browser, tip);
  }
}
项目:consulo    文件:TipUIUtil.java   
private static void updateImages(StringBuilder text, ClassLoader tipLoader, JEditorPane browser) {
    final boolean dark = UIUtil.isUnderDarcula();
//    if (!dark && !retina) {
//      return;
//    }

    Component af = IdeFrameImpl.getActiveFrame();
    Component comp = af != null ? af : 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);
    }
  }
项目:consulo    文件:ResourceTextDescriptor.java   
@Override
public String getText() throws IOException {
  return ResourceUtil.loadText(myUrl);
}
项目:consulo    文件:DumpInspectionDescriptionsAction.java   
private static URL getDescriptionUrl(final InspectionToolWrapper toolWrapper) {
  final Class aClass = getInspectionClass(toolWrapper);
  return ResourceUtil.getResource(aClass, "/inspectionDescriptions", toolWrapper.getShortName() + ".html");
}