001    /* EVolve - an Extensible Software Visualization Framework
002     * Copyright (C) 2001-2002 Qin Wang
003     *
004     * This library is free software; you can redistribute it and/or
005     * modify it under the terms of the GNU Library General Public
006     * License as published by the Free Software Foundation; either
007     * version 2 of the License, or (at your option) any later version.
008     *
009     * This library is distributed in the hope that it will be useful,
010     * but WITHOUT ANY WARRANTY; without even the implied warranty of
011     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012     * Library General Public License for more details.
013     *
014     * You should have received a copy of the GNU Library General Public
015     * License along with this library; if not, write to the
016     * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017     * Boston, MA 02111-1307, USA.
018     */
019    
020    /*
021     * EVolve is distributed at http://www.sable.mcgill.ca/EVolve/
022     */
023    
024    package EVolve.visualization;
025    
026    import javax.swing.*;
027    import javax.swing.table.*;
028    
029    /**
030     * Model of a two-column table.
031     */
032    public class TableVizModel extends AbstractTableModel {
033        private String[] name; // names of the columns
034        private String[] left; // left column
035        private int[] right; // right column
036    
037        /**
038         * Creates a table model.
039         */
040        public TableVizModel() {
041            name = new String[2];
042            name[0] = "Left Column";
043            name[1] = "Right Column";
044            left = new String[0];
045            right = new int[0];
046        }
047    
048        /**
049         * Gets the number of columns.
050         *
051         * @return  number of columns
052         */
053        public int getColumnCount() {
054            return name.length;
055        }
056    
057        /**
058         * Gets the name of a column
059         *
060         * @param   col the column
061         * @return  name of the column
062         */
063        public String getColumnName(int col) {
064            return name[col];
065        }
066    
067        /**
068         * Gets the value of the table.
069         *
070         * @param   row the row
071         * @param   col the column
072         * @return  the value
073         */
074        public Object getValueAt(int row, int col) {
075            if (col == 0) {
076                return left[row];
077            } else {
078                return new Integer(right[row]);
079            }
080        }
081    
082        /**
083         * Gets the number of rows.
084         *
085         * @return  number of rows
086         */
087        public int getRowCount() {
088            return left.length;
089        }
090    
091        /**
092         * Whether the cell is editable.
093         *
094         * @param   row the row
095         * @param   col the column
096         * @return  false, not editable
097         */
098        public boolean isCellEditable(int row, int col) {
099            return false;
100        }
101    
102        /**
103         * Sets the names of the columns.
104         *
105         * @param   nameLeft name of the left column
106         * @param   nameRight name of the right column
107         */
108        public void setName(String nameLeft, String nameRight) {
109            name[0] = nameLeft;
110            name[1] = nameRight;
111        }
112    
113        /**
114         * Sets the value of the table.
115         *
116         * @param   left the left column
117         * @param   right the right column
118         */
119        public void setValue(String[] left, int[] right) {
120            this.left = left;
121            this.right = right;
122        }
123    }