package org.antlr.intellij.plugin.preview;

import com.intellij.ui.JBColor;
import org.antlr.intellij.plugin.parsing.PreviewInterpreterRuleContext;
import org.antlr.v4.gui.TreeViewer;
import org.antlr.v4.runtime.tree.Tree;

import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.util.List;

public class UberTreeViewer extends TreeViewer {
	public boolean highlightUnreachedNodes = false;

	public UberTreeViewer(List<String> ruleNames, Tree tree, boolean highlightUnreachedNodes) {
		super(ruleNames, tree);
		this.highlightUnreachedNodes = highlightUnreachedNodes;
	}

	@Override
	protected void paintBox(Graphics g, Tree tree) {
		super.paintBox(g, tree);
		Rectangle2D.Double box = getBoundsOfNode(tree);
		if ( tree instanceof PreviewInterpreterRuleContext ) {
			PreviewInterpreterRuleContext ctx = (PreviewInterpreterRuleContext)tree;
			if ( highlightUnreachedNodes && !ctx.reached ) {
				g.setColor(JBColor.orange);
				g.drawRoundRect((int) box.x, (int) box.y, (int) box.width - 1,
								(int) box.height - 1, arcSize, arcSize);
			}
		}
	}
}

@@ -217,16 +217,38 @@
 .Tree;%0A%0A
+import javax.swing.*;%0A
 import j
@@ -1078,11 +1078,268 @@
 %7D%0A%09%09%7D%0A%09%7D
+%0A%0A%09@Override%0A%09public void setTree(Tree root) %7B%0A%09%09LookAndFeel theme = UIManager.getLookAndFeel();%0A%09%09UIDefaults themeDefaults = theme.getDefaults();%0A%09%09Color textColor = (Color)themeDefaults.get(%22textText%22);%0A%09%09setTextColor(textColor);%0A%09%09super.setTree(root);%0A%09%7D
 %0A%7D%0A

set text color in parse tree to "textText" property color of LookAndFeel.getDefaults(). Fixes #170.