aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/console
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-04-08 20:04:12 +0100
committerEduardo Pedroni <ep625@york.ac.uk>2014-04-08 20:04:12 +0100
commit260f1baaab10ab9b1db67ab587bc36adcb34494e (patch)
tree408c472a31c3fb26894c02f50803a36b684486bc /src/jcgp/gui/console
parent226365bd6a0f56143ffbce7379857ff3e126fbaf (diff)
GUIParameters all refactored and commented.
Diffstat (limited to 'src/jcgp/gui/console')
-rw-r--r--src/jcgp/gui/console/GUIConsole.java62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/jcgp/gui/console/GUIConsole.java b/src/jcgp/gui/console/GUIConsole.java
index 55291aa..8148ec8 100644
--- a/src/jcgp/gui/console/GUIConsole.java
+++ b/src/jcgp/gui/console/GUIConsole.java
@@ -1,6 +1,16 @@
package jcgp.gui.console;
+import javafx.event.ActionEvent;
+import javafx.event.Event;
+import javafx.event.EventDispatchChain;
+import javafx.event.EventDispatcher;
+import javafx.event.EventHandler;
+import javafx.scene.control.ContextMenu;
+import javafx.scene.control.MenuItem;
+import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.TextArea;
+import javafx.scene.input.MouseButton;
+import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import jcgp.backend.resources.Console;
import jcgp.gui.GUI;
@@ -15,6 +25,58 @@ public class GUIConsole extends AnchorPane implements Console {
super();
textArea.setEditable(false);
+ /*
+ * This nasty hack is needed because the default TextArea ContextMenu is not
+ * in the public API, making it impossible to override it with a custom one.
+ * This has not been fixed as of 8/4/2014.
+ *
+ * The following code modifies the EventDispatcher to consume the right mouse
+ * button click, preventing the default menu from appearing.
+ */
+ final EventDispatcher initial = textArea.getEventDispatcher();
+ textArea.setEventDispatcher(new EventDispatcher() {
+ @Override
+ public Event dispatchEvent(Event event, EventDispatchChain tail) {
+ if (event instanceof MouseEvent) {
+ //shot in the dark guess for OSX, might not work
+ MouseEvent mouseEvent = (MouseEvent)event;
+ if (mouseEvent.getButton() == MouseButton.SECONDARY ||
+ (mouseEvent.getButton() == MouseButton.PRIMARY && mouseEvent.isControlDown())) {
+ event.consume();
+ }
+ }
+ return initial.dispatchEvent(event, tail);
+ }
+ });
+
+ // make the new context menu including the clear option
+ MenuItem copySelected = new MenuItem("Copy");
+ copySelected.setOnAction(new EventHandler<ActionEvent>() {
+ @Override
+ public void handle(ActionEvent event) {
+ textArea.copy();
+ }
+ });
+ MenuItem selectAll = new MenuItem("Select all");
+ selectAll.setOnAction(new EventHandler<ActionEvent>() {
+ @Override
+ public void handle(ActionEvent event) {
+ textArea.selectAll();
+ }
+ });
+ MenuItem clearConsole = new MenuItem("Clear");
+ clearConsole.setOnAction(new EventHandler<ActionEvent>() {
+ @Override
+ public void handle(ActionEvent event) {
+ textArea.setText("");
+ }
+ });
+
+ textArea.setContextMenu(new ContextMenu(copySelected,
+ selectAll,
+ new SeparatorMenuItem(),
+ clearConsole));
+
AnchorPane.setTopAnchor(textArea, GUI.RESIZE_MARGIN);
AnchorPane.setBottomAnchor(textArea, 0.0);
AnchorPane.setRightAnchor(textArea, 0.0);