Source Code Cross Referenced for BasicStyle.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:        /*
002:         * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003:         * for visualizing and manipulating spatial features with geometry and attributes.
004:         *
005:         * Copyright (C) 2003 Vivid Solutions
006:         *
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License
009:         * as published by the Free Software Foundation; either version 2
010:         * of the License, or (at your option) any later version.
011:         *
012:         * This program 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
015:         * GNU General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU General Public License
018:         * along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020:         *
021:         * For more information, contact:
022:         *
023:         * Vivid Solutions
024:         * Suite #1A
025:         * 2328 Government Street
026:         * Victoria BC  V8T 5G5
027:         * Canada
028:         *
029:         * (250)385-6040
030:         * www.vividsolutions.com
031:         */
032:        package com.vividsolutions.jump.workbench.ui.renderer.style;
033:
034:        import com.vividsolutions.jts.util.Assert;
035:
036:        import com.vividsolutions.jump.I18N;
037:        import com.vividsolutions.jump.feature.Feature;
038:        import com.vividsolutions.jump.util.StringUtil;
039:        import com.vividsolutions.jump.workbench.model.Layer;
040:        import com.vividsolutions.jump.workbench.ui.GUIUtil;
041:        import com.vividsolutions.jump.workbench.ui.Viewport;
042:
043:        import java.awt.*;
044:        import java.awt.BasicStroke;
045:        import java.awt.Color;
046:        import java.awt.Graphics2D;
047:        import java.awt.Stroke;
048:        import java.awt.geom.NoninvertibleTransformException;
049:
050:        import java.util.List;
051:
052:        public class BasicStyle implements  Style {
053:            private boolean renderingFill = true;
054:            private boolean renderingLine = true;
055:            private boolean renderingLinePattern = false;
056:            private boolean renderingFillPattern = false;
057:
058:            public static final Color DEFAULT_FILL_COLOR = new Color(0, 0, 0,
059:                    255);
060:            public static final Color DEFAULT_LINE_COLOR = DEFAULT_FILL_COLOR;
061:            public static final BasicStroke DEFAULT_FILL_STROKE = new BasicStroke(
062:                    1);
063:
064:            //The important thing here is the initial alpha. [Jon Aquino]
065:            private Color fillColor = DEFAULT_FILL_COLOR;
066:            private Color lineColor = DEFAULT_LINE_COLOR;
067:
068:            private BasicStroke lineStroke;
069:            private Stroke fillStroke = DEFAULT_FILL_STROKE;
070:            private boolean enabled = true;
071:            private String linePattern = "3";
072:
073:            //Set fill pattern to something, so that the BasicStylePanel combobox won't
074:            //start empty. [Jon Aquino]
075:            // Fixing the GUI is a better idea! [s-l-teichmann]
076:            private Paint fillPattern;
077:
078:            public BasicStyle(Color fillColor) {
079:                setFillColor(fillColor);
080:                setLineColor(Layer.defaultLineColor(fillColor));
081:                setLineWidth(1);
082:            }
083:
084:            public BasicStyle() {
085:                this (Color.black);
086:            }
087:
088:            public boolean isRenderingFillPattern() {
089:                return renderingFillPattern;
090:            }
091:
092:            public BasicStyle setRenderingFillPattern(
093:                    boolean renderingFillPattern) {
094:                this .renderingFillPattern = renderingFillPattern;
095:                return this ;
096:            }
097:
098:            public Paint getFillPattern() {
099:                return fillPattern;
100:            }
101:
102:            /**
103:             * Remember to call #setRenderingFillPattern(true).
104:             */
105:            public BasicStyle setFillPattern(Paint fillPattern) {
106:                this .fillPattern = fillPattern;
107:                if (fillPattern instanceof  BasicFillPattern) {
108:                    ((BasicFillPattern) fillPattern).setColor(this .fillColor);
109:                }
110:                return this ;
111:            }
112:
113:            public String getLinePattern() {
114:                return linePattern;
115:            }
116:
117:            /**
118:             * The actual dash pattern used internally will be the given dash pattern
119:             * multiplied by the line length. Remember to call #setRenderingLinePattern(true).
120:             * @param linePattern e.g. "5,2,3,2"
121:             */
122:            public BasicStyle setLinePattern(String linePattern) {
123:                this .linePattern = linePattern;
124:                lineStroke = createLineStroke(lineStroke.getLineWidth());
125:                return this ;
126:            }
127:
128:            public void initialize(Layer layer) {
129:            }
130:
131:            public void setEnabled(boolean enabled) {
132:                this .enabled = enabled;
133:            }
134:
135:            public boolean isEnabled() {
136:                return enabled;
137:            }
138:
139:            public void paint(Feature f, Graphics2D g, Viewport viewport)
140:                    throws NoninvertibleTransformException {
141:                StyleUtil
142:                        .paint(
143:                                f.getGeometry(),
144:                                g,
145:                                viewport,
146:                                renderingFill,
147:                                fillStroke,
148:                                (renderingFillPattern && (fillPattern != null)) ? fillPattern
149:                                        : fillColor, renderingLine, lineStroke,
150:                                lineColor);
151:            }
152:
153:            public Object clone() {
154:                try {
155:                    return super .clone();
156:                } catch (CloneNotSupportedException e) {
157:                    Assert.shouldNeverReachHere();
158:
159:                    return null;
160:                }
161:            }
162:
163:            public boolean isRenderingFill() {
164:                return renderingFill;
165:            }
166:
167:            public boolean isRenderingLine() {
168:                return renderingLine;
169:            }
170:
171:            public boolean isRenderingLinePattern() {
172:                return renderingLinePattern;
173:            }
174:
175:            public void setRenderingFill(boolean renderingFill) {
176:                this .renderingFill = renderingFill;
177:            }
178:
179:            public void setRenderingLine(boolean renderingLine) {
180:                this .renderingLine = renderingLine;
181:            }
182:
183:            public BasicStyle setRenderingLinePattern(
184:                    boolean renderingLinePattern) {
185:                this .renderingLinePattern = renderingLinePattern;
186:                lineStroke = createLineStroke(lineStroke.getLineWidth());
187:                return this ;
188:            }
189:
190:            public void setFillColor(Color fillColor) {
191:                setFillColor(fillColor, getAlpha());
192:            }
193:
194:            private BasicStyle setFillColor(Color fillColor, int alpha) {
195:                this .fillColor = GUIUtil.alphaColor(fillColor, alpha);
196:                if (fillPattern instanceof  BasicFillPattern) {
197:                    ((BasicFillPattern) fillPattern).setColor(this .fillColor);
198:                }
199:                return this ;
200:            }
201:
202:            public void setLineColor(Color lineColor) {
203:                this .lineColor = GUIUtil.alphaColor(lineColor, getAlpha());
204:            }
205:
206:            public void setLineWidth(int lineWidth) {
207:                //Don't use BasicStroke.JOIN_ROUND or JOIN_BEVEL -- when the line
208:                //width is 1, one of the corners will not be drawn. [Jon Aquino]
209:                lineStroke = createLineStroke(lineWidth);
210:            }
211:
212:            private BasicStroke createLineStroke(float lineWidth) {
213:                return (renderingLinePattern
214:                        && (linePattern.trim().length() != 0) && (lineWidth > 0)) ? new BasicStroke(
215:                        lineWidth, BasicStroke.CAP_BUTT,
216:                        BasicStroke.JOIN_BEVEL, 1.0f, toArray(linePattern,
217:                                lineWidth), 0)
218:                        : new BasicStroke(lineWidth, BasicStroke.CAP_BUTT,
219:                                BasicStroke.JOIN_BEVEL);
220:            }
221:
222:            public static float[] toArray(String linePattern, float lineWidth) {
223:                List strings = StringUtil.fromCommaDelimitedString(linePattern);
224:                float[] array = new float[strings.size()];
225:
226:                for (int i = 0; i < strings.size(); i++) {
227:                    String string = (String) strings.get(i);
228:                    array[i] = Float.parseFloat(string) * lineWidth;
229:
230:                    if (array[i] <= 0) {
231:                        throw new IllegalArgumentException(
232:                                I18N
233:                                        .get("ui.renderer.style.BasicStyle.negative-dash-length"));
234:                    }
235:                }
236:                return array;
237:            }
238:
239:            /**
240:             * @return 0-255 (255 is opaque)
241:             */
242:            public int getAlpha() {
243:                return fillColor.getAlpha();
244:            }
245:
246:            public Color getFillColor() {
247:                return GUIUtil.alphaColor(fillColor, 255);
248:            }
249:
250:            public Color getLineColor() {
251:                return GUIUtil.alphaColor(lineColor, 255);
252:            }
253:
254:            public int getLineWidth() {
255:                return (int) lineStroke.getLineWidth();
256:            }
257:
258:            /**
259:             * @param alpha 0-255 (255 is opaque)
260:             */
261:            public void setAlpha(int alpha) {
262:                setFillColor(fillColor, alpha);
263:                lineColor = GUIUtil.alphaColor(lineColor, alpha);
264:            }
265:
266:            public BasicStroke getLineStroke() {
267:                return lineStroke;
268:            }
269:        }
w_w_w___.___j__a__v_a2__s___.___c_o_m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.