mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix tree control alignment in the settings tree
This commit is contained in:
@@ -554,39 +554,38 @@ public class SimpleTree extends Tree implements CellEditorListener {
|
||||
|
||||
myExpandedHandle = null;
|
||||
myCollapsedHandle = null;
|
||||
myExpandedHandle = null;
|
||||
myEmptyHandle = null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Icon getHandleIcon(DefaultMutableTreeNode node, TreePath path) {
|
||||
if (node.getChildCount() == 0) return getEmptyHandle();
|
||||
|
||||
|
||||
return isExpanded(path) ? getExpandedHandle() : getCollapsedHandle();
|
||||
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Icon getExpandedHandle() {
|
||||
if (myExpandedHandle == null) {
|
||||
myExpandedHandle = UIUtil.getTreeExpandedIcon();
|
||||
}
|
||||
|
||||
return myExpandedHandle;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Icon getCollapsedHandle() {
|
||||
if (myCollapsedHandle == null) {
|
||||
myCollapsedHandle = UIUtil.getTreeCollapsedIcon();
|
||||
}
|
||||
|
||||
return myCollapsedHandle;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Icon getEmptyHandle() {
|
||||
if (myEmptyHandle == null) {
|
||||
final Icon expand = getExpandedHandle();
|
||||
myEmptyHandle = expand != null ? EmptyIcon.create(expand) : EmptyIcon.create(0);
|
||||
}
|
||||
|
||||
return myEmptyHandle;
|
||||
}
|
||||
|
||||
|
||||
+48
-10
@@ -19,6 +19,8 @@ import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.components.GradientViewport;
|
||||
import com.intellij.ui.tree.ui.Control;
|
||||
import com.intellij.ui.tree.ui.DefaultControl;
|
||||
import com.intellij.ui.treeStructure.*;
|
||||
import com.intellij.ui.treeStructure.filtered.FilteringTreeBuilder;
|
||||
import com.intellij.ui.treeStructure.filtered.FilteringTreeStructure;
|
||||
@@ -74,6 +76,8 @@ public class SettingsTreeView extends JComponent implements Accessible, Disposab
|
||||
private Configurable myQueuedConfigurable;
|
||||
private boolean myPaintInternalInfo;
|
||||
|
||||
private MyControl myControl;
|
||||
|
||||
public SettingsTreeView(SettingsFilter filter, ConfigurableGroup[] groups) {
|
||||
myFilter = filter;
|
||||
myRoot = new MyRoot(groups);
|
||||
@@ -123,7 +127,7 @@ public class SettingsTreeView extends JComponent implements Accessible, Disposab
|
||||
myHeader.setBorder(BorderFactory.createEmptyBorder(1, 10 + getLeftMargin(0), 0, 0));
|
||||
}
|
||||
myHeader.setFont(myTree.getFont());
|
||||
myHeader.setIcon(myTree.getEmptyHandle());
|
||||
myHeader.setIcon(getIcon(null));
|
||||
int height = myHeader.getPreferredSize().height;
|
||||
String group = findGroupNameAt(0, height + 3);
|
||||
if (group == null || !group.equals(findGroupNameAt(0, 0))) {
|
||||
@@ -181,6 +185,48 @@ public class SettingsTreeView extends JComponent implements Accessible, Disposab
|
||||
Disposer.register(this, myBuilder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUI() {
|
||||
super.updateUI();
|
||||
myControl = null;
|
||||
}
|
||||
|
||||
private Icon getIcon(@Nullable DefaultMutableTreeNode node) {
|
||||
if (myControl == null) myControl = new MyControl();
|
||||
if (node == null || 0 == node.getChildCount()) return myControl.empty;
|
||||
return myTree.isExpanded(new TreePath(node.getPath())) ? myControl.expanded : myControl.collapsed;
|
||||
}
|
||||
|
||||
private static final class MyControl {
|
||||
private final Control control = new DefaultControl();
|
||||
private final Icon collapsed = new MyIcon(false);
|
||||
private final Icon expanded = new MyIcon(true);
|
||||
private final Icon empty = new MyIcon(null);
|
||||
|
||||
private final class MyIcon implements Icon {
|
||||
private final Boolean expanded;
|
||||
|
||||
private MyIcon(@Nullable Boolean expanded) {
|
||||
this.expanded = expanded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconWidth() {
|
||||
return control.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconHeight() {
|
||||
return control.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
if (expanded != null) control.paint(g, x, y, getIconWidth(), getIconHeight(), expanded, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void setComponentPopupMenuTo(JTree tree) {
|
||||
tree.setComponentPopupMenu(new JPopupMenu() {
|
||||
private Transferable transferable;
|
||||
@@ -584,15 +630,7 @@ public class SettingsTreeView extends JComponent implements Accessible, Disposab
|
||||
// configure node icon
|
||||
Icon nodeIcon = null;
|
||||
if (value instanceof DefaultMutableTreeNode) {
|
||||
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode)value;
|
||||
if (0 == treeNode.getChildCount()) {
|
||||
nodeIcon = myTree.getEmptyHandle();
|
||||
}
|
||||
else {
|
||||
nodeIcon = myTree.isExpanded(new TreePath(treeNode.getPath()))
|
||||
? myTree.getExpandedHandle()
|
||||
: myTree.getCollapsedHandle();
|
||||
}
|
||||
nodeIcon = getIcon((DefaultMutableTreeNode)value);
|
||||
}
|
||||
myNodeIcon.setIcon(nodeIcon);
|
||||
if (node != null && myPaintInternalInfo) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.awt.Graphics;
|
||||
import javax.swing.Icon;
|
||||
|
||||
final class DefaultControl implements Control {
|
||||
public final class DefaultControl implements Control {
|
||||
private final CompoundIcon collapsedIcon = new CompoundIcon("treeCollapsed");
|
||||
private final CompoundIcon expandedIcon = new CompoundIcon("treeExpanded");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user