Skip to content

Commit ed63af0

Browse files
committed
Try styling for icons
1 parent 1c413d3 commit ed63af0

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3+
*/
4+
5+
package net.sourceforge.pmd.util.fxdesigner.util;
6+
7+
import java.util.EnumMap;
8+
import java.util.Locale;
9+
10+
import org.apache.commons.lang3.StringUtils;
11+
12+
import net.sourceforge.pmd.util.designerbindings.DesignerBindings.TreeIconId;
13+
14+
public final class TreeIcons {
15+
16+
private static final EnumMap<TreeIconId, String> ICONS_CSS = new EnumMap<>(TreeIconId.class);
17+
private static final EnumMap<TreeIconId, String> ICONS_DISPLAY_NAME = new EnumMap<>(TreeIconId.class);
18+
19+
20+
static {
21+
for (TreeIconId id : TreeIconId.values()) {
22+
String lowerName = id.name().toLowerCase(Locale.ROOT);
23+
String idCss = "icon-" + lowerName.replace('_', '-');
24+
25+
String displayName = StringUtils.capitalize(lowerName) + " declaration";
26+
27+
ICONS_CSS.put(id, idCss);
28+
ICONS_DISPLAY_NAME.put(id, displayName);
29+
}
30+
}
31+
32+
33+
public static String cssClass(TreeIconId id) {
34+
return id == null ? null : ICONS_CSS.get(id);
35+
}
36+
37+
38+
public static String displayName(TreeIconId id) {
39+
return id == null ? null : ICONS_DISPLAY_NAME.get(id);
40+
}
41+
42+
}

src/main/java/net/sourceforge/pmd/util/fxdesigner/util/controls/ASTTreeItem.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,22 @@
1616
import java.util.function.Consumer;
1717

1818
import org.apache.commons.lang3.mutable.MutableInt;
19+
import org.checkerframework.checker.nullness.qual.Nullable;
1920
import org.reactfx.value.Var;
2021

2122
import net.sourceforge.pmd.lang.ast.Node;
2223
import net.sourceforge.pmd.lang.ast.xpath.Attribute;
2324
import net.sourceforge.pmd.util.designerbindings.DesignerBindings;
2425
import net.sourceforge.pmd.util.designerbindings.DesignerBindings.DefaultDesignerBindings;
26+
import net.sourceforge.pmd.util.designerbindings.DesignerBindings.TreeIconId;
2527
import net.sourceforge.pmd.util.fxdesigner.app.ApplicationComponent;
2628
import net.sourceforge.pmd.util.fxdesigner.app.DesignerRoot;
29+
import net.sourceforge.pmd.util.fxdesigner.util.TreeIcons;
2730
import net.sourceforge.pmd.util.fxdesigner.util.controls.SearchableTreeView.SearchableTreeItem;
2831

32+
import javafx.scene.control.Tooltip;
2933
import javafx.scene.control.TreeItem;
34+
import javafx.scene.text.Text;
3035
import javafx.scene.text.TextFlow;
3136

3237
/**
@@ -200,7 +205,9 @@ TextFlow styledPresentableText(Node node) {
200205

201206
Attribute attr = bindings.getMainAttribute(node);
202207

203-
TextFlow flow = new TextFlow(makeStyledText(node.getXPathNodeName(), NODE_XPATH_NAME_CSS));
208+
TextFlow flow = new TextFlow();
209+
addXPathName(flow, node.getXPathNodeName(), bindings.getIcon(node));
210+
204211
if (attr != null && attr.getStringValue() != null) {
205212
flow.getChildren().add(makeStyledText(" [", NODE_XPATH_PUNCT_CSS));
206213
flow.getChildren().add(makeStyledText("@" + attr.getName(), NODE_XPATH_MAIN_ATTR_NAME_CSS));
@@ -212,4 +219,16 @@ TextFlow styledPresentableText(Node node) {
212219
}
213220

214221

222+
private void addXPathName(TextFlow flow, String name, @Nullable TreeIconId id) {
223+
if (id == null) {
224+
flow.getChildren().addAll(makeStyledText(name, NODE_XPATH_NAME_CSS));
225+
} else {
226+
Text headText = new Text(name);
227+
headText.getStyleClass().addAll(NODE_XPATH_NAME_CSS, "tree-icon-emphasis", TreeIcons.cssClass(id));
228+
Tooltip.install(headText, new Tooltip(TreeIcons.displayName(id)));
229+
flow.getChildren().add(headText);
230+
}
231+
}
232+
233+
215234
}

src/main/resources/net/sourceforge/pmd/util/fxdesigner/less/designer.less

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
}
4646
}
4747

48+
.tree-icon-emphasis {
49+
-fx-fill: green;
50+
-fx-font-weight: bold;
51+
}
52+
4853

4954
.table-view {
5055
-fx-border-color: @darker-accent;

0 commit comments

Comments
 (0)