Ejemplo n.º 1
0
  private void doShowHint(
      final XValue xValue,
      final String separator,
      final String value,
      String type,
      @NotNull XValuePresenter valuePresenter,
      final boolean hasChildren) {
    if (isHintHidden()) return;

    SimpleColoredText text = new SimpleColoredText();
    text.append(myExpression, XDebuggerUIConstants.VALUE_NAME_ATTRIBUTES);
    text.append(separator, SimpleTextAttributes.REGULAR_ATTRIBUTES);
    if (type != null) {
      text.append("{" + type + "} ", XDebuggerUIConstants.TYPE_ATTRIBUTES);
    }
    valuePresenter.append(value, text, false);

    if (!hasChildren) {
      showHint(HintUtil.createInformationLabel(text));
    } else if (getType() == ValueHintType.MOUSE_CLICK_HINT) {
      showTree(xValue, myExpression);
    } else {
      JComponent component =
          createExpandableHintComponent(
              text,
              new Runnable() {
                public void run() {
                  showTree(xValue, myExpression);
                }
              });
      showHint(component);
    }
  }
  @NotNull
  private JComponent createHintComponent(
      @NotNull String text,
      @NotNull final FindUsagesHandler handler,
      @NotNull final RelativePoint popupPosition,
      final Editor editor,
      @NotNull final Runnable cancelAction,
      final int maxUsages,
      @NotNull final FindUsagesOptions options) {
    JComponent label =
        HintUtil.createInformationLabel(suggestSecondInvocation(options, handler, text + " "));
    InplaceButton button =
        createSettingsButton(handler, popupPosition, editor, maxUsages, cancelAction);

    JPanel panel =
        new JPanel(new BorderLayout()) {
          @Override
          public void addNotify() {
            mySearchEverywhereRunnable =
                new Runnable() {
                  @Override
                  public void run() {
                    searchEverywhere(options, handler, editor, popupPosition, maxUsages);
                  }
                };
            super.addNotify();
          }

          @Override
          public void removeNotify() {
            mySearchEverywhereRunnable = null;
            super.removeNotify();
          }
        };
    button.setBackground(label.getBackground());
    panel.setBackground(label.getBackground());
    label.setOpaque(false);
    label.setBorder(null);
    panel.setBorder(HintUtil.createHintBorder());
    panel.add(label, BorderLayout.CENTER);
    panel.add(button, BorderLayout.EAST);
    return panel;
  }
Ejemplo n.º 3
0
  /**
   * It's possible that we need to expand quick doc control's width in order to provide better
   * visual representation (see http://youtrack.jetbrains.com/issue/IDEA-101425). This method
   * calculates that width expand.
   *
   * @param buttonWidth icon button's width
   * @param updatedText text which will be should at the quick doc control
   * @return width increase to apply to the target quick doc control (zero if no additional width
   *     increase is required)
   */
  private static int calculateWidthIncrease(int buttonWidth, String updatedText) {
    int maxLineWidth = 0;
    TIntArrayList lineWidths = new TIntArrayList();
    for (String lineText : StringUtil.split(updatedText, "<br/>")) {
      String html = HintUtil.prepareHintText(lineText, HintUtil.getInformationHint());
      int width = new JLabel(html).getPreferredSize().width;
      maxLineWidth = Math.max(maxLineWidth, width);
      lineWidths.add(width);
    }

    if (!lineWidths.isEmpty()) {
      int firstLineAvailableTrailingWidth = maxLineWidth - lineWidths.get(0);
      if (firstLineAvailableTrailingWidth >= buttonWidth) {
        return 0;
      } else {
        return buttonWidth - firstLineAvailableTrailingWidth;
      }
    }
    return 0;
  }
 private static void showEditorHint(String message, final Editor editor) {
   JComponent component = HintUtil.createInformationLabel(message);
   final LightweightHint hint = new LightweightHint(component);
   HintManagerImpl.getInstanceImpl()
       .showEditorHint(
           hint,
           editor,
           HintManager.UNDER,
           HintManager.HIDE_BY_ANY_KEY
               | HintManager.HIDE_BY_TEXT_CHANGE
               | HintManager.HIDE_BY_SCROLLING,
           0,
           false);
 }
  private void showNoSuggestions(boolean isExplicit) {
    hideCurrentPopup();

    if (!isExplicit) return;

    final JComponent message =
        HintUtil.createErrorLabel(IdeBundle.message("file.chooser.completion.no.suggestions"));
    final ComponentPopupBuilder builder =
        JBPopupFactory.getInstance().createComponentPopupBuilder(message, message);
    builder
        .setRequestFocus(false)
        .setResizable(false)
        .setAlpha(0.1f)
        .setFocusOwners(new Component[] {myPathTextField});
    myNoSuggestionsPopup = builder.createPopup();
    myNoSuggestionsPopup.showInScreenCoordinates(getField(), getLocationForCaret(myPathTextField));
  }
 public void setAdText(@NotNull final String s, int alignment) {
   if (myAdComponent == null) {
     myAdComponent =
         HintUtil.createAdComponent(s, BorderFactory.createEmptyBorder(1, 5, 1, 5), alignment);
     JPanel wrapper =
         new JPanel(new BorderLayout()) {
           @Override
           protected void paintComponent(Graphics g) {
             g.setColor(Gray._135);
             g.drawLine(0, 0, getWidth(), 0);
             super.paintComponent(g);
           }
         };
     wrapper.setOpaque(false);
     wrapper.setBorder(new EmptyBorder(1, 0, 0, 0));
     wrapper.add(myAdComponent, BorderLayout.CENTER);
     myContent.add(wrapper, BorderLayout.SOUTH);
     pack(false, true);
   } else {
     myAdComponent.setText(s);
     myAdComponent.setHorizontalAlignment(alignment);
   }
 }
Ejemplo n.º 7
0
    private void showHint(Info info) {
      if (myDisposed) return;
      Component internalComponent = myEditor.getContentComponent();
      if (myHighlighter != null) {
        if (!info.isSimilarTo(myHighlighter.getStoredInfo())) {
          disposeHighlighter();
        } else {
          // highlighter already set
          internalComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
          return;
        }
      }

      if (info.isValid(myEditor.getDocument())) {
        myHighlighter = installHighlighterSet(info, myEditor);

        String text = info.getInfo();

        if (text == null) return;

        JComponent label = HintUtil.createInformationLabel(text);
        final LightweightHint hint = new LightweightHint(label);
        final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
        Point p = HintManagerImpl.getHintPosition(hint, myEditor, myPosition, HintManager.ABOVE);
        hintManager.showEditorHint(
            hint,
            myEditor,
            p,
            HintManager.HIDE_BY_ANY_KEY
                | HintManager.HIDE_BY_TEXT_CHANGE
                | HintManager.HIDE_BY_SCROLLING,
            0,
            false,
            HintManagerImpl.createHintHint(myEditor, p, hint, HintManager.ABOVE)
                .setContentActive(false));
      }
    }
Ejemplo n.º 8
0
    private void showHint(Info info) {
      if (myDisposed || myEditor.isDisposed()) return;
      Component internalComponent = myEditor.getContentComponent();
      if (myHighlighter != null) {
        if (!info.isSimilarTo(myHighlighter.getStoredInfo())) {
          disposeHighlighter();
        } else {
          // highlighter already set
          internalComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
          return;
        }
      }

      if (!info.isValid(myEditor.getDocument())) {
        return;
      }

      myHighlighter = installHighlighterSet(info, myEditor);

      DocInfo docInfo = info.getInfo();

      if (docInfo.text == null) return;

      if (myDocumentationManager.hasActiveDockedDocWindow()) {
        info.showDocInfo(myDocumentationManager);
      }

      HyperlinkListener hyperlinkListener =
          docInfo.docProvider == null
              ? null
              : new QuickDocHyperlinkListener(docInfo.docProvider, info.myElementAtPointer);
      final Ref<QuickDocInfoPane> quickDocPaneRef = new Ref<QuickDocInfoPane>();
      MouseListener mouseListener =
          new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
              QuickDocInfoPane pane = quickDocPaneRef.get();
              if (pane != null) {
                pane.mouseEntered(e);
              }
            }

            @Override
            public void mouseExited(MouseEvent e) {
              QuickDocInfoPane pane = quickDocPaneRef.get();
              if (pane != null) {
                pane.mouseExited(e);
              }
            }

            @Override
            public void mouseClicked(MouseEvent e) {
              QuickDocInfoPane pane = quickDocPaneRef.get();
              if (pane != null) {
                pane.mouseClicked(e);
              }
            }
          };
      Ref<Consumer<String>> newTextConsumerRef = new Ref<Consumer<String>>();
      JComponent label =
          HintUtil.createInformationLabel(
              docInfo.text, hyperlinkListener, mouseListener, newTextConsumerRef);
      Consumer<String> newTextConsumer = newTextConsumerRef.get();
      QuickDocInfoPane quickDocPane = null;
      if (docInfo.documentationAnchor != null) {
        quickDocPane =
            new QuickDocInfoPane(docInfo.documentationAnchor, info.myElementAtPointer, label);
        quickDocPaneRef.set(quickDocPane);
      }

      JComponent hintContent = quickDocPane == null ? label : quickDocPane;

      final LightweightHint hint = new LightweightHint(hintContent);
      myHint = hint;
      hint.addHintListener(
          new HintListener() {
            @Override
            public void hintHidden(EventObject event) {
              myHint = null;
            }
          });
      myDocAlarm.cancelAllRequests();
      if (newTextConsumer != null
          && docInfo.docProvider != null
          && docInfo.documentationAnchor != null) {
        fulfillDocInfo(
            docInfo.text,
            docInfo.docProvider,
            info.myElementAtPointer,
            docInfo.documentationAnchor,
            newTextConsumer,
            hint);
      }

      showHint(hint);
    }