001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.engine.design;
029:
030: import java.util.ArrayList;
031: import java.util.Iterator;
032: import java.util.List;
033:
034: import net.sf.jasperreports.engine.JRConstants;
035: import net.sf.jasperreports.engine.JRExpression;
036: import net.sf.jasperreports.engine.JRHyperlink;
037: import net.sf.jasperreports.engine.JRHyperlinkHelper;
038: import net.sf.jasperreports.engine.JRHyperlinkParameter;
039: import net.sf.jasperreports.engine.base.JRBaseHyperlink;
040:
041: /**
042: * Stand-alone implementation of {@link JRHyperlink JRHyperlink}
043: * which should be used for report design purposes.
044: *
045: * @author Lucian Chirita (lucianc@users.sourceforge.net)
046: * @version $Id: JRDesignHyperlink.java 1368 2006-09-01 12:01:52Z lucianc $
047: */
048: public class JRDesignHyperlink extends JRBaseHyperlink {
049:
050: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
051:
052: private List hyperlinkParameters;
053:
054: public JRDesignHyperlink() {
055: hyperlinkParameters = new ArrayList();
056: }
057:
058: /**
059: * Sets the link type as a built-in hyperlink type.
060: *
061: * @param hyperlinkType the built-in hyperlink type
062: * @see #getLinkType()
063: */
064: public void setHyperlinkType(byte hyperlinkType) {
065: setLinkType(JRHyperlinkHelper.getLinkType(hyperlinkType));
066: }
067:
068: /**
069: * Sets the hyperlink target.
070: *
071: * @param hyperlinkTarget the hyperlink target, one of
072: * <ul>
073: * <li>{@link JRHyperlink#HYPERLINK_TARGET_SELF JRHyperlink.HYPERLINK_TARGET_SELF}</li>
074: * <li>{@link JRHyperlink#HYPERLINK_TARGET_BLANK JRHyperlink.HYPERLINK_TARGET_BLANK}</li>
075: * </ul>
076: * @see #getHyperlinkTarget()
077: */
078: public void setHyperlinkTarget(byte hyperlinkTarget) {
079: this .hyperlinkTarget = hyperlinkTarget;
080: }
081:
082: /**
083: * Sets the expression that will generate the hyperlink reference URL
084: * or the referred document location.
085: * <p>
086: * This expression is used when the hyperlink type is
087: * {@link JRHyperlink#HYPERLINK_TYPE_REFERENCE JRHyperlink.HYPERLINK_TYPE_REFERENCE},
088: * {@link JRHyperlink#HYPERLINK_TYPE_REMOTE_ANCHOR JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR} or
089: * {@link JRHyperlink#HYPERLINK_TYPE_REMOTE_PAGE JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE}.
090: * The type of the expression should be <code>java.lang.String</code>
091: * </p>
092: *
093: * @param hyperlinkReferenceExpression the reference expression
094: * @see #getHyperlinkReferenceExpression()
095: */
096: public void setHyperlinkReferenceExpression(
097: JRExpression hyperlinkReferenceExpression) {
098: this .hyperlinkReferenceExpression = hyperlinkReferenceExpression;
099: }
100:
101: /**
102: * Sets the expression that will generate the referred anchor.
103: * <p>
104: * This expression is used when the hyperlink type is
105: * {@link JRHyperlink#HYPERLINK_TYPE_LOCAL_ANCHOR JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR} or
106: * {@link JRHyperlink#HYPERLINK_TYPE_REMOTE_ANCHOR JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR}.
107: * The type of the expression should be <code>java.lang.String</code>
108: * </p>
109: *
110: * @param hyperlinkAnchorExpression the anchor expression
111: * @see #getHyperlinkAnchorExpression()
112: */
113: public void setHyperlinkAnchorExpression(
114: JRExpression hyperlinkAnchorExpression) {
115: this .hyperlinkAnchorExpression = hyperlinkAnchorExpression;
116: }
117:
118: /**
119: * Sets the expression that will generate the referred page.
120: * <p>
121: * This expression is used when the hyperlink type is
122: * {@link JRHyperlink#HYPERLINK_TYPE_LOCAL_PAGE JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE} or
123: * {@link JRHyperlink#HYPERLINK_TYPE_REMOTE_PAGE JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE}.
124: * The type of the expression should be <code>java.lang.Integer</code>
125: * </p>
126: *
127: * @param hyperlinkPageExpression the page expression
128: * @see #getHyperlinkPageExpression()
129: */
130: public void setHyperlinkPageExpression(
131: JRExpression hyperlinkPageExpression) {
132: this .hyperlinkPageExpression = hyperlinkPageExpression;
133: }
134:
135: /**
136: * Sets the hyperlink type.
137: * <p>
138: * The type can be one of the built-in types
139: * (Reference, LocalAnchor, LocalPage, RemoteAnchor, RemotePage),
140: * or can be an arbitrary type.
141: * </p>
142: * @param type the hyperlink type
143: */
144: public void setLinkType(String type) {
145: this .linkType = type;
146: }
147:
148: public JRHyperlinkParameter[] getHyperlinkParameters() {
149: JRHyperlinkParameter[] parameters;
150: if (hyperlinkParameters.isEmpty()) {
151: parameters = null;
152: } else {
153: parameters = new JRHyperlinkParameter[hyperlinkParameters
154: .size()];
155: hyperlinkParameters.toArray(parameters);
156: }
157: return parameters;
158: }
159:
160: /**
161: * Returns the list of custom hyperlink parameters.
162: *
163: * @return the list of custom hyperlink parameters
164: */
165: public List getHyperlinkParametersList() {
166: return hyperlinkParameters;
167: }
168:
169: /**
170: * Adds a custom hyperlink parameter.
171: *
172: * @param parameter the parameter to add
173: */
174: public void addHyperlinkParameter(JRHyperlinkParameter parameter) {
175: hyperlinkParameters.add(parameter);
176: }
177:
178: /**
179: * Removes a custom hyperlink parameter.
180: *
181: * @param parameter the parameter to remove
182: */
183: public void removeHyperlinkParameter(JRHyperlinkParameter parameter) {
184: hyperlinkParameters.remove(parameter);
185: }
186:
187: /**
188: * Removes a custom hyperlink parameter.
189: * <p>
190: * If multiple parameters having the specified name exist, all of them
191: * will be removed
192: * </p>
193: *
194: * @param parameterName the parameter name
195: */
196: public void removeHyperlinkParameter(String parameterName) {
197: for (Iterator it = hyperlinkParameters.iterator(); it.hasNext();) {
198: JRHyperlinkParameter parameter = (JRHyperlinkParameter) it
199: .next();
200: if (parameter.getName() != null
201: && parameter.getName().equals(parameterName)) {
202: it.remove();
203: }
204: }
205: }
206:
207: /**
208: * Sets the expression which will be used to generate the hyperlink tooltip.
209: * The type of the expression should be <code>java.lang.String</code>.
210: *
211: * @param hyperlinkTooltipExpression the expression which will be used to generate the hyperlink tooltip
212: * @see #getHyperlinkTooltipExpression()
213: */
214: public void setHyperlinkTooltipExpression(
215: JRExpression hyperlinkTooltipExpression) {
216: this.hyperlinkTooltipExpression = hyperlinkTooltipExpression;
217: }
218:
219: }
|