-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2. 分组支持添加描述信息
- Loading branch information
Showing
10 changed files
with
149 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/java/indi/bookmarkx/ui/tree/BmkTreeCellRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package indi.bookmarkx.ui.tree; | ||
|
||
|
||
import com.intellij.icons.AllIcons; | ||
import com.intellij.openapi.util.IconLoader; | ||
import com.intellij.util.ui.UIUtil; | ||
import indi.bookmarkx.common.BaseColors; | ||
|
||
import javax.swing.Icon; | ||
import javax.swing.JTree; | ||
import javax.swing.tree.DefaultTreeCellRenderer; | ||
import java.awt.Color; | ||
import java.awt.Component; | ||
|
||
/** | ||
* 标签树节点渲染 | ||
* | ||
* @author Nonoas | ||
* @version 1.0 | ||
* @date 2024/5/2 | ||
* @since 1.2.1 | ||
*/ | ||
public class BmkTreeCellRenderer extends DefaultTreeCellRenderer { | ||
|
||
public BmkTreeCellRenderer() { | ||
// ReflectionUtil.setField(DefaultTreeCellRenderer.class, this, Boolean.TYPE, "fillBackground", false); | ||
} | ||
|
||
@Override | ||
public Component getTreeCellRendererComponent(JTree tree, | ||
Object value, | ||
boolean selected, | ||
boolean expanded, | ||
boolean isLeaf, | ||
int row, | ||
boolean hasFocus) { | ||
|
||
setColor(selected, hasFocus); | ||
|
||
super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row, hasFocus); | ||
|
||
BookmarkTreeNode node = (BookmarkTreeNode) value; | ||
Icon icon = null; | ||
if (0 == row) { | ||
// if is root node | ||
icon = AllIcons.Nodes.Module; | ||
} else if (row > 0) { | ||
icon = node.isBookmark() | ||
? IconLoader.findIcon("icons/bookmark.svg") | ||
: AllIcons.Nodes.Folder; | ||
} | ||
setIcon(icon); | ||
return this; | ||
} | ||
|
||
/** | ||
* This method fix the difference of background color between the icon and text in the hover state | ||
*/ | ||
private void setColor(boolean selected, boolean hasFocus) { | ||
this.setBorderSelectionColor(null); | ||
this.setBackgroundSelectionColor(null); | ||
this.setBackgroundNonSelectionColor(null); | ||
this.setBackground(UIUtil.getTreeBackground(selected, hasFocus)); | ||
this.setForeground(UIUtil.getTreeForeground(selected, hasFocus)); | ||
} | ||
|
||
@Override | ||
public Color getBorderSelectionColor() { | ||
return BaseColors.TRANSPARENT; | ||
} | ||
} |
Oops, something went wrong.