Source Code Cross Referenced for Timing.java in  » GIS » GeoTools-2.4.1 » org » geotools » renderer » shape » 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.renderer.shape 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    Geotools2 - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2002, 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;
009:         *    version 2.1 of the License.
010:         *
011:         *    This library is distributed in the hryope 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:         */
017:        package org.geotools.renderer.shape;
018:
019:        import java.awt.Color;
020:        import java.awt.Frame;
021:        import java.awt.Graphics;
022:        import java.awt.Graphics2D;
023:        import java.awt.Image;
024:        import java.awt.Panel;
025:        import java.awt.Rectangle;
026:        import java.awt.RenderingHints;
027:        import java.awt.event.WindowAdapter;
028:        import java.awt.event.WindowEvent;
029:        import java.awt.image.BufferedImage;
030:        import java.awt.image.VolatileImage;
031:        import java.io.File;
032:        import java.io.FileWriter;
033:        import java.io.IOException;
034:        import java.io.PrintWriter;
035:        import java.net.URL;
036:        import java.util.HashMap;
037:        import java.util.Map;
038:
039:        import org.geotools.data.shapefile.Lock;
040:        import org.geotools.data.shapefile.ShapefileDataStore;
041:        import org.geotools.data.shapefile.ShapefileDataStoreFactory;
042:        import org.geotools.data.shapefile.indexed.IndexedShapefileDataStore;
043:        import org.geotools.data.shapefile.indexed.IndexedShapefileDataStoreFactory;
044:        import org.geotools.data.shapefile.indexed.ShapeFileIndexer;
045:        import org.geotools.filter.AttributeExpression;
046:        import org.geotools.filter.CompareFilter;
047:        import org.geotools.filter.Filter;
048:        import org.geotools.filter.FilterFactory;
049:        import org.geotools.filter.FilterFactoryFinder;
050:        import org.geotools.map.DefaultMapContext;
051:        import org.geotools.map.MapContext;
052:        import org.geotools.renderer.lite.StreamingRenderer;
053:        import org.geotools.resources.TestData;
054:        import org.geotools.styling.FeatureTypeStyle;
055:        import org.geotools.styling.Fill;
056:        import org.geotools.styling.Font;
057:        import org.geotools.styling.LineSymbolizer;
058:        import org.geotools.styling.PointSymbolizer;
059:        import org.geotools.styling.PolygonSymbolizer;
060:        import org.geotools.styling.Rule;
061:        import org.geotools.styling.Stroke;
062:        import org.geotools.styling.Style;
063:        import org.geotools.styling.StyleBuilder;
064:        import org.geotools.styling.StyleFactory;
065:        import org.geotools.styling.StyleFactoryFinder;
066:        import org.geotools.styling.Symbolizer;
067:        import org.geotools.styling.TextSymbolizer;
068:
069:        import com.vividsolutions.jts.geom.Envelope;
070:
071:        /**
072:         * @TODO class description
073:         * 
074:         * @author jeichar
075:         * @since 2.1.x
076:         * @source $URL:
077:         *         http://svn.geotools.org/geotools/branches/2.2.x/ext/shaperenderer/perf/org/geotools/renderer/shape/Timing.java $
078:         */
079:        public class Timing {
080:
081:            private static final FilterFactory filterFactory = FilterFactoryFinder
082:                    .createFilterFactory();
083:
084:            private static final int POINTS = 0;
085:
086:            private static final int LINES = 1;
087:
088:            private static final int POLYGONS = 2;
089:
090:            private static boolean ALL_DATA = true;
091:
092:            private static boolean DISPLAY = false;
093:
094:            private static boolean ANTI_ALIASING = false;
095:
096:            private static boolean RUN_SHAPE = true;
097:
098:            private static boolean RUN_LITE = true;
099:
100:            private static boolean RUN_TINY = false;
101:
102:            private static boolean ACCURATE = true;
103:
104:            private static boolean NO_REPROJECTION = true;
105:
106:            private static boolean FILTER = false;
107:
108:            private static boolean CPU_PROFILE = false;
109:
110:            private static int SHAPE_TYPE = POLYGONS;
111:
112:            private static boolean LABELING = false;
113:
114:            private static boolean QUADTREE = false;
115:
116:            private static int CYCLES = 4;
117:
118:            private String getTestName() {
119:                String testName = "";
120:                if (SHAPE_TYPE == LINES) {
121:                    testName += LINES_TYPE_NAME;
122:                } else if (SHAPE_TYPE == POLYGONS) {
123:                    testName += POLY_TYPE_NAME;
124:                } else if (SHAPE_TYPE == POINTS) {
125:                    testName += POINT_TYPE_NAME;
126:                }
127:                if (ALL_DATA) {
128:                    testName += "_ALL";
129:                } else {
130:                    testName += "_ZOOM";
131:                }
132:                if (ACCURATE) {
133:                    testName += "_ACCURATE";
134:                } else {
135:                    testName += "_INACCURATE";
136:                }
137:                if (NO_REPROJECTION) {
138:                    testName += "_NO_REPROJECTION";
139:                } else {
140:                    testName += "_REPROJECTED";
141:                }
142:                if (FILTER) {
143:                    testName += "_FILTER";
144:                } else {
145:                    testName += "_NO_FILTER";
146:                }
147:                if (CPU_PROFILE) {
148:                    testName += "_PROFILE";
149:                }
150:                if (QUADTREE) {
151:                    testName += "_QUADTREE";
152:                }
153:                return testName;
154:            }
155:
156:            public final static FileWriter out;
157:
158:            static {
159:                FileWriter tmp;
160:                try {
161:                    String homePath = System.getProperty("user.home");
162:                    File results = new File(homePath, "TimingResults.txt");
163:                    tmp = new FileWriter(results, true);
164:                } catch (IOException e) {
165:                    tmp = null;
166:                    e.printStackTrace();
167:                }
168:                out = tmp;
169:            }
170:
171:            static Style createLineStyle() throws Exception {
172:                return createLineStyle(null);
173:            }
174:
175:            static Style createLineStyle(String typeName) throws Exception {
176:                if (typeName == null)
177:                    typeName = LINES_TYPE_NAME;
178:                StyleFactory sFac = StyleFactoryFinder.createStyleFactory();
179:                // The following is complex, and should be built from
180:
181:                LineSymbolizer linesym = sFac.createLineSymbolizer();
182:                Stroke myStroke = sFac.getDefaultStroke();
183:                myStroke.setColor(filterFactory
184:                        .createLiteralExpression("#0000ff"));
185:                myStroke.setWidth(filterFactory
186:                        .createLiteralExpression(new Integer(2)));
187:                linesym.setStroke(myStroke);
188:
189:                Rule rule2 = sFac.createRule();
190:                rule2.setSymbolizers(new Symbolizer[] { linesym });
191:                if (FILTER) {
192:                    AttributeExpression exp = filterFactory
193:                            .createAttributeExpression("STREETS");
194:                    CompareFilter filter = filterFactory
195:                            .createCompareFilter(Filter.COMPARE_NOT_EQUALS);
196:                    filter.addLeftValue(exp);
197:                    filter.addRightValue(filterFactory
198:                            .createLiteralExpression("blah"));
199:                    rule2.setFilter(filter);
200:                }
201:                if (LABELING) {
202:                    StyleBuilder builder = new StyleBuilder();
203:                    TextSymbolizer textsym = sFac.createTextSymbolizer();
204:                    textsym.setFill(sFac.getDefaultFill());
205:                    textsym.setGeometryPropertyName("the_geom");
206:                    textsym.setLabel(filterFactory
207:                            .createLiteralExpression(LINES_LABEL));
208:                    textsym.setFonts(new Font[] { builder
209:                            .createFont(new java.awt.Font("Arial",
210:                                    java.awt.Font.PLAIN, 10)) });
211:                    rule2.setSymbolizers(new Symbolizer[] { linesym, textsym });
212:                }
213:                FeatureTypeStyle fts2 = sFac.createFeatureTypeStyle();
214:                fts2.setRules(new Rule[] { rule2 });
215:                fts2.setFeatureTypeName(typeName);
216:
217:                Style style = sFac.createStyle();
218:                style.setFeatureTypeStyles(new FeatureTypeStyle[] { fts2 });
219:
220:                return style;
221:            }
222:
223:            static Style createPolyStyle() throws Exception {
224:                return createPolyStyle(null);
225:            }
226:
227:            static Style createPolyStyle(String typeName) throws Exception {
228:                if (typeName == null)
229:                    typeName = POLY_TYPE_NAME;
230:                StyleFactory sFac = StyleFactoryFinder.createStyleFactory();
231:                // The following is complex, and should be built from
232:                Stroke myStroke = sFac.getDefaultStroke();
233:                myStroke.setColor(filterFactory
234:                        .createLiteralExpression("#0000ff"));
235:                myStroke.setWidth(filterFactory
236:                        .createLiteralExpression(new Integer(2)));
237:                Fill myFill = sFac.getDefaultFill();
238:                PolygonSymbolizer lineSym = sFac.createPolygonSymbolizer(
239:                        myStroke, myFill, "the_geom");
240:
241:                Rule rule2 = sFac.createRule();
242:                rule2.setSymbolizers(new Symbolizer[] { lineSym });
243:                if (FILTER) {
244:                    AttributeExpression exp = filterFactory
245:                            .createAttributeExpression(POLY_LABEL);
246:                    CompareFilter filter = filterFactory
247:                            .createCompareFilter(Filter.COMPARE_NOT_EQUALS);
248:                    filter.addLeftValue(exp);
249:                    filter.addRightValue(filterFactory
250:                            .createLiteralExpression("blah"));
251:                    rule2.setFilter(filter);
252:                }
253:                if (LABELING) {
254:                    StyleBuilder builder = new StyleBuilder();
255:
256:                    TextSymbolizer textsym = sFac.createTextSymbolizer();
257:                    textsym.setFill(sFac.createFill(filterFactory
258:                            .createLiteralExpression("#000000")));
259:                    textsym.setGeometryPropertyName("the_geom");
260:                    textsym.setLabel(filterFactory
261:                            .createAttributeExpression(POLY_LABEL));
262:                    textsym.setFonts(new Font[] { builder
263:                            .createFont(new java.awt.Font("Arial",
264:                                    java.awt.Font.PLAIN, 10)) });
265:                    rule2.setSymbolizers(new Symbolizer[] { lineSym, textsym });
266:                }
267:
268:                FeatureTypeStyle fts2 = sFac.createFeatureTypeStyle();
269:                fts2.setRules(new Rule[] { rule2 });
270:                fts2.setFeatureTypeName(typeName);
271:
272:                Style style = sFac.createStyle();
273:                style.setFeatureTypeStyles(new FeatureTypeStyle[] { fts2 });
274:
275:                return style;
276:            }
277:
278:            static Style createPointStyle() throws Exception {
279:                return createPointStyle(null);
280:            }
281:
282:            static Style createPointStyle(String typeName) throws Exception {
283:                if (typeName == null)
284:                    typeName = POINT_TYPE_NAME;
285:                StyleFactory sFac = StyleFactoryFinder.createStyleFactory();
286:                StyleBuilder builder = new StyleBuilder(sFac);
287:                // The following is complex, and should be built from
288:                Stroke myStroke = sFac.getDefaultStroke();
289:                myStroke.setColor(filterFactory
290:                        .createLiteralExpression("#0000ff"));
291:                myStroke.setWidth(filterFactory
292:                        .createLiteralExpression(new Integer(2)));
293:                PointSymbolizer point = sFac.createPointSymbolizer(builder
294:                        .createGraphic(), "the_geom");
295:
296:                Rule rule2 = sFac.createRule();
297:                rule2.setSymbolizers(new Symbolizer[] { point });
298:                if (FILTER) {
299:                    AttributeExpression exp = filterFactory
300:                            .createAttributeExpression(POINT_LABEL);
301:                    CompareFilter filter = filterFactory
302:                            .createCompareFilter(Filter.COMPARE_NOT_EQUALS);
303:                    filter.addLeftValue(exp);
304:                    filter.addRightValue(filterFactory
305:                            .createLiteralExpression("blah"));
306:                    rule2.setFilter(filter);
307:                }
308:                if (LABELING) {
309:
310:                    TextSymbolizer textsym = sFac.createTextSymbolizer();
311:                    textsym.setFill(sFac.createFill(filterFactory
312:                            .createLiteralExpression("#000000")));
313:                    textsym.setGeometryPropertyName("the_geom");
314:                    textsym.setLabel(filterFactory
315:                            .createAttributeExpression(POINT_LABEL));
316:                    textsym.setFonts(new Font[] { builder
317:                            .createFont(new java.awt.Font("Arial",
318:                                    java.awt.Font.PLAIN, 10)) });
319:                    rule2.setSymbolizers(new Symbolizer[] { point, textsym });
320:                }
321:
322:                FeatureTypeStyle fts2 = sFac.createFeatureTypeStyle();
323:                fts2.setRules(new Rule[] { rule2 });
324:                fts2.setFeatureTypeName(typeName);
325:
326:                Style style = sFac.createStyle();
327:                style.setFeatureTypeStyles(new FeatureTypeStyle[] { fts2 });
328:
329:                return style;
330:            }
331:
332:            public static void main(String[] args) throws Exception {
333:                try {
334:                    DISPLAY = false;
335:                    RUN_LITE = true;
336:                    RUN_SHAPE = true;
337:                    RUN_TINY = false;
338:                    ACCURATE = true;
339:
340:                    out.write("Battery 1\n");
341:                    ALL_DATA = true;
342:                    ANTI_ALIASING = true;
343:                    FILTER = false;
344:                    LABELING = false;
345:                    NO_REPROJECTION = true;
346:                    QUADTREE = false;
347:                    runLineTest(5);
348:                    runPolygonTest(8);
349:                    runPointTest(20);
350:
351:                    out.write("Battery 2\n");
352:
353:                    QUADTREE = true;
354:                    runLineTest(5);
355:                    runPolygonTest(8);
356:                    runPointTest(20);
357:                    out.write("Battery 3\n");
358:
359:                    ALL_DATA = false;
360:                    QUADTREE = false;
361:                    runLineTest(5);
362:                    runPolygonTest(8);
363:                    runPointTest(20);
364:                    out.write("Battery 4\n");
365:
366:                    QUADTREE = true;
367:                    runLineTest(5);
368:                    runPolygonTest(8);
369:                    runPointTest(20);
370:                    out.write("Battery 5\n");
371:
372:                    ALL_DATA = true;
373:                    QUADTREE = true;
374:                    NO_REPROJECTION = false;
375:                    runLineTest(5);
376:                    runPolygonTest(8);
377:                    runPointTest(20);
378:                    out.write("Battery 6\n");
379:
380:                    NO_REPROJECTION = true;
381:                    LABELING = true;
382:                    runLineTest(5);
383:                    runPolygonTest(8);
384:                    runPointTest(20);
385:
386:                } catch (Throwable e) {
387:                    e.printStackTrace(new PrintWriter(out));
388:                } finally {
389:
390:                    if (out != null && !DISPLAY && !CPU_PROFILE)
391:                        out.close();
392:
393:                    System.exit(0);
394:                }
395:            }
396:
397:            private static void runLineTest(int cycles) throws Exception,
398:                    IOException {
399:                CYCLES = cycles;
400:                SHAPE_TYPE = LINES;
401:                runSuite();
402:            }
403:
404:            private static void runPolygonTest(int cycles) throws Exception,
405:                    IOException {
406:                CYCLES = cycles;
407:                SHAPE_TYPE = POLYGONS;
408:                runSuite();
409:            }
410:
411:            private static void runPointTest(int cycles) throws Exception,
412:                    IOException {
413:                CYCLES = cycles;
414:                SHAPE_TYPE = POINTS;
415:                runSuite();
416:            }
417:
418:            private static void runSuite() throws Exception, IOException {
419:                Timing t = new Timing();
420:                if (RUN_SHAPE)
421:                    t.runShapeRendererTest();
422:
423:                if (RUN_TINY)
424:                    t.runTinyTest();
425:
426:                if (RUN_LITE)
427:                    t.runLiteRendererTest();
428:
429:            }
430:
431:            private void runShapeRendererTest() throws Exception {
432:                MapContext context = getMapContext();
433:                ShapefileRenderer renderer = new ShapefileRenderer(context);
434:
435:                if (ANTI_ALIASING) {
436:                    RenderingHints hints = new RenderingHints(
437:                            RenderingHints.KEY_ANTIALIASING,
438:                            RenderingHints.VALUE_ANTIALIAS_ON);
439:                    renderer.setJava2DHints(hints);
440:                }
441:
442:                Image image;
443:                Graphics2D g;
444:
445:                image = createImage();
446:                g = createGraphics(image);
447:
448:                g.setColor(Color.white);
449:                g.fillRect(0, 0, w, h);
450:
451:                Envelope bounds = context.getLayerBounds();
452:                if (!ALL_DATA)
453:                    bounds = new Envelope(bounds.getMinX() + bounds.getWidth()
454:                            / 4, bounds.getMaxX() - bounds.getWidth() / 4,
455:                            bounds.getMinY() + bounds.getHeight() / 4, bounds
456:                                    .getMaxY()
457:                                    - bounds.getHeight() / 4);
458:
459:                if (ACCURATE)
460:                    renderer.paint(g, new Rectangle(w, h), bounds);
461:                long start = System.currentTimeMillis();
462:
463:                renderer.paint(g, new Rectangle(w, h), bounds);
464:                if (ACCURATE) {
465:                    for (int i = 0; i < CYCLES; i++)
466:                        renderer.paint(g, new Rectangle(w, h), bounds);
467:                }
468:
469:                long end = System.currentTimeMillis();
470:                if (ACCURATE) {
471:                    if (out != null) {
472:                        out.write("shape " + getTestName() + "="
473:                                + (end - start) / 3 + "\n");
474:                    }
475:                } else if (out != null) {
476:                    out.write("shape " + getTestName() + "=" + (end - start)
477:                            + "\n");
478:                }
479:
480:                if (DISPLAY) {
481:                    display("shape", image, w, h);
482:                }
483:            }
484:
485:            private Graphics2D createGraphics(Image image) {
486:                Graphics2D g;
487:                if (image instanceof  VolatileImage) {
488:                    g = ((VolatileImage) image).createGraphics();
489:                } else {
490:                    g = ((BufferedImage) image).createGraphics();
491:                }
492:                return g;
493:            }
494:
495:            private Image createImage() {
496:                Image image;
497:                image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
498:                return image;
499:            }
500:
501:            private MapContext getMapContext() throws Exception {
502:                URL url;
503:                if (SHAPE_TYPE == LINES) {
504:                    url = new URL(LINES_FILE);
505:                } else if (SHAPE_TYPE == POLYGONS) {
506:                    url = new URL(POLY_FILE);
507:                } else {
508:                    url = new URL(POINT_FILE);
509:                }
510:
511:                if (!QUADTREE) {
512:                    String s = url.getPath();
513:                    s = s.substring(0, s.lastIndexOf("."));
514:                    File file = new File(s + ".qix");
515:                    if (file.exists()) {
516:                        file.delete();
517:                    }
518:                }
519:
520:                IndexedShapefileDataStoreFactory fac = new IndexedShapefileDataStoreFactory();
521:                IndexedShapefileDataStore store;
522:                Map params = new HashMap();
523:                params.put(IndexedShapefileDataStoreFactory.URLP.key, url);
524:                params
525:                        .put(
526:                                IndexedShapefileDataStoreFactory.CREATE_SPATIAL_INDEX.key,
527:                                new Boolean(false));
528:                if (QUADTREE) {
529:                    params
530:                            .put(
531:                                    IndexedShapefileDataStoreFactory.CREATE_SPATIAL_INDEX.key,
532:                                    new Boolean(true));
533:                }
534:                store = (IndexedShapefileDataStore) fac.createDataStore(params);
535:                if (QUADTREE)
536:                    store.buildQuadTree(0);
537:
538:                DefaultMapContext context = new DefaultMapContext();
539:                if (SHAPE_TYPE == LINES)
540:                    context.addLayer(store.getFeatureSource(),
541:                            createLineStyle());
542:                else if (SHAPE_TYPE == POLYGONS)
543:                    context.addLayer(store.getFeatureSource(),
544:                            createPolyStyle());
545:                else
546:                    context.addLayer(store.getFeatureSource(),
547:                            createPointStyle());
548:
549:                if (NO_REPROJECTION)
550:                    context.setAreaOfInterest(new Envelope(), store.getSchema()
551:                            .getDefaultGeometry().getCoordinateSystem());
552:                return context;
553:            }
554:
555:            private void runTinyTest() throws Exception {
556:                ShapefileDataStoreFactory fac = new ShapefileDataStoreFactory();
557:                ShapefileDataStore store = (ShapefileDataStore) fac
558:                        .createDataStore(TestData.getResource(Timing.class,
559:                                "theme1.shp"));
560:                DefaultMapContext context = new DefaultMapContext();
561:                context.addLayer(store.getFeatureSource(),
562:                        createLineStyle("theme1"));
563:                if (NO_REPROJECTION)
564:                    context.setAreaOfInterest(new Envelope(), store.getSchema()
565:                            .getDefaultGeometry().getCoordinateSystem());
566:                ShapefileRenderer renderer = new ShapefileRenderer(context);
567:                if (ANTI_ALIASING) {
568:                    RenderingHints hints = new RenderingHints(
569:                            RenderingHints.KEY_ANTIALIASING,
570:                            RenderingHints.VALUE_ANTIALIAS_ON);
571:                    renderer.setJava2DHints(hints);
572:                }
573:                Image image;
574:                Graphics2D g;
575:
576:                image = createImage();
577:                g = createGraphics(image);
578:
579:                g.setColor(Color.white);
580:                g.fillRect(0, 0, w, h);
581:
582:                Envelope bounds = new Envelope(-7.105552354197932,
583:                        8.20555235419793, -3.239388966356115, 4.191388966388683);
584:
585:                if (!ALL_DATA)
586:                    bounds = new Envelope(bounds.getMinX() + bounds.getWidth()
587:                            / 4, bounds.getMaxX() - bounds.getWidth() / 4,
588:                            bounds.getMinY() + bounds.getHeight() / 4, bounds
589:                                    .getMaxY()
590:                                    - bounds.getHeight() / 4);
591:
592:                if (ACCURATE)
593:                    renderer.paint(g, new Rectangle(w, h), bounds);
594:                long start = System.currentTimeMillis();
595:
596:                renderer.paint(g, new Rectangle(w, h), bounds);
597:                if (ACCURATE) {
598:                    for (int i = 0; i < CYCLES; i++)
599:                        renderer.paint(g, new Rectangle(w, h), bounds);
600:                }
601:
602:                long end = System.currentTimeMillis();
603:                if (ACCURATE) {
604:                    out.write("tiny " + getTestName() + "=" + (end - start) / 3
605:                            + "\n");
606:                } else
607:                    out.write("tiny " + getTestName() + "=" + (end - start)
608:                            + "\n");
609:                if (DISPLAY)
610:                    display("tiny", image, w, h);
611:
612:            }
613:
614:            private void runLiteRendererTest() throws Exception {
615:
616:                MapContext context = getMapContext();
617:                StreamingRenderer renderer = new StreamingRenderer();
618:                renderer.setContext(context);
619:                Map basichints = new HashMap();
620:                basichints
621:                        .put("optimizedDataLoadingEnabled", new Boolean(true));
622:                renderer.setRendererHints(basichints);
623:                if (ANTI_ALIASING) {
624:                    RenderingHints hints = new RenderingHints(
625:                            RenderingHints.KEY_ANTIALIASING,
626:                            RenderingHints.VALUE_ANTIALIAS_ON);
627:                    renderer.setJava2DHints(hints);
628:                }
629:
630:                Image image;
631:                Graphics2D g;
632:
633:                image = createImage();
634:                g = createGraphics(image);
635:
636:                g.setColor(Color.white);
637:                g.fillRect(0, 0, w, h);
638:                Envelope bounds = context.getLayerBounds();
639:
640:                if (!ALL_DATA)
641:                    bounds = new Envelope(bounds.getMinX() + bounds.getWidth()
642:                            / 4, bounds.getMaxX() - bounds.getWidth() / 4,
643:                            bounds.getMinY() + bounds.getHeight() / 4, bounds
644:                                    .getMaxY()
645:                                    - bounds.getHeight() / 4);
646:
647:                if (ACCURATE)
648:                    renderer.paint(g, new Rectangle(w, h), bounds);
649:                long start = System.currentTimeMillis();
650:
651:                renderer.paint(g, new Rectangle(w, h), bounds);
652:                if (ACCURATE) {
653:                    for (int i = 0; i < CYCLES; i++)
654:                        renderer.paint(g, new Rectangle(w, h), bounds);
655:                }
656:                long end = System.currentTimeMillis();
657:                if (ACCURATE) {
658:                    if (out != null)
659:                        out.write("lite " + getTestName() + "=" + (end - start)
660:                                / 3 + "\n");
661:                } else if (out != null)
662:                    out.write("lite " + getTestName() + "=" + (end - start)
663:                            + "\n");
664:                if (DISPLAY)
665:                    display("lite", image, w, h);
666:
667:            }
668:
669:            public static Frame display(String testName, final Image image,
670:                    int w, int h) {
671:                Frame frame = new Frame(testName);
672:                frame.addWindowListener(new WindowAdapter() {
673:                    public void windowClosing(WindowEvent e) {
674:                        e.getWindow().dispose();
675:                    }
676:                });
677:
678:                Panel p = new Panel() {
679:                    /** <code>serialVersionUID</code> field */
680:                    private static final long serialVersionUID = 1L;
681:
682:                    public void paint(Graphics g) {
683:                        g.drawImage(image, 0, 0, this );
684:                    }
685:                };
686:                frame.add(p);
687:                frame.setSize(w, h);
688:                frame.setVisible(true);
689:                return frame;
690:            }
691:
692:            private static String LINES_WORK_FILE = "file:/Users/Jesse/dev/Data/uDigData/bc_roads.shp";
693:
694:            private static String LINES_WORK_TYPE_NAME = "bc_roads";
695:
696:            private static String LINES_WORK_LABEL = "STREET";
697:
698:            private static String LINES_FILE = LINES_WORK_FILE;
699:
700:            private static String LINES_TYPE_NAME = LINES_WORK_TYPE_NAME;
701:
702:            private static String LINES_LABEL = LINES_WORK_LABEL;
703:
704:            private static String POLY_FILE = "file:/Users/Jesse/dev/Data/uDigData/bc_parks_2001.shp";
705:
706:            private static String POLY_TYPE_NAME = "bc_parks_2001";
707:
708:            private static String POLY_LABEL = "PA_NAME";
709:
710:            private static String POINT_FILE = "file:/Users/Jesse/dev/Data/uDigData/bc_pubs.shp";
711:
712:            private static String POINT_TYPE_NAME = "bc_pubs";
713:
714:            private static String POINT_LABEL = "NAME";
715:
716:            int w = 512, h = 512;
717:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.