From fd0fe1110ddb2d838f707b76fa79d779cf590664 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Wed, 9 Nov 2022 12:15:12 +0200 Subject: [PATCH] improve terminal resizing behaviour --- .../sparrow/terminal/SparrowTerminal.java | 4 +++ .../sparrow/terminal/SparrowTextGui.java | 25 ++++++++----------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/terminal/SparrowTerminal.java b/src/main/java/com/sparrowwallet/sparrow/terminal/SparrowTerminal.java index f01a3eef..e4daa671 100644 --- a/src/main/java/com/sparrowwallet/sparrow/terminal/SparrowTerminal.java +++ b/src/main/java/com/sparrowwallet/sparrow/terminal/SparrowTerminal.java @@ -57,6 +57,10 @@ public class SparrowTerminal extends Application { this.gui = new SparrowTextGui(this, screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE)); EventManager.get().register(gui); + terminal.addResizeListener((terminal1, newSize) -> { + gui.handleResize(); + }); + sparrowTerminal = this; try { diff --git a/src/main/java/com/sparrowwallet/sparrow/terminal/SparrowTextGui.java b/src/main/java/com/sparrowwallet/sparrow/terminal/SparrowTextGui.java index de3be136..07257c2f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/terminal/SparrowTextGui.java +++ b/src/main/java/com/sparrowwallet/sparrow/terminal/SparrowTextGui.java @@ -1,7 +1,6 @@ package com.sparrowwallet.sparrow.terminal; import com.google.common.eventbus.Subscribe; -import com.googlecode.lanterna.TerminalSize; import com.googlecode.lanterna.TextColor; import com.googlecode.lanterna.gui2.*; import com.googlecode.lanterna.screen.Screen; @@ -15,11 +14,12 @@ import javafx.beans.property.DoubleProperty; import javafx.beans.property.SimpleDoubleProperty; import javafx.util.Duration; -import java.util.Objects; - public class SparrowTextGui extends MultiWindowTextGUI { private final BasicWindow mainWindow; + private final Panel titleBar; + private final Panel statusBar; + private final Label connectedLabel; private final Label statusLabel; private final ProgressBar statusProgress; @@ -36,7 +36,7 @@ public class SparrowTextGui extends MultiWindowTextGUI { Panel panel = new Panel(new BorderLayout()); - Panel titleBar = new Panel(new GridLayout(2)); + titleBar = new Panel(new GridLayout(2)); new Label("Sparrow Terminal").addTo(titleBar); this.connectedLabel = new Label("Disconnected"); titleBar.addComponent(connectedLabel, GridLayout.createLayoutData(GridLayout.Alignment.END, GridLayout.Alignment.CENTER, true, false)); @@ -44,7 +44,7 @@ public class SparrowTextGui extends MultiWindowTextGUI { panel.addComponent(new EmptySpace(TextColor.ANSI.BLUE)); - Panel statusBar = new Panel(new GridLayout(2)); + statusBar = new Panel(new GridLayout(2)); this.statusLabel = new Label("").addTo(statusBar); this.statusProgress = new ProgressBar(0, 100, 10); statusBar.addComponent(statusProgress, GridLayout.createLayoutData(GridLayout.Alignment.END, GridLayout.Alignment.CENTER, true, false)); @@ -55,19 +55,14 @@ public class SparrowTextGui extends MultiWindowTextGUI { panel.addComponent(statusBar, BorderLayout.Location.BOTTOM); getBackgroundPane().setComponent(panel); - getMainWindow().addWindowListener(new WindowListenerAdapter() { - @Override - public void onResized(Window window, TerminalSize oldSize, TerminalSize newSize) { - if(!Objects.equals(oldSize, newSize)) { - titleBar.invalidate(); - statusBar.invalidate(); - } - } - }); - AppServices.get().start(); } + public void handleResize() { + titleBar.invalidate(); + statusBar.invalidate(); + } + public BasicWindow getMainWindow() { return mainWindow; }