From a0e0a64637fbb4fe9e4fb825c60965370b841fbd Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Wed, 29 Jun 2016 20:38:50 +0300 Subject: [PATCH] show warning in settings UI when user enables ligatures, and IDE is not launched using bundled JRE add clickable link to Confluence page about JetBrains Runtime Environment --- .../options/colors/FontOptions.java | 12 ++-- .../com/intellij/ide/IdeTooltipManager.java | 45 +++++++++----- .../ui/TooltipWithClickableLinks.java | 59 +++++++++++++++++++ .../src/messages/ApplicationBundle.properties | 2 +- 4 files changed, 96 insertions(+), 22 deletions(-) create mode 100644 platform/platform-impl/src/com/intellij/ui/TooltipWithClickableLinks.java diff --git a/platform/lang-impl/src/com/intellij/application/options/colors/FontOptions.java b/platform/lang-impl/src/com/intellij/application/options/colors/FontOptions.java index b133d5e02b09..59e3f116c0db 100644 --- a/platform/lang-impl/src/com/intellij/application/options/colors/FontOptions.java +++ b/platform/lang-impl/src/com/intellij/application/options/colors/FontOptions.java @@ -18,6 +18,7 @@ package com.intellij.application.options.colors; import com.intellij.application.options.EditorFontsConstants; import com.intellij.icons.AllIcons; +import com.intellij.ide.IdeTooltipManager; import com.intellij.ide.ui.AntialiasingType; import com.intellij.ide.ui.UISettings; import com.intellij.openapi.application.ApplicationBundle; @@ -27,10 +28,7 @@ import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.colors.FontPreferences; import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.util.SystemInfo; -import com.intellij.ui.DocumentAdapter; -import com.intellij.ui.FontComboBox; -import com.intellij.ui.FontInfoRenderer; -import com.intellij.ui.IdeBorderFactory; +import com.intellij.ui.*; import com.intellij.ui.components.JBCheckBox; import com.intellij.util.EventDispatcher; import com.intellij.util.ui.JBUI; @@ -105,7 +103,11 @@ public class FontOptions extends JPanel implements OptionsPanel{ myEnableLigaturesCheckbox.setBorder(null); panel.add(myEnableLigaturesCheckbox); JLabel warningIcon = new JLabel(AllIcons.General.BalloonWarning); - warningIcon.setToolTipText(ApplicationBundle.message("ligatures.jre.warning", ApplicationNamesInfo.getInstance().getFullProductName())); + IdeTooltipManager.getInstance().setCustomTooltip( + warningIcon, + new TooltipWithClickableLinks.ForBrowser(warningIcon, + ApplicationBundle.message("ligatures.jre.warning", + ApplicationNamesInfo.getInstance().getFullProductName()))); warningIcon.setBorder(JBUI.Borders.emptyLeft(5)); updateWarningIconVisibility(warningIcon); panel.add(warningIcon); diff --git a/platform/platform-impl/src/com/intellij/ide/IdeTooltipManager.java b/platform/platform-impl/src/com/intellij/ide/IdeTooltipManager.java index c4a88552ee43..55996f068815 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeTooltipManager.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeTooltipManager.java @@ -38,6 +38,7 @@ import com.intellij.ui.*; import com.intellij.ui.awt.RelativePoint; import com.intellij.ui.components.panels.Wrapper; import com.intellij.util.Alarm; +import com.intellij.util.ObjectUtils; import com.intellij.util.ui.Html; import com.intellij.util.ui.JBInsets; import com.intellij.util.ui.JBUI; @@ -57,6 +58,7 @@ import java.awt.event.AWTEventListener; import java.awt.event.MouseEvent; public class IdeTooltipManager implements ApplicationComponent, AWTEventListener { + private static final String CUSTOM_TOOLTIP = "custom.tooltip"; public static final String IDE_TOOLTIP_PLACE = "IdeTooltip"; public static final Color GRAPHITE_COLOR = new Color(100, 100, 100, 230); @@ -177,7 +179,7 @@ public class IdeTooltipManager implements ApplicationComponent, AWTEventListener } String tooltipText = comp.getToolTipText(me); - if (tooltipText == null || tooltipText.trim().isEmpty()) return; + if ((tooltipText == null || tooltipText.trim().isEmpty()) && getCustomTooltip(comp) == null) return; boolean centerDefault = Boolean.TRUE.equals(comp.getClientProperty(UIUtil.CENTER_TOOLTIP_DEFAULT)); @@ -199,29 +201,40 @@ public class IdeTooltipManager implements ApplicationComponent, AWTEventListener } private void queueShow(final JComponent c, final MouseEvent me, final boolean toCenter, int shift, int posChangeX, int posChangeY) { - String aText = String.valueOf(c.getToolTipText(me)); - final IdeTooltip tooltip = new IdeTooltip(c, me.getPoint(), null, /*new Object()*/c, aText) { - @Override - protected boolean beforeShow() { - myCurrentEvent = me; + IdeTooltip tooltip = getCustomTooltip(c); + if (tooltip == null) { + String aText = String.valueOf(c.getToolTipText(me)); + tooltip = new IdeTooltip(c, me.getPoint(), null, /*new Object()*/c, aText) { + @Override + protected boolean beforeShow() { + myCurrentEvent = me; - if (!c.isShowing()) return false; + if (!c.isShowing()) return false; - String text = c.getToolTipText(myCurrentEvent); - if (text == null || text.trim().isEmpty()) return false; + String text = c.getToolTipText(myCurrentEvent); + if (text == null || text.trim().isEmpty()) return false; - JLayeredPane layeredPane = UIUtil.getParentOfType(JLayeredPane.class, c); + JLayeredPane layeredPane = UIUtil.getParentOfType(JLayeredPane.class, c); - final JEditorPane pane = initPane(text, new HintHint(me).setAwtTooltip(true), layeredPane); - final Wrapper wrapper = new Wrapper(pane); - setTipComponent(wrapper); - return true; - } - }.setToCenter(toCenter).setCalloutShift(shift).setPositionChangeShift(posChangeX, posChangeY).setLayer(Balloon.Layer.top); + final JEditorPane pane = initPane(text, new HintHint(me).setAwtTooltip(true), layeredPane); + final Wrapper wrapper = new Wrapper(pane); + setTipComponent(wrapper); + return true; + } + }.setToCenter(toCenter).setCalloutShift(shift).setPositionChangeShift(posChangeX, posChangeY).setLayer(Balloon.Layer.top); + } show(tooltip, false); } + public void setCustomTooltip(JComponent component, IdeTooltip tooltip) { + component.putClientProperty(CUSTOM_TOOLTIP, tooltip); + } + + public IdeTooltip getCustomTooltip(JComponent component) { + return ObjectUtils.tryCast(component.getClientProperty(CUSTOM_TOOLTIP), IdeTooltip.class); + } + public IdeTooltip show(final IdeTooltip tooltip, boolean now) { return show(tooltip, now, true); } diff --git a/platform/platform-impl/src/com/intellij/ui/TooltipWithClickableLinks.java b/platform/platform-impl/src/com/intellij/ui/TooltipWithClickableLinks.java new file mode 100644 index 000000000000..bbbe06cf18f0 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ui/TooltipWithClickableLinks.java @@ -0,0 +1,59 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.ui; + +import com.intellij.ide.BrowserUtil; +import com.intellij.ide.IdeTooltip; +import com.intellij.ide.IdeTooltipManager; +import com.intellij.ide.TooltipEvent; + +import javax.swing.*; +import javax.swing.event.HyperlinkEvent; +import javax.swing.event.HyperlinkListener; +import java.awt.*; + +/** + * Custom tooltip implementation which supports clickable links in HTML text + * + * @see IdeTooltipManager#setCustomTooltip(JComponent, IdeTooltip) + */ +public class TooltipWithClickableLinks extends IdeTooltip { + public TooltipWithClickableLinks(JComponent component, String htmlText, HyperlinkListener hyperlinkListener) { + super(component, new Point(), createTipComponent(htmlText, hyperlinkListener), component, htmlText); + } + + private static JComponent createTipComponent(String text, HyperlinkListener hyperlinkListener) { + JEditorPane pane = IdeTooltipManager.initPane(text, new HintHint().setAwtTooltip(true), null); + pane.addHyperlinkListener(hyperlinkListener); + return pane; + } + + @Override + protected boolean canAutohideOn(TooltipEvent event) { + return !event.isIsEventInsideBalloon(); + } + + public static class ForBrowser extends TooltipWithClickableLinks { + public ForBrowser(JComponent component, String htmlText) { + super(component, htmlText, new HyperlinkAdapter() { + @Override + protected void hyperlinkActivated(HyperlinkEvent e) { + BrowserUtil.browse(e.getURL()); + } + }); + } + } +} diff --git a/platform/platform-resources-en/src/messages/ApplicationBundle.properties b/platform/platform-resources-en/src/messages/ApplicationBundle.properties index 19ac3c9e7033..fb0ab61a8f02 100644 --- a/platform/platform-resources-en/src/messages/ApplicationBundle.properties +++ b/platform/platform-resources-en/src/messages/ApplicationBundle.properties @@ -533,7 +533,7 @@ checkbox.show.only.monospaced.fonts=Show only monospaced fonts primary.font=Primary font: secondary.font=Secondary font: use.ligatures=Enable font ligatures -ligatures.jre.warning=The JRE you are running {0} with might have\nfunctional and performance issues related to ligatures support.\nTo avoid such issues, run IntelliJ IDEA with the bundled JRE. +ligatures.jre.warning=The JRE you are running {0} with might have
functional and performance issues related to ligatures support.
To avoid such issues, run {0} with JetBrains Runtime. editbox.enter.tag.name=Enter tag name: title.tag.name=Tag Name title.xml=XML