001: /*
002: * This file is part of the GeOxygene project source files.
003: *
004: * GeOxygene aims at providing an open framework which implements OGC/ISO specifications for
005: * the development and deployment of geographic (GIS) applications. It is a open source
006: * contribution of the COGIT laboratory at the Institut Géographique National (the French
007: * National Mapping Agency).
008: *
009: * See: http://oxygene-project.sourceforge.net
010: *
011: * Copyright (C) 2005 Institut Géographique National
012: *
013: * This library is free software; you can redistribute it and/or modify it under the terms
014: * of the GNU Lesser General Public License as published by the Free Software Foundation;
015: * either version 2.1 of the License, or any later version.
016: *
017: * This library is distributed in the hope that it will be useful, but WITHOUT ANY
018: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
019: * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
020: *
021: * You should have received a copy of the GNU Lesser General Public License along with
022: * this library (see file LICENSE if present); if not, write to the Free Software
023: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024: *
025: */
026:
027: package fr.ign.cogit.geoxygene.util.viewer;
028:
029: import java.awt.BorderLayout;
030: import java.util.Vector;
031:
032: import javax.swing.JFrame;
033: import javax.swing.JScrollPane;
034: import javax.swing.JTable;
035:
036: import uk.ac.leeds.ccg.dbffile.Dbf;
037: import uk.ac.leeds.ccg.geotools.DataSource;
038: import uk.ac.leeds.ccg.geotools.ShapefileReader;
039: import uk.ac.leeds.ccg.geotools.Theme;
040:
041: /**
042: *
043: * @author Thierry Badard & Arnaud Braun
044: * @version 1.0
045: *
046: */
047:
048: class ObjectViewerAttributesTableFrame extends JFrame {
049:
050: private static final String FRAME_TITLE = "GeOxygene Theme Values - ";
051:
052: private Theme theme;
053: private int nbFields;
054: private int nbRecords;
055: private Vector columnNames;
056: private Vector rowData;
057: private String title;
058: private DataSource dataSource;
059:
060: public ObjectViewerAttributesTableFrame(Theme t,
061: String dataSourceType, DataSource source) {
062: super ();
063:
064: theme = t;
065: dataSource = source;
066:
067: if (dataSourceType.equals(Utils.SHAPEFILE)) {
068: shapefile();
069: }
070:
071: else if (dataSourceType.equals(Utils.GEOXYGENE)) {
072: geoxygene();
073: }
074:
075: else {
076: System.out
077: .println(" ## SHOW ATTRIBUTES : NOT DEFINED FOR THIS KIND OF DATASOURCE ");
078: }
079:
080: // Title
081: this .setTitle(FRAME_TITLE + title);
082:
083: // Layout
084: this .getContentPane().setLayout(new BorderLayout());
085:
086: // Create/setup table
087: JTable table = new JTable(rowData, columnNames);
088:
089: // Place table in JScrollPane
090: JScrollPane scrollPane = new JScrollPane(table);
091:
092: // Add to Screen
093: this .getContentPane().add(scrollPane, BorderLayout.CENTER);
094:
095: }
096:
097: /** Fill vectors of attributes for a shapefile by reading directly dbf file (we do not load it into memory) */
098: public void shapefile() {
099:
100: String themeName = theme.getName();
101: title = themeName.substring(themeName.lastIndexOf("/") + 1);
102:
103: try {
104: // Transformer URL en File pour eviter le chargement en memoire du fichier Dbf
105: final Dbf themeDbf = ((ShapefileReader) dataSource).dbf;
106:
107: nbFields = themeDbf.getNumFields();
108: nbRecords = themeDbf.getLastRec();
109: StringBuffer fieldName;
110: Vector row;
111: columnNames = new Vector();
112: rowData = new Vector();
113:
114: for (int i = 0; i < nbFields; i++) {
115: fieldName = themeDbf.getFieldName(i);
116: columnNames.add(fieldName);
117: }
118:
119: for (int j = 0; j < nbRecords; j++) {
120: row = new Vector();
121: for (int i = 0; i < nbFields; i++) {
122: if (themeDbf.getFieldType(i) == 'N') {
123: row.add((themeDbf.getFloatCol(i, j, j + 1))[0]
124: .toString());
125: } else {
126: row.add((themeDbf.getStringCol(i, j, j + 1))[0]
127: .toString());
128: }
129: }
130: rowData.add(row);
131: }
132:
133: } catch (Exception e) {
134: System.err.println("Can not open the file: " + e);
135: }
136:
137: }
138:
139: /** Fill vectors of attributes for GeOxygene data */
140: public void geoxygene() {
141: title = theme.getName();
142: GeOxygeneReader geOxyRd = (GeOxygeneReader) dataSource;
143: Object[] result = geOxyRd.readData();
144: columnNames = (Vector) result[0];
145: rowData = (Vector) result[1];
146:
147: }
148:
149: }
|