소스 검색

Console window now autoscrolls perfectly and can display Debug.out text

- added in Debug.out link to ConsoleManager.add...Text
- added Listener in ConsoleManager for autoscrolling
- Bug: Update button not above consoleWindow
Julian Ohl 8 년 전
부모
커밋
9cbcc2123a

+ 3 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/debug/Debug.java

@@ -4,6 +4,8 @@ import javax.xml.stream.events.Attribute;
 import javax.xml.stream.events.XMLEvent;
 
 import de.tu_darmstadt.informatik.tk.scopviz.io.MyFileSourceGraphML;
+import de.tu_darmstadt.informatik.tk.scopviz.ui.ConsoleManager;
+import javafx.application.Platform;
 
 /**
  * Debug class to allow easy, static access to console output.
@@ -77,6 +79,7 @@ public final class Debug {
 	public static void out(String s) {
 		if (DEBUG_ENABLED) {
 			System.out.println(s);
+			Platform.runLater(() -> ConsoleManager.addNormalText(s));
 		}
 	}
 

+ 12 - 4
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/ConsoleManager.java

@@ -1,5 +1,7 @@
 package de.tu_darmstadt.informatik.tk.scopviz.ui;
 
+import javafx.collections.ListChangeListener;
+import javafx.scene.Node;
 import javafx.scene.paint.Color;
 import javafx.scene.text.Text;
 
@@ -23,6 +25,14 @@ public class ConsoleManager {
 	 */
 	public static void initialize(GUIController c) {
 		controller = c;
+		
+		//behaviour for autoscrolling of the console window
+		controller.consoleWindow.getChildren().addListener(
+                (ListChangeListener<Node>) ((change) -> {
+                	controller.consoleWindow.layout();
+                	controller.consoleScrollPane.layout();
+                	controller.consoleScrollPane.setVvalue(1.0f);
+                }));
 	}
 
 	/**
@@ -34,10 +44,9 @@ public class ConsoleManager {
 	public static void addNormalText(String s) {
 		StringBuilder sb = new StringBuilder();
 
-		sb.append(s).append(System.lineSeparator());
+		sb.append(System.lineSeparator()).append(s);
 
 		controller.consoleWindow.getChildren().add(new Text(sb.toString()));
-		controller.consoleScrollPane.setVvalue(1.0);
 	}
 
 	/**
@@ -49,12 +58,11 @@ public class ConsoleManager {
 	public static void addErrorText(String s) {
 		StringBuilder sb = new StringBuilder();
 
-		sb.append(s).append(System.lineSeparator());
+		sb.append(System.lineSeparator()).append(s);
 
 		Text errorText = new Text(sb.toString());
 
 		errorText.setFill(Color.RED);
 		controller.consoleWindow.getChildren().add(errorText);
-		controller.consoleScrollPane.setVvalue(1.0);
 	}
 }