Source Code Cross Referenced for GDISupport.java in  » IDE-Netbeans » uml » org » netbeans » modules » uml » ui » support » viewfactorysupport » 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 » IDE Netbeans » uml » org.netbeans.modules.uml.ui.support.viewfactorysupport 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.uml.ui.support.viewfactorysupport;
043:
044:        import java.awt.Color;
045:        import java.awt.Font;
046:        import java.awt.FontMetrics;
047:        import java.awt.Graphics2D;
048:        import java.awt.Paint;
049:        import java.awt.Point;
050:        import java.awt.Polygon;
051:        import java.awt.Rectangle;
052:        import java.awt.Stroke;
053:        import java.awt.geom.GeneralPath;
054:        import java.util.Iterator;
055:
056:        import org.netbeans.modules.uml.core.support.umlsupport.ETPoint;
057:        import org.netbeans.modules.uml.core.support.umlsupport.ETRect;
058:        import org.netbeans.modules.uml.core.support.umlsupport.ETSize;
059:        import org.netbeans.modules.uml.core.support.umlsupport.IETPoint;
060:        import org.netbeans.modules.uml.core.support.umlsupport.IETRect;
061:        import org.netbeans.modules.uml.core.support.umlsupport.IETSize;
062:        import org.netbeans.modules.uml.core.support.umlutils.ETArrayList;
063:        import org.netbeans.modules.uml.core.support.umlutils.ETList;
064:        import org.netbeans.modules.uml.ui.products.ad.drawengines.ETStrokeCache;
065:        import org.netbeans.modules.uml.ui.products.ad.viewfactory.ETArrowHeadFactory;
066:        import com.tomsawyer.editor.TSEColor;
067:        import com.tomsawyer.editor.TSEEdge; //import com.tomsawyer.util.TSConstPoint;
068:        import com.tomsawyer.drawing.geometry.TSConstPoint;
069:
070:        /**
071:         * @author KevinM
072:         *
073:         */
074:        public class GDISupport {
075:            private static final int SMALLEST_TEXT = 3;
076:
077:            public static void fillRectangle(Graphics2D dc,
078:                    final Rectangle boundingRect) {
079:                dc.fillRect(boundingRect.x, boundingRect.y, boundingRect.width,
080:                        boundingRect.height);
081:            }
082:
083:            public static void fillRectangle(Graphics2D dc,
084:                    final IETRect boundingRect, final Color fillColor) {
085:                Color prevColor = dc.getColor();
086:
087:                dc.setColor(fillColor);
088:                fillRectangle(dc, boundingRect);
089:
090:                dc.setColor(prevColor);
091:
092:            }
093:
094:            public static void fillRectangle(Graphics2D dc,
095:                    final IETRect boundingRect) {
096:                dc.fillRect((int) boundingRect.getLeft(), (int) boundingRect
097:                        .getTop(), (int) boundingRect.getWidth(),
098:                        (int) boundingRect.getHeight());
099:            }
100:
101:            public static void frameRectangle(Graphics2D dc,
102:                    final Rectangle boundingRect) {
103:                dc.drawRect(boundingRect.x, boundingRect.y, boundingRect.width,
104:                        boundingRect.height);
105:            }
106:
107:            public static void frameRectangle(Graphics2D dc,
108:                    final IETRect boundingRect) {
109:                dc.draw(boundingRect.getRectangle());
110:            }
111:
112:            /**
113:             * Draws a frame with the specified parameters
114:             * 
115:             * @param dc            Graphical device context
116:             * @param boundingRect  Rectangle for the frame's location
117:             * @param lineKind      DrawEngineLineKindEnum which specifies the type of line to use for the frame
118:             * @param width         Pixel width of the frame
119:             * @param frameColor    Color of the frame
120:             */
121:            public static void frameRectangle(Graphics2D dc,
122:                    final IETRect boundingRect, int lineKind, int width,
123:                    final Color frameColor) {
124:                // Select the pen, but save off the current one first.
125:                Color prevColor = dc.getColor();
126:                Stroke prevPen = dc.getStroke();
127:
128:                dc.setColor(frameColor);
129:                dc.setStroke(getLineStroke(lineKind, width));
130:                frameRectangle(dc, boundingRect);
131:
132:                dc.setColor(prevColor);
133:                dc.setStroke(prevPen);
134:            }
135:
136:            /*
137:             *  Draws a rectangle using the dc's current color settings
138:             */
139:            public static void drawRectangle(Graphics2D dc,
140:                    final Rectangle boundingRect) {
141:                fillRectangle(dc, boundingRect);
142:                frameRectangle(dc, boundingRect);
143:            }
144:
145:            /*
146:             * Draw a rectangle with a pen color and solid back color
147:             * If the background color is not desired pass bkColor = null to just draw the frame
148:             */
149:            public static void drawRectangle(Graphics2D dc,
150:                    final Rectangle boundingRect, final Paint penColor,
151:                    final Paint bkColor) {
152:                drawRectangle(dc, boundingRect, penColor, bkColor,
153:                        getLineStroke(DrawEngineLineKindEnum.DELK_SOLID, 1));
154:            }
155:
156:            /*
157:             * Draw a dashed rectangle with a pen color and solid back color
158:             * If the background color is not desired pass bkColor = null to just draw the frame
159:             */
160:            public static void drawDashedRectangle(Graphics2D dc,
161:                    final Rectangle boundingRect, Paint penColor, Paint bkColor) {
162:                drawRectangle(dc, boundingRect, penColor, bkColor,
163:                        getLineStroke(DrawEngineLineKindEnum.DELK_DASH, 1));
164:            }
165:
166:            /*
167:             * Draw a hatched rectangle with a pen color and solid back color
168:             * If the background color is not desired pass bkColor = null to just draw the frame
169:             */
170:            public static void drawHatchedRectangle(Graphics2D dc,
171:                    final Rectangle boundingRect, Color penColor, Color bkColor) {
172:                drawRectangle(dc, boundingRect, penColor, bkColor,
173:                        getLineStroke(DrawEngineLineKindEnum.DELK_HATCHED, 1));
174:            }
175:
176:            /// Draws a rectangle with the pen and the brush arguments
177:            public static void drawRectangle(Graphics2D dc,
178:                    final Rectangle boundingRect, final Paint penColor,
179:                    final Paint bkColor, final Stroke pPen) {
180:                Paint prevColor = dc.getPaint();
181:
182:                // Select the pen, but save off the current one first.
183:                Stroke prevPen = dc.getStroke();
184:                dc.setStroke(pPen);
185:
186:                if (bkColor != null) {
187:                    dc.setPaint(bkColor);
188:                    dc.fill(boundingRect);
189:                }
190:
191:                dc.setPaint(penColor);
192:                dc.draw(boundingRect);
193:
194:                dc.setPaint(prevColor);
195:                dc.setStroke(prevPen);
196:            }
197:
198:            public static void frameEllipse(Graphics2D dc,
199:                    final Rectangle boundingRect) {
200:                dc.drawOval(boundingRect.x, boundingRect.y, boundingRect.width,
201:                        boundingRect.height);
202:            }
203:
204:            public static void fillEllipse(Graphics2D dc,
205:                    final Rectangle boundingRect) {
206:                //dc.fillOval(boundingRect.x, boundingRect.y, boundingRect.width, boundingRect.height);
207:                java.awt.geom.Ellipse2D.Float shape = new java.awt.geom.Ellipse2D.Float(
208:                        boundingRect.x, boundingRect.y, boundingRect.width,
209:                        boundingRect.height);
210:                dc.fill(shape);
211:            }
212:
213:            /// Draws an ellipse using the current pen and brush
214:            public static void drawEllipse(Graphics2D dc,
215:                    final Rectangle boundingRect) {
216:                fillEllipse(dc, boundingRect);
217:                Color prevColor = dc.getColor();
218:                dc.setColor(TSEColor.black.getColor());
219:                frameEllipse(dc, boundingRect);
220:                dc.setColor(prevColor);
221:            }
222:
223:            public static void drawEllipse(Graphics2D dc,
224:                    final Rectangle boundingRect, final Paint penColor,
225:                    final Paint bkColor) {
226:                drawEllipse(dc, boundingRect, penColor, bkColor, getLineStroke(
227:                        DrawEngineLineKindEnum.DELK_SOLID, 1));
228:            }
229:
230:            public static void drawEllipse(Graphics2D dc,
231:                    final Rectangle boundingRect, final Paint penColor,
232:                    final Paint bkColor, final Stroke pen) {
233:                Paint prevColor = dc.getPaint();
234:
235:                // Select the pen, but save off the current one first.
236:                Stroke prevPen = dc.getStroke();
237:                dc.setPaint(bkColor);
238:                fillEllipse(dc, boundingRect);
239:                dc.setStroke(pen);
240:                dc.setPaint(penColor);
241:                frameEllipse(dc, boundingRect);
242:                dc.setPaint(prevColor);
243:                dc.setStroke(prevPen);
244:            }
245:
246:            /// Draws an dashed ellipse using the argument pen and brush
247:            public static void drawDashedEllipse(Graphics2D dc,
248:                    final Rectangle boundingRect, final Paint penColor,
249:                    final Paint bkColor) {
250:                drawEllipse(dc, boundingRect, penColor, bkColor, getLineStroke(
251:                        DrawEngineLineKindEnum.DELK_DASH, 1));
252:            }
253:
254:            public static void drawRoundRect(Graphics2D dc,
255:                    Rectangle boundingRect, double nCurrentZoom,
256:                    Paint penColor, Paint bkColor) {
257:                drawRoundRect(dc, boundingRect, nCurrentZoom, penColor,
258:                        bkColor, getLineStroke(
259:                                DrawEngineLineKindEnum.DELK_SOLID, 1));
260:            }
261:
262:            public static void drawRoundRect(Graphics2D dc,
263:                    Rectangle boundingRect, double nCurrentZoom,
264:                    Paint penColor, Paint bkColor, Stroke pen) {
265:                Paint prevColor = dc.getPaint();
266:
267:                // Select the pen, but save off the current one first.
268:                Stroke prevPen = dc.getStroke();
269:                dc.setPaint(bkColor);
270:                fillRoundRect(dc, boundingRect, nCurrentZoom);
271:                dc.setStroke(pen);
272:                dc.setPaint(penColor);
273:                frameRoundRect(dc, boundingRect, nCurrentZoom);
274:                dc.setPaint(prevColor);
275:                dc.setStroke(prevPen);
276:            }
277:
278:            public static void frameRoundRect(Graphics2D dc,
279:                    final Rectangle boundingRect, double nCurrentZoom) {
280:                dc.drawRoundRect(boundingRect.x, boundingRect.y,
281:                        boundingRect.width, boundingRect.height, 15, 15);
282:            }
283:
284:            public static void fillRoundRect(Graphics2D dc,
285:                    final Rectangle boundingRect, double nCurrentZoom) {
286:                dc.fillRoundRect(boundingRect.x, boundingRect.y,
287:                        boundingRect.width, boundingRect.height, 15, 15);
288:            }
289:
290:            /// Draws a rounded rectangle
291:            public static void drawRoundRect(Graphics2D dc,
292:                    final Rectangle boundingRect, double nCurrentZoom,
293:                    final Color penColor, final Color bkColor, final Stroke pen) {
294:                Color prevColor = dc.getColor();
295:
296:                // Select the pen, but save off the current one first.
297:                Stroke prevPen = dc.getStroke();
298:                dc.setColor(bkColor);
299:                fillRoundRect(dc, boundingRect, nCurrentZoom);
300:                dc.setStroke(pen);
301:                dc.setColor(penColor);
302:                frameRoundRect(dc, boundingRect, nCurrentZoom);
303:                dc.setColor(prevColor);
304:                dc.setStroke(prevPen);
305:            }
306:
307:            /// Draws a dashed, rounded rectangle using the current pen and brush
308:            public static void drawDashedRoundRect(Graphics2D dc,
309:                    final Rectangle boundingRect, double nCurrentZoom,
310:                    final Color penColor, final Paint bkColor) {
311:                drawRoundRect(dc, boundingRect, nCurrentZoom, penColor,
312:                        bkColor, getLineStroke(
313:                                DrawEngineLineKindEnum.DELK_DASH, 1));
314:            }
315:
316:            /// Draws a rounded rectangle using the argument pen and brush
317:            public static void drawRoundRect(Graphics2D dc,
318:                    final Rectangle boundingRect, double nCurrentZoom,
319:                    final Color penColor, final Paint bkColor) {
320:                drawRoundRect(dc, boundingRect, nCurrentZoom, penColor,
321:                        bkColor, getLineStroke(
322:                                DrawEngineLineKindEnum.DELK_SOLID, 1));
323:            }
324:
325:            /// Draws a black rounded rectangle using the current color.
326:            public static void drawRoundRect(Graphics2D dc,
327:                    final Rectangle boundingRect, double nCurrentZoom) {
328:                drawRoundRect(dc, boundingRect, nCurrentZoom, TSEColor.black
329:                        .getColor(), dc.getColor());
330:            }
331:
332:            /// Draws a rounded rectangle using the argument pen and brush
333:            public static void drawRoundOnTopRect(Graphics2D dc,
334:                    final Rectangle boundingRect, double nCurrentZoom,
335:                    final Color penColor, final Color bkColor) {
336:            }
337:
338:            /// Draws a rounded rectangle using the current pen and brush
339:            public static void drawRoundOnTopRect(Graphics2D dc,
340:                    final Rectangle boundingRect, double nCurrentZoom) {
341:            }
342:
343:            public static void drawLine(Graphics2D dc, final Point topLeft,
344:                    final Point bottomRight, final Stroke pen) {
345:                // Select the pen, but save off the current one first.
346:                Stroke prevPen = dc.getStroke();
347:                dc.setStroke(pen);
348:                dc.drawLine(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y);
349:                dc.setStroke(prevPen);
350:            }
351:
352:            /*
353:             * Draws the line onto the Graphics context
354:             */
355:            public static void drawLine(Graphics2D dc, final Point topLeft,
356:                    final Point bottomRight, final Color penColor,
357:                    final Stroke pen) {
358:                Color prevColor = dc.getColor();
359:
360:                // Select the pen, but save off the current one first.
361:                dc.setColor(penColor);
362:                drawLine(dc, topLeft, bottomRight, pen);
363:                dc.setColor(prevColor);
364:            }
365:
366:            public static void drawLine(Graphics2D dc, final Point topLeft,
367:                    final Point bottomRight, final Color penColor,
368:                    int penWidth, int lineStyle) {
369:                drawLine(dc, topLeft, bottomRight, penColor, getLineStroke(
370:                        lineStyle, penWidth));
371:            }
372:
373:            public static void drawLine(Graphics2D dc, final Point topLeft,
374:                    final Point bottomRight, final Color penColor, int penWidth) {
375:                drawLine(dc, topLeft, bottomRight, penColor, getLineStroke(
376:                        DrawEngineLineKindEnum.DELK_SOLID, penWidth));
377:            }
378:
379:            /// Draws a line using the currently selected colors
380:            public static void drawLine(Graphics2D dc, final Point topLeft,
381:                    final Point bottomRight) {
382:                dc.drawLine(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y);
383:            }
384:
385:            public static void drawDashedLine(Graphics2D dc,
386:                    final Point topLeft, final Point bottomRight,
387:                    final Color penColor) {
388:                drawLine(dc, topLeft, bottomRight, penColor, getLineStroke(
389:                        DrawEngineLineKindEnum.DELK_DASH, 1));
390:            }
391:
392:            /// Draws a dotted line with the pen color and the brush arguments
393:            public static void drawDottedLine(Graphics2D dc,
394:                    final Point topLeft, final Point bottomRight,
395:                    final Color penColor) {
396:                drawLine(dc, topLeft, bottomRight, penColor, getLineStroke(
397:                        DrawEngineLineKindEnum.DELK_COUNT, 1));
398:            }
399:
400:            /// Draws a poly line with the pen color and the brush arguments
401:            public static void drawPolyLine(Graphics2D dc,
402:                    ETList<IETPoint> pPoints, final Color penColor, int penWidth) {
403:                Color prevColor = dc.getColor();
404:                Stroke prevPen = dc.getStroke();
405:                dc.setStroke(getLineStroke(DrawEngineLineKindEnum.DELK_SOLID,
406:                        penWidth));
407:                dc.setColor(penColor);
408:                drawPolyLine(dc, pPoints, penColor);
409:                dc.setStroke(prevPen);
410:                dc.setColor(prevColor);
411:
412:            }
413:
414:            /// Draws a poly line with the pen color and the brush arguments
415:            public static void drawPolyLine(Graphics2D dc,
416:                    ETList<IETPoint> pPoints, final Color penColor) {
417:                if (pPoints == null || pPoints.size() < 2)
418:                    return;
419:
420:                Color prevColor = dc.getColor();
421:
422:                dc.setColor(penColor);
423:
424:                GeneralPath polyline = getPolyline(pPoints);
425:                if (polyline != null)
426:                    dc.draw(polyline);
427:
428:                dc.setColor(prevColor);
429:            }
430:
431:            /**
432:             * Draws a poly line with the pen color and the brush arguments
433:             */
434:            public static void drawPolyLine(Graphics2D dc,
435:                    final Rectangle boundingRect, final Color penColor) {
436:                Color prevColor = dc.getColor();
437:                fillRectangle(dc, boundingRect);
438:                dc.setColor(prevColor);
439:            }
440:
441:            public static GeneralPath getPolyline(ETList<IETPoint> pPoints) {
442:                if (pPoints == null || pPoints.size() < 2)
443:                    return null;
444:
445:                GeneralPath polyline = new GeneralPath(
446:                        GeneralPath.WIND_EVEN_ODD);
447:                Iterator<IETPoint> iter = pPoints.iterator();
448:                IETPoint pt = iter.next();
449:                polyline.moveTo((int) pt.getX(), (int) pt.getY());
450:
451:                while (iter.hasNext()) {
452:                    pt = iter.next();
453:                    polyline.lineTo((int) pt.getX(), (int) pt.getY());
454:                }
455:                return polyline;
456:            }
457:
458:            public static GeneralPath getPolygon(ETList<IETPoint> pPoints) {
459:                GeneralPath polygon = getPolyline(pPoints);
460:                if (polygon != null)
461:                    polygon.closePath();
462:                return polygon;
463:            }
464:
465:            public static void framePolygon(Graphics2D dc,
466:                    ETList<IETPoint> pPoints) {
467:                framePolygon(dc, getPolygon(pPoints));
468:            }
469:
470:            public static void framePolygon(Graphics2D dc, GeneralPath polygon) {
471:                if (polygon != null)
472:                    dc.draw(polygon);
473:            }
474:
475:            public static void fillPolygon(Graphics2D dc,
476:                    ETList<IETPoint> pPoints) {
477:                fillPolygon(dc, getPolygon(pPoints));
478:            }
479:
480:            public static void fillPolygon(Graphics2D dc, GeneralPath polygon) {
481:                if (polygon != null)
482:                    dc.fill(polygon);
483:            }
484:
485:            public static void drawPolygon(Graphics2D dc,
486:                    ETList<IETPoint> pPoints, final Color penColor,
487:                    final Color bkColor, final Stroke pen) {
488:                drawPolygon(dc, getPolygon(pPoints), penColor, bkColor, pen);
489:            }
490:
491:            /// Draws a polygon with the pen color and the brush arguments
492:            public static void drawPolygon(Graphics2D dc,
493:                    ETList<IETPoint> pPoints, final Color penColor,
494:                    int penWidth, final Color bkColor) {
495:                drawPolygon(dc, pPoints, penColor, bkColor, getLineStroke(
496:                        DrawEngineLineKindEnum.DELK_SOLID, penWidth));
497:            }
498:
499:            /// Draws a polygon with the pen color and the brush arguments
500:            public static void drawPolygon(Graphics2D dc,
501:                    ETList<IETPoint> pPoints, final Color penColor,
502:                    final Color bkColor) {
503:                Stroke currentPen = dc.getStroke() != null ? dc.getStroke()
504:                        : getLineStroke(DrawEngineLineKindEnum.DELK_SOLID, 1);
505:
506:                drawPolygon(dc, pPoints, penColor, bkColor, currentPen);
507:            }
508:
509:            public static void drawPolygon(Graphics2D dc, GeneralPath polygon,
510:                    final Color penColor, final Color bkColor) {
511:                Stroke currentPen = dc.getStroke() != null ? dc.getStroke()
512:                        : getLineStroke(DrawEngineLineKindEnum.DELK_SOLID, 1);
513:
514:                drawPolygon(dc, polygon, penColor, bkColor, currentPen);
515:            }
516:
517:            public static void drawPolygon(Graphics2D dc,
518:                    final ETList<IETPoint> pPoints, final Paint penColor,
519:                    final int penWidth, final Paint bkColor) {
520:                drawPolygon(dc, getPolygon(pPoints), penColor, bkColor,
521:                        getLineStroke(DrawEngineLineKindEnum.DELK_SOLID,
522:                                penWidth));
523:            }
524:
525:            public static void drawPolygon(Graphics2D dc,
526:                    final ETList<IETPoint> pPoints, final Paint penColor,
527:                    final Paint bkColor) {
528:                drawPolygon(dc, getPolygon(pPoints), penColor, bkColor,
529:                        getLineStroke(DrawEngineLineKindEnum.DELK_SOLID, 1));
530:            }
531:
532:            public static void drawPolygon(Graphics2D dc,
533:                    final GeneralPath polygon, final Paint penColor,
534:                    final Paint bkColor, final Stroke pen) {
535:                Paint prevColor = dc.getPaint();
536:
537:                // Select the pen, but save off the current one first.
538:                Stroke prevPen = dc.getStroke();
539:                dc.setPaint(bkColor);
540:                fillPolygon(dc, polygon);
541:                dc.setStroke(pen);
542:                dc.setPaint(penColor);
543:                framePolygon(dc, polygon);
544:                dc.setPaint(prevColor);
545:                dc.setStroke(prevPen);
546:            }
547:
548:            public static void drawPolygon(Graphics2D dc, GeneralPath polygon,
549:                    final Color penColor, final Color bkColor, final Stroke pen) {
550:                Color prevColor = dc.getColor();
551:
552:                // Select the pen, but save off the current one first.
553:                Stroke prevPen = dc.getStroke();
554:                dc.setColor(bkColor);
555:                fillPolygon(dc, polygon);
556:                dc.setStroke(pen);
557:                dc.setColor(penColor);
558:                framePolygon(dc, polygon);
559:                dc.setColor(prevColor);
560:                dc.setStroke(prevPen);
561:            }
562:
563:            /*
564:             * Get the text extent, a small margin is added to the width to avoid drawing on its bounding rectangle
565:             */
566:            public static IETSize getTextExtent(Graphics2D dc, Font font,
567:                    String text) {
568:                return dc != null && font != null ? getTextExtent(dc
569:                        .getFontMetrics(font), text) : null;
570:            }
571:
572:            /*
573:             * Get the text extent, a small margin is added to the width to avoid drawing on its bounding rectangle
574:             */
575:            public static IETSize getTextExtent(Graphics2D dc, String text) {
576:                return dc != null ? getTextExtent(dc.getFontMetrics(), text)
577:                        : null;
578:            }
579:
580:            /*
581:             * Get the text extent, a small margin is added to the width to avoid drawing on its bounding rectangle
582:             */
583:            public static IETSize getTextExtent(FontMetrics metrics, String text) {
584:                if (metrics != null && text != null) {
585:                    final int iBuffer = metrics.getMaxAdvance() / 2;
586:                    return new ETSize(metrics.stringWidth(text) + iBuffer,
587:                            metrics.getHeight());
588:                }
589:
590:                return null;
591:            }
592:
593:            /**
594:             * Draws text in the rectangle.  If the rect is less than SMALLEST_TEXT height then we don't draw
595:             */
596:            public static void drawText(Graphics2D dc, Font font, String text,
597:                    IETRect rectText) {
598:                if (dc != null) {
599:                    Font originalFont = dc.getFont();
600:                    dc.setFont(font);
601:
602:                    drawText(dc, text, rectText);
603:
604:                    dc.setFont(originalFont);
605:                }
606:            }
607:
608:            /**
609:             * Draws text in the rectangle.  If the rect is less than SMALLEST_TEXT height then we don't draw
610:             */
611:            public static void drawText(Graphics2D dc, String text,
612:                    IETRect rectText) {
613:                // TODO add all the other capabilities for this function
614:
615:                FontMetrics metrics = dc.getFontMetrics();
616:                if ((metrics != null) && (rectText.getHeight() > SMALLEST_TEXT)) {
617:                    Color prevColor = dc.getColor();
618:
619:                    final int iStartX = rectText.getLeft()
620:                            + (metrics.getMaxAdvance() / 4);
621:                    final int iBaseline = (int) (rectText.getTop() + rectText
622:                            .getHeight())
623:                            - metrics.getMaxDescent();
624:
625:                    dc.setColor(Color.BLACK);
626:                    dc.drawString(text, iStartX, iBaseline);
627:                    dc.setColor(prevColor);
628:                }
629:            }
630:
631:            /*
632:             * Return the input rectangle converted into a diamond points list, with a 90 degree rotational transform applied
633:             */
634:            public static ETList<IETPoint> getDiamondPolygonPoints(
635:                    Graphics2D dc, Rectangle rect) {
636:                IETRect boundingRect = new ETRect(rect);
637:                /*
638:                     Point centerPt = boundingRect.getCenterPoint();
639:                	ETPoint top = new ETPoint(centerPt.x, boundingRect.getTop());
640:                	ETPoint bottom = new ETPoint(centerPt.x, boundingRect.getBottom());
641:                	ETPoint left = new ETPoint(boundingRect.getLeft(), centerPt.y);
642:                	ETPoint right = new ETPoint(boundingRect.getRight(), centerPt.y);
643:                 */
644:                int maxY = Math.max(boundingRect.getTop(), boundingRect
645:                        .getBottom());
646:                int minY = Math.min(boundingRect.getTop(), boundingRect
647:                        .getBottom());
648:                int maxX = Math.max(boundingRect.getLeft(), boundingRect
649:                        .getRight());
650:                int minX = Math.min(boundingRect.getLeft(), boundingRect
651:                        .getRight());
652:
653:                ETPoint top = new ETPoint(minX
654:                        + (int) (boundingRect.getWidth() / 2), minY
655:                        + (int) boundingRect.getHeight());
656:                ETPoint bottom = new ETPoint(minX
657:                        + (int) (boundingRect.getWidth() / 2), maxY
658:                        + (int) boundingRect.getHeight());
659:                ETPoint left = new ETPoint(minX, maxY
660:                        + (int) (boundingRect.getHeight() / 2));
661:                ETPoint right = new ETPoint(maxX, left.getY());
662:
663:                ETList<IETPoint> polylinePoints = new ETArrayList<IETPoint>();
664:
665:                polylinePoints.add(top);
666:                polylinePoints.add(left);
667:                polylinePoints.add(bottom);
668:                polylinePoints.add(right);
669:                polylinePoints.add(top);
670:                return polylinePoints;
671:            }
672:
673:            /*
674:             * Return the input rectangle converted into Polygon converted into a diamond, with a 90 degree rotational transform applied
675:             */
676:            public static GeneralPath getDiamondPolygon(Graphics2D dc,
677:                    Rectangle rect) {
678:                return getPolygon(getDiamondPolygonPoints(dc, rect));
679:            }
680:
681:            /*
682:             * Returns the Pen or Stroke used to draw the Path Digraph.
683:             */
684:            public static Stroke getLineStroke(int nLineKind, float width) {
685:                return m_stokeCache.getStroke(nLineKind, width);
686:            }
687:
688:            public static void drawArrowHead(IDrawInfo drawInfo,
689:                    IETEdge pOwnerEdge, IETEdgeUI pOwnerEdgeView,
690:                    TSConstPoint fromPoint, TSConstPoint toPoint,
691:                    int nArrowheadKind, Color nEdgeBackgroundColor,
692:                    Color nSelectedEdgeBackgroundColor) {
693:                boolean selected = pOwnerEdge != null ? pOwnerEdge.isSelected()
694:                        : false;
695:
696:                IETArrowHead arrowHead = ETArrowHeadFactory
697:                        .create(nArrowheadKind);
698:                TSEColor color = new TSEColor(
699:                        selected ? nSelectedEdgeBackgroundColor
700:                                : nEdgeBackgroundColor);
701:                if (arrowHead != null)
702:                    arrowHead.draw(drawInfo, fromPoint, toPoint, color);
703:            }
704:
705:            protected static ETStrokeCache m_stokeCache = new ETStrokeCache();
706:        }
w__w___w.j_a___v___a__2s_._com___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.