jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTableUI.java
author martin
Thu, 30 Oct 2014 07:31:41 -0700
changeset 28059 e576535359cc
parent 25859 3317bb8137f4
child 28236 610561ed1847
permissions -rw-r--r--
8067377: My hobby: caning, then then canning, the the can-can Summary: Fix ALL the stutters! Reviewed-by: rriggs, mchung, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 21278
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3977
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3977
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3977
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3977
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3977
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.plaf.basic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.datatransfer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.dnd.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.EventObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.TooManyListenersException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.swing.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.swing.table.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.swing.plaf.basic.DragRecognitionSupport.BeforeDrag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import sun.swing.DefaultLookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import sun.swing.UIAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * BasicTableUI implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @author Philip Milne
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @author Shannon Hickey (drag and drop)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
public class BasicTableUI extends TableUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static final StringBuilder BASELINE_COMPONENT_KEY =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        new StringBuilder("Table.baselineComponent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
// Instance Variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    // The JTable that is delegating the painting to this UI.
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
    67
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
    68
     * The instance of {@code JTable}.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
    69
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    protected JTable table;
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
    71
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
    72
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
    73
     * The instance of {@code CellRendererPane}.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
    74
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    protected CellRendererPane rendererPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
    77
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
    78
     * {@code KeyListener} that are attached to the {@code JTable}.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
    79
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    protected KeyListener keyListener;
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
    81
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
    82
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
    83
     * {@code FocusListener} that are attached to the {@code JTable}.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
    84
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    protected FocusListener focusListener;
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
    86
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
    87
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
    88
     * {@code MouseInputListener} that are attached to the {@code JTable}.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
    89
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    protected MouseInputListener mouseInputListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private Handler handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * Local cache of Table's client property "Table.isFileList"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private boolean isFileList = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
//  Helper class for keyboard actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private static class Actions extends UIAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        private static final String CANCEL_EDITING = "cancel";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        private static final String SELECT_ALL = "selectAll";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        private static final String CLEAR_SELECTION = "clearSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        private static final String START_EDITING = "startEditing";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        private static final String NEXT_ROW = "selectNextRow";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        private static final String NEXT_ROW_CELL = "selectNextRowCell";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        private static final String NEXT_ROW_EXTEND_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                "selectNextRowExtendSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        private static final String NEXT_ROW_CHANGE_LEAD =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                "selectNextRowChangeLead";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        private static final String PREVIOUS_ROW = "selectPreviousRow";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        private static final String PREVIOUS_ROW_CELL = "selectPreviousRowCell";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        private static final String PREVIOUS_ROW_EXTEND_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                "selectPreviousRowExtendSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        private static final String PREVIOUS_ROW_CHANGE_LEAD =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                "selectPreviousRowChangeLead";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        private static final String NEXT_COLUMN = "selectNextColumn";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        private static final String NEXT_COLUMN_CELL = "selectNextColumnCell";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        private static final String NEXT_COLUMN_EXTEND_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                "selectNextColumnExtendSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        private static final String NEXT_COLUMN_CHANGE_LEAD =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                "selectNextColumnChangeLead";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        private static final String PREVIOUS_COLUMN = "selectPreviousColumn";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        private static final String PREVIOUS_COLUMN_CELL =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                "selectPreviousColumnCell";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        private static final String PREVIOUS_COLUMN_EXTEND_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                "selectPreviousColumnExtendSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        private static final String PREVIOUS_COLUMN_CHANGE_LEAD =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                "selectPreviousColumnChangeLead";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        private static final String SCROLL_LEFT_CHANGE_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                "scrollLeftChangeSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        private static final String SCROLL_LEFT_EXTEND_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                "scrollLeftExtendSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        private static final String SCROLL_RIGHT_CHANGE_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                "scrollRightChangeSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        private static final String SCROLL_RIGHT_EXTEND_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                "scrollRightExtendSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        private static final String SCROLL_UP_CHANGE_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                "scrollUpChangeSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        private static final String SCROLL_UP_EXTEND_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                "scrollUpExtendSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        private static final String SCROLL_DOWN_CHANGE_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                "scrollDownChangeSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        private static final String SCROLL_DOWN_EXTEND_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                "scrollDownExtendSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        private static final String FIRST_COLUMN =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                "selectFirstColumn";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        private static final String FIRST_COLUMN_EXTEND_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                "selectFirstColumnExtendSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        private static final String LAST_COLUMN =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                "selectLastColumn";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        private static final String LAST_COLUMN_EXTEND_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                "selectLastColumnExtendSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        private static final String FIRST_ROW =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                "selectFirstRow";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        private static final String FIRST_ROW_EXTEND_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                "selectFirstRowExtendSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        private static final String LAST_ROW =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                "selectLastRow";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        private static final String LAST_ROW_EXTEND_SELECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                "selectLastRowExtendSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        // add the lead item to the selection without changing lead or anchor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        private static final String ADD_TO_SELECTION = "addToSelection";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        // toggle the selected state of the lead item and move the anchor to it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        private static final String TOGGLE_AND_ANCHOR = "toggleAndAnchor";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        // extend the selection to the lead item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        private static final String EXTEND_TO = "extendTo";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        // move the anchor to the lead and ensure only that item is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        private static final String MOVE_SELECTION_TO = "moveSelectionTo";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        // give focus to the JTableHeader, if one exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        private static final String FOCUS_HEADER = "focusHeader";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        protected int dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        protected int dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        protected boolean extend;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        protected boolean inSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        // horizontally, forwards always means right,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        // regardless of component orientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        protected boolean forwards;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        protected boolean vertically;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        protected boolean toLimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        protected int leadRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        protected int leadColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        Actions(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        Actions(String name, int dx, int dy, boolean extend,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                boolean inSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            // Actions spcifying true for "inSelection" are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            // fairly sensitive to bad parameter values. They require
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            // that one of dx and dy be 0 and the other be -1 or 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            // Bogus parameter values could cause an infinite loop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            // To prevent any problems we massage the params here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            // and complain if we get something we can't deal with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            if (inSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                this.inSelection = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                // look at the sign of dx and dy only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                dx = sign(dx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                dy = sign(dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                // make sure one is zero, but not both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                assert (dx == 0 || dy == 0) && !(dx == 0 && dy == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            this.dx = dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            this.dy = dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            this.extend = extend;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        Actions(String name, boolean extend, boolean forwards,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                boolean vertically, boolean toLimit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            this(name, 0, 0, extend, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            this.forwards = forwards;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            this.vertically = vertically;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            this.toLimit = toLimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        private static int clipToRange(int i, int a, int b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            return Math.min(Math.max(i, a), b-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        private void moveWithinTableRange(JTable table, int dx, int dy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            leadRow = clipToRange(leadRow+dy, 0, table.getRowCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            leadColumn = clipToRange(leadColumn+dx, 0, table.getColumnCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        private static int sign(int num) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            return (num < 0) ? -1 : ((num == 0) ? 0 : 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
         * Called to move within the selected range of the given JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
         * This method uses the table's notion of selection, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
         * important to allow the user to navigate between items visually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
         * selected on screen. This notion may or may not be the same as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
         * what could be determined by directly querying the selection models.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
         * It depends on certain table properties (such as whether or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
         * row or column selection is allowed). When performing modifications,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
         * it is recommended that caution be taken in order to preserve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
         * the intent of this method, especially when deciding whether to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
         * query the selection models or interact with JTable directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        private boolean moveWithinSelectedRange(JTable table, int dx, int dy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                ListSelectionModel rsm, ListSelectionModel csm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            // Note: The Actions constructor ensures that only one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            // dx and dy is 0, and the other is either -1 or 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            // find out how many items the table is showing as selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            // and the range of items to navigate through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            int totalCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            int minX, maxX, minY, maxY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            boolean rs = table.getRowSelectionAllowed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            boolean cs = table.getColumnSelectionAllowed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            // both column and row selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            if (rs && cs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                totalCount = table.getSelectedRowCount() * table.getSelectedColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                minX = csm.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                maxX = csm.getMaxSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                minY = rsm.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                maxY = rsm.getMaxSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            // row selection only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            } else if (rs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                totalCount = table.getSelectedRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                minX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                maxX = table.getColumnCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                minY = rsm.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                maxY = rsm.getMaxSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            // column selection only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            } else if (cs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                totalCount = table.getSelectedColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                minX = csm.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                maxX = csm.getMaxSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                minY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                maxY = table.getRowCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            // no selection allowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                totalCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                // A bogus assignment to stop javac from complaining
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                // about unitialized values. In this case, these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                // won't even be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                minX = maxX = minY = maxY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            // For some cases, there is no point in trying to stay within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            // selected area. Instead, move outside the selection, wrapping at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            // the table boundaries. The cases are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            boolean stayInSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            // - nothing selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            if (totalCount == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                    // - one item selected, and the lead is already selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                    (totalCount == 1 && table.isCellSelected(leadRow, leadColumn))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                stayInSelection = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                maxX = table.getColumnCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                maxY = table.getRowCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                // the mins are calculated like this in case the max is -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                minX = Math.min(0, maxX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                minY = Math.min(0, maxY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                stayInSelection = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            // the algorithm below isn't prepared to deal with -1 lead/anchor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            // so massage appropriately here first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            if (dy == 1 && leadColumn == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                leadColumn = minX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                leadRow = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            } else if (dx == 1 && leadRow == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                leadRow = minY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                leadColumn = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            } else if (dy == -1 && leadColumn == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                leadColumn = maxX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                leadRow = maxY + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            } else if (dx == -1 && leadRow == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                leadRow = maxY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                leadColumn = maxX + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            // In cases where the lead is not within the search range,
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
   347
            // we need to bring it within one cell for the search
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            // to work properly. Check these here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            leadRow = Math.min(Math.max(leadRow, minY - 1), maxY + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            leadColumn = Math.min(Math.max(leadColumn, minX - 1), maxX + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            // find the next position, possibly looping until it is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                calcNextPos(dx, minX, maxX, dy, minY, maxY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            } while (stayInSelection && !table.isCellSelected(leadRow, leadColumn));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            return stayInSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
         * Find the next lead row and column based on the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
         * dx/dy and max/min values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        private void calcNextPos(int dx, int minX, int maxX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                                 int dy, int minY, int maxY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            if (dx != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                leadColumn += dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                if (leadColumn > maxX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    leadColumn = minX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    leadRow++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    if (leadRow > maxY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                        leadRow = minY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                } else if (leadColumn < minX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                    leadColumn = maxX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                    leadRow--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                    if (leadRow < minY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                        leadRow = maxY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                leadRow += dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                if (leadRow > maxY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                    leadRow = minY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                    leadColumn++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    if (leadColumn > maxX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                        leadColumn = minX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                } else if (leadRow < minY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    leadRow = maxY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                    leadColumn--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                    if (leadColumn < minX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                        leadColumn = maxX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            String key = getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            JTable table = (JTable)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            ListSelectionModel rsm = table.getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            leadRow = getAdjustedLead(table, true, rsm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            ListSelectionModel csm = table.getColumnModel().getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            leadColumn = getAdjustedLead(table, false, csm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            if (key == SCROLL_LEFT_CHANGE_SELECTION ||        // Paging Actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                    key == SCROLL_LEFT_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                    key == SCROLL_RIGHT_CHANGE_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                    key == SCROLL_RIGHT_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                    key == SCROLL_UP_CHANGE_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                    key == SCROLL_UP_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                    key == SCROLL_DOWN_CHANGE_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                    key == SCROLL_DOWN_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                    key == FIRST_COLUMN ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                    key == FIRST_COLUMN_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                    key == FIRST_ROW ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    key == FIRST_ROW_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                    key == LAST_COLUMN ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    key == LAST_COLUMN_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    key == LAST_ROW ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                    key == LAST_ROW_EXTEND_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                if (toLimit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                    if (vertically) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                        int rowCount = table.getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                        this.dx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                        this.dy = forwards ? rowCount : -rowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                        int colCount = table.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                        this.dx = forwards ? colCount : -colCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                        this.dy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                else {
17897
fb367e67916d 7068740: If you wrap a JTable in a JLayer you can't use the page up and page down cmds
vkarnauk
parents: 9230
diff changeset
   439
                    if (!(SwingUtilities.getUnwrappedParent(table).getParent() instanceof
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                            JScrollPane)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                    Dimension delta = table.getParent().getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    if (vertically) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                        Rectangle r = table.getCellRect(leadRow, 0, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                        if (forwards) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                            // scroll by at least one cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                            r.y += Math.max(delta.height, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                            r.y -= delta.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                        this.dx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                        int newRow = table.rowAtPoint(r.getLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                        if (newRow == -1 && forwards) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                            newRow = table.getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                        this.dy = newRow - leadRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                        Rectangle r = table.getCellRect(0, leadColumn, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                        if (forwards) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                            // scroll by at least one cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                            r.x += Math.max(delta.width, r.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                            r.x -= delta.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                        int newColumn = table.columnAtPoint(r.getLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                        if (newColumn == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                            boolean ltr = table.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                            newColumn = forwards ? (ltr ? table.getColumnCount() : 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                                                 : (ltr ? 0 : table.getColumnCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                        this.dx = newColumn - leadColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                        this.dy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            if (key == NEXT_ROW ||  // Navigate Actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                    key == NEXT_ROW_CELL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                    key == NEXT_ROW_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                    key == NEXT_ROW_CHANGE_LEAD ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                    key == NEXT_COLUMN ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                    key == NEXT_COLUMN_CELL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                    key == NEXT_COLUMN_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                    key == NEXT_COLUMN_CHANGE_LEAD ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                    key == PREVIOUS_ROW ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                    key == PREVIOUS_ROW_CELL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                    key == PREVIOUS_ROW_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                    key == PREVIOUS_ROW_CHANGE_LEAD ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                    key == PREVIOUS_COLUMN ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                    key == PREVIOUS_COLUMN_CELL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                    key == PREVIOUS_COLUMN_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                    key == PREVIOUS_COLUMN_CHANGE_LEAD ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                    // Paging Actions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                    key == SCROLL_LEFT_CHANGE_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                    key == SCROLL_LEFT_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                    key == SCROLL_RIGHT_CHANGE_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                    key == SCROLL_RIGHT_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                    key == SCROLL_UP_CHANGE_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                    key == SCROLL_UP_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                    key == SCROLL_DOWN_CHANGE_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                    key == SCROLL_DOWN_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                    key == FIRST_COLUMN ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                    key == FIRST_COLUMN_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                    key == FIRST_ROW ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                    key == FIRST_ROW_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                    key == LAST_COLUMN ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                    key == LAST_COLUMN_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                    key == LAST_ROW ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                    key == LAST_ROW_EXTEND_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                if (table.isEditing() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                        !table.getCellEditor().stopCellEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                // Unfortunately, this strategy introduces bugs because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                // of the asynchronous nature of requestFocus() call below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                // Introducing a delay with invokeLater() makes this work
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                // in the typical case though race conditions then allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                // focus to disappear altogether. The right solution appears
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                // to be to fix requestFocus() so that it queues a request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                // for the focus regardless of who owns the focus at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                // time the call to requestFocus() is made. The optimisation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                // to ignore the call to requestFocus() when the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                // already has focus may ligitimately be made as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                // request focus event is dequeued, not before.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                // boolean wasEditingWithFocus = table.isEditing() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                // table.getEditorComponent().isFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                boolean changeLead = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                if (key == NEXT_ROW_CHANGE_LEAD || key == PREVIOUS_ROW_CHANGE_LEAD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                    changeLead = (rsm.getSelectionMode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                                     == ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                } else if (key == NEXT_COLUMN_CHANGE_LEAD || key == PREVIOUS_COLUMN_CHANGE_LEAD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                    changeLead = (csm.getSelectionMode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                                     == ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                if (changeLead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                    moveWithinTableRange(table, dx, dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                    if (dy != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                        // casting should be safe since the action is only enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                        // for DefaultListSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                        ((DefaultListSelectionModel)rsm).moveLeadSelectionIndex(leadRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                        if (getAdjustedLead(table, false, csm) == -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                                && table.getColumnCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                            ((DefaultListSelectionModel)csm).moveLeadSelectionIndex(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                        // casting should be safe since the action is only enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                        // for DefaultListSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                        ((DefaultListSelectionModel)csm).moveLeadSelectionIndex(leadColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                        if (getAdjustedLead(table, true, rsm) == -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                                && table.getRowCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                            ((DefaultListSelectionModel)rsm).moveLeadSelectionIndex(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                    Rectangle cellRect = table.getCellRect(leadRow, leadColumn, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                    if (cellRect != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                        table.scrollRectToVisible(cellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                } else if (!inSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                    moveWithinTableRange(table, dx, dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                    table.changeSelection(leadRow, leadColumn, false, extend);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                    if (table.getRowCount() <= 0 || table.getColumnCount() <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                        // bail - don't try to move selection on an empty table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                    if (moveWithinSelectedRange(table, dx, dy, rsm, csm)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                        // this is the only way we have to set both the lead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                        // and the anchor without changing the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                        if (rsm.isSelectedIndex(leadRow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                            rsm.addSelectionInterval(leadRow, leadRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                            rsm.removeSelectionInterval(leadRow, leadRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                        if (csm.isSelectedIndex(leadColumn)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                            csm.addSelectionInterval(leadColumn, leadColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                            csm.removeSelectionInterval(leadColumn, leadColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                        Rectangle cellRect = table.getCellRect(leadRow, leadColumn, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                        if (cellRect != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                            table.scrollRectToVisible(cellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                        table.changeSelection(leadRow, leadColumn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                                false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                if (wasEditingWithFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                    table.editCellAt(leadRow, leadColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                    final Component editorComp = table.getEditorComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                    if (editorComp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                        SwingUtilities.invokeLater(new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                                editorComp.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            } else if (key == CANCEL_EDITING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                table.removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            } else if (key == SELECT_ALL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                table.selectAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            } else if (key == CLEAR_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                table.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            } else if (key == START_EDITING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                if (!table.hasFocus()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                    CellEditor cellEditor = table.getCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                    if (cellEditor != null && !cellEditor.stopCellEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                    table.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                table.editCellAt(leadRow, leadColumn, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                Component editorComp = table.getEditorComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                if (editorComp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                    editorComp.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            } else if (key == ADD_TO_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                if (!table.isCellSelected(leadRow, leadColumn)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                    int oldAnchorRow = rsm.getAnchorSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                    int oldAnchorColumn = csm.getAnchorSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                    rsm.setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                    csm.setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                    table.changeSelection(leadRow, leadColumn, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                    rsm.setAnchorSelectionIndex(oldAnchorRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                    csm.setAnchorSelectionIndex(oldAnchorColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                    rsm.setValueIsAdjusting(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                    csm.setValueIsAdjusting(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            } else if (key == TOGGLE_AND_ANCHOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                table.changeSelection(leadRow, leadColumn, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            } else if (key == EXTEND_TO) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                table.changeSelection(leadRow, leadColumn, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            } else if (key == MOVE_SELECTION_TO) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                table.changeSelection(leadRow, leadColumn, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            } else if (key == FOCUS_HEADER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                JTableHeader th = table.getTableHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                if (th != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                    //Set the header's selected column to match the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                    int col = table.getSelectedColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                    if (col >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                        TableHeaderUI thUI = th.getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                        if (thUI instanceof BasicTableHeaderUI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                            ((BasicTableHeaderUI)thUI).selectColumn(col);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                    //Then give the header the focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                    th.requestFocusInWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        public boolean isEnabled(Object sender) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            String key = getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            if (sender instanceof JTable &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                Boolean.TRUE.equals(((JTable)sender).getClientProperty("Table.isFileList"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                if (key == NEXT_COLUMN ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                        key == NEXT_COLUMN_CELL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                        key == NEXT_COLUMN_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                        key == NEXT_COLUMN_CHANGE_LEAD ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                        key == PREVIOUS_COLUMN ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                        key == PREVIOUS_COLUMN_CELL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                        key == PREVIOUS_COLUMN_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                        key == PREVIOUS_COLUMN_CHANGE_LEAD ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                        key == SCROLL_LEFT_CHANGE_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                        key == SCROLL_LEFT_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                        key == SCROLL_RIGHT_CHANGE_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                        key == SCROLL_RIGHT_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                        key == FIRST_COLUMN ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                        key == FIRST_COLUMN_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                        key == LAST_COLUMN ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                        key == LAST_COLUMN_EXTEND_SELECTION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                        key == NEXT_ROW_CELL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                        key == PREVIOUS_ROW_CELL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            if (key == CANCEL_EDITING && sender instanceof JTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                return ((JTable)sender).isEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            } else if (key == NEXT_ROW_CHANGE_LEAD ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                       key == PREVIOUS_ROW_CHANGE_LEAD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                // discontinuous selection actions are only enabled for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                // DefaultListSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                return sender != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                       ((JTable)sender).getSelectionModel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                           instanceof DefaultListSelectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            } else if (key == NEXT_COLUMN_CHANGE_LEAD ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                       key == PREVIOUS_COLUMN_CHANGE_LEAD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                // discontinuous selection actions are only enabled for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                // DefaultListSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                return sender != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                       ((JTable)sender).getColumnModel().getSelectionModel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                           instanceof DefaultListSelectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            } else if (key == ADD_TO_SELECTION && sender instanceof JTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                // This action is typically bound to SPACE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                // If the table is already in an editing mode, SPACE should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                // simply enter a space character into the table, and not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                // select a cell. Likewise, if the lead cell is already selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                // then hitting SPACE should just enter a space character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                // into the cell and begin editing. In both of these cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                // this action will be disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                JTable table = (JTable)sender;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                int leadRow = getAdjustedLead(table, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                int leadCol = getAdjustedLead(table, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                return !(table.isEditing() || table.isCellSelected(leadRow, leadCol));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            } else if (key == FOCUS_HEADER && sender instanceof JTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                JTable table = (JTable)sender;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                return table.getTableHeader() != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
//  The Table's Key listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * This class should be treated as a &quot;protected&quot; inner class.
9230
c5674561cb9e 6985329: 9 classes in swing.plaf contains words inappropriate for public spec - about some compiler bug
alexp
parents: 5506
diff changeset
   751
     * Instantiate it only within subclasses of {@code BasicTableUI}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * <p>As of Java 2 platform v1.3 this class is no longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * Instead <code>JTable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * overrides <code>processKeyBinding</code> to dispatch the event to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * the current <code>TableCellEditor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     public class KeyHandler implements KeyListener {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 17897
diff changeset
   758
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        public void keyPressed(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            getHandler().keyPressed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        public void keyReleased(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            getHandler().keyReleased(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        public void keyTyped(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            getHandler().keyTyped(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
//  The Table's focus listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * This class should be treated as a &quot;protected&quot; inner class.
9230
c5674561cb9e 6985329: 9 classes in swing.plaf contains words inappropriate for public spec - about some compiler bug
alexp
parents: 5506
diff changeset
   781
     * Instantiate it only within subclasses of {@code BasicTableUI}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    public class FocusHandler implements FocusListener {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 17897
diff changeset
   784
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            getHandler().focusGained(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            getHandler().focusLost(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
//  The Table's mouse and mouse motion listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * Instantiate it only within subclasses of BasicTableUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    public class MouseInputHandler implements MouseInputListener {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 17897
diff changeset
   806
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        public void mouseClicked(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            getHandler().mouseClicked(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            getHandler().mousePressed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            getHandler().mouseReleased(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        public void mouseEntered(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            getHandler().mouseEntered(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        public void mouseExited(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            getHandler().mouseExited(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        public void mouseMoved(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            getHandler().mouseMoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        public void mouseDragged(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            getHandler().mouseDragged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    private class Handler implements FocusListener, MouseInputListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            PropertyChangeListener, ListSelectionListener, ActionListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            BeforeDrag {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        // FocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        private void repaintLeadCell( ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            int lr = getAdjustedLead(table, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            int lc = getAdjustedLead(table, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            if (lr < 0 || lc < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            Rectangle dirtyRect = table.getCellRect(lr, lc, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            table.repaint(dirtyRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            repaintLeadCell();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            repaintLeadCell();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        // KeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        public void keyPressed(KeyEvent e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        public void keyReleased(KeyEvent e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        public void keyTyped(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            KeyStroke keyStroke = KeyStroke.getKeyStroke(e.getKeyChar(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                    e.getModifiers());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            // We register all actions using ANCESTOR_OF_FOCUSED_COMPONENT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            // which means that we might perform the appropriate action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            // in the table and then forward it to the editor if the editor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            // had focus. Make sure this doesn't happen by checking our
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            // InputMaps.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            InputMap map = table.getInputMap(JComponent.WHEN_FOCUSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            if (map != null && map.get(keyStroke) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            map = table.getInputMap(JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                                  WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            if (map != null && map.get(keyStroke) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            keyStroke = KeyStroke.getKeyStrokeForEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            // The AWT seems to generate an unconsumed \r event when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            // ENTER (\n) is pressed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            if (e.getKeyChar() == '\r') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            int leadRow = getAdjustedLead(table, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            int leadColumn = getAdjustedLead(table, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            if (leadRow != -1 && leadColumn != -1 && !table.isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                if (!table.editCellAt(leadRow, leadColumn)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            // Forwarding events this way seems to put the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            // in a state where it believes it has focus. In reality
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            // the table retains focus - though it is difficult for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            // a user to tell, since the caret is visible and flashing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            // Calling table.requestFocus() here, to get the focus back to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            // the table, seems to have no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            Component editorComp = table.getEditorComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            if (table.isEditing() && editorComp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                if (editorComp instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                    JComponent component = (JComponent)editorComp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                    map = component.getInputMap(JComponent.WHEN_FOCUSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                    Object binding = (map != null) ? map.get(keyStroke) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                    if (binding == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                        map = component.getInputMap(JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                                         WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                        binding = (map != null) ? map.get(keyStroke) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                    if (binding != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                        ActionMap am = component.getActionMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                        Action action = (am != null) ? am.get(binding) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                        if (action != null && SwingUtilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                            notifyAction(action, keyStroke, e, component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                                         e.getModifiers())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                            e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        // MouseInputListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        // Component receiving mouse events during editing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        // May not be editorComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        private Component dispatchComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        public void mouseClicked(MouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        private void setDispatchComponent(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            Component editorComponent = table.getEditorComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            Point p = e.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            Point p2 = SwingUtilities.convertPoint(table, p, editorComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            dispatchComponent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                    SwingUtilities.getDeepestComponentAt(editorComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                            p2.x, p2.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            SwingUtilities2.setSkipClickCount(dispatchComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                                              e.getClickCount() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        private boolean repostEvent(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            // Check for isEditing() in case another event has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            // caused the editor to be removed. See bug #4306499.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            if (dispatchComponent == null || !table.isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            MouseEvent e2 = SwingUtilities.convertMouseEvent(table, e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                    dispatchComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            dispatchComponent.dispatchEvent(e2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        private void setValueIsAdjusting(boolean flag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            table.getSelectionModel().setValueIsAdjusting(flag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            table.getColumnModel().getSelectionModel().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                    setValueIsAdjusting(flag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        // The row and column where the press occurred and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        // press event itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        private int pressedRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        private int pressedCol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        private MouseEvent pressedEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        // Whether or not the mouse press (which is being considered as part
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        // of a drag sequence) also caused the selection change to be fully
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        // processed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        private boolean dragPressDidSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        // Set to true when a drag gesture has been fully recognized and DnD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        // begins. Use this to ignore further mouse events which could be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        // delivered if DnD is cancelled (via ESCAPE for example)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        private boolean dragStarted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        // Whether or not we should start the editing timer on release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        private boolean shouldStartTimer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        // To cache the return value of pointOutsidePrefSize since we use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        // it multiple times.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        private boolean outsidePrefSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        // Used to delay the start of editing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        private Timer timer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        private boolean canStartDrag() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            if (pressedRow == -1 || pressedCol == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            if (isFileList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                return !outsidePrefSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            // if this is a single selection table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
            if ((table.getSelectionModel().getSelectionMode() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                     ListSelectionModel.SINGLE_SELECTION) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                (table.getColumnModel().getSelectionModel().getSelectionMode() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                     ListSelectionModel.SINGLE_SELECTION)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            return table.isCellSelected(pressedRow, pressedCol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            if (SwingUtilities2.shouldIgnore(e, table)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            if (table.isEditing() && !table.getCellEditor().stopCellEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                Component editorComponent = table.getEditorComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                if (editorComponent != null && !editorComponent.hasFocus()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                    SwingUtilities2.compositeRequestFocus(editorComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            Point p = e.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            pressedRow = table.rowAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            pressedCol = table.columnAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            outsidePrefSize = pointOutsidePrefSize(pressedRow, pressedCol, p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            if (isFileList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                shouldStartTimer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                    table.isCellSelected(pressedRow, pressedCol) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                    !e.isShiftDown() &&
3977
0da8e3baf0b5 4833524: BasicTreeUI.isToggleSelectionEvent() does not properly handle popup triggers
alexp
parents: 2658
diff changeset
  1044
                    !BasicGraphicsUtils.isMenuShortcutKeyDown(e) &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                    !outsidePrefSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            if (table.getDragEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                mousePressedDND(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                SwingUtilities2.adjustFocus(table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                if (!isFileList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                    setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                adjustSelection(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        private void mousePressedDND(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            pressedEvent = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            boolean grabFocus = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            dragStarted = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            if (canStartDrag() && DragRecognitionSupport.mousePressed(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                dragPressDidSelection = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
3977
0da8e3baf0b5 4833524: BasicTreeUI.isToggleSelectionEvent() does not properly handle popup triggers
alexp
parents: 2658
diff changeset
  1068
                if (BasicGraphicsUtils.isMenuShortcutKeyDown(e) && isFileList) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                    // do nothing for control - will be handled on release
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                    // or when drag starts
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                } else if (!e.isShiftDown() && table.isCellSelected(pressedRow, pressedCol)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                    // clicking on something that's already selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                    // and need to make it the lead now
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                    table.getSelectionModel().addSelectionInterval(pressedRow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                                                                   pressedRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                    table.getColumnModel().getSelectionModel().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                        addSelectionInterval(pressedCol, pressedCol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                dragPressDidSelection = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                // could be a drag initiating event - don't grab focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                grabFocus = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            } else if (!isFileList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                // When drag can't happen, mouse drags might change the selection in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                // so we want the isAdjusting flag to be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            if (grabFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                SwingUtilities2.adjustFocus(table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
            adjustSelection(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        private void adjustSelection(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            // Fix for 4835633
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
            if (outsidePrefSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                // If shift is down in multi-select, we should just return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                // For single select or non-shift-click, clear the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                if (e.getID() ==  MouseEvent.MOUSE_PRESSED &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                    (!e.isShiftDown() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                     table.getSelectionModel().getSelectionMode() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                     ListSelectionModel.SINGLE_SELECTION)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                    table.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                    TableCellEditor tce = table.getCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                    if (tce != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                        tce.stopCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            // The autoscroller can generate drag events outside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            // table's range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            if ((pressedCol == -1) || (pressedRow == -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
            boolean dragEnabled = table.getDragEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            if (!dragEnabled && !isFileList && table.editCellAt(pressedRow, pressedCol, e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                setDispatchComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                repostEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            CellEditor editor = table.getCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            if (dragEnabled || editor == null || editor.shouldSelectCell(e)) {
3977
0da8e3baf0b5 4833524: BasicTreeUI.isToggleSelectionEvent() does not properly handle popup triggers
alexp
parents: 2658
diff changeset
  1132
                table.changeSelection(pressedRow, pressedCol,
0da8e3baf0b5 4833524: BasicTreeUI.isToggleSelectionEvent() does not properly handle popup triggers
alexp
parents: 2658
diff changeset
  1133
                        BasicGraphicsUtils.isMenuShortcutKeyDown(e),
0da8e3baf0b5 4833524: BasicTreeUI.isToggleSelectionEvent() does not properly handle popup triggers
alexp
parents: 2658
diff changeset
  1134
                        e.isShiftDown());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        public void valueChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            if (timer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                timer.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                timer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        public void actionPerformed(ActionEvent ae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            table.editCellAt(pressedRow, pressedCol, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            Component editorComponent = table.getEditorComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            if (editorComponent != null && !editorComponent.hasFocus()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                SwingUtilities2.compositeRequestFocus(editorComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        private void maybeStartTimer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
            if (!shouldStartTimer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
            if (timer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                timer = new Timer(1200, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                timer.setRepeats(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            timer.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            if (SwingUtilities2.shouldIgnore(e, table)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
            if (table.getDragEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                mouseReleasedDND(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                if (isFileList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                    maybeStartTimer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
            pressedEvent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            repostEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
            dispatchComponent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
            setValueIsAdjusting(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        private void mouseReleasedDND(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
            MouseEvent me = DragRecognitionSupport.mouseReleased(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
            if (me != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                SwingUtilities2.adjustFocus(table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                if (!dragPressDidSelection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
                    adjustSelection(me);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            if (!dragStarted) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                if (isFileList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                    maybeStartTimer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                Point p = e.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                if (pressedEvent != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                        table.rowAtPoint(p) == pressedRow &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                        table.columnAtPoint(p) == pressedCol &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
                        table.editCellAt(pressedRow, pressedCol, pressedEvent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                    setDispatchComponent(pressedEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                    repostEvent(pressedEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                    // This may appear completely odd, but must be done for backward
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                    // compatibility reasons. Developers have been known to rely on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                    // a call to shouldSelectCell after editing has begun.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                    CellEditor ce = table.getCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                    if (ce != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                        ce.shouldSelectCell(pressedEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        public void mouseEntered(MouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        public void mouseExited(MouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        public void mouseMoved(MouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        public void dragStarting(MouseEvent me) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
            dragStarted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
3977
0da8e3baf0b5 4833524: BasicTreeUI.isToggleSelectionEvent() does not properly handle popup triggers
alexp
parents: 2658
diff changeset
  1231
            if (BasicGraphicsUtils.isMenuShortcutKeyDown(me) && isFileList) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                table.getSelectionModel().addSelectionInterval(pressedRow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                                                               pressedRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                table.getColumnModel().getSelectionModel().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
                    addSelectionInterval(pressedCol, pressedCol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
            pressedEvent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        public void mouseDragged(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
            if (SwingUtilities2.shouldIgnore(e, table)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            if (table.getDragEnabled() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
                    (DragRecognitionSupport.mouseDragged(e, this) || dragStarted)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            repostEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            // Check isFileList:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            // Until we support drag-selection, dragging should not change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
            // the selection (act like single-select).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            if (isFileList || table.isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            Point p = e.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            int row = table.rowAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
            int column = table.columnAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
            // The autoscroller can generate drag events outside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
            // table's range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            if ((column == -1) || (row == -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
3977
0da8e3baf0b5 4833524: BasicTreeUI.isToggleSelectionEvent() does not properly handle popup triggers
alexp
parents: 2658
diff changeset
  1270
            table.changeSelection(row, column,
0da8e3baf0b5 4833524: BasicTreeUI.isToggleSelectionEvent() does not properly handle popup triggers
alexp
parents: 2658
diff changeset
  1271
                    BasicGraphicsUtils.isMenuShortcutKeyDown(e), true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        // PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        public void propertyChange(PropertyChangeEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
            String changeName = event.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
            if ("componentOrientation" == changeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                InputMap inputMap = getInputMap(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                    JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
                SwingUtilities.replaceUIInputMap(table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                    JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                    inputMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
                JTableHeader header = table.getTableHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
                if (header != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                    header.setComponentOrientation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                            (ComponentOrientation)event.getNewValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
            } else if ("dropLocation" == changeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                JTable.DropLocation oldValue = (JTable.DropLocation)event.getOldValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                repaintDropLocation(oldValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                repaintDropLocation(table.getDropLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
            } else if ("Table.isFileList" == changeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                isFileList = Boolean.TRUE.equals(table.getClientProperty("Table.isFileList"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                table.revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                table.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                if (isFileList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                    table.getSelectionModel().addListSelectionListener(getHandler());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                    table.getSelectionModel().removeListSelectionListener(getHandler());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                    timer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            } else if ("selectionModel" == changeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                if (isFileList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                    ListSelectionModel old = (ListSelectionModel)event.getOldValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
                    old.removeListSelectionListener(getHandler());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                    table.getSelectionModel().addListSelectionListener(getHandler());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        private void repaintDropLocation(JTable.DropLocation loc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            if (loc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
            if (!loc.isInsertRow() && !loc.isInsertColumn()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                Rectangle rect = table.getCellRect(loc.getRow(), loc.getColumn(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                if (rect != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                    table.repaint(rect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
            if (loc.isInsertRow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
                Rectangle rect = extendRect(getHDropLineRect(loc), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                if (rect != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
                    table.repaint(rect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
            if (loc.isInsertColumn()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
                Rectangle rect = extendRect(getVDropLineRect(loc), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                if (rect != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
                    table.repaint(rect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
     * Returns true if the given point is outside the preferredSize of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
     * item at the given row of the table.  (Column must be 0).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
     * Returns false if the "Table.isFileList" client property is not set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    private boolean pointOutsidePrefSize(int row, int column, Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        if (!isFileList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
        return SwingUtilities2.pointOutsidePrefSize(table, row, column, p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
//  Factory methods for the Listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
    private Handler getHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        if (handler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
            handler = new Handler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        return handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
    /**
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1370
     * Creates the key listener for handling keyboard navigation in the {@code JTable}.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1371
     *
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1372
     * @return the key listener for handling keyboard navigation in the {@code JTable}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
    protected KeyListener createKeyListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
    /**
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1379
     * Creates the focus listener for handling keyboard navigation in the {@code JTable}.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1380
     *
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1381
     * @return the focus listener for handling keyboard navigation in the {@code JTable}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
    protected FocusListener createFocusListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
    /**
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1388
     * Creates the mouse listener for the {@code JTable}.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1389
     *
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1390
     * @return the mouse listener for the {@code JTable}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
    protected MouseInputListener createMouseInputListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
//  The installation/uninstall procedures and support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1400
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1401
     * Returns a new instance of {@code BasicTableUI}.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1402
     *
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1403
     * @param c a component
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1404
     * @return a new instance of {@code BasicTableUI}
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1405
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
        return new BasicTableUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
//  Installation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
    public void installUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
        table = (JTable)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
        rendererPane = new CellRendererPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
        table.add(rendererPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
        installDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
        installDefaults2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
        installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
        installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     * Initialize JTable properties, e.g. font, foreground, and background.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     * The font, foreground, and background properties are only set if their
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     * current value is either null or a UIResource, other properties are set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
     * if the current value is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
     * @see #installUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
        LookAndFeel.installColorsAndFont(table, "Table.background",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
                                         "Table.foreground", "Table.font");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
        // JTable's original row height is 16.  To correctly display the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
        // contents on Linux we should have set it to 18, Windows 19 and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
        // Solaris 20.  As these values vary so much it's too hard to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
        // be backward compatable and try to update the row height, we're
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
        // therefor NOT going to adjust the row height based on font.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        // developer changes the font, it's there responsability to update
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
        // the row height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
        LookAndFeel.installProperty(table, "opaque", Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
        Color sbg = table.getSelectionBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
        if (sbg == null || sbg instanceof UIResource) {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
  1446
            sbg = UIManager.getColor("Table.selectionBackground");
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
  1447
            table.setSelectionBackground(sbg != null ? sbg : UIManager.getColor("textHighlight"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
        Color sfg = table.getSelectionForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        if (sfg == null || sfg instanceof UIResource) {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
  1452
            sfg = UIManager.getColor("Table.selectionForeground");
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
  1453
            table.setSelectionForeground(sfg != null ? sfg : UIManager.getColor("textHighlightText"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
        Color gridColor = table.getGridColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
        if (gridColor == null || gridColor instanceof UIResource) {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
  1458
            gridColor = UIManager.getColor("Table.gridColor");
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
  1459
            table.setGridColor(gridColor != null ? gridColor : Color.GRAY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        // install the scrollpane border
17897
fb367e67916d 7068740: If you wrap a JTable in a JLayer you can't use the page up and page down cmds
vkarnauk
parents: 9230
diff changeset
  1463
        Container parent = SwingUtilities.getUnwrappedParent(table);  // should be viewport
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
            parent = parent.getParent();  // should be the scrollpane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
            if (parent != null && parent instanceof JScrollPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
                LookAndFeel.installBorder((JScrollPane)parent, "Table.scrollPaneBorder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        isFileList = Boolean.TRUE.equals(table.getClientProperty("Table.isFileList"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
    private void installDefaults2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
        TransferHandler th = table.getTransferHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
        if (th == null || th instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
            table.setTransferHandler(defaultTransferHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
            // default TransferHandler doesn't support drop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
            // so we don't want drop handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
            if (table.getDropTarget() instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
                table.setDropTarget(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
     * Attaches listeners to the JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        focusListener = createFocusListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
        keyListener = createKeyListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
        mouseInputListener = createMouseInputListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
        table.addFocusListener(focusListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
        table.addKeyListener(keyListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
        table.addMouseListener(mouseInputListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        table.addMouseMotionListener(mouseInputListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
        table.addPropertyChangeListener(getHandler());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
        if (isFileList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
            table.getSelectionModel().addListSelectionListener(getHandler());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
     * Register all keyboard actions on the JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
    protected void installKeyboardActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
        LazyActionMap.installLazyActionMap(table, BasicTableUI.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
                "Table.actionMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
        InputMap inputMap = getInputMap(JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
                                        WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
        SwingUtilities.replaceUIInputMap(table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
                                JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
                                inputMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
    InputMap getInputMap(int condition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
        if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
            InputMap keyMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
                (InputMap)DefaultLookup.get(table, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
                                            "Table.ancestorInputMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
            InputMap rtlKeyMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
            if (table.getComponentOrientation().isLeftToRight() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
                ((rtlKeyMap = (InputMap)DefaultLookup.get(table, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                                            "Table.ancestorInputMap.RightToLeft")) == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
                return keyMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
                rtlKeyMap.setParent(keyMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
                return rtlKeyMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
    static void loadActionMap(LazyActionMap map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
        // IMPORTANT: There is a very close coupling between the parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
        // passed to the Actions constructor. Only certain parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
        // combinations are supported. For example, the following Action would
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
        // not work as expected:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
        //     new Actions(Actions.NEXT_ROW_CELL, 1, 4, false, true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
        // Actions which move within the selection only (having a true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
        // inSelection parameter) require that one of dx or dy be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
        // zero and the other be -1 or 1. The point of this warning is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
        // that you should be very careful about making sure a particular
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
        // combination of parameters is supported before changing or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
        // adding anything here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
        map.put(new Actions(Actions.NEXT_COLUMN, 1, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
                false, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
        map.put(new Actions(Actions.NEXT_COLUMN_CHANGE_LEAD, 1, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
                false, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
        map.put(new Actions(Actions.PREVIOUS_COLUMN, -1, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                false, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
        map.put(new Actions(Actions.PREVIOUS_COLUMN_CHANGE_LEAD, -1, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
                false, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
        map.put(new Actions(Actions.NEXT_ROW, 0, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                false, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
        map.put(new Actions(Actions.NEXT_ROW_CHANGE_LEAD, 0, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                false, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
        map.put(new Actions(Actions.PREVIOUS_ROW, 0, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
                false, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
        map.put(new Actions(Actions.PREVIOUS_ROW_CHANGE_LEAD, 0, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                false, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
        map.put(new Actions(Actions.NEXT_COLUMN_EXTEND_SELECTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                1, 0, true, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
        map.put(new Actions(Actions.PREVIOUS_COLUMN_EXTEND_SELECTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
                -1, 0, true, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
        map.put(new Actions(Actions.NEXT_ROW_EXTEND_SELECTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                0, 1, true, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
        map.put(new Actions(Actions.PREVIOUS_ROW_EXTEND_SELECTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
                0, -1, true, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
        map.put(new Actions(Actions.SCROLL_UP_CHANGE_SELECTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
                false, false, true, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
        map.put(new Actions(Actions.SCROLL_DOWN_CHANGE_SELECTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
                false, true, true, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
        map.put(new Actions(Actions.FIRST_COLUMN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
                false, false, false, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
        map.put(new Actions(Actions.LAST_COLUMN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
                false, true, false, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
        map.put(new Actions(Actions.SCROLL_UP_EXTEND_SELECTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                true, false, true, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
        map.put(new Actions(Actions.SCROLL_DOWN_EXTEND_SELECTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                true, true, true, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
        map.put(new Actions(Actions.FIRST_COLUMN_EXTEND_SELECTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
                true, false, false, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
        map.put(new Actions(Actions.LAST_COLUMN_EXTEND_SELECTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
                true, true, false, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
        map.put(new Actions(Actions.FIRST_ROW, false, false, true, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
        map.put(new Actions(Actions.LAST_ROW, false, true, true, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
        map.put(new Actions(Actions.FIRST_ROW_EXTEND_SELECTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
                true, false, true, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
        map.put(new Actions(Actions.LAST_ROW_EXTEND_SELECTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
                true, true, true, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
        map.put(new Actions(Actions.NEXT_COLUMN_CELL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                1, 0, false, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
        map.put(new Actions(Actions.PREVIOUS_COLUMN_CELL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                -1, 0, false, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
        map.put(new Actions(Actions.NEXT_ROW_CELL, 0, 1, false, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
        map.put(new Actions(Actions.PREVIOUS_ROW_CELL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
                0, -1, false, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
        map.put(new Actions(Actions.SELECT_ALL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
        map.put(new Actions(Actions.CLEAR_SELECTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
        map.put(new Actions(Actions.CANCEL_EDITING));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
        map.put(new Actions(Actions.START_EDITING));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
        map.put(TransferHandler.getCutAction().getValue(Action.NAME),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
                TransferHandler.getCutAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
        map.put(TransferHandler.getCopyAction().getValue(Action.NAME),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
                TransferHandler.getCopyAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
        map.put(TransferHandler.getPasteAction().getValue(Action.NAME),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
                TransferHandler.getPasteAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
        map.put(new Actions(Actions.SCROLL_LEFT_CHANGE_SELECTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
                false, false, false, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
        map.put(new Actions(Actions.SCROLL_RIGHT_CHANGE_SELECTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
                false, true, false, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
        map.put(new Actions(Actions.SCROLL_LEFT_EXTEND_SELECTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
                true, false, false, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
        map.put(new Actions(Actions.SCROLL_RIGHT_EXTEND_SELECTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
                true, true, false, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
        map.put(new Actions(Actions.ADD_TO_SELECTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
        map.put(new Actions(Actions.TOGGLE_AND_ANCHOR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
        map.put(new Actions(Actions.EXTEND_TO));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
        map.put(new Actions(Actions.MOVE_SELECTION_TO));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
        map.put(new Actions(Actions.FOCUS_HEADER));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
//  Uninstallation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
    public void uninstallUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
        uninstallDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
        uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
        uninstallKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
        table.remove(rendererPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
        rendererPane = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        table = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1648
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1649
     * Uninstalls default properties.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1650
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
        if (table.getTransferHandler() instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
            table.setTransferHandler(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1657
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1658
     * Unregisters listeners.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1659
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
        table.removeFocusListener(focusListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
        table.removeKeyListener(keyListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
        table.removeMouseListener(mouseInputListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
        table.removeMouseMotionListener(mouseInputListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
        table.removePropertyChangeListener(getHandler());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
        if (isFileList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
            table.getSelectionModel().removeListSelectionListener(getHandler());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
        focusListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
        keyListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
        mouseInputListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
        handler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1676
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1677
     * Unregisters keyboard actions.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 25565
diff changeset
  1678
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
    protected void uninstallKeyboardActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
        SwingUtilities.replaceUIInputMap(table, JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                                   WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
        SwingUtilities.replaceUIActionMap(table, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
     * Returns the baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
     * @throws IllegalArgumentException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
     * @see javax.swing.JComponent#getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
    public int getBaseline(JComponent c, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
        super.getBaseline(c, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
        UIDefaults lafDefaults = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
        Component renderer = (Component)lafDefaults.get(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
                BASELINE_COMPONENT_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
        if (renderer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
            DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
            renderer = tcr.getTableCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
                    table, "a", false, false, -1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
            lafDefaults.put(BASELINE_COMPONENT_KEY, renderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
        renderer.setFont(table.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
        int rowMargin = table.getRowMargin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
        return renderer.getBaseline(Integer.MAX_VALUE, table.getRowHeight() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
                                    rowMargin) + rowMargin / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
     * Returns an enum indicating how the baseline of the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
     * changes as the size changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
     * @see javax.swing.JComponent#getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
    public Component.BaselineResizeBehavior getBaselineResizeBehavior(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
            JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
        super.getBaselineResizeBehavior(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
        return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
// Size Methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
    private Dimension createTableSize(long width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
        int height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
        int rowCount = table.getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
        if (rowCount > 0 && table.getColumnCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
            Rectangle r = table.getCellRect(rowCount-1, 0, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
            height = r.y + r.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
        // Width is always positive. The call to abs() is a workaround for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
        // a bug in the 1.1.6 JIT on Windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        long tmp = Math.abs(width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
        if (tmp > Integer.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
            tmp = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
        return new Dimension((int)tmp, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
     * Return the minimum size of the table. The minimum height is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
     * row height times the number of rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
     * The minimum width is the sum of the minimum widths of each column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
    public Dimension getMinimumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
        long width = 0;
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 24969
diff changeset
  1751
        Enumeration<TableColumn> enumeration = table.getColumnModel().getColumns();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
        while (enumeration.hasMoreElements()) {
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 24969
diff changeset
  1753
            TableColumn aColumn = enumeration.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
            width = width + aColumn.getMinWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
        return createTableSize(width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
     * Return the preferred size of the table. The preferred height is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
     * row height times the number of rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
     * The preferred width is the sum of the preferred widths of each column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
    public Dimension getPreferredSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
        long width = 0;
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 24969
diff changeset
  1766
        Enumeration<TableColumn> enumeration = table.getColumnModel().getColumns();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
        while (enumeration.hasMoreElements()) {
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 24969
diff changeset
  1768
            TableColumn aColumn = enumeration.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
            width = width + aColumn.getPreferredWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
        return createTableSize(width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
     * Return the maximum size of the table. The maximum height is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
     * row heighttimes the number of rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
     * The maximum width is the sum of the maximum widths of each column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
    public Dimension getMaximumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
        long width = 0;
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 24969
diff changeset
  1781
        Enumeration<TableColumn> enumeration = table.getColumnModel().getColumns();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
        while (enumeration.hasMoreElements()) {
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 24969
diff changeset
  1783
            TableColumn aColumn = enumeration.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
            width = width + aColumn.getMaxWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
        return createTableSize(width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
//  Paint methods and support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
    /** Paint a representation of the <code>table</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
     * that was set in installUI().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
        Rectangle clip = g.getClipBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
        Rectangle bounds = table.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
        // account for the fact that the graphics has already been translated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
        // into the table's bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
        bounds.x = bounds.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
        if (table.getRowCount() <= 0 || table.getColumnCount() <= 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
                // this check prevents us from painting the entire table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
                // when the clip doesn't intersect our bounds at all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
                !bounds.intersects(clip)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
            paintDropLines(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
        boolean ltr = table.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
        Point upperLeft = clip.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
        Point lowerRight = new Point(clip.x + clip.width - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
                                     clip.y + clip.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
        int rMin = table.rowAtPoint(upperLeft);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
        int rMax = table.rowAtPoint(lowerRight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
        // This should never happen (as long as our bounds intersect the clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
        // which is why we bail above if that is the case).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
        if (rMin == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
            rMin = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
        // If the table does not have enough rows to fill the view we'll get -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
        // (We could also get -1 if our bounds don't intersect the clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
        // which is why we bail above if that is the case).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
        // Replace this with the index of the last row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
        if (rMax == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
            rMax = table.getRowCount()-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
        int cMin = table.columnAtPoint(ltr ? upperLeft : lowerRight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
        int cMax = table.columnAtPoint(ltr ? lowerRight : upperLeft);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
        // This should never happen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
        if (cMin == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
            cMin = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
        // If the table does not have enough columns to fill the view we'll get -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
        // Replace this with the index of the last column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
        if (cMax == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
            cMax = table.getColumnCount()-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
        // Paint the grid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
        paintGrid(g, rMin, rMax, cMin, cMax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
        // Paint the cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
        paintCells(g, rMin, rMax, cMin, cMax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
        paintDropLines(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
    private void paintDropLines(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
        JTable.DropLocation loc = table.getDropLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
        if (loc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
        Color color = UIManager.getColor("Table.dropLineColor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
        Color shortColor = UIManager.getColor("Table.dropLineShortColor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
        if (color == null && shortColor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
        Rectangle rect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
        rect = getHDropLineRect(loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
        if (rect != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
            int x = rect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
            int w = rect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
            if (color != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
                extendRect(rect, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
                g.setColor(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
                g.fillRect(rect.x, rect.y, rect.width, rect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
            if (!loc.isInsertColumn() && shortColor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
                g.setColor(shortColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
                g.fillRect(x, rect.y, w, rect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
        rect = getVDropLineRect(loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
        if (rect != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
            int y = rect.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
            int h = rect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
            if (color != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
                extendRect(rect, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
                g.setColor(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
                g.fillRect(rect.x, rect.y, rect.width, rect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
            if (!loc.isInsertRow() && shortColor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
                g.setColor(shortColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
                g.fillRect(rect.x, y, rect.width, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
    private Rectangle getHDropLineRect(JTable.DropLocation loc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
        if (!loc.isInsertRow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
        int row = loc.getRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
        int col = loc.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
        if (col >= table.getColumnCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
            col--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
        Rectangle rect = table.getCellRect(row, col, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
        if (row >= table.getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
            row--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
            Rectangle prevRect = table.getCellRect(row, col, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
            rect.y = prevRect.y + prevRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
        if (rect.y == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
            rect.y = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
            rect.y -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
        rect.height = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
        return rect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
    private Rectangle getVDropLineRect(JTable.DropLocation loc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
        if (!loc.isInsertColumn()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
        boolean ltr = table.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
        int col = loc.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
        Rectangle rect = table.getCellRect(loc.getRow(), col, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
        if (col >= table.getColumnCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
            col--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
            rect = table.getCellRect(loc.getRow(), col, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
            if (ltr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
                rect.x = rect.x + rect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
        } else if (!ltr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
            rect.x = rect.x + rect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
        if (rect.x == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
            rect.x = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
            rect.x -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
        rect.width = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
        return rect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
    private Rectangle extendRect(Rectangle rect, boolean horizontal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
        if (rect == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
            return rect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
        if (horizontal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
            rect.x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
            rect.width = table.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
            rect.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
            if (table.getRowCount() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
                Rectangle lastRect = table.getCellRect(table.getRowCount() - 1, 0, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
                rect.height = lastRect.y + lastRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
                rect.height = table.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
        return rect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
     * Paints the grid lines within <I>aRect</I>, using the grid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
     * color set with <I>setGridColor</I>. Paints vertical lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
     * if <code>getShowVerticalLines()</code> returns true and paints
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
     * horizontal lines if <code>getShowHorizontalLines()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
    private void paintGrid(Graphics g, int rMin, int rMax, int cMin, int cMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
        g.setColor(table.getGridColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
        Rectangle minCell = table.getCellRect(rMin, cMin, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
        Rectangle maxCell = table.getCellRect(rMax, cMax, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
        Rectangle damagedArea = minCell.union( maxCell );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
        if (table.getShowHorizontalLines()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
            int tableWidth = damagedArea.x + damagedArea.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
            int y = damagedArea.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
            for (int row = rMin; row <= rMax; row++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
                y += table.getRowHeight(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
                g.drawLine(damagedArea.x, y - 1, tableWidth - 1, y - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
        if (table.getShowVerticalLines()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
            TableColumnModel cm = table.getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
            int tableHeight = damagedArea.y + damagedArea.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
            int x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
            if (table.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
                x = damagedArea.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
                for (int column = cMin; column <= cMax; column++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
                    int w = cm.getColumn(column).getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
                    x += w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
                    g.drawLine(x - 1, 0, x - 1, tableHeight - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
                x = damagedArea.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
                for (int column = cMax; column >= cMin; column--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
                    int w = cm.getColumn(column).getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
                    x += w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
                    g.drawLine(x - 1, 0, x - 1, tableHeight - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
    private int viewIndexForColumn(TableColumn aColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
        TableColumnModel cm = table.getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
        for (int column = 0; column < cm.getColumnCount(); column++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
            if (cm.getColumn(column) == aColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
                return column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
    private void paintCells(Graphics g, int rMin, int rMax, int cMin, int cMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
        JTableHeader header = table.getTableHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
        TableColumn draggedColumn = (header == null) ? null : header.getDraggedColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
        TableColumnModel cm = table.getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
        int columnMargin = cm.getColumnMargin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
        Rectangle cellRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
        TableColumn aColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
        int columnWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
        if (table.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
            for(int row = rMin; row <= rMax; row++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
                cellRect = table.getCellRect(row, cMin, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
                for(int column = cMin; column <= cMax; column++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
                    aColumn = cm.getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
                    columnWidth = aColumn.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
                    cellRect.width = columnWidth - columnMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
                    if (aColumn != draggedColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
                        paintCell(g, cellRect, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
                    cellRect.x += columnWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
            for(int row = rMin; row <= rMax; row++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
                cellRect = table.getCellRect(row, cMin, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
                aColumn = cm.getColumn(cMin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
                if (aColumn != draggedColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
                    columnWidth = aColumn.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
                    cellRect.width = columnWidth - columnMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
                    paintCell(g, cellRect, row, cMin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
                for(int column = cMin+1; column <= cMax; column++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
                    aColumn = cm.getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
                    columnWidth = aColumn.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
                    cellRect.width = columnWidth - columnMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
                    cellRect.x -= columnWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
                    if (aColumn != draggedColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
                        paintCell(g, cellRect, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
        // Paint the dragged column if we are dragging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
        if (draggedColumn != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
            paintDraggedArea(g, rMin, rMax, draggedColumn, header.getDraggedDistance());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
        // Remove any renderers that may be left in the rendererPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
        rendererPane.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
    private void paintDraggedArea(Graphics g, int rMin, int rMax, TableColumn draggedColumn, int distance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
        int draggedColumnIndex = viewIndexForColumn(draggedColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
        Rectangle minCell = table.getCellRect(rMin, draggedColumnIndex, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
        Rectangle maxCell = table.getCellRect(rMax, draggedColumnIndex, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
        Rectangle vacatedColumnRect = minCell.union(maxCell);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
        // Paint a gray well in place of the moving column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
        g.setColor(table.getParent().getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
        g.fillRect(vacatedColumnRect.x, vacatedColumnRect.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
                   vacatedColumnRect.width, vacatedColumnRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
        // Move to the where the cell has been dragged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
        vacatedColumnRect.x += distance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
        // Fill the background.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
        g.setColor(table.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
        g.fillRect(vacatedColumnRect.x, vacatedColumnRect.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
                   vacatedColumnRect.width, vacatedColumnRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
        // Paint the vertical grid lines if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
        if (table.getShowVerticalLines()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
            g.setColor(table.getGridColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
            int x1 = vacatedColumnRect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
            int y1 = vacatedColumnRect.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
            int x2 = x1 + vacatedColumnRect.width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
            int y2 = y1 + vacatedColumnRect.height - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
            // Left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
            g.drawLine(x1-1, y1, x1-1, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
            // Right
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
            g.drawLine(x2, y1, x2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
        for(int row = rMin; row <= rMax; row++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
            // Render the cell value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
            Rectangle r = table.getCellRect(row, draggedColumnIndex, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
            r.x += distance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
            paintCell(g, r, row, draggedColumnIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
            // Paint the (lower) horizontal grid line if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
            if (table.getShowHorizontalLines()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
                g.setColor(table.getGridColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
                Rectangle rcr = table.getCellRect(row, draggedColumnIndex, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
                rcr.x += distance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
                int x1 = rcr.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
                int y1 = rcr.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
                int x2 = x1 + rcr.width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
                int y2 = y1 + rcr.height - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
                g.drawLine(x1, y2, x2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
    private void paintCell(Graphics g, Rectangle cellRect, int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
        if (table.isEditing() && table.getEditingRow()==row &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
                                 table.getEditingColumn()==column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
            Component component = table.getEditorComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
            component.setBounds(cellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
            component.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
            TableCellRenderer renderer = table.getCellRenderer(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
            Component component = table.prepareRenderer(renderer, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
            rendererPane.paintComponent(g, component, table, cellRect.x, cellRect.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
                                        cellRect.width, cellRect.height, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
    private static int getAdjustedLead(JTable table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
                                       boolean row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
                                       ListSelectionModel model) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
        int index = model.getLeadSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
        int compare = row ? table.getRowCount() : table.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
        return index < compare ? index : -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
    private static int getAdjustedLead(JTable table, boolean row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
        return row ? getAdjustedLead(table, row, table.getSelectionModel())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
                   : getAdjustedLead(table, row, table.getColumnModel().getSelectionModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
    private static final TransferHandler defaultTransferHandler = new TableTransferHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 21278
diff changeset
  2175
    @SuppressWarnings("serial") // JDK-implementation class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
    static class TableTransferHandler extends TransferHandler implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
         * Create a Transferable to use as the source for a data transfer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
         * @param c  The component holding the data to be transfered.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
         *  argument is provided to enable sharing of TransferHandlers by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
         *  multiple components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
         * @return  The representation of the data to be transfered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
        protected Transferable createTransferable(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
            if (c instanceof JTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
                JTable table = (JTable) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
                int[] rows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
                int[] cols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
                if (!table.getRowSelectionAllowed() && !table.getColumnSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
                if (!table.getRowSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
                    int rowCount = table.getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
                    rows = new int[rowCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
                    for (int counter = 0; counter < rowCount; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
                        rows[counter] = counter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
                    rows = table.getSelectedRows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
                if (!table.getColumnSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
                    int colCount = table.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
                    cols = new int[colCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
                    for (int counter = 0; counter < colCount; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
                        cols[counter] = counter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
                    cols = table.getSelectedColumns();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
                if (rows == null || cols == null || rows.length == 0 || cols.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23697
diff changeset
  2223
                StringBuilder plainStr = new StringBuilder();
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23697
diff changeset
  2224
                StringBuilder htmlStr = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23697
diff changeset
  2226
                htmlStr.append("<html>\n<body>\n<table>\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
                for (int row = 0; row < rows.length; row++) {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23697
diff changeset
  2229
                    htmlStr.append("<tr>\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
                    for (int col = 0; col < cols.length; col++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
                        Object obj = table.getValueAt(rows[row], cols[col]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
                        String val = ((obj == null) ? "" : obj.toString());
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23697
diff changeset
  2233
                        plainStr.append(val + "\t");
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23697
diff changeset
  2234
                        htmlStr.append("  <td>" + val + "</td>\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
                    // we want a newline at the end of each line and not a tab
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23697
diff changeset
  2237
                    plainStr.deleteCharAt(plainStr.length() - 1).append("\n");
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23697
diff changeset
  2238
                    htmlStr.append("</tr>\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
                // remove the last newline
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23697
diff changeset
  2242
                plainStr.deleteCharAt(plainStr.length() - 1);
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23697
diff changeset
  2243
                htmlStr.append("</table>\n</body>\n</html>");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23697
diff changeset
  2245
                return new BasicTransferable(plainStr.toString(), htmlStr.toString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
        public int getSourceActions(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
            return COPY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
}  // End of Class BasicTableUI