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


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2007, Geotools Project Managment Committee (PMC)
005:         *    (C) 2007, Geomatys
006:         *
007:         *    This library is free software; you can redistribute it and/or
008:         *    modify it under the terms of the GNU Lesser General Public
009:         *    License as published by the Free Software Foundation; either
010:         *    version 2.1 of the License, or (at your option) any later version.
011:         *
012:         *    This library is distributed in the hope that it will be useful,
013:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         *    Lesser General Public License for more details.
016:         */
017:        package org.geotools.image.io.text;
018:
019:        import java.io.BufferedWriter;
020:        import java.io.IOException;
021:        import java.text.FieldPosition;
022:        import java.text.NumberFormat;
023:        import java.util.Locale;
024:        import javax.imageio.IIOImage;
025:        import javax.imageio.ImageWriter;
026:        import javax.imageio.ImageWriteParam;
027:        import javax.imageio.spi.ImageWriterSpi;
028:        import javax.imageio.metadata.IIOMetadata;
029:        import javax.media.jai.iterator.RectIter;
030:
031:        import org.geotools.image.ImageDimension;
032:        import org.geotools.resources.Utilities;
033:        import org.geotools.resources.i18n.Descriptions;
034:        import org.geotools.resources.i18n.DescriptionKeys;
035:
036:        /**
037:         * An image encoder for matrix of floating-point numbers.
038:         *
039:         * @since 2.4
040:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/coverageio/src/main/java/org/geotools/image/io/text/TextMatrixImageWriter.java $
041:         * @version $Id: TextMatrixImageWriter.java 27629 2007-10-26 09:59:20Z desruisseaux $
042:         * @author Martin Desruisseaux
043:         */
044:        public class TextMatrixImageWriter extends TextImageWriter {
045:            /**
046:             * Amount of spaces to put between columns.
047:             */
048:            private static final int SEPARATOR_WIDTH = 1;
049:
050:            /**
051:             * Constructs a new image writer.
052:             *
053:             * @param provider the provider that is invoking this constructor, or {@code null} if none.
054:             */
055:            protected TextMatrixImageWriter(final ImageWriterSpi provider) {
056:                super (provider);
057:            }
058:
059:            /**
060:             * Appends a complete image stream containing a single image.
061:             *
062:             * @param streamMetadata The stream metadata (ignored in default implementation).
063:             * @param image The image or raster to be written.
064:             * @param parameters The write parameters, or null if the whole image will be written.
065:             */
066:            public void write(final IIOMetadata streamMetadata,
067:                    final IIOImage image, final ImageWriteParam parameters)
068:                    throws IOException {
069:                processImageStarted();
070:                final BufferedWriter out = getWriter(parameters);
071:                final String lineSeparator = getLineSeparator(parameters);
072:                final NumberFormat format = createNumberFormat(image,
073:                        parameters);
074:                final FieldPosition pos = getExpectedFractionPosition(format);
075:                final int fractionWidth = pos.getEndIndex()
076:                        - pos.getBeginIndex();
077:                final int width = pos.getEndIndex() + SEPARATOR_WIDTH;
078:                final StringBuffer buffer = new StringBuffer(width);
079:                final RectIter iterator = createRectIter(image, parameters);
080:                final ImageDimension size = computeSize(image, parameters);
081:                final float progressScale = 100f / size.getNumSampleValues();
082:                int numSampleValues = 0, nextProgress = 0;
083:                if (!iterator.finishedBands())
084:                    do {
085:                        if (!iterator.finishedLines())
086:                            do {
087:                                if (numSampleValues >= nextProgress) {
088:                                    // Informs about progress only every 32 lines.
089:                                    processImageProgress(progressScale
090:                                            * numSampleValues);
091:                                    nextProgress = numSampleValues + 2000; // Reports after every 2000 numbers.
092:                                }
093:                                if (!iterator.finishedPixels())
094:                                    do {
095:                                        buffer.setLength(0);
096:                                        String n = format.format(
097:                                                iterator.getSampleDouble(),
098:                                                buffer, pos).toString();
099:                                        final int fractionOffset = Math
100:                                                .max(
101:                                                        0,
102:                                                        fractionWidth
103:                                                                - (pos
104:                                                                        .getEndIndex() - pos
105:                                                                        .getBeginIndex()));
106:                                        out.write(Utilities.spaces(width
107:                                                - n.length() - fractionOffset));
108:                                        out.write(n);
109:                                        out.write(Utilities
110:                                                .spaces(fractionOffset));
111:                                    } while (!iterator.nextPixelDone());
112:                                out.write(lineSeparator);
113:                                numSampleValues += size.width;
114:                                iterator.startPixels();
115:                            } while (!iterator.nextLineDone());
116:                        out.write(lineSeparator); // Separate bands by a blank line.
117:                        iterator.startLines();
118:                    } while (!iterator.nextBandDone());
119:                out.flush();
120:                processImageComplete();
121:            }
122:
123:            /**
124:             * Service provider interface (SPI) for {@link TextMatrixImageWriter}s.
125:             *
126:             * @since 2.4
127:             * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/coverageio/src/main/java/org/geotools/image/io/text/TextMatrixImageWriter.java $
128:             * @version $Id: TextMatrixImageWriter.java 27629 2007-10-26 09:59:20Z desruisseaux $
129:             * @author Martin Desruisseaux
130:             */
131:            public static class Spi extends TextImageWriter.Spi {
132:                /**
133:                 * The format names for the default {@link TextMatrixImageWriter} configuration.
134:                 */
135:                private static final String[] NAMES = { "matrix" };
136:
137:                /**
138:                 * The mime types for the default {@link TextMatrixImageWriter} configuration.
139:                 */
140:                private static final String[] MIME_TYPES = { "text/x-matrix" };
141:
142:                /**
143:                 * Constructs a default {@code TextMatrixImageWriter.Spi}. This constructor
144:                 * provides the following defaults in addition to the defaults defined in the
145:                 * {@linkplain TextImageWriter.Spi#Spi super-class constructor}:
146:                 *
147:                 * <ul>
148:                 *   <li>{@link #names}           = {@code "matrix"}</li>
149:                 *   <li>{@link #MIMETypes}       = {@code "text/x-matrix"}</li>
150:                 *   <li>{@link #pluginClassName} = {@code "org.geotools.image.io.text.TextMatrixImageWriter"}</li>
151:                 *   <li>{@link #vendorName}      = {@code "Geotools"}</li>
152:                 * </ul>
153:                 *
154:                 * For efficienty reasons, the above fields are initialized to shared arrays. Subclasses
155:                 * can assign new arrays, but should not modify the default array content.
156:                 */
157:                public Spi() {
158:                    names = NAMES;
159:                    MIMETypes = MIME_TYPES;
160:                    pluginClassName = "org.geotools.image.io.text.TextMatrixImageWriter";
161:                    vendorName = "Geotools";
162:                    version = "2.4";
163:                }
164:
165:                /**
166:                 * Returns a brief, human-readable description of this service provider
167:                 * and its associated implementation. The resulting string should be
168:                 * localized for the supplied locale, if possible.
169:                 *
170:                 * @param  locale A Locale for which the return value should be localized.
171:                 * @return A String containing a description of this service provider.
172:                 */
173:                public String getDescription(final Locale locale) {
174:                    return Descriptions.getResources(locale).getString(
175:                            DescriptionKeys.CODEC_MATRIX);
176:                }
177:
178:                /**
179:                 * Returns an instance of the {@code ImageWriter} implementation associated
180:                 * with this service provider.
181:                 *
182:                 * @param  extension An optional extension object, which may be null.
183:                 * @return An image writer instance.
184:                 * @throws IOException if the attempt to instantiate the writer fails.
185:                 */
186:                public ImageWriter createWriterInstance(final Object extension)
187:                        throws IOException {
188:                    return new TextMatrixImageWriter(this);
189:                }
190:            }
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.