Source Code Cross Referenced for SubstanceNoiseWatermark.java in  » Swing-Library » substance-look-feel » org » jvnet » substance » watermark » 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 » Swing Library » substance look feel » org.jvnet.substance.watermark 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.jvnet.substance.watermark;
002:
003:        import java.awt.*;
004:
005:        import org.jvnet.substance.SubstanceLookAndFeel;
006:        import org.jvnet.substance.painter.noise.NoiseFactory;
007:        import org.jvnet.substance.painter.noise.NoiseFilter;
008:        import org.jvnet.substance.utils.*;
009:
010:        /**
011:         * Base class for noise-based watermarks. This class is part of officially
012:         * supported API.
013:         * 
014:         * @author Kirill Grouchnikov
015:         */
016:        public class SubstanceNoiseWatermark implements  SubstanceWatermark {
017:            /**
018:             * Watermark image (screen-sized).
019:             */
020:            private Image watermarkImage = null;
021:
022:            /**
023:             * Display name of <code>this</code> watermark.
024:             */
025:            protected String displayName;
026:
027:            /**
028:             * Factor along X axis.
029:             */
030:            protected double xFactor;
031:
032:            /**
033:             * Factor along Y axis.
034:             */
035:            protected double yFactor;
036:
037:            /**
038:             * Indicates whether <code>this</code> watermark is based on constant Z
039:             * values.
040:             */
041:            protected boolean hasConstantZ;
042:
043:            /**
044:             * Noise filter of <code>this</code> watermark.
045:             */
046:            protected NoiseFilter noiseFilter;
047:
048:            /**
049:             * Indicates whether the resulting image (after applying the
050:             * {@link #noiseFilter}) should be blurred.
051:             */
052:            protected boolean toBlur;
053:
054:            /**
055:             * Creates a new noise-based watermark.
056:             * 
057:             * @param displayName
058:             *            Display name of <code>this</code> watermark.
059:             * @param xFactor
060:             *            Factor along X axis.
061:             * @param yFactor
062:             *            Factor along Y axis.
063:             * @param hasConstantZ
064:             *            Indicates whether <code>this</code> watermark is based on
065:             *            constant Z values.
066:             * @param noiseFilter
067:             *            Noise filter of <code>this</code> watermark.
068:             * @param toBlur
069:             *            Indicates whether the resulting image should be blurred.
070:             */
071:            public SubstanceNoiseWatermark(String displayName, double xFactor,
072:                    double yFactor, boolean hasConstantZ,
073:                    NoiseFilter noiseFilter, boolean toBlur) {
074:                this .displayName = displayName;
075:                this .xFactor = xFactor;
076:                this .yFactor = yFactor;
077:                this .hasConstantZ = hasConstantZ;
078:                this .noiseFilter = noiseFilter;
079:                this .toBlur = toBlur;
080:            }
081:
082:            /*
083:             * (non-Javadoc)
084:             * 
085:             * @see org.jvnet.substance.watermark.SubstanceWatermark#drawWatermarkImage(java.awt.Graphics,
086:             *      java.awt.Component, int, int, int, int)
087:             */
088:            public void drawWatermarkImage(Graphics graphics, Component c,
089:                    int x, int y, int width, int height) {
090:                if (!c.isShowing())
091:                    return;
092:                int dx = c.getLocationOnScreen().x;
093:                int dy = c.getLocationOnScreen().y;
094:                graphics.drawImage(this .watermarkImage, x, y, x + width, y
095:                        + height, x + dx, y + dy, x + dx + width, y + dy
096:                        + height, null);
097:            }
098:
099:            /*
100:             * (non-Javadoc)
101:             * 
102:             * @see org.jvnet.substance.watermark.SubstanceWatermark#updateWatermarkImage()
103:             */
104:            public boolean updateWatermarkImage() {
105:                // fix by Chris for bug 67 - support for multiple screens
106:                Rectangle virtualBounds = new Rectangle();
107:                GraphicsEnvironment ge = GraphicsEnvironment
108:                        .getLocalGraphicsEnvironment();
109:                GraphicsDevice[] gds = ge.getScreenDevices();
110:                for (GraphicsDevice gd : gds) {
111:                    GraphicsConfiguration gc = gd.getDefaultConfiguration();
112:                    virtualBounds = virtualBounds.union(gc.getBounds());
113:                }
114:
115:                int screenWidth = virtualBounds.width;
116:                int screenHeight = virtualBounds.height;
117:                this .watermarkImage = SubstanceCoreUtilities.getBlankImage(
118:                        screenWidth, screenHeight);
119:
120:                Graphics2D graphics = (Graphics2D) this .watermarkImage
121:                        .getGraphics().create();
122:
123:                boolean status = this .drawWatermarkImage(graphics, 0, 0,
124:                        screenWidth, screenHeight, false);
125:                graphics.dispose();
126:                return status;
127:            }
128:
129:            /*
130:             * (non-Javadoc)
131:             * 
132:             * @see org.jvnet.substance.watermark.SubstanceWatermark#getDisplayName()
133:             */
134:            public String getDisplayName() {
135:                return this .displayName;
136:            }
137:
138:            /*
139:             * (non-Javadoc)
140:             * 
141:             * @see org.jvnet.substance.watermark.SubstanceWatermark#isDependingOnTheme()
142:             */
143:            public boolean isDependingOnTheme() {
144:                return true;
145:            }
146:
147:            /*
148:             * (non-Javadoc)
149:             * 
150:             * @see org.jvnet.substance.watermark.SubstanceWatermark#previewWatermark(java.awt.Graphics,
151:             *      int, int, int, int)
152:             */
153:            public void previewWatermark(Graphics g, int x, int y, int width,
154:                    int height) {
155:                this .drawWatermarkImage((Graphics2D) g, x, y, width, height,
156:                        true);
157:            }
158:
159:            /**
160:             * Draws the specified portion of the watermark image.
161:             * 
162:             * @param graphics
163:             *            Graphic context.
164:             * @param x
165:             *            the <i>x</i> coordinate of the watermark to be drawn.
166:             * @param y
167:             *            The <i>y</i> coordinate of the watermark to be drawn.
168:             * @param width
169:             *            The width of the watermark to be drawn.
170:             * @param height
171:             *            The height of the watermark to be drawn.
172:             * @param isPreview
173:             *            Indication whether the result is a preview image.
174:             * @return Indication whether the draw succeeded.
175:             */
176:            private boolean drawWatermarkImage(Graphics2D graphics, int x,
177:                    int y, int width, int height, boolean isPreview) {
178:                if (isPreview) {
179:                    graphics.drawImage(NoiseFactory.getNoiseImage(
180:                            SubstanceThemeUtilities.getTheme(null,
181:                                    ComponentState.DEFAULT).getFirstTheme(),
182:                            SubstanceThemeUtilities.getTheme(null,
183:                                    ComponentState.DEFAULT).getSecondTheme(),
184:                            width, height, this .xFactor, this .yFactor,
185:                            this .hasConstantZ, this .noiseFilter, this .toBlur,
186:                            true), x, y, null);
187:                } else {
188:                    int alpha = SubstanceCoreUtilities
189:                            .isThemeDark(SubstanceLookAndFeel.getTheme()) ? 200
190:                            : 50;
191:                    graphics.setComposite(AlphaComposite.getInstance(
192:                            AlphaComposite.SRC_OVER, alpha / 255.0f));
193:                    graphics.drawImage(NoiseFactory.getNoiseImage(
194:                            SubstanceLookAndFeel.getTheme().getFirstTheme()
195:                                    .getWatermarkTheme(), SubstanceLookAndFeel
196:                                    .getTheme().getSecondTheme()
197:                                    .getWatermarkTheme(), width, height,
198:                            this .xFactor, this .yFactor, this .hasConstantZ,
199:                            this .noiseFilter, this .toBlur, false), x, y, null);
200:                }
201:                return true;
202:            }
203:
204:            /*
205:             * (non-Javadoc)
206:             * 
207:             * @see org.jvnet.substance.watermark.SubstanceWatermark#dispose()
208:             */
209:            public void dispose() {
210:                this.watermarkImage = null;
211:            }
212:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.