jdk/src/share/classes/javax/swing/JTable.java
author alexp
Thu, 22 Oct 2009 18:42:18 +0400
changeset 4272 f4742294ef29
parent 3737 83fb4621a129
child 4278 b7a976422d27
permissions -rw-r--r--
6795356: Leak caused by javax.swing.UIDefaults.ProxyLazyValue.acc Reviewed-by: hawtin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 438
diff changeset
     2
 * Copyright 1997-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.applet.Applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.print.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.swing.table.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.text.NumberFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.text.DateFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.text.MessageFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import javax.print.attribute.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import javax.print.PrintService;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import sun.swing.SwingUtilities2.Section;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import static sun.swing.SwingUtilities2.Section.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import sun.swing.PrintingStatus;
4272
f4742294ef29 6795356: Leak caused by javax.swing.UIDefaults.ProxyLazyValue.acc
alexp
parents: 3737
diff changeset
    60
import sun.swing.SwingLazyValue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * The <code>JTable</code> is used to display and edit regular two-dimensional tables
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * of cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * See <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/table.html">How to Use Tables</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * in <em>The Java Tutorial</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * for task-oriented documentation and examples of using <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * The <code>JTable</code> has many
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * facilities that make it possible to customize its rendering and editing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * but provides defaults for these features so that simple tables can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * set up easily.  For example, to set up a table with 10 rows and 10
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * columns of numbers:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *      TableModel dataModel = new AbstractTableModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *          public int getColumnCount() { return 10; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *          public int getRowCount() { return 10;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *          public Object getValueAt(int row, int col) { return new Integer(row*col); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *      };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *      JTable table = new JTable(dataModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *      JScrollPane scrollpane = new JScrollPane(table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * {@code JTable}s are typically placed inside of a {@code JScrollPane}.  By
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * default, a {@code JTable} will adjust its width such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * a horizontal scrollbar is unnecessary.  To allow for a horizontal scrollbar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * invoke {@link #setAutoResizeMode} with {@code AUTO_RESIZE_OFF}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * Note that if you wish to use a <code>JTable</code> in a standalone
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * view (outside of a <code>JScrollPane</code>) and want the header
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * displayed, you can get it using {@link #getTableHeader} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * display it separately.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * To enable sorting and filtering of rows, use a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * {@code RowSorter}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * You can set up a row sorter in either of two ways:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *   <li>Directly set the {@code RowSorter}. For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *        {@code table.setRowSorter(new TableRowSorter(model))}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *   <li>Set the {@code autoCreateRowSorter}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *       property to {@code true}, so that the {@code JTable}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *       creates a {@code RowSorter} for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *       you. For example: {@code setAutoCreateRowSorter(true)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * When designing applications that use the <code>JTable</code> it is worth paying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * close attention to the data structures that will represent the table's data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * The <code>DefaultTableModel</code> is a model implementation that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * uses a <code>Vector</code> of <code>Vector</code>s of <code>Object</code>s to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * store the cell values. As well as copying the data from an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * application into the <code>DefaultTableModel</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * it is also possible to wrap the data in the methods of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * <code>TableModel</code> interface so that the data can be passed to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * <code>JTable</code> directly, as in the example above. This often results
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * in more efficient applications because the model is free to choose the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * internal representation that best suits the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * A good rule of thumb for deciding whether to use the <code>AbstractTableModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * or the <code>DefaultTableModel</code> is to use the <code>AbstractTableModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * as the base class for creating subclasses and the <code>DefaultTableModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * when subclassing is not required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * The "TableExample" directory in the demo area of the source distribution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * gives a number of complete examples of <code>JTable</code> usage,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * covering how the <code>JTable</code> can be used to provide an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * editable view of data taken from a database and how to modify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * the columns in the display to use specialized renderers and editors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * The <code>JTable</code> uses integers exclusively to refer to both the rows and the columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * of the model that it displays. The <code>JTable</code> simply takes a tabular range of cells
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * and uses <code>getValueAt(int, int)</code> to retrieve the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * values from the model during painting.  It is important to remember that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * the column and row indexes returned by various <code>JTable</code> methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * are in terms of the <code>JTable</code> (the view) and are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * necessarily the same indexes used by the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * By default, columns may be rearranged in the <code>JTable</code> so that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * view's columns appear in a different order to the columns in the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * This does not affect the implementation of the model at all: when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * columns are reordered, the <code>JTable</code> maintains the new order of the columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * internally and converts its column indices before querying the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * So, when writing a <code>TableModel</code>, it is not necessary to listen for column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * reordering events as the model will be queried in its own coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * system regardless of what is happening in the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * In the examples area there is a demonstration of a sorting algorithm making
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * use of exactly this technique to interpose yet another coordinate system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * where the order of the rows is changed, rather than the order of the columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * Similarly when using the sorting and filtering functionality
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * provided by <code>RowSorter</code> the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * <code>TableModel</code> does not need to know how to do sorting,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * rather <code>RowSorter</code> will handle it.  Coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * conversions will be necessary when using the row based methods of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * <code>JTable</code> with the underlying <code>TableModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * All of <code>JTable</code>s row based methods are in terms of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * <code>RowSorter</code>, which is not necessarily the same as that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * of the underlying <code>TableModel</code>.  For example, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * selection is always in terms of <code>JTable</code> so that when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * using <code>RowSorter</code> you will need to convert using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * <code>convertRowIndexToView</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * <code>convertRowIndexToModel</code>.  The following shows how to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * convert coordinates from <code>JTable</code> to that of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * underlying model:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 *   int[] selection = table.getSelectedRows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 *   for (int i = 0; i &lt; selection.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 *     selection[i] = table.convertRowIndexToModel(selection[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 *   // selection is now in terms of the underlying TableModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * By default if sorting is enabled <code>JTable</code> will persist the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * selection and variable row heights in terms of the model on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * sorting.  For example if row 0, in terms of the underlying model,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * is currently selected, after the sort row 0, in terms of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * underlying model will be selected.  Visually the selection may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * change, but in terms of the underlying model it will remain the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * same.  The one exception to that is if the model index is no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * visible or was removed.  For example, if row 0 in terms of model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * was filtered out the selection will be empty after the sort.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * J2SE 5 adds methods to <code>JTable</code> to provide convenient access to some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * common printing needs. Simple new {@link #print()} methods allow for quick
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * and easy addition of printing support to your application. In addition, a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * {@link #getPrintable} method is available for more advanced printing needs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * As for all <code>JComponent</code> classes, you can use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * {@link InputMap} and {@link ActionMap} to associate an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * {@link Action} object with a {@link KeyStroke} and execute the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * action under specified conditions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 *   attribute: isContainer false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 * description: A component which displays data in a two dimensional grid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 * @author Philip Milne
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 * @author Shannon Hickey (printing support)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 * @see javax.swing.table.DefaultTableModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 * @see javax.swing.table.TableRowSorter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
/* The first versions of the JTable, contained in Swing-0.1 through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 * Swing-0.4, were written by Alan Chung.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
public class JTable extends JComponent implements TableModelListener, Scrollable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    TableColumnModelListener, ListSelectionListener, CellEditorListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    Accessible, RowSorterListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
// Static Constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    private static final String uiClassID = "TableUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /** Do not adjust column widths automatically; use a horizontal scrollbar instead. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public static final int     AUTO_RESIZE_OFF = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /** When a column is adjusted in the UI, adjust the next column the opposite way. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public static final int     AUTO_RESIZE_NEXT_COLUMN = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /** During UI adjustment, change subsequent columns to preserve the total width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
      * this is the default behavior. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public static final int     AUTO_RESIZE_SUBSEQUENT_COLUMNS = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /** During all resize operations, apply adjustments to the last column only. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public static final int     AUTO_RESIZE_LAST_COLUMN = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /** During all resize operations, proportionately resize all columns. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public static final int     AUTO_RESIZE_ALL_COLUMNS = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Printing modes, used in printing <code>JTable</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @see #print(JTable.PrintMode, MessageFormat, MessageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *             boolean, PrintRequestAttributeSet, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @see #getPrintable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public enum PrintMode {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
         * Printing mode that prints the table at its current size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
         * spreading both columns and rows across multiple pages if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        NORMAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
         * Printing mode that scales the output smaller, if necessary,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
         * to fit the table's entire width (and thereby all columns) on each page;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
         * Rows are spread across multiple pages as necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        FIT_WIDTH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
// Instance Variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /** The <code>TableModel</code> of the table. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    protected TableModel        dataModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    /** The <code>TableColumnModel</code> of the table. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    protected TableColumnModel  columnModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /** The <code>ListSelectionModel</code> of the table, used to keep track of row selections. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    protected ListSelectionModel selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /** The <code>TableHeader</code> working with the table. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    protected JTableHeader      tableHeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    /** The height in pixels of each row in the table. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    protected int               rowHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /** The height in pixels of the margin between the cells in each row. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    protected int               rowMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    /** The color of the grid. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    protected Color             gridColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /** The table draws horizontal lines between cells if <code>showHorizontalLines</code> is true. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    protected boolean           showHorizontalLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    /** The table draws vertical lines between cells if <code>showVerticalLines</code> is true. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    protected boolean           showVerticalLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *  Determines if the table automatically resizes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *  width of the table's columns to take up the entire width of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *  table, and how it does the resizing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    protected int               autoResizeMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     *  The table will query the <code>TableModel</code> to build the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *  set of columns if this is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    protected boolean           autoCreateColumnsFromModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    /** Used by the <code>Scrollable</code> interface to determine the initial visible area. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    protected Dimension         preferredViewportSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /** True if row selection is allowed in this table. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    protected boolean           rowSelectionAllowed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * Obsolete as of Java 2 platform v1.3.  Please use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * <code>rowSelectionAllowed</code> property and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * <code>columnSelectionAllowed</code> property of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * <code>columnModel</code> instead. Or use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * method <code>getCellSelectionEnabled</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * If true, both a row selection and a column selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * can be non-empty at the same time, the selected cells are the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * the cells whose row and column are both selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    protected boolean           cellSelectionEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    /** If editing, the <code>Component</code> that is handling the editing. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    transient protected Component       editorComp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * The active cell editor object, that overwrites the screen real estate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * occupied by the current cell and allows the user to change its contents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * {@code null} if the table isn't currently editing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    transient protected TableCellEditor cellEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    /** Identifies the column of the cell being edited. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    transient protected int             editingColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    /** Identifies the row of the cell being edited. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    transient protected int             editingRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * A table of objects that display the contents of a cell,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * indexed by class as declared in <code>getColumnClass</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * in the <code>TableModel</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    transient protected Hashtable defaultRenderersByColumnClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * A table of objects that display and edit the contents of a cell,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * indexed by class as declared in <code>getColumnClass</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * in the <code>TableModel</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    transient protected Hashtable defaultEditorsByColumnClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    /** The foreground color of selected cells. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    protected Color selectionForeground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    /** The background color of selected cells. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    protected Color selectionBackground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
// Private state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    // WARNING: If you directly access this field you should also change the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    // SortManager.modelRowSizes field as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    private SizeSequence rowModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    private boolean dragEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    private boolean surrendersFocusOnKeystroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    private PropertyChangeListener editorRemover = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * The last value of getValueIsAdjusting from the column selection models
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * columnSelectionChanged notification. Used to test if a repaint is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    private boolean columnSelectionAdjusting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * The last value of getValueIsAdjusting from the row selection models
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * valueChanged notification. Used to test if a repaint is needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    private boolean rowSelectionAdjusting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * To communicate errors between threads during printing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    private Throwable printError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * True when setRowHeight(int) has been invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    private boolean isRowHeightSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * If true, on a sort the selection is reset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    private boolean updateSelectionOnSort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * Information used in sorting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    private transient SortManager sortManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * If true, when sorterChanged is invoked it's value is ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    private boolean ignoreSortChange;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * Whether or not sorterChanged has been invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    private boolean sorterChanged;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * If true, any time the model changes a new RowSorter is set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    private boolean autoCreateRowSorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * Whether or not the table always fills the viewport height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @see #setFillsViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @see #getScrollableTracksViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    private boolean fillsViewportHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * The drop mode for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    private DropMode dropMode = DropMode.USE_SELECTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * The drop location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    private transient DropLocation dropLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * A subclass of <code>TransferHandler.DropLocation</code> representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * a drop location for a <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @see #getDropLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    public static final class DropLocation extends TransferHandler.DropLocation {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        private final int row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        private final int col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        private final boolean isInsertRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        private final boolean isInsertCol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        private DropLocation(Point p, int row, int col,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                             boolean isInsertRow, boolean isInsertCol) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            super(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            this.row = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            this.col = col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            this.isInsertRow = isInsertRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            this.isInsertCol = isInsertCol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
         * Returns the row index where a dropped item should be placed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
         * table. Interpretation of the value depends on the return of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
         * <code>isInsertRow()</code>. If that method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
         * <code>true</code> this value indicates the index where a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
         * row should be inserted. Otherwise, it represents the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
         * of an existing row on which the data was dropped. This index is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
         * in terms of the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
         * <code>-1</code> indicates that the drop occurred over empty space,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
         * and no row could be calculated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
         * @return the drop row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        public int getRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            return row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
         * Returns the column index where a dropped item should be placed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
         * table. Interpretation of the value depends on the return of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
         * <code>isInsertColumn()</code>. If that method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
         * <code>true</code> this value indicates the index where a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
         * column should be inserted. Otherwise, it represents the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
         * of an existing column on which the data was dropped. This index is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
         * in terms of the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
         * <code>-1</code> indicates that the drop occurred over empty space,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
         * and no column could be calculated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
         * @return the drop row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        public int getColumn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            return col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
         * Returns whether or not this location represents an insert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
         * of a row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
         * @return whether or not this is an insert row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        public boolean isInsertRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            return isInsertRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
         * Returns whether or not this location represents an insert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
         * of a column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
         * @return whether or not this is an insert column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        public boolean isInsertColumn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            return isInsertCol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
         * Returns a string representation of this drop location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
         * This method is intended to be used for debugging purposes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
         * and the content and format of the returned string may vary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
         * between implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
         * @return a string representation of this drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            return getClass().getName()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                   + "[dropPoint=" + getDropPoint() + ","
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                   + "row=" + row + ","
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                   + "column=" + col + ","
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                   + "insertRow=" + isInsertRow + ","
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                   + "insertColumn=" + isInsertCol + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
// Constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * Constructs a default <code>JTable</code> that is initialized with a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * data model, a default column model, and a default selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * @see #createDefaultDataModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * @see #createDefaultColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @see #createDefaultSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    public JTable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        this(null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * Constructs a <code>JTable</code> that is initialized with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * <code>dm</code> as the data model, a default column model,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * and a default selection model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * @param dm        the data model for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * @see #createDefaultColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * @see #createDefaultSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    public JTable(TableModel dm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        this(dm, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * Constructs a <code>JTable</code> that is initialized with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * <code>dm</code> as the data model, <code>cm</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * as the column model, and a default selection model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * @param dm        the data model for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * @param cm        the column model for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * @see #createDefaultSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    public JTable(TableModel dm, TableColumnModel cm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        this(dm, cm, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * Constructs a <code>JTable</code> that is initialized with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * <code>dm</code> as the data model, <code>cm</code> as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * column model, and <code>sm</code> as the selection model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * If any of the parameters are <code>null</code> this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * will initialize the table with the corresponding default model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * The <code>autoCreateColumnsFromModel</code> flag is set to false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * if <code>cm</code> is non-null, otherwise it is set to true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * and the column model is populated with suitable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * <code>TableColumns</code> for the columns in <code>dm</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * @param dm        the data model for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * @param cm        the column model for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * @param sm        the row selection model for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * @see #createDefaultDataModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * @see #createDefaultColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * @see #createDefaultSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    public JTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        setLayout(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                           JComponent.getManagingFocusForwardTraversalKeys());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                           JComponent.getManagingFocusBackwardTraversalKeys());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        if (cm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            cm = createDefaultColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            autoCreateColumnsFromModel = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        setColumnModel(cm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        if (sm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            sm = createDefaultSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        setSelectionModel(sm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    // Set the model last, that way if the autoCreatColumnsFromModel has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    // been set above, we will automatically populate an empty columnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    // with suitable columns for the new model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        if (dm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            dm = createDefaultDataModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        setModel(dm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        initializeLocalVars();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * Constructs a <code>JTable</code> with <code>numRows</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * and <code>numColumns</code> of empty cells using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * <code>DefaultTableModel</code>.  The columns will have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * names of the form "A", "B", "C", etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * @param numRows           the number of rows the table holds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * @param numColumns        the number of columns the table holds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * @see javax.swing.table.DefaultTableModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    public JTable(int numRows, int numColumns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        this(new DefaultTableModel(numRows, numColumns));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * Constructs a <code>JTable</code> to display the values in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * <code>Vector</code> of <code>Vectors</code>, <code>rowData</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * with column names, <code>columnNames</code>.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * <code>Vectors</code> contained in <code>rowData</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * should contain the values for that row. In other words,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * the value of the cell at row 1, column 5 can be obtained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * with the following code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * <pre>((Vector)rowData.elementAt(1)).elementAt(5);</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * @param rowData           the data for the new table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * @param columnNames       names of each column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    public JTable(Vector rowData, Vector columnNames) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        this(new DefaultTableModel(rowData, columnNames));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * Constructs a <code>JTable</code> to display the values in the two dimensional array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * <code>rowData</code>, with column names, <code>columnNames</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * <code>rowData</code> is an array of rows, so the value of the cell at row 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * column 5 can be obtained with the following code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * <pre> rowData[1][5]; </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * All rows must be of the same length as <code>columnNames</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * @param rowData           the data for the new table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * @param columnNames       names of each column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    public JTable(final Object[][] rowData, final Object[] columnNames) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        this(new AbstractTableModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            public String getColumnName(int column) { return columnNames[column].toString(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            public int getRowCount() { return rowData.length; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            public int getColumnCount() { return columnNames.length; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            public Object getValueAt(int row, int col) { return rowData[row][col]; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            public boolean isCellEditable(int row, int column) { return true; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            public void setValueAt(Object value, int row, int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                rowData[row][col] = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                fireTableCellUpdated(row, col);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * Calls the <code>configureEnclosingScrollPane</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * @see #configureEnclosingScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        super.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        configureEnclosingScrollPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * If this <code>JTable</code> is the <code>viewportView</code> of an enclosing <code>JScrollPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * (the usual situation), configure this <code>ScrollPane</code> by, amongst other things,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * installing the table's <code>tableHeader</code> as the <code>columnHeaderView</code> of the scroll pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * When a <code>JTable</code> is added to a <code>JScrollPane</code> in the usual way,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * using <code>new JScrollPane(myTable)</code>, <code>addNotify</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * called in the <code>JTable</code> (when the table is added to the viewport).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * <code>JTable</code>'s <code>addNotify</code> method in turn calls this method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * which is protected so that this default installation procedure can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * be overridden by a subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * @see #addNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    protected void configureEnclosingScrollPane() {
3737
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 2658
diff changeset
   722
        JViewport port = SwingUtilities2.getViewport(this);
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 2658
diff changeset
   723
        if (port != null) {
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 2658
diff changeset
   724
            Container gp = port.getParent();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            if (gp instanceof JScrollPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                JScrollPane scrollPane = (JScrollPane)gp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                // Make certain we are the viewPort's view and not, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                // example, the rowHeaderView of the scrollPane -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                // an implementor of fixed columns might do this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                JViewport viewport = scrollPane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                if (viewport == null || viewport.getView() != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                scrollPane.setColumnHeaderView(getTableHeader());
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   735
                // configure the scrollpane for any LAF dependent settings
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   736
                configureEnclosingScrollPaneUI();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   737
            }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   738
        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   739
    }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   740
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   741
    /**
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   742
     * This is a sub-part of configureEnclosingScrollPane() that configures
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   743
     * anything on the scrollpane that may change when the look and feel
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   744
     * changes. It needed to be split out from configureEnclosingScrollPane() so
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   745
     * that it can be called from updateUI() when the LAF changes without
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   746
     * causing the regression found in bug 6687962. This was because updateUI()
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   747
     * is called from the constructor which then caused
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   748
     * configureEnclosingScrollPane() to be called by the constructor which
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   749
     * changes its contract for any subclass that overrides it. So by splitting
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   750
     * it out in this way configureEnclosingScrollPaneUI() can be called both
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   751
     * from configureEnclosingScrollPane() and updateUI() in a safe manor.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   752
     */
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   753
    private void configureEnclosingScrollPaneUI() {
3737
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 2658
diff changeset
   754
        JViewport port = SwingUtilities2.getViewport(this);
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 2658
diff changeset
   755
        if (port != null) {
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 2658
diff changeset
   756
            Container gp = port.getParent();
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   757
            if (gp instanceof JScrollPane) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   758
                JScrollPane scrollPane = (JScrollPane)gp;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   759
                // Make certain we are the viewPort's view and not, for
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   760
                // example, the rowHeaderView of the scrollPane -
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   761
                // an implementor of fixed columns might do this.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   762
                JViewport viewport = scrollPane.getViewport();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   763
                if (viewport == null || viewport.getView() != this) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   764
                    return;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   765
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                //  scrollPane.getViewport().setBackingStoreEnabled(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                Border border = scrollPane.getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                if (border == null || border instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                    Border scrollPaneBorder =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                        UIManager.getBorder("Table.scrollPaneBorder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                    if (scrollPaneBorder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                        scrollPane.setBorder(scrollPaneBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                }
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   775
                // add JScrollBar corner component if available from LAF and not already set by the user
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   776
                Component corner =
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   777
                        scrollPane.getCorner(JScrollPane.UPPER_TRAILING_CORNER);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   778
                if (corner == null || corner instanceof UIResource){
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   779
                    corner = null;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   780
                    Object componentClass = UIManager.get(
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   781
                            "Table.scrollPaneCornerComponent");
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   782
                    if (componentClass instanceof Class){
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   783
                        try {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   784
                            corner = (Component)
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   785
                                    ((Class)componentClass).newInstance();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   786
                        } catch (Exception e) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   787
                            // just ignore and don't set corner
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   788
                        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   789
                    }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   790
                    scrollPane.setCorner(JScrollPane.UPPER_TRAILING_CORNER,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   791
                            corner);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   792
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            }
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
     * Calls the <code>unconfigureEnclosingScrollPane</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * @see #unconfigureEnclosingScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    public void removeNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            removePropertyChangeListener("permanentFocusOwner", editorRemover);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        editorRemover = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        unconfigureEnclosingScrollPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        super.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * Reverses the effect of <code>configureEnclosingScrollPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * by replacing the <code>columnHeaderView</code> of the enclosing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * scroll pane with <code>null</code>. <code>JTable</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * <code>removeNotify</code> method calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * this method, which is protected so that this default uninstallation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * procedure can be overridden by a subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * @see #removeNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * @see #configureEnclosingScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    protected void unconfigureEnclosingScrollPane() {
3737
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 2658
diff changeset
   823
        JViewport port = SwingUtilities2.getViewport(this);
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 2658
diff changeset
   824
        if (port != null) {
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 2658
diff changeset
   825
            Container gp = port.getParent();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            if (gp instanceof JScrollPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                JScrollPane scrollPane = (JScrollPane)gp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                // Make certain we are the viewPort's view and not, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                // example, the rowHeaderView of the scrollPane -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                // an implementor of fixed columns might do this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                JViewport viewport = scrollPane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                if (viewport == null || viewport.getView() != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                scrollPane.setColumnHeaderView(null);
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   836
                // remove ScrollPane corner if one was added by the LAF
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   837
                Component corner =
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   838
                        scrollPane.getCorner(JScrollPane.UPPER_TRAILING_CORNER);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   839
                if (corner instanceof UIResource){
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   840
                    scrollPane.setCorner(JScrollPane.UPPER_TRAILING_CORNER,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   841
                            null);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   842
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    void setUIProperty(String propertyName, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        if (propertyName == "rowHeight") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            if (!isRowHeightSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                setRowHeight(((Number)value).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                isRowHeightSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        super.setUIProperty(propertyName, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
// Static Methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * Equivalent to <code>new JScrollPane(aTable)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * @deprecated As of Swing version 1.0.2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * replaced by <code>new JScrollPane(aTable)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    static public JScrollPane createScrollPaneForTable(JTable aTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        return new JScrollPane(aTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
// Table Attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * Sets the <code>tableHeader</code> working with this <code>JTable</code> to <code>newHeader</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * It is legal to have a <code>null</code> <code>tableHeader</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * @param   tableHeader                       new tableHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * @see     #getTableHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     *  description: The JTableHeader instance which renders the column headers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    public void setTableHeader(JTableHeader tableHeader) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        if (this.tableHeader != tableHeader) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            JTableHeader old = this.tableHeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            // Release the old header
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            if (old != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                old.setTable(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            this.tableHeader = tableHeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            if (tableHeader != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                tableHeader.setTable(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            firePropertyChange("tableHeader", old, tableHeader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * Returns the <code>tableHeader</code> used by this <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * @return  the <code>tableHeader</code> used by this table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * @see     #setTableHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    public JTableHeader getTableHeader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        return tableHeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * Sets the height, in pixels, of all cells to <code>rowHeight</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * revalidates, and repaints.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * The height of the cells will be equal to the row height minus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     * the row margin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * @param   rowHeight                       new row height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * @exception IllegalArgumentException      if <code>rowHeight</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     *                                          less than 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * @see     #getRowHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     *  description: The height of the specified row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    public void setRowHeight(int rowHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        if (rowHeight <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            throw new IllegalArgumentException("New row height less than 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        int old = this.rowHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        this.rowHeight = rowHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        rowModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        if (sortManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            sortManager.modelRowSizes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        isRowHeightSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        firePropertyChange("rowHeight", old, rowHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * Returns the height of a table row, in pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     * The default row height is 16.0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     * @return  the height in pixels of a table row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * @see     #setRowHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    public int getRowHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        return rowHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    private SizeSequence getRowModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        if (rowModel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            rowModel = new SizeSequence(getRowCount(), getRowHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        return rowModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * Sets the height for <code>row</code> to <code>rowHeight</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * revalidates, and repaints. The height of the cells in this row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     * will be equal to the row height minus the row margin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     * @param   row                             the row whose height is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                                                changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     * @param   rowHeight                       new row height, in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     * @exception IllegalArgumentException      if <code>rowHeight</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     *                                          less than 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     *  description: The height in pixels of the cells in <code>row</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    public void setRowHeight(int row, int rowHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        if (rowHeight <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
            throw new IllegalArgumentException("New row height less than 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        getRowModel().setSize(row, rowHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        if (sortManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            sortManager.setViewRowHeight(row, rowHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * Returns the height, in pixels, of the cells in <code>row</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * @param   row              the row whose height is to be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * @return the height, in pixels, of the cells in the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    public int getRowHeight(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        return (rowModel == null) ? getRowHeight() : rowModel.getSize(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * Sets the amount of empty space between cells in adjacent rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * @param  rowMargin  the number of pixels between cells in a row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * @see     #getRowMargin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     *  description: The amount of space between cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    public void setRowMargin(int rowMargin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        int old = this.rowMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        this.rowMargin = rowMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        firePropertyChange("rowMargin", old, rowMargin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * Gets the amount of empty space, in pixels, between cells. Equivalent to:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * <code>getIntercellSpacing().height</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * @return the number of pixels between cells in a row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * @see     #setRowMargin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    public int getRowMargin() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
        return rowMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     * Sets the <code>rowMargin</code> and the <code>columnMargin</code> --
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * the height and width of the space between cells -- to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * <code>intercellSpacing</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * @param   intercellSpacing        a <code>Dimension</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     *                                  specifying the new width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     *                                  and height between cells
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * @see     #getIntercellSpacing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     *  description: The spacing between the cells,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     *               drawn in the background color of the JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
    public void setIntercellSpacing(Dimension intercellSpacing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        // Set the rowMargin here and columnMargin in the TableColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        setRowMargin(intercellSpacing.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        getColumnModel().setColumnMargin(intercellSpacing.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     * Returns the horizontal and vertical space between cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     * The default spacing is (1, 1), which provides room to draw the grid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * @return  the horizontal and vertical spacing between cells
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     * @see     #setIntercellSpacing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
    public Dimension getIntercellSpacing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        return new Dimension(getColumnModel().getColumnMargin(), rowMargin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     * Sets the color used to draw grid lines to <code>gridColor</code> and redisplays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     * The default color is look and feel dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     * @param   gridColor                       the new color of the grid lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     * @exception IllegalArgumentException      if <code>gridColor</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     * @see     #getGridColor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     *  description: The grid color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    public void setGridColor(Color gridColor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        if (gridColor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            throw new IllegalArgumentException("New color is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        Color old = this.gridColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        this.gridColor = gridColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        firePropertyChange("gridColor", old, gridColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        // Redraw
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * Returns the color used to draw grid lines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * The default color is look and feel dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     * @return  the color used to draw grid lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     * @see     #setGridColor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
    public Color getGridColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        return gridColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     *  Sets whether the table draws grid lines around cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     *  If <code>showGrid</code> is true it does; if it is false it doesn't.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     *  There is no <code>getShowGrid</code> method as this state is held
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     *  in two variables -- <code>showHorizontalLines</code> and <code>showVerticalLines</code> --
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     *  each of which can be queried independently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
     * @param   showGrid                 true if table view should draw grid lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     * @see     #setShowVerticalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     * @see     #setShowHorizontalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     *  description: The color used to draw the grid lines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
    public void setShowGrid(boolean showGrid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        setShowHorizontalLines(showGrid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        setShowVerticalLines(showGrid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        // Redraw
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     *  Sets whether the table draws horizontal lines between cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     *  If <code>showHorizontalLines</code> is true it does; if it is false it doesn't.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     * @param   showHorizontalLines      true if table view should draw horizontal lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     * @see     #getShowHorizontalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     * @see     #setShowGrid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     * @see     #setShowVerticalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     *  description: Whether horizontal lines should be drawn in between the cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    public void setShowHorizontalLines(boolean showHorizontalLines) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        boolean old = this.showHorizontalLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        this.showHorizontalLines = showHorizontalLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        firePropertyChange("showHorizontalLines", old, showHorizontalLines);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        // Redraw
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     *  Sets whether the table draws vertical lines between cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     *  If <code>showVerticalLines</code> is true it does; if it is false it doesn't.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     * @param   showVerticalLines              true if table view should draw vertical lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * @see     #getShowVerticalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * @see     #setShowGrid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * @see     #setShowHorizontalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     *  description: Whether vertical lines should be drawn in between the cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
    public void setShowVerticalLines(boolean showVerticalLines) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        boolean old = this.showVerticalLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        this.showVerticalLines = showVerticalLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        firePropertyChange("showVerticalLines", old, showVerticalLines);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        // Redraw
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     * Returns true if the table draws horizontal lines between cells, false if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     * doesn't. The default is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     * @return  true if the table draws horizontal lines between cells, false if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     *          doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     * @see     #setShowHorizontalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
    public boolean getShowHorizontalLines() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        return showHorizontalLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     * Returns true if the table draws vertical lines between cells, false if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * doesn't. The default is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     * @return  true if the table draws vertical lines between cells, false if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     *          doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     * @see     #setShowVerticalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
    public boolean getShowVerticalLines() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        return showVerticalLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * Sets the table's auto resize mode when the table is resized.  For further
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     * information on how the different resize modes work, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     * {@link #doLayout}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     * @param   mode One of 5 legal values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     *                   AUTO_RESIZE_OFF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     *                   AUTO_RESIZE_NEXT_COLUMN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     *                   AUTO_RESIZE_SUBSEQUENT_COLUMNS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     *                   AUTO_RESIZE_LAST_COLUMN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     *                   AUTO_RESIZE_ALL_COLUMNS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     * @see     #getAutoResizeMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     * @see     #doLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     *  description: Whether the columns should adjust themselves automatically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     *        enum: AUTO_RESIZE_OFF                JTable.AUTO_RESIZE_OFF
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     *              AUTO_RESIZE_NEXT_COLUMN        JTable.AUTO_RESIZE_NEXT_COLUMN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     *              AUTO_RESIZE_SUBSEQUENT_COLUMNS JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     *              AUTO_RESIZE_LAST_COLUMN        JTable.AUTO_RESIZE_LAST_COLUMN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     *              AUTO_RESIZE_ALL_COLUMNS        JTable.AUTO_RESIZE_ALL_COLUMNS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
    public void setAutoResizeMode(int mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        if ((mode == AUTO_RESIZE_OFF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
            (mode == AUTO_RESIZE_NEXT_COLUMN) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            (mode == AUTO_RESIZE_SUBSEQUENT_COLUMNS) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            (mode == AUTO_RESIZE_LAST_COLUMN) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
            (mode == AUTO_RESIZE_ALL_COLUMNS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            int old = autoResizeMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
            autoResizeMode = mode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            if (tableHeader != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                tableHeader.resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            firePropertyChange("autoResizeMode", old, autoResizeMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     * Returns the auto resize mode of the table.  The default mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     * is AUTO_RESIZE_SUBSEQUENT_COLUMNS.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
     * @return  the autoResizeMode of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
     * @see     #setAutoResizeMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
     * @see     #doLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
    public int getAutoResizeMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        return autoResizeMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     * Sets this table's <code>autoCreateColumnsFromModel</code> flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     * This method calls <code>createDefaultColumnsFromModel</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     * <code>autoCreateColumnsFromModel</code> changes from false to true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * @param   autoCreateColumnsFromModel   true if <code>JTable</code> should automatically create columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     * @see     #getAutoCreateColumnsFromModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * @see     #createDefaultColumnsFromModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     *  description: Automatically populates the columnModel when a new TableModel is submitted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
    public void setAutoCreateColumnsFromModel(boolean autoCreateColumnsFromModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        if (this.autoCreateColumnsFromModel != autoCreateColumnsFromModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
            boolean old = this.autoCreateColumnsFromModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
            this.autoCreateColumnsFromModel = autoCreateColumnsFromModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
            if (autoCreateColumnsFromModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                createDefaultColumnsFromModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
            firePropertyChange("autoCreateColumnsFromModel", old, autoCreateColumnsFromModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
     * Determines whether the table will create default columns from the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
     * If true, <code>setModel</code> will clear any existing columns and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
     * create new columns from the new model.  Also, if the event in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
     * the <code>tableChanged</code> notification specifies that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
     * entire table changed, then the columns will be rebuilt.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
     * The default is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     * @return  the autoCreateColumnsFromModel of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     * @see     #setAutoCreateColumnsFromModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     * @see     #createDefaultColumnsFromModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    public boolean getAutoCreateColumnsFromModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
        return autoCreateColumnsFromModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     * Creates default columns for the table from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * the data model using the <code>getColumnCount</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     * defined in the <code>TableModel</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     * Clears any existing columns before creating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     * new columns based on information from the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     * @see     #getAutoCreateColumnsFromModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    public void createDefaultColumnsFromModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        TableModel m = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        if (m != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
            // Remove any current columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
            TableColumnModel cm = getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            while (cm.getColumnCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                cm.removeColumn(cm.getColumn(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
            // Create new columns from the data model info
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
            for (int i = 0; i < m.getColumnCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                TableColumn newColumn = new TableColumn(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
                addColumn(newColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
     * Sets a default cell renderer to be used if no renderer has been set in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
     * a <code>TableColumn</code>. If renderer is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
     * removes the default renderer for this column class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
     * @param  columnClass     set the default cell renderer for this columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     * @param  renderer        default cell renderer to be used for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     *                         columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * @see     #getDefaultRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     * @see     #setDefaultEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
    public void setDefaultRenderer(Class<?> columnClass, TableCellRenderer renderer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
        if (renderer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
            defaultRenderersByColumnClass.put(columnClass, renderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            defaultRenderersByColumnClass.remove(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
     * Returns the cell renderer to be used when no renderer has been set in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
     * a <code>TableColumn</code>. During the rendering of cells the renderer is fetched from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
     * a <code>Hashtable</code> of entries according to the class of the cells in the column. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
     * there is no entry for this <code>columnClass</code> the method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
     * the entry for the most specific superclass. The <code>JTable</code> installs entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
     * for <code>Object</code>, <code>Number</code>, and <code>Boolean</code>, all of which can be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
     * or replaced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
     * @param   columnClass   return the default cell renderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
     *                        for this columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
     * @return  the renderer for this columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     * @see     #setDefaultRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
     * @see     #getColumnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
    public TableCellRenderer getDefaultRenderer(Class<?> columnClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        if (columnClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
            Object renderer = defaultRenderersByColumnClass.get(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
            if (renderer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
                return (TableCellRenderer)renderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                return getDefaultRenderer(columnClass.getSuperclass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
            }
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
     * Sets a default cell editor to be used if no editor has been set in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
     * a <code>TableColumn</code>. If no editing is required in a table, or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
     * particular column in a table, uses the <code>isCellEditable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
     * method in the <code>TableModel</code> interface to ensure that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
     * <code>JTable</code> will not start an editor in these columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
     * If editor is <code>null</code>, removes the default editor for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
     * column class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
     * @param  columnClass  set the default cell editor for this columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
     * @param  editor   default cell editor to be used for this columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
     * @see     TableModel#isCellEditable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
     * @see     #getDefaultEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     * @see     #setDefaultRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    public void setDefaultEditor(Class<?> columnClass, TableCellEditor editor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
        if (editor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
            defaultEditorsByColumnClass.put(columnClass, editor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
            defaultEditorsByColumnClass.remove(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
     * Returns the editor to be used when no editor has been set in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
     * a <code>TableColumn</code>. During the editing of cells the editor is fetched from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
     * a <code>Hashtable</code> of entries according to the class of the cells in the column. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
     * there is no entry for this <code>columnClass</code> the method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
     * the entry for the most specific superclass. The <code>JTable</code> installs entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
     * for <code>Object</code>, <code>Number</code>, and <code>Boolean</code>, all of which can be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
     * or replaced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
     * @param   columnClass  return the default cell editor for this columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
     * @return the default cell editor to be used for this columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
     * @see     #setDefaultEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
     * @see     #getColumnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
    public TableCellEditor getDefaultEditor(Class<?> columnClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        if (columnClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
            Object editor = defaultEditorsByColumnClass.get(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
            if (editor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
                return (TableCellEditor)editor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
                return getDefaultEditor(columnClass.getSuperclass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
     * Turns on or off automatic drag handling. In order to enable automatic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
     * drag handling, this property should be set to {@code true}, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
     * table's {@code TransferHandler} needs to be {@code non-null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
     * The default value of the {@code dragEnabled} property is {@code false}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
     * The job of honoring this property, and recognizing a user drag gesture,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
     * lies with the look and feel implementation, and in particular, the table's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
     * {@code TableUI}. When automatic drag handling is enabled, most look and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     * feels (including those that subclass {@code BasicLookAndFeel}) begin a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     * drag and drop operation whenever the user presses the mouse button over
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     * an item (in single selection mode) or a selection (in other selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     * modes) and then moves the mouse a few pixels. Setting this property to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     * {@code true} can therefore have a subtle effect on how selections behave.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     * If a look and feel is used that ignores this property, you can still
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     * begin a drag and drop operation by calling {@code exportAsDrag} on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     * table's {@code TransferHandler}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     * @param b whether or not to enable automatic drag handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
     *            <code>b</code> is <code>true</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     *            <code>GraphicsEnvironment.isHeadless()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
     *            returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
     * @see #getDragEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     * @see #setTransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     * @see TransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     *  description: determines whether automatic drag handling is enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
     *        bound: false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
    public void setDragEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        if (b && GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
            throw new HeadlessException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
        dragEnabled = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
     * Returns whether or not automatic drag handling is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
     * @return the value of the {@code dragEnabled} property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
     * @see #setDragEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
    public boolean getDragEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
        return dragEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
     * Sets the drop mode for this component. For backward compatibility,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
     * the default for this property is <code>DropMode.USE_SELECTION</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
     * Usage of one of the other modes is recommended, however, for an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
     * improved user experience. <code>DropMode.ON</code>, for instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
     * offers similar behavior of showing items as selected, but does so without
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
     * affecting the actual selection in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
     * <code>JTable</code> supports the following drop modes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
     *    <li><code>DropMode.USE_SELECTION</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
     *    <li><code>DropMode.ON</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
     *    <li><code>DropMode.INSERT</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
     *    <li><code>DropMode.INSERT_ROWS</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
     *    <li><code>DropMode.INSERT_COLS</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
     *    <li><code>DropMode.ON_OR_INSERT</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
     *    <li><code>DropMode.ON_OR_INSERT_ROWS</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
     *    <li><code>DropMode.ON_OR_INSERT_COLS</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
     * The drop mode is only meaningful if this component has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
     * <code>TransferHandler</code> that accepts drops.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
     * @param dropMode the drop mode to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
     * @throws IllegalArgumentException if the drop mode is unsupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
     *         or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
     * @see #getDropMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
     * @see #getDropLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     * @see #setTransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
     * @see TransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
    public final void setDropMode(DropMode dropMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
        if (dropMode != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
            switch (dropMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
                case USE_SELECTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
                case ON:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
                case INSERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
                case INSERT_ROWS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
                case INSERT_COLS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
                case ON_OR_INSERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                case ON_OR_INSERT_ROWS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
                case ON_OR_INSERT_COLS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
                    this.dropMode = dropMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
        throw new IllegalArgumentException(dropMode + ": Unsupported drop mode for table");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
     * Returns the drop mode for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
     * @return the drop mode for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
     * @see #setDropMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
    public final DropMode getDropMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
        return dropMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
     * Calculates a drop location in this component, representing where a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
     * drop at the given point should insert data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
     * @param p the point to calculate a drop location for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
     * @return the drop location, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
    DropLocation dropLocationForPoint(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
        DropLocation location = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
        int row = rowAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
        int col = columnAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
        boolean outside = Boolean.TRUE == getClientProperty("Table.isFileList")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
                          && SwingUtilities2.pointOutsidePrefSize(this, row, col, p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
        Rectangle rect = getCellRect(row, col, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
        Section xSection, ySection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
        boolean between = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
        boolean ltr = getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
        switch(dropMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
            case USE_SELECTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
            case ON:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
                if (row == -1 || col == -1 || outside) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
                    location = new DropLocation(p, -1, -1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
                    location = new DropLocation(p, row, col, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
            case INSERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
                if (row == -1 && col == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
                    location = new DropLocation(p, 0, 0, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
                xSection = SwingUtilities2.liesInHorizontal(rect, p, ltr, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
                if (row == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
                    if (xSection == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
                        location = new DropLocation(p, getRowCount(), col, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
                    } else if (xSection == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
                        location = new DropLocation(p, getRowCount(), col + 1, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
                        location = new DropLocation(p, getRowCount(), col, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
                } else if (xSection == LEADING || xSection == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                    ySection = SwingUtilities2.liesInVertical(rect, p, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                    if (ySection == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
                        between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                    } else if (ySection == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                        row++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                        between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
                    location = new DropLocation(p, row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
                                                xSection == TRAILING ? col + 1 : col,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                                                between, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                    if (SwingUtilities2.liesInVertical(rect, p, false) == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
                        row++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                    location = new DropLocation(p, row, col, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
            case INSERT_ROWS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
                if (row == -1 && col == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
                    location = new DropLocation(p, -1, -1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
                if (row == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
                    location = new DropLocation(p, getRowCount(), col, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                if (SwingUtilities2.liesInVertical(rect, p, false) == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
                    row++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
                location = new DropLocation(p, row, col, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
            case ON_OR_INSERT_ROWS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
                if (row == -1 && col == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
                    location = new DropLocation(p, -1, -1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
                if (row == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
                    location = new DropLocation(p, getRowCount(), col, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                ySection = SwingUtilities2.liesInVertical(rect, p, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
                if (ySection == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
                    between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
                } else if (ySection == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
                    row++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
                    between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
                location = new DropLocation(p, row, col, between, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
            case INSERT_COLS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
                if (row == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
                    location = new DropLocation(p, -1, -1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
                if (col == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
                    location = new DropLocation(p, getColumnCount(), col, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
                if (SwingUtilities2.liesInHorizontal(rect, p, ltr, false) == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
                    col++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
                location = new DropLocation(p, row, col, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
            case ON_OR_INSERT_COLS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
                if (row == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
                    location = new DropLocation(p, -1, -1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
                if (col == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
                    location = new DropLocation(p, row, getColumnCount(), false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
                xSection = SwingUtilities2.liesInHorizontal(rect, p, ltr, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
                if (xSection == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
                    between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
                } else if (xSection == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
                    col++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
                    between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
                location = new DropLocation(p, row, col, false, between);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
            case ON_OR_INSERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
                if (row == -1 && col == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
                    location = new DropLocation(p, 0, 0, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
                xSection = SwingUtilities2.liesInHorizontal(rect, p, ltr, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
                if (row == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
                    if (xSection == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
                        location = new DropLocation(p, getRowCount(), col, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
                    } else if (xSection == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
                        location = new DropLocation(p, getRowCount(), col + 1, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
                        location = new DropLocation(p, getRowCount(), col, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
                ySection = SwingUtilities2.liesInVertical(rect, p, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
                if (ySection == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
                    between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
                } else if (ySection == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
                    row++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                    between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
                location = new DropLocation(p, row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
                                            xSection == TRAILING ? col + 1 : col,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                                            between,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                                            xSection != MIDDLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
                assert false : "Unexpected drop mode";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
        return location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
     * Called to set or clear the drop location during a DnD operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
     * In some cases, the component may need to use it's internal selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
     * temporarily to indicate the drop location. To help facilitate this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
     * this method returns and accepts as a parameter a state object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
     * This state object can be used to store, and later restore, the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
     * state. Whatever this method returns will be passed back to it in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
     * future calls, as the state parameter. If it wants the DnD system to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
     * continue storing the same state, it must pass it back every time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
     * Here's how this is used:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
     * Let's say that on the first call to this method the component decides
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
     * to save some state (because it is about to use the selection to show
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
     * a drop index). It can return a state object to the caller encapsulating
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
     * any saved selection state. On a second call, let's say the drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
     * is being changed to something else. The component doesn't need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
     * restore anything yet, so it simply passes back the same state object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
     * to have the DnD system continue storing it. Finally, let's say this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
     * method is messaged with <code>null</code>. This means DnD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
     * is finished with this component for now, meaning it should restore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
     * state. At this point, it can use the state parameter to restore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
     * said state, and of course return <code>null</code> since there's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
     * no longer anything to store.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
     * @param location the drop location (as calculated by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
     *        <code>dropLocationForPoint</code>) or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
     *        if there's no longer a valid drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
     * @param state the state object saved earlier for this component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
     *        or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
     * @param forDrop whether or not the method is being called because an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
     *        actual drop occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
     * @return any saved state for this component, or <code>null</code> if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
    Object setDropLocation(TransferHandler.DropLocation location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
                           Object state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
                           boolean forDrop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
        Object retVal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
        DropLocation tableLocation = (DropLocation)location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
        if (dropMode == DropMode.USE_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
            if (tableLocation == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
                if (!forDrop && state != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
                    clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1737
                    int[] rows = ((int[][])state)[0];
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1738
                    int[] cols = ((int[][])state)[1];
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1739
                    int[] anchleads = ((int[][])state)[2];
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1740
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1741
                    for (int row : rows) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1742
                        addRowSelectionInterval(row, row);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1745
                    for (int col : cols) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1746
                        addColumnSelectionInterval(col, col);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
                    SwingUtilities2.setLeadAnchorWithoutSelection(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
                            getSelectionModel(), anchleads[1], anchleads[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
                    SwingUtilities2.setLeadAnchorWithoutSelection(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
                            getColumnModel().getSelectionModel(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
                            anchleads[3], anchleads[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
                if (dropLocation == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
                    retVal = new int[][]{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
                        getSelectedRows(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
                        getSelectedColumns(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
                        {getAdjustedIndex(getSelectionModel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
                             .getAnchorSelectionIndex(), true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
                         getAdjustedIndex(getSelectionModel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
                             .getLeadSelectionIndex(), true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
                         getAdjustedIndex(getColumnModel().getSelectionModel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
                             .getAnchorSelectionIndex(), false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
                         getAdjustedIndex(getColumnModel().getSelectionModel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
                             .getLeadSelectionIndex(), false)}};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
                    retVal = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
                if (tableLocation.getRow() == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
                    clearSelectionAndLeadAnchor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
                    setRowSelectionInterval(tableLocation.getRow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
                                            tableLocation.getRow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
                    setColumnSelectionInterval(tableLocation.getColumn(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
                                               tableLocation.getColumn());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
        DropLocation old = dropLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
        dropLocation = tableLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
        firePropertyChange("dropLocation", old, dropLocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
        return retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
     * Returns the location that this component should visually indicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
     * as the drop location during a DnD operation over the component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
     * or {@code null} if no location is to currently be shown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
     * This method is not meant for querying the drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
     * from a {@code TransferHandler}, as the drop location is only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
     * set after the {@code TransferHandler}'s <code>canImport</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
     * has returned and has allowed for the location to be shown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
     * When this property changes, a property change event with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
     * name "dropLocation" is fired by the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
     * @return the drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
     * @see #setDropMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
     * @see TransferHandler#canImport(TransferHandler.TransferSupport)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
    public final DropLocation getDropLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
        return dropLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
     * Specifies whether a {@code RowSorter} should be created for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
     * table whenever its model changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
     * When {@code setAutoCreateRowSorter(true)} is invoked, a {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
     * TableRowSorter} is immediately created and installed on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
     * table.  While the {@code autoCreateRowSorter} property remains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
     * {@code true}, every time the model is changed, a new {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
     * TableRowSorter} is created and set as the table's row sorter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
     * @param autoCreateRowSorter whether or not a {@code RowSorter}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
     *        should be automatically created
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
     * @see javax.swing.table.TableRowSorter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
     *  description: Whether or not to turn on sorting by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
    public void setAutoCreateRowSorter(boolean autoCreateRowSorter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
        boolean oldValue = this.autoCreateRowSorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
        this.autoCreateRowSorter = autoCreateRowSorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
        if (autoCreateRowSorter) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1836
            setRowSorter(new TableRowSorter<TableModel>(getModel()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
        firePropertyChange("autoCreateRowSorter", oldValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
                           autoCreateRowSorter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
     * Returns {@code true} if whenever the model changes, a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
     * {@code RowSorter} should be created and installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
     * as the table's sorter; otherwise, returns {@code false}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
     * @return true if a {@code RowSorter} should be created when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
     *         the model changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
    public boolean getAutoCreateRowSorter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
        return autoCreateRowSorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
     * Specifies whether the selection should be updated after sorting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
     * If true, on sorting the selection is reset such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
     * the same rows, in terms of the model, remain selected.  The default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
     * is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
     * @param update whether or not to update the selection on sorting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
     *       expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
     *  description: Whether or not to update the selection on sorting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
    public void setUpdateSelectionOnSort(boolean update) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
        if (updateSelectionOnSort != update) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
            updateSelectionOnSort = update;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
            firePropertyChange("updateSelectionOnSort", !update, update);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
     * Returns true if the selection should be updated after sorting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
     * @return whether to update the selection on a sort
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
    public boolean getUpdateSelectionOnSort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
        return updateSelectionOnSort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
     * Sets the <code>RowSorter</code>.  <code>RowSorter</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
     * to provide sorting and filtering to a <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
     * This method clears the selection and resets any variable row heights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
     * This method fires a <code>PropertyChangeEvent</code> when appropriate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
     * with the property name <code>"rowSorter"</code>.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
     * backward-compatibility, this method fires an additional event with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
     * property name <code>"sorter"</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
     * If the underlying model of the <code>RowSorter</code> differs from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
     * that of this <code>JTable</code> undefined behavior will result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
     * @param sorter the <code>RowSorter</code>; <code>null</code> turns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
     *        sorting off
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
     * @see javax.swing.table.TableRowSorter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
     *  description: The table's RowSorter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
    public void setRowSorter(RowSorter<? extends TableModel> sorter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
        RowSorter<? extends TableModel> oldRowSorter = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
        if (sortManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
            oldRowSorter = sortManager.sorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
            sortManager.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
            sortManager = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
        rowModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
        clearSelectionAndLeadAnchor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
        if (sorter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
            sortManager = new SortManager(sorter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
        firePropertyChange("rowSorter", oldRowSorter, sorter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
        firePropertyChange("sorter", oldRowSorter, sorter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
     * Returns the object responsible for sorting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
     * @return the object responsible for sorting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
    public RowSorter<? extends TableModel> getRowSorter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
        return (sortManager != null) ? sortManager.sorter : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
// Selection methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
     * Sets the table's selection mode to allow only single selections, a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
     * contiguous interval, or multiple intervals.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
     * <bold>Note:</bold>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
     * <code>JTable</code> provides all the methods for handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
     * column and row selection.  When setting states,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
     * such as <code>setSelectionMode</code>, it not only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
     * updates the mode for the row selection model but also sets similar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
     * values in the selection model of the <code>columnModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
     * If you want to have the row and column selection models operating
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
     * in different modes, set them both directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
     * Both the row and column selection models for <code>JTable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
     * default to using a <code>DefaultListSelectionModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
     * so that <code>JTable</code> works the same way as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
     * <code>JList</code>. See the <code>setSelectionMode</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
     * in <code>JList</code> for details about the modes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
     * @see JList#setSelectionMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
     * description: The selection mode used by the row and column selection models.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
     *        enum: SINGLE_SELECTION            ListSelectionModel.SINGLE_SELECTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
     *              SINGLE_INTERVAL_SELECTION   ListSelectionModel.SINGLE_INTERVAL_SELECTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
     *              MULTIPLE_INTERVAL_SELECTION ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
    public void setSelectionMode(int selectionMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
        clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
        getSelectionModel().setSelectionMode(selectionMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
        getColumnModel().getSelectionModel().setSelectionMode(selectionMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
     * Sets whether the rows in this model can be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
     * @param rowSelectionAllowed   true if this model will allow row selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
     * @see #getRowSelectionAllowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
     *  description: If true, an entire row is selected for each selected cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
    public void setRowSelectionAllowed(boolean rowSelectionAllowed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
        boolean old = this.rowSelectionAllowed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
        this.rowSelectionAllowed = rowSelectionAllowed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
        if (old != rowSelectionAllowed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
        firePropertyChange("rowSelectionAllowed", old, rowSelectionAllowed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
     * Returns true if rows can be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
     * @return true if rows can be selected, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
     * @see #setRowSelectionAllowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
    public boolean getRowSelectionAllowed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
        return rowSelectionAllowed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
     * Sets whether the columns in this model can be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
     * @param columnSelectionAllowed   true if this model will allow column selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
     * @see #getColumnSelectionAllowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
     *  description: If true, an entire column is selected for each selected cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
    public void setColumnSelectionAllowed(boolean columnSelectionAllowed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
        boolean old = columnModel.getColumnSelectionAllowed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
        columnModel.setColumnSelectionAllowed(columnSelectionAllowed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
        if (old != columnSelectionAllowed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
        firePropertyChange("columnSelectionAllowed", old, columnSelectionAllowed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
     * Returns true if columns can be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
     * @return true if columns can be selected, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
     * @see #setColumnSelectionAllowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
    public boolean getColumnSelectionAllowed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
        return columnModel.getColumnSelectionAllowed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
     * Sets whether this table allows both a column selection and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
     * row selection to exist simultaneously. When set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
     * the table treats the intersection of the row and column selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
     * models as the selected cells. Override <code>isCellSelected</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
     * change this default behavior. This method is equivalent to setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
     * both the <code>rowSelectionAllowed</code> property and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
     * <code>columnSelectionAllowed</code> property of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
     * <code>columnModel</code> to the supplied value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
     * @param  cellSelectionEnabled     true if simultaneous row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
     *                                  selection is allowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
     * @see #getCellSelectionEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
     * @see #isCellSelected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
     *  description: Select a rectangular region of cells rather than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
     *               rows or columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
    public void setCellSelectionEnabled(boolean cellSelectionEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
        setRowSelectionAllowed(cellSelectionEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
        setColumnSelectionAllowed(cellSelectionEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
        boolean old = this.cellSelectionEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
        this.cellSelectionEnabled = cellSelectionEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
        firePropertyChange("cellSelectionEnabled", old, cellSelectionEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
     * Returns true if both row and column selection models are enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
     * Equivalent to <code>getRowSelectionAllowed() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
     * getColumnSelectionAllowed()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
     * @return true if both row and column selection models are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
     * @see #setCellSelectionEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
    public boolean getCellSelectionEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
        return getRowSelectionAllowed() && getColumnSelectionAllowed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
     *  Selects all rows, columns, and cells in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
    public void selectAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
        // If I'm currently editing, then I should stop editing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
        if (isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
            removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
        if (getRowCount() > 0 && getColumnCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
            int oldLead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
            int oldAnchor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
            ListSelectionModel selModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
            selModel = selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
            selModel.setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
            oldLead = getAdjustedIndex(selModel.getLeadSelectionIndex(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
            oldAnchor = getAdjustedIndex(selModel.getAnchorSelectionIndex(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
            setRowSelectionInterval(0, getRowCount()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
            // this is done to restore the anchor and lead
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
            SwingUtilities2.setLeadAnchorWithoutSelection(selModel, oldLead, oldAnchor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
            selModel.setValueIsAdjusting(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
            selModel = columnModel.getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
            selModel.setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
            oldLead = getAdjustedIndex(selModel.getLeadSelectionIndex(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
            oldAnchor = getAdjustedIndex(selModel.getAnchorSelectionIndex(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
            setColumnSelectionInterval(0, getColumnCount()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
            // this is done to restore the anchor and lead
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
            SwingUtilities2.setLeadAnchorWithoutSelection(selModel, oldLead, oldAnchor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
            selModel.setValueIsAdjusting(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
     * Deselects all selected columns and rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
    public void clearSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
        selectionModel.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
        columnModel.getSelectionModel().clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
    private void clearSelectionAndLeadAnchor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
        selectionModel.setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
        columnModel.getSelectionModel().setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
        clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
        selectionModel.setAnchorSelectionIndex(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
        selectionModel.setLeadSelectionIndex(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
        columnModel.getSelectionModel().setAnchorSelectionIndex(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
        columnModel.getSelectionModel().setLeadSelectionIndex(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
        selectionModel.setValueIsAdjusting(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
        columnModel.getSelectionModel().setValueIsAdjusting(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
    private int getAdjustedIndex(int index, boolean row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
        int compare = row ? getRowCount() : getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
        return index < compare ? index : -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
    private int boundRow(int row) throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
        if (row < 0 || row >= getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
            throw new IllegalArgumentException("Row index out of range");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
        return row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
    private int boundColumn(int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
        if (col< 0 || col >= getColumnCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
            throw new IllegalArgumentException("Column index out of range");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
        return col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
     * Selects the rows from <code>index0</code> to <code>index1</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
     * inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
     * @exception IllegalArgumentException      if <code>index0</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
     *                                          <code>index1</code> lie outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
     *                                          [0, <code>getRowCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
     * @param   index0 one end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
     * @param   index1 the other end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
    public void setRowSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
        selectionModel.setSelectionInterval(boundRow(index0), boundRow(index1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
     * Selects the columns from <code>index0</code> to <code>index1</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
     * inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
     * @exception IllegalArgumentException      if <code>index0</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
     *                                          <code>index1</code> lie outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
     *                                          [0, <code>getColumnCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
     * @param   index0 one end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
     * @param   index1 the other end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
    public void setColumnSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
        columnModel.getSelectionModel().setSelectionInterval(boundColumn(index0), boundColumn(index1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
     * Adds the rows from <code>index0</code> to <code>index1</code>, inclusive, to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
     * the current selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
     * @exception IllegalArgumentException      if <code>index0</code> or <code>index1</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
     *                                          lie outside [0, <code>getRowCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
     * @param   index0 one end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
     * @param   index1 the other end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
    public void addRowSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
        selectionModel.addSelectionInterval(boundRow(index0), boundRow(index1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
     * Adds the columns from <code>index0</code> to <code>index1</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
     * inclusive, to the current selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
     * @exception IllegalArgumentException      if <code>index0</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
     *                                          <code>index1</code> lie outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
     *                                          [0, <code>getColumnCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
     * @param   index0 one end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
     * @param   index1 the other end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
    public void addColumnSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
        columnModel.getSelectionModel().addSelectionInterval(boundColumn(index0), boundColumn(index1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
     * Deselects the rows from <code>index0</code> to <code>index1</code>, inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
     * @exception IllegalArgumentException      if <code>index0</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
     *                                          <code>index1</code> lie outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
     *                                          [0, <code>getRowCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
     * @param   index0 one end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
     * @param   index1 the other end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
    public void removeRowSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
        selectionModel.removeSelectionInterval(boundRow(index0), boundRow(index1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
     * Deselects the columns from <code>index0</code> to <code>index1</code>, inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
     * @exception IllegalArgumentException      if <code>index0</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
     *                                          <code>index1</code> lie outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
     *                                          [0, <code>getColumnCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
     * @param   index0 one end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
     * @param   index1 the other end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
    public void removeColumnSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
        columnModel.getSelectionModel().removeSelectionInterval(boundColumn(index0), boundColumn(index1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
     * Returns the index of the first selected row, -1 if no row is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
     * @return the index of the first selected row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
    public int getSelectedRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
        return selectionModel.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
     * Returns the index of the first selected column,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
     * -1 if no column is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
     * @return the index of the first selected column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
    public int getSelectedColumn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
        return columnModel.getSelectionModel().getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
     * Returns the indices of all selected rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
     * @return an array of integers containing the indices of all selected rows,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
     *         or an empty array if no row is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
     * @see #getSelectedRow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
    public int[] getSelectedRows() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
        int iMin = selectionModel.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
        int iMax = selectionModel.getMaxSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
        if ((iMin == -1) || (iMax == -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
            return new int[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
        int[] rvTmp = new int[1+ (iMax - iMin)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
        int n = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
        for(int i = iMin; i <= iMax; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
            if (selectionModel.isSelectedIndex(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
                rvTmp[n++] = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
        int[] rv = new int[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
        System.arraycopy(rvTmp, 0, rv, 0, n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
        return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
     * Returns the indices of all selected columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
     * @return an array of integers containing the indices of all selected columns,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
     *         or an empty array if no column is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
     * @see #getSelectedColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
    public int[] getSelectedColumns() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
        return columnModel.getSelectedColumns();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
     * Returns the number of selected rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
     * @return the number of selected rows, 0 if no rows are selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
    public int getSelectedRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
        int iMin = selectionModel.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
        int iMax = selectionModel.getMaxSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
        int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
        for(int i = iMin; i <= iMax; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
            if (selectionModel.isSelectedIndex(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
                count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
        return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
     * Returns the number of selected columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
     * @return the number of selected columns, 0 if no columns are selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
    public int getSelectedColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
        return columnModel.getSelectedColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
     * Returns true if the specified index is in the valid range of rows,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
     * and the row at that index is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
     * @return true if <code>row</code> is a valid index and the row at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
     *              that index is selected (where 0 is the first row)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
    public boolean isRowSelected(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
        return selectionModel.isSelectedIndex(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
     * Returns true if the specified index is in the valid range of columns,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
     * and the column at that index is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
     * @param   column   the column in the column model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
     * @return true if <code>column</code> is a valid index and the column at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
     *              that index is selected (where 0 is the first column)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
    public boolean isColumnSelected(int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
        return columnModel.getSelectionModel().isSelectedIndex(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
     * Returns true if the specified indices are in the valid range of rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
     * and columns and the cell at the specified position is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
     * @param row   the row being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
     * @param column  the column being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
     * @return true if <code>row</code> and <code>column</code> are valid indices
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
     *              and the cell at index <code>(row, column)</code> is selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
     *              where the first row and first column are at index 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
    public boolean isCellSelected(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
        if (!getRowSelectionAllowed() && !getColumnSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
        return (!getRowSelectionAllowed() || isRowSelected(row)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
               (!getColumnSelectionAllowed() || isColumnSelected(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
    private void changeSelectionModel(ListSelectionModel sm, int index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
                                      boolean toggle, boolean extend, boolean selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
                                      int anchor, boolean anchorSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
        if (extend) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
            if (toggle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
                if (anchorSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
                    sm.addSelectionInterval(anchor, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
                    sm.removeSelectionInterval(anchor, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
                    // this is a Windows-only behavior that we want for file lists
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
                    if (Boolean.TRUE == getClientProperty("Table.isFileList")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
                        sm.addSelectionInterval(index, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
                        sm.setAnchorSelectionIndex(anchor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
                sm.setSelectionInterval(anchor, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
            if (toggle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
                if (selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
                    sm.removeSelectionInterval(index, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
                    sm.addSelectionInterval(index, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
                sm.setSelectionInterval(index, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
     * Updates the selection models of the table, depending on the state of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
     * two flags: <code>toggle</code> and <code>extend</code>. Most changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
     * to the selection that are the result of keyboard or mouse events received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
     * by the UI are channeled through this method so that the behavior may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
     * overridden by a subclass. Some UIs may need more functionality than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
     * this method provides, such as when manipulating the lead for discontiguous
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
     * selection, and may not call into this method for some selection changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
     * This implementation uses the following conventions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
     * <li> <code>toggle</code>: <em>false</em>, <code>extend</code>: <em>false</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
     *      Clear the previous selection and ensure the new cell is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
     * <li> <code>toggle</code>: <em>false</em>, <code>extend</code>: <em>true</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
     *      Extend the previous selection from the anchor to the specified cell,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
     *      clearing all other selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
     * <li> <code>toggle</code>: <em>true</em>, <code>extend</code>: <em>false</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
     *      If the specified cell is selected, deselect it. If it is not selected, select it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
     * <li> <code>toggle</code>: <em>true</em>, <code>extend</code>: <em>true</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
     *      Apply the selection state of the anchor to all cells between it and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
     *      specified cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
     * @param  rowIndex   affects the selection at <code>row</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
     * @param  columnIndex  affects the selection at <code>column</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
     * @param  toggle  see description above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
     * @param  extend  if true, extend the current selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
    public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
        ListSelectionModel rsm = getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
        ListSelectionModel csm = getColumnModel().getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
        int anchorRow = getAdjustedIndex(rsm.getAnchorSelectionIndex(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
        int anchorCol = getAdjustedIndex(csm.getAnchorSelectionIndex(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
        boolean anchorSelected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
        if (anchorRow == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
            if (getRowCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
                anchorRow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
            anchorSelected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
        if (anchorCol == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
            if (getColumnCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
                anchorCol = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
            anchorSelected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
        // Check the selection here rather than in each selection model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
        // This is significant in cell selection mode if we are supposed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
        // to be toggling the selection. In this case it is better to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
        // ensure that the cell's selection state will indeed be changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
        // If this were done in the code for the selection model it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
        // might leave a cell in selection state if the row was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
        // selected but the column was not - as it would toggle them both.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
        boolean selected = isCellSelected(rowIndex, columnIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
        anchorSelected = anchorSelected && isCellSelected(anchorRow, anchorCol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
        changeSelectionModel(csm, columnIndex, toggle, extend, selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
                             anchorCol, anchorSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
        changeSelectionModel(rsm, rowIndex, toggle, extend, selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
                             anchorRow, anchorSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
        // Scroll after changing the selection as blit scrolling is immediate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
        // so that if we cause the repaint after the scroll we end up painting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
        // everything!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
        if (getAutoscrolls()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
            Rectangle cellRect = getCellRect(rowIndex, columnIndex, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
            if (cellRect != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
                scrollRectToVisible(cellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
     * Returns the foreground color for selected cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
     * @return the <code>Color</code> object for the foreground property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
     * @see #setSelectionForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
     * @see #setSelectionBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
    public Color getSelectionForeground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
        return selectionForeground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
     * Sets the foreground color for selected cells.  Cell renderers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
     * can use this color to render text and graphics for selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
     * cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
     * The default value of this property is defined by the look
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
     * and feel implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
     * This is a <a href="http://java.sun.com/docs/books/tutorial/javabeans/whatis/beanDefinition.html">JavaBeans</a> bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
     * @param selectionForeground  the <code>Color</code> to use in the foreground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
     *                             for selected list items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
     * @see #getSelectionForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
     * @see #setSelectionBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
     * @see #setForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
     * @see #setBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
     * @see #setFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
     * description: A default foreground color for selected cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
    public void setSelectionForeground(Color selectionForeground) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
        Color old = this.selectionForeground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
        this.selectionForeground = selectionForeground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
        firePropertyChange("selectionForeground", old, selectionForeground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
        if ( !selectionForeground.equals(old) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
     * Returns the background color for selected cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
     * @return the <code>Color</code> used for the background of selected list items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
     * @see #setSelectionBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
     * @see #setSelectionForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
    public Color getSelectionBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
        return selectionBackground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
     * Sets the background color for selected cells.  Cell renderers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
     * can use this color to the fill selected cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
     * The default value of this property is defined by the look
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
     * and feel implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
     * This is a <a href="http://java.sun.com/docs/books/tutorial/javabeans/whatis/beanDefinition.html">JavaBeans</a> bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
     * @param selectionBackground  the <code>Color</code> to use for the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
     *                             of selected cells
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
     * @see #getSelectionBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
     * @see #setSelectionForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
     * @see #setForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
     * @see #setBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
     * @see #setFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
     * description: A default background color for selected cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
    public void setSelectionBackground(Color selectionBackground) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
        Color old = this.selectionBackground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
        this.selectionBackground = selectionBackground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
        firePropertyChange("selectionBackground", old, selectionBackground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
        if ( !selectionBackground.equals(old) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
     * Returns the <code>TableColumn</code> object for the column in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
     * whose identifier is equal to <code>identifier</code>, when compared using
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
     * <code>equals</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
     * @return  the <code>TableColumn</code> object that matches the identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
     * @exception IllegalArgumentException      if <code>identifier</code> is <code>null</code> or no <code>TableColumn</code> has this identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
     * @param   identifier                      the identifier object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
    public TableColumn getColumn(Object identifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
        TableColumnModel cm = getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
        int columnIndex = cm.getColumnIndex(identifier);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
        return cm.getColumn(columnIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
// Informally implement the TableModel interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
     * Maps the index of the column in the view at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
     * <code>viewColumnIndex</code> to the index of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
     * in the table model.  Returns the index of the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
     * column in the model.  If <code>viewColumnIndex</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
     * is less than zero, returns <code>viewColumnIndex</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
     * @param   viewColumnIndex     the index of the column in the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
     * @return  the index of the corresponding column in the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
     * @see #convertColumnIndexToView
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
    public int convertColumnIndexToModel(int viewColumnIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
        if (viewColumnIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
            return viewColumnIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
        return getColumnModel().getColumn(viewColumnIndex).getModelIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
     * Maps the index of the column in the table model at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
     * <code>modelColumnIndex</code> to the index of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
     * in the view.  Returns the index of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
     * corresponding column in the view; returns -1 if this column is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
     * being displayed.  If <code>modelColumnIndex</code> is less than zero,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
     * returns <code>modelColumnIndex</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
     * @param   modelColumnIndex     the index of the column in the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
     * @return   the index of the corresponding column in the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
     * @see #convertColumnIndexToModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
    public int convertColumnIndexToView(int modelColumnIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
        if (modelColumnIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
            return modelColumnIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
        TableColumnModel cm = getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
        for (int column = 0; column < getColumnCount(); column++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
            if (cm.getColumn(column).getModelIndex() == modelColumnIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
                return column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
     * Maps the index of the row in terms of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
     * <code>TableModel</code> to the view.  If the contents of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
     * model are not sorted the model and view indices are the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
     * @param modelRowIndex the index of the row in terms of the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
     * @return the index of the corresponding row in the view, or -1 if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
     *         the row isn't visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
     * @throws IndexOutOfBoundsException if sorting is enabled and passed an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
     *         index outside the number of rows of the <code>TableModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
     * @see javax.swing.table.TableRowSorter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
    public int convertRowIndexToView(int modelRowIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
        RowSorter sorter = getRowSorter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
        if (sorter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
            return sorter.convertRowIndexToView(modelRowIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
        return modelRowIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
     * Maps the index of the row in terms of the view to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
     * underlying <code>TableModel</code>.  If the contents of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
     * model are not sorted the model and view indices are the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
     * @param viewRowIndex the index of the row in the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
     * @return the index of the corresponding row in the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
     * @throws IndexOutOfBoundsException if sorting is enabled and passed an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
     *         index outside the range of the <code>JTable</code> as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
     *         determined by the method <code>getRowCount</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
     * @see javax.swing.table.TableRowSorter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
     * @see #getRowCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
    public int convertRowIndexToModel(int viewRowIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
        RowSorter sorter = getRowSorter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
        if (sorter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
            return sorter.convertRowIndexToModel(viewRowIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
        return viewRowIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
     * Returns the number of rows that can be shown in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
     * <code>JTable</code>, given unlimited space.  If a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
     * <code>RowSorter</code> with a filter has been specified, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
     * number of rows returned may differ from that of the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
     * <code>TableModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
     * @return the number of rows shown in the <code>JTable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
     * @see #getColumnCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
    public int getRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
        RowSorter sorter = getRowSorter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
        if (sorter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
            return sorter.getViewRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
        return getModel().getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
     * Returns the number of columns in the column model. Note that this may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
     * be different from the number of columns in the table model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
     * @return  the number of columns in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
     * @see #getRowCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
     * @see #removeColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
    public int getColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
        return getColumnModel().getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
     * Returns the name of the column appearing in the view at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
     * column position <code>column</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
     * @param  column    the column in the view being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
     * @return the name of the column at position <code>column</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
                        in the view where the first column is column 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
    public String getColumnName(int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
        return getModel().getColumnName(convertColumnIndexToModel(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
     * Returns the type of the column appearing in the view at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
     * column position <code>column</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
     * @param   column   the column in the view being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
     * @return the type of the column at position <code>column</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
     *          in the view where the first column is column 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
    public Class<?> getColumnClass(int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
        return getModel().getColumnClass(convertColumnIndexToModel(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
     * Returns the cell value at <code>row</code> and <code>column</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
     * <b>Note</b>: The column is specified in the table view's display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
     *              order, and not in the <code>TableModel</code>'s column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
     *              order.  This is an important distinction because as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
     *              user rearranges the columns in the table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
     *              the column at a given index in the view will change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
     *              Meanwhile the user's actions never affect the model's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
     *              column ordering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
     * @param   row             the row whose value is to be queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
     * @param   column          the column whose value is to be queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
     * @return  the Object at the specified cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
    public Object getValueAt(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
        return getModel().getValueAt(convertRowIndexToModel(row),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
                                     convertColumnIndexToModel(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
     * Sets the value for the cell in the table model at <code>row</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
     * and <code>column</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
     * <b>Note</b>: The column is specified in the table view's display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
     *              order, and not in the <code>TableModel</code>'s column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
     *              order.  This is an important distinction because as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
     *              user rearranges the columns in the table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
     *              the column at a given index in the view will change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
     *              Meanwhile the user's actions never affect the model's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
     *              column ordering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
     * <code>aValue</code> is the new value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
     * @param   aValue          the new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
     * @param   row             the row of the cell to be changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
     * @param   column          the column of the cell to be changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
     * @see #getValueAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
    public void setValueAt(Object aValue, int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
        getModel().setValueAt(aValue, convertRowIndexToModel(row),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
                              convertColumnIndexToModel(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
     * Returns true if the cell at <code>row</code> and <code>column</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
     * is editable.  Otherwise, invoking <code>setValueAt</code> on the cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
     * will have no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
     * <b>Note</b>: The column is specified in the table view's display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
     *              order, and not in the <code>TableModel</code>'s column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
     *              order.  This is an important distinction because as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
     *              user rearranges the columns in the table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
     *              the column at a given index in the view will change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
     *              Meanwhile the user's actions never affect the model's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
     *              column ordering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
     * @param   row      the row whose value is to be queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
     * @param   column   the column whose value is to be queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
     * @return  true if the cell is editable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
     * @see #setValueAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
    public boolean isCellEditable(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
        return getModel().isCellEditable(convertRowIndexToModel(row),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
                                         convertColumnIndexToModel(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
// Adding and removing columns in the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
     *  Appends <code>aColumn</code> to the end of the array of columns held by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
     *  this <code>JTable</code>'s column model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
     *  If the column name of <code>aColumn</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
     *  sets the column name of <code>aColumn</code> to the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
     *  returned by <code>getModel().getColumnName()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
     *  <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
     *  To add a column to this <code>JTable</code> to display the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
     *  <code>modelColumn</code>'th column of data in the model with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
     *  given <code>width</code>, <code>cellRenderer</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
     *  and <code>cellEditor</code> you can use:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
     *  <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
     *      addColumn(new TableColumn(modelColumn, width, cellRenderer, cellEditor));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
     *  </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
     *  [Any of the <code>TableColumn</code> constructors can be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
     *  instead of this one.]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
     *  The model column number is stored inside the <code>TableColumn</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
     *  and is used during rendering and editing to locate the appropriates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
     *  data values in the model. The model column number does not change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
     *  when columns are reordered in the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
     *  @param  aColumn         the <code>TableColumn</code> to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
     *  @see    #removeColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
    public void addColumn(TableColumn aColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
        if (aColumn.getHeaderValue() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
            int modelColumn = aColumn.getModelIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
            String columnName = getModel().getColumnName(modelColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
            aColumn.setHeaderValue(columnName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
        getColumnModel().addColumn(aColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
     *  Removes <code>aColumn</code> from this <code>JTable</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
     *  array of columns.  Note: this method does not remove the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
     *  of data from the model; it just removes the <code>TableColumn</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
     *  that was responsible for displaying it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
     *  @param  aColumn         the <code>TableColumn</code> to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
     *  @see    #addColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
    public void removeColumn(TableColumn aColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
        getColumnModel().removeColumn(aColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
     * Moves the column <code>column</code> to the position currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
     * occupied by the column <code>targetColumn</code> in the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
     * The old column at <code>targetColumn</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
     * shifted left or right to make room.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
     * @param   column                  the index of column to be moved
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
     * @param   targetColumn            the new index of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
    public void moveColumn(int column, int targetColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
        getColumnModel().moveColumn(column, targetColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
// Cover methods for various models and helper methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
     * Returns the index of the column that <code>point</code> lies in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
     * or -1 if the result is not in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
     * [0, <code>getColumnCount()</code>-1].
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
     * @param   point   the location of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
     * @return  the index of the column that <code>point</code> lies in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
     *          or -1 if the result is not in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
     *          [0, <code>getColumnCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
     * @see     #rowAtPoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
    public int columnAtPoint(Point point) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
        int x = point.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
        if( !getComponentOrientation().isLeftToRight() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
            x = getWidth() - x - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
        return getColumnModel().getColumnIndexAtX(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
     * Returns the index of the row that <code>point</code> lies in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
     * or -1 if the result is not in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
     * [0, <code>getRowCount()</code>-1].
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
     * @param   point   the location of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
     * @return  the index of the row that <code>point</code> lies in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
     *          or -1 if the result is not in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
     *          [0, <code>getRowCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
     * @see     #columnAtPoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
    public int rowAtPoint(Point point) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
        int y = point.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
        int result = (rowModel == null) ?  y/getRowHeight() : rowModel.getIndex(y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
        if (result < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
        else if (result >= getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
     * Returns a rectangle for the cell that lies at the intersection of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
     * <code>row</code> and <code>column</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
     * If <code>includeSpacing</code> is true then the value returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
     * has the full height and width of the row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
     * specified. If it is false, the returned rectangle is inset by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
     * intercell spacing to return the true bounds of the rendering or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
     * editing component as it will be set during rendering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
     * If the column index is valid but the row index is less
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
     * than zero the method returns a rectangle with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
     * <code>y</code> and <code>height</code> values set appropriately
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
     * and the <code>x</code> and <code>width</code> values both set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
     * to zero. In general, when either the row or column indices indicate a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
     * cell outside the appropriate range, the method returns a rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
     * depicting the closest edge of the closest cell that is within
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
     * the table's range. When both row and column indices are out
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
     * of range the returned rectangle covers the closest
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
     * point of the closest cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
     * In all cases, calculations that use this method to calculate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
     * results along one axis will not fail because of anomalies in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
     * calculations along the other axis. When the cell is not valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
     * the <code>includeSpacing</code> parameter is ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
     * @param   row                   the row index where the desired cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
     *                                is located
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
     * @param   column                the column index where the desired cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
     *                                is located in the display; this is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
     *                                necessarily the same as the column index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
     *                                in the data model for the table; the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
     *                                {@link #convertColumnIndexToView(int)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
     *                                method may be used to convert a data
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
     *                                model column index to a display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
     *                                column index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
     * @param   includeSpacing        if false, return the true cell bounds -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
     *                                computed by subtracting the intercell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
     *                                spacing from the height and widths of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
     *                                the column and row models
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
     * @return  the rectangle containing the cell at location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
     *          <code>row</code>,<code>column</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
     * @see #getIntercellSpacing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
    public Rectangle getCellRect(int row, int column, boolean includeSpacing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
        Rectangle r = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
        boolean valid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
        if (row < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
            // y = height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
            valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
        else if (row >= getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
            r.y = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
            valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
            r.height = getRowHeight(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
            r.y = (rowModel == null) ? row * r.height : rowModel.getPosition(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
        if (column < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
            if( !getComponentOrientation().isLeftToRight() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
                r.x = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
            // otherwise, x = width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
            valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
        else if (column >= getColumnCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
            if( getComponentOrientation().isLeftToRight() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
                r.x = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
            // otherwise, x = width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
            valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
            TableColumnModel cm = getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
            if( getComponentOrientation().isLeftToRight() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
                for(int i = 0; i < column; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
                    r.x += cm.getColumn(i).getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
                for(int i = cm.getColumnCount()-1; i > column; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
                    r.x += cm.getColumn(i).getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
            r.width = cm.getColumn(column).getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
        if (valid && !includeSpacing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
            // Bound the margins by their associated dimensions to prevent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
            // returning bounds with negative dimensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
            int rm = Math.min(getRowMargin(), r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
            int cm = Math.min(getColumnModel().getColumnMargin(), r.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
            // This is not the same as grow(), it rounds differently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
            r.setBounds(r.x + cm/2, r.y + rm/2, r.width - cm, r.height - rm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
        return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2990
    private int viewIndexForColumn(TableColumn aColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2991
        TableColumnModel cm = getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2992
        for (int column = 0; column < cm.getColumnCount(); column++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2993
            if (cm.getColumn(column) == aColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2994
                return column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
     * Causes this table to lay out its rows and columns.  Overridden so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
     * that columns can be resized to accomodate a change in the size of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
     * a containing parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3004
     * Resizes one or more of the columns in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
     * so that the total width of all of this <code>JTable</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
     * columns is equal to the width of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3008
     * Before the layout begins the method gets the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
     * <code>resizingColumn</code> of the <code>tableHeader</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
     * When the method is called as a result of the resizing of an enclosing window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
     * the <code>resizingColumn</code> is <code>null</code>. This means that resizing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
     * has taken place "outside" the <code>JTable</code> and the change -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
     * or "delta" - should be distributed to all of the columns regardless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
     * of this <code>JTable</code>'s automatic resize mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
     * If the <code>resizingColumn</code> is not <code>null</code>, it is one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
     * the columns in the table that has changed size rather than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
     * the table itself. In this case the auto-resize modes govern
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
     * the way the extra (or deficit) space is distributed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
     * amongst the available columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
     * The modes are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
     * <li>  AUTO_RESIZE_OFF: Don't automatically adjust the column's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
     * widths at all. Use a horizontal scrollbar to accomodate the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
     * columns when their sum exceeds the width of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
     * <code>Viewport</code>.  If the <code>JTable</code> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
     * enclosed in a <code>JScrollPane</code> this may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
     * leave parts of the table invisible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
     * <li>  AUTO_RESIZE_NEXT_COLUMN: Use just the column after the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
     * resizing column. This results in the "boundary" or divider
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
     * between adjacent cells being independently adjustable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
     * <li>  AUTO_RESIZE_SUBSEQUENT_COLUMNS: Use all columns after the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
     * one being adjusted to absorb the changes.  This is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
     * default behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
     * <li>  AUTO_RESIZE_LAST_COLUMN: Automatically adjust the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
     * size of the last column only. If the bounds of the last column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
     * prevent the desired size from being allocated, set the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
     * width of the last column to the appropriate limit and make
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
     * no further adjustments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
     * <li>  AUTO_RESIZE_ALL_COLUMNS: Spread the delta amongst all the columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
     * in the <code>JTable</code>, including the one that is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
     * adjusted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
     * <bold>Note:</bold> When a <code>JTable</code> makes adjustments
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
     *   to the widths of the columns it respects their minimum and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
     *   maximum values absolutely.  It is therefore possible that,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
     *   even after this method is called, the total width of the columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
     *   is still not equal to the width of the table. When this happens
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
     *   the <code>JTable</code> does not put itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
     *   in AUTO_RESIZE_OFF mode to bring up a scroll bar, or break other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
     *   commitments of its current auto-resize mode -- instead it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
     *   allows its bounds to be set larger (or smaller) than the total of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
     *   column minimum or maximum, meaning, either that there
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
     *   will not be enough room to display all of the columns, or that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
     *   columns will not fill the <code>JTable</code>'s bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
     *   These respectively, result in the clipping of some columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3059
     *   or an area being painted in the <code>JTable</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
     *   background color during painting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
     *   The mechanism for distributing the delta amongst the available
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
     *   columns is provided in a private method in the <code>JTable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
     *   class:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3066
     *   adjustSizes(long targetSize, final Resizable3 r, boolean inverse)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3067
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3068
     *   an explanation of which is provided in the following section.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3069
     *   <code>Resizable3</code> is a private
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
     *   interface that allows any data structure containing a collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3071
     *   of elements with a size, preferred size, maximum size and minimum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3072
     *   to have its elements manipulated by the algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
     * <H3> Distributing the delta </H3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
     * <H4> Overview </H4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3077
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
     * Call "DELTA" the difference between the target size and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3079
     * sum of the preferred sizes of the elements in r. The individual
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
     * sizes are calculated by taking the original preferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
     * sizes and adding a share of the DELTA - that share being based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
     * how far each preferred size is from its limiting bound (minimum or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
     * maximum).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3085
     * <H4>Definition</H4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
     * Call the individual constraints min[i], max[i], and pref[i].
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
     * Call their respective sums: MIN, MAX, and PREF.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3091
     * Each new size will be calculated using:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3092
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3093
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
     *          size[i] = pref[i] + delta[i]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
     * where each individual delta[i] is calculated according to:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3098
     * If (DELTA < 0) we are in shrink mode where:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3099
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
     * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
     *                        DELTA
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3102
     *          delta[i] = ------------ * (pref[i] - min[i])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3103
     *                     (PREF - MIN)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3104
     * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3105
     * If (DELTA > 0) we are in expand mode where:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3106
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3107
     * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3108
     *                        DELTA
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3109
     *          delta[i] = ------------ * (max[i] - pref[i])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3110
     *                      (MAX - PREF)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3111
     * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3112
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3113
     * The overall effect is that the total size moves that same percentage,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3114
     * k, towards the total minimum or maximum and that percentage guarantees
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3115
     * accomodation of the required space, DELTA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3117
     * <H4>Details</H4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3118
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3119
     * Naive evaluation of the formulae presented here would be subject to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3120
     * the aggregated rounding errors caused by doing this operation in finite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3121
     * precision (using ints). To deal with this, the multiplying factor above,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3122
     * is constantly recalculated and this takes account of the rounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3123
     * errors in the previous iterations. The result is an algorithm that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3124
     * produces a set of integers whose values exactly sum to the supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3125
     * <code>targetSize</code>, and does so by spreading the rounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3126
     * errors evenly over the given elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3128
     * <H4>When the MAX and MIN bounds are hit</H4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3129
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3130
     * When <code>targetSize</code> is outside the [MIN, MAX] range,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
     * the algorithm sets all sizes to their appropriate limiting value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3132
     * (maximum or minimum).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3133
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3135
    public void doLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3136
        TableColumn resizingColumn = getResizingColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3137
        if (resizingColumn == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3138
            setWidthsFromPreferredWidths(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3140
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3141
            // JTable behaves like a layout manger - but one in which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3142
            // user can come along and dictate how big one of the children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
            // (columns) is supposed to be.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3145
            // A column has been resized and JTable may need to distribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3146
            // any overall delta to other columns, according to the resize mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3147
            int columnIndex = viewIndexForColumn(resizingColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3148
            int delta = getWidth() - getColumnModel().getTotalColumnWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3149
            accommodateDelta(columnIndex, delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3150
            delta = getWidth() - getColumnModel().getTotalColumnWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3151
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3152
            // If the delta cannot be completely accomodated, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3153
            // resizing column will have to take any remainder. This means
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3154
            // that the column is not being allowed to take the requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3155
            // width. This happens under many circumstances: For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
            // AUTO_RESIZE_NEXT_COLUMN specifies that any delta be distributed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
            // to the column after the resizing column. If one were to attempt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
            // to resize the last column of the table, there would be no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
            // columns after it, and hence nowhere to distribute the delta.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
            // It would then be given entirely back to the resizing column,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
            // preventing it from changing size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3162
            if (delta != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3163
                resizingColumn.setWidth(resizingColumn.getWidth() + delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3164
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3165
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3166
            // At this point the JTable has to work out what preferred sizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3167
            // would have resulted in the layout the user has chosen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3168
            // Thereafter, during window resizing etc. it has to work off
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3169
            // the preferred sizes as usual - the idea being that, whatever
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3170
            // the user does, everything stays in synch and things don't jump
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3171
            // around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3172
            setWidthsFromPreferredWidths(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3175
        super.doLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3177
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3178
    private TableColumn getResizingColumn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3179
        return (tableHeader == null) ? null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3180
                                     : tableHeader.getResizingColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3182
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3184
     * Sizes the table columns to fit the available space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3185
     * @deprecated As of Swing version 1.0.3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3186
     * replaced by <code>doLayout()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3187
     * @see #doLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3189
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3190
    public void sizeColumnsToFit(boolean lastColumnOnly) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3191
        int oldAutoResizeMode = autoResizeMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
        setAutoResizeMode(lastColumnOnly ? AUTO_RESIZE_LAST_COLUMN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
                                         : AUTO_RESIZE_ALL_COLUMNS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3194
        sizeColumnsToFit(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3195
        setAutoResizeMode(oldAutoResizeMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3197
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3199
     * Obsolete as of Java 2 platform v1.4.  Please use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3200
     * <code>doLayout()</code> method instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3201
     * @param resizingColumn    the column whose resizing made this adjustment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
     *                          necessary or -1 if there is no such column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
     * @see  #doLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
    public void sizeColumnsToFit(int resizingColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
        if (resizingColumn == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3207
            setWidthsFromPreferredWidths(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3210
            if (autoResizeMode == AUTO_RESIZE_OFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
                TableColumn aColumn = getColumnModel().getColumn(resizingColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
                aColumn.setPreferredWidth(aColumn.getWidth());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
                int delta = getWidth() - getColumnModel().getTotalColumnWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
                accommodateDelta(resizingColumn, delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
                setWidthsFromPreferredWidths(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
    private void setWidthsFromPreferredWidths(final boolean inverse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
        int totalWidth     = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3224
        int totalPreferred = getPreferredSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3225
        int target = !inverse ? totalWidth : totalPreferred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
        final TableColumnModel cm = columnModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
        Resizable3 r = new Resizable3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
            public int  getElementCount()      { return cm.getColumnCount(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3230
            public int  getLowerBoundAt(int i) { return cm.getColumn(i).getMinWidth(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
            public int  getUpperBoundAt(int i) { return cm.getColumn(i).getMaxWidth(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3232
            public int  getMidPointAt(int i)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
                if (!inverse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
                    return cm.getColumn(i).getPreferredWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
                    return cm.getColumn(i).getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3240
            public void setSizeAt(int s, int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
                if (!inverse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
                    cm.getColumn(i).setWidth(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
                    cm.getColumn(i).setPreferredWidth(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3250
        adjustSizes(target, r, inverse);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3252
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3254
    // Distribute delta over columns, as indicated by the autoresize mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3255
    private void accommodateDelta(int resizingColumnIndex, int delta) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
        int columnCount = getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3257
        int from = resizingColumnIndex;
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  3258
        int to;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
        // Use the mode to determine how to absorb the changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
        switch(autoResizeMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
            case AUTO_RESIZE_NEXT_COLUMN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3263
                from = from + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
                to = Math.min(from + 1, columnCount); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
            case AUTO_RESIZE_SUBSEQUENT_COLUMNS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3266
                from = from + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
                to = columnCount; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3268
            case AUTO_RESIZE_LAST_COLUMN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3269
                from = columnCount - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3270
                to = from + 1; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3271
            case AUTO_RESIZE_ALL_COLUMNS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
                from = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
                to = columnCount; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
        final int start = from;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3279
        final int end = to;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3280
        final TableColumnModel cm = columnModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3281
        Resizable3 r = new Resizable3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3282
            public int  getElementCount()       { return end-start; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3283
            public int  getLowerBoundAt(int i)  { return cm.getColumn(i+start).getMinWidth(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3284
            public int  getUpperBoundAt(int i)  { return cm.getColumn(i+start).getMaxWidth(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
            public int  getMidPointAt(int i)    { return cm.getColumn(i+start).getWidth(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
            public void setSizeAt(int s, int i) {        cm.getColumn(i+start).setWidth(s); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3287
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3289
        int totalWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
        for(int i = from; i < to; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3291
            TableColumn aColumn = columnModel.getColumn(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
            int input = aColumn.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3293
            totalWidth = totalWidth + input;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
        adjustSizes(totalWidth + delta, r, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
    private interface Resizable2 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
        public int  getElementCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
        public int  getLowerBoundAt(int i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
        public int  getUpperBoundAt(int i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
        public void setSizeAt(int newSize, int i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
    private interface Resizable3 extends Resizable2 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
        public int  getMidPointAt(int i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3309
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
    private void adjustSizes(long target, final Resizable3 r, boolean inverse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
        int N = r.getElementCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3313
        long totalPreferred = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3314
        for(int i = 0; i < N; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3315
            totalPreferred += r.getMidPointAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
        Resizable2 s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3318
        if ((target < totalPreferred) == !inverse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3319
            s = new Resizable2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3320
                public int  getElementCount()      { return r.getElementCount(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
                public int  getLowerBoundAt(int i) { return r.getLowerBoundAt(i); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
                public int  getUpperBoundAt(int i) { return r.getMidPointAt(i); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
                public void setSizeAt(int newSize, int i) { r.setSizeAt(newSize, i); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3324
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
            s = new Resizable2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
                public int  getElementCount()      { return r.getElementCount(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
                public int  getLowerBoundAt(int i) { return r.getMidPointAt(i); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
                public int  getUpperBoundAt(int i) { return r.getUpperBoundAt(i); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3332
                public void setSizeAt(int newSize, int i) { r.setSizeAt(newSize, i); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
        adjustSizes(target, s, !inverse);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3339
    private void adjustSizes(long target, Resizable2 r, boolean limitToRange) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
        long totalLowerBound = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
        long totalUpperBound = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
        for(int i = 0; i < r.getElementCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
            totalLowerBound += r.getLowerBoundAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
            totalUpperBound += r.getUpperBoundAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
        if (limitToRange) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
            target = Math.min(Math.max(totalLowerBound, target), totalUpperBound);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
        for(int i = 0; i < r.getElementCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3352
            int lowerBound = r.getLowerBoundAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
            int upperBound = r.getUpperBoundAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
            // Check for zero. This happens when the distribution of the delta
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3355
            // finishes early due to a series of "fixed" entries at the end.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3356
            // In this case, lowerBound == upperBound, for all subsequent terms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3357
            int newSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
            if (totalLowerBound == totalUpperBound) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3359
                newSize = lowerBound;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
                double f = (double)(target - totalLowerBound)/(totalUpperBound - totalLowerBound);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
                newSize = (int)Math.round(lowerBound+f*(upperBound - lowerBound));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3364
                // We'd need to round manually in an all integer version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
                // size[i] = (int)(((totalUpperBound - target) * lowerBound +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
                //     (target - totalLowerBound) * upperBound)/(totalUpperBound-totalLowerBound));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3368
            r.setSizeAt(newSize, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3369
            target -= newSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3370
            totalLowerBound -= lowerBound;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3371
            totalUpperBound -= upperBound;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
     * Overrides <code>JComponent</code>'s <code>getToolTipText</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3377
     * method in order to allow the renderer's tips to be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3378
     * if it has text set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3379
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3380
     * <bold>Note:</bold> For <code>JTable</code> to properly display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3381
     * tooltips of its renderers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3382
     * <code>JTable</code> must be a registered component with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3383
     * <code>ToolTipManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3384
     * This is done automatically in <code>initializeLocalVars</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3385
     * but if at a later point <code>JTable</code> is told
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3386
     * <code>setToolTipText(null)</code> it will unregister the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
     * component, and no tips from renderers will display anymore.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3388
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
     * @see JComponent#getToolTipText
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
    public String getToolTipText(MouseEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
        String tip = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
        Point p = event.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
        // Locate the renderer under the event location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
        int hitColumnIndex = columnAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
        int hitRowIndex = rowAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3398
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
        if ((hitColumnIndex != -1) && (hitRowIndex != -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3400
            TableCellRenderer renderer = getCellRenderer(hitRowIndex, hitColumnIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3401
            Component component = prepareRenderer(renderer, hitRowIndex, hitColumnIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
            // Now have to see if the component is a JComponent before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
            // getting the tip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
            if (component instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3406
                // Convert the event to the renderer's coordinate system
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
                Rectangle cellRect = getCellRect(hitRowIndex, hitColumnIndex, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3408
                p.translate(-cellRect.x, -cellRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3409
                MouseEvent newEvent = new MouseEvent(component, event.getID(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3410
                                          event.getWhen(), event.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3411
                                          p.x, p.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3412
                                          event.getXOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
                                          event.getYOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
                                          event.getClickCount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
                                          event.isPopupTrigger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
                                          MouseEvent.NOBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
                tip = ((JComponent)component).getToolTipText(newEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3419
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3421
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
        // No tip from the renderer get our own tip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3423
        if (tip == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
            tip = getToolTipText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
        return tip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3429
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
// Editing Support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3431
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3433
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3434
     * Sets whether editors in this JTable get the keyboard focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3435
     * when an editor is activated as a result of the JTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3436
     * forwarding keyboard events for a cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3437
     * By default, this property is false, and the JTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
     * retains the focus unless the cell is clicked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3439
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3440
     * @param surrendersFocusOnKeystroke true if the editor should get the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3441
     *          when keystrokes cause the editor to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3442
     *          activated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3443
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3444
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3445
     * @see #getSurrendersFocusOnKeystroke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3446
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3447
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3448
    public void setSurrendersFocusOnKeystroke(boolean surrendersFocusOnKeystroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
        this.surrendersFocusOnKeystroke = surrendersFocusOnKeystroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3451
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3453
     * Returns true if the editor should get the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3454
     * when keystrokes cause the editor to be activated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3455
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3456
     * @return  true if the editor should get the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3457
     *          when keystrokes cause the editor to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3458
     *          activated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3459
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3460
     * @see #setSurrendersFocusOnKeystroke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3461
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3462
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
    public boolean getSurrendersFocusOnKeystroke() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
        return surrendersFocusOnKeystroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3468
     * Programmatically starts editing the cell at <code>row</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3469
     * <code>column</code>, if those indices are in the valid range, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3470
     * the cell at those indices is editable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3471
     * Note that this is a convenience method for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3472
     * <code>editCellAt(int, int, null)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3473
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3474
     * @param   row                             the row to be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
     * @param   column                          the column to be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
     * @return  false if for any reason the cell cannot be edited,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3477
     *                or if the indices are invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3478
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
    public boolean editCellAt(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
        return editCellAt(row, column, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3483
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
     * Programmatically starts editing the cell at <code>row</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
     * <code>column</code>, if those indices are in the valid range, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3486
     * the cell at those indices is editable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
     * To prevent the <code>JTable</code> from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
     * editing a particular table, column or cell value, return false from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
     * the <code>isCellEditable</code> method in the <code>TableModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
     * interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
     * @param   row     the row to be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3493
     * @param   column  the column to be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3494
     * @param   e       event to pass into <code>shouldSelectCell</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3495
     *                  note that as of Java 2 platform v1.2, the call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3496
     *                  <code>shouldSelectCell</code> is no longer made
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
     * @return  false if for any reason the cell cannot be edited,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3498
     *                or if the indices are invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3499
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3500
    public boolean editCellAt(int row, int column, EventObject e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3501
        if (cellEditor != null && !cellEditor.stopCellEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3502
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3504
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
        if (row < 0 || row >= getRowCount() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
            column < 0 || column >= getColumnCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3507
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3509
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
        if (!isCellEditable(row, column))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3513
        if (editorRemover == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
            KeyboardFocusManager fm =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
                KeyboardFocusManager.getCurrentKeyboardFocusManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3516
            editorRemover = new CellEditorRemover(fm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3517
            fm.addPropertyChangeListener("permanentFocusOwner", editorRemover);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3519
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3520
        TableCellEditor editor = getCellEditor(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3521
        if (editor != null && editor.isCellEditable(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3522
            editorComp = prepareEditor(editor, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3523
            if (editorComp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3524
                removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3525
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3526
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
            editorComp.setBounds(getCellRect(row, column, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
            add(editorComp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
            editorComp.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
            editorComp.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3531
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
            setCellEditor(editor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3533
            setEditingRow(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
            setEditingColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3535
            editor.addCellEditorListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3536
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3537
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3538
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3539
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3541
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3542
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3543
     * Returns true if a cell is being edited.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3544
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3545
     * @return  true if the table is editing a cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3546
     * @see     #editingColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3547
     * @see     #editingRow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3548
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3549
    public boolean isEditing() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  3550
        return cellEditor != null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3551
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3552
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3553
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3554
     * Returns the component that is handling the editing session.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3555
     * If nothing is being edited, returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3556
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3557
     * @return  Component handling editing session
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3558
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3559
    public Component getEditorComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3560
        return editorComp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3562
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3563
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3564
     * Returns the index of the column that contains the cell currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3565
     * being edited.  If nothing is being edited, returns -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3566
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3567
     * @return  the index of the column that contains the cell currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3568
     *          being edited; returns -1 if nothing being edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3569
     * @see #editingRow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3570
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3571
    public int getEditingColumn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3572
        return editingColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3574
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3575
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3576
     * Returns the index of the row that contains the cell currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3577
     * being edited.  If nothing is being edited, returns -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3578
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3579
     * @return  the index of the row that contains the cell currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3580
     *          being edited; returns -1 if nothing being edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3581
     * @see #editingColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3582
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3583
    public int getEditingRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3584
        return editingRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3585
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3586
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3587
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3588
// Managing TableUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3589
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3590
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3591
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3592
     * Returns the L&F object that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3593
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3594
     * @return the <code>TableUI</code> object that renders this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3595
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3596
    public TableUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3597
        return (TableUI)ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3598
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3599
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3600
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3601
     * Sets the L&F object that renders this component and repaints.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3602
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3603
     * @param ui  the TableUI L&F object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3604
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3605
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3606
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3607
     *       hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3608
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3609
     *  description: The UI object that implements the Component's LookAndFeel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3610
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3611
    public void setUI(TableUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3612
        if (this.ui != ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3613
            super.setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3614
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3616
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3617
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3618
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3619
     * Notification from the <code>UIManager</code> that the L&F has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3620
     * Replaces the current UI object with the latest version from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3621
     * <code>UIManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3622
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3623
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3624
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3625
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3626
        // Update the UIs of the cell renderers, cell editors and header renderers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3627
        TableColumnModel cm = getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3628
        for(int column = 0; column < cm.getColumnCount(); column++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3629
            TableColumn aColumn = cm.getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3630
            SwingUtilities.updateRendererOrEditorUI(aColumn.getCellRenderer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3631
            SwingUtilities.updateRendererOrEditorUI(aColumn.getCellEditor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3632
            SwingUtilities.updateRendererOrEditorUI(aColumn.getHeaderRenderer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3633
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3635
        // Update the UIs of all the default renderers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3636
        Enumeration defaultRenderers = defaultRenderersByColumnClass.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3637
        while (defaultRenderers.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3638
            SwingUtilities.updateRendererOrEditorUI(defaultRenderers.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3639
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3640
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3641
        // Update the UIs of all the default editors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3642
        Enumeration defaultEditors = defaultEditorsByColumnClass.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3643
        while (defaultEditors.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3644
            SwingUtilities.updateRendererOrEditorUI(defaultEditors.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3645
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3646
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3647
        // Update the UI of the table header
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3648
        if (tableHeader != null && tableHeader.getParent() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3649
            tableHeader.updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3650
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3651
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
  3652
        // Update UI applied to parent ScrollPane
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
  3653
        configureEnclosingScrollPaneUI();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
  3654
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3655
        setUI((TableUI)UIManager.getUI(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3656
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3657
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3658
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3659
     * Returns the suffix used to construct the name of the L&F class used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3660
     * render this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3661
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3662
     * @return the string "TableUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3663
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3664
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3665
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3666
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3667
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3668
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3670
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3671
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3672
// Managing models
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3673
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3674
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3675
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3676
     * Sets the data model for this table to <code>newModel</code> and registers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3677
     * with it for listener notifications from the new data model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3678
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3679
     * @param   dataModel        the new data source for this table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3680
     * @exception IllegalArgumentException      if <code>newModel</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3681
     * @see     #getModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3682
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3683
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3684
     *  description: The model that is the source of the data for this view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3685
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3686
    public void setModel(TableModel dataModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3687
        if (dataModel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3688
            throw new IllegalArgumentException("Cannot set a null TableModel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3689
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3690
        if (this.dataModel != dataModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3691
            TableModel old = this.dataModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3692
            if (old != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3693
                old.removeTableModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3694
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3695
            this.dataModel = dataModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3696
            dataModel.addTableModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3697
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3698
            tableChanged(new TableModelEvent(dataModel, TableModelEvent.HEADER_ROW));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3699
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3700
            firePropertyChange("model", old, dataModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3701
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3702
            if (getAutoCreateRowSorter()) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  3703
                setRowSorter(new TableRowSorter<TableModel>(dataModel));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3704
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3705
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3707
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3708
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3709
     * Returns the <code>TableModel</code> that provides the data displayed by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3710
     * <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3711
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3712
     * @return  the <code>TableModel</code> that provides the data displayed by this <code>JTable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3713
     * @see     #setModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3714
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3715
    public TableModel getModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3716
        return dataModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3717
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3718
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3719
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3720
     * Sets the column model for this table to <code>newModel</code> and registers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3721
     * for listener notifications from the new column model. Also sets
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3722
     * the column model of the <code>JTableHeader</code> to <code>columnModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3723
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3724
     * @param   columnModel        the new data source for this table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3725
     * @exception IllegalArgumentException      if <code>columnModel</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3726
     * @see     #getColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3727
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3728
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3729
     *  description: The object governing the way columns appear in the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3730
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3731
    public void setColumnModel(TableColumnModel columnModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3732
        if (columnModel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3733
            throw new IllegalArgumentException("Cannot set a null ColumnModel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3734
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3735
        TableColumnModel old = this.columnModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3736
        if (columnModel != old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3737
            if (old != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3738
                old.removeColumnModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3739
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3740
            this.columnModel = columnModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3741
            columnModel.addColumnModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3742
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3743
            // Set the column model of the header as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3744
            if (tableHeader != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3745
                tableHeader.setColumnModel(columnModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3746
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3747
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3748
            firePropertyChange("columnModel", old, columnModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3749
            resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3750
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3751
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3752
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3753
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3754
     * Returns the <code>TableColumnModel</code> that contains all column information
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3755
     * of this table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3756
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3757
     * @return  the object that provides the column state of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3758
     * @see     #setColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3759
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3760
    public TableColumnModel getColumnModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3761
        return columnModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3762
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3763
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3764
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3765
     * Sets the row selection model for this table to <code>newModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3766
     * and registers for listener notifications from the new selection model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3767
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3768
     * @param   newModel        the new selection model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3769
     * @exception IllegalArgumentException      if <code>newModel</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3770
     * @see     #getSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3771
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3772
     *      bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3773
     *      description: The selection model for rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3774
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3775
    public void setSelectionModel(ListSelectionModel newModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3776
        if (newModel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3777
            throw new IllegalArgumentException("Cannot set a null SelectionModel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3778
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3779
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3780
        ListSelectionModel oldModel = selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3781
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3782
        if (newModel != oldModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3783
            if (oldModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3784
                oldModel.removeListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3785
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3786
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3787
            selectionModel = newModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3788
            newModel.addListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3789
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3790
            firePropertyChange("selectionModel", oldModel, newModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3791
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3792
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3793
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3794
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3795
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3796
     * Returns the <code>ListSelectionModel</code> that is used to maintain row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3797
     * selection state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3798
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3799
     * @return  the object that provides row selection state, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3800
     *          if row selection is not allowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3801
     * @see     #setSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3802
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3803
    public ListSelectionModel getSelectionModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3804
        return selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3805
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3806
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3807
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3808
// RowSorterListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3809
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3810
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3811
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3812
     * <code>RowSorterListener</code> notification that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3813
     * <code>RowSorter</code> has changed in some way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3814
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3815
     * @param e the <code>RowSorterEvent</code> describing the change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3816
     * @throws NullPointerException if <code>e</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3817
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3818
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3819
    public void sorterChanged(RowSorterEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3820
        if (e.getType() == RowSorterEvent.Type.SORT_ORDER_CHANGED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3821
            JTableHeader header = getTableHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3822
            if (header != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3823
                header.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3824
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3825
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3826
        else if (e.getType() == RowSorterEvent.Type.SORTED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3827
            sorterChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3828
            if (!ignoreSortChange) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3829
                sortedTableChanged(e, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3830
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3831
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3832
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3833
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3834
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3835
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3836
     * SortManager provides support for managing the selection and variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3837
     * row heights when sorting is enabled. This information is encapsulated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3838
     * into a class to avoid bulking up JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3839
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3840
    private final class SortManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3841
        RowSorter<? extends TableModel> sorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3842
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3843
        // Selection, in terms of the model. This is lazily created
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3844
        // as needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3845
        private ListSelectionModel modelSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3846
        private int modelLeadIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3847
        // Set to true while in the process of changing the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3848
        // If this is true the selection change is ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3849
        private boolean syncingSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3850
        // Temporary cache of selection, in terms of model. This is only used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3851
        // if we don't need the full weight of modelSelection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3852
        private int[] lastModelSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3853
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3854
        // Heights of the rows in terms of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3855
        private SizeSequence modelRowSizes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3856
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3857
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3858
        SortManager(RowSorter<? extends TableModel> sorter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3859
            this.sorter = sorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3860
            sorter.addRowSorterListener(JTable.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3861
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3862
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3863
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3864
         * Disposes any resources used by this SortManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3865
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3866
        public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3867
            if (sorter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3868
                sorter.removeRowSorterListener(JTable.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3869
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3870
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3871
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3872
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3873
         * Sets the height for a row at a specified index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3874
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3875
        public void setViewRowHeight(int viewIndex, int rowHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3876
            if (modelRowSizes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3877
                modelRowSizes = new SizeSequence(getModel().getRowCount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3878
                                                 getRowHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3879
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3880
            modelRowSizes.setSize(convertRowIndexToModel(viewIndex),rowHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3881
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3882
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3883
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3884
         * Invoked when the underlying model has completely changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3885
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3886
        public void allChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3887
            modelLeadIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3888
            modelSelection = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3889
            modelRowSizes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3890
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3891
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3892
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3893
         * Invoked when the selection, on the view, has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3894
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3895
        public void viewSelectionChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3896
            if (!syncingSelection && modelSelection != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3897
                modelSelection = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3898
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3899
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3900
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3901
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3902
         * Invoked when either the table model has changed, or the RowSorter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3903
         * has changed. This is invoked prior to notifying the sorter of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3904
         * change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3905
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3906
        public void prepareForChange(RowSorterEvent sortEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3907
                                     ModelChange change) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3908
            if (getUpdateSelectionOnSort()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3909
                cacheSelection(sortEvent, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3910
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3911
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3912
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3913
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3914
         * Updates the internal cache of the selection based on the change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3915
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3916
        private void cacheSelection(RowSorterEvent sortEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3917
                                    ModelChange change) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3918
            if (sortEvent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3919
                // sort order changed. If modelSelection is null and filtering
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3920
                // is enabled we need to cache the selection in terms of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3921
                // underlying model, this will allow us to correctly restore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3922
                // the selection even if rows are filtered out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3923
                if (modelSelection == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3924
                        sorter.getViewRowCount() != getModel().getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3925
                    modelSelection = new DefaultListSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3926
                    ListSelectionModel viewSelection = getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3927
                    int min = viewSelection.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3928
                    int max = viewSelection.getMaxSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3929
                    int modelIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3930
                    for (int viewIndex = min; viewIndex <= max; viewIndex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3931
                        if (viewSelection.isSelectedIndex(viewIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3932
                            modelIndex = convertRowIndexToModel(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3933
                                    sortEvent, viewIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3934
                            if (modelIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3935
                                modelSelection.addSelectionInterval(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3936
                                    modelIndex, modelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3937
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3938
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3939
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3940
                    modelIndex = convertRowIndexToModel(sortEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3941
                            viewSelection.getLeadSelectionIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3942
                    SwingUtilities2.setLeadAnchorWithoutSelection(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3943
                            modelSelection, modelIndex, modelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3944
                } else if (modelSelection == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3945
                    // Sorting changed, haven't cached selection in terms
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3946
                    // of model and no filtering. Temporarily cache selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3947
                    cacheModelSelection(sortEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3948
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3949
            } else if (change.allRowsChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3950
                // All the rows have changed, chuck any cached selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3951
                modelSelection = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3952
            } else if (modelSelection != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3953
                // Table changed, reflect changes in cached selection model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3954
                switch(change.type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3955
                case TableModelEvent.DELETE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3956
                    modelSelection.removeIndexInterval(change.startModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3957
                                                       change.endModelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3958
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3959
                case TableModelEvent.INSERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3960
                    modelSelection.insertIndexInterval(change.startModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3961
                                                       change.endModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3962
                                                       true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3963
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3964
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3965
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3966
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3967
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3968
                // table changed, but haven't cached rows, temporarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3969
                // cache them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3970
                cacheModelSelection(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3971
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3972
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3973
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3974
        private void cacheModelSelection(RowSorterEvent sortEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3975
            lastModelSelection = convertSelectionToModel(sortEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3976
            modelLeadIndex = convertRowIndexToModel(sortEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3977
                        selectionModel.getLeadSelectionIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3978
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3979
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3980
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3981
         * Inovked when either the table has changed or the sorter has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3982
         * and after the sorter has been notified. If necessary this will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3983
         * reapply the selection and variable row heights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3984
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3985
        public void processChange(RowSorterEvent sortEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3986
                                  ModelChange change,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3987
                                  boolean sorterChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3988
            if (change != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3989
                if (change.allRowsChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3990
                    modelRowSizes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3991
                    rowModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3992
                } else if (modelRowSizes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3993
                    if (change.type == TableModelEvent.INSERT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3994
                        modelRowSizes.insertEntries(change.startModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3995
                                                    change.endModelIndex -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3996
                                                    change.startModelIndex + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3997
                                                    getRowHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3998
                    } else if (change.type == TableModelEvent.DELETE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3999
                        modelRowSizes.removeEntries(change.startModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4000
                                                    change.endModelIndex -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4001
                                                    change.startModelIndex +1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4002
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4003
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4004
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4005
            if (sorterChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4006
                setViewRowHeightsFromModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4007
                restoreSelection(change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4008
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4009
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4011
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4012
         * Resets the variable row heights in terms of the view from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4013
         * that of the variable row heights in terms of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4014
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4015
        private void setViewRowHeightsFromModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4016
            if (modelRowSizes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4017
                rowModel.setSizes(getRowCount(), getRowHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4018
                for (int viewIndex = getRowCount() - 1; viewIndex >= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4019
                         viewIndex--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4020
                    int modelIndex = convertRowIndexToModel(viewIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4021
                    rowModel.setSize(viewIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4022
                                     modelRowSizes.getSize(modelIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4023
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4024
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4025
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4027
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4028
         * Restores the selection from that in terms of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4029
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4030
        private void restoreSelection(ModelChange change) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4031
            syncingSelection = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4032
            if (lastModelSelection != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4033
                restoreSortingSelection(lastModelSelection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4034
                                        modelLeadIndex, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4035
                lastModelSelection = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4036
            } else if (modelSelection != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4037
                ListSelectionModel viewSelection = getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4038
                viewSelection.setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4039
                viewSelection.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4040
                int min = modelSelection.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4041
                int max = modelSelection.getMaxSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4042
                int viewIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4043
                for (int modelIndex = min; modelIndex <= max; modelIndex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4044
                    if (modelSelection.isSelectedIndex(modelIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4045
                        viewIndex = convertRowIndexToView(modelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4046
                        if (viewIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4047
                            viewSelection.addSelectionInterval(viewIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4048
                                                               viewIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4049
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4050
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4051
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4052
                // Restore the lead
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4053
                int viewLeadIndex = modelSelection.getLeadSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4054
                if (viewLeadIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4055
                    viewLeadIndex = convertRowIndexToView(viewLeadIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4056
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4057
                SwingUtilities2.setLeadAnchorWithoutSelection(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4058
                        viewSelection, viewLeadIndex, viewLeadIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4059
                viewSelection.setValueIsAdjusting(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4060
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4061
            syncingSelection = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4062
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4063
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4065
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4066
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4067
     * ModelChange is used when sorting to restore state, it corresponds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4068
     * to data from a TableModelEvent.  The values are precalculated as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4069
     * they are used extensively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4070
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4071
    private final class ModelChange {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4072
        // Starting index of the change, in terms of the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4073
        int startModelIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4074
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4075
        // Ending index of the change, in terms of the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4076
        int endModelIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4078
        // Type of change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4079
        int type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4081
        // Number of rows in the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4082
        int modelRowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4084
        // The event that triggered this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4085
        TableModelEvent event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4087
        // Length of the change (end - start + 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4088
        int length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4090
        // True if the event indicates all the contents have changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4091
        boolean allRowsChanged;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4093
        ModelChange(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4094
            startModelIndex = Math.max(0, e.getFirstRow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4095
            endModelIndex = e.getLastRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4096
            modelRowCount = getModel().getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4097
            if (endModelIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4098
                endModelIndex = Math.max(0, modelRowCount - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4099
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4100
            length = endModelIndex - startModelIndex + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4101
            type = e.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4102
            event = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4103
            allRowsChanged = (e.getLastRow() == Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4108
     * Invoked when <code>sorterChanged</code> is invoked, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4109
     * when <code>tableChanged</code> is invoked and sorting is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4111
    private void sortedTableChanged(RowSorterEvent sortedEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4112
                                    TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4113
        int editingModelIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4114
        ModelChange change = (e != null) ? new ModelChange(e) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4116
        if ((change == null || !change.allRowsChanged) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4117
                this.editingRow != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4118
            editingModelIndex = convertRowIndexToModel(sortedEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4119
                                                       this.editingRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4122
        sortManager.prepareForChange(sortedEvent, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4124
        if (e != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4125
            if (change.type == TableModelEvent.UPDATE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4126
                repaintSortedRows(change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4128
            notifySorter(change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4129
            if (change.type != TableModelEvent.UPDATE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4130
                // If the Sorter is unsorted we will not have received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4131
                // notification, force treating insert/delete as a change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4132
                sorterChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4133
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4135
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4136
            sorterChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4139
        sortManager.processChange(sortedEvent, change, sorterChanged);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4141
        if (sorterChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4142
            // Update the editing row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4143
            if (this.editingRow != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4144
                int newIndex = (editingModelIndex == -1) ? -1 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4145
                        convertRowIndexToView(editingModelIndex,change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4146
                restoreSortingEditingRow(newIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4147
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4149
            // And handle the appropriate repainting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4150
            if (e == null || change.type != TableModelEvent.UPDATE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4151
                resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4152
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4155
        // Check if lead/anchor need to be reset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4156
        if (change != null && change.allRowsChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4157
            clearSelectionAndLeadAnchor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4158
            resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4163
     * Repaints the sort of sorted rows in response to a TableModelEvent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4165
    private void repaintSortedRows(ModelChange change) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4166
        if (change.startModelIndex > change.endModelIndex ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4167
                change.startModelIndex + 10 < change.endModelIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4168
            // Too much has changed, punt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4169
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4170
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4172
        int eventColumn = change.event.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4173
        int columnViewIndex = eventColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4174
        if (columnViewIndex == TableModelEvent.ALL_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4175
            columnViewIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4177
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4178
            columnViewIndex = convertColumnIndexToView(columnViewIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4179
            if (columnViewIndex == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4180
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4181
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4183
        int modelIndex = change.startModelIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4184
        while (modelIndex <= change.endModelIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4185
            int viewIndex = convertRowIndexToView(modelIndex++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4186
            if (viewIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4187
                Rectangle dirty = getCellRect(viewIndex, columnViewIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4188
                                              false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4189
                int x = dirty.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4190
                int w = dirty.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4191
                if (eventColumn == TableModelEvent.ALL_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4192
                    x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4193
                    w = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4194
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4195
                repaint(x, dirty.y, w, dirty.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4196
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4201
     * Restores the selection after a model event/sort order changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4202
     * All coordinates are in terms of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4204
    private void restoreSortingSelection(int[] selection, int lead,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4205
            ModelChange change) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4206
        // Convert the selection from model to view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4207
        for (int i = selection.length - 1; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4208
            selection[i] = convertRowIndexToView(selection[i], change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4210
        lead = convertRowIndexToView(lead, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4212
        // Check for the common case of no change in selection for 1 row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4213
        if (selection.length == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4214
            (selection.length == 1 && selection[0] == getSelectedRow())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4215
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4217
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4218
        // And apply the new selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4219
        selectionModel.setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4220
        selectionModel.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4221
        for (int i = selection.length - 1; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4222
            if (selection[i] != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4223
                selectionModel.addSelectionInterval(selection[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4224
                                                    selection[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4227
        SwingUtilities2.setLeadAnchorWithoutSelection(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4228
                selectionModel, lead, lead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4229
        selectionModel.setValueIsAdjusting(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4231
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4233
     * Restores the editing row after a model event/sort order change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4235
     * @param editingRow new index of the editingRow, in terms of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4237
    private void restoreSortingEditingRow(int editingRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4238
        if (editingRow == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4239
            // Editing row no longer being shown, cancel editing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4240
            TableCellEditor editor = getCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4241
            if (editor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4242
                // First try and cancel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4243
                editor.cancelCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4244
                if (getCellEditor() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4245
                    // CellEditor didn't cede control, forcefully
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4246
                    // remove it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4247
                    removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4248
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4249
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4251
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4252
            // Repositioning handled in BasicTableUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4253
            this.editingRow = editingRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4254
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4257
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4258
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4259
     * Notifies the sorter of a change in the underlying model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4261
    private void notifySorter(ModelChange change) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4262
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4263
            ignoreSortChange = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4264
            sorterChanged = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4265
            switch(change.type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4266
            case TableModelEvent.UPDATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4267
                if (change.event.getLastRow() == Integer.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4268
                    sortManager.sorter.allRowsChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4269
                } else if (change.event.getColumn() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4270
                           TableModelEvent.ALL_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4271
                    sortManager.sorter.rowsUpdated(change.startModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4272
                                       change.endModelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4273
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4274
                    sortManager.sorter.rowsUpdated(change.startModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4275
                                       change.endModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4276
                                       change.event.getColumn());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4277
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4278
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4279
            case TableModelEvent.INSERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4280
                sortManager.sorter.rowsInserted(change.startModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4281
                                    change.endModelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4282
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4283
            case TableModelEvent.DELETE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4284
                sortManager.sorter.rowsDeleted(change.startModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4285
                                   change.endModelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4286
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4288
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4289
            ignoreSortChange = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4294
     * Converts a model index to view index.  This is called when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4295
     * sorter or model changes and sorting is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4296
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4297
     * @param change describes the TableModelEvent that initiated the change;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4298
     *        will be null if called as the result of a sort
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4299
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4300
    private int convertRowIndexToView(int modelIndex, ModelChange change) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4301
        if (modelIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4302
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4304
        if (change != null && modelIndex >= change.startModelIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4305
            if (change.type == TableModelEvent.INSERT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4306
                if (modelIndex + change.length >= change.modelRowCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4307
                    return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4308
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4309
                return sortManager.sorter.convertRowIndexToView(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4310
                        modelIndex + change.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4311
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4312
            else if (change.type == TableModelEvent.DELETE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4313
                if (modelIndex <= change.endModelIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4314
                    // deleted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4315
                    return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4316
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4317
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4318
                    if (modelIndex - change.length >= change.modelRowCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4319
                        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4320
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4321
                    return sortManager.sorter.convertRowIndexToView(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4322
                            modelIndex - change.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4323
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4324
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4325
            // else, updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4327
        if (modelIndex >= getModel().getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4328
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4330
        return sortManager.sorter.convertRowIndexToView(modelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4333
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4334
     * Converts the selection to model coordinates.  This is used when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4335
     * the model changes or the sorter changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4337
    private int[] convertSelectionToModel(RowSorterEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4338
        int[] selection = getSelectedRows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4339
        for (int i = selection.length - 1; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4340
            selection[i] = convertRowIndexToModel(e, selection[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4342
        return selection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4344
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4345
    private int convertRowIndexToModel(RowSorterEvent e, int viewIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4346
        if (e != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4347
            if (e.getPreviousRowCount() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4348
                return viewIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4349
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4350
            // range checking handled by RowSorterEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4351
            return e.convertPreviousRowIndexToModel(viewIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4353
        // Make sure the viewIndex is valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4354
        if (viewIndex < 0 || viewIndex >= getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4355
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4357
        return convertRowIndexToModel(viewIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4359
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4360
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4361
// Implementing TableModelListener interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4362
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4363
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4364
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4365
     * Invoked when this table's <code>TableModel</code> generates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4366
     * a <code>TableModelEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4367
     * The <code>TableModelEvent</code> should be constructed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4368
     * coordinate system of the model; the appropriate mapping to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4369
     * view coordinate system is performed by this <code>JTable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4370
     * when it receives the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4371
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4372
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4373
     * are used internally by <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4374
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4375
     * Note that as of 1.3, this method clears the selection, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4377
    public void tableChanged(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4378
        if (e == null || e.getFirstRow() == TableModelEvent.HEADER_ROW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4379
            // The whole thing changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4380
            clearSelectionAndLeadAnchor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4381
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4382
            rowModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4383
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4384
            if (sortManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4385
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4386
                    ignoreSortChange = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4387
                    sortManager.sorter.modelStructureChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4388
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4389
                    ignoreSortChange = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4390
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4391
                sortManager.allChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4392
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4393
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4394
            if (getAutoCreateColumnsFromModel()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4395
                // This will effect invalidation of the JTable and JTableHeader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4396
                createDefaultColumnsFromModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4397
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4398
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4400
            resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4401
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4403
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4404
        if (sortManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4405
            sortedTableChanged(null, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4406
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4408
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4409
        // The totalRowHeight calculated below will be incorrect if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4410
        // there are variable height rows. Repaint the visible region,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4411
        // but don't return as a revalidate may be necessary as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4412
        if (rowModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4413
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4416
        if (e.getType() == TableModelEvent.INSERT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4417
            tableRowsInserted(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4418
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4421
        if (e.getType() == TableModelEvent.DELETE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4422
            tableRowsDeleted(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4423
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4426
        int modelColumn = e.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4427
        int start = e.getFirstRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4428
        int end = e.getLastRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4430
        Rectangle dirtyRegion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4431
        if (modelColumn == TableModelEvent.ALL_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4432
            // 1 or more rows changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4433
            dirtyRegion = new Rectangle(0, start * getRowHeight(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4434
                                        getColumnModel().getTotalColumnWidth(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4436
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4437
            // A cell or column of cells has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4438
            // Unlike the rest of the methods in the JTable, the TableModelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4439
            // uses the coordinate system of the model instead of the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4440
            // This is the only place in the JTable where this "reverse mapping"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4441
            // is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4442
            int column = convertColumnIndexToView(modelColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4443
            dirtyRegion = getCellRect(start, column, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4445
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4446
        // Now adjust the height of the dirty region according to the value of "end".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4447
        // Check for Integer.MAX_VALUE as this will cause an overflow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4448
        if (end != Integer.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4449
            dirtyRegion.height = (end-start+1)*getRowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4450
            repaint(dirtyRegion.x, dirtyRegion.y, dirtyRegion.width, dirtyRegion.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4452
        // In fact, if the end is Integer.MAX_VALUE we need to revalidate anyway
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4453
        // because the scrollbar may need repainting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4454
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4455
            clearSelectionAndLeadAnchor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4456
            resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4457
            rowModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4459
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4460
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4461
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4462
     * Invoked when rows have been inserted into the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4463
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4464
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4465
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4466
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4467
     * @param e the TableModelEvent encapsulating the insertion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4468
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4469
    private void tableRowsInserted(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4470
        int start = e.getFirstRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4471
        int end = e.getLastRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4472
        if (start < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4473
            start = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4475
        if (end < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4476
            end = getRowCount()-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4479
        // Adjust the selection to account for the new rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4480
        int length = end - start + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4481
        selectionModel.insertIndexInterval(start, length, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4483
        // If we have variable height rows, adjust the row model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4484
        if (rowModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4485
            rowModel.insertEntries(start, length, getRowHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4487
        int rh = getRowHeight() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4488
        Rectangle drawRect = new Rectangle(0, start * rh,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4489
                                        getColumnModel().getTotalColumnWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4490
                                           (getRowCount()-start) * rh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4491
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4492
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4493
        // PENDING(milne) revalidate calls repaint() if parent is a ScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4494
        // repaint still required in the unusual case where there is no ScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4495
        repaint(drawRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4497
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4498
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4499
     * Invoked when rows have been removed from the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4500
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4501
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4502
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4503
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4504
     * @param e the TableModelEvent encapsulating the deletion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4505
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4506
    private void tableRowsDeleted(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4507
        int start = e.getFirstRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4508
        int end = e.getLastRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4509
        if (start < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4510
            start = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4512
        if (end < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4513
            end = getRowCount()-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4514
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4515
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4516
        int deletedCount = end - start + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4517
        int previousRowCount = getRowCount() + deletedCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4518
        // Adjust the selection to account for the new rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4519
        selectionModel.removeIndexInterval(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4520
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4521
        // If we have variable height rows, adjust the row model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4522
        if (rowModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4523
            rowModel.removeEntries(start, deletedCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4525
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4526
        int rh = getRowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4527
        Rectangle drawRect = new Rectangle(0, start * rh,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4528
                                        getColumnModel().getTotalColumnWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4529
                                        (previousRowCount - start) * rh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4530
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4531
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4532
        // PENDING(milne) revalidate calls repaint() if parent is a ScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4533
        // repaint still required in the unusual case where there is no ScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4534
        repaint(drawRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4536
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4537
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4538
// Implementing TableColumnModelListener interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4539
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4541
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4542
     * Invoked when a column is added to the table column model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4543
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4544
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4545
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4546
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4547
     * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4548
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4549
    public void columnAdded(TableColumnModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4550
        // If I'm currently editing, then I should stop editing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4551
        if (isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4552
            removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4553
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4554
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4556
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4557
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4558
     * Invoked when a column is removed from the table column model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4559
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4560
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4561
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4562
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4563
     * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4564
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4565
    public void columnRemoved(TableColumnModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4566
        // If I'm currently editing, then I should stop editing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4567
        if (isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4568
            removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4570
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4572
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4573
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4574
     * Invoked when a column is repositioned. If a cell is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4575
     * edited, then editing is stopped and the cell is redrawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4576
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4577
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4578
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4579
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4580
     * @param e   the event received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4581
     * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4582
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4583
    public void columnMoved(TableColumnModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4584
        // If I'm currently editing, then I should stop editing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4585
        if (isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4586
            removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4587
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4588
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4589
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4590
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4591
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4592
     * Invoked when a column is moved due to a margin change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4593
     * If a cell is being edited, then editing is stopped and the cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4594
     * is redrawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4595
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4596
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4597
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4598
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4599
     * @param  e    the event received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4600
     * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4601
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4602
    public void columnMarginChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4603
        if (isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4604
            removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4605
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4606
        TableColumn resizingColumn = getResizingColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4607
        // Need to do this here, before the parent's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4608
        // layout manager calls getPreferredSize().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4609
        if (resizingColumn != null && autoResizeMode == AUTO_RESIZE_OFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4610
            resizingColumn.setPreferredWidth(resizingColumn.getWidth());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4611
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4612
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4613
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4614
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4615
    private int limit(int i, int a, int b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4616
        return Math.min(b, Math.max(i, a));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4617
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4618
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4619
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4620
     * Invoked when the selection model of the <code>TableColumnModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4621
     * is changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4622
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4623
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4624
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4625
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4626
     * @param  e  the event received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4627
     * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4628
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4629
    public void columnSelectionChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4630
        boolean isAdjusting = e.getValueIsAdjusting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4631
        if (columnSelectionAdjusting && !isAdjusting) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4632
            // The assumption is that when the model is no longer adjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4633
            // we will have already gotten all the changes, and therefore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4634
            // don't need to do an additional paint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4635
            columnSelectionAdjusting = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4636
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4638
        columnSelectionAdjusting = isAdjusting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4639
        // The getCellRect() call will fail unless there is at least one row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4640
        if (getRowCount() <= 0 || getColumnCount() <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4641
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4643
        int firstIndex = limit(e.getFirstIndex(), 0, getColumnCount()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4644
        int lastIndex = limit(e.getLastIndex(), 0, getColumnCount()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4645
        int minRow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4646
        int maxRow = getRowCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4647
        if (getRowSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4648
            minRow = selectionModel.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4649
            maxRow = selectionModel.getMaxSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4650
            int leadRow = getAdjustedIndex(selectionModel.getLeadSelectionIndex(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4651
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4652
            if (minRow == -1 || maxRow == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4653
                if (leadRow == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4654
                    // nothing to repaint, return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4655
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4656
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4657
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4658
                // only thing to repaint is the lead
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4659
                minRow = maxRow = leadRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4660
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4661
                // We need to consider more than just the range between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4662
                // the min and max selected index. The lead row, which could
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4663
                // be outside this range, should be considered also.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4664
                if (leadRow != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4665
                    minRow = Math.min(minRow, leadRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4666
                    maxRow = Math.max(maxRow, leadRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4667
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4668
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4669
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4670
        Rectangle firstColumnRect = getCellRect(minRow, firstIndex, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4671
        Rectangle lastColumnRect = getCellRect(maxRow, lastIndex, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4672
        Rectangle dirtyRegion = firstColumnRect.union(lastColumnRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4673
        repaint(dirtyRegion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4674
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4675
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4676
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4677
// Implementing ListSelectionListener interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4678
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4679
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4680
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4681
     * Invoked when the row selection changes -- repaints to show the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4682
     * selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4683
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4684
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4685
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4686
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4687
     * @param e   the event received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4688
     * @see ListSelectionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4689
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4690
    public void valueChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4691
        if (sortManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4692
            sortManager.viewSelectionChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4694
        boolean isAdjusting = e.getValueIsAdjusting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4695
        if (rowSelectionAdjusting && !isAdjusting) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4696
            // The assumption is that when the model is no longer adjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4697
            // we will have already gotten all the changes, and therefore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4698
            // don't need to do an additional paint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4699
            rowSelectionAdjusting = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4700
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4701
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4702
        rowSelectionAdjusting = isAdjusting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4703
        // The getCellRect() calls will fail unless there is at least one column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4704
        if (getRowCount() <= 0 || getColumnCount() <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4705
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4706
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4707
        int firstIndex = limit(e.getFirstIndex(), 0, getRowCount()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4708
        int lastIndex = limit(e.getLastIndex(), 0, getRowCount()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4709
        Rectangle firstRowRect = getCellRect(firstIndex, 0, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4710
        Rectangle lastRowRect = getCellRect(lastIndex, getColumnCount()-1, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4711
        Rectangle dirtyRegion = firstRowRect.union(lastRowRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4712
        repaint(dirtyRegion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4713
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4714
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4715
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4716
// Implementing the CellEditorListener interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4717
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4718
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4719
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4720
     * Invoked when editing is finished. The changes are saved and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4721
     * editor is discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4722
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4723
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4724
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4725
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4726
     * @param  e  the event received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4727
     * @see CellEditorListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4728
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4729
    public void editingStopped(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4730
        // Take in the new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4731
        TableCellEditor editor = getCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4732
        if (editor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4733
            Object value = editor.getCellEditorValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4734
            setValueAt(value, editingRow, editingColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4735
            removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4736
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4737
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4738
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4739
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4740
     * Invoked when editing is canceled. The editor object is discarded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4741
     * and the cell is rendered once again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4742
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4743
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4744
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4745
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4746
     * @param  e  the event received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4747
     * @see CellEditorListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4748
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4749
    public void editingCanceled(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4750
        removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4751
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4752
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4753
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4754
// Implementing the Scrollable interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4755
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4756
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4757
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4758
     * Sets the preferred size of the viewport for this table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4759
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4760
     * @param size  a <code>Dimension</code> object specifying the <code>preferredSize</code> of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4761
     *              <code>JViewport</code> whose view is this table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4762
     * @see Scrollable#getPreferredScrollableViewportSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4763
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4764
     * description: The preferred size of the viewport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4765
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4766
    public void setPreferredScrollableViewportSize(Dimension size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4767
        preferredViewportSize = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4768
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4769
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4770
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4771
     * Returns the preferred size of the viewport for this table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4772
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4773
     * @return a <code>Dimension</code> object containing the <code>preferredSize</code> of the <code>JViewport</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4774
     *         which displays this table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4775
     * @see Scrollable#getPreferredScrollableViewportSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4776
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4777
    public Dimension getPreferredScrollableViewportSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4778
        return preferredViewportSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4779
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4780
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4781
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4782
     * Returns the scroll increment (in pixels) that completely exposes one new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4783
     * row or column (depending on the orientation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4784
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4785
     * This method is called each time the user requests a unit scroll.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4786
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4787
     * @param visibleRect the view area visible within the viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4788
     * @param orientation either <code>SwingConstants.VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4789
     *                  or <code>SwingConstants.HORIZONTAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4790
     * @param direction less than zero to scroll up/left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4791
     *                  greater than zero for down/right
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4792
     * @return the "unit" increment for scrolling in the specified direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4793
     * @see Scrollable#getScrollableUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4794
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4795
    public int getScrollableUnitIncrement(Rectangle visibleRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4796
                                          int orientation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4797
                                          int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4798
        int leadingRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4799
        int leadingCol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4800
        Rectangle leadingCellRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4801
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4802
        int leadingVisibleEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4803
        int leadingCellEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4804
        int leadingCellSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4805
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4806
        leadingRow = getLeadingRow(visibleRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4807
        leadingCol = getLeadingCol(visibleRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4808
        if (orientation == SwingConstants.VERTICAL && leadingRow < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4809
            // Couldn't find leading row - return some default value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4810
            return getRowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4811
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4812
        else if (orientation == SwingConstants.HORIZONTAL && leadingCol < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4813
            // Couldn't find leading col - return some default value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4814
            return 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4815
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4816
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4817
        // Note that it's possible for one of leadingCol or leadingRow to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4818
        // -1, depending on the orientation.  This is okay, as getCellRect()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4819
        // still provides enough information to calculate the unit increment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4820
        leadingCellRect = getCellRect(leadingRow, leadingCol, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4821
        leadingVisibleEdge = leadingEdge(visibleRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4822
        leadingCellEdge = leadingEdge(leadingCellRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4823
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4824
        if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4825
            leadingCellSize = leadingCellRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4826
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4827
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4828
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4829
            leadingCellSize = leadingCellRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4830
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4831
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4832
        // 4 cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4833
        // #1: Leading cell fully visible, reveal next cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4834
        // #2: Leading cell fully visible, hide leading cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4835
        // #3: Leading cell partially visible, hide rest of leading cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4836
        // #4: Leading cell partially visible, reveal rest of leading cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4837
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4838
        if (leadingVisibleEdge == leadingCellEdge) { // Leading cell is fully
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4839
                                                     // visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4840
            // Case #1: Reveal previous cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4841
            if (direction < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4842
                int retVal = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4843
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4844
                if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4845
                    // Loop past any zero-height rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4846
                    while (--leadingRow >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4847
                        retVal = getRowHeight(leadingRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4848
                        if (retVal != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4849
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4850
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4851
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4852
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4853
                else { // HORIZONTAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4854
                    // Loop past any zero-width cols
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4855
                    while (--leadingCol >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4856
                        retVal = getCellRect(leadingRow, leadingCol, true).width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4857
                        if (retVal != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4858
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4859
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4860
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4861
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4862
                return retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4863
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4864
            else { // Case #2: hide leading cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4865
                return leadingCellSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4866
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4867
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4868
        else { // Leading cell is partially hidden
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4869
            // Compute visible, hidden portions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4870
            int hiddenAmt = Math.abs(leadingVisibleEdge - leadingCellEdge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4871
            int visibleAmt = leadingCellSize - hiddenAmt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4872
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4873
            if (direction > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4874
                // Case #3: hide showing portion of leading cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4875
                return visibleAmt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4876
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4877
            else { // Case #4: reveal hidden portion of leading cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4878
                return hiddenAmt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4879
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4880
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4881
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4882
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4883
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4884
     * Returns <code>visibleRect.height</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4885
     * <code>visibleRect.width</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4886
     * depending on this table's orientation.  Note that as of Swing 1.1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4887
     * (Java 2 v 1.2.2) the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4888
     * returned will ensure that the viewport is cleanly aligned on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4889
     * a row boundary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4890
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4891
     * @return <code>visibleRect.height</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4892
     *                                  <code>visibleRect.width</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4893
     *                                  per the orientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4894
     * @see Scrollable#getScrollableBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4895
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4896
    public int getScrollableBlockIncrement(Rectangle visibleRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4897
            int orientation, int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4898
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4899
        if (getRowCount() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4900
            // Short-circuit empty table model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4901
            if (SwingConstants.VERTICAL == orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4902
                int rh = getRowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4903
                return (rh > 0) ? Math.max(rh, (visibleRect.height / rh) * rh) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4904
                                  visibleRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4905
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4906
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4907
                return visibleRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4908
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4909
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4910
        // Shortcut for vertical scrolling of a table w/ uniform row height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4911
        if (null == rowModel && SwingConstants.VERTICAL == orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4912
            int row = rowAtPoint(visibleRect.getLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4913
            assert row != -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4914
            int col = columnAtPoint(visibleRect.getLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4915
            Rectangle cellRect = getCellRect(row, col, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4916
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4917
            if (cellRect.y == visibleRect.y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4918
                int rh = getRowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4919
                assert rh > 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4920
                return Math.max(rh, (visibleRect.height / rh) * rh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4921
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4922
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4923
        if (direction < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4924
            return getPreviousBlockIncrement(visibleRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4925
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4926
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4927
            return getNextBlockIncrement(visibleRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4928
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4929
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4930
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4931
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4932
     * Called to get the block increment for upward scrolling in cases of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4933
     * horizontal scrolling, or for vertical scrolling of a table with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4934
     * variable row heights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4935
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4936
    private int getPreviousBlockIncrement(Rectangle visibleRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4937
                                          int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4938
        // Measure back from visible leading edge
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4939
        // If we hit the cell on its leading edge, it becomes the leading cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4940
        // Else, use following cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4941
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4942
        int row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4943
        int col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4944
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4945
        int   newEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4946
        Point newCellLoc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4947
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4948
        int visibleLeadingEdge = leadingEdge(visibleRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4949
        boolean leftToRight = getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4950
        int newLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4951
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4952
        // Roughly determine the new leading edge by measuring back from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4953
        // leading visible edge by the size of the visible rect, and find the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4954
        // cell there.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4955
        if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4956
            newEdge = visibleLeadingEdge - visibleRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4957
            int x = visibleRect.x + (leftToRight ? 0 : visibleRect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4958
            newCellLoc = new Point(x, newEdge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4959
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4960
        else if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4961
            newEdge = visibleLeadingEdge - visibleRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4962
            newCellLoc = new Point(newEdge, visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4963
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4964
        else { // Horizontal, right-to-left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4965
            newEdge = visibleLeadingEdge + visibleRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4966
            newCellLoc = new Point(newEdge - 1, visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4968
        row = rowAtPoint(newCellLoc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4969
        col = columnAtPoint(newCellLoc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4970
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4971
        // If we're measuring past the beginning of the table, we get an invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4972
        // cell.  Just go to the beginning of the table in this case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4973
        if (orientation == SwingConstants.VERTICAL & row < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4974
            newLeadingEdge = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4975
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4976
        else if (orientation == SwingConstants.HORIZONTAL & col < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4977
            if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4978
                newLeadingEdge = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4979
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4980
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4981
                newLeadingEdge = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4982
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4983
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4984
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4985
            // Refine our measurement
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4986
            Rectangle newCellRect = getCellRect(row, col, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4987
            int newCellLeadingEdge = leadingEdge(newCellRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4988
            int newCellTrailingEdge = trailingEdge(newCellRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4989
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4990
            // Usually, we hit in the middle of newCell, and want to scroll to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4991
            // the beginning of the cell after newCell.  But there are a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4992
            // couple corner cases where we want to scroll to the beginning of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4993
            // newCell itself.  These cases are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4994
            // 1) newCell is so large that it ends at or extends into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4995
            //    visibleRect (newCell is the leading cell, or is adjacent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4996
            //    the leading cell)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4997
            // 2) newEdge happens to fall right on the beginning of a cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4998
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4999
            // Case 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5000
            if ((orientation == SwingConstants.VERTICAL || leftToRight) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5001
                (newCellTrailingEdge >= visibleLeadingEdge)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5002
                newLeadingEdge = newCellLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5003
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5004
            else if (orientation == SwingConstants.HORIZONTAL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5005
                     !leftToRight &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5006
                     newCellTrailingEdge <= visibleLeadingEdge) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5007
                newLeadingEdge = newCellLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5008
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5009
            // Case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5010
            else if (newEdge == newCellLeadingEdge) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5011
                newLeadingEdge = newCellLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5012
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5013
            // Common case: scroll to cell after newCell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5014
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5015
                newLeadingEdge = newCellTrailingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5016
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5017
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5018
        return Math.abs(visibleLeadingEdge - newLeadingEdge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5019
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5021
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5022
     * Called to get the block increment for downward scrolling in cases of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5023
     * horizontal scrolling, or for vertical scrolling of a table with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5024
     * variable row heights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5025
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5026
    private int getNextBlockIncrement(Rectangle visibleRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5027
                                      int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5028
        // Find the cell at the trailing edge.  Return the distance to put
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5029
        // that cell at the leading edge.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5030
        int trailingRow = getTrailingRow(visibleRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5031
        int trailingCol = getTrailingCol(visibleRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5032
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5033
        Rectangle cellRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5034
        boolean cellFillsVis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5036
        int cellLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5037
        int cellTrailingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5038
        int newLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5039
        int visibleLeadingEdge = leadingEdge(visibleRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5041
        // If we couldn't find trailing cell, just return the size of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5042
        // visibleRect.  Note that, for instance, we don't need the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5043
        // trailingCol to proceed if we're scrolling vertically, because
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5044
        // cellRect will still fill in the required dimensions.  This would
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5045
        // happen if we're scrolling vertically, and the table is not wide
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5046
        // enough to fill the visibleRect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5047
        if (orientation == SwingConstants.VERTICAL && trailingRow < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5048
            return visibleRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5049
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5050
        else if (orientation == SwingConstants.HORIZONTAL && trailingCol < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5051
            return visibleRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5052
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5053
        cellRect = getCellRect(trailingRow, trailingCol, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5054
        cellLeadingEdge = leadingEdge(cellRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5055
        cellTrailingEdge = trailingEdge(cellRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5057
        if (orientation == SwingConstants.VERTICAL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5058
            getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5059
            cellFillsVis = cellLeadingEdge <= visibleLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5060
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5061
        else { // Horizontal, right-to-left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5062
            cellFillsVis = cellLeadingEdge >= visibleLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5063
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5065
        if (cellFillsVis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5066
            // The visibleRect contains a single large cell.  Scroll to the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5067
            // of this cell, so the following cell is the first cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5068
            newLeadingEdge = cellTrailingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5069
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5070
        else if (cellTrailingEdge == trailingEdge(visibleRect, orientation)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5071
            // The trailing cell happens to end right at the end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5072
            // visibleRect.  Again, scroll to the beginning of the next cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5073
            newLeadingEdge = cellTrailingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5074
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5075
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5076
            // Common case: the trailing cell is partially visible, and isn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5077
            // big enough to take up the entire visibleRect.  Scroll so it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5078
            // becomes the leading cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5079
            newLeadingEdge = cellLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5080
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5081
        return Math.abs(newLeadingEdge - visibleLeadingEdge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5082
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5084
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5085
     * Return the row at the top of the visibleRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5086
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5087
     * May return -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5088
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5089
    private int getLeadingRow(Rectangle visibleRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5090
        Point leadingPoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5092
        if (getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5093
            leadingPoint = new Point(visibleRect.x, visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5094
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5095
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5096
            leadingPoint = new Point(visibleRect.x + visibleRect.width - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5097
                                     visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5098
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5099
        return rowAtPoint(leadingPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5102
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5103
     * Return the column at the leading edge of the visibleRect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5105
     * May return -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5107
    private int getLeadingCol(Rectangle visibleRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5108
        Point leadingPoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5109
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5110
        if (getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5111
            leadingPoint = new Point(visibleRect.x, visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5113
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5114
            leadingPoint = new Point(visibleRect.x + visibleRect.width - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5115
                                     visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5117
        return columnAtPoint(leadingPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5120
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5121
     * Return the row at the bottom of the visibleRect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5123
     * May return -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5125
    private int getTrailingRow(Rectangle visibleRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5126
        Point trailingPoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5128
        if (getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5129
            trailingPoint = new Point(visibleRect.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5130
                                      visibleRect.y + visibleRect.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5132
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5133
            trailingPoint = new Point(visibleRect.x + visibleRect.width - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5134
                                      visibleRect.y + visibleRect.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5136
        return rowAtPoint(trailingPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5139
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5140
     * Return the column at the trailing edge of the visibleRect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5142
     * May return -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5144
    private int getTrailingCol(Rectangle visibleRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5145
        Point trailingPoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5147
        if (getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5148
            trailingPoint = new Point(visibleRect.x + visibleRect.width - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5149
                                      visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5151
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5152
            trailingPoint = new Point(visibleRect.x, visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5154
        return columnAtPoint(trailingPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5157
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5158
     * Returns the leading edge ("beginning") of the given Rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5159
     * For VERTICAL, this is the top, for left-to-right, the left side, and for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5160
     * right-to-left, the right side.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5162
    private int leadingEdge(Rectangle rect, int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5163
        if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5164
            return rect.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5166
        else if (getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5167
            return rect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5169
        else { // Horizontal, right-to-left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5170
            return rect.x + rect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5173
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5174
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5175
     * Returns the trailing edge ("end") of the given Rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5176
     * For VERTICAL, this is the bottom, for left-to-right, the right side, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5177
     * for right-to-left, the left side.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5179
    private int trailingEdge(Rectangle rect, int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5180
        if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5181
            return rect.y + rect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5183
        else if (getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5184
            return rect.x + rect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5186
        else { // Horizontal, right-to-left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5187
            return rect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5192
     * Returns false if <code>autoResizeMode</code> is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5193
     * <code>AUTO_RESIZE_OFF</code>, which indicates that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5194
     * width of the viewport does not determine the width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5195
     * of the table.  Otherwise returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5197
     * @return false if <code>autoResizeMode</code> is set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5198
     *   to <code>AUTO_RESIZE_OFF</code>, otherwise returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5199
     * @see Scrollable#getScrollableTracksViewportWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5201
    public boolean getScrollableTracksViewportWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5202
        return !(autoResizeMode == AUTO_RESIZE_OFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5206
     * Returns {@code false} to indicate that the height of the viewport does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5207
     * not determine the height of the table, unless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5208
     * {@code getFillsViewportHeight} is {@code true} and the preferred height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5209
     * of the table is smaller than the viewport's height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5211
     * @return {@code false} unless {@code getFillsViewportHeight} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5212
     *         {@code true} and the table needs to be stretched to fill
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5213
     *         the viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5214
     * @see Scrollable#getScrollableTracksViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5215
     * @see #setFillsViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5216
     * @see #getFillsViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5218
    public boolean getScrollableTracksViewportHeight() {
3737
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 2658
diff changeset
  5219
        JViewport port = SwingUtilities2.getViewport(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5220
        return getFillsViewportHeight()
3737
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 2658
diff changeset
  5221
               && port != null
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 2658
diff changeset
  5222
               && port.getHeight() > getPreferredSize().height;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5224
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5226
     * Sets whether or not this table is always made large enough
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5227
     * to fill the height of an enclosing viewport. If the preferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5228
     * height of the table is smaller than the viewport, then the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5229
     * will be stretched to fill the viewport. In other words, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5230
     * ensures the table is never smaller than the viewport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5231
     * The default for this property is {@code false}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5233
     * @param fillsViewportHeight whether or not this table is always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5234
     *        made large enough to fill the height of an enclosing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5235
     *        viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5236
     * @see #getFillsViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5237
     * @see #getScrollableTracksViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5238
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5239
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5240
     *      bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5241
     *      description: Whether or not this table is always made large enough
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5242
     *                   to fill the height of an enclosing viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5244
    public void setFillsViewportHeight(boolean fillsViewportHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5245
        boolean old = this.fillsViewportHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5246
        this.fillsViewportHeight = fillsViewportHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5247
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5248
        firePropertyChange("fillsViewportHeight", old, fillsViewportHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5250
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5252
     * Returns whether or not this table is always made large enough
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5253
     * to fill the height of an enclosing viewport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5255
     * @return whether or not this table is always made large enough
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5256
     *         to fill the height of an enclosing viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5257
     * @see #setFillsViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5258
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5260
    public boolean getFillsViewportHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5261
        return fillsViewportHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5264
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5265
// Protected Methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5266
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5268
    protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5269
                                        int condition, boolean pressed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5270
        boolean retValue = super.processKeyBinding(ks, e, condition, pressed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5272
        // Start editing when a key is typed. UI classes can disable this behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5273
        // by setting the client property JTable.autoStartsEdit to Boolean.FALSE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5274
        if (!retValue && condition == WHEN_ANCESTOR_OF_FOCUSED_COMPONENT &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5275
            isFocusOwner() &&
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  5276
            !Boolean.FALSE.equals(getClientProperty("JTable.autoStartsEdit"))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5277
            // We do not have a binding for the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5278
            Component editorComponent = getEditorComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5279
            if (editorComponent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5280
                // Only attempt to install the editor on a KEY_PRESSED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5281
                if (e == null || e.getID() != KeyEvent.KEY_PRESSED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5282
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5283
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5284
                // Don't start when just a modifier is pressed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5285
                int code = e.getKeyCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5286
                if (code == KeyEvent.VK_SHIFT || code == KeyEvent.VK_CONTROL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5287
                    code == KeyEvent.VK_ALT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5288
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5289
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5290
                // Try to install the editor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5291
                int leadRow = getSelectionModel().getLeadSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5292
                int leadColumn = getColumnModel().getSelectionModel().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5293
                                   getLeadSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5294
                if (leadRow != -1 && leadColumn != -1 && !isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5295
                    if (!editCellAt(leadRow, leadColumn, e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5296
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5297
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5298
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5299
                editorComponent = getEditorComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5300
                if (editorComponent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5301
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5302
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5303
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5304
            // If the editorComponent is a JComponent, pass the event to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5305
            if (editorComponent instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5306
                retValue = ((JComponent)editorComponent).processKeyBinding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5307
                                        (ks, e, WHEN_FOCUSED, pressed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5308
                // If we have started an editor as a result of the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5309
                // pressing a key and the surrendersFocusOnKeystroke property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5310
                // is true, give the focus to the new editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5311
                if (getSurrendersFocusOnKeystroke()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5312
                    editorComponent.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5313
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5314
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5316
        return retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5319
    private void setLazyValue(Hashtable h, Class c, String s) {
4272
f4742294ef29 6795356: Leak caused by javax.swing.UIDefaults.ProxyLazyValue.acc
alexp
parents: 3737
diff changeset
  5320
        h.put(c, new SwingLazyValue(s));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5323
    private void setLazyRenderer(Class c, String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5324
        setLazyValue(defaultRenderersByColumnClass, c, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5328
     * Creates default cell renderers for objects, numbers, doubles, dates,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5329
     * booleans, and icons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5330
     * @see javax.swing.table.DefaultTableCellRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5331
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5332
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5333
    protected void createDefaultRenderers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5334
        defaultRenderersByColumnClass = new UIDefaults(8, 0.75f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5336
        // Objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5337
        setLazyRenderer(Object.class, "javax.swing.table.DefaultTableCellRenderer$UIResource");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5339
        // Numbers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5340
        setLazyRenderer(Number.class, "javax.swing.JTable$NumberRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5341
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5342
        // Doubles and Floats
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5343
        setLazyRenderer(Float.class, "javax.swing.JTable$DoubleRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5344
        setLazyRenderer(Double.class, "javax.swing.JTable$DoubleRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5345
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5346
        // Dates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5347
        setLazyRenderer(Date.class, "javax.swing.JTable$DateRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5349
        // Icons and ImageIcons
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5350
        setLazyRenderer(Icon.class, "javax.swing.JTable$IconRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5351
        setLazyRenderer(ImageIcon.class, "javax.swing.JTable$IconRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5352
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5353
        // Booleans
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5354
        setLazyRenderer(Boolean.class, "javax.swing.JTable$BooleanRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5356
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5358
     * Default Renderers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5359
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5360
    static class NumberRenderer extends DefaultTableCellRenderer.UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5361
        public NumberRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5362
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5363
            setHorizontalAlignment(JLabel.RIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5366
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5367
    static class DoubleRenderer extends NumberRenderer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5368
        NumberFormat formatter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5369
        public DoubleRenderer() { super(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5370
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5371
        public void setValue(Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5372
            if (formatter == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5373
                formatter = NumberFormat.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5374
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5375
            setText((value == null) ? "" : formatter.format(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5379
    static class DateRenderer extends DefaultTableCellRenderer.UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5380
        DateFormat formatter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5381
        public DateRenderer() { super(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5383
        public void setValue(Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5384
            if (formatter==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5385
                formatter = DateFormat.getDateInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5387
            setText((value == null) ? "" : formatter.format(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5390
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5391
    static class IconRenderer extends DefaultTableCellRenderer.UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5392
        public IconRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5393
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5394
            setHorizontalAlignment(JLabel.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5395
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5396
        public void setValue(Object value) { setIcon((value instanceof Icon) ? (Icon)value : null); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5398
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5400
    static class BooleanRenderer extends JCheckBox implements TableCellRenderer, UIResource
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5401
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5402
        private static final Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5403
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5404
        public BooleanRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5405
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5406
            setHorizontalAlignment(JLabel.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5407
            setBorderPainted(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5410
        public Component getTableCellRendererComponent(JTable table, Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5411
                                                       boolean isSelected, boolean hasFocus, int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5412
            if (isSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5413
                setForeground(table.getSelectionForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5414
                super.setBackground(table.getSelectionBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5415
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5416
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5417
                setForeground(table.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5418
                setBackground(table.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5419
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5420
            setSelected((value != null && ((Boolean)value).booleanValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5421
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5422
            if (hasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5423
                setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5424
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5425
                setBorder(noFocusBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5426
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5427
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5428
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5431
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5432
    private void setLazyEditor(Class c, String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5433
        setLazyValue(defaultEditorsByColumnClass, c, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5435
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5436
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5437
     * Creates default cell editors for objects, numbers, and boolean values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5438
     * @see DefaultCellEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5439
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5440
    protected void createDefaultEditors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5441
        defaultEditorsByColumnClass = new UIDefaults(3, 0.75f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5442
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5443
        // Objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5444
        setLazyEditor(Object.class, "javax.swing.JTable$GenericEditor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5445
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5446
        // Numbers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5447
        setLazyEditor(Number.class, "javax.swing.JTable$NumberEditor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5448
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5449
        // Booleans
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5450
        setLazyEditor(Boolean.class, "javax.swing.JTable$BooleanEditor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5453
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5454
     * Default Editors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5455
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5456
    static class GenericEditor extends DefaultCellEditor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5458
        Class[] argTypes = new Class[]{String.class};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5459
        java.lang.reflect.Constructor constructor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5460
        Object value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5461
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5462
        public GenericEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5463
            super(new JTextField());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5464
            getComponent().setName("Table.editor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5465
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5466
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5467
        public boolean stopCellEditing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5468
            String s = (String)super.getCellEditorValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5469
            // Here we are dealing with the case where a user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5470
            // has deleted the string value in a cell, possibly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5471
            // after a failed validation. Return null, so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5472
            // they have the option to replace the value with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5473
            // null or use escape to restore the original.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5474
            // For Strings, return "" for backward compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5475
            if ("".equals(s)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5476
                if (constructor.getDeclaringClass() == String.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5477
                    value = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5478
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5479
                super.stopCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5480
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5481
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5482
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5483
                value = constructor.newInstance(new Object[]{s});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5484
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5485
            catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5486
                ((JComponent)getComponent()).setBorder(new LineBorder(Color.red));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5487
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5488
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5489
            return super.stopCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5491
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5492
        public Component getTableCellEditorComponent(JTable table, Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5493
                                                 boolean isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5494
                                                 int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5495
            this.value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5496
            ((JComponent)getComponent()).setBorder(new LineBorder(Color.black));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5497
            try {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  5498
                Class<?> type = table.getColumnClass(column);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5499
                // Since our obligation is to produce a value which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5500
                // assignable for the required type it is OK to use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5501
                // String constructor for columns which are declared
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5502
                // to contain Objects. A String is an Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5503
                if (type == Object.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5504
                    type = String.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5505
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5506
                constructor = type.getConstructor(argTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5507
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5508
            catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5509
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5510
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5511
            return super.getTableCellEditorComponent(table, value, isSelected, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5513
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5514
        public Object getCellEditorValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5515
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5519
    static class NumberEditor extends GenericEditor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5520
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5521
        public NumberEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5522
            ((JTextField)getComponent()).setHorizontalAlignment(JTextField.RIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5525
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5526
    static class BooleanEditor extends DefaultCellEditor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5527
        public BooleanEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5528
            super(new JCheckBox());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5529
            JCheckBox checkBox = (JCheckBox)getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5530
            checkBox.setHorizontalAlignment(JCheckBox.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5532
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5533
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5534
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5535
     * Initializes table properties to their default values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5536
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5537
    protected void initializeLocalVars() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5538
        updateSelectionOnSort = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5539
        setOpaque(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5540
        createDefaultRenderers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5541
        createDefaultEditors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5542
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5543
        setTableHeader(createDefaultTableHeader());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5544
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5545
        setShowGrid(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5546
        setAutoResizeMode(AUTO_RESIZE_SUBSEQUENT_COLUMNS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5547
        setRowHeight(16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5548
        isRowHeightSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5549
        setRowMargin(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5550
        setRowSelectionAllowed(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5551
        setCellEditor(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5552
        setEditingColumn(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5553
        setEditingRow(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5554
        setSurrendersFocusOnKeystroke(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5555
        setPreferredScrollableViewportSize(new Dimension(450, 400));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5556
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5557
        // I'm registered to do tool tips so we can draw tips for the renderers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5558
        ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5559
        toolTipManager.registerComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5560
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5561
        setAutoscrolls(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5563
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5564
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5565
     * Returns the default table model object, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5566
     * a <code>DefaultTableModel</code>.  A subclass can override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5567
     * method to return a different table model object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5568
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5569
     * @return the default table model object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5570
     * @see javax.swing.table.DefaultTableModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5571
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5572
    protected TableModel createDefaultDataModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5573
        return new DefaultTableModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5574
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5575
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5576
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5577
     * Returns the default column model object, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5578
     * a <code>DefaultTableColumnModel</code>.  A subclass can override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5579
     * method to return a different column model object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5580
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5581
     * @return the default column model object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5582
     * @see javax.swing.table.DefaultTableColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5583
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5584
    protected TableColumnModel createDefaultColumnModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5585
        return new DefaultTableColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5586
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5587
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5588
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5589
     * Returns the default selection model object, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5590
     * a <code>DefaultListSelectionModel</code>.  A subclass can override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5591
     * method to return a different selection model object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5592
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5593
     * @return the default selection model object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5594
     * @see javax.swing.DefaultListSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5595
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5596
    protected ListSelectionModel createDefaultSelectionModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5597
        return new DefaultListSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5598
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5599
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5600
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5601
     * Returns the default table header object, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5602
     * a <code>JTableHeader</code>.  A subclass can override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5603
     * method to return a different table header object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5604
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5605
     * @return the default table header object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5606
     * @see javax.swing.table.JTableHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5607
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5608
    protected JTableHeader createDefaultTableHeader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5609
        return new JTableHeader(columnModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5610
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5611
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5612
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5613
     * Equivalent to <code>revalidate</code> followed by <code>repaint</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5614
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5615
    protected void resizeAndRepaint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5616
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5617
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5618
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5619
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5620
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5621
     * Returns the active cell editor, which is {@code null} if the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5622
     * is not currently editing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5623
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5624
     * @return the {@code TableCellEditor} that does the editing,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5625
     *         or {@code null} if the table is not currently editing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5626
     * @see #cellEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5627
     * @see #getCellEditor(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5628
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5629
    public TableCellEditor getCellEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5630
        return cellEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5631
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5632
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5633
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5634
     * Sets the active cell editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5635
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5636
     * @param anEditor the active cell editor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5637
     * @see #cellEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5638
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5639
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5640
     *  description: The table's active cell editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5641
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5642
    public void setCellEditor(TableCellEditor anEditor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5643
        TableCellEditor oldEditor = cellEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5644
        cellEditor = anEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5645
        firePropertyChange("tableCellEditor", oldEditor, anEditor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5646
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5647
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5648
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5649
     * Sets the <code>editingColumn</code> variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5650
     * @param aColumn  the column of the cell to be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5651
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5652
     * @see #editingColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5653
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5654
    public void setEditingColumn(int aColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5655
        editingColumn = aColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5656
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5657
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5658
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5659
     * Sets the <code>editingRow</code> variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5660
     * @param aRow  the row of the cell to be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5661
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5662
     * @see #editingRow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5663
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5664
    public void setEditingRow(int aRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5665
        editingRow = aRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5666
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5667
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5668
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5669
     * Returns an appropriate renderer for the cell specified by this row and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5670
     * column. If the <code>TableColumn</code> for this column has a non-null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5671
     * renderer, returns that.  If not, finds the class of the data in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5672
     * this column (using <code>getColumnClass</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5673
     * and returns the default renderer for this type of data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5674
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5675
     * <b>Note:</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5676
     * Throughout the table package, the internal implementations always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5677
     * use this method to provide renderers so that this default behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5678
     * can be safely overridden by a subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5679
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5680
     * @param row       the row of the cell to render, where 0 is the first row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5681
     * @param column    the column of the cell to render,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5682
     *                  where 0 is the first column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5683
     * @return the assigned renderer; if <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5684
     *                  returns the default renderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5685
     *                  for this type of object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5686
     * @see javax.swing.table.DefaultTableCellRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5687
     * @see javax.swing.table.TableColumn#setCellRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5688
     * @see #setDefaultRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5689
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5690
    public TableCellRenderer getCellRenderer(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5691
        TableColumn tableColumn = getColumnModel().getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5692
        TableCellRenderer renderer = tableColumn.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5693
        if (renderer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5694
            renderer = getDefaultRenderer(getColumnClass(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5695
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5696
        return renderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5697
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5698
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5699
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5700
     * Prepares the renderer by querying the data model for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5701
     * value and selection state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5702
     * of the cell at <code>row</code>, <code>column</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5703
     * Returns the component (may be a <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5704
     * or a <code>JComponent</code>) under the event location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5705
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5706
     * During a printing operation, this method will configure the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5707
     * renderer without indicating selection or focus, to prevent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5708
     * them from appearing in the printed output. To do other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5709
     * customizations based on whether or not the table is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5710
     * printed, you can check the value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5711
     * {@link javax.swing.JComponent#isPaintingForPrint()}, either here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5712
     * or within custom renderers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5713
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5714
     * <b>Note:</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5715
     * Throughout the table package, the internal implementations always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5716
     * use this method to prepare renderers so that this default behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5717
     * can be safely overridden by a subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5718
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5719
     * @param renderer  the <code>TableCellRenderer</code> to prepare
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5720
     * @param row       the row of the cell to render, where 0 is the first row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5721
     * @param column    the column of the cell to render,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5722
     *                  where 0 is the first column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5723
     * @return          the <code>Component</code> under the event location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5724
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5725
    public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5726
        Object value = getValueAt(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5727
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5728
        boolean isSelected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5729
        boolean hasFocus = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5730
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5731
        // Only indicate the selection and focused cell if not printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5732
        if (!isPaintingForPrint()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5733
            isSelected = isCellSelected(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5734
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5735
            boolean rowIsLead =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5736
                (selectionModel.getLeadSelectionIndex() == row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5737
            boolean colIsLead =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5738
                (columnModel.getSelectionModel().getLeadSelectionIndex() == column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5739
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5740
            hasFocus = (rowIsLead && colIsLead) && isFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5741
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5742
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5743
        return renderer.getTableCellRendererComponent(this, value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5744
                                                      isSelected, hasFocus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5745
                                                      row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5746
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5747
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5748
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5749
     * Returns an appropriate editor for the cell specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5750
     * <code>row</code> and <code>column</code>. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5751
     * <code>TableColumn</code> for this column has a non-null editor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5752
     * returns that.  If not, finds the class of the data in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5753
     * column (using <code>getColumnClass</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5754
     * and returns the default editor for this type of data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5755
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5756
     * <b>Note:</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5757
     * Throughout the table package, the internal implementations always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5758
     * use this method to provide editors so that this default behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5759
     * can be safely overridden by a subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5760
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5761
     * @param row       the row of the cell to edit, where 0 is the first row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5762
     * @param column    the column of the cell to edit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5763
     *                  where 0 is the first column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5764
     * @return          the editor for this cell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5765
     *                  if <code>null</code> return the default editor for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5766
     *                  this type of cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5767
     * @see DefaultCellEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5768
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5769
    public TableCellEditor getCellEditor(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5770
        TableColumn tableColumn = getColumnModel().getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5771
        TableCellEditor editor = tableColumn.getCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5772
        if (editor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5773
            editor = getDefaultEditor(getColumnClass(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5774
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5775
        return editor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5776
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5777
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5778
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5779
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5780
     * Prepares the editor by querying the data model for the value and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5781
     * selection state of the cell at <code>row</code>, <code>column</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5782
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5783
     * <b>Note:</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5784
     * Throughout the table package, the internal implementations always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5785
     * use this method to prepare editors so that this default behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5786
     * can be safely overridden by a subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5787
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5788
     * @param editor  the <code>TableCellEditor</code> to set up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5789
     * @param row     the row of the cell to edit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5790
     *                where 0 is the first row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5791
     * @param column  the column of the cell to edit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5792
     *                where 0 is the first column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5793
     * @return the <code>Component</code> being edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5794
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5795
    public Component prepareEditor(TableCellEditor editor, int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5796
        Object value = getValueAt(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5797
        boolean isSelected = isCellSelected(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5798
        Component comp = editor.getTableCellEditorComponent(this, value, isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5799
                                                  row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5800
        if (comp instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5801
            JComponent jComp = (JComponent)comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5802
            if (jComp.getNextFocusableComponent() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5803
                jComp.setNextFocusableComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5804
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5805
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5806
        return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5807
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5808
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5809
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5810
     * Discards the editor object and frees the real estate it used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5811
     * cell rendering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5812
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5813
    public void removeEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5814
        KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5815
            removePropertyChangeListener("permanentFocusOwner", editorRemover);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5816
        editorRemover = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5817
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5818
        TableCellEditor editor = getCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5819
        if(editor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5820
            editor.removeCellEditorListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5821
            if (editorComp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5822
                Component focusOwner =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5823
                        KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5824
                boolean isFocusOwnerInTheTable = focusOwner != null?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5825
                        SwingUtilities.isDescendingFrom(focusOwner, this):false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5826
                remove(editorComp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5827
                if(isFocusOwnerInTheTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5828
                    requestFocusInWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5829
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5830
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5831
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5832
            Rectangle cellRect = getCellRect(editingRow, editingColumn, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5833
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5834
            setCellEditor(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5835
            setEditingColumn(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5836
            setEditingRow(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5837
            editorComp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5838
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5839
            repaint(cellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5840
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5841
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5842
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5843
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5844
// Serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5845
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5846
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5847
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5848
     * See readObject() and writeObject() in JComponent for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5849
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5850
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5851
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5852
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5853
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5854
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5855
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5856
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5857
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5858
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5859
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5860
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5861
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5862
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5863
        throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5864
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5865
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5866
        if ((ui != null) && (getUIClassID().equals(uiClassID))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5867
            ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5868
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5869
        createDefaultRenderers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5870
        createDefaultEditors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5871
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5872
        // If ToolTipText != null, then the tooltip has already been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5873
        // registered by JComponent.readObject() and we don't want
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5874
        // to re-register here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5875
        if (getToolTipText() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5876
            ToolTipManager.sharedInstance().registerComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5877
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5878
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5879
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5880
    /* Called from the JComponent's EnableSerializationFocusListener to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5881
     * do any Swing-specific pre-serialization configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5882
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5883
    void compWriteObjectNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5884
        super.compWriteObjectNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5885
        // If ToolTipText != null, then the tooltip has already been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5886
        // unregistered by JComponent.compWriteObjectNotify()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5887
        if (getToolTipText() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5888
            ToolTipManager.sharedInstance().unregisterComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5889
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5890
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5891
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5892
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5893
     * Returns a string representation of this table. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5894
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5895
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5896
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5897
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5898
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5899
     * @return  a string representation of this table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5900
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5901
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5902
        String gridColorString = (gridColor != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5903
                                  gridColor.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5904
        String showHorizontalLinesString = (showHorizontalLines ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5905
                                            "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5906
        String showVerticalLinesString = (showVerticalLines ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5907
                                          "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5908
        String autoResizeModeString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5909
        if (autoResizeMode == AUTO_RESIZE_OFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5910
            autoResizeModeString = "AUTO_RESIZE_OFF";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5911
        } else if (autoResizeMode == AUTO_RESIZE_NEXT_COLUMN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5912
            autoResizeModeString = "AUTO_RESIZE_NEXT_COLUMN";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5913
        } else if (autoResizeMode == AUTO_RESIZE_SUBSEQUENT_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5914
            autoResizeModeString = "AUTO_RESIZE_SUBSEQUENT_COLUMNS";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5915
        } else if (autoResizeMode == AUTO_RESIZE_LAST_COLUMN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5916
            autoResizeModeString = "AUTO_RESIZE_LAST_COLUMN";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5917
        } else if (autoResizeMode == AUTO_RESIZE_ALL_COLUMNS)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5918
            autoResizeModeString = "AUTO_RESIZE_ALL_COLUMNS";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5919
        } else autoResizeModeString = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5920
        String autoCreateColumnsFromModelString = (autoCreateColumnsFromModel ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5921
                                                   "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5922
        String preferredViewportSizeString = (preferredViewportSize != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5923
                                              preferredViewportSize.toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5924
                                              : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5925
        String rowSelectionAllowedString = (rowSelectionAllowed ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5926
                                            "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5927
        String cellSelectionEnabledString = (cellSelectionEnabled ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5928
                                            "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5929
        String selectionForegroundString = (selectionForeground != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5930
                                            selectionForeground.toString() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5931
                                            "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5932
        String selectionBackgroundString = (selectionBackground != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5933
                                            selectionBackground.toString() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5934
                                            "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5935
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5936
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5937
        ",autoCreateColumnsFromModel=" + autoCreateColumnsFromModelString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5938
        ",autoResizeMode=" + autoResizeModeString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5939
        ",cellSelectionEnabled=" + cellSelectionEnabledString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5940
        ",editingColumn=" + editingColumn +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5941
        ",editingRow=" + editingRow +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5942
        ",gridColor=" + gridColorString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5943
        ",preferredViewportSize=" + preferredViewportSizeString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5944
        ",rowHeight=" + rowHeight +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5945
        ",rowMargin=" + rowMargin +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5946
        ",rowSelectionAllowed=" + rowSelectionAllowedString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5947
        ",selectionBackground=" + selectionBackgroundString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5948
        ",selectionForeground=" + selectionForegroundString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5949
        ",showHorizontalLines=" + showHorizontalLinesString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5950
        ",showVerticalLines=" + showVerticalLinesString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5951
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5952
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5953
    // This class tracks changes in the keyboard focus state. It is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5954
    // when the JTable is editing to determine when to cancel the edit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5955
    // If focus switches to a component outside of the jtable, but in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5956
    // same window, this will cancel editing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5957
    class CellEditorRemover implements PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5958
        KeyboardFocusManager focusManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5959
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5960
        public CellEditorRemover(KeyboardFocusManager fm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5961
            this.focusManager = fm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5962
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5963
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5964
        public void propertyChange(PropertyChangeEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5965
            if (!isEditing() || getClientProperty("terminateEditOnFocusLost") != Boolean.TRUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5966
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5967
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5968
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5969
            Component c = focusManager.getPermanentFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5970
            while (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5971
                if (c == JTable.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5972
                    // focus remains inside the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5973
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5974
                } else if ((c instanceof Window) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5975
                           (c instanceof Applet && c.getParent() == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5976
                    if (c == SwingUtilities.getRoot(JTable.this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5977
                        if (!getCellEditor().stopCellEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5978
                            getCellEditor().cancelCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5979
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5980
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5981
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5982
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5983
                c = c.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5984
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5985
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5986
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5987
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5988
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5989
// Printing Support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5990
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5991
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5992
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5993
     * A convenience method that displays a printing dialog, and then prints
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5994
     * this <code>JTable</code> in mode <code>PrintMode.FIT_WIDTH</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5995
     * with no header or footer text. A modal progress dialog, with an abort
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5996
     * option, will be shown for the duration of printing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5997
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5998
     * Note: In headless mode, no dialogs are shown and printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5999
     * occurs on the default printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6000
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6001
     * @return true, unless printing is cancelled by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6002
     * @throws SecurityException if this thread is not allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6003
     *                           initiate a print job request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6004
     * @throws PrinterException if an error in the print system causes the job
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6005
     *                          to be aborted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6006
     * @see #print(JTable.PrintMode, MessageFormat, MessageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6007
     *             boolean, PrintRequestAttributeSet, boolean, PrintService)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6008
     * @see #getPrintable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6009
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6010
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6011
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6012
    public boolean print() throws PrinterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6014
        return print(PrintMode.FIT_WIDTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6015
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6017
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6018
     * A convenience method that displays a printing dialog, and then prints
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6019
     * this <code>JTable</code> in the given printing mode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6020
     * with no header or footer text. A modal progress dialog, with an abort
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6021
     * option, will be shown for the duration of printing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6022
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6023
     * Note: In headless mode, no dialogs are shown and printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6024
     * occurs on the default printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6025
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6026
     * @param  printMode        the printing mode that the printable should use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6027
     * @return true, unless printing is cancelled by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6028
     * @throws SecurityException if this thread is not allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6029
     *                           initiate a print job request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6030
     * @throws PrinterException if an error in the print system causes the job
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6031
     *                          to be aborted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6032
     * @see #print(JTable.PrintMode, MessageFormat, MessageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6033
     *             boolean, PrintRequestAttributeSet, boolean, PrintService)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6034
     * @see #getPrintable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6035
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6036
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6037
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6038
    public boolean print(PrintMode printMode) throws PrinterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6039
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6040
        return print(printMode, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6041
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6043
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6044
     * A convenience method that displays a printing dialog, and then prints
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6045
     * this <code>JTable</code> in the given printing mode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6046
     * with the specified header and footer text. A modal progress dialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6047
     * with an abort option, will be shown for the duration of printing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6048
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6049
     * Note: In headless mode, no dialogs are shown and printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6050
     * occurs on the default printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6051
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6052
     * @param  printMode        the printing mode that the printable should use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6053
     * @param  headerFormat     a <code>MessageFormat</code> specifying the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6054
     *                          to be used in printing a header,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6055
     *                          or null for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6056
     * @param  footerFormat     a <code>MessageFormat</code> specifying the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6057
     *                          to be used in printing a footer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6058
     *                          or null for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6059
     * @return true, unless printing is cancelled by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6060
     * @throws SecurityException if this thread is not allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6061
     *                           initiate a print job request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6062
     * @throws PrinterException if an error in the print system causes the job
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6063
     *                          to be aborted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6064
     * @see #print(JTable.PrintMode, MessageFormat, MessageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6065
     *             boolean, PrintRequestAttributeSet, boolean, PrintService)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6066
     * @see #getPrintable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6067
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6068
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6069
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6070
    public boolean print(PrintMode printMode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6071
                         MessageFormat headerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6072
                         MessageFormat footerFormat) throws PrinterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6074
        boolean showDialogs = !GraphicsEnvironment.isHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6075
        return print(printMode, headerFormat, footerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6076
                     showDialogs, null, showDialogs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6077
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6079
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6080
     * Prints this table, as specified by the fully featured
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6081
     * {@link #print(JTable.PrintMode, MessageFormat, MessageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6082
     * boolean, PrintRequestAttributeSet, boolean, PrintService) print}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6083
     * method, with the default printer specified as the print service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6084
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6085
     * @param  printMode        the printing mode that the printable should use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6086
     * @param  headerFormat     a <code>MessageFormat</code> specifying the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6087
     *                          to be used in printing a header,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6088
     *                          or <code>null</code> for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6089
     * @param  footerFormat     a <code>MessageFormat</code> specifying the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6090
     *                          to be used in printing a footer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6091
     *                          or <code>null</code> for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6092
     * @param  showPrintDialog  whether or not to display a print dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6093
     * @param  attr             a <code>PrintRequestAttributeSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6094
     *                          specifying any printing attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6095
     *                          or <code>null</code> for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6096
     * @param  interactive      whether or not to print in an interactive mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6097
     * @return true, unless printing is cancelled by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6098
     * @throws HeadlessException if the method is asked to show a printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6099
     *                           dialog or run interactively, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6100
     *                           <code>GraphicsEnvironment.isHeadless</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6101
     *                           returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6102
     * @throws SecurityException if this thread is not allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6103
     *                           initiate a print job request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6104
     * @throws PrinterException if an error in the print system causes the job
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6105
     *                          to be aborted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6106
     * @see #print(JTable.PrintMode, MessageFormat, MessageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6107
     *             boolean, PrintRequestAttributeSet, boolean, PrintService)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6108
     * @see #getPrintable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6109
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6110
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6112
    public boolean print(PrintMode printMode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6113
                         MessageFormat headerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6114
                         MessageFormat footerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6115
                         boolean showPrintDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6116
                         PrintRequestAttributeSet attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6117
                         boolean interactive) throws PrinterException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6118
                                                     HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6120
        return print(printMode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6121
                     headerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6122
                     footerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6123
                     showPrintDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6124
                     attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6125
                     interactive,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6126
                     null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6130
     * Prints this <code>JTable</code>. Takes steps that the majority of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6131
     * developers would take in order to print a <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6132
     * In short, it prepares the table, calls <code>getPrintable</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6133
     * fetch an appropriate <code>Printable</code>, and then sends it to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6134
     * printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6135
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6136
     * A <code>boolean</code> parameter allows you to specify whether or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6137
     * a printing dialog is displayed to the user. When it is, the user may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6138
     * use the dialog to change the destination printer or printing attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6139
     * or even to cancel the print. Another two parameters allow for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6140
     * <code>PrintService</code> and printing attributes to be specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6141
     * These parameters can be used either to provide initial values for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6142
     * print dialog, or to specify values when the dialog is not shown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6143
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6144
     * A second <code>boolean</code> parameter allows you to specify whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6145
     * or not to perform printing in an interactive mode. If <code>true</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6146
     * a modal progress dialog, with an abort option, is displayed for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6147
     * duration of printing . This dialog also prevents any user action which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6148
     * may affect the table. However, it can not prevent the table from being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6149
     * modified by code (for example, another thread that posts updates using
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6150
     * <code>SwingUtilities.invokeLater</code>). It is therefore the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6151
     * responsibility of the developer to ensure that no other code modifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6152
     * the table in any way during printing (invalid modifications include
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6153
     * changes in: size, renderers, or underlying data). Printing behavior is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6154
     * undefined when the table is changed during printing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6155
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6156
     * If <code>false</code> is specified for this parameter, no dialog will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6157
     * be displayed and printing will begin immediately on the event-dispatch
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6158
     * thread. This blocks any other events, including repaints, from being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6159
     * processed until printing is complete. Although this effectively prevents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6160
     * the table from being changed, it doesn't provide a good user experience.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6161
     * For this reason, specifying <code>false</code> is only recommended when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6162
     * printing from an application with no visible GUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6163
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6164
     * Note: Attempting to show the printing dialog or run interactively, while
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6165
     * in headless mode, will result in a <code>HeadlessException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6166
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6167
     * Before fetching the printable, this method will gracefully terminate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6168
     * editing, if necessary, to prevent an editor from showing in the printed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6169
     * result. Additionally, <code>JTable</code> will prepare its renderers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6170
     * during printing such that selection and focus are not indicated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6171
     * As far as customizing further how the table looks in the printout,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6172
     * developers can provide custom renderers or paint code that conditionalize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6173
     * on the value of {@link javax.swing.JComponent#isPaintingForPrint()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6174
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6175
     * See {@link #getPrintable} for more description on how the table is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6176
     * printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6178
     * @param  printMode        the printing mode that the printable should use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6179
     * @param  headerFormat     a <code>MessageFormat</code> specifying the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6180
     *                          to be used in printing a header,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6181
     *                          or <code>null</code> for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6182
     * @param  footerFormat     a <code>MessageFormat</code> specifying the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6183
     *                          to be used in printing a footer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6184
     *                          or <code>null</code> for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6185
     * @param  showPrintDialog  whether or not to display a print dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6186
     * @param  attr             a <code>PrintRequestAttributeSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6187
     *                          specifying any printing attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6188
     *                          or <code>null</code> for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6189
     * @param  interactive      whether or not to print in an interactive mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6190
     * @param  service          the destination <code>PrintService</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6191
     *                          or <code>null</code> to use the default printer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6192
     * @return true, unless printing is cancelled by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6193
     * @throws HeadlessException if the method is asked to show a printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6194
     *                           dialog or run interactively, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6195
     *                           <code>GraphicsEnvironment.isHeadless</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6196
     *                           returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6197
     * @throws  SecurityException if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6198
     *          {@link java.lang.SecurityManager#checkPrintJobAccess}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6199
     *          method disallows this thread from creating a print job request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6200
     * @throws PrinterException if an error in the print system causes the job
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6201
     *                          to be aborted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6202
     * @see #getPrintable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6203
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6205
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6207
    public boolean print(PrintMode printMode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6208
                         MessageFormat headerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6209
                         MessageFormat footerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6210
                         boolean showPrintDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6211
                         PrintRequestAttributeSet attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6212
                         boolean interactive,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6213
                         PrintService service) throws PrinterException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6214
                                                      HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6215
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6216
        // complain early if an invalid parameter is specified for headless mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6217
        boolean isHeadless = GraphicsEnvironment.isHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6218
        if (isHeadless) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6219
            if (showPrintDialog) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6220
                throw new HeadlessException("Can't show print dialog.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6221
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6223
            if (interactive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6224
                throw new HeadlessException("Can't run interactively.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6228
        // Get a PrinterJob.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6229
        // Do this before anything with side-effects since it may throw a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6230
        // security exception - in which case we don't want to do anything else.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6231
        final PrinterJob job = PrinterJob.getPrinterJob();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6233
        if (isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6234
            // try to stop cell editing, and failing that, cancel it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6235
            if (!getCellEditor().stopCellEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6236
                getCellEditor().cancelCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6237
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6240
        if (attr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6241
            attr = new HashPrintRequestAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6244
        final PrintingStatus printingStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6245
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6246
         // fetch the Printable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6247
        Printable printable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6248
             getPrintable(printMode, headerFormat, footerFormat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6250
        if (interactive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6251
            // wrap the Printable so that we can print on another thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6252
            printable = new ThreadSafePrintable(printable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6253
            printingStatus = PrintingStatus.createPrintingStatus(this, job);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6254
            printable = printingStatus.createNotificationPrintable(printable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6255
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6256
            // to please compiler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6257
            printingStatus = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6259
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6260
        // set the printable on the PrinterJob
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6261
        job.setPrintable(printable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6263
        // if specified, set the PrintService on the PrinterJob
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6264
        if (service != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6265
            job.setPrintService(service);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6268
        // if requested, show the print dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6269
        if (showPrintDialog && !job.printDialog(attr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6270
            // the user cancelled the print dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6271
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6274
        // if not interactive, just print on this thread (no dialog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6275
        if (!interactive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6276
            // do the printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6277
            job.print(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6278
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6279
            // we're done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6280
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6282
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6283
        // make sure this is clear since we'll check it after
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6284
        printError = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6286
        // to synchronize on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6287
        final Object lock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6289
        // copied so we can access from the inner class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6290
        final PrintRequestAttributeSet copyAttr = attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6291
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6292
        // this runnable will be used to do the printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6293
        // (and save any throwables) on another thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6294
        Runnable runnable = new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6295
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6296
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6297
                    // do the printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6298
                    job.print(copyAttr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6299
                } catch (Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6300
                    // save any Throwable to be rethrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6301
                    synchronized(lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6302
                        printError = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6303
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6304
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6305
                    // we're finished - hide the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6306
                    printingStatus.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6307
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6308
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6309
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6310
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6311
        // start printing on another thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6312
        Thread th = new Thread(runnable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6313
        th.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6315
        printingStatus.showModal(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6316
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6317
        // look for any error that the printing may have generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6318
        Throwable pe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6319
        synchronized(lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6320
            pe = printError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6321
            printError = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6323
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6324
        // check the type of error and handle it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6325
        if (pe != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6326
            // a subclass of PrinterException meaning the job was aborted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6327
            // in this case, by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6328
            if (pe instanceof PrinterAbortException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6329
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6330
            } else if (pe instanceof PrinterException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6331
                throw (PrinterException)pe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6332
            } else if (pe instanceof RuntimeException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6333
                throw (RuntimeException)pe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6334
            } else if (pe instanceof Error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6335
                throw (Error)pe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6336
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6338
            // can not happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6339
            throw new AssertionError(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6341
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6342
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6344
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6346
     * Return a <code>Printable</code> for use in printing this JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6347
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6348
     * This method is meant for those wishing to customize the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6349
     * <code>Printable</code> implementation used by <code>JTable</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6350
     * <code>print</code> methods. Developers wanting simply to print the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6351
     * should use one of those methods directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6352
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6353
     * The <code>Printable</code> can be requested in one of two printing modes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6354
     * In both modes, it spreads table rows naturally in sequence across
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6355
     * multiple pages, fitting as many rows as possible per page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6356
     * <code>PrintMode.NORMAL</code> specifies that the table be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6357
     * printed at its current size. In this mode, there may be a need to spread
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6358
     * columns across pages in a similar manner to that of the rows. When the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6359
     * need arises, columns are distributed in an order consistent with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6360
     * table's <code>ComponentOrientation</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6361
     * <code>PrintMode.FIT_WIDTH</code> specifies that the output be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6362
     * scaled smaller, if necessary, to fit the table's entire width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6363
     * (and thereby all columns) on each page. Width and height are scaled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6364
     * equally, maintaining the aspect ratio of the output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6365
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6366
     * The <code>Printable</code> heads the portion of table on each page
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6367
     * with the appropriate section from the table's <code>JTableHeader</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6368
     * if it has one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6369
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6370
     * Header and footer text can be added to the output by providing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6371
     * <code>MessageFormat</code> arguments. The printing code requests
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6372
     * Strings from the formats, providing a single item which may be included
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6373
     * in the formatted string: an <code>Integer</code> representing the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6374
     * page number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6375
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6376
     * You are encouraged to read the documentation for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6377
     * <code>MessageFormat</code> as some characters, such as single-quote,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6378
     * are special and need to be escaped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6379
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6380
     * Here's an example of creating a <code>MessageFormat</code> that can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6381
     * used to print "Duke's Table: Page - " and the current page number:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6382
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6383
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6384
     *     // notice the escaping of the single quote
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6385
     *     // notice how the page number is included with "{0}"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6386
     *     MessageFormat format = new MessageFormat("Duke''s Table: Page - {0}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6387
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6388
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6389
     * The <code>Printable</code> constrains what it draws to the printable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6390
     * area of each page that it prints. Under certain circumstances, it may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6391
     * find it impossible to fit all of a page's content into that area. In
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6392
     * these cases the output may be clipped, but the implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6393
     * makes an effort to do something reasonable. Here are a few situations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6394
     * where this is known to occur, and how they may be handled by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6395
     * particular implementation:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6396
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6397
     *   <li>In any mode, when the header or footer text is too wide to fit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6398
     *       completely in the printable area -- print as much of the text as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6399
     *       possible starting from the beginning, as determined by the table's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6400
     *       <code>ComponentOrientation</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6401
     *   <li>In any mode, when a row is too tall to fit in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6402
     *       printable area -- print the upper-most portion of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6403
     *       and paint no lower border on the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6404
     *   <li>In <code>PrintMode.NORMAL</code> when a column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6405
     *       is too wide to fit in the printable area -- print the center
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6406
     *       portion of the column and leave the left and right borders
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6407
     *       off the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6408
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6409
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6410
     * It is entirely valid for this <code>Printable</code> to be wrapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6411
     * inside another in order to create complex reports and documents. You may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6412
     * even request that different pages be rendered into different sized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6413
     * printable areas. The implementation must be prepared to handle this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6414
     * (possibly by doing its layout calculations on the fly). However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6415
     * providing different heights to each page will likely not work well
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6416
     * with <code>PrintMode.NORMAL</code> when it has to spread columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6417
     * across pages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6418
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6419
     * As far as customizing how the table looks in the printed result,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6420
     * <code>JTable</code> itself will take care of hiding the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6421
     * and focus during printing. For additional customizations, your
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6422
     * renderers or painting code can customize the look based on the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6423
     * of {@link javax.swing.JComponent#isPaintingForPrint()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6424
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6425
     * Also, <i>before</i> calling this method you may wish to <i>first</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6426
     * modify the state of the table, such as to cancel cell editing or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6427
     * have the user size the table appropriately. However, you must not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6428
     * modify the state of the table <i>after</i> this <code>Printable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6429
     * has been fetched (invalid modifications include changes in size or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6430
     * underlying data). The behavior of the returned <code>Printable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6431
     * is undefined once the table has been changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6432
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6433
     * @param  printMode     the printing mode that the printable should use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6434
     * @param  headerFormat  a <code>MessageFormat</code> specifying the text to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6435
     *                       be used in printing a header, or null for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6436
     * @param  footerFormat  a <code>MessageFormat</code> specifying the text to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6437
     *                       be used in printing a footer, or null for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6438
     * @return a <code>Printable</code> for printing this JTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6439
     * @see #print(JTable.PrintMode, MessageFormat, MessageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6440
     *             boolean, PrintRequestAttributeSet, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6441
     * @see Printable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6442
     * @see PrinterJob
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6443
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6444
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6445
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6446
    public Printable getPrintable(PrintMode printMode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6447
                                  MessageFormat headerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6448
                                  MessageFormat footerFormat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6450
        return new TablePrintable(this, printMode, headerFormat, footerFormat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6453
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6454
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6455
     * A <code>Printable</code> implementation that wraps another
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6456
     * <code>Printable</code>, making it safe for printing on another thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6457
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6458
    private class ThreadSafePrintable implements Printable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6460
        /** The delegate <code>Printable</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6461
        private Printable printDelegate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6462
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6463
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6464
         * To communicate any return value when delegating.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6465
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6466
        private int retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6467
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6468
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6469
         * To communicate any <code>Throwable</code> when delegating.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6470
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6471
        private Throwable retThrowable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6472
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6473
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6474
         * Construct a <code>ThreadSafePrintable</code> around the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6475
         * delegate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6476
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6477
         * @param printDelegate the <code>Printable</code> to delegate to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6478
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6479
        public ThreadSafePrintable(Printable printDelegate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6480
            this.printDelegate = printDelegate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6481
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6483
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6484
         * Prints the specified page into the given {@link Graphics}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6485
         * context, in the specified format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6486
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6487
         * Regardless of what thread this method is called on, all calls into
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6488
         * the delegate will be done on the event-dispatch thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6489
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6490
         * @param   graphics    the context into which the page is drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6491
         * @param   pageFormat  the size and orientation of the page being drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6492
         * @param   pageIndex   the zero based index of the page to be drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6493
         * @return  PAGE_EXISTS if the page is rendered successfully, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6494
         *          NO_SUCH_PAGE if a non-existent page index is specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6495
         * @throws  PrinterException if an error causes printing to be aborted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6496
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6497
        public int print(final Graphics graphics,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6498
                         final PageFormat pageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6499
                         final int pageIndex) throws PrinterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6500
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6501
            // We'll use this Runnable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6502
            Runnable runnable = new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6503
                public synchronized void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6504
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6505
                        // call into the delegate and save the return value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6506
                        retVal = printDelegate.print(graphics, pageFormat, pageIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6507
                    } catch (Throwable throwable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6508
                        // save any Throwable to be rethrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6509
                        retThrowable = throwable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6510
                    } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6511
                        // notify the caller that we're done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6512
                        notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6513
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6514
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6515
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6516
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6517
            synchronized(runnable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6518
                // make sure these are initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6519
                retVal = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6520
                retThrowable = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6521
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6522
                // call into the EDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6523
                SwingUtilities.invokeLater(runnable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6524
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6525
                // wait for the runnable to finish
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6526
                while (retVal == -1 && retThrowable == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6527
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6528
                        runnable.wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6529
                    } catch (InterruptedException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6530
                        // short process, safe to ignore interrupts
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6531
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6532
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6533
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6534
                // if the delegate threw a throwable, rethrow it here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6535
                if (retThrowable != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6536
                    if (retThrowable instanceof PrinterException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6537
                        throw (PrinterException)retThrowable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6538
                    } else if (retThrowable instanceof RuntimeException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6539
                        throw (RuntimeException)retThrowable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6540
                    } else if (retThrowable instanceof Error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6541
                        throw (Error)retThrowable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6542
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6544
                    // can not happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6545
                    throw new AssertionError(retThrowable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6546
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6547
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6548
                return retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6549
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6550
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6551
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6552
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6553
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6554
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6555
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6556
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6557
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6558
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6559
     * Gets the AccessibleContext associated with this JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6560
     * For tables, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6561
     * AccessibleJTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6562
     * A new AccessibleJTable instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6563
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6564
     * @return an AccessibleJTable that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6565
     *         AccessibleContext of this JTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6566
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6567
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6568
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6569
            accessibleContext = new AccessibleJTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6570
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6571
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6574
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6575
    // *** should also implement AccessibleSelection?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6576
    // *** and what's up with keyboard navigation/manipulation?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6577
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6578
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6579
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6580
     * <code>JTable</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6581
     * Java Accessibility API appropriate to table user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6582
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6583
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6584
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6585
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6586
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6587
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6588
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6589
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6590
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6591
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6592
    protected class AccessibleJTable extends AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6593
    implements AccessibleSelection, ListSelectionListener, TableModelListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6594
    TableColumnModelListener, CellEditorListener, PropertyChangeListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6595
    AccessibleExtendedTable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6596
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6597
        int lastSelectedRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6598
        int lastSelectedCol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6599
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6600
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6601
         * AccessibleJTable constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6602
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6603
         * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6604
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6605
        protected AccessibleJTable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6606
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6607
            JTable.this.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6608
            JTable.this.getSelectionModel().addListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6609
            TableColumnModel tcm = JTable.this.getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6610
            tcm.addColumnModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6611
            tcm.getSelectionModel().addListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6612
            JTable.this.getModel().addTableModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6613
            lastSelectedRow = JTable.this.getSelectedRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6614
            lastSelectedCol = JTable.this.getSelectedColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6616
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6617
    // Listeners to track model, etc. changes to as to re-place the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6618
    // listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6619
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6620
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6621
         * Track changes to selection model, column model, etc. so as to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6622
         * be able to re-place listeners on those in order to pass on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6623
         * information to the Accessibility PropertyChange mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6624
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6625
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6626
            String name = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6627
            Object oldValue = e.getOldValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6628
            Object newValue = e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6629
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6630
                // re-set tableModel listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6631
            if (name.compareTo("model") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6632
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6633
                if (oldValue != null && oldValue instanceof TableModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6634
                    ((TableModel) oldValue).removeTableModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6635
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6636
                if (newValue != null && newValue instanceof TableModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6637
                    ((TableModel) newValue).addTableModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6638
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6639
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6640
                // re-set selectionModel listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6641
            } else if (name.compareTo("selectionModel") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6642
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6643
                Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6644
                if (source == JTable.this) {    // row selection model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6645
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6646
                    if (oldValue != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6647
                        oldValue instanceof ListSelectionModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6648
                        ((ListSelectionModel) oldValue).removeListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6649
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6650
                    if (newValue != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6651
                        newValue instanceof ListSelectionModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6652
                        ((ListSelectionModel) newValue).addListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6653
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6654
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6655
                } else if (source == JTable.this.getColumnModel()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6656
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6657
                    if (oldValue != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6658
                        oldValue instanceof ListSelectionModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6659
                        ((ListSelectionModel) oldValue).removeListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6660
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6661
                    if (newValue != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6662
                        newValue instanceof ListSelectionModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6663
                        ((ListSelectionModel) newValue).addListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6664
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6665
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6666
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6667
                  //        System.out.println("!!! Bug in source of selectionModel propertyChangeEvent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6668
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6670
                // re-set columnModel listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6671
                // and column's selection property listener as well
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6672
            } else if (name.compareTo("columnModel") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6674
                if (oldValue != null && oldValue instanceof TableColumnModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6675
                    TableColumnModel tcm = (TableColumnModel) oldValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6676
                    tcm.removeColumnModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6677
                    tcm.getSelectionModel().removeListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6678
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6679
                if (newValue != null && newValue instanceof TableColumnModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6680
                    TableColumnModel tcm = (TableColumnModel) newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6681
                    tcm.addColumnModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6682
                    tcm.getSelectionModel().addListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6683
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6684
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6685
                // re-se cellEditor listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6686
            } else if (name.compareTo("tableCellEditor") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6687
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6688
                if (oldValue != null && oldValue instanceof TableCellEditor) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  6689
                    ((TableCellEditor) oldValue).removeCellEditorListener(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6690
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6691
                if (newValue != null && newValue instanceof TableCellEditor) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  6692
                    ((TableCellEditor) newValue).addCellEditorListener(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6693
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6694
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6695
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6696
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6697
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6698
    // Listeners to echo changes to the AccessiblePropertyChange mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6699
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6700
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6701
         * Describes a change in the accessible table model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6702
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6703
        protected class AccessibleJTableModelChange
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6704
            implements AccessibleTableModelChange {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6705
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6706
            protected int type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6707
            protected int firstRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6708
            protected int lastRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6709
            protected int firstColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6710
            protected int lastColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6711
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6712
            protected AccessibleJTableModelChange(int type, int firstRow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6713
                                                  int lastRow, int firstColumn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6714
                                                  int lastColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6715
                this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6716
                this.firstRow = firstRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6717
                this.lastRow = lastRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6718
                this.firstColumn = firstColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6719
                this.lastColumn = lastColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6720
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6721
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6722
            public int getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6723
                return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6724
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6725
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6726
            public int getFirstRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6727
                return firstRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6728
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6729
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6730
            public int getLastRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6731
                return lastRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6732
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6733
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6734
            public int getFirstColumn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6735
                return firstColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6736
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6737
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6738
            public int getLastColumn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6739
                return lastColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6740
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6741
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6742
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6743
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6744
         * Track changes to the table contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6745
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6746
        public void tableChanged(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6747
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6748
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6749
           if (e != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6750
               int firstColumn = e.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6751
               int lastColumn = e.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6752
               if (firstColumn == TableModelEvent.ALL_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6753
                   firstColumn = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6754
                   lastColumn = getColumnCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6755
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6756
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6757
               // Fire a property change event indicating the table model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6758
               // has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6759
               AccessibleJTableModelChange change =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6760
                   new AccessibleJTableModelChange(e.getType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6761
                                                   e.getFirstRow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6762
                                                   e.getLastRow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6763
                                                   firstColumn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6764
                                                   lastColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6765
               firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_MODEL_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6766
                                  null, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6767
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6768
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6769
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6770
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6771
         * Track changes to the table contents (row insertions)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6772
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6773
        public void tableRowsInserted(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6774
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6775
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6776
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6777
           // Fire a property change event indicating the table model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6778
           // has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6779
           int firstColumn = e.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6780
           int lastColumn = e.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6781
           if (firstColumn == TableModelEvent.ALL_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6782
               firstColumn = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6783
               lastColumn = getColumnCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6784
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6785
           AccessibleJTableModelChange change =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6786
               new AccessibleJTableModelChange(e.getType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6787
                                               e.getFirstRow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6788
                                               e.getLastRow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6789
                                               firstColumn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6790
                                               lastColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6791
           firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_MODEL_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6792
                              null, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6794
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6795
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6796
         * Track changes to the table contents (row deletions)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6797
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6798
        public void tableRowsDeleted(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6799
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6800
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6801
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6802
           // Fire a property change event indicating the table model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6803
           // has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6804
           int firstColumn = e.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6805
           int lastColumn = e.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6806
           if (firstColumn == TableModelEvent.ALL_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6807
               firstColumn = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6808
               lastColumn = getColumnCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6809
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6810
           AccessibleJTableModelChange change =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6811
               new AccessibleJTableModelChange(e.getType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6812
                                               e.getFirstRow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6813
                                               e.getLastRow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6814
                                               firstColumn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6815
                                               lastColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6816
           firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_MODEL_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6817
                              null, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6818
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6819
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6820
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6821
         * Track changes to the table contents (column insertions)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6822
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6823
        public void columnAdded(TableColumnModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6824
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6825
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6826
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6827
           // Fire a property change event indicating the table model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6828
           // has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6829
           int type = AccessibleTableModelChange.INSERT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6830
           AccessibleJTableModelChange change =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6831
               new AccessibleJTableModelChange(type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6832
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6833
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6834
                                               e.getFromIndex(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6835
                                               e.getToIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6836
           firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_MODEL_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6837
                              null, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6839
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6840
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6841
         * Track changes to the table contents (column deletions)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6842
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6843
        public void columnRemoved(TableColumnModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6844
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6845
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6846
           // Fire a property change event indicating the table model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6847
           // has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6848
           int type = AccessibleTableModelChange.DELETE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6849
           AccessibleJTableModelChange change =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6850
               new AccessibleJTableModelChange(type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6851
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6852
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6853
                                               e.getFromIndex(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6854
                                               e.getToIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6855
           firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_MODEL_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6856
                              null, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6857
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6858
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6859
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6860
         * Track changes of a column repositioning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6861
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6862
         * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6863
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6864
        public void columnMoved(TableColumnModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6865
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6866
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6867
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6868
           // Fire property change events indicating the table model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6869
           // has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6870
           int type = AccessibleTableModelChange.DELETE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6871
           AccessibleJTableModelChange change =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6872
               new AccessibleJTableModelChange(type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6873
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6874
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6875
                                               e.getFromIndex(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6876
                                               e.getFromIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6877
           firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_MODEL_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6878
                              null, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6879
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6880
           int type2 = AccessibleTableModelChange.INSERT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6881
           AccessibleJTableModelChange change2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6882
               new AccessibleJTableModelChange(type2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6883
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6884
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6885
                                               e.getToIndex(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6886
                                               e.getToIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6887
           firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_MODEL_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6888
                              null, change2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6889
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6890
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6891
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6892
         * Track changes of a column moving due to margin changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6893
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6894
         * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6895
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6896
        public void columnMarginChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6897
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6898
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6899
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6900
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6901
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6902
         * Track that the selection model of the TableColumnModel changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6903
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6904
         * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6905
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6906
        public void columnSelectionChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6907
            // we should now re-place our TableColumn listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6908
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6909
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6910
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6911
         * Track changes to a cell's contents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6912
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6913
         * Invoked when editing is finished. The changes are saved, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6914
         * editor object is discarded, and the cell is rendered once again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6915
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6916
         * @see CellEditorListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6917
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6918
        public void editingStopped(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6919
           // it'd be great if we could figure out which cell, and pass that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6920
           // somehow as a parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6921
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6922
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6923
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6924
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6925
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6926
         * Invoked when editing is canceled. The editor object is discarded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6927
         * and the cell is rendered once again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6928
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6929
         * @see CellEditorListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6930
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6931
        public void editingCanceled(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6932
            // nothing to report, 'cause nothing changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6933
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6934
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6935
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6936
         * Track changes to table cell selections
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6937
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6938
        public void valueChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6939
            firePropertyChange(AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6940
                               Boolean.valueOf(false), Boolean.valueOf(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6941
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6942
            int selectedRow = JTable.this.getSelectedRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6943
            int selectedCol = JTable.this.getSelectedColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6944
            if (selectedRow != lastSelectedRow ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6945
                selectedCol != lastSelectedCol) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6946
                Accessible oldA = getAccessibleAt(lastSelectedRow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6947
                                                  lastSelectedCol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6948
                Accessible newA = getAccessibleAt(selectedRow, selectedCol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6949
                firePropertyChange(AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6950
                                   oldA, newA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6951
                 lastSelectedRow = selectedRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6952
                 lastSelectedCol = selectedCol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6953
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6954
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6955
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6956
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6957
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6958
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6959
    // AccessibleContext support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6960
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6961
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6962
         * Get the AccessibleSelection associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6963
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6964
         * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6965
         * AccessibleSelection interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6966
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6967
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6968
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6969
        public AccessibleSelection getAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6970
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6971
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6972
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6973
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6974
         * Gets the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6975
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6976
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6977
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6978
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6979
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6980
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6981
            return AccessibleRole.TABLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6982
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6983
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6984
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6985
         * Returns the <code>Accessible</code> child, if one exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6986
         * contained at the local coordinate <code>Point</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6987
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6988
         * @param p the point defining the top-left corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6989
         *    <code>Accessible</code>, given in the coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6990
         *    of the object's parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6991
         * @return the <code>Accessible</code>, if it exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6992
         *    at the specified location; else <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6993
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6994
        public Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6995
            int column = columnAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6996
            int row = rowAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6997
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6998
            if ((column != -1) && (row != -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6999
                TableColumn aColumn = getColumnModel().getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7000
                TableCellRenderer renderer = aColumn.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7001
                if (renderer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7002
                    Class<?> columnClass = getColumnClass(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7003
                    renderer = getDefaultRenderer(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7004
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7005
                Component component = renderer.getTableCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7006
                                  JTable.this, null, false, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7007
                                  row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7008
                return new AccessibleJTableCell(JTable.this, row, column,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7009
                      getAccessibleIndexAt(row, column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7010
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7011
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7012
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7014
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7015
         * Returns the number of accessible children in the object.  If all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7016
         * of the children of this object implement <code>Accessible</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7017
         * then this method should return the number of children of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7018
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7019
         * @return the number of accessible children in the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7020
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7021
        public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7022
            return (JTable.this.getColumnCount() * JTable.this.getRowCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7023
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7025
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7026
         * Returns the nth <code>Accessible</code> child of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7027
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7028
         * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7029
         * @return the nth Accessible child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7030
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7031
        public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7032
            if (i < 0 || i >= getAccessibleChildrenCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7033
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7034
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7035
                // children increase across, and then down, for tables
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7036
                // (arbitrary decision)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7037
                int column = getAccessibleColumnAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7038
                int row = getAccessibleRowAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7039
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7040
                TableColumn aColumn = getColumnModel().getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7041
                TableCellRenderer renderer = aColumn.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7042
                if (renderer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7043
                    Class<?> columnClass = getColumnClass(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7044
                    renderer = getDefaultRenderer(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7045
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7046
                Component component = renderer.getTableCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7047
                                  JTable.this, null, false, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7048
                                  row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7049
                return new AccessibleJTableCell(JTable.this, row, column,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7050
                      getAccessibleIndexAt(row, column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7051
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7052
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7054
    // AccessibleSelection support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7056
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7057
         * Returns the number of <code>Accessible</code> children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7058
         * currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7059
         * If no children are selected, the return value will be 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7060
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7061
         * @return the number of items currently selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7062
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7063
        public int getAccessibleSelectionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7064
            int rowsSel = JTable.this.getSelectedRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7065
            int colsSel = JTable.this.getSelectedColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7067
            if (JTable.this.cellSelectionEnabled) { // a contiguous block
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7068
                return rowsSel * colsSel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7070
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7071
                // a column swath and a row swath, with a shared block
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7072
                if (JTable.this.getRowSelectionAllowed() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7073
                    JTable.this.getColumnSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7074
                    return rowsSel * JTable.this.getColumnCount() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7075
                           colsSel * JTable.this.getRowCount() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7076
                           rowsSel * colsSel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7078
                // just one or more rows in selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7079
                } else if (JTable.this.getRowSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7080
                    return rowsSel * JTable.this.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7082
                // just one or more rows in selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7083
                } else if (JTable.this.getColumnSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7084
                    return colsSel * JTable.this.getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7086
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7087
                    return 0;    // JTable doesn't allow selections
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7088
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7089
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7090
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7092
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7093
         * Returns an <code>Accessible</code> representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7094
         * specified selected child in the object.  If there
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7095
         * isn't a selection, or there are fewer children selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7096
         * than the integer passed in, the return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7097
         * value will be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7098
         * <p>Note that the index represents the i-th selected child, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7099
         * is different from the i-th child.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7100
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7101
         * @param i the zero-based index of selected children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7102
         * @return the i-th selected child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7103
         * @see #getAccessibleSelectionCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7104
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7105
        public Accessible getAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7106
            if (i < 0 || i > getAccessibleSelectionCount()) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  7107
                return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7108
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7109
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7110
            int rowsSel = JTable.this.getSelectedRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7111
            int colsSel = JTable.this.getSelectedColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7112
            int rowIndicies[] = getSelectedRows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7113
            int colIndicies[] = getSelectedColumns();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7114
            int ttlCols = JTable.this.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7115
            int ttlRows = JTable.this.getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7116
            int r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7117
            int c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7119
            if (JTable.this.cellSelectionEnabled) { // a contiguous block
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7120
                r = rowIndicies[i / colsSel];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7121
                c = colIndicies[i % colsSel];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7122
                return getAccessibleChild((r * ttlCols) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7123
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7125
                // a column swath and a row swath, with a shared block
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7126
                if (JTable.this.getRowSelectionAllowed() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7127
                    JTable.this.getColumnSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7129
                    // Situation:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7130
                    //   We have a table, like the 6x3 table below,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7131
                    //   wherein three colums and one row selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7132
                    //   (selected cells marked with "*", unselected "0"):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7133
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7134
                    //            0 * 0 * * 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7135
                    //            * * * * * *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7136
                    //            0 * 0 * * 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7137
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7139
                    // State machine below walks through the array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7140
                    // selected rows in two states: in a selected row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7141
                    // and not in one; continuing until we are in a row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7142
                    // in which the ith selection exists.  Then we return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7143
                    // the appropriate cell.  In the state machine, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7144
                    // always do rows above the "current" selected row first,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7145
                    // then the cells in the selected row.  If we're done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7146
                    // with the state machine before finding the requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7147
                    // selected child, we handle the rows below the last
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7148
                    // selected row at the end.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7149
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7150
                    int curIndex = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7151
                    final int IN_ROW = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7152
                    final int NOT_IN_ROW = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7153
                    int state = (rowIndicies[0] == 0 ? IN_ROW : NOT_IN_ROW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7154
                    int j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7155
                    int prevRow = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7156
                    while (j < rowIndicies.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7157
                        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7159
                        case IN_ROW:   // on individual row full of selections
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7160
                            if (curIndex < ttlCols) { // it's here!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7161
                                c = curIndex % ttlCols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7162
                                r = rowIndicies[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7163
                                return getAccessibleChild((r * ttlCols) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7164
                            } else {                               // not here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7165
                                curIndex -= ttlCols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7166
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7167
                            // is the next row in table selected or not?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7168
                            if (j + 1 == rowIndicies.length ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7169
                                rowIndicies[j] != rowIndicies[j+1] - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7170
                                state = NOT_IN_ROW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7171
                                prevRow = rowIndicies[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7172
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7173
                            j++;  // we didn't return earlier, so go to next row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7174
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7175
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7176
                        case NOT_IN_ROW:  // sparse bunch of rows of selections
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7177
                            if (curIndex <
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7178
                                (colsSel * (rowIndicies[j] -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7179
                                (prevRow == -1 ? 0 : (prevRow + 1))))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7181
                                // it's here!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7182
                                c = colIndicies[curIndex % colsSel];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7183
                                r = (j > 0 ? rowIndicies[j-1] + 1 : 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7184
                                    + curIndex / colsSel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7185
                                return getAccessibleChild((r * ttlCols) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7186
                            } else {                               // not here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7187
                                curIndex -= colsSel * (rowIndicies[j] -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7188
                                (prevRow == -1 ? 0 : (prevRow + 1)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7189
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7190
                            state = IN_ROW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7191
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7192
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7193
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7194
                    // we got here, so we didn't find it yet; find it in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7195
                    // the last sparse bunch of rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7196
                    if (curIndex <
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7197
                        (colsSel * (ttlRows -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7198
                        (prevRow == -1 ? 0 : (prevRow + 1))))) { // it's here!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7199
                        c = colIndicies[curIndex % colsSel];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7200
                        r = rowIndicies[j-1] + curIndex / colsSel + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7201
                        return getAccessibleChild((r * ttlCols) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7202
                    } else {                               // not here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7203
                        // we shouldn't get to this spot in the code!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7204
//                      System.out.println("Bug in AccessibleJTable.getAccessibleSelection()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7205
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7207
                // one or more rows selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7208
                } else if (JTable.this.getRowSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7209
                    c = i % ttlCols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7210
                    r = rowIndicies[i / ttlCols];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7211
                    return getAccessibleChild((r * ttlCols) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7213
                // one or more columns selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7214
                } else if (JTable.this.getColumnSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7215
                    c = colIndicies[i % colsSel];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7216
                    r = i / colsSel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7217
                    return getAccessibleChild((r * ttlCols) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7218
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7219
            }
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  7220
            return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7223
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7224
         * Determines if the current child of this object is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7225
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7226
         * @param i the zero-based index of the child in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7227
         *    <code>Accessible</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7228
         * @return true if the current child of this object is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7229
         * @see AccessibleContext#getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7230
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7231
        public boolean isAccessibleChildSelected(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7232
            int column = getAccessibleColumnAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7233
            int row = getAccessibleRowAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7234
            return JTable.this.isCellSelected(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7237
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7238
         * Adds the specified <code>Accessible</code> child of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7239
         * object to the object's selection.  If the object supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7240
         * multiple selections, the specified child is added to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7241
         * any existing selection, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7242
         * it replaces any existing selection in the object.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7243
         * specified child is already selected, this method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7244
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7245
         * This method only works on <code>JTable</code>s which have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7246
         * individual cell selection enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7247
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7248
         * @param i the zero-based index of the child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7249
         * @see AccessibleContext#getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7250
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7251
        public void addAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7252
            // TIGER - 4495286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7253
            int column = getAccessibleColumnAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7254
            int row = getAccessibleRowAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7255
            JTable.this.changeSelection(row, column, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7257
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7258
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7259
         * Removes the specified child of the object from the object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7260
         * selection.  If the specified item isn't currently selected, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7261
         * method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7262
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7263
         * This method only works on <code>JTables</code> which have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7264
         * individual cell selection enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7265
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7266
         * @param i the zero-based index of the child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7267
         * @see AccessibleContext#getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7268
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7269
        public void removeAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7270
            if (JTable.this.cellSelectionEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7271
                int column = getAccessibleColumnAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7272
                int row = getAccessibleRowAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7273
                JTable.this.removeRowSelectionInterval(row, row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7274
                JTable.this.removeColumnSelectionInterval(column, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7275
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7278
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7279
         * Clears the selection in the object, so that no children in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7280
         * object are selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7281
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7282
        public void clearAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7283
            JTable.this.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7286
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7287
         * Causes every child of the object to be selected, but only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7288
         * if the <code>JTable</code> supports multiple selections,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7289
         * and if individual cell selection is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7290
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7291
        public void selectAllAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7292
            if (JTable.this.cellSelectionEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7293
                JTable.this.selectAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7294
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7296
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7297
        // begin AccessibleExtendedTable implementation -------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7298
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7299
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7300
         * Returns the row number of an index in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7301
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7302
         * @param index the zero-based index in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7303
         * @return the zero-based row of the table if one exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7304
         * otherwise -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7305
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7306
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7307
        public int getAccessibleRow(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7308
            return getAccessibleRowAtIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7310
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7311
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7312
         * Returns the column number of an index in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7313
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7314
         * @param index the zero-based index in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7315
         * @return the zero-based column of the table if one exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7316
         * otherwise -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7317
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7318
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7319
        public int getAccessibleColumn(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7320
            return getAccessibleColumnAtIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7323
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7324
         * Returns the index at a row and column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7325
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7326
         * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7327
         * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7328
         * @return the zero-based index in the table if one exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7329
         * otherwise -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7330
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7331
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7332
        public int getAccessibleIndex(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7333
            return getAccessibleIndexAt(r, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7336
        // end of AccessibleExtendedTable implementation ------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7338
        // start of AccessibleTable implementation ------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7339
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7340
        private Accessible caption;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7341
        private Accessible summary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7342
        private Accessible [] rowDescription;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7343
        private Accessible [] columnDescription;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7344
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7345
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7346
         * Gets the <code>AccessibleTable</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7347
         * object.  In the implementation of the Java Accessibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7348
         * API for this class, return this object, which is responsible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7349
         * for implementing the <code>AccessibleTables</code> interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7350
         * on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7351
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7352
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7353
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7354
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7355
        public AccessibleTable getAccessibleTable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7356
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7358
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7359
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7360
         * Returns the caption for the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7361
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7362
         * @return the caption for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7363
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7364
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7365
        public Accessible getAccessibleCaption() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7366
            return this.caption;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7367
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7368
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7369
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7370
         * Sets the caption for the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7371
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7372
         * @param a the caption for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7373
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7374
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7375
        public void setAccessibleCaption(Accessible a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7376
            Accessible oldCaption = caption;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7377
            this.caption = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7378
            firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_CAPTION_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7379
                               oldCaption, this.caption);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7381
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7382
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7383
         * Returns the summary description of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7384
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7385
         * @return the summary description of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7386
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7387
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7388
        public Accessible getAccessibleSummary() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7389
            return this.summary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7391
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7392
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7393
         * Sets the summary description of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7394
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7395
         * @param a the summary description of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7396
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7397
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7398
        public void setAccessibleSummary(Accessible a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7399
            Accessible oldSummary = summary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7400
            this.summary = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7401
            firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_SUMMARY_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7402
                               oldSummary, this.summary);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7404
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7405
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7406
         * Returns the total number of rows in this table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7407
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7408
         * @return the total number of rows in this table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7409
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7410
        public int getAccessibleRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7411
            return JTable.this.getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7413
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7414
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7415
         * Returns the total number of columns in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7416
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7417
         * @return the total number of columns in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7418
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7419
        public int getAccessibleColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7420
            return JTable.this.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7421
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7422
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7423
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7424
         * Returns the <code>Accessible</code> at a specified row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7425
         * and column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7426
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7427
         * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7428
         * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7429
         * @return the <code>Accessible</code> at the specified row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7430
         * in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7431
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7432
        public Accessible getAccessibleAt(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7433
            return getAccessibleChild((r * getAccessibleColumnCount()) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7435
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7436
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7437
         * Returns the number of rows occupied by the <code>Accessible</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7438
         * at a specified row and column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7439
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7440
         * @return the number of rows occupied by the <code>Accessible</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7441
         *     at a specified row and column in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7442
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7443
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7444
        public int getAccessibleRowExtentAt(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7445
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7446
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7447
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7448
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7449
         * Returns the number of columns occupied by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7450
         * <code>Accessible</code> at a given (row, column).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7451
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7452
         * @return the number of columns occupied by the <code>Accessible</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7453
         *     at a specified row and column in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7454
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7455
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7456
        public int getAccessibleColumnExtentAt(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7457
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7460
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7461
         * Returns the row headers as an <code>AccessibleTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7462
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7463
         * @return an <code>AccessibleTable</code> representing the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7464
         * headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7465
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7466
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7467
        public AccessibleTable getAccessibleRowHeader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7468
            // row headers are not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7469
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7471
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7472
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7473
         * Sets the row headers as an <code>AccessibleTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7474
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7475
         * @param a an <code>AccessibleTable</code> representing the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7476
         *  headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7477
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7478
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7479
        public void setAccessibleRowHeader(AccessibleTable a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7480
            // row headers are not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7481
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7483
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7484
         * Returns the column headers as an <code>AccessibleTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7485
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7486
         *  @return an <code>AccessibleTable</code> representing the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7487
         *          headers, or <code>null</code> if the table header is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7488
         *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7489
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7490
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7491
        public AccessibleTable getAccessibleColumnHeader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7492
            JTableHeader header = JTable.this.getTableHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7493
            return header == null ? null : new AccessibleTableHeader(header);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7496
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7497
         * Private class representing a table column header
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7498
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7499
        private class AccessibleTableHeader implements AccessibleTable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7500
            private JTableHeader header;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7501
            private TableColumnModel headerModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7502
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7503
            AccessibleTableHeader(JTableHeader header) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7504
                this.header = header;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7505
                this.headerModel = header.getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7506
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7507
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7508
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7509
             * Returns the caption for the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7510
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7511
             * @return the caption for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7512
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7513
            public Accessible getAccessibleCaption() { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7514
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7515
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7516
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7517
             * Sets the caption for the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7518
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7519
             * @param a the caption for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7520
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7521
            public void setAccessibleCaption(Accessible a) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7522
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7523
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7524
             * Returns the summary description of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7525
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7526
             * @return the summary description of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7527
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7528
            public Accessible getAccessibleSummary() { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7529
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7530
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7531
             * Sets the summary description of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7532
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7533
             * @param a the summary description of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7534
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7535
            public void setAccessibleSummary(Accessible a) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7536
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7537
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7538
             * Returns the number of rows in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7539
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7540
             * @return the number of rows in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7541
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7542
            public int getAccessibleRowCount() { return 1; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7544
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7545
             * Returns the number of columns in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7546
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7547
             * @return the number of columns in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7548
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7549
            public int getAccessibleColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7550
                return headerModel.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7551
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7552
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7553
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7554
             * Returns the Accessible at a specified row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7555
             * in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7556
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7557
             * @param row zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7558
             * @param column zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7559
             * @return the Accessible at the specified row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7560
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7561
            public Accessible getAccessibleAt(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7562
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7563
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7564
                // TIGER - 4715503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7565
                TableColumn aColumn = headerModel.getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7566
                TableCellRenderer renderer = aColumn.getHeaderRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7567
                if (renderer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7568
                    renderer = header.getDefaultRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7569
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7570
                Component component = renderer.getTableCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7571
                                  header.getTable(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7572
                                  aColumn.getHeaderValue(), false, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7573
                                  -1, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7574
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7575
                return new AccessibleJTableHeaderCell(row, column,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7576
                                                      JTable.this.getTableHeader(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7577
                                                      component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7578
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7579
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7580
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7581
             * Returns the number of rows occupied by the Accessible at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7582
             * a specified row and column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7583
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7584
             * @return the number of rows occupied by the Accessible at a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7585
             * given specified (row, column)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7586
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7587
            public int getAccessibleRowExtentAt(int r, int c) { return 1; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7588
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7589
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7590
             * Returns the number of columns occupied by the Accessible at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7591
             * a specified row and column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7592
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7593
             * @return the number of columns occupied by the Accessible at a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7594
             * given specified row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7595
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7596
            public int getAccessibleColumnExtentAt(int r, int c) { return 1; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7597
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7598
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7599
             * Returns the row headers as an AccessibleTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7600
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7601
             * @return an AccessibleTable representing the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7602
             * headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7603
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7604
            public AccessibleTable getAccessibleRowHeader() { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7605
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7606
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7607
             * Sets the row headers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7608
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7609
             * @param table an AccessibleTable representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7610
             * row headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7611
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7612
            public void setAccessibleRowHeader(AccessibleTable table) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7613
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7614
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7615
             * Returns the column headers as an AccessibleTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7616
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7617
             * @return an AccessibleTable representing the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7618
             * headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7619
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7620
            public AccessibleTable getAccessibleColumnHeader() { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7621
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7622
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7623
             * Sets the column headers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7624
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7625
             * @param table an AccessibleTable representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7626
             * column headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7627
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7628
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7629
            public void setAccessibleColumnHeader(AccessibleTable table) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7630
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7631
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7632
             * Returns the description of the specified row in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7633
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7634
             * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7635
             * @return the description of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7636
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7637
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7638
            public Accessible getAccessibleRowDescription(int r) { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7639
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7640
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7641
             * Sets the description text of the specified row of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7642
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7643
             * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7644
             * @param a the description of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7645
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7646
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7647
            public void setAccessibleRowDescription(int r, Accessible a) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7648
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7649
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7650
             * Returns the description text of the specified column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7651
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7652
             * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7653
             * @return the text description of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7654
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7655
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7656
            public Accessible getAccessibleColumnDescription(int c) { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7657
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7658
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7659
             * Sets the description text of the specified column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7660
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7661
             * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7662
             * @param a the text description of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7663
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7664
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7665
            public void setAccessibleColumnDescription(int c, Accessible a) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7666
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7667
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7668
             * Returns a boolean value indicating whether the accessible at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7669
             * a specified row and column is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7670
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7671
             * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7672
             * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7673
             * @return the boolean value true if the accessible at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7674
             * row and column is selected. Otherwise, the boolean value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7675
             * false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7676
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7677
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7678
            public boolean isAccessibleSelected(int r, int c) { return false; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7679
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7680
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7681
             * Returns a boolean value indicating whether the specified row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7682
             * is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7683
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7684
             * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7685
             * @return the boolean value true if the specified row is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7686
             * Otherwise, false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7687
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7688
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7689
            public boolean isAccessibleRowSelected(int r) { return false; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7690
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7691
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7692
             * Returns a boolean value indicating whether the specified column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7693
             * is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7694
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7695
             * @param r zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7696
             * @return the boolean value true if the specified column is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7697
             * Otherwise, false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7698
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7699
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7700
            public boolean isAccessibleColumnSelected(int c) { return false; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7701
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7702
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7703
             * Returns the selected rows in a table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7704
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7705
             * @return an array of selected rows where each element is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7706
             * zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7707
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7708
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7709
            public int [] getSelectedAccessibleRows() { return new int[0]; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7710
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7711
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7712
             * Returns the selected columns in a table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7713
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7714
             * @return an array of selected columns where each element is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7715
             * zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7716
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7717
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7718
            public int [] getSelectedAccessibleColumns() { return new int[0]; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7719
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7720
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7721
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7722
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7723
         * Sets the column headers as an <code>AccessibleTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7724
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7725
         * @param a an <code>AccessibleTable</code> representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7726
         * column headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7727
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7728
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7729
        public void setAccessibleColumnHeader(AccessibleTable a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7730
            // XXX not implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7731
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7732
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7733
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7734
         * Returns the description of the specified row in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7735
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7736
         * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7737
         * @return the description of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7738
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7739
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7740
        public Accessible getAccessibleRowDescription(int r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7741
            if (r < 0 || r >= getAccessibleRowCount()) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  7742
                throw new IllegalArgumentException(Integer.toString(r));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7743
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7744
            if (rowDescription == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7745
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7746
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7747
                return rowDescription[r];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7748
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7750
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7751
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7752
         * Sets the description text of the specified row of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7753
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7754
         * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7755
         * @param a the description of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7756
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7757
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7758
        public void setAccessibleRowDescription(int r, Accessible a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7759
            if (r < 0 || r >= getAccessibleRowCount()) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  7760
                throw new IllegalArgumentException(Integer.toString(r));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7761
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7762
            if (rowDescription == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7763
                int numRows = getAccessibleRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7764
                rowDescription = new Accessible[numRows];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7765
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7766
            rowDescription[r] = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7767
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7768
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7769
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7770
         * Returns the description of the specified column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7771
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7772
         * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7773
         * @return the description of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7774
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7775
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7776
        public Accessible getAccessibleColumnDescription(int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7777
            if (c < 0 || c >= getAccessibleColumnCount()) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  7778
                throw new IllegalArgumentException(Integer.toString(c));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7779
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7780
            if (columnDescription == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7781
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7782
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7783
                return columnDescription[c];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7784
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7785
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7786
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7787
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7788
         * Sets the description text of the specified column of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7789
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7790
         * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7791
         * @param a the description of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7792
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7793
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7794
        public void setAccessibleColumnDescription(int c, Accessible a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7795
            if (c < 0 || c >= getAccessibleColumnCount()) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  7796
                throw new IllegalArgumentException(Integer.toString(c));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7797
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7798
            if (columnDescription == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7799
                int numColumns = getAccessibleColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7800
                columnDescription = new Accessible[numColumns];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7801
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7802
            columnDescription[c] = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7803
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7804
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7805
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7806
         * Returns a boolean value indicating whether the accessible at a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7807
         * given (row, column) is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7808
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7809
         * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7810
         * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7811
         * @return the boolean value true if the accessible at (row, column)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7812
         *     is selected; otherwise, the boolean value false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7813
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7814
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7815
        public boolean isAccessibleSelected(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7816
            return JTable.this.isCellSelected(r, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7817
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7818
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7819
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7820
         * Returns a boolean value indicating whether the specified row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7821
         * is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7822
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7823
         * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7824
         * @return the boolean value true if the specified row is selected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7825
         *     otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7826
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7827
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7828
        public boolean isAccessibleRowSelected(int r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7829
            return JTable.this.isRowSelected(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7830
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7831
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7832
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7833
         * Returns a boolean value indicating whether the specified column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7834
         * is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7835
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7836
         * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7837
         * @return the boolean value true if the specified column is selected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7838
         *     otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7839
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7840
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7841
        public boolean isAccessibleColumnSelected(int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7842
            return JTable.this.isColumnSelected(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7843
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7844
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7845
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7846
         * Returns the selected rows in a table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7847
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7848
         * @return an array of selected rows where each element is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7849
         *     zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7850
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7851
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7852
        public int [] getSelectedAccessibleRows() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7853
            return JTable.this.getSelectedRows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7854
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7855
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7856
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7857
         * Returns the selected columns in a table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7858
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7859
         * @return an array of selected columns where each element is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7860
         *     zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7861
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7862
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7863
        public int [] getSelectedAccessibleColumns() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7864
            return JTable.this.getSelectedColumns();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7865
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7866
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7867
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7868
         * Returns the row at a given index into the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7869
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7870
         * @param i zero-based index into the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7871
         * @return the row at a given index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7872
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7873
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7874
        public int getAccessibleRowAtIndex(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7875
            int columnCount = getAccessibleColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7876
            if (columnCount == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7877
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7878
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7879
                return (i / columnCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7880
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7881
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7882
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7883
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7884
         * Returns the column at a given index into the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7885
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7886
         * @param i zero-based index into the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7887
         * @return the column at a given index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7888
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7889
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7890
        public int getAccessibleColumnAtIndex(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7891
            int columnCount = getAccessibleColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7892
            if (columnCount == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7893
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7894
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7895
                return (i % columnCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7896
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7897
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7898
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7899
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7900
         * Returns the index at a given (row, column) in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7901
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7902
         * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7903
         * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7904
         * @return the index into the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7905
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7906
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7907
        public int getAccessibleIndexAt(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7908
            return ((r * getAccessibleColumnCount()) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7909
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7910
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7911
        // end of AccessibleTable implementation --------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7912
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7913
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7914
         * The class provides an implementation of the Java Accessibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7915
         * API appropriate to table cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7916
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7917
        protected class AccessibleJTableCell extends AccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7918
            implements Accessible, AccessibleComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7919
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7920
            private JTable parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7921
            private int row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7922
            private int column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7923
            private int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7924
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7925
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7926
             *  Constructs an <code>AccessibleJTableHeaderEntry</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7927
             * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7928
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7929
            public AccessibleJTableCell(JTable t, int r, int c, int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7930
                parent = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7931
                row = r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7932
                column = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7933
                index = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7934
                this.setAccessibleParent(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7935
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7936
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7937
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7938
             * Gets the <code>AccessibleContext</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7939
             * component. In the implementation of the Java Accessibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7940
             * API for this class, return this object, which is its own
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7941
             * <code>AccessibleContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7942
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7943
             * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7944
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7945
            public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7946
                return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7947
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7948
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7949
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7950
             * Gets the AccessibleContext for the table cell renderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7951
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7952
             * @return the <code>AccessibleContext</code> for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7953
             * cell renderer if one exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7954
             * otherwise, returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7955
             * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7956
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7957
            protected AccessibleContext getCurrentAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7958
                TableColumn aColumn = getColumnModel().getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7959
                TableCellRenderer renderer = aColumn.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7960
                if (renderer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7961
                    Class<?> columnClass = getColumnClass(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7962
                    renderer = getDefaultRenderer(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7963
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7964
                Component component = renderer.getTableCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7965
                                  JTable.this, getValueAt(row, column),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7966
                                  false, false, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7967
                if (component instanceof Accessible) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  7968
                    return component.getAccessibleContext();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7969
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7970
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7971
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7972
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7973
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7974
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7975
             * Gets the table cell renderer component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7976
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7977
             * @return the table cell renderer component if one exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7978
             * otherwise, returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7979
             * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7980
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7981
            protected Component getCurrentComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7982
                TableColumn aColumn = getColumnModel().getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7983
                TableCellRenderer renderer = aColumn.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7984
                if (renderer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7985
                    Class<?> columnClass = getColumnClass(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7986
                    renderer = getDefaultRenderer(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7987
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7988
                return renderer.getTableCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7989
                                  JTable.this, null, false, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7990
                                  row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7991
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7992
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7993
        // AccessibleContext methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7994
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7995
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7996
             * Gets the accessible name of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7997
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7998
             * @return the localized name of the object; <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7999
             *     if this object does not have a name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8000
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8001
            public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8002
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8003
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8004
                    String name = ac.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8005
                    if ((name != null) && (name != "")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8006
                        // return the cell renderer's AccessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8007
                        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8008
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8009
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8010
                if ((accessibleName != null) && (accessibleName != "")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8011
                    return accessibleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8012
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8013
                    // fall back to the client property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8014
                    return (String)getClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8015
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8016
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8018
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8019
             * Sets the localized accessible name of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8020
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8021
             * @param s the new localized name of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8022
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8023
            public void setAccessibleName(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8024
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8025
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8026
                    ac.setAccessibleName(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8027
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8028
                    super.setAccessibleName(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8029
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8030
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8032
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8033
            // *** should check toolTip text for desc. (needs MouseEvent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8034
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8035
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8036
             * Gets the accessible description of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8037
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8038
             * @return the localized description of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8039
             *     <code>null</code> if this object does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8040
             *     a description
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8041
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8042
            public String getAccessibleDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8043
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8044
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8045
                    return ac.getAccessibleDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8046
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8047
                    return super.getAccessibleDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8048
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8049
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8051
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8052
             * Sets the accessible description of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8053
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8054
             * @param s the new localized description of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8055
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8056
            public void setAccessibleDescription(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8057
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8058
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8059
                    ac.setAccessibleDescription(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8060
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8061
                    super.setAccessibleDescription(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8062
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8063
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8065
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8066
             * Gets the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8067
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8068
             * @return an instance of <code>AccessibleRole</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8069
             *      describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8070
             * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8071
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8072
            public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8073
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8074
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8075
                    return ac.getAccessibleRole();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8076
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8077
                    return AccessibleRole.UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8078
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8079
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8081
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8082
             * Gets the state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8083
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8084
             * @return an instance of <code>AccessibleStateSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8085
             *     containing the current state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8086
             * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8087
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8088
            public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8089
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8090
                AccessibleStateSet as = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8092
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8093
                    as = ac.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8094
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8095
                if (as == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8096
                    as = new AccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8097
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8098
                Rectangle rjt = JTable.this.getVisibleRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8099
                Rectangle rcell = JTable.this.getCellRect(row, column, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8100
                if (rjt.intersects(rcell)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8101
                    as.add(AccessibleState.SHOWING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8102
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8103
                    if (as.contains(AccessibleState.SHOWING)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8104
                         as.remove(AccessibleState.SHOWING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8105
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8106
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8107
                if (parent.isCellSelected(row, column)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8108
                    as.add(AccessibleState.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8109
                } else if (as.contains(AccessibleState.SELECTED)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8110
                    as.remove(AccessibleState.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8111
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8112
                if ((row == getSelectedRow()) && (column == getSelectedColumn())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8113
                    as.add(AccessibleState.ACTIVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8114
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8115
                as.add(AccessibleState.TRANSIENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8116
                return as;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8117
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8119
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8120
             * Gets the <code>Accessible</code> parent of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8121
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8122
             * @return the Accessible parent of this object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8123
             *     <code>null</code> if this object does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8124
             *     have an <code>Accessible</code> parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8125
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8126
            public Accessible getAccessibleParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8127
                return parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8128
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8130
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8131
             * Gets the index of this object in its accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8132
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8133
             * @return the index of this object in its parent; -1 if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8134
             *     object does not have an accessible parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8135
             * @see #getAccessibleParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8136
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8137
            public int getAccessibleIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8138
                return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8139
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8141
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8142
             * Returns the number of accessible children in the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8143
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8144
             * @return the number of accessible children in the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8145
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8146
            public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8147
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8148
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8149
                    return ac.getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8150
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8151
                    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8152
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8153
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8155
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8156
             * Returns the specified <code>Accessible</code> child of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8157
             * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8158
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8159
             * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8160
             * @return the <code>Accessible</code> child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8161
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8162
            public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8163
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8164
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8165
                    Accessible accessibleChild = ac.getAccessibleChild(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8166
                    ac.setAccessibleParent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8167
                    return accessibleChild;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8168
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8169
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8170
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8171
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8172
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8173
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8174
             * Gets the locale of the component. If the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8175
             * does not have a locale, then the locale of its parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8176
             * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8177
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8178
             * @return this component's locale; if this component does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8179
             *    not have a locale, the locale of its parent is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8180
             * @exception IllegalComponentStateException if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8181
             *    <code>Component</code> does not have its own locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8182
             *    and has not yet been added to a containment hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8183
             *    such that the locale can be determined from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8184
             *    containing parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8185
             * @see #setLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8186
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8187
            public Locale getLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8188
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8189
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8190
                    return ac.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8191
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8192
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8193
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8194
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8195
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8196
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8197
             * Adds a <code>PropertyChangeListener</code> to the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8198
             * The listener is registered for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8199
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8200
             * @param l  the <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8201
             *     to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8202
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8203
            public void addPropertyChangeListener(PropertyChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8204
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8205
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8206
                    ac.addPropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8207
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8208
                    super.addPropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8209
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8210
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8212
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8213
             * Removes a <code>PropertyChangeListener</code> from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8214
             * listener list. This removes a <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8215
             * that was registered for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8216
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8217
             * @param l  the <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8218
             *    to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8219
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8220
            public void removePropertyChangeListener(PropertyChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8221
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8222
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8223
                    ac.removePropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8224
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8225
                    super.removePropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8226
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8229
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8230
             * Gets the <code>AccessibleAction</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8231
             * object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8232
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8233
             * @return the <code>AccessibleAction</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8234
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8235
            public AccessibleAction getAccessibleAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8236
                return getCurrentAccessibleContext().getAccessibleAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8237
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8239
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8240
             * Gets the <code>AccessibleComponent</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8241
             * this object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8242
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8243
             * @return the <code>AccessibleComponent</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8244
             *    <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8245
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8246
            public AccessibleComponent getAccessibleComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8247
                return this; // to override getBounds()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8248
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8250
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8251
             * Gets the <code>AccessibleSelection</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8252
             * this object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8253
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8254
             * @return the <code>AccessibleSelection</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8255
             *    <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8256
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8257
            public AccessibleSelection getAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8258
                return getCurrentAccessibleContext().getAccessibleSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8259
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8261
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8262
             * Gets the <code>AccessibleText</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8263
             * object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8264
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8265
             * @return the <code>AccessibleText</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8266
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8267
            public AccessibleText getAccessibleText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8268
                return getCurrentAccessibleContext().getAccessibleText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8269
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8271
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8272
             * Gets the <code>AccessibleValue</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8273
             * this object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8274
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8275
             * @return the <code>AccessibleValue</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8276
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8277
            public AccessibleValue getAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8278
                return getCurrentAccessibleContext().getAccessibleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8279
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8280
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8282
        // AccessibleComponent methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8284
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8285
             * Gets the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8286
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8287
             * @return the background color, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8288
             *     otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8289
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8290
            public Color getBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8291
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8292
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8293
                    return ((AccessibleComponent) ac).getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8294
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8295
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8296
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8297
                        return c.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8298
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8299
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8300
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8301
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8302
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8303
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8304
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8305
             * Sets the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8306
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8307
             * @param c the new <code>Color</code> for the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8308
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8309
            public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8310
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8311
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8312
                    ((AccessibleComponent) ac).setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8313
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8314
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8315
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8316
                        cp.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8317
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8318
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8319
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8321
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8322
             * Gets the foreground color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8323
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8324
             * @return the foreground color, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8325
             *     otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8326
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8327
            public Color getForeground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8328
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8329
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8330
                    return ((AccessibleComponent) ac).getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8331
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8332
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8333
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8334
                        return c.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8335
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8336
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8337
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8338
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8339
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8340
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8341
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8342
             * Sets the foreground color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8343
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8344
             * @param c the new <code>Color</code> for the foreground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8345
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8346
            public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8347
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8348
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8349
                    ((AccessibleComponent) ac).setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8350
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8351
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8352
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8353
                        cp.setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8354
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8355
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8356
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8357
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8358
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8359
             * Gets the <code>Cursor</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8360
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8361
             * @return the <code>Cursor</code>, if supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8362
             *    of the object; otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8363
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8364
            public Cursor getCursor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8365
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8366
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8367
                    return ((AccessibleComponent) ac).getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8368
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8369
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8370
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8371
                        return c.getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8372
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8373
                        Accessible ap = getAccessibleParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8374
                        if (ap instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8375
                            return ((AccessibleComponent) ap).getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8376
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8377
                            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8378
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8379
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8380
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8381
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8383
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8384
             * Sets the <code>Cursor</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8385
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8386
             * @param c the new <code>Cursor</code> for the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8387
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8388
            public void setCursor(Cursor c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8389
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8390
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8391
                    ((AccessibleComponent) ac).setCursor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8392
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8393
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8394
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8395
                        cp.setCursor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8396
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8397
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8398
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8400
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8401
             * Gets the <code>Font</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8402
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8403
             * @return the <code>Font</code>,if supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8404
             *   for the object; otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8405
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8406
            public Font getFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8407
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8408
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8409
                    return ((AccessibleComponent) ac).getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8410
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8411
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8412
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8413
                        return c.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8414
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8415
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8416
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8417
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8418
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8419
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8420
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8421
             * Sets the <code>Font</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8422
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8423
             * @param f the new <code>Font</code> for the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8424
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8425
            public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8426
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8427
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8428
                    ((AccessibleComponent) ac).setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8429
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8430
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8431
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8432
                        c.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8433
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8434
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8435
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8436
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8437
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8438
             * Gets the <code>FontMetrics</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8439
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8440
             * @param f the <code>Font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8441
             * @return the <code>FontMetrics</code> object, if supported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8442
             *    otherwise <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8443
             * @see #getFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8444
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8445
            public FontMetrics getFontMetrics(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8446
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8447
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8448
                    return ((AccessibleComponent) ac).getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8449
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8450
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8451
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8452
                        return c.getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8453
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8454
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8455
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8456
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8457
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8458
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8459
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8460
             * Determines if the object is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8461
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8462
             * @return true if object is enabled; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8463
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8464
            public boolean isEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8465
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8466
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8467
                    return ((AccessibleComponent) ac).isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8468
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8469
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8470
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8471
                        return c.isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8472
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8473
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8474
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8475
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8476
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8477
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8478
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8479
             * Sets the enabled state of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8480
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8481
             * @param b if true, enables this object; otherwise, disables it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8482
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8483
            public void setEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8484
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8485
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8486
                    ((AccessibleComponent) ac).setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8487
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8488
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8489
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8490
                        c.setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8491
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8492
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8493
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8495
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8496
             * Determines if this object is visible.  Note: this means that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8497
             * object intends to be visible; however, it may not in fact be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8498
             * showing on the screen because one of the objects that this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8499
             * is contained by is not visible.  To determine if an object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8500
             * showing on the screen, use <code>isShowing</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8501
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8502
             * @return true if object is visible; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8503
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8504
            public boolean isVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8505
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8506
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8507
                    return ((AccessibleComponent) ac).isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8508
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8509
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8510
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8511
                        return c.isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8512
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8513
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8514
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8515
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8516
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8517
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8518
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8519
             * Sets the visible state of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8520
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8521
             * @param b if true, shows this object; otherwise, hides it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8522
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8523
            public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8524
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8525
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8526
                    ((AccessibleComponent) ac).setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8527
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8528
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8529
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8530
                        c.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8531
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8532
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8533
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8534
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8535
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8536
             * Determines if the object is showing.  This is determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8537
             * by checking the visibility of the object and ancestors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8538
             * of the object.  Note: this will return true even if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8539
             * object is obscured by another (for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8540
             * it happens to be underneath a menu that was pulled down).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8541
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8542
             * @return true if the object is showing; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8543
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8544
            public boolean isShowing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8545
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8546
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8547
                    if (ac.getAccessibleParent() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8548
                        return ((AccessibleComponent) ac).isShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8549
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8550
                        // Fixes 4529616 - AccessibleJTableCell.isShowing()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8551
                        // returns false when the cell on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8552
                        // if no parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8553
                        return isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8554
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8555
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8556
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8557
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8558
                        return c.isShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8559
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8560
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8561
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8562
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8563
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8564
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8565
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8566
             * Checks whether the specified point is within this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8567
             * object's bounds, where the point's x and y coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8568
             * are defined to be relative to the coordinate system of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8569
             * the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8570
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8571
             * @param p the <code>Point</code> relative to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8572
             *    coordinate system of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8573
             * @return true if object contains <code>Point</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8574
             *    otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8575
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8576
            public boolean contains(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8577
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8578
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8579
                    Rectangle r = ((AccessibleComponent) ac).getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8580
                    return r.contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8581
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8582
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8583
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8584
                        Rectangle r = c.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8585
                        return r.contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8586
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8587
                        return getBounds().contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8588
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8589
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8590
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8591
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8592
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8593
             * Returns the location of the object on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8594
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8595
             * @return location of object on screen -- can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8596
             *    <code>null</code> if this object is not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8597
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8598
            public Point getLocationOnScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8599
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8600
                    Point parentLocation = parent.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8601
                    Point componentLocation = getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8602
                    componentLocation.translate(parentLocation.x, parentLocation.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8603
                    return componentLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8604
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8605
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8606
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8607
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8608
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8609
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8610
             * Gets the location of the object relative to the parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8611
             * in the form of a point specifying the object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8612
             * top-left corner in the screen's coordinate space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8613
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8614
             * @return an instance of <code>Point</code> representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8615
             *    the top-left corner of the object's bounds in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8616
             *    coordinate space of the screen; <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8617
             *    this object or its parent are not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8618
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8619
            public Point getLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8620
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8621
                    Rectangle r = parent.getCellRect(row, column, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8622
                    if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8623
                        return r.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8624
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8625
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8626
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8627
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8628
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8629
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8630
             * Sets the location of the object relative to the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8631
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8632
            public void setLocation(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8633
//              if ((parent != null)  && (parent.contains(p))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8634
//                  ensureIndexIsVisible(indexInParent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8635
//              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8636
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8637
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8638
            public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8639
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8640
                    return parent.getCellRect(row, column, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8641
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8642
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8643
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8644
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8645
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8646
            public void setBounds(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8647
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8648
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8649
                    ((AccessibleComponent) ac).setBounds(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8650
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8651
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8652
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8653
                        c.setBounds(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8654
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8655
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8656
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8657
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8658
            public Dimension getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8659
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8660
                    Rectangle r = parent.getCellRect(row, column, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8661
                    if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8662
                        return r.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8663
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8664
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8665
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8666
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8667
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8668
            public void setSize (Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8669
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8670
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8671
                    ((AccessibleComponent) ac).setSize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8672
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8673
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8674
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8675
                        c.setSize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8676
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8677
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8678
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8679
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8680
            public Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8681
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8682
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8683
                    return ((AccessibleComponent) ac).getAccessibleAt(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8684
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8685
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8686
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8687
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8688
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8689
            public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8690
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8691
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8692
                    return ((AccessibleComponent) ac).isFocusTraversable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8693
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8694
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8695
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8696
                        return c.isFocusTraversable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8697
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8698
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8699
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8700
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8701
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8702
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8703
            public void requestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8704
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8705
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8706
                    ((AccessibleComponent) ac).requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8707
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8708
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8709
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8710
                        c.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8711
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8712
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8713
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8714
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8715
            public void addFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8716
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8717
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8718
                    ((AccessibleComponent) ac).addFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8719
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8720
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8721
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8722
                        c.addFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8723
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8724
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8725
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8726
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8727
            public void removeFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8728
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8729
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8730
                    ((AccessibleComponent) ac).removeFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8731
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8732
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8733
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8734
                        c.removeFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8735
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8736
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8737
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8738
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8739
        } // inner class AccessibleJTableCell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8740
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8741
        // Begin AccessibleJTableHeader ========== // TIGER - 4715503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8742
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8743
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8744
         * This class implements accessibility for JTable header cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8745
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8746
        private class AccessibleJTableHeaderCell extends AccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8747
            implements Accessible, AccessibleComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8748
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8749
            private int row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8750
            private int column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8751
            private JTableHeader parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8752
            private Component rendererComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8753
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8754
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8755
             * Constructs an <code>AccessibleJTableHeaderEntry</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8756
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8757
             * @param row header cell row index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8758
             * @param column header cell column index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8759
             * @param parent header cell parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8760
             * @param rendererComponent component that renders the header cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8761
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8762
            public AccessibleJTableHeaderCell(int row, int column,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8763
                                              JTableHeader parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8764
                                              Component rendererComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8765
                this.row = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8766
                this.column = column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8767
                this.parent = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8768
                this.rendererComponent = rendererComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8769
                this.setAccessibleParent(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8770
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8771
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8772
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8773
             * Gets the <code>AccessibleContext</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8774
             * component. In the implementation of the Java Accessibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8775
             * API for this class, return this object, which is its own
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8776
             * <code>AccessibleContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8777
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8778
             * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8779
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8780
            public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8781
                return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8782
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8783
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8784
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8785
             * Returns the AccessibleContext for the header cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8786
             * renderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8787
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8788
            private AccessibleContext getCurrentAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8789
                return rendererComponent.getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8790
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8791
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8792
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8793
             * Returns the component that renders the header cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8794
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8795
            private Component getCurrentComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8796
                return rendererComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8797
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8798
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8799
            // AccessibleContext methods ==========
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8800
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8801
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8802
             * Gets the accessible name of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8803
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8804
             * @return the localized name of the object; <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8805
             *     if this object does not have a name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8806
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8807
            public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8808
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8809
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8810
                    String name = ac.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8811
                    if ((name != null) && (name != "")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8812
                        return ac.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8813
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8814
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8815
                if ((accessibleName != null) && (accessibleName != "")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8816
                    return accessibleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8817
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8818
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8819
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8820
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8821
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8822
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8823
             * Sets the localized accessible name of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8824
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8825
             * @param s the new localized name of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8826
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8827
            public void setAccessibleName(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8828
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8829
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8830
                    ac.setAccessibleName(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8831
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8832
                    super.setAccessibleName(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8833
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8834
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8835
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8836
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8837
             * Gets the accessible description of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8838
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8839
             * @return the localized description of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8840
             *     <code>null</code> if this object does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8841
             *     a description
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8842
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8843
            public String getAccessibleDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8844
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8845
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8846
                    return ac.getAccessibleDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8847
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8848
                    return super.getAccessibleDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8849
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8850
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8851
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8852
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8853
             * Sets the accessible description of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8854
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8855
             * @param s the new localized description of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8856
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8857
            public void setAccessibleDescription(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8858
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8859
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8860
                    ac.setAccessibleDescription(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8861
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8862
                    super.setAccessibleDescription(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8863
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8864
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8865
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8866
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8867
             * Gets the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8868
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8869
             * @return an instance of <code>AccessibleRole</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8870
             *      describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8871
             * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8872
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8873
            public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8874
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8875
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8876
                    return ac.getAccessibleRole();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8877
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8878
                    return AccessibleRole.UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8879
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8880
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8881
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8882
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8883
             * Gets the state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8884
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8885
             * @return an instance of <code>AccessibleStateSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8886
             *     containing the current state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8887
             * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8888
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8889
            public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8890
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8891
                AccessibleStateSet as = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8892
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8893
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8894
                    as = ac.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8895
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8896
                if (as == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8897
                    as = new AccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8898
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8899
                Rectangle rjt = JTable.this.getVisibleRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8900
                Rectangle rcell = JTable.this.getCellRect(row, column, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8901
                if (rjt.intersects(rcell)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8902
                    as.add(AccessibleState.SHOWING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8903
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8904
                    if (as.contains(AccessibleState.SHOWING)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8905
                         as.remove(AccessibleState.SHOWING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8906
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8907
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8908
                if (JTable.this.isCellSelected(row, column)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8909
                    as.add(AccessibleState.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8910
                } else if (as.contains(AccessibleState.SELECTED)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8911
                    as.remove(AccessibleState.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8912
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8913
                if ((row == getSelectedRow()) && (column == getSelectedColumn())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8914
                    as.add(AccessibleState.ACTIVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8915
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8916
                as.add(AccessibleState.TRANSIENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8917
                return as;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8918
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8919
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8920
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8921
             * Gets the <code>Accessible</code> parent of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8922
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8923
             * @return the Accessible parent of this object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8924
             *     <code>null</code> if this object does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8925
             *     have an <code>Accessible</code> parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8926
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8927
            public Accessible getAccessibleParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8928
                return parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8929
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8930
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8931
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8932
             * Gets the index of this object in its accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8933
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8934
             * @return the index of this object in its parent; -1 if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8935
             *     object does not have an accessible parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8936
             * @see #getAccessibleParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8937
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8938
            public int getAccessibleIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8939
                return column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8940
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8941
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8942
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8943
             * Returns the number of accessible children in the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8944
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8945
             * @return the number of accessible children in the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8946
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8947
            public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8948
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8949
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8950
                    return ac.getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8951
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8952
                    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8953
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8954
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8955
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8956
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8957
             * Returns the specified <code>Accessible</code> child of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8958
             * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8959
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8960
             * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8961
             * @return the <code>Accessible</code> child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8962
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8963
            public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8964
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8965
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8966
                    Accessible accessibleChild = ac.getAccessibleChild(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8967
                    ac.setAccessibleParent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8968
                    return accessibleChild;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8969
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8970
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8971
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8972
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8973
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8974
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8975
             * Gets the locale of the component. If the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8976
             * does not have a locale, then the locale of its parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8977
             * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8978
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8979
             * @return this component's locale; if this component does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8980
             *    not have a locale, the locale of its parent is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8981
             * @exception IllegalComponentStateException if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8982
             *    <code>Component</code> does not have its own locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8983
             *    and has not yet been added to a containment hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8984
             *    such that the locale can be determined from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8985
             *    containing parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8986
             * @see #setLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8987
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8988
            public Locale getLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8989
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8990
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8991
                    return ac.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8992
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8993
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8994
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8995
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8996
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8997
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8998
             * Adds a <code>PropertyChangeListener</code> to the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8999
             * The listener is registered for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9000
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9001
             * @param l  the <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9002
             *     to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9003
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9004
            public void addPropertyChangeListener(PropertyChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9005
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9006
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9007
                    ac.addPropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9008
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9009
                    super.addPropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9010
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9011
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9013
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9014
             * Removes a <code>PropertyChangeListener</code> from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9015
             * listener list. This removes a <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9016
             * that was registered for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9017
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9018
             * @param l  the <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9019
             *    to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9020
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9021
            public void removePropertyChangeListener(PropertyChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9022
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9023
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9024
                    ac.removePropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9025
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9026
                    super.removePropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9027
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9028
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9030
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9031
             * Gets the <code>AccessibleAction</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9032
             * object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9033
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9034
             * @return the <code>AccessibleAction</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9035
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9036
            public AccessibleAction getAccessibleAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9037
                return getCurrentAccessibleContext().getAccessibleAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9038
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9039
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9040
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9041
             * Gets the <code>AccessibleComponent</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9042
             * this object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9043
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9044
             * @return the <code>AccessibleComponent</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9045
             *    <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9046
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9047
            public AccessibleComponent getAccessibleComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9048
                return this; // to override getBounds()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9049
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9051
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9052
             * Gets the <code>AccessibleSelection</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9053
             * this object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9054
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9055
             * @return the <code>AccessibleSelection</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9056
             *    <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9057
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9058
            public AccessibleSelection getAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9059
                return getCurrentAccessibleContext().getAccessibleSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9060
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9062
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9063
             * Gets the <code>AccessibleText</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9064
             * object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9065
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9066
             * @return the <code>AccessibleText</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9067
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9068
            public AccessibleText getAccessibleText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9069
                return getCurrentAccessibleContext().getAccessibleText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9070
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9072
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9073
             * Gets the <code>AccessibleValue</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9074
             * this object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9075
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9076
             * @return the <code>AccessibleValue</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9077
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9078
            public AccessibleValue getAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9079
                return getCurrentAccessibleContext().getAccessibleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9080
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9083
            // AccessibleComponent methods ==========
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9085
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9086
             * Gets the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9087
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9088
             * @return the background color, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9089
             *     otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9090
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9091
            public Color getBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9092
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9093
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9094
                    return ((AccessibleComponent) ac).getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9095
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9096
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9097
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9098
                        return c.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9099
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9100
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9101
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9102
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9103
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9105
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9106
             * Sets the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9107
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9108
             * @param c the new <code>Color</code> for the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9109
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9110
            public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9111
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9112
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9113
                    ((AccessibleComponent) ac).setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9114
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9115
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9116
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9117
                        cp.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9118
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9119
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9120
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9122
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9123
             * Gets the foreground color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9124
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9125
             * @return the foreground color, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9126
             *     otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9127
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9128
            public Color getForeground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9129
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9130
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9131
                    return ((AccessibleComponent) ac).getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9132
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9133
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9134
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9135
                        return c.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9136
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9137
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9138
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9139
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9140
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9141
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9142
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9143
             * Sets the foreground color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9144
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9145
             * @param c the new <code>Color</code> for the foreground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9146
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9147
            public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9148
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9149
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9150
                    ((AccessibleComponent) ac).setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9151
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9152
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9153
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9154
                        cp.setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9155
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9156
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9157
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9159
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9160
             * Gets the <code>Cursor</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9161
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9162
             * @return the <code>Cursor</code>, if supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9163
             *    of the object; otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9164
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9165
            public Cursor getCursor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9166
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9167
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9168
                    return ((AccessibleComponent) ac).getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9169
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9170
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9171
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9172
                        return c.getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9173
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9174
                        Accessible ap = getAccessibleParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9175
                        if (ap instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9176
                            return ((AccessibleComponent) ap).getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9177
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9178
                            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9179
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9180
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9181
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9182
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9184
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9185
             * Sets the <code>Cursor</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9186
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9187
             * @param c the new <code>Cursor</code> for the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9188
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9189
            public void setCursor(Cursor c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9190
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9191
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9192
                    ((AccessibleComponent) ac).setCursor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9193
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9194
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9195
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9196
                        cp.setCursor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9197
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9198
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9199
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9201
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9202
             * Gets the <code>Font</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9203
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9204
             * @return the <code>Font</code>,if supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9205
             *   for the object; otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9206
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9207
            public Font getFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9208
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9209
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9210
                    return ((AccessibleComponent) ac).getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9211
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9212
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9213
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9214
                        return c.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9215
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9216
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9217
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9218
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9221
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9222
             * Sets the <code>Font</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9223
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9224
             * @param f the new <code>Font</code> for the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9225
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9226
            public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9227
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9228
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9229
                    ((AccessibleComponent) ac).setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9230
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9231
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9232
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9233
                        c.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9234
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9235
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9238
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9239
             * Gets the <code>FontMetrics</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9240
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9241
             * @param f the <code>Font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9242
             * @return the <code>FontMetrics</code> object, if supported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9243
             *    otherwise <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9244
             * @see #getFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9245
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9246
            public FontMetrics getFontMetrics(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9247
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9248
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9249
                    return ((AccessibleComponent) ac).getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9250
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9251
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9252
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9253
                        return c.getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9254
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9255
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9256
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9257
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9258
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9259
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9260
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9261
             * Determines if the object is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9262
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9263
             * @return true if object is enabled; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9264
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9265
            public boolean isEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9266
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9267
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9268
                    return ((AccessibleComponent) ac).isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9269
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9270
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9271
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9272
                        return c.isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9273
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9274
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9275
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9276
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9277
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9278
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9279
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9280
             * Sets the enabled state of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9281
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9282
             * @param b if true, enables this object; otherwise, disables it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9283
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9284
            public void setEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9285
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9286
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9287
                    ((AccessibleComponent) ac).setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9288
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9289
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9290
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9291
                        c.setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9292
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9293
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9294
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9295
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9296
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9297
             * Determines if this object is visible.  Note: this means that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9298
             * object intends to be visible; however, it may not in fact be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9299
             * showing on the screen because one of the objects that this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9300
             * is contained by is not visible.  To determine if an object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9301
             * showing on the screen, use <code>isShowing</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9302
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9303
             * @return true if object is visible; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9304
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9305
            public boolean isVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9306
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9307
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9308
                    return ((AccessibleComponent) ac).isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9309
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9310
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9311
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9312
                        return c.isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9313
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9314
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9315
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9316
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9317
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9319
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9320
             * Sets the visible state of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9321
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9322
             * @param b if true, shows this object; otherwise, hides it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9323
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9324
            public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9325
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9326
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9327
                    ((AccessibleComponent) ac).setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9328
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9329
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9330
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9331
                        c.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9332
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9333
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9334
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9336
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9337
             * Determines if the object is showing.  This is determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9338
             * by checking the visibility of the object and ancestors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9339
             * of the object.  Note: this will return true even if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9340
             * object is obscured by another (for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9341
             * it happens to be underneath a menu that was pulled down).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9342
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9343
             * @return true if the object is showing; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9344
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9345
            public boolean isShowing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9346
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9347
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9348
                    if (ac.getAccessibleParent() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9349
                        return ((AccessibleComponent) ac).isShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9350
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9351
                        // Fixes 4529616 - AccessibleJTableCell.isShowing()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9352
                        // returns false when the cell on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9353
                        // if no parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9354
                        return isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9355
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9356
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9357
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9358
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9359
                        return c.isShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9360
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9361
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9362
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9363
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9364
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9365
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9366
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9367
             * Checks whether the specified point is within this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9368
             * object's bounds, where the point's x and y coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9369
             * are defined to be relative to the coordinate system of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9370
             * the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9371
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9372
             * @param p the <code>Point</code> relative to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9373
             *    coordinate system of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9374
             * @return true if object contains <code>Point</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9375
             *    otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9376
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9377
            public boolean contains(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9378
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9379
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9380
                    Rectangle r = ((AccessibleComponent) ac).getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9381
                    return r.contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9382
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9383
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9384
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9385
                        Rectangle r = c.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9386
                        return r.contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9387
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9388
                        return getBounds().contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9389
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9390
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9391
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9392
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9393
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9394
             * Returns the location of the object on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9395
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9396
             * @return location of object on screen -- can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9397
             *    <code>null</code> if this object is not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9398
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9399
            public Point getLocationOnScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9400
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9401
                    Point parentLocation = parent.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9402
                    Point componentLocation = getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9403
                    componentLocation.translate(parentLocation.x, parentLocation.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9404
                    return componentLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9405
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9406
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9407
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9408
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9410
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9411
             * Gets the location of the object relative to the parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9412
             * in the form of a point specifying the object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9413
             * top-left corner in the screen's coordinate space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9414
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9415
             * @return an instance of <code>Point</code> representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9416
             *    the top-left corner of the object's bounds in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9417
             *    coordinate space of the screen; <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9418
             *    this object or its parent are not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9419
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9420
            public Point getLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9421
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9422
                    Rectangle r = parent.getHeaderRect(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9423
                    if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9424
                        return r.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9425
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9426
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9427
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9428
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9430
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9431
             * Sets the location of the object relative to the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9432
             * @param p the new position for the top-left corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9433
             * @see #getLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9434
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9435
            public void setLocation(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9436
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9437
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9438
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9439
             * Gets the bounds of this object in the form of a Rectangle object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9440
             * The bounds specify this object's width, height, and location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9441
             * relative to its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9442
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9443
             * @return A rectangle indicating this component's bounds; null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9444
             * this object is not on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9445
             * @see #contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9446
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9447
            public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9448
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9449
                    return parent.getHeaderRect(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9450
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9451
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9452
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9453
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9454
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9455
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9456
             * Sets the bounds of this object in the form of a Rectangle object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9457
             * The bounds specify this object's width, height, and location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9458
             * relative to its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9459
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9460
             * @param r rectangle indicating this component's bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9461
             * @see #getBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9462
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9463
            public void setBounds(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9464
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9465
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9466
                    ((AccessibleComponent) ac).setBounds(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9467
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9468
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9469
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9470
                        c.setBounds(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9471
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9472
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9473
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9474
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9475
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9476
             * Returns the size of this object in the form of a Dimension object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9477
             * The height field of the Dimension object contains this object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9478
             * height, and the width field of the Dimension object contains this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9479
             * object's width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9480
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9481
             * @return A Dimension object that indicates the size of this component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9482
             * null if this object is not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9483
             * @see #setSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9484
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9485
            public Dimension getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9486
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9487
                    Rectangle r = parent.getHeaderRect(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9488
                    if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9489
                        return r.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9490
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9491
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9492
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9493
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9495
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9496
             * Resizes this object so that it has width and height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9497
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9498
             * @param d The dimension specifying the new size of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9499
             * @see #getSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9500
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9501
            public void setSize (Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9502
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9503
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9504
                    ((AccessibleComponent) ac).setSize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9505
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9506
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9507
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9508
                        c.setSize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9509
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9510
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9511
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9512
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9513
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9514
             * Returns the Accessible child, if one exists, contained at the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9515
             * coordinate Point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9516
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9517
             * @param p The point relative to the coordinate system of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9518
             * @return the Accessible, if it exists, at the specified location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9519
             * otherwise null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9520
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9521
            public Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9522
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9523
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9524
                    return ((AccessibleComponent) ac).getAccessibleAt(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9525
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9526
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9527
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9528
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9529
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9530
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9531
             * Returns whether this object can accept focus or not.   Objects that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9532
             * can accept focus will also have the AccessibleState.FOCUSABLE state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9533
             * set in their AccessibleStateSets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9534
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9535
             * @return true if object can accept focus; otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9536
             * @see AccessibleContext#getAccessibleStateSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9537
             * @see AccessibleState#FOCUSABLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9538
             * @see AccessibleState#FOCUSED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9539
             * @see AccessibleStateSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9540
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9541
            public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9542
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9543
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9544
                    return ((AccessibleComponent) ac).isFocusTraversable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9545
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9546
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9547
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9548
                        return c.isFocusTraversable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9549
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9550
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9551
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9552
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9553
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9554
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9555
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9556
             * Requests focus for this object.  If this object cannot accept focus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9557
             * nothing will happen.  Otherwise, the object will attempt to take
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9558
             * focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9559
             * @see #isFocusTraversable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9560
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9561
            public void requestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9562
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9563
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9564
                    ((AccessibleComponent) ac).requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9565
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9566
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9567
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9568
                        c.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9569
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9570
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9571
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9572
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9573
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9574
             * Adds the specified focus listener to receive focus events from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9575
             * component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9576
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9577
             * @param l the focus listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9578
             * @see #removeFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9579
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9580
            public void addFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9581
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9582
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9583
                    ((AccessibleComponent) ac).addFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9584
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9585
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9586
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9587
                        c.addFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9588
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9589
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9590
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9591
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9592
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9593
             * Removes the specified focus listener so it no longer receives focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9594
             * events from this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9595
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9596
             * @param l the focus listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9597
             * @see #addFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9598
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9599
            public void removeFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9600
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9601
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9602
                    ((AccessibleComponent) ac).removeFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9603
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9604
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9605
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9606
                        c.removeFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9607
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9608
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9609
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9610
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9611
        } // inner class AccessibleJTableHeaderCell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9612
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9613
    }  // inner class AccessibleJTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9614
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9615
}  // End of Class JTable