Source Code Cross Referenced for DrawPathCommand.java in  » GIS » udig-1.1 » net » refractions » udig » project » ui » internal » commands » draw » 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 » udig 1.1 » net.refractions.udig.project.ui.internal.commands.draw 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    uDig - User Friendly Desktop Internet GIS client
003:         *    http://udig.refractions.net
004:         *    (C) 2004, Refractions Research Inc.
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 hope 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 net.refractions.udig.project.ui.internal.commands.draw;
018:
019:        import java.awt.Color;
020:        import java.awt.Paint;
021:        import java.awt.Rectangle;
022:        import java.awt.geom.GeneralPath;
023:        import java.awt.geom.PathIterator;
024:
025:        import net.refractions.udig.project.command.MapCommand;
026:        import net.refractions.udig.project.ui.commands.AbstractDrawCommand;
027:        import net.refractions.udig.ui.graphics.SWTGraphics;
028:        import net.refractions.udig.ui.graphics.ViewportGraphics;
029:
030:        import org.eclipse.core.runtime.IProgressMonitor;
031:        import org.eclipse.swt.graphics.Device;
032:        import org.eclipse.swt.graphics.Path;
033:
034:        /**
035:         * Draws the outline of a shape on the Acetate layer.
036:         * 
037:         * @author jeichar
038:         * @since 0.3
039:         */
040:        public class DrawPathCommand extends AbstractDrawCommand {
041:
042:            Path path = null;
043:            Color paint = null;
044:            private int style = -1;
045:            private int width;
046:            private Color fill;
047:            private boolean closeShape;
048:            private int closex1;
049:            private int closex2;
050:            private int closey1;
051:            private int closey2;
052:
053:            /**
054:             * Creates a new instance of DrawShapeCommand
055:             */
056:            public DrawPathCommand() {
057:                this ((Path) null, Color.BLACK, ViewportGraphics.LINE_SOLID, 1);
058:            }
059:
060:            /**
061:             * Creates a new instance of DrawShapeCommand
062:             * 
063:             * @param path The path to draw
064:             * @param color The paint to draw the shape with.
065:             * @param lineStyle the line style to use for the shape outline
066:             * @param lineWidth the line width in pixels.
067:             */
068:            public DrawPathCommand(Path path, Color color, int lineStyle,
069:                    int lineWidth) {
070:                this .path = path;
071:                this .paint = color;
072:                this .style = lineStyle;
073:                this .width = lineWidth;
074:            }
075:
076:            /**
077:             * Creates a new instance of DrawShapeCommand
078:             * 
079:             * @param path The path to draw
080:             * @param color The paint to draw the shape with.
081:             * @param lineStyle the line style to use for the shape outline
082:             * @param lineWidth the line width in pixels.
083:             */
084:            public DrawPathCommand(Device device, PathIterator path,
085:                    Color color, int lineStyle, int lineWidth) {
086:                this .paint = color;
087:                this .style = lineStyle;
088:                this .width = lineWidth;
089:                this .path = SWTGraphics.createPath(path, device);
090:            }
091:
092:            /**
093:             * @see MapCommand#run()
094:             */
095:            public void run(IProgressMonitor monitor) {
096:                if (path == null)
097:                    return;
098:                fill();
099:
100:                draw();
101:
102:                close();
103:            }
104:
105:            private void draw() {
106:                if (paint != null || fill == null) {
107:                    if (paint != null)
108:                        graphics.setColor(paint);
109:                    if (style > -1)
110:                        graphics.setStroke(style, width);
111:                    if (path != null)
112:                        graphics.drawPath(path);
113:                }
114:
115:            }
116:
117:            private void close() {
118:                if (closeShape)
119:                    graphics.drawLine(closex1, closey1, closex2, closey2);
120:            }
121:
122:            private void fill() {
123:                if (fill != null) {
124:                    graphics.setColor(fill);
125:                    if (path != null)
126:                        graphics.fillPath(path);
127:                }
128:            }
129:
130:            /**
131:             * @return Returns the paint.
132:             */
133:            public Paint getPaint() {
134:                return paint;
135:            }
136:
137:            /**
138:             * @param paint The paint to set.
139:             */
140:            public void setPaint(Color paint) {
141:                this .paint = paint;
142:            }
143:
144:            /**
145:             * @param path The new path.
146:             */
147:            public void setPath(Path path) {
148:                this .path = path;
149:            }
150:
151:            /**
152:             * @param path The new path.
153:             */
154:            public void setPath(Device device, PathIterator path) {
155:                this .path = SWTGraphics.createPath(path, device);
156:
157:            }
158:
159:            /**
160:             * @return Returns the line style.
161:             */
162:            public int getLineStyle() {
163:                return style;
164:            }
165:
166:            /**
167:             * @return Returns the line width.
168:             */
169:            public int getLineWidth() {
170:                return width;
171:            }
172:
173:            /**
174:             * Sets the line style
175:             * 
176:             * @param lineStyle the style of the line
177:             * @param lineWidth the width of the line
178:             */
179:            public void setStroke(int lineStyle, int lineWidth) {
180:                this .style = lineStyle;
181:                this .width = lineWidth;
182:            }
183:
184:            /**
185:             * Sets the color that the shape will be filled with.  
186:             * If fill is null then no fill will be applied.
187:             *  
188:             * @param fillColor a color to be used to fill the shapeor null.
189:             */
190:            public void setFill(Color fillColor) {
191:                this .fill = fillColor;
192:            }
193:
194:            public Rectangle getValidArea() {
195:                if (path != null) {
196:                    float[] bounds = new float[4];
197:                    path.getBounds(bounds);
198:                    return new Rectangle((int) bounds[0], (int) bounds[1],
199:                            (int) bounds[2], (int) bounds[3]);
200:                }
201:                return null;
202:            }
203:
204:            /**
205:             * Disposes of the Path object if it is not null and sets this command as invalid.
206:             *
207:             */
208:            public void dispose() {
209:                if (path != null) {
210:                    path.dispose();
211:                    path = null;
212:                }
213:                super .setValid(false);
214:            }
215:
216:            @Override
217:            public void setValid(boolean valid) {
218:                if (!valid) {
219:                    dispose();
220:                } else {
221:                    super .setValid(true);
222:                }
223:            }
224:
225:            /**
226:             * if this is called then a line is also drawn from (x1,y1) to (x2,y2).  This would be used to make the path appear to be closed.  Actually closing
227:             * the path is problematic because it cannot be undone.  So this is a method to simulate it.  Obviously if the path is not going to need to be re-opened 
228:             * then this method does not need to be called.
229:             *
230:             */
231:            public void line(int x1, int y1, int x2, int y2) {
232:                closeShape = true;
233:                this.closex1 = x1;
234:                this.closex2 = x2;
235:                this.closey1 = y1;
236:                this.closey2 = y2;
237:            }
238:        }
w_w_w.j_a_v__a___2_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.