public static void openTipInBrowser( String tipFileName, JEditorPane browser, Class providerClass) { TipAndTrickBean tip = TipAndTrickBean.findByFileName(tipFileName); if (tip == null && StringUtil.isNotEmpty(tipFileName)) { tip = new TipAndTrickBean(); tip.fileName = tipFileName; } openTipInBrowser(tip, browser); }
@NotNull public static String getPoweredByText(@NotNull TipAndTrickBean tip) { PluginDescriptor descriptor = tip.getPluginDescriptor(); return descriptor instanceof IdeaPluginDescriptor && !PluginManagerCore.CORE_PLUGIN_ID.equals(descriptor.getPluginId().getIdString()) ? ((IdeaPluginDescriptor) descriptor).getName() : ""; }
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); } }