Source Code Cross Referenced for Glyph.java in  » GIS » udig-1.1 » net » refractions » udig » ui » graphics » 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.ui.graphics 
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.ui.graphics;
018:
019:        import java.awt.Color;
020:
021:        import net.refractions.udig.ui.Drawing;
022:        import net.refractions.udig.ui.PlatformGIS;
023:
024:        import org.eclipse.jface.resource.ImageDescriptor;
025:        import org.eclipse.swt.SWT;
026:        import org.eclipse.swt.graphics.GC;
027:        import org.eclipse.swt.graphics.Image;
028:        import org.eclipse.swt.graphics.ImageData;
029:        import org.eclipse.swt.graphics.PaletteData;
030:        import org.eclipse.swt.graphics.RGB;
031:        import org.eclipse.swt.widgets.Display;
032:        import org.eclipse.ui.PlatformUI;
033:        import org.geotools.feature.Feature;
034:        import org.geotools.feature.FeatureType;
035:        import org.geotools.styling.Rule;
036:
037:        import com.vividsolutions.jts.geom.LineString;
038:        import com.vividsolutions.jts.geom.LinearRing;
039:        import com.vividsolutions.jts.geom.MultiLineString;
040:        import com.vividsolutions.jts.geom.MultiPoint;
041:        import com.vividsolutions.jts.geom.MultiPolygon;
042:        import com.vividsolutions.jts.geom.Point;
043:        import com.vividsolutions.jts.geom.Polygon;
044:
045:        /**
046:         * Utility methods to create common ImageDescriptors.
047:         * 
048:         * @author jgarnett
049:         * @since 0.7.0
050:         */
051:        public class Glyph {
052:
053:            private final static int DEFAULT_WIDTH = 16;
054:            private final static int DEFAULT_HEIGHT = 16;
055:            static final int DEFAULT_DEPTH = 24;
056:
057:            public static ImageDescriptor push(final ImageDescriptor icon) {
058:                return new ImageDescriptor() {
059:                    @Override
060:                    public ImageData getImageData() {
061:                        ImageData push = icon.getImageData();
062:                        if (!push.palette.isDirect) {
063:                            RGB[] rgb = new RGB[push.palette.colors.length];
064:                            System.arraycopy(push.palette.colors, 0, rgb, 0,
065:                                    push.palette.colors.length);
066:                            rgb[push.transparentPixel] = Display.getDefault()
067:                                    .getSystemColor(
068:                                            SWT.COLOR_WIDGET_NORMAL_SHADOW)
069:                                    .getRGB();
070:                            push.palette = new PaletteData(rgb);
071:                            push.transparentPixel = -1;
072:
073:                            createBorder(push);
074:
075:                            return push;
076:                        }
077:                        int pushColour = push.palette.getPixel(Display
078:                                .getDefault().getSystemColor(
079:                                        SWT.COLOR_WIDGET_NORMAL_SHADOW)
080:                                .getRGB());
081:
082:                        for (int x = 0; x < push.width; x++)
083:                            for (int y = 0; y < push.height; y++) {
084:                                if (push.getAlpha(x, y) == 0) {
085:                                    push.setAlpha(x, y, 255);
086:                                    push.setPixel(x, y, pushColour);
087:                                }
088:                                if (push.getPixel(x, y) == push.transparentPixel) {
089:                                    push.setPixel(x, y, pushColour);
090:                                }
091:                            }
092:                        return push;
093:                    }
094:
095:                    private void createBorder(ImageData push) {
096:                        for (int y = 0; y < push.height; y++) {
097:                            for (int x = 0; x < push.width; x++) {
098:                                if (y == 0 || x == 0)
099:                                    push.setPixel(x, y, 0);
100:                            }
101:                        }
102:                    }
103:
104:                };
105:            }
106:
107:            /**
108:             * Create a transparent image, this is a *real* resource against the
109:             * provided display.
110:             * 
111:             * @param display
112:             * @param rgb
113:             * @return
114:             */
115:            public static Image image(Display display) {
116:                PaletteData palette = new PaletteData(0xFF0000, 0xFF00, 0xFF);
117:                ImageData imageData = new ImageData(DEFAULT_WIDTH,
118:                        DEFAULT_HEIGHT, DEFAULT_DEPTH, palette);
119:                imageData.transparentPixel = palette.getPixel(display
120:                        .getSystemColor(SWT.COLOR_WIDGET_BACKGROUND).getRGB());
121:
122:                return new Image(display, imageData);
123:            }
124:
125:            public final static int WHITE = 0xFFFFFF;
126:            private static final Color DEFAULT_BORDER = new Color(0, 0, 0);
127:            private static final Color DEFAULT_FILL = new Color(27, 158, 119,
128:                    255);
129:            // public final static int CLEAR = 0x220000|0x2200|0x22;
130:
131:            /** Utility class for working with Images, Features and Styles */
132:            static Drawing d = Drawing.create();
133:
134:            /**
135:             * Convert Color to to SWT 
136:             * @param color 
137:             * 
138:             * @return SWT Color
139:             */
140:            static org.eclipse.swt.graphics.Color color(Color color) {
141:                Display display = PlatformUI.getWorkbench().getDisplay();
142:                return new org.eclipse.swt.graphics.Color(display, color
143:                        .getRed(), color.getGreen(), color.getBlue());
144:            }
145:
146:            static ImageData extractImageDataAndDispose(Image image) {
147:                ImageData data = (ImageData) image.getImageData();
148:                image.dispose();
149:                return data;
150:            }
151:
152:            /**
153:             * Render a icon based on the current style.
154:             * <p>
155:             * Simple render of point in the center of the screen.
156:             * </p>
157:             * @param style
158:             * @return Icon representing style applyed to an image
159:             */
160:            public static ImageDescriptor point(final Rule rule) {
161:                return new ImageDescriptor() {
162:                    public ImageData getImageData() {
163:                        Image image = null;
164:                        try {
165:                            Display display = PlatformUI.getWorkbench()
166:                                    .getDisplay();
167:
168:                            image = new Image(display, DEFAULT_WIDTH,
169:                                    DEFAULT_HEIGHT);
170:                            d.drawDirect(image, display, d.feature(d
171:                                    .point(7, 7)), rule);
172:                            return extractImageDataAndDispose(image);
173:                        } catch (RuntimeException ex) {
174:                            if (image != null && !image.isDisposed()) {
175:                                image.dispose();
176:                            }
177:                            throw ex;
178:                        }
179:                    }
180:                };
181:            }
182:
183:            /**
184:             * Icon for point data in the provided color
185:             * <p>
186:             * XXX: Suggest point( SLD style ) at a later time.
187:             * </p>
188:             * @param color
189:             * @param fill
190:             * @return ImageDescriptor
191:             */
192:            public static ImageDescriptor point(final Color color,
193:                    final Color fill) {
194:                return new ImageDescriptor() {
195:                    public ImageData getImageData() {
196:                        Image swtImage = null;
197:                        try {
198:                            Display display = PlatformUI.getWorkbench()
199:                                    .getDisplay();
200:
201:                            swtImage = new Image(display, DEFAULT_WIDTH,
202:                                    DEFAULT_HEIGHT);
203:                            GC gc = new GC(swtImage);
204:                            gc.setAntialias(SWT.ON);
205:                            gc.setLineCap(SWT.CAP_SQUARE);
206:                            gc.setLineStyle(SWT.LINE_SOLID);
207:                            gc.setLineWidth(1);
208:
209:                            Color c = color;
210:                            Color f = fill;
211:
212:                            if (c == null && f == null) { // only need default if both are empty                    
213:                                c = Color.BLACK;
214:                                f = Color.LIGHT_GRAY;
215:                            }
216:                            if (f != null) {
217:                                gc.setBackground(color(f));
218:                                gc.setAlpha(f.getAlpha());
219:                                gc.fillRectangle(8, 7, 5, 5);
220:                            }
221:                            if (c != null) {
222:                                gc.setForeground(color(c));
223:                                gc.setAlpha(c.getAlpha());
224:                                gc.drawRectangle(8, 7, 5, 5);
225:                            }
226:                            ImageData clone = (ImageData) swtImage
227:                                    .getImageData().clone();
228:                            swtImage.dispose();
229:                            gc.dispose();
230:                            return clone;
231:                        } catch (RuntimeException ex) {
232:                            if (swtImage != null && !swtImage.isDisposed()) {
233:                                swtImage.dispose();
234:                            }
235:                            throw ex;
236:                        }
237:                    }
238:                };
239:            }
240:
241:            /**
242:             * Complex render of Geometry allowing presentation of point, line and polygon styles.
243:             * <p>
244:             * Layout:<pre><code>
245:             *    1 2 3 4 5 6 7 8 9101112131415
246:             *   0
247:             *  1          LL                 L  
248:             *  2          L L                L
249:             *  3         L  L               L                   
250:             *  4        L    L             L  
251:             *  5        L     L            L  
252:             *  6       L      L           L   
253:             *  7      L        L         L    
254:             *  8      L         L        L    
255:             *  9     L          L       L     
256:             * 10    L            L     L      
257:             * 11    L             L    L      
258:             * 12   L              L   L       
259:             * 13  L                L L        
260:             * 14  L                 LL            
261:             * 15
262:             * </code><pre>
263:             * </p>
264:             * @param style 
265:             * @return Icon representing geometry style
266:             */
267:            public static ImageDescriptor line(final Rule rule) {
268:                final Feature feature = d.feature(d.line(new int[] { 1, 14, 6,
269:                        0, 11, 14, 15, 1 }));
270:                return new ImageDescriptor() {
271:                    public ImageData getImageData() {
272:                        Image image = null;
273:                        try {
274:                            Display display = PlatformUI.getWorkbench()
275:                                    .getDisplay();
276:
277:                            image = new Image(display, DEFAULT_WIDTH,
278:                                    DEFAULT_HEIGHT);
279:                            d.drawDirect(image, display, feature, rule);
280:                            return extractImageDataAndDispose(image);
281:                        } catch (RuntimeException ex) {
282:                            if (image != null && !image.isDisposed()) {
283:                                image.dispose();
284:                            }
285:                            throw ex;
286:                        }
287:                    }
288:                };
289:            }
290:
291:            /**
292:             * Icon for linestring in the provided color and width.
293:             * <p>
294:             * XXX: Suggest line( SLD style ) at a later time.
295:             * </p>
296:             * @param black
297:             * @return Icon
298:             */
299:            public static ImageDescriptor line(Color color, int width) {
300:                Color color2 = color;
301:                int width2 = width;
302:                if (color2 == null) {
303:                    color2 = Color.BLACK;
304:                }
305:
306:                if (width2 <= 0) {
307:                    width2 = 1;
308:                }
309:
310:                final int finalWidth = width2;
311:                final Color finalColor = color2;
312:
313:                return new ImageDescriptor() {
314:                    public ImageData getImageData() {
315:                        Image swtImage = null;
316:                        try {
317:                            Display display = PlatformUI.getWorkbench()
318:                                    .getDisplay();
319:
320:                            swtImage = new Image(display, DEFAULT_WIDTH,
321:                                    DEFAULT_HEIGHT);
322:                            GC gc = new GC(swtImage);
323:                            gc.setAntialias(SWT.ON);
324:
325:                            gc.setLineCap(SWT.CAP_SQUARE);
326:                            gc.setLineStyle(SWT.LINE_SOLID);
327:
328:                            gc.setForeground(color(finalColor));
329:                            gc.setAlpha(finalColor.getAlpha());
330:                            gc.setLineWidth(finalWidth);
331:                            gc.drawLine(1, 13, 6, 2);
332:                            gc.drawLine(6, 2, 9, 13);
333:                            gc.drawLine(9, 13, 14, 2);
334:
335:                            ImageData clone = (ImageData) swtImage
336:                                    .getImageData().clone();
337:
338:                            swtImage.dispose();
339:
340:                            return clone;
341:                        } catch (RuntimeException ex) {
342:                            if (swtImage != null && !swtImage.isDisposed()) {
343:                                swtImage.dispose();
344:                            }
345:                            throw ex;
346:                        }
347:                    }
348:                };
349:            }
350:
351:            /**
352:             * Complex render of Geometry allowing presentation of point, line and polygon styles.
353:             * <p>
354:             * Layout:<pre><code>
355:             *    1 2 3 4 5 6 7 8 9101112131415
356:             *   0
357:             *  1 
358:             *  2
359:             *  3           L                 L                  
360:             *  4       p  L L           PPPPPP
361:             *  5         L   L     PPPPP   L p
362:             *  6        L     LPPPP       L  p
363:             *  7       L    PPPL         L   p
364:             *  8      L   PP    L       L    p
365:             *  9     L   P       L     L     P
366:             * 10    L   P         L   L      P
367:             * 11   L   P           L L       P
368:             * 12  L   P             L        P
369:             * 13      p                      P
370:             * 14      PPPPPPPPPPPPPPPPPPPPPPPP    
371:             * 15
372:             * </code><pre>
373:             * </p>
374:             * @param style 
375:             * @return Icon representing geometry style
376:             */
377:            public static ImageDescriptor geometry(final Rule rule) {
378:                return new ImageDescriptor() {
379:                    public ImageData getImageData() {
380:                        Image image = null;
381:                        try {
382:                            Display display = PlatformUI.getWorkbench()
383:                                    .getDisplay();
384:
385:                            image = new Image(display, DEFAULT_WIDTH,
386:                                    DEFAULT_HEIGHT);
387:                            //                d.drawDirect( image, display,
388:                            //                        d.feature(d.polygon(new int[]{4,14, 5,9, 7,6, 12,4, 15,3, 15,14})),
389:                            //                        rule );
390:                            d.drawDirect(image, display, d.feature(d
391:                                    .line(new int[] { 0, 12, 6, 3, 11, 12, 15,
392:                                            3 })), rule);
393:                            d.drawDirect(image, display, d.feature(d
394:                                    .point(4, 4)), rule);
395:
396:                            return extractImageDataAndDispose(image);
397:                        } catch (RuntimeException ex) {
398:                            if (image != null && !image.isDisposed()) {
399:                                image.dispose();
400:                            }
401:                            throw ex;
402:                        }
403:                    }
404:                };
405:            }
406:
407:            /**
408:             * Icon for generic Geometry or Geometry Collection.
409:             * @param color 
410:             * @param fill 
411:             * 
412:             * @return Icon
413:             */
414:            public static ImageDescriptor geometry(final Color color,
415:                    final Color fill) {
416:                return new ImageDescriptor() {
417:                    public ImageData getImageData() {
418:
419:                        Image swtImage = null;
420:                        try {
421:                            Display display = PlatformUI.getWorkbench()
422:                                    .getDisplay();
423:
424:                            swtImage = new Image(display, DEFAULT_WIDTH,
425:                                    DEFAULT_HEIGHT);
426:                            GC gc = new GC(swtImage);
427:                            gc.setAntialias(SWT.ON);
428:                            gc.setLineCap(SWT.CAP_SQUARE);
429:                            gc.setLineStyle(SWT.LINE_SOLID);
430:                            gc.setLineWidth(1);
431:
432:                            Color c = color;
433:                            Color f = fill;
434:
435:                            if (c == null && f == null) { // only need default if both are empty                    
436:                                c = Color.BLACK;
437:                                f = Color.LIGHT_GRAY;
438:                            }
439:                            if (f != null) {
440:                                gc.setBackground(color(f));
441:                                gc.setAlpha(f.getAlpha());
442:                                gc.fillRoundRectangle(2, 1, 13, 13, 2, 2);
443:                            }
444:                            if (c != null) {
445:                                gc.setForeground(color(c));
446:                                gc.setAlpha(c.getAlpha());
447:                                gc.drawRoundRectangle(2, 1, 13, 13, 2, 2);
448:                            }
449:                            ImageData clone = (ImageData) swtImage
450:                                    .getImageData().clone();
451:                            swtImage.dispose();
452:
453:                            return clone;
454:                        } catch (RuntimeException ex) {
455:                            if (swtImage != null && !swtImage.isDisposed()) {
456:                                swtImage.dispose();
457:                            }
458:                            throw ex;
459:                        }
460:                    }
461:                };
462:            }
463:
464:            /**
465:             * Render of a polygon allowing style.
466:             * <p>
467:             * Layout:<pre><code>
468:             *    1 2 3 4 5 6 7 8 9101112131415
469:             *   0
470:             *  1             
471:             *  2                      PPPPPPPP
472:             *  3                PPPPPP       P                  
473:             *  4           PPPPPP            P
474:             *  5        PPP                  p
475:             *  6      PP                     p
476:             *  7     P                       p
477:             *  8    P                        p
478:             *  9   P                         P
479:             * 10   P                         P
480:             * 11  P                          P
481:             * 12  P                          P
482:             * 13  P                          P
483:             * 14  PPPPPPPPPPPPPPPPPPPPPPPPPPPP    
484:             * 15
485:             * </code><pre>
486:             * </p>
487:             * @param style 
488:             * @return Icon representing geometry style
489:             */
490:            public static ImageDescriptor polygon(final Rule rule) {
491:                return new ImageDescriptor() {
492:                    public ImageData getImageData() {
493:                        final Image[] image = new Image[1];
494:                        try {
495:                            final Display display = PlatformUI.getWorkbench()
496:                                    .getDisplay();
497:                            PlatformGIS.syncInDisplayThread(display,
498:                                    new Runnable() {
499:                                        public void run() {
500:                                            image[0] = new Image(display,
501:                                                    DEFAULT_WIDTH,
502:                                                    DEFAULT_HEIGHT);
503:                                            d.drawDirect(image[0], display, d
504:                                                    .feature(d
505:                                                            .polygon(new int[] {
506:                                                                    1, 14, 3,
507:                                                                    9, 4, 6, 6,
508:                                                                    4, 9, 3,
509:                                                                    14, 1, 14,
510:                                                                    14 })),
511:                                                    rule);
512:                                        }
513:                                    });
514:
515:                            return extractImageDataAndDispose(image[0]);
516:                        } catch (RuntimeException ex) {
517:                            if (image != null && !image[0].isDisposed()) {
518:                                image[0].dispose();
519:                            }
520:                            throw ex;
521:                        }
522:                    }
523:                };
524:            }
525:
526:            /**
527:             * Icon for polygon in provided border, fill and width
528:             * 
529:             * @param black
530:             * @param gray
531:             * @param i
532:             * @return
533:             */
534:            public static ImageDescriptor polygon(final Color color,
535:                    final Color fill, final int width) {
536:                return new ImageDescriptor() {
537:                    public ImageData getImageData() {
538:                        Image swtImage = null;
539:                        try {
540:                            Display display = PlatformUI.getWorkbench()
541:                                    .getDisplay();
542:
543:                            swtImage = new Image(display, DEFAULT_WIDTH,
544:                                    DEFAULT_HEIGHT);
545:                            GC gc = new GC(swtImage);
546:                            gc.setAntialias(SWT.ON);
547:                            gc.setLineCap(SWT.CAP_SQUARE);
548:                            gc.setLineStyle(SWT.LINE_SOLID);
549:
550:                            org.eclipse.swt.graphics.Color t = null;
551:
552:                            Color c = color;
553:                            Color f = fill;
554:                            int w = width > 0 ? width : 1;
555:
556:                            if (c == null && f == null) { // only need default if both are empty                    
557:                                c = Color.BLACK;
558:                                f = Color.LIGHT_GRAY;
559:                            }
560:                            if (f != null) {
561:                                gc.setBackground(t = color(f));
562:                                t.dispose();
563:                            }
564:                            if (c != null) {
565:                                gc.setForeground(t = color(c));
566:                                t.dispose();
567:                            }
568:                            gc.setLineWidth(w);
569:
570:                            int[] points = { 1, 14, 3, 9, 4, 6, 6, 4, 9, 3, 14,
571:                                    1, 14, 14 };
572:
573:                            gc.setAlpha(f.getAlpha());
574:                            gc.fillPolygon(points);
575:                            gc.setAlpha(c.getAlpha());
576:                            gc.drawPolygon(points);
577:
578:                            ImageData clone = (ImageData) swtImage
579:                                    .getImageData().clone();
580:                            swtImage.dispose();
581:                            return clone;
582:                        } finally {
583:                            if (swtImage != null && !swtImage.isDisposed())
584:                                swtImage.dispose();
585:                        }
586:                    }
587:                };
588:            }
589:
590:            /**
591:             * Icon for grid data, small grid made up of provided colors.
592:             * <p>
593:             * Layout:<pre><code>
594:             *    0 1 2 3 4 5 6 7 8 9 101112131415
595:             *  0  
596:             *  1   AAAAAAAAAAAAABBBBBBBBBBBBBB           
597:             *  2   AAAAAAAAAAAAABBBBBBBBBBBBBB
598:             *  3   AAAAAAAAAAAAABBBBBBBBBBBBBB                  
599:             *  4   AAAAAAAAAAAAABBBBBBBBBBBBBB
600:             *  5   AAAAAAAAAAAAABBBBBBBBBBBBBB
601:             *  6   AAAAAAAAAAAAABBBBBBBBBBBBBB
602:             *  7   AAAAAAAAAAAAABBBBBBBBBBBBBB
603:             *  8   CCCCCCCCCCCCCDDDDDDDDDDDDDD
604:             *  9   CCCCCCCCCCCCCDDDDDDDDDDDDDD
605:             * 10   CCCCCCCCCCCCCDDDDDDDDDDDDDD
606:             * 11   CCCCCCCCCCCCCDDDDDDDDDDDDDD
607:             * 12   CCCCCCCCCCCCCDDDDDDDDDDDDDD
608:             * 13   CCCCCCCCCCCCCDDDDDDDDDDDDDD
609:             * 14   CCCCCCCCCCCCCDDDDDDDDDDDDDD
610:             * 15
611:             * </code><pre>
612:             * </p>
613:             * @param a
614:             * @param b
615:             * @param c
616:             * @param d1
617:             * @return Icon representing a grid
618:             * 
619:             */
620:            public static ImageDescriptor grid(Color a, Color b, Color c,
621:                    Color d1) {
622:                if (a == null) {
623:                    a = Color.BLACK;
624:                }
625:                if (b == null) {
626:                    b = Color.DARK_GRAY;
627:                }
628:
629:                if (c == null) {
630:                    c = Color.LIGHT_GRAY;
631:                }
632:
633:                if (d1 == null) {
634:                    d1 = Color.WHITE;
635:                }
636:                final Color finalA = a;
637:                final Color finalB = b;
638:                final Color finalC = c;
639:                final Color finalD = d1;
640:
641:                return new ImageDescriptor() {
642:                    public ImageData getImageData() {
643:
644:                        Display display = PlatformUI.getWorkbench()
645:                                .getDisplay();
646:
647:                        Image swtImage = new Image(display, DEFAULT_WIDTH,
648:                                DEFAULT_HEIGHT);
649:                        GC gc = new GC(swtImage);
650:                        gc.setAntialias(SWT.ON);
651:                        org.eclipse.swt.graphics.Color c = null;
652:
653:                        gc.setBackground(c = color(finalA));
654:                        gc.fillRectangle(0, 0, 7, 7);
655:                        c.dispose();
656:
657:                        gc.setBackground(c = color(finalB));
658:                        gc.fillRectangle(7, 0, 15, 7);
659:                        c.dispose();
660:
661:                        gc.setBackground(c = color(finalC));
662:                        gc.fillRectangle(0, 7, 7, 15);
663:                        c.dispose();
664:
665:                        gc.setBackground(c = color(finalD));
666:                        gc.fillRectangle(7, 7, 15, 15);
667:                        c.dispose();
668:
669:                        gc.setForeground(c = color(Color.BLACK));
670:                        gc.drawRectangle(0, 0, 7, 7);
671:                        gc.drawRectangle(0, 0, 15, 7);
672:                        gc.drawRectangle(0, 7, 7, 15);
673:                        gc.drawRectangle(0, 7, 15, 15);
674:                        c.dispose();
675:
676:                        ImageData clone = (ImageData) swtImage.getImageData()
677:                                .clone();
678:                        swtImage.dispose();
679:
680:                        return clone;
681:                    }
682:                };
683:            }
684:
685:            /**
686:             * Render of a color swatch allowing style.
687:             * <p>
688:             * Layout:<pre><code>
689:             *    0 1 2 3 4 5 6 7 8 9 101112131415
690:             *  0  
691:             *  1  dddddddddddddddddddddddddddd           
692:             *  2 dCCCCCCCCCCCCCCCCCCCCCcCCCCCCd
693:             *  3 dCCCCCCCCCCCCCCCCCCCCCCcCCCCCd                  
694:             *  4 dCCCCCCCCCCCCCCCCCCCCCCCcCCCCd
695:             *  5 dCCCCCCCCCCCCCCCCCCCCCCCCcCCCd
696:             *  6 dCCCCCCCCCCCCCCCCCCCCCCCCCcCCd
697:             *  7 dCCCCCCCCCCCCCCCCCCCCCCCCCCcCd
698:             *  8 dCcCCCCCCCCCCCCCCCCCCCCCCCCCCd
699:             *  9 dCCcCCCCCCCCCCCCCCCCCCCCCCCCCd
700:             * 10 dCCCcCCCCCCCCCCCCCCCCCCCCCCCCd
701:             * 11 dCCCCcCCCCCCCCCCCCCCCCCCCCCCCd
702:             * 12 dCCCCCcCCCCCCCCCCCCCCCCCCCCCCd
703:             * 13 ddCCCCCcCCCCCCCCCCCCCCCCCCCCdd
704:             * 14  ddddddddddddddddddddddddddd
705:             * 15    
706:             * </code><pre>
707:             * </p>
708:             * @param style 
709:             * @return Icon representing geometry style
710:             */
711:            public static ImageDescriptor swatch(Color c) {
712:                Color c2 = c;
713:                if (c == null) {
714:                    c2 = Color.GRAY;
715:                } else {
716:                    c2 = c;
717:                }
718:
719:                final Color color = c2;
720:
721:                int saturation = color.getRed() + color.getGreen()
722:                        + color.getBlue();
723:                final Color contrast = saturation < 384 ? c.brighter() : c
724:                        .darker();
725:                return new ImageDescriptor() {
726:                    public ImageData getImageData() {
727:
728:                        Display display = PlatformUI.getWorkbench()
729:                                .getDisplay();
730:
731:                        Image swtImage = new Image(display, DEFAULT_WIDTH,
732:                                DEFAULT_HEIGHT);
733:                        GC gc = new GC(swtImage);
734:                        gc.setAntialias(SWT.ON);
735:                        org.eclipse.swt.graphics.Color swtColor = color(color);
736:                        try {
737:                            gc.setBackground(swtColor);
738:                            gc.fillRoundRectangle(0, 0, 14, 14, 2, 2);
739:                        } finally {
740:                            swtColor.dispose();
741:                        }
742:                        try {
743:                            swtColor = color(contrast);
744:                            gc.setForeground(swtColor);
745:                            gc.drawRoundRectangle(0, 0, 14, 14, 2, 2);
746:                        } finally {
747:                            swtColor.dispose();
748:                        }
749:                        ImageData clone = (ImageData) swtImage.getImageData()
750:                                .clone();
751:                        swtImage.dispose();
752:
753:                        return clone;
754:                    }
755:                };
756:            }
757:
758:            /**
759:             * Icon for grid data, small grid made up of provided colors.
760:             * Layout:<pre><code>
761:             *    0 1 2 3 4 5 6 7 8 9 101112131415
762:             *  0  
763:             *  1 AABBCDEEFfGgHhIiJjKkllmmnnoopp           
764:             *  2 AABBCDEEFfGgHhIiJjKkllmmnnoopp
765:             *  3 AABBCDEEFfGgHhIiJjKkllmmnnoopp                 
766:             *  4 AABBCDEEFfGgHhIiJjKkllmmnnoopp
767:             *  5 AABBCDEEFfGgHhIiJjKkllmmnnoopp
768:             *  6 AABBCDEEFfGgHhIiJjKkllmmnnoopp
769:             *  7 AABBCDEEFfGgHhIiJjKkllmmnnoopp
770:             *  8 AABBCDEEFfGgHhIiJjKkllmmnnoopp
771:             *  9 AABBCDEEFfGgHhIiJjKkllmmnnoopp
772:             * 10 AABBCDEEFfGgHhIiJjKkllmmnnoopp
773:             * 11 AABBCDEEFfGgHhIiJjKkllmmnnoopp
774:             * 12 AABBCDEEFfGgHhIiJjKkllmmnnoopp
775:             * 14 AABBCDEEFfGgHhIiJjKkllmmnnoopp
776:             * 15
777:             * </code><pre>
778:             * </p>
779:             * @param c palette of colors
780:             * @return Icon representing a palette
781:             * 
782:             */
783:            public static ImageDescriptor palette(Color c[]) {
784:                final Color[] colors = new Color[16];
785:                Color color = Color.GRAY;
786:                if (c == null) {
787:                    for (int i = 0; i < 16; i++)
788:                        color = Color.GRAY;
789:                } else {
790:                    for (int i = 0; i < 16; i++) {
791:                        int lookup = (i * c.length) / 16;
792:                        if (c[lookup] != null)
793:                            color = c[lookup];
794:                        colors[i] = color;
795:                    }
796:                }
797:                return new ImageDescriptor() {
798:                    public ImageData getImageData() {
799:
800:                        Display display = PlatformUI.getWorkbench()
801:                                .getDisplay();
802:
803:                        Image swtImage = new Image(display, DEFAULT_WIDTH,
804:                                DEFAULT_HEIGHT);
805:                        GC gc = new GC(swtImage);
806:                        gc.setAntialias(SWT.ON);
807:                        org.eclipse.swt.graphics.Color swtColor = null;
808:
809:                        for (int i = 0; i < 16; i++) {
810:                            try {
811:                                swtColor = color(colors[i]);
812:                                gc.setForeground(swtColor);
813:                                gc.drawLine(i, 0, i, 15);
814:                            } finally {
815:                                swtColor.dispose();
816:                            }
817:                        }
818:                        try {
819:                            swtColor = color(Color.GRAY);
820:                            gc.setForeground(swtColor);
821:                            gc.drawRoundRectangle(0, 0, 14, 14, 2, 2);
822:                        } finally {
823:                            swtColor.dispose();
824:                        }
825:
826:                        ImageData clone = (ImageData) swtImage.getImageData()
827:                                .clone();
828:                        swtImage.dispose();
829:
830:                        return clone;
831:                    }
832:                };
833:            }
834:
835:            public static ImageDescriptor icon(FeatureType ft) {
836:                if (ft == null || ft.getDefaultGeometry() == null)
837:                    return null;
838:
839:                if (Point.class.isAssignableFrom(ft.getDefaultGeometry()
840:                        .getType())
841:                        || MultiPoint.class.isAssignableFrom(ft
842:                                .getDefaultGeometry().getType())) {
843:                    return point(DEFAULT_BORDER, DEFAULT_FILL);
844:                }
845:
846:                if (LineString.class.isAssignableFrom(ft.getDefaultGeometry()
847:                        .getType())
848:                        || MultiLineString.class.isAssignableFrom(ft
849:                                .getDefaultGeometry().getType())
850:                        || LinearRing.class.isAssignableFrom(ft
851:                                .getDefaultGeometry().getType())) {
852:                    return line(DEFAULT_BORDER, 1);
853:                }
854:
855:                if (Polygon.class.isAssignableFrom(ft.getDefaultGeometry()
856:                        .getType())
857:                        || MultiPolygon.class.isAssignableFrom(ft
858:                                .getDefaultGeometry().getType())) {
859:                    return polygon(DEFAULT_BORDER, DEFAULT_FILL, 1);
860:                }
861:
862:                return geometry(DEFAULT_BORDER, DEFAULT_FILL);
863:            }
864:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.