- // Selected cell.
- rows.get(y).cells.get(selectedColumn).setX(leftCellX);
- assert (rows.get(y).cells.get(selectedColumn).isVisible());
-
- // All cells to the right of selected cell.
- newCellX = leftCellX + selectedColumnCell.getWidth() + 1;
- for (int x = selectedColumn + 1; x < columns.size(); x++) {
- if (newCellX <= getWidth()) {
- rows.get(y).cells.get(x).setVisible(true);
- rows.get(y).cells.get(x).setX(newCellX);
+ /*
+ * leftCellX now contains the basic left offset necessary to draw
+ * the cells such that the selected cell (column) is fully
+ * visible within this widget's given width. Or, if the widget
+ * is too narrow to display the full cell, leftCellX is 0 or
+ * ROW_LABEL_WIDTH.
+ *
+ * Now reset all of the X positions of the other cells so that
+ * the selected cell X is leftCellX.
+ */
+ for (int y = 0; y < rows.size(); y++) {
+ // All cells to the left of selected cell.
+ int newCellX = leftCellX;
+ left = selectedColumn - 1;
+ for (int x = selectedColumn - 1; x >= 0; x--) {
+ newCellX -= rows.get(y).get(x).getWidth() + 1;
+ rows.get(y).get(x).setX(newCellX);
+ if (newCellX >= (showRowLabels ? ROW_LABEL_WIDTH : 0)) {
+ if ((rows.get(y).get(0).getY() < (showColumnLabels ? COLUMN_LABEL_HEIGHT : 0))
+ || (rows.get(y).get(0).getY() >= getHeight())
+ ) {
+ // This row isn't visible.
+ rows.get(y).get(x).setVisible(false);
+ } else {
+ rows.get(y).get(x).setVisible(true);
+ }
+ left--;
+ } else {
+ // This cell won't be visible.
+ rows.get(y).get(x).setVisible(false);
+ }
+ }
+ left++;
+
+ // Selected cell.
+ rows.get(y).get(selectedColumn).setX(leftCellX);
+ if ((rows.get(y).get(0).getY() < (showColumnLabels ? COLUMN_LABEL_HEIGHT : 0))
+ || (rows.get(y).get(0).getY() >= getHeight())
+ ) {
+ // This row isn't visible.
+ rows.get(y).get(selectedColumn).setVisible(false);