Source Code Cross Referenced for MapImageFormatChooser.java in  » GIS » openjump » com » vividsolutions » wms » 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 » openjump » com.vividsolutions.wms 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:
002:        /*
003:         * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI 
004:         * for visualizing and manipulating spatial features with geometry and attributes.
005:         *
006:         * Copyright (C) 2003 Vivid Solutions
007:         * 
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public License
010:         * as published by the Free Software Foundation; either version 2
011:         * of the License, or (at your option) any later version.
012:         * 
013:         * This program is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU General Public License for more details.
017:         * 
018:         * You should have received a copy of the GNU General Public License
019:         * along with this program; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
021:         * 
022:         * For more information, contact:
023:         *
024:         * Vivid Solutions
025:         * Suite #1A
026:         * 2328 Government Street
027:         * Victoria BC  V8T 5G5
028:         * Canada
029:         *
030:         * (250)385-6040
031:         * www.vividsolutions.com
032:         */
033:
034:        package com.vividsolutions.wms;
035:
036:        import java.util.Arrays;
037:
038:        /**
039:         * A Utility class to select the optimal Map Format based on some preferences.
040:         * @author  Chris Hodgson chodgson@refractions.net
041:         */
042:        public class MapImageFormatChooser {
043:
044:            private boolean transparencyRequired;
045:            private boolean useLossy;
046:            //[UT]
047:            public static final String[][] IMAGE_FORMATS = {
048:                    { "GIF", "PNG", "JPEG" }, // for WMS 1.0.0
049:                    { "image/gif", "image/png", "image/jpeg" } // for WMS 1.1.1
050:            };
051:
052:            // set image formats to the default WMS (1.0.0)
053:            private String[] imageFormats = IMAGE_FORMATS[0];
054:
055:            /** 
056:             * Creates a new instance of MapImageFormatChooser.
057:             */
058:            public MapImageFormatChooser() {
059:                //[UT]
060:                this (WMService.WMS_1_0_0); // 1.0.0 is the default WMS, anyway...
061:            }
062:
063:            /** 
064:             * Creates a new instance of MapImageFormatChooser.
065:             */
066:            public MapImageFormatChooser(String wmsVersion) {
067:                this .transparencyRequired = false;
068:                this .useLossy = false;
069:                if (WMService.WMS_1_1_1.equals(wmsVersion)
070:                        || WMService.WMS_1_1_0.equals(wmsVersion)) {
071:                    imageFormats = IMAGE_FORMATS[1];
072:                }
073:            }
074:
075:            /**
076:             * Returns true if the specified format is known by the MapFormatChooser, false 
077:             * otherwise. The MapFormatChooser can only reliably select between formats 
078:             * which it knows; it will only return an unknown format if there are no known 
079:             * formats to select from. [UT] changed to accept WMS 1.0 and 1.1.1 image formats 
080:             * @param format the format which is in question
081:             * @return true if the specified format is known by the MapFormatChooser, false 
082:             *         otherwise
083:             */
084:            static public boolean isKnownFormat(String format) {
085:                for (int i = 0; i < IMAGE_FORMATS.length; i++) {
086:                    for (int j = 0; j < IMAGE_FORMATS[i].length; j++) {
087:                        if (format.equals(IMAGE_FORMATS[i][j])) {
088:                            return true;
089:                        }
090:                    }
091:                }
092:                return false;
093:            }
094:
095:            /*
096:             * Sets whether tranparency is required in the image format.
097:             * If transparency is required it takes priority over lossy compression.
098:             * However, if no format that supports transparency is available, the next best
099:             * format will be selected.
100:             * @param transparencyRequired true if the image format chosen needs to support 
101:             *                             transparency
102:             */
103:            public void setTransparencyRequired(boolean transparencyRequired) {
104:                this .transparencyRequired = transparencyRequired;
105:            }
106:
107:            /*
108:             * Sets whether lossy compression is preferred over non-lossy compression.
109:             * Lossy compression would generally only be preferred over a slow connection,
110:             * and also note that image formats which use lossy compression generally don't
111:             * support transparency - in this case the transparency requirement takes priority.
112:             * @param useLossy true if lossy compression is preferrable
113:             */
114:            public void setPreferLossyCompression(boolean useLossy) {
115:                this .useLossy = useLossy;
116:            }
117:
118:            /*
119:             * Returns a format String from the Array of available formats which best
120:             * matches the requirements and preferences specified. If there are no image
121:             * formats available which can be used by the WMS image handling code, then 
122:             * null is returned.
123:             * @param formats the array of available formats to choose from
124:             * @return the chosen format string from Array of available formats, or null 
125:             *         if none of the available formats are known
126:             */
127:            public String chooseFormat(String[] formats) {
128:                if (formats.length == 0) {
129:                    throw new IllegalArgumentException();
130:                }
131:                String[] order = new String[3];
132:                if (transparencyRequired) {
133:                    order[0] = imageFormats[1]; //png
134:                    order[1] = imageFormats[0]; //gif
135:                    order[2] = imageFormats[2]; //jpg
136:
137:                } else if (useLossy) {
138:
139:                    order[0] = imageFormats[2]; //jpg
140:                    order[1] = imageFormats[1]; //png
141:                    order[2] = imageFormats[0];
142:                } else {
143:
144:                    order[0] = imageFormats[1]; //png
145:                    order[1] = imageFormats[2]; //jpg
146:                    order[2] = imageFormats[0];
147:                }
148:                Arrays.sort(formats);
149:                for (int i = 0; i < order.length; i++) {
150:                    if (Arrays.binarySearch(formats, order[i]) >= 0) {
151:                        return order[i];
152:                    }
153:                }
154:                return null;
155:            }
156:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.