-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Application: Support clickable tags in trees
- Loading branch information
1 parent
638ce6b
commit 1c9431f
Showing
6 changed files
with
148 additions
and
17 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
36 changes: 36 additions & 0 deletions
36
modules/platform-ui/src/main/java/com/shade/platform/ui/controls/TagMouseListener.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,36 @@ | ||
package com.shade.platform.ui.controls; | ||
|
||
import com.shade.platform.ui.util.UIUtils; | ||
import com.shade.util.NotNull; | ||
import com.shade.util.Nullable; | ||
|
||
import java.awt.*; | ||
import java.awt.event.MouseAdapter; | ||
import java.awt.event.MouseEvent; | ||
|
||
public abstract class TagMouseListener<T extends ColoredComponent.Tag> extends MouseAdapter { | ||
public void installOn(@NotNull Component component) { | ||
component.addMouseListener(this); | ||
component.addMouseMotionListener(this); | ||
} | ||
|
||
@Override | ||
public void mouseClicked(MouseEvent e) { | ||
if (e.getButton() == MouseEvent.BUTTON1) { | ||
final T tag = getTagAt(e); | ||
if (tag != null) { | ||
tag.run(e); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void mouseMoved(MouseEvent e) { | ||
final Component component = (Component) e.getSource(); | ||
final T tag = getTagAt(e); | ||
UIUtils.setCursor(component, tag != null ? Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) : null); | ||
} | ||
|
||
@Nullable | ||
protected abstract T getTagAt(@NotNull MouseEvent e); | ||
} |
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