terminal automatically detects if a console or dialog terminal is required

This commit is contained in:
hneemann 2020-02-11 07:49:44 +01:00
parent 652767c865
commit b7eb5221a3
3 changed files with 13 additions and 7 deletions

View File

@ -131,6 +131,13 @@ public class Model implements Iterable<Node>, SyncAccess {
return windowPosManager; return windowPosManager;
} }
/**
* @return true if this model runs in the main frame
*/
public boolean runningInMainFrame() {
return getWindowPosManager().getMainFrame() != null;
}
/** /**
* Returns the actual step counter. * Returns the actual step counter.
* This counter is incremented by every micro step * This counter is incremented by every micro step

View File

@ -22,7 +22,6 @@ import static de.neemann.digital.core.element.PinInfo.input;
* Component which represents a text terminal. * Component which represents a text terminal.
*/ */
public class Terminal extends Node implements Element { public class Terminal extends Node implements Element {
private static final boolean HIDE_DIALOG = GraphicsEnvironment.isHeadless() || System.getProperty("testdata") != null;
/** /**
* The terminal description * The terminal description
@ -72,10 +71,10 @@ public class Terminal extends Node implements Element {
long value = data.getValue(); long value = data.getValue();
if (value != 0) { if (value != 0) {
if (terminal == null) { if (terminal == null) {
if (HIDE_DIALOG) { if (getModel().runningInMainFrame()) {
terminal = new ConsoleTerminal();
} else {
terminal = TerminalDialog.getTerminal(getModel(), attr); terminal = TerminalDialog.getTerminal(getModel(), attr);
} else {
terminal = new ConsoleTerminal();
} }
} }
terminal.addChar((char) value); terminal.addChar((char) value);
@ -89,9 +88,9 @@ public class Terminal extends Node implements Element {
} }
/** /**
* @return the terminal dialog * @return the terminal interface
*/ */
public TerminalInterface getTerminalDialog() { public TerminalInterface getTerminalInterface() {
return terminal; return terminal;
} }
} }

View File

@ -530,7 +530,7 @@ public class TestInGUI extends TestCase {
List<Terminal> n = main.getModel().findNode(Terminal.class); List<Terminal> n = main.getModel().findNode(Terminal.class);
assertEquals(1, n.size()); assertEquals(1, n.size());
Terminal t = n.get(0); Terminal t = n.get(0);
assertEquals("\nHello World!", t.getTerminalDialog().getText()); assertEquals("\nHello World!", t.getTerminalInterface().getText());
})) }))
.execute(); .execute();
} }