KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > gp > anttrail > AntTreeNodeRenderer


1 /*
2  * This file is part of JGAP.
3  *
4  * JGAP offers a dual license model containing the LGPL as well as the MPL.
5  *
6  * For licencing information please see the file license.txt included with JGAP
7  * or have a look at the top of class org.jgap.Chromosome which representatively
8  * includes the JGAP license policy applicable for any file delivered with JGAP.
9  */

10 package examples.gp.anttrail;
11
12 import java.awt.*;
13 import org.jgap.util.tree.*;
14 import org.jgap.gp.terminal.*;
15 import org.jgap.gp.impl.*;
16
17 /**
18  * Renders the nodes' colors of a tree to display.
19  *
20  * @author Klaus Meffert
21  * @since 3.0
22  */

23 public class AntTreeNodeRenderer
24     extends JGAPTreeNodeRenderer {
25   /** String containing the CVS revision. Read out via reflection!*/
26   private final static String JavaDoc CVS_REVISION = "$Revision: 1.1 $";
27
28   //This implementation basis the shade of the node on the level
29
//but you may employ any property of your node.
30
public Color getNodeColor(Object JavaDoc a_node, int a_level) {
31     String JavaDoc name = ( (JGAPTreeNode) a_node).getName();
32     Color out;
33     if (name.equals(Move.class.getName())) {
34       out = new Color(0, 140, 86);
35     }
36     else if (name.equals(Left.class.getName())) {
37       out = new Color(44, 200, 70);
38     }
39     else if (name.equals(Right.class.getName())) {
40       out = new Color(0, 86, 22);
41     }
42     else {
43       return super.getNodeColor(a_node, a_level);
44     }
45     return out;
46   }
47 }
48
Popular Tags