Show tooltip in the Settings tree for the Project icon only.

This commit is contained in:
Sergey Malenkov
2014-07-28 21:29:46 +04:00
parent 365cb603d6
commit ee723252da
2 changed files with 51 additions and 3 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -828,4 +828,35 @@ public class Tree extends JTree implements ComponentWithEmptyText, ComponentWith
public void setHorizontalAutoScrollingEnabled(boolean enabled) {
myHorizontalAutoScrolling = enabled;
}
/**
* Returns the deepest visible component
* that will be rendered at the specified location.
*
* @param x horizontal location in the tree
* @param y vertical location in the tree
* @return the deepest visible component of the renderer
*/
@Nullable
protected Component getDeepestRendererComponentAt(int x, int y) {
int row = getRowForLocation(x, y);
if (row >= 0) {
TreeCellRenderer renderer = getCellRenderer();
if (renderer != null) {
TreePath path = getPathForRow(row);
Object node = path.getLastPathComponent();
Component component = renderer.getTreeCellRendererComponent(this, node,
isRowSelected(row),
isExpanded(row),
getModel().isLeaf(node),
row, true);
Rectangle bounds = getPathBounds(path);
if (bounds != null) {
component.setBounds(bounds); // initialize size to layout complex renderer
return SwingUtilities.getDeepestComponentAt(component, x - bounds.x, y - bounds.y);
}
}
}
return null;
}
}
@@ -409,12 +409,11 @@ public class OptionsTree extends JPanel implements Disposable, OptionsEditorColl
myProjectIcon.setBackground(selected ? getSelectionBackground() : getBackground());
myProjectIcon.setIcon(selected ? AllIcons.General.ProjectConfigurableSelected : AllIcons.General.ProjectConfigurable);
myProjectIcon.setVisible(true);
tree.setToolTipText(OptionsBundle.message(project.isDefault()
myProjectIcon.setToolTipText(OptionsBundle.message(project.isDefault()
? "configurable.default.project.tooltip"
: "configurable.current.project.tooltip"));
} else {
myProjectIcon.setVisible(false);
tree.setToolTipText(null);
}
return result;
}
@@ -627,6 +626,24 @@ public class OptionsTree extends JPanel implements Disposable, OptionsEditorColl
setOpaque(true);
}
@Override
public final String getToolTipText(MouseEvent event) {
if (event != null) {
Point point = event.getPoint();
Component component = getDeepestRendererComponentAt(point.x, point.y);
if (component instanceof JLabel) {
JLabel label = (JLabel)component;
if (label.getIcon() != null) {
String text = label.getToolTipText();
if (text != null) {
return text;
}
}
}
}
return super.getToolTipText(event);
}
@Override
protected boolean paintNodes() {
return false;