01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: 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: package org.apache.poi.hssf.contrib.view;
19:
20: import java.util.Iterator;
21: import javax.swing.table.*;
22:
23: import org.apache.poi.hssf.usermodel.HSSFRow;
24: import org.apache.poi.hssf.usermodel.HSSFSheet;
25: import org.apache.poi.hssf.usermodel.HSSFCell;
26:
27: /**
28: * Sheet Viewer Table Model - The model for the Sheet Viewer just overrides things.
29: * @author Andrew C. Oliver
30: */
31:
32: public class SVTableModel extends AbstractTableModel {
33: private HSSFSheet st = null;
34: int maxcol = 0;
35:
36: public SVTableModel(HSSFSheet st, int maxcol) {
37: this .st = st;
38: this .maxcol = maxcol;
39: }
40:
41: public SVTableModel(HSSFSheet st) {
42: this .st = st;
43: Iterator i = st.rowIterator();
44:
45: while (i.hasNext()) {
46: HSSFRow row = (HSSFRow) i.next();
47: if (maxcol < (row.getLastCellNum() + 1)) {
48: this .maxcol = row.getLastCellNum();
49: }
50: }
51: }
52:
53: public int getColumnCount() {
54: return this .maxcol + 1;
55: }
56:
57: public Object getValueAt(int row, int col) {
58: HSSFRow r = st.getRow(row);
59: HSSFCell c = null;
60: if (r != null) {
61: c = r.getCell((short) col);
62: }
63: return c;
64: }
65:
66: public int getRowCount() {
67: return st.getLastRowNum() + 1;
68: }
69:
70: public Class getColumnClass(int c) {
71: return HSSFCell.class;
72: }
73:
74: public boolean isCellEditable(int rowIndex, int columnIndex) {
75: return true;
76: }
77:
78: public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
79: if (aValue != null)
80: System.out.println("SVTableModel.setValueAt. value type = "
81: + aValue.getClass().getName());
82: else
83: System.out
84: .println("SVTableModel.setValueAt. value type = null");
85: }
86:
87: }
|