From 9240f032a51de25bdc90bdebec99bb63896b24d0 Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Fri, 22 Nov 2019 11:04:51 -0600 Subject: [PATCH] retrofit --- src/jexer/TEditorWidget.java | 11 +++++-- src/jexer/TExceptionDialog.java | 9 +++--- src/jexer/TList.java | 17 +++++++---- src/jexer/TWidget.java | 6 ++-- src/jexer/ttree/TTreeViewWidget.java | 44 ++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 15 deletions(-) diff --git a/src/jexer/TEditorWidget.java b/src/jexer/TEditorWidget.java index 9236da2..6d24a19 100644 --- a/src/jexer/TEditorWidget.java +++ b/src/jexer/TEditorWidget.java @@ -164,8 +164,15 @@ public class TEditorWidget extends TWidget implements EditMenuUser { if (mouse.isMouse1()) { // Selection. + int newLine = topLine + mouse.getY(); + int newX = leftColumn + mouse.getX(); + inSelection = true; - selectionLine0 = topLine + mouse.getY(); + if (newLine > document.getLineCount() - 1) { + selectionLine0 = document.getLineCount() - 1; + } else { + selectionLine0 = topLine + mouse.getY(); + } selectionColumn0 = leftColumn + mouse.getX(); selectionColumn0 = Math.max(0, Math.min(selectionColumn0, document.getLine(selectionLine0).getDisplayLength() - 1)); @@ -173,8 +180,6 @@ public class TEditorWidget extends TWidget implements EditMenuUser { selectionLine1 = selectionLine0; // Set the row and column - int newLine = topLine + mouse.getY(); - int newX = leftColumn + mouse.getX(); if (newLine > document.getLineCount() - 1) { // Go to the end document.setLineNumber(document.getLineCount() - 1); diff --git a/src/jexer/TExceptionDialog.java b/src/jexer/TExceptionDialog.java index 227aceb..f526a64 100644 --- a/src/jexer/TExceptionDialog.java +++ b/src/jexer/TExceptionDialog.java @@ -82,7 +82,7 @@ public class TExceptionDialog extends TWindow { final Throwable exception) { super(application, i18n.getString("windowTitle"), - 1, 1, 70, 20, CENTERED | MODAL); + 1, 1, 78, 22, CENTERED | MODAL); this.exception = exception; @@ -100,14 +100,15 @@ public class TExceptionDialog extends TWindow { 2, 6, "ttext", false); ArrayList stackTraceStrings = new ArrayList(); + stackTraceStrings.add(exception.getMessage()); StackTraceElement [] stack = exception.getStackTrace(); for (int i = 0; i < stack.length; i++) { stackTraceStrings.add(stack[i].toString()); } - stackTrace = addList(stackTraceStrings, 2, 7, getWidth() - 6, 8); + stackTrace = addList(stackTraceStrings, 2, 7, getWidth() - 6, 10); // Buttons - addButton(i18n.getString("saveButton"), 19, getHeight() - 4, + addButton(i18n.getString("saveButton"), 21, getHeight() - 4, new TAction() { public void DO() { saveToFile(); @@ -115,7 +116,7 @@ public class TExceptionDialog extends TWindow { }); TButton closeButton = addButton(i18n.getString("closeButton"), - 35, getHeight() - 4, + 37, getHeight() - 4, new TAction() { public void DO() { // Don't do anything, just close the window. diff --git a/src/jexer/TList.java b/src/jexer/TList.java index 38a994c..6b0a205 100644 --- a/src/jexer/TList.java +++ b/src/jexer/TList.java @@ -335,21 +335,28 @@ public class TList extends TScrollableWidget { @Override public void setWidth(final int width) { super.setWidth(width); - hScroller.setWidth(getWidth() - 1); - vScroller.setX(getWidth() - 1); + if (hScroller != null) { + hScroller.setWidth(getWidth() - 1); + } + if (vScroller != null) { + vScroller.setX(getWidth() - 1); + } } /** * Override TWidget's height: we need to set child widget heights. - * time. * * @param height new widget height */ @Override public void setHeight(final int height) { super.setHeight(height); - hScroller.setY(getHeight() - 1); - vScroller.setHeight(getHeight() - 1); + if (hScroller != null) { + hScroller.setY(getHeight() - 1); + } + if (vScroller != null) { + vScroller.setHeight(getHeight() - 1); + } } /** diff --git a/src/jexer/TWidget.java b/src/jexer/TWidget.java index 0d7d5bb..5c93712 100644 --- a/src/jexer/TWidget.java +++ b/src/jexer/TWidget.java @@ -1157,7 +1157,7 @@ public abstract class TWidget implements Comparable { * @return difference between this.tabOrder and that.tabOrder, or * difference between this.z and that.z, or String.compareTo(text) */ - public final int compareTo(final TWidget that) { + public int compareTo(final TWidget that) { if ((this instanceof TWindow) && (that instanceof TWindow) ) { @@ -1434,9 +1434,9 @@ public abstract class TWidget implements Comparable { if (activeChild != null) { activeChild.active = false; } - child.active = true; - activeChild = child; } + child.active = true; + activeChild = child; } } diff --git a/src/jexer/ttree/TTreeViewWidget.java b/src/jexer/ttree/TTreeViewWidget.java index 080a200..13beac3 100644 --- a/src/jexer/ttree/TTreeViewWidget.java +++ b/src/jexer/ttree/TTreeViewWidget.java @@ -268,11 +268,55 @@ public class TTreeViewWidget extends TScrollableWidget { // TScrollableWidget ------------------------------------------------------ // ------------------------------------------------------------------------ + /** + * Override TWidget's width: we need to set child widget widths. + * + * @param width new widget width + */ + @Override + public void setWidth(final int width) { + super.setWidth(width); + if (hScroller != null) { + hScroller.setWidth(getWidth() - 1); + } + if (vScroller != null) { + vScroller.setX(getWidth() - 1); + } + if (treeView != null) { + treeView.setWidth(getWidth() - 1); + } + reflowData(); + } + + /** + * Override TWidget's height: we need to set child widget heights. + * + * @param height new widget height + */ + @Override + public void setHeight(final int height) { + super.setHeight(height); + if (hScroller != null) { + hScroller.setY(getHeight() - 1); + } + if (vScroller != null) { + vScroller.setHeight(getHeight() - 1); + } + if (treeView != null) { + treeView.setHeight(getHeight() - 1); + } + reflowData(); + } + /** * Resize text and scrollbars for a new width/height. */ @Override public void reflowData() { + if (treeView == null) { + return; + } + int selectedRow = 0; boolean foundSelectedRow = false; -- 2.27.0