Search in sources :

Example 16 with HintHint

use of com.intellij.ui.HintHint in project intellij-community by JetBrains.

the class PopupFactoryImpl method createHtmlTextBalloonBuilder.

@NotNull
@Override
public BalloonBuilder createHtmlTextBalloonBuilder(@NotNull final String htmlContent, @Nullable final Icon icon, final Color fillColor, @Nullable final HyperlinkListener listener) {
    JEditorPane text = IdeTooltipManager.initPane(htmlContent, new HintHint().setAwtTooltip(true), null);
    if (listener != null) {
        text.addHyperlinkListener(listener);
    }
    text.setEditable(false);
    NonOpaquePanel.setTransparent(text);
    text.setBorder(null);
    JLabel label = new JLabel();
    final JPanel content = new NonOpaquePanel(new BorderLayout((int) (label.getIconTextGap() * 1.5), (int) (label.getIconTextGap() * 1.5)));
    final NonOpaquePanel textWrapper = new NonOpaquePanel(new GridBagLayout());
    JScrollPane scrolledText = new JScrollPane(text);
    scrolledText.setBackground(fillColor);
    scrolledText.getViewport().setBackground(fillColor);
    scrolledText.getViewport().setBorder(null);
    scrolledText.setBorder(null);
    textWrapper.add(scrolledText);
    content.add(textWrapper, BorderLayout.CENTER);
    final NonOpaquePanel north = new NonOpaquePanel(new BorderLayout());
    north.add(new JLabel(icon), BorderLayout.NORTH);
    content.add(north, BorderLayout.WEST);
    content.setBorder(new EmptyBorder(2, 4, 2, 4));
    final BalloonBuilder builder = createBalloonBuilder(content);
    builder.setFillColor(fillColor);
    return builder;
}
Also used : NonOpaquePanel(com.intellij.ui.components.panels.NonOpaquePanel) HintHint(com.intellij.ui.HintHint) EmptyBorder(javax.swing.border.EmptyBorder) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with HintHint

use of com.intellij.ui.HintHint in project intellij-community by JetBrains.

the class ShowXPathAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
    if (editor == null) {
        return;
    }
    final Project project = editor.getProject();
    if (project == null) {
        return;
    }
    final PsiDocumentManager docmgr = PsiDocumentManager.getInstance(project);
    final Document document = editor.getDocument();
    docmgr.commitDocument(document);
    final PsiFile psiFile = docmgr.getPsiFile(document);
    if (!(psiFile instanceof XmlFile)) {
        return;
    }
    final PsiElement element = psiFile.findElementAt(editor.getCaretModel().getOffset());
    if (!(element instanceof XmlElement || element instanceof PsiWhiteSpace)) {
        XPathAppComponent.showEditorHint("No suitable context for an XPath-expression selected.", editor);
        return;
    }
    final PsiElement node = XPathExpressionGenerator.transformToValidShowPathNode(element);
    if (node == null) {
        XPathAppComponent.showEditorHint("No suitable context for an XPath-expression selected.", editor);
        return;
    }
    final Config cfg = XPathAppComponent.getInstance().getConfig();
    final RangeHighlighter h = HighlighterUtil.highlightNode(editor, node, cfg.getContextAttributes(), cfg);
    final String path = XPathSupport.getInstance().getUniquePath((XmlElement) node, null);
    final JTextField label = new JTextField(path);
    label.setPreferredSize(new Dimension(label.getPreferredSize().width + new JLabel("M").getPreferredSize().width, label.getPreferredSize().height));
    label.setOpaque(false);
    label.setEditable(false);
    label.setBorder(null);
    label.setHorizontalAlignment(SwingConstants.CENTER);
    label.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
    final JPanel p = new NonOpaquePanel(new BorderLayout());
    final JLabel l = new JLabel("XPath:");
    p.add(l, BorderLayout.WEST);
    p.add(label, BorderLayout.CENTER);
    InplaceButton copy = new InplaceButton(ActionsBundle.message("action.EditorCopy.text"), PlatformIcons.COPY_ICON, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            CopyPasteManager.getInstance().setContents(new StringSelection(path));
        }
    });
    p.add(copy, BorderLayout.EAST);
    final LightweightHint hint = new LightweightHint(p) {

        public void hide() {
            super.hide();
            HighlighterUtil.removeHighlighter(editor, h);
        }
    };
    final Point point = editor.visualPositionToXY(editor.getCaretModel().getVisualPosition());
    point.y += editor.getLineHeight() / 2;
    HintHint hintHint = new HintHint(editor, point).setAwtTooltip(true).setContentActive(true).setExplicitClose(true).setShowImmediately(true);
    HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, point, HintManager.HIDE_BY_ANY_KEY, 0, false, hintHint);
}
Also used : ActionEvent(java.awt.event.ActionEvent) Document(com.intellij.openapi.editor.Document) StringSelection(java.awt.datatransfer.StringSelection) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) NonOpaquePanel(com.intellij.ui.components.panels.NonOpaquePanel) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) XmlFile(com.intellij.psi.xml.XmlFile) LightweightHint(com.intellij.ui.LightweightHint) InplaceButton(com.intellij.ui.InplaceButton) Project(com.intellij.openapi.project.Project) HintHint(com.intellij.ui.HintHint) ActionListener(java.awt.event.ActionListener) XmlElement(com.intellij.psi.xml.XmlElement) Editor(com.intellij.openapi.editor.Editor) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Example 18 with HintHint

use of com.intellij.ui.HintHint in project intellij-community by JetBrains.

the class QuickFixManager method showIntentionHint.

/**
   * Shows intention hint (light bulb) if it's not visible yet.
   */
final void showIntentionHint() {
    if (!myComponent.isShowing() || !IJSwingUtilities.hasFocus(myComponent)) {
        hideIntentionHint();
        return;
    }
    // 1. Hide previous hint (if any)
    hideIntentionHint();
    // 2. Found error (if any)
    final ErrorInfo[] errorInfos = getErrorInfos();
    if (!haveFixes(errorInfos)) {
        hideIntentionHint();
        return;
    }
    // 3. Determine position where this hint should be shown
    final Rectangle bounds = getErrorBounds();
    if (bounds == null) {
        return;
    }
    // 4. Show light bulb to fix this error
    final LightBulbComponentImpl lightBulbComponent = new LightBulbComponentImpl(this, AllIcons.Actions.IntentionBulb);
    myHint = new LightweightHint(lightBulbComponent);
    myLastHintBounds = bounds;
    myHint.show(myComponent, bounds.x - AllIcons.Actions.IntentionBulb.getIconWidth() - 4, bounds.y, myComponent, new HintHint(myComponent, bounds.getLocation()));
}
Also used : HintHint(com.intellij.ui.HintHint) ErrorInfo(com.intellij.uiDesigner.ErrorInfo) LightweightHint(com.intellij.ui.LightweightHint)

Aggregations

HintHint (com.intellij.ui.HintHint)18 LightweightHint (com.intellij.ui.LightweightHint)10 Document (com.intellij.openapi.editor.Document)4 TooltipController (com.intellij.codeInsight.hint.TooltipController)2 Editor (com.intellij.openapi.editor.Editor)2 RelativePoint (com.intellij.ui.awt.RelativePoint)2 NonOpaquePanel (com.intellij.ui.components.panels.NonOpaquePanel)2 GutterMark (com.intellij.codeInsight.daemon.GutterMark)1 NonHideableIconGutterMark (com.intellij.codeInsight.daemon.NonHideableIconGutterMark)1 ErrorInfo (com.intellij.designer.model.ErrorInfo)1 DiffFragment (com.intellij.diff.fragments.DiffFragment)1 LineRange (com.intellij.diff.util.LineRange)1 IdeTooltip (com.intellij.ide.IdeTooltip)1 EditorWindow (com.intellij.injected.editor.EditorWindow)1 Disposable (com.intellij.openapi.Disposable)1 EditorFactory (com.intellij.openapi.editor.EditorFactory)1 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)1 EditorActionManager (com.intellij.openapi.editor.actionSystem.EditorActionManager)1 TypedAction (com.intellij.openapi.editor.actionSystem.TypedAction)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1