From: Kevin Lamonte Date: Thu, 1 Aug 2019 04:28:36 +0000 (-0500) Subject: ttable delete up/left X-Git-Tag: fanfix-swing-0.0.1~12^2~13^2~133 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=ab8b0034fec1f17f97cfaa96d83c030180ffaa37;p=fanfix-swing.git ttable delete up/left --- diff --git a/src/jexer/TTableWidget.java b/src/jexer/TTableWidget.java index 548acf64..f25f429d 100644 --- a/src/jexer/TTableWidget.java +++ b/src/jexer/TTableWidget.java @@ -801,7 +801,7 @@ public class TTableWidget extends TWidget { public void onResize(final TResizeEvent event) { super.onResize(event); - alignGrid(); + bottomRightCorner(); } /** @@ -1276,6 +1276,24 @@ public class TTableWidget extends TWidget { return rows.size(); } + + /** + * Push top and left to the bottom-most right corner of the available + * grid. + */ + private void bottomRightCorner() { + int viewColumns = getWidth(); + if (showRowLabels == true) { + viewColumns -= ROW_LABEL_WIDTH; + } + + // Set left and top such that the table stays on screen if possible. + top = rows.size() - getHeight(); + left = columns.size() - (getWidth() / (viewColumns / (COLUMN_DEFAULT_WIDTH + 1))); + // Now ensure the selection is visible. + alignGrid(); + } + /** * Align the grid so that the selected cell is fully visible. */ @@ -1768,7 +1786,7 @@ public class TTableWidget extends TWidget { if (selectedRow == rows.size()) { selectedRow--; } - alignGrid(); + bottomRightCorner(); } /** @@ -1878,21 +1896,29 @@ public class TTableWidget extends TWidget { if (selectedColumn == columns.size()) { selectedColumn--; } - alignGrid(); + bottomRightCorner(); } /** * Delete the selected cell, shifting cells over to the left. */ public void deleteCellShiftLeft() { - // TODO + // All we do is copy the text from every cell in this row over. + for (int i = selectedColumn + 1; i < columns.size(); i++) { + setCellText(i - 1, selectedRow, getCellText(i, selectedRow)); + } + setCellText(columns.size() - 1, selectedRow, ""); } /** * Delete the selected cell, shifting cells from below up. */ public void deleteCellShiftUp() { - // TODO + // All we do is copy the text from every cell in this column up. + for (int i = selectedRow + 1; i < rows.size(); i++) { + setCellText(selectedColumn, i - 1, getCellText(selectedColumn, i)); + } + setCellText(selectedColumn, rows.size() - 1, ""); } /**