Source Code Cross Referenced for DrawPointCommand.java in  » GIS » udig-1.1 » net » refractions » udig » tools » edit » commands » 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.tools.edit.commands 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* uDig - User Friendly Desktop Internet GIS client
002:         * http://udig.refractions.net
003:         * (C) 2004, Refractions Research Inc.
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation;
008:         * version 2.1 of the License.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         */
015:        package net.refractions.udig.tools.edit.commands;
016:
017:        import java.awt.Color;
018:        import java.awt.Rectangle;
019:        import java.util.Iterator;
020:
021:        import net.refractions.udig.project.ui.commands.AbstractDrawCommand;
022:        import net.refractions.udig.project.ui.render.displayAdapter.MapMouseEvent;
023:        import net.refractions.udig.project.ui.render.displayAdapter.MapMouseMotionListener;
024:        import net.refractions.udig.project.ui.render.displayAdapter.ViewportPane;
025:        import net.refractions.udig.tools.edit.EditPlugin;
026:        import net.refractions.udig.tools.edit.EditToolHandler;
027:        import net.refractions.udig.tools.edit.preferences.PreferenceConstants;
028:        import net.refractions.udig.tools.edit.support.EditGeomPointIterator;
029:        import net.refractions.udig.tools.edit.support.Point;
030:        import net.refractions.udig.tools.edit.support.PrimitiveShape;
031:        import net.refractions.udig.tools.edit.support.ShapeType;
032:        import net.refractions.udig.ui.graphics.ViewportGraphics;
033:
034:        import org.eclipse.core.runtime.IProgressMonitor;
035:        import org.eclipse.jface.preference.IPreferenceStore;
036:
037:        /**
038:         * Draws each vertex point as a rectangle.  Listens to mouse events as long as valid and fills vertext when
039:         * cursor is over a vertex.
040:         * 
041:         * @author jones
042:         * @since 1.1.0
043:         */
044:        public class DrawPointCommand extends AbstractDrawCommand implements 
045:                MapMouseMotionListener {
046:
047:            private PrimitiveShape shape;
048:            private int radius = 3;
049:            private Color outline = Color.BLACK;
050:            private Color fill = new Color(255, 168, 168);
051:            private ViewportPane pane;
052:            private Point location;
053:            private int radiusDelta = 1;
054:            private Color selectionFill = Color.YELLOW;
055:            private boolean overPoint;
056:            private EditToolHandler handler;
057:            private boolean drawCurrentShape;
058:            IPreferenceStore store = EditPlugin.getDefault()
059:                    .getPreferenceStore();
060:
061:            public DrawPointCommand(EditToolHandler handler2,
062:                    PrimitiveShape shape, ViewportPane pane) {
063:                this .shape = shape;
064:                this .pane = pane;
065:                pane.addMouseMotionListener(this );
066:                this .handler = handler2;
067:            }
068:
069:            public void run(IProgressMonitor monitor) throws Exception {
070:                graphics.setStroke(ViewportGraphics.LINE_SOLID, 1);
071:                if (drawCurrentShape) {
072:                    shape = handler.getCurrentShape();
073:                }
074:                if (shape == null || shape.getNumPoints() == 0)
075:                    return;
076:                Rectangle rect = new Rectangle();
077:                rect.width = radius * 2;
078:                rect.height = radius * 2;
079:                boolean selected;
080:                for (Iterator<Point> iter = new EditGeomPointIterator(shape
081:                        .getEditGeom()); iter.hasNext();) {
082:                    Point p = iter.next();
083:                    if ((p.getX() < 0 || p.getX() > display.getWidth())
084:                            && (p.getY() < 0 || p.getY() > display.getHeight()))
085:                        continue;
086:                    rect.x = p.getX() - radius;
087:                    rect.y = p.getY() - radius;
088:
089:                    setZoomedRect(rect, p, 0);
090:                    if (shape.getEditBlackboard().getSelection().contains(p)) {
091:                        graphics.setColor(selectionFill);
092:                        selected = true;
093:                    } else {
094:                        graphics.setColor(fill);
095:                        selected = false;
096:                    }
097:                    if (selected
098:                            || store
099:                                    .getBoolean(PreferenceConstants.P_FILL_VERTICES)
100:                            || shape.getEditGeom().getShapeType() == ShapeType.POINT)
101:                        graphics.fillRect(rect.x, rect.y, rect.width,
102:                                rect.height);
103:
104:                    graphics.setColor(outline);
105:                    graphics.drawRect(rect.x, rect.y, rect.width, rect.height);
106:                }
107:                if (overPoint) {
108:                    Point firstPoint = shape.getPoint(0);
109:                    rect.x = firstPoint.getX() - radius;
110:                    rect.y = firstPoint.getY() - radius;
111:
112:                    setZoomedRect(rect, firstPoint, radiusDelta);
113:                    if (shape.getEditBlackboard().getSelection().contains(
114:                            firstPoint))
115:                        graphics.setColor(selectionFill);
116:                    else
117:                        graphics.setColor(fill);
118:                    graphics.fillRect(rect.x, rect.y, rect.width, rect.height);
119:
120:                    graphics.setColor(outline);
121:                    graphics.drawRect(rect.x, rect.y, rect.width, rect.height);
122:                }
123:
124:            }
125:
126:            public void setDrawCurrentShape(boolean b) {
127:                drawCurrentShape = b;
128:            }
129:
130:            /**
131:             * Sets the size of the point box.  
132:             *
133:             * @param rect rectangle to set
134:             * @param p center point
135:             * @param widthDelta the number of pixels larger the box should be than the radius.  
136:             * (radius of box is size of box from center to edge) delta is number of pixel from edge of normal
137:             * rect to new edge.  So 1 pixel delta would make rectangle 2 pixels larger. 
138:             */
139:            private void setZoomedRect(Rectangle rect, Point p, int widthRad) {
140:                rect.width = (widthRad * 2) + radius * 2;
141:                rect.height = rect.width;
142:                int i = radius + widthRad;
143:                rect.x = p.getX() - i;
144:                rect.y = p.getY() - i;
145:            }
146:
147:            private boolean isOverPoint(Point p) {
148:                for (int x = -radiusDelta - radius, max = radius + radiusDelta; x < max; x++) {
149:                    for (int y = -radiusDelta - radius; y < max; y++) {
150:                        if (Point.valueOf(p.getX() + x, p.getY() + y).equals(
151:                                location))
152:                            return true;
153:                    }
154:                }
155:                return false;
156:            }
157:
158:            @Override
159:            public void setValid(boolean valid) {
160:                if (!valid) {
161:                    pane.removeMouseMotionListener(this );
162:                }
163:                super .setValid(valid);
164:            }
165:
166:            public void mouseMoved(MapMouseEvent event) {
167:                boolean oldIsOver = overPoint;
168:                this .location = Point.valueOf(event.x, event.y);
169:
170:                if (shape == null || shape.getNumPoints() == 0)
171:                    return;
172:
173:                Point firstPoint = shape.getPoint(0);
174:                overPoint = isOverPoint(firstPoint);
175:                if (overPoint != oldIsOver)
176:                    handler.repaint();
177:            }
178:
179:            public void mouseDragged(MapMouseEvent event) {
180:                mouseMoved(event);
181:            }
182:
183:            public void setCurrentShape(PrimitiveShape shape) {
184:                if (shape == this .shape)
185:                    return;
186:                this .shape = shape;
187:                handler.repaint();
188:            }
189:
190:            /**
191:             * 
192:             * @return Returns the radiusDelta.
193:             */
194:            public int getRadiusDelta() {
195:                return radiusDelta;
196:            }
197:
198:            /**
199:             * Default is 1.
200:             * @param width_rad The radiusDelta to set.
201:             */
202:            public void setRadiusDelta(int radiusDelta) {
203:                this .radiusDelta = radiusDelta;
204:            }
205:
206:            /**
207:             * @return Returns the fill.
208:             */
209:            public Color getFill() {
210:                return fill;
211:            }
212:
213:            /**
214:             * Default is Color( 255,168,168,188 )
215:             * @param fill The fill to set.
216:             */
217:            public void setFill(Color fill) {
218:                this .fill = fill;
219:                if (fill.getAlpha() != 255) {
220:                    this .fill = new Color(fill.getRGB());
221:                }
222:            }
223:
224:            /**
225:             * @return Returns the outline.
226:             */
227:            public Color getOutline() {
228:                return outline;
229:            }
230:
231:            /**
232:             * Default is Black
233:             * @param outline The outline to set.
234:             */
235:            public void setOutline(Color outline) {
236:                this .outline = outline;
237:            }
238:
239:            /**
240:             * @return Returns the radius.
241:             */
242:            public int getRadius() {
243:                return radius;
244:            }
245:
246:            /**
247:             * Default is 3.
248:             * @param radius The radius to set.
249:             */
250:            public void setRadius(int radius) {
251:                this .radius = radius - radiusDelta;
252:            }
253:
254:            /**
255:             * @return Returns the geom.
256:             */
257:            public PrimitiveShape getGeom() {
258:                return shape;
259:            }
260:
261:            /**
262:             * @return Returns the selectionFill.
263:             */
264:            public Color getSelectionFill() {
265:                return selectionFill;
266:            }
267:
268:            /**
269:             * @param selectionFill The selectionFill to set.
270:             */
271:            public void setSelectionFill(Color selectionFill) {
272:                this .selectionFill = selectionFill;
273:            }
274:
275:            public Rectangle getValidArea() {
276:                if (shape != null)
277:                    return shape.getBounds();
278:                else
279:                    return null;
280:            }
281:
282:            public void mouseHovered(MapMouseEvent event) {
283:            }
284:
285:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.