org.eclipse.birt.chart.device.svg_3.7.2.v20120213

ibute(scriptEvent, 
        wrapJS(bDblClick, 
        callbackFunction.toString()));
      if (!scripts.contains(script))
      {
        svg_g2d.addScript(generateCallBackMethodName(funcName) + 
          "{" + script + "}");
        scripts.add(script);
      }
    }
  }
  
  private void addURLRedirectJSCode(Element elm, StructureSource src, String scriptEvent, boolean bDblClick, Action action)
  {
    ActionValue av = action.getValue();
    if ((av instanceof URLValue))
    {
      URLValue urlValue = (URLValue)av;
      
      setURLValueAttributes(urlValue, 
        elm, 
        src, 
        scriptEvent, 
        bDblClick);
    }
    else if ((av instanceof MultiURLValues))
    {
      MultiURLValues muv = (MultiURLValues)av;
      
      setTooltipForURLRedirect(elm, src, muv.getTooltip());
      
      List<URLValue> validURLValues = MultiActionValuesScriptGenerator.getValidURLValues(muv);
      int size = validURLValues.size();
      if (size == 1) {
        setURLValueAttributes((URLValue)validURLValues.get(0), 
          elm, 
          src, 
          scriptEvent, 
          bDblClick);
      } else if (size > 1) {
        setMultiURLValuesAttributes(muv, 
          elm, 
          src, 
          scriptEvent, 
          bDblClick);
      }
    }
  }
  
  private static StringBuilder getPropertiesJS(EMap<String, String> propMap)
  {
    StringBuilder sb = new StringBuilder();
    for (Map.Entry<String, String> entry : propMap.entrySet())
    {
      String key = (String)entry.getKey();
      String properties = (String)entry.getValue();
      if (MenuStylesKeyType.MENU.getName().equals(key)) {
        sb.append("\t menuInfo.menuStyles = '" + CSSHelper.getStylingHyphenFormat(properties) + "';\n");
      } else if (MenuStylesKeyType.MENU_ITEM.getName().equals(key)) {
        sb.append("\t menuInfo.menuItemStyles = '" + CSSHelper.getStylingHyphenFormat(properties) + "';\n");
      } else if (MenuStylesKeyType.ON_MOUSE_OVER.getName().equals(key)) {
        sb.append("\t menuInfo.mouseOverStyles = '" + CSSHelper.getStylingHyphenFormat(properties) + "';\n");
      } else if (MenuStylesKeyType.ON_MOUSE_OUT.getName().equals(key)) {
        sb.append("\tmenuInfo.mouseOutStyles = '" + CSSHelper.getStylingHyphenFormat(properties) + "';\n");
      }
    }
    return sb;
  }
  
  private String getMultiActionsCallbackContent(MultipleActions actions)
  {
    StringBuilder sb = new StringBuilder();
    
    sb.append("\n\t var menuInfo = new BirtChartMenuInfo();\n");
    
    EMap<String, String> propMap = actions.getPropertiesMap();
    sb.append(getPropertiesJS(propMap).toString());
    int i = 0;
    for (Action subAction : MultiActionValuesScriptGenerator.getValidActions(actions))
    {
      int typeValue = subAction.getType().getValue();
      switch (typeValue)
      {
      case 0: 
        sb = MultiActionValuesScriptGenerator.getURLValueJS(sb, i, (URLValue)subAction.getValue(), SVGEncoderAdapter.getInstance());
        break;
      case 3: 
        sb = MultiActionValuesScriptGenerator.getScriptValueJS(sb, 
          i, 
          (ScriptValue)subAction.getValue(), 
          getULocale());
        break;
      case 2: 
        sb = MultiActionValuesScriptGenerator.getVisualJS(sb, i, subAction.getValue(), "BirtChartInteractivityActions.TOGGLE_VISIBILITY");
        break;
      case 6: 
        sb = MultiActionValuesScriptGenerator.getVisualJS(sb, i, subAction.getValue(), "BirtChartInteractivityActions.TOGGLE_DATA_POINT_VISIBILITY");
        break;
      case 4: 
        sb = MultiActionValuesScriptGenerator.getVisualJS(sb, i, subAction.getValue(), "BirtChartInteractivityActions.HIGHLIGHT");
        break;
      case 1: 
        sb = MultiActionValuesScriptGenerator.getVisualJS(sb, i, subAction.getValue(), "BirtChartInteractivityActions.SHOW_TOOLTIP");
      }
      i++;
    }
    MultiActionValuesScriptGenerator.appendInteractivityVariables(sb);
    
    sb.append("\n");
    sb.append("if ( menuInfo.menuItemNames.length == 1 ) {\n");
    sb.append("\tBirtChartActionsMenu.executeMenuActionImpl( evt, menuInfo.menuItems[0], menuInfo );\n");
    sb.append("} else { \n");
    sb.append("  BirtChartActionsMenu.show( evt, source, menuInfo ); ");
    sb.append("}\n");
    
    return sb.toString();
  }
  
  private void setMultiURLValuesAttributes(MultiURLValues values, Element elm, StructureSource src, String scriptEvent, boolean bDblClick)
  {
    StringBuilder sb = new StringBuilder();
    sb.append("\n\t var menuInfo = new BirtChartMenuInfo();\n");
    
    EMap<String, String> propMap = values.getPropertiesMap();
    sb.append(getPropertiesJS(propMap).toString());
    int i = 0;
    for (URLValue uv : MultiActionValuesScriptGenerator.getValidURLValues(values))
    {
      sb = MultiActionValuesScriptGenerator.getURLValueJS(sb, i, uv, SVGEncoderAdapter.getInstance());
      i++;
    }
    MultiActionValuesScriptGenerator.appendInteractivityVariables(sb);
    sb.append("\n");
    sb.append("  BirtChartActionsMenu.show( evt, source, menuInfo ); ");
    
    String script = sb.toString();
    
    StringBuffer callbackFunction = generateScriptCallbackFunctionName(script);
    
    String funcName = callbackFunction.toString();
    addCallBackScript(src, callbackFunction, true);
    
    elm.setAttribute(scriptEvent, 
      wrapJS(bDblClick, 
      callbackFunction.toString()));
    if (!scripts.contains(script))
    {
      svg_g2d.addScript(generateCallBackMethodName(funcName) + 
        "{" + script + "}");
      scripts.add(script);
    }
  }
  
  private StringBuffer generateScriptCallbackFunctionName(String script)
  {
    StringBuffer callbackFunction = new StringBuffer("callback");
    
    int hashCode = script.hashCode();
    if (hashCode != Integer.MIN_VALUE) {
      callbackFunction.append(Math.abs(hashCode));
    } else {
      callbackFunction.append(Integer.MAX_VALUE);
    }
    return callbackFunction;
  }
  
  private void setURLValueAttributes(URLValue urlValue, Element elm, StructureSource src, String scriptEvent, boolean bDblClick)
  {
    setTooltipForURLRedirect(elm, src, urlValue);
    
    String url = "";
    if (urlValue.getBaseUrl().startsWith("#"))
    {
      url = 
      
        "top.document.location.hash='" + urlValue.getBaseUrl() + "';";
    }
    else if (urlValue.getBaseUrl().startsWith("javascript:"))
    {
      url = urlValue.getBaseUrl();
    }
    else
    {
      String target = urlValue.getTarget();
      if (target == null) {
        target = "_self";
      }
      String jsRedirect = "redirect('" + 
        target + 
        "',_url);";
      url = "var _url='" + 
        urlValue.getBaseUrl() + 
        "'; try { parent." + 
        jsRedirect + 
        " } catch(e) { " + 
        jsRedirect + 
        " }";
    }
    elm.setAttribute(scriptEvent, 
      wrapJS(bDblClick, url));
  }
  
  private void setTooltipForURLRedirect(Element elm, StructureSource src, URLValue urlValue)
  {
    setTooltipForURLRedirect(elm, src, urlValue.getTooltip());
  }
  
  private void setTooltipForURLRedirect(Element elm, StructureSource src, String tooltipText)
  {
    if ((tooltipText != null) && 
      (tooltipText.trim().length() > 0))
    {
      Element title = svg_g2d.dom.createElement("title");
      title.appendChild(svg_g2d.dom.createTextNode(tooltipText));
      elm.appendChild(title);
      
      String componentId = null;
      if ((src instanceof WrappedStructureSource)) {
        componentId = findFirstComponentId((WrappedStructureSource)src);
      }
      elm.setAttribute("onmouseout", "TM.remove()");
      if (componentId != null) {
        elm.setAttribute("onmousemove", "TM.show(evt," + componentId + ")");
      } else {
        elm.setAttribute("onmousemove", "TM.show(evt)");
      }
    }
  }
  
  private final Series findDesignTimeSeries(Series seRT)
    throws ChartException
  {
    Series seDT = null;
    
    Chart cmRT = _iun.getRunTimeModel();
    Chart cmDT = _iun.getDesignTimeModel();
    if ((cmDT instanceof ChartWithAxes))
    {
      ChartWithAxes cwaRT = (ChartWithAxes)cmRT;
      ChartWithAxes cwaDT = (ChartWithAxes)cmDT;
      
      Axis[] axaBase = cwaRT.getPrimaryBaseAxes();
      Axis axBase = axaBase[0];
      Axis[] axaOrthogonal = cwaRT.getOrthogonalAxes(axBase, true);
      
      Series se = null;
      int i = -1;int j = 0;int k = 0;
      boolean bFound = false;
      
      EList<SeriesDefinition> elSD = axaBase[0].getSeriesDefinitions();
      for (j = 0; j < elSD.size(); j++)
      {
        SeriesDefinition sd = (SeriesDefinition)elSD.get(j);
        EList<Series> elSE = sd.getSeries();
        for (k = 0; k < elSE.size(); k++)
        {
          se = (Series)elSE.get(k);
          if (seRT == se)
          {
            bFound = true;
            break;
          }
        }
        if (bFound) {
          break;
        }
      }
      if (!bFound) {
        for (i = 0; i < axaOrthogonal.length; i++)
        {
          elSD = axaOrthogonal[i].getSeriesDefinitions();
          for (j = 0; j < elSD.size(); j++)
          {
            SeriesDefinition sd = (SeriesDefinition)elSD.get(j);
            EList<Series> elSE = sd.getSeries();
            for (k = 0; k < elSE.size(); k++)
            {
              se = (Series)elSE.get(k);
              if (seRT == se)
              {
                bFound = true;
                break;
              }
            }
            if (bFound) {
              break;
            }
          }
          if (bFound) {
            break;
          }
        }
      }
      if (!bFound) {
        throw new ChartException("org.eclipse.birt.chart.device.extension", 
          8, 
          "info.cannot.find.series", 
          new Object[] {
          seRT }, 
          
          org.eclipse.birt.chart.device.extension.i18n.Messages.getResourceBundle(getULocale()));
      }
      axaBase = cwaDT.getPrimaryBaseAxes();
      axBase = axaBase[0];
      axaOrthogonal = cwaDT.getOrthogonalAxes(axBase, true);
      if (i == -1) {
        elSD = axaBase[0].getSeriesDefinitions();
      } else {
        elSD = axaOrthogonal[i].getSeriesDefinitions();
      }
      SeriesDefinition sd = (SeriesDefinition)elSD.get(j);
      EList<Series> elSE = sd.getSeries();
      seDT = (Series)elSE.get(k);
    }
    else if ((cmDT instanceof ChartWithoutAxes))
    {
      ChartWithoutAxes cwoaRT = (ChartWithoutAxes)cmRT;
      ChartWithoutAxes cwoaDT = (ChartWithoutAxes)cmDT;
      
      Series se = null;
      int i = -1;int j = 0;int k = 0;
      boolean bFound = false;
      
      EList<SeriesDefinition> elSD = cwoaRT.getSeriesDefinitions();
      for (j = 0; j < elSD.size(); j++)
      {
        SeriesDefinition sd = (SeriesDefinition)elSD.get(j);
        EList<Series> elSE = sd.getSeries();
        for (k = 0; k < elSE.size(); k++)
        {
          se = (Series)elSE.get(k);
          if (seRT == se)
          {
            bFound = true;
            break;
          }
        }
        if (bFound) {
          break;
        }
      }
      if (!bFound)
      {
        i = 1;
        elSD = 
          ((SeriesDefinition)cwoaRT.getSeriesDefinitions().get(0))
          .getSeriesDefinitions();
        for (j = 0; j < elSD.size(); j++)
        {
          SeriesDefinition sd = (SeriesDefinition)elSD.get(j);
          EList<Series> elSE = sd.getSeries();
          for (k = 0; k < elSE.size(); k++)
          {
            se = (Series)elSE.get(k);
            if (seRT == se)
            {
              bFound = true;
              break;
            }
          }
          if (bFound) {
            break;
          }
        }
      }
      if (!bFound) {
        throw new ChartException("org.eclipse.birt.chart.device.extension", 
          8, 
          "info.cannot.find.series", 
          new Object[] {
          seRT }, 
          
          org.eclipse.birt.chart.device.extension.i18n.Messages.getResourceBundle(getULocale()));
      }
      if (i == -1) {
        elSD = cwoaDT.getSeriesDefinitions();
      } else {
        elSD = 
        
          ((SeriesDefinition)cwoaDT.getSeriesDefinitions().get(0)).getSeriesDefinitions();
      }
      SeriesDefinition sd = (SeriesDefinition)elSD.get(j);
      EList<Series> elSE = sd.getSeries();
      seDT = (Series)elSE.get(k);
    }
    return seDT;
  }
  
  private String getJsScriptEvent(int condition)
  {
    switch (condition)
    {
    case 0: 
      return "onmouseover";
    case 1: 
      return "onclick";
    case 2: 
      return "onclick";
    case 3: 
      return "ondblclick";
    case 4: 
      return "onmousedown";
    case 5: 
      return "onmouseup";
    case 6: 
      return "onmouseover";
    case 7: 
      return "onmousemove";
    case 8: 
      return "onmouseout";
    case 9: 
      return "onfocusin";
    case 10: 
      return "onfocusout";
    case 11: 
      return "onkeydown";
    case 12: 
      return "onkeypress";
    case 13: 
      return "onkeyup";
    case 15: 
      return "onload";
    }
    return null;
  }
  
  protected void setCursor(Element currentElement, Cursor cursor, String defaultCursor)
  {
    setCursorAttribute(currentElement, cursor, defaultCursor);
  }
  
  public void clear()
  {
    labelPrimitives.clear();
    componentPrimitives.clear();
    scripts.clear();
    mapOnloadAdded.clear();
  }
  
  public Node getHotspotLayer()
  {
    return hotspotLayer;
  }
  
  public void createHotspotLayer(Document dom)
  {
    hotspotLayer = dom.createElement("g");
    hotspotLayer.setAttribute("id", "hotSpots");
    hotspotLayer.setAttribute("style", "fill-opacity:0.01;fill:#FFFFFF;");
  }
  
  private ULocale getULocale()
  {
    return device.getULocale();
  }
  
  private boolean isColoredByCategories()
  {
    return _iun.getRunTimeModel().getLegend().getItemType() == LegendItemType.CATEGORIES_LITERAL;
  }
  
  private String findFirstComponentId(WrappedStructureSource src)
  {
    Series seRT = (Series)getElementFromSource(src.getParent(), 
      StructureType.SERIES);
    if (seRT != null)
    {
      Series seDT = null;
      String groupIdentifier = null;
      if (isColoredByCategories())
      {
        seDT = findCategorySeries(seRT);
        StringBuffer sb = new StringBuffer();
        sb.append(seDT.hashCode());
        sb.append("index");
        
        sb.append(iFirstDataPointIndex);
        groupIdentifier = sb.toString();
      }
      else
      {
        try
        {
          seDT = findDesignTimeSeries(seRT);
        }
        catch (ChartException e)
        {
          logger.log(e);
          return null;
        }
        groupIdentifier = String.valueOf(seDT.hashCode());
      }
      List<String> components = (List)componentPrimitives.get(seDT);
      if ((components != null) && (components.size() > 0)) {
        return "'" + groupIdentifier + "_" + (String)components.get(0) + "'";
      }
    }
    return null;
  }
  
  private String getJSCodeFunctionSuffix(StructureSource src)
  {
    String jsFunction = null;
    
    Series seRT = (Series)getElementFromSource(src, 
      StructureType.SERIES);
    if (seRT != null)
    {
      Series seDT = null;
      String groupIdentifier = null;
      if (isColoredByCategories())
      {
        seDT = findCategorySeries(seRT);
        int baseIndex = getDataPointHints(src).getIndex();
        StringBuffer sb = new StringBuffer();
        sb.append("'");
        sb.append(seDT.hashCode());
        sb.append("index");
        sb.append(baseIndex);
        sb.append("'");
        groupIdentifier = sb.toString();
      }
      else
      {
        try
        {
          seDT = findDesignTimeSeries(seRT);
        }
        catch (ChartException e)
        {
          logger.log(e);
          return null;
        }
        groupIdentifier = String.valueOf(seDT.hashCode());
      }
      boolean includeLabels = true;
      boolean includeGraphics = true;
      if ((includeGraphics) || (includeLabels))
      {
        StringBuffer sb = new StringBuffer();
        sb.append(", ");
        sb.append(groupIdentifier);
        
        sb.append(",new Array(");
        
        List<String> labelComponents = (List)labelPrimitives.get(seDT);
        List<String> components = (List)componentPrimitives.get(seDT);
        
        Iterator<String> iter = null;
        if ((includeGraphics) && (components != null))
        {
          iter = components.iterator();
          appendArguments(sb, iter);
          if ((includeLabels) && (labelComponents != null)) {
            sb.append("), new Array(");
          }
        }
        if ((includeLabels) && (labelComponents != null))
        {
          iter = labelComponents.iterator();
          appendArguments(sb, iter);
        }
        sb.append(")");
        
        jsFunction = sb.toString() + ")";
      }
    }
    else
    {
      Object designObject = null;
      if (getElementFromSource(src, StructureType.TITLE) != null) {
        designObject = src.getSource();
      } else if (getElementFromSource(src, StructureType.PLOT) != null) {
        designObject = src.getSource();
      } else if (getElementFromSource(src, StructureType.CHART_BLOCK) != null) {
        designObject = src.getSource();
      } else if (getElementFromSource(src, StructureType.AXIS) != null) {
        designObject = src.getSource();
      }
      if (designObject != null)
      {
        List<String> components = (List)componentPrimitives.get(designObject);
        
        Iterator<String> iter = null;
        if (components != null)
        {
          String groupIdentifier = String.valueOf(designObject.hashCode());
          StringBuffer sb = new StringBuffer();
          sb.append(", ");
          sb.append(groupIdentifier);
          
          sb.append(",new Array(");
          iter = components.iterator();
          appendArguments(sb, iter);
          
          sb.append(")");
          jsFunction = sb.toString() + ")";
        }
      }
    }
    return jsFunction;
  }
  
  private void addJSCodeOnElement(StructureSource src, Trigger tg, Element elm, String scriptEvent, int type, boolean bDblClick)
  {
    Series seRT = (Series)getElementFromSource(src, 
      StructureType.SERIES);
    if (seRT != null)
    {
      Series seDT = null;
      String groupIdentifier = null;
      if (isColoredByCategories())
      {
        seDT = findCategorySeries(seRT);
        int baseIndex = getDataPointHints(src).getIndex();
        StringBuffer sb = new StringBuffer();
        sb.append("'");
        sb.append(seDT.hashCode());
        sb.append("index");
        sb.append(baseIndex);
        sb.append("'");
        groupIdentifier = sb.toString();
      }
      else
      {
        try
        {
          seDT = findDesignTimeSeries(seRT);
        }
        catch (ChartException e)
        {
          logger.log(e);
          return;
        }
        groupIdentifier = String.valueOf(seDT.hashCode());
      }
      boolean includeLabels = false;
      boolean includeGraphics = false;
      
      String jsFunction = null;
      switch (type)
      {
      case 2: 
        jsFunction = "toggleVisibility(evt";
        includeLabels = true;
        includeGraphics = true;
        break;
      case 6: 
        jsFunction = "toggleLabelsVisibility(evt";
        includeLabels = true;
        includeGraphics = false;
        break;
      case 4: 
        jsFunction = "highlight(evt";
        includeLabels = true;
        includeGraphics = true;
      }
      if (jsFunction == null)
      {
        if (!$assertionsDisabled) {
          throw new AssertionError();
        }
        return;
      }
      if ((includeGraphics) || (includeLabels))
      {
        StringBuffer sb = new StringBuffer();
        sb.append(", ");
        sb.append(groupIdentifier);
        
        sb.append(",new Array(");
        
        List<String> labelComponents = (List)labelPrimitives.get(seDT);
        List<String> components = (List)componentPrimitives.get(seDT);
        
        Iterator<String> iter = null;
        if ((includeGraphics) && (components != null))
        {
          iter = components.iterator();
          appendArguments(sb, iter);
          if ((includeLabels) && (labelComponents != null)) {
            sb.append("), new Array(");
          }
        }
        if ((includeLabels) && (labelComponents != null))
        {
          iter = labelComponents.iterator();
          appendArguments(sb, iter);
        }
        sb.append(")");
        
        jsFunction = jsFunction + sb.toString() + ")";
        elm.setAttribute(scriptEvent, wrapJS(bDblClick, 
          jsFunction));
        if (tg.getCondition().getValue() == 6) {
          elm.setAttribute("onmouseout", 
            jsFunction);
        }
      }
    }
    else
    {
      Object designObject = null;
      if (getElementFromSource(src, StructureType.TITLE) != null) {
        designObject = src.getSource();
      } else if (getElementFromSource(src, StructureType.PLOT) != null) {
        designObject = src.getSource();
      } else if (getElementFromSource(src, StructureType.CHART_BLOCK) != null) {
        designObject = src.getSource();
      } else if (getElementFromSource(src, StructureType.AXIS) != null) {
        designObject = src.getSource();
      }
      if (designObject != null)
      {
        String jsFunction = null;
        switch (type)
        {
        case 2: 
          jsFunction = "toggleVisibility(evt";
          break;
        case 4: 
          jsFunction = "highlight(evt";
        }
        if (jsFunction == null)
        {
          if (!$assertionsDisabled) {
            throw new AssertionError();
          }
          return;
        }
        List<String> components = (List)componentPrimitives.get(designObject);
        
        Iterator<String> iter = null;
        if (components != null)
        {
          String groupIdentifier = String.valueOf(designObject.hashCode());
          StringBuffer sb = new StringBuffer();
          sb.append(", ");
          sb.append(groupIdentifier);
          
          sb.append(",new Array(");
          iter = components.iterator();
          appendArguments(sb, iter);
          
          sb.append(")");
          
          elm.setAttribute(scriptEvent, wrapJS(bDblClick, 
            jsFunction + sb.toString() + ")"));
          if (tg.getCondition().getValue() == 6) {
            elm.setAttribute("onmouseout", 
              jsFunction + sb.toString() + ")");
          }
        }
      }
    }
  }
  
  private void appendArguments(StringBuffer sb, Iterator<String> iter)
  {
    if (iter != null) {
      while (iter.hasNext())
      {
        sb.append("'").append((String)iter.next()).append("'");
        if (iter.hasNext()) {
          sb.append(",");
        }
      }
    }
  }
  
  private String wrapJS(boolean bDblClick, String js)
  {
    if (!bDblClick) {
      return js;
    }
    return "if ( evt.detail==2 ){" + js + "}";
  }
  
  private void setCursorAttribute(Element elm, Cursor cursor, String defaultValue)
  {
    String style = elm.getAttribute("style");
    if (style == null) {
      style = "";
    }
    if ((cursor == null) || (cursor.getType() == CursorType.AUTO)) {
      return;
    }
    String value = style + CSSHelper.getCSSCursorValue(cursor);
    elm.setAttribute("style", style + value);
  }
  
  private void addCallBackScript(StructureSource src, StringBuffer callbackFunction, boolean hasEndTag)
  {
    callbackFunction.append("(evt,");
    callbackFunction.append(src.getSource().hashCode());
    DataPointHints dph;
    DataPointHints dph;
    if (StructureType.SERIES_DATA_POINT.equals(src.getType())) {
      dph = (DataPointHints)src.getSource();
    } else {
      dph = null;
    }
    LegendItemHints lerh;
    LegendItemHints lerh;
    if (StructureType.LEGEND_ENTRY.equals(src.getType())) {
      lerh = (LegendItemHints)src.getSource();
    } else {
      lerh = null;
    }
    String axisLabel;
    String axisLabel;
    if (StructureType.AXIS_LABEL.equals(src.getType())) {
      axisLabel = (String)src.getSource();
    } else {
      axisLabel = null;
    }
    ScriptUtil.script(callbackFunction, dph, lerh, axisLabel);
    if (hasEndTag) {
      callbackFunction.append(");");
    }
  }
  
  private String generateCallBackMethodName(String funcName)
  {
    return 
    
      "function " + funcName + "(evt,source," + "categoryData" + "," + "valueData" + "," + "valueSeriesName" + "," + "legendItemText" + "," + "legendItemValue" + "," + "axisLabel" + "," + "id" + "," + "compList" + "," + "labelList" + ")";
  }
  
  private DataPointHints getDataPointHints(StructureSource src)
  {
    if ((src.getType() == StructureType.SERIES_DATA_POINT) || 
      (src.getType() == StructureType.SERIES_ELEMENT)) {
      return (DataPointHints)src.getSource();
    }
    if ((src instanceof WrappedStructureSource)) {
      return getDataPointHints(((WrappedStructureSource)src).getParent());
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.birt.chart.device.svg.SVGInteractiveRenderer
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.birt.chart.device.svg;

import java.awt.Image;
import java.awt.Shape;
import java.awt.geom.Arc2D.Double;
import java.awt.geom.Area;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D.Double;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.eclipse.birt.chart.computation.DataPointHints;
import org.eclipse.birt.chart.device.FontUtil;
import org.eclipse.birt.chart.device.ITextRenderer;
import org.eclipse.birt.chart.device.IUpdateNotifier;
import org.eclipse.birt.chart.device.extension.i18n.Messages;
import org.eclipse.birt.chart.device.swing.SwingRendererImpl;
import org.eclipse.birt.chart.event.ArcRenderEvent;
import org.eclipse.birt.chart.event.AreaRenderEvent;
import org.eclipse.birt.chart.event.ImageRenderEvent;
import org.eclipse.birt.chart.event.InteractionEvent;
import org.eclipse.birt.chart.event.LineRenderEvent;
import org.eclipse.birt.chart.event.OvalRenderEvent;
import org.eclipse.birt.chart.event.PolygonRenderEvent;
import org.eclipse.birt.chart.event.PrimitiveRenderEvent;
import org.eclipse.birt.chart.event.RectangleRenderEvent;
import org.eclipse.birt.chart.event.StructureChangeEvent;
import org.eclipse.birt.chart.event.TextRenderEvent;
import org.eclipse.birt.chart.exception.ChartException;
import org.eclipse.birt.chart.log.ILogger;
import org.eclipse.birt.chart.log.Logger;
import org.eclipse.birt.chart.model.attribute.Bounds;
import org.eclipse.birt.chart.model.attribute.Fill;
import org.eclipse.birt.chart.model.attribute.FontDefinition;
import org.eclipse.birt.chart.model.attribute.Location;
import org.eclipse.birt.chart.model.attribute.Text;
import org.eclipse.birt.chart.model.component.Label;
import org.eclipse.birt.chart.model.component.Series;
import org.eclipse.birt.chart.model.data.Trigger;
import org.eclipse.birt.chart.model.layout.LabelBlock;
import org.eclipse.birt.chart.model.layout.Legend;
import org.eclipse.birt.chart.model.layout.Plot;
import org.eclipse.birt.chart.model.layout.TitleBlock;
import org.eclipse.birt.chart.util.PluginSettings;
import org.eclipse.birt.chart.util.SecurityUtil;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentType;
import org.w3c.dom.Element;

public class SVGRendererImpl
  extends SwingRendererImpl
{
  protected List<String> scriptRefList = null;
  protected List<String> scriptCodeList = null;
  private static ILogger logger = Logger.getLogger("org.eclipse.birt.chart.device.svg/trace");
  private IUpdateNotifier _iun = null;
  protected SVGInteractiveRenderer ivRenderer;
  private static final String SVG_VERSION = "-//W3C//DTD SVG 1.0//EN";
  private static final String SVG_DTD = "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd";
  private static final String XMLNS = "http://www.w3.org/2000/svg";
  private static final String XMLNSXINK = "http://www.w3.org/1999/xlink";
  protected Object oOutputIdentifier = null;
  protected Document dom;
  protected SVGGraphics2D svggc;
  protected boolean _resizeSVG = false;
  public boolean _enableScript = true;
  
  protected void init()
  {
    PluginSettings ps = PluginSettings.instance();
    try
    {
      SVGDisplayServer ids = (SVGDisplayServer)ps.getDisplayServer("ds.SVG");
      SVGTextRenderer tr = new SVGTextRenderer(ids);
      tr.setTextLayoutFactory(ids);
      _ids = ids;
      _tr = tr;
      ivRenderer = new SVGInteractiveRenderer(this);
    }
    catch (ChartException pex)
    {
      logger.log(pex);
    }
  }
  
  public void setProperty(String sProperty, Object oValue)
  {
    super.setProperty(sProperty, oValue);
    if (sProperty.equals("device.component"))
    {
      _iun = ((IUpdateNotifier)oValue);
      ivRenderer.setIUpdateNotifier(_iun);
    }
    else if (sProperty.equals("device.bounds"))
    {
      Bounds bo = (Bounds)oValue;
      try
      {
        dom = createSvgDocument(bo.getWidth(), bo.getHeight());
        svggc = new SVGGraphics2D(dom, _enableScript);
        ivRenderer.setSVG2D(svggc);
        
        ivRenderer.createHotspotLayer(dom);
        super.setProperty("device.output.context", svggc);
      }
      catch (Exception e)
      {
        e.printStackTrace();
      }
    }
    else if (sProperty.equals("device.file.identifier"))
    {
      oOutputIdentifier = oValue;
    }
    else if (sProperty.equals("javascript.code.list"))
    {
      scriptCodeList = ((List)oValue);
    }
    else if (sProperty.equals("javascript.ref.list"))
    {
      scriptRefList = ((List)oValue);
    }
    else if (sProperty.equals("resize.svg"))
    {
      _resizeSVG = ((Boolean)oValue).booleanValue();
    }
    else if (sProperty.equals("enable.scriptable"))
    {
      _enableScript = ((Boolean)oValue).booleanValue();
    }
  }
  
  protected void addScripts()
  {
    if (scriptCodeList != null) {
      for (int x = 0; x < scriptCodeList.size(); x++)
      {
        String code = (String)scriptCodeList.get(x);
        ((SVGGraphics2D)_g2d).addScript(code);
      }
    }
    if (scriptRefList != null) {
      for (int x = 0; x < scriptRefList.size(); x++)
      {
        String ref = (String)scriptRefList.get(x);
        ((SVGGraphics2D)_g2d).addScriptRef(ref);
      }
    }
  }
  
  public void after()
    throws ChartException
  {
    super.after();
    
    ivRenderer.addInteractivity();
    addScripts();
    ((SVGGraphics2D)_g2d).flush();
    
    dom.getDocumentElement().appendChild(ivRenderer.getHotspotLayer());
    if ((oOutputIdentifier instanceof OutputStream))
    {
      try
      {
        writeDocumentToOutputStream(dom, 
          (OutputStream)oOutputIdentifier);
      }
      catch (Exception ex)
      {
        throw new ChartException("org.eclipse.birt.chart.device.svg", 
          11, 
          ex);
      }
    }
    else if ((oOutputIdentifier instanceof String))
    {
      FileOutputStream fos = null;
      try
      {
        fos = SecurityUtil.newFileOutputStream((String)oOutputIdentifier);
        writeDocumentToOutputStream(dom, fos);
        fos.close();
      }
      catch (Exception ex)
      {
        throw new ChartException("org.eclipse.birt.chart.device.svg", 
          11, 
          ex);
      }
    }
    else
    {
      throw new ChartException("org.eclipse.birt.chart.device.svg", 
        11, 
        "SVGRendererImpl.exception.UnableToWriteChartImage", 
        new Object[] {
        oOutputIdentifier }, 
        
        null);
    }
    ivRenderer.clear();
  }
  
  private void writeDocumentToOutputStream(Document svgDocument, OutputStream outputStream)
    throws Exception
  {
    if ((svgDocument != null) && (outputStream != null))
    {
      OutputStreamWriter writer = null;
      
      writer = SecurityUtil.newOutputStreamWriter(outputStream, "UTF-8");
      
      DOMSource source = new DOMSource(svgDocument);
      StreamResult result = new StreamResult(writer);
      
      checkForTransformFactoryImpl();
      TransformerFactory transFactory = SecurityUtil.newTransformerFactory();
      Transformer transformer = transFactory.newTransformer();
      
      transformer.transform(source, result);
    }
  }
  
  private void checkForTransformFactoryImpl()
  {
    try
    {
      Class.forName("org.apache.xalan.processor.TransformerFactoryImpl");
    }
    catch (ClassNotFoundException localClassNotFoundException)
    {
      SecurityUtil.setSysProp("javax.xml.transform.TransformerFactory", 
        "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
    }
  }
  
  protected Document createSvgDocument()
    throws Exception
  {
    DocumentBuilderFactory factory = SecurityUtil.newDocumentBuilderFactory();
    
    DocumentBuilder builder = factory.newDocumentBuilder();
    DOMImplementation domImpl = builder.getDOMImplementation();
    DocumentType dType = domImpl.createDocumentType("svg", 
      "-//W3C//DTD SVG 1.0//EN", 
      "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd");
    Document svgDocument = domImpl.createDocument("http://www.w3.org/2000/svg", "svg", dType);
    svgDocument.getDocumentElement().setAttribute("xmlns", "http://www.w3.org/2000/svg");
    svgDocument.getDocumentElement()
      .setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
    if (_resizeSVG)
    {
      svgDocument.getDocumentElement().setAttribute("onload", "resizeSVG(evt)");
      
      svgDocument.getDocumentElement()
        .setAttribute("onresize", "resizeSVG(evt)");
    }
    return svgDocument;
  }
  
  protected Document createSvgDocument(double width, double height)
    throws Exception
  {
    Document svgDocument = createSvgDocument();
    svgDocument.getDocumentElement().setAttribute("width", 
      SVGGraphics2D.toString(width));
    svgDocument.getDocumentElement().setAttribute("height", 
      SVGGraphics2D.toString(height));
    svgDocument.getDocumentElement().setAttribute("initialWidth", 
      SVGGraphics2D.toString(width));
    svgDocument.getDocumentElement().setAttribute("initialHeight", 
      SVGGraphics2D.toString(height));
    return svgDocument;
  }
  
  public void changeStructure(StructureChangeEvent scev) {}
  
  protected void removeGroupStructure(Object block)
  {
    if (((block instanceof TitleBlock)) || 
      ((block instanceof Legend)) || 
      ((block instanceof Plot)) || 
      ((block instanceof LabelBlock)) || 
      ((block instanceof Series)) || 
      ((block instanceof DataPointHints))) {
      svggc.popParent();
    }
  }
  
  protected void addGroupStructure(Object block)
  {
    if ((block instanceof TitleBlock))
    {
      Element group = svggc.dom.createElement("g");
      group.setAttribute("id", "title");
      svggc.pushParent(group);
    }
    else if ((block instanceof Legend))
    {
      Element group = svggc.dom.createElement("g");
      group.setAttribute("id", "legend");
      svggc.pushParent(group);
    }
    else if ((block instanceof Plot))
    {
      Element group = svggc.dom.createElement("g");
      group.setAttribute("id", "plot");
      svggc.pushParent(group);
    }
    else if ((block instanceof LabelBlock))
    {
      Element group = svggc.dom.createElement("g");
      group.setAttribute("id", "label");
      svggc.pushParent(group);
    }
    else if ((block instanceof Series))
    {
      Element group = svggc.dom.createElement("g");
      group.setAttribute("id", "series");
      svggc.pushParent(group);
    }
    else if ((block instanceof DataPointHints))
    {
      Element group = svggc.dom.createElement("g");
      group.setAttribute("id", "dp" + block.hashCode());
      svggc.pushParent(group);
    }
  }
  
  public void enableInteraction(InteractionEvent ie)
    throws ChartException
  {
    if (_iun == null)
    {
      logger.log(2, 
        Messages.getString("exception.missing.component.interaction", getULocale()));
      return;
    }
    Trigger[] triggers = ie.getTriggers();
    if (triggers == null) {
      return;
    }
    PrimitiveRenderEvent pre = ie.getHotSpot();
    Element elm = null;
    if ((pre instanceof PolygonRenderEvent))
    {
      Location[] loa = ((PolygonRenderEvent)pre).getPoints();
      
      int[][] pa = getCoordinatesAsInts(loa);
      
      elm = svggc.createPolygon(pa[0], pa[1], pa[0].length);
    }
    else if ((pre instanceof OvalRenderEvent))
    {
      Bounds boEllipse = ((OvalRenderEvent)pre).getBounds();
      
      elm = svggc.createOval(boEllipse.getLeft() + 
        boEllipse.getWidth() / 
        2.0D, 
        boEllipse.getTop() + boEllipse.getHeight() / 2.0D, 
        boEllipse.getWidth() / 2.0D, 
        boEllipse.getHeight() / 2.0D);
    }
    else if ((pre instanceof RectangleRenderEvent))
    {
      Bounds boRect = ((RectangleRenderEvent)pre).getBounds();
      
      elm = svggc.createRect(boRect.getLeft(), 
        boRect.getTop(), 
        boRect.getWidth(), 
        boRect.getHeight());
    }
    else if ((pre instanceof AreaRenderEvent))
    {
      AreaRenderEvent are = (AreaRenderEvent)pre;
      
      GeneralPath gp = new GeneralPath();
      for (int i = 0; i < are.getElementCount(); i++)
      {
        PrimitiveRenderEvent subPre = are.getElement(i);
        if ((subPre instanceof ArcRenderEvent))
        {
          ArcRenderEvent acre = (ArcRenderEvent)subPre;
          Arc2D.Double a2d = new Arc2D.Double(acre.getTopLeft()
            .getX(), 
            acre.getTopLeft().getY(), 
            acre.getWidth(), 
            acre.getHeight(), 
            acre.getStartAngle(), 
            acre.getAngleExtent(), 
            toG2dArcType(acre.getStyle()));
          gp.append(a2d, true);
        }
        else if ((subPre instanceof LineRenderEvent))
        {
          LineRenderEvent lre = (LineRenderEvent)subPre;
          Line2D.Double l2d = new Line2D.Double(lre.getStart()
            .getX(), lre.getStart().getY(), lre.getEnd()
            .getX(), lre.getEnd().getY());
          gp.append(l2d, true);
        }
      }
      elm = svggc.createGeneralPath(gp);
    }
    else if ((pre instanceof LineRenderEvent))
    {
      GeneralPath gp = new GeneralPath();
      LineRenderEvent lre = (LineRenderEvent)pre;
      Line2D.Double l2d = new Line2D.Double(lre.getStart()
        .getX(), lre.getStart().getY(), lre.getEnd()
        .getX(), lre.getEnd().getY());
      gp.append(l2d, true);
      elm = svggc.createGeneralPath(gp);
    }
    else if ((pre instanceof ArcRenderEvent))
    {
      ArcRenderEvent are = (ArcRenderEvent)pre;
      if ((are.getInnerRadius() >= 0.0D) && 
        (are.getOuterRadius() > 0.0D) && 
        (are.getInnerRadius() < are.getOuterRadius()))
      {
        Shape outerArc = new Arc2D.Double(are.getTopLeft().getX() + 
          (are.getWidth() - 2.0D * are.getOuterRadius()) / 
          2.0D, 
          are.getTopLeft().getY() + 
          (are.getHeight() - 2.0D * are.getOuterRadius()) / 
          2.0D, 
          2.0D * are.getOuterRadius(), 
          2.0D * are.getOuterRadius(), 
          are.getStartAngle(), 
          are.getAngleExtent(), 
          2);
        Shape innerArc = new Arc2D.Double(are.getTopLeft().getX() + 
          (are.getWidth() - 2.0D * are.getInnerRadius()) / 
          2.0D, 
          are.getTopLeft().getY() + 
          (are.getHeight() - 2.0D * are.getInnerRadius()) / 
          2.0D, 
          2.0D * are.getInnerRadius(), 
          2.0D * are.getInnerRadius(), 
          are.getStartAngle(), 
          are.getAngleExtent(), 
          2);
        
        Area fArea = new Area
1 2 3 4

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd