Source Code Cross Referenced for FeatureTableModelTest.java in  » GIS » GeoTools-2.4.1 » org » geotools » gui » swing » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » GeoTools 2.4.1 » org.geotools.gui.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2002-2006, Geotools Project Managment Committee (PMC)
005:         *
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation; either
009:         *    version 2.1 of the License, or (at your option) any later version.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         */
016:        package org.geotools.gui.swing;
017:
018:        // J2SE dependencies
019:        import java.util.logging.Logger;
020:        import javax.swing.JFrame;
021:        import javax.swing.JScrollPane;
022:        import javax.swing.JTable;
023:
024:        // JUnit dependencies
025:        import junit.framework.Test;
026:        import junit.framework.TestCase;
027:        import junit.framework.TestSuite;
028:
029:        // JTS dependencies
030:        import com.vividsolutions.jts.geom.Coordinate;
031:        import com.vividsolutions.jts.geom.Geometry;
032:        import com.vividsolutions.jts.geom.GeometryFactory;
033:        import com.vividsolutions.jts.geom.LinearRing;
034:        import com.vividsolutions.jts.geom.TopologyException;
035:
036:        // Geotools dependencies
037:        import org.geotools.util.logging.Logging;
038:        import org.geotools.data.memory.MemoryDataStore;
039:        import org.geotools.feature.AttributeType;
040:        import org.geotools.feature.AttributeTypeFactory;
041:        import org.geotools.feature.Feature;
042:        import org.geotools.feature.FeatureCollection;
043:        import org.geotools.feature.FeatureType;
044:        import org.geotools.feature.FeatureTypeFactory;
045:        import org.geotools.feature.IllegalAttributeException;
046:        import org.geotools.feature.SchemaException;
047:        import org.geotools.gui.swing.table.FeatureTableModel;
048:
049:        /**
050:         * Tests {@link FeatureTableModel}. The table will be shown only if the test is run from the
051:         * main method. Otherwise (i.e. if run from Maven), widgets are invisibles.
052:         *
053:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/widgets-swing/src/test/java/org/geotools/gui/swing/FeatureTableModelTest.java $
054:         * @version $Id: FeatureTableModelTest.java 27862 2007-11-12 19:51:19Z desruisseaux $
055:         * @author James Macgill, CCG
056:         */
057:        public class FeatureTableModelTest extends TestBase {
058:            /**
059:             * Standard logging instance.
060:             */
061:            protected static final Logger LOGGER = Logging
062:                    .getLogger("org.geotools.filter");
063:
064:            /**
065:             * The attribute factory instance.
066:             */
067:            protected static final AttributeTypeFactory attFactory = AttributeTypeFactory
068:                    .defaultInstance();
069:
070:            /**
071:             * Feature on which to perform tests.
072:             */
073:            private static Feature testFeatures[] = null;
074:
075:            /**
076:             * Feature type on which to perform tests.
077:             */
078:            private static FeatureType testSchema;
079:
080:            /**
081:             * Creates a test case.
082:             */
083:            public FeatureTableModelTest(final String testName) {
084:                super (testName);
085:            }
086:
087:            /**
088:             * Run the test case from the command line.
089:             */
090:            public static void main(final String[] args) {
091:                main(args, suite());
092:            }
093:
094:            /**
095:             * Returns the test suite.
096:             */
097:            public static Test suite() {
098:                TestSuite suite = new TestSuite(FeatureTableModelTest.class);
099:                return suite;
100:            }
101:
102:            /**
103:             * Display the table.
104:             */
105:            public void testDisplay() throws Exception {
106:                MemoryDataStore datastore = new MemoryDataStore();
107:                datastore.addFeature(testFeatures[0]);
108:                datastore.addFeature(testFeatures[1]);
109:
110:                String typeName = datastore.getTypeNames()[0];
111:                FeatureCollection table = datastore.getFeatureSource(typeName)
112:                        .getFeatures();
113:
114:                FeatureTableModel ftm = new FeatureTableModel();
115:                ftm.setFeatureCollection(table);
116:                JTable jtable = new JTable();
117:                jtable.setModel(ftm);
118:                JScrollPane scroll = new JScrollPane(jtable);
119:                show(scroll, "FeatureTableModel");
120:            }
121:
122:            /**
123:             * Sets up a schema and a test feature.
124:             *
125:             * @throws SchemaException If there is a problem setting up the schema.
126:             * @throws IllegalAttributeException If problem setting up the feature.
127:             */
128:            protected void setUp() throws SchemaException,
129:                    IllegalAttributeException, TopologyException {
130:                AttributeType geometryAttribute = attFactory.newAttributeType(
131:                        "testGeometry", Geometry.class);
132:                LOGGER.finest("created geometry attribute");
133:
134:                AttributeType booleanAttribute = attFactory.newAttributeType(
135:                        "testBoolean", Boolean.class);
136:                LOGGER.finest("created boolean attribute");
137:
138:                AttributeType charAttribute = attFactory.newAttributeType(
139:                        "testCharacter", Character.class);
140:                AttributeType byteAttribute = attFactory.newAttributeType(
141:                        "testByte", Byte.class);
142:                AttributeType shortAttribute = attFactory.newAttributeType(
143:                        "testShort", Short.class);
144:                AttributeType intAttribute = attFactory.newAttributeType(
145:                        "testInteger", Integer.class);
146:                AttributeType longAttribute = attFactory.newAttributeType(
147:                        "testLong", Long.class);
148:                AttributeType floatAttribute = attFactory.newAttributeType(
149:                        "testFloat", Float.class);
150:                AttributeType doubleAttribute = attFactory.newAttributeType(
151:                        "testDouble", Double.class);
152:                AttributeType stringAttribute = attFactory.newAttributeType(
153:                        "testString", String.class);
154:
155:                AttributeType[] types = { geometryAttribute, booleanAttribute,
156:                        charAttribute, byteAttribute, shortAttribute,
157:                        intAttribute, longAttribute, floatAttribute,
158:                        doubleAttribute, stringAttribute };
159:
160:                // Builds the schema
161:                testSchema = FeatureTypeFactory.newFeatureType(types,
162:                        "testSchema");
163:
164:                // Creates coordinates for a linestring
165:                Coordinate[] lineCoords = new Coordinate[3];
166:                lineCoords[0] = new Coordinate(1, 2);
167:                lineCoords[1] = new Coordinate(3, 4);
168:                lineCoords[2] = new Coordinate(5, 6);
169:
170:                // Creates coordinates for a polygon
171:                Coordinate[] polyCoords = new Coordinate[5];
172:                polyCoords[0] = new Coordinate(1, 1);
173:                polyCoords[1] = new Coordinate(2, 4);
174:                polyCoords[2] = new Coordinate(4, 4);
175:                polyCoords[3] = new Coordinate(8, 2);
176:                polyCoords[4] = new Coordinate(1, 1);
177:
178:                GeometryFactory fac = new GeometryFactory();
179:
180:                // Builds the test feature
181:                Object[] attributesA = new Object[10];
182:                attributesA[0] = fac.createLineString(lineCoords);
183:                attributesA[1] = new Boolean(true);
184:                attributesA[2] = new Character('t');
185:                attributesA[3] = new Byte("10");
186:                attributesA[4] = new Short("101");
187:                attributesA[5] = new Integer(1002);
188:                attributesA[6] = new Long(10003);
189:                attributesA[7] = new Float(10000.4);
190:                attributesA[8] = new Double(100000.5);
191:                attributesA[9] = "feature A";
192:
193:                Object[] attributesB = new Object[10];
194:                LinearRing ring = fac.createLinearRing(polyCoords);
195:                attributesB[0] = fac.createPolygon(ring, null);
196:                attributesB[1] = new Boolean(false);
197:                attributesB[2] = new Character('t');
198:                attributesB[3] = new Byte("20");
199:                attributesB[4] = new Short("201");
200:                attributesB[5] = new Integer(2002);
201:                attributesB[6] = new Long(20003);
202:                attributesB[7] = new Float(20000.4);
203:                attributesB[8] = new Double(200000.5);
204:                attributesB[9] = "feature B";
205:
206:                // Creates the feature itself
207:                testFeatures = new Feature[2];
208:                testFeatures[0] = testSchema.create(attributesA);
209:                testFeatures[1] = testSchema.create(attributesB);
210:                //_log.debug("...flat features created");
211:            }
212:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.