aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/console
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-03-31 20:32:59 +0100
committerEduardo Pedroni <ep625@york.ac.uk>2014-03-31 20:32:59 +0100
commita757deacded0d7357a9f68462d3f2051e16004ee (patch)
tree4706e867ed7686a155f0c8ee16ffb3eeb74daac4 /src/jcgp/gui/console
parent04b35ccdad6e18701ede823e333118b0b22907c2 (diff)
Need to do a few tests on windows
Diffstat (limited to 'src/jcgp/gui/console')
-rw-r--r--src/jcgp/gui/console/GUIConsole.java94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/jcgp/gui/console/GUIConsole.java b/src/jcgp/gui/console/GUIConsole.java
new file mode 100644
index 0000000..0ef2be3
--- /dev/null
+++ b/src/jcgp/gui/console/GUIConsole.java
@@ -0,0 +1,94 @@
+package jcgp.gui.console;
+
+import javafx.event.EventHandler;
+import javafx.scene.Cursor;
+import javafx.scene.control.TextArea;
+import javafx.scene.input.MouseEvent;
+import javafx.scene.layout.AnchorPane;
+import jcgp.GUI;
+
+public class GUIConsole extends AnchorPane {
+
+ private boolean dragging;
+ private TextArea textArea = new TextArea("Welcome to JCGP!\n");
+
+ public GUIConsole() {
+ super();
+ textArea.setEditable(false);
+ textArea.setWrapText(true);
+
+ setResizeListeners();
+
+ 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);
+
+ }
+
+ /**
+ *
+ */
+ private void setResizeListeners() {
+ setOnMousePressed(new EventHandler<MouseEvent>() {
+ @Override
+ public void handle(MouseEvent event) {
+ // ignore clicks outside of the draggable margin
+ if(isInDraggableZone(event)) {
+ dragging = true;
+ }
+ }
+ });
+ setOnMouseDragged(new EventHandler<MouseEvent>() {
+ @Override
+ public void handle(MouseEvent event) {
+ if(dragging) {
+ double newHeight = getHeight() - event.getY();
+ if (newHeight >= getMinHeight()) {
+ setPrefHeight(newHeight);
+ } else {
+ setPrefHeight(getMinHeight());
+ }
+ }
+ }
+ });
+ setOnMouseMoved(new EventHandler<MouseEvent>() {
+ @Override
+ public void handle(MouseEvent event) {
+ if(isInDraggableZone(event) || dragging) {
+ setCursor(Cursor.V_RESIZE);
+ }
+ else {
+ setCursor(Cursor.DEFAULT);
+ }
+ }
+ });
+ setOnMouseReleased(new EventHandler<MouseEvent>() {
+ @Override
+ public void handle(MouseEvent event) {
+ dragging = false;
+ setCursor(Cursor.DEFAULT);
+ }
+ });
+ textArea.setOnMouseEntered(new EventHandler<MouseEvent>() {
+ @Override
+ public void handle(MouseEvent event) {
+ setCursor(Cursor.DEFAULT);
+ }
+ });
+ }
+
+ private boolean isInDraggableZone(MouseEvent event) {
+ return event.getY() < (GUI.RESIZE_MARGIN);
+ }
+
+ public TextArea getTextArea() {
+ return textArea;
+ }
+
+}