1 45 46 package org.jfree.chart.imagemap; 47 48 import java.io.IOException ; 49 import java.io.PrintWriter ; 50 51 import org.jfree.chart.ChartRenderingInfo; 52 import org.jfree.chart.entity.ChartEntity; 53 import org.jfree.chart.entity.EntityCollection; 54 import org.jfree.util.StringUtils; 55 56 62 public class ImageMapUtilities { 63 64 73 public static void writeImageMap(PrintWriter writer, String name, 74 ChartRenderingInfo info) 75 throws IOException { 76 77 ImageMapUtilities.writeImageMap( 79 writer, name, info, 80 new StandardToolTipTagFragmentGenerator(), 81 new StandardURLTagFragmentGenerator() 82 ); 83 84 } 85 86 97 public static void writeImageMap(PrintWriter writer, 98 String name, 99 ChartRenderingInfo info, 100 boolean useOverLibForToolTips) 101 throws IOException { 102 103 ToolTipTagFragmentGenerator toolTipTagFragmentGenerator = null; 104 if (useOverLibForToolTips) { 105 toolTipTagFragmentGenerator 106 = new OverLIBToolTipTagFragmentGenerator(); 107 } 108 else { 109 toolTipTagFragmentGenerator 110 = new StandardToolTipTagFragmentGenerator(); 111 } 112 ImageMapUtilities.writeImageMap( 113 writer, name, info, toolTipTagFragmentGenerator, 114 new StandardURLTagFragmentGenerator() 115 ); 116 117 } 118 119 130 public static void writeImageMap(PrintWriter writer, String name, 131 ChartRenderingInfo info, 132 ToolTipTagFragmentGenerator toolTipTagFragmentGenerator, 133 URLTagFragmentGenerator urlTagFragmentGenerator) 134 throws IOException { 135 136 writer.println( 137 ImageMapUtilities.getImageMap( 138 name, info, toolTipTagFragmentGenerator, urlTagFragmentGenerator 139 ) 140 ); 141 } 142 143 152 public static String getImageMap(String name, ChartRenderingInfo info) { 153 return ImageMapUtilities.getImageMap( 154 name, 155 info, 156 new StandardToolTipTagFragmentGenerator(), 157 new StandardURLTagFragmentGenerator() 158 ); 159 } 160 161 172 public static String getImageMap(String name, ChartRenderingInfo info, 173 ToolTipTagFragmentGenerator toolTipTagFragmentGenerator, 174 URLTagFragmentGenerator urlTagFragmentGenerator) { 175 176 StringBuffer sb = new StringBuffer (); 177 sb.append("<map id=\"" + name + "\" name=\"" + name + "\">"); 178 sb.append(StringUtils.getLineSeparator()); 179 EntityCollection entities = info.getEntityCollection(); 180 if (entities != null) { 181 int count = entities.getEntityCount(); 182 for (int i = count - 1; i >= 0; i--) { 183 ChartEntity entity = entities.getEntity(i); 184 if (entity.getToolTipText() != null 185 || entity.getURLText() != null) { 186 String area = entity.getImageMapAreaTag( 187 toolTipTagFragmentGenerator, urlTagFragmentGenerator 188 ); 189 if (area.length() > 0) { 190 sb.append(area); 191 sb.append(StringUtils.getLineSeparator()); 192 } 193 } 194 } 195 } 196 sb.append("</map>"); 197 return sb.toString(); 198 199 } 200 201 } 202 | Popular Tags |