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: package com.sun.rave.web.ui.component;
042:
043: import java.beans.Beans;
044: import java.util.List;
045:
046: /**
047: *
048: */
049: public class ImageHyperlink extends ImageHyperlinkBase {
050:
051: /**
052: * Used for identifying the facet in the facet map associated with this component
053: * This is used as a suffix combined with the id of the component.
054: */
055: final protected String IMAGE_FACET_SUFFIX = "_image"; //NOI18N
056:
057: /**
058: * Get Image Facet for this ImageHyperlink. This facet will always reset the
059: * properties on embedded facet. This facet is not meant to be overridden
060: * by others, but is only used as a storage bin for keeping the image associated
061: * with the hyperlink
062: * @return an {@link ImageComponent} to render
063: */
064: public ImageComponent getImageFacet() {
065: ImageComponent image = null;
066: String facetName;
067: String facetId = getId();
068:
069: String imageURL = getImageURL();
070: String icon = getIcon();
071:
072: if (imageURL != null || icon != null) {
073: if (facetId == null) {
074: facetId = IMAGE_FACET_SUFFIX;
075: } else {
076: facetId += IMAGE_FACET_SUFFIX;
077: }
078:
079: image = (ImageComponent) getFacet(facetId);
080: if (image == null) {
081: if (imageURL != null) {
082: image = new ImageComponent();
083: } else {
084: image = new Icon();
085: }
086: }
087:
088: //always reset all the properties
089:
090: image.setIcon(icon);
091: image.setUrl(imageURL);
092:
093: setAttributes(facetId, image);
094: }
095:
096: return image;
097: }
098:
099: protected void setAttributes(String facetId, ImageComponent image) {
100: //must reset the id always due to a side effect in JSF and putting
101: //components in a table.
102:
103: image.setId(facetId);
104:
105: // align
106: String align = getAlign();
107: if (align != null) {
108: image.setAlign(align);
109: }
110: // border
111: int dim = getBorder();
112: if (dim >= 0) {
113: image.setBorder(dim);
114: }
115: // description
116: String description = getAlt();
117: if (description != null) {
118: image.setAlt(description);
119: }
120: // height
121: dim = getHeight();
122: if (dim >= 0) {
123: image.setHeight(dim);
124: }
125: // hspace
126: dim = getHspace();
127: if (dim >= 0) {
128: image.setHspace(dim);
129: }
130: // vspace
131: dim = getVspace();
132: if (dim >= 0) {
133: image.setVspace(dim);
134: }
135: // width
136: dim = getWidth();
137: if (dim >= 0) {
138: image.setWidth(dim);
139: }
140: // disabled (based on parent)
141: Boolean disabled = (Boolean) getAttributes().get("disabled"); //NOI18N
142: if (disabled != null) {
143: image.getAttributes().put("disabled",
144: String.valueOf(disabled)); //NOI18N
145: }
146: // <RAVE>
147: // getFacets().put(facetId, image);
148: if (!Beans.isDesignTime())
149: getFacets().put(facetId, image);
150: // </RAVE>
151: }
152:
153: }
|