aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/console/GUIConsole.java
blob: 55291aaed03f023be3ea57444b1b78f15047a8ec (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
package jcgp.gui.console;

import javafx.scene.control.TextArea;
import javafx.scene.layout.AnchorPane;
import jcgp.backend.resources.Console;
import jcgp.gui.GUI;

public class GUIConsole extends AnchorPane implements Console {
	
	private TextArea textArea = new TextArea("Welcome to JCGP!\n");
	
	private StringBuffer printBuffer = new StringBuffer();
		
	public GUIConsole() {
		super();
		textArea.setEditable(false);
		
		AnchorPane.setTopAnchor(textArea, GUI.RESIZE_MARGIN);
		AnchorPane.setBottomAnchor(textArea, 0.0);
		AnchorPane.setRightAnchor(textArea, 0.0);
		AnchorPane.setLeftAnchor(textArea, 0.0);
		
		setMinHeight(GUI.CONSOLE_HEIGHT);
		setPrefHeight(GUI.CONSOLE_HEIGHT);
		
		getChildren().add(textArea);
	}

	@Override
	public void println(String s) {
		printBuffer.append(s + "\n");
	}

	@Override
	public void print(String s) {
		printBuffer.append(s);
	}

	@Override
	public void flush() {
		textArea.appendText(printBuffer.toString());
		printBuffer = new StringBuffer();
	}
	
}