@Override public Dimension getPreferredSize() { Dimension size = super.getPreferredSize(); UIManager.LookAndFeelInfo info = LafManager.getInstance().getCurrentLookAndFeel(); if (info != null && info.getName().contains("Windows")) size.width += 10; return size; }
private void initComponents() { Platform.runLater( () -> { myPane = new StackPane(); myWebComponent = new WebView(); myEngine = myWebComponent.getEngine(); if (myShowProgress) { myProgressBar = makeProgressBarWithListener(); myWebComponent.setVisible(false); myPane.getChildren().addAll(myWebComponent, myProgressBar); } else { myPane.getChildren().add(myWebComponent); } if (myLinkInNewBrowser) { initHyperlinkListener(); } Scene scene = new Scene(myPane); myPanel.setScene(scene); myPanel.setVisible(true); updateLaf( LafManager.getInstance().getCurrentLookAndFeel() instanceof DarculaLookAndFeelInfo); }); add(myPanel, BorderLayout.CENTER); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); }
private JTextField createColorField(boolean hex) { final NumberDocument doc = new NumberDocument(hex); int lafFix = UIUtil.isUnderWindowsLookAndFeel() || UIUtil.isUnderDarcula() ? 1 : 0; UIManager.LookAndFeelInfo info = LafManager.getInstance().getCurrentLookAndFeel(); if (info != null && (info.getName().startsWith("IDEA") || info.getName().equals("Windows Classic"))) lafFix = 1; final JTextField field; if (SystemInfo.isMac && UIUtil.isUnderIntelliJLaF()) { field = new JTextField(""); field.setDocument(doc); field.setPreferredSize(new Dimension(hex ? 60 : 40, 26)); } else { field = new JTextField(doc, "", (hex ? 5 : 2) + lafFix); field.setSize(50, -1); } doc.setSource(field); field.getDocument().addDocumentListener(this); field.addFocusListener( new FocusAdapter() { @Override public void focusGained(final FocusEvent e) { field.selectAll(); } }); return field; }
public StudyBrowserWindow(final boolean linkInNewWindow, final boolean showProgress) { myLinkInNewBrowser = linkInNewWindow; myShowProgress = showProgress; setSize(new Dimension(900, 800)); setLayout(new BorderLayout()); setPanel(new JFXPanel()); setTitle("Study Browser"); LafManager.getInstance().addLafManagerListener(new StudyLafManagerListener()); initComponents(); }
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); } }
@Override public void apply() throws ConfigurationException { if (myApplyCompleted) { return; } try { EditorColorsManager myColorsManager = EditorColorsManager.getInstance(); myColorsManager.removeAllSchemes(); for (MyColorScheme scheme : mySchemes.values()) { if (!scheme.isDefault()) { scheme.apply(); myColorsManager.addColorsScheme(scheme.getOriginalScheme()); } } EditorColorsScheme originalScheme = mySelectedScheme.getOriginalScheme(); myColorsManager.setGlobalScheme(originalScheme); if (originalScheme != null && DarculaLaf.NAME.equals(originalScheme.getName()) && !UIUtil.isUnderDarcula()) { int ok = Messages.showYesNoDialog( "Darcula color scheme has been set for editors. Would you like to set Darcula as default Look and Feel?", "Darcula Look and Feel", Messages.getQuestionIcon()); if (ok == Messages.YES) { LafManager.getInstance().setCurrentLookAndFeel(new DarculaLookAndFeelInfo()); DarculaInstaller.install(); } } applyChangesToEditors(); reset(); } finally { myApplyCompleted = true; } }
@Override public void lookAndFeelChanged(LafManager manager) { updateLaf(manager.getCurrentLookAndFeel() instanceof DarculaLookAndFeelInfo); }
@Nullable private String createHtmlWithCodeHighlighting( @NotNull final String content, @NotNull StudyToolWindowConfigurator configurator) { String template = null; InputStream stream = getClass().getResourceAsStream("/code-mirror/template.html"); try { template = StreamUtil.readText(stream, "utf-8"); } catch (IOException e) { LOG.warn(e.getMessage()); } finally { try { stream.close(); } catch (IOException e) { LOG.warn(e.getMessage()); } } if (template == null) { LOG.warn("Code mirror template is null"); return null; } final EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme(); int fontSize = editorColorsScheme.getEditorFontSize(); template = template.replace("${font_size}", String.valueOf(fontSize - 2)); template = template.replace( "${highlight_mode}", getClass().getResource("/code-mirror/clike.js").toExternalForm()); template = template.replace( "${codemirror}", getClass().getResource("/code-mirror/codemirror.js").toExternalForm()); template = template.replace( "${python}", getClass().getResource("/code-mirror/python.js").toExternalForm()); template = template.replace( "${runmode}", getClass().getResource("/code-mirror/runmode.js").toExternalForm()); template = template.replace( "${colorize}", getClass().getResource("/code-mirror/colorize.js").toExternalForm()); template = template.replace( "${javascript}", getClass().getResource("/code-mirror/javascript.js").toExternalForm()); if (LafManager.getInstance().getCurrentLookAndFeel() instanceof DarculaLookAndFeelInfo) { template = template.replace( "${css_oldcodemirror}", getClass().getResource("/code-mirror/codemirror-old-darcula.css").toExternalForm()); template = template.replace( "${css_codemirror}", getClass().getResource("/code-mirror/codemirror-darcula.css").toExternalForm()); } else { template = template.replace( "${css_oldcodemirror}", getClass().getResource("/code-mirror/codemirror-old.css").toExternalForm()); template = template.replace( "${css_codemirror}", getClass().getResource("/code-mirror/codemirror.css").toExternalForm()); } template = template.replace("${default-mode}", configurator.getDefaultHighlightingMode()); template = template.replace("${code}", content); return template; }