Source Code Cross Referenced for ChartMapTag.java in  » Chart » cewolf-1.0 » de » laures » cewolf » taglib » tags » 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 » Chart » cewolf 1.0 » de.laures.cewolf.taglib.tags 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ================================================================
002:         * Cewolf : Chart enabling Web Objects Framework
003:         * ================================================================
004:         *
005:         * Project Info:  http://cewolf.sourceforge.net
006:         * Project Lead:  Guido Laures (guido@laures.de);
007:         *
008:         * (C) Copyright 2002, by Guido Laures
009:         *
010:         * This library is free software; you can redistribute it and/or modify it under the terms
011:         * of the GNU Lesser General Public License as published by the Free Software Foundation;
012:         * either 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, but WITHOUT ANY WARRANTY;
015:         * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016:         * See the GNU Lesser General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU Lesser General Public License along with this
019:         * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020:         * Boston, MA 02111-1307, USA.
021:         */
022:
023:        package de.laures.cewolf.taglib.tags;
024:
025:        import java.io.IOException;
026:        import java.io.Writer;
027:        import java.util.Iterator;
028:
029:        import javax.servlet.http.HttpServletRequest;
030:        import javax.servlet.http.HttpServletResponse;
031:        import javax.servlet.jsp.JspException;
032:
033:        import org.apache.commons.logging.Log;
034:        import org.apache.commons.logging.LogFactory;
035:        import org.jfree.chart.ChartRenderingInfo;
036:        import org.jfree.chart.entity.CategoryItemEntity;
037:        import org.jfree.chart.entity.ChartEntity;
038:        import org.jfree.chart.entity.LegendItemEntity;
039:        import org.jfree.chart.entity.PieSectionEntity;
040:        import org.jfree.chart.entity.XYItemEntity;
041:        import org.jfree.data.category.CategoryDataset;
042:        import org.jfree.data.general.Dataset;
043:        import org.jfree.data.general.PieDataset;
044:        import org.jfree.data.xy.XYDataset;
045:
046:        import de.laures.cewolf.CewolfException;
047:        import de.laures.cewolf.Configuration;
048:        import de.laures.cewolf.links.CategoryItemLinkGenerator;
049:        import de.laures.cewolf.links.LinkGenerator;
050:        import de.laures.cewolf.links.PieSectionLinkGenerator;
051:        import de.laures.cewolf.links.XYItemLinkGenerator;
052:        import de.laures.cewolf.taglib.util.BrowserDetection;
053:        import de.laures.cewolf.taglib.util.PageUtils;
054:        import de.laures.cewolf.tooltips.CategoryToolTipGenerator;
055:        import de.laures.cewolf.tooltips.PieToolTipGenerator;
056:        import de.laures.cewolf.tooltips.ToolTipGenerator;
057:        import de.laures.cewolf.tooltips.XYToolTipGenerator;
058:
059:        /**
060:         * Tag <map> which defines the tooltip and link tags.
061:         * @see DataTag
062:         * @author  Guido Laures
063:         */
064:        public class ChartMapTag extends CewolfTag {
065:
066:            private static final long serialVersionUID = -3742340487378471159L;
067:
068:            private static final Log LOG = LogFactory.getLog(ChartMapTag.class);
069:
070:            ToolTipGenerator toolTipGenerator = null;
071:            LinkGenerator linkGenerator = null;
072:
073:            // If the links provided by the JFreeChart renderer should be used.
074:            boolean useJFreeChartLinkGenerator = false;
075:            // If the tooltips provided by the JFreeChart renderer should be used.
076:            boolean useJFreeChartTooltipGenerator = false;
077:
078:            public int doStartTag() throws JspException {
079:                // Object linkGenerator = getLinkGenerator();
080:                Mapped root = (Mapped) PageUtils.findRoot(this , pageContext);
081:                root.enableMapping();
082:                String chartId = ((CewolfRootTag) root).getChartId();
083:                try {
084:                    Dataset dataset = PageUtils
085:                            .getDataset(chartId, pageContext);
086:                    Writer out = pageContext.getOut();
087:                    final boolean isIE = BrowserDetection
088:                            .isIE((HttpServletRequest) pageContext.getRequest());
089:                    if (hasToolTips()) {
090:                        enableToolTips(out, isIE);
091:                    }
092:                    out.write("<MAP name=\"" + chartId + "\">\n");
093:                    ChartRenderingInfo info = (ChartRenderingInfo) root
094:                            .getRenderingInfo();
095:                    Iterator entities = info.getEntityCollection().iterator();
096:                    while (entities.hasNext()) {
097:                        ChartEntity ce = (ChartEntity) entities.next();
098:                        out.write("\n<AREA shape=\"" + ce.getShapeType()
099:                                + "\" ");
100:                        out.write("COORDS=\"" + ce.getShapeCoords() + "\" ");
101:                        if (ce instanceof  XYItemEntity) {
102:                            dataset = ((XYItemEntity) ce).getDataset();
103:                        }
104:                        if (!(ce instanceof  LegendItemEntity)) {
105:                            if (hasToolTips()) {
106:                                writeOutToolTip(dataset, out, isIE, ce);
107:                            }
108:                            if (hasLinks()) {
109:                                writeOutLink(linkGenerator, dataset, out, ce);
110:                            }
111:                        }
112:                        out.write(">");
113:                    }
114:                } catch (IOException ioex) {
115:                    log.error(ioex);
116:                    throw new JspException(ioex.getMessage());
117:                } catch (CewolfException cwex) {
118:                    log.error(cwex);
119:                    throw new JspException(cwex.getMessage());
120:                }
121:                return EVAL_PAGE;
122:            }
123:
124:            public int doEndTag() throws JspException {
125:                // print out image map end
126:                Writer out = pageContext.getOut();
127:                try {
128:                    out.write("</MAP>");
129:                } catch (IOException ioex) {
130:                    log.error(ioex);
131:                    throw new JspException(ioex.getMessage());
132:                }
133:                return doAfterEndTag(EVAL_PAGE);
134:            }
135:
136:            public void reset() {
137:                this .toolTipGenerator = null;
138:                this .linkGenerator = null;
139:            }
140:
141:            public void writeOutLink(Object linkGen, Dataset dataset,
142:                    Writer out, ChartEntity ce) throws IOException {
143:                final String link = generateLink(dataset, ce);
144:
145:                if (null != link) {
146:                    final String href = ((HttpServletResponse) pageContext
147:                            .getResponse()).encodeURL(link);
148:                    out.write("HREF=\"" + href + "\"");
149:                }
150:            }
151:
152:            private void writeOutToolTip(Dataset dataset, Writer out,
153:                    final boolean isIE, ChartEntity ce) throws IOException,
154:                    JspException {
155:                String toolTip = generateToolTip(dataset, ce);
156:                if (null != toolTip) {
157:                    if (!isIE) {
158:                        out
159:                                .write("ONMOUSEOVER=\"return overlib('"
160:                                        + toolTip
161:                                        + "', WIDTH, '20');\" ONMOUSEOUT=\"return nd();\" ");
162:                    } else {
163:                        out.write("ALT=\"" + toolTip + "\" ");
164:                    }
165:                }
166:            }
167:
168:            public void enableToolTips(Writer out, final boolean isIE)
169:                    throws IOException {
170:                if (!PageUtils.isToolTipsEnabled(pageContext) && !isIE) {
171:                    Configuration config = Configuration
172:                            .getInstance(pageContext.getServletContext());
173:                    String overLibURL = ChartImgTag.fixAbsolutURL(config
174:                            .getOverlibURL(), pageContext);
175:                    out.write("<script language=\"JavaScript\" src=\"");
176:                    out.write(overLibURL
177:                            + "\"><!-- overLIB (c) Erik Bosrup --></script>\n");
178:                    out
179:                            .write("<div id=\"overDiv\" style=\"position:absolute; visibility:hidden; z-index:1000;\"></div>\n");
180:                    PageUtils.setToolTipsEnabled(pageContext);
181:                }
182:            }
183:
184:            private String generateLink(Dataset dataset, ChartEntity ce) {
185:                String link = null;
186:                if (useJFreeChartLinkGenerator) {
187:                    link = ce.getURLText();
188:                } else if (linkGenerator instanceof  CategoryItemLinkGenerator
189:                        || linkGenerator instanceof  XYItemLinkGenerator
190:                        || linkGenerator instanceof  PieSectionLinkGenerator) {
191:                    if (linkGenerator instanceof  CategoryItemLinkGenerator) {
192:                        if (ce instanceof  CategoryItemEntity) {
193:                            CategoryItemEntity catEnt = (CategoryItemEntity) ce;
194:                            link = ((CategoryItemLinkGenerator) linkGenerator)
195:                                    .generateLink(dataset, catEnt.getSeries(),
196:                                            catEnt.getCategory());
197:                        }
198:                    }
199:                    if (linkGenerator instanceof  XYItemLinkGenerator) {
200:                        if (ce instanceof  XYItemEntity) {
201:                            XYItemEntity xyEnt = (XYItemEntity) ce;
202:                            link = ((XYItemLinkGenerator) linkGenerator)
203:                                    .generateLink(dataset, xyEnt
204:                                            .getSeriesIndex(), xyEnt.getItem());
205:                        } else {
206:                            // Note; there is a simple ChartEntity also passed since Jfreechart 1.0rc1, that is ignored
207:                            LOG
208:                                    .debug("Link entity skipped, not XYItemEntity.class:"
209:                                            + ce);
210:                        }
211:                    }
212:                    if (linkGenerator instanceof  PieSectionLinkGenerator) {
213:                        if (ce instanceof  PieSectionEntity) {
214:                            PieSectionEntity pieEnt = (PieSectionEntity) ce;
215:                            link = ((PieSectionLinkGenerator) linkGenerator)
216:                                    .generateLink(dataset, pieEnt
217:                                            .getSectionKey());
218:                        }
219:                    }
220:                }
221:                return link;
222:            }
223:
224:            private String generateToolTip(Dataset dataset, ChartEntity ce)
225:                    throws JspException {
226:                String tooltip = null;
227:                if (useJFreeChartTooltipGenerator) {
228:                    tooltip = ce.getToolTipText();
229:                } else if (toolTipGenerator instanceof  CategoryToolTipGenerator
230:                        || toolTipGenerator instanceof  XYToolTipGenerator
231:                        || toolTipGenerator instanceof  PieToolTipGenerator) {
232:                    if (toolTipGenerator instanceof  CategoryToolTipGenerator) {
233:                        if (ce instanceof  CategoryItemEntity) {
234:                            CategoryItemEntity catEnt = (CategoryItemEntity) ce;
235:                            tooltip = ((CategoryToolTipGenerator) toolTipGenerator)
236:                                    .generateToolTip((CategoryDataset) dataset,
237:                                            catEnt.getSeries(), catEnt
238:                                                    .getCategoryIndex());
239:                        }
240:                    }
241:
242:                    if (toolTipGenerator instanceof  XYToolTipGenerator) {
243:                        if (ce instanceof  XYItemEntity) {
244:                            XYItemEntity xyEnt = (XYItemEntity) ce;
245:                            tooltip = ((XYToolTipGenerator) toolTipGenerator)
246:                                    .generateToolTip((XYDataset) dataset, xyEnt
247:                                            .getSeriesIndex(), xyEnt.getItem());
248:                        }
249:                    }
250:
251:                    if (toolTipGenerator instanceof  PieToolTipGenerator) {
252:                        if (ce instanceof  PieSectionEntity) {
253:                            PieSectionEntity pieEnt = (PieSectionEntity) ce;
254:                            PieDataset ds = (PieDataset) dataset;
255:                            final int index = pieEnt.getSectionIndex();
256:                            tooltip = ((PieToolTipGenerator) toolTipGenerator)
257:                                    .generateToolTip(ds, ds.getKey(index),
258:                                            index);
259:                        }
260:                    }
261:                } else {
262:                    // throw because category is unknown
263:                    throw new JspException(
264:                            "TooltipgGenerator of class "
265:                                    + toolTipGenerator.getClass().getName()
266:                                    + " does not implement the appropriate TooltipGenerator interface for entity type "
267:                                    + ce.getClass().getName());
268:                }
269:                return tooltip;
270:            }
271:
272:            private boolean hasToolTips() throws JspException {
273:                if (toolTipGenerator != null && useJFreeChartTooltipGenerator) {
274:                    throw new JspException(
275:                            "Can't have both tooltipGenerator and useJFreeChartTooltipGenerator parameters specified!");
276:                }
277:                return toolTipGenerator != null
278:                        || useJFreeChartTooltipGenerator;
279:            }
280:
281:            public void setTooltipgeneratorid(String id) {
282:                this .toolTipGenerator = (ToolTipGenerator) pageContext
283:                        .findAttribute(id);
284:            }
285:
286:            private boolean hasLinks() throws JspException {
287:                if (linkGenerator != null && useJFreeChartLinkGenerator) {
288:                    throw new JspException(
289:                            "Can't have both linkGenerator and useJFreeChartLinkGenerator parameters specified!");
290:                }
291:                return linkGenerator != null || useJFreeChartLinkGenerator;
292:            }
293:
294:            public void setLinkgeneratorid(String id) {
295:                this .linkGenerator = (LinkGenerator) pageContext
296:                        .findAttribute(id);
297:            }
298:
299:            /**
300:             * Setter of the useJFreeChartLinkGenerator field.
301:             * @param useJFreeChartLinkGenerator the useJFreeChartLinkGenerator to set.
302:             */
303:            public void setUseJFreeChartLinkGenerator(
304:                    boolean useJFreeChartLinkGenerator) {
305:                this .useJFreeChartLinkGenerator = useJFreeChartLinkGenerator;
306:            }
307:
308:            /**
309:             * Setter of the useJFreeChartTooltipGenerator field.
310:             * @param useJFreeChartTooltipGenerator the useJFreeChartTooltipGenerator to set.
311:             */
312:            public void setUseJFreeChartTooltipGenerator(
313:                    boolean useJFreeChartTooltipGenerator) {
314:                this.useJFreeChartTooltipGenerator = useJFreeChartTooltipGenerator;
315:            }
316:
317:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.