aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/population/GUIGene.java
blob: eb7070c6b04c30faaa5a64783319b598f668e880 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package jcgp.gui.population;

import javafx.geometry.VPos;
import javafx.scene.Group;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Circle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import jcgp.gui.constants.Constants;

/**
 * Defines the general behaviour of the visual representation of each chromosome gene.
 * <br><br>
 * In practice, this is subclass of {@code javafx.scene.Group} containing a {@code Circle}
 * object and a {@code Text} object. Subclasses may add further elements to the group, for
 * instance to display connection input and output sockets. 
 * 
 * @author Eduardo Pedroni
 *
 */
public abstract class GUIGene extends Group {

	private Text text = new Text();
	protected final Circle mainCircle = new Circle(Constants.NODE_RADIUS, Paint.valueOf(Constants.NEUTRAL_COLOUR));
	
	/**
	 * Initialises the {@code Text} and {@code Circle} objects so that all genes are standardised.
	 */
	protected GUIGene() {
		text.setFont(Font.font("Arial", 12));
		text.setTextOrigin(VPos.CENTER);
		text.setTextAlignment(TextAlignment.CENTER);
		text.setWrappingWidth(Constants.NODE_RADIUS * 2);
		text.setX(-Constants.NODE_RADIUS);
		text.setVisible(true);
		
		mainCircle.setStroke(Paint.valueOf("black"));
		
		getChildren().addAll(mainCircle, text);
	}
	
	/**
	 * Sets the gene's text field.
	 * 
	 * @param newText the text string to be displayed.
	 */
	public void setText(String newText) {
		text.setText(newText);
	}
	
	public abstract void mouseEnter();
	public abstract void mouseExit();
	
}