Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/hsqldb/util/GridSwing.java


1   /* Copyrights and Licenses
2    *
3    * This product includes Hypersonic SQL.
4    * Originally developed by Thomas Mueller and the Hypersonic SQL Group. 
5    *
6    * Copyright (c) 1995-2000 by the Hypersonic SQL Group. All rights reserved. 
7    * Redistribution and use in source and binary forms, with or without modification, are permitted
8    * provided that the following conditions are met: 
9    *     -  Redistributions of source code must retain the above copyright notice, this list of conditions
10   *         and the following disclaimer. 
11   *     -  Redistributions in binary form must reproduce the above copyright notice, this list of
12   *         conditions and the following disclaimer in the documentation and/or other materials
13   *         provided with the distribution. 
14   *     -  All advertising materials mentioning features or use of this software must display the
15   *        following acknowledgment: "This product includes Hypersonic SQL." 
16   *     -  Products derived from this software may not be called "Hypersonic SQL" nor may
17   *        "Hypersonic SQL" appear in their names without prior written permission of the
18   *         Hypersonic SQL Group. 
19   *     -  Redistributions of any form whatsoever must retain the following acknowledgment: "This
20   *          product includes Hypersonic SQL." 
21   * This software is provided "as is" and any expressed or implied warranties, including, but
22   * not limited to, the implied warranties of merchantability and fitness for a particular purpose are
23   * disclaimed. In no event shall the Hypersonic SQL Group or its contributors be liable for any
24   * direct, indirect, incidental, special, exemplary, or consequential damages (including, but
25   * not limited to, procurement of substitute goods or services; loss of use, data, or profits;
26   * or business interruption). However caused any on any theory of liability, whether in contract,
27   * strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this
28   * software, even if advised of the possibility of such damage. 
29   * This software consists of voluntary contributions made by many individuals on behalf of the
30   * Hypersonic SQL Group.
31   *
32   *
33   * For work added by the HSQL Development Group:
34   *
35   * Copyright (c) 2001-2002, The HSQL Development Group
36   * All rights reserved.
37   *
38   * Redistribution and use in source and binary forms, with or without
39   * modification, are permitted provided that the following conditions are met:
40   *
41   * Redistributions of source code must retain the above copyright notice, this
42   * list of conditions and the following disclaimer, including earlier
43   * license statements (above) and comply with all above license conditions.
44   *
45   * Redistributions in binary form must reproduce the above copyright notice,
46   * this list of conditions and the following disclaimer in the documentation
47   * and/or other materials provided with the distribution, including earlier
48   * license statements (above) and comply with all above license conditions.
49   *
50   * Neither the name of the HSQL Development Group nor the names of its
51   * contributors may be used to endorse or promote products derived from this
52   * software without specific prior written permission.
53   *
54   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
55   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57   * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, 
58   * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
59   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
60   * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
61   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
62   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
63   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
64   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65   */
66  
67  
68  package org.hsqldb.util;
69  
70  import java.util.Vector;
71  import javax.swing.table.*;
72  
73  // sqlbob@users 20020401 - patch 1.7.0 by sqlbob (RMP) - enhancements
74  
75  /** Simple table model to represent a grid of tuples.
76   *
77   * @version 1.7.0
78   */
79  class GridSwing extends AbstractTableModel {
80  
81      String[] headers;
82      Vector   rows;
83  
84      /**
85       * Default constructor.
86       */
87      public GridSwing() {
88  
89          super();
90  
91          headers = new String[0];    // initially empty
92          rows    = new Vector();     // initially empty
93      }
94  
95      /**
96       * Get the name for the specified column.
97       */
98      public String getColumnName(int i) {
99          return headers[i];
100     }
101 
102     /**
103      * Get the number of columns.
104      */
105     public int getColumnCount() {
106         return headers.length;
107     }
108 
109     /**
110      * Get the number of rows currently in the table.
111      */
112     public int getRowCount() {
113         return rows.size();
114     }
115 
116     /**
117      * Get the current column headings.
118      */
119     public String[] getHead() {
120         return headers;
121     }
122 
123     /**
124      * Get the current table data.
125      *  Each row is represented as a <code>String[]</code>
126      *  with a single non-null value in the 0-relative
127      *  column position.
128      *  <p>The first row is at offset 0, the nth row at offset n etc.
129      */
130     public Vector getData() {
131         return rows;
132     }
133 
134     /**
135      * Get the object at the specified cell location.
136      */
137     public Object getValueAt(int row, int col) {
138         return ((String[]) rows.elementAt(row))[col];
139     }
140 
141     /**
142      * Set the name of the column headings.
143      */
144     public void setHead(String[] h) {
145 
146         headers = new String[h.length];
147 
148         // System.arraycopy(h, 0, headers, 0, h.length);
149         for (int i = 0; i < h.length; i++) {
150             headers[i] = h[i];
151         }
152     }
153 
154     /**
155      * Append a tuple to the end of the table.
156      */
157     public void addRow(String[] r) {
158 
159         String[] row = new String[r.length];
160 
161         // System.arraycopy(r, 0, row, 0, r.length);
162         for (int i = 0; i < r.length; i++) {
163             row[i] = r[i];
164 
165             if (row[i] == null) {
166                 row[i] = "(null)";
167             }
168         }
169 
170         rows.addElement(row);
171     }
172 
173     /**
174      * Remove data from all cells in the table (without
175      *  affecting the current headings).
176      */
177     public void clear() {
178         rows.removeAllElements();
179     }
180 }