jdk/src/share/classes/javax/swing/JTable.java
author ant
Fri, 31 Jan 2014 18:49:58 +0400
changeset 23280 df31f522531f
parent 22574 7f8ce0c8c20a
child 23295 6c61adf6111e
permissions -rw-r--r--
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE Reviewed-by: alexsch, pchelko
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21982
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5449
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5449
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5449
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5449
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5449
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing;
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;
20800
1f6b7d81410d 8013744: Better tabling for AWT
alexsch
parents: 16100
diff changeset
    55
import sun.reflect.misc.ReflectUtil;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import sun.swing.SwingUtilities2.Section;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import static sun.swing.SwingUtilities2.Section.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import sun.swing.PrintingStatus;
4272
f4742294ef29 6795356: Leak caused by javax.swing.UIDefaults.ProxyLazyValue.acc
alexp
parents: 3737
diff changeset
    61
import sun.swing.SwingLazyValue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * The <code>JTable</code> is used to display and edit regular two-dimensional tables
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * of cells.
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20157
diff changeset
    66
 * See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/table.html">How to Use Tables</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * in <em>The Java Tutorial</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * for task-oriented documentation and examples of using <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * The <code>JTable</code> has many
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * facilities that make it possible to customize its rendering and editing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * but provides defaults for these features so that simple tables can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * set up easily.  For example, to set up a table with 10 rows and 10
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * columns of numbers:
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 21278
diff changeset
    76
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *      TableModel dataModel = new AbstractTableModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *          public int getColumnCount() { return 10; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *          public int getRowCount() { return 10;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *          public Object getValueAt(int row, int col) { return new Integer(row*col); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *      };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *      JTable table = new JTable(dataModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *      JScrollPane scrollpane = new JScrollPane(table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * {@code JTable}s are typically placed inside of a {@code JScrollPane}.  By
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * default, a {@code JTable} will adjust its width such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * a horizontal scrollbar is unnecessary.  To allow for a horizontal scrollbar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * invoke {@link #setAutoResizeMode} with {@code AUTO_RESIZE_OFF}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * Note that if you wish to use a <code>JTable</code> in a standalone
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * view (outside of a <code>JScrollPane</code>) and want the header
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * displayed, you can get it using {@link #getTableHeader} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * display it separately.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * To enable sorting and filtering of rows, use a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * {@code RowSorter}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * You can set up a row sorter in either of two ways:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *   <li>Directly set the {@code RowSorter}. For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *        {@code table.setRowSorter(new TableRowSorter(model))}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *   <li>Set the {@code autoCreateRowSorter}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *       property to {@code true}, so that the {@code JTable}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *       creates a {@code RowSorter} for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *       you. For example: {@code setAutoCreateRowSorter(true)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * When designing applications that use the <code>JTable</code> it is worth paying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * close attention to the data structures that will represent the table's data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * The <code>DefaultTableModel</code> is a model implementation that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * uses a <code>Vector</code> of <code>Vector</code>s of <code>Object</code>s to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * store the cell values. As well as copying the data from an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * application into the <code>DefaultTableModel</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * it is also possible to wrap the data in the methods of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * <code>TableModel</code> interface so that the data can be passed to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * <code>JTable</code> directly, as in the example above. This often results
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * in more efficient applications because the model is free to choose the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * internal representation that best suits the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * A good rule of thumb for deciding whether to use the <code>AbstractTableModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * or the <code>DefaultTableModel</code> is to use the <code>AbstractTableModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * as the base class for creating subclasses and the <code>DefaultTableModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * when subclassing is not required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * The "TableExample" directory in the demo area of the source distribution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * gives a number of complete examples of <code>JTable</code> usage,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * covering how the <code>JTable</code> can be used to provide an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * editable view of data taken from a database and how to modify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * the columns in the display to use specialized renderers and editors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * The <code>JTable</code> uses integers exclusively to refer to both the rows and the columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * of the model that it displays. The <code>JTable</code> simply takes a tabular range of cells
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * and uses <code>getValueAt(int, int)</code> to retrieve the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * values from the model during painting.  It is important to remember that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * the column and row indexes returned by various <code>JTable</code> methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * are in terms of the <code>JTable</code> (the view) and are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * necessarily the same indexes used by the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * By default, columns may be rearranged in the <code>JTable</code> so that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * view's columns appear in a different order to the columns in the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * This does not affect the implementation of the model at all: when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * columns are reordered, the <code>JTable</code> maintains the new order of the columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * internally and converts its column indices before querying the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * So, when writing a <code>TableModel</code>, it is not necessary to listen for column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * reordering events as the model will be queried in its own coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * system regardless of what is happening in the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * In the examples area there is a demonstration of a sorting algorithm making
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * use of exactly this technique to interpose yet another coordinate system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * where the order of the rows is changed, rather than the order of the columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * Similarly when using the sorting and filtering functionality
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * provided by <code>RowSorter</code> the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * <code>TableModel</code> does not need to know how to do sorting,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * rather <code>RowSorter</code> will handle it.  Coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * conversions will be necessary when using the row based methods of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * <code>JTable</code> with the underlying <code>TableModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * All of <code>JTable</code>s row based methods are in terms of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * <code>RowSorter</code>, which is not necessarily the same as that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * of the underlying <code>TableModel</code>.  For example, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * selection is always in terms of <code>JTable</code> so that when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * using <code>RowSorter</code> you will need to convert using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * <code>convertRowIndexToView</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * <code>convertRowIndexToModel</code>.  The following shows how to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * convert coordinates from <code>JTable</code> to that of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * underlying model:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 *   int[] selection = table.getSelectedRows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 *   for (int i = 0; i &lt; selection.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 *     selection[i] = table.convertRowIndexToModel(selection[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 *   // selection is now in terms of the underlying TableModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * By default if sorting is enabled <code>JTable</code> will persist the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * selection and variable row heights in terms of the model on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * sorting.  For example if row 0, in terms of the underlying model,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * is currently selected, after the sort row 0, in terms of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * underlying model will be selected.  Visually the selection may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * change, but in terms of the underlying model it will remain the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * same.  The one exception to that is if the model index is no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * visible or was removed.  For example, if row 0 in terms of model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * was filtered out the selection will be empty after the sort.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * J2SE 5 adds methods to <code>JTable</code> to provide convenient access to some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * common printing needs. Simple new {@link #print()} methods allow for quick
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * and easy addition of printing support to your application. In addition, a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * {@link #getPrintable} method is available for more advanced printing needs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * As for all <code>JComponent</code> classes, you can use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * {@link InputMap} and {@link ActionMap} to associate an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * {@link Action} object with a {@link KeyStroke} and execute the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * action under specified conditions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
   204
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 *   attribute: isContainer false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 * description: A component which displays data in a two dimensional grid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 * @author Philip Milne
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 * @author Shannon Hickey (printing support)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 * @see javax.swing.table.DefaultTableModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 * @see javax.swing.table.TableRowSorter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
/* The first versions of the JTable, contained in Swing-0.1 through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 * Swing-0.4, were written by Alan Chung.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21982
diff changeset
   221
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
public class JTable extends JComponent implements TableModelListener, Scrollable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    TableColumnModelListener, ListSelectionListener, CellEditorListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    Accessible, RowSorterListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
// Static Constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    private static final String uiClassID = "TableUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /** Do not adjust column widths automatically; use a horizontal scrollbar instead. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public static final int     AUTO_RESIZE_OFF = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /** When a column is adjusted in the UI, adjust the next column the opposite way. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public static final int     AUTO_RESIZE_NEXT_COLUMN = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /** During UI adjustment, change subsequent columns to preserve the total width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
      * this is the default behavior. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public static final int     AUTO_RESIZE_SUBSEQUENT_COLUMNS = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /** During all resize operations, apply adjustments to the last column only. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public static final int     AUTO_RESIZE_LAST_COLUMN = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /** During all resize operations, proportionately resize all columns. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public static final int     AUTO_RESIZE_ALL_COLUMNS = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * Printing modes, used in printing <code>JTable</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @see #print(JTable.PrintMode, MessageFormat, MessageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *             boolean, PrintRequestAttributeSet, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @see #getPrintable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public enum PrintMode {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
         * Printing mode that prints the table at its current size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
         * spreading both columns and rows across multiple pages if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        NORMAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
         * Printing mode that scales the output smaller, if necessary,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
         * to fit the table's entire width (and thereby all columns) on each page;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
         * Rows are spread across multiple pages as necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        FIT_WIDTH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
// Instance Variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /** The <code>TableModel</code> of the table. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    protected TableModel        dataModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /** The <code>TableColumnModel</code> of the table. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    protected TableColumnModel  columnModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    /** The <code>ListSelectionModel</code> of the table, used to keep track of row selections. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    protected ListSelectionModel selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /** The <code>TableHeader</code> working with the table. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    protected JTableHeader      tableHeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /** The height in pixels of each row in the table. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    protected int               rowHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /** The height in pixels of the margin between the cells in each row. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    protected int               rowMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /** The color of the grid. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    protected Color             gridColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /** The table draws horizontal lines between cells if <code>showHorizontalLines</code> is true. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    protected boolean           showHorizontalLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    /** The table draws vertical lines between cells if <code>showVerticalLines</code> is true. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    protected boolean           showVerticalLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *  Determines if the table automatically resizes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *  width of the table's columns to take up the entire width of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *  table, and how it does the resizing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    protected int               autoResizeMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *  The table will query the <code>TableModel</code> to build the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *  set of columns if this is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    protected boolean           autoCreateColumnsFromModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /** Used by the <code>Scrollable</code> interface to determine the initial visible area. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    protected Dimension         preferredViewportSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    /** True if row selection is allowed in this table. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    protected boolean           rowSelectionAllowed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * Obsolete as of Java 2 platform v1.3.  Please use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * <code>rowSelectionAllowed</code> property and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * <code>columnSelectionAllowed</code> property of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * <code>columnModel</code> instead. Or use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * method <code>getCellSelectionEnabled</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * If true, both a row selection and a column selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * can be non-empty at the same time, the selected cells are the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * the cells whose row and column are both selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    protected boolean           cellSelectionEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    /** If editing, the <code>Component</code> that is handling the editing. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    transient protected Component       editorComp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * The active cell editor object, that overwrites the screen real estate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * occupied by the current cell and allows the user to change its contents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * {@code null} if the table isn't currently editing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    transient protected TableCellEditor cellEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    /** Identifies the column of the cell being edited. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    transient protected int             editingColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    /** Identifies the row of the cell being edited. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    transient protected int             editingRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * A table of objects that display the contents of a cell,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * indexed by class as declared in <code>getColumnClass</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * in the <code>TableModel</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    transient protected Hashtable defaultRenderersByColumnClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * A table of objects that display and edit the contents of a cell,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * indexed by class as declared in <code>getColumnClass</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * in the <code>TableModel</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    transient protected Hashtable defaultEditorsByColumnClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    /** The foreground color of selected cells. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    protected Color selectionForeground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    /** The background color of selected cells. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    protected Color selectionBackground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
// Private state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    // WARNING: If you directly access this field you should also change the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    // SortManager.modelRowSizes field as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    private SizeSequence rowModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    private boolean dragEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    private boolean surrendersFocusOnKeystroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    private PropertyChangeListener editorRemover = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * The last value of getValueIsAdjusting from the column selection models
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * columnSelectionChanged notification. Used to test if a repaint is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    private boolean columnSelectionAdjusting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * The last value of getValueIsAdjusting from the row selection models
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * valueChanged notification. Used to test if a repaint is needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    private boolean rowSelectionAdjusting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * To communicate errors between threads during printing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    private Throwable printError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * True when setRowHeight(int) has been invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    private boolean isRowHeightSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * If true, on a sort the selection is reset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    private boolean updateSelectionOnSort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * Information used in sorting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    private transient SortManager sortManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * If true, when sorterChanged is invoked it's value is ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    private boolean ignoreSortChange;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * Whether or not sorterChanged has been invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    private boolean sorterChanged;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * If true, any time the model changes a new RowSorter is set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    private boolean autoCreateRowSorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * Whether or not the table always fills the viewport height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @see #setFillsViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @see #getScrollableTracksViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    private boolean fillsViewportHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * The drop mode for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    private DropMode dropMode = DropMode.USE_SELECTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * The drop location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    private transient DropLocation dropLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * A subclass of <code>TransferHandler.DropLocation</code> representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * a drop location for a <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @see #getDropLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    public static final class DropLocation extends TransferHandler.DropLocation {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        private final int row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        private final int col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        private final boolean isInsertRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        private final boolean isInsertCol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        private DropLocation(Point p, int row, int col,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                             boolean isInsertRow, boolean isInsertCol) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            super(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            this.row = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            this.col = col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            this.isInsertRow = isInsertRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            this.isInsertCol = isInsertCol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
         * Returns the row index where a dropped item should be placed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
         * table. Interpretation of the value depends on the return of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
         * <code>isInsertRow()</code>. If that method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
         * <code>true</code> this value indicates the index where a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
         * row should be inserted. Otherwise, it represents the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
         * of an existing row on which the data was dropped. This index is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
         * in terms of the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
         * <code>-1</code> indicates that the drop occurred over empty space,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
         * and no row could be calculated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
         * @return the drop row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        public int getRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            return row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
         * Returns the column index where a dropped item should be placed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
         * table. Interpretation of the value depends on the return of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
         * <code>isInsertColumn()</code>. If that method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
         * <code>true</code> this value indicates the index where a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
         * column should be inserted. Otherwise, it represents the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
         * of an existing column on which the data was dropped. This index is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
         * in terms of the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
         * <code>-1</code> indicates that the drop occurred over empty space,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
         * and no column could be calculated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
         * @return the drop row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        public int getColumn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            return col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
         * Returns whether or not this location represents an insert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
         * of a row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
         * @return whether or not this is an insert row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        public boolean isInsertRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            return isInsertRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
         * Returns whether or not this location represents an insert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
         * of a column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
         * @return whether or not this is an insert column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        public boolean isInsertColumn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            return isInsertCol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
         * Returns a string representation of this drop location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
         * This method is intended to be used for debugging purposes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
         * and the content and format of the returned string may vary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
         * between implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
         * @return a string representation of this drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            return getClass().getName()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                   + "[dropPoint=" + getDropPoint() + ","
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                   + "row=" + row + ","
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                   + "column=" + col + ","
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                   + "insertRow=" + isInsertRow + ","
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                   + "insertColumn=" + isInsertCol + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
// Constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * Constructs a default <code>JTable</code> that is initialized with a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * data model, a default column model, and a default selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @see #createDefaultDataModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * @see #createDefaultColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * @see #createDefaultSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    public JTable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        this(null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * Constructs a <code>JTable</code> that is initialized with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * <code>dm</code> as the data model, a default column model,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * and a default selection model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * @param dm        the data model for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * @see #createDefaultColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * @see #createDefaultSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    public JTable(TableModel dm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        this(dm, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * Constructs a <code>JTable</code> that is initialized with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * <code>dm</code> as the data model, <code>cm</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * as the column model, and a default selection model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * @param dm        the data model for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * @param cm        the column model for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * @see #createDefaultSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    public JTable(TableModel dm, TableColumnModel cm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        this(dm, cm, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * Constructs a <code>JTable</code> that is initialized with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * <code>dm</code> as the data model, <code>cm</code> as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * column model, and <code>sm</code> as the selection model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * If any of the parameters are <code>null</code> this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * will initialize the table with the corresponding default model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * The <code>autoCreateColumnsFromModel</code> flag is set to false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * if <code>cm</code> is non-null, otherwise it is set to true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * and the column model is populated with suitable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * <code>TableColumns</code> for the columns in <code>dm</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * @param dm        the data model for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * @param cm        the column model for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * @param sm        the row selection model for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * @see #createDefaultDataModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * @see #createDefaultColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * @see #createDefaultSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    public JTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        setLayout(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                           JComponent.getManagingFocusForwardTraversalKeys());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                           JComponent.getManagingFocusBackwardTraversalKeys());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        if (cm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            cm = createDefaultColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            autoCreateColumnsFromModel = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        setColumnModel(cm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        if (sm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            sm = createDefaultSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        setSelectionModel(sm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    // Set the model last, that way if the autoCreatColumnsFromModel has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    // been set above, we will automatically populate an empty columnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    // with suitable columns for the new model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        if (dm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            dm = createDefaultDataModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        setModel(dm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        initializeLocalVars();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * Constructs a <code>JTable</code> with <code>numRows</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * and <code>numColumns</code> of empty cells using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * <code>DefaultTableModel</code>.  The columns will have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * names of the form "A", "B", "C", etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * @param numRows           the number of rows the table holds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * @param numColumns        the number of columns the table holds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * @see javax.swing.table.DefaultTableModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    public JTable(int numRows, int numColumns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        this(new DefaultTableModel(numRows, numColumns));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * Constructs a <code>JTable</code> to display the values in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * <code>Vector</code> of <code>Vectors</code>, <code>rowData</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * with column names, <code>columnNames</code>.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * <code>Vectors</code> contained in <code>rowData</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * should contain the values for that row. In other words,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * the value of the cell at row 1, column 5 can be obtained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * with the following code:
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 21278
diff changeset
   663
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * <pre>((Vector)rowData.elementAt(1)).elementAt(5);</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * @param rowData           the data for the new table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * @param columnNames       names of each column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    public JTable(Vector rowData, Vector columnNames) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        this(new DefaultTableModel(rowData, columnNames));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * Constructs a <code>JTable</code> to display the values in the two dimensional array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * <code>rowData</code>, with column names, <code>columnNames</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * <code>rowData</code> is an array of rows, so the value of the cell at row 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * column 5 can be obtained with the following code:
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 21278
diff changeset
   678
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * <pre> rowData[1][5]; </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * All rows must be of the same length as <code>columnNames</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * @param rowData           the data for the new table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * @param columnNames       names of each column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    public JTable(final Object[][] rowData, final Object[] columnNames) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        this(new AbstractTableModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            public String getColumnName(int column) { return columnNames[column].toString(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            public int getRowCount() { return rowData.length; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            public int getColumnCount() { return columnNames.length; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            public Object getValueAt(int row, int col) { return rowData[row][col]; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            public boolean isCellEditable(int row, int column) { return true; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            public void setValueAt(Object value, int row, int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                rowData[row][col] = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                fireTableCellUpdated(row, col);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * Calls the <code>configureEnclosingScrollPane</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * @see #configureEnclosingScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        super.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        configureEnclosingScrollPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * If this <code>JTable</code> is the <code>viewportView</code> of an enclosing <code>JScrollPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * (the usual situation), configure this <code>ScrollPane</code> by, amongst other things,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * installing the table's <code>tableHeader</code> as the <code>columnHeaderView</code> of the scroll pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * When a <code>JTable</code> is added to a <code>JScrollPane</code> in the usual way,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * using <code>new JScrollPane(myTable)</code>, <code>addNotify</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * called in the <code>JTable</code> (when the table is added to the viewport).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * <code>JTable</code>'s <code>addNotify</code> method in turn calls this method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * which is protected so that this default installation procedure can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * be overridden by a subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * @see #addNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    protected void configureEnclosingScrollPane() {
5449
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
   724
        Container parent = SwingUtilities.getUnwrappedParent(this);
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
   725
        if (parent instanceof JViewport) {
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
   726
            JViewport port = (JViewport) parent;
3737
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 2658
diff changeset
   727
            Container gp = port.getParent();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            if (gp instanceof JScrollPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                JScrollPane scrollPane = (JScrollPane)gp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                // Make certain we are the viewPort's view and not, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                // example, the rowHeaderView of the scrollPane -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                // an implementor of fixed columns might do this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                JViewport viewport = scrollPane.getViewport();
4278
b7a976422d27 6878399: public SwingUtilities.getParentViewport() is required
alexp
parents: 4272
diff changeset
   734
                if (viewport == null ||
b7a976422d27 6878399: public SwingUtilities.getParentViewport() is required
alexp
parents: 4272
diff changeset
   735
                        SwingUtilities.getUnwrappedView(viewport) != this) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                scrollPane.setColumnHeaderView(getTableHeader());
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   739
                // configure the scrollpane for any LAF dependent settings
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   740
                configureEnclosingScrollPaneUI();
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
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   745
    /**
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   746
     * This is a sub-part of configureEnclosingScrollPane() that configures
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   747
     * anything on the scrollpane that may change when the look and feel
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   748
     * changes. It needed to be split out from configureEnclosingScrollPane() so
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   749
     * that it can be called from updateUI() when the LAF changes without
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   750
     * causing the regression found in bug 6687962. This was because updateUI()
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   751
     * is called from the constructor which then caused
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   752
     * configureEnclosingScrollPane() to be called by the constructor which
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   753
     * changes its contract for any subclass that overrides it. So by splitting
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   754
     * it out in this way configureEnclosingScrollPaneUI() can be called both
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   755
     * from configureEnclosingScrollPane() and updateUI() in a safe manor.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   756
     */
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   757
    private void configureEnclosingScrollPaneUI() {
5449
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
   758
        Container parent = SwingUtilities.getUnwrappedParent(this);
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
   759
        if (parent instanceof JViewport) {
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
   760
            JViewport port = (JViewport) parent;
3737
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 2658
diff changeset
   761
            Container gp = port.getParent();
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   762
            if (gp instanceof JScrollPane) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   763
                JScrollPane scrollPane = (JScrollPane)gp;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   764
                // Make certain we are the viewPort's view and not, for
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   765
                // example, the rowHeaderView of the scrollPane -
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   766
                // an implementor of fixed columns might do this.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   767
                JViewport viewport = scrollPane.getViewport();
4278
b7a976422d27 6878399: public SwingUtilities.getParentViewport() is required
alexp
parents: 4272
diff changeset
   768
                if (viewport == null ||
b7a976422d27 6878399: public SwingUtilities.getParentViewport() is required
alexp
parents: 4272
diff changeset
   769
                        SwingUtilities.getUnwrappedView(viewport) != this) {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   770
                    return;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   771
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                //  scrollPane.getViewport().setBackingStoreEnabled(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                Border border = scrollPane.getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                if (border == null || border instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                    Border scrollPaneBorder =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                        UIManager.getBorder("Table.scrollPaneBorder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                    if (scrollPaneBorder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                        scrollPane.setBorder(scrollPaneBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                }
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   781
                // 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
   782
                Component corner =
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   783
                        scrollPane.getCorner(JScrollPane.UPPER_TRAILING_CORNER);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   784
                if (corner == null || corner instanceof UIResource){
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   785
                    corner = null;
16088
8edf3fb360ea 7200491: Tighten up JTable layout code
rupashka
parents: 13546
diff changeset
   786
                    try {
8edf3fb360ea 7200491: Tighten up JTable layout code
rupashka
parents: 13546
diff changeset
   787
                        corner = (Component) UIManager.get(
8edf3fb360ea 7200491: Tighten up JTable layout code
rupashka
parents: 13546
diff changeset
   788
                                "Table.scrollPaneCornerComponent");
8edf3fb360ea 7200491: Tighten up JTable layout code
rupashka
parents: 13546
diff changeset
   789
                    } catch (Exception e) {
8edf3fb360ea 7200491: Tighten up JTable layout code
rupashka
parents: 13546
diff changeset
   790
                        // just ignore and don't set corner
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   791
                    }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   792
                    scrollPane.setCorner(JScrollPane.UPPER_TRAILING_CORNER,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   793
                            corner);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   794
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * Calls the <code>unconfigureEnclosingScrollPane</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * @see #unconfigureEnclosingScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    public void removeNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            removePropertyChangeListener("permanentFocusOwner", editorRemover);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        editorRemover = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        unconfigureEnclosingScrollPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        super.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * Reverses the effect of <code>configureEnclosingScrollPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * by replacing the <code>columnHeaderView</code> of the enclosing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * scroll pane with <code>null</code>. <code>JTable</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * <code>removeNotify</code> method calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * this method, which is protected so that this default uninstallation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * procedure can be overridden by a subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * @see #removeNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * @see #configureEnclosingScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    protected void unconfigureEnclosingScrollPane() {
5449
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
   825
        Container parent = SwingUtilities.getUnwrappedParent(this);
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
   826
        if (parent instanceof JViewport) {
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
   827
            JViewport port = (JViewport) parent;
3737
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 2658
diff changeset
   828
            Container gp = port.getParent();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            if (gp instanceof JScrollPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                JScrollPane scrollPane = (JScrollPane)gp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                // Make certain we are the viewPort's view and not, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                // example, the rowHeaderView of the scrollPane -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                // an implementor of fixed columns might do this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                JViewport viewport = scrollPane.getViewport();
4278
b7a976422d27 6878399: public SwingUtilities.getParentViewport() is required
alexp
parents: 4272
diff changeset
   835
                if (viewport == null ||
b7a976422d27 6878399: public SwingUtilities.getParentViewport() is required
alexp
parents: 4272
diff changeset
   836
                        SwingUtilities.getUnwrappedView(viewport) != this) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                scrollPane.setColumnHeaderView(null);
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   840
                // remove ScrollPane corner if one was added by the LAF
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   841
                Component corner =
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   842
                        scrollPane.getCorner(JScrollPane.UPPER_TRAILING_CORNER);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   843
                if (corner instanceof UIResource){
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   844
                    scrollPane.setCorner(JScrollPane.UPPER_TRAILING_CORNER,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   845
                            null);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
   846
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    void setUIProperty(String propertyName, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        if (propertyName == "rowHeight") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            if (!isRowHeightSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                setRowHeight(((Number)value).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                isRowHeightSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        super.setUIProperty(propertyName, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
// Static Methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * Equivalent to <code>new JScrollPane(aTable)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * @deprecated As of Swing version 1.0.2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * replaced by <code>new JScrollPane(aTable)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    static public JScrollPane createScrollPaneForTable(JTable aTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        return new JScrollPane(aTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
// Table Attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * Sets the <code>tableHeader</code> working with this <code>JTable</code> to <code>newHeader</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * It is legal to have a <code>null</code> <code>tableHeader</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * @param   tableHeader                       new tableHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * @see     #getTableHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     *  description: The JTableHeader instance which renders the column headers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    public void setTableHeader(JTableHeader tableHeader) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        if (this.tableHeader != tableHeader) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            JTableHeader old = this.tableHeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            // Release the old header
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            if (old != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                old.setTable(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            this.tableHeader = tableHeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            if (tableHeader != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                tableHeader.setTable(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            firePropertyChange("tableHeader", old, tableHeader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * Returns the <code>tableHeader</code> used by this <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * @return  the <code>tableHeader</code> used by this table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * @see     #setTableHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    public JTableHeader getTableHeader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        return tableHeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * Sets the height, in pixels, of all cells to <code>rowHeight</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * revalidates, and repaints.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * The height of the cells will be equal to the row height minus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * the row margin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * @param   rowHeight                       new row height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * @exception IllegalArgumentException      if <code>rowHeight</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     *                                          less than 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * @see     #getRowHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     *  description: The height of the specified row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    public void setRowHeight(int rowHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        if (rowHeight <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            throw new IllegalArgumentException("New row height less than 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        int old = this.rowHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        this.rowHeight = rowHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        rowModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        if (sortManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            sortManager.modelRowSizes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        isRowHeightSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        firePropertyChange("rowHeight", old, rowHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * Returns the height of a table row, in pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * @return  the height in pixels of a table row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * @see     #setRowHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    public int getRowHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        return rowHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    private SizeSequence getRowModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        if (rowModel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            rowModel = new SizeSequence(getRowCount(), getRowHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        return rowModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * Sets the height for <code>row</code> to <code>rowHeight</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     * revalidates, and repaints. The height of the cells in this row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     * will be equal to the row height minus the row margin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     * @param   row                             the row whose height is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                                                changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * @param   rowHeight                       new row height, in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     * @exception IllegalArgumentException      if <code>rowHeight</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     *                                          less than 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     *  description: The height in pixels of the cells in <code>row</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    public void setRowHeight(int row, int rowHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        if (rowHeight <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            throw new IllegalArgumentException("New row height less than 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        getRowModel().setSize(row, rowHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        if (sortManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
            sortManager.setViewRowHeight(row, rowHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * Returns the height, in pixels, of the cells in <code>row</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * @param   row              the row whose height is to be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * @return the height, in pixels, of the cells in the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
    public int getRowHeight(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        return (rowModel == null) ? getRowHeight() : rowModel.getSize(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * Sets the amount of empty space between cells in adjacent rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * @param  rowMargin  the number of pixels between cells in a row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * @see     #getRowMargin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     *  description: The amount of space between cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    public void setRowMargin(int rowMargin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        int old = this.rowMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        this.rowMargin = rowMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        firePropertyChange("rowMargin", old, rowMargin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * Gets the amount of empty space, in pixels, between cells. Equivalent to:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * <code>getIntercellSpacing().height</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * @return the number of pixels between cells in a row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * @see     #setRowMargin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    public int getRowMargin() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        return rowMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * Sets the <code>rowMargin</code> and the <code>columnMargin</code> --
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * the height and width of the space between cells -- to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * <code>intercellSpacing</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * @param   intercellSpacing        a <code>Dimension</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     *                                  specifying the new width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     *                                  and height between cells
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * @see     #getIntercellSpacing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     *  description: The spacing between the cells,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     *               drawn in the background color of the JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    public void setIntercellSpacing(Dimension intercellSpacing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        // Set the rowMargin here and columnMargin in the TableColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        setRowMargin(intercellSpacing.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        getColumnModel().setColumnMargin(intercellSpacing.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * Returns the horizontal and vertical space between cells.
5956
e30f106a4b8b 6937415: Some components return undocumented default values under Nimbus LaF
alexp
parents: 5597
diff changeset
  1048
     * The default spacing is look and feel dependent.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     * @return  the horizontal and vertical spacing between cells
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     * @see     #setIntercellSpacing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    public Dimension getIntercellSpacing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        return new Dimension(getColumnModel().getColumnMargin(), rowMargin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     * Sets the color used to draw grid lines to <code>gridColor</code> and redisplays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     * The default color is look and feel dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     * @param   gridColor                       the new color of the grid lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * @exception IllegalArgumentException      if <code>gridColor</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * @see     #getGridColor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     *  description: The grid color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
    public void setGridColor(Color gridColor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        if (gridColor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
            throw new IllegalArgumentException("New color is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        Color old = this.gridColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        this.gridColor = gridColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        firePropertyChange("gridColor", old, gridColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        // Redraw
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     * Returns the color used to draw grid lines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     * The default color is look and feel dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     * @return  the color used to draw grid lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     * @see     #setGridColor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
    public Color getGridColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        return gridColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     *  Sets whether the table draws grid lines around cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     *  If <code>showGrid</code> is true it does; if it is false it doesn't.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     *  There is no <code>getShowGrid</code> method as this state is held
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
     *  in two variables -- <code>showHorizontalLines</code> and <code>showVerticalLines</code> --
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     *  each of which can be queried independently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     * @param   showGrid                 true if table view should draw grid lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     * @see     #setShowVerticalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     * @see     #setShowHorizontalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     *  description: The color used to draw the grid lines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    public void setShowGrid(boolean showGrid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        setShowHorizontalLines(showGrid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        setShowVerticalLines(showGrid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        // Redraw
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     *  Sets whether the table draws horizontal lines between cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     *  If <code>showHorizontalLines</code> is true it does; if it is false it doesn't.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     * @param   showHorizontalLines      true if table view should draw horizontal lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     * @see     #getShowHorizontalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     * @see     #setShowGrid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     * @see     #setShowVerticalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
     *  description: Whether horizontal lines should be drawn in between the cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
    public void setShowHorizontalLines(boolean showHorizontalLines) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        boolean old = this.showHorizontalLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        this.showHorizontalLines = showHorizontalLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        firePropertyChange("showHorizontalLines", old, showHorizontalLines);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        // Redraw
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     *  Sets whether the table draws vertical lines between cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     *  If <code>showVerticalLines</code> is true it does; if it is false it doesn't.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * @param   showVerticalLines              true if table view should draw vertical lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     * @see     #getShowVerticalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     * @see     #setShowGrid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * @see     #setShowHorizontalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     *  description: Whether vertical lines should be drawn in between the cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
    public void setShowVerticalLines(boolean showVerticalLines) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        boolean old = this.showVerticalLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        this.showVerticalLines = showVerticalLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        firePropertyChange("showVerticalLines", old, showVerticalLines);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        // Redraw
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     * Returns true if the table draws horizontal lines between cells, false if it
5956
e30f106a4b8b 6937415: Some components return undocumented default values under Nimbus LaF
alexp
parents: 5597
diff changeset
  1155
     * doesn't. The default value is look and feel dependent.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     * @return  true if the table draws horizontal lines between cells, false if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     *          doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     * @see     #setShowHorizontalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    public boolean getShowHorizontalLines() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        return showHorizontalLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     * Returns true if the table draws vertical lines between cells, false if it
5956
e30f106a4b8b 6937415: Some components return undocumented default values under Nimbus LaF
alexp
parents: 5597
diff changeset
  1167
     * doesn't. The default value is look and feel dependent.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     * @return  true if the table draws vertical lines between cells, false if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     *          doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * @see     #setShowVerticalLines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
    public boolean getShowVerticalLines() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        return showVerticalLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     * Sets the table's auto resize mode when the table is resized.  For further
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     * information on how the different resize modes work, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     * {@link #doLayout}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     * @param   mode One of 5 legal values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     *                   AUTO_RESIZE_OFF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     *                   AUTO_RESIZE_NEXT_COLUMN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     *                   AUTO_RESIZE_SUBSEQUENT_COLUMNS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     *                   AUTO_RESIZE_LAST_COLUMN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     *                   AUTO_RESIZE_ALL_COLUMNS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     * @see     #getAutoResizeMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     * @see     #doLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     *  description: Whether the columns should adjust themselves automatically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     *        enum: AUTO_RESIZE_OFF                JTable.AUTO_RESIZE_OFF
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     *              AUTO_RESIZE_NEXT_COLUMN        JTable.AUTO_RESIZE_NEXT_COLUMN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     *              AUTO_RESIZE_SUBSEQUENT_COLUMNS JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     *              AUTO_RESIZE_LAST_COLUMN        JTable.AUTO_RESIZE_LAST_COLUMN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     *              AUTO_RESIZE_ALL_COLUMNS        JTable.AUTO_RESIZE_ALL_COLUMNS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
    public void setAutoResizeMode(int mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        if ((mode == AUTO_RESIZE_OFF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
            (mode == AUTO_RESIZE_NEXT_COLUMN) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            (mode == AUTO_RESIZE_SUBSEQUENT_COLUMNS) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
            (mode == AUTO_RESIZE_LAST_COLUMN) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            (mode == AUTO_RESIZE_ALL_COLUMNS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            int old = autoResizeMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            autoResizeMode = mode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            if (tableHeader != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
                tableHeader.resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
            firePropertyChange("autoResizeMode", old, autoResizeMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
     * Returns the auto resize mode of the table.  The default mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     * is AUTO_RESIZE_SUBSEQUENT_COLUMNS.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
     * @return  the autoResizeMode of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
     * @see     #setAutoResizeMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
     * @see     #doLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
    public int getAutoResizeMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        return autoResizeMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     * Sets this table's <code>autoCreateColumnsFromModel</code> flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * This method calls <code>createDefaultColumnsFromModel</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     * <code>autoCreateColumnsFromModel</code> changes from false to true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * @param   autoCreateColumnsFromModel   true if <code>JTable</code> should automatically create columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     * @see     #getAutoCreateColumnsFromModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     * @see     #createDefaultColumnsFromModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     *  description: Automatically populates the columnModel when a new TableModel is submitted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
    public void setAutoCreateColumnsFromModel(boolean autoCreateColumnsFromModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        if (this.autoCreateColumnsFromModel != autoCreateColumnsFromModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
            boolean old = this.autoCreateColumnsFromModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            this.autoCreateColumnsFromModel = autoCreateColumnsFromModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
            if (autoCreateColumnsFromModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                createDefaultColumnsFromModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
            firePropertyChange("autoCreateColumnsFromModel", old, autoCreateColumnsFromModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
     * Determines whether the table will create default columns from the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
     * If true, <code>setModel</code> will clear any existing columns and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
     * create new columns from the new model.  Also, if the event in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     * the <code>tableChanged</code> notification specifies that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     * entire table changed, then the columns will be rebuilt.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     * The default is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     * @return  the autoCreateColumnsFromModel of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     * @see     #setAutoCreateColumnsFromModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     * @see     #createDefaultColumnsFromModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
    public boolean getAutoCreateColumnsFromModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
        return autoCreateColumnsFromModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     * Creates default columns for the table from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     * the data model using the <code>getColumnCount</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     * defined in the <code>TableModel</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     * Clears any existing columns before creating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
     * new columns based on information from the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     * @see     #getAutoCreateColumnsFromModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    public void createDefaultColumnsFromModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        TableModel m = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        if (m != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            // Remove any current columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            TableColumnModel cm = getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            while (cm.getColumnCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                cm.removeColumn(cm.getColumn(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            // Create new columns from the data model info
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            for (int i = 0; i < m.getColumnCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                TableColumn newColumn = new TableColumn(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                addColumn(newColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     * Sets a default cell renderer to be used if no renderer has been set in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
     * a <code>TableColumn</code>. If renderer is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     * removes the default renderer for this column class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * @param  columnClass     set the default cell renderer for this columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     * @param  renderer        default cell renderer to be used for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
     *                         columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
     * @see     #getDefaultRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
     * @see     #setDefaultEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
    public void setDefaultRenderer(Class<?> columnClass, TableCellRenderer renderer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        if (renderer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            defaultRenderersByColumnClass.put(columnClass, renderer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            defaultRenderersByColumnClass.remove(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
     * Returns the cell renderer to be used when no renderer has been set in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
     * a <code>TableColumn</code>. During the rendering of cells the renderer is fetched from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
     * a <code>Hashtable</code> of entries according to the class of the cells in the column. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
     * there is no entry for this <code>columnClass</code> the method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
     * the entry for the most specific superclass. The <code>JTable</code> installs entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
     * for <code>Object</code>, <code>Number</code>, and <code>Boolean</code>, all of which can be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
     * or replaced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     * @param   columnClass   return the default cell renderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
     *                        for this columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
     * @return  the renderer for this columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
     * @see     #setDefaultRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
     * @see     #getColumnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
    public TableCellRenderer getDefaultRenderer(Class<?> columnClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        if (columnClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
            Object renderer = defaultRenderersByColumnClass.get(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
            if (renderer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                return (TableCellRenderer)renderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
            else {
4379
ce28939f55fc 6888156: With GTK Look and Feel Icons cannot be rendered in Jtable Cells
peterz
parents: 4278
diff changeset
  1340
                Class c = columnClass.getSuperclass();
ce28939f55fc 6888156: With GTK Look and Feel Icons cannot be rendered in Jtable Cells
peterz
parents: 4278
diff changeset
  1341
                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
  1342
                    c = Object.class;
ce28939f55fc 6888156: With GTK Look and Feel Icons cannot be rendered in Jtable Cells
peterz
parents: 4278
diff changeset
  1343
                }
ce28939f55fc 6888156: With GTK Look and Feel Icons cannot be rendered in Jtable Cells
peterz
parents: 4278
diff changeset
  1344
                return getDefaultRenderer(c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
     * Sets a default cell editor to be used if no editor has been set in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
     * a <code>TableColumn</code>. If no editing is required in a table, or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
     * particular column in a table, uses the <code>isCellEditable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
     * method in the <code>TableModel</code> interface to ensure that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
     * <code>JTable</code> will not start an editor in these columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     * If editor is <code>null</code>, removes the default editor for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     * column class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     * @param  columnClass  set the default cell editor for this columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
     * @param  editor   default cell editor to be used for this columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
     * @see     TableModel#isCellEditable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
     * @see     #getDefaultEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
     * @see     #setDefaultRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
    public void setDefaultEditor(Class<?> columnClass, TableCellEditor editor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        if (editor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
            defaultEditorsByColumnClass.put(columnClass, editor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
            defaultEditorsByColumnClass.remove(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
     * Returns the editor to be used when no editor has been set in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
     * a <code>TableColumn</code>. During the editing of cells the editor is fetched from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
     * a <code>Hashtable</code> of entries according to the class of the cells in the column. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
     * there is no entry for this <code>columnClass</code> the method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
     * the entry for the most specific superclass. The <code>JTable</code> installs entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
     * for <code>Object</code>, <code>Number</code>, and <code>Boolean</code>, all of which can be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
     * or replaced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
     * @param   columnClass  return the default cell editor for this columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
     * @return the default cell editor to be used for this columnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
     * @see     #setDefaultEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
     * @see     #getColumnClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
    public TableCellEditor getDefaultEditor(Class<?> columnClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        if (columnClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
            Object editor = defaultEditorsByColumnClass.get(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
            if (editor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                return (TableCellEditor)editor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
                return getDefaultEditor(columnClass.getSuperclass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
     * Turns on or off automatic drag handling. In order to enable automatic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     * drag handling, this property should be set to {@code true}, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     * table's {@code TransferHandler} needs to be {@code non-null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     * The default value of the {@code dragEnabled} property is {@code false}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     * The job of honoring this property, and recognizing a user drag gesture,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     * lies with the look and feel implementation, and in particular, the table's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     * {@code TableUI}. When automatic drag handling is enabled, most look and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     * feels (including those that subclass {@code BasicLookAndFeel}) begin a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     * drag and drop operation whenever the user presses the mouse button over
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     * an item (in single selection mode) or a selection (in other selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     * modes) and then moves the mouse a few pixels. Setting this property to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     * {@code true} can therefore have a subtle effect on how selections behave.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     * If a look and feel is used that ignores this property, you can still
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
     * begin a drag and drop operation by calling {@code exportAsDrag} on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
     * table's {@code TransferHandler}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     * @param b whether or not to enable automatic drag handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     *            <code>b</code> is <code>true</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     *            <code>GraphicsEnvironment.isHeadless()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     *            returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
     * @see #getDragEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
     * @see #setTransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
     * @see TransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
     *  description: determines whether automatic drag handling is enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
     *        bound: false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
    public void setDragEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
        if (b && GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
            throw new HeadlessException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
        dragEnabled = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
     * Returns whether or not automatic drag handling is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
     * @return the value of the {@code dragEnabled} property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
     * @see #setDragEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
    public boolean getDragEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        return dragEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
     * Sets the drop mode for this component. For backward compatibility,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
     * the default for this property is <code>DropMode.USE_SELECTION</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
     * Usage of one of the other modes is recommended, however, for an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
     * improved user experience. <code>DropMode.ON</code>, for instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
     * offers similar behavior of showing items as selected, but does so without
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
     * affecting the actual selection in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
     * <code>JTable</code> supports the following drop modes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
     *    <li><code>DropMode.USE_SELECTION</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
     *    <li><code>DropMode.ON</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
     *    <li><code>DropMode.INSERT</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
     *    <li><code>DropMode.INSERT_ROWS</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
     *    <li><code>DropMode.INSERT_COLS</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
     *    <li><code>DropMode.ON_OR_INSERT</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
     *    <li><code>DropMode.ON_OR_INSERT_ROWS</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
     *    <li><code>DropMode.ON_OR_INSERT_COLS</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
     * The drop mode is only meaningful if this component has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     * <code>TransferHandler</code> that accepts drops.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
     * @param dropMode the drop mode to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
     * @throws IllegalArgumentException if the drop mode is unsupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
     *         or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
     * @see #getDropMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
     * @see #getDropLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
     * @see #setTransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
     * @see TransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
    public final void setDropMode(DropMode dropMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
        if (dropMode != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
            switch (dropMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
                case USE_SELECTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
                case ON:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
                case INSERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
                case INSERT_ROWS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
                case INSERT_COLS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                case ON_OR_INSERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
                case ON_OR_INSERT_ROWS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
                case ON_OR_INSERT_COLS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
                    this.dropMode = dropMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
        throw new IllegalArgumentException(dropMode + ": Unsupported drop mode for table");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
     * Returns the drop mode for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
     * @return the drop mode for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
     * @see #setDropMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
    public final DropMode getDropMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
        return dropMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
     * Calculates a drop location in this component, representing where a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
     * drop at the given point should insert data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
     * @param p the point to calculate a drop location for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
     * @return the drop location, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
    DropLocation dropLocationForPoint(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
        DropLocation location = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
        int row = rowAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
        int col = columnAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
        boolean outside = Boolean.TRUE == getClientProperty("Table.isFileList")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
                          && SwingUtilities2.pointOutsidePrefSize(this, row, col, p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
        Rectangle rect = getCellRect(row, col, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
        Section xSection, ySection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
        boolean between = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
        boolean ltr = getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
        switch(dropMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
            case USE_SELECTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
            case ON:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
                if (row == -1 || col == -1 || outside) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
                    location = new DropLocation(p, -1, -1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                    location = new DropLocation(p, row, col, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
            case INSERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
                if (row == -1 && col == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
                    location = new DropLocation(p, 0, 0, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
                xSection = SwingUtilities2.liesInHorizontal(rect, p, ltr, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
                if (row == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
                    if (xSection == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                        location = new DropLocation(p, getRowCount(), col, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                    } else if (xSection == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
                        location = new DropLocation(p, getRowCount(), col + 1, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                        location = new DropLocation(p, getRowCount(), col, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                } else if (xSection == LEADING || xSection == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
                    ySection = SwingUtilities2.liesInVertical(rect, p, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
                    if (ySection == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
                        between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                    } else if (ySection == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
                        row++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                        between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
                    location = new DropLocation(p, row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                                                xSection == TRAILING ? col + 1 : col,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
                                                between, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
                    if (SwingUtilities2.liesInVertical(rect, p, false) == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
                        row++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
                    location = new DropLocation(p, row, col, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
            case INSERT_ROWS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
                if (row == -1 && col == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                    location = new DropLocation(p, -1, -1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
                if (row == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
                    location = new DropLocation(p, getRowCount(), col, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
                if (SwingUtilities2.liesInVertical(rect, p, false) == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
                    row++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
                location = new DropLocation(p, row, col, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
            case ON_OR_INSERT_ROWS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                if (row == -1 && col == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                    location = new DropLocation(p, -1, -1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
                if (row == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
                    location = new DropLocation(p, getRowCount(), col, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
                ySection = SwingUtilities2.liesInVertical(rect, p, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
                if (ySection == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
                    between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
                } else if (ySection == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
                    row++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
                    between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
                location = new DropLocation(p, row, col, between, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
            case INSERT_COLS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
                if (row == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
                    location = new DropLocation(p, -1, -1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
                if (col == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
                    location = new DropLocation(p, getColumnCount(), col, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
                if (SwingUtilities2.liesInHorizontal(rect, p, ltr, false) == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
                    col++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
                location = new DropLocation(p, row, col, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
            case ON_OR_INSERT_COLS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
                if (row == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
                    location = new DropLocation(p, -1, -1, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
                if (col == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
                    location = new DropLocation(p, row, getColumnCount(), false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
                xSection = SwingUtilities2.liesInHorizontal(rect, p, ltr, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
                if (xSection == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
                    between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
                } else if (xSection == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
                    col++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
                    between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
                location = new DropLocation(p, row, col, false, between);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
            case ON_OR_INSERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
                if (row == -1 && col == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
                    location = new DropLocation(p, 0, 0, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
                xSection = SwingUtilities2.liesInHorizontal(rect, p, ltr, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
                if (row == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
                    if (xSection == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
                        location = new DropLocation(p, getRowCount(), col, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
                    } else if (xSection == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
                        location = new DropLocation(p, getRowCount(), col + 1, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
                        location = new DropLocation(p, getRowCount(), col, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
                ySection = SwingUtilities2.liesInVertical(rect, p, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
                if (ySection == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
                    between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                } else if (ySection == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                    row++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
                    between = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
                location = new DropLocation(p, row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
                                            xSection == TRAILING ? col + 1 : col,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
                                            between,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
                                            xSection != MIDDLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
                assert false : "Unexpected drop mode";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
        return location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
     * Called to set or clear the drop location during a DnD operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
     * In some cases, the component may need to use it's internal selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
     * temporarily to indicate the drop location. To help facilitate this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
     * this method returns and accepts as a parameter a state object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
     * This state object can be used to store, and later restore, the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
     * state. Whatever this method returns will be passed back to it in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
     * future calls, as the state parameter. If it wants the DnD system to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
     * continue storing the same state, it must pass it back every time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
     * Here's how this is used:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
     * Let's say that on the first call to this method the component decides
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
     * to save some state (because it is about to use the selection to show
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
     * a drop index). It can return a state object to the caller encapsulating
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
     * any saved selection state. On a second call, let's say the drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
     * is being changed to something else. The component doesn't need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
     * restore anything yet, so it simply passes back the same state object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
     * to have the DnD system continue storing it. Finally, let's say this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
     * method is messaged with <code>null</code>. This means DnD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
     * is finished with this component for now, meaning it should restore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
     * state. At this point, it can use the state parameter to restore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
     * said state, and of course return <code>null</code> since there's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
     * no longer anything to store.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
     * @param location the drop location (as calculated by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
     *        <code>dropLocationForPoint</code>) or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
     *        if there's no longer a valid drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
     * @param state the state object saved earlier for this component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
     *        or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
     * @param forDrop whether or not the method is being called because an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
     *        actual drop occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
     * @return any saved state for this component, or <code>null</code> if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
    Object setDropLocation(TransferHandler.DropLocation location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
                           Object state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
                           boolean forDrop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
        Object retVal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        DropLocation tableLocation = (DropLocation)location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
        if (dropMode == DropMode.USE_SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
            if (tableLocation == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
                if (!forDrop && state != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
                    clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1744
                    int[] rows = ((int[][])state)[0];
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1745
                    int[] cols = ((int[][])state)[1];
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1746
                    int[] anchleads = ((int[][])state)[2];
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1747
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1748
                    for (int row : rows) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1749
                        addRowSelectionInterval(row, row);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1752
                    for (int col : cols) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1753
                        addColumnSelectionInterval(col, col);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
                    SwingUtilities2.setLeadAnchorWithoutSelection(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
                            getSelectionModel(), anchleads[1], anchleads[0]);
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
                            getColumnModel().getSelectionModel(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
                            anchleads[3], anchleads[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
                if (dropLocation == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
                    retVal = new int[][]{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
                        getSelectedRows(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
                        getSelectedColumns(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
                        {getAdjustedIndex(getSelectionModel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
                             .getAnchorSelectionIndex(), true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
                         getAdjustedIndex(getSelectionModel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
                             .getLeadSelectionIndex(), true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
                         getAdjustedIndex(getColumnModel().getSelectionModel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
                             .getAnchorSelectionIndex(), false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
                         getAdjustedIndex(getColumnModel().getSelectionModel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
                             .getLeadSelectionIndex(), false)}};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
                    retVal = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
                if (tableLocation.getRow() == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
                    clearSelectionAndLeadAnchor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
                    setRowSelectionInterval(tableLocation.getRow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
                                            tableLocation.getRow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
                    setColumnSelectionInterval(tableLocation.getColumn(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
                                               tableLocation.getColumn());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
        DropLocation old = dropLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
        dropLocation = tableLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
        firePropertyChange("dropLocation", old, dropLocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
        return retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
     * Returns the location that this component should visually indicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
     * as the drop location during a DnD operation over the component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
     * or {@code null} if no location is to currently be shown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
     * This method is not meant for querying the drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
     * from a {@code TransferHandler}, as the drop location is only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
     * set after the {@code TransferHandler}'s <code>canImport</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
     * has returned and has allowed for the location to be shown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
     * When this property changes, a property change event with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
     * name "dropLocation" is fired by the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
     * @return the drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
     * @see #setDropMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
     * @see TransferHandler#canImport(TransferHandler.TransferSupport)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
    public final DropLocation getDropLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
        return dropLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
     * Specifies whether a {@code RowSorter} should be created for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
     * table whenever its model changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
     * When {@code setAutoCreateRowSorter(true)} is invoked, a {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
     * TableRowSorter} is immediately created and installed on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
     * table.  While the {@code autoCreateRowSorter} property remains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
     * {@code true}, every time the model is changed, a new {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
     * TableRowSorter} is created and set as the table's row sorter.
10868
d134ad3bc135 7100004: javax.swing.JTable.setAutoCreateRowSorter(boolean autoCreateRowSorter) should mention default value
rupashka
parents: 6836
diff changeset
  1829
     * The default value for the {@code autoCreateRowSorter}
d134ad3bc135 7100004: javax.swing.JTable.setAutoCreateRowSorter(boolean autoCreateRowSorter) should mention default value
rupashka
parents: 6836
diff changeset
  1830
     * property is {@code false}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
     * @param autoCreateRowSorter whether or not a {@code RowSorter}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
     *        should be automatically created
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
     * @see javax.swing.table.TableRowSorter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
     *  description: Whether or not to turn on sorting by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
    public void setAutoCreateRowSorter(boolean autoCreateRowSorter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
        boolean oldValue = this.autoCreateRowSorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
        this.autoCreateRowSorter = autoCreateRowSorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
        if (autoCreateRowSorter) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1845
            setRowSorter(new TableRowSorter<TableModel>(getModel()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
        firePropertyChange("autoCreateRowSorter", oldValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
                           autoCreateRowSorter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
     * Returns {@code true} if whenever the model changes, a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
     * {@code RowSorter} should be created and installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
     * as the table's sorter; otherwise, returns {@code false}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
     * @return true if a {@code RowSorter} should be created when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
     *         the model changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
    public boolean getAutoCreateRowSorter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
        return autoCreateRowSorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
     * Specifies whether the selection should be updated after sorting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
     * If true, on sorting the selection is reset such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
     * the same rows, in terms of the model, remain selected.  The default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
     * is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
     * @param update whether or not to update the selection on sorting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
     *       expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
     *  description: Whether or not to update the selection on sorting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
    public void setUpdateSelectionOnSort(boolean update) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
        if (updateSelectionOnSort != update) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
            updateSelectionOnSort = update;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
            firePropertyChange("updateSelectionOnSort", !update, update);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
     * Returns true if the selection should be updated after sorting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
     * @return whether to update the selection on a sort
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
    public boolean getUpdateSelectionOnSort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
        return updateSelectionOnSort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
     * Sets the <code>RowSorter</code>.  <code>RowSorter</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
     * to provide sorting and filtering to a <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
     * This method clears the selection and resets any variable row heights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
     * This method fires a <code>PropertyChangeEvent</code> when appropriate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
     * with the property name <code>"rowSorter"</code>.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
     * backward-compatibility, this method fires an additional event with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
     * property name <code>"sorter"</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
     * If the underlying model of the <code>RowSorter</code> differs from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
     * that of this <code>JTable</code> undefined behavior will result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
     * @param sorter the <code>RowSorter</code>; <code>null</code> turns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
     *        sorting off
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
     * @see javax.swing.table.TableRowSorter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
     *  description: The table's RowSorter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
    public void setRowSorter(RowSorter<? extends TableModel> sorter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
        RowSorter<? extends TableModel> oldRowSorter = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
        if (sortManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
            oldRowSorter = sortManager.sorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
            sortManager.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
            sortManager = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
        rowModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
        clearSelectionAndLeadAnchor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
        if (sorter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
            sortManager = new SortManager(sorter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
        firePropertyChange("rowSorter", oldRowSorter, sorter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
        firePropertyChange("sorter", oldRowSorter, sorter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
     * Returns the object responsible for sorting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
     * @return the object responsible for sorting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
    public RowSorter<? extends TableModel> getRowSorter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
        return (sortManager != null) ? sortManager.sorter : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
// Selection methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
     * Sets the table's selection mode to allow only single selections, a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
     * contiguous interval, or multiple intervals.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
     * <P>
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 16100
diff changeset
  1950
     * <b>Note:</b>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
     * <code>JTable</code> provides all the methods for handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
     * column and row selection.  When setting states,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
     * such as <code>setSelectionMode</code>, it not only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
     * updates the mode for the row selection model but also sets similar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
     * values in the selection model of the <code>columnModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
     * If you want to have the row and column selection models operating
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
     * in different modes, set them both directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
     * Both the row and column selection models for <code>JTable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
     * default to using a <code>DefaultListSelectionModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
     * so that <code>JTable</code> works the same way as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
     * <code>JList</code>. See the <code>setSelectionMode</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
     * in <code>JList</code> for details about the modes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
     * @see JList#setSelectionMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
     * description: The selection mode used by the row and column selection models.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
     *        enum: SINGLE_SELECTION            ListSelectionModel.SINGLE_SELECTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
     *              SINGLE_INTERVAL_SELECTION   ListSelectionModel.SINGLE_INTERVAL_SELECTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
     *              MULTIPLE_INTERVAL_SELECTION ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
    public void setSelectionMode(int selectionMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
        clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
        getSelectionModel().setSelectionMode(selectionMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
        getColumnModel().getSelectionModel().setSelectionMode(selectionMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
     * Sets whether the rows in this model can be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
     * @param rowSelectionAllowed   true if this model will allow row selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
     * @see #getRowSelectionAllowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
     *  description: If true, an entire row is selected for each selected cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
    public void setRowSelectionAllowed(boolean rowSelectionAllowed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
        boolean old = this.rowSelectionAllowed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
        this.rowSelectionAllowed = rowSelectionAllowed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
        if (old != rowSelectionAllowed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
        firePropertyChange("rowSelectionAllowed", old, rowSelectionAllowed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
     * Returns true if rows can be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
     * @return true if rows can be selected, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
     * @see #setRowSelectionAllowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
    public boolean getRowSelectionAllowed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
        return rowSelectionAllowed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
     * Sets whether the columns in this model can be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
     * @param columnSelectionAllowed   true if this model will allow column selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
     * @see #getColumnSelectionAllowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
     *  description: If true, an entire column is selected for each selected cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
    public void setColumnSelectionAllowed(boolean columnSelectionAllowed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
        boolean old = columnModel.getColumnSelectionAllowed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
        columnModel.setColumnSelectionAllowed(columnSelectionAllowed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
        if (old != columnSelectionAllowed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
        firePropertyChange("columnSelectionAllowed", old, columnSelectionAllowed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
     * Returns true if columns can be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
     * @return true if columns can be selected, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
     * @see #setColumnSelectionAllowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
    public boolean getColumnSelectionAllowed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
        return columnModel.getColumnSelectionAllowed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
     * Sets whether this table allows both a column selection and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
     * row selection to exist simultaneously. When set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
     * the table treats the intersection of the row and column selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
     * models as the selected cells. Override <code>isCellSelected</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
     * change this default behavior. This method is equivalent to setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
     * both the <code>rowSelectionAllowed</code> property and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
     * <code>columnSelectionAllowed</code> property of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
     * <code>columnModel</code> to the supplied value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
     * @param  cellSelectionEnabled     true if simultaneous row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
     *                                  selection is allowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
     * @see #getCellSelectionEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
     * @see #isCellSelected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
     *  description: Select a rectangular region of cells rather than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
     *               rows or columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
    public void setCellSelectionEnabled(boolean cellSelectionEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
        setRowSelectionAllowed(cellSelectionEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
        setColumnSelectionAllowed(cellSelectionEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
        boolean old = this.cellSelectionEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
        this.cellSelectionEnabled = cellSelectionEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
        firePropertyChange("cellSelectionEnabled", old, cellSelectionEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
     * Returns true if both row and column selection models are enabled.
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 16100
diff changeset
  2066
     * Equivalent to <code>getRowSelectionAllowed() &amp;&amp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
     * getColumnSelectionAllowed()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
     * @return true if both row and column selection models are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
     * @see #setCellSelectionEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
    public boolean getCellSelectionEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
        return getRowSelectionAllowed() && getColumnSelectionAllowed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
     *  Selects all rows, columns, and cells in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
    public void selectAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
        // If I'm currently editing, then I should stop editing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
        if (isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
            removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
        if (getRowCount() > 0 && getColumnCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
            int oldLead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
            int oldAnchor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
            ListSelectionModel selModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
            selModel = selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
            selModel.setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
            oldLead = getAdjustedIndex(selModel.getLeadSelectionIndex(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
            oldAnchor = getAdjustedIndex(selModel.getAnchorSelectionIndex(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
            setRowSelectionInterval(0, getRowCount()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
            // this is done to restore the anchor and lead
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
            SwingUtilities2.setLeadAnchorWithoutSelection(selModel, oldLead, oldAnchor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
            selModel.setValueIsAdjusting(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
            selModel = columnModel.getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
            selModel.setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
            oldLead = getAdjustedIndex(selModel.getLeadSelectionIndex(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
            oldAnchor = getAdjustedIndex(selModel.getAnchorSelectionIndex(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
            setColumnSelectionInterval(0, getColumnCount()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
            // this is done to restore the anchor and lead
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
            SwingUtilities2.setLeadAnchorWithoutSelection(selModel, oldLead, oldAnchor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
            selModel.setValueIsAdjusting(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
        }
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
     * Deselects all selected columns and rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
    public void clearSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
        selectionModel.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
        columnModel.getSelectionModel().clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
    private void clearSelectionAndLeadAnchor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
        selectionModel.setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
        columnModel.getSelectionModel().setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
        clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
        selectionModel.setAnchorSelectionIndex(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
        selectionModel.setLeadSelectionIndex(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
        columnModel.getSelectionModel().setAnchorSelectionIndex(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
        columnModel.getSelectionModel().setLeadSelectionIndex(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
        selectionModel.setValueIsAdjusting(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
        columnModel.getSelectionModel().setValueIsAdjusting(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
    private int getAdjustedIndex(int index, boolean row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
        int compare = row ? getRowCount() : getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
        return index < compare ? index : -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
    private int boundRow(int row) throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
        if (row < 0 || row >= getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
            throw new IllegalArgumentException("Row index out of range");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
        return row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
    private int boundColumn(int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
        if (col< 0 || col >= getColumnCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
            throw new IllegalArgumentException("Column index out of range");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
        return col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
     * Selects the rows from <code>index0</code> to <code>index1</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
     * inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
     * @exception IllegalArgumentException      if <code>index0</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
     *                                          <code>index1</code> lie outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
     *                                          [0, <code>getRowCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
     * @param   index0 one end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
     * @param   index1 the other end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
    public void setRowSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
        selectionModel.setSelectionInterval(boundRow(index0), boundRow(index1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
     * Selects the columns from <code>index0</code> to <code>index1</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
     * inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
     * @exception IllegalArgumentException      if <code>index0</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
     *                                          <code>index1</code> lie outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
     *                                          [0, <code>getColumnCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
     * @param   index0 one end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
     * @param   index1 the other end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
    public void setColumnSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
        columnModel.getSelectionModel().setSelectionInterval(boundColumn(index0), boundColumn(index1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
     * Adds the rows from <code>index0</code> to <code>index1</code>, inclusive, to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
     * the current selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
     * @exception IllegalArgumentException      if <code>index0</code> or <code>index1</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
     *                                          lie outside [0, <code>getRowCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
     * @param   index0 one end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
     * @param   index1 the other end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
    public void addRowSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
        selectionModel.addSelectionInterval(boundRow(index0), boundRow(index1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
     * Adds the columns from <code>index0</code> to <code>index1</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
     * inclusive, to the current selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
     * @exception IllegalArgumentException      if <code>index0</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
     *                                          <code>index1</code> lie outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
     *                                          [0, <code>getColumnCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
     * @param   index0 one end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
     * @param   index1 the other end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
    public void addColumnSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
        columnModel.getSelectionModel().addSelectionInterval(boundColumn(index0), boundColumn(index1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
     * Deselects the rows from <code>index0</code> to <code>index1</code>, inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
     * @exception IllegalArgumentException      if <code>index0</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
     *                                          <code>index1</code> lie outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
     *                                          [0, <code>getRowCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
     * @param   index0 one end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
     * @param   index1 the other end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
    public void removeRowSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
        selectionModel.removeSelectionInterval(boundRow(index0), boundRow(index1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
     * Deselects the columns from <code>index0</code> to <code>index1</code>, inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
     * @exception IllegalArgumentException      if <code>index0</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
     *                                          <code>index1</code> lie outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
     *                                          [0, <code>getColumnCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
     * @param   index0 one end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
     * @param   index1 the other end of the interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
    public void removeColumnSelectionInterval(int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
        columnModel.getSelectionModel().removeSelectionInterval(boundColumn(index0), boundColumn(index1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
     * Returns the index of the first selected row, -1 if no row is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
     * @return the index of the first selected row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
    public int getSelectedRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
        return selectionModel.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
     * Returns the index of the first selected column,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
     * -1 if no column is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
     * @return the index of the first selected column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
    public int getSelectedColumn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
        return columnModel.getSelectionModel().getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
     * Returns the indices of all selected rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
     * @return an array of integers containing the indices of all selected rows,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
     *         or an empty array if no row is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
     * @see #getSelectedRow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
    public int[] getSelectedRows() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
        int iMin = selectionModel.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
        int iMax = selectionModel.getMaxSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
        if ((iMin == -1) || (iMax == -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
            return new int[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
        int[] rvTmp = new int[1+ (iMax - iMin)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
        int n = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
        for(int i = iMin; i <= iMax; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
            if (selectionModel.isSelectedIndex(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
                rvTmp[n++] = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
        int[] rv = new int[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
        System.arraycopy(rvTmp, 0, rv, 0, n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
        return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
     * Returns the indices of all selected columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
     * @return an array of integers containing the indices of all selected columns,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
     *         or an empty array if no column is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
     * @see #getSelectedColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
    public int[] getSelectedColumns() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
        return columnModel.getSelectedColumns();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
     * Returns the number of selected rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
     * @return the number of selected rows, 0 if no rows are selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
    public int getSelectedRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
        int iMin = selectionModel.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
        int iMax = selectionModel.getMaxSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
        int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
        for(int i = iMin; i <= iMax; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
            if (selectionModel.isSelectedIndex(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
                count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
        return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
     * Returns the number of selected columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
     * @return the number of selected columns, 0 if no columns are selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
    public int getSelectedColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
        return columnModel.getSelectedColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
     * Returns true if the specified index is in the valid range of rows,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
     * and the row at that index is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
     * @return true if <code>row</code> is a valid index and the row at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
     *              that index is selected (where 0 is the first row)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
    public boolean isRowSelected(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
        return selectionModel.isSelectedIndex(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
     * Returns true if the specified index is in the valid range of columns,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
     * and the column at that index is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
     * @param   column   the column in the column model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
     * @return true if <code>column</code> is a valid index and the column at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
     *              that index is selected (where 0 is the first column)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
    public boolean isColumnSelected(int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
        return columnModel.getSelectionModel().isSelectedIndex(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
     * Returns true if the specified indices are in the valid range of rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
     * and columns and the cell at the specified position is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
     * @param row   the row being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
     * @param column  the column being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
     * @return true if <code>row</code> and <code>column</code> are valid indices
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
     *              and the cell at index <code>(row, column)</code> is selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
     *              where the first row and first column are at index 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
    public boolean isCellSelected(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
        if (!getRowSelectionAllowed() && !getColumnSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
        return (!getRowSelectionAllowed() || isRowSelected(row)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
               (!getColumnSelectionAllowed() || isColumnSelected(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
    private void changeSelectionModel(ListSelectionModel sm, int index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
                                      boolean toggle, boolean extend, boolean selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
                                      int anchor, boolean anchorSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
        if (extend) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
            if (toggle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
                if (anchorSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
                    sm.addSelectionInterval(anchor, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
                    sm.removeSelectionInterval(anchor, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
                    // this is a Windows-only behavior that we want for file lists
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
                    if (Boolean.TRUE == getClientProperty("Table.isFileList")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
                        sm.addSelectionInterval(index, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
                        sm.setAnchorSelectionIndex(anchor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
                sm.setSelectionInterval(anchor, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
            if (toggle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
                if (selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
                    sm.removeSelectionInterval(index, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
                    sm.addSelectionInterval(index, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
                sm.setSelectionInterval(index, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
            }
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
     * Updates the selection models of the table, depending on the state of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
     * two flags: <code>toggle</code> and <code>extend</code>. Most changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
     * to the selection that are the result of keyboard or mouse events received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
     * by the UI are channeled through this method so that the behavior may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
     * overridden by a subclass. Some UIs may need more functionality than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
     * this method provides, such as when manipulating the lead for discontiguous
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
     * selection, and may not call into this method for some selection changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
     * This implementation uses the following conventions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
     * <li> <code>toggle</code>: <em>false</em>, <code>extend</code>: <em>false</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
     *      Clear the previous selection and ensure the new cell is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
     * <li> <code>toggle</code>: <em>false</em>, <code>extend</code>: <em>true</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
     *      Extend the previous selection from the anchor to the specified cell,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
     *      clearing all other selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
     * <li> <code>toggle</code>: <em>true</em>, <code>extend</code>: <em>false</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
     *      If the specified cell is selected, deselect it. If it is not selected, select it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
     * <li> <code>toggle</code>: <em>true</em>, <code>extend</code>: <em>true</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
     *      Apply the selection state of the anchor to all cells between it and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
     *      specified cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
     * @param  rowIndex   affects the selection at <code>row</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
     * @param  columnIndex  affects the selection at <code>column</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
     * @param  toggle  see description above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
     * @param  extend  if true, extend the current selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
    public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
        ListSelectionModel rsm = getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
        ListSelectionModel csm = getColumnModel().getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
        int anchorRow = getAdjustedIndex(rsm.getAnchorSelectionIndex(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
        int anchorCol = getAdjustedIndex(csm.getAnchorSelectionIndex(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
        boolean anchorSelected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
        if (anchorRow == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
            if (getRowCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
                anchorRow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
            anchorSelected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
        if (anchorCol == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
            if (getColumnCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
                anchorCol = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
            anchorSelected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
        // Check the selection here rather than in each selection model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
        // This is significant in cell selection mode if we are supposed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
        // to be toggling the selection. In this case it is better to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
        // ensure that the cell's selection state will indeed be changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
        // If this were done in the code for the selection model it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
        // might leave a cell in selection state if the row was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
        // selected but the column was not - as it would toggle them both.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
        boolean selected = isCellSelected(rowIndex, columnIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
        anchorSelected = anchorSelected && isCellSelected(anchorRow, anchorCol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
        changeSelectionModel(csm, columnIndex, toggle, extend, selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
                             anchorCol, anchorSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
        changeSelectionModel(rsm, rowIndex, toggle, extend, selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
                             anchorRow, anchorSelected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
        // Scroll after changing the selection as blit scrolling is immediate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
        // so that if we cause the repaint after the scroll we end up painting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
        // everything!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
        if (getAutoscrolls()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
            Rectangle cellRect = getCellRect(rowIndex, columnIndex, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
            if (cellRect != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
                scrollRectToVisible(cellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
            }
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
     * Returns the foreground color for selected cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
     * @return the <code>Color</code> object for the foreground property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
     * @see #setSelectionForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
     * @see #setSelectionBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
    public Color getSelectionForeground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
        return selectionForeground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
     * Sets the foreground color for selected cells.  Cell renderers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
     * can use this color to render text and graphics for selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
     * cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
     * The default value of this property is defined by the look
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
     * and feel implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
     * <p>
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20157
diff changeset
  2494
     * This is a <a href="http://docs.oracle.com/javase/tutorial/javabeans/writing/properties.html">JavaBeans</a> bound property.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
     * @param selectionForeground  the <code>Color</code> to use in the foreground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
     *                             for selected list items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
     * @see #getSelectionForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
     * @see #setSelectionBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
     * @see #setForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
     * @see #setBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
     * @see #setFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
     * description: A default foreground color for selected cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
    public void setSelectionForeground(Color selectionForeground) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
        Color old = this.selectionForeground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
        this.selectionForeground = selectionForeground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
        firePropertyChange("selectionForeground", old, selectionForeground);
4967
da853cd502c8 6913768: With default SynthLookAndFeel instance installed new JTable creation leads to throwing NPE
rupashka
parents: 4379
diff changeset
  2511
        repaint();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
     * Returns the background color for selected cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
     * @return the <code>Color</code> used for the background of selected list items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
     * @see #setSelectionBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
     * @see #setSelectionForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
    public Color getSelectionBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
        return selectionBackground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
     * Sets the background color for selected cells.  Cell renderers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
     * can use this color to the fill selected cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
     * The default value of this property is defined by the look
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
     * and feel implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
     * <p>
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20157
diff changeset
  2532
     * This is a <a href="http://docs.oracle.com/javase/tutorial/javabeans/writing/properties.html">JavaBeans</a> bound property.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
     * @param selectionBackground  the <code>Color</code> to use for the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
     *                             of selected cells
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
     * @see #getSelectionBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
     * @see #setSelectionForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
     * @see #setForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
     * @see #setBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
     * @see #setFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
     * description: A default background color for selected cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
    public void setSelectionBackground(Color selectionBackground) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
        Color old = this.selectionBackground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
        this.selectionBackground = selectionBackground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
        firePropertyChange("selectionBackground", old, selectionBackground);
4967
da853cd502c8 6913768: With default SynthLookAndFeel instance installed new JTable creation leads to throwing NPE
rupashka
parents: 4379
diff changeset
  2549
        repaint();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
     * Returns the <code>TableColumn</code> object for the column in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
     * whose identifier is equal to <code>identifier</code>, when compared using
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
     * <code>equals</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
     * @return  the <code>TableColumn</code> object that matches the identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
     * @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
  2559
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
     * @param   identifier                      the identifier object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
    public TableColumn getColumn(Object identifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
        TableColumnModel cm = getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
        int columnIndex = cm.getColumnIndex(identifier);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
        return cm.getColumn(columnIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
// Informally implement the TableModel interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
     * Maps the index of the column in the view at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
     * <code>viewColumnIndex</code> to the index of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
     * in the table model.  Returns the index of the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
     * column in the model.  If <code>viewColumnIndex</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
     * is less than zero, returns <code>viewColumnIndex</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
     * @param   viewColumnIndex     the index of the column in the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
     * @return  the index of the corresponding column in the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
     * @see #convertColumnIndexToView
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
    public int convertColumnIndexToModel(int viewColumnIndex) {
5590
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents: 5449
diff changeset
  2585
        return SwingUtilities2.convertColumnIndexToModel(
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents: 5449
diff changeset
  2586
                getColumnModel(), viewColumnIndex);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
     * Maps the index of the column in the table model at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
     * <code>modelColumnIndex</code> to the index of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
     * in the view.  Returns the index of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
     * corresponding column in the view; returns -1 if this column is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
     * being displayed.  If <code>modelColumnIndex</code> is less than zero,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
     * returns <code>modelColumnIndex</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
     * @param   modelColumnIndex     the index of the column in the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
     * @return   the index of the corresponding column in the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
     * @see #convertColumnIndexToModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
    public int convertColumnIndexToView(int modelColumnIndex) {
5590
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents: 5449
diff changeset
  2603
        return SwingUtilities2.convertColumnIndexToView(
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents: 5449
diff changeset
  2604
                getColumnModel(), modelColumnIndex);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
     * Maps the index of the row in terms of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
     * <code>TableModel</code> to the view.  If the contents of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
     * model are not sorted the model and view indices are the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
     * @param modelRowIndex the index of the row in terms of the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
     * @return the index of the corresponding row in the view, or -1 if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
     *         the row isn't visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
     * @throws IndexOutOfBoundsException if sorting is enabled and passed an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
     *         index outside the number of rows of the <code>TableModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
     * @see javax.swing.table.TableRowSorter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
    public int convertRowIndexToView(int modelRowIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
        RowSorter sorter = getRowSorter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
        if (sorter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
            return sorter.convertRowIndexToView(modelRowIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
        return modelRowIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
     * Maps the index of the row in terms of the view to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
     * underlying <code>TableModel</code>.  If the contents of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
     * model are not sorted the model and view indices are the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
     * @param viewRowIndex the index of the row in the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
     * @return the index of the corresponding row in the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
     * @throws IndexOutOfBoundsException if sorting is enabled and passed an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
     *         index outside the range of the <code>JTable</code> as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
     *         determined by the method <code>getRowCount</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
     * @see javax.swing.table.TableRowSorter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
     * @see #getRowCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
    public int convertRowIndexToModel(int viewRowIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
        RowSorter sorter = getRowSorter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
        if (sorter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
            return sorter.convertRowIndexToModel(viewRowIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
        return viewRowIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
     * Returns the number of rows that can be shown in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
     * <code>JTable</code>, given unlimited space.  If a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
     * <code>RowSorter</code> with a filter has been specified, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
     * number of rows returned may differ from that of the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
     * <code>TableModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
     * @return the number of rows shown in the <code>JTable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
     * @see #getColumnCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
    public int getRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
        RowSorter sorter = getRowSorter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
        if (sorter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
            return sorter.getViewRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
        return getModel().getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
     * Returns the number of columns in the column model. Note that this may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
     * be different from the number of columns in the table model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
     * @return  the number of columns in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
     * @see #getRowCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
     * @see #removeColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
    public int getColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
        return getColumnModel().getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
     * Returns the name of the column appearing in the view at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
     * column position <code>column</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
     * @param  column    the column in the view being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
     * @return the name of the column at position <code>column</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
                        in the view where the first column is column 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
    public String getColumnName(int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
        return getModel().getColumnName(convertColumnIndexToModel(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
     * Returns the type of the column appearing in the view at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
     * column position <code>column</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
     * @param   column   the column in the view being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
     * @return the type of the column at position <code>column</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
     *          in the view where the first column is column 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
    public Class<?> getColumnClass(int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
        return getModel().getColumnClass(convertColumnIndexToModel(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
     * Returns the cell value at <code>row</code> and <code>column</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
     * <b>Note</b>: The column is specified in the table view's display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
     *              order, and not in the <code>TableModel</code>'s column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
     *              order.  This is an important distinction because as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
     *              user rearranges the columns in the table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
     *              the column at a given index in the view will change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
     *              Meanwhile the user's actions never affect the model's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
     *              column ordering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
     * @param   row             the row whose value is to be queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
     * @param   column          the column whose value is to be queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
     * @return  the Object at the specified cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
    public Object getValueAt(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
        return getModel().getValueAt(convertRowIndexToModel(row),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
                                     convertColumnIndexToModel(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
     * Sets the value for the cell in the table model at <code>row</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
     * and <code>column</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
     * <b>Note</b>: The column is specified in the table view's display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
     *              order, and not in the <code>TableModel</code>'s column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
     *              order.  This is an important distinction because as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
     *              user rearranges the columns in the table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
     *              the column at a given index in the view will change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
     *              Meanwhile the user's actions never affect the model's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
     *              column ordering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
     * <code>aValue</code> is the new value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
     * @param   aValue          the new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
     * @param   row             the row of the cell to be changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
     * @param   column          the column of the cell to be changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
     * @see #getValueAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
    public void setValueAt(Object aValue, int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
        getModel().setValueAt(aValue, convertRowIndexToModel(row),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
                              convertColumnIndexToModel(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
     * Returns true if the cell at <code>row</code> and <code>column</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
     * is editable.  Otherwise, invoking <code>setValueAt</code> on the cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
     * will have no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
     * <b>Note</b>: The column is specified in the table view's display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
     *              order, and not in the <code>TableModel</code>'s column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
     *              order.  This is an important distinction because as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
     *              user rearranges the columns in the table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
     *              the column at a given index in the view will change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
     *              Meanwhile the user's actions never affect the model's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
     *              column ordering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
     * @param   row      the row whose value is to be queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
     * @param   column   the column whose value is to be queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
     * @return  true if the cell is editable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
     * @see #setValueAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
    public boolean isCellEditable(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
        return getModel().isCellEditable(convertRowIndexToModel(row),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
                                         convertColumnIndexToModel(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
// Adding and removing columns in the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
     *  Appends <code>aColumn</code> to the end of the array of columns held by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
     *  this <code>JTable</code>'s column model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
     *  If the column name of <code>aColumn</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
     *  sets the column name of <code>aColumn</code> to the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
     *  returned by <code>getModel().getColumnName()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
     *  <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
     *  To add a column to this <code>JTable</code> to display the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
     *  <code>modelColumn</code>'th column of data in the model with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
     *  given <code>width</code>, <code>cellRenderer</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
     *  and <code>cellEditor</code> you can use:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
     *  <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
     *      addColumn(new TableColumn(modelColumn, width, cellRenderer, cellEditor));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
     *  </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
     *  [Any of the <code>TableColumn</code> constructors can be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
     *  instead of this one.]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
     *  The model column number is stored inside the <code>TableColumn</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
     *  and is used during rendering and editing to locate the appropriates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
     *  data values in the model. The model column number does not change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
     *  when columns are reordered in the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
     *  @param  aColumn         the <code>TableColumn</code> to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
     *  @see    #removeColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
    public void addColumn(TableColumn aColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
        if (aColumn.getHeaderValue() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
            int modelColumn = aColumn.getModelIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
            String columnName = getModel().getColumnName(modelColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
            aColumn.setHeaderValue(columnName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
        getColumnModel().addColumn(aColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
     *  Removes <code>aColumn</code> from this <code>JTable</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
     *  array of columns.  Note: this method does not remove the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
     *  of data from the model; it just removes the <code>TableColumn</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
     *  that was responsible for displaying it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
     *  @param  aColumn         the <code>TableColumn</code> to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
     *  @see    #addColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
    public void removeColumn(TableColumn aColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
        getColumnModel().removeColumn(aColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
     * Moves the column <code>column</code> to the position currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
     * occupied by the column <code>targetColumn</code> in the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
     * The old column at <code>targetColumn</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
     * shifted left or right to make room.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
     * @param   column                  the index of column to be moved
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
     * @param   targetColumn            the new index of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
    public void moveColumn(int column, int targetColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
        getColumnModel().moveColumn(column, targetColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
// Cover methods for various models and helper methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
     * Returns the index of the column that <code>point</code> lies in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
     * or -1 if the result is not in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
     * [0, <code>getColumnCount()</code>-1].
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
     * @param   point   the location of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
     * @return  the index of the column that <code>point</code> lies in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
     *          or -1 if the result is not in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
     *          [0, <code>getColumnCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
     * @see     #rowAtPoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
    public int columnAtPoint(Point point) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
        int x = point.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
        if( !getComponentOrientation().isLeftToRight() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
            x = getWidth() - x - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
        return getColumnModel().getColumnIndexAtX(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
     * Returns the index of the row that <code>point</code> lies in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
     * or -1 if the result is not in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
     * [0, <code>getRowCount()</code>-1].
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
     * @param   point   the location of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
     * @return  the index of the row that <code>point</code> lies in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
     *          or -1 if the result is not in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
     *          [0, <code>getRowCount()</code>-1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
     * @see     #columnAtPoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
    public int rowAtPoint(Point point) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
        int y = point.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
        int result = (rowModel == null) ?  y/getRowHeight() : rowModel.getIndex(y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
        if (result < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
        else if (result >= getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
     * Returns a rectangle for the cell that lies at the intersection of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
     * <code>row</code> and <code>column</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
     * If <code>includeSpacing</code> is true then the value returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
     * has the full height and width of the row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
     * specified. If it is false, the returned rectangle is inset by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
     * intercell spacing to return the true bounds of the rendering or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
     * editing component as it will be set during rendering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
     * If the column index is valid but the row index is less
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
     * than zero the method returns a rectangle with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
     * <code>y</code> and <code>height</code> values set appropriately
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
     * and the <code>x</code> and <code>width</code> values both set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
     * to zero. In general, when either the row or column indices indicate a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
     * cell outside the appropriate range, the method returns a rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
     * depicting the closest edge of the closest cell that is within
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
     * the table's range. When both row and column indices are out
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
     * of range the returned rectangle covers the closest
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
     * point of the closest cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
     * In all cases, calculations that use this method to calculate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
     * results along one axis will not fail because of anomalies in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
     * calculations along the other axis. When the cell is not valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
     * the <code>includeSpacing</code> parameter is ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
     * @param   row                   the row index where the desired cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
     *                                is located
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
     * @param   column                the column index where the desired cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
     *                                is located in the display; this is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
     *                                necessarily the same as the column index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
     *                                in the data model for the table; the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
     *                                {@link #convertColumnIndexToView(int)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
     *                                method may be used to convert a data
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
     *                                model column index to a display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
     *                                column index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
     * @param   includeSpacing        if false, return the true cell bounds -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
     *                                computed by subtracting the intercell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
     *                                spacing from the height and widths of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
     *                                the column and row models
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
     * @return  the rectangle containing the cell at location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
     *          <code>row</code>,<code>column</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
     * @see #getIntercellSpacing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
    public Rectangle getCellRect(int row, int column, boolean includeSpacing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
        Rectangle r = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
        boolean valid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
        if (row < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
            // y = height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
            valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
        else if (row >= getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
            r.y = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
            valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
            r.height = getRowHeight(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
            r.y = (rowModel == null) ? row * r.height : rowModel.getPosition(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
        if (column < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
            if( !getComponentOrientation().isLeftToRight() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
                r.x = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
            // otherwise, x = width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
            valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
        else if (column >= getColumnCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
            if( getComponentOrientation().isLeftToRight() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
                r.x = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
            // otherwise, x = width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
            valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
            TableColumnModel cm = getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
            if( getComponentOrientation().isLeftToRight() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
                for(int i = 0; i < column; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
                    r.x += cm.getColumn(i).getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
                for(int i = cm.getColumnCount()-1; i > column; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
                    r.x += cm.getColumn(i).getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
            r.width = cm.getColumn(column).getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
        if (valid && !includeSpacing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
            // Bound the margins by their associated dimensions to prevent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
            // returning bounds with negative dimensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
            int rm = Math.min(getRowMargin(), r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
            int cm = Math.min(getColumnModel().getColumnMargin(), r.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
            // This is not the same as grow(), it rounds differently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
            r.setBounds(r.x + cm/2, r.y + rm/2, r.width - cm, r.height - rm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
        return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
    private int viewIndexForColumn(TableColumn aColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
        TableColumnModel cm = getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
        for (int column = 0; column < cm.getColumnCount(); column++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
            if (cm.getColumn(column) == aColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
                return column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2990
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2991
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2992
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2993
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2994
     * Causes this table to lay out its rows and columns.  Overridden so
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20854
diff changeset
  2995
     * that columns can be resized to accommodate a change in the size of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
     * a containing parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
     * Resizes one or more of the columns in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
     * so that the total width of all of this <code>JTable</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
     * columns is equal to the width of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
     * Before the layout begins the method gets the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
     * <code>resizingColumn</code> of the <code>tableHeader</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
     * When the method is called as a result of the resizing of an enclosing window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3004
     * the <code>resizingColumn</code> is <code>null</code>. This means that resizing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
     * has taken place "outside" the <code>JTable</code> and the change -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
     * or "delta" - should be distributed to all of the columns regardless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
     * of this <code>JTable</code>'s automatic resize mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3008
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
     * If the <code>resizingColumn</code> is not <code>null</code>, it is one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
     * the columns in the table that has changed size rather than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
     * the table itself. In this case the auto-resize modes govern
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
     * the way the extra (or deficit) space is distributed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
     * amongst the available columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
     * The modes are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
     * <li>  AUTO_RESIZE_OFF: Don't automatically adjust the column's
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20854
diff changeset
  3018
     * widths at all. Use a horizontal scrollbar to accommodate the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
     * columns when their sum exceeds the width of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
     * <code>Viewport</code>.  If the <code>JTable</code> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
     * enclosed in a <code>JScrollPane</code> this may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
     * leave parts of the table invisible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
     * <li>  AUTO_RESIZE_NEXT_COLUMN: Use just the column after the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
     * resizing column. This results in the "boundary" or divider
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
     * between adjacent cells being independently adjustable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
     * <li>  AUTO_RESIZE_SUBSEQUENT_COLUMNS: Use all columns after the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
     * one being adjusted to absorb the changes.  This is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
     * default behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
     * <li>  AUTO_RESIZE_LAST_COLUMN: Automatically adjust the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
     * size of the last column only. If the bounds of the last column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
     * prevent the desired size from being allocated, set the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
     * width of the last column to the appropriate limit and make
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
     * no further adjustments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
     * <li>  AUTO_RESIZE_ALL_COLUMNS: Spread the delta amongst all the columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
     * in the <code>JTable</code>, including the one that is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
     * adjusted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
     * <p>
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 16100
diff changeset
  3039
     * <b>Note:</b> When a <code>JTable</code> makes adjustments
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
     *   to the widths of the columns it respects their minimum and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
     *   maximum values absolutely.  It is therefore possible that,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
     *   even after this method is called, the total width of the columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
     *   is still not equal to the width of the table. When this happens
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
     *   the <code>JTable</code> does not put itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
     *   in AUTO_RESIZE_OFF mode to bring up a scroll bar, or break other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
     *   commitments of its current auto-resize mode -- instead it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
     *   allows its bounds to be set larger (or smaller) than the total of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
     *   column minimum or maximum, meaning, either that there
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
     *   will not be enough room to display all of the columns, or that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
     *   columns will not fill the <code>JTable</code>'s bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
     *   These respectively, result in the clipping of some columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
     *   or an area being painted in the <code>JTable</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
     *   background color during painting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
     *   The mechanism for distributing the delta amongst the available
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
     *   columns is provided in a private method in the <code>JTable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
     *   class:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3059
     *   adjustSizes(long targetSize, final Resizable3 r, boolean inverse)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
     *   an explanation of which is provided in the following section.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
     *   <code>Resizable3</code> is a private
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
     *   interface that allows any data structure containing a collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
     *   of elements with a size, preferred size, maximum size and minimum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
     *   to have its elements manipulated by the algorithm.
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 21278
diff changeset
  3066
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3067
     * <H3> Distributing the delta </H3>
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 21278
diff changeset
  3068
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3069
     * <H4> Overview </H4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3071
     * Call "DELTA" the difference between the target size and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3072
     * sum of the preferred sizes of the elements in r. The individual
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
     * sizes are calculated by taking the original preferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
     * sizes and adding a share of the DELTA - that share being based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
     * how far each preferred size is from its limiting bound (minimum or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
     * maximum).
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 21278
diff changeset
  3077
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
     * <H4>Definition</H4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3079
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
     * Call the individual constraints min[i], max[i], and pref[i].
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
     * Call their respective sums: MIN, MAX, and PREF.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
     * Each new size will be calculated using:
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 21278
diff changeset
  3085
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
     *          size[i] = pref[i] + delta[i]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
     * where each individual delta[i] is calculated according to:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
     * <p>
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 16100
diff changeset
  3091
     * If (DELTA &lt; 0) we are in shrink mode where:
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 21278
diff changeset
  3092
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3093
     * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
     *                        DELTA
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
     *          delta[i] = ------------ * (pref[i] - min[i])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
     *                     (PREF - MIN)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
     * </PRE>
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 16100
diff changeset
  3098
     * If (DELTA &gt; 0) we are in expand mode where:
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 21278
diff changeset
  3099
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
     * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
     *                        DELTA
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3102
     *          delta[i] = ------------ * (max[i] - pref[i])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3103
     *                      (MAX - PREF)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3104
     * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3105
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3106
     * The overall effect is that the total size moves that same percentage,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3107
     * k, towards the total minimum or maximum and that percentage guarantees
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20854
diff changeset
  3108
     * accommodation of the required space, DELTA.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3109
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3110
     * <H4>Details</H4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3111
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3112
     * Naive evaluation of the formulae presented here would be subject to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3113
     * the aggregated rounding errors caused by doing this operation in finite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3114
     * precision (using ints). To deal with this, the multiplying factor above,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3115
     * is constantly recalculated and this takes account of the rounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3116
     * errors in the previous iterations. The result is an algorithm that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3117
     * produces a set of integers whose values exactly sum to the supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3118
     * <code>targetSize</code>, and does so by spreading the rounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3119
     * errors evenly over the given elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3121
     * <H4>When the MAX and MIN bounds are hit</H4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3122
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3123
     * When <code>targetSize</code> is outside the [MIN, MAX] range,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3124
     * the algorithm sets all sizes to their appropriate limiting value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3125
     * (maximum or minimum).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3128
    public void doLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3129
        TableColumn resizingColumn = getResizingColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3130
        if (resizingColumn == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
            setWidthsFromPreferredWidths(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3133
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3134
            // JTable behaves like a layout manger - but one in which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3135
            // user can come along and dictate how big one of the children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3136
            // (columns) is supposed to be.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3138
            // A column has been resized and JTable may need to distribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3139
            // any overall delta to other columns, according to the resize mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3140
            int columnIndex = viewIndexForColumn(resizingColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3141
            int delta = getWidth() - getColumnModel().getTotalColumnWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3142
            accommodateDelta(columnIndex, delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
            delta = getWidth() - getColumnModel().getTotalColumnWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3145
            // If the delta cannot be completely accomodated, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3146
            // resizing column will have to take any remainder. This means
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3147
            // that the column is not being allowed to take the requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3148
            // width. This happens under many circumstances: For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3149
            // AUTO_RESIZE_NEXT_COLUMN specifies that any delta be distributed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3150
            // to the column after the resizing column. If one were to attempt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3151
            // to resize the last column of the table, there would be no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3152
            // columns after it, and hence nowhere to distribute the delta.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3153
            // It would then be given entirely back to the resizing column,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3154
            // preventing it from changing size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3155
            if (delta != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
                resizingColumn.setWidth(resizingColumn.getWidth() + delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
            // At this point the JTable has to work out what preferred sizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
            // would have resulted in the layout the user has chosen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
            // Thereafter, during window resizing etc. it has to work off
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3162
            // the preferred sizes as usual - the idea being that, whatever
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3163
            // the user does, everything stays in synch and things don't jump
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3164
            // around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3165
            setWidthsFromPreferredWidths(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3168
        super.doLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3170
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3171
    private TableColumn getResizingColumn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3172
        return (tableHeader == null) ? null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3173
                                     : tableHeader.getResizingColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3175
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3177
     * Sizes the table columns to fit the available space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3178
     * @deprecated As of Swing version 1.0.3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3179
     * replaced by <code>doLayout()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3180
     * @see #doLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3182
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3183
    public void sizeColumnsToFit(boolean lastColumnOnly) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3184
        int oldAutoResizeMode = autoResizeMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3185
        setAutoResizeMode(lastColumnOnly ? AUTO_RESIZE_LAST_COLUMN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3186
                                         : AUTO_RESIZE_ALL_COLUMNS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3187
        sizeColumnsToFit(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3188
        setAutoResizeMode(oldAutoResizeMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
     * Obsolete as of Java 2 platform v1.4.  Please use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
     * <code>doLayout()</code> method instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3194
     * @param resizingColumn    the column whose resizing made this adjustment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3195
     *                          necessary or -1 if there is no such column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3196
     * @see  #doLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3198
    public void sizeColumnsToFit(int resizingColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3199
        if (resizingColumn == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3200
            setWidthsFromPreferredWidths(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
            if (autoResizeMode == AUTO_RESIZE_OFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
                TableColumn aColumn = getColumnModel().getColumn(resizingColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
                aColumn.setPreferredWidth(aColumn.getWidth());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3207
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
                int delta = getWidth() - getColumnModel().getTotalColumnWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
                accommodateDelta(resizingColumn, delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3210
                setWidthsFromPreferredWidths(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
    private void setWidthsFromPreferredWidths(final boolean inverse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
        int totalWidth     = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
        int totalPreferred = getPreferredSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
        int target = !inverse ? totalWidth : totalPreferred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
        final TableColumnModel cm = columnModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3221
        Resizable3 r = new Resizable3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
            public int  getElementCount()      { return cm.getColumnCount(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
            public int  getLowerBoundAt(int i) { return cm.getColumn(i).getMinWidth(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3224
            public int  getUpperBoundAt(int i) { return cm.getColumn(i).getMaxWidth(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3225
            public int  getMidPointAt(int i)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
                if (!inverse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
                    return cm.getColumn(i).getPreferredWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3230
                    return cm.getColumn(i).getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3232
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
            public void setSizeAt(int s, int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
                if (!inverse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
                    cm.getColumn(i).setWidth(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
                    cm.getColumn(i).setPreferredWidth(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
        adjustSizes(target, r, inverse);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
    // Distribute delta over columns, as indicated by the autoresize mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
    private void accommodateDelta(int resizingColumnIndex, int delta) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
        int columnCount = getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3250
        int from = resizingColumnIndex;
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  3251
        int to;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3252
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3253
        // Use the mode to determine how to absorb the changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3254
        switch(autoResizeMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3255
            case AUTO_RESIZE_NEXT_COLUMN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
                from = from + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3257
                to = Math.min(from + 1, columnCount); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3258
            case AUTO_RESIZE_SUBSEQUENT_COLUMNS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
                from = from + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
                to = columnCount; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
            case AUTO_RESIZE_LAST_COLUMN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
                from = columnCount - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3263
                to = from + 1; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
            case AUTO_RESIZE_ALL_COLUMNS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
                from = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3266
                to = columnCount; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3268
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3271
        final int start = from;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
        final int end = to;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
        final TableColumnModel cm = columnModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
        Resizable3 r = new Resizable3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
            public int  getElementCount()       { return end-start; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
            public int  getLowerBoundAt(int i)  { return cm.getColumn(i+start).getMinWidth(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3277
            public int  getUpperBoundAt(int i)  { return cm.getColumn(i+start).getMaxWidth(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
            public int  getMidPointAt(int i)    { return cm.getColumn(i+start).getWidth(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3279
            public void setSizeAt(int s, int i) {        cm.getColumn(i+start).setWidth(s); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3280
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3282
        int totalWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3283
        for(int i = from; i < to; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3284
            TableColumn aColumn = columnModel.getColumn(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
            int input = aColumn.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
            totalWidth = totalWidth + input;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3289
        adjustSizes(totalWidth + delta, r, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3291
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
    private interface Resizable2 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3293
        public int  getElementCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
        public int  getLowerBoundAt(int i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
        public int  getUpperBoundAt(int i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
        public void setSizeAt(int newSize, int i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
    private interface Resizable3 extends Resizable2 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
        public int  getMidPointAt(int i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
    private void adjustSizes(long target, final Resizable3 r, boolean inverse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
        int N = r.getElementCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
        long totalPreferred = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
        for(int i = 0; i < N; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
            totalPreferred += r.getMidPointAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
        Resizable2 s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
        if ((target < totalPreferred) == !inverse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
            s = new Resizable2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3313
                public int  getElementCount()      { return r.getElementCount(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3314
                public int  getLowerBoundAt(int i) { return r.getLowerBoundAt(i); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3315
                public int  getUpperBoundAt(int i) { return r.getMidPointAt(i); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3316
                public void setSizeAt(int newSize, int i) { r.setSizeAt(newSize, i); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3318
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3320
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
            s = new Resizable2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
                public int  getElementCount()      { return r.getElementCount(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
                public int  getLowerBoundAt(int i) { return r.getMidPointAt(i); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3324
                public int  getUpperBoundAt(int i) { return r.getUpperBoundAt(i); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
                public void setSizeAt(int newSize, int i) { r.setSizeAt(newSize, i); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
        adjustSizes(target, s, !inverse);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3332
    private void adjustSizes(long target, Resizable2 r, boolean limitToRange) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
        long totalLowerBound = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
        long totalUpperBound = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
        for(int i = 0; i < r.getElementCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
            totalLowerBound += r.getLowerBoundAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
            totalUpperBound += r.getUpperBoundAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3339
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
        if (limitToRange) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
            target = Math.min(Math.max(totalLowerBound, target), totalUpperBound);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
        for(int i = 0; i < r.getElementCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
            int lowerBound = r.getLowerBoundAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
            int upperBound = r.getUpperBoundAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
            // Check for zero. This happens when the distribution of the delta
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
            // finishes early due to a series of "fixed" entries at the end.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3349
            // In this case, lowerBound == upperBound, for all subsequent terms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
            int newSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
            if (totalLowerBound == totalUpperBound) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3352
                newSize = lowerBound;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3355
                double f = (double)(target - totalLowerBound)/(totalUpperBound - totalLowerBound);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3356
                newSize = (int)Math.round(lowerBound+f*(upperBound - lowerBound));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3357
                // We'd need to round manually in an all integer version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
                // size[i] = (int)(((totalUpperBound - target) * lowerBound +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3359
                //     (target - totalLowerBound) * upperBound)/(totalUpperBound-totalLowerBound));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
            r.setSizeAt(newSize, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
            target -= newSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
            totalLowerBound -= lowerBound;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3364
            totalUpperBound -= upperBound;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3369
     * Overrides <code>JComponent</code>'s <code>getToolTipText</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3370
     * method in order to allow the renderer's tips to be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3371
     * if it has text set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3372
     * <p>
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 16100
diff changeset
  3373
     * <b>Note:</b> For <code>JTable</code> to properly display
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3374
     * tooltips of its renderers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
     * <code>JTable</code> must be a registered component with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
     * <code>ToolTipManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3377
     * This is done automatically in <code>initializeLocalVars</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3378
     * but if at a later point <code>JTable</code> is told
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3379
     * <code>setToolTipText(null)</code> it will unregister the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3380
     * component, and no tips from renderers will display anymore.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3381
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3382
     * @see JComponent#getToolTipText
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3383
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3384
    public String getToolTipText(MouseEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3385
        String tip = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3386
        Point p = event.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3388
        // Locate the renderer under the event location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
        int hitColumnIndex = columnAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
        int hitRowIndex = rowAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
        if ((hitColumnIndex != -1) && (hitRowIndex != -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
            TableCellRenderer renderer = getCellRenderer(hitRowIndex, hitColumnIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
            Component component = prepareRenderer(renderer, hitRowIndex, hitColumnIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
            // Now have to see if the component is a JComponent before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
            // getting the tip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3398
            if (component instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
                // Convert the event to the renderer's coordinate system
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3400
                Rectangle cellRect = getCellRect(hitRowIndex, hitColumnIndex, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3401
                p.translate(-cellRect.x, -cellRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3402
                MouseEvent newEvent = new MouseEvent(component, event.getID(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
                                          event.getWhen(), event.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
                                          p.x, p.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
                                          event.getXOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3406
                                          event.getYOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
                                          event.getClickCount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3408
                                          event.isPopupTrigger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3409
                                          MouseEvent.NOBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3410
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3411
                tip = ((JComponent)component).getToolTipText(newEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3412
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
        // No tip from the renderer get our own tip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
        if (tip == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
            tip = getToolTipText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3419
        return tip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3421
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3423
// Editing Support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
     * Sets whether editors in this JTable get the keyboard focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
     * when an editor is activated as a result of the JTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3429
     * forwarding keyboard events for a cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
     * By default, this property is false, and the JTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3431
     * retains the focus unless the cell is clicked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3432
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3433
     * @param surrendersFocusOnKeystroke true if the editor should get the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3434
     *          when keystrokes cause the editor to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3435
     *          activated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3437
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
     * @see #getSurrendersFocusOnKeystroke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3439
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3440
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3441
    public void setSurrendersFocusOnKeystroke(boolean surrendersFocusOnKeystroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3442
        this.surrendersFocusOnKeystroke = surrendersFocusOnKeystroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3444
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3445
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3446
     * Returns true if the editor should get the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3447
     * when keystrokes cause the editor to be activated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3448
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
     * @return  true if the editor should get the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3450
     *          when keystrokes cause the editor to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3451
     *          activated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3453
     * @see #setSurrendersFocusOnKeystroke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3454
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3455
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3456
    public boolean getSurrendersFocusOnKeystroke() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3457
        return surrendersFocusOnKeystroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3460
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3461
     * Programmatically starts editing the cell at <code>row</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3462
     * <code>column</code>, if those indices are in the valid range, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
     * the cell at those indices is editable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
     * Note that this is a convenience method for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
     * <code>editCellAt(int, int, null)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
     * @param   row                             the row to be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3468
     * @param   column                          the column to be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3469
     * @return  false if for any reason the cell cannot be edited,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3470
     *                or if the indices are invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3471
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3472
    public boolean editCellAt(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3473
        return editCellAt(row, column, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3477
     * Programmatically starts editing the cell at <code>row</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3478
     * <code>column</code>, if those indices are in the valid range, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
     * the cell at those indices is editable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
     * To prevent the <code>JTable</code> from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3481
     * editing a particular table, column or cell value, return false from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3482
     * the <code>isCellEditable</code> method in the <code>TableModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3483
     * interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
     * @param   row     the row to be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3486
     * @param   column  the column to be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
     * @param   e       event to pass into <code>shouldSelectCell</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
     *                  note that as of Java 2 platform v1.2, the call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
     *                  <code>shouldSelectCell</code> is no longer made
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
     * @return  false if for any reason the cell cannot be edited,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
     *                or if the indices are invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3493
    public boolean editCellAt(int row, int column, EventObject e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3494
        if (cellEditor != null && !cellEditor.stopCellEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3495
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3498
        if (row < 0 || row >= getRowCount() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3499
            column < 0 || column >= getColumnCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3500
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3502
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3503
        if (!isCellEditable(row, column))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3504
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
        if (editorRemover == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3507
            KeyboardFocusManager fm =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3508
                KeyboardFocusManager.getCurrentKeyboardFocusManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3509
            editorRemover = new CellEditorRemover(fm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
            fm.addPropertyChangeListener("permanentFocusOwner", editorRemover);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3513
        TableCellEditor editor = getCellEditor(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
        if (editor != null && editor.isCellEditable(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
            editorComp = prepareEditor(editor, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3516
            if (editorComp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3517
                removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3518
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3519
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3520
            editorComp.setBounds(getCellRect(row, column, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3521
            add(editorComp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3522
            editorComp.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3523
            editorComp.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3524
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3525
            setCellEditor(editor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3526
            setEditingRow(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
            setEditingColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
            editor.addCellEditorListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3535
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3536
     * Returns true if a cell is being edited.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3537
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3538
     * @return  true if the table is editing a cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3539
     * @see     #editingColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3540
     * @see     #editingRow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3541
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3542
    public boolean isEditing() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  3543
        return cellEditor != null;
2
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 the component that is handling the editing session.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3548
     * If nothing is being edited, returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3549
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3550
     * @return  Component handling editing session
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3551
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3552
    public Component getEditorComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3553
        return editorComp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3554
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3555
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3556
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3557
     * Returns the index of the column that contains the cell currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3558
     * being edited.  If nothing is being edited, returns -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3559
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3560
     * @return  the index of the column that contains the cell currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3561
     *          being edited; returns -1 if nothing being edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3562
     * @see #editingRow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3563
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3564
    public int getEditingColumn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3565
        return editingColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3567
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3568
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3569
     * Returns the index of the row that contains the cell currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3570
     * being edited.  If nothing is being edited, returns -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3571
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3572
     * @return  the index of the row that contains the cell currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3573
     *          being edited; returns -1 if nothing being edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3574
     * @see #editingColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3575
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3576
    public int getEditingRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3577
        return editingRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3579
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3580
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3581
// Managing TableUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3582
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3583
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3584
    /**
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 16100
diff changeset
  3585
     * Returns the L&amp;F object that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3586
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3587
     * @return the <code>TableUI</code> object that renders this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3588
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3589
    public TableUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3590
        return (TableUI)ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3591
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3592
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3593
    /**
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 16100
diff changeset
  3594
     * Sets the L&amp;F object that renders this component and repaints.
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 16100
diff changeset
  3595
     *
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 16100
diff changeset
  3596
     * @param ui  the TableUI L&amp;F object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3597
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3598
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3599
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3600
     *       hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3601
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3602
     *  description: The UI object that implements the Component's LookAndFeel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3603
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3604
    public void setUI(TableUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3605
        if (this.ui != ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3606
            super.setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3607
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3608
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3610
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3611
    /**
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 16100
diff changeset
  3612
     * Notification from the <code>UIManager</code> that the L&amp;F has changed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3613
     * Replaces the current UI object with the latest version from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3614
     * <code>UIManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3615
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3616
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3617
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3618
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3619
        // Update the UIs of the cell renderers, cell editors and header renderers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3620
        TableColumnModel cm = getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3621
        for(int column = 0; column < cm.getColumnCount(); column++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3622
            TableColumn aColumn = cm.getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3623
            SwingUtilities.updateRendererOrEditorUI(aColumn.getCellRenderer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3624
            SwingUtilities.updateRendererOrEditorUI(aColumn.getCellEditor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3625
            SwingUtilities.updateRendererOrEditorUI(aColumn.getHeaderRenderer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3627
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3628
        // Update the UIs of all the default renderers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3629
        Enumeration defaultRenderers = defaultRenderersByColumnClass.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3630
        while (defaultRenderers.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3631
            SwingUtilities.updateRendererOrEditorUI(defaultRenderers.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3632
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3633
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3634
        // Update the UIs of all the default editors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3635
        Enumeration defaultEditors = defaultEditorsByColumnClass.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3636
        while (defaultEditors.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3637
            SwingUtilities.updateRendererOrEditorUI(defaultEditors.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3638
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3639
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3640
        // Update the UI of the table header
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3641
        if (tableHeader != null && tableHeader.getParent() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3642
            tableHeader.updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3643
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3644
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
  3645
        // Update UI applied to parent ScrollPane
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
  3646
        configureEnclosingScrollPaneUI();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1301
diff changeset
  3647
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3648
        setUI((TableUI)UIManager.getUI(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3649
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3650
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3651
    /**
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 16100
diff changeset
  3652
     * Returns the suffix used to construct the name of the L&amp;F class used to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3653
     * render this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3654
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3655
     * @return the string "TableUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3656
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3657
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3658
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3659
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3660
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3661
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3662
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3663
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3664
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3665
// Managing models
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3666
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3667
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3668
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3669
     * Sets the data model for this table to <code>newModel</code> and registers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3670
     * with it for listener notifications from the new data model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3671
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3672
     * @param   dataModel        the new data source for this table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3673
     * @exception IllegalArgumentException      if <code>newModel</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3674
     * @see     #getModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3675
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3676
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3677
     *  description: The model that is the source of the data for this view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3678
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3679
    public void setModel(TableModel dataModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3680
        if (dataModel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3681
            throw new IllegalArgumentException("Cannot set a null TableModel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3683
        if (this.dataModel != dataModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3684
            TableModel old = this.dataModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3685
            if (old != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3686
                old.removeTableModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3687
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3688
            this.dataModel = dataModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3689
            dataModel.addTableModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3690
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3691
            tableChanged(new TableModelEvent(dataModel, TableModelEvent.HEADER_ROW));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3692
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3693
            firePropertyChange("model", old, dataModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3694
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3695
            if (getAutoCreateRowSorter()) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  3696
                setRowSorter(new TableRowSorter<TableModel>(dataModel));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3697
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3699
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3700
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3701
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3702
     * Returns the <code>TableModel</code> that provides the data displayed by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3703
     * <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3704
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3705
     * @return  the <code>TableModel</code> that provides the data displayed by this <code>JTable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3706
     * @see     #setModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3707
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3708
    public TableModel getModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3709
        return dataModel;
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
     * Sets the column model for this table to <code>newModel</code> and registers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3714
     * for listener notifications from the new column model. Also sets
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3715
     * the column model of the <code>JTableHeader</code> to <code>columnModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3716
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3717
     * @param   columnModel        the new data source for this table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3718
     * @exception IllegalArgumentException      if <code>columnModel</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3719
     * @see     #getColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3720
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3721
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3722
     *  description: The object governing the way columns appear in the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3723
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3724
    public void setColumnModel(TableColumnModel columnModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3725
        if (columnModel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3726
            throw new IllegalArgumentException("Cannot set a null ColumnModel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3727
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3728
        TableColumnModel old = this.columnModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3729
        if (columnModel != old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3730
            if (old != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3731
                old.removeColumnModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3732
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3733
            this.columnModel = columnModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3734
            columnModel.addColumnModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3735
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3736
            // Set the column model of the header as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3737
            if (tableHeader != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3738
                tableHeader.setColumnModel(columnModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3739
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3740
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3741
            firePropertyChange("columnModel", old, columnModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3742
            resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3743
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3744
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3745
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3746
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3747
     * Returns the <code>TableColumnModel</code> that contains all column information
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3748
     * of this table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3749
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3750
     * @return  the object that provides the column state of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3751
     * @see     #setColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3752
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3753
    public TableColumnModel getColumnModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3754
        return columnModel;
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
     * Sets the row selection model for this table to <code>newModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3759
     * and registers for listener notifications from the new selection model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3760
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3761
     * @param   newModel        the new selection model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3762
     * @exception IllegalArgumentException      if <code>newModel</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3763
     * @see     #getSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3764
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3765
     *      bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3766
     *      description: The selection model for rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3767
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3768
    public void setSelectionModel(ListSelectionModel newModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3769
        if (newModel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3770
            throw new IllegalArgumentException("Cannot set a null SelectionModel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3771
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3772
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3773
        ListSelectionModel oldModel = selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3774
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3775
        if (newModel != oldModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3776
            if (oldModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3777
                oldModel.removeListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3778
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3779
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3780
            selectionModel = newModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3781
            newModel.addListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3782
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3783
            firePropertyChange("selectionModel", oldModel, newModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3784
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3785
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3786
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3787
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3788
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3789
     * Returns the <code>ListSelectionModel</code> that is used to maintain row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3790
     * selection state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3791
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3792
     * @return  the object that provides row selection state, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3793
     *          if row selection is not allowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3794
     * @see     #setSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3795
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3796
    public ListSelectionModel getSelectionModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3797
        return selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3798
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3799
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3800
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3801
// RowSorterListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3802
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3803
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3804
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3805
     * <code>RowSorterListener</code> notification that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3806
     * <code>RowSorter</code> has changed in some way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3807
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3808
     * @param e the <code>RowSorterEvent</code> describing the change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3809
     * @throws NullPointerException if <code>e</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3810
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3811
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3812
    public void sorterChanged(RowSorterEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3813
        if (e.getType() == RowSorterEvent.Type.SORT_ORDER_CHANGED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3814
            JTableHeader header = getTableHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3815
            if (header != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3816
                header.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3817
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3818
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3819
        else if (e.getType() == RowSorterEvent.Type.SORTED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3820
            sorterChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3821
            if (!ignoreSortChange) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3822
                sortedTableChanged(e, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3823
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3824
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3825
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3826
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3827
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3828
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3829
     * SortManager provides support for managing the selection and variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3830
     * row heights when sorting is enabled. This information is encapsulated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3831
     * into a class to avoid bulking up JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3832
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3833
    private final class SortManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3834
        RowSorter<? extends TableModel> sorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3835
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3836
        // Selection, in terms of the model. This is lazily created
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3837
        // as needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3838
        private ListSelectionModel modelSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3839
        private int modelLeadIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3840
        // Set to true while in the process of changing the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3841
        // If this is true the selection change is ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3842
        private boolean syncingSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3843
        // Temporary cache of selection, in terms of model. This is only used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3844
        // if we don't need the full weight of modelSelection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3845
        private int[] lastModelSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3846
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3847
        // Heights of the rows in terms of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3848
        private SizeSequence modelRowSizes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3849
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3850
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3851
        SortManager(RowSorter<? extends TableModel> sorter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3852
            this.sorter = sorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3853
            sorter.addRowSorterListener(JTable.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3854
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3855
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3856
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3857
         * Disposes any resources used by this SortManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3858
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3859
        public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3860
            if (sorter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3861
                sorter.removeRowSorterListener(JTable.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3862
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3863
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3864
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3865
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3866
         * Sets the height for a row at a specified index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3867
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3868
        public void setViewRowHeight(int viewIndex, int rowHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3869
            if (modelRowSizes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3870
                modelRowSizes = new SizeSequence(getModel().getRowCount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3871
                                                 getRowHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3872
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3873
            modelRowSizes.setSize(convertRowIndexToModel(viewIndex),rowHeight);
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
         * Invoked when the underlying model has completely changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3878
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3879
        public void allChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3880
            modelLeadIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3881
            modelSelection = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3882
            modelRowSizes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3883
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3884
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3885
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3886
         * Invoked when the selection, on the view, has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3887
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3888
        public void viewSelectionChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3889
            if (!syncingSelection && modelSelection != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3890
                modelSelection = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3891
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3892
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3893
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3894
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3895
         * Invoked when either the table model has changed, or the RowSorter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3896
         * has changed. This is invoked prior to notifying the sorter of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3897
         * change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3898
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3899
        public void prepareForChange(RowSorterEvent sortEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3900
                                     ModelChange change) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3901
            if (getUpdateSelectionOnSort()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3902
                cacheSelection(sortEvent, change);
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
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3907
         * Updates the internal cache of the selection based on the change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3908
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3909
        private void cacheSelection(RowSorterEvent sortEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3910
                                    ModelChange change) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3911
            if (sortEvent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3912
                // sort order changed. If modelSelection is null and filtering
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3913
                // is enabled we need to cache the selection in terms of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3914
                // underlying model, this will allow us to correctly restore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3915
                // the selection even if rows are filtered out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3916
                if (modelSelection == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3917
                        sorter.getViewRowCount() != getModel().getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3918
                    modelSelection = new DefaultListSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3919
                    ListSelectionModel viewSelection = getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3920
                    int min = viewSelection.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3921
                    int max = viewSelection.getMaxSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3922
                    int modelIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3923
                    for (int viewIndex = min; viewIndex <= max; viewIndex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3924
                        if (viewSelection.isSelectedIndex(viewIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3925
                            modelIndex = convertRowIndexToModel(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3926
                                    sortEvent, viewIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3927
                            if (modelIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3928
                                modelSelection.addSelectionInterval(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3929
                                    modelIndex, modelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3930
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3931
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3932
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3933
                    modelIndex = convertRowIndexToModel(sortEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3934
                            viewSelection.getLeadSelectionIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3935
                    SwingUtilities2.setLeadAnchorWithoutSelection(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3936
                            modelSelection, modelIndex, modelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3937
                } else if (modelSelection == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3938
                    // Sorting changed, haven't cached selection in terms
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3939
                    // of model and no filtering. Temporarily cache selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3940
                    cacheModelSelection(sortEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3941
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3942
            } else if (change.allRowsChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3943
                // All the rows have changed, chuck any cached selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3944
                modelSelection = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3945
            } else if (modelSelection != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3946
                // Table changed, reflect changes in cached selection model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3947
                switch(change.type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3948
                case TableModelEvent.DELETE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3949
                    modelSelection.removeIndexInterval(change.startModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3950
                                                       change.endModelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3951
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3952
                case TableModelEvent.INSERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3953
                    modelSelection.insertIndexInterval(change.startModelIndex,
14992
e9db4be29324 8005019: JTable passes row index instead of length when inserts selection interval
alexsch
parents: 13546
diff changeset
  3954
                                                       change.length,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3955
                                                       true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3956
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3957
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3958
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3959
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3960
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3961
                // table changed, but haven't cached rows, temporarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3962
                // cache them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3963
                cacheModelSelection(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3964
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3965
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3966
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3967
        private void cacheModelSelection(RowSorterEvent sortEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3968
            lastModelSelection = convertSelectionToModel(sortEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3969
            modelLeadIndex = convertRowIndexToModel(sortEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3970
                        selectionModel.getLeadSelectionIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3971
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3972
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3973
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3974
         * Inovked when either the table has changed or the sorter has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3975
         * and after the sorter has been notified. If necessary this will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3976
         * reapply the selection and variable row heights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3977
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3978
        public void processChange(RowSorterEvent sortEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3979
                                  ModelChange change,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3980
                                  boolean sorterChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3981
            if (change != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3982
                if (change.allRowsChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3983
                    modelRowSizes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3984
                    rowModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3985
                } else if (modelRowSizes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3986
                    if (change.type == TableModelEvent.INSERT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3987
                        modelRowSizes.insertEntries(change.startModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3988
                                                    change.endModelIndex -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3989
                                                    change.startModelIndex + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3990
                                                    getRowHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3991
                    } else if (change.type == TableModelEvent.DELETE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3992
                        modelRowSizes.removeEntries(change.startModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3993
                                                    change.endModelIndex -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3994
                                                    change.startModelIndex +1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3995
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3996
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3997
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3998
            if (sorterChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3999
                setViewRowHeightsFromModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4000
                restoreSelection(change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4001
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4002
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4004
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4005
         * Resets the variable row heights in terms of the view from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4006
         * that of the variable row heights in terms of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4007
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4008
        private void setViewRowHeightsFromModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4009
            if (modelRowSizes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4010
                rowModel.setSizes(getRowCount(), getRowHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4011
                for (int viewIndex = getRowCount() - 1; viewIndex >= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4012
                         viewIndex--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4013
                    int modelIndex = convertRowIndexToModel(viewIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4014
                    rowModel.setSize(viewIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4015
                                     modelRowSizes.getSize(modelIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4016
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4017
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4018
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4020
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4021
         * Restores the selection from that in terms of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4022
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4023
        private void restoreSelection(ModelChange change) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4024
            syncingSelection = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4025
            if (lastModelSelection != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4026
                restoreSortingSelection(lastModelSelection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4027
                                        modelLeadIndex, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4028
                lastModelSelection = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4029
            } else if (modelSelection != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4030
                ListSelectionModel viewSelection = getSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4031
                viewSelection.setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4032
                viewSelection.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4033
                int min = modelSelection.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4034
                int max = modelSelection.getMaxSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4035
                int viewIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4036
                for (int modelIndex = min; modelIndex <= max; modelIndex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4037
                    if (modelSelection.isSelectedIndex(modelIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4038
                        viewIndex = convertRowIndexToView(modelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4039
                        if (viewIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4040
                            viewSelection.addSelectionInterval(viewIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4041
                                                               viewIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4042
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4043
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4044
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4045
                // Restore the lead
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4046
                int viewLeadIndex = modelSelection.getLeadSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4047
                if (viewLeadIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4048
                    viewLeadIndex = convertRowIndexToView(viewLeadIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4049
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4050
                SwingUtilities2.setLeadAnchorWithoutSelection(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4051
                        viewSelection, viewLeadIndex, viewLeadIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4052
                viewSelection.setValueIsAdjusting(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4053
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4054
            syncingSelection = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4055
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4056
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4059
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4060
     * ModelChange is used when sorting to restore state, it corresponds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4061
     * to data from a TableModelEvent.  The values are precalculated as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4062
     * they are used extensively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4063
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4064
    private final class ModelChange {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4065
        // Starting index of the change, in terms of the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4066
        int startModelIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4068
        // Ending index of the change, in terms of the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4069
        int endModelIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4071
        // Type of change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4072
        int type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4074
        // Number of rows in the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4075
        int modelRowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4077
        // The event that triggered this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4078
        TableModelEvent event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4080
        // Length of the change (end - start + 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4081
        int length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4083
        // True if the event indicates all the contents have changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4084
        boolean allRowsChanged;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4086
        ModelChange(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4087
            startModelIndex = Math.max(0, e.getFirstRow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4088
            endModelIndex = e.getLastRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4089
            modelRowCount = getModel().getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4090
            if (endModelIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4091
                endModelIndex = Math.max(0, modelRowCount - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4092
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4093
            length = endModelIndex - startModelIndex + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4094
            type = e.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4095
            event = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4096
            allRowsChanged = (e.getLastRow() == Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4097
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4098
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4101
     * Invoked when <code>sorterChanged</code> is invoked, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4102
     * when <code>tableChanged</code> is invoked and sorting is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4104
    private void sortedTableChanged(RowSorterEvent sortedEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4105
                                    TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4106
        int editingModelIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4107
        ModelChange change = (e != null) ? new ModelChange(e) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4109
        if ((change == null || !change.allRowsChanged) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4110
                this.editingRow != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4111
            editingModelIndex = convertRowIndexToModel(sortedEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4112
                                                       this.editingRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4115
        sortManager.prepareForChange(sortedEvent, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4117
        if (e != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4118
            if (change.type == TableModelEvent.UPDATE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4119
                repaintSortedRows(change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4120
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4121
            notifySorter(change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4122
            if (change.type != TableModelEvent.UPDATE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4123
                // If the Sorter is unsorted we will not have received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4124
                // notification, force treating insert/delete as a change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4125
                sorterChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4126
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4128
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4129
            sorterChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4132
        sortManager.processChange(sortedEvent, change, sorterChanged);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4134
        if (sorterChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4135
            // Update the editing row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4136
            if (this.editingRow != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4137
                int newIndex = (editingModelIndex == -1) ? -1 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4138
                        convertRowIndexToView(editingModelIndex,change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4139
                restoreSortingEditingRow(newIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4140
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4141
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4142
            // And handle the appropriate repainting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4143
            if (e == null || change.type != TableModelEvent.UPDATE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4144
                resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4145
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4147
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4148
        // Check if lead/anchor need to be reset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4149
        if (change != null && change.allRowsChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4150
            clearSelectionAndLeadAnchor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4151
            resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4155
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4156
     * Repaints the sort of sorted rows in response to a TableModelEvent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4158
    private void repaintSortedRows(ModelChange change) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4159
        if (change.startModelIndex > change.endModelIndex ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4160
                change.startModelIndex + 10 < change.endModelIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4161
            // Too much has changed, punt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4162
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4163
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4165
        int eventColumn = change.event.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4166
        int columnViewIndex = eventColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4167
        if (columnViewIndex == TableModelEvent.ALL_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4168
            columnViewIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4170
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4171
            columnViewIndex = convertColumnIndexToView(columnViewIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4172
            if (columnViewIndex == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4173
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4174
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4176
        int modelIndex = change.startModelIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4177
        while (modelIndex <= change.endModelIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4178
            int viewIndex = convertRowIndexToView(modelIndex++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4179
            if (viewIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4180
                Rectangle dirty = getCellRect(viewIndex, columnViewIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4181
                                              false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4182
                int x = dirty.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4183
                int w = dirty.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4184
                if (eventColumn == TableModelEvent.ALL_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4185
                    x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4186
                    w = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4187
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4188
                repaint(x, dirty.y, w, dirty.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4189
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4194
     * Restores the selection after a model event/sort order changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4195
     * All coordinates are in terms of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4197
    private void restoreSortingSelection(int[] selection, int lead,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4198
            ModelChange change) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4199
        // Convert the selection from model to view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4200
        for (int i = selection.length - 1; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4201
            selection[i] = convertRowIndexToView(selection[i], change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4203
        lead = convertRowIndexToView(lead, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4205
        // Check for the common case of no change in selection for 1 row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4206
        if (selection.length == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4207
            (selection.length == 1 && selection[0] == getSelectedRow())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4208
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4211
        // And apply the new selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4212
        selectionModel.setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4213
        selectionModel.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4214
        for (int i = selection.length - 1; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4215
            if (selection[i] != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4216
                selectionModel.addSelectionInterval(selection[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4217
                                                    selection[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4218
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4220
        SwingUtilities2.setLeadAnchorWithoutSelection(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4221
                selectionModel, lead, lead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4222
        selectionModel.setValueIsAdjusting(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4224
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4226
     * Restores the editing row after a model event/sort order change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4228
     * @param editingRow new index of the editingRow, in terms of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4230
    private void restoreSortingEditingRow(int editingRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4231
        if (editingRow == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4232
            // Editing row no longer being shown, cancel editing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4233
            TableCellEditor editor = getCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4234
            if (editor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4235
                // First try and cancel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4236
                editor.cancelCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4237
                if (getCellEditor() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4238
                    // CellEditor didn't cede control, forcefully
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4239
                    // remove it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4240
                    removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4241
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4242
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4244
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4245
            // Repositioning handled in BasicTableUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4246
            this.editingRow = editingRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4247
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4250
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4252
     * Notifies the sorter of a change in the underlying model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4254
    private void notifySorter(ModelChange change) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4255
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4256
            ignoreSortChange = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4257
            sorterChanged = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4258
            switch(change.type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4259
            case TableModelEvent.UPDATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4260
                if (change.event.getLastRow() == Integer.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4261
                    sortManager.sorter.allRowsChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4262
                } else if (change.event.getColumn() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4263
                           TableModelEvent.ALL_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4264
                    sortManager.sorter.rowsUpdated(change.startModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4265
                                       change.endModelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4266
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4267
                    sortManager.sorter.rowsUpdated(change.startModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4268
                                       change.endModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4269
                                       change.event.getColumn());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4270
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4271
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4272
            case TableModelEvent.INSERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4273
                sortManager.sorter.rowsInserted(change.startModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4274
                                    change.endModelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4275
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4276
            case TableModelEvent.DELETE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4277
                sortManager.sorter.rowsDeleted(change.startModelIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4278
                                   change.endModelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4279
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4280
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4281
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4282
            ignoreSortChange = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4287
     * Converts a model index to view index.  This is called when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4288
     * sorter or model changes and sorting is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4290
     * @param change describes the TableModelEvent that initiated the change;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4291
     *        will be null if called as the result of a sort
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4293
    private int convertRowIndexToView(int modelIndex, ModelChange change) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4294
        if (modelIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4295
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4297
        if (change != null && modelIndex >= change.startModelIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4298
            if (change.type == TableModelEvent.INSERT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4299
                if (modelIndex + change.length >= change.modelRowCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4300
                    return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4301
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4302
                return sortManager.sorter.convertRowIndexToView(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4303
                        modelIndex + change.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4305
            else if (change.type == TableModelEvent.DELETE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4306
                if (modelIndex <= change.endModelIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4307
                    // deleted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4308
                    return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4309
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4310
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4311
                    if (modelIndex - change.length >= change.modelRowCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4312
                        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4313
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4314
                    return sortManager.sorter.convertRowIndexToView(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4315
                            modelIndex - change.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4316
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4317
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4318
            // else, updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4320
        if (modelIndex >= getModel().getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4321
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4323
        return sortManager.sorter.convertRowIndexToView(modelIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4325
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4326
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4327
     * Converts the selection to model coordinates.  This is used when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4328
     * the model changes or the sorter changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4330
    private int[] convertSelectionToModel(RowSorterEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4331
        int[] selection = getSelectedRows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4332
        for (int i = selection.length - 1; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4333
            selection[i] = convertRowIndexToModel(e, selection[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4335
        return selection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4338
    private int convertRowIndexToModel(RowSorterEvent e, int viewIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4339
        if (e != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4340
            if (e.getPreviousRowCount() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4341
                return viewIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4342
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4343
            // range checking handled by RowSorterEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4344
            return e.convertPreviousRowIndexToModel(viewIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4345
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4346
        // Make sure the viewIndex is valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4347
        if (viewIndex < 0 || viewIndex >= getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4348
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4350
        return convertRowIndexToModel(viewIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4352
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4353
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4354
// Implementing TableModelListener interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4355
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4356
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4358
     * Invoked when this table's <code>TableModel</code> generates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4359
     * a <code>TableModelEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4360
     * The <code>TableModelEvent</code> should be constructed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4361
     * coordinate system of the model; the appropriate mapping to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4362
     * view coordinate system is performed by this <code>JTable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4363
     * when it receives the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4364
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4365
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4366
     * are used internally by <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4367
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4368
     * Note that as of 1.3, this method clears the selection, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4369
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4370
    public void tableChanged(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4371
        if (e == null || e.getFirstRow() == TableModelEvent.HEADER_ROW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4372
            // The whole thing changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4373
            clearSelectionAndLeadAnchor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4375
            rowModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4376
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4377
            if (sortManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4378
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4379
                    ignoreSortChange = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4380
                    sortManager.sorter.modelStructureChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4381
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4382
                    ignoreSortChange = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4383
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4384
                sortManager.allChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4385
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4386
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4387
            if (getAutoCreateColumnsFromModel()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4388
                // This will effect invalidation of the JTable and JTableHeader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4389
                createDefaultColumnsFromModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4390
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4391
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4392
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4393
            resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4394
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4395
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4396
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4397
        if (sortManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4398
            sortedTableChanged(null, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4399
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4400
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4401
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4402
        // The totalRowHeight calculated below will be incorrect if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4403
        // there are variable height rows. Repaint the visible region,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4404
        // but don't return as a revalidate may be necessary as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4405
        if (rowModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4406
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4408
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4409
        if (e.getType() == TableModelEvent.INSERT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4410
            tableRowsInserted(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4411
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4413
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4414
        if (e.getType() == TableModelEvent.DELETE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4415
            tableRowsDeleted(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4416
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4417
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4418
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4419
        int modelColumn = e.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4420
        int start = e.getFirstRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4421
        int end = e.getLastRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4422
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4423
        Rectangle dirtyRegion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4424
        if (modelColumn == TableModelEvent.ALL_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4425
            // 1 or more rows changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4426
            dirtyRegion = new Rectangle(0, start * getRowHeight(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4427
                                        getColumnModel().getTotalColumnWidth(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4429
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4430
            // A cell or column of cells has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4431
            // Unlike the rest of the methods in the JTable, the TableModelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4432
            // uses the coordinate system of the model instead of the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4433
            // This is the only place in the JTable where this "reverse mapping"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4434
            // is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4435
            int column = convertColumnIndexToView(modelColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4436
            dirtyRegion = getCellRect(start, column, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4439
        // Now adjust the height of the dirty region according to the value of "end".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4440
        // Check for Integer.MAX_VALUE as this will cause an overflow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4441
        if (end != Integer.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4442
            dirtyRegion.height = (end-start+1)*getRowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4443
            repaint(dirtyRegion.x, dirtyRegion.y, dirtyRegion.width, dirtyRegion.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4445
        // In fact, if the end is Integer.MAX_VALUE we need to revalidate anyway
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4446
        // because the scrollbar may need repainting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4447
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4448
            clearSelectionAndLeadAnchor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4449
            resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4450
            rowModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4453
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4454
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4455
     * Invoked when rows have been inserted into the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4456
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4457
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4458
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4459
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4460
     * @param e the TableModelEvent encapsulating the insertion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4461
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4462
    private void tableRowsInserted(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4463
        int start = e.getFirstRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4464
        int end = e.getLastRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4465
        if (start < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4466
            start = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4467
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4468
        if (end < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4469
            end = getRowCount()-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4471
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4472
        // Adjust the selection to account for the new rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4473
        int length = end - start + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4474
        selectionModel.insertIndexInterval(start, length, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4475
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4476
        // If we have variable height rows, adjust the row model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4477
        if (rowModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4478
            rowModel.insertEntries(start, length, getRowHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4480
        int rh = getRowHeight() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4481
        Rectangle drawRect = new Rectangle(0, start * rh,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4482
                                        getColumnModel().getTotalColumnWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4483
                                           (getRowCount()-start) * rh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4484
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4485
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4486
        // PENDING(milne) revalidate calls repaint() if parent is a ScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4487
        // repaint still required in the unusual case where there is no ScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4488
        repaint(drawRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4489
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4490
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4491
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4492
     * Invoked when rows have been removed from the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4493
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4494
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4495
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4496
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4497
     * @param e the TableModelEvent encapsulating the deletion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4498
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4499
    private void tableRowsDeleted(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4500
        int start = e.getFirstRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4501
        int end = e.getLastRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4502
        if (start < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4503
            start = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4504
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4505
        if (end < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4506
            end = getRowCount()-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4509
        int deletedCount = end - start + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4510
        int previousRowCount = getRowCount() + deletedCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4511
        // Adjust the selection to account for the new rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4512
        selectionModel.removeIndexInterval(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4513
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4514
        // If we have variable height rows, adjust the row model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4515
        if (rowModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4516
            rowModel.removeEntries(start, deletedCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4517
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4519
        int rh = getRowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4520
        Rectangle drawRect = new Rectangle(0, start * rh,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4521
                                        getColumnModel().getTotalColumnWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4522
                                        (previousRowCount - start) * rh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4524
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4525
        // PENDING(milne) revalidate calls repaint() if parent is a ScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4526
        // repaint still required in the unusual case where there is no ScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4527
        repaint(drawRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4529
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4530
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4531
// Implementing TableColumnModelListener interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4532
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4533
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4534
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4535
     * Invoked when a column is added to the table column model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4536
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4537
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4538
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4539
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4540
     * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4541
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4542
    public void columnAdded(TableColumnModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4543
        // If I'm currently editing, then I should stop editing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4544
        if (isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4545
            removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4546
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4547
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4548
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4549
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4550
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4551
     * Invoked when a column is removed from the table column model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4552
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4553
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4554
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4555
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4556
     * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4557
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4558
    public void columnRemoved(TableColumnModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4559
        // If I'm currently editing, then I should stop editing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4560
        if (isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4561
            removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4562
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4563
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4565
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4566
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4567
     * Invoked when a column is repositioned. If a cell is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4568
     * edited, then editing is stopped and the cell is redrawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4569
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4570
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4571
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4572
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4573
     * @param e   the event received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4574
     * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4575
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4576
    public void columnMoved(TableColumnModelEvent e) {
6651
f3f6465a128e 4330950: Lost newly entered data in the cell when resizing column width
alexp
parents: 6288
diff changeset
  4577
        if (isEditing() && !getCellEditor().stopCellEditing()) {
f3f6465a128e 4330950: Lost newly entered data in the cell when resizing column width
alexp
parents: 6288
diff changeset
  4578
            getCellEditor().cancelCellEditing();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4580
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4581
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4582
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4583
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4584
     * Invoked when a column is moved due to a margin change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4585
     * If a cell is being edited, then editing is stopped and the cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4586
     * is redrawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4587
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4588
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4589
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4590
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4591
     * @param  e    the event received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4592
     * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4593
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4594
    public void columnMarginChanged(ChangeEvent e) {
6651
f3f6465a128e 4330950: Lost newly entered data in the cell when resizing column width
alexp
parents: 6288
diff changeset
  4595
        if (isEditing() && !getCellEditor().stopCellEditing()) {
f3f6465a128e 4330950: Lost newly entered data in the cell when resizing column width
alexp
parents: 6288
diff changeset
  4596
            getCellEditor().cancelCellEditing();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4597
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4598
        TableColumn resizingColumn = getResizingColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4599
        // Need to do this here, before the parent's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4600
        // layout manager calls getPreferredSize().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4601
        if (resizingColumn != null && autoResizeMode == AUTO_RESIZE_OFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4602
            resizingColumn.setPreferredWidth(resizingColumn.getWidth());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4603
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4604
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4605
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4606
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4607
    private int limit(int i, int a, int b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4608
        return Math.min(b, Math.max(i, a));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4610
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4611
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4612
     * Invoked when the selection model of the <code>TableColumnModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4613
     * is changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4614
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4615
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4616
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4617
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4618
     * @param  e  the event received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4619
     * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4620
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4621
    public void columnSelectionChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4622
        boolean isAdjusting = e.getValueIsAdjusting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4623
        if (columnSelectionAdjusting && !isAdjusting) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4624
            // The assumption is that when the model is no longer adjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4625
            // we will have already gotten all the changes, and therefore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4626
            // don't need to do an additional paint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4627
            columnSelectionAdjusting = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4628
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4629
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4630
        columnSelectionAdjusting = isAdjusting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4631
        // The getCellRect() call will fail unless there is at least one row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4632
        if (getRowCount() <= 0 || getColumnCount() <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4633
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4634
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4635
        int firstIndex = limit(e.getFirstIndex(), 0, getColumnCount()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4636
        int lastIndex = limit(e.getLastIndex(), 0, getColumnCount()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4637
        int minRow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4638
        int maxRow = getRowCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4639
        if (getRowSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4640
            minRow = selectionModel.getMinSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4641
            maxRow = selectionModel.getMaxSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4642
            int leadRow = getAdjustedIndex(selectionModel.getLeadSelectionIndex(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4643
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4644
            if (minRow == -1 || maxRow == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4645
                if (leadRow == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4646
                    // nothing to repaint, return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4647
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4648
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4649
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4650
                // only thing to repaint is the lead
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4651
                minRow = maxRow = leadRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4652
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4653
                // We need to consider more than just the range between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4654
                // the min and max selected index. The lead row, which could
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4655
                // be outside this range, should be considered also.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4656
                if (leadRow != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4657
                    minRow = Math.min(minRow, leadRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4658
                    maxRow = Math.max(maxRow, leadRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4659
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4660
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4661
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4662
        Rectangle firstColumnRect = getCellRect(minRow, firstIndex, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4663
        Rectangle lastColumnRect = getCellRect(maxRow, lastIndex, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4664
        Rectangle dirtyRegion = firstColumnRect.union(lastColumnRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4665
        repaint(dirtyRegion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4666
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4667
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4668
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4669
// Implementing ListSelectionListener interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4670
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4671
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4672
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4673
     * Invoked when the row selection changes -- repaints to show the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4674
     * selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4675
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4676
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4677
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4678
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4679
     * @param e   the event received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4680
     * @see ListSelectionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4681
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4682
    public void valueChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4683
        if (sortManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4684
            sortManager.viewSelectionChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4685
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4686
        boolean isAdjusting = e.getValueIsAdjusting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4687
        if (rowSelectionAdjusting && !isAdjusting) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4688
            // The assumption is that when the model is no longer adjusting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4689
            // we will have already gotten all the changes, and therefore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4690
            // don't need to do an additional paint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4691
            rowSelectionAdjusting = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4692
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4694
        rowSelectionAdjusting = isAdjusting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4695
        // The getCellRect() calls will fail unless there is at least one column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4696
        if (getRowCount() <= 0 || getColumnCount() <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4697
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4699
        int firstIndex = limit(e.getFirstIndex(), 0, getRowCount()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4700
        int lastIndex = limit(e.getLastIndex(), 0, getRowCount()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4701
        Rectangle firstRowRect = getCellRect(firstIndex, 0, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4702
        Rectangle lastRowRect = getCellRect(lastIndex, getColumnCount()-1, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4703
        Rectangle dirtyRegion = firstRowRect.union(lastRowRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4704
        repaint(dirtyRegion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4705
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4706
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4707
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4708
// Implementing the CellEditorListener interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4709
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4710
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4711
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4712
     * Invoked when editing is finished. The changes are saved and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4713
     * editor is discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4714
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4715
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4716
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4717
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4718
     * @param  e  the event received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4719
     * @see CellEditorListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4720
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4721
    public void editingStopped(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4722
        // Take in the new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4723
        TableCellEditor editor = getCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4724
        if (editor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4725
            Object value = editor.getCellEditorValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4726
            setValueAt(value, editingRow, editingColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4727
            removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4728
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4729
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4730
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4731
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4732
     * Invoked when editing is canceled. The editor object is discarded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4733
     * and the cell is rendered once again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4734
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4735
     * Application code will not use these methods explicitly, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4736
     * are used internally by JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4737
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4738
     * @param  e  the event received
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4739
     * @see CellEditorListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4740
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4741
    public void editingCanceled(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4742
        removeEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4743
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4744
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4745
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4746
// Implementing the Scrollable interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4747
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4748
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4749
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4750
     * Sets the preferred size of the viewport for this table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4751
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4752
     * @param size  a <code>Dimension</code> object specifying the <code>preferredSize</code> of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4753
     *              <code>JViewport</code> whose view is this table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4754
     * @see Scrollable#getPreferredScrollableViewportSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4755
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4756
     * description: The preferred size of the viewport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4757
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4758
    public void setPreferredScrollableViewportSize(Dimension size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4759
        preferredViewportSize = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4760
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4761
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4762
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4763
     * Returns the preferred size of the viewport for this table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4764
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4765
     * @return a <code>Dimension</code> object containing the <code>preferredSize</code> of the <code>JViewport</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4766
     *         which displays this table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4767
     * @see Scrollable#getPreferredScrollableViewportSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4768
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4769
    public Dimension getPreferredScrollableViewportSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4770
        return preferredViewportSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4771
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4772
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4773
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4774
     * Returns the scroll increment (in pixels) that completely exposes one new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4775
     * row or column (depending on the orientation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4776
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4777
     * This method is called each time the user requests a unit scroll.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4778
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4779
     * @param visibleRect the view area visible within the viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4780
     * @param orientation either <code>SwingConstants.VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4781
     *                  or <code>SwingConstants.HORIZONTAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4782
     * @param direction less than zero to scroll up/left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4783
     *                  greater than zero for down/right
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4784
     * @return the "unit" increment for scrolling in the specified direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4785
     * @see Scrollable#getScrollableUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4786
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4787
    public int getScrollableUnitIncrement(Rectangle visibleRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4788
                                          int orientation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4789
                                          int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4790
        int leadingRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4791
        int leadingCol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4792
        Rectangle leadingCellRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4793
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4794
        int leadingVisibleEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4795
        int leadingCellEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4796
        int leadingCellSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4797
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4798
        leadingRow = getLeadingRow(visibleRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4799
        leadingCol = getLeadingCol(visibleRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4800
        if (orientation == SwingConstants.VERTICAL && leadingRow < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4801
            // Couldn't find leading row - return some default value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4802
            return getRowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4803
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4804
        else if (orientation == SwingConstants.HORIZONTAL && leadingCol < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4805
            // Couldn't find leading col - return some default value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4806
            return 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4807
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4808
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4809
        // Note that it's possible for one of leadingCol or leadingRow to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4810
        // -1, depending on the orientation.  This is okay, as getCellRect()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4811
        // still provides enough information to calculate the unit increment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4812
        leadingCellRect = getCellRect(leadingRow, leadingCol, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4813
        leadingVisibleEdge = leadingEdge(visibleRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4814
        leadingCellEdge = leadingEdge(leadingCellRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4815
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4816
        if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4817
            leadingCellSize = leadingCellRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4818
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4819
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4820
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4821
            leadingCellSize = leadingCellRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4822
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4823
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4824
        // 4 cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4825
        // #1: Leading cell fully visible, reveal next cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4826
        // #2: Leading cell fully visible, hide leading cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4827
        // #3: Leading cell partially visible, hide rest of leading cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4828
        // #4: Leading cell partially visible, reveal rest of leading cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4829
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4830
        if (leadingVisibleEdge == leadingCellEdge) { // Leading cell is fully
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4831
                                                     // visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4832
            // Case #1: Reveal previous cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4833
            if (direction < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4834
                int retVal = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4835
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4836
                if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4837
                    // Loop past any zero-height rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4838
                    while (--leadingRow >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4839
                        retVal = getRowHeight(leadingRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4840
                        if (retVal != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4841
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4842
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4843
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4844
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4845
                else { // HORIZONTAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4846
                    // Loop past any zero-width cols
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4847
                    while (--leadingCol >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4848
                        retVal = getCellRect(leadingRow, leadingCol, true).width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4849
                        if (retVal != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4850
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4851
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4852
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4853
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4854
                return retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4855
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4856
            else { // Case #2: hide leading cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4857
                return leadingCellSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4858
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4859
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4860
        else { // Leading cell is partially hidden
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4861
            // Compute visible, hidden portions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4862
            int hiddenAmt = Math.abs(leadingVisibleEdge - leadingCellEdge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4863
            int visibleAmt = leadingCellSize - hiddenAmt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4864
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4865
            if (direction > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4866
                // Case #3: hide showing portion of leading cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4867
                return visibleAmt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4868
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4869
            else { // Case #4: reveal hidden portion of leading cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4870
                return hiddenAmt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4871
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4872
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4873
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4874
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4875
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4876
     * Returns <code>visibleRect.height</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4877
     * <code>visibleRect.width</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4878
     * depending on this table's orientation.  Note that as of Swing 1.1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4879
     * (Java 2 v 1.2.2) the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4880
     * returned will ensure that the viewport is cleanly aligned on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4881
     * a row boundary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4882
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4883
     * @return <code>visibleRect.height</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4884
     *                                  <code>visibleRect.width</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4885
     *                                  per the orientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4886
     * @see Scrollable#getScrollableBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4887
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4888
    public int getScrollableBlockIncrement(Rectangle visibleRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4889
            int orientation, int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4890
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4891
        if (getRowCount() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4892
            // Short-circuit empty table model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4893
            if (SwingConstants.VERTICAL == orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4894
                int rh = getRowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4895
                return (rh > 0) ? Math.max(rh, (visibleRect.height / rh) * rh) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4896
                                  visibleRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4897
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4898
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4899
                return visibleRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4900
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4901
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4902
        // Shortcut for vertical scrolling of a table w/ uniform row height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4903
        if (null == rowModel && SwingConstants.VERTICAL == orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4904
            int row = rowAtPoint(visibleRect.getLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4905
            assert row != -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4906
            int col = columnAtPoint(visibleRect.getLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4907
            Rectangle cellRect = getCellRect(row, col, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4908
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4909
            if (cellRect.y == visibleRect.y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4910
                int rh = getRowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4911
                assert rh > 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4912
                return Math.max(rh, (visibleRect.height / rh) * rh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4913
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4914
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4915
        if (direction < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4916
            return getPreviousBlockIncrement(visibleRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4917
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4918
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4919
            return getNextBlockIncrement(visibleRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4920
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4921
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4922
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4923
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4924
     * Called to get the block increment for upward scrolling in cases of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4925
     * horizontal scrolling, or for vertical scrolling of a table with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4926
     * variable row heights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4927
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4928
    private int getPreviousBlockIncrement(Rectangle visibleRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4929
                                          int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4930
        // Measure back from visible leading edge
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4931
        // If we hit the cell on its leading edge, it becomes the leading cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4932
        // Else, use following cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4933
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4934
        int row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4935
        int col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4936
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4937
        int   newEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4938
        Point newCellLoc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4939
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4940
        int visibleLeadingEdge = leadingEdge(visibleRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4941
        boolean leftToRight = getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4942
        int newLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4943
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4944
        // Roughly determine the new leading edge by measuring back from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4945
        // leading visible edge by the size of the visible rect, and find the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4946
        // cell there.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4947
        if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4948
            newEdge = visibleLeadingEdge - visibleRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4949
            int x = visibleRect.x + (leftToRight ? 0 : visibleRect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4950
            newCellLoc = new Point(x, newEdge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4951
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4952
        else if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4953
            newEdge = visibleLeadingEdge - visibleRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4954
            newCellLoc = new Point(newEdge, visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4955
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4956
        else { // Horizontal, right-to-left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4957
            newEdge = visibleLeadingEdge + visibleRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4958
            newCellLoc = new Point(newEdge - 1, visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4959
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4960
        row = rowAtPoint(newCellLoc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4961
        col = columnAtPoint(newCellLoc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4962
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4963
        // If we're measuring past the beginning of the table, we get an invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4964
        // cell.  Just go to the beginning of the table in this case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4965
        if (orientation == SwingConstants.VERTICAL & row < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4966
            newLeadingEdge = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4968
        else if (orientation == SwingConstants.HORIZONTAL & col < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4969
            if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4970
                newLeadingEdge = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4971
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4972
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4973
                newLeadingEdge = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4974
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4975
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4976
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4977
            // Refine our measurement
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4978
            Rectangle newCellRect = getCellRect(row, col, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4979
            int newCellLeadingEdge = leadingEdge(newCellRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4980
            int newCellTrailingEdge = trailingEdge(newCellRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4981
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4982
            // Usually, we hit in the middle of newCell, and want to scroll to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4983
            // the beginning of the cell after newCell.  But there are a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4984
            // couple corner cases where we want to scroll to the beginning of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4985
            // newCell itself.  These cases are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4986
            // 1) newCell is so large that it ends at or extends into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4987
            //    visibleRect (newCell is the leading cell, or is adjacent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4988
            //    the leading cell)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4989
            // 2) newEdge happens to fall right on the beginning of a cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4990
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4991
            // Case 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4992
            if ((orientation == SwingConstants.VERTICAL || leftToRight) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4993
                (newCellTrailingEdge >= visibleLeadingEdge)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4994
                newLeadingEdge = newCellLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4995
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4996
            else if (orientation == SwingConstants.HORIZONTAL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4997
                     !leftToRight &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4998
                     newCellTrailingEdge <= visibleLeadingEdge) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4999
                newLeadingEdge = newCellLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5000
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5001
            // Case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5002
            else if (newEdge == newCellLeadingEdge) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5003
                newLeadingEdge = newCellLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5004
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5005
            // Common case: scroll to cell after newCell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5006
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5007
                newLeadingEdge = newCellTrailingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5008
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5009
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5010
        return Math.abs(visibleLeadingEdge - newLeadingEdge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5011
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5013
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5014
     * Called to get the block increment for downward scrolling in cases of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5015
     * horizontal scrolling, or for vertical scrolling of a table with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5016
     * variable row heights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5017
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5018
    private int getNextBlockIncrement(Rectangle visibleRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5019
                                      int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5020
        // Find the cell at the trailing edge.  Return the distance to put
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5021
        // that cell at the leading edge.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5022
        int trailingRow = getTrailingRow(visibleRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5023
        int trailingCol = getTrailingCol(visibleRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5025
        Rectangle cellRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5026
        boolean cellFillsVis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5028
        int cellLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5029
        int cellTrailingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5030
        int newLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5031
        int visibleLeadingEdge = leadingEdge(visibleRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5032
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5033
        // If we couldn't find trailing cell, just return the size of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5034
        // visibleRect.  Note that, for instance, we don't need the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5035
        // trailingCol to proceed if we're scrolling vertically, because
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5036
        // cellRect will still fill in the required dimensions.  This would
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5037
        // happen if we're scrolling vertically, and the table is not wide
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5038
        // enough to fill the visibleRect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5039
        if (orientation == SwingConstants.VERTICAL && trailingRow < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5040
            return visibleRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5041
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5042
        else if (orientation == SwingConstants.HORIZONTAL && trailingCol < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5043
            return visibleRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5044
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5045
        cellRect = getCellRect(trailingRow, trailingCol, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5046
        cellLeadingEdge = leadingEdge(cellRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5047
        cellTrailingEdge = trailingEdge(cellRect, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5049
        if (orientation == SwingConstants.VERTICAL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5050
            getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5051
            cellFillsVis = cellLeadingEdge <= visibleLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5052
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5053
        else { // Horizontal, right-to-left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5054
            cellFillsVis = cellLeadingEdge >= visibleLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5055
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5057
        if (cellFillsVis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5058
            // The visibleRect contains a single large cell.  Scroll to the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5059
            // of this cell, so the following cell is the first cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5060
            newLeadingEdge = cellTrailingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5061
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5062
        else if (cellTrailingEdge == trailingEdge(visibleRect, orientation)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5063
            // The trailing cell happens to end right at the end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5064
            // visibleRect.  Again, scroll to the beginning of the next cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5065
            newLeadingEdge = cellTrailingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5066
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5067
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5068
            // Common case: the trailing cell is partially visible, and isn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5069
            // big enough to take up the entire visibleRect.  Scroll so it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5070
            // becomes the leading cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5071
            newLeadingEdge = cellLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5072
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5073
        return Math.abs(newLeadingEdge - visibleLeadingEdge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5074
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5076
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5077
     * Return the row at the top of the visibleRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5078
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5079
     * May return -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5080
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5081
    private int getLeadingRow(Rectangle visibleRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5082
        Point leadingPoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5084
        if (getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5085
            leadingPoint = new Point(visibleRect.x, visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5086
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5087
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5088
            leadingPoint = new Point(visibleRect.x + visibleRect.width - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5089
                                     visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5090
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5091
        return rowAtPoint(leadingPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5092
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5094
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5095
     * Return the column at the leading edge of the visibleRect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5096
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5097
     * May return -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5098
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5099
    private int getLeadingCol(Rectangle visibleRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5100
        Point leadingPoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5102
        if (getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5103
            leadingPoint = new Point(visibleRect.x, visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5105
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5106
            leadingPoint = new Point(visibleRect.x + visibleRect.width - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5107
                                     visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5109
        return columnAtPoint(leadingPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5112
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5113
     * Return the row at the bottom of the visibleRect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5114
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5115
     * May return -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5117
    private int getTrailingRow(Rectangle visibleRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5118
        Point trailingPoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5120
        if (getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5121
            trailingPoint = new Point(visibleRect.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5122
                                      visibleRect.y + visibleRect.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5124
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5125
            trailingPoint = new Point(visibleRect.x + visibleRect.width - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5126
                                      visibleRect.y + visibleRect.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5128
        return rowAtPoint(trailingPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5131
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5132
     * Return the column at the trailing edge of the visibleRect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5133
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5134
     * May return -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5136
    private int getTrailingCol(Rectangle visibleRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5137
        Point trailingPoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5139
        if (getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5140
            trailingPoint = new Point(visibleRect.x + visibleRect.width - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5141
                                      visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5143
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5144
            trailingPoint = new Point(visibleRect.x, visibleRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5146
        return columnAtPoint(trailingPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5149
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5150
     * Returns the leading edge ("beginning") of the given Rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5151
     * For VERTICAL, this is the top, for left-to-right, the left side, and for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5152
     * right-to-left, the right side.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5154
    private int leadingEdge(Rectangle rect, int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5155
        if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5156
            return rect.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5158
        else if (getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5159
            return rect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5161
        else { // Horizontal, right-to-left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5162
            return rect.x + rect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5165
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5166
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5167
     * Returns the trailing edge ("end") of the given Rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5168
     * For VERTICAL, this is the bottom, for left-to-right, the right side, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5169
     * for right-to-left, the left side.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5171
    private int trailingEdge(Rectangle rect, int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5172
        if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5173
            return rect.y + rect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5175
        else if (getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5176
            return rect.x + rect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5178
        else { // Horizontal, right-to-left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5179
            return rect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5182
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5184
     * Returns false if <code>autoResizeMode</code> is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5185
     * <code>AUTO_RESIZE_OFF</code>, which indicates that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5186
     * width of the viewport does not determine the width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5187
     * of the table.  Otherwise returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5189
     * @return false if <code>autoResizeMode</code> is set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5190
     *   to <code>AUTO_RESIZE_OFF</code>, otherwise returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5191
     * @see Scrollable#getScrollableTracksViewportWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5193
    public boolean getScrollableTracksViewportWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5194
        return !(autoResizeMode == AUTO_RESIZE_OFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5198
     * Returns {@code false} to indicate that the height of the viewport does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5199
     * not determine the height of the table, unless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5200
     * {@code getFillsViewportHeight} is {@code true} and the preferred height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5201
     * of the table is smaller than the viewport's height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5203
     * @return {@code false} unless {@code getFillsViewportHeight} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5204
     *         {@code true} and the table needs to be stretched to fill
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5205
     *         the viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5206
     * @see Scrollable#getScrollableTracksViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5207
     * @see #setFillsViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5208
     * @see #getFillsViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5210
    public boolean getScrollableTracksViewportHeight() {
5449
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
  5211
        Container parent = SwingUtilities.getUnwrappedParent(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5212
        return getFillsViewportHeight()
5449
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
  5213
               && parent instanceof JViewport
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4967
diff changeset
  5214
               && parent.getHeight() > getPreferredSize().height;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5218
     * Sets whether or not this table is always made large enough
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5219
     * to fill the height of an enclosing viewport. If the preferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5220
     * height of the table is smaller than the viewport, then the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5221
     * will be stretched to fill the viewport. In other words, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5222
     * ensures the table is never smaller than the viewport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5223
     * The default for this property is {@code false}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5225
     * @param fillsViewportHeight whether or not this table is always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5226
     *        made large enough to fill the height of an enclosing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5227
     *        viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5228
     * @see #getFillsViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5229
     * @see #getScrollableTracksViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5230
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5231
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5232
     *      bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5233
     *      description: Whether or not this table is always made large enough
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5234
     *                   to fill the height of an enclosing viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5236
    public void setFillsViewportHeight(boolean fillsViewportHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5237
        boolean old = this.fillsViewportHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5238
        this.fillsViewportHeight = fillsViewportHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5239
        resizeAndRepaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5240
        firePropertyChange("fillsViewportHeight", old, fillsViewportHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5243
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5244
     * Returns whether or not this table is always made large enough
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5245
     * to fill the height of an enclosing viewport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5247
     * @return whether or not this table is always made large enough
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5248
     *         to fill the height of an enclosing viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5249
     * @see #setFillsViewportHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5250
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5252
    public boolean getFillsViewportHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5253
        return fillsViewportHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5256
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5257
// Protected Methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5258
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5259
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5260
    protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5261
                                        int condition, boolean pressed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5262
        boolean retValue = super.processKeyBinding(ks, e, condition, pressed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5264
        // Start editing when a key is typed. UI classes can disable this behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5265
        // by setting the client property JTable.autoStartsEdit to Boolean.FALSE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5266
        if (!retValue && condition == WHEN_ANCESTOR_OF_FOCUSED_COMPONENT &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5267
            isFocusOwner() &&
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  5268
            !Boolean.FALSE.equals(getClientProperty("JTable.autoStartsEdit"))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5269
            // We do not have a binding for the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5270
            Component editorComponent = getEditorComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5271
            if (editorComponent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5272
                // Only attempt to install the editor on a KEY_PRESSED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5273
                if (e == null || e.getID() != KeyEvent.KEY_PRESSED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5274
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5275
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5276
                // Don't start when just a modifier is pressed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5277
                int code = e.getKeyCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5278
                if (code == KeyEvent.VK_SHIFT || code == KeyEvent.VK_CONTROL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5279
                    code == KeyEvent.VK_ALT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5280
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5281
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5282
                // Try to install the editor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5283
                int leadRow = getSelectionModel().getLeadSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5284
                int leadColumn = getColumnModel().getSelectionModel().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5285
                                   getLeadSelectionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5286
                if (leadRow != -1 && leadColumn != -1 && !isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5287
                    if (!editCellAt(leadRow, leadColumn, e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5288
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5289
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5290
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5291
                editorComponent = getEditorComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5292
                if (editorComponent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5293
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5294
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5295
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5296
            // If the editorComponent is a JComponent, pass the event to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5297
            if (editorComponent instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5298
                retValue = ((JComponent)editorComponent).processKeyBinding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5299
                                        (ks, e, WHEN_FOCUSED, pressed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5300
                // If we have started an editor as a result of the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5301
                // pressing a key and the surrendersFocusOnKeystroke property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5302
                // is true, give the focus to the new editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5303
                if (getSurrendersFocusOnKeystroke()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5304
                    editorComponent.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5305
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5306
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5308
        return retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5310
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5311
    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
  5312
        h.put(c, new SwingLazyValue(s));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5315
    private void setLazyRenderer(Class c, String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5316
        setLazyValue(defaultRenderersByColumnClass, c, s);
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
     * Creates default cell renderers for objects, numbers, doubles, dates,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5321
     * booleans, and icons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5322
     * @see javax.swing.table.DefaultTableCellRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5323
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5325
    protected void createDefaultRenderers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5326
        defaultRenderersByColumnClass = new UIDefaults(8, 0.75f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5328
        // Objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5329
        setLazyRenderer(Object.class, "javax.swing.table.DefaultTableCellRenderer$UIResource");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5331
        // Numbers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5332
        setLazyRenderer(Number.class, "javax.swing.JTable$NumberRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5333
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5334
        // Doubles and Floats
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5335
        setLazyRenderer(Float.class, "javax.swing.JTable$DoubleRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5336
        setLazyRenderer(Double.class, "javax.swing.JTable$DoubleRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5338
        // Dates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5339
        setLazyRenderer(Date.class, "javax.swing.JTable$DateRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5340
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5341
        // Icons and ImageIcons
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5342
        setLazyRenderer(Icon.class, "javax.swing.JTable$IconRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5343
        setLazyRenderer(ImageIcon.class, "javax.swing.JTable$IconRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5344
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5345
        // Booleans
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5346
        setLazyRenderer(Boolean.class, "javax.swing.JTable$BooleanRenderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5349
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5350
     * Default Renderers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5351
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5352
    static class NumberRenderer extends DefaultTableCellRenderer.UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5353
        public NumberRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5354
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5355
            setHorizontalAlignment(JLabel.RIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5358
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5359
    static class DoubleRenderer extends NumberRenderer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5360
        NumberFormat formatter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5361
        public DoubleRenderer() { super(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5363
        public void setValue(Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5364
            if (formatter == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5365
                formatter = NumberFormat.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5366
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5367
            setText((value == null) ? "" : formatter.format(value));
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 DateRenderer extends DefaultTableCellRenderer.UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5372
        DateFormat formatter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5373
        public DateRenderer() { 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 = DateFormat.getDateInstance();
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 IconRenderer extends DefaultTableCellRenderer.UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5384
        public IconRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5385
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5386
            setHorizontalAlignment(JLabel.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5388
        public void setValue(Object value) { setIcon((value instanceof Icon) ? (Icon)value : null); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5390
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5391
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5392
    static class BooleanRenderer extends JCheckBox implements TableCellRenderer, UIResource
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5393
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5394
        private static final Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5396
        public BooleanRenderer() {
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
            setBorderPainted(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5400
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5401
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5402
        public Component getTableCellRendererComponent(JTable table, Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5403
                                                       boolean isSelected, boolean hasFocus, int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5404
            if (isSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5405
                setForeground(table.getSelectionForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5406
                super.setBackground(table.getSelectionBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5407
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5408
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5409
                setForeground(table.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5410
                setBackground(table.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5411
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5412
            setSelected((value != null && ((Boolean)value).booleanValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5413
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5414
            if (hasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5415
                setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5416
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5417
                setBorder(noFocusBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5418
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5419
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5420
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5421
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5423
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5424
    private void setLazyEditor(Class c, String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5425
        setLazyValue(defaultEditorsByColumnClass, c, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5427
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5428
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5429
     * Creates default cell editors for objects, numbers, and boolean values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5430
     * @see DefaultCellEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5431
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5432
    protected void createDefaultEditors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5433
        defaultEditorsByColumnClass = new UIDefaults(3, 0.75f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5434
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5435
        // Objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5436
        setLazyEditor(Object.class, "javax.swing.JTable$GenericEditor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5437
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5438
        // Numbers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5439
        setLazyEditor(Number.class, "javax.swing.JTable$NumberEditor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5441
        // Booleans
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5442
        setLazyEditor(Boolean.class, "javax.swing.JTable$BooleanEditor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5444
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5445
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5446
     * Default Editors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5447
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5448
    static class GenericEditor extends DefaultCellEditor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5450
        Class[] argTypes = new Class[]{String.class};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5451
        java.lang.reflect.Constructor constructor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5452
        Object value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5453
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5454
        public GenericEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5455
            super(new JTextField());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5456
            getComponent().setName("Table.editor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5457
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5458
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5459
        public boolean stopCellEditing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5460
            String s = (String)super.getCellEditorValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5461
            // Here we are dealing with the case where a user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5462
            // has deleted the string value in a cell, possibly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5463
            // after a failed validation. Return null, so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5464
            // they have the option to replace the value with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5465
            // null or use escape to restore the original.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5466
            // For Strings, return "" for backward compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5467
            try {
20800
1f6b7d81410d 8013744: Better tabling for AWT
alexsch
parents: 16100
diff changeset
  5468
                if ("".equals(s)) {
1f6b7d81410d 8013744: Better tabling for AWT
alexsch
parents: 16100
diff changeset
  5469
                    if (constructor.getDeclaringClass() == String.class) {
1f6b7d81410d 8013744: Better tabling for AWT
alexsch
parents: 16100
diff changeset
  5470
                        value = s;
1f6b7d81410d 8013744: Better tabling for AWT
alexsch
parents: 16100
diff changeset
  5471
                    }
1f6b7d81410d 8013744: Better tabling for AWT
alexsch
parents: 16100
diff changeset
  5472
                    return super.stopCellEditing();
1f6b7d81410d 8013744: Better tabling for AWT
alexsch
parents: 16100
diff changeset
  5473
                }
1f6b7d81410d 8013744: Better tabling for AWT
alexsch
parents: 16100
diff changeset
  5474
1f6b7d81410d 8013744: Better tabling for AWT
alexsch
parents: 16100
diff changeset
  5475
                SwingUtilities2.checkAccess(constructor.getModifiers());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5476
                value = constructor.newInstance(new Object[]{s});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5477
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5478
            catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5479
                ((JComponent)getComponent()).setBorder(new LineBorder(Color.red));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5480
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5481
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5482
            return super.stopCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5484
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5485
        public Component getTableCellEditorComponent(JTable table, Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5486
                                                 boolean isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5487
                                                 int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5488
            this.value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5489
            ((JComponent)getComponent()).setBorder(new LineBorder(Color.black));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5490
            try {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  5491
                Class<?> type = table.getColumnClass(column);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5492
                // Since our obligation is to produce a value which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5493
                // assignable for the required type it is OK to use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5494
                // String constructor for columns which are declared
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5495
                // to contain Objects. A String is an Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5496
                if (type == Object.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5497
                    type = String.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5498
                }
20800
1f6b7d81410d 8013744: Better tabling for AWT
alexsch
parents: 16100
diff changeset
  5499
                ReflectUtil.checkPackageAccess(type);
1f6b7d81410d 8013744: Better tabling for AWT
alexsch
parents: 16100
diff changeset
  5500
                SwingUtilities2.checkAccess(type.getModifiers());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5501
                constructor = type.getConstructor(argTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5502
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5503
            catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5504
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5505
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5506
            return super.getTableCellEditorComponent(table, value, isSelected, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5509
        public Object getCellEditorValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5510
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5513
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5514
    static class NumberEditor extends GenericEditor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5515
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5516
        public NumberEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5517
            ((JTextField)getComponent()).setHorizontalAlignment(JTextField.RIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5520
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5521
    static class BooleanEditor extends DefaultCellEditor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5522
        public BooleanEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5523
            super(new JCheckBox());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5524
            JCheckBox checkBox = (JCheckBox)getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5525
            checkBox.setHorizontalAlignment(JCheckBox.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5526
        }
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
     * Initializes table properties to their default values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5531
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5532
    protected void initializeLocalVars() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5533
        updateSelectionOnSort = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5534
        setOpaque(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5535
        createDefaultRenderers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5536
        createDefaultEditors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5537
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5538
        setTableHeader(createDefaultTableHeader());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5539
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5540
        setShowGrid(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5541
        setAutoResizeMode(AUTO_RESIZE_SUBSEQUENT_COLUMNS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5542
        setRowHeight(16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5543
        isRowHeightSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5544
        setRowMargin(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5545
        setRowSelectionAllowed(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5546
        setCellEditor(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5547
        setEditingColumn(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5548
        setEditingRow(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5549
        setSurrendersFocusOnKeystroke(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5550
        setPreferredScrollableViewportSize(new Dimension(450, 400));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5551
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5552
        // I'm registered to do tool tips so we can draw tips for the renderers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5553
        ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5554
        toolTipManager.registerComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5555
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5556
        setAutoscrolls(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5557
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5558
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5559
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5560
     * Returns the default table model object, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5561
     * a <code>DefaultTableModel</code>.  A subclass can override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5562
     * method to return a different table model object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5563
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5564
     * @return the default table model object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5565
     * @see javax.swing.table.DefaultTableModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5566
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5567
    protected TableModel createDefaultDataModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5568
        return new DefaultTableModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5570
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5571
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5572
     * Returns the default column model object, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5573
     * a <code>DefaultTableColumnModel</code>.  A subclass can override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5574
     * method to return a different column model object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5575
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5576
     * @return the default column model object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5577
     * @see javax.swing.table.DefaultTableColumnModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5578
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5579
    protected TableColumnModel createDefaultColumnModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5580
        return new DefaultTableColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5581
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5582
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5583
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5584
     * Returns the default selection model object, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5585
     * a <code>DefaultListSelectionModel</code>.  A subclass can override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5586
     * method to return a different selection model object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5587
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5588
     * @return the default selection model object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5589
     * @see javax.swing.DefaultListSelectionModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5590
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5591
    protected ListSelectionModel createDefaultSelectionModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5592
        return new DefaultListSelectionModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5594
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5595
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5596
     * Returns the default table header object, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5597
     * a <code>JTableHeader</code>.  A subclass can override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5598
     * method to return a different table header object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5599
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5600
     * @return the default table header object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5601
     * @see javax.swing.table.JTableHeader
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5602
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5603
    protected JTableHeader createDefaultTableHeader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5604
        return new JTableHeader(columnModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5605
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5606
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5607
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5608
     * Equivalent to <code>revalidate</code> followed by <code>repaint</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5609
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5610
    protected void resizeAndRepaint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5611
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5612
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5613
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5614
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5615
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5616
     * Returns the active cell editor, which is {@code null} if the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5617
     * is not currently editing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5618
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5619
     * @return the {@code TableCellEditor} that does the editing,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5620
     *         or {@code null} if the table is not currently editing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5621
     * @see #cellEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5622
     * @see #getCellEditor(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5623
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5624
    public TableCellEditor getCellEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5625
        return cellEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5626
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5627
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5628
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5629
     * Sets the active cell editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5630
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5631
     * @param anEditor the active cell editor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5632
     * @see #cellEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5633
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5634
     *  bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5635
     *  description: The table's active cell editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5636
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5637
    public void setCellEditor(TableCellEditor anEditor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5638
        TableCellEditor oldEditor = cellEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5639
        cellEditor = anEditor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5640
        firePropertyChange("tableCellEditor", oldEditor, anEditor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5641
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5642
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5643
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5644
     * Sets the <code>editingColumn</code> variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5645
     * @param aColumn  the column of the cell to be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5646
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5647
     * @see #editingColumn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5648
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5649
    public void setEditingColumn(int aColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5650
        editingColumn = aColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5651
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5652
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5653
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5654
     * Sets the <code>editingRow</code> variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5655
     * @param aRow  the row of the cell to be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5656
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5657
     * @see #editingRow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5658
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5659
    public void setEditingRow(int aRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5660
        editingRow = aRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5661
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5662
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5663
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5664
     * Returns an appropriate renderer for the cell specified by this row and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5665
     * column. If the <code>TableColumn</code> for this column has a non-null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5666
     * renderer, returns that.  If not, finds the class of the data in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5667
     * this column (using <code>getColumnClass</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5668
     * and returns the default renderer for this type of data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5669
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5670
     * <b>Note:</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5671
     * Throughout the table package, the internal implementations always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5672
     * use this method to provide renderers so that this default behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5673
     * can be safely overridden by a subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5674
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5675
     * @param row       the row of the cell to render, where 0 is the first row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5676
     * @param column    the column of the cell to render,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5677
     *                  where 0 is the first column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5678
     * @return the assigned renderer; if <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5679
     *                  returns the default renderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5680
     *                  for this type of object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5681
     * @see javax.swing.table.DefaultTableCellRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5682
     * @see javax.swing.table.TableColumn#setCellRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5683
     * @see #setDefaultRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5684
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5685
    public TableCellRenderer getCellRenderer(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5686
        TableColumn tableColumn = getColumnModel().getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5687
        TableCellRenderer renderer = tableColumn.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5688
        if (renderer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5689
            renderer = getDefaultRenderer(getColumnClass(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5690
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5691
        return renderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5692
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5693
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5694
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5695
     * Prepares the renderer by querying the data model for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5696
     * value and selection state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5697
     * of the cell at <code>row</code>, <code>column</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5698
     * Returns the component (may be a <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5699
     * or a <code>JComponent</code>) under the event location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5700
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5701
     * During a printing operation, this method will configure the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5702
     * renderer without indicating selection or focus, to prevent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5703
     * them from appearing in the printed output. To do other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5704
     * customizations based on whether or not the table is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5705
     * printed, you can check the value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5706
     * {@link javax.swing.JComponent#isPaintingForPrint()}, either here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5707
     * or within custom renderers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5708
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5709
     * <b>Note:</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5710
     * Throughout the table package, the internal implementations always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5711
     * use this method to prepare renderers so that this default behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5712
     * can be safely overridden by a subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5713
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5714
     * @param renderer  the <code>TableCellRenderer</code> to prepare
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5715
     * @param row       the row of the cell to render, where 0 is the first row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5716
     * @param column    the column of the cell to render,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5717
     *                  where 0 is the first column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5718
     * @return          the <code>Component</code> under the event location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5719
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5720
    public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5721
        Object value = getValueAt(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5722
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5723
        boolean isSelected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5724
        boolean hasFocus = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5725
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5726
        // Only indicate the selection and focused cell if not printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5727
        if (!isPaintingForPrint()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5728
            isSelected = isCellSelected(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5729
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5730
            boolean rowIsLead =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5731
                (selectionModel.getLeadSelectionIndex() == row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5732
            boolean colIsLead =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5733
                (columnModel.getSelectionModel().getLeadSelectionIndex() == column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5734
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5735
            hasFocus = (rowIsLead && colIsLead) && isFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5736
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5737
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5738
        return renderer.getTableCellRendererComponent(this, value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5739
                                                      isSelected, hasFocus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5740
                                                      row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5741
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5742
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5743
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5744
     * Returns an appropriate editor for the cell specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5745
     * <code>row</code> and <code>column</code>. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5746
     * <code>TableColumn</code> for this column has a non-null editor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5747
     * returns that.  If not, finds the class of the data in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5748
     * column (using <code>getColumnClass</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5749
     * and returns the default editor for this type of data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5750
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5751
     * <b>Note:</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5752
     * Throughout the table package, the internal implementations always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5753
     * use this method to provide editors so that this default behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5754
     * can be safely overridden by a subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5755
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5756
     * @param row       the row of the cell to edit, where 0 is the first row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5757
     * @param column    the column of the cell to edit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5758
     *                  where 0 is the first column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5759
     * @return          the editor for this cell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5760
     *                  if <code>null</code> return the default editor for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5761
     *                  this type of cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5762
     * @see DefaultCellEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5763
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5764
    public TableCellEditor getCellEditor(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5765
        TableColumn tableColumn = getColumnModel().getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5766
        TableCellEditor editor = tableColumn.getCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5767
        if (editor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5768
            editor = getDefaultEditor(getColumnClass(column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5769
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5770
        return editor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5771
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5772
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5773
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5774
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5775
     * Prepares the editor by querying the data model for the value and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5776
     * selection state of the cell at <code>row</code>, <code>column</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5777
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5778
     * <b>Note:</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5779
     * Throughout the table package, the internal implementations always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5780
     * use this method to prepare editors so that this default behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5781
     * can be safely overridden by a subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5782
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5783
     * @param editor  the <code>TableCellEditor</code> to set up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5784
     * @param row     the row of the cell to edit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5785
     *                where 0 is the first row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5786
     * @param column  the column of the cell to edit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5787
     *                where 0 is the first column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5788
     * @return the <code>Component</code> being edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5789
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5790
    public Component prepareEditor(TableCellEditor editor, int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5791
        Object value = getValueAt(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5792
        boolean isSelected = isCellSelected(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5793
        Component comp = editor.getTableCellEditorComponent(this, value, isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5794
                                                  row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5795
        if (comp instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5796
            JComponent jComp = (JComponent)comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5797
            if (jComp.getNextFocusableComponent() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5798
                jComp.setNextFocusableComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5799
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5800
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5801
        return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5802
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5803
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5804
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5805
     * Discards the editor object and frees the real estate it used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5806
     * cell rendering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5807
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5808
    public void removeEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5809
        KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5810
            removePropertyChangeListener("permanentFocusOwner", editorRemover);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5811
        editorRemover = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5812
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5813
        TableCellEditor editor = getCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5814
        if(editor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5815
            editor.removeCellEditorListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5816
            if (editorComp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5817
                Component focusOwner =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5818
                        KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5819
                boolean isFocusOwnerInTheTable = focusOwner != null?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5820
                        SwingUtilities.isDescendingFrom(focusOwner, this):false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5821
                remove(editorComp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5822
                if(isFocusOwnerInTheTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5823
                    requestFocusInWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5824
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5825
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5826
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5827
            Rectangle cellRect = getCellRect(editingRow, editingColumn, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5828
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5829
            setCellEditor(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5830
            setEditingColumn(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5831
            setEditingRow(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5832
            editorComp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5833
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5834
            repaint(cellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5835
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5836
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5837
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5838
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5839
// Serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5840
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5841
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5842
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5843
     * See readObject() and writeObject() in JComponent for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5844
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5845
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5846
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5847
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5848
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5849
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5850
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5851
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5852
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5853
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5854
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5855
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5856
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5857
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5858
        throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5859
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5860
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5861
        if ((ui != null) && (getUIClassID().equals(uiClassID))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5862
            ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5863
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5864
        createDefaultRenderers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5865
        createDefaultEditors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5866
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5867
        // If ToolTipText != null, then the tooltip has already been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5868
        // registered by JComponent.readObject() and we don't want
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5869
        // to re-register here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5870
        if (getToolTipText() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5871
            ToolTipManager.sharedInstance().registerComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5872
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5873
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5874
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5875
    /* Called from the JComponent's EnableSerializationFocusListener to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5876
     * do any Swing-specific pre-serialization configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5877
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5878
    void compWriteObjectNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5879
        super.compWriteObjectNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5880
        // If ToolTipText != null, then the tooltip has already been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5881
        // unregistered by JComponent.compWriteObjectNotify()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5882
        if (getToolTipText() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5883
            ToolTipManager.sharedInstance().unregisterComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5884
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5885
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5886
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5887
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5888
     * Returns a string representation of this table. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5889
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5890
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5891
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5892
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5893
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5894
     * @return  a string representation of this table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5895
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5896
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5897
        String gridColorString = (gridColor != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5898
                                  gridColor.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5899
        String showHorizontalLinesString = (showHorizontalLines ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5900
                                            "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5901
        String showVerticalLinesString = (showVerticalLines ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5902
                                          "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5903
        String autoResizeModeString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5904
        if (autoResizeMode == AUTO_RESIZE_OFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5905
            autoResizeModeString = "AUTO_RESIZE_OFF";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5906
        } else if (autoResizeMode == AUTO_RESIZE_NEXT_COLUMN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5907
            autoResizeModeString = "AUTO_RESIZE_NEXT_COLUMN";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5908
        } else if (autoResizeMode == AUTO_RESIZE_SUBSEQUENT_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5909
            autoResizeModeString = "AUTO_RESIZE_SUBSEQUENT_COLUMNS";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5910
        } else if (autoResizeMode == AUTO_RESIZE_LAST_COLUMN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5911
            autoResizeModeString = "AUTO_RESIZE_LAST_COLUMN";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5912
        } else if (autoResizeMode == AUTO_RESIZE_ALL_COLUMNS)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5913
            autoResizeModeString = "AUTO_RESIZE_ALL_COLUMNS";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5914
        } else autoResizeModeString = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5915
        String autoCreateColumnsFromModelString = (autoCreateColumnsFromModel ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5916
                                                   "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5917
        String preferredViewportSizeString = (preferredViewportSize != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5918
                                              preferredViewportSize.toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5919
                                              : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5920
        String rowSelectionAllowedString = (rowSelectionAllowed ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5921
                                            "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5922
        String cellSelectionEnabledString = (cellSelectionEnabled ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5923
                                            "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5924
        String selectionForegroundString = (selectionForeground != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5925
                                            selectionForeground.toString() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5926
                                            "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5927
        String selectionBackgroundString = (selectionBackground != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5928
                                            selectionBackground.toString() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5929
                                            "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5930
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5931
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5932
        ",autoCreateColumnsFromModel=" + autoCreateColumnsFromModelString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5933
        ",autoResizeMode=" + autoResizeModeString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5934
        ",cellSelectionEnabled=" + cellSelectionEnabledString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5935
        ",editingColumn=" + editingColumn +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5936
        ",editingRow=" + editingRow +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5937
        ",gridColor=" + gridColorString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5938
        ",preferredViewportSize=" + preferredViewportSizeString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5939
        ",rowHeight=" + rowHeight +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5940
        ",rowMargin=" + rowMargin +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5941
        ",rowSelectionAllowed=" + rowSelectionAllowedString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5942
        ",selectionBackground=" + selectionBackgroundString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5943
        ",selectionForeground=" + selectionForegroundString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5944
        ",showHorizontalLines=" + showHorizontalLinesString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5945
        ",showVerticalLines=" + showVerticalLinesString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5946
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5947
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5948
    // This class tracks changes in the keyboard focus state. It is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5949
    // when the JTable is editing to determine when to cancel the edit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5950
    // If focus switches to a component outside of the jtable, but in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5951
    // same window, this will cancel editing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5952
    class CellEditorRemover implements PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5953
        KeyboardFocusManager focusManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5954
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5955
        public CellEditorRemover(KeyboardFocusManager fm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5956
            this.focusManager = fm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5957
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5958
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5959
        public void propertyChange(PropertyChangeEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5960
            if (!isEditing() || getClientProperty("terminateEditOnFocusLost") != Boolean.TRUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5961
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5962
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5963
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5964
            Component c = focusManager.getPermanentFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5965
            while (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5966
                if (c == JTable.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5967
                    // focus remains inside the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5968
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5969
                } else if ((c instanceof Window) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5970
                           (c instanceof Applet && c.getParent() == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5971
                    if (c == SwingUtilities.getRoot(JTable.this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5972
                        if (!getCellEditor().stopCellEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5973
                            getCellEditor().cancelCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5974
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5975
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5976
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5977
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5978
                c = c.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5979
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5980
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5981
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5982
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5983
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5984
// Printing Support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5985
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5986
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5987
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5988
     * A convenience method that displays a printing dialog, and then prints
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5989
     * this <code>JTable</code> in mode <code>PrintMode.FIT_WIDTH</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5990
     * with no header or footer text. A modal progress dialog, with an abort
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5991
     * option, will be shown for the duration of printing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5992
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5993
     * Note: In headless mode, no dialogs are shown and printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5994
     * occurs on the default printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5995
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5996
     * @return true, unless printing is cancelled by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5997
     * @throws SecurityException if this thread is not allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5998
     *                           initiate a print job request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5999
     * @throws PrinterException if an error in the print system causes the job
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6000
     *                          to be aborted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6001
     * @see #print(JTable.PrintMode, MessageFormat, MessageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6002
     *             boolean, PrintRequestAttributeSet, boolean, PrintService)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6003
     * @see #getPrintable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6004
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6005
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6006
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6007
    public boolean print() throws PrinterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6009
        return print(PrintMode.FIT_WIDTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6010
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6012
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6013
     * A convenience method that displays a printing dialog, and then prints
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6014
     * this <code>JTable</code> in the given printing mode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6015
     * with no header or footer text. A modal progress dialog, with an abort
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6016
     * option, will be shown for the duration of printing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6017
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6018
     * Note: In headless mode, no dialogs are shown and printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6019
     * occurs on the default printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6020
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6021
     * @param  printMode        the printing mode that the printable should use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6022
     * @return true, unless printing is cancelled by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6023
     * @throws SecurityException if this thread is not allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6024
     *                           initiate a print job request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6025
     * @throws PrinterException if an error in the print system causes the job
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6026
     *                          to be aborted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6027
     * @see #print(JTable.PrintMode, MessageFormat, MessageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6028
     *             boolean, PrintRequestAttributeSet, boolean, PrintService)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6029
     * @see #getPrintable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6030
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6031
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6032
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6033
    public boolean print(PrintMode printMode) throws PrinterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6035
        return print(printMode, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6036
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6038
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6039
     * A convenience method that displays a printing dialog, and then prints
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6040
     * this <code>JTable</code> in the given printing mode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6041
     * with the specified header and footer text. A modal progress dialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6042
     * with an abort option, will be shown for the duration of printing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6043
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6044
     * Note: In headless mode, no dialogs are shown and printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6045
     * occurs on the default printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6046
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6047
     * @param  printMode        the printing mode that the printable should use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6048
     * @param  headerFormat     a <code>MessageFormat</code> specifying the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6049
     *                          to be used in printing a header,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6050
     *                          or null for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6051
     * @param  footerFormat     a <code>MessageFormat</code> specifying the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6052
     *                          to be used in printing a footer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6053
     *                          or null for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6054
     * @return true, unless printing is cancelled by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6055
     * @throws SecurityException if this thread is not allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6056
     *                           initiate a print job request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6057
     * @throws PrinterException if an error in the print system causes the job
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6058
     *                          to be aborted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6059
     * @see #print(JTable.PrintMode, MessageFormat, MessageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6060
     *             boolean, PrintRequestAttributeSet, boolean, PrintService)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6061
     * @see #getPrintable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6062
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6063
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6064
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6065
    public boolean print(PrintMode printMode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6066
                         MessageFormat headerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6067
                         MessageFormat footerFormat) throws PrinterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6069
        boolean showDialogs = !GraphicsEnvironment.isHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6070
        return print(printMode, headerFormat, footerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6071
                     showDialogs, null, showDialogs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6072
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6074
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6075
     * Prints this table, as specified by the fully featured
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6076
     * {@link #print(JTable.PrintMode, MessageFormat, MessageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6077
     * boolean, PrintRequestAttributeSet, boolean, PrintService) print}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6078
     * method, with the default printer specified as the print service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6079
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6080
     * @param  printMode        the printing mode that the printable should use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6081
     * @param  headerFormat     a <code>MessageFormat</code> specifying the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6082
     *                          to be used in printing a header,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6083
     *                          or <code>null</code> for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6084
     * @param  footerFormat     a <code>MessageFormat</code> specifying the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6085
     *                          to be used in printing a footer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6086
     *                          or <code>null</code> for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6087
     * @param  showPrintDialog  whether or not to display a print dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6088
     * @param  attr             a <code>PrintRequestAttributeSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6089
     *                          specifying any printing attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6090
     *                          or <code>null</code> for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6091
     * @param  interactive      whether or not to print in an interactive mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6092
     * @return true, unless printing is cancelled by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6093
     * @throws HeadlessException if the method is asked to show a printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6094
     *                           dialog or run interactively, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6095
     *                           <code>GraphicsEnvironment.isHeadless</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6096
     *                           returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6097
     * @throws SecurityException if this thread is not allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6098
     *                           initiate a print job request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6099
     * @throws PrinterException if an error in the print system causes the job
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6100
     *                          to be aborted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6101
     * @see #print(JTable.PrintMode, MessageFormat, MessageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6102
     *             boolean, PrintRequestAttributeSet, boolean, PrintService)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6103
     * @see #getPrintable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6105
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6107
    public boolean print(PrintMode printMode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6108
                         MessageFormat headerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6109
                         MessageFormat footerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6110
                         boolean showPrintDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6111
                         PrintRequestAttributeSet attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6112
                         boolean interactive) throws PrinterException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6113
                                                     HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6115
        return print(printMode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6116
                     headerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6117
                     footerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6118
                     showPrintDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6119
                     attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6120
                     interactive,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6121
                     null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6125
     * Prints this <code>JTable</code>. Takes steps that the majority of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6126
     * developers would take in order to print a <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6127
     * In short, it prepares the table, calls <code>getPrintable</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6128
     * fetch an appropriate <code>Printable</code>, and then sends it to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6129
     * printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6130
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6131
     * A <code>boolean</code> parameter allows you to specify whether or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6132
     * a printing dialog is displayed to the user. When it is, the user may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6133
     * use the dialog to change the destination printer or printing attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6134
     * or even to cancel the print. Another two parameters allow for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6135
     * <code>PrintService</code> and printing attributes to be specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6136
     * These parameters can be used either to provide initial values for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6137
     * print dialog, or to specify values when the dialog is not shown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6138
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6139
     * A second <code>boolean</code> parameter allows you to specify whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6140
     * or not to perform printing in an interactive mode. If <code>true</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6141
     * a modal progress dialog, with an abort option, is displayed for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6142
     * duration of printing . This dialog also prevents any user action which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6143
     * may affect the table. However, it can not prevent the table from being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6144
     * modified by code (for example, another thread that posts updates using
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6145
     * <code>SwingUtilities.invokeLater</code>). It is therefore the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6146
     * responsibility of the developer to ensure that no other code modifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6147
     * the table in any way during printing (invalid modifications include
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6148
     * changes in: size, renderers, or underlying data). Printing behavior is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6149
     * undefined when the table is changed during printing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6150
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6151
     * If <code>false</code> is specified for this parameter, no dialog will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6152
     * be displayed and printing will begin immediately on the event-dispatch
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6153
     * thread. This blocks any other events, including repaints, from being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6154
     * processed until printing is complete. Although this effectively prevents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6155
     * the table from being changed, it doesn't provide a good user experience.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6156
     * For this reason, specifying <code>false</code> is only recommended when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6157
     * printing from an application with no visible GUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6158
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6159
     * Note: Attempting to show the printing dialog or run interactively, while
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6160
     * in headless mode, will result in a <code>HeadlessException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6161
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6162
     * Before fetching the printable, this method will gracefully terminate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6163
     * editing, if necessary, to prevent an editor from showing in the printed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6164
     * result. Additionally, <code>JTable</code> will prepare its renderers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6165
     * during printing such that selection and focus are not indicated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6166
     * As far as customizing further how the table looks in the printout,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6167
     * developers can provide custom renderers or paint code that conditionalize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6168
     * on the value of {@link javax.swing.JComponent#isPaintingForPrint()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6169
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6170
     * See {@link #getPrintable} for more description on how the table is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6171
     * printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6172
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6173
     * @param  printMode        the printing mode that the printable should use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6174
     * @param  headerFormat     a <code>MessageFormat</code> specifying the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6175
     *                          to be used in printing a header,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6176
     *                          or <code>null</code> for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6177
     * @param  footerFormat     a <code>MessageFormat</code> specifying the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6178
     *                          to be used in printing a footer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6179
     *                          or <code>null</code> for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6180
     * @param  showPrintDialog  whether or not to display a print dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6181
     * @param  attr             a <code>PrintRequestAttributeSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6182
     *                          specifying any printing attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6183
     *                          or <code>null</code> for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6184
     * @param  interactive      whether or not to print in an interactive mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6185
     * @param  service          the destination <code>PrintService</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6186
     *                          or <code>null</code> to use the default printer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6187
     * @return true, unless printing is cancelled by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6188
     * @throws HeadlessException if the method is asked to show a printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6189
     *                           dialog or run interactively, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6190
     *                           <code>GraphicsEnvironment.isHeadless</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6191
     *                           returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6192
     * @throws  SecurityException if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6193
     *          {@link java.lang.SecurityManager#checkPrintJobAccess}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6194
     *          method disallows this thread from creating a print job request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6195
     * @throws PrinterException if an error in the print system causes the job
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6196
     *                          to be aborted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6197
     * @see #getPrintable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6198
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6200
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6202
    public boolean print(PrintMode printMode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6203
                         MessageFormat headerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6204
                         MessageFormat footerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6205
                         boolean showPrintDialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6206
                         PrintRequestAttributeSet attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6207
                         boolean interactive,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6208
                         PrintService service) throws PrinterException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6209
                                                      HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6211
        // complain early if an invalid parameter is specified for headless mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6212
        boolean isHeadless = GraphicsEnvironment.isHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6213
        if (isHeadless) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6214
            if (showPrintDialog) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6215
                throw new HeadlessException("Can't show print dialog.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6216
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6217
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6218
            if (interactive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6219
                throw new HeadlessException("Can't run interactively.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6220
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6223
        // Get a PrinterJob.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6224
        // Do this before anything with side-effects since it may throw a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6225
        // security exception - in which case we don't want to do anything else.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6226
        final PrinterJob job = PrinterJob.getPrinterJob();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6228
        if (isEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6229
            // try to stop cell editing, and failing that, cancel it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6230
            if (!getCellEditor().stopCellEditing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6231
                getCellEditor().cancelCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6232
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6235
        if (attr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6236
            attr = new HashPrintRequestAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6239
        final PrintingStatus printingStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6241
         // fetch the Printable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6242
        Printable printable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6243
             getPrintable(printMode, headerFormat, footerFormat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6245
        if (interactive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6246
            // wrap the Printable so that we can print on another thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6247
            printable = new ThreadSafePrintable(printable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6248
            printingStatus = PrintingStatus.createPrintingStatus(this, job);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6249
            printable = printingStatus.createNotificationPrintable(printable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6250
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6251
            // to please compiler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6252
            printingStatus = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6255
        // set the printable on the PrinterJob
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6256
        job.setPrintable(printable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6257
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6258
        // if specified, set the PrintService on the PrinterJob
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6259
        if (service != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6260
            job.setPrintService(service);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6263
        // if requested, show the print dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6264
        if (showPrintDialog && !job.printDialog(attr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6265
            // the user cancelled the print dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6266
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6269
        // if not interactive, just print on this thread (no dialog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6270
        if (!interactive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6271
            // do the printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6272
            job.print(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6274
            // we're done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6275
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6278
        // make sure this is clear since we'll check it after
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6279
        printError = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6280
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6281
        // to synchronize on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6282
        final Object lock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6284
        // copied so we can access from the inner class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6285
        final PrintRequestAttributeSet copyAttr = attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6287
        // this runnable will be used to do the printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6288
        // (and save any throwables) on another thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6289
        Runnable runnable = new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6290
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6291
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6292
                    // do the printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6293
                    job.print(copyAttr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6294
                } catch (Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6295
                    // save any Throwable to be rethrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6296
                    synchronized(lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6297
                        printError = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6298
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6299
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6300
                    // we're finished - hide the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6301
                    printingStatus.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6302
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6303
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6304
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6306
        // start printing on another thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6307
        Thread th = new Thread(runnable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6308
        th.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6309
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6310
        printingStatus.showModal(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6312
        // look for any error that the printing may have generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6313
        Throwable pe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6314
        synchronized(lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6315
            pe = printError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6316
            printError = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6319
        // check the type of error and handle it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6320
        if (pe != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6321
            // a subclass of PrinterException meaning the job was aborted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6322
            // in this case, by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6323
            if (pe instanceof PrinterAbortException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6324
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6325
            } else if (pe instanceof PrinterException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6326
                throw (PrinterException)pe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6327
            } else if (pe instanceof RuntimeException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6328
                throw (RuntimeException)pe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6329
            } else if (pe instanceof Error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6330
                throw (Error)pe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6333
            // can not happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6334
            throw new AssertionError(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6336
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6337
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6339
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6340
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6341
     * Return a <code>Printable</code> for use in printing this JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6342
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6343
     * This method is meant for those wishing to customize the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6344
     * <code>Printable</code> implementation used by <code>JTable</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6345
     * <code>print</code> methods. Developers wanting simply to print the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6346
     * should use one of those methods directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6347
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6348
     * The <code>Printable</code> can be requested in one of two printing modes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6349
     * In both modes, it spreads table rows naturally in sequence across
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6350
     * multiple pages, fitting as many rows as possible per page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6351
     * <code>PrintMode.NORMAL</code> specifies that the table be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6352
     * printed at its current size. In this mode, there may be a need to spread
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6353
     * columns across pages in a similar manner to that of the rows. When the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6354
     * need arises, columns are distributed in an order consistent with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6355
     * table's <code>ComponentOrientation</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6356
     * <code>PrintMode.FIT_WIDTH</code> specifies that the output be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6357
     * scaled smaller, if necessary, to fit the table's entire width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6358
     * (and thereby all columns) on each page. Width and height are scaled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6359
     * equally, maintaining the aspect ratio of the output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6360
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6361
     * The <code>Printable</code> heads the portion of table on each page
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6362
     * with the appropriate section from the table's <code>JTableHeader</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6363
     * if it has one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6364
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6365
     * Header and footer text can be added to the output by providing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6366
     * <code>MessageFormat</code> arguments. The printing code requests
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6367
     * Strings from the formats, providing a single item which may be included
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6368
     * in the formatted string: an <code>Integer</code> representing the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6369
     * page number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6370
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6371
     * You are encouraged to read the documentation for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6372
     * <code>MessageFormat</code> as some characters, such as single-quote,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6373
     * are special and need to be escaped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6374
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6375
     * Here's an example of creating a <code>MessageFormat</code> that can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6376
     * used to print "Duke's Table: Page - " and the current page number:
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 21278
diff changeset
  6377
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6378
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6379
     *     // notice the escaping of the single quote
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6380
     *     // notice how the page number is included with "{0}"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6381
     *     MessageFormat format = new MessageFormat("Duke''s Table: Page - {0}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6382
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6383
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6384
     * The <code>Printable</code> constrains what it draws to the printable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6385
     * area of each page that it prints. Under certain circumstances, it may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6386
     * find it impossible to fit all of a page's content into that area. In
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6387
     * these cases the output may be clipped, but the implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6388
     * makes an effort to do something reasonable. Here are a few situations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6389
     * where this is known to occur, and how they may be handled by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6390
     * particular implementation:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6391
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6392
     *   <li>In any mode, when the header or footer text is too wide to fit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6393
     *       completely in the printable area -- print as much of the text as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6394
     *       possible starting from the beginning, as determined by the table's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6395
     *       <code>ComponentOrientation</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6396
     *   <li>In any mode, when a row is too tall to fit in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6397
     *       printable area -- print the upper-most portion of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6398
     *       and paint no lower border on the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6399
     *   <li>In <code>PrintMode.NORMAL</code> when a column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6400
     *       is too wide to fit in the printable area -- print the center
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6401
     *       portion of the column and leave the left and right borders
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6402
     *       off the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6403
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6404
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6405
     * It is entirely valid for this <code>Printable</code> to be wrapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6406
     * inside another in order to create complex reports and documents. You may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6407
     * even request that different pages be rendered into different sized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6408
     * printable areas. The implementation must be prepared to handle this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6409
     * (possibly by doing its layout calculations on the fly). However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6410
     * providing different heights to each page will likely not work well
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6411
     * with <code>PrintMode.NORMAL</code> when it has to spread columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6412
     * across pages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6413
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6414
     * As far as customizing how the table looks in the printed result,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6415
     * <code>JTable</code> itself will take care of hiding the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6416
     * and focus during printing. For additional customizations, your
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6417
     * renderers or painting code can customize the look based on the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6418
     * of {@link javax.swing.JComponent#isPaintingForPrint()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6419
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6420
     * Also, <i>before</i> calling this method you may wish to <i>first</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6421
     * modify the state of the table, such as to cancel cell editing or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6422
     * have the user size the table appropriately. However, you must not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6423
     * modify the state of the table <i>after</i> this <code>Printable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6424
     * has been fetched (invalid modifications include changes in size or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6425
     * underlying data). The behavior of the returned <code>Printable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6426
     * is undefined once the table has been changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6427
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6428
     * @param  printMode     the printing mode that the printable should use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6429
     * @param  headerFormat  a <code>MessageFormat</code> specifying the text to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6430
     *                       be used in printing a header, or null for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6431
     * @param  footerFormat  a <code>MessageFormat</code> specifying the text to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6432
     *                       be used in printing a footer, or null for none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6433
     * @return a <code>Printable</code> for printing this JTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6434
     * @see #print(JTable.PrintMode, MessageFormat, MessageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6435
     *             boolean, PrintRequestAttributeSet, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6436
     * @see Printable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6437
     * @see PrinterJob
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6438
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6439
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6440
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6441
    public Printable getPrintable(PrintMode printMode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6442
                                  MessageFormat headerFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6443
                                  MessageFormat footerFormat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6444
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6445
        return new TablePrintable(this, printMode, headerFormat, footerFormat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6447
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6448
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6449
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6450
     * A <code>Printable</code> implementation that wraps another
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6451
     * <code>Printable</code>, making it safe for printing on another thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6452
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6453
    private class ThreadSafePrintable implements Printable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6454
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6455
        /** The delegate <code>Printable</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6456
        private Printable printDelegate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6458
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6459
         * To communicate any return value when delegating.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6460
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6461
        private int retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6462
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6463
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6464
         * To communicate any <code>Throwable</code> when delegating.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6465
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6466
        private Throwable retThrowable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6467
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6468
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6469
         * Construct a <code>ThreadSafePrintable</code> around the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6470
         * delegate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6471
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6472
         * @param printDelegate the <code>Printable</code> to delegate to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6473
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6474
        public ThreadSafePrintable(Printable printDelegate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6475
            this.printDelegate = printDelegate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6477
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6478
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6479
         * Prints the specified page into the given {@link Graphics}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6480
         * context, in the specified format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6481
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6482
         * Regardless of what thread this method is called on, all calls into
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6483
         * the delegate will be done on the event-dispatch thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6484
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6485
         * @param   graphics    the context into which the page is drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6486
         * @param   pageFormat  the size and orientation of the page being drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6487
         * @param   pageIndex   the zero based index of the page to be drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6488
         * @return  PAGE_EXISTS if the page is rendered successfully, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6489
         *          NO_SUCH_PAGE if a non-existent page index is specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6490
         * @throws  PrinterException if an error causes printing to be aborted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6491
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6492
        public int print(final Graphics graphics,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6493
                         final PageFormat pageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6494
                         final int pageIndex) throws PrinterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6496
            // We'll use this Runnable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6497
            Runnable runnable = new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6498
                public synchronized void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6499
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6500
                        // call into the delegate and save the return value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6501
                        retVal = printDelegate.print(graphics, pageFormat, pageIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6502
                    } catch (Throwable throwable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6503
                        // save any Throwable to be rethrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6504
                        retThrowable = throwable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6505
                    } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6506
                        // notify the caller that we're done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6507
                        notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6508
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6509
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6510
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6511
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6512
            synchronized(runnable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6513
                // make sure these are initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6514
                retVal = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6515
                retThrowable = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6516
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6517
                // call into the EDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6518
                SwingUtilities.invokeLater(runnable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6519
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6520
                // wait for the runnable to finish
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6521
                while (retVal == -1 && retThrowable == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6522
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6523
                        runnable.wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6524
                    } catch (InterruptedException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6525
                        // short process, safe to ignore interrupts
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6526
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6527
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6528
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6529
                // if the delegate threw a throwable, rethrow it here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6530
                if (retThrowable != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6531
                    if (retThrowable instanceof PrinterException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6532
                        throw (PrinterException)retThrowable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6533
                    } else if (retThrowable instanceof RuntimeException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6534
                        throw (RuntimeException)retThrowable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6535
                    } else if (retThrowable instanceof Error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6536
                        throw (Error)retThrowable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6537
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6538
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6539
                    // can not happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6540
                    throw new AssertionError(retThrowable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6541
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6542
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6543
                return retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6544
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6546
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6547
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6548
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6549
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6550
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6551
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6552
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6553
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6554
     * Gets the AccessibleContext associated with this JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6555
     * For tables, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6556
     * AccessibleJTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6557
     * A new AccessibleJTable instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6558
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6559
     * @return an AccessibleJTable that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6560
     *         AccessibleContext of this JTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6561
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6562
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6563
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6564
            accessibleContext = new AccessibleJTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6566
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6569
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6570
    // *** should also implement AccessibleSelection?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6571
    // *** and what's up with keyboard navigation/manipulation?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6572
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6573
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6574
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6575
     * <code>JTable</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6576
     * Java Accessibility API appropriate to table user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6577
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6578
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6579
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6580
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6581
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6582
     * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
  6583
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6584
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6585
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6586
     */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21982
diff changeset
  6587
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6588
    protected class AccessibleJTable extends AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6589
    implements AccessibleSelection, ListSelectionListener, TableModelListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6590
    TableColumnModelListener, CellEditorListener, PropertyChangeListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6591
    AccessibleExtendedTable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6592
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6593
        int lastSelectedRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6594
        int lastSelectedCol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6595
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6596
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6597
         * AccessibleJTable constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6598
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6599
         * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6600
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6601
        protected AccessibleJTable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6602
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6603
            JTable.this.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6604
            JTable.this.getSelectionModel().addListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6605
            TableColumnModel tcm = JTable.this.getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6606
            tcm.addColumnModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6607
            tcm.getSelectionModel().addListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6608
            JTable.this.getModel().addTableModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6609
            lastSelectedRow = JTable.this.getSelectedRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6610
            lastSelectedCol = JTable.this.getSelectedColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6611
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6612
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6613
    // Listeners to track model, etc. changes to as to re-place the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6614
    // listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6615
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6616
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6617
         * Track changes to selection model, column model, etc. so as to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6618
         * be able to re-place listeners on those in order to pass on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6619
         * information to the Accessibility PropertyChange mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6620
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6621
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6622
            String name = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6623
            Object oldValue = e.getOldValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6624
            Object newValue = e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6625
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6626
                // re-set tableModel listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6627
            if (name.compareTo("model") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6628
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6629
                if (oldValue != null && oldValue instanceof TableModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6630
                    ((TableModel) oldValue).removeTableModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6631
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6632
                if (newValue != null && newValue instanceof TableModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6633
                    ((TableModel) newValue).addTableModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6634
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6635
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6636
                // re-set selectionModel listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6637
            } else if (name.compareTo("selectionModel") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6638
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6639
                Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6640
                if (source == JTable.this) {    // row selection model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6641
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6642
                    if (oldValue != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6643
                        oldValue instanceof ListSelectionModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6644
                        ((ListSelectionModel) oldValue).removeListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6645
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6646
                    if (newValue != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6647
                        newValue instanceof ListSelectionModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6648
                        ((ListSelectionModel) newValue).addListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6649
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6650
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6651
                } else if (source == JTable.this.getColumnModel()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6652
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6653
                    if (oldValue != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6654
                        oldValue instanceof ListSelectionModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6655
                        ((ListSelectionModel) oldValue).removeListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6656
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6657
                    if (newValue != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6658
                        newValue instanceof ListSelectionModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6659
                        ((ListSelectionModel) newValue).addListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6660
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6661
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6662
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6663
                  //        System.out.println("!!! Bug in source of selectionModel propertyChangeEvent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6664
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6665
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6666
                // re-set columnModel listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6667
                // and column's selection property listener as well
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6668
            } else if (name.compareTo("columnModel") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6670
                if (oldValue != null && oldValue instanceof TableColumnModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6671
                    TableColumnModel tcm = (TableColumnModel) oldValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6672
                    tcm.removeColumnModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6673
                    tcm.getSelectionModel().removeListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6674
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6675
                if (newValue != null && newValue instanceof TableColumnModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6676
                    TableColumnModel tcm = (TableColumnModel) newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6677
                    tcm.addColumnModelListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6678
                    tcm.getSelectionModel().addListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6679
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6680
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6681
                // re-se cellEditor listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6682
            } else if (name.compareTo("tableCellEditor") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6683
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6684
                if (oldValue != null && oldValue instanceof TableCellEditor) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  6685
                    ((TableCellEditor) oldValue).removeCellEditorListener(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6686
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6687
                if (newValue != null && newValue instanceof TableCellEditor) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  6688
                    ((TableCellEditor) newValue).addCellEditorListener(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6689
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6690
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6691
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6692
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6693
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6694
    // Listeners to echo changes to the AccessiblePropertyChange mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6695
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6696
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6697
         * Describes a change in the accessible table model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6698
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6699
        protected class AccessibleJTableModelChange
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6700
            implements AccessibleTableModelChange {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6701
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6702
            protected int type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6703
            protected int firstRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6704
            protected int lastRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6705
            protected int firstColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6706
            protected int lastColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6707
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6708
            protected AccessibleJTableModelChange(int type, int firstRow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6709
                                                  int lastRow, int firstColumn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6710
                                                  int lastColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6711
                this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6712
                this.firstRow = firstRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6713
                this.lastRow = lastRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6714
                this.firstColumn = firstColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6715
                this.lastColumn = lastColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6716
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6717
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6718
            public int getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6719
                return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6720
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6721
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6722
            public int getFirstRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6723
                return firstRow;
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 getLastRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6727
                return lastRow;
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 getFirstColumn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6731
                return firstColumn;
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 getLastColumn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6735
                return lastColumn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6736
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6737
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6738
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6739
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6740
         * Track changes to the table contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6741
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6742
        public void tableChanged(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6743
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6744
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6745
           if (e != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6746
               int firstColumn = e.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6747
               int lastColumn = e.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6748
               if (firstColumn == TableModelEvent.ALL_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6749
                   firstColumn = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6750
                   lastColumn = getColumnCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6751
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6752
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6753
               // Fire a property change event indicating the table model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6754
               // has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6755
               AccessibleJTableModelChange change =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6756
                   new AccessibleJTableModelChange(e.getType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6757
                                                   e.getFirstRow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6758
                                                   e.getLastRow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6759
                                                   firstColumn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6760
                                                   lastColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6761
               firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_MODEL_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6762
                                  null, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6763
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6764
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6765
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6766
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6767
         * Track changes to the table contents (row insertions)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6768
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6769
        public void tableRowsInserted(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6770
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6771
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6772
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6773
           // Fire a property change event indicating the table model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6774
           // has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6775
           int firstColumn = e.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6776
           int lastColumn = e.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6777
           if (firstColumn == TableModelEvent.ALL_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6778
               firstColumn = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6779
               lastColumn = getColumnCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6780
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6781
           AccessibleJTableModelChange change =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6782
               new AccessibleJTableModelChange(e.getType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6783
                                               e.getFirstRow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6784
                                               e.getLastRow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6785
                                               firstColumn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6786
                                               lastColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6787
           firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_MODEL_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6788
                              null, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6790
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6791
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6792
         * Track changes to the table contents (row deletions)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6793
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6794
        public void tableRowsDeleted(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6795
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6796
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6797
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6798
           // Fire a property change event indicating the table model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6799
           // has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6800
           int firstColumn = e.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6801
           int lastColumn = e.getColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6802
           if (firstColumn == TableModelEvent.ALL_COLUMNS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6803
               firstColumn = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6804
               lastColumn = getColumnCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6805
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6806
           AccessibleJTableModelChange change =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6807
               new AccessibleJTableModelChange(e.getType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6808
                                               e.getFirstRow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6809
                                               e.getLastRow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6810
                                               firstColumn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6811
                                               lastColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6812
           firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_MODEL_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6813
                              null, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6814
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6815
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6816
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6817
         * Track changes to the table contents (column insertions)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6818
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6819
        public void columnAdded(TableColumnModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6820
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6821
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6822
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6823
           // Fire a property change event indicating the table model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6824
           // has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6825
           int type = AccessibleTableModelChange.INSERT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6826
           AccessibleJTableModelChange change =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6827
               new AccessibleJTableModelChange(type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6828
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6829
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6830
                                               e.getFromIndex(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6831
                                               e.getToIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6832
           firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_MODEL_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6833
                              null, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6834
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6835
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6836
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6837
         * Track changes to the table contents (column deletions)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6838
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6839
        public void columnRemoved(TableColumnModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6840
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6841
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6842
           // Fire a property change event indicating the table model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6843
           // has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6844
           int type = AccessibleTableModelChange.DELETE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6845
           AccessibleJTableModelChange change =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6846
               new AccessibleJTableModelChange(type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6847
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6848
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6849
                                               e.getFromIndex(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6850
                                               e.getToIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6851
           firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_MODEL_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6852
                              null, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6853
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6854
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6855
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6856
         * Track changes of a column repositioning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6857
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6858
         * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6859
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6860
        public void columnMoved(TableColumnModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6861
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6862
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6864
           // Fire property change events indicating the table model
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6865
           // has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6866
           int type = AccessibleTableModelChange.DELETE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6867
           AccessibleJTableModelChange change =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6868
               new AccessibleJTableModelChange(type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6869
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6870
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6871
                                               e.getFromIndex(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6872
                                               e.getFromIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6873
           firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_MODEL_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6874
                              null, change);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6875
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6876
           int type2 = AccessibleTableModelChange.INSERT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6877
           AccessibleJTableModelChange change2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6878
               new AccessibleJTableModelChange(type2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6879
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6880
                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6881
                                               e.getToIndex(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6882
                                               e.getToIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6883
           firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_MODEL_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6884
                              null, change2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6885
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6886
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6887
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6888
         * Track changes of a column moving due to margin changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6889
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6890
         * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6891
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6892
        public void columnMarginChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6893
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6894
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6895
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6896
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6897
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6898
         * Track that the selection model of the TableColumnModel changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6899
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6900
         * @see TableColumnModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6901
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6902
        public void columnSelectionChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6903
            // we should now re-place our TableColumn listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6904
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6905
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6906
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6907
         * Track changes to a cell's contents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6908
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6909
         * Invoked when editing is finished. The changes are saved, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6910
         * editor object is discarded, and the cell is rendered once again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6911
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6912
         * @see CellEditorListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6913
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6914
        public void editingStopped(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6915
           // it'd be great if we could figure out which cell, and pass that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6916
           // somehow as a parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6917
           firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6918
                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6919
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6920
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6921
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6922
         * Invoked when editing is canceled. The editor object is discarded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6923
         * and the cell is rendered once again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6924
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6925
         * @see CellEditorListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6926
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6927
        public void editingCanceled(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6928
            // nothing to report, 'cause nothing changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6929
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6930
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6931
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6932
         * Track changes to table cell selections
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6933
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6934
        public void valueChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6935
            firePropertyChange(AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6936
                               Boolean.valueOf(false), Boolean.valueOf(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6937
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6938
            int selectedRow = JTable.this.getSelectedRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6939
            int selectedCol = JTable.this.getSelectedColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6940
            if (selectedRow != lastSelectedRow ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6941
                selectedCol != lastSelectedCol) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6942
                Accessible oldA = getAccessibleAt(lastSelectedRow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6943
                                                  lastSelectedCol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6944
                Accessible newA = getAccessibleAt(selectedRow, selectedCol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6945
                firePropertyChange(AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6946
                                   oldA, newA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6947
                 lastSelectedRow = selectedRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6948
                 lastSelectedCol = selectedCol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6949
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6950
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6951
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6952
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6953
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6954
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6955
    // AccessibleContext support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6956
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6957
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6958
         * Get the AccessibleSelection associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6959
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6960
         * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6961
         * AccessibleSelection interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6962
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6963
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6964
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6965
        public AccessibleSelection getAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6966
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6968
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6969
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6970
         * Gets the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6971
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6972
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6973
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6974
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6975
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6976
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6977
            return AccessibleRole.TABLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6978
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6979
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6980
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6981
         * Returns the <code>Accessible</code> child, if one exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6982
         * contained at the local coordinate <code>Point</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6983
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6984
         * @param p the point defining the top-left corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6985
         *    <code>Accessible</code>, given in the coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6986
         *    of the object's parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6987
         * @return the <code>Accessible</code>, if it exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6988
         *    at the specified location; else <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6989
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6990
        public Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6991
            int column = columnAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6992
            int row = rowAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6993
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6994
            if ((column != -1) && (row != -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6995
                TableColumn aColumn = getColumnModel().getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6996
                TableCellRenderer renderer = aColumn.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6997
                if (renderer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6998
                    Class<?> columnClass = getColumnClass(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6999
                    renderer = getDefaultRenderer(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7000
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7001
                Component component = renderer.getTableCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7002
                                  JTable.this, null, false, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7003
                                  row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7004
                return new AccessibleJTableCell(JTable.this, row, column,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7005
                      getAccessibleIndexAt(row, column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7006
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7007
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7008
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7010
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7011
         * Returns the number of accessible children in the object.  If all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7012
         * of the children of this object implement <code>Accessible</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7013
         * then this method should return the number of children of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7014
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7015
         * @return the number of accessible children in the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7016
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7017
        public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7018
            return (JTable.this.getColumnCount() * JTable.this.getRowCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7019
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7021
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7022
         * Returns the nth <code>Accessible</code> child of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7023
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7024
         * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7025
         * @return the nth Accessible child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7026
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7027
        public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7028
            if (i < 0 || i >= getAccessibleChildrenCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7029
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7030
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7031
                // children increase across, and then down, for tables
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7032
                // (arbitrary decision)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7033
                int column = getAccessibleColumnAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7034
                int row = getAccessibleRowAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7036
                TableColumn aColumn = getColumnModel().getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7037
                TableCellRenderer renderer = aColumn.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7038
                if (renderer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7039
                    Class<?> columnClass = getColumnClass(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7040
                    renderer = getDefaultRenderer(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7041
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7042
                Component component = renderer.getTableCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7043
                                  JTable.this, null, false, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7044
                                  row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7045
                return new AccessibleJTableCell(JTable.this, row, column,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7046
                      getAccessibleIndexAt(row, column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7047
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7048
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7050
    // AccessibleSelection support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7051
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7052
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7053
         * Returns the number of <code>Accessible</code> children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7054
         * currently selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7055
         * If no children are selected, the return value will be 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7056
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7057
         * @return the number of items currently selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7058
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7059
        public int getAccessibleSelectionCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7060
            int rowsSel = JTable.this.getSelectedRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7061
            int colsSel = JTable.this.getSelectedColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7063
            if (JTable.this.cellSelectionEnabled) { // a contiguous block
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7064
                return rowsSel * colsSel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7065
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7066
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7067
                // a column swath and a row swath, with a shared block
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7068
                if (JTable.this.getRowSelectionAllowed() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7069
                    JTable.this.getColumnSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7070
                    return rowsSel * JTable.this.getColumnCount() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7071
                           colsSel * JTable.this.getRowCount() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7072
                           rowsSel * colsSel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7074
                // just one or more rows in selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7075
                } else if (JTable.this.getRowSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7076
                    return rowsSel * JTable.this.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7078
                // just one or more rows in selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7079
                } else if (JTable.this.getColumnSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7080
                    return colsSel * JTable.this.getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7082
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7083
                    return 0;    // JTable doesn't allow selections
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7084
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7085
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7086
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7088
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7089
         * Returns an <code>Accessible</code> representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7090
         * specified selected child in the object.  If there
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7091
         * isn't a selection, or there are fewer children selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7092
         * than the integer passed in, the return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7093
         * value will be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7094
         * <p>Note that the index represents the i-th selected child, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7095
         * is different from the i-th child.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7096
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7097
         * @param i the zero-based index of selected children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7098
         * @return the i-th selected child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7099
         * @see #getAccessibleSelectionCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7100
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7101
        public Accessible getAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7102
            if (i < 0 || i > getAccessibleSelectionCount()) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  7103
                return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7104
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7106
            int rowsSel = JTable.this.getSelectedRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7107
            int colsSel = JTable.this.getSelectedColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7108
            int rowIndicies[] = getSelectedRows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7109
            int colIndicies[] = getSelectedColumns();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7110
            int ttlCols = JTable.this.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7111
            int ttlRows = JTable.this.getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7112
            int r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7113
            int c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7115
            if (JTable.this.cellSelectionEnabled) { // a contiguous block
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7116
                r = rowIndicies[i / colsSel];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7117
                c = colIndicies[i % colsSel];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7118
                return getAccessibleChild((r * ttlCols) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7119
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7121
                // a column swath and a row swath, with a shared block
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7122
                if (JTable.this.getRowSelectionAllowed() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7123
                    JTable.this.getColumnSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7125
                    // Situation:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7126
                    //   We have a table, like the 6x3 table below,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7127
                    //   wherein three colums and one row selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7128
                    //   (selected cells marked with "*", unselected "0"):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7129
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7130
                    //            0 * 0 * * 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7131
                    //            * * * * * *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7132
                    //            0 * 0 * * 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7133
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7135
                    // State machine below walks through the array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7136
                    // selected rows in two states: in a selected row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7137
                    // and not in one; continuing until we are in a row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7138
                    // in which the ith selection exists.  Then we return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7139
                    // the appropriate cell.  In the state machine, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7140
                    // always do rows above the "current" selected row first,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7141
                    // then the cells in the selected row.  If we're done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7142
                    // with the state machine before finding the requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7143
                    // selected child, we handle the rows below the last
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7144
                    // selected row at the end.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7145
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7146
                    int curIndex = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7147
                    final int IN_ROW = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7148
                    final int NOT_IN_ROW = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7149
                    int state = (rowIndicies[0] == 0 ? IN_ROW : NOT_IN_ROW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7150
                    int j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7151
                    int prevRow = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7152
                    while (j < rowIndicies.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7153
                        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7155
                        case IN_ROW:   // on individual row full of selections
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7156
                            if (curIndex < ttlCols) { // it's here!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7157
                                c = curIndex % ttlCols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7158
                                r = rowIndicies[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7159
                                return getAccessibleChild((r * ttlCols) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7160
                            } else {                               // not here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7161
                                curIndex -= ttlCols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7162
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7163
                            // is the next row in table selected or not?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7164
                            if (j + 1 == rowIndicies.length ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7165
                                rowIndicies[j] != rowIndicies[j+1] - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7166
                                state = NOT_IN_ROW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7167
                                prevRow = rowIndicies[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7168
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7169
                            j++;  // we didn't return earlier, so go to next row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7170
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7172
                        case NOT_IN_ROW:  // sparse bunch of rows of selections
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7173
                            if (curIndex <
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7174
                                (colsSel * (rowIndicies[j] -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7175
                                (prevRow == -1 ? 0 : (prevRow + 1))))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7177
                                // it's here!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7178
                                c = colIndicies[curIndex % colsSel];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7179
                                r = (j > 0 ? rowIndicies[j-1] + 1 : 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7180
                                    + curIndex / colsSel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7181
                                return getAccessibleChild((r * ttlCols) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7182
                            } else {                               // not here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7183
                                curIndex -= colsSel * (rowIndicies[j] -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7184
                                (prevRow == -1 ? 0 : (prevRow + 1)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7185
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7186
                            state = IN_ROW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7187
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7188
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7189
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7190
                    // we got here, so we didn't find it yet; find it in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7191
                    // the last sparse bunch of rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7192
                    if (curIndex <
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7193
                        (colsSel * (ttlRows -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7194
                        (prevRow == -1 ? 0 : (prevRow + 1))))) { // it's here!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7195
                        c = colIndicies[curIndex % colsSel];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7196
                        r = rowIndicies[j-1] + curIndex / colsSel + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7197
                        return getAccessibleChild((r * ttlCols) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7198
                    } else {                               // not here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7199
                        // we shouldn't get to this spot in the code!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7200
//                      System.out.println("Bug in AccessibleJTable.getAccessibleSelection()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7201
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7203
                // one or more rows selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7204
                } else if (JTable.this.getRowSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7205
                    c = i % ttlCols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7206
                    r = rowIndicies[i / ttlCols];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7207
                    return getAccessibleChild((r * ttlCols) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7209
                // one or more columns selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7210
                } else if (JTable.this.getColumnSelectionAllowed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7211
                    c = colIndicies[i % colsSel];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7212
                    r = i / colsSel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7213
                    return getAccessibleChild((r * ttlCols) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7214
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7215
            }
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  7216
            return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7219
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7220
         * Determines if the current child of this object is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7221
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7222
         * @param i the zero-based index of the child in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7223
         *    <code>Accessible</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7224
         * @return true if the current child of this object is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7225
         * @see AccessibleContext#getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7226
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7227
        public boolean isAccessibleChildSelected(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7228
            int column = getAccessibleColumnAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7229
            int row = getAccessibleRowAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7230
            return JTable.this.isCellSelected(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7233
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7234
         * Adds the specified <code>Accessible</code> child of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7235
         * object to the object's selection.  If the object supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7236
         * multiple selections, the specified child is added to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7237
         * any existing selection, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7238
         * it replaces any existing selection in the object.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7239
         * specified child is already selected, this method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7240
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7241
         * This method only works on <code>JTable</code>s which have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7242
         * individual cell selection enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7243
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7244
         * @param i the zero-based index of the child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7245
         * @see AccessibleContext#getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7246
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7247
        public void addAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7248
            // TIGER - 4495286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7249
            int column = getAccessibleColumnAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7250
            int row = getAccessibleRowAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7251
            JTable.this.changeSelection(row, column, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7254
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7255
         * Removes the specified child of the object from the object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7256
         * selection.  If the specified item isn't currently selected, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7257
         * method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7258
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7259
         * This method only works on <code>JTables</code> which have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7260
         * individual cell selection enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7261
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7262
         * @param i the zero-based index of the child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7263
         * @see AccessibleContext#getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7264
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7265
        public void removeAccessibleSelection(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7266
            if (JTable.this.cellSelectionEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7267
                int column = getAccessibleColumnAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7268
                int row = getAccessibleRowAtIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7269
                JTable.this.removeRowSelectionInterval(row, row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7270
                JTable.this.removeColumnSelectionInterval(column, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7271
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7274
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7275
         * Clears the selection in the object, so that no children in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7276
         * object are selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7277
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7278
        public void clearAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7279
            JTable.this.clearSelection();
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
         * Causes every child of the object to be selected, but only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7284
         * if the <code>JTable</code> supports multiple selections,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7285
         * and if individual cell selection is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7286
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7287
        public void selectAllAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7288
            if (JTable.this.cellSelectionEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7289
                JTable.this.selectAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7293
        // begin AccessibleExtendedTable implementation -------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7295
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7296
         * Returns the row number of an index in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7297
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7298
         * @param index the zero-based index in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7299
         * @return the zero-based row of the table if one exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7300
         * otherwise -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7301
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7302
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7303
        public int getAccessibleRow(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7304
            return getAccessibleRowAtIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7306
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7307
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7308
         * Returns the column number of an index in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7309
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7310
         * @param index the zero-based index in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7311
         * @return the zero-based column of the table if one exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7312
         * otherwise -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7313
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7314
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7315
        public int getAccessibleColumn(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7316
            return getAccessibleColumnAtIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7319
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7320
         * Returns the index at a row and column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7321
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7322
         * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7323
         * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7324
         * @return the zero-based index in the table if one exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7325
         * otherwise -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7326
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7327
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7328
        public int getAccessibleIndex(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7329
            return getAccessibleIndexAt(r, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7331
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7332
        // end of AccessibleExtendedTable implementation ------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7333
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7334
        // start of AccessibleTable implementation ------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7336
        private Accessible caption;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7337
        private Accessible summary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7338
        private Accessible [] rowDescription;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7339
        private Accessible [] columnDescription;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7340
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7341
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7342
         * Gets the <code>AccessibleTable</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7343
         * object.  In the implementation of the Java Accessibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7344
         * API for this class, return this object, which is responsible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7345
         * for implementing the <code>AccessibleTables</code> interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7346
         * on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7347
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7348
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7349
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7350
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7351
        public AccessibleTable getAccessibleTable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7352
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7354
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7355
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7356
         * Returns the caption for the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7357
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7358
         * @return the caption for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7359
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7360
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7361
        public Accessible getAccessibleCaption() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7362
            return this.caption;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7364
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7365
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7366
         * Sets the caption for the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7367
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7368
         * @param a the caption for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7369
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7370
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7371
        public void setAccessibleCaption(Accessible a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7372
            Accessible oldCaption = caption;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7373
            this.caption = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7374
            firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_CAPTION_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7375
                               oldCaption, this.caption);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7377
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7378
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7379
         * Returns the summary description of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7380
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7381
         * @return the summary description of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7382
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7383
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7384
        public Accessible getAccessibleSummary() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7385
            return this.summary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7387
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7388
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7389
         * Sets the summary description of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7390
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7391
         * @param a the summary description of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7392
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7393
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7394
        public void setAccessibleSummary(Accessible a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7395
            Accessible oldSummary = summary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7396
            this.summary = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7397
            firePropertyChange(AccessibleContext.ACCESSIBLE_TABLE_SUMMARY_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7398
                               oldSummary, this.summary);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7400
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7401
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7402
         * Returns the total number of rows in this table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7403
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7404
         * @return the total number of rows in this table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7405
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7406
        public int getAccessibleRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7407
            return JTable.this.getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7410
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7411
         * Returns the total number of columns in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7412
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7413
         * @return the total number of columns in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7414
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7415
        public int getAccessibleColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7416
            return JTable.this.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7417
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7418
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7419
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7420
         * Returns the <code>Accessible</code> at a specified row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7421
         * and column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7422
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7423
         * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7424
         * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7425
         * @return the <code>Accessible</code> at the specified row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7426
         * in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7427
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7428
        public Accessible getAccessibleAt(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7429
            return getAccessibleChild((r * getAccessibleColumnCount()) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7431
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7432
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7433
         * Returns the number of rows occupied by the <code>Accessible</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7434
         * at a specified row and column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7435
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7436
         * @return the number of rows occupied by the <code>Accessible</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7437
         *     at a specified row and column in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7438
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7439
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7440
        public int getAccessibleRowExtentAt(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7441
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7442
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7443
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7444
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7445
         * Returns the number of columns occupied by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7446
         * <code>Accessible</code> at a given (row, column).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7447
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7448
         * @return the number of columns occupied by the <code>Accessible</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7449
         *     at a specified row and column in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7450
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7451
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7452
        public int getAccessibleColumnExtentAt(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7453
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7455
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7456
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7457
         * Returns the row headers as an <code>AccessibleTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7458
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7459
         * @return an <code>AccessibleTable</code> representing the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7460
         * headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7461
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7462
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7463
        public AccessibleTable getAccessibleRowHeader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7464
            // row headers are not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7465
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7467
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7468
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7469
         * Sets the row headers as an <code>AccessibleTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7470
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7471
         * @param a an <code>AccessibleTable</code> representing the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7472
         *  headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7473
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7474
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7475
        public void setAccessibleRowHeader(AccessibleTable a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7476
            // row headers are not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7479
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7480
         * Returns the column headers as an <code>AccessibleTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7481
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7482
         *  @return an <code>AccessibleTable</code> representing the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7483
         *          headers, or <code>null</code> if the table header is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7484
         *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7485
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7486
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7487
        public AccessibleTable getAccessibleColumnHeader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7488
            JTableHeader header = JTable.this.getTableHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7489
            return header == null ? null : new AccessibleTableHeader(header);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7491
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7492
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7493
         * Private class representing a table column header
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7494
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7495
        private class AccessibleTableHeader implements AccessibleTable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7496
            private JTableHeader header;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7497
            private TableColumnModel headerModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7499
            AccessibleTableHeader(JTableHeader header) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7500
                this.header = header;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7501
                this.headerModel = header.getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7502
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7504
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7505
             * Returns the caption for the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7506
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7507
             * @return the caption for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7508
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7509
            public Accessible getAccessibleCaption() { return null; }
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
             * Sets the caption for the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7514
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7515
             * @param a the caption for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7516
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7517
            public void setAccessibleCaption(Accessible a) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7519
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7520
             * Returns the summary description of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7521
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7522
             * @return the summary description of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7523
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7524
            public Accessible getAccessibleSummary() { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7525
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7526
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7527
             * Sets the summary description of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7528
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7529
             * @param a the summary description of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7530
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7531
            public void setAccessibleSummary(Accessible a) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7532
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7533
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7534
             * Returns the number of rows in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7535
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7536
             * @return the number of rows in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7537
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7538
            public int getAccessibleRowCount() { return 1; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7539
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7540
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7541
             * Returns the number of columns in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7542
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7543
             * @return the number of columns in the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7544
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7545
            public int getAccessibleColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7546
                return headerModel.getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7547
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7548
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7549
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7550
             * Returns the Accessible at a specified row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7551
             * in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7552
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7553
             * @param row zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7554
             * @param column zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7555
             * @return the Accessible at the specified row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7556
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7557
            public Accessible getAccessibleAt(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7558
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7559
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7560
                // TIGER - 4715503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7561
                TableColumn aColumn = headerModel.getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7562
                TableCellRenderer renderer = aColumn.getHeaderRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7563
                if (renderer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7564
                    renderer = header.getDefaultRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7565
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7566
                Component component = renderer.getTableCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7567
                                  header.getTable(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7568
                                  aColumn.getHeaderValue(), false, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7569
                                  -1, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7570
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7571
                return new AccessibleJTableHeaderCell(row, column,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7572
                                                      JTable.this.getTableHeader(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7573
                                                      component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7574
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7575
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7576
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7577
             * Returns the number of rows occupied by the Accessible at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7578
             * a specified row and column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7579
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7580
             * @return the number of rows occupied by the Accessible at a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7581
             * given specified (row, column)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7582
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7583
            public int getAccessibleRowExtentAt(int r, int c) { return 1; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7584
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7585
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7586
             * Returns the number of columns occupied by the Accessible at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7587
             * a specified row and column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7588
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7589
             * @return the number of columns occupied by the Accessible at a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7590
             * given specified row and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7591
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7592
            public int getAccessibleColumnExtentAt(int r, int c) { return 1; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7593
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7594
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7595
             * Returns the row headers as an AccessibleTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7596
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7597
             * @return an AccessibleTable representing the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7598
             * headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7599
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7600
            public AccessibleTable getAccessibleRowHeader() { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7601
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7602
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7603
             * Sets the row headers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7604
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7605
             * @param table an AccessibleTable representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7606
             * row headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7607
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7608
            public void setAccessibleRowHeader(AccessibleTable table) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7609
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7610
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7611
             * Returns the column headers as an AccessibleTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7612
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7613
             * @return an AccessibleTable representing the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7614
             * headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7615
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7616
            public AccessibleTable getAccessibleColumnHeader() { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7617
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7618
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7619
             * Sets the column headers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7620
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7621
             * @param table an AccessibleTable representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7622
             * column headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7623
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7624
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7625
            public void setAccessibleColumnHeader(AccessibleTable table) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7626
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7627
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7628
             * Returns the description of the specified row in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7629
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7630
             * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7631
             * @return the description of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7632
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7633
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7634
            public Accessible getAccessibleRowDescription(int r) { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7635
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7636
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7637
             * Sets the description text of the specified row of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7638
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7639
             * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7640
             * @param a the description of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7641
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7642
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7643
            public void setAccessibleRowDescription(int r, Accessible a) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7645
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7646
             * Returns the description text of the specified column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7647
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7648
             * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7649
             * @return the text description of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7650
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7651
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7652
            public Accessible getAccessibleColumnDescription(int c) { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7653
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7654
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7655
             * Sets the description text of the specified column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7656
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7657
             * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7658
             * @param a the text description of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7659
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7660
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7661
            public void setAccessibleColumnDescription(int c, Accessible a) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7662
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7663
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7664
             * Returns a boolean value indicating whether the accessible at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7665
             * a specified row and column is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7666
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7667
             * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7668
             * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7669
             * @return the boolean value true if the accessible at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7670
             * row and column is selected. Otherwise, the boolean value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7671
             * false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7672
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7673
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7674
            public boolean isAccessibleSelected(int r, int c) { return false; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7675
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7676
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7677
             * Returns a boolean value indicating whether the specified row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7678
             * is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7679
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7680
             * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7681
             * @return the boolean value true if the specified row is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7682
             * Otherwise, false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7683
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7684
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7685
            public boolean isAccessibleRowSelected(int r) { return false; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7686
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7687
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7688
             * Returns a boolean value indicating whether the specified column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7689
             * is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7690
             *
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 21278
diff changeset
  7691
             * @param c zero-based column of the table
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7692
             * @return the boolean value true if the specified column is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7693
             * Otherwise, false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7694
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7695
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7696
            public boolean isAccessibleColumnSelected(int c) { return false; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7697
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7698
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7699
             * Returns the selected rows in a table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7700
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7701
             * @return an array of selected rows where each element is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7702
             * zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7703
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7704
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7705
            public int [] getSelectedAccessibleRows() { return new int[0]; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7706
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7707
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7708
             * Returns the selected columns in a table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7709
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7710
             * @return an array of selected columns where each element is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7711
             * zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7712
             * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7713
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7714
            public int [] getSelectedAccessibleColumns() { return new int[0]; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7715
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7716
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7717
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7718
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7719
         * Sets the column headers as an <code>AccessibleTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7720
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7721
         * @param a an <code>AccessibleTable</code> representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7722
         * column headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7723
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7724
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7725
        public void setAccessibleColumnHeader(AccessibleTable a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7726
            // XXX not implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7727
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7728
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7729
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7730
         * Returns the description of the specified row in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7731
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7732
         * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7733
         * @return the description of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7734
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7735
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7736
        public Accessible getAccessibleRowDescription(int r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7737
            if (r < 0 || r >= getAccessibleRowCount()) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  7738
                throw new IllegalArgumentException(Integer.toString(r));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7739
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7740
            if (rowDescription == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7741
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7742
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7743
                return rowDescription[r];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7744
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7745
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7746
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7747
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7748
         * Sets the description text of the specified row of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7749
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7750
         * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7751
         * @param a the description of the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7752
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7753
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7754
        public void setAccessibleRowDescription(int r, Accessible a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7755
            if (r < 0 || r >= getAccessibleRowCount()) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  7756
                throw new IllegalArgumentException(Integer.toString(r));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7757
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7758
            if (rowDescription == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7759
                int numRows = getAccessibleRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7760
                rowDescription = new Accessible[numRows];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7761
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7762
            rowDescription[r] = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7763
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7764
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7765
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7766
         * Returns the description of the specified column in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7767
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7768
         * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7769
         * @return the description of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7770
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7771
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7772
        public Accessible getAccessibleColumnDescription(int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7773
            if (c < 0 || c >= getAccessibleColumnCount()) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  7774
                throw new IllegalArgumentException(Integer.toString(c));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7775
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7776
            if (columnDescription == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7777
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7778
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7779
                return columnDescription[c];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7780
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7781
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7782
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7783
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7784
         * Sets the description text of the specified column of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7785
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7786
         * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7787
         * @param a the description of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7788
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7789
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7790
        public void setAccessibleColumnDescription(int c, Accessible a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7791
            if (c < 0 || c >= getAccessibleColumnCount()) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  7792
                throw new IllegalArgumentException(Integer.toString(c));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7793
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7794
            if (columnDescription == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7795
                int numColumns = getAccessibleColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7796
                columnDescription = new Accessible[numColumns];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7797
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7798
            columnDescription[c] = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7799
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7800
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7801
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7802
         * Returns a boolean value indicating whether the accessible at a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7803
         * given (row, column) is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7804
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7805
         * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7806
         * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7807
         * @return the boolean value true if the accessible at (row, column)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7808
         *     is selected; otherwise, the boolean value false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7809
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7810
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7811
        public boolean isAccessibleSelected(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7812
            return JTable.this.isCellSelected(r, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7814
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7815
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7816
         * Returns a boolean value indicating whether the specified row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7817
         * is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7818
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7819
         * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7820
         * @return the boolean value true if the specified row is selected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7821
         *     otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7822
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7823
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7824
        public boolean isAccessibleRowSelected(int r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7825
            return JTable.this.isRowSelected(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7826
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7827
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7828
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7829
         * Returns a boolean value indicating whether the specified column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7830
         * is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7831
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7832
         * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7833
         * @return the boolean value true if the specified column is selected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7834
         *     otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7835
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7836
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7837
        public boolean isAccessibleColumnSelected(int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7838
            return JTable.this.isColumnSelected(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7839
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7840
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7841
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7842
         * Returns the selected rows in a table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7843
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7844
         * @return an array of selected rows where each element is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7845
         *     zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7846
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7847
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7848
        public int [] getSelectedAccessibleRows() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7849
            return JTable.this.getSelectedRows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7851
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7852
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7853
         * Returns the selected columns in a table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7854
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7855
         * @return an array of selected columns where each element is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7856
         *     zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7857
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7858
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7859
        public int [] getSelectedAccessibleColumns() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7860
            return JTable.this.getSelectedColumns();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7861
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7862
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7863
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7864
         * Returns the row at a given index into the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7865
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7866
         * @param i zero-based index into the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7867
         * @return the row at a given index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7868
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7869
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7870
        public int getAccessibleRowAtIndex(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7871
            int columnCount = getAccessibleColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7872
            if (columnCount == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7873
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7874
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7875
                return (i / columnCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7876
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7877
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7878
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7879
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7880
         * Returns the column at a given index into the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7881
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7882
         * @param i zero-based index into the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7883
         * @return the column at a given index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7884
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7885
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7886
        public int getAccessibleColumnAtIndex(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7887
            int columnCount = getAccessibleColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7888
            if (columnCount == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7889
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7890
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7891
                return (i % columnCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7892
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7893
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7894
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7895
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7896
         * Returns the index at a given (row, column) in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7897
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7898
         * @param r zero-based row of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7899
         * @param c zero-based column of the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7900
         * @return the index into the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7901
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7902
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7903
        public int getAccessibleIndexAt(int r, int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7904
            return ((r * getAccessibleColumnCount()) + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7905
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7906
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7907
        // end of AccessibleTable implementation --------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7908
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7909
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7910
         * The class provides an implementation of the Java Accessibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7911
         * API appropriate to table cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7912
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7913
        protected class AccessibleJTableCell extends AccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7914
            implements Accessible, AccessibleComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7915
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7916
            private JTable parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7917
            private int row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7918
            private int column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7919
            private int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7920
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7921
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7922
             *  Constructs an <code>AccessibleJTableHeaderEntry</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7923
             * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7924
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7925
            public AccessibleJTableCell(JTable t, int r, int c, int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7926
                parent = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7927
                row = r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7928
                column = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7929
                index = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7930
                this.setAccessibleParent(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7931
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7932
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7933
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7934
             * Gets the <code>AccessibleContext</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7935
             * component. In the implementation of the Java Accessibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7936
             * API for this class, return this object, which is its own
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7937
             * <code>AccessibleContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7938
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7939
             * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7940
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7941
            public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7942
                return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7943
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7944
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7945
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7946
             * Gets the AccessibleContext for the table cell renderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7947
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7948
             * @return the <code>AccessibleContext</code> for the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7949
             * cell renderer if one exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7950
             * otherwise, returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7951
             * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7952
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7953
            protected AccessibleContext getCurrentAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7954
                TableColumn aColumn = getColumnModel().getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7955
                TableCellRenderer renderer = aColumn.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7956
                if (renderer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7957
                    Class<?> columnClass = getColumnClass(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7958
                    renderer = getDefaultRenderer(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7959
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7960
                Component component = renderer.getTableCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7961
                                  JTable.this, getValueAt(row, column),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7962
                                  false, false, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7963
                if (component instanceof Accessible) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  7964
                    return component.getAccessibleContext();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7965
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7966
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7967
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7968
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7969
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7970
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7971
             * Gets the table cell renderer component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7972
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7973
             * @return the table cell renderer component if one exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7974
             * otherwise, returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7975
             * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7976
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7977
            protected Component getCurrentComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7978
                TableColumn aColumn = getColumnModel().getColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7979
                TableCellRenderer renderer = aColumn.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7980
                if (renderer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7981
                    Class<?> columnClass = getColumnClass(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7982
                    renderer = getDefaultRenderer(columnClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7983
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7984
                return renderer.getTableCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7985
                                  JTable.this, null, false, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7986
                                  row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7987
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7988
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7989
        // AccessibleContext methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7990
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7991
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7992
             * Gets the accessible name of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7993
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7994
             * @return the localized name of the object; <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7995
             *     if this object does not have a name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7996
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7997
            public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7998
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7999
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8000
                    String name = ac.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8001
                    if ((name != null) && (name != "")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8002
                        // return the cell renderer's AccessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8003
                        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8004
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8005
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8006
                if ((accessibleName != null) && (accessibleName != "")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8007
                    return accessibleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8008
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8009
                    // fall back to the client property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8010
                    return (String)getClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8011
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8012
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8014
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8015
             * Sets the localized accessible name of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8016
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8017
             * @param s the new localized name of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8018
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8019
            public void setAccessibleName(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8020
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8021
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8022
                    ac.setAccessibleName(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8023
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8024
                    super.setAccessibleName(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8025
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8026
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8028
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8029
            // *** should check toolTip text for desc. (needs MouseEvent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8030
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8031
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8032
             * Gets the accessible description of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8033
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8034
             * @return the localized description of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8035
             *     <code>null</code> if this object does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8036
             *     a description
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8037
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8038
            public String getAccessibleDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8039
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8040
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8041
                    return ac.getAccessibleDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8042
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8043
                    return super.getAccessibleDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8044
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8045
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8046
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8047
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8048
             * Sets the accessible description of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8049
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8050
             * @param s the new localized description of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8051
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8052
            public void setAccessibleDescription(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8053
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8054
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8055
                    ac.setAccessibleDescription(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8056
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8057
                    super.setAccessibleDescription(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8058
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8059
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8061
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8062
             * Gets the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8063
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8064
             * @return an instance of <code>AccessibleRole</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8065
             *      describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8066
             * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8067
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8068
            public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8069
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8070
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8071
                    return ac.getAccessibleRole();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8072
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8073
                    return AccessibleRole.UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8074
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8075
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8077
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8078
             * Gets the state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8079
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8080
             * @return an instance of <code>AccessibleStateSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8081
             *     containing the current state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8082
             * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8083
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8084
            public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8085
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8086
                AccessibleStateSet as = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8088
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8089
                    as = ac.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8090
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8091
                if (as == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8092
                    as = new AccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8093
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8094
                Rectangle rjt = JTable.this.getVisibleRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8095
                Rectangle rcell = JTable.this.getCellRect(row, column, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8096
                if (rjt.intersects(rcell)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8097
                    as.add(AccessibleState.SHOWING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8098
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8099
                    if (as.contains(AccessibleState.SHOWING)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8100
                         as.remove(AccessibleState.SHOWING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8101
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8102
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8103
                if (parent.isCellSelected(row, column)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8104
                    as.add(AccessibleState.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8105
                } else if (as.contains(AccessibleState.SELECTED)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8106
                    as.remove(AccessibleState.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8107
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8108
                if ((row == getSelectedRow()) && (column == getSelectedColumn())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8109
                    as.add(AccessibleState.ACTIVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8110
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8111
                as.add(AccessibleState.TRANSIENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8112
                return as;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8113
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8115
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8116
             * Gets the <code>Accessible</code> parent of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8117
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8118
             * @return the Accessible parent of this object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8119
             *     <code>null</code> if this object does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8120
             *     have an <code>Accessible</code> parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8121
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8122
            public Accessible getAccessibleParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8123
                return parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8124
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8126
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8127
             * Gets the index of this object in its accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8128
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8129
             * @return the index of this object in its parent; -1 if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8130
             *     object does not have an accessible parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8131
             * @see #getAccessibleParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8132
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8133
            public int getAccessibleIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8134
                return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8135
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8136
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8137
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8138
             * Returns the number of accessible children in the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8139
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8140
             * @return the number of accessible children in the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8141
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8142
            public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8143
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8144
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8145
                    return ac.getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8146
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8147
                    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8148
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8150
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8151
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8152
             * Returns the specified <code>Accessible</code> child of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8153
             * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8154
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8155
             * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8156
             * @return the <code>Accessible</code> child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8157
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8158
            public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8159
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8160
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8161
                    Accessible accessibleChild = ac.getAccessibleChild(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8162
                    ac.setAccessibleParent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8163
                    return accessibleChild;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8164
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8165
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8166
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8168
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8169
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8170
             * Gets the locale of the component. If the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8171
             * does not have a locale, then the locale of its parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8172
             * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8173
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8174
             * @return this component's locale; if this component does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8175
             *    not have a locale, the locale of its parent is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8176
             * @exception IllegalComponentStateException if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8177
             *    <code>Component</code> does not have its own locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8178
             *    and has not yet been added to a containment hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8179
             *    such that the locale can be determined from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8180
             *    containing parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8181
             * @see #setLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8182
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8183
            public Locale getLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8184
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8185
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8186
                    return ac.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8187
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8188
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8189
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8192
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8193
             * Adds a <code>PropertyChangeListener</code> to the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8194
             * The listener is registered for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8195
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8196
             * @param l  the <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8197
             *     to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8198
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8199
            public void addPropertyChangeListener(PropertyChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8200
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8201
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8202
                    ac.addPropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8203
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8204
                    super.addPropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8205
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8207
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8208
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8209
             * Removes a <code>PropertyChangeListener</code> from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8210
             * listener list. This removes a <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8211
             * that was registered for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8212
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8213
             * @param l  the <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8214
             *    to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8215
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8216
            public void removePropertyChangeListener(PropertyChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8217
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8218
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8219
                    ac.removePropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8220
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8221
                    super.removePropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8222
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8224
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8225
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8226
             * Gets the <code>AccessibleAction</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8227
             * object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8228
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8229
             * @return the <code>AccessibleAction</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8230
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8231
            public AccessibleAction getAccessibleAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8232
                return getCurrentAccessibleContext().getAccessibleAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8235
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8236
             * Gets the <code>AccessibleComponent</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8237
             * this object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8238
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8239
             * @return the <code>AccessibleComponent</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8240
             *    <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8241
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8242
            public AccessibleComponent getAccessibleComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8243
                return this; // to override getBounds()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8245
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8246
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8247
             * Gets the <code>AccessibleSelection</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8248
             * this object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8249
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8250
             * @return the <code>AccessibleSelection</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8251
             *    <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8252
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8253
            public AccessibleSelection getAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8254
                return getCurrentAccessibleContext().getAccessibleSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8255
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8256
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8257
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8258
             * Gets the <code>AccessibleText</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8259
             * object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8260
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8261
             * @return the <code>AccessibleText</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8262
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8263
            public AccessibleText getAccessibleText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8264
                return getCurrentAccessibleContext().getAccessibleText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8265
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8266
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8267
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8268
             * Gets the <code>AccessibleValue</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8269
             * this object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8270
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8271
             * @return the <code>AccessibleValue</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8272
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8273
            public AccessibleValue getAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8274
                return getCurrentAccessibleContext().getAccessibleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8275
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8276
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8278
        // AccessibleComponent methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8280
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8281
             * Gets the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8282
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8283
             * @return the background color, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8284
             *     otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8285
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8286
            public Color getBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8287
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8288
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8289
                    return ((AccessibleComponent) ac).getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8290
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8291
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8292
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8293
                        return c.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8294
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8295
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8296
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8297
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8298
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8300
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8301
             * Sets the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8302
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8303
             * @param c the new <code>Color</code> for the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8304
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8305
            public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8306
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8307
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8308
                    ((AccessibleComponent) ac).setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8309
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8310
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8311
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8312
                        cp.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8313
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8314
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8315
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8316
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8317
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8318
             * Gets the foreground color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8319
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8320
             * @return the foreground color, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8321
             *     otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8322
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8323
            public Color getForeground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8324
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8325
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8326
                    return ((AccessibleComponent) ac).getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8327
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8328
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8329
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8330
                        return c.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8331
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8332
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8333
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8334
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8335
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8336
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8337
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8338
             * Sets the foreground color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8339
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8340
             * @param c the new <code>Color</code> for the foreground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8341
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8342
            public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8343
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8344
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8345
                    ((AccessibleComponent) ac).setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8346
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8347
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8348
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8349
                        cp.setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8350
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8351
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8352
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8353
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8354
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8355
             * Gets the <code>Cursor</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8356
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8357
             * @return the <code>Cursor</code>, if supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8358
             *    of the object; otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8359
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8360
            public Cursor getCursor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8361
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8362
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8363
                    return ((AccessibleComponent) ac).getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8364
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8365
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8366
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8367
                        return c.getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8368
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8369
                        Accessible ap = getAccessibleParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8370
                        if (ap instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8371
                            return ((AccessibleComponent) ap).getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8372
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8373
                            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8374
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8375
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8376
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8377
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8379
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8380
             * Sets the <code>Cursor</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8381
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8382
             * @param c the new <code>Cursor</code> for the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8383
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8384
            public void setCursor(Cursor c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8385
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8386
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8387
                    ((AccessibleComponent) ac).setCursor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8388
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8389
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8390
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8391
                        cp.setCursor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8392
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8393
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8394
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8396
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8397
             * Gets the <code>Font</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8398
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8399
             * @return the <code>Font</code>,if supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8400
             *   for the object; otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8401
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8402
            public Font getFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8403
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8404
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8405
                    return ((AccessibleComponent) ac).getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8406
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8407
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8408
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8409
                        return c.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8410
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8411
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8412
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8413
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8414
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8416
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8417
             * Sets the <code>Font</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8418
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8419
             * @param f the new <code>Font</code> for the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8420
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8421
            public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8422
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8423
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8424
                    ((AccessibleComponent) ac).setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8425
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8426
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8427
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8428
                        c.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8429
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8430
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8431
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8433
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8434
             * Gets the <code>FontMetrics</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8435
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8436
             * @param f the <code>Font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8437
             * @return the <code>FontMetrics</code> object, if supported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8438
             *    otherwise <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8439
             * @see #getFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8440
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8441
            public FontMetrics getFontMetrics(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8442
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8443
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8444
                    return ((AccessibleComponent) ac).getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8445
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8446
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8447
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8448
                        return c.getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8449
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8450
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8451
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8452
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8453
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8454
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8455
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8456
             * Determines if the object is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8457
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8458
             * @return true if object is enabled; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8459
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8460
            public boolean isEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8461
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8462
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8463
                    return ((AccessibleComponent) ac).isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8464
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8465
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8466
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8467
                        return c.isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8468
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8469
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8470
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8471
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8472
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8473
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8474
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8475
             * Sets the enabled state of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8476
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8477
             * @param b if true, enables this object; otherwise, disables it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8478
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8479
            public void setEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8480
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8481
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8482
                    ((AccessibleComponent) ac).setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8483
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8484
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8485
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8486
                        c.setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8487
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8488
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8489
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8490
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8491
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8492
             * Determines if this object is visible.  Note: this means that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8493
             * object intends to be visible; however, it may not in fact be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8494
             * showing on the screen because one of the objects that this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8495
             * is contained by is not visible.  To determine if an object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8496
             * showing on the screen, use <code>isShowing</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8497
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8498
             * @return true if object is visible; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8499
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8500
            public boolean isVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8501
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8502
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8503
                    return ((AccessibleComponent) ac).isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8504
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8505
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8506
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8507
                        return c.isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8508
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8509
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8510
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8511
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8512
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8513
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8514
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8515
             * Sets the visible state of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8516
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8517
             * @param b if true, shows this object; otherwise, hides it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8518
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8519
            public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8520
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8521
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8522
                    ((AccessibleComponent) ac).setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8523
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8524
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8525
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8526
                        c.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8527
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8528
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8529
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8530
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8531
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8532
             * Determines if the object is showing.  This is determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8533
             * by checking the visibility of the object and ancestors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8534
             * of the object.  Note: this will return true even if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8535
             * object is obscured by another (for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8536
             * it happens to be underneath a menu that was pulled down).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8537
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8538
             * @return true if the object is showing; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8539
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8540
            public boolean isShowing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8541
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8542
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8543
                    if (ac.getAccessibleParent() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8544
                        return ((AccessibleComponent) ac).isShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8545
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8546
                        // Fixes 4529616 - AccessibleJTableCell.isShowing()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8547
                        // returns false when the cell on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8548
                        // if no parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8549
                        return isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8550
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8551
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8552
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8553
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8554
                        return c.isShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8555
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8556
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8557
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8558
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8559
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8560
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8561
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8562
             * Checks whether the specified point is within this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8563
             * object's bounds, where the point's x and y coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8564
             * are defined to be relative to the coordinate system of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8565
             * the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8566
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8567
             * @param p the <code>Point</code> relative to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8568
             *    coordinate system of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8569
             * @return true if object contains <code>Point</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8570
             *    otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8571
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8572
            public boolean contains(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8573
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8574
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8575
                    Rectangle r = ((AccessibleComponent) ac).getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8576
                    return r.contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8577
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8578
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8579
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8580
                        Rectangle r = c.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8581
                        return r.contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8582
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8583
                        return getBounds().contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8584
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8585
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8586
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8587
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8588
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8589
             * Returns the location of the object on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8590
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8591
             * @return location of object on screen -- can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8592
             *    <code>null</code> if this object is not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8593
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8594
            public Point getLocationOnScreen() {
13546
8c7270c4ce42 7188612: JTable's AccessibleJTable throws IllegalComponentStateException instead of null
dingxmin
parents: 12524
diff changeset
  8595
                if (parent != null && parent.isShowing()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8596
                    Point parentLocation = parent.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8597
                    Point componentLocation = getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8598
                    componentLocation.translate(parentLocation.x, parentLocation.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8599
                    return componentLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8600
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8601
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8602
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8603
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8604
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8605
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8606
             * Gets the location of the object relative to the parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8607
             * in the form of a point specifying the object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8608
             * top-left corner in the screen's coordinate space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8609
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8610
             * @return an instance of <code>Point</code> representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8611
             *    the top-left corner of the object's bounds in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8612
             *    coordinate space of the screen; <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8613
             *    this object or its parent are not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8614
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8615
            public Point getLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8616
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8617
                    Rectangle r = parent.getCellRect(row, column, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8618
                    if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8619
                        return r.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8620
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8621
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8622
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8623
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8624
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8625
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8626
             * Sets the location of the object relative to the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8627
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8628
            public void setLocation(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8629
//              if ((parent != null)  && (parent.contains(p))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8630
//                  ensureIndexIsVisible(indexInParent);
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
            public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8635
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8636
                    return parent.getCellRect(row, column, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8637
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8638
                    return null;
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 void setBounds(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8643
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8644
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8645
                    ((AccessibleComponent) ac).setBounds(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8646
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8647
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8648
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8649
                        c.setBounds(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8650
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8651
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8652
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8653
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8654
            public Dimension getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8655
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8656
                    Rectangle r = parent.getCellRect(row, column, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8657
                    if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8658
                        return r.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8659
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8660
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8661
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8662
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8663
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8664
            public void setSize (Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8665
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8666
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8667
                    ((AccessibleComponent) ac).setSize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8668
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8669
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8670
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8671
                        c.setSize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8672
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8673
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8674
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8675
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8676
            public Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8677
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8678
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8679
                    return ((AccessibleComponent) ac).getAccessibleAt(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8680
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8681
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8682
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8683
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8684
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8685
            public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8686
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8687
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8688
                    return ((AccessibleComponent) ac).isFocusTraversable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8689
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8690
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8691
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8692
                        return c.isFocusTraversable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8693
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8694
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8695
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8696
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8697
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8698
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8699
            public void requestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8700
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8701
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8702
                    ((AccessibleComponent) ac).requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8703
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8704
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8705
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8706
                        c.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8707
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8708
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8709
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8710
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8711
            public void addFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8712
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8713
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8714
                    ((AccessibleComponent) ac).addFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8715
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8716
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8717
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8718
                        c.addFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8719
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8720
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8721
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8722
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8723
            public void removeFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8724
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8725
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8726
                    ((AccessibleComponent) ac).removeFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8727
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8728
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8729
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8730
                        c.removeFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8731
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8732
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8733
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8734
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8735
        } // inner class AccessibleJTableCell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8736
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8737
        // Begin AccessibleJTableHeader ========== // TIGER - 4715503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8738
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8739
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8740
         * This class implements accessibility for JTable header cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8741
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8742
        private class AccessibleJTableHeaderCell extends AccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8743
            implements Accessible, AccessibleComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8744
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8745
            private int row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8746
            private int column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8747
            private JTableHeader parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8748
            private Component rendererComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8749
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8750
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8751
             * Constructs an <code>AccessibleJTableHeaderEntry</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8752
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8753
             * @param row header cell row index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8754
             * @param column header cell column index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8755
             * @param parent header cell parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8756
             * @param rendererComponent component that renders the header cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8757
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8758
            public AccessibleJTableHeaderCell(int row, int column,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8759
                                              JTableHeader parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8760
                                              Component rendererComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8761
                this.row = row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8762
                this.column = column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8763
                this.parent = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8764
                this.rendererComponent = rendererComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8765
                this.setAccessibleParent(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8766
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8767
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8768
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8769
             * Gets the <code>AccessibleContext</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8770
             * component. In the implementation of the Java Accessibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8771
             * API for this class, return this object, which is its own
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8772
             * <code>AccessibleContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8773
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8774
             * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8775
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8776
            public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8777
                return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8778
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8779
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8780
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8781
             * Returns the AccessibleContext for the header cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8782
             * renderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8783
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8784
            private AccessibleContext getCurrentAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8785
                return rendererComponent.getAccessibleContext();
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 component that renders the header cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8790
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8791
            private Component getCurrentComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8792
                return rendererComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8793
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8794
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8795
            // AccessibleContext methods ==========
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8796
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8797
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8798
             * Gets the accessible name of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8799
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8800
             * @return the localized name of the object; <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8801
             *     if this object does not have a name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8802
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8803
            public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8804
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8805
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8806
                    String name = ac.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8807
                    if ((name != null) && (name != "")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8808
                        return ac.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8809
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8810
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8811
                if ((accessibleName != null) && (accessibleName != "")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8812
                    return accessibleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8813
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8814
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8815
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8816
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8817
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8818
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8819
             * Sets the localized accessible name of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8820
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8821
             * @param s the new localized name of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8822
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8823
            public void setAccessibleName(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8824
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8825
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8826
                    ac.setAccessibleName(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8827
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8828
                    super.setAccessibleName(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8829
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8830
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8831
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8832
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8833
             * Gets the accessible description of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8834
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8835
             * @return the localized description of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8836
             *     <code>null</code> if this object does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8837
             *     a description
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8838
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8839
            public String getAccessibleDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8840
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8841
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8842
                    return ac.getAccessibleDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8843
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8844
                    return super.getAccessibleDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8845
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8846
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8847
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8848
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8849
             * Sets the accessible description of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8850
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8851
             * @param s the new localized description of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8852
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8853
            public void setAccessibleDescription(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8854
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8855
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8856
                    ac.setAccessibleDescription(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8857
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8858
                    super.setAccessibleDescription(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8859
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8860
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8861
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8862
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8863
             * Gets the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8864
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8865
             * @return an instance of <code>AccessibleRole</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8866
             *      describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8867
             * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8868
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8869
            public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8870
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8871
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8872
                    return ac.getAccessibleRole();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8873
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8874
                    return AccessibleRole.UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8875
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8876
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8877
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8878
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8879
             * Gets the state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8880
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8881
             * @return an instance of <code>AccessibleStateSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8882
             *     containing the current state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8883
             * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8884
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8885
            public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8886
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8887
                AccessibleStateSet as = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8888
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8889
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8890
                    as = ac.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8891
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8892
                if (as == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8893
                    as = new AccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8894
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8895
                Rectangle rjt = JTable.this.getVisibleRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8896
                Rectangle rcell = JTable.this.getCellRect(row, column, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8897
                if (rjt.intersects(rcell)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8898
                    as.add(AccessibleState.SHOWING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8899
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8900
                    if (as.contains(AccessibleState.SHOWING)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8901
                         as.remove(AccessibleState.SHOWING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8902
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8903
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8904
                if (JTable.this.isCellSelected(row, column)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8905
                    as.add(AccessibleState.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8906
                } else if (as.contains(AccessibleState.SELECTED)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8907
                    as.remove(AccessibleState.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8908
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8909
                if ((row == getSelectedRow()) && (column == getSelectedColumn())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8910
                    as.add(AccessibleState.ACTIVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8911
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8912
                as.add(AccessibleState.TRANSIENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8913
                return as;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8914
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8915
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8916
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8917
             * Gets the <code>Accessible</code> parent of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8918
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8919
             * @return the Accessible parent of this object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8920
             *     <code>null</code> if this object does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8921
             *     have an <code>Accessible</code> parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8922
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8923
            public Accessible getAccessibleParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8924
                return parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8925
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8926
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8927
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8928
             * Gets the index of this object in its accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8929
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8930
             * @return the index of this object in its parent; -1 if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8931
             *     object does not have an accessible parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8932
             * @see #getAccessibleParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8933
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8934
            public int getAccessibleIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8935
                return column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8936
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8937
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8938
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8939
             * Returns the number of accessible children in the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8940
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8941
             * @return the number of accessible children in the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8942
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8943
            public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8944
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8945
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8946
                    return ac.getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8947
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8948
                    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8949
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8950
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8951
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8952
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8953
             * Returns the specified <code>Accessible</code> child of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8954
             * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8955
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8956
             * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8957
             * @return the <code>Accessible</code> child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8958
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8959
            public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8960
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8961
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8962
                    Accessible accessibleChild = ac.getAccessibleChild(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8963
                    ac.setAccessibleParent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8964
                    return accessibleChild;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8965
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8966
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8967
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8968
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8969
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8970
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8971
             * Gets the locale of the component. If the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8972
             * does not have a locale, then the locale of its parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8973
             * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8974
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8975
             * @return this component's locale; if this component does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8976
             *    not have a locale, the locale of its parent is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8977
             * @exception IllegalComponentStateException if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8978
             *    <code>Component</code> does not have its own locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8979
             *    and has not yet been added to a containment hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8980
             *    such that the locale can be determined from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8981
             *    containing parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8982
             * @see #setLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8983
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8984
            public Locale getLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8985
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8986
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8987
                    return ac.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8988
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8989
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8990
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8991
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8992
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8993
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8994
             * Adds a <code>PropertyChangeListener</code> to the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8995
             * The listener is registered for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8996
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8997
             * @param l  the <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8998
             *     to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8999
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9000
            public void addPropertyChangeListener(PropertyChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9001
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9002
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9003
                    ac.addPropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9004
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9005
                    super.addPropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9006
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9007
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9009
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9010
             * Removes a <code>PropertyChangeListener</code> from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9011
             * listener list. This removes a <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9012
             * that was registered for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9013
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9014
             * @param l  the <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9015
             *    to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9016
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9017
            public void removePropertyChangeListener(PropertyChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9018
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9019
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9020
                    ac.removePropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9021
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9022
                    super.removePropertyChangeListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9023
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9024
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9025
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9026
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9027
             * Gets the <code>AccessibleAction</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9028
             * object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9029
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9030
             * @return the <code>AccessibleAction</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9031
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9032
            public AccessibleAction getAccessibleAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9033
                return getCurrentAccessibleContext().getAccessibleAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9034
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9036
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9037
             * Gets the <code>AccessibleComponent</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9038
             * this object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9039
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9040
             * @return the <code>AccessibleComponent</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9041
             *    <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9042
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9043
            public AccessibleComponent getAccessibleComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9044
                return this; // to override getBounds()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9045
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9046
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9047
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9048
             * Gets the <code>AccessibleSelection</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9049
             * this object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9050
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9051
             * @return the <code>AccessibleSelection</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9052
             *    <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9053
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9054
            public AccessibleSelection getAccessibleSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9055
                return getCurrentAccessibleContext().getAccessibleSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9056
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9058
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9059
             * Gets the <code>AccessibleText</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9060
             * object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9061
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9062
             * @return the <code>AccessibleText</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9063
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9064
            public AccessibleText getAccessibleText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9065
                return getCurrentAccessibleContext().getAccessibleText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9066
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9068
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9069
             * Gets the <code>AccessibleValue</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9070
             * this object if one exists.  Otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9071
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9072
             * @return the <code>AccessibleValue</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9073
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9074
            public AccessibleValue getAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9075
                return getCurrentAccessibleContext().getAccessibleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9076
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9079
            // AccessibleComponent methods ==========
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9081
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9082
             * Gets the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9083
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9084
             * @return the background color, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9085
             *     otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9086
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9087
            public Color getBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9088
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9089
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9090
                    return ((AccessibleComponent) ac).getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9091
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9092
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9093
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9094
                        return c.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9095
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9096
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9097
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9098
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9099
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9101
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9102
             * Sets the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9103
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9104
             * @param c the new <code>Color</code> for the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9105
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9106
            public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9107
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9108
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9109
                    ((AccessibleComponent) ac).setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9110
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9111
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9112
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9113
                        cp.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9114
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9115
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9118
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9119
             * Gets the foreground color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9120
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9121
             * @return the foreground color, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9122
             *     otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9123
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9124
            public Color getForeground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9125
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9126
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9127
                    return ((AccessibleComponent) ac).getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9128
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9129
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9130
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9131
                        return c.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9132
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9133
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9134
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9135
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9138
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9139
             * Sets the foreground color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9140
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9141
             * @param c the new <code>Color</code> for the foreground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9142
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9143
            public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9144
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9145
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9146
                    ((AccessibleComponent) ac).setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9147
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9148
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9149
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9150
                        cp.setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9151
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9152
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9153
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9155
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9156
             * Gets the <code>Cursor</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9157
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9158
             * @return the <code>Cursor</code>, if supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9159
             *    of the object; otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9160
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9161
            public Cursor getCursor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9162
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9163
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9164
                    return ((AccessibleComponent) ac).getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9165
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9166
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9167
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9168
                        return c.getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9169
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9170
                        Accessible ap = getAccessibleParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9171
                        if (ap instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9172
                            return ((AccessibleComponent) ap).getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9173
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9174
                            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9175
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9176
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9177
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9180
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9181
             * Sets the <code>Cursor</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9182
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9183
             * @param c the new <code>Cursor</code> for the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9184
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9185
            public void setCursor(Cursor c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9186
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9187
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9188
                    ((AccessibleComponent) ac).setCursor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9189
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9190
                    Component cp = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9191
                    if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9192
                        cp.setCursor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9193
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9194
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9197
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9198
             * Gets the <code>Font</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9199
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9200
             * @return the <code>Font</code>,if supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9201
             *   for the object; otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9202
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9203
            public Font getFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9204
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9205
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9206
                    return ((AccessibleComponent) ac).getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9207
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9208
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9209
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9210
                        return c.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9211
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9212
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9213
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9214
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9215
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9217
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9218
             * Sets the <code>Font</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9219
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9220
             * @param f the new <code>Font</code> for the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9221
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9222
            public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9223
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9224
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9225
                    ((AccessibleComponent) ac).setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9226
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9227
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9228
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9229
                        c.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9230
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9231
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9232
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9234
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9235
             * Gets the <code>FontMetrics</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9236
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9237
             * @param f the <code>Font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9238
             * @return the <code>FontMetrics</code> object, if supported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9239
             *    otherwise <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9240
             * @see #getFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9241
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9242
            public FontMetrics getFontMetrics(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9243
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9244
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9245
                    return ((AccessibleComponent) ac).getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9246
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9247
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9248
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9249
                        return c.getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9250
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9251
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9252
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9253
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9256
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9257
             * Determines if the object is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9258
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9259
             * @return true if object is enabled; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9260
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9261
            public boolean isEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9262
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9263
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9264
                    return ((AccessibleComponent) ac).isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9265
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9266
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9267
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9268
                        return c.isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9269
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9270
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9271
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9272
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9273
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9275
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9276
             * Sets the enabled state of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9277
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9278
             * @param b if true, enables this object; otherwise, disables it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9279
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9280
            public void setEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9281
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9282
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9283
                    ((AccessibleComponent) ac).setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9284
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9285
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9286
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9287
                        c.setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9288
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9289
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9291
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9292
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9293
             * Determines if this object is visible.  Note: this means that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9294
             * object intends to be visible; however, it may not in fact be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9295
             * showing on the screen because one of the objects that this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9296
             * is contained by is not visible.  To determine if an object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9297
             * showing on the screen, use <code>isShowing</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9298
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9299
             * @return true if object is visible; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9300
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9301
            public boolean isVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9302
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9303
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9304
                    return ((AccessibleComponent) ac).isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9305
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9306
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9307
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9308
                        return c.isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9309
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9310
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9311
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9312
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9313
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9315
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9316
             * Sets the visible state of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9317
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9318
             * @param b if true, shows this object; otherwise, hides it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9319
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9320
            public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9321
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9322
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9323
                    ((AccessibleComponent) ac).setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9324
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9325
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9326
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9327
                        c.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9328
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9329
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9330
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9331
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9332
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9333
             * Determines if the object is showing.  This is determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9334
             * by checking the visibility of the object and ancestors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9335
             * of the object.  Note: this will return true even if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9336
             * object is obscured by another (for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9337
             * it happens to be underneath a menu that was pulled down).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9338
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9339
             * @return true if the object is showing; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9340
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9341
            public boolean isShowing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9342
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9343
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9344
                    if (ac.getAccessibleParent() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9345
                        return ((AccessibleComponent) ac).isShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9346
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9347
                        // Fixes 4529616 - AccessibleJTableCell.isShowing()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9348
                        // returns false when the cell on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9349
                        // if no parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9350
                        return isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9351
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9352
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9353
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9354
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9355
                        return c.isShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9356
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9357
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9358
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9359
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9360
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9362
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9363
             * Checks whether the specified point is within this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9364
             * object's bounds, where the point's x and y coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9365
             * are defined to be relative to the coordinate system of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9366
             * the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9367
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9368
             * @param p the <code>Point</code> relative to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9369
             *    coordinate system of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9370
             * @return true if object contains <code>Point</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9371
             *    otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9372
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9373
            public boolean contains(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9374
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9375
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9376
                    Rectangle r = ((AccessibleComponent) ac).getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9377
                    return r.contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9378
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9379
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9380
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9381
                        Rectangle r = c.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9382
                        return r.contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9383
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9384
                        return getBounds().contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9385
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9386
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9387
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9388
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9389
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9390
             * Returns the location of the object on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9391
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9392
             * @return location of object on screen -- can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9393
             *    <code>null</code> if this object is not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9394
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9395
            public Point getLocationOnScreen() {
13546
8c7270c4ce42 7188612: JTable's AccessibleJTable throws IllegalComponentStateException instead of null
dingxmin
parents: 12524
diff changeset
  9396
                if (parent != null && parent.isShowing()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9397
                    Point parentLocation = parent.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9398
                    Point componentLocation = getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9399
                    componentLocation.translate(parentLocation.x, parentLocation.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9400
                    return componentLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9401
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9402
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9403
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9405
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9406
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9407
             * Gets the location of the object relative to the parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9408
             * in the form of a point specifying the object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9409
             * top-left corner in the screen's coordinate space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9410
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9411
             * @return an instance of <code>Point</code> representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9412
             *    the top-left corner of the object's bounds in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9413
             *    coordinate space of the screen; <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9414
             *    this object or its parent are not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9415
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9416
            public Point getLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9417
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9418
                    Rectangle r = parent.getHeaderRect(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9419
                    if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9420
                        return r.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9421
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9422
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9423
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9424
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9426
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9427
             * Sets the location of the object relative to the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9428
             * @param p the new position for the top-left corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9429
             * @see #getLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9430
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9431
            public void setLocation(Point p) {
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
             * Gets the bounds of this object in the form of a Rectangle object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9436
             * The bounds specify this object's width, height, and location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9437
             * relative to its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9438
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9439
             * @return A rectangle indicating this component's bounds; null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9440
             * this object is not on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9441
             * @see #contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9442
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9443
            public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9444
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9445
                    return parent.getHeaderRect(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9446
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9447
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9448
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9449
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9450
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9451
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9452
             * Sets the bounds of this object in the form of a Rectangle object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9453
             * The bounds specify this object's width, height, and location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9454
             * relative to its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9455
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9456
             * @param r rectangle indicating this component's bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9457
             * @see #getBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9458
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9459
            public void setBounds(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9460
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9461
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9462
                    ((AccessibleComponent) ac).setBounds(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9463
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9464
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9465
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9466
                        c.setBounds(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9467
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9468
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9469
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9470
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9471
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9472
             * Returns the size of this object in the form of a Dimension object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9473
             * The height field of the Dimension object contains this object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9474
             * height, and the width field of the Dimension object contains this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9475
             * object's width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9476
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9477
             * @return A Dimension object that indicates the size of this component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9478
             * null if this object is not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9479
             * @see #setSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9480
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9481
            public Dimension getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9482
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9483
                    Rectangle r = parent.getHeaderRect(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9484
                    if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9485
                        return r.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9486
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9487
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9488
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9489
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9490
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9491
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9492
             * Resizes this object so that it has width and height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9493
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9494
             * @param d The dimension specifying the new size of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9495
             * @see #getSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9496
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9497
            public void setSize (Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9498
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9499
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9500
                    ((AccessibleComponent) ac).setSize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9501
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9502
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9503
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9504
                        c.setSize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9505
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9506
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9507
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9509
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9510
             * Returns the Accessible child, if one exists, contained at the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9511
             * coordinate Point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9512
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9513
             * @param p The point relative to the coordinate system of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9514
             * @return the Accessible, if it exists, at the specified location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9515
             * otherwise null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9516
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9517
            public Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9518
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9519
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9520
                    return ((AccessibleComponent) ac).getAccessibleAt(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9521
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9522
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9523
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9524
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9525
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9526
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9527
             * Returns whether this object can accept focus or not.   Objects that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9528
             * can accept focus will also have the AccessibleState.FOCUSABLE state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9529
             * set in their AccessibleStateSets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9530
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9531
             * @return true if object can accept focus; otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9532
             * @see AccessibleContext#getAccessibleStateSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9533
             * @see AccessibleState#FOCUSABLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9534
             * @see AccessibleState#FOCUSED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9535
             * @see AccessibleStateSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9536
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9537
            public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9538
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9539
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9540
                    return ((AccessibleComponent) ac).isFocusTraversable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9541
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9542
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9543
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9544
                        return c.isFocusTraversable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9545
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9546
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9547
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9548
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9549
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9550
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9551
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9552
             * Requests focus for this object.  If this object cannot accept focus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9553
             * nothing will happen.  Otherwise, the object will attempt to take
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9554
             * focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9555
             * @see #isFocusTraversable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9556
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9557
            public void requestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9558
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9559
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9560
                    ((AccessibleComponent) ac).requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9561
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9562
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9563
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9564
                        c.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9565
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9566
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9567
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9569
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9570
             * Adds the specified focus listener to receive focus events from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9571
             * component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9572
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9573
             * @param l the focus listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9574
             * @see #removeFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9575
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9576
            public void addFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9577
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9578
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9579
                    ((AccessibleComponent) ac).addFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9580
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9581
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9582
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9583
                        c.addFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9584
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9585
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9586
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9587
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9588
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9589
             * Removes the specified focus listener so it no longer receives focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9590
             * events from this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9591
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9592
             * @param l the focus listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9593
             * @see #addFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9594
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9595
            public void removeFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9596
                AccessibleContext ac = getCurrentAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9597
                if (ac instanceof AccessibleComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9598
                    ((AccessibleComponent) ac).removeFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9599
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9600
                    Component c = getCurrentComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9601
                    if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9602
                        c.removeFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9603
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9604
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9605
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9606
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9607
        } // inner class AccessibleJTableHeaderCell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9608
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9609
    }  // inner class AccessibleJTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9610
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9611
}  // End of Class JTable