KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > gp > impl > JGAPTreeNodeRenderer


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 org.jgap.gp.impl;
11
12 //
13
// METreeNodeRenderer.java
14
// MetaEvolve
15
//
16
// Version 1
17
//
18
// Created by Brian Risk of Geneffects on March 19, 2004.
19
// Last Modified on March 19, 2004.
20
// www.geneffects.com
21
//
22
// Modified by Klaus Meffert
23

24 import java.awt.*;
25 import org.jgap.util.tree.*;
26 import org.jgap.gp.terminal.*;
27
28 /**
29  * Renders the nodes' colors of a tree to display.
30  *
31  * @author Klaus Meffert
32  * @since 3.0
33  */

34 public class JGAPTreeNodeRenderer
35     implements TreeNodeRenderer {
36   /** String containing the CVS revision. Read out via reflection!*/
37   private final static String JavaDoc CVS_REVISION = "$Revision: 1.1 $";
38
39   //This implementation basis the shade of the node on the level
40
//but you may employ any property of your node.
41
public Color getNodeColor(Object JavaDoc a_node, int a_level) {
42     String JavaDoc name = ( (JGAPTreeNode) a_node).getName();
43     Color out;
44     if (name.equals(Constant.class.getName())) {
45       out = Color.orange;
46     }
47     else if (name.equals(Variable.class.getName())) {
48       out = Color.green;
49     }
50     else if (name.equals(Terminal.class.getName())) {
51       out = Color.yellow;
52     }
53     else if (name.equals(NOP.class.getName())) {
54       out = new Color(255, 255, 255);
55     }
56     else if (name.equals(True.class.getName())) {
57       out = Color.blue;
58     }
59     else if (name.equals(False.class.getName())) {
60       out = Color.gray;
61     }
62     else {
63       switch (a_level) {
64         case 0:
65           out = Color.orange;
66           break;
67         case 1:
68           out = new Color(240, 200, 100);
69           break;
70         case 2:
71           out = new Color(200, 140, 80);
72           break;
73         case 3:
74           out = new Color(140, 240, 180);
75           break;
76         case 4:
77           out = new Color(140, 180, 220);
78           break;
79         default:
80           if (a_level <= 7) {
81             int amt = (8 - a_level) * 32;
82             if (amt >= 256) {
83               amt = 255;
84             }
85             out = new Color(amt, amt, amt);
86           }
87           else {
88             out = Color.black;
89           }
90       }
91     }
92     return out;
93   }
94 }
95
Popular Tags