jdk/src/share/classes/javax/swing/JTable.java
author alexp
Thu, 29 Apr 2010 18:38:25 +0400
changeset 5449 21bec46ee9e3
parent 4967 da853cd502c8
child 5506 202f599c92aa
child 5590 3ec077d7e893
permissions -rw-r--r--
6899413: Fix for CR #6878399 should be refactored Reviewed-by: peterz
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() {
5449
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
   722
        Container parent = SwingUtilities.getUnwrappedParent(this);
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
   723
        if (parent instanceof JViewport) {
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
   724
            JViewport port = (JViewport) parent;
3737
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 2658
diff changeset
   725
            Container gp = port.getParent();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            if (gp instanceof JScrollPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                JScrollPane scrollPane = (JScrollPane)gp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                // Make certain we are the viewPort's view and not, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                // example, the rowHeaderView of the scrollPane -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                // an implementor of fixed columns might do this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                JViewport viewport = scrollPane.getViewport();
4278
b7a976422d27 6878399: public SwingUtilities.getParentViewport() is required
alexp
parents: 4272
diff changeset
   732
                if (viewport == null ||
b7a976422d27 6878399: public SwingUtilities.getParentViewport() is required
alexp
parents: 4272
diff changeset
   733
                        SwingUtilities.getUnwrappedView(viewport) != this) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                scrollPane.setColumnHeaderView(getTableHeader());
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   737
                // configure the scrollpane for any LAF dependent settings
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   738
                configureEnclosingScrollPaneUI();
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
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   743
    /**
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   744
     * This is a sub-part of configureEnclosingScrollPane() that configures
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   745
     * anything on the scrollpane that may change when the look and feel
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   746
     * changes. It needed to be split out from configureEnclosingScrollPane() so
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   747
     * that it can be called from updateUI() when the LAF changes without
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   748
     * causing the regression found in bug 6687962. This was because updateUI()
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   749
     * is called from the constructor which then caused
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   750
     * configureEnclosingScrollPane() to be called by the constructor which
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   751
     * changes its contract for any subclass that overrides it. So by splitting
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   752
     * it out in this way configureEnclosingScrollPaneUI() can be called both
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   753
     * from configureEnclosingScrollPane() and updateUI() in a safe manor.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   754
     */
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   755
    private void configureEnclosingScrollPaneUI() {
5449
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
   756
        Container parent = SwingUtilities.getUnwrappedParent(this);
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
   757
        if (parent instanceof JViewport) {
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
   758
            JViewport port = (JViewport) parent;
3737
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 2658
diff changeset
   759
            Container gp = port.getParent();
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   760
            if (gp instanceof JScrollPane) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   761
                JScrollPane scrollPane = (JScrollPane)gp;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   762
                // Make certain we are the viewPort's view and not, for
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   763
                // example, the rowHeaderView of the scrollPane -
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   764
                // an implementor of fixed columns might do this.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   765
                JViewport viewport = scrollPane.getViewport();
4278
b7a976422d27 6878399: public SwingUtilities.getParentViewport() is required
alexp
parents: 4272
diff changeset
   766
                if (viewport == null ||
b7a976422d27 6878399: public SwingUtilities.getParentViewport() is required
alexp
parents: 4272
diff changeset
   767
                        SwingUtilities.getUnwrappedView(viewport) != this) {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   768
                    return;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   769
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                //  scrollPane.getViewport().setBackingStoreEnabled(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                Border border = scrollPane.getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                if (border == null || border instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                    Border scrollPaneBorder =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                        UIManager.getBorder("Table.scrollPaneBorder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                    if (scrollPaneBorder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                        scrollPane.setBorder(scrollPaneBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                }
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   779
                // 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
   780
                Component corner =
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   781
                        scrollPane.getCorner(JScrollPane.UPPER_TRAILING_CORNER);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   782
                if (corner == null || corner instanceof UIResource){
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   783
                    corner = null;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   784
                    Object componentClass = UIManager.get(
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   785
                            "Table.scrollPaneCornerComponent");
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   786
                    if (componentClass instanceof Class){
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   787
                        try {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   788
                            corner = (Component)
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   789
                                    ((Class)componentClass).newInstance();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   790
                        } catch (Exception e) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   791
                            // just ignore and don't set corner
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   792
                        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   793
                    }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   794
                    scrollPane.setCorner(JScrollPane.UPPER_TRAILING_CORNER,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   795
                            corner);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   796
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * Calls the <code>unconfigureEnclosingScrollPane</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * @see #unconfigureEnclosingScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    public void removeNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            removePropertyChangeListener("permanentFocusOwner", editorRemover);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        editorRemover = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        unconfigureEnclosingScrollPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        super.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * Reverses the effect of <code>configureEnclosingScrollPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * by replacing the <code>columnHeaderView</code> of the enclosing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * scroll pane with <code>null</code>. <code>JTable</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * <code>removeNotify</code> method calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * this method, which is protected so that this default uninstallation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * procedure can be overridden by a subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * @see #removeNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * @see #configureEnclosingScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    protected void unconfigureEnclosingScrollPane() {
5449
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
   827
        Container parent = SwingUtilities.getUnwrappedParent(this);
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
   828
        if (parent instanceof JViewport) {
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
   829
            JViewport port = (JViewport) parent;
3737
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 2658
diff changeset
   830
            Container gp = port.getParent();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            if (gp instanceof JScrollPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                JScrollPane scrollPane = (JScrollPane)gp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                // Make certain we are the viewPort's view and not, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                // example, the rowHeaderView of the scrollPane -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                // an implementor of fixed columns might do this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                JViewport viewport = scrollPane.getViewport();
4278
b7a976422d27 6878399: public SwingUtilities.getParentViewport() is required
alexp
parents: 4272
diff changeset
   837
                if (viewport == null ||
b7a976422d27 6878399: public SwingUtilities.getParentViewport() is required
alexp
parents: 4272
diff changeset
   838
                        SwingUtilities.getUnwrappedView(viewport) != this) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                scrollPane.setColumnHeaderView(null);
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   842
                // remove ScrollPane corner if one was added by the LAF
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   843
                Component corner =
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   844
                        scrollPane.getCorner(JScrollPane.UPPER_TRAILING_CORNER);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   845
                if (corner instanceof UIResource){
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   846
                    scrollPane.setCorner(JScrollPane.UPPER_TRAILING_CORNER,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   847
                            null);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   848
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    void setUIProperty(String propertyName, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        if (propertyName == "rowHeight") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            if (!isRowHeightSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                setRowHeight(((Number)value).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                isRowHeightSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        super.setUIProperty(propertyName, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
// Static Methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * Equivalent to <code>new JScrollPane(aTable)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * @deprecated As of Swing version 1.0.2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * replaced by <code>new JScrollPane(aTable)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    static public JScrollPane createScrollPaneForTable(JTable aTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        return new JScrollPane(aTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
// Table Attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * Sets the <code>tableHeader</code> working with this <code>JTable</code> to <code>newHeader</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * It is legal to have a <code>null</code> <code>tableHeader</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * @param   tableHeader                       new tableHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * @see     #getTableHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     *  description: The JTableHeader instance which renders the column headers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    public void setTableHeader(JTableHeader tableHeader) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        if (this.tableHeader != tableHeader) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            JTableHeader old = this.tableHeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            // Release the old header
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            if (old != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                old.setTable(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            this.tableHeader = tableHeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            if (tableHeader != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                tableHeader.setTable(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            firePropertyChange("tableHeader", old, tableHeader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * Returns the <code>tableHeader</code> used by this <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * @return  the <code>tableHeader</code> used by this table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * @see     #setTableHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    public JTableHeader getTableHeader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        return tableHeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * Sets the height, in pixels, of all cells to <code>rowHeight</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * revalidates, and repaints.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * The height of the cells will be equal to the row height minus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * the row margin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * @param   rowHeight                       new row height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * @exception IllegalArgumentException      if <code>rowHeight</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     *                                          less than 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * @see     #getRowHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     *  description: The height of the specified row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    public void setRowHeight(int rowHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        if (rowHeight <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            throw new IllegalArgumentException("New row height less than 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        int old = this.rowHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        this.rowHeight = rowHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        rowModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        if (sortManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            sortManager.modelRowSizes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        isRowHeightSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        firePropertyChange("rowHeight", old, rowHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * Returns the height of a table row, in pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * The default row height is 16.0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * @return  the height in pixels of a table row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * @see     #setRowHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    public int getRowHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        return rowHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    private SizeSequence getRowModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        if (rowModel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            rowModel = new SizeSequence(getRowCount(), getRowHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        return rowModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     * Sets the height for <code>row</code> to <code>rowHeight</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     * revalidates, and repaints. The height of the cells in this row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * will be equal to the row height minus the row margin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     * @param   row                             the row whose height is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                                                changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * @param   rowHeight                       new row height, in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     * @exception IllegalArgumentException      if <code>rowHeight</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     *                                          less than 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     *  description: The height in pixels of the cells in <code>row</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    public void setRowHeight(int row, int rowHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        if (rowHeight <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            throw new IllegalArgumentException("New row height less than 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        getRowModel().setSize(row, rowHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        if (sortManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            sortManager.setViewRowHeight(row, rowHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * Returns the height, in pixels, of the cells in <code>row</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * @param   row              the row whose height is to be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * @return the height, in pixels, of the cells in the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    public int getRowHeight(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        return (rowModel == null) ? getRowHeight() : rowModel.getSize(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * Sets the amount of empty space between cells in adjacent rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * @param  rowMargin  the number of pixels between cells in a row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * @see     #getRowMargin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     *  description: The amount of space between cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
    public void setRowMargin(int rowMargin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        int old = this.rowMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        this.rowMargin = rowMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        firePropertyChange("rowMargin", old, rowMargin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * Gets the amount of empty space, in pixels, between cells. Equivalent to:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * <code>getIntercellSpacing().height</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * @return the number of pixels between cells in a row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     * @see     #setRowMargin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
    public int getRowMargin() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        return rowMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     * Sets the <code>rowMargin</code> and the <code>columnMargin</code> --
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * the height and width of the space between cells -- to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * <code>intercellSpacing</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * @param   intercellSpacing        a <code>Dimension</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     *                                  specifying the new width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     *                                  and height between cells
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     * @see     #getIntercellSpacing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     *  description: The spacing between the cells,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     *               drawn in the background color of the JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    public void setIntercellSpacing(Dimension intercellSpacing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        // Set the rowMargin here and columnMargin in the TableColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        setRowMargin(intercellSpacing.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        getColumnModel().setColumnMargin(intercellSpacing.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     * Returns the horizontal and vertical space between cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     * The default spacing is (1, 1), which provides room to draw the grid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     * @return  the horizontal and vertical spacing between cells
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     * @see     #setIntercellSpacing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    public Dimension getIntercellSpacing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        return new Dimension(getColumnModel().getColumnMargin(), rowMargin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     * Sets the color used to draw grid lines to <code>gridColor</code> and redisplays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * The default color is look and feel dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * @param   gridColor                       the new color of the grid lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * @exception IllegalArgumentException      if <code>gridColor</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * @see     #getGridColor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     *  description: The grid color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    public void setGridColor(Color gridColor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        if (gridColor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            throw new IllegalArgumentException("New color is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        Color old = this.gridColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        this.gridColor = gridColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        firePropertyChange("gridColor", old, gridColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        // Redraw
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     * Returns the color used to draw grid lines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     * The default color is look and feel dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     * @return  the color used to draw grid lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     * @see     #setGridColor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
    public Color getGridColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        return gridColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
     *  Sets whether the table draws grid lines around cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     *  If <code>showGrid</code> is true it does; if it is false it doesn't.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     *  There is no <code>getShowGrid</code> method as this state is held
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     *  in two variables -- <code>showHorizontalLines</code> and <code>showVerticalLines</code> --
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     *  each of which can be queried independently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     * @param   showGrid                 true if table view should draw grid lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * @see     #setShowVerticalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     * @see     #setShowHorizontalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     *  description: The color used to draw the grid lines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
    public void setShowGrid(boolean showGrid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        setShowHorizontalLines(showGrid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        setShowVerticalLines(showGrid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        // Redraw
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     *  Sets whether the table draws horizontal lines between cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     *  If <code>showHorizontalLines</code> is true it does; if it is false it doesn't.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     * @param   showHorizontalLines      true if table view should draw horizontal lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     * @see     #getShowHorizontalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
     * @see     #setShowGrid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
     * @see     #setShowVerticalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     *  description: Whether horizontal lines should be drawn in between the cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    public void setShowHorizontalLines(boolean showHorizontalLines) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        boolean old = this.showHorizontalLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        this.showHorizontalLines = showHorizontalLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        firePropertyChange("showHorizontalLines", old, showHorizontalLines);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        // Redraw
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     *  Sets whether the table draws vertical lines between cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     *  If <code>showVerticalLines</code> is true it does; if it is false it doesn't.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * @param   showVerticalLines              true if table view should draw vertical lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * @see     #getShowVerticalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     * @see     #setShowGrid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * @see     #setShowHorizontalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     *  description: Whether vertical lines should be drawn in between the cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
    public void setShowVerticalLines(boolean showVerticalLines) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        boolean old = this.showVerticalLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        this.showVerticalLines = showVerticalLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        firePropertyChange("showVerticalLines", old, showVerticalLines);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        // Redraw
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     * Returns true if the table draws horizontal lines between cells, false if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     * doesn't. The default is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     * @return  true if the table draws horizontal lines between cells, false if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     *          doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     * @see     #setShowHorizontalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    public boolean getShowHorizontalLines() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        return showHorizontalLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     * Returns true if the table draws vertical lines between cells, false if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     * doesn't. The default is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * @return  true if the table draws vertical lines between cells, false if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     *          doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * @see     #setShowVerticalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
    public boolean getShowVerticalLines() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        return showVerticalLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     * Sets the table's auto resize mode when the table is resized.  For further
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     * information on how the different resize modes work, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     * {@link #doLayout}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     * @param   mode One of 5 legal values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     *                   AUTO_RESIZE_OFF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     *                   AUTO_RESIZE_NEXT_COLUMN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     *                   AUTO_RESIZE_SUBSEQUENT_COLUMNS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     *                   AUTO_RESIZE_LAST_COLUMN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     *                   AUTO_RESIZE_ALL_COLUMNS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     * @see     #getAutoResizeMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     * @see     #doLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     *  description: Whether the columns should adjust themselves automatically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     *        enum: AUTO_RESIZE_OFF                JTable.AUTO_RESIZE_OFF
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     *              AUTO_RESIZE_NEXT_COLUMN        JTable.AUTO_RESIZE_NEXT_COLUMN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
     *              AUTO_RESIZE_SUBSEQUENT_COLUMNS JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     *              AUTO_RESIZE_LAST_COLUMN        JTable.AUTO_RESIZE_LAST_COLUMN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
     *              AUTO_RESIZE_ALL_COLUMNS        JTable.AUTO_RESIZE_ALL_COLUMNS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
    public void setAutoResizeMode(int mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        if ((mode == AUTO_RESIZE_OFF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            (mode == AUTO_RESIZE_NEXT_COLUMN) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            (mode == AUTO_RESIZE_SUBSEQUENT_COLUMNS) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            (mode == AUTO_RESIZE_LAST_COLUMN) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            (mode == AUTO_RESIZE_ALL_COLUMNS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            int old = autoResizeMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
            autoResizeMode = mode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
            if (tableHeader != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                tableHeader.resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
            firePropertyChange("autoResizeMode", old, autoResizeMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
     * Returns the auto resize mode of the table.  The default mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
     * is AUTO_RESIZE_SUBSEQUENT_COLUMNS.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
     * @return  the autoResizeMode of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
     * @see     #setAutoResizeMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
     * @see     #doLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    public int getAutoResizeMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        return autoResizeMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * Sets this table's <code>autoCreateColumnsFromModel</code> flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * This method calls <code>createDefaultColumnsFromModel</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     * <code>autoCreateColumnsFromModel</code> changes from false to true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     * @param   autoCreateColumnsFromModel   true if <code>JTable</code> should automatically create columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * @see     #getAutoCreateColumnsFromModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * @see     #createDefaultColumnsFromModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     *  description: Automatically populates the columnModel when a new TableModel is submitted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
    public void setAutoCreateColumnsFromModel(boolean autoCreateColumnsFromModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        if (this.autoCreateColumnsFromModel != autoCreateColumnsFromModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            boolean old = this.autoCreateColumnsFromModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
            this.autoCreateColumnsFromModel = autoCreateColumnsFromModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
            if (autoCreateColumnsFromModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                createDefaultColumnsFromModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            firePropertyChange("autoCreateColumnsFromModel", old, autoCreateColumnsFromModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     * Determines whether the table will create default columns from the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     * If true, <code>setModel</code> will clear any existing columns and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     * create new columns from the new model.  Also, if the event in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     * the <code>tableChanged</code> notification specifies that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     * entire table changed, then the columns will be rebuilt.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     * The default is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     * @return  the autoCreateColumnsFromModel of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     * @see     #setAutoCreateColumnsFromModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     * @see     #createDefaultColumnsFromModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
    public boolean getAutoCreateColumnsFromModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        return autoCreateColumnsFromModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     * Creates default columns for the table from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     * the data model using the <code>getColumnCount</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
     * defined in the <code>TableModel</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     * Clears any existing columns before creating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     * new columns based on information from the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     * @see     #getAutoCreateColumnsFromModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
    public void createDefaultColumnsFromModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        TableModel m = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        if (m != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
            // Remove any current columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
            TableColumnModel cm = getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            while (cm.getColumnCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
                cm.removeColumn(cm.getColumn(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
            // Create new columns from the data model info
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
            for (int i = 0; i < m.getColumnCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
                TableColumn newColumn = new TableColumn(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                addColumn(newColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     * Sets a default cell renderer to be used if no renderer has been set in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * a <code>TableColumn</code>. If renderer is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     * removes the default renderer for this column class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
     * @param  columnClass     set the default cell renderer for this columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
     * @param  renderer        default cell renderer to be used for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
     *                         columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
     * @see     #getDefaultRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     * @see     #setDefaultEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
    public void setDefaultRenderer(Class<?> columnClass, TableCellRenderer renderer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        if (renderer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            defaultRenderersByColumnClass.put(columnClass, renderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
            defaultRenderersByColumnClass.remove(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
     * Returns the cell renderer to be used when no renderer has been set in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
     * a <code>TableColumn</code>. During the rendering of cells the renderer is fetched from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
     * a <code>Hashtable</code> of entries according to the class of the cells in the column. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
     * there is no entry for this <code>columnClass</code> the method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
     * the entry for the most specific superclass. The <code>JTable</code> installs entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     * for <code>Object</code>, <code>Number</code>, and <code>Boolean</code>, all of which can be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
     * or replaced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
     * @param   columnClass   return the default cell renderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
     *                        for this columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
     * @return  the renderer for this columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
     * @see     #setDefaultRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
     * @see     #getColumnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
    public TableCellRenderer getDefaultRenderer(Class<?> columnClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        if (columnClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
            Object renderer = defaultRenderersByColumnClass.get(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
            if (renderer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                return (TableCellRenderer)renderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
            else {
4379
ce28939f55fc 6888156: With GTK Look and Feel Icons cannot be rendered in Jtable Cells
peterz
parents: 4278
diff changeset
  1343
                Class c = columnClass.getSuperclass();
ce28939f55fc 6888156: With GTK Look and Feel Icons cannot be rendered in Jtable Cells
peterz
parents: 4278
diff changeset
  1344
                if (c == null && columnClass != Object.class) {
ce28939f55fc 6888156: With GTK Look and Feel Icons cannot be rendered in Jtable Cells
peterz
parents: 4278
diff changeset
  1345
                    c = Object.class;
ce28939f55fc 6888156: With GTK Look and Feel Icons cannot be rendered in Jtable Cells
peterz
parents: 4278
diff changeset
  1346
                }
ce28939f55fc 6888156: With GTK Look and Feel Icons cannot be rendered in Jtable Cells
peterz
parents: 4278
diff changeset
  1347
                return getDefaultRenderer(c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
     * Sets a default cell editor to be used if no editor has been set in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
     * a <code>TableColumn</code>. If no editing is required in a table, or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     * particular column in a table, uses the <code>isCellEditable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     * method in the <code>TableModel</code> interface to ensure that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
     * <code>JTable</code> will not start an editor in these columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     * If editor is <code>null</code>, removes the default editor for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
     * column class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
     * @param  columnClass  set the default cell editor for this columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
     * @param  editor   default cell editor to be used for this columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
     * @see     TableModel#isCellEditable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
     * @see     #getDefaultEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
     * @see     #setDefaultRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
    public void setDefaultEditor(Class<?> columnClass, TableCellEditor editor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
        if (editor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
            defaultEditorsByColumnClass.put(columnClass, editor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
            defaultEditorsByColumnClass.remove(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
     * Returns the editor to be used when no editor has been set in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
     * a <code>TableColumn</code>. During the editing of cells the editor is fetched from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
     * a <code>Hashtable</code> of entries according to the class of the cells in the column. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
     * there is no entry for this <code>columnClass</code> the method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
     * the entry for the most specific superclass. The <code>JTable</code> installs entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
     * for <code>Object</code>, <code>Number</code>, and <code>Boolean</code>, all of which can be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
     * or replaced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
     * @param   columnClass  return the default cell editor for this columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
     * @return the default cell editor to be used for this columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
     * @see     #setDefaultEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
     * @see     #getColumnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
    public TableCellEditor getDefaultEditor(Class<?> columnClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
        if (columnClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
            Object editor = defaultEditorsByColumnClass.get(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
            if (editor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
                return (TableCellEditor)editor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                return getDefaultEditor(columnClass.getSuperclass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     * Turns on or off automatic drag handling. In order to enable automatic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     * drag handling, this property should be set to {@code true}, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     * table's {@code TransferHandler} needs to be {@code non-null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     * The default value of the {@code dragEnabled} property is {@code false}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     * The job of honoring this property, and recognizing a user drag gesture,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     * lies with the look and feel implementation, and in particular, the table's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     * {@code TableUI}. When automatic drag handling is enabled, most look and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     * feels (including those that subclass {@code BasicLookAndFeel}) begin a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     * drag and drop operation whenever the user presses the mouse button over
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
     * an item (in single selection mode) or a selection (in other selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     * modes) and then moves the mouse a few pixels. Setting this property to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
     * {@code true} can therefore have a subtle effect on how selections behave.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
     * If a look and feel is used that ignores this property, you can still
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     * begin a drag and drop operation by calling {@code exportAsDrag} on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     * table's {@code TransferHandler}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     * @param b whether or not to enable automatic drag handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     *            <code>b</code> is <code>true</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
     *            <code>GraphicsEnvironment.isHeadless()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
     *            returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
     * @see #getDragEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
     * @see #setTransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
     * @see TransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
     *  description: determines whether automatic drag handling is enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
     *        bound: false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
    public void setDragEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
        if (b && GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
            throw new HeadlessException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
        dragEnabled = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
     * Returns whether or not automatic drag handling is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
     * @return the value of the {@code dragEnabled} property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
     * @see #setDragEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
    public boolean getDragEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
        return dragEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
     * Sets the drop mode for this component. For backward compatibility,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
     * the default for this property is <code>DropMode.USE_SELECTION</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
     * Usage of one of the other modes is recommended, however, for an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
     * improved user experience. <code>DropMode.ON</code>, for instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
     * offers similar behavior of showing items as selected, but does so without
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
     * affecting the actual selection in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
     * <code>JTable</code> supports the following drop modes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
     *    <li><code>DropMode.USE_SELECTION</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
     *    <li><code>DropMode.ON</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
     *    <li><code>DropMode.INSERT</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
     *    <li><code>DropMode.INSERT_ROWS</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
     *    <li><code>DropMode.INSERT_COLS</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
     *    <li><code>DropMode.ON_OR_INSERT</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
     *    <li><code>DropMode.ON_OR_INSERT_ROWS</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
     *    <li><code>DropMode.ON_OR_INSERT_COLS</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
     * The drop mode is only meaningful if this component has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
     * <code>TransferHandler</code> that accepts drops.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
     * @param dropMode the drop mode to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
     * @throws IllegalArgumentException if the drop mode is unsupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
     *         or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
     * @see #getDropMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
     * @see #getDropLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
     * @see #setTransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
     * @see TransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
    public final void setDropMode(DropMode dropMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        if (dropMode != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
            switch (dropMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
                case USE_SELECTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
                case ON:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                case INSERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
                case INSERT_ROWS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
                case INSERT_COLS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
                case ON_OR_INSERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
                case ON_OR_INSERT_ROWS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
                case ON_OR_INSERT_COLS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
                    this.dropMode = dropMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
        throw new IllegalArgumentException(dropMode + ": Unsupported drop mode for table");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
     * Returns the drop mode for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
     * @return the drop mode for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
     * @see #setDropMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
    public final DropMode getDropMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
        return dropMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
     * Calculates a drop location in this component, representing where a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
     * drop at the given point should insert data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
     * @param p the point to calculate a drop location for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
     * @return the drop location, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
    DropLocation dropLocationForPoint(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
        DropLocation location = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
        int row = rowAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
        int col = columnAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
        boolean outside = Boolean.TRUE == getClientProperty("Table.isFileList")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
                          && SwingUtilities2.pointOutsidePrefSize(this, row, col, p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
        Rectangle rect = getCellRect(row, col, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
        Section xSection, ySection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
        boolean between = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
        boolean ltr = getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
        switch(dropMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
            case USE_SELECTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
            case ON:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                if (row == -1 || col == -1 || outside) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
                    location = new DropLocation(p, -1, -1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
                    location = new DropLocation(p, row, col, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
            case INSERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
                if (row == -1 && col == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
                    location = new DropLocation(p, 0, 0, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
                xSection = SwingUtilities2.liesInHorizontal(rect, p, ltr, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                if (row == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
                    if (xSection == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                        location = new DropLocation(p, getRowCount(), col, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                    } else if (xSection == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                        location = new DropLocation(p, getRowCount(), col + 1, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
                        location = new DropLocation(p, getRowCount(), col, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
                } else if (xSection == LEADING || xSection == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                    ySection = SwingUtilities2.liesInVertical(rect, p, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
                    if (ySection == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                        between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
                    } else if (ySection == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
                        row++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
                        between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
                    location = new DropLocation(p, row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
                                                xSection == TRAILING ? col + 1 : col,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
                                                between, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
                    if (SwingUtilities2.liesInVertical(rect, p, false) == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
                        row++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
                    location = new DropLocation(p, row, col, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
            case INSERT_ROWS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                if (row == -1 && col == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
                    location = new DropLocation(p, -1, -1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
                if (row == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
                    location = new DropLocation(p, getRowCount(), col, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
                if (SwingUtilities2.liesInVertical(rect, p, false) == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
                    row++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                location = new DropLocation(p, row, col, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
            case ON_OR_INSERT_ROWS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                if (row == -1 && col == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
                    location = new DropLocation(p, -1, -1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
                if (row == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
                    location = new DropLocation(p, getRowCount(), col, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
                ySection = SwingUtilities2.liesInVertical(rect, p, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
                if (ySection == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
                    between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
                } else if (ySection == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
                    row++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
                    between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
                location = new DropLocation(p, row, col, between, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
            case INSERT_COLS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
                if (row == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
                    location = new DropLocation(p, -1, -1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
                if (col == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
                    location = new DropLocation(p, getColumnCount(), col, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
                if (SwingUtilities2.liesInHorizontal(rect, p, ltr, false) == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
                    col++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
                location = new DropLocation(p, row, col, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
            case ON_OR_INSERT_COLS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
                if (row == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
                    location = new DropLocation(p, -1, -1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
                if (col == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
                    location = new DropLocation(p, row, getColumnCount(), false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
                xSection = SwingUtilities2.liesInHorizontal(rect, p, ltr, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
                if (xSection == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
                    between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
                } else if (xSection == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
                    col++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
                    between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
                location = new DropLocation(p, row, col, false, between);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
            case ON_OR_INSERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
                if (row == -1 && col == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
                    location = new DropLocation(p, 0, 0, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
                xSection = SwingUtilities2.liesInHorizontal(rect, p, ltr, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
                if (row == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
                    if (xSection == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
                        location = new DropLocation(p, getRowCount(), col, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
                    } else if (xSection == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
                        location = new DropLocation(p, getRowCount(), col + 1, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
                        location = new DropLocation(p, getRowCount(), col, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                ySection = SwingUtilities2.liesInVertical(rect, p, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                if (ySection == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
                    between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                } else if (ySection == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                    row++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
                    between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
                location = new DropLocation(p, row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
                                            xSection == TRAILING ? col + 1 : col,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
                                            between,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
                                            xSection != MIDDLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
                assert false : "Unexpected drop mode";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
        return location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
     * Called to set or clear the drop location during a DnD operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
     * In some cases, the component may need to use it's internal selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
     * temporarily to indicate the drop location. To help facilitate this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
     * this method returns and accepts as a parameter a state object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
     * This state object can be used to store, and later restore, the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
     * state. Whatever this method returns will be passed back to it in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
     * future calls, as the state parameter. If it wants the DnD system to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
     * continue storing the same state, it must pass it back every time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
     * Here's how this is used:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
     * Let's say that on the first call to this method the component decides
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
     * to save some state (because it is about to use the selection to show
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
     * a drop index). It can return a state object to the caller encapsulating
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
     * any saved selection state. On a second call, let's say the drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
     * is being changed to something else. The component doesn't need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
     * restore anything yet, so it simply passes back the same state object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
     * to have the DnD system continue storing it. Finally, let's say this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
     * method is messaged with <code>null</code>. This means DnD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
     * is finished with this component for now, meaning it should restore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
     * state. At this point, it can use the state parameter to restore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
     * said state, and of course return <code>null</code> since there's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
     * no longer anything to store.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
     * @param location the drop location (as calculated by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
     *        <code>dropLocationForPoint</code>) or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
     *        if there's no longer a valid drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
     * @param state the state object saved earlier for this component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
     *        or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
     * @param forDrop whether or not the method is being called because an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
     *        actual drop occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
     * @return any saved state for this component, or <code>null</code> if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
    Object setDropLocation(TransferHandler.DropLocation location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
                           Object state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
                           boolean forDrop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
        Object retVal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
        DropLocation tableLocation = (DropLocation)location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
        if (dropMode == DropMode.USE_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
            if (tableLocation == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
                if (!forDrop && state != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
                    clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1747
                    int[] rows = ((int[][])state)[0];
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1748
                    int[] cols = ((int[][])state)[1];
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1749
                    int[] anchleads = ((int[][])state)[2];
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1750
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1751
                    for (int row : rows) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1752
                        addRowSelectionInterval(row, row);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1755
                    for (int col : cols) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1756
                        addColumnSelectionInterval(col, col);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
                    SwingUtilities2.setLeadAnchorWithoutSelection(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
                            getSelectionModel(), anchleads[1], anchleads[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
                    SwingUtilities2.setLeadAnchorWithoutSelection(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
                            getColumnModel().getSelectionModel(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
                            anchleads[3], anchleads[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
                if (dropLocation == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
                    retVal = new int[][]{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
                        getSelectedRows(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
                        getSelectedColumns(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
                        {getAdjustedIndex(getSelectionModel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
                             .getAnchorSelectionIndex(), true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
                         getAdjustedIndex(getSelectionModel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
                             .getLeadSelectionIndex(), true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
                         getAdjustedIndex(getColumnModel().getSelectionModel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
                             .getAnchorSelectionIndex(), false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
                         getAdjustedIndex(getColumnModel().getSelectionModel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
                             .getLeadSelectionIndex(), false)}};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
                    retVal = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
                if (tableLocation.getRow() == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
                    clearSelectionAndLeadAnchor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
                    setRowSelectionInterval(tableLocation.getRow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
                                            tableLocation.getRow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
                    setColumnSelectionInterval(tableLocation.getColumn(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
                                               tableLocation.getColumn());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
        DropLocation old = dropLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
        dropLocation = tableLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
        firePropertyChange("dropLocation", old, dropLocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
        return retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
     * Returns the location that this component should visually indicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
     * as the drop location during a DnD operation over the component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
     * or {@code null} if no location is to currently be shown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
     * This method is not meant for querying the drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
     * from a {@code TransferHandler}, as the drop location is only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
     * set after the {@code TransferHandler}'s <code>canImport</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
     * has returned and has allowed for the location to be shown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
     * When this property changes, a property change event with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
     * name "dropLocation" is fired by the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
     * @return the drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
     * @see #setDropMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
     * @see TransferHandler#canImport(TransferHandler.TransferSupport)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
    public final DropLocation getDropLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
        return dropLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
     * Specifies whether a {@code RowSorter} should be created for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
     * table whenever its model changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
     * When {@code setAutoCreateRowSorter(true)} is invoked, a {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
     * TableRowSorter} is immediately created and installed on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
     * table.  While the {@code autoCreateRowSorter} property remains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
     * {@code true}, every time the model is changed, a new {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
     * TableRowSorter} is created and set as the table's row sorter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
     * @param autoCreateRowSorter whether or not a {@code RowSorter}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
     *        should be automatically created
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
     * @see javax.swing.table.TableRowSorter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
     *  description: Whether or not to turn on sorting by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
    public void setAutoCreateRowSorter(boolean autoCreateRowSorter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
        boolean oldValue = this.autoCreateRowSorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
        this.autoCreateRowSorter = autoCreateRowSorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
        if (autoCreateRowSorter) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1846
            setRowSorter(new TableRowSorter<TableModel>(getModel()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
        firePropertyChange("autoCreateRowSorter", oldValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
                           autoCreateRowSorter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
     * Returns {@code true} if whenever the model changes, a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
     * {@code RowSorter} should be created and installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
     * as the table's sorter; otherwise, returns {@code false}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
     * @return true if a {@code RowSorter} should be created when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
     *         the model changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
    public boolean getAutoCreateRowSorter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
        return autoCreateRowSorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
     * Specifies whether the selection should be updated after sorting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
     * If true, on sorting the selection is reset such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
     * the same rows, in terms of the model, remain selected.  The default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
     * is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
     * @param update whether or not to update the selection on sorting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
     *       expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
     *  description: Whether or not to update the selection on sorting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
    public void setUpdateSelectionOnSort(boolean update) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
        if (updateSelectionOnSort != update) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
            updateSelectionOnSort = update;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
            firePropertyChange("updateSelectionOnSort", !update, update);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
        }
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
     * Returns true if the selection should be updated after sorting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
     * @return whether to update the selection on a sort
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
    public boolean getUpdateSelectionOnSort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
        return updateSelectionOnSort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
     * Sets the <code>RowSorter</code>.  <code>RowSorter</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
     * to provide sorting and filtering to a <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
     * This method clears the selection and resets any variable row heights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
     * This method fires a <code>PropertyChangeEvent</code> when appropriate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
     * with the property name <code>"rowSorter"</code>.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
     * backward-compatibility, this method fires an additional event with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
     * property name <code>"sorter"</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
     * If the underlying model of the <code>RowSorter</code> differs from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
     * that of this <code>JTable</code> undefined behavior will result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
     * @param sorter the <code>RowSorter</code>; <code>null</code> turns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
     *        sorting off
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
     * @see javax.swing.table.TableRowSorter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
     *  description: The table's RowSorter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
    public void setRowSorter(RowSorter<? extends TableModel> sorter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
        RowSorter<? extends TableModel> oldRowSorter = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
        if (sortManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
            oldRowSorter = sortManager.sorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
            sortManager.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
            sortManager = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
        rowModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
        clearSelectionAndLeadAnchor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
        if (sorter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
            sortManager = new SortManager(sorter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
        firePropertyChange("rowSorter", oldRowSorter, sorter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
        firePropertyChange("sorter", oldRowSorter, sorter);
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
     * Returns the object responsible for sorting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
     * @return the object responsible for sorting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
    public RowSorter<? extends TableModel> getRowSorter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
        return (sortManager != null) ? sortManager.sorter : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
// Selection methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
     * Sets the table's selection mode to allow only single selections, a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
     * contiguous interval, or multiple intervals.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
     * <bold>Note:</bold>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
     * <code>JTable</code> provides all the methods for handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
     * column and row selection.  When setting states,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
     * such as <code>setSelectionMode</code>, it not only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
     * updates the mode for the row selection model but also sets similar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
     * values in the selection model of the <code>columnModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
     * If you want to have the row and column selection models operating
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
     * in different modes, set them both directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
     * Both the row and column selection models for <code>JTable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
     * default to using a <code>DefaultListSelectionModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
     * so that <code>JTable</code> works the same way as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
     * <code>JList</code>. See the <code>setSelectionMode</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
     * in <code>JList</code> for details about the modes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
     * @see JList#setSelectionMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
     * description: The selection mode used by the row and column selection models.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
     *        enum: SINGLE_SELECTION            ListSelectionModel.SINGLE_SELECTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
     *              SINGLE_INTERVAL_SELECTION   ListSelectionModel.SINGLE_INTERVAL_SELECTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
     *              MULTIPLE_INTERVAL_SELECTION ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
    public void setSelectionMode(int selectionMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
        clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
        getSelectionModel().setSelectionMode(selectionMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
        getColumnModel().getSelectionModel().setSelectionMode(selectionMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
     * Sets whether the rows in this model can be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
     * @param rowSelectionAllowed   true if this model will allow row selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
     * @see #getRowSelectionAllowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
     *  description: If true, an entire row is selected for each selected cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
    public void setRowSelectionAllowed(boolean rowSelectionAllowed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
        boolean old = this.rowSelectionAllowed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
        this.rowSelectionAllowed = rowSelectionAllowed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
        if (old != rowSelectionAllowed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
        firePropertyChange("rowSelectionAllowed", old, 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
     * Returns true if rows can be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
     * @return true if rows can be selected, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
     * @see #setRowSelectionAllowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
    public boolean getRowSelectionAllowed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
        return rowSelectionAllowed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
     * Sets whether the columns in this model can be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
     * @param columnSelectionAllowed   true if this model will allow column selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
     * @see #getColumnSelectionAllowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
     *  description: If true, an entire column is selected for each selected cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
    public void setColumnSelectionAllowed(boolean columnSelectionAllowed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
        boolean old = columnModel.getColumnSelectionAllowed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
        columnModel.setColumnSelectionAllowed(columnSelectionAllowed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
        if (old != columnSelectionAllowed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
        firePropertyChange("columnSelectionAllowed", old, columnSelectionAllowed);
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
     * Returns true if columns can be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
     * @return true if columns can be selected, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
     * @see #setColumnSelectionAllowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
    public boolean getColumnSelectionAllowed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
        return columnModel.getColumnSelectionAllowed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
     * Sets whether this table allows both a column selection and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
     * row selection to exist simultaneously. When set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
     * the table treats the intersection of the row and column selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
     * models as the selected cells. Override <code>isCellSelected</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
     * change this default behavior. This method is equivalent to setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
     * both the <code>rowSelectionAllowed</code> property and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
     * <code>columnSelectionAllowed</code> property of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
     * <code>columnModel</code> to the supplied value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
     * @param  cellSelectionEnabled     true if simultaneous row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
     *                                  selection is allowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
     * @see #getCellSelectionEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
     * @see #isCellSelected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
     *  description: Select a rectangular region of cells rather than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
     *               rows or columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
    public void setCellSelectionEnabled(boolean cellSelectionEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
        setRowSelectionAllowed(cellSelectionEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
        setColumnSelectionAllowed(cellSelectionEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
        boolean old = this.cellSelectionEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
        this.cellSelectionEnabled = cellSelectionEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
        firePropertyChange("cellSelectionEnabled", old, cellSelectionEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
     * Returns true if both row and column selection models are enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
     * Equivalent to <code>getRowSelectionAllowed() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
     * getColumnSelectionAllowed()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
     * @return true if both row and column selection models are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
     * @see #setCellSelectionEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
    public boolean getCellSelectionEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
        return getRowSelectionAllowed() && getColumnSelectionAllowed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
     *  Selects all rows, columns, and cells in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
    public void selectAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
        // If I'm currently editing, then I should stop editing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
        if (isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
            removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
        if (getRowCount() > 0 && getColumnCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
            int oldLead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
            int oldAnchor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
            ListSelectionModel selModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
            selModel = selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
            selModel.setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
            oldLead = getAdjustedIndex(selModel.getLeadSelectionIndex(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
            oldAnchor = getAdjustedIndex(selModel.getAnchorSelectionIndex(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
            setRowSelectionInterval(0, getRowCount()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
            // this is done to restore the anchor and lead
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
            SwingUtilities2.setLeadAnchorWithoutSelection(selModel, oldLead, oldAnchor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
            selModel.setValueIsAdjusting(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
            selModel = columnModel.getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
            selModel.setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
            oldLead = getAdjustedIndex(selModel.getLeadSelectionIndex(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
            oldAnchor = getAdjustedIndex(selModel.getAnchorSelectionIndex(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
            setColumnSelectionInterval(0, getColumnCount()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
            // this is done to restore the anchor and lead
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
            SwingUtilities2.setLeadAnchorWithoutSelection(selModel, oldLead, oldAnchor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
            selModel.setValueIsAdjusting(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
     * Deselects all selected columns and rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
    public void clearSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
        selectionModel.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
        columnModel.getSelectionModel().clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
    private void clearSelectionAndLeadAnchor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
        selectionModel.setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
        columnModel.getSelectionModel().setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
        clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
        selectionModel.setAnchorSelectionIndex(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
        selectionModel.setLeadSelectionIndex(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
        columnModel.getSelectionModel().setAnchorSelectionIndex(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
        columnModel.getSelectionModel().setLeadSelectionIndex(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
        selectionModel.setValueIsAdjusting(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
        columnModel.getSelectionModel().setValueIsAdjusting(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
    private int getAdjustedIndex(int index, boolean row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
        int compare = row ? getRowCount() : getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
        return index < compare ? index : -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
    private int boundRow(int row) throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
        if (row < 0 || row >= getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
            throw new IllegalArgumentException("Row index out of range");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
        return row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
    private int boundColumn(int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
        if (col< 0 || col >= getColumnCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
            throw new IllegalArgumentException("Column index out of range");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
        return col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
     * Selects the rows from <code>index0</code> to <code>index1</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
     * inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
     * @exception IllegalArgumentException      if <code>index0</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
     *                                          <code>index1</code> lie outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
     *                                          [0, <code>getRowCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
     * @param   index0 one end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
     * @param   index1 the other end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
    public void setRowSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
        selectionModel.setSelectionInterval(boundRow(index0), boundRow(index1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
     * Selects the columns from <code>index0</code> to <code>index1</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
     * inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
     * @exception IllegalArgumentException      if <code>index0</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
     *                                          <code>index1</code> lie outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
     *                                          [0, <code>getColumnCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
     * @param   index0 one end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
     * @param   index1 the other end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
    public void setColumnSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
        columnModel.getSelectionModel().setSelectionInterval(boundColumn(index0), boundColumn(index1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
     * Adds the rows from <code>index0</code> to <code>index1</code>, inclusive, to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
     * the current selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
     * @exception IllegalArgumentException      if <code>index0</code> or <code>index1</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
     *                                          lie outside [0, <code>getRowCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
     * @param   index0 one end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
     * @param   index1 the other end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
    public void addRowSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
        selectionModel.addSelectionInterval(boundRow(index0), boundRow(index1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
     * Adds the columns from <code>index0</code> to <code>index1</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
     * inclusive, to the current selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
     * @exception IllegalArgumentException      if <code>index0</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
     *                                          <code>index1</code> lie outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
     *                                          [0, <code>getColumnCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
     * @param   index0 one end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
     * @param   index1 the other end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
    public void addColumnSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
        columnModel.getSelectionModel().addSelectionInterval(boundColumn(index0), boundColumn(index1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
     * Deselects the rows from <code>index0</code> to <code>index1</code>, inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
     * @exception IllegalArgumentException      if <code>index0</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
     *                                          <code>index1</code> lie outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
     *                                          [0, <code>getRowCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
     * @param   index0 one end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
     * @param   index1 the other end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
    public void removeRowSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
        selectionModel.removeSelectionInterval(boundRow(index0), boundRow(index1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
     * Deselects the columns from <code>index0</code> to <code>index1</code>, inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
     * @exception IllegalArgumentException      if <code>index0</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
     *                                          <code>index1</code> lie outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
     *                                          [0, <code>getColumnCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
     * @param   index0 one end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
     * @param   index1 the other end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
    public void removeColumnSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
        columnModel.getSelectionModel().removeSelectionInterval(boundColumn(index0), boundColumn(index1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
     * Returns the index of the first selected row, -1 if no row is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
     * @return the index of the first selected row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
    public int getSelectedRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
        return selectionModel.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
     * Returns the index of the first selected column,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
     * -1 if no column is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
     * @return the index of the first selected column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
    public int getSelectedColumn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
        return columnModel.getSelectionModel().getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
     * Returns the indices of all selected rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
     * @return an array of integers containing the indices of all selected rows,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
     *         or an empty array if no row is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
     * @see #getSelectedRow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
    public int[] getSelectedRows() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
        int iMin = selectionModel.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
        int iMax = selectionModel.getMaxSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
        if ((iMin == -1) || (iMax == -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
            return new int[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
        int[] rvTmp = new int[1+ (iMax - iMin)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
        int n = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
        for(int i = iMin; i <= iMax; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
            if (selectionModel.isSelectedIndex(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
                rvTmp[n++] = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
        int[] rv = new int[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
        System.arraycopy(rvTmp, 0, rv, 0, n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
        return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
     * Returns the indices of all selected columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
     * @return an array of integers containing the indices of all selected columns,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
     *         or an empty array if no column is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
     * @see #getSelectedColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
    public int[] getSelectedColumns() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
        return columnModel.getSelectedColumns();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
     * Returns the number of selected rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
     * @return the number of selected rows, 0 if no rows are selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
    public int getSelectedRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
        int iMin = selectionModel.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
        int iMax = selectionModel.getMaxSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
        int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
        for(int i = iMin; i <= iMax; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
            if (selectionModel.isSelectedIndex(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
                count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
        return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
     * Returns the number of selected columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
     * @return the number of selected columns, 0 if no columns are selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
    public int getSelectedColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
        return columnModel.getSelectedColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
     * Returns true if the specified index is in the valid range of rows,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
     * and the row at that index is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
     * @return true if <code>row</code> is a valid index and the row at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
     *              that index is selected (where 0 is the first row)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
    public boolean isRowSelected(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
        return selectionModel.isSelectedIndex(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
     * Returns true if the specified index is in the valid range of columns,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
     * and the column at that index is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
     * @param   column   the column in the column model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
     * @return true if <code>column</code> is a valid index and the column at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
     *              that index is selected (where 0 is the first column)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
    public boolean isColumnSelected(int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
        return columnModel.getSelectionModel().isSelectedIndex(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
     * Returns true if the specified indices are in the valid range of rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
     * and columns and the cell at the specified position is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
     * @param row   the row being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
     * @param column  the column being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
     * @return true if <code>row</code> and <code>column</code> are valid indices
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
     *              and the cell at index <code>(row, column)</code> is selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
     *              where the first row and first column are at index 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
    public boolean isCellSelected(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
        if (!getRowSelectionAllowed() && !getColumnSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
        return (!getRowSelectionAllowed() || isRowSelected(row)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
               (!getColumnSelectionAllowed() || isColumnSelected(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
    private void changeSelectionModel(ListSelectionModel sm, int index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
                                      boolean toggle, boolean extend, boolean selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
                                      int anchor, boolean anchorSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
        if (extend) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
            if (toggle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
                if (anchorSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
                    sm.addSelectionInterval(anchor, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
                    sm.removeSelectionInterval(anchor, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
                    // this is a Windows-only behavior that we want for file lists
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
                    if (Boolean.TRUE == getClientProperty("Table.isFileList")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
                        sm.addSelectionInterval(index, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
                        sm.setAnchorSelectionIndex(anchor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
                sm.setSelectionInterval(anchor, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
            if (toggle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
                if (selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
                    sm.removeSelectionInterval(index, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
                    sm.addSelectionInterval(index, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
                sm.setSelectionInterval(index, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
     * Updates the selection models of the table, depending on the state of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
     * two flags: <code>toggle</code> and <code>extend</code>. Most changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
     * to the selection that are the result of keyboard or mouse events received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
     * by the UI are channeled through this method so that the behavior may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
     * overridden by a subclass. Some UIs may need more functionality than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
     * this method provides, such as when manipulating the lead for discontiguous
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
     * selection, and may not call into this method for some selection changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
     * This implementation uses the following conventions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
     * <li> <code>toggle</code>: <em>false</em>, <code>extend</code>: <em>false</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
     *      Clear the previous selection and ensure the new cell is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
     * <li> <code>toggle</code>: <em>false</em>, <code>extend</code>: <em>true</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
     *      Extend the previous selection from the anchor to the specified cell,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
     *      clearing all other selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
     * <li> <code>toggle</code>: <em>true</em>, <code>extend</code>: <em>false</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
     *      If the specified cell is selected, deselect it. If it is not selected, select it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
     * <li> <code>toggle</code>: <em>true</em>, <code>extend</code>: <em>true</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
     *      Apply the selection state of the anchor to all cells between it and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
     *      specified cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
     * @param  rowIndex   affects the selection at <code>row</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
     * @param  columnIndex  affects the selection at <code>column</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
     * @param  toggle  see description above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
     * @param  extend  if true, extend the current selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
    public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
        ListSelectionModel rsm = getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
        ListSelectionModel csm = getColumnModel().getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
        int anchorRow = getAdjustedIndex(rsm.getAnchorSelectionIndex(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
        int anchorCol = getAdjustedIndex(csm.getAnchorSelectionIndex(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
        boolean anchorSelected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
        if (anchorRow == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
            if (getRowCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
                anchorRow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
            anchorSelected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
        if (anchorCol == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
            if (getColumnCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
                anchorCol = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
            anchorSelected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
        // Check the selection here rather than in each selection model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
        // This is significant in cell selection mode if we are supposed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
        // to be toggling the selection. In this case it is better to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
        // ensure that the cell's selection state will indeed be changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
        // If this were done in the code for the selection model it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
        // might leave a cell in selection state if the row was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
        // selected but the column was not - as it would toggle them both.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
        boolean selected = isCellSelected(rowIndex, columnIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
        anchorSelected = anchorSelected && isCellSelected(anchorRow, anchorCol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
        changeSelectionModel(csm, columnIndex, toggle, extend, selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
                             anchorCol, anchorSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
        changeSelectionModel(rsm, rowIndex, toggle, extend, selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
                             anchorRow, anchorSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
        // Scroll after changing the selection as blit scrolling is immediate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
        // so that if we cause the repaint after the scroll we end up painting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
        // everything!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
        if (getAutoscrolls()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
            Rectangle cellRect = getCellRect(rowIndex, columnIndex, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
            if (cellRect != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
                scrollRectToVisible(cellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
     * Returns the foreground color for selected cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
     * @return the <code>Color</code> object for the foreground property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
     * @see #setSelectionForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
     * @see #setSelectionBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
    public Color getSelectionForeground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
        return selectionForeground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
     * Sets the foreground color for selected cells.  Cell renderers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
     * can use this color to render text and graphics for selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
     * cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
     * The default value of this property is defined by the look
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
     * and feel implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
     * 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
  2496
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
     * @param selectionForeground  the <code>Color</code> to use in the foreground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
     *                             for selected list items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
     * @see #getSelectionForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
     * @see #setSelectionBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
     * @see #setForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
     * @see #setBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
     * @see #setFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
     * description: A default foreground color for selected cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
    public void setSelectionForeground(Color selectionForeground) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
        Color old = this.selectionForeground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
        this.selectionForeground = selectionForeground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
        firePropertyChange("selectionForeground", old, selectionForeground);
4967
da853cd502c8 6913768: With default SynthLookAndFeel instance installed new JTable creation leads to throwing NPE
rupashka
parents: 4379
diff changeset
  2512
        repaint();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
     * Returns the background color for selected cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
     * @return the <code>Color</code> used for the background of selected list items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
     * @see #setSelectionBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
     * @see #setSelectionForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
    public Color getSelectionBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
        return selectionBackground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
     * Sets the background color for selected cells.  Cell renderers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
     * can use this color to the fill selected cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
     * The default value of this property is defined by the look
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
     * and feel implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
     * 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
  2534
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
     * @param selectionBackground  the <code>Color</code> to use for the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
     *                             of selected cells
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
     * @see #getSelectionBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
     * @see #setSelectionForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
     * @see #setForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
     * @see #setBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
     * @see #setFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
     * description: A default background color for selected cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
    public void setSelectionBackground(Color selectionBackground) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
        Color old = this.selectionBackground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
        this.selectionBackground = selectionBackground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
        firePropertyChange("selectionBackground", old, selectionBackground);
4967
da853cd502c8 6913768: With default SynthLookAndFeel instance installed new JTable creation leads to throwing NPE
rupashka
parents: 4379
diff changeset
  2550
        repaint();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
     * Returns the <code>TableColumn</code> object for the column in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
     * whose identifier is equal to <code>identifier</code>, when compared using
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
     * <code>equals</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
     * @return  the <code>TableColumn</code> object that matches the identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
     * @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
  2560
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
     * @param   identifier                      the identifier object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
    public TableColumn getColumn(Object identifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
        TableColumnModel cm = getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
        int columnIndex = cm.getColumnIndex(identifier);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
        return cm.getColumn(columnIndex);
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
// Informally implement the TableModel interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
     * Maps the index of the column in the view at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
     * <code>viewColumnIndex</code> to the index of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
     * in the table model.  Returns the index of the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
     * column in the model.  If <code>viewColumnIndex</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
     * is less than zero, returns <code>viewColumnIndex</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
     * @param   viewColumnIndex     the index of the column in the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
     * @return  the index of the corresponding column in the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
     * @see #convertColumnIndexToView
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
    public int convertColumnIndexToModel(int viewColumnIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
        if (viewColumnIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
            return viewColumnIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
        return getColumnModel().getColumn(viewColumnIndex).getModelIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
     * Maps the index of the column in the table model at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
     * <code>modelColumnIndex</code> to the index of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
     * in the view.  Returns the index of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
     * corresponding column in the view; returns -1 if this column is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
     * being displayed.  If <code>modelColumnIndex</code> is less than zero,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
     * returns <code>modelColumnIndex</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
     * @param   modelColumnIndex     the index of the column in the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
     * @return   the index of the corresponding column in the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
     * @see #convertColumnIndexToModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
    public int convertColumnIndexToView(int modelColumnIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
        if (modelColumnIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
            return modelColumnIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
        TableColumnModel cm = getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
        for (int column = 0; column < getColumnCount(); column++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
            if (cm.getColumn(column).getModelIndex() == modelColumnIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
                return column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
     * Maps the index of the row in terms of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
     * <code>TableModel</code> to the view.  If the contents of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
     * model are not sorted the model and view indices are the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
     * @param modelRowIndex the index of the row in terms of the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
     * @return the index of the corresponding row in the view, or -1 if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
     *         the row isn't visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
     * @throws IndexOutOfBoundsException if sorting is enabled and passed an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
     *         index outside the number of rows of the <code>TableModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
     * @see javax.swing.table.TableRowSorter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
    public int convertRowIndexToView(int modelRowIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
        RowSorter sorter = getRowSorter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
        if (sorter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
            return sorter.convertRowIndexToView(modelRowIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
        return modelRowIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
     * Maps the index of the row in terms of the view to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
     * underlying <code>TableModel</code>.  If the contents of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
     * model are not sorted the model and view indices are the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
     * @param viewRowIndex the index of the row in the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
     * @return the index of the corresponding row in the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
     * @throws IndexOutOfBoundsException if sorting is enabled and passed an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
     *         index outside the range of the <code>JTable</code> as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
     *         determined by the method <code>getRowCount</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
     * @see javax.swing.table.TableRowSorter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
     * @see #getRowCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
    public int convertRowIndexToModel(int viewRowIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
        RowSorter sorter = getRowSorter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
        if (sorter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
            return sorter.convertRowIndexToModel(viewRowIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
        return viewRowIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
     * Returns the number of rows that can be shown in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
     * <code>JTable</code>, given unlimited space.  If a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
     * <code>RowSorter</code> with a filter has been specified, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
     * number of rows returned may differ from that of the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
     * <code>TableModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
     * @return the number of rows shown in the <code>JTable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
     * @see #getColumnCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
    public int getRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
        RowSorter sorter = getRowSorter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
        if (sorter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
            return sorter.getViewRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
        return getModel().getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
     * Returns the number of columns in the column model. Note that this may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
     * be different from the number of columns in the table model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
     * @return  the number of columns in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
     * @see #getRowCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
     * @see #removeColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
    public int getColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
        return getColumnModel().getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
     * Returns the name of the column appearing in the view at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
     * column position <code>column</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
     * @param  column    the column in the view being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
     * @return the name of the column at position <code>column</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
                        in the view where the first column is column 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
    public String getColumnName(int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
        return getModel().getColumnName(convertColumnIndexToModel(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
     * Returns the type of the column appearing in the view at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
     * column position <code>column</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
     * @param   column   the column in the view being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
     * @return the type of the column at position <code>column</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
     *          in the view where the first column is column 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
    public Class<?> getColumnClass(int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
        return getModel().getColumnClass(convertColumnIndexToModel(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
     * Returns the cell value at <code>row</code> and <code>column</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
     * <b>Note</b>: The column is specified in the table view's display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
     *              order, and not in the <code>TableModel</code>'s column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
     *              order.  This is an important distinction because as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
     *              user rearranges the columns in the table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
     *              the column at a given index in the view will change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
     *              Meanwhile the user's actions never affect the model's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
     *              column ordering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
     * @param   row             the row whose value is to be queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
     * @param   column          the column whose value is to be queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
     * @return  the Object at the specified cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
    public Object getValueAt(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
        return getModel().getValueAt(convertRowIndexToModel(row),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
                                     convertColumnIndexToModel(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
     * Sets the value for the cell in the table model at <code>row</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
     * and <code>column</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
     * <b>Note</b>: The column is specified in the table view's display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
     *              order, and not in the <code>TableModel</code>'s column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
     *              order.  This is an important distinction because as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
     *              user rearranges the columns in the table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
     *              the column at a given index in the view will change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
     *              Meanwhile the user's actions never affect the model's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
     *              column ordering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
     * <code>aValue</code> is the new value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
     * @param   aValue          the new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
     * @param   row             the row of the cell to be changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
     * @param   column          the column of the cell to be changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
     * @see #getValueAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
    public void setValueAt(Object aValue, int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
        getModel().setValueAt(aValue, convertRowIndexToModel(row),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
                              convertColumnIndexToModel(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
     * Returns true if the cell at <code>row</code> and <code>column</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
     * is editable.  Otherwise, invoking <code>setValueAt</code> on the cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
     * will have no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
     * <b>Note</b>: The column is specified in the table view's display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
     *              order, and not in the <code>TableModel</code>'s column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
     *              order.  This is an important distinction because as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
     *              user rearranges the columns in the table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
     *              the column at a given index in the view will change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
     *              Meanwhile the user's actions never affect the model's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
     *              column ordering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
     * @param   row      the row whose value is to be queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
     * @param   column   the column whose value is to be queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
     * @return  true if the cell is editable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
     * @see #setValueAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
    public boolean isCellEditable(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
        return getModel().isCellEditable(convertRowIndexToModel(row),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
                                         convertColumnIndexToModel(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
// Adding and removing columns in the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
     *  Appends <code>aColumn</code> to the end of the array of columns held by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
     *  this <code>JTable</code>'s column model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
     *  If the column name of <code>aColumn</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
     *  sets the column name of <code>aColumn</code> to the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
     *  returned by <code>getModel().getColumnName()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
     *  <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
     *  To add a column to this <code>JTable</code> to display the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
     *  <code>modelColumn</code>'th column of data in the model with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
     *  given <code>width</code>, <code>cellRenderer</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
     *  and <code>cellEditor</code> you can use:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
     *  <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
     *      addColumn(new TableColumn(modelColumn, width, cellRenderer, cellEditor));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
     *  </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
     *  [Any of the <code>TableColumn</code> constructors can be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
     *  instead of this one.]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
     *  The model column number is stored inside the <code>TableColumn</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
     *  and is used during rendering and editing to locate the appropriates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
     *  data values in the model. The model column number does not change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
     *  when columns are reordered in the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
     *  @param  aColumn         the <code>TableColumn</code> to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
     *  @see    #removeColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
    public void addColumn(TableColumn aColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
        if (aColumn.getHeaderValue() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
            int modelColumn = aColumn.getModelIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
            String columnName = getModel().getColumnName(modelColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
            aColumn.setHeaderValue(columnName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
        getColumnModel().addColumn(aColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
     *  Removes <code>aColumn</code> from this <code>JTable</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
     *  array of columns.  Note: this method does not remove the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
     *  of data from the model; it just removes the <code>TableColumn</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
     *  that was responsible for displaying it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
     *  @param  aColumn         the <code>TableColumn</code> to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
     *  @see    #addColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
    public void removeColumn(TableColumn aColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
        getColumnModel().removeColumn(aColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
     * Moves the column <code>column</code> to the position currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
     * occupied by the column <code>targetColumn</code> in the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
     * The old column at <code>targetColumn</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
     * shifted left or right to make room.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
     * @param   column                  the index of column to be moved
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
     * @param   targetColumn            the new index of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
    public void moveColumn(int column, int targetColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
        getColumnModel().moveColumn(column, targetColumn);
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
// Cover methods for various models and helper methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
     * Returns the index of the column that <code>point</code> lies in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
     * or -1 if the result is not in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
     * [0, <code>getColumnCount()</code>-1].
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
     * @param   point   the location of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
     * @return  the index of the column that <code>point</code> lies in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
     *          or -1 if the result is not in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
     *          [0, <code>getColumnCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
     * @see     #rowAtPoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
    public int columnAtPoint(Point point) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
        int x = point.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
        if( !getComponentOrientation().isLeftToRight() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
            x = getWidth() - x - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
        return getColumnModel().getColumnIndexAtX(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
     * Returns the index of the row that <code>point</code> lies in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
     * or -1 if the result is not in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
     * [0, <code>getRowCount()</code>-1].
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
     * @param   point   the location of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
     * @return  the index of the row that <code>point</code> lies in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
     *          or -1 if the result is not in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
     *          [0, <code>getRowCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
     * @see     #columnAtPoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
    public int rowAtPoint(Point point) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
        int y = point.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
        int result = (rowModel == null) ?  y/getRowHeight() : rowModel.getIndex(y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
        if (result < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
        else if (result >= getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
     * Returns a rectangle for the cell that lies at the intersection of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
     * <code>row</code> and <code>column</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
     * If <code>includeSpacing</code> is true then the value returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
     * has the full height and width of the row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
     * specified. If it is false, the returned rectangle is inset by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
     * intercell spacing to return the true bounds of the rendering or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
     * editing component as it will be set during rendering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
     * If the column index is valid but the row index is less
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
     * than zero the method returns a rectangle with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
     * <code>y</code> and <code>height</code> values set appropriately
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
     * and the <code>x</code> and <code>width</code> values both set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
     * to zero. In general, when either the row or column indices indicate a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
     * cell outside the appropriate range, the method returns a rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
     * depicting the closest edge of the closest cell that is within
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
     * the table's range. When both row and column indices are out
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
     * of range the returned rectangle covers the closest
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
     * point of the closest cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
     * In all cases, calculations that use this method to calculate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
     * results along one axis will not fail because of anomalies in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
     * calculations along the other axis. When the cell is not valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
     * the <code>includeSpacing</code> parameter is ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
     * @param   row                   the row index where the desired cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
     *                                is located
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
     * @param   column                the column index where the desired cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
     *                                is located in the display; this is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
     *                                necessarily the same as the column index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
     *                                in the data model for the table; the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
     *                                {@link #convertColumnIndexToView(int)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
     *                                method may be used to convert a data
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
     *                                model column index to a display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
     *                                column index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
     * @param   includeSpacing        if false, return the true cell bounds -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
     *                                computed by subtracting the intercell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
     *                                spacing from the height and widths of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
     *                                the column and row models
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
     * @return  the rectangle containing the cell at location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
     *          <code>row</code>,<code>column</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
     * @see #getIntercellSpacing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
    public Rectangle getCellRect(int row, int column, boolean includeSpacing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
        Rectangle r = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
        boolean valid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
        if (row < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
            // y = height = 0;
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 if (row >= getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
            r.y = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
            valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
            r.height = getRowHeight(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
            r.y = (rowModel == null) ? row * r.height : rowModel.getPosition(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
        if (column < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
            if( !getComponentOrientation().isLeftToRight() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
                r.x = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
            // otherwise, x = width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
            valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
        else if (column >= getColumnCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
            if( getComponentOrientation().isLeftToRight() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
                r.x = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
            // otherwise, x = width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
            valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
            TableColumnModel cm = getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
            if( getComponentOrientation().isLeftToRight() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
                for(int i = 0; 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
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
                for(int i = cm.getColumnCount()-1; i > column; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
                    r.x += cm.getColumn(i).getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
            r.width = cm.getColumn(column).getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
        if (valid && !includeSpacing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
            // Bound the margins by their associated dimensions to prevent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
            // returning bounds with negative dimensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
            int rm = Math.min(getRowMargin(), r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
            int cm = Math.min(getColumnModel().getColumnMargin(), r.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
            // This is not the same as grow(), it rounds differently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
            r.setBounds(r.x + cm/2, r.y + rm/2, r.width - cm, r.height - rm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2990
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2991
        return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2992
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2993
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2994
    private int viewIndexForColumn(TableColumn aColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
        TableColumnModel cm = getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
        for (int column = 0; column < cm.getColumnCount(); column++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
            if (cm.getColumn(column) == aColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
                return column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3004
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
     * Causes this table to lay out its rows and columns.  Overridden so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
     * that columns can be resized to accomodate a change in the size of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
     * a containing parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3008
     * Resizes one or more of the columns in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
     * so that the total width of all of this <code>JTable</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
     * columns is equal to the width of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
     * Before the layout begins the method gets the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
     * <code>resizingColumn</code> of the <code>tableHeader</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
     * When the method is called as a result of the resizing of an enclosing window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
     * the <code>resizingColumn</code> is <code>null</code>. This means that resizing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
     * has taken place "outside" the <code>JTable</code> and the change -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
     * or "delta" - should be distributed to all of the columns regardless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
     * of this <code>JTable</code>'s automatic resize mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
     * If the <code>resizingColumn</code> is not <code>null</code>, it is one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
     * the columns in the table that has changed size rather than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
     * the table itself. In this case the auto-resize modes govern
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
     * the way the extra (or deficit) space is distributed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
     * amongst the available columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
     * The modes are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
     * <li>  AUTO_RESIZE_OFF: Don't automatically adjust the column's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
     * widths at all. Use a horizontal scrollbar to accomodate the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
     * columns when their sum exceeds the width of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
     * <code>Viewport</code>.  If the <code>JTable</code> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
     * enclosed in a <code>JScrollPane</code> this may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
     * leave parts of the table invisible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
     * <li>  AUTO_RESIZE_NEXT_COLUMN: Use just the column after the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
     * resizing column. This results in the "boundary" or divider
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
     * between adjacent cells being independently adjustable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
     * <li>  AUTO_RESIZE_SUBSEQUENT_COLUMNS: Use all columns after the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
     * one being adjusted to absorb the changes.  This is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
     * default behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
     * <li>  AUTO_RESIZE_LAST_COLUMN: Automatically adjust the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
     * size of the last column only. If the bounds of the last column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
     * prevent the desired size from being allocated, set the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
     * width of the last column to the appropriate limit and make
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
     * no further adjustments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
     * <li>  AUTO_RESIZE_ALL_COLUMNS: Spread the delta amongst all the columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
     * in the <code>JTable</code>, including the one that is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
     * adjusted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
     * <bold>Note:</bold> When a <code>JTable</code> makes adjustments
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
     *   to the widths of the columns it respects their minimum and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
     *   maximum values absolutely.  It is therefore possible that,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
     *   even after this method is called, the total width of the columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
     *   is still not equal to the width of the table. When this happens
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
     *   the <code>JTable</code> does not put itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
     *   in AUTO_RESIZE_OFF mode to bring up a scroll bar, or break other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
     *   commitments of its current auto-resize mode -- instead it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
     *   allows its bounds to be set larger (or smaller) than the total of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3059
     *   column minimum or maximum, meaning, either that there
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
     *   will not be enough room to display all of the columns, or that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
     *   columns will not fill the <code>JTable</code>'s bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
     *   These respectively, result in the clipping of some columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
     *   or an area being painted in the <code>JTable</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
     *   background color during painting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3066
     *   The mechanism for distributing the delta amongst the available
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3067
     *   columns is provided in a private method in the <code>JTable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3068
     *   class:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3069
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
     *   adjustSizes(long targetSize, final Resizable3 r, boolean inverse)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3071
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3072
     *   an explanation of which is provided in the following section.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
     *   <code>Resizable3</code> is a private
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
     *   interface that allows any data structure containing a collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
     *   of elements with a size, preferred size, maximum size and minimum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
     *   to have its elements manipulated by the algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3077
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
     * <H3> Distributing the delta </H3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3079
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
     * <H4> Overview </H4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
     * Call "DELTA" the difference between the target size and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
     * sum of the preferred sizes of the elements in r. The individual
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
     * sizes are calculated by taking the original preferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3085
     * sizes and adding a share of the DELTA - that share being based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
     * how far each preferred size is from its limiting bound (minimum or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
     * maximum).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
     * <H4>Definition</H4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3091
     * Call the individual constraints min[i], max[i], and pref[i].
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3092
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3093
     * Call their respective sums: MIN, MAX, and PREF.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
     * Each new size will be calculated using:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3098
     *          size[i] = pref[i] + delta[i]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3099
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
     * where each individual delta[i] is calculated according to:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3102
     * If (DELTA < 0) we are in shrink mode where:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3103
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3104
     * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3105
     *                        DELTA
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3106
     *          delta[i] = ------------ * (pref[i] - min[i])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3107
     *                     (PREF - MIN)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3108
     * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3109
     * If (DELTA > 0) we are in expand mode where:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3110
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3111
     * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3112
     *                        DELTA
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3113
     *          delta[i] = ------------ * (max[i] - pref[i])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3114
     *                      (MAX - PREF)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3115
     * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3116
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3117
     * The overall effect is that the total size moves that same percentage,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3118
     * k, towards the total minimum or maximum and that percentage guarantees
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3119
     * accomodation of the required space, DELTA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3121
     * <H4>Details</H4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3122
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3123
     * Naive evaluation of the formulae presented here would be subject to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3124
     * the aggregated rounding errors caused by doing this operation in finite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3125
     * precision (using ints). To deal with this, the multiplying factor above,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3126
     * is constantly recalculated and this takes account of the rounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3127
     * errors in the previous iterations. The result is an algorithm that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3128
     * produces a set of integers whose values exactly sum to the supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3129
     * <code>targetSize</code>, and does so by spreading the rounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3130
     * errors evenly over the given elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3132
     * <H4>When the MAX and MIN bounds are hit</H4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3133
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3134
     * When <code>targetSize</code> is outside the [MIN, MAX] range,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3135
     * the algorithm sets all sizes to their appropriate limiting value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3136
     * (maximum or minimum).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3139
    public void doLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3140
        TableColumn resizingColumn = getResizingColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3141
        if (resizingColumn == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3142
            setWidthsFromPreferredWidths(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3144
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3145
            // JTable behaves like a layout manger - but one in which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3146
            // user can come along and dictate how big one of the children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3147
            // (columns) is supposed to be.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3149
            // A column has been resized and JTable may need to distribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3150
            // any overall delta to other columns, according to the resize mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3151
            int columnIndex = viewIndexForColumn(resizingColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3152
            int delta = getWidth() - getColumnModel().getTotalColumnWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3153
            accommodateDelta(columnIndex, delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3154
            delta = getWidth() - getColumnModel().getTotalColumnWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3155
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
            // If the delta cannot be completely accomodated, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
            // resizing column will have to take any remainder. This means
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
            // that the column is not being allowed to take the requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
            // width. This happens under many circumstances: For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
            // AUTO_RESIZE_NEXT_COLUMN specifies that any delta be distributed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
            // to the column after the resizing column. If one were to attempt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3162
            // to resize the last column of the table, there would be no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3163
            // columns after it, and hence nowhere to distribute the delta.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3164
            // It would then be given entirely back to the resizing column,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3165
            // preventing it from changing size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3166
            if (delta != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3167
                resizingColumn.setWidth(resizingColumn.getWidth() + delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3168
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3170
            // At this point the JTable has to work out what preferred sizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3171
            // would have resulted in the layout the user has chosen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3172
            // Thereafter, during window resizing etc. it has to work off
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3173
            // the preferred sizes as usual - the idea being that, whatever
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3174
            // the user does, everything stays in synch and things don't jump
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3175
            // around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3176
            setWidthsFromPreferredWidths(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3179
        super.doLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3182
    private TableColumn getResizingColumn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3183
        return (tableHeader == null) ? null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3184
                                     : tableHeader.getResizingColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3188
     * Sizes the table columns to fit the available space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3189
     * @deprecated As of Swing version 1.0.3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3190
     * replaced by <code>doLayout()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3191
     * @see #doLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3194
    public void sizeColumnsToFit(boolean lastColumnOnly) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3195
        int oldAutoResizeMode = autoResizeMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3196
        setAutoResizeMode(lastColumnOnly ? AUTO_RESIZE_LAST_COLUMN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3197
                                         : AUTO_RESIZE_ALL_COLUMNS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3198
        sizeColumnsToFit(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3199
        setAutoResizeMode(oldAutoResizeMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3201
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
     * Obsolete as of Java 2 platform v1.4.  Please use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
     * <code>doLayout()</code> method instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
     * @param resizingColumn    the column whose resizing made this adjustment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
     *                          necessary or -1 if there is no such column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3207
     * @see  #doLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
    public void sizeColumnsToFit(int resizingColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3210
        if (resizingColumn == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
            setWidthsFromPreferredWidths(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
            if (autoResizeMode == AUTO_RESIZE_OFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
                TableColumn aColumn = getColumnModel().getColumn(resizingColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
                aColumn.setPreferredWidth(aColumn.getWidth());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
                int delta = getWidth() - getColumnModel().getTotalColumnWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
                accommodateDelta(resizingColumn, delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3221
                setWidthsFromPreferredWidths(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
    private void setWidthsFromPreferredWidths(final boolean inverse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
        int totalWidth     = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
        int totalPreferred = getPreferredSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
        int target = !inverse ? totalWidth : totalPreferred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3230
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
        final TableColumnModel cm = columnModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3232
        Resizable3 r = new Resizable3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
            public int  getElementCount()      { return cm.getColumnCount(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
            public int  getLowerBoundAt(int i) { return cm.getColumn(i).getMinWidth(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
            public int  getUpperBoundAt(int i) { return cm.getColumn(i).getMaxWidth(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
            public int  getMidPointAt(int i)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
                if (!inverse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
                    return cm.getColumn(i).getPreferredWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3240
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
                    return cm.getColumn(i).getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
            public void setSizeAt(int s, int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
                if (!inverse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
                    cm.getColumn(i).setWidth(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
                    cm.getColumn(i).setPreferredWidth(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3250
                }
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
        adjustSizes(target, r, inverse);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3257
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3258
    // Distribute delta over columns, as indicated by the autoresize mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
    private void accommodateDelta(int resizingColumnIndex, int delta) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
        int columnCount = getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
        int from = resizingColumnIndex;
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  3262
        int to;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
        // Use the mode to determine how to absorb the changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
        switch(autoResizeMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3266
            case AUTO_RESIZE_NEXT_COLUMN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
                from = from + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3268
                to = Math.min(from + 1, columnCount); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3269
            case AUTO_RESIZE_SUBSEQUENT_COLUMNS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3270
                from = from + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3271
                to = columnCount; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
            case AUTO_RESIZE_LAST_COLUMN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
                from = columnCount - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
                to = from + 1; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
            case AUTO_RESIZE_ALL_COLUMNS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
                from = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3277
                to = columnCount; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3279
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3282
        final int start = from;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3283
        final int end = to;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3284
        final TableColumnModel cm = columnModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
        Resizable3 r = new Resizable3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
            public int  getElementCount()       { return end-start; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3287
            public int  getLowerBoundAt(int i)  { return cm.getColumn(i+start).getMinWidth(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
            public int  getUpperBoundAt(int i)  { return cm.getColumn(i+start).getMaxWidth(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3289
            public int  getMidPointAt(int i)    { return cm.getColumn(i+start).getWidth(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
            public void setSizeAt(int s, int i) {        cm.getColumn(i+start).setWidth(s); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3291
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3293
        int totalWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
        for(int i = from; i < to; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
            TableColumn aColumn = columnModel.getColumn(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
            int input = aColumn.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
            totalWidth = totalWidth + input;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
        adjustSizes(totalWidth + delta, r, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
    private interface Resizable2 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
        public int  getElementCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
        public int  getLowerBoundAt(int i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
        public int  getUpperBoundAt(int i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
        public void setSizeAt(int newSize, 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
    private interface Resizable3 extends Resizable2 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
        public int  getMidPointAt(int i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3315
    private void adjustSizes(long target, final Resizable3 r, boolean inverse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3316
        int N = r.getElementCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
        long totalPreferred = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3318
        for(int i = 0; i < N; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3319
            totalPreferred += r.getMidPointAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
        Resizable2 s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
        if ((target < totalPreferred) == !inverse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
            s = new Resizable2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3324
                public int  getElementCount()      { return r.getElementCount(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
                public int  getLowerBoundAt(int i) { return r.getLowerBoundAt(i); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
                public int  getUpperBoundAt(int i) { return r.getMidPointAt(i); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
                public void setSizeAt(int newSize, int i) { r.setSizeAt(newSize, i); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3332
            s = new Resizable2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
                public int  getElementCount()      { return r.getElementCount(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
                public int  getLowerBoundAt(int i) { return r.getMidPointAt(i); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
                public int  getUpperBoundAt(int i) { return r.getUpperBoundAt(i); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
                public void setSizeAt(int newSize, int i) { r.setSizeAt(newSize, i); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3338
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
        adjustSizes(target, s, !inverse);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
    private void adjustSizes(long target, Resizable2 r, boolean limitToRange) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
        long totalLowerBound = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
        long totalUpperBound = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
        for(int i = 0; i < r.getElementCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
            totalLowerBound += r.getLowerBoundAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
            totalUpperBound += r.getUpperBoundAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
        if (limitToRange) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3352
            target = Math.min(Math.max(totalLowerBound, target), totalUpperBound);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3355
        for(int i = 0; i < r.getElementCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3356
            int lowerBound = r.getLowerBoundAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3357
            int upperBound = r.getUpperBoundAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
            // Check for zero. This happens when the distribution of the delta
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3359
            // finishes early due to a series of "fixed" entries at the end.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
            // In this case, lowerBound == upperBound, for all subsequent terms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
            int newSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
            if (totalLowerBound == totalUpperBound) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
                newSize = lowerBound;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3364
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
                double f = (double)(target - totalLowerBound)/(totalUpperBound - totalLowerBound);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
                newSize = (int)Math.round(lowerBound+f*(upperBound - lowerBound));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3368
                // We'd need to round manually in an all integer version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3369
                // size[i] = (int)(((totalUpperBound - target) * lowerBound +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3370
                //     (target - totalLowerBound) * upperBound)/(totalUpperBound-totalLowerBound));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3371
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3372
            r.setSizeAt(newSize, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3373
            target -= newSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3374
            totalLowerBound -= lowerBound;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
            totalUpperBound -= upperBound;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3379
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3380
     * Overrides <code>JComponent</code>'s <code>getToolTipText</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3381
     * method in order to allow the renderer's tips to be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3382
     * if it has text set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3383
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3384
     * <bold>Note:</bold> For <code>JTable</code> to properly display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3385
     * tooltips of its renderers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3386
     * <code>JTable</code> must be a registered component with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
     * <code>ToolTipManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3388
     * This is done automatically in <code>initializeLocalVars</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
     * but if at a later point <code>JTable</code> is told
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
     * <code>setToolTipText(null)</code> it will unregister the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
     * component, and no tips from renderers will display anymore.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
     * @see JComponent#getToolTipText
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
    public String getToolTipText(MouseEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
        String tip = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
        Point p = event.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3398
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
        // Locate the renderer under the event location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3400
        int hitColumnIndex = columnAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3401
        int hitRowIndex = rowAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
        if ((hitColumnIndex != -1) && (hitRowIndex != -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
            TableCellRenderer renderer = getCellRenderer(hitRowIndex, hitColumnIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
            Component component = prepareRenderer(renderer, hitRowIndex, hitColumnIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3406
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
            // Now have to see if the component is a JComponent before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3408
            // getting the tip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3409
            if (component instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3410
                // Convert the event to the renderer's coordinate system
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3411
                Rectangle cellRect = getCellRect(hitRowIndex, hitColumnIndex, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3412
                p.translate(-cellRect.x, -cellRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
                MouseEvent newEvent = new MouseEvent(component, event.getID(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
                                          event.getWhen(), event.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
                                          p.x, p.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
                                          event.getXOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
                                          event.getYOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
                                          event.getClickCount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3419
                                          event.isPopupTrigger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
                                          MouseEvent.NOBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3421
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
                tip = ((JComponent)component).getToolTipText(newEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3423
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
        // No tip from the renderer get our own tip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
        if (tip == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
            tip = getToolTipText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
        return tip;
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
// Editing Support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3435
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3436
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3437
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
     * Sets whether editors in this JTable get the keyboard focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3439
     * when an editor is activated as a result of the JTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3440
     * forwarding keyboard events for a cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3441
     * By default, this property is false, and the JTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3442
     * retains the focus unless the cell is clicked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3443
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3444
     * @param surrendersFocusOnKeystroke true if the editor should get the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3445
     *          when keystrokes cause the editor to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3446
     *          activated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3447
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3448
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
     * @see #getSurrendersFocusOnKeystroke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3450
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3451
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
    public void setSurrendersFocusOnKeystroke(boolean surrendersFocusOnKeystroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3453
        this.surrendersFocusOnKeystroke = surrendersFocusOnKeystroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3455
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3456
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3457
     * Returns true if the editor should get the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3458
     * when keystrokes cause the editor to be activated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3459
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3460
     * @return  true if the editor should get the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3461
     *          when keystrokes cause the editor to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3462
     *          activated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
     * @see #setSurrendersFocusOnKeystroke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
    public boolean getSurrendersFocusOnKeystroke() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3468
        return surrendersFocusOnKeystroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3470
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3471
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3472
     * Programmatically starts editing the cell at <code>row</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3473
     * <code>column</code>, if those indices are in the valid range, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3474
     * the cell at those indices is editable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
     * Note that this is a convenience method for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
     * <code>editCellAt(int, int, null)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3477
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3478
     * @param   row                             the row to be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
     * @param   column                          the column to be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
     * @return  false if for any reason the cell cannot be edited,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3481
     *                or if the indices are invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3482
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3483
    public boolean editCellAt(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
        return editCellAt(row, column, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3486
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
     * Programmatically starts editing the cell at <code>row</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
     * <code>column</code>, if those indices are in the valid range, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
     * the cell at those indices is editable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
     * To prevent the <code>JTable</code> from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
     * editing a particular table, column or cell value, return false from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3493
     * the <code>isCellEditable</code> method in the <code>TableModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3494
     * interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3495
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3496
     * @param   row     the row to be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
     * @param   column  the column to be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3498
     * @param   e       event to pass into <code>shouldSelectCell</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3499
     *                  note that as of Java 2 platform v1.2, the call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3500
     *                  <code>shouldSelectCell</code> is no longer made
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3501
     * @return  false if for any reason the cell cannot be edited,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3502
     *                or if the indices are invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3504
    public boolean editCellAt(int row, int column, EventObject e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
        if (cellEditor != null && !cellEditor.stopCellEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3509
        if (row < 0 || row >= getRowCount() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
            column < 0 || column >= getColumnCount()) {
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
        if (!isCellEditable(row, column))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3516
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3517
        if (editorRemover == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3518
            KeyboardFocusManager fm =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3519
                KeyboardFocusManager.getCurrentKeyboardFocusManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3520
            editorRemover = new CellEditorRemover(fm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3521
            fm.addPropertyChangeListener("permanentFocusOwner", editorRemover);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3524
        TableCellEditor editor = getCellEditor(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3525
        if (editor != null && editor.isCellEditable(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3526
            editorComp = prepareEditor(editor, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
            if (editorComp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
                removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3531
            editorComp.setBounds(getCellRect(row, column, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
            add(editorComp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3533
            editorComp.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
            editorComp.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3535
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3536
            setCellEditor(editor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3537
            setEditingRow(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3538
            setEditingColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3539
            editor.addCellEditorListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3541
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3543
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3545
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3546
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3547
     * Returns true if a cell is being edited.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3548
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3549
     * @return  true if the table is editing a cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3550
     * @see     #editingColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3551
     * @see     #editingRow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3552
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3553
    public boolean isEditing() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  3554
        return cellEditor != null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3556
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3557
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3558
     * Returns the component that is handling the editing session.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3559
     * If nothing is being edited, returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3560
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3561
     * @return  Component handling editing session
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3562
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3563
    public Component getEditorComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3564
        return editorComp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3565
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3566
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3567
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3568
     * Returns the index of the column that contains the cell currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3569
     * being edited.  If nothing is being edited, returns -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3570
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3571
     * @return  the index of the column that contains the cell currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3572
     *          being edited; returns -1 if nothing being edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3573
     * @see #editingRow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3574
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3575
    public int getEditingColumn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3576
        return editingColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3578
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3579
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3580
     * Returns the index of the row that contains the cell currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3581
     * being edited.  If nothing is being edited, returns -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3582
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3583
     * @return  the index of the row that contains the cell currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3584
     *          being edited; returns -1 if nothing being edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3585
     * @see #editingColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3586
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3587
    public int getEditingRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3588
        return editingRow;
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
// Managing TableUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3593
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3594
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3595
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3596
     * Returns the L&F object that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3597
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3598
     * @return the <code>TableUI</code> object that renders this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3599
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3600
    public TableUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3601
        return (TableUI)ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3604
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3605
     * Sets the L&F object that renders this component and repaints.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3606
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3607
     * @param ui  the TableUI L&F object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3608
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3609
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3610
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3611
     *       hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3612
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3613
     *  description: The UI object that implements the Component's LookAndFeel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3614
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3615
    public void setUI(TableUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3616
        if (this.ui != ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3617
            super.setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3618
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3620
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3621
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3622
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3623
     * Notification from the <code>UIManager</code> that the L&F has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3624
     * Replaces the current UI object with the latest version from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3625
     * <code>UIManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3626
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3627
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3628
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3629
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3630
        // Update the UIs of the cell renderers, cell editors and header renderers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3631
        TableColumnModel cm = getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3632
        for(int column = 0; column < cm.getColumnCount(); column++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3633
            TableColumn aColumn = cm.getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3634
            SwingUtilities.updateRendererOrEditorUI(aColumn.getCellRenderer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3635
            SwingUtilities.updateRendererOrEditorUI(aColumn.getCellEditor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3636
            SwingUtilities.updateRendererOrEditorUI(aColumn.getHeaderRenderer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3638
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3639
        // Update the UIs of all the default renderers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3640
        Enumeration defaultRenderers = defaultRenderersByColumnClass.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3641
        while (defaultRenderers.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3642
            SwingUtilities.updateRendererOrEditorUI(defaultRenderers.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3643
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3645
        // Update the UIs of all the default editors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3646
        Enumeration defaultEditors = defaultEditorsByColumnClass.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3647
        while (defaultEditors.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3648
            SwingUtilities.updateRendererOrEditorUI(defaultEditors.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3649
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3650
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3651
        // Update the UI of the table header
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3652
        if (tableHeader != null && tableHeader.getParent() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3653
            tableHeader.updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3654
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3655
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
  3656
        // Update UI applied to parent ScrollPane
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
  3657
        configureEnclosingScrollPaneUI();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
  3658
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3659
        setUI((TableUI)UIManager.getUI(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3661
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3662
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3663
     * Returns the suffix used to construct the name of the L&F class used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3664
     * render this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3665
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3666
     * @return the string "TableUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3667
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3668
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3669
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3670
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3671
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3672
    }
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
// Managing models
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3677
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3678
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3679
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3680
     * Sets the data model for this table to <code>newModel</code> and registers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3681
     * with it for listener notifications from the new data model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3682
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3683
     * @param   dataModel        the new data source for this table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3684
     * @exception IllegalArgumentException      if <code>newModel</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3685
     * @see     #getModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3686
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3687
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3688
     *  description: The model that is the source of the data for this view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3689
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3690
    public void setModel(TableModel dataModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3691
        if (dataModel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3692
            throw new IllegalArgumentException("Cannot set a null TableModel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3694
        if (this.dataModel != dataModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3695
            TableModel old = this.dataModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3696
            if (old != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3697
                old.removeTableModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3698
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3699
            this.dataModel = dataModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3700
            dataModel.addTableModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3701
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3702
            tableChanged(new TableModelEvent(dataModel, TableModelEvent.HEADER_ROW));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3703
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3704
            firePropertyChange("model", old, dataModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3705
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3706
            if (getAutoCreateRowSorter()) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  3707
                setRowSorter(new TableRowSorter<TableModel>(dataModel));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3708
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3709
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3710
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3711
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3712
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3713
     * Returns the <code>TableModel</code> that provides the data displayed by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3714
     * <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3715
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3716
     * @return  the <code>TableModel</code> that provides the data displayed by this <code>JTable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3717
     * @see     #setModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3718
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3719
    public TableModel getModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3720
        return dataModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3721
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3722
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3723
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3724
     * Sets the column model for this table to <code>newModel</code> and registers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3725
     * for listener notifications from the new column model. Also sets
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3726
     * the column model of the <code>JTableHeader</code> to <code>columnModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3727
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3728
     * @param   columnModel        the new data source for this table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3729
     * @exception IllegalArgumentException      if <code>columnModel</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3730
     * @see     #getColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3731
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3732
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3733
     *  description: The object governing the way columns appear in the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3734
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3735
    public void setColumnModel(TableColumnModel columnModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3736
        if (columnModel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3737
            throw new IllegalArgumentException("Cannot set a null ColumnModel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3738
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3739
        TableColumnModel old = this.columnModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3740
        if (columnModel != old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3741
            if (old != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3742
                old.removeColumnModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3743
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3744
            this.columnModel = columnModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3745
            columnModel.addColumnModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3746
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3747
            // Set the column model of the header as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3748
            if (tableHeader != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3749
                tableHeader.setColumnModel(columnModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3750
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3751
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3752
            firePropertyChange("columnModel", old, columnModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3753
            resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3754
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3755
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3756
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3757
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3758
     * Returns the <code>TableColumnModel</code> that contains all column information
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3759
     * of this table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3760
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3761
     * @return  the object that provides the column state of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3762
     * @see     #setColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3763
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3764
    public TableColumnModel getColumnModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3765
        return columnModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3766
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3767
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3768
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3769
     * Sets the row selection model for this table to <code>newModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3770
     * and registers for listener notifications from the new selection model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3771
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3772
     * @param   newModel        the new selection model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3773
     * @exception IllegalArgumentException      if <code>newModel</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3774
     * @see     #getSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3775
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3776
     *      bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3777
     *      description: The selection model for rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3778
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3779
    public void setSelectionModel(ListSelectionModel newModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3780
        if (newModel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3781
            throw new IllegalArgumentException("Cannot set a null SelectionModel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3782
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3783
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3784
        ListSelectionModel oldModel = selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3785
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3786
        if (newModel != oldModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3787
            if (oldModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3788
                oldModel.removeListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3789
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3790
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3791
            selectionModel = newModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3792
            newModel.addListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3793
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3794
            firePropertyChange("selectionModel", oldModel, newModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3795
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3796
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3797
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3798
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3799
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3800
     * Returns the <code>ListSelectionModel</code> that is used to maintain row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3801
     * selection state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3802
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3803
     * @return  the object that provides row selection state, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3804
     *          if row selection is not allowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3805
     * @see     #setSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3806
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3807
    public ListSelectionModel getSelectionModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3808
        return selectionModel;
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
// RowSorterListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3813
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3814
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3815
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3816
     * <code>RowSorterListener</code> notification that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3817
     * <code>RowSorter</code> has changed in some way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3818
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3819
     * @param e the <code>RowSorterEvent</code> describing the change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3820
     * @throws NullPointerException if <code>e</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3821
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3822
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3823
    public void sorterChanged(RowSorterEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3824
        if (e.getType() == RowSorterEvent.Type.SORT_ORDER_CHANGED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3825
            JTableHeader header = getTableHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3826
            if (header != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3827
                header.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3828
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3829
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3830
        else if (e.getType() == RowSorterEvent.Type.SORTED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3831
            sorterChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3832
            if (!ignoreSortChange) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3833
                sortedTableChanged(e, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3834
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3835
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3836
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3837
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3838
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3839
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3840
     * SortManager provides support for managing the selection and variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3841
     * row heights when sorting is enabled. This information is encapsulated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3842
     * into a class to avoid bulking up JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3843
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3844
    private final class SortManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3845
        RowSorter<? extends TableModel> sorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3846
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3847
        // Selection, in terms of the model. This is lazily created
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3848
        // as needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3849
        private ListSelectionModel modelSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3850
        private int modelLeadIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3851
        // Set to true while in the process of changing the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3852
        // If this is true the selection change is ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3853
        private boolean syncingSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3854
        // Temporary cache of selection, in terms of model. This is only used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3855
        // if we don't need the full weight of modelSelection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3856
        private int[] lastModelSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3857
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3858
        // Heights of the rows in terms of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3859
        private SizeSequence modelRowSizes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3860
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3861
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3862
        SortManager(RowSorter<? extends TableModel> sorter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3863
            this.sorter = sorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3864
            sorter.addRowSorterListener(JTable.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3865
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3866
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3867
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3868
         * Disposes any resources used by this SortManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3869
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3870
        public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3871
            if (sorter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3872
                sorter.removeRowSorterListener(JTable.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3873
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3874
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3875
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3876
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3877
         * Sets the height for a row at a specified index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3878
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3879
        public void setViewRowHeight(int viewIndex, int rowHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3880
            if (modelRowSizes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3881
                modelRowSizes = new SizeSequence(getModel().getRowCount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3882
                                                 getRowHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3883
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3884
            modelRowSizes.setSize(convertRowIndexToModel(viewIndex),rowHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3885
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3886
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3887
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3888
         * Invoked when the underlying model has completely changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3889
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3890
        public void allChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3891
            modelLeadIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3892
            modelSelection = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3893
            modelRowSizes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3894
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3895
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3896
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3897
         * Invoked when the selection, on the view, has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3898
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3899
        public void viewSelectionChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3900
            if (!syncingSelection && modelSelection != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3901
                modelSelection = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3902
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3903
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3904
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3905
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3906
         * Invoked when either the table model has changed, or the RowSorter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3907
         * has changed. This is invoked prior to notifying the sorter of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3908
         * change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3909
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3910
        public void prepareForChange(RowSorterEvent sortEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3911
                                     ModelChange change) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3912
            if (getUpdateSelectionOnSort()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3913
                cacheSelection(sortEvent, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3914
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3915
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3916
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3917
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3918
         * Updates the internal cache of the selection based on the change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3919
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3920
        private void cacheSelection(RowSorterEvent sortEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3921
                                    ModelChange change) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3922
            if (sortEvent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3923
                // sort order changed. If modelSelection is null and filtering
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3924
                // is enabled we need to cache the selection in terms of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3925
                // underlying model, this will allow us to correctly restore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3926
                // the selection even if rows are filtered out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3927
                if (modelSelection == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3928
                        sorter.getViewRowCount() != getModel().getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3929
                    modelSelection = new DefaultListSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3930
                    ListSelectionModel viewSelection = getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3931
                    int min = viewSelection.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3932
                    int max = viewSelection.getMaxSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3933
                    int modelIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3934
                    for (int viewIndex = min; viewIndex <= max; viewIndex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3935
                        if (viewSelection.isSelectedIndex(viewIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3936
                            modelIndex = convertRowIndexToModel(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3937
                                    sortEvent, viewIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3938
                            if (modelIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3939
                                modelSelection.addSelectionInterval(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3940
                                    modelIndex, modelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3941
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3942
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3943
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3944
                    modelIndex = convertRowIndexToModel(sortEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3945
                            viewSelection.getLeadSelectionIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3946
                    SwingUtilities2.setLeadAnchorWithoutSelection(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3947
                            modelSelection, modelIndex, modelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3948
                } else if (modelSelection == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3949
                    // Sorting changed, haven't cached selection in terms
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3950
                    // of model and no filtering. Temporarily cache selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3951
                    cacheModelSelection(sortEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3952
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3953
            } else if (change.allRowsChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3954
                // All the rows have changed, chuck any cached selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3955
                modelSelection = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3956
            } else if (modelSelection != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3957
                // Table changed, reflect changes in cached selection model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3958
                switch(change.type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3959
                case TableModelEvent.DELETE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3960
                    modelSelection.removeIndexInterval(change.startModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3961
                                                       change.endModelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3962
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3963
                case TableModelEvent.INSERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3964
                    modelSelection.insertIndexInterval(change.startModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3965
                                                       change.endModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3966
                                                       true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3967
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3968
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3969
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3970
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3971
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3972
                // table changed, but haven't cached rows, temporarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3973
                // cache them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3974
                cacheModelSelection(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3975
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3976
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3977
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3978
        private void cacheModelSelection(RowSorterEvent sortEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3979
            lastModelSelection = convertSelectionToModel(sortEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3980
            modelLeadIndex = convertRowIndexToModel(sortEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3981
                        selectionModel.getLeadSelectionIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3982
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3983
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3984
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3985
         * Inovked when either the table has changed or the sorter has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3986
         * and after the sorter has been notified. If necessary this will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3987
         * reapply the selection and variable row heights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3988
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3989
        public void processChange(RowSorterEvent sortEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3990
                                  ModelChange change,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3991
                                  boolean sorterChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3992
            if (change != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3993
                if (change.allRowsChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3994
                    modelRowSizes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3995
                    rowModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3996
                } else if (modelRowSizes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3997
                    if (change.type == TableModelEvent.INSERT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3998
                        modelRowSizes.insertEntries(change.startModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3999
                                                    change.endModelIndex -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4000
                                                    change.startModelIndex + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4001
                                                    getRowHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4002
                    } else if (change.type == TableModelEvent.DELETE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4003
                        modelRowSizes.removeEntries(change.startModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4004
                                                    change.endModelIndex -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4005
                                                    change.startModelIndex +1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4006
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4007
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4008
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4009
            if (sorterChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4010
                setViewRowHeightsFromModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4011
                restoreSelection(change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4012
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4013
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4015
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4016
         * Resets the variable row heights in terms of the view from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4017
         * that of the variable row heights in terms of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4018
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4019
        private void setViewRowHeightsFromModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4020
            if (modelRowSizes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4021
                rowModel.setSizes(getRowCount(), getRowHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4022
                for (int viewIndex = getRowCount() - 1; viewIndex >= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4023
                         viewIndex--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4024
                    int modelIndex = convertRowIndexToModel(viewIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4025
                    rowModel.setSize(viewIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4026
                                     modelRowSizes.getSize(modelIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4027
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4028
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4029
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4031
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4032
         * Restores the selection from that in terms of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4033
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4034
        private void restoreSelection(ModelChange change) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4035
            syncingSelection = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4036
            if (lastModelSelection != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4037
                restoreSortingSelection(lastModelSelection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4038
                                        modelLeadIndex, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4039
                lastModelSelection = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4040
            } else if (modelSelection != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4041
                ListSelectionModel viewSelection = getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4042
                viewSelection.setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4043
                viewSelection.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4044
                int min = modelSelection.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4045
                int max = modelSelection.getMaxSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4046
                int viewIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4047
                for (int modelIndex = min; modelIndex <= max; modelIndex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4048
                    if (modelSelection.isSelectedIndex(modelIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4049
                        viewIndex = convertRowIndexToView(modelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4050
                        if (viewIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4051
                            viewSelection.addSelectionInterval(viewIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4052
                                                               viewIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4053
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4054
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4055
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4056
                // Restore the lead
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4057
                int viewLeadIndex = modelSelection.getLeadSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4058
                if (viewLeadIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4059
                    viewLeadIndex = convertRowIndexToView(viewLeadIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4060
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4061
                SwingUtilities2.setLeadAnchorWithoutSelection(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4062
                        viewSelection, viewLeadIndex, viewLeadIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4063
                viewSelection.setValueIsAdjusting(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4064
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4065
            syncingSelection = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4066
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4067
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4070
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4071
     * ModelChange is used when sorting to restore state, it corresponds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4072
     * to data from a TableModelEvent.  The values are precalculated as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4073
     * they are used extensively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4074
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4075
    private final class ModelChange {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4076
        // Starting index of the change, in terms of the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4077
        int startModelIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4079
        // Ending index of the change, in terms of the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4080
        int endModelIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4082
        // Type of change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4083
        int type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4085
        // Number of rows in the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4086
        int modelRowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4088
        // The event that triggered this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4089
        TableModelEvent event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4091
        // Length of the change (end - start + 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4092
        int length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4094
        // True if the event indicates all the contents have changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4095
        boolean allRowsChanged;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4097
        ModelChange(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4098
            startModelIndex = Math.max(0, e.getFirstRow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4099
            endModelIndex = e.getLastRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4100
            modelRowCount = getModel().getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4101
            if (endModelIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4102
                endModelIndex = Math.max(0, modelRowCount - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4103
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4104
            length = endModelIndex - startModelIndex + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4105
            type = e.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4106
            event = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4107
            allRowsChanged = (e.getLastRow() == Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4112
     * Invoked when <code>sorterChanged</code> is invoked, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4113
     * when <code>tableChanged</code> is invoked and sorting is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4115
    private void sortedTableChanged(RowSorterEvent sortedEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4116
                                    TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4117
        int editingModelIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4118
        ModelChange change = (e != null) ? new ModelChange(e) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4120
        if ((change == null || !change.allRowsChanged) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4121
                this.editingRow != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4122
            editingModelIndex = convertRowIndexToModel(sortedEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4123
                                                       this.editingRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4126
        sortManager.prepareForChange(sortedEvent, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4128
        if (e != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4129
            if (change.type == TableModelEvent.UPDATE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4130
                repaintSortedRows(change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4132
            notifySorter(change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4133
            if (change.type != TableModelEvent.UPDATE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4134
                // If the Sorter is unsorted we will not have received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4135
                // notification, force treating insert/delete as a change.
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
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4140
            sorterChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4143
        sortManager.processChange(sortedEvent, change, sorterChanged);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4145
        if (sorterChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4146
            // Update the editing row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4147
            if (this.editingRow != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4148
                int newIndex = (editingModelIndex == -1) ? -1 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4149
                        convertRowIndexToView(editingModelIndex,change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4150
                restoreSortingEditingRow(newIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4151
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4153
            // And handle the appropriate repainting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4154
            if (e == null || change.type != TableModelEvent.UPDATE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4155
                resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4156
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4159
        // Check if lead/anchor need to be reset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4160
        if (change != null && change.allRowsChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4161
            clearSelectionAndLeadAnchor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4162
            resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4165
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4167
     * Repaints the sort of sorted rows in response to a TableModelEvent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4169
    private void repaintSortedRows(ModelChange change) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4170
        if (change.startModelIndex > change.endModelIndex ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4171
                change.startModelIndex + 10 < change.endModelIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4172
            // Too much has changed, punt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4173
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4174
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4176
        int eventColumn = change.event.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4177
        int columnViewIndex = eventColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4178
        if (columnViewIndex == TableModelEvent.ALL_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4179
            columnViewIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4181
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4182
            columnViewIndex = convertColumnIndexToView(columnViewIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4183
            if (columnViewIndex == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4184
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4185
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4187
        int modelIndex = change.startModelIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4188
        while (modelIndex <= change.endModelIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4189
            int viewIndex = convertRowIndexToView(modelIndex++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4190
            if (viewIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4191
                Rectangle dirty = getCellRect(viewIndex, columnViewIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4192
                                              false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4193
                int x = dirty.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4194
                int w = dirty.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4195
                if (eventColumn == TableModelEvent.ALL_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4196
                    x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4197
                    w = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4198
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4199
                repaint(x, dirty.y, w, dirty.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4200
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4203
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4205
     * Restores the selection after a model event/sort order changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4206
     * All coordinates are in terms of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4208
    private void restoreSortingSelection(int[] selection, int lead,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4209
            ModelChange change) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4210
        // Convert the selection from model to view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4211
        for (int i = selection.length - 1; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4212
            selection[i] = convertRowIndexToView(selection[i], change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4214
        lead = convertRowIndexToView(lead, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4215
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4216
        // Check for the common case of no change in selection for 1 row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4217
        if (selection.length == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4218
            (selection.length == 1 && selection[0] == getSelectedRow())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4219
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4222
        // And apply the new selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4223
        selectionModel.setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4224
        selectionModel.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4225
        for (int i = selection.length - 1; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4226
            if (selection[i] != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4227
                selectionModel.addSelectionInterval(selection[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4228
                                                    selection[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4229
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4231
        SwingUtilities2.setLeadAnchorWithoutSelection(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4232
                selectionModel, lead, lead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4233
        selectionModel.setValueIsAdjusting(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4235
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4237
     * Restores the editing row after a model event/sort order change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4239
     * @param editingRow new index of the editingRow, in terms of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4241
    private void restoreSortingEditingRow(int editingRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4242
        if (editingRow == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4243
            // Editing row no longer being shown, cancel editing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4244
            TableCellEditor editor = getCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4245
            if (editor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4246
                // First try and cancel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4247
                editor.cancelCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4248
                if (getCellEditor() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4249
                    // CellEditor didn't cede control, forcefully
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4250
                    // remove it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4251
                    removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4252
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4253
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4255
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4256
            // Repositioning handled in BasicTableUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4257
            this.editingRow = editingRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4258
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4263
     * Notifies the sorter of a change in the underlying model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4265
    private void notifySorter(ModelChange change) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4266
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4267
            ignoreSortChange = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4268
            sorterChanged = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4269
            switch(change.type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4270
            case TableModelEvent.UPDATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4271
                if (change.event.getLastRow() == Integer.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4272
                    sortManager.sorter.allRowsChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4273
                } else if (change.event.getColumn() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4274
                           TableModelEvent.ALL_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4275
                    sortManager.sorter.rowsUpdated(change.startModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4276
                                       change.endModelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4277
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4278
                    sortManager.sorter.rowsUpdated(change.startModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4279
                                       change.endModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4280
                                       change.event.getColumn());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4281
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4282
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4283
            case TableModelEvent.INSERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4284
                sortManager.sorter.rowsInserted(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
            case TableModelEvent.DELETE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4288
                sortManager.sorter.rowsDeleted(change.startModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4289
                                   change.endModelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4290
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4291
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4292
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4293
            ignoreSortChange = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4296
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4297
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4298
     * Converts a model index to view index.  This is called when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4299
     * sorter or model changes and sorting is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4300
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4301
     * @param change describes the TableModelEvent that initiated the change;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4302
     *        will be null if called as the result of a sort
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4304
    private int convertRowIndexToView(int modelIndex, ModelChange change) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4305
        if (modelIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4306
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4308
        if (change != null && modelIndex >= change.startModelIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4309
            if (change.type == TableModelEvent.INSERT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4310
                if (modelIndex + change.length >= change.modelRowCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4311
                    return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4312
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4313
                return sortManager.sorter.convertRowIndexToView(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4314
                        modelIndex + change.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4315
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4316
            else if (change.type == TableModelEvent.DELETE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4317
                if (modelIndex <= change.endModelIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4318
                    // deleted
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
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4322
                    if (modelIndex - change.length >= change.modelRowCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4323
                        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4324
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4325
                    return sortManager.sorter.convertRowIndexToView(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4326
                            modelIndex - change.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4327
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4328
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4329
            // else, updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4331
        if (modelIndex >= getModel().getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4332
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4334
        return sortManager.sorter.convertRowIndexToView(modelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4336
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4337
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4338
     * Converts the selection to model coordinates.  This is used when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4339
     * the model changes or the sorter changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4341
    private int[] convertSelectionToModel(RowSorterEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4342
        int[] selection = getSelectedRows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4343
        for (int i = selection.length - 1; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4344
            selection[i] = convertRowIndexToModel(e, selection[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4345
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4346
        return selection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4349
    private int convertRowIndexToModel(RowSorterEvent e, int viewIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4350
        if (e != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4351
            if (e.getPreviousRowCount() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4352
                return viewIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4353
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4354
            // range checking handled by RowSorterEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4355
            return e.convertPreviousRowIndexToModel(viewIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4357
        // Make sure the viewIndex is valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4358
        if (viewIndex < 0 || viewIndex >= getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4359
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4361
        return convertRowIndexToModel(viewIndex);
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
// Implementing TableModelListener interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4366
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4369
     * Invoked when this table's <code>TableModel</code> generates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4370
     * a <code>TableModelEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4371
     * The <code>TableModelEvent</code> should be constructed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4372
     * coordinate system of the model; the appropriate mapping to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4373
     * view coordinate system is performed by this <code>JTable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4374
     * when it receives the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4375
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4376
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4377
     * are used internally by <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4378
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4379
     * Note that as of 1.3, this method clears the selection, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4381
    public void tableChanged(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4382
        if (e == null || e.getFirstRow() == TableModelEvent.HEADER_ROW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4383
            // The whole thing changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4384
            clearSelectionAndLeadAnchor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4385
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4386
            rowModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4387
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4388
            if (sortManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4389
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4390
                    ignoreSortChange = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4391
                    sortManager.sorter.modelStructureChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4392
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4393
                    ignoreSortChange = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4394
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4395
                sortManager.allChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4396
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4397
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4398
            if (getAutoCreateColumnsFromModel()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4399
                // This will effect invalidation of the JTable and JTableHeader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4400
                createDefaultColumnsFromModel();
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
            resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4405
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4407
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4408
        if (sortManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4409
            sortedTableChanged(null, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4410
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4412
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4413
        // The totalRowHeight calculated below will be incorrect if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4414
        // there are variable height rows. Repaint the visible region,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4415
        // but don't return as a revalidate may be necessary as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4416
        if (rowModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4417
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4419
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4420
        if (e.getType() == TableModelEvent.INSERT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4421
            tableRowsInserted(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4422
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4424
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4425
        if (e.getType() == TableModelEvent.DELETE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4426
            tableRowsDeleted(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4427
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4430
        int modelColumn = e.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4431
        int start = e.getFirstRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4432
        int end = e.getLastRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4433
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4434
        Rectangle dirtyRegion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4435
        if (modelColumn == TableModelEvent.ALL_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4436
            // 1 or more rows changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4437
            dirtyRegion = new Rectangle(0, start * getRowHeight(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4438
                                        getColumnModel().getTotalColumnWidth(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4440
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4441
            // A cell or column of cells has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4442
            // Unlike the rest of the methods in the JTable, the TableModelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4443
            // uses the coordinate system of the model instead of the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4444
            // This is the only place in the JTable where this "reverse mapping"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4445
            // is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4446
            int column = convertColumnIndexToView(modelColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4447
            dirtyRegion = getCellRect(start, column, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4450
        // Now adjust the height of the dirty region according to the value of "end".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4451
        // Check for Integer.MAX_VALUE as this will cause an overflow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4452
        if (end != Integer.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4453
            dirtyRegion.height = (end-start+1)*getRowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4454
            repaint(dirtyRegion.x, dirtyRegion.y, dirtyRegion.width, dirtyRegion.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4456
        // In fact, if the end is Integer.MAX_VALUE we need to revalidate anyway
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4457
        // because the scrollbar may need repainting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4458
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4459
            clearSelectionAndLeadAnchor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4460
            resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4461
            rowModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4463
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4464
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4465
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4466
     * Invoked when rows have been inserted into the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4467
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4468
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4469
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4470
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4471
     * @param e the TableModelEvent encapsulating the insertion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4472
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4473
    private void tableRowsInserted(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4474
        int start = e.getFirstRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4475
        int end = e.getLastRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4476
        if (start < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4477
            start = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4478
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4479
        if (end < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4480
            end = getRowCount()-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4481
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4483
        // Adjust the selection to account for the new rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4484
        int length = end - start + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4485
        selectionModel.insertIndexInterval(start, length, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4486
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4487
        // If we have variable height rows, adjust the row model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4488
        if (rowModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4489
            rowModel.insertEntries(start, length, getRowHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4491
        int rh = getRowHeight() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4492
        Rectangle drawRect = new Rectangle(0, start * rh,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4493
                                        getColumnModel().getTotalColumnWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4494
                                           (getRowCount()-start) * rh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4496
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4497
        // PENDING(milne) revalidate calls repaint() if parent is a ScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4498
        // repaint still required in the unusual case where there is no ScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4499
        repaint(drawRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4501
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4502
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4503
     * Invoked when rows have been removed from the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4504
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4505
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4506
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4507
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4508
     * @param e the TableModelEvent encapsulating the deletion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4509
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4510
    private void tableRowsDeleted(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4511
        int start = e.getFirstRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4512
        int end = e.getLastRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4513
        if (start < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4514
            start = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4516
        if (end < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4517
            end = getRowCount()-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4519
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4520
        int deletedCount = end - start + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4521
        int previousRowCount = getRowCount() + deletedCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4522
        // Adjust the selection to account for the new rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4523
        selectionModel.removeIndexInterval(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4524
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4525
        // If we have variable height rows, adjust the row model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4526
        if (rowModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4527
            rowModel.removeEntries(start, deletedCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4528
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4529
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4530
        int rh = getRowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4531
        Rectangle drawRect = new Rectangle(0, start * rh,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4532
                                        getColumnModel().getTotalColumnWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4533
                                        (previousRowCount - start) * rh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4534
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4535
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4536
        // PENDING(milne) revalidate calls repaint() if parent is a ScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4537
        // repaint still required in the unusual case where there is no ScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4538
        repaint(drawRect);
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
// Implementing TableColumnModelListener interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4543
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4544
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4545
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4546
     * Invoked when a column is added to the table column model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4547
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4548
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4549
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4550
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4551
     * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4552
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4553
    public void columnAdded(TableColumnModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4554
        // If I'm currently editing, then I should stop editing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4555
        if (isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4556
            removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4557
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4558
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4559
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4560
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4561
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4562
     * Invoked when a column is removed from the table column model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4563
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4564
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4565
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4566
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4567
     * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4568
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4569
    public void columnRemoved(TableColumnModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4570
        // If I'm currently editing, then I should stop editing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4571
        if (isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4572
            removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4573
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4574
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4575
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4576
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4577
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4578
     * Invoked when a column is repositioned. If a cell is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4579
     * edited, then editing is stopped and the cell is redrawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4580
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4581
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4582
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4583
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4584
     * @param e   the event received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4585
     * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4586
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4587
    public void columnMoved(TableColumnModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4588
        // If I'm currently editing, then I should stop editing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4589
        if (isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4590
            removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4592
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4594
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4595
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4596
     * Invoked when a column is moved due to a margin change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4597
     * If a cell is being edited, then editing is stopped and the cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4598
     * is redrawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4599
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4600
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4601
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4602
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4603
     * @param  e    the event received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4604
     * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4605
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4606
    public void columnMarginChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4607
        if (isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4608
            removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4609
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4610
        TableColumn resizingColumn = getResizingColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4611
        // Need to do this here, before the parent's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4612
        // layout manager calls getPreferredSize().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4613
        if (resizingColumn != null && autoResizeMode == AUTO_RESIZE_OFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4614
            resizingColumn.setPreferredWidth(resizingColumn.getWidth());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4616
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4617
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4618
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4619
    private int limit(int i, int a, int b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4620
        return Math.min(b, Math.max(i, a));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4622
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4623
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4624
     * Invoked when the selection model of the <code>TableColumnModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4625
     * is changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4626
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4627
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4628
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4629
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4630
     * @param  e  the event received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4631
     * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4632
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4633
    public void columnSelectionChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4634
        boolean isAdjusting = e.getValueIsAdjusting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4635
        if (columnSelectionAdjusting && !isAdjusting) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4636
            // The assumption is that when the model is no longer adjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4637
            // we will have already gotten all the changes, and therefore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4638
            // don't need to do an additional paint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4639
            columnSelectionAdjusting = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4640
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4641
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4642
        columnSelectionAdjusting = isAdjusting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4643
        // The getCellRect() call will fail unless there is at least one row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4644
        if (getRowCount() <= 0 || getColumnCount() <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4645
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4646
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4647
        int firstIndex = limit(e.getFirstIndex(), 0, getColumnCount()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4648
        int lastIndex = limit(e.getLastIndex(), 0, getColumnCount()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4649
        int minRow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4650
        int maxRow = getRowCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4651
        if (getRowSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4652
            minRow = selectionModel.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4653
            maxRow = selectionModel.getMaxSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4654
            int leadRow = getAdjustedIndex(selectionModel.getLeadSelectionIndex(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4655
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4656
            if (minRow == -1 || maxRow == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4657
                if (leadRow == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4658
                    // nothing to repaint, return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4659
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4660
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4661
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4662
                // only thing to repaint is the lead
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4663
                minRow = maxRow = leadRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4664
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4665
                // We need to consider more than just the range between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4666
                // the min and max selected index. The lead row, which could
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4667
                // be outside this range, should be considered also.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4668
                if (leadRow != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4669
                    minRow = Math.min(minRow, leadRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4670
                    maxRow = Math.max(maxRow, leadRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4671
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4672
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4673
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4674
        Rectangle firstColumnRect = getCellRect(minRow, firstIndex, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4675
        Rectangle lastColumnRect = getCellRect(maxRow, lastIndex, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4676
        Rectangle dirtyRegion = firstColumnRect.union(lastColumnRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4677
        repaint(dirtyRegion);
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
// Implementing ListSelectionListener interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4682
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4683
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4684
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4685
     * Invoked when the row selection changes -- repaints to show the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4686
     * selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4687
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4688
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4689
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4690
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4691
     * @param e   the event received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4692
     * @see ListSelectionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4693
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4694
    public void valueChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4695
        if (sortManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4696
            sortManager.viewSelectionChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4697
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4698
        boolean isAdjusting = e.getValueIsAdjusting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4699
        if (rowSelectionAdjusting && !isAdjusting) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4700
            // The assumption is that when the model is no longer adjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4701
            // we will have already gotten all the changes, and therefore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4702
            // don't need to do an additional paint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4703
            rowSelectionAdjusting = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4704
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4705
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4706
        rowSelectionAdjusting = isAdjusting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4707
        // The getCellRect() calls will fail unless there is at least one column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4708
        if (getRowCount() <= 0 || getColumnCount() <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4709
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4710
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4711
        int firstIndex = limit(e.getFirstIndex(), 0, getRowCount()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4712
        int lastIndex = limit(e.getLastIndex(), 0, getRowCount()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4713
        Rectangle firstRowRect = getCellRect(firstIndex, 0, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4714
        Rectangle lastRowRect = getCellRect(lastIndex, getColumnCount()-1, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4715
        Rectangle dirtyRegion = firstRowRect.union(lastRowRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4716
        repaint(dirtyRegion);
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
// Implementing the CellEditorListener interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4721
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4722
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4723
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4724
     * Invoked when editing is finished. The changes are saved and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4725
     * editor is discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4726
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4727
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4728
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4729
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4730
     * @param  e  the event received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4731
     * @see CellEditorListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4732
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4733
    public void editingStopped(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4734
        // Take in the new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4735
        TableCellEditor editor = getCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4736
        if (editor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4737
            Object value = editor.getCellEditorValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4738
            setValueAt(value, editingRow, editingColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4739
            removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4741
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4742
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4743
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4744
     * Invoked when editing is canceled. The editor object is discarded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4745
     * and the cell is rendered once again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4746
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4747
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4748
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4749
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4750
     * @param  e  the event received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4751
     * @see CellEditorListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4752
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4753
    public void editingCanceled(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4754
        removeEditor();
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
// Implementing the Scrollable interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4759
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4760
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4761
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4762
     * Sets the preferred size of the viewport for this table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4763
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4764
     * @param size  a <code>Dimension</code> object specifying the <code>preferredSize</code> of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4765
     *              <code>JViewport</code> whose view is this table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4766
     * @see Scrollable#getPreferredScrollableViewportSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4767
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4768
     * description: The preferred size of the viewport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4769
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4770
    public void setPreferredScrollableViewportSize(Dimension size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4771
        preferredViewportSize = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4772
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4773
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4774
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4775
     * Returns the preferred size of the viewport for this table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4776
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4777
     * @return a <code>Dimension</code> object containing the <code>preferredSize</code> of the <code>JViewport</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4778
     *         which displays this table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4779
     * @see Scrollable#getPreferredScrollableViewportSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4780
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4781
    public Dimension getPreferredScrollableViewportSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4782
        return preferredViewportSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4783
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4784
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4785
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4786
     * Returns the scroll increment (in pixels) that completely exposes one new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4787
     * row or column (depending on the orientation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4788
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4789
     * This method is called each time the user requests a unit scroll.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4790
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4791
     * @param visibleRect the view area visible within the viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4792
     * @param orientation either <code>SwingConstants.VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4793
     *                  or <code>SwingConstants.HORIZONTAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4794
     * @param direction less than zero to scroll up/left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4795
     *                  greater than zero for down/right
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4796
     * @return the "unit" increment for scrolling in the specified direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4797
     * @see Scrollable#getScrollableUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4798
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4799
    public int getScrollableUnitIncrement(Rectangle visibleRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4800
                                          int orientation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4801
                                          int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4802
        int leadingRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4803
        int leadingCol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4804
        Rectangle leadingCellRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4805
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4806
        int leadingVisibleEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4807
        int leadingCellEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4808
        int leadingCellSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4809
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4810
        leadingRow = getLeadingRow(visibleRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4811
        leadingCol = getLeadingCol(visibleRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4812
        if (orientation == SwingConstants.VERTICAL && leadingRow < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4813
            // Couldn't find leading row - return some default value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4814
            return getRowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4815
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4816
        else if (orientation == SwingConstants.HORIZONTAL && leadingCol < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4817
            // Couldn't find leading col - return some default value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4818
            return 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4819
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4820
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4821
        // Note that it's possible for one of leadingCol or leadingRow to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4822
        // -1, depending on the orientation.  This is okay, as getCellRect()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4823
        // still provides enough information to calculate the unit increment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4824
        leadingCellRect = getCellRect(leadingRow, leadingCol, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4825
        leadingVisibleEdge = leadingEdge(visibleRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4826
        leadingCellEdge = leadingEdge(leadingCellRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4827
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4828
        if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4829
            leadingCellSize = leadingCellRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4830
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4831
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4832
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4833
            leadingCellSize = leadingCellRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4834
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4835
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4836
        // 4 cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4837
        // #1: Leading cell fully visible, reveal next cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4838
        // #2: Leading cell fully visible, hide leading cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4839
        // #3: Leading cell partially visible, hide rest of leading cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4840
        // #4: Leading cell partially visible, reveal rest of leading cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4841
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4842
        if (leadingVisibleEdge == leadingCellEdge) { // Leading cell is fully
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4843
                                                     // visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4844
            // Case #1: Reveal previous cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4845
            if (direction < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4846
                int retVal = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4847
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4848
                if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4849
                    // Loop past any zero-height rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4850
                    while (--leadingRow >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4851
                        retVal = getRowHeight(leadingRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4852
                        if (retVal != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4853
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4854
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4855
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4856
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4857
                else { // HORIZONTAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4858
                    // Loop past any zero-width cols
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4859
                    while (--leadingCol >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4860
                        retVal = getCellRect(leadingRow, leadingCol, true).width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4861
                        if (retVal != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4862
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4863
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4864
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4865
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4866
                return retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4867
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4868
            else { // Case #2: hide leading cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4869
                return leadingCellSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4870
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4871
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4872
        else { // Leading cell is partially hidden
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4873
            // Compute visible, hidden portions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4874
            int hiddenAmt = Math.abs(leadingVisibleEdge - leadingCellEdge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4875
            int visibleAmt = leadingCellSize - hiddenAmt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4876
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4877
            if (direction > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4878
                // Case #3: hide showing portion of leading cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4879
                return visibleAmt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4880
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4881
            else { // Case #4: reveal hidden portion of leading cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4882
                return hiddenAmt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4883
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4884
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4885
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4886
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4887
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4888
     * Returns <code>visibleRect.height</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4889
     * <code>visibleRect.width</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4890
     * depending on this table's orientation.  Note that as of Swing 1.1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4891
     * (Java 2 v 1.2.2) the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4892
     * returned will ensure that the viewport is cleanly aligned on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4893
     * a row boundary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4894
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4895
     * @return <code>visibleRect.height</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4896
     *                                  <code>visibleRect.width</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4897
     *                                  per the orientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4898
     * @see Scrollable#getScrollableBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4899
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4900
    public int getScrollableBlockIncrement(Rectangle visibleRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4901
            int orientation, int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4902
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4903
        if (getRowCount() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4904
            // Short-circuit empty table model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4905
            if (SwingConstants.VERTICAL == orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4906
                int rh = getRowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4907
                return (rh > 0) ? Math.max(rh, (visibleRect.height / rh) * rh) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4908
                                  visibleRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4909
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4910
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4911
                return visibleRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4912
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4913
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4914
        // Shortcut for vertical scrolling of a table w/ uniform row height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4915
        if (null == rowModel && SwingConstants.VERTICAL == orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4916
            int row = rowAtPoint(visibleRect.getLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4917
            assert row != -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4918
            int col = columnAtPoint(visibleRect.getLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4919
            Rectangle cellRect = getCellRect(row, col, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4920
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4921
            if (cellRect.y == visibleRect.y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4922
                int rh = getRowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4923
                assert rh > 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4924
                return Math.max(rh, (visibleRect.height / rh) * rh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4925
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4926
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4927
        if (direction < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4928
            return getPreviousBlockIncrement(visibleRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4929
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4930
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4931
            return getNextBlockIncrement(visibleRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4932
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4933
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4934
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4935
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4936
     * Called to get the block increment for upward scrolling in cases of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4937
     * horizontal scrolling, or for vertical scrolling of a table with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4938
     * variable row heights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4939
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4940
    private int getPreviousBlockIncrement(Rectangle visibleRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4941
                                          int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4942
        // Measure back from visible leading edge
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4943
        // If we hit the cell on its leading edge, it becomes the leading cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4944
        // Else, use following cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4945
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4946
        int row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4947
        int col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4948
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4949
        int   newEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4950
        Point newCellLoc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4951
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4952
        int visibleLeadingEdge = leadingEdge(visibleRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4953
        boolean leftToRight = getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4954
        int newLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4955
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4956
        // Roughly determine the new leading edge by measuring back from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4957
        // leading visible edge by the size of the visible rect, and find the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4958
        // cell there.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4959
        if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4960
            newEdge = visibleLeadingEdge - visibleRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4961
            int x = visibleRect.x + (leftToRight ? 0 : visibleRect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4962
            newCellLoc = new Point(x, newEdge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4963
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4964
        else if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4965
            newEdge = visibleLeadingEdge - visibleRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4966
            newCellLoc = new Point(newEdge, visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4968
        else { // Horizontal, right-to-left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4969
            newEdge = visibleLeadingEdge + visibleRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4970
            newCellLoc = new Point(newEdge - 1, visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4971
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4972
        row = rowAtPoint(newCellLoc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4973
        col = columnAtPoint(newCellLoc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4974
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4975
        // If we're measuring past the beginning of the table, we get an invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4976
        // cell.  Just go to the beginning of the table in this case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4977
        if (orientation == SwingConstants.VERTICAL & row < 0) {
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 if (orientation == SwingConstants.HORIZONTAL & col < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4981
            if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4982
                newLeadingEdge = 0;
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
                newLeadingEdge = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4986
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4987
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4988
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4989
            // Refine our measurement
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4990
            Rectangle newCellRect = getCellRect(row, col, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4991
            int newCellLeadingEdge = leadingEdge(newCellRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4992
            int newCellTrailingEdge = trailingEdge(newCellRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4993
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4994
            // Usually, we hit in the middle of newCell, and want to scroll to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4995
            // the beginning of the cell after newCell.  But there are a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4996
            // couple corner cases where we want to scroll to the beginning of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4997
            // newCell itself.  These cases are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4998
            // 1) newCell is so large that it ends at or extends into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4999
            //    visibleRect (newCell is the leading cell, or is adjacent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5000
            //    the leading cell)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5001
            // 2) newEdge happens to fall right on the beginning of a cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5003
            // Case 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5004
            if ((orientation == SwingConstants.VERTICAL || leftToRight) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5005
                (newCellTrailingEdge >= visibleLeadingEdge)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5006
                newLeadingEdge = newCellLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5007
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5008
            else if (orientation == SwingConstants.HORIZONTAL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5009
                     !leftToRight &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5010
                     newCellTrailingEdge <= visibleLeadingEdge) {
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
            // Case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5014
            else if (newEdge == newCellLeadingEdge) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5015
                newLeadingEdge = newCellLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5016
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5017
            // Common case: scroll to cell after newCell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5018
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5019
                newLeadingEdge = newCellTrailingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5020
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5021
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5022
        return Math.abs(visibleLeadingEdge - newLeadingEdge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5023
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5025
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5026
     * Called to get the block increment for downward scrolling in cases of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5027
     * horizontal scrolling, or for vertical scrolling of a table with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5028
     * variable row heights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5029
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5030
    private int getNextBlockIncrement(Rectangle visibleRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5031
                                      int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5032
        // Find the cell at the trailing edge.  Return the distance to put
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5033
        // that cell at the leading edge.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5034
        int trailingRow = getTrailingRow(visibleRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5035
        int trailingCol = getTrailingCol(visibleRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5037
        Rectangle cellRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5038
        boolean cellFillsVis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5039
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5040
        int cellLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5041
        int cellTrailingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5042
        int newLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5043
        int visibleLeadingEdge = leadingEdge(visibleRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5044
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5045
        // If we couldn't find trailing cell, just return the size of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5046
        // visibleRect.  Note that, for instance, we don't need the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5047
        // trailingCol to proceed if we're scrolling vertically, because
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5048
        // cellRect will still fill in the required dimensions.  This would
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5049
        // happen if we're scrolling vertically, and the table is not wide
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5050
        // enough to fill the visibleRect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5051
        if (orientation == SwingConstants.VERTICAL && trailingRow < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5052
            return visibleRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5053
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5054
        else if (orientation == SwingConstants.HORIZONTAL && trailingCol < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5055
            return visibleRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5056
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5057
        cellRect = getCellRect(trailingRow, trailingCol, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5058
        cellLeadingEdge = leadingEdge(cellRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5059
        cellTrailingEdge = trailingEdge(cellRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5061
        if (orientation == SwingConstants.VERTICAL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5062
            getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5063
            cellFillsVis = cellLeadingEdge <= visibleLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5064
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5065
        else { // Horizontal, right-to-left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5066
            cellFillsVis = cellLeadingEdge >= visibleLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5067
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5069
        if (cellFillsVis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5070
            // The visibleRect contains a single large cell.  Scroll to the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5071
            // of this cell, so the following cell is the first cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5072
            newLeadingEdge = cellTrailingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5073
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5074
        else if (cellTrailingEdge == trailingEdge(visibleRect, orientation)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5075
            // The trailing cell happens to end right at the end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5076
            // visibleRect.  Again, scroll to the beginning of the next cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5077
            newLeadingEdge = cellTrailingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5078
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5079
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5080
            // Common case: the trailing cell is partially visible, and isn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5081
            // big enough to take up the entire visibleRect.  Scroll so it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5082
            // becomes the leading cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5083
            newLeadingEdge = cellLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5084
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5085
        return Math.abs(newLeadingEdge - visibleLeadingEdge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5086
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5088
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5089
     * Return the row at the top of the visibleRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5090
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5091
     * May return -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5092
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5093
    private int getLeadingRow(Rectangle visibleRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5094
        Point leadingPoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5096
        if (getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5097
            leadingPoint = new Point(visibleRect.x, visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5098
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5099
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5100
            leadingPoint = new Point(visibleRect.x + visibleRect.width - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5101
                                     visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5103
        return rowAtPoint(leadingPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5106
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5107
     * Return the column at the leading edge of the visibleRect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5109
     * May return -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5111
    private int getLeadingCol(Rectangle visibleRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5112
        Point leadingPoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5114
        if (getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5115
            leadingPoint = new Point(visibleRect.x, visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5117
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5118
            leadingPoint = new Point(visibleRect.x + visibleRect.width - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5119
                                     visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5121
        return columnAtPoint(leadingPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5124
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5125
     * Return the row at the bottom of the visibleRect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5127
     * May return -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5129
    private int getTrailingRow(Rectangle visibleRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5130
        Point trailingPoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5132
        if (getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5133
            trailingPoint = new Point(visibleRect.x,
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
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5137
            trailingPoint = new Point(visibleRect.x + visibleRect.width - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5138
                                      visibleRect.y + visibleRect.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5140
        return rowAtPoint(trailingPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5143
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5144
     * Return the column at the trailing edge of the visibleRect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5145
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5146
     * May return -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5148
    private int getTrailingCol(Rectangle visibleRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5149
        Point trailingPoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5150
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5151
        if (getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5152
            trailingPoint = new Point(visibleRect.x + visibleRect.width - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5153
                                      visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5155
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5156
            trailingPoint = new Point(visibleRect.x, visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5158
        return columnAtPoint(trailingPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5160
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5161
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5162
     * Returns the leading edge ("beginning") of the given Rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5163
     * For VERTICAL, this is the top, for left-to-right, the left side, and for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5164
     * right-to-left, the right side.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5166
    private int leadingEdge(Rectangle rect, int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5167
        if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5168
            return rect.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5170
        else if (getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5171
            return rect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5173
        else { // Horizontal, right-to-left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5174
            return rect.x + rect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5177
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5178
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5179
     * Returns the trailing edge ("end") of the given Rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5180
     * For VERTICAL, this is the bottom, for left-to-right, the right side, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5181
     * for right-to-left, the left side.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5183
    private int trailingEdge(Rectangle rect, int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5184
        if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5185
            return rect.y + rect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5187
        else if (getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5188
            return rect.x + rect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5190
        else { // Horizontal, right-to-left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5191
            return rect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5194
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5196
     * Returns false if <code>autoResizeMode</code> is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5197
     * <code>AUTO_RESIZE_OFF</code>, which indicates that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5198
     * width of the viewport does not determine the width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5199
     * of the table.  Otherwise returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5201
     * @return false if <code>autoResizeMode</code> is set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5202
     *   to <code>AUTO_RESIZE_OFF</code>, otherwise returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5203
     * @see Scrollable#getScrollableTracksViewportWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5205
    public boolean getScrollableTracksViewportWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5206
        return !(autoResizeMode == AUTO_RESIZE_OFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5210
     * Returns {@code false} to indicate that the height of the viewport does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5211
     * not determine the height of the table, unless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5212
     * {@code getFillsViewportHeight} is {@code true} and the preferred height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5213
     * of the table is smaller than the viewport's height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5215
     * @return {@code false} unless {@code getFillsViewportHeight} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5216
     *         {@code true} and the table needs to be stretched to fill
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5217
     *         the viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5218
     * @see Scrollable#getScrollableTracksViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5219
     * @see #setFillsViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5220
     * @see #getFillsViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5222
    public boolean getScrollableTracksViewportHeight() {
5449
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
  5223
        Container parent = SwingUtilities.getUnwrappedParent(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5224
        return getFillsViewportHeight()
5449
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
  5225
               && parent instanceof JViewport
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
  5226
               && parent.getHeight() > getPreferredSize().height;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5230
     * Sets whether or not this table is always made large enough
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5231
     * to fill the height of an enclosing viewport. If the preferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5232
     * height of the table is smaller than the viewport, then the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5233
     * will be stretched to fill the viewport. In other words, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5234
     * ensures the table is never smaller than the viewport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5235
     * The default for this property is {@code false}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5237
     * @param fillsViewportHeight whether or not this table is always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5238
     *        made large enough to fill the height of an enclosing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5239
     *        viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5240
     * @see #getFillsViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5241
     * @see #getScrollableTracksViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5242
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5243
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5244
     *      bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5245
     *      description: Whether or not this table is always made large enough
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5246
     *                   to fill the height of an enclosing viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5248
    public void setFillsViewportHeight(boolean fillsViewportHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5249
        boolean old = this.fillsViewportHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5250
        this.fillsViewportHeight = fillsViewportHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5251
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5252
        firePropertyChange("fillsViewportHeight", old, fillsViewportHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5256
     * Returns whether or not this table is always made large enough
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5257
     * to fill the height of an enclosing viewport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5258
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5259
     * @return whether or not this table is always made large enough
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5260
     *         to fill the height of an enclosing viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5261
     * @see #setFillsViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5262
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5264
    public boolean getFillsViewportHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5265
        return fillsViewportHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5268
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5269
// Protected Methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5270
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5272
    protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5273
                                        int condition, boolean pressed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5274
        boolean retValue = super.processKeyBinding(ks, e, condition, pressed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5275
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5276
        // Start editing when a key is typed. UI classes can disable this behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5277
        // by setting the client property JTable.autoStartsEdit to Boolean.FALSE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5278
        if (!retValue && condition == WHEN_ANCESTOR_OF_FOCUSED_COMPONENT &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5279
            isFocusOwner() &&
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  5280
            !Boolean.FALSE.equals(getClientProperty("JTable.autoStartsEdit"))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5281
            // We do not have a binding for the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5282
            Component editorComponent = getEditorComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5283
            if (editorComponent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5284
                // Only attempt to install the editor on a KEY_PRESSED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5285
                if (e == null || e.getID() != KeyEvent.KEY_PRESSED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5286
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5287
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5288
                // Don't start when just a modifier is pressed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5289
                int code = e.getKeyCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5290
                if (code == KeyEvent.VK_SHIFT || code == KeyEvent.VK_CONTROL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5291
                    code == KeyEvent.VK_ALT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5292
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5293
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5294
                // Try to install the editor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5295
                int leadRow = getSelectionModel().getLeadSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5296
                int leadColumn = getColumnModel().getSelectionModel().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5297
                                   getLeadSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5298
                if (leadRow != -1 && leadColumn != -1 && !isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5299
                    if (!editCellAt(leadRow, leadColumn, e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5300
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5301
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5302
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5303
                editorComponent = getEditorComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5304
                if (editorComponent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5305
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5306
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5307
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5308
            // If the editorComponent is a JComponent, pass the event to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5309
            if (editorComponent instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5310
                retValue = ((JComponent)editorComponent).processKeyBinding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5311
                                        (ks, e, WHEN_FOCUSED, pressed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5312
                // If we have started an editor as a result of the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5313
                // pressing a key and the surrendersFocusOnKeystroke property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5314
                // is true, give the focus to the new editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5315
                if (getSurrendersFocusOnKeystroke()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5316
                    editorComponent.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5317
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5318
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5320
        return retValue;
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 setLazyValue(Hashtable h, Class c, String s) {
4272
f4742294ef29 6795356: Leak caused by javax.swing.UIDefaults.ProxyLazyValue.acc
alexp
parents: 3737
diff changeset
  5324
        h.put(c, new SwingLazyValue(s));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5327
    private void setLazyRenderer(Class c, String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5328
        setLazyValue(defaultRenderersByColumnClass, c, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5331
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5332
     * Creates default cell renderers for objects, numbers, doubles, dates,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5333
     * booleans, and icons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5334
     * @see javax.swing.table.DefaultTableCellRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5337
    protected void createDefaultRenderers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5338
        defaultRenderersByColumnClass = new UIDefaults(8, 0.75f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5339
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5340
        // Objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5341
        setLazyRenderer(Object.class, "javax.swing.table.DefaultTableCellRenderer$UIResource");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5342
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5343
        // Numbers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5344
        setLazyRenderer(Number.class, "javax.swing.JTable$NumberRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5345
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5346
        // Doubles and Floats
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5347
        setLazyRenderer(Float.class, "javax.swing.JTable$DoubleRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5348
        setLazyRenderer(Double.class, "javax.swing.JTable$DoubleRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5350
        // Dates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5351
        setLazyRenderer(Date.class, "javax.swing.JTable$DateRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5352
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5353
        // Icons and ImageIcons
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5354
        setLazyRenderer(Icon.class, "javax.swing.JTable$IconRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5355
        setLazyRenderer(ImageIcon.class, "javax.swing.JTable$IconRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5356
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5357
        // Booleans
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5358
        setLazyRenderer(Boolean.class, "javax.swing.JTable$BooleanRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5360
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5361
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5362
     * Default Renderers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5363
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5364
    static class NumberRenderer extends DefaultTableCellRenderer.UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5365
        public NumberRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5366
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5367
            setHorizontalAlignment(JLabel.RIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5370
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5371
    static class DoubleRenderer extends NumberRenderer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5372
        NumberFormat formatter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5373
        public DoubleRenderer() { super(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5375
        public void setValue(Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5376
            if (formatter == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5377
                formatter = NumberFormat.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5378
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5379
            setText((value == null) ? "" : formatter.format(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5383
    static class DateRenderer extends DefaultTableCellRenderer.UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5384
        DateFormat formatter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5385
        public DateRenderer() { super(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5386
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5387
        public void setValue(Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5388
            if (formatter==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5389
                formatter = DateFormat.getDateInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5390
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5391
            setText((value == null) ? "" : formatter.format(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5395
    static class IconRenderer extends DefaultTableCellRenderer.UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5396
        public IconRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5397
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5398
            setHorizontalAlignment(JLabel.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5400
        public void setValue(Object value) { setIcon((value instanceof Icon) ? (Icon)value : null); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5403
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5404
    static class BooleanRenderer extends JCheckBox implements TableCellRenderer, UIResource
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5405
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5406
        private static final Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5407
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5408
        public BooleanRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5409
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5410
            setHorizontalAlignment(JLabel.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5411
            setBorderPainted(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5413
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5414
        public Component getTableCellRendererComponent(JTable table, Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5415
                                                       boolean isSelected, boolean hasFocus, int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5416
            if (isSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5417
                setForeground(table.getSelectionForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5418
                super.setBackground(table.getSelectionBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5419
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5420
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5421
                setForeground(table.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5422
                setBackground(table.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5423
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5424
            setSelected((value != null && ((Boolean)value).booleanValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5426
            if (hasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5427
                setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5428
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5429
                setBorder(noFocusBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5430
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5431
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5432
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5433
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5435
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5436
    private void setLazyEditor(Class c, String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5437
        setLazyValue(defaultEditorsByColumnClass, c, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5439
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5440
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5441
     * Creates default cell editors for objects, numbers, and boolean values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5442
     * @see DefaultCellEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5443
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5444
    protected void createDefaultEditors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5445
        defaultEditorsByColumnClass = new UIDefaults(3, 0.75f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5447
        // Objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5448
        setLazyEditor(Object.class, "javax.swing.JTable$GenericEditor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5450
        // Numbers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5451
        setLazyEditor(Number.class, "javax.swing.JTable$NumberEditor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5453
        // Booleans
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5454
        setLazyEditor(Boolean.class, "javax.swing.JTable$BooleanEditor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5456
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5457
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5458
     * Default Editors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5459
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5460
    static class GenericEditor extends DefaultCellEditor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5461
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5462
        Class[] argTypes = new Class[]{String.class};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5463
        java.lang.reflect.Constructor constructor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5464
        Object value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5466
        public GenericEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5467
            super(new JTextField());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5468
            getComponent().setName("Table.editor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5470
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5471
        public boolean stopCellEditing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5472
            String s = (String)super.getCellEditorValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5473
            // Here we are dealing with the case where a user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5474
            // has deleted the string value in a cell, possibly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5475
            // after a failed validation. Return null, so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5476
            // they have the option to replace the value with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5477
            // null or use escape to restore the original.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5478
            // For Strings, return "" for backward compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5479
            if ("".equals(s)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5480
                if (constructor.getDeclaringClass() == String.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5481
                    value = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5482
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5483
                super.stopCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5484
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5486
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5487
                value = constructor.newInstance(new Object[]{s});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5488
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5489
            catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5490
                ((JComponent)getComponent()).setBorder(new LineBorder(Color.red));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5491
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5492
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5493
            return super.stopCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5496
        public Component getTableCellEditorComponent(JTable table, Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5497
                                                 boolean isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5498
                                                 int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5499
            this.value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5500
            ((JComponent)getComponent()).setBorder(new LineBorder(Color.black));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5501
            try {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  5502
                Class<?> type = table.getColumnClass(column);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5503
                // Since our obligation is to produce a value which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5504
                // assignable for the required type it is OK to use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5505
                // String constructor for columns which are declared
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5506
                // to contain Objects. A String is an Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5507
                if (type == Object.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5508
                    type = String.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5509
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5510
                constructor = type.getConstructor(argTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5511
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5512
            catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5513
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5514
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5515
            return super.getTableCellEditorComponent(table, value, isSelected, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5517
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5518
        public Object getCellEditorValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5519
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5520
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5522
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5523
    static class NumberEditor extends GenericEditor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5524
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5525
        public NumberEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5526
            ((JTextField)getComponent()).setHorizontalAlignment(JTextField.RIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5527
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5529
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5530
    static class BooleanEditor extends DefaultCellEditor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5531
        public BooleanEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5532
            super(new JCheckBox());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5533
            JCheckBox checkBox = (JCheckBox)getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5534
            checkBox.setHorizontalAlignment(JCheckBox.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5535
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5536
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5537
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5538
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5539
     * Initializes table properties to their default values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5540
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5541
    protected void initializeLocalVars() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5542
        updateSelectionOnSort = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5543
        setOpaque(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5544
        createDefaultRenderers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5545
        createDefaultEditors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5546
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5547
        setTableHeader(createDefaultTableHeader());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5548
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5549
        setShowGrid(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5550
        setAutoResizeMode(AUTO_RESIZE_SUBSEQUENT_COLUMNS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5551
        setRowHeight(16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5552
        isRowHeightSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5553
        setRowMargin(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5554
        setRowSelectionAllowed(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5555
        setCellEditor(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5556
        setEditingColumn(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5557
        setEditingRow(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5558
        setSurrendersFocusOnKeystroke(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5559
        setPreferredScrollableViewportSize(new Dimension(450, 400));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5560
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5561
        // I'm registered to do tool tips so we can draw tips for the renderers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5562
        ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5563
        toolTipManager.registerComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5564
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5565
        setAutoscrolls(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5567
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5568
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5569
     * Returns the default table model object, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5570
     * a <code>DefaultTableModel</code>.  A subclass can override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5571
     * method to return a different table model object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5572
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5573
     * @return the default table model object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5574
     * @see javax.swing.table.DefaultTableModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5575
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5576
    protected TableModel createDefaultDataModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5577
        return new DefaultTableModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5579
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5580
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5581
     * Returns the default column model object, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5582
     * a <code>DefaultTableColumnModel</code>.  A subclass can override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5583
     * method to return a different column model object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5584
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5585
     * @return the default column model object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5586
     * @see javax.swing.table.DefaultTableColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5587
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5588
    protected TableColumnModel createDefaultColumnModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5589
        return new DefaultTableColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5590
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5591
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5592
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5593
     * Returns the default selection model object, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5594
     * a <code>DefaultListSelectionModel</code>.  A subclass can override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5595
     * method to return a different selection model object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5596
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5597
     * @return the default selection model object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5598
     * @see javax.swing.DefaultListSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5599
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5600
    protected ListSelectionModel createDefaultSelectionModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5601
        return new DefaultListSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5604
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5605
     * Returns the default table header object, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5606
     * a <code>JTableHeader</code>.  A subclass can override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5607
     * method to return a different table header object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5608
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5609
     * @return the default table header object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5610
     * @see javax.swing.table.JTableHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5611
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5612
    protected JTableHeader createDefaultTableHeader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5613
        return new JTableHeader(columnModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5615
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5616
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5617
     * Equivalent to <code>revalidate</code> followed by <code>repaint</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5618
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5619
    protected void resizeAndRepaint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5620
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5621
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5623
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5624
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5625
     * Returns the active cell editor, which is {@code null} if the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5626
     * is not currently editing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5627
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5628
     * @return the {@code TableCellEditor} that does the editing,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5629
     *         or {@code null} if the table is not currently editing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5630
     * @see #cellEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5631
     * @see #getCellEditor(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5632
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5633
    public TableCellEditor getCellEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5634
        return cellEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5635
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5636
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5637
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5638
     * Sets the active cell editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5639
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5640
     * @param anEditor the active cell editor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5641
     * @see #cellEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5642
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5643
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5644
     *  description: The table's active cell editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5645
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5646
    public void setCellEditor(TableCellEditor anEditor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5647
        TableCellEditor oldEditor = cellEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5648
        cellEditor = anEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5649
        firePropertyChange("tableCellEditor", oldEditor, anEditor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5650
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5651
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5652
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5653
     * Sets the <code>editingColumn</code> variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5654
     * @param aColumn  the column of the cell to be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5655
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5656
     * @see #editingColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5657
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5658
    public void setEditingColumn(int aColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5659
        editingColumn = aColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5661
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5662
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5663
     * Sets the <code>editingRow</code> variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5664
     * @param aRow  the row of the cell to be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5665
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5666
     * @see #editingRow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5667
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5668
    public void setEditingRow(int aRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5669
        editingRow = aRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5670
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5671
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5672
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5673
     * Returns an appropriate renderer for the cell specified by this row and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5674
     * column. If the <code>TableColumn</code> for this column has a non-null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5675
     * renderer, returns that.  If not, finds the class of the data in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5676
     * this column (using <code>getColumnClass</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5677
     * and returns the default renderer for this type of data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5678
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5679
     * <b>Note:</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5680
     * Throughout the table package, the internal implementations always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5681
     * use this method to provide renderers so that this default behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5682
     * can be safely overridden by a subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5683
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5684
     * @param row       the row of the cell to render, where 0 is the first row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5685
     * @param column    the column of the cell to render,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5686
     *                  where 0 is the first column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5687
     * @return the assigned renderer; if <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5688
     *                  returns the default renderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5689
     *                  for this type of object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5690
     * @see javax.swing.table.DefaultTableCellRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5691
     * @see javax.swing.table.TableColumn#setCellRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5692
     * @see #setDefaultRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5693
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5694
    public TableCellRenderer getCellRenderer(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5695
        TableColumn tableColumn = getColumnModel().getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5696
        TableCellRenderer renderer = tableColumn.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5697
        if (renderer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5698
            renderer = getDefaultRenderer(getColumnClass(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5699
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5700
        return renderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5701
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5702
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5703
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5704
     * Prepares the renderer by querying the data model for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5705
     * value and selection state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5706
     * of the cell at <code>row</code>, <code>column</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5707
     * Returns the component (may be a <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5708
     * or a <code>JComponent</code>) under the event location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5709
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5710
     * During a printing operation, this method will configure the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5711
     * renderer without indicating selection or focus, to prevent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5712
     * them from appearing in the printed output. To do other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5713
     * customizations based on whether or not the table is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5714
     * printed, you can check the value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5715
     * {@link javax.swing.JComponent#isPaintingForPrint()}, either here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5716
     * or within custom renderers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5717
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5718
     * <b>Note:</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5719
     * Throughout the table package, the internal implementations always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5720
     * use this method to prepare renderers so that this default behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5721
     * can be safely overridden by a subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5722
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5723
     * @param renderer  the <code>TableCellRenderer</code> to prepare
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5724
     * @param row       the row of the cell to render, where 0 is the first row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5725
     * @param column    the column of the cell to render,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5726
     *                  where 0 is the first column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5727
     * @return          the <code>Component</code> under the event location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5728
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5729
    public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5730
        Object value = getValueAt(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5731
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5732
        boolean isSelected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5733
        boolean hasFocus = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5734
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5735
        // Only indicate the selection and focused cell if not printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5736
        if (!isPaintingForPrint()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5737
            isSelected = isCellSelected(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5738
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5739
            boolean rowIsLead =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5740
                (selectionModel.getLeadSelectionIndex() == row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5741
            boolean colIsLead =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5742
                (columnModel.getSelectionModel().getLeadSelectionIndex() == column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5743
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5744
            hasFocus = (rowIsLead && colIsLead) && isFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5745
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5746
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5747
        return renderer.getTableCellRendererComponent(this, value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5748
                                                      isSelected, hasFocus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5749
                                                      row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5750
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5751
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5752
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5753
     * Returns an appropriate editor for the cell specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5754
     * <code>row</code> and <code>column</code>. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5755
     * <code>TableColumn</code> for this column has a non-null editor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5756
     * returns that.  If not, finds the class of the data in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5757
     * column (using <code>getColumnClass</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5758
     * and returns the default editor for this type of data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5759
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5760
     * <b>Note:</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5761
     * Throughout the table package, the internal implementations always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5762
     * use this method to provide editors so that this default behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5763
     * can be safely overridden by a subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5764
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5765
     * @param row       the row of the cell to edit, where 0 is the first row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5766
     * @param column    the column of the cell to edit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5767
     *                  where 0 is the first column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5768
     * @return          the editor for this cell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5769
     *                  if <code>null</code> return the default editor for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5770
     *                  this type of cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5771
     * @see DefaultCellEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5772
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5773
    public TableCellEditor getCellEditor(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5774
        TableColumn tableColumn = getColumnModel().getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5775
        TableCellEditor editor = tableColumn.getCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5776
        if (editor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5777
            editor = getDefaultEditor(getColumnClass(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5778
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5779
        return editor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5780
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5781
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5782
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5783
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5784
     * Prepares the editor by querying the data model for the value and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5785
     * selection state of the cell at <code>row</code>, <code>column</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5786
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5787
     * <b>Note:</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5788
     * Throughout the table package, the internal implementations always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5789
     * use this method to prepare editors so that this default behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5790
     * can be safely overridden by a subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5791
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5792
     * @param editor  the <code>TableCellEditor</code> to set up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5793
     * @param row     the row of the cell to edit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5794
     *                where 0 is the first row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5795
     * @param column  the column of the cell to edit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5796
     *                where 0 is the first column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5797
     * @return the <code>Component</code> being edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5798
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5799
    public Component prepareEditor(TableCellEditor editor, int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5800
        Object value = getValueAt(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5801
        boolean isSelected = isCellSelected(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5802
        Component comp = editor.getTableCellEditorComponent(this, value, isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5803
                                                  row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5804
        if (comp instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5805
            JComponent jComp = (JComponent)comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5806
            if (jComp.getNextFocusableComponent() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5807
                jComp.setNextFocusableComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5808
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5809
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5810
        return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5811
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5812
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5813
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5814
     * Discards the editor object and frees the real estate it used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5815
     * cell rendering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5816
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5817
    public void removeEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5818
        KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5819
            removePropertyChangeListener("permanentFocusOwner", editorRemover);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5820
        editorRemover = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5821
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5822
        TableCellEditor editor = getCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5823
        if(editor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5824
            editor.removeCellEditorListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5825
            if (editorComp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5826
                Component focusOwner =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5827
                        KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5828
                boolean isFocusOwnerInTheTable = focusOwner != null?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5829
                        SwingUtilities.isDescendingFrom(focusOwner, this):false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5830
                remove(editorComp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5831
                if(isFocusOwnerInTheTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5832
                    requestFocusInWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5833
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5834
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5835
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5836
            Rectangle cellRect = getCellRect(editingRow, editingColumn, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5837
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5838
            setCellEditor(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5839
            setEditingColumn(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5840
            setEditingRow(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5841
            editorComp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5842
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5843
            repaint(cellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5844
        }
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
// Serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5849
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5850
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5851
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5852
     * See readObject() and writeObject() in JComponent for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5853
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5854
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5855
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5856
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5857
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5858
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5859
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5860
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5861
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5862
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5863
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5864
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5865
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5866
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5867
        throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5868
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5869
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5870
        if ((ui != null) && (getUIClassID().equals(uiClassID))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5871
            ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5872
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5873
        createDefaultRenderers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5874
        createDefaultEditors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5875
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5876
        // If ToolTipText != null, then the tooltip has already been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5877
        // registered by JComponent.readObject() and we don't want
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5878
        // to re-register here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5879
        if (getToolTipText() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5880
            ToolTipManager.sharedInstance().registerComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5881
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5882
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5883
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5884
    /* Called from the JComponent's EnableSerializationFocusListener to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5885
     * do any Swing-specific pre-serialization configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5886
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5887
    void compWriteObjectNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5888
        super.compWriteObjectNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5889
        // If ToolTipText != null, then the tooltip has already been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5890
        // unregistered by JComponent.compWriteObjectNotify()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5891
        if (getToolTipText() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5892
            ToolTipManager.sharedInstance().unregisterComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5893
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5894
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5895
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5896
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5897
     * Returns a string representation of this table. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5898
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5899
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5900
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5901
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5902
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5903
     * @return  a string representation of this table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5904
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5905
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5906
        String gridColorString = (gridColor != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5907
                                  gridColor.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5908
        String showHorizontalLinesString = (showHorizontalLines ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5909
                                            "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5910
        String showVerticalLinesString = (showVerticalLines ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5911
                                          "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5912
        String autoResizeModeString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5913
        if (autoResizeMode == AUTO_RESIZE_OFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5914
            autoResizeModeString = "AUTO_RESIZE_OFF";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5915
        } else if (autoResizeMode == AUTO_RESIZE_NEXT_COLUMN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5916
            autoResizeModeString = "AUTO_RESIZE_NEXT_COLUMN";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5917
        } else if (autoResizeMode == AUTO_RESIZE_SUBSEQUENT_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5918
            autoResizeModeString = "AUTO_RESIZE_SUBSEQUENT_COLUMNS";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5919
        } else if (autoResizeMode == AUTO_RESIZE_LAST_COLUMN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5920
            autoResizeModeString = "AUTO_RESIZE_LAST_COLUMN";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5921
        } else if (autoResizeMode == AUTO_RESIZE_ALL_COLUMNS)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5922
            autoResizeModeString = "AUTO_RESIZE_ALL_COLUMNS";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5923
        } else autoResizeModeString = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5924
        String autoCreateColumnsFromModelString = (autoCreateColumnsFromModel ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5925
                                                   "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5926
        String preferredViewportSizeString = (preferredViewportSize != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5927
                                              preferredViewportSize.toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5928
                                              : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5929
        String rowSelectionAllowedString = (rowSelectionAllowed ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5930
                                            "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5931
        String cellSelectionEnabledString = (cellSelectionEnabled ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5932
                                            "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5933
        String selectionForegroundString = (selectionForeground != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5934
                                            selectionForeground.toString() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5935
                                            "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5936
        String selectionBackgroundString = (selectionBackground != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5937
                                            selectionBackground.toString() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5938
                                            "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5939
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5940
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5941
        ",autoCreateColumnsFromModel=" + autoCreateColumnsFromModelString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5942
        ",autoResizeMode=" + autoResizeModeString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5943
        ",cellSelectionEnabled=" + cellSelectionEnabledString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5944
        ",editingColumn=" + editingColumn +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5945
        ",editingRow=" + editingRow +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5946
        ",gridColor=" + gridColorString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5947
        ",preferredViewportSize=" + preferredViewportSizeString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5948
        ",rowHeight=" + rowHeight +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5949
        ",rowMargin=" + rowMargin +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5950
        ",rowSelectionAllowed=" + rowSelectionAllowedString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5951
        ",selectionBackground=" + selectionBackgroundString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5952
        ",selectionForeground=" + selectionForegroundString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5953
        ",showHorizontalLines=" + showHorizontalLinesString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5954
        ",showVerticalLines=" + showVerticalLinesString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5955
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5956
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5957
    // This class tracks changes in the keyboard focus state. It is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5958
    // when the JTable is editing to determine when to cancel the edit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5959
    // If focus switches to a component outside of the jtable, but in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5960
    // same window, this will cancel editing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5961
    class CellEditorRemover implements PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5962
        KeyboardFocusManager focusManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5963
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5964
        public CellEditorRemover(KeyboardFocusManager fm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5965
            this.focusManager = fm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5966
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5967
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5968
        public void propertyChange(PropertyChangeEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5969
            if (!isEditing() || getClientProperty("terminateEditOnFocusLost") != Boolean.TRUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5970
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5971
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5972
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5973
            Component c = focusManager.getPermanentFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5974
            while (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5975
                if (c == JTable.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5976
                    // focus remains inside the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5977
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5978
                } else if ((c instanceof Window) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5979
                           (c instanceof Applet && c.getParent() == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5980
                    if (c == SwingUtilities.getRoot(JTable.this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5981
                        if (!getCellEditor().stopCellEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5982
                            getCellEditor().cancelCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5983
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5984
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5985
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5986
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5987
                c = c.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5988
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5989
        }
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
// Printing Support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5994
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5995
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5996
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5997
     * A convenience method that displays a printing dialog, and then prints
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5998
     * this <code>JTable</code> in mode <code>PrintMode.FIT_WIDTH</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5999
     * with no header or footer text. A modal progress dialog, with an abort
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6000
     * option, will be shown for the duration of printing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6001
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6002
     * Note: In headless mode, no dialogs are shown and printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6003
     * occurs on the default printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6004
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6005
     * @return true, unless printing is cancelled by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6006
     * @throws SecurityException if this thread is not allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6007
     *                           initiate a print job request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6008
     * @throws PrinterException if an error in the print system causes the job
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6009
     *                          to be aborted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6010
     * @see #print(JTable.PrintMode, MessageFormat, MessageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6011
     *             boolean, PrintRequestAttributeSet, boolean, PrintService)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6012
     * @see #getPrintable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6013
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6014
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6015
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6016
    public boolean print() throws PrinterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6018
        return print(PrintMode.FIT_WIDTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6019
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6021
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6022
     * A convenience method that displays a printing dialog, and then prints
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6023
     * this <code>JTable</code> in the given printing mode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6024
     * with no header or footer text. A modal progress dialog, with an abort
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6025
     * option, will be shown for the duration of printing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6026
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6027
     * Note: In headless mode, no dialogs are shown and printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6028
     * occurs on the default printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6029
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6030
     * @param  printMode        the printing mode that the printable should use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6031
     * @return true, unless printing is cancelled by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6032
     * @throws SecurityException if this thread is not allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6033
     *                           initiate a print job request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6034
     * @throws PrinterException if an error in the print system causes the job
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6035
     *                          to be aborted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6036
     * @see #print(JTable.PrintMode, MessageFormat, MessageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6037
     *             boolean, PrintRequestAttributeSet, boolean, PrintService)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6038
     * @see #getPrintable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6039
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6040
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6041
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6042
    public boolean print(PrintMode printMode) throws PrinterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6044
        return print(printMode, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6045
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6046
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6047
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6048
     * A convenience method that displays a printing dialog, and then prints
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6049
     * this <code>JTable</code> in the given printing mode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6050
     * with the specified header and footer text. A modal progress dialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6051
     * with an abort option, will be shown for the duration of printing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6052
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6053
     * Note: In headless mode, no dialogs are shown and printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6054
     * occurs on the default printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6055
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6056
     * @param  printMode        the printing mode that the printable should use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6057
     * @param  headerFormat     a <code>MessageFormat</code> specifying the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6058
     *                          to be used in printing a header,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6059
     *                          or null for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6060
     * @param  footerFormat     a <code>MessageFormat</code> specifying the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6061
     *                          to be used in printing a footer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6062
     *                          or null for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6063
     * @return true, unless printing is cancelled by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6064
     * @throws SecurityException if this thread is not allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6065
     *                           initiate a print job request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6066
     * @throws PrinterException if an error in the print system causes the job
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6067
     *                          to be aborted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6068
     * @see #print(JTable.PrintMode, MessageFormat, MessageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6069
     *             boolean, PrintRequestAttributeSet, boolean, PrintService)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6070
     * @see #getPrintable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6071
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6072
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6073
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6074
    public boolean print(PrintMode printMode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6075
                         MessageFormat headerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6076
                         MessageFormat footerFormat) throws PrinterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6078
        boolean showDialogs = !GraphicsEnvironment.isHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6079
        return print(printMode, headerFormat, footerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6080
                     showDialogs, null, showDialogs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6081
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6083
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6084
     * Prints this table, as specified by the fully featured
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6085
     * {@link #print(JTable.PrintMode, MessageFormat, MessageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6086
     * boolean, PrintRequestAttributeSet, boolean, PrintService) print}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6087
     * method, with the default printer specified as the print service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6088
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6089
     * @param  printMode        the printing mode that the printable should use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6090
     * @param  headerFormat     a <code>MessageFormat</code> specifying the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6091
     *                          to be used in printing a header,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6092
     *                          or <code>null</code> for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6093
     * @param  footerFormat     a <code>MessageFormat</code> specifying the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6094
     *                          to be used in printing a footer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6095
     *                          or <code>null</code> for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6096
     * @param  showPrintDialog  whether or not to display a print dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6097
     * @param  attr             a <code>PrintRequestAttributeSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6098
     *                          specifying any printing attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6099
     *                          or <code>null</code> for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6100
     * @param  interactive      whether or not to print in an interactive mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6101
     * @return true, unless printing is cancelled by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6102
     * @throws HeadlessException if the method is asked to show a printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6103
     *                           dialog or run interactively, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6104
     *                           <code>GraphicsEnvironment.isHeadless</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6105
     *                           returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6106
     * @throws SecurityException if this thread is not allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6107
     *                           initiate a print job request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6108
     * @throws PrinterException if an error in the print system causes the job
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6109
     *                          to be aborted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6110
     * @see #print(JTable.PrintMode, MessageFormat, MessageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6111
     *             boolean, PrintRequestAttributeSet, boolean, PrintService)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6112
     * @see #getPrintable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6114
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6116
    public boolean print(PrintMode printMode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6117
                         MessageFormat headerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6118
                         MessageFormat footerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6119
                         boolean showPrintDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6120
                         PrintRequestAttributeSet attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6121
                         boolean interactive) throws PrinterException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6122
                                                     HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6124
        return print(printMode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6125
                     headerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6126
                     footerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6127
                     showPrintDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6128
                     attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6129
                     interactive,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6130
                     null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6134
     * Prints this <code>JTable</code>. Takes steps that the majority of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6135
     * developers would take in order to print a <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6136
     * In short, it prepares the table, calls <code>getPrintable</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6137
     * fetch an appropriate <code>Printable</code>, and then sends it to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6138
     * printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6139
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6140
     * A <code>boolean</code> parameter allows you to specify whether or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6141
     * a printing dialog is displayed to the user. When it is, the user may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6142
     * use the dialog to change the destination printer or printing attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6143
     * or even to cancel the print. Another two parameters allow for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6144
     * <code>PrintService</code> and printing attributes to be specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6145
     * These parameters can be used either to provide initial values for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6146
     * print dialog, or to specify values when the dialog is not shown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6147
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6148
     * A second <code>boolean</code> parameter allows you to specify whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6149
     * or not to perform printing in an interactive mode. If <code>true</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6150
     * a modal progress dialog, with an abort option, is displayed for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6151
     * duration of printing . This dialog also prevents any user action which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6152
     * may affect the table. However, it can not prevent the table from being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6153
     * modified by code (for example, another thread that posts updates using
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6154
     * <code>SwingUtilities.invokeLater</code>). It is therefore the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6155
     * responsibility of the developer to ensure that no other code modifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6156
     * the table in any way during printing (invalid modifications include
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6157
     * changes in: size, renderers, or underlying data). Printing behavior is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6158
     * undefined when the table is changed during printing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6159
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6160
     * If <code>false</code> is specified for this parameter, no dialog will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6161
     * be displayed and printing will begin immediately on the event-dispatch
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6162
     * thread. This blocks any other events, including repaints, from being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6163
     * processed until printing is complete. Although this effectively prevents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6164
     * the table from being changed, it doesn't provide a good user experience.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6165
     * For this reason, specifying <code>false</code> is only recommended when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6166
     * printing from an application with no visible GUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6167
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6168
     * Note: Attempting to show the printing dialog or run interactively, while
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6169
     * in headless mode, will result in a <code>HeadlessException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6170
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6171
     * Before fetching the printable, this method will gracefully terminate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6172
     * editing, if necessary, to prevent an editor from showing in the printed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6173
     * result. Additionally, <code>JTable</code> will prepare its renderers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6174
     * during printing such that selection and focus are not indicated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6175
     * As far as customizing further how the table looks in the printout,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6176
     * developers can provide custom renderers or paint code that conditionalize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6177
     * on the value of {@link javax.swing.JComponent#isPaintingForPrint()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6178
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6179
     * See {@link #getPrintable} for more description on how the table is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6180
     * printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6182
     * @param  printMode        the printing mode that the printable should use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6183
     * @param  headerFormat     a <code>MessageFormat</code> specifying the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6184
     *                          to be used in printing a header,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6185
     *                          or <code>null</code> for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6186
     * @param  footerFormat     a <code>MessageFormat</code> specifying the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6187
     *                          to be used in printing a footer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6188
     *                          or <code>null</code> for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6189
     * @param  showPrintDialog  whether or not to display a print dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6190
     * @param  attr             a <code>PrintRequestAttributeSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6191
     *                          specifying any printing attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6192
     *                          or <code>null</code> for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6193
     * @param  interactive      whether or not to print in an interactive mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6194
     * @param  service          the destination <code>PrintService</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6195
     *                          or <code>null</code> to use the default printer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6196
     * @return true, unless printing is cancelled by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6197
     * @throws HeadlessException if the method is asked to show a printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6198
     *                           dialog or run interactively, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6199
     *                           <code>GraphicsEnvironment.isHeadless</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6200
     *                           returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6201
     * @throws  SecurityException if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6202
     *          {@link java.lang.SecurityManager#checkPrintJobAccess}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6203
     *          method disallows this thread from creating a print job request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6204
     * @throws PrinterException if an error in the print system causes the job
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6205
     *                          to be aborted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6206
     * @see #getPrintable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6207
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6209
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6211
    public boolean print(PrintMode printMode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6212
                         MessageFormat headerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6213
                         MessageFormat footerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6214
                         boolean showPrintDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6215
                         PrintRequestAttributeSet attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6216
                         boolean interactive,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6217
                         PrintService service) throws PrinterException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6218
                                                      HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6220
        // complain early if an invalid parameter is specified for headless mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6221
        boolean isHeadless = GraphicsEnvironment.isHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6222
        if (isHeadless) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6223
            if (showPrintDialog) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6224
                throw new HeadlessException("Can't show print dialog.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6227
            if (interactive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6228
                throw new HeadlessException("Can't run interactively.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6229
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6231
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6232
        // Get a PrinterJob.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6233
        // Do this before anything with side-effects since it may throw a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6234
        // security exception - in which case we don't want to do anything else.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6235
        final PrinterJob job = PrinterJob.getPrinterJob();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6237
        if (isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6238
            // try to stop cell editing, and failing that, cancel it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6239
            if (!getCellEditor().stopCellEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6240
                getCellEditor().cancelCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6244
        if (attr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6245
            attr = new HashPrintRequestAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6248
        final PrintingStatus printingStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6250
         // fetch the Printable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6251
        Printable printable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6252
             getPrintable(printMode, headerFormat, footerFormat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6254
        if (interactive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6255
            // wrap the Printable so that we can print on another thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6256
            printable = new ThreadSafePrintable(printable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6257
            printingStatus = PrintingStatus.createPrintingStatus(this, job);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6258
            printable = printingStatus.createNotificationPrintable(printable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6259
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6260
            // to please compiler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6261
            printingStatus = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6264
        // set the printable on the PrinterJob
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6265
        job.setPrintable(printable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6266
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6267
        // if specified, set the PrintService on the PrinterJob
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6268
        if (service != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6269
            job.setPrintService(service);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6272
        // if requested, show the print dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6273
        if (showPrintDialog && !job.printDialog(attr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6274
            // the user cancelled the print dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6275
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6278
        // if not interactive, just print on this thread (no dialog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6279
        if (!interactive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6280
            // do the printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6281
            job.print(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6282
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6283
            // we're done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6284
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6287
        // make sure this is clear since we'll check it after
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6288
        printError = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6290
        // to synchronize on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6291
        final Object lock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6293
        // copied so we can access from the inner class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6294
        final PrintRequestAttributeSet copyAttr = attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6295
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6296
        // this runnable will be used to do the printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6297
        // (and save any throwables) on another thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6298
        Runnable runnable = new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6299
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6300
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6301
                    // do the printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6302
                    job.print(copyAttr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6303
                } catch (Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6304
                    // save any Throwable to be rethrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6305
                    synchronized(lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6306
                        printError = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6307
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6308
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6309
                    // we're finished - hide the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6310
                    printingStatus.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6311
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6312
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6313
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6315
        // start printing on another thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6316
        Thread th = new Thread(runnable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6317
        th.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6319
        printingStatus.showModal(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6321
        // look for any error that the printing may have generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6322
        Throwable pe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6323
        synchronized(lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6324
            pe = printError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6325
            printError = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6328
        // check the type of error and handle it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6329
        if (pe != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6330
            // a subclass of PrinterException meaning the job was aborted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6331
            // in this case, by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6332
            if (pe instanceof PrinterAbortException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6333
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6334
            } else if (pe instanceof PrinterException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6335
                throw (PrinterException)pe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6336
            } else if (pe instanceof RuntimeException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6337
                throw (RuntimeException)pe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6338
            } else if (pe instanceof Error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6339
                throw (Error)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
            // can not happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6343
            throw new AssertionError(pe);
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 true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6349
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6350
     * Return a <code>Printable</code> for use in printing this JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6351
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6352
     * This method is meant for those wishing to customize the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6353
     * <code>Printable</code> implementation used by <code>JTable</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6354
     * <code>print</code> methods. Developers wanting simply to print the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6355
     * should use one of those methods directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6356
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6357
     * The <code>Printable</code> can be requested in one of two printing modes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6358
     * In both modes, it spreads table rows naturally in sequence across
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6359
     * multiple pages, fitting as many rows as possible per page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6360
     * <code>PrintMode.NORMAL</code> specifies that the table be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6361
     * printed at its current size. In this mode, there may be a need to spread
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6362
     * columns across pages in a similar manner to that of the rows. When the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6363
     * need arises, columns are distributed in an order consistent with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6364
     * table's <code>ComponentOrientation</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6365
     * <code>PrintMode.FIT_WIDTH</code> specifies that the output be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6366
     * scaled smaller, if necessary, to fit the table's entire width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6367
     * (and thereby all columns) on each page. Width and height are scaled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6368
     * equally, maintaining the aspect ratio of the output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6369
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6370
     * The <code>Printable</code> heads the portion of table on each page
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6371
     * with the appropriate section from the table's <code>JTableHeader</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6372
     * if it has one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6373
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6374
     * Header and footer text can be added to the output by providing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6375
     * <code>MessageFormat</code> arguments. The printing code requests
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6376
     * Strings from the formats, providing a single item which may be included
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6377
     * in the formatted string: an <code>Integer</code> representing the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6378
     * page number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6379
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6380
     * You are encouraged to read the documentation for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6381
     * <code>MessageFormat</code> as some characters, such as single-quote,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6382
     * are special and need to be escaped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6383
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6384
     * Here's an example of creating a <code>MessageFormat</code> that can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6385
     * used to print "Duke's Table: Page - " and the current page number:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6386
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6387
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6388
     *     // notice the escaping of the single quote
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6389
     *     // notice how the page number is included with "{0}"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6390
     *     MessageFormat format = new MessageFormat("Duke''s Table: Page - {0}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6391
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6392
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6393
     * The <code>Printable</code> constrains what it draws to the printable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6394
     * area of each page that it prints. Under certain circumstances, it may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6395
     * find it impossible to fit all of a page's content into that area. In
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6396
     * these cases the output may be clipped, but the implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6397
     * makes an effort to do something reasonable. Here are a few situations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6398
     * where this is known to occur, and how they may be handled by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6399
     * particular implementation:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6400
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6401
     *   <li>In any mode, when the header or footer text is too wide to fit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6402
     *       completely in the printable area -- print as much of the text as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6403
     *       possible starting from the beginning, as determined by the table's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6404
     *       <code>ComponentOrientation</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6405
     *   <li>In any mode, when a row is too tall to fit in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6406
     *       printable area -- print the upper-most portion of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6407
     *       and paint no lower border on the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6408
     *   <li>In <code>PrintMode.NORMAL</code> when a column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6409
     *       is too wide to fit in the printable area -- print the center
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6410
     *       portion of the column and leave the left and right borders
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6411
     *       off the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6412
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6413
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6414
     * It is entirely valid for this <code>Printable</code> to be wrapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6415
     * inside another in order to create complex reports and documents. You may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6416
     * even request that different pages be rendered into different sized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6417
     * printable areas. The implementation must be prepared to handle this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6418
     * (possibly by doing its layout calculations on the fly). However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6419
     * providing different heights to each page will likely not work well
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6420
     * with <code>PrintMode.NORMAL</code> when it has to spread columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6421
     * across pages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6422
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6423
     * As far as customizing how the table looks in the printed result,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6424
     * <code>JTable</code> itself will take care of hiding the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6425
     * and focus during printing. For additional customizations, your
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6426
     * renderers or painting code can customize the look based on the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6427
     * of {@link javax.swing.JComponent#isPaintingForPrint()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6428
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6429
     * Also, <i>before</i> calling this method you may wish to <i>first</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6430
     * modify the state of the table, such as to cancel cell editing or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6431
     * have the user size the table appropriately. However, you must not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6432
     * modify the state of the table <i>after</i> this <code>Printable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6433
     * has been fetched (invalid modifications include changes in size or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6434
     * underlying data). The behavior of the returned <code>Printable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6435
     * is undefined once the table has been changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6437
     * @param  printMode     the printing mode that the printable should use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6438
     * @param  headerFormat  a <code>MessageFormat</code> specifying the text to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6439
     *                       be used in printing a header, or null for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6440
     * @param  footerFormat  a <code>MessageFormat</code> specifying the text to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6441
     *                       be used in printing a footer, or null for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6442
     * @return a <code>Printable</code> for printing this JTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6443
     * @see #print(JTable.PrintMode, MessageFormat, MessageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6444
     *             boolean, PrintRequestAttributeSet, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6445
     * @see Printable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6446
     * @see PrinterJob
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6447
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6448
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6450
    public Printable getPrintable(PrintMode printMode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6451
                                  MessageFormat headerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6452
                                  MessageFormat footerFormat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6453
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6454
        return new TablePrintable(this, printMode, headerFormat, footerFormat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6456
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6458
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6459
     * A <code>Printable</code> implementation that wraps another
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6460
     * <code>Printable</code>, making it safe for printing on another thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6461
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6462
    private class ThreadSafePrintable implements Printable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6463
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6464
        /** The delegate <code>Printable</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6465
        private Printable printDelegate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6466
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6467
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6468
         * To communicate any return value when delegating.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6469
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6470
        private int retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6471
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6472
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6473
         * To communicate any <code>Throwable</code> when delegating.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6474
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6475
        private Throwable retThrowable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6476
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6477
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6478
         * Construct a <code>ThreadSafePrintable</code> around the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6479
         * delegate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6480
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6481
         * @param printDelegate the <code>Printable</code> to delegate to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6482
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6483
        public ThreadSafePrintable(Printable printDelegate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6484
            this.printDelegate = printDelegate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6485
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6486
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6487
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6488
         * Prints the specified page into the given {@link Graphics}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6489
         * context, in the specified format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6490
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6491
         * Regardless of what thread this method is called on, all calls into
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6492
         * the delegate will be done on the event-dispatch thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6493
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6494
         * @param   graphics    the context into which the page is drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6495
         * @param   pageFormat  the size and orientation of the page being drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6496
         * @param   pageIndex   the zero based index of the page to be drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6497
         * @return  PAGE_EXISTS if the page is rendered successfully, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6498
         *          NO_SUCH_PAGE if a non-existent page index is specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6499
         * @throws  PrinterException if an error causes printing to be aborted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6500
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6501
        public int print(final Graphics graphics,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6502
                         final PageFormat pageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6503
                         final int pageIndex) throws PrinterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6504
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6505
            // We'll use this Runnable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6506
            Runnable runnable = new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6507
                public synchronized void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6508
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6509
                        // call into the delegate and save the return value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6510
                        retVal = printDelegate.print(graphics, pageFormat, pageIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6511
                    } catch (Throwable throwable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6512
                        // save any Throwable to be rethrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6513
                        retThrowable = throwable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6514
                    } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6515
                        // notify the caller that we're done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6516
                        notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6517
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6518
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6519
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6520
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6521
            synchronized(runnable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6522
                // make sure these are initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6523
                retVal = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6524
                retThrowable = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6525
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6526
                // call into the EDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6527
                SwingUtilities.invokeLater(runnable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6528
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6529
                // wait for the runnable to finish
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6530
                while (retVal == -1 && retThrowable == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6531
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6532
                        runnable.wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6533
                    } catch (InterruptedException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6534
                        // short process, safe to ignore interrupts
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6535
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6536
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6537
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6538
                // if the delegate threw a throwable, rethrow it here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6539
                if (retThrowable != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6540
                    if (retThrowable instanceof PrinterException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6541
                        throw (PrinterException)retThrowable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6542
                    } else if (retThrowable instanceof RuntimeException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6543
                        throw (RuntimeException)retThrowable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6544
                    } else if (retThrowable instanceof Error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6545
                        throw (Error)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
                    // can not happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6549
                    throw new AssertionError(retThrowable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6550
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6551
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6552
                return retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6553
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6554
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6555
    }
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
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6560
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6561
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6562
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6563
     * Gets the AccessibleContext associated with this JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6564
     * For tables, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6565
     * AccessibleJTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6566
     * A new AccessibleJTable instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6567
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6568
     * @return an AccessibleJTable that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6569
     *         AccessibleContext of this JTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6570
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6571
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6572
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6573
            accessibleContext = new AccessibleJTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6574
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6575
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6577
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6578
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6579
    // *** should also implement AccessibleSelection?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6580
    // *** and what's up with keyboard navigation/manipulation?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6581
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6582
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6583
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6584
     * <code>JTable</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6585
     * Java Accessibility API appropriate to table user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6586
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6587
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6588
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6589
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6590
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6591
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6592
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6593
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6594
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6595
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6596
    protected class AccessibleJTable extends AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6597
    implements AccessibleSelection, ListSelectionListener, TableModelListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6598
    TableColumnModelListener, CellEditorListener, PropertyChangeListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6599
    AccessibleExtendedTable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6600
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6601
        int lastSelectedRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6602
        int lastSelectedCol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6604
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6605
         * AccessibleJTable constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6606
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6607
         * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6608
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6609
        protected AccessibleJTable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6610
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6611
            JTable.this.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6612
            JTable.this.getSelectionModel().addListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6613
            TableColumnModel tcm = JTable.this.getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6614
            tcm.addColumnModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6615
            tcm.getSelectionModel().addListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6616
            JTable.this.getModel().addTableModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6617
            lastSelectedRow = JTable.this.getSelectedRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6618
            lastSelectedCol = JTable.this.getSelectedColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6620
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6621
    // Listeners to track model, etc. changes to as to re-place the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6622
    // listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6623
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6624
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6625
         * Track changes to selection model, column model, etc. so as to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6626
         * be able to re-place listeners on those in order to pass on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6627
         * information to the Accessibility PropertyChange mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6628
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6629
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6630
            String name = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6631
            Object oldValue = e.getOldValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6632
            Object newValue = e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6633
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6634
                // re-set tableModel listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6635
            if (name.compareTo("model") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6636
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6637
                if (oldValue != null && oldValue instanceof TableModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6638
                    ((TableModel) oldValue).removeTableModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6639
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6640
                if (newValue != null && newValue instanceof TableModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6641
                    ((TableModel) newValue).addTableModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6642
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6643
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6644
                // re-set selectionModel listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6645
            } else if (name.compareTo("selectionModel") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6646
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6647
                Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6648
                if (source == JTable.this) {    // row selection model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6649
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6650
                    if (oldValue != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6651
                        oldValue instanceof ListSelectionModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6652
                        ((ListSelectionModel) oldValue).removeListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6653
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6654
                    if (newValue != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6655
                        newValue instanceof ListSelectionModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6656
                        ((ListSelectionModel) newValue).addListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6657
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6658
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6659
                } else if (source == JTable.this.getColumnModel()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6660
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6661
                    if (oldValue != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6662
                        oldValue instanceof ListSelectionModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6663
                        ((ListSelectionModel) oldValue).removeListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6664
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6665
                    if (newValue != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6666
                        newValue instanceof ListSelectionModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6667
                        ((ListSelectionModel) newValue).addListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6668
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6670
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6671
                  //        System.out.println("!!! Bug in source of selectionModel propertyChangeEvent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6672
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6674
                // re-set columnModel listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6675
                // and column's selection property listener as well
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6676
            } else if (name.compareTo("columnModel") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6677
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6678
                if (oldValue != null && oldValue instanceof TableColumnModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6679
                    TableColumnModel tcm = (TableColumnModel) oldValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6680
                    tcm.removeColumnModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6681
                    tcm.getSelectionModel().removeListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6682
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6683
                if (newValue != null && newValue instanceof TableColumnModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6684
                    TableColumnModel tcm = (TableColumnModel) newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6685
                    tcm.addColumnModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6686
                    tcm.getSelectionModel().addListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6687
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6688
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6689
                // re-se cellEditor listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6690
            } else if (name.compareTo("tableCellEditor") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6691
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6692
                if (oldValue != null && oldValue instanceof TableCellEditor) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  6693
                    ((TableCellEditor) oldValue).removeCellEditorListener(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6694
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6695
                if (newValue != null && newValue instanceof TableCellEditor) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  6696
                    ((TableCellEditor) newValue).addCellEditorListener(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6697
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6698
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6699
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6700
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6701
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6702
    // Listeners to echo changes to the AccessiblePropertyChange mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6703
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6704
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6705
         * Describes a change in the accessible table model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6706
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6707
        protected class AccessibleJTableModelChange
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6708
            implements AccessibleTableModelChange {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6709
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6710
            protected int type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6711
            protected int firstRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6712
            protected int lastRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6713
            protected int firstColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6714
            protected int lastColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6715
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6716
            protected AccessibleJTableModelChange(int type, int firstRow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6717
                                                  int lastRow, int firstColumn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6718
                                                  int lastColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6719
                this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6720
                this.firstRow = firstRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6721
                this.lastRow = lastRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6722
                this.firstColumn = firstColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6723
                this.lastColumn = lastColumn;
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 getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6727
                return type;
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 getFirstRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6731
                return firstRow;
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 getLastRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6735
                return lastRow;
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 getFirstColumn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6739
                return firstColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6740
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6741
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6742
            public int getLastColumn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6743
                return lastColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6744
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6745
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6746
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6747
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6748
         * Track changes to the table contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6749
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6750
        public void tableChanged(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6751
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6752
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6753
           if (e != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6754
               int firstColumn = e.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6755
               int lastColumn = e.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6756
               if (firstColumn == TableModelEvent.ALL_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6757
                   firstColumn = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6758
                   lastColumn = getColumnCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6759
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6760
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6761
               // Fire a property change event indicating the table model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6762
               // has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6763
               AccessibleJTableModelChange change =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6764
                   new AccessibleJTableModelChange(e.getType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6765
                                                   e.getFirstRow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6766
                                                   e.getLastRow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6767
                                                   firstColumn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6768
                                                   lastColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6769
               firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_MODEL_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6770
                                  null, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6771
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6773
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6774
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6775
         * Track changes to the table contents (row insertions)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6776
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6777
        public void tableRowsInserted(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6778
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6779
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6780
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6781
           // Fire a property change event indicating the table model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6782
           // has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6783
           int firstColumn = e.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6784
           int lastColumn = e.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6785
           if (firstColumn == TableModelEvent.ALL_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6786
               firstColumn = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6787
               lastColumn = getColumnCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6788
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6789
           AccessibleJTableModelChange change =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6790
               new AccessibleJTableModelChange(e.getType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6791
                                               e.getFirstRow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6792
                                               e.getLastRow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6793
                                               firstColumn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6794
                                               lastColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6795
           firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_MODEL_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6796
                              null, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6797
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6798
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6799
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6800
         * Track changes to the table contents (row deletions)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6801
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6802
        public void tableRowsDeleted(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6803
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6804
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6805
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6806
           // Fire a property change event indicating the table model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6807
           // has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6808
           int firstColumn = e.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6809
           int lastColumn = e.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6810
           if (firstColumn == TableModelEvent.ALL_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6811
               firstColumn = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6812
               lastColumn = getColumnCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6813
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6814
           AccessibleJTableModelChange change =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6815
               new AccessibleJTableModelChange(e.getType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6816
                                               e.getFirstRow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6817
                                               e.getLastRow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6818
                                               firstColumn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6819
                                               lastColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6820
           firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_MODEL_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6821
                              null, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6822
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6823
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6824
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6825
         * Track changes to the table contents (column insertions)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6826
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6827
        public void columnAdded(TableColumnModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6828
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6829
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6830
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6831
           // Fire a property change event indicating the table model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6832
           // has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6833
           int type = AccessibleTableModelChange.INSERT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6834
           AccessibleJTableModelChange change =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6835
               new AccessibleJTableModelChange(type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6836
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6837
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6838
                                               e.getFromIndex(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6839
                                               e.getToIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6840
           firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_MODEL_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6841
                              null, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6842
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6843
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6844
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6845
         * Track changes to the table contents (column deletions)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6846
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6847
        public void columnRemoved(TableColumnModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6848
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6849
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6850
           // Fire a property change event indicating the table model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6851
           // has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6852
           int type = AccessibleTableModelChange.DELETE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6853
           AccessibleJTableModelChange change =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6854
               new AccessibleJTableModelChange(type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6855
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6856
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6857
                                               e.getFromIndex(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6858
                                               e.getToIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6859
           firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_MODEL_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6860
                              null, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6861
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6862
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6863
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6864
         * Track changes of a column repositioning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6865
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6866
         * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6867
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6868
        public void columnMoved(TableColumnModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6869
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6870
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6871
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6872
           // Fire property change events indicating the table model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6873
           // has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6874
           int type = AccessibleTableModelChange.DELETE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6875
           AccessibleJTableModelChange change =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6876
               new AccessibleJTableModelChange(type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6877
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6878
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6879
                                               e.getFromIndex(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6880
                                               e.getFromIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6881
           firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_MODEL_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6882
                              null, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6883
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6884
           int type2 = AccessibleTableModelChange.INSERT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6885
           AccessibleJTableModelChange change2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6886
               new AccessibleJTableModelChange(type2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6887
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6888
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6889
                                               e.getToIndex(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6890
                                               e.getToIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6891
           firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_MODEL_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6892
                              null, change2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6893
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6894
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6895
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6896
         * Track changes of a column moving due to margin changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6897
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6898
         * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6899
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6900
        public void columnMarginChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6901
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6902
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6903
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6904
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6905
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6906
         * Track that the selection model of the TableColumnModel changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6907
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6908
         * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6909
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6910
        public void columnSelectionChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6911
            // we should now re-place our TableColumn listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6912
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6913
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6914
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6915
         * Track changes to a cell's contents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6916
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6917
         * Invoked when editing is finished. The changes are saved, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6918
         * editor object is discarded, and the cell is rendered once again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6919
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6920
         * @see CellEditorListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6921
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6922
        public void editingStopped(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6923
           // it'd be great if we could figure out which cell, and pass that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6924
           // somehow as a parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6925
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6926
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6927
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6928
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6929
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6930
         * Invoked when editing is canceled. The editor object is discarded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6931
         * and the cell is rendered once again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6932
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6933
         * @see CellEditorListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6934
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6935
        public void editingCanceled(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6936
            // nothing to report, 'cause nothing changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6937
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6938
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6939
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6940
         * Track changes to table cell selections
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6941
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6942
        public void valueChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6943
            firePropertyChange(AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6944
                               Boolean.valueOf(false), Boolean.valueOf(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6945
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6946
            int selectedRow = JTable.this.getSelectedRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6947
            int selectedCol = JTable.this.getSelectedColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6948
            if (selectedRow != lastSelectedRow ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6949
                selectedCol != lastSelectedCol) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6950
                Accessible oldA = getAccessibleAt(lastSelectedRow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6951
                                                  lastSelectedCol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6952
                Accessible newA = getAccessibleAt(selectedRow, selectedCol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6953
                firePropertyChange(AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6954
                                   oldA, newA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6955
                 lastSelectedRow = selectedRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6956
                 lastSelectedCol = selectedCol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6957
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6958
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6959
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6960
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6961
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6962
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6963
    // AccessibleContext support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6964
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6965
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6966
         * Get the AccessibleSelection associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6967
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6968
         * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6969
         * AccessibleSelection interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6970
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6971
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6972
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6973
        public AccessibleSelection getAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6974
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6975
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6976
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6977
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6978
         * Gets the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6979
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6980
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6981
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6982
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6983
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6984
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6985
            return AccessibleRole.TABLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6986
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6987
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6988
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6989
         * Returns the <code>Accessible</code> child, if one exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6990
         * contained at the local coordinate <code>Point</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6991
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6992
         * @param p the point defining the top-left corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6993
         *    <code>Accessible</code>, given in the coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6994
         *    of the object's parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6995
         * @return the <code>Accessible</code>, if it exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6996
         *    at the specified location; else <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6997
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6998
        public Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6999
            int column = columnAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7000
            int row = rowAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7001
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7002
            if ((column != -1) && (row != -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7003
                TableColumn aColumn = getColumnModel().getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7004
                TableCellRenderer renderer = aColumn.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7005
                if (renderer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7006
                    Class<?> columnClass = getColumnClass(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7007
                    renderer = getDefaultRenderer(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7008
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7009
                Component component = renderer.getTableCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7010
                                  JTable.this, null, false, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7011
                                  row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7012
                return new AccessibleJTableCell(JTable.this, row, column,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7013
                      getAccessibleIndexAt(row, column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7014
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7015
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7016
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7018
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7019
         * Returns the number of accessible children in the object.  If all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7020
         * of the children of this object implement <code>Accessible</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7021
         * then this method should return the number of children of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7022
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7023
         * @return the number of accessible children in the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7024
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7025
        public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7026
            return (JTable.this.getColumnCount() * JTable.this.getRowCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7027
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7029
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7030
         * Returns the nth <code>Accessible</code> child of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7031
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7032
         * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7033
         * @return the nth Accessible child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7034
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7035
        public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7036
            if (i < 0 || i >= getAccessibleChildrenCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7037
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7038
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7039
                // children increase across, and then down, for tables
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7040
                // (arbitrary decision)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7041
                int column = getAccessibleColumnAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7042
                int row = getAccessibleRowAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7044
                TableColumn aColumn = getColumnModel().getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7045
                TableCellRenderer renderer = aColumn.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7046
                if (renderer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7047
                    Class<?> columnClass = getColumnClass(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7048
                    renderer = getDefaultRenderer(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7049
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7050
                Component component = renderer.getTableCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7051
                                  JTable.this, null, false, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7052
                                  row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7053
                return new AccessibleJTableCell(JTable.this, row, column,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7054
                      getAccessibleIndexAt(row, column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7055
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7056
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7058
    // AccessibleSelection support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7060
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7061
         * Returns the number of <code>Accessible</code> children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7062
         * currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7063
         * If no children are selected, the return value will be 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7064
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7065
         * @return the number of items currently selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7066
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7067
        public int getAccessibleSelectionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7068
            int rowsSel = JTable.this.getSelectedRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7069
            int colsSel = JTable.this.getSelectedColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7071
            if (JTable.this.cellSelectionEnabled) { // a contiguous block
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7072
                return rowsSel * colsSel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7074
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7075
                // a column swath and a row swath, with a shared block
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7076
                if (JTable.this.getRowSelectionAllowed() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7077
                    JTable.this.getColumnSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7078
                    return rowsSel * JTable.this.getColumnCount() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7079
                           colsSel * JTable.this.getRowCount() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7080
                           rowsSel * colsSel;
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.getRowSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7084
                    return rowsSel * JTable.this.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7086
                // just one or more rows in selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7087
                } else if (JTable.this.getColumnSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7088
                    return colsSel * JTable.this.getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7090
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7091
                    return 0;    // JTable doesn't allow selections
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7092
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7093
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7094
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7096
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7097
         * Returns an <code>Accessible</code> representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7098
         * specified selected child in the object.  If there
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7099
         * isn't a selection, or there are fewer children selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7100
         * than the integer passed in, the return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7101
         * value will be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7102
         * <p>Note that the index represents the i-th selected child, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7103
         * is different from the i-th child.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7104
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7105
         * @param i the zero-based index of selected children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7106
         * @return the i-th selected child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7107
         * @see #getAccessibleSelectionCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7108
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7109
        public Accessible getAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7110
            if (i < 0 || i > getAccessibleSelectionCount()) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  7111
                return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7112
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7114
            int rowsSel = JTable.this.getSelectedRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7115
            int colsSel = JTable.this.getSelectedColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7116
            int rowIndicies[] = getSelectedRows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7117
            int colIndicies[] = getSelectedColumns();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7118
            int ttlCols = JTable.this.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7119
            int ttlRows = JTable.this.getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7120
            int r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7121
            int c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7123
            if (JTable.this.cellSelectionEnabled) { // a contiguous block
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7124
                r = rowIndicies[i / colsSel];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7125
                c = colIndicies[i % colsSel];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7126
                return getAccessibleChild((r * ttlCols) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7127
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7129
                // a column swath and a row swath, with a shared block
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7130
                if (JTable.this.getRowSelectionAllowed() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7131
                    JTable.this.getColumnSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7133
                    // Situation:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7134
                    //   We have a table, like the 6x3 table below,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7135
                    //   wherein three colums and one row selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7136
                    //   (selected cells marked with "*", unselected "0"):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7137
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7138
                    //            0 * 0 * * 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7139
                    //            * * * * * *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7140
                    //            0 * 0 * * 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7141
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7143
                    // State machine below walks through the array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7144
                    // selected rows in two states: in a selected row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7145
                    // and not in one; continuing until we are in a row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7146
                    // in which the ith selection exists.  Then we return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7147
                    // the appropriate cell.  In the state machine, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7148
                    // always do rows above the "current" selected row first,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7149
                    // then the cells in the selected row.  If we're done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7150
                    // with the state machine before finding the requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7151
                    // selected child, we handle the rows below the last
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7152
                    // selected row at the end.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7153
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7154
                    int curIndex = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7155
                    final int IN_ROW = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7156
                    final int NOT_IN_ROW = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7157
                    int state = (rowIndicies[0] == 0 ? IN_ROW : NOT_IN_ROW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7158
                    int j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7159
                    int prevRow = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7160
                    while (j < rowIndicies.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7161
                        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7163
                        case IN_ROW:   // on individual row full of selections
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7164
                            if (curIndex < ttlCols) { // it's here!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7165
                                c = curIndex % ttlCols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7166
                                r = rowIndicies[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7167
                                return getAccessibleChild((r * ttlCols) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7168
                            } else {                               // not here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7169
                                curIndex -= ttlCols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7170
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7171
                            // is the next row in table selected or not?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7172
                            if (j + 1 == rowIndicies.length ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7173
                                rowIndicies[j] != rowIndicies[j+1] - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7174
                                state = NOT_IN_ROW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7175
                                prevRow = rowIndicies[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7176
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7177
                            j++;  // we didn't return earlier, so go to next row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7178
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7180
                        case NOT_IN_ROW:  // sparse bunch of rows of selections
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7181
                            if (curIndex <
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7182
                                (colsSel * (rowIndicies[j] -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7183
                                (prevRow == -1 ? 0 : (prevRow + 1))))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7185
                                // it's here!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7186
                                c = colIndicies[curIndex % colsSel];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7187
                                r = (j > 0 ? rowIndicies[j-1] + 1 : 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7188
                                    + curIndex / colsSel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7189
                                return getAccessibleChild((r * ttlCols) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7190
                            } else {                               // not here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7191
                                curIndex -= colsSel * (rowIndicies[j] -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7192
                                (prevRow == -1 ? 0 : (prevRow + 1)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7193
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7194
                            state = IN_ROW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7195
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7196
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7197
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7198
                    // we got here, so we didn't find it yet; find it in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7199
                    // the last sparse bunch of rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7200
                    if (curIndex <
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7201
                        (colsSel * (ttlRows -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7202
                        (prevRow == -1 ? 0 : (prevRow + 1))))) { // it's here!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7203
                        c = colIndicies[curIndex % colsSel];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7204
                        r = rowIndicies[j-1] + curIndex / colsSel + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7205
                        return getAccessibleChild((r * ttlCols) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7206
                    } else {                               // not here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7207
                        // we shouldn't get to this spot in the code!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7208
//                      System.out.println("Bug in AccessibleJTable.getAccessibleSelection()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7209
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7211
                // one or more rows selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7212
                } else if (JTable.this.getRowSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7213
                    c = i % ttlCols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7214
                    r = rowIndicies[i / ttlCols];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7215
                    return getAccessibleChild((r * ttlCols) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7217
                // one or more columns selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7218
                } else if (JTable.this.getColumnSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7219
                    c = colIndicies[i % colsSel];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7220
                    r = i / colsSel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7221
                    return getAccessibleChild((r * ttlCols) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7222
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7223
            }
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  7224
            return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7227
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7228
         * Determines if the current child of this object is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7229
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7230
         * @param i the zero-based index of the child in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7231
         *    <code>Accessible</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7232
         * @return true if the current child of this object is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7233
         * @see AccessibleContext#getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7234
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7235
        public boolean isAccessibleChildSelected(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7236
            int column = getAccessibleColumnAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7237
            int row = getAccessibleRowAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7238
            return JTable.this.isCellSelected(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7241
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7242
         * Adds the specified <code>Accessible</code> child of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7243
         * object to the object's selection.  If the object supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7244
         * multiple selections, the specified child is added to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7245
         * any existing selection, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7246
         * it replaces any existing selection in the object.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7247
         * specified child is already selected, this method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7248
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7249
         * This method only works on <code>JTable</code>s which have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7250
         * individual cell selection enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7251
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7252
         * @param i the zero-based index of the child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7253
         * @see AccessibleContext#getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7254
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7255
        public void addAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7256
            // TIGER - 4495286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7257
            int column = getAccessibleColumnAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7258
            int row = getAccessibleRowAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7259
            JTable.this.changeSelection(row, column, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7262
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7263
         * Removes the specified child of the object from the object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7264
         * selection.  If the specified item isn't currently selected, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7265
         * method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7266
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7267
         * This method only works on <code>JTables</code> which have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7268
         * individual cell selection enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7269
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7270
         * @param i the zero-based index of the child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7271
         * @see AccessibleContext#getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7272
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7273
        public void removeAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7274
            if (JTable.this.cellSelectionEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7275
                int column = getAccessibleColumnAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7276
                int row = getAccessibleRowAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7277
                JTable.this.removeRowSelectionInterval(row, row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7278
                JTable.this.removeColumnSelectionInterval(column, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7279
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7282
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7283
         * Clears the selection in the object, so that no children in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7284
         * object are selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7285
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7286
        public void clearAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7287
            JTable.this.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7290
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7291
         * Causes every child of the object to be selected, but only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7292
         * if the <code>JTable</code> supports multiple selections,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7293
         * and if individual cell selection is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7294
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7295
        public void selectAllAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7296
            if (JTable.this.cellSelectionEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7297
                JTable.this.selectAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7298
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7300
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7301
        // begin AccessibleExtendedTable implementation -------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7303
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7304
         * Returns the row number of an index in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7305
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7306
         * @param index the zero-based index in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7307
         * @return the zero-based row of the table if one exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7308
         * otherwise -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7309
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7310
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7311
        public int getAccessibleRow(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7312
            return getAccessibleRowAtIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7315
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7316
         * Returns the column number of an index in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7317
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7318
         * @param index the zero-based index in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7319
         * @return the zero-based column of the table if one exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7320
         * otherwise -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7321
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7322
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7323
        public int getAccessibleColumn(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7324
            return getAccessibleColumnAtIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7327
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7328
         * Returns the index at a row and column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7329
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7330
         * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7331
         * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7332
         * @return the zero-based index in the table if one exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7333
         * otherwise -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7334
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7335
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7336
        public int getAccessibleIndex(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7337
            return getAccessibleIndexAt(r, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7339
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7340
        // end of AccessibleExtendedTable implementation ------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7341
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7342
        // start of AccessibleTable implementation ------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7344
        private Accessible caption;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7345
        private Accessible summary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7346
        private Accessible [] rowDescription;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7347
        private Accessible [] columnDescription;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7349
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7350
         * Gets the <code>AccessibleTable</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7351
         * object.  In the implementation of the Java Accessibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7352
         * API for this class, return this object, which is responsible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7353
         * for implementing the <code>AccessibleTables</code> interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7354
         * on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7355
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7356
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7357
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7358
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7359
        public AccessibleTable getAccessibleTable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7360
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7363
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7364
         * Returns the caption for the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7365
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7366
         * @return the caption for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7367
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7368
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7369
        public Accessible getAccessibleCaption() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7370
            return this.caption;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7373
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7374
         * Sets the caption for the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7375
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7376
         * @param a the caption for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7377
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7378
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7379
        public void setAccessibleCaption(Accessible a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7380
            Accessible oldCaption = caption;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7381
            this.caption = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7382
            firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_CAPTION_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7383
                               oldCaption, this.caption);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7385
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7386
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7387
         * Returns the summary description of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7388
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7389
         * @return the summary description of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7390
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7391
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7392
        public Accessible getAccessibleSummary() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7393
            return this.summary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7396
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7397
         * Sets the summary description of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7398
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7399
         * @param a the summary description of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7400
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7401
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7402
        public void setAccessibleSummary(Accessible a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7403
            Accessible oldSummary = summary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7404
            this.summary = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7405
            firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_SUMMARY_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7406
                               oldSummary, this.summary);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7408
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7409
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7410
         * Returns the total number of rows in this table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7411
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7412
         * @return the total number of rows in this table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7413
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7414
        public int getAccessibleRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7415
            return JTable.this.getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7417
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7418
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7419
         * Returns the total number of columns in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7420
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7421
         * @return the total number of columns in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7422
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7423
        public int getAccessibleColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7424
            return JTable.this.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7425
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7426
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7427
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7428
         * Returns the <code>Accessible</code> at a specified row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7429
         * and column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7430
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7431
         * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7432
         * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7433
         * @return the <code>Accessible</code> at the specified row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7434
         * in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7435
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7436
        public Accessible getAccessibleAt(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7437
            return getAccessibleChild((r * getAccessibleColumnCount()) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7439
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7440
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7441
         * Returns the number of rows occupied by the <code>Accessible</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7442
         * at a specified row and column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7443
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7444
         * @return the number of rows occupied by the <code>Accessible</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7445
         *     at a specified row and column in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7446
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7447
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7448
        public int getAccessibleRowExtentAt(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7449
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7451
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7452
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7453
         * Returns the number of columns occupied by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7454
         * <code>Accessible</code> at a given (row, column).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7455
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7456
         * @return the number of columns occupied by the <code>Accessible</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7457
         *     at a specified row and column in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7458
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7459
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7460
        public int getAccessibleColumnExtentAt(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7461
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7463
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7464
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7465
         * Returns the row headers as an <code>AccessibleTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7466
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7467
         * @return an <code>AccessibleTable</code> representing the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7468
         * headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7469
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7470
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7471
        public AccessibleTable getAccessibleRowHeader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7472
            // row headers are not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7473
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7475
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7476
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7477
         * Sets the row headers as an <code>AccessibleTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7478
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7479
         * @param a an <code>AccessibleTable</code> representing the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7480
         *  headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7481
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7482
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7483
        public void setAccessibleRowHeader(AccessibleTable a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7484
            // row headers are not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7485
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7486
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7487
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7488
         * Returns the column headers as an <code>AccessibleTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7489
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7490
         *  @return an <code>AccessibleTable</code> representing the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7491
         *          headers, or <code>null</code> if the table header is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7492
         *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7493
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7494
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7495
        public AccessibleTable getAccessibleColumnHeader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7496
            JTableHeader header = JTable.this.getTableHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7497
            return header == null ? null : new AccessibleTableHeader(header);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7499
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7500
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7501
         * Private class representing a table column header
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7502
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7503
        private class AccessibleTableHeader implements AccessibleTable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7504
            private JTableHeader header;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7505
            private TableColumnModel headerModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7506
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7507
            AccessibleTableHeader(JTableHeader header) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7508
                this.header = header;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7509
                this.headerModel = header.getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7510
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7511
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7512
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7513
             * Returns the caption for the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7514
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7515
             * @return the caption for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7516
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7517
            public Accessible getAccessibleCaption() { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7519
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7520
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7521
             * Sets the caption for the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7522
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7523
             * @param a the caption for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7524
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7525
            public void setAccessibleCaption(Accessible a) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7526
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7527
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7528
             * Returns the summary description of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7529
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7530
             * @return the summary description of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7531
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7532
            public Accessible getAccessibleSummary() { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7533
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7534
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7535
             * Sets the summary description of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7536
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7537
             * @param a the summary description of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7538
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7539
            public void setAccessibleSummary(Accessible a) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7541
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7542
             * Returns the number of rows in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7543
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7544
             * @return the number of rows in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7545
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7546
            public int getAccessibleRowCount() { return 1; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7547
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7548
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7549
             * Returns the number of columns in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7550
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7551
             * @return the number of columns in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7552
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7553
            public int getAccessibleColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7554
                return headerModel.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7555
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7556
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7557
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7558
             * Returns the Accessible at a specified row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7559
             * in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7560
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7561
             * @param row zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7562
             * @param column zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7563
             * @return the Accessible at the specified row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7564
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7565
            public Accessible getAccessibleAt(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7566
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7567
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7568
                // TIGER - 4715503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7569
                TableColumn aColumn = headerModel.getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7570
                TableCellRenderer renderer = aColumn.getHeaderRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7571
                if (renderer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7572
                    renderer = header.getDefaultRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7573
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7574
                Component component = renderer.getTableCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7575
                                  header.getTable(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7576
                                  aColumn.getHeaderValue(), false, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7577
                                  -1, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7578
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7579
                return new AccessibleJTableHeaderCell(row, column,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7580
                                                      JTable.this.getTableHeader(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7581
                                                      component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7582
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7583
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7584
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7585
             * Returns the number of rows occupied by the Accessible at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7586
             * a specified row and column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7587
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7588
             * @return the number of rows occupied by the Accessible at a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7589
             * given specified (row, column)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7590
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7591
            public int getAccessibleRowExtentAt(int r, int c) { return 1; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7592
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7593
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7594
             * Returns the number of columns occupied by the Accessible at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7595
             * a specified row and column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7596
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7597
             * @return the number of columns occupied by the Accessible at a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7598
             * given specified row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7599
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7600
            public int getAccessibleColumnExtentAt(int r, int c) { return 1; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7601
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7602
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7603
             * Returns the row headers as an AccessibleTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7604
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7605
             * @return an AccessibleTable representing the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7606
             * headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7607
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7608
            public AccessibleTable getAccessibleRowHeader() { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7609
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7610
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7611
             * Sets the row headers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7612
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7613
             * @param table an AccessibleTable representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7614
             * row headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7615
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7616
            public void setAccessibleRowHeader(AccessibleTable table) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7617
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7618
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7619
             * Returns the column headers as an AccessibleTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7620
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7621
             * @return an AccessibleTable representing the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7622
             * headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7623
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7624
            public AccessibleTable getAccessibleColumnHeader() { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7625
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7626
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7627
             * Sets the column headers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7628
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7629
             * @param table an AccessibleTable representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7630
             * column headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7631
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7632
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7633
            public void setAccessibleColumnHeader(AccessibleTable table) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7635
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7636
             * Returns the description of the specified row in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7637
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7638
             * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7639
             * @return the description of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7640
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7641
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7642
            public Accessible getAccessibleRowDescription(int r) { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7643
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7644
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7645
             * Sets the description text of the specified row of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7646
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7647
             * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7648
             * @param a the description of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7649
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7650
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7651
            public void setAccessibleRowDescription(int r, Accessible a) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7652
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7653
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7654
             * Returns the description text of the specified column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7655
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7656
             * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7657
             * @return the text description of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7658
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7659
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7660
            public Accessible getAccessibleColumnDescription(int c) { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7661
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7662
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7663
             * Sets the description text of the specified column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7664
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7665
             * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7666
             * @param a the text description of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7667
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7668
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7669
            public void setAccessibleColumnDescription(int c, Accessible a) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7670
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7671
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7672
             * Returns a boolean value indicating whether the accessible at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7673
             * a specified row and column is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7674
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7675
             * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7676
             * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7677
             * @return the boolean value true if the accessible at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7678
             * row and column is selected. Otherwise, the boolean value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7679
             * false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7680
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7681
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7682
            public boolean isAccessibleSelected(int r, int c) { return false; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7683
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7684
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7685
             * Returns a boolean value indicating whether the specified row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7686
             * is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7687
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7688
             * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7689
             * @return the boolean value true if the specified row is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7690
             * Otherwise, false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7691
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7692
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7693
            public boolean isAccessibleRowSelected(int r) { return false; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7694
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7695
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7696
             * Returns a boolean value indicating whether the specified column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7697
             * is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7698
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7699
             * @param r zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7700
             * @return the boolean value true if the specified column is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7701
             * Otherwise, false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7702
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7703
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7704
            public boolean isAccessibleColumnSelected(int c) { return false; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7705
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7706
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7707
             * Returns the selected rows in a table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7708
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7709
             * @return an array of selected rows where each element is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7710
             * zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7711
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7712
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7713
            public int [] getSelectedAccessibleRows() { return new int[0]; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7714
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7715
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7716
             * Returns the selected columns in a table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7717
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7718
             * @return an array of selected columns where each element is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7719
             * zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7720
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7721
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7722
            public int [] getSelectedAccessibleColumns() { return new int[0]; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7723
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7724
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7725
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7726
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7727
         * Sets the column headers as an <code>AccessibleTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7728
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7729
         * @param a an <code>AccessibleTable</code> representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7730
         * column headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7731
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7732
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7733
        public void setAccessibleColumnHeader(AccessibleTable a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7734
            // XXX not implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7735
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7736
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7737
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7738
         * Returns the description of the specified row in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7739
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7740
         * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7741
         * @return the description of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7742
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7743
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7744
        public Accessible getAccessibleRowDescription(int r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7745
            if (r < 0 || r >= getAccessibleRowCount()) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  7746
                throw new IllegalArgumentException(Integer.toString(r));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7747
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7748
            if (rowDescription == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7749
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7750
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7751
                return rowDescription[r];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7752
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7753
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7754
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7755
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7756
         * Sets the description text of the specified row of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7757
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7758
         * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7759
         * @param a the description of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7760
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7761
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7762
        public void setAccessibleRowDescription(int r, Accessible a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7763
            if (r < 0 || r >= getAccessibleRowCount()) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  7764
                throw new IllegalArgumentException(Integer.toString(r));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7765
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7766
            if (rowDescription == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7767
                int numRows = getAccessibleRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7768
                rowDescription = new Accessible[numRows];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7769
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7770
            rowDescription[r] = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7771
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7772
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7773
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7774
         * Returns the description of the specified column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7775
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7776
         * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7777
         * @return the description of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7778
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7779
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7780
        public Accessible getAccessibleColumnDescription(int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7781
            if (c < 0 || c >= getAccessibleColumnCount()) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  7782
                throw new IllegalArgumentException(Integer.toString(c));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7783
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7784
            if (columnDescription == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7785
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7786
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7787
                return columnDescription[c];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7788
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7790
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7791
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7792
         * Sets the description text of the specified column of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7793
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7794
         * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7795
         * @param a the description of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7796
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7797
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7798
        public void setAccessibleColumnDescription(int c, Accessible a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7799
            if (c < 0 || c >= getAccessibleColumnCount()) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  7800
                throw new IllegalArgumentException(Integer.toString(c));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7801
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7802
            if (columnDescription == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7803
                int numColumns = getAccessibleColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7804
                columnDescription = new Accessible[numColumns];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7805
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7806
            columnDescription[c] = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7807
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7808
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7809
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7810
         * Returns a boolean value indicating whether the accessible at a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7811
         * given (row, column) is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7812
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7813
         * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7814
         * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7815
         * @return the boolean value true if the accessible at (row, column)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7816
         *     is selected; otherwise, the boolean value false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7817
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7818
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7819
        public boolean isAccessibleSelected(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7820
            return JTable.this.isCellSelected(r, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7821
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7822
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7823
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7824
         * Returns a boolean value indicating whether the specified row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7825
         * is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7826
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7827
         * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7828
         * @return the boolean value true if the specified row is selected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7829
         *     otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7830
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7831
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7832
        public boolean isAccessibleRowSelected(int r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7833
            return JTable.this.isRowSelected(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7834
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7835
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7836
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7837
         * Returns a boolean value indicating whether the specified column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7838
         * is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7839
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7840
         * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7841
         * @return the boolean value true if the specified column is selected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7842
         *     otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7843
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7844
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7845
        public boolean isAccessibleColumnSelected(int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7846
            return JTable.this.isColumnSelected(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7847
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7848
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7849
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7850
         * Returns the selected rows in a table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7851
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7852
         * @return an array of selected rows where each element is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7853
         *     zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7854
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7855
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7856
        public int [] getSelectedAccessibleRows() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7857
            return JTable.this.getSelectedRows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7858
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7859
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7860
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7861
         * Returns the selected columns in a table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7862
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7863
         * @return an array of selected columns where each element is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7864
         *     zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7865
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7866
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7867
        public int [] getSelectedAccessibleColumns() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7868
            return JTable.this.getSelectedColumns();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7869
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7870
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7871
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7872
         * Returns the row at a given index into the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7873
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7874
         * @param i zero-based index into the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7875
         * @return the row at a given index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7876
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7877
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7878
        public int getAccessibleRowAtIndex(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7879
            int columnCount = getAccessibleColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7880
            if (columnCount == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7881
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7882
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7883
                return (i / columnCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7884
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7885
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7886
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7887
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7888
         * Returns the column at a given index into the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7889
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7890
         * @param i zero-based index into the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7891
         * @return the column at a given index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7892
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7893
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7894
        public int getAccessibleColumnAtIndex(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7895
            int columnCount = getAccessibleColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7896
            if (columnCount == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7897
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7898
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7899
                return (i % columnCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7900
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7901
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7902
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7903
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7904
         * Returns the index at a given (row, column) in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7905
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7906
         * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7907
         * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7908
         * @return the index into the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7909
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7910
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7911
        public int getAccessibleIndexAt(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7912
            return ((r * getAccessibleColumnCount()) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7913
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7914
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7915
        // end of AccessibleTable implementation --------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7916
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7917
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7918
         * The class provides an implementation of the Java Accessibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7919
         * API appropriate to table cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7920
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7921
        protected class AccessibleJTableCell extends AccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7922
            implements Accessible, AccessibleComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7923
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7924
            private JTable parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7925
            private int row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7926
            private int column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7927
            private int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7928
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7929
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7930
             *  Constructs an <code>AccessibleJTableHeaderEntry</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7931
             * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7932
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7933
            public AccessibleJTableCell(JTable t, int r, int c, int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7934
                parent = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7935
                row = r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7936
                column = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7937
                index = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7938
                this.setAccessibleParent(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7939
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7940
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7941
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7942
             * Gets the <code>AccessibleContext</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7943
             * component. In the implementation of the Java Accessibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7944
             * API for this class, return this object, which is its own
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7945
             * <code>AccessibleContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7946
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7947
             * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7948
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7949
            public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7950
                return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7951
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7952
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7953
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7954
             * Gets the AccessibleContext for the table cell renderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7955
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7956
             * @return the <code>AccessibleContext</code> for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7957
             * cell renderer if one exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7958
             * otherwise, returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7959
             * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7960
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7961
            protected AccessibleContext getCurrentAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7962
                TableColumn aColumn = getColumnModel().getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7963
                TableCellRenderer renderer = aColumn.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7964
                if (renderer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7965
                    Class<?> columnClass = getColumnClass(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7966
                    renderer = getDefaultRenderer(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7967
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7968
                Component component = renderer.getTableCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7969
                                  JTable.this, getValueAt(row, column),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7970
                                  false, false, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7971
                if (component instanceof Accessible) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  7972
                    return component.getAccessibleContext();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7973
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7974
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7975
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7976
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7977
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7978
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7979
             * Gets the table cell renderer component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7980
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7981
             * @return the table cell renderer component if one exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7982
             * otherwise, returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7983
             * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7984
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7985
            protected Component getCurrentComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7986
                TableColumn aColumn = getColumnModel().getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7987
                TableCellRenderer renderer = aColumn.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7988
                if (renderer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7989
                    Class<?> columnClass = getColumnClass(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7990
                    renderer = getDefaultRenderer(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7991
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7992
                return renderer.getTableCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7993
                                  JTable.this, null, false, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7994
                                  row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7995
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7996
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7997
        // AccessibleContext methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7998
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7999
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8000
             * Gets the accessible name of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8001
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8002
             * @return the localized name of the object; <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8003
             *     if this object does not have a name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8004
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8005
            public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8006
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8007
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8008
                    String name = ac.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8009
                    if ((name != null) && (name != "")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8010
                        // return the cell renderer's AccessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8011
                        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8012
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8013
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8014
                if ((accessibleName != null) && (accessibleName != "")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8015
                    return accessibleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8016
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8017
                    // fall back to the client property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8018
                    return (String)getClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8019
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8020
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8022
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8023
             * Sets the localized accessible name of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8024
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8025
             * @param s the new localized name of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8026
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8027
            public void setAccessibleName(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8028
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8029
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8030
                    ac.setAccessibleName(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8031
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8032
                    super.setAccessibleName(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8033
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8034
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8036
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8037
            // *** should check toolTip text for desc. (needs MouseEvent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8038
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8039
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8040
             * Gets the accessible description of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8041
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8042
             * @return the localized description of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8043
             *     <code>null</code> if this object does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8044
             *     a description
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8045
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8046
            public String getAccessibleDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8047
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8048
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8049
                    return ac.getAccessibleDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8050
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8051
                    return super.getAccessibleDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8052
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8053
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8055
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8056
             * Sets the accessible description of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8057
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8058
             * @param s the new localized description of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8059
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8060
            public void setAccessibleDescription(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8061
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8062
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8063
                    ac.setAccessibleDescription(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8064
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8065
                    super.setAccessibleDescription(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8066
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8067
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8069
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8070
             * Gets the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8071
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8072
             * @return an instance of <code>AccessibleRole</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8073
             *      describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8074
             * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8075
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8076
            public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8077
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8078
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8079
                    return ac.getAccessibleRole();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8080
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8081
                    return AccessibleRole.UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8082
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8083
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8085
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8086
             * Gets the state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8087
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8088
             * @return an instance of <code>AccessibleStateSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8089
             *     containing the current state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8090
             * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8091
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8092
            public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8093
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8094
                AccessibleStateSet as = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8096
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8097
                    as = ac.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8098
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8099
                if (as == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8100
                    as = new AccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8101
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8102
                Rectangle rjt = JTable.this.getVisibleRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8103
                Rectangle rcell = JTable.this.getCellRect(row, column, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8104
                if (rjt.intersects(rcell)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8105
                    as.add(AccessibleState.SHOWING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8106
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8107
                    if (as.contains(AccessibleState.SHOWING)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8108
                         as.remove(AccessibleState.SHOWING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8109
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8110
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8111
                if (parent.isCellSelected(row, column)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8112
                    as.add(AccessibleState.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8113
                } else if (as.contains(AccessibleState.SELECTED)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8114
                    as.remove(AccessibleState.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8115
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8116
                if ((row == getSelectedRow()) && (column == getSelectedColumn())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8117
                    as.add(AccessibleState.ACTIVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8118
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8119
                as.add(AccessibleState.TRANSIENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8120
                return as;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8121
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8123
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8124
             * Gets the <code>Accessible</code> parent of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8125
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8126
             * @return the Accessible parent of this object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8127
             *     <code>null</code> if this object does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8128
             *     have an <code>Accessible</code> parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8129
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8130
            public Accessible getAccessibleParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8131
                return parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8132
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8134
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8135
             * Gets the index of this object in its accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8136
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8137
             * @return the index of this object in its parent; -1 if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8138
             *     object does not have an accessible parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8139
             * @see #getAccessibleParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8140
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8141
            public int getAccessibleIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8142
                return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8143
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8145
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8146
             * Returns the number of accessible children in the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8147
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8148
             * @return the number of accessible children in the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8149
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8150
            public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8151
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8152
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8153
                    return ac.getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8154
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8155
                    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8156
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8157
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8159
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8160
             * Returns the specified <code>Accessible</code> child of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8161
             * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8162
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8163
             * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8164
             * @return the <code>Accessible</code> child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8165
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8166
            public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8167
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8168
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8169
                    Accessible accessibleChild = ac.getAccessibleChild(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8170
                    ac.setAccessibleParent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8171
                    return accessibleChild;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8172
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8173
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8174
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8175
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8177
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8178
             * Gets the locale of the component. If the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8179
             * does not have a locale, then the locale of its parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8180
             * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8181
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8182
             * @return this component's locale; if this component does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8183
             *    not have a locale, the locale of its parent is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8184
             * @exception IllegalComponentStateException if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8185
             *    <code>Component</code> does not have its own locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8186
             *    and has not yet been added to a containment hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8187
             *    such that the locale can be determined from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8188
             *    containing parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8189
             * @see #setLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8190
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8191
            public Locale getLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8192
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8193
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8194
                    return ac.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8195
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8196
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8197
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8198
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8200
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8201
             * Adds a <code>PropertyChangeListener</code> to the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8202
             * The listener is registered for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8203
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8204
             * @param l  the <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8205
             *     to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8206
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8207
            public void addPropertyChangeListener(PropertyChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8208
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8209
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8210
                    ac.addPropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8211
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8212
                    super.addPropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8213
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8214
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8215
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8216
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8217
             * Removes a <code>PropertyChangeListener</code> from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8218
             * listener list. This removes a <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8219
             * that was registered for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8220
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8221
             * @param l  the <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8222
             *    to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8223
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8224
            public void removePropertyChangeListener(PropertyChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8225
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8226
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8227
                    ac.removePropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8228
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8229
                    super.removePropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8230
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8231
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8233
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8234
             * Gets the <code>AccessibleAction</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8235
             * object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8236
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8237
             * @return the <code>AccessibleAction</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8238
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8239
            public AccessibleAction getAccessibleAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8240
                return getCurrentAccessibleContext().getAccessibleAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8243
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8244
             * Gets the <code>AccessibleComponent</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8245
             * this object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8246
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8247
             * @return the <code>AccessibleComponent</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8248
             *    <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8249
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8250
            public AccessibleComponent getAccessibleComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8251
                return this; // to override getBounds()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8252
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8254
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8255
             * Gets the <code>AccessibleSelection</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8256
             * this object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8257
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8258
             * @return the <code>AccessibleSelection</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8259
             *    <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8260
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8261
            public AccessibleSelection getAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8262
                return getCurrentAccessibleContext().getAccessibleSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8264
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8265
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8266
             * Gets the <code>AccessibleText</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8267
             * object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8268
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8269
             * @return the <code>AccessibleText</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8270
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8271
            public AccessibleText getAccessibleText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8272
                return getCurrentAccessibleContext().getAccessibleText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8273
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8275
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8276
             * Gets the <code>AccessibleValue</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8277
             * this object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8278
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8279
             * @return the <code>AccessibleValue</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8280
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8281
            public AccessibleValue getAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8282
                return getCurrentAccessibleContext().getAccessibleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8283
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8286
        // AccessibleComponent methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8288
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8289
             * Gets the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8290
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8291
             * @return the background color, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8292
             *     otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8293
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8294
            public Color getBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8295
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8296
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8297
                    return ((AccessibleComponent) ac).getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8298
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8299
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8300
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8301
                        return c.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8302
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8303
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8304
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8305
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8306
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8307
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8308
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8309
             * Sets the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8310
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8311
             * @param c the new <code>Color</code> for the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8312
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8313
            public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8314
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8315
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8316
                    ((AccessibleComponent) ac).setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8317
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8318
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8319
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8320
                        cp.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8321
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8322
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8323
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8324
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8325
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8326
             * Gets the foreground color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8327
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8328
             * @return the foreground color, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8329
             *     otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8330
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8331
            public Color getForeground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8332
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8333
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8334
                    return ((AccessibleComponent) ac).getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8335
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8336
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8337
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8338
                        return c.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8339
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8340
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8341
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8342
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8343
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8344
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8345
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8346
             * Sets the foreground color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8347
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8348
             * @param c the new <code>Color</code> for the foreground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8349
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8350
            public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8351
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8352
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8353
                    ((AccessibleComponent) ac).setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8354
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8355
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8356
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8357
                        cp.setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8358
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8359
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8360
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8362
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8363
             * Gets the <code>Cursor</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8364
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8365
             * @return the <code>Cursor</code>, if supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8366
             *    of the object; otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8367
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8368
            public Cursor getCursor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8369
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8370
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8371
                    return ((AccessibleComponent) ac).getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8372
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8373
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8374
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8375
                        return c.getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8376
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8377
                        Accessible ap = getAccessibleParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8378
                        if (ap instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8379
                            return ((AccessibleComponent) ap).getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8380
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8381
                            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8382
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8383
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8384
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8385
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8386
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8387
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8388
             * Sets the <code>Cursor</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8389
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8390
             * @param c the new <code>Cursor</code> for the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8391
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8392
            public void setCursor(Cursor c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8393
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8394
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8395
                    ((AccessibleComponent) ac).setCursor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8396
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8397
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8398
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8399
                        cp.setCursor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8400
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8401
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8402
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8403
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8404
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8405
             * Gets the <code>Font</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8406
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8407
             * @return the <code>Font</code>,if supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8408
             *   for the object; otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8409
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8410
            public Font getFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8411
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8412
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8413
                    return ((AccessibleComponent) ac).getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8414
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8415
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8416
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8417
                        return c.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8418
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8419
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8420
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8421
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8422
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8423
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8424
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8425
             * Sets the <code>Font</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8426
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8427
             * @param f the new <code>Font</code> for the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8428
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8429
            public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8430
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8431
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8432
                    ((AccessibleComponent) ac).setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8433
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8434
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8435
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8436
                        c.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8437
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8438
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8439
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8441
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8442
             * Gets the <code>FontMetrics</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8443
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8444
             * @param f the <code>Font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8445
             * @return the <code>FontMetrics</code> object, if supported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8446
             *    otherwise <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8447
             * @see #getFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8448
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8449
            public FontMetrics getFontMetrics(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8450
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8451
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8452
                    return ((AccessibleComponent) ac).getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8453
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8454
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8455
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8456
                        return c.getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8457
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8458
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8459
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8460
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8461
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8462
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8463
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8464
             * Determines if the object is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8465
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8466
             * @return true if object is enabled; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8467
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8468
            public boolean isEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8469
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8470
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8471
                    return ((AccessibleComponent) ac).isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8472
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8473
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8474
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8475
                        return c.isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8476
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8477
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8478
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8479
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8480
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8481
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8482
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8483
             * Sets the enabled state of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8484
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8485
             * @param b if true, enables this object; otherwise, disables it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8486
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8487
            public void setEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8488
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8489
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8490
                    ((AccessibleComponent) ac).setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8491
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8492
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8493
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8494
                        c.setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8495
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8496
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8497
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8499
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8500
             * Determines if this object is visible.  Note: this means that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8501
             * object intends to be visible; however, it may not in fact be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8502
             * showing on the screen because one of the objects that this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8503
             * is contained by is not visible.  To determine if an object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8504
             * showing on the screen, use <code>isShowing</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8505
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8506
             * @return true if object is visible; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8507
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8508
            public boolean isVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8509
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8510
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8511
                    return ((AccessibleComponent) ac).isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8512
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8513
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8514
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8515
                        return c.isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8516
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8517
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8518
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8519
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8520
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8521
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8522
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8523
             * Sets the visible state of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8524
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8525
             * @param b if true, shows this object; otherwise, hides it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8526
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8527
            public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8528
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8529
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8530
                    ((AccessibleComponent) ac).setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8531
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8532
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8533
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8534
                        c.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8535
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8536
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8537
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8538
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8539
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8540
             * Determines if the object is showing.  This is determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8541
             * by checking the visibility of the object and ancestors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8542
             * of the object.  Note: this will return true even if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8543
             * object is obscured by another (for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8544
             * it happens to be underneath a menu that was pulled down).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8545
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8546
             * @return true if the object is showing; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8547
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8548
            public boolean isShowing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8549
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8550
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8551
                    if (ac.getAccessibleParent() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8552
                        return ((AccessibleComponent) ac).isShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8553
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8554
                        // Fixes 4529616 - AccessibleJTableCell.isShowing()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8555
                        // returns false when the cell on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8556
                        // if no parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8557
                        return isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8558
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8559
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8560
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8561
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8562
                        return c.isShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8563
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8564
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8565
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8566
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8567
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8569
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8570
             * Checks whether the specified point is within this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8571
             * object's bounds, where the point's x and y coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8572
             * are defined to be relative to the coordinate system of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8573
             * the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8574
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8575
             * @param p the <code>Point</code> relative to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8576
             *    coordinate system of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8577
             * @return true if object contains <code>Point</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8578
             *    otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8579
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8580
            public boolean contains(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8581
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8582
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8583
                    Rectangle r = ((AccessibleComponent) ac).getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8584
                    return r.contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8585
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8586
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8587
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8588
                        Rectangle r = c.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8589
                        return r.contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8590
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8591
                        return getBounds().contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8592
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8593
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8594
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8595
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8596
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8597
             * Returns the location of the object on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8598
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8599
             * @return location of object on screen -- can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8600
             *    <code>null</code> if this object is not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8601
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8602
            public Point getLocationOnScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8603
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8604
                    Point parentLocation = parent.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8605
                    Point componentLocation = getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8606
                    componentLocation.translate(parentLocation.x, parentLocation.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8607
                    return componentLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8608
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8609
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8610
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8611
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8612
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8613
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8614
             * Gets the location of the object relative to the parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8615
             * in the form of a point specifying the object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8616
             * top-left corner in the screen's coordinate space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8617
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8618
             * @return an instance of <code>Point</code> representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8619
             *    the top-left corner of the object's bounds in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8620
             *    coordinate space of the screen; <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8621
             *    this object or its parent are not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8622
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8623
            public Point getLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8624
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8625
                    Rectangle r = parent.getCellRect(row, column, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8626
                    if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8627
                        return r.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8628
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8629
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8630
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8631
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8632
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8633
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8634
             * Sets the location of the object relative to the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8635
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8636
            public void setLocation(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8637
//              if ((parent != null)  && (parent.contains(p))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8638
//                  ensureIndexIsVisible(indexInParent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8639
//              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8640
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8641
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8642
            public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8643
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8644
                    return parent.getCellRect(row, column, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8645
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8646
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8647
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8648
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8649
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8650
            public void setBounds(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8651
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8652
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8653
                    ((AccessibleComponent) ac).setBounds(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8654
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8655
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8656
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8657
                        c.setBounds(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8658
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8659
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8660
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8661
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8662
            public Dimension getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8663
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8664
                    Rectangle r = parent.getCellRect(row, column, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8665
                    if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8666
                        return r.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8667
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8668
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8669
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8670
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8671
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8672
            public void setSize (Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8673
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8674
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8675
                    ((AccessibleComponent) ac).setSize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8676
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8677
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8678
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8679
                        c.setSize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8680
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8681
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8682
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8683
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8684
            public Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8685
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8686
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8687
                    return ((AccessibleComponent) ac).getAccessibleAt(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8688
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8689
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8690
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8691
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8692
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8693
            public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8694
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8695
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8696
                    return ((AccessibleComponent) ac).isFocusTraversable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8697
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8698
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8699
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8700
                        return c.isFocusTraversable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8701
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8702
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8703
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8704
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8705
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8706
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8707
            public void requestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8708
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8709
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8710
                    ((AccessibleComponent) ac).requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8711
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8712
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8713
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8714
                        c.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8715
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8716
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8717
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8718
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8719
            public void addFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8720
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8721
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8722
                    ((AccessibleComponent) ac).addFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8723
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8724
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8725
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8726
                        c.addFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8727
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8728
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8729
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8730
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8731
            public void removeFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8732
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8733
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8734
                    ((AccessibleComponent) ac).removeFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8735
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8736
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8737
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8738
                        c.removeFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8739
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8740
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8741
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8742
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8743
        } // inner class AccessibleJTableCell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8744
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8745
        // Begin AccessibleJTableHeader ========== // TIGER - 4715503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8746
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8747
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8748
         * This class implements accessibility for JTable header cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8749
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8750
        private class AccessibleJTableHeaderCell extends AccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8751
            implements Accessible, AccessibleComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8752
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8753
            private int row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8754
            private int column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8755
            private JTableHeader parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8756
            private Component rendererComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8757
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8758
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8759
             * Constructs an <code>AccessibleJTableHeaderEntry</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8760
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8761
             * @param row header cell row index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8762
             * @param column header cell column index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8763
             * @param parent header cell parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8764
             * @param rendererComponent component that renders the header cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8765
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8766
            public AccessibleJTableHeaderCell(int row, int column,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8767
                                              JTableHeader parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8768
                                              Component rendererComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8769
                this.row = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8770
                this.column = column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8771
                this.parent = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8772
                this.rendererComponent = rendererComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8773
                this.setAccessibleParent(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8774
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8775
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8776
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8777
             * Gets the <code>AccessibleContext</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8778
             * component. In the implementation of the Java Accessibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8779
             * API for this class, return this object, which is its own
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8780
             * <code>AccessibleContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8781
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8782
             * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8783
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8784
            public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8785
                return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8786
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8787
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8788
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8789
             * Returns the AccessibleContext for the header cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8790
             * renderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8791
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8792
            private AccessibleContext getCurrentAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8793
                return rendererComponent.getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8794
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8795
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8796
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8797
             * Returns the component that renders the header cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8798
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8799
            private Component getCurrentComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8800
                return rendererComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8801
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8802
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8803
            // AccessibleContext methods ==========
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8804
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8805
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8806
             * Gets the accessible name of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8807
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8808
             * @return the localized name of the object; <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8809
             *     if this object does not have a name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8810
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8811
            public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8812
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8813
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8814
                    String name = ac.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8815
                    if ((name != null) && (name != "")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8816
                        return ac.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8817
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8818
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8819
                if ((accessibleName != null) && (accessibleName != "")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8820
                    return accessibleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8821
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8822
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8823
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8824
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8825
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8826
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8827
             * Sets the localized accessible name of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8828
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8829
             * @param s the new localized name of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8830
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8831
            public void setAccessibleName(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8832
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8833
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8834
                    ac.setAccessibleName(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8835
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8836
                    super.setAccessibleName(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8837
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8838
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8839
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8840
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8841
             * Gets the accessible description of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8842
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8843
             * @return the localized description of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8844
             *     <code>null</code> if this object does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8845
             *     a description
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8846
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8847
            public String getAccessibleDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8848
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8849
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8850
                    return ac.getAccessibleDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8851
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8852
                    return super.getAccessibleDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8853
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8854
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8855
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8856
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8857
             * Sets the accessible description of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8858
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8859
             * @param s the new localized description of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8860
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8861
            public void setAccessibleDescription(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8862
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8863
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8864
                    ac.setAccessibleDescription(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8865
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8866
                    super.setAccessibleDescription(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8867
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8868
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8869
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8870
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8871
             * Gets the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8872
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8873
             * @return an instance of <code>AccessibleRole</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8874
             *      describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8875
             * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8876
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8877
            public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8878
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8879
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8880
                    return ac.getAccessibleRole();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8881
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8882
                    return AccessibleRole.UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8883
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8884
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8885
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8886
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8887
             * Gets the state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8888
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8889
             * @return an instance of <code>AccessibleStateSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8890
             *     containing the current state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8891
             * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8892
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8893
            public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8894
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8895
                AccessibleStateSet as = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8896
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8897
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8898
                    as = ac.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8899
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8900
                if (as == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8901
                    as = new AccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8902
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8903
                Rectangle rjt = JTable.this.getVisibleRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8904
                Rectangle rcell = JTable.this.getCellRect(row, column, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8905
                if (rjt.intersects(rcell)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8906
                    as.add(AccessibleState.SHOWING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8907
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8908
                    if (as.contains(AccessibleState.SHOWING)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8909
                         as.remove(AccessibleState.SHOWING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8910
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8911
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8912
                if (JTable.this.isCellSelected(row, column)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8913
                    as.add(AccessibleState.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8914
                } else if (as.contains(AccessibleState.SELECTED)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8915
                    as.remove(AccessibleState.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8916
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8917
                if ((row == getSelectedRow()) && (column == getSelectedColumn())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8918
                    as.add(AccessibleState.ACTIVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8919
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8920
                as.add(AccessibleState.TRANSIENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8921
                return as;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8922
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8923
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8924
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8925
             * Gets the <code>Accessible</code> parent of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8926
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8927
             * @return the Accessible parent of this object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8928
             *     <code>null</code> if this object does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8929
             *     have an <code>Accessible</code> parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8930
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8931
            public Accessible getAccessibleParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8932
                return parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8933
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8934
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8935
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8936
             * Gets the index of this object in its accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8937
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8938
             * @return the index of this object in its parent; -1 if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8939
             *     object does not have an accessible parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8940
             * @see #getAccessibleParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8941
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8942
            public int getAccessibleIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8943
                return column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8944
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8945
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8946
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8947
             * Returns the number of accessible children in the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8948
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8949
             * @return the number of accessible children in the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8950
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8951
            public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8952
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8953
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8954
                    return ac.getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8955
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8956
                    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8957
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8958
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8959
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8960
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8961
             * Returns the specified <code>Accessible</code> child of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8962
             * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8963
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8964
             * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8965
             * @return the <code>Accessible</code> child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8966
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8967
            public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8968
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8969
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8970
                    Accessible accessibleChild = ac.getAccessibleChild(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8971
                    ac.setAccessibleParent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8972
                    return accessibleChild;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8973
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8974
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8975
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8976
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8977
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8978
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8979
             * Gets the locale of the component. If the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8980
             * does not have a locale, then the locale of its parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8981
             * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8982
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8983
             * @return this component's locale; if this component does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8984
             *    not have a locale, the locale of its parent is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8985
             * @exception IllegalComponentStateException if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8986
             *    <code>Component</code> does not have its own locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8987
             *    and has not yet been added to a containment hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8988
             *    such that the locale can be determined from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8989
             *    containing parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8990
             * @see #setLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8991
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8992
            public Locale getLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8993
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8994
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8995
                    return ac.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8996
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8997
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8998
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8999
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9001
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9002
             * Adds a <code>PropertyChangeListener</code> to the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9003
             * The listener is registered for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9004
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9005
             * @param l  the <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9006
             *     to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9007
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9008
            public void addPropertyChangeListener(PropertyChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9009
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9010
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9011
                    ac.addPropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9012
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9013
                    super.addPropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9014
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9015
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9017
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9018
             * Removes a <code>PropertyChangeListener</code> from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9019
             * listener list. This removes a <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9020
             * that was registered for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9021
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9022
             * @param l  the <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9023
             *    to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9024
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9025
            public void removePropertyChangeListener(PropertyChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9026
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9027
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9028
                    ac.removePropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9029
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9030
                    super.removePropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9031
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9032
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9034
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9035
             * Gets the <code>AccessibleAction</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9036
             * object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9037
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9038
             * @return the <code>AccessibleAction</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9039
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9040
            public AccessibleAction getAccessibleAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9041
                return getCurrentAccessibleContext().getAccessibleAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9042
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9044
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9045
             * Gets the <code>AccessibleComponent</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9046
             * this object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9047
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9048
             * @return the <code>AccessibleComponent</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9049
             *    <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9050
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9051
            public AccessibleComponent getAccessibleComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9052
                return this; // to override getBounds()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9053
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9055
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9056
             * Gets the <code>AccessibleSelection</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9057
             * this object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9058
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9059
             * @return the <code>AccessibleSelection</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9060
             *    <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9061
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9062
            public AccessibleSelection getAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9063
                return getCurrentAccessibleContext().getAccessibleSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9064
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9065
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9066
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9067
             * Gets the <code>AccessibleText</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9068
             * object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9069
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9070
             * @return the <code>AccessibleText</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9071
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9072
            public AccessibleText getAccessibleText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9073
                return getCurrentAccessibleContext().getAccessibleText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9074
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9076
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9077
             * Gets the <code>AccessibleValue</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9078
             * this object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9079
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9080
             * @return the <code>AccessibleValue</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9081
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9082
            public AccessibleValue getAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9083
                return getCurrentAccessibleContext().getAccessibleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9084
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9087
            // AccessibleComponent methods ==========
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9089
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9090
             * Gets the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9091
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9092
             * @return the background color, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9093
             *     otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9094
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9095
            public Color getBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9096
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9097
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9098
                    return ((AccessibleComponent) ac).getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9099
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9100
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9101
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9102
                        return c.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9103
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9104
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9105
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9106
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9107
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9109
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9110
             * Sets the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9111
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9112
             * @param c the new <code>Color</code> for the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9113
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9114
            public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9115
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9116
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9117
                    ((AccessibleComponent) ac).setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9118
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9119
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9120
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9121
                        cp.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9122
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9123
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9124
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9126
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9127
             * Gets the foreground color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9128
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9129
             * @return the foreground color, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9130
             *     otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9131
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9132
            public Color getForeground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9133
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9134
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9135
                    return ((AccessibleComponent) ac).getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9136
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9137
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9138
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9139
                        return c.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9140
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9141
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9142
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9143
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9144
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9145
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9146
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9147
             * Sets the foreground color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9148
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9149
             * @param c the new <code>Color</code> for the foreground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9150
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9151
            public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9152
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9153
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9154
                    ((AccessibleComponent) ac).setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9155
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9156
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9157
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9158
                        cp.setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9159
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9160
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9161
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9163
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9164
             * Gets the <code>Cursor</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9165
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9166
             * @return the <code>Cursor</code>, if supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9167
             *    of the object; otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9168
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9169
            public Cursor getCursor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9170
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9171
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9172
                    return ((AccessibleComponent) ac).getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9173
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9174
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9175
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9176
                        return c.getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9177
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9178
                        Accessible ap = getAccessibleParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9179
                        if (ap instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9180
                            return ((AccessibleComponent) ap).getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9181
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9182
                            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9183
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9184
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9185
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9188
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9189
             * Sets the <code>Cursor</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9190
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9191
             * @param c the new <code>Cursor</code> for the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9192
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9193
            public void setCursor(Cursor c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9194
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9195
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9196
                    ((AccessibleComponent) ac).setCursor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9197
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9198
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9199
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9200
                        cp.setCursor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9201
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9202
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9205
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9206
             * Gets the <code>Font</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9207
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9208
             * @return the <code>Font</code>,if supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9209
             *   for the object; otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9210
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9211
            public Font getFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9212
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9213
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9214
                    return ((AccessibleComponent) ac).getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9215
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9216
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9217
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9218
                        return c.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9219
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9220
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9221
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9222
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9224
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9225
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9226
             * Sets the <code>Font</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9227
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9228
             * @param f the new <code>Font</code> for the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9229
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9230
            public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9231
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9232
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9233
                    ((AccessibleComponent) ac).setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9234
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9235
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9236
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9237
                        c.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9238
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9239
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9241
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9242
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9243
             * Gets the <code>FontMetrics</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9244
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9245
             * @param f the <code>Font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9246
             * @return the <code>FontMetrics</code> object, if supported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9247
             *    otherwise <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9248
             * @see #getFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9249
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9250
            public FontMetrics getFontMetrics(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9251
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9252
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9253
                    return ((AccessibleComponent) ac).getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9254
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9255
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9256
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9257
                        return c.getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9258
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9259
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9260
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9261
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9262
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9264
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9265
             * Determines if the object is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9266
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9267
             * @return true if object is enabled; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9268
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9269
            public boolean isEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9270
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9271
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9272
                    return ((AccessibleComponent) ac).isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9273
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9274
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9275
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9276
                        return c.isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9277
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9278
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9279
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9280
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9281
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9282
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9283
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9284
             * Sets the enabled state of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9285
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9286
             * @param b if true, enables this object; otherwise, disables it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9287
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9288
            public void setEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9289
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9290
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9291
                    ((AccessibleComponent) ac).setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9292
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9293
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9294
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9295
                        c.setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9296
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9297
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9298
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9300
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9301
             * Determines if this object is visible.  Note: this means that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9302
             * object intends to be visible; however, it may not in fact be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9303
             * showing on the screen because one of the objects that this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9304
             * is contained by is not visible.  To determine if an object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9305
             * showing on the screen, use <code>isShowing</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9306
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9307
             * @return true if object is visible; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9308
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9309
            public boolean isVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9310
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9311
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9312
                    return ((AccessibleComponent) ac).isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9313
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9314
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9315
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9316
                        return c.isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9317
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9318
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9319
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9320
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9321
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9323
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9324
             * Sets the visible state of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9325
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9326
             * @param b if true, shows this object; otherwise, hides it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9327
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9328
            public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9329
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9330
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9331
                    ((AccessibleComponent) ac).setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9332
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9333
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9334
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9335
                        c.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9336
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9337
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9338
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9339
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9340
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9341
             * Determines if the object is showing.  This is determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9342
             * by checking the visibility of the object and ancestors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9343
             * of the object.  Note: this will return true even if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9344
             * object is obscured by another (for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9345
             * it happens to be underneath a menu that was pulled down).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9346
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9347
             * @return true if the object is showing; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9348
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9349
            public boolean isShowing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9350
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9351
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9352
                    if (ac.getAccessibleParent() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9353
                        return ((AccessibleComponent) ac).isShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9354
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9355
                        // Fixes 4529616 - AccessibleJTableCell.isShowing()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9356
                        // returns false when the cell on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9357
                        // if no parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9358
                        return isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9359
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9360
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9361
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9362
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9363
                        return c.isShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9364
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9365
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9366
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9367
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9368
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9369
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9370
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9371
             * Checks whether the specified point is within this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9372
             * object's bounds, where the point's x and y coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9373
             * are defined to be relative to the coordinate system of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9374
             * the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9375
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9376
             * @param p the <code>Point</code> relative to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9377
             *    coordinate system of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9378
             * @return true if object contains <code>Point</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9379
             *    otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9380
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9381
            public boolean contains(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9382
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9383
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9384
                    Rectangle r = ((AccessibleComponent) ac).getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9385
                    return r.contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9386
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9387
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9388
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9389
                        Rectangle r = c.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9390
                        return r.contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9391
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9392
                        return getBounds().contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9393
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9394
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9395
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9396
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9397
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9398
             * Returns the location of the object on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9399
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9400
             * @return location of object on screen -- can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9401
             *    <code>null</code> if this object is not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9402
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9403
            public Point getLocationOnScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9404
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9405
                    Point parentLocation = parent.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9406
                    Point componentLocation = getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9407
                    componentLocation.translate(parentLocation.x, parentLocation.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9408
                    return componentLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9409
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9410
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9411
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9412
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9413
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9414
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9415
             * Gets the location of the object relative to the parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9416
             * in the form of a point specifying the object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9417
             * top-left corner in the screen's coordinate space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9418
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9419
             * @return an instance of <code>Point</code> representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9420
             *    the top-left corner of the object's bounds in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9421
             *    coordinate space of the screen; <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9422
             *    this object or its parent are not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9423
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9424
            public Point getLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9425
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9426
                    Rectangle r = parent.getHeaderRect(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9427
                    if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9428
                        return r.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9429
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9430
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9431
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9432
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9433
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9434
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9435
             * Sets the location of the object relative to the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9436
             * @param p the new position for the top-left corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9437
             * @see #getLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9438
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9439
            public void setLocation(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9440
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9441
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9442
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9443
             * Gets the bounds of this object in the form of a Rectangle object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9444
             * The bounds specify this object's width, height, and location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9445
             * relative to its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9446
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9447
             * @return A rectangle indicating this component's bounds; null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9448
             * this object is not on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9449
             * @see #contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9450
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9451
            public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9452
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9453
                    return parent.getHeaderRect(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9454
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9455
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9456
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9457
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9458
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9459
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9460
             * Sets the bounds of this object in the form of a Rectangle object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9461
             * The bounds specify this object's width, height, and location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9462
             * relative to its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9463
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9464
             * @param r rectangle indicating this component's bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9465
             * @see #getBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9466
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9467
            public void setBounds(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9468
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9469
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9470
                    ((AccessibleComponent) ac).setBounds(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9471
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9472
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9473
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9474
                        c.setBounds(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9475
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9476
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9477
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9479
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9480
             * Returns the size of this object in the form of a Dimension object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9481
             * The height field of the Dimension object contains this object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9482
             * height, and the width field of the Dimension object contains this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9483
             * object's width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9484
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9485
             * @return A Dimension object that indicates the size of this component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9486
             * null if this object is not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9487
             * @see #setSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9488
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9489
            public Dimension getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9490
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9491
                    Rectangle r = parent.getHeaderRect(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9492
                    if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9493
                        return r.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9494
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9495
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9496
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9497
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9499
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9500
             * Resizes this object so that it has width and height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9501
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9502
             * @param d The dimension specifying the new size of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9503
             * @see #getSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9504
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9505
            public void setSize (Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9506
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9507
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9508
                    ((AccessibleComponent) ac).setSize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9509
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9510
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9511
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9512
                        c.setSize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9513
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9514
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9515
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9516
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9517
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9518
             * Returns the Accessible child, if one exists, contained at the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9519
             * coordinate Point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9520
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9521
             * @param p The point relative to the coordinate system of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9522
             * @return the Accessible, if it exists, at the specified location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9523
             * otherwise null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9524
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9525
            public Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9526
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9527
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9528
                    return ((AccessibleComponent) ac).getAccessibleAt(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9529
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9530
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9531
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9532
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9533
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9534
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9535
             * Returns whether this object can accept focus or not.   Objects that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9536
             * can accept focus will also have the AccessibleState.FOCUSABLE state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9537
             * set in their AccessibleStateSets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9538
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9539
             * @return true if object can accept focus; otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9540
             * @see AccessibleContext#getAccessibleStateSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9541
             * @see AccessibleState#FOCUSABLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9542
             * @see AccessibleState#FOCUSED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9543
             * @see AccessibleStateSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9544
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9545
            public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9546
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9547
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9548
                    return ((AccessibleComponent) ac).isFocusTraversable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9549
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9550
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9551
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9552
                        return c.isFocusTraversable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9553
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9554
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9555
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9556
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9557
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9558
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9559
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9560
             * Requests focus for this object.  If this object cannot accept focus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9561
             * nothing will happen.  Otherwise, the object will attempt to take
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9562
             * focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9563
             * @see #isFocusTraversable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9564
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9565
            public void requestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9566
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9567
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9568
                    ((AccessibleComponent) ac).requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9569
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9570
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9571
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9572
                        c.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9573
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9574
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9575
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9576
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9577
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9578
             * Adds the specified focus listener to receive focus events from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9579
             * component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9580
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9581
             * @param l the focus listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9582
             * @see #removeFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9583
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9584
            public void addFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9585
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9586
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9587
                    ((AccessibleComponent) ac).addFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9588
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9589
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9590
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9591
                        c.addFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9592
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9593
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9594
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9595
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9596
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9597
             * Removes the specified focus listener so it no longer receives focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9598
             * events from this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9599
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9600
             * @param l the focus listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9601
             * @see #addFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9602
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9603
            public void removeFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9604
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9605
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9606
                    ((AccessibleComponent) ac).removeFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9607
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9608
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9609
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9610
                        c.removeFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9611
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9612
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9613
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9614
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9615
        } // inner class AccessibleJTableHeaderCell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9616
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9617
    }  // inner class AccessibleJTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9618
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9619
}  // End of Class JTable