Source Code Cross Referenced for WKTFillPattern.java in  » GIS » openjump » com » vividsolutions » jump » workbench » ui » renderer » style » 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.jump.workbench.ui.renderer.style 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.vividsolutions.jump.workbench.ui.renderer.style;
002:
003:        import com.vividsolutions.jts.geom.Coordinate;
004:        import com.vividsolutions.jts.io.ParseException;
005:        import com.vividsolutions.jts.io.WKTReader;
006:        import com.vividsolutions.jts.util.Assert;
007:
008:        import com.vividsolutions.jump.geom.Angle;
009:        import com.vividsolutions.jump.util.Blackboard;
010:        import com.vividsolutions.jump.util.CollectionUtil;
011:        import com.vividsolutions.jump.warp.AffineTransform;
012:        import com.vividsolutions.jump.workbench.ui.renderer.java2D.Java2DConverter;
013:
014:        import java.awt.AlphaComposite;
015:        import java.awt.BasicStroke;
016:        import java.awt.Color;
017:        import java.awt.Graphics2D;
018:        import java.awt.geom.NoninvertibleTransformException;
019:        import java.awt.geom.Point2D;
020:        import java.awt.image.BufferedImage;
021:
022:        public class WKTFillPattern extends BasicFillPattern {
023:            private static final String LINE_WIDTH_KEY = "LINE WIDTH";
024:            private static final String EXTENT_KEY = "EXTENT";
025:            private static final String PATTERN_WKT_KEY = "PATTERN WKT";
026:
027:            /**
028:             * Parameterless constructor for Java2XML
029:             */
030:            public WKTFillPattern() {
031:            }
032:
033:            public WKTFillPattern(int lineWidth, int extent, String patternWKT) {
034:                super (new Blackboard().putAll(CollectionUtil
035:                        .createMap(new Object[] { BasicFillPattern.COLOR_KEY,
036:                                Color.black, LINE_WIDTH_KEY,
037:                                new Integer(lineWidth), EXTENT_KEY,
038:                                new Integer(extent), PATTERN_WKT_KEY,
039:                                patternWKT })));
040:            }
041:
042:            public BufferedImage createImage(Blackboard properties) {
043:                BufferedImage image = new BufferedImage(properties
044:                        .getInt(EXTENT_KEY), properties.getInt(EXTENT_KEY),
045:                        BufferedImage.TYPE_INT_ARGB);
046:                Graphics2D g = image.createGraphics();
047:                g.setComposite(AlphaComposite.getInstance(
048:                        AlphaComposite.SRC_OVER, ((Color) getProperties().get(
049:                                COLOR_KEY)).getAlpha() / 255f));
050:
051:                //Vertical flip so the y-axis points upwards [Jon Aquino]
052:                g.scale(1, -1);
053:
054:                //Center [Jon Aquino]
055:                g.translate(properties.getInt(EXTENT_KEY) / 2d, -properties
056:                        .getInt(EXTENT_KEY) / 2d);
057:                g.setColor((Color) properties.get(BasicFillPattern.COLOR_KEY));
058:                g.setStroke(new BasicStroke(properties.getInt(LINE_WIDTH_KEY)));
059:
060:                try {
061:                    g.draw(new Java2DConverter(
062:                            new Java2DConverter.PointConverter() {
063:                                public Point2D toViewPoint(
064:                                        Coordinate modelCoordinate) {
065:                                    return new Point2D.Double(
066:                                            modelCoordinate.x,
067:                                            modelCoordinate.y);
068:                                }
069:
070:                                public double getScale() {
071:                                    return 1;
072:                                }
073:                            }).toShape(new WKTReader().read((String) properties
074:                            .get(PATTERN_WKT_KEY))));
075:                } catch (NoninvertibleTransformException e) {
076:                    //Eat it [Jon Aquino]
077:                } catch (ParseException e) {
078:                    Assert.shouldNeverReachHere((String) properties
079:                            .get(PATTERN_WKT_KEY));
080:                }
081:
082:                return image;
083:            }
084:
085:            public static WKTFillPattern createDiagonalStripePattern(
086:                    int lineWidth, double centerlineSeparationInLineWidths,
087:                    boolean forward, boolean back) {
088:                double centerlineSeparation = centerlineSeparationInLineWidths
089:                        * lineWidth;
090:
091:                return new WKTFillPattern(lineWidth, (int) Math.rint(Math
092:                        .sqrt(2)
093:                        * centerlineSeparation), "GEOMETRYCOLLECTION("
094:                        + wktForThreeLines(centerlineSeparation, 45, forward)
095:                        + ", "
096:                        + wktForThreeLines(centerlineSeparation, -45, back)
097:                        + ")");
098:            }
099:
100:            public static WKTFillPattern createVerticalHorizontalStripePattern(
101:                    int lineWidth, double centerlineSeparationInLineWidths,
102:                    boolean vertical, boolean horizontal) {
103:                double centerlineSeparation = centerlineSeparationInLineWidths
104:                        * lineWidth;
105:
106:                return new WKTFillPattern(lineWidth, (int) Math
107:                        .rint(2 * centerlineSeparation), "GEOMETRYCOLLECTION("
108:                        + wktForThreeLines(centerlineSeparation, 90, vertical)
109:                        + ", "
110:                        + wktForThreeLines(centerlineSeparation, 0, horizontal)
111:                        + ")");
112:            }
113:
114:            private static String wktForThreeLines(double centerlineSeparation,
115:                    double angleInDegrees, boolean enabled) {
116:                return enabled ? wktForThreeLines(4 * centerlineSeparation,
117:                        centerlineSeparation, angleInDegrees) : "POINT EMPTY";
118:            }
119:
120:            private static String wktForThreeLines(double length,
121:                    double centerlineSeparation, double angleInDegrees) {
122:                AffineTransform transform = new AffineTransform(
123:                        new Coordinate(), new Coordinate(),
124:                        new Coordinate(1, 0), new Coordinate(Math.cos(Angle
125:                                .toRadians(angleInDegrees)), Math.sin(Angle
126:                                .toRadians(angleInDegrees))));
127:
128:                try {
129:                    return transform.transform(
130:                            new WKTReader().read("MULTILINESTRING("
131:                                    + ("(" + (-length / 2) + " "
132:                                            + -centerlineSeparation + ", "
133:                                            + (length / 2) + " "
134:                                            + -centerlineSeparation + "), ")
135:                                    + ("(" + (-length / 2) + " " + 0 + ", "
136:                                            + (length / 2) + " " + 0 + "), ")
137:                                    + ("(" + (-length / 2) + " "
138:                                            + centerlineSeparation + ", "
139:                                            + (length / 2) + " "
140:                                            + centerlineSeparation + ") ")
141:                                    + ")")).toText();
142:                } catch (Exception e) {
143:                    Assert.shouldNeverReachHere();
144:
145:                    return null;
146:                }
147:            }
148:        }
ww_w___.__ja___v___a__2s___.__c___o_m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.