KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > contrib > view > SVTableModel


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18
19
20 package org.apache.poi.hssf.contrib.view;
21
22 import java.util.Iterator JavaDoc;
23 import javax.swing.table.*;
24
25 import org.apache.poi.hssf.usermodel.HSSFRow;
26 import org.apache.poi.hssf.usermodel.HSSFSheet;
27 import org.apache.poi.hssf.usermodel.HSSFCell;
28
29 /**
30  * Sheet Viewer Table Model - The model for the Sheet Viewer just overrides things.
31  * @author Andrew C. Oliver
32  */

33
34 public class SVTableModel extends AbstractTableModel {
35   private HSSFSheet st = null;
36   int maxcol = 0;
37
38   public SVTableModel(HSSFSheet st, int maxcol) {
39     this.st = st;
40     this.maxcol=maxcol;
41   }
42
43   public SVTableModel(HSSFSheet st) {
44     this.st = st;
45     Iterator JavaDoc i = st.rowIterator();
46
47     while (i.hasNext()) {
48       HSSFRow row = (HSSFRow)i.next();
49       if (maxcol < (row.getLastCellNum()+1)) {
50          this.maxcol = row.getLastCellNum();
51       }
52     }
53   }
54
55
56   public int getColumnCount() {
57     return this.maxcol+1;
58   }
59   public Object JavaDoc getValueAt(int row, int col) {
60     HSSFRow r = st.getRow(row);
61     HSSFCell c = null;
62     if (r != null) {
63       c = r.getCell((short)col);
64     }
65     return c;
66   }
67   public int getRowCount() {
68     return st.getLastRowNum() + 1;
69   }
70
71   public Class JavaDoc getColumnClass(int c) {
72     return HSSFCell.class;
73   }
74
75   public boolean isCellEditable(int rowIndex, int columnIndex) {
76     return true;
77   }
78
79   public void setValueAt(Object JavaDoc aValue, int rowIndex, int columnIndex) {
80     if (aValue != null)
81       System.out.println("SVTableModel.setValueAt. value type = "+aValue.getClass().getName());
82     else System.out.println("SVTableModel.setValueAt. value type = null");
83   }
84
85
86 }
87
Popular Tags