0N/A/*
3853N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A *
0N/A * Redistribution and use in source and binary forms, with or without
0N/A * modification, are permitted provided that the following conditions
0N/A * are met:
0N/A *
0N/A * - Redistributions of source code must retain the above copyright
0N/A * notice, this list of conditions and the following disclaimer.
0N/A *
0N/A * - Redistributions in binary form must reproduce the above copyright
0N/A * notice, this list of conditions and the following disclaimer in the
0N/A * documentation and/or other materials provided with the distribution.
0N/A *
2362N/A * - Neither the name of Oracle nor the names of its
0N/A * contributors may be used to endorse or promote products derived
0N/A * from this software without specific prior written permission.
0N/A *
0N/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
0N/A * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
0N/A * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
0N/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
0N/A * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0N/A * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0N/A * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
0N/A * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0N/A * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0N/A * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
0N/A * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0N/A */
0N/A
4378N/A/*
4378N/A * This source code is provided to illustrate the usage of a given feature
4378N/A * or technique and has been deliberately simplified. Additional steps
4378N/A * required for a production-quality application, such as security checks,
4378N/A * input validation and proper error handling, might not be present in
4378N/A * this sample code.
4378N/A */
4378N/A
4378N/A
0N/A
3853N/Aimport java.util.EventObject;
3853N/Aimport java.util.List;
3853N/Aimport javax.swing.JTable;
3853N/Aimport javax.swing.table.DefaultTableModel;
3853N/Aimport javax.swing.table.TableCellEditor;
3853N/Aimport javax.swing.table.TableCellRenderer;
3853N/Aimport javax.swing.table.TableColumn;
0N/A
0N/A
0N/A/**
0N/A * The OldJTable is an unsupported class containing some methods that were
0N/A * deleted from the JTable between releases 0.6 and 0.7
0N/A */
3853N/A@SuppressWarnings("serial")
0N/Apublic class OldJTable extends JTable
0N/A{
0N/A /*
3853N/A * A new convenience method returning the index of the column in the
3853N/A * co-ordinate space of the view.
0N/A */
0N/A public int getColumnIndex(Object identifier) {
0N/A return getColumnModel().getColumnIndex(identifier);
0N/A }
0N/A
0N/A//
0N/A// Methods deleted from the JTable because they only work with the
0N/A// DefaultTableModel.
0N/A//
0N/A
0N/A public TableColumn addColumn(Object columnIdentifier, int width) {
0N/A return addColumn(columnIdentifier, width, null, null, null);
0N/A }
0N/A
3853N/A public TableColumn addColumn(Object columnIdentifier, List columnData) {
0N/A return addColumn(columnIdentifier, -1, null, null, columnData);
0N/A }
0N/A
0N/A // Override the new JTable implementation - it will not add a column to the
0N/A // DefaultTableModel.
0N/A public TableColumn addColumn(Object columnIdentifier, int width,
0N/A TableCellRenderer renderer,
0N/A TableCellEditor editor) {
0N/A return addColumn(columnIdentifier, width, renderer, editor, null);
0N/A }
0N/A
0N/A public TableColumn addColumn(Object columnIdentifier, int width,
0N/A TableCellRenderer renderer,
3853N/A TableCellEditor editor, List columnData) {
0N/A checkDefaultTableModel();
0N/A
0N/A // Set up the model side first
0N/A DefaultTableModel m = (DefaultTableModel)getModel();
3853N/A m.addColumn(columnIdentifier, columnData.toArray());
0N/A
0N/A // The column will have been added to the end, so the index of the
0N/A // column in the model is the last element.
3853N/A TableColumn newColumn = new TableColumn(
3853N/A m.getColumnCount()-1, width, renderer, editor);
0N/A super.addColumn(newColumn);
0N/A return newColumn;
0N/A }
0N/A
0N/A // Not possilble to make this work the same way ... change it so that
0N/A // it does not delete columns from the model.
0N/A public void removeColumn(Object columnIdentifier) {
0N/A super.removeColumn(getColumn(columnIdentifier));
0N/A }
0N/A
0N/A public void addRow(Object[] rowData) {
0N/A checkDefaultTableModel();
0N/A ((DefaultTableModel)getModel()).addRow(rowData);
0N/A }
0N/A
3853N/A public void addRow(List rowData) {
0N/A checkDefaultTableModel();
3853N/A ((DefaultTableModel)getModel()).addRow(rowData.toArray());
0N/A }
0N/A
0N/A public void removeRow(int rowIndex) {
0N/A checkDefaultTableModel();
0N/A ((DefaultTableModel)getModel()).removeRow(rowIndex);
0N/A }
0N/A
0N/A public void moveRow(int startIndex, int endIndex, int toIndex) {
0N/A checkDefaultTableModel();
0N/A ((DefaultTableModel)getModel()).moveRow(startIndex, endIndex, toIndex);
0N/A }
0N/A
0N/A public void insertRow(int rowIndex, Object[] rowData) {
0N/A checkDefaultTableModel();
0N/A ((DefaultTableModel)getModel()).insertRow(rowIndex, rowData);
0N/A }
0N/A
3853N/A public void insertRow(int rowIndex, List rowData) {
0N/A checkDefaultTableModel();
3853N/A ((DefaultTableModel)getModel()).insertRow(rowIndex, rowData.toArray());
0N/A }
0N/A
0N/A public void setNumRows(int newSize) {
0N/A checkDefaultTableModel();
0N/A ((DefaultTableModel)getModel()).setNumRows(newSize);
0N/A }
0N/A
3853N/A public void setDataVector(Object[][] newData, List columnIds) {
0N/A checkDefaultTableModel();
3853N/A ((DefaultTableModel)getModel()).setDataVector(
3853N/A newData, columnIds.toArray());
0N/A }
0N/A
0N/A public void setDataVector(Object[][] newData, Object[] columnIds) {
0N/A checkDefaultTableModel();
0N/A ((DefaultTableModel)getModel()).setDataVector(newData, columnIds);
0N/A }
0N/A
0N/A protected void checkDefaultTableModel() {
0N/A if(!(dataModel instanceof DefaultTableModel))
0N/A throw new InternalError("In order to use this method, the data model must be an instance of DefaultTableModel.");
0N/A }
0N/A
0N/A//
0N/A// Methods removed from JTable in the move from identifiers to ints.
0N/A//
0N/A
0N/A public Object getValueAt(Object columnIdentifier, int rowIndex) {
3853N/A return super.getValueAt(rowIndex, getColumnIndex(columnIdentifier));
0N/A }
0N/A
0N/A public boolean isCellEditable(Object columnIdentifier, int rowIndex) {
3853N/A return super.isCellEditable(rowIndex, getColumnIndex(columnIdentifier));
0N/A }
0N/A
0N/A public void setValueAt(Object aValue, Object columnIdentifier, int rowIndex) {
0N/A super.setValueAt(aValue, rowIndex, getColumnIndex(columnIdentifier));
0N/A }
0N/A
0N/A public boolean editColumnRow(Object identifier, int row) {
0N/A return super.editCellAt(row, getColumnIndex(identifier));
0N/A }
0N/A
0N/A public void moveColumn(Object columnIdentifier, Object targetColumnIdentifier) {
0N/A moveColumn(getColumnIndex(columnIdentifier),
0N/A getColumnIndex(targetColumnIdentifier));
0N/A }
0N/A
0N/A public boolean isColumnSelected(Object identifier) {
0N/A return isColumnSelected(getColumnIndex(identifier));
0N/A }
0N/A
0N/A public TableColumn addColumn(int modelColumn, int width) {
0N/A return addColumn(modelColumn, width, null, null);
0N/A }
0N/A
0N/A public TableColumn addColumn(int modelColumn) {
0N/A return addColumn(modelColumn, 75, null, null);
0N/A }
0N/A
0N/A /**
0N/A * Creates a new column with <I>modelColumn</I>, <I>width</I>,
0N/A * <I>renderer</I>, and <I>editor</I> and adds it to the end of
0N/A * the JTable's array of columns. This method also retrieves the
0N/A * name of the column using the model's <I>getColumnName(modelColumn)</I>
0N/A * method, and sets the both the header value and the identifier
0N/A * for this TableColumn accordingly.
0N/A * <p>
0N/A * The <I>modelColumn</I> is the index of the column in the model which
0N/A * will supply the data for this column in the table. This, like the
0N/A * <I>columnIdentifier</I> in previous releases, does not change as the
0N/A * columns are moved in the view.
0N/A * <p>
0N/A * For the rest of the JTable API, and all of its associated classes,
0N/A * columns are referred to in the co-ordinate system of the view, the
0N/A * index of the column in the model is kept inside the TableColumn
0N/A * and is used only to retrieve the information from the appropraite
0N/A * column in the model.
0N/A * <p>
0N/A *
0N/A * @param modelColumn The index of the column in the model
0N/A * @param width The new column's width. Or -1 to use
0N/A * the default width
0N/A * @param renderer The renderer used with the new column.
0N/A * Or null to use the default renderer.
0N/A * @param editor The editor used with the new column.
0N/A * Or null to use the default editor.
0N/A */
0N/A public TableColumn addColumn(int modelColumn, int width,
0N/A TableCellRenderer renderer,
0N/A TableCellEditor editor) {
3853N/A TableColumn newColumn = new TableColumn(
3853N/A modelColumn, width, renderer, editor);
0N/A addColumn(newColumn);
0N/A return newColumn;
0N/A }
0N/A
0N/A//
0N/A// Methods that had their arguments switched.
0N/A//
0N/A
0N/A// These won't work with the new table package.
0N/A
0N/A/*
0N/A public Object getValueAt(int columnIndex, int rowIndex) {
0N/A return super.getValueAt(rowIndex, columnIndex);
0N/A }
0N/A
0N/A public boolean isCellEditable(int columnIndex, int rowIndex) {
0N/A return super.isCellEditable(rowIndex, columnIndex);
0N/A }
0N/A
0N/A public void setValueAt(Object aValue, int columnIndex, int rowIndex) {
0N/A super.setValueAt(aValue, rowIndex, columnIndex);
0N/A }
0N/A*/
0N/A
0N/A public boolean editColumnRow(int columnIndex, int rowIndex) {
0N/A return super.editCellAt(rowIndex, columnIndex);
0N/A }
0N/A
0N/A public boolean editColumnRow(int columnIndex, int rowIndex, EventObject e){
0N/A return super.editCellAt(rowIndex, columnIndex, e);
0N/A }
0N/A
0N/A
0N/A} // End Of Class OldJTable