KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nextapp > echo2 > webcontainer > propertyrender > FillImageRender


1 /*
2  * This file is part of the Echo Web Application Framework (hereinafter "Echo").
3  * Copyright (C) 2002-2005 NextApp, Inc.
4  *
5  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * Alternatively, the contents of this file may be used under the terms of
18  * either the GNU General Public License Version 2 or later (the "GPL"), or
19  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20  * in which case the provisions of the GPL or the LGPL are applicable instead
21  * of those above. If you wish to allow use of your version of this file only
22  * under the terms of either the GPL or the LGPL, and not to allow others to
23  * use your version of this file under the terms of the MPL, indicate your
24  * decision by deleting the provisions above and replace them with the notice
25  * and other provisions required by the GPL or the LGPL. If you do not delete
26  * the provisions above, a recipient may use your version of this file under
27  * the terms of any one of the MPL, the GPL or the LGPL.
28  */

29
30 package nextapp.echo2.webcontainer.propertyrender;
31
32 import nextapp.echo2.app.FillImage;
33 import nextapp.echo2.app.Component;
34 import nextapp.echo2.webcontainer.RenderContext;
35 import nextapp.echo2.webcontainer.image.ImageRenderSupport;
36 import nextapp.echo2.webcontainer.image.ImageTools;
37 import nextapp.echo2.webrender.ClientProperties;
38 import nextapp.echo2.webrender.output.CssStyle;
39
40 /**
41  * Utility class for rendering <code>nextapp.echo2.FillImage</code>
42  * properties to CSS.
43  */

44 public class FillImageRender {
45     
46     /**
47      * A flag indicating that the 'fixed' property of the <code>FillImage</code>
48      * should be ignored.
49      */

50     public static final int FLAG_DISABLE_FIXED_MODE = 0x1;
51     
52     /**
53      * A flag indicating that the Internet Explorer 6.0 PNG AlphaImageLoader
54      * filter should be enabled for Internet Explorer clients that might
55      * "benefit" from it. Enabling this flag can however have serious
56      * unacceptable side-effects for Internet Explorer clients:
57      * If the flag is enabled, Images will be <b>SCALED</b> to span
58      * the entire region. IE will ignore any positioning/repeat information
59      * if this flag is enabled. Further, the browser may in fact not allow
60      * the user to click on any content within the region.
61      * Use of this flag is thus strongly discouraged in most all situations.
62      * <p>
63      * This flag has no effect for clients other than Internet Explorer 6.0.
64      */

65     public static final int FLAG_ENABLE_IE_PNG_ALPHA_FILTER = 0x2;
66     
67     /**
68      * Renders a <code>FillImage</code> to a CSS style.
69      *
70      * @param cssStyle the CSS style to be updated
71      * @param rc the relevant <code>RenderContext</code>
72      * @param irs a <code>ComponentSynchronizePeer</code> providing
73      * <code>ImageRenderSupport</code>
74      * @param component the relevant <code>Component</code>
75      * @param imageId the image id of the background image
76      * @param fillImage the <code>FillImage</code> property value
77      * @param flags optional image rendering flags (see <code>FLAG_XXX</code>
78      * constants)
79      */

80     public static void renderToStyle(CssStyle cssStyle, RenderContext rc, ImageRenderSupport irs,
81             Component component, String JavaDoc imageId, FillImage fillImage, int flags) {
82         
83         if (fillImage == null) {
84             return;
85         }
86         String JavaDoc imageUri = ImageTools.getUri(rc, irs, component, imageId);
87         
88         if ((flags & FLAG_ENABLE_IE_PNG_ALPHA_FILTER) != 0 && rc.getContainerInstance().getClientProperties().getBoolean(
89                 ClientProperties.PROPRIETARY_IE_PNG_ALPHA_FILTER_REQUIRED)) {
90             cssStyle.setAttribute("background-image", "none");
91             cssStyle.setAttribute("filter",
92                     "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imageUri + "', sizingMethod='scale')");
93         } else {
94             cssStyle.setAttribute("background-image", "url(" + imageUri + ")");
95         }
96
97         if (rc.getContainerInstance().getClientProperties().getBoolean(
98                 ClientProperties.QUIRK_CSS_BACKGROUND_ATTACHMENT_USE_FIXED)) {
99             cssStyle.setAttribute("background-attachment", "fixed");
100         }
101         
102         switch (fillImage.getRepeat()) {
103         case FillImage.NO_REPEAT:
104             cssStyle.setAttribute("background-repeat", "no-repeat");
105             break;
106         case FillImage.REPEAT_HORIZONTAL:
107             cssStyle.setAttribute("background-repeat", "repeat-x");
108             break;
109         case FillImage.REPEAT_VERTICAL:
110             cssStyle.setAttribute("background-repeat", "repeat-y");
111             break;
112         default:
113             cssStyle.setAttribute("background-repeat", "repeat");
114         }
115         if (fillImage.getHorizontalOffset() != null || fillImage.getVerticalOffset() != null) {
116             StringBuffer JavaDoc positionText = new StringBuffer JavaDoc();
117             if (fillImage.getHorizontalOffset() == null) {
118                 positionText.append("0px");
119             } else {
120                 positionText.append(ExtentRender.renderCssAttributeValue(fillImage.getHorizontalOffset()));
121             }
122             positionText.append(" " );
123             if (fillImage.getVerticalOffset() == null) {
124                 positionText.append("0px");
125             } else {
126                 positionText.append(ExtentRender.renderCssAttributeValue(fillImage.getVerticalOffset()));
127             }
128             cssStyle.setAttribute("background-position", positionText.toString());
129         }
130     }
131     
132     /** Non-instantiable class. */
133     private FillImageRender() { }
134 }
135
Popular Tags