<commit_before>/*
 * Copyright 2000-2009 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.
 */

/*
 * Class DebuggerTreeBase
 * @author Jeka
 */
package com.intellij.debugger.ui.impl;

import com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl;
import com.intellij.debugger.ui.impl.watch.NodeDescriptorImpl;
import com.intellij.debugger.ui.impl.watch.ValueDescriptorImpl;
import com.intellij.ide.dnd.aware.DnDAwareTree;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.ui.ScreenUtil;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.util.text.StringTokenizer;
import com.intellij.util.ui.GeometryUtil;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.tree.TreeUtil;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;


public class DebuggerTreeBase extends DnDAwareTree implements Disposable {
  private final Project myProject;
  private DebuggerTreeNodeImpl myCurrentTooltipNode;

  private JComponent myCurrentTooltip;
  private Point myCurrentPosition;

  protected final TipManager myTipManager;

  public DebuggerTreeBase(TreeModel model, Project project) {
    super(model);
    myProject = project;

    myTipManager = new TipManager(this, new TipManager.TipFactory() {
      public JComponent createToolTip(MouseEvent e) {
        return DebuggerTreeBase.this.createToolTip(e);
      }

      public MouseEvent createTooltipEvent(MouseEvent candiateEvent) {
        return DebuggerTreeBase.this.createTooltipEvent(candiateEvent);
      }

      public boolean isFocusOwner() {
        return DebuggerTreeBase.this.isFocusOwner();
      }
    });

    UIUtil.setLineStyleAngled(this);
    setRootVisible(false);
    setShowsRootHandles(true);
    setCellRenderer(new DebuggerTreeRenderer());
    updateUI();
    TreeUtil.installActions(this);
  }

  private static int getMaximumChars(final String s, final FontMetrics metrics, final int maxWidth) {
    int minChar = 0;
    int maxChar = s.length();
    int chars;
    while (minChar < maxChar) {
      chars = (minChar + maxChar + 1) / 2;
      final int width = metrics.stringWidth(s.substring(0, chars));
      if (width <= maxWidth) {
        minChar = chars;
      }
      else {
        maxChar = chars - 1;
      }
    }
    return minChar;
  }

  private JComponent createTipContent(String tipText, DebuggerTreeNodeImpl node) {
    final JToolTip tooltip = new JToolTip();

    if (tipText == null) {
      tooltip.setTipText(tipText);
    }
    else {
      Dimension rootSize = getVisibleRect().getSize();
      Insets borderInsets = tooltip.getBorder().getBorderInsets(tooltip);
      rootSize.width -= (borderInsets.left + borderInsets.right) * 2;
      rootSize.height -= (borderInsets.top + borderInsets.bottom) * 2;

      //noinspection HardCodedStringLiteral
      final StringBuffer tipBuilder = new StringBuffer();
      try {
        final String markupText = node.getMarkupTooltipText();
        if (markupText != null) {
          tipBuilder.append(markupText);
        }

        if (tipText.length() > 0) {
          tipBuilder.append("<br><br>").append("Value=");

          final StringTokenizer tokenizer = new StringTokenizer(tipText, "\n");

          while (tokenizer.hasMoreElements()) {
            final String each = tokenizer.nextElement();
            tipBuilder.append(JDOMUtil.legalizeText(each));
            tipBuilder.append("<br>");
          }
        }

        tooltip.setTipText(UIUtil.toHtml(tipBuilder.toString(), 0));
      }
      finally {<commit_msg>don't strip empty lines in debugger tooltip (IDEA-58046)<commit_after>/*
 * Copyright 2000-2009 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.
 */

/*
 * Class DebuggerTreeBase
 * @author Jeka
 */
package com.intellij.debugger.ui.impl;

import com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl;
import com.intellij.debugger.ui.impl.watch.NodeDescriptorImpl;
import com.intellij.debugger.ui.impl.watch.ValueDescriptorImpl;
import com.intellij.ide.dnd.aware.DnDAwareTree;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.ui.ScreenUtil;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.util.text.StringTokenizer;
import com.intellij.util.ui.GeometryUtil;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.tree.TreeUtil;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;


public class DebuggerTreeBase extends DnDAwareTree implements Disposable {
  private final Project myProject;
  private DebuggerTreeNodeImpl myCurrentTooltipNode;

  private JComponent myCurrentTooltip;
  private Point myCurrentPosition;

  protected final TipManager myTipManager;

  public DebuggerTreeBase(TreeModel model, Project project) {
    super(model);
    myProject = project;

    myTipManager = new TipManager(this, new TipManager.TipFactory() {
      public JComponent createToolTip(MouseEvent e) {
        return DebuggerTreeBase.this.createToolTip(e);
      }

      public MouseEvent createTooltipEvent(MouseEvent candiateEvent) {
        return DebuggerTreeBase.this.createTooltipEvent(candiateEvent);
      }

      public boolean isFocusOwner() {
        return DebuggerTreeBase.this.isFocusOwner();
      }
    });

    UIUtil.setLineStyleAngled(this);
    setRootVisible(false);
    setShowsRootHandles(true);
    setCellRenderer(new DebuggerTreeRenderer());
    updateUI();
    TreeUtil.installActions(this);
  }

  private static int getMaximumChars(final String s, final FontMetrics metrics, final int maxWidth) {
    int minChar = 0;
    int maxChar = s.length();
    int chars;
    while (minChar < maxChar) {
      chars = (minChar + maxChar + 1) / 2;
      final int width = metrics.stringWidth(s.substring(0, chars));
      if (width <= maxWidth) {
        minChar = chars;
      }
      else {
        maxChar = chars - 1;
      }
    }
    return minChar;
  }

  private JComponent createTipContent(String tipText, DebuggerTreeNodeImpl node) {
    final JToolTip tooltip = new JToolTip();

    if (tipText == null) {
      tooltip.setTipText(tipText);
    }
    else {
      Dimension rootSize = getVisibleRect().getSize();
      Insets borderInsets = tooltip.getBorder().getBorderInsets(tooltip);
      rootSize.width -= (borderInsets.left + borderInsets.right) * 2;
      rootSize.height -= (borderInsets.top + borderInsets.bottom) * 2;

      //noinspection HardCodedStringLiteral
      final StringBuffer tipBuilder = new StringBuffer();
      try {
        final String markupText = node.getMarkupTooltipText();
        if (markupText != null) {
          tipBuilder.append(markupText);
        }

        if (tipText.length() > 0) {
          tipBuilder.append("<br><br>").append("Value=");

          final StringTokenizer tokenizer = new StringTokenizer(tipText, "\n", true);

          while (tokenizer.hasMoreElements()) {
            final String each = tokenizer.nextElement();
            if ("\n".equals(each)) {
              tipBuilder.append("<br>");
            }
            else {
              tipBuilder.append(JDOMUtil.legalizeText(each));
            }
          }
        }

        tooltip.setTipText(UIUtil.toHtml(tipBuilder.toString(), 0));
      }
      finally {
{'fraction_non_alphanumeric': 0.10088148873653281, 'fraction_numerical': 0.00511481118728915, 'mean_word_length': 3.4590004852013587, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5398137', 'n_tokens_mistral': 2783, 'n_tokens_neox': 2701, 'n_words': 633}