Browse Source

improve terminal resizing behaviour

master
Craig Raw 2 years ago
parent
commit
fd0fe1110d
  1. 4
      src/main/java/com/sparrowwallet/sparrow/terminal/SparrowTerminal.java
  2. 25
      src/main/java/com/sparrowwallet/sparrow/terminal/SparrowTextGui.java

4
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)); this.gui = new SparrowTextGui(this, screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE));
EventManager.get().register(gui); EventManager.get().register(gui);
terminal.addResizeListener((terminal1, newSize) -> {
gui.handleResize();
});
sparrowTerminal = this; sparrowTerminal = this;
try { try {

25
src/main/java/com/sparrowwallet/sparrow/terminal/SparrowTextGui.java

@ -1,7 +1,6 @@
package com.sparrowwallet.sparrow.terminal; package com.sparrowwallet.sparrow.terminal;
import com.google.common.eventbus.Subscribe; import com.google.common.eventbus.Subscribe;
import com.googlecode.lanterna.TerminalSize;
import com.googlecode.lanterna.TextColor; import com.googlecode.lanterna.TextColor;
import com.googlecode.lanterna.gui2.*; import com.googlecode.lanterna.gui2.*;
import com.googlecode.lanterna.screen.Screen; import com.googlecode.lanterna.screen.Screen;
@ -15,11 +14,12 @@ import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleDoubleProperty;
import javafx.util.Duration; import javafx.util.Duration;
import java.util.Objects;
public class SparrowTextGui extends MultiWindowTextGUI { public class SparrowTextGui extends MultiWindowTextGUI {
private final BasicWindow mainWindow; private final BasicWindow mainWindow;
private final Panel titleBar;
private final Panel statusBar;
private final Label connectedLabel; private final Label connectedLabel;
private final Label statusLabel; private final Label statusLabel;
private final ProgressBar statusProgress; private final ProgressBar statusProgress;
@ -36,7 +36,7 @@ public class SparrowTextGui extends MultiWindowTextGUI {
Panel panel = new Panel(new BorderLayout()); 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); new Label("Sparrow Terminal").addTo(titleBar);
this.connectedLabel = new Label("Disconnected"); this.connectedLabel = new Label("Disconnected");
titleBar.addComponent(connectedLabel, GridLayout.createLayoutData(GridLayout.Alignment.END, GridLayout.Alignment.CENTER, true, false)); 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.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.statusLabel = new Label("").addTo(statusBar);
this.statusProgress = new ProgressBar(0, 100, 10); this.statusProgress = new ProgressBar(0, 100, 10);
statusBar.addComponent(statusProgress, GridLayout.createLayoutData(GridLayout.Alignment.END, GridLayout.Alignment.CENTER, true, false)); 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); panel.addComponent(statusBar, BorderLayout.Location.BOTTOM);
getBackgroundPane().setComponent(panel); 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(); AppServices.get().start();
} }
public void handleResize() {
titleBar.invalidate();
statusBar.invalidate();
}
public BasicWindow getMainWindow() { public BasicWindow getMainWindow() {
return mainWindow; return mainWindow;
} }

Loading…
Cancel
Save