Skip to content

Commit 9d7eca9

Browse files
committed
rendering variable icons from svg in the debugger
1 parent 805306f commit 9d7eca9

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

java/src/processing/mode/java/debug/VariableInspector.java

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import processing.app.Language;
4141
import processing.app.Messages;
4242
import processing.app.Mode;
43+
import processing.app.ui.Toolkit;
4344
import processing.mode.java.JavaEditor;
4445

4546

@@ -295,13 +296,45 @@ public String getColumnName(int i) {
295296
* Handles icons, text color and tool tips.
296297
*/
297298
class OutlineRenderer implements RenderDataProvider {
298-
Icon[][] icons;
299+
static final String ENABLED_COLOR = "#000000";
300+
static final String DISABLED_COLOR = "#808080";
299301
static final int ICON_SIZE = 16;
300302

303+
// Indices correspond to VariableNode.TYPE_OBJECT...TYPE_SHORT
304+
static final String[] TYPE_NAMES = {
305+
"object", "array", "integer", "float", "boolean",
306+
"char", "string", "long", "double", "byte", "short"
307+
};
308+
309+
Icon[][] icons;
310+
311+
301312
OutlineRenderer() {
302-
icons = loadIcons("theme/variables-1x.png");
313+
icons = new Icon[][] {
314+
renderIcons("object"),
315+
renderIcons("array"),
316+
renderIcons("integer"),
317+
renderIcons("float"),
318+
renderIcons("boolean"),
319+
renderIcons("char"),
320+
renderIcons("string"),
321+
renderIcons("long"),
322+
renderIcons("double"),
323+
renderIcons("byte"),
324+
renderIcons("short")
325+
};
303326
}
304327

328+
329+
private ImageIcon[] renderIcons(String type) {
330+
File file = editor.getMode().getContentFile("theme/variables/" + type + ".svg");
331+
return new ImageIcon[] {
332+
Toolkit.renderIcon(file, ENABLED_COLOR, ICON_SIZE),
333+
Toolkit.renderIcon(file, DISABLED_COLOR, ICON_SIZE)
334+
};
335+
}
336+
337+
305338
/**
306339
* Load multiple icons (horizontal) with multiple states (vertical) from
307340
* a single file.
@@ -334,11 +367,11 @@ private ImageIcon[][] loadIcons(String fileName) {
334367
}
335368

336369

337-
protected Icon getIcon(int type, int state) {
370+
protected Icon getIcon(int type, boolean enabled) {
338371
if (type < 0 || type > icons.length - 1) {
339372
return null;
340373
}
341-
return icons[type][state];
374+
return icons[type][enabled ? 0 : 1];
342375
}
343376

344377

@@ -400,7 +433,7 @@ public String getTooltipText(Object o) {
400433
public Icon getIcon(Object o) {
401434
VariableNode var = toVariableNode(o);
402435
if (var != null) {
403-
return getIcon(var.getType(), tree.isEnabled() ? 0 : 1);
436+
return getIcon(var.getType(), tree.isEnabled());
404437
}
405438
if (o instanceof TreeNode) {
406439
UIDefaults defaults = UIManager.getDefaults();

0 commit comments

Comments
 (0)