Source Code Cross Referenced for DecorationOverlayIcon.java in  » IDE-Eclipse » jface » org » eclipse » jface » viewers » 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 Eclipse » jface » org.eclipse.jface.viewers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.jface.viewers;
011:
012:        import java.util.Arrays;
013:
014:        import org.eclipse.jface.resource.CompositeImageDescriptor;
015:        import org.eclipse.jface.resource.ImageDescriptor;
016:        import org.eclipse.swt.graphics.*;
017:
018:        /**
019:         * A <code>DecorationOverlayIcon</code> is an image descriptor that can be used
020:         * to overlay decoration images on to the 4 corner quadrants of a base image.
021:         * The four quadrants are {@link IDecoration#TOP_LEFT}, {@link IDecoration#TOP_RIGHT},
022:         * {@link IDecoration#BOTTOM_LEFT} and {@link IDecoration#BOTTOM_RIGHT}. Additionally,
023:         * the overlay can be used to provide an underlay corresponding to {@link IDecoration#UNDERLAY}. 
024:         * 
025:         * @since 3.3
026:         * @see IDecoration
027:         */
028:        public class DecorationOverlayIcon extends CompositeImageDescriptor {
029:
030:            // the base image
031:            private Image base;
032:
033:            // the overlay images
034:            private ImageDescriptor[] overlays;
035:
036:            // the size
037:            private Point size;
038:
039:            /**
040:             * Create the decoration overlay for the base image using the array of
041:             * provided overlays. The indices of the array correspond to the values
042:             * of the 5 overlay constants defined on {@link IDecoration} 
043:             * ({@link IDecoration#TOP_LEFT}, {@link IDecoration#TOP_RIGHT},
044:             * {@link IDecoration#BOTTOM_LEFT}, {@link IDecoration#BOTTOM_RIGHT} 
045:             * and{@link IDecoration#UNDERLAY}).
046:             * 
047:             * @param baseImage the base image
048:             * @param overlaysArray the overlay images
049:             * @param sizeValue the size of the resulting image
050:             */
051:            public DecorationOverlayIcon(Image baseImage,
052:                    ImageDescriptor[] overlaysArray, Point sizeValue) {
053:                this .base = baseImage;
054:                this .overlays = overlaysArray;
055:                this .size = sizeValue;
056:            }
057:
058:            /**
059:             * Create the decoration overlay for the base image using the array of
060:             * provided overlays. The indices of the array correspond to the values
061:             * of the 5 overlay constants defined on {@link IDecoration} 
062:             * ({@link IDecoration#TOP_LEFT}, {@link IDecoration#TOP_RIGHT},
063:             * {@link IDecoration#BOTTOM_LEFT}, {@link IDecoration#BOTTOM_RIGHT} 
064:             * and {@link IDecoration#UNDERLAY}).
065:             * 
066:             * @param baseImage the base image
067:             * @param overlaysArray the overlay images
068:             */
069:            public DecorationOverlayIcon(Image baseImage,
070:                    ImageDescriptor[] overlaysArray) {
071:                this (baseImage, overlaysArray, new Point(
072:                        baseImage.getBounds().width,
073:                        baseImage.getBounds().height));
074:            }
075:
076:            /**
077:             * Create a decoration overlay icon that will place the given overlay icon in
078:             * the given quadrant of the base image.
079:             * @param baseImage the base image
080:             * @param overlayImage the overlay image
081:             * @param quadrant the quadrant (one of {@link IDecoration} 
082:             * ({@link IDecoration#TOP_LEFT}, {@link IDecoration#TOP_RIGHT},
083:             * {@link IDecoration#BOTTOM_LEFT}, {@link IDecoration#BOTTOM_RIGHT} 
084:             * or {@link IDecoration#UNDERLAY})
085:             */
086:            public DecorationOverlayIcon(Image baseImage,
087:                    ImageDescriptor overlayImage, int quadrant) {
088:                this (baseImage, createArrayFrom(overlayImage, quadrant));
089:            }
090:
091:            /**
092:             * Convert the given image and quadrant into the proper input array.
093:             * @param overlayImage the overlay image
094:             * @param quadrant the quadrant
095:             * @return an array with the given image in the proper quadrant
096:             */
097:            private static ImageDescriptor[] createArrayFrom(
098:                    ImageDescriptor overlayImage, int quadrant) {
099:                ImageDescriptor[] descs = new ImageDescriptor[] { null, null,
100:                        null, null, null };
101:                descs[quadrant] = overlayImage;
102:                return descs;
103:            }
104:
105:            /**
106:             * Draw the overlays for the receiver.
107:             * @param overlaysArray 
108:             */
109:            private void drawOverlays(ImageDescriptor[] overlaysArray) {
110:
111:                for (int i = 0; i < overlays.length; i++) {
112:                    ImageDescriptor overlay = overlaysArray[i];
113:                    if (overlay == null) {
114:                        continue;
115:                    }
116:                    ImageData overlayData = overlay.getImageData();
117:                    //Use the missing descriptor if it is not there.
118:                    if (overlayData == null) {
119:                        overlayData = ImageDescriptor
120:                                .getMissingImageDescriptor().getImageData();
121:                    }
122:                    switch (i) {
123:                    case IDecoration.TOP_LEFT:
124:                        drawImage(overlayData, 0, 0);
125:                        break;
126:                    case IDecoration.TOP_RIGHT:
127:                        drawImage(overlayData, size.x - overlayData.width, 0);
128:                        break;
129:                    case IDecoration.BOTTOM_LEFT:
130:                        drawImage(overlayData, 0, size.y - overlayData.height);
131:                        break;
132:                    case IDecoration.BOTTOM_RIGHT:
133:                        drawImage(overlayData, size.x - overlayData.width,
134:                                size.y - overlayData.height);
135:                        break;
136:                    }
137:                }
138:            }
139:
140:            /* (non-Javadoc)
141:             * @see java.lang.Object#equals(java.lang.Object)
142:             */
143:            public boolean equals(Object o) {
144:                if (!(o instanceof  DecorationOverlayIcon)) {
145:                    return false;
146:                }
147:                DecorationOverlayIcon other = (DecorationOverlayIcon) o;
148:                return base.equals(other.base)
149:                        && Arrays.equals(overlays, other.overlays);
150:            }
151:
152:            /* (non-Javadoc)
153:             * @see java.lang.Object#hashCode()
154:             */
155:            public int hashCode() {
156:                int code = System.identityHashCode(base);
157:                for (int i = 0; i < overlays.length; i++) {
158:                    if (overlays[i] != null) {
159:                        code ^= overlays[i].hashCode();
160:                    }
161:                }
162:                return code;
163:            }
164:
165:            /* (non-Javadoc)
166:             * @see org.eclipse.jface.resource.CompositeImageDescriptor#drawCompositeImage(int, int)
167:             */
168:            protected void drawCompositeImage(int width, int height) {
169:                if (overlays.length > IDecoration.UNDERLAY) {
170:                    ImageDescriptor underlay = overlays[IDecoration.UNDERLAY];
171:                    if (underlay != null) {
172:                        drawImage(underlay.getImageData(), 0, 0);
173:                    }
174:                }
175:                drawImage(base.getImageData(), 0, 0);
176:                drawOverlays(overlays);
177:            }
178:
179:            /* (non-Javadoc)
180:             * @see org.eclipse.jface.resource.CompositeImageDescriptor#getSize()
181:             */
182:            protected Point getSize() {
183:                return size;
184:            }
185:
186:            /* (non-Javadoc)
187:             * @see org.eclipse.jface.resource.CompositeImageDescriptor#getTransparentPixel()
188:             */
189:            protected int getTransparentPixel() {
190:                return base.getImageData().transparentPixel;
191:            }
192:
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.