- if (column != -1) {
- int status = getSortingStatus(column);
- if (!e.isControlDown()) {
- cancelSorting();
- }
- // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
- // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
- status = status + (e.isShiftDown() ? -1 : 1);
- status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
- setSortingStatus(column, status);
- }
- }
- }
-
- private static class Arrow implements Icon {
- private boolean descending;
- private int size;
- private int priority;
-
- public Arrow(boolean descending, int size, int priority) {
- this.descending = descending;
- this.size = size;
- this.priority = priority;
- }
-
- public void paintIcon(Component c, Graphics g, int x, int y) {
- Color color = c == null ? Color.GRAY : c.getBackground();
- // In a compound sort, make each succesive triangle 20%
- // smaller than the previous one.
- int dx = (int)(size/2*Math.pow(0.8, priority));
- int dy = descending ? dx : -dx;
- // Align icon (roughly) with font baseline.
- y = y + 5*size/6 + (descending ? -dy : 0);
- int shift = descending ? 1 : -1;
- g.translate(x, y);
-
- // Right diagonal.
- g.setColor(color.darker());
- g.drawLine(dx / 2, dy, 0, 0);
- g.drawLine(dx / 2, dy + shift, 0, shift);
-
- // Left diagonal.
- g.setColor(color.brighter());
- g.drawLine(dx / 2, dy, dx, 0);
- g.drawLine(dx / 2, dy + shift, dx, shift);
-
- // Horizontal line.
- if (descending) {
- g.setColor(color.darker().darker());
- } else {
- g.setColor(color.brighter().brighter());
- }
- g.drawLine(dx, 0, 0, 0);
-
- g.setColor(color);
- g.translate(-x, -y);
- }
-
- public int getIconWidth() {
- return size;
- }
-
- public int getIconHeight() {
- return size;
- }
- }
-
- private class SortableHeaderRenderer implements TableCellRenderer {
- private TableCellRenderer tableCellRenderer;
-
- public SortableHeaderRenderer(TableCellRenderer tableCellRenderer) {
- this.tableCellRenderer = tableCellRenderer;
- }