001: /*
002: * Copyright 2005-2007 jWic group (http://www.jwic.de)
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: *
016: * de.jwic.ecolib.util.ImageDef
017: * Created on 12.03.2007
018: * $Id: ImageRef.java,v 1.3 2007/04/13 00:18:02 cosote Exp $
019: */
020: package de.jwic.base;
021:
022: import java.io.Serializable;
023:
024: /**
025: * References the location of an Image. Used by UI elements to generate
026: * urls to an image.
027: * @author Florian Lippisch
028: */
029: public class ImageRef implements Serializable {
030:
031: private boolean bundled = false;
032: private String path = "";
033: private int width = -1;
034: private int height = -1;
035:
036: /**
037: * Default constructor.
038: *
039: */
040: public ImageRef() {
041:
042: }
043:
044: /**
045: * @param package1
046: * @param string
047: */
048: public ImageRef(Package srcPackage, String resourceName) {
049: this (srcPackage, resourceName, -1, -1);
050: }
051:
052: /**
053: * @param package1
054: * @param string
055: */
056: public ImageRef(Package srcPackage, String resourceName, int width,
057: int height) {
058: bundled = true;
059: String packageName = srcPackage.getName();
060: path = JWicRuntime.getJWicRuntime().getContextPath() + "/cp/"
061: + packageName.replace('.', '/') + "/" + resourceName;
062: this .width = width;
063: this .height = height;
064: }
065:
066: /**
067: * @param string
068: */
069: public ImageRef(String pathName) {
070: bundled = false;
071: if (pathName.startsWith("/")) {
072: path = JWicRuntime.getJWicRuntime().getContextPath()
073: + pathName;
074: } else {
075: path = pathName; // relative URLs are stored as is.
076: }
077: }
078:
079: /**
080: * @param string
081: */
082: public ImageRef(String pathName, int width, int height) {
083: bundled = false;
084: if (pathName.startsWith("/")) {
085: path = JWicRuntime.getJWicRuntime().getContextPath()
086: + pathName;
087: } else {
088: path = pathName; // relative URLs are stored as is.
089: }
090: this .width = width;
091: this .height = height;
092: }
093:
094: /**
095: * @return the bundled
096: */
097: public boolean isBundled() {
098: return bundled;
099: }
100:
101: /**
102: * @param bundled the bundled to set
103: */
104: public void setBundled(boolean bundled) {
105: this .bundled = bundled;
106: }
107:
108: /**
109: * @return the path
110: */
111: public String getPath() {
112: return path;
113: }
114:
115: /**
116: * @param path the path to set
117: */
118: public void setPath(String path) {
119: this .path = path;
120: }
121:
122: /**
123: * @return the height
124: */
125: public int getHeight() {
126: return height;
127: }
128:
129: /**
130: * @param height the height to set
131: */
132: public void setHeight(int height) {
133: this .height = height;
134: }
135:
136: /**
137: * @return the width
138: */
139: public int getWidth() {
140: return width;
141: }
142:
143: /**
144: * @param width the width to set
145: */
146: public void setWidth(int width) {
147: this .width = width;
148: }
149:
150: /**
151: * Returns the IMG HTML tag.
152: * @return
153: */
154: public String toImgTag() {
155: return toImgTag(width, height);
156: }
157:
158: /**
159: * Returns the IMG HTML tag.
160: * @param width
161: * @param height
162: * @return
163: */
164: public String toImgTag(int width, int height) {
165: return "<IMG src=\"" + path + "\" border=\"0\""
166: + (width != -1 ? " width=\"" + width + "\"" : "")
167: + (height != -1 ? " height=\"" + height + "\"" : "")
168: + "/>";
169: }
170:
171: }
|