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

16:41:23.234 INFO  jd.cli.Main - Decompiling org.eclipse.birt.chart.device.extension_3.7.2.v20120213.jar
package org.eclipse.birt.chart.device.extension.i18n;

import com.ibm.icu.util.ULocale;
import com.ibm.icu.util.UResourceBundle;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.birt.chart.util.SecurityUtil;

public final class Messages
{
  private static final String DEVICE_EXTENSION = "org.eclipse.birt.chart.device.extension.i18n.nls";
  private static final ResourceBundle RESOURCE_BUNDLE = UResourceBundle.getBundleInstance("org.eclipse.birt.chart.device.extension.i18n.nls", 
    ULocale.getDefault(), 
    SecurityUtil.getClassLoader(Messages.class));
  private static Map<ULocale, ResourceBundle> hmLocalToBundle = new HashMap(2);
  
  public static ResourceBundle getResourceBundle()
  {
    return RESOURCE_BUNDLE;
  }
  
  public static ResourceBundle getResourceBundle(ULocale locale)
  {
    if (locale == null) {
      return RESOURCE_BUNDLE;
    }
    ResourceBundle bundle = (ResourceBundle)hmLocalToBundle.get(locale);
    if (bundle == null)
    {
      bundle = getMatchedResourceBundle(locale, 
        "org.eclipse.birt.chart.device.extension.i18n.nls", 
        Messages.class);
      if (bundle != null) {
        hmLocalToBundle.put(locale, bundle);
      }
    }
    return bundle;
  }
  
  private static ResourceBundle getMatchedResourceBundle(ULocale locale, String baseName, Class clazz)
  {
    ResourceBundle bundle = UResourceBundle.getBundleInstance(baseName, 
      locale, 
      SecurityUtil.getClassLoader(clazz));
    if (bundle != null)
    {
      String language = locale.getLanguage();
      String country = locale.getCountry();
      boolean useDefaultResource = true;
      if ((language.length() == 0) && (country.length() == 0))
      {
        useDefaultResource = false;
      }
      else
      {
        Locale bundleLocale = bundle.getLocale();
        if ((bundleLocale.getLanguage().length() == 0) && 
          (bundleLocale.getCountry().length() == 0))
        {
          useDefaultResource = false;
        }
        else if (language.equals(bundleLocale.getLanguage()))
        {
          String bundleCountry = bundleLocale.getCountry();
          if ((country.equals(bundleCountry)) || 
            (bundleCountry.length() == 0)) {
            useDefaultResource = false;
          }
        }
      }
      if (useDefaultResource) {
        bundle = ResourceBundle.getBundle(baseName, 
          new Locale("", ""));
      }
    }
    return bundle;
  }
  
  public static String getString(String key, ULocale lcl)
  {
    try
    {
      return getResourceBundle(lcl).getString(key);
    }
    catch (MissingResourceException localMissingResourceException) {}
    return '!' + key + '!';
  }
  
  public static String getString(String key, Object[] oa, ULocale lcl)
  {
    try
    {
      return SecurityUtil.formatMessage(getResourceBundle(lcl).getString(key), 
        oa);
    }
    catch (MissingResourceException e)
    {
      e.printStackTrace();
    }
    return '!' + key + '!';
  }
}

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

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.font.FontRenderContext;
import java.awt.font.TextAttribute;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.text.AttributedCharacterIterator.Attribute;
import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;
import org.eclipse.birt.chart.device.DisplayAdapter;
import org.eclipse.birt.chart.device.ITextMetrics;
import org.eclipse.birt.chart.device.util.ChartTextLayout;
import org.eclipse.birt.chart.device.util.ChartTextMetrics;
import org.eclipse.birt.chart.device.util.ITextLayoutFactory;
import org.eclipse.birt.chart.exception.ChartException;
import org.eclipse.birt.chart.model.attribute.ColorDefinition;
import org.eclipse.birt.chart.model.attribute.FontDefinition;
import org.eclipse.birt.chart.model.attribute.Size;
import org.eclipse.birt.chart.model.attribute.impl.SizeImpl;
import org.eclipse.birt.chart.model.component.Label;
import org.eclipse.birt.chart.util.ChartUtil;

public class G2dDisplayServerBase
  extends DisplayAdapter
  implements ITextLayoutFactory
{
  protected Graphics2D _g2d;
  protected int iDpiResolution = 0;
  private static Map<String, BufferedImage> imageCache = new HashMap();
  private static Map<BufferedImage, Size> sizeCache = new HashMap();
  
  public Object createFont(FontDefinition fd)
  {
    Map<TextAttribute, Object> fontAttribs = ChartUtil.newHashMap();
    fontAttribs.put(TextAttribute.FAMILY, fd.getName());
    
    fontAttribs.put(TextAttribute.SIZE, new Float(fd.getSize() * getDpiResolution() / 72.0D));
    if (fd.isItalic()) {
      fontAttribs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);
    }
    if (fd.isBold()) {
      fontAttribs.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
    }
    if (fd.isUnderline()) {
      fontAttribs.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
    }
    if (fd.isStrikethrough()) {
      fontAttribs.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
    }
    return new Font(fontAttribs);
  }
  
  public final Object getColor(ColorDefinition cd)
  {
    return new Color(cd.getRed(), 
      cd.getGreen(), 
      cd.getBlue(), 
      cd.getTransparency());
  }
  
  public int getDpiResolution()
  {
    if (iDpiResolution <= 0) {
      return super.getDpiResolution();
    }
    return iDpiResolution;
  }
  
  public void setDpiResolution(int dpi)
  {
    iDpiResolution = dpi;
  }
  
  public void setGraphicsContext(Object graphicContext)
  {
    _g2d = ((Graphics2D)graphicContext);
  }
  
  public ITextMetrics getTextMetrics(Label la, boolean autoReuse)
  {
    ChartTextMetrics tm = new ChartTextMetrics(this, la, autoReuse);
    return tm;
  }
  
  public Object loadImage(URL url)
    throws ChartException
  {
    String sUrl = url.toString();
    BufferedImage image = (BufferedImage)imageCache.get(sUrl);
    if (image == null)
    {
      URL urlFound = findResource(url);
      try
      {
        image = ImageIO.read(urlFound);
        imageCache.put(sUrl, image);
      }
      catch (IOException e)
      {
        throw new ChartException("org.eclipse.birt.chart.device.extension", 
          4, 
          e);
      }
    }
    return image;
  }
  
  public Size getSize(Object oImage)
  {
    Size size = null;
    if ((oImage instanceof BufferedImage))
    {
      BufferedImage image = (BufferedImage)oImage;
      size = (Size)sizeCache.get(image);
      if (size == null)
      {
        size = SizeImpl.create(image.getWidth(), image.getHeight());
        sizeCache.put(image, size);
      }
    }
    return size;
  }
  
  public ChartTextLayout createTextLayout(String value, Map<? extends AttributedCharacterIterator.Attribute, ?> fontAttributes, FontRenderContext frc)
  {
    return new ChartTextLayout(value, fontAttributes, frc);
  }
}

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

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.Paint;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.TexturePaint;
import java.awt.geom.Arc2D.Double;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D.Double;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D.Double;
import java.awt.geom.Point2D.Double;
import java.awt.geom.Rectangle2D.Double;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.awt.image.WritableRaster;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.imageio.ImageIO;
import org.apache.commons.codec.binary.Base64;
import org.eclipse.birt.chart.device.DeviceAdapter;
import org.eclipse.birt.chart.device.FontUtil;
import org.eclipse.birt.chart.device.IDisplayServer;
import org.eclipse.birt.chart.device.ITextRenderer;
import org.eclipse.birt.chart.device.extension.i18n.Messages;
import org.eclipse.birt.chart.event.ArcRenderEvent;
import org.eclipse.birt.chart.event.AreaRenderEvent;
import org.eclipse.birt.chart.event.ClipRenderEvent;
import org.eclipse.birt.chart.event.ImageRenderEvent;
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.TextRenderEvent;
import org.eclipse.birt.chart.event.TransformationEvent;
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.ColorDefinition;
import org.eclipse.birt.chart.model.attribute.EmbeddedImage;
import org.eclipse.birt.chart.model.attribute.Fill;
import org.eclipse.birt.chart.model.attribute.FontDefinition;
import org.eclipse.birt.chart.model.attribute.Gradient;
import org.eclipse.birt.chart.model.attribute.LineAttributes;
import org.eclipse.birt.chart.model.attribute.LineStyle;
import org.eclipse.birt.chart.model.attribute.Location;
import org.eclipse.birt.chart.model.attribute.PatternImage;
import org.eclipse.birt.chart.model.attribute.Position;
import org.eclipse.birt.chart.model.attribute.Size;
import org.eclipse.birt.chart.model.attribute.Text;
import org.eclipse.birt.chart.model.attribute.impl.BoundsImpl;
import org.eclipse.birt.chart.model.component.Label;
import org.eclipse.birt.chart.render.BaseRenderer;
import org.eclipse.birt.chart.render.InteractiveRenderer;
import org.eclipse.birt.chart.util.PatternImageUtil;
import org.eclipse.birt.chart.util.PatternImageUtil.ByteColorModel;
import org.eclipse.birt.chart.util.SecurityUtil;

public class G2dRendererBase
  extends DeviceAdapter
{
  private static ILogger logger = Logger.getLogger("org.eclipse.birt.chart.device.extension/g2d");
  protected IDisplayServer _ids;
  protected Graphics2D _g2d;
  protected InteractiveRenderer iv;
  protected ITextRenderer _tr = null;
  private final Map<LineAttributes, Stroke> _htLineStyles = new HashMap();
  
  protected static final Bounds normalizeBounds(Bounds bo)
  {
    if (bo.getHeight() < 0.0D)
    {
      bo.setTop(bo.getTop() + bo.getHeight());
      bo.setHeight(-bo.getHeight());
    }
    if (bo.getWidth() < 0.0D)
    {
      bo.setLeft(bo.getLeft() + bo.getWidth());
      bo.setWidth(-bo.getWidth());
    }
    return bo;
  }
  
  public static final int[][] getCoordinatesAsInts(Location[] la)
  {
    int n = la.length;
    int[] iaX = new int[n];
    int[] iaY = new int[n];
    for (int i = 0; i < n; i++)
    {
      iaX[i] = ((int)la[i].getX());
      iaY[i] = ((int)la[i].getY());
    }
    return new int[][] {
      iaX, iaY };
  }
  
  protected static final int toG2dArcType(int iArcStyle)
  {
    switch (iArcStyle)
    {
    case 1: 
      return 0;
    case 2: 
      return 1;
    case 3: 
      return 2;
    }
    return -1;
  }
  
  public final Stroke getCachedStroke(LineAttributes lia)
  {
    if (lia == null) {
      return null;
    }
    Stroke s = (Stroke)_htLineStyles.get(lia);
    if (s == null)
    {
      BasicStroke bs = null;
      int thickness = lia.getThickness();
      if (thickness == 0) {
        thickness = 1;
      }
      if (lia.getStyle().getValue() == 1)
      {
        float[] faStyle = {
          6 * thickness, 4 * thickness };
        
        bs = new BasicStroke(lia.getThickness(), 
          1, 
          1, 
          0.0F, 
          faStyle, 
          0.0F);
      }
      else if (lia.getStyle().getValue() == 2)
      {
        float[] faStyle = {
          thickness, 4 * thickness };
        
        bs = new BasicStroke(lia.getThickness(), 
          1, 
          1, 
          0.0F, 
          faStyle, 
          0.0F);
      }
      else if (lia.getStyle().getValue() == 3)
      {
        float[] faStyle = {
          6 * thickness, 4 * thickness, thickness, 4 * thickness };
        
        bs = new BasicStroke(lia.getThickness(), 
          1, 
          1, 
          0.0F, 
          faStyle, 
          0.0F);
      }
      else if (lia.getStyle().getValue() == 0)
      {
        bs = new BasicStroke(lia.getThickness(), 
          2, 
          1);
      }
      if (bs != null) {
        _htLineStyles.put(lia, bs);
      }
      return bs;
    }
    return s;
  }
  
  private static Set<String> sLocalFontFamilyNamesSet = new HashSet();
  private static Map<String, String> sLogicFontNameMap;
  
  static
  {
    String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment()
      .getAvailableFontFamilyNames();
    sLocalFontFamilyNamesSet = new HashSet(Arrays.asList(fonts));
    
    sLogicFontNameMap = new HashMap();
    
    sLogicFontNameMap.put("serif", "Serif");
    sLogicFontNameMap.put("sans-serif", 
      "SansSerif");
    sLogicFontNameMap.put("monospace", 
      "Monospaced");
  }
  
  protected String convertFont(String fontFamily)
  {
    String localFont = (String)sLogicFontNameMap.get(fontFamily);
    if (localFont == null) {
      localFont = fontFamily;
    }
    if (sLocalFontFamilyNamesSet.contains(localFont)) {
      return localFont.toLowerCase();
    }
    return FontUtil.getFontFamily(fontFamily);
  }
  
  protected void prepareGraphicsContext()
  {
    _g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, 
      RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    _g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
      RenderingHints.VALUE_ANTIALIAS_ON);
    
    getDisplayServer().setGraphicsContext(_g2d);
  }
  
  public void setProperty(String sProperty, Object oValue)
  {
    if (sProperty.equals("device.output.context"))
    {
      _g2d = ((Graphics2D)oValue);
      prepareGraphicsContext();
    }
    else if (sProperty.equals("device.resolution"))
    {
      getDisplayServer().setDpiResolution(((Integer)oValue).intValue());
    }
  }
  
  public Object getGraphicsContext()
  {
    return _g2d;
  }
  
  public IDisplayServer getDisplayServer()
  {
    return _ids;
  }
  
  public void setClip(ClipRenderEvent cre)
  {
    Location[] loa = cre.getVertices();
    if (loa == null)
    {
      _g2d.setClip(null);
    }
    else
    {
      int[][] i2a = getCoordinatesAsInts(loa);
      _g2d.setClip(new Polygon(i2a[0], i2a[1], loa.length));
    }
  }
  
  public void drawImage(ImageRenderEvent ire)
    throws ChartException
  {
    if (iv != null) {
      iv.modifyEvent(ire);
    }
    if ((ire.getImage() == null) || (ire.getLocation() == null)) {
      return;
    }
    java.awt.Image img = null;
    if ((ire.getImage() instanceof EmbeddedImage)) {
      try
      {
        byte[] data = Base64.decodeBase64(((EmbeddedImage)ire.getImage()).getData()
          .getBytes());
        
        img = createImage(data);
      }
      catch (Exception ilex)
      {
        throw new ChartException("org.eclipse.birt.chart.device.extension", 
          11, 
          ilex);
      }
    } else {
      try
      {
        String sUrl = ire.getImage().getURL();
        img = (java.awt.Image)_ids.loadImage(SecurityUtil.newURL(sUrl));
      }
      catch (ChartException ilex)
      {
        logger.log(new ChartException("org.eclipse.birt.chart.device.extension", 
          11, 
          ilex));
      }
      catch (MalformedURLException muex)
      {
        throw new ChartException("org.eclipse.birt.chart.device.extension", 
          11, 
          muex);
      }
    }
    if (img == null) {
      return;
    }
    Location loc = ire.getLocation();
    Position pos = ire.getPosition();
    if (pos == null) {
      pos = Position.INSIDE_LITERAL;
    }
    ImageObserver io = (ImageObserver)_ids.getObserver();
    
    boolean bSizeSet = ire.getWidth() * ire.getHeight() > 0;
    int width = bSizeSet ? ire.getWidth() : img.getWidth(io);
    int height = bSizeSet ? ire.getHeight() : img.getHeight(io);
    int x = (int)loc.getX();
    int y = (int)loc.getY();
    switch (pos.getValue())
    {
    case 4: 
    case 5: 
      x -= width / 2;
      y -= height / 2;
      break;
    case 2: 
      x -= width;
      y -= height / 2;
      break;
    case 3: 
      y -= height / 2;
      break;
    case 0: 
      x -= width / 2;
      y -= height;
      break;
    case 1: 
      x -= width / 2;
    }
    _g2d.drawImage(img, x, y, width, height, io);
  }
  
  public void drawLine(LineRenderEvent lre)
    throws ChartException
  {
    if (iv != null) {
      iv.modifyEvent(lre);
    }
    LineAttributes lia = lre.getLineAttributes();
    if ((!validateLineAttributes(lre.getSource(), lia)) || 
      (lia.getColor() == null)) {
      return;
    }
    if ((lia.getColor().isSetTransparency()) && 
      (lia.getColor().getTransparency() == 0)) {
      return;
    }
    Location loStart = lre.getStart();
    Location loEnd = lre.getEnd();
    Stroke sPrevious = null;Stroke sCurrent = getCachedStroke(lia);
    if (sCurrent != null)
    {
      sPrevious = _g2d.getStroke();
      _g2d.setStroke(sCurrent);
    }
    _g2d.setColor((Color)_ids.getColor(lia.getColor()));
    _g2d.draw(new Line2D.Double(loStart.getX(), 
      loStart.getY(), 
      loEnd.getX(), 
      loEnd.getY()));
    if (sPrevious != null) {
      _g2d.setStroke(sPrevious);
    }
  }
  
  public void drawRectangle(RectangleRenderEvent rre)
    throws ChartException
  {
    if (iv != null) {
      iv.modifyEvent(rre);
    }
    LineAttributes lia = rre.getOutline();
    if (!validateLineAttributes(rre.getSource(), lia)) {
      return;
    }
    Color cFG = (Color)validateEdgeColor(lia.getColor(), 
      rre.getBackground(), 
      _ids);
    if ((cFG == null) || (cFG.getAlpha() == 0)) {
      return;
    }
    Bounds bo = normalizeBounds(rre.getBounds());
    Stroke sPrevious = null;
    Stroke sCurrent = getCachedStroke(lia);
    if (sCurrent != null)
    {
      sPrevious = _g2d.getStroke();
      _g2d.setStroke(sCurrent);
    }
    _g2d.setColor(cFG);
    _g2d.draw(new Rectangle2D.Double(bo.getLeft(), 
      bo.getTop(), 
      bo.getWidth() - 1.0D, 
      bo.getHeight() - 1.0D));
    if (sPrevious != null) {
      _g2d.setStroke(sPrevious);
    }
  }
  
  public void fillRectangle(RectangleRenderEvent rre)
    throws ChartException
  {
    if (iv != null) {
      iv.modifyEvent(rre);
    }
    Fill flBackground = validateMultipleFill(rre.getBackground());
    if (isFullTransparent(flBackground)) {
      return;
    }
    Bounds bo = normalizeBounds(rre.getBounds());
    Rectangle2D.Double r2d = new Rectangle2D.Double(bo.getLeft(), 
      bo.getTop(), 
      bo.getWidth(), 
      bo.getHeight());
    if ((flBackground instanceof ColorDefinition))
    {
      ColorDefinition cd = (ColorDefinition)flBackground;
      _g2d.setColor((Color)_ids.getColor(cd));
      _g2d.fill(r2d);
    }
    else if ((flBackground instanceof Gradient))
    {
      Gradient g = (Gradient)flBackground;
      ColorDefinition cdStart = g.getStartColor();
      ColorDefinition cdEnd = g.getEndColor();
      
      double dAngleInDegrees = g.getDirection();
      double dAngleInRadians = -dAngleInDegrees * 3.141592653589793D / 180.0D;
      if ((dAngleInDegrees < -90.0D) || (dAngleInDegrees > 90.0D)) {
        throw new ChartException("org.eclipse.birt.chart.device.extension", 
          11, 
          "SwingRendererImpl.exception.gradient.angle", 
          new Object[] {
          new Double(dAngleInDegrees) }, 
          
          Messages.getResourceBundle(getULocale()));
      }
      Point2D.Double p2dEnd;
      Point2D.Double p2dStart;
      Point2D.Double p2dEnd;
      if (dAngleInDegrees == 90.0D)
      {
        Point2D.Double p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop() + 
          bo.getHeight());
        p2dEnd = new Point2D.Double(bo.getLeft(), bo.getTop());
      }
      else
      {
        Point2D.Double p2dStart;
        if (dAngleInDegrees == -90.0D)
        {
          Point2D.Double p2dEnd = new Point2D.Double(bo.getLeft(), bo.getTop() + 
            bo.getHeight());
          p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop());
        }
        else
        {
          Point2D.Double p2dEnd;
          if (dAngleInDegrees > 0.0D)
          {
            Point2D.Double p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop() + 
              bo.getHeight());
            p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), 
              bo.getTop() + 
              bo.getHeight() - 
              bo.getWidth() * 
              Math.abs(Math.tan(dAngleInRadians)));
          }
          else
          {
            Point2D.Double p2dEnd;
            if (dAngleInDegrees < 0.0D)
            {
              Point2D.Double p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop());
              p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), 
                bo.getTop() + 
                bo.getWidth() * 
                Math.abs(Math.tan(dAngleInRadians)));
            }
            else
            {
              p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop());
              p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), 
                bo.getTop());
            }
          }
        }
      }
      _g2d.setPaint(new GradientPaint(p2dStart, 
        (Color)_ids.getColor(cdStart), 
        p2dEnd, 
        (Color)_ids.getColor(cdEnd)));
      _g2d.fill(r2d);
    }
    else if ((flBackground instanceof org.eclipse.birt.chart.model.attribute.Image))
    {
      if ((flBackground instanceof PatternImage))
      {
        fillWithPatternImage(new Area(r2d), flBackground);
        return;
      }
      java.awt.Image img = createImageFromModel(flBackground);
      if (img != null)
      {
        Shape shClip = _g2d.getClip();
        Area ar2 = new Area(r2d);
        if (shClip != null)
        {
          Area ar1 = new Area(shClip);
          ar2.intersect(ar1);
        }
        _g2d.setClip(ar2);
        
        Size szImage = computeImageSize(img);
        
        int iXRepeat = (int)Math.ceil(width / 
          szImage.getWidth());
        int iYRepeat = (int)Math.ceil(height / 
          szImage.getHeight());
        ImageObserver io = (ImageObserver)_ids.getObserver();
        for (int i = 0; i < iXRepeat; i++) {
          for (int j = 0; j < iYRepeat; j++)
          {
            img = scaleImage(img);
            _g2d.drawImage(img, 
              (int)(x + i * szImage.getWidth()), 
              (int)(y + j * szImage.getHeight()), 
              io);
          }
        }
        _g2d.setClip(shClip);
      }
    }
  }
  
  private Size computeImageSize(java.awt.Image img)
  {
    Size size = _ids.getSize(img);
    double scale = _ids.getDpiResolution() / 72.0D;
    size.setWidth(size.getWidth() * scale);
    size.setHeight(size.getHeight() * scale);
    return size;
  }
  
  public void drawPolygon(PolygonRenderEvent pre)
    throws ChartException
  {
    if (iv != null) {
      iv.modifyEvent(pre);
    }
    LineAttributes lia = pre.getOutline();
    if (!validateLineAttributes(pre.getSource(), lia)) {
      return;
    }
    Color cFG = (Color)validateEdgeColor(lia.getColor(), 
      pre.getBackground(), 
      _ids);
    if ((cFG == null) || (cFG.getAlpha() == 0)) {
      return;
    }
    Location[] la = pre.getPoints();
    int[][] i2a = getCoordinatesAsInts(la);
    Stroke sPrevious = null;
    Stroke sCurrent = getCachedStroke(lia);
    if (sCurrent != null)
    {
      sPrevious = _g2d.getStroke();
      _g2d.setStroke(sCurrent);
    }
    _g2d.setColor(cFG);
    _g2d.draw(new Polygon(i2a[0], i2a[1], la.length));
    if (sPrevious != null) {
      _g2d.setStroke(sPrevious);
    }
  }
  
  public void fillPolygon(PolygonRenderEvent pre)
    throws ChartException
  {
    if (iv != null) {
      iv.modifyEvent(pre);
    }
    Fill flBackground = validateMultipleFill(pre.getBackground());
    if (isFullTransparent(flBackground)) {
      return;
    }
    Location[] loa = pre.getPoints();
    int[][] i2a = getCoordinatesAsInts(loa);
    if ((flBackground instanceof ColorDefinition))
    {
      ColorDefinition cd = (ColorDefinition)flBackground;
      _g2d.setColor((Color)_ids.getColor(cd));
      _g2d.fill(new Polygon(i2a[0], i2a[1], loa.length));
    }
    else if ((flBackground instanceof Gradient))
    {
      Gradient g = (Gradient)flBackground;
      ColorDefinition cdStart = g.getStartColor();
      ColorDefinition cdEnd = g.getEndColor();
      
      double dAngleInDegrees = g.getDirection();
      double dAngleInRadians = -dAngleInDegrees * 3.141592653589793D / 180.0D;
      
      double dMinX = BaseRenderer.getX(loa, 2);
      double dMaxX = BaseRenderer.getX(loa, 1);
      double dMinY = BaseRenderer.getY(loa, 2);
      double dMaxY = BaseRenderer.getY(loa, 1);
      if ((dAngleInDegrees < -90.0D) || (dAngleInDegrees > 90.0D)) {
        throw new ChartException("org.eclipse.birt.chart.device.extension", 
          11, 
          "SwingRendererImpl.exception.gradient.angle", 
          new Object[] {
          new Double(dAngleInDegrees) }, 
          
          Messages.getResourceBundle(getULocale()));
      }
      Point2D.Double p2dEnd;
      Point2D.Double p2dStart;
      Point2D.Double p2dEnd;
      if (dAngleInDegrees == 90.0D)
      {
        Point2D.Double p2dStart = new Point2D.Double(dMinX, dMaxY);
        p2dEnd = new Point2D.Double(dMinX, dMinY);
      }
      else
      {
        Point2D.Double p2dEnd;
        if (dAngleInDegrees == -90.0D)
        {
          Point2D.Double p2dStart = new Point2D.Double(dMinX, dMinY);
          p2dEnd = new Point2D.Double(dMinX, dMaxY);
        }
        else
        {
          Point2D.Double p2dEnd;
          if (dAngleInDegrees > 0.0D)
          {
            Point2D.Double p2dStart = new Point2D.Double(dMinX, dMaxY);
            p2dEnd = new Point2D.Double(dMaxX, dMaxY - 
              (dMaxX - dMinX) * 
              Math.abs(Math.tan(dAngleInRadians)));
          }
          else
          {
            Point2D.Double p2dEnd;
            if (dAngleInDegrees < 0.0D)
            {
              Point2D.Double p2dStart = new Point2D.Double(dMinX, dMinY);
              p2dEnd = new Point2D.Double(dMaxX, dMinY + 
                (dMaxX - dMinX) * 
                Math.abs(Math.tan(dAngleInRadians)));
            }
            else
            {
              p2dStart = new Point2D.Double(dMinX, dMinY);
              p2dEnd = new Point2D.Double(dMaxX, dMinY);
            }
          }
        }
      }
      _g2d.setPaint(new GradientPaint(p2dStart, 
        (Color)_ids.getColor(cdStart), 
        p2dEnd, 
        (Color)_ids.getColor(cdEnd)));
      _g2d.fill(new Polygon(i2a[0], i2a[1], loa.length));
    }
    else if ((flBackground instanceof org.eclipse.birt.chart.model.attribute.Image))
    {
      Area ar2 = new Area(new Polygon(i2a[0], i2a[1], loa.length));
      if ((flBackground instanceof PatternImage))
      {
        fillWithPatternImage(ar2, flBackground);
        return;
      }
      java.awt.Image img = createImageFromModel(flBackground);
      if (img != null)
      {
        Shape shClip = _g2d.getClip();
        if (shClip != null)
        {
          Area ar1 = new Area(shClip);
          ar2.intersect(ar1);
        }
        _g2d.setClip(ar2);
        
        double dMinX = BaseRenderer.getX(loa, 2);
        double dMaxX = BaseRenderer.getX(loa, 1);
        double dMinY = BaseRenderer.getY(loa, 2);
        double dMaxY = BaseRenderer.getY(loa, 1);
        Size szImage = _ids.getSize(img);
        
        int iXRepeat = (int)Math.ceil((dMaxX - dMinX) / 
          szImage.getWidth());
        int iYRepeat = (int)Math.ceil((dMaxY - dMinY) / 
          szImage.getHeight());
        ImageObserver io = (ImageObserver)_ids.getObserver();
        for (int i = 0; i < iXRepeat; i++) {
          for (int j = 0; j < iYRepeat; j++) {
            _g2d.drawImage(img, 
              (int)(dMinX + i * szImage.getWidth()), 
              (int)(dMinY + j * szImage.getHeight()), io);
          }
        }
        _g2d.setClip(shClip);
      }
    }
  }
  
  public void drawArc(ArcRenderEvent are)
    throws ChartException
  {
    if (iv != null) {
      iv.modifyEvent(are);
    }
    LineAttributes lia = are.getOutline();
    if (!validateLineAttributes(are.getSource(), lia)) {
      return;
    }
    Color cFG = (Color)validateEdgeColor(lia.getColor(), 
      are.getBackground(), 
      _ids);
    if ((cFG == null) || (cFG.getAlpha() == 0)) {
      return;
    }
    Stroke sPrevious = null;
    Stroke sCurrent = getCachedStroke(lia);
    if (sCurrent != null)
    {
      sPrevious = _g2d.getStroke();
      _g2d.setStroke(sCurrent);
    }
    _g2d.setColor(cFG);
    if (((are.getInnerRadius() >= 0.0D) && (are.getOuterRadius() > 0.0D) && (are.getInnerRadius() < are.getOuterRadius())) || (
      (are.getInnerRadius() > 0.0D) && (are.getOuterRadius() <= 0.0D)))
    {
      Bounds rctOuter = getOuterRectangle(are);
      Bounds rctInner = getInnerRectangle(are);
      
      Shape outerArc = new Arc2D.Double(rctOuter.getLeft(), 
        rctOuter.getTop(), 
        rctOuter.getWidth(), 
        rctOuter.getHeight(), 
        are.getStartAngle(), 
        are.getAngleExtent(), 
        0);
      Shape innerArc = new Arc2D.Double(rctInner.getLeft(), 
        rctInner.getTop(), 
        rctInner.getWidth(), 
        rctInner.getHeight(), 
        are.getStartAngle() + are.getAngleExtent(), 
        -are.getAngleExtent(), 
        0);
      
      double startAngle = Math.toRadians(-are.getStartAngle());
      double stopAngle = Math.toRadians(-are.getStartAngle() - 
        are.getAngleExtent());
      
      double xsOuter = rctOuter.getLeft() + (Math.cos(startAngle) * 0.5D + 0.5D) * 
        rctOuter.getWidth();
      double ysOuter = rctOuter.getTop() + (Math.sin(startAngle) * 0.5D + 0.5D) * 
        rctOuter.getHeight();
      
      double xeInner = rctInner.getLeft() + (Math.cos(stopAngle) * 0.5D + 0.5D) * 
        rctInner.getWidth();
      double yeInner = rctInner.getTop() + (Math.sin(stopAngle) * 0.5D + 0.5D) * 
        rctInner.getHeight();
      
      GeneralPath gp = new GeneralPath();
      gp.append(outerArc, false);
      gp.lineTo((float)xeInner, (float)yeInner);
      gp.append(innerArc, false);
      gp.lineTo((float)xsOuter, (float)ysOuter);
      
      Area area = new Area(gp);
      Shape prevClip = _g2d.getClip();
      Area ar2 = new Area(area);
      if (prevClip != null)
      {
        Area ar1 = new Area(prevClip);
        ar2.intersect(ar1);
      }
      _g2d.setClip(ar2);
      _g2d.draw(area);
      _g2d.setClip(prevClip);
    }
    else
    {
      _g2d.draw(new Arc2D.Double(are.getTopLeft().getX(), 
        are.getTopLeft().getY(), 
        are.getWidth(), 
        are.getHeight(), 
        are.getStartAngle(), 
        are.getAngleExtent(), 
        toG2dArcType(are.getStyle())));
    }
    if (sPrevious != null) {
      _g2d.setStroke(sPrevious);
    }
  }
  
  protected Bounds getOuterRectangle(ArcRenderEvent are)
  {
    Bounds rctOuter;
    Bounds rctOuter;
    if (are.getOuterRadius() > 0.0D)
    {
      double radio = are.getHeight() / are.getWidth();
      rctOuter = BoundsImpl.create(are.getTopLeft().getX() + 
        (are.getWidth() - 2.0D * are.getOuterRadius()) / 2.0D, 
        are.getTopLeft().getY() + 
        (are.getHeight() - 2.0D * are.getOuterRadius() * radio) / 
        2.0D, 
        2.0D * are.getOuterRadius(), 
        2.0D * are.getOuterRadius() * radio);
    }
    else
    {
      rctOuter = BoundsImpl.create(are.getTopLeft().getX(), 
        are.getTopLeft().getY(), 
        are.getWidth(), 
        are.getHeight());
    }
    return rctOuter;
  }
  
  protected Bounds getInnerRectangle(ArcRenderEvent are)
  {
    Bounds rctInner;
    Bounds rctInner;
    if (are.getInnerRadius() > 0.0D)
    {
      double radio = are.getHeight() / are.getWidth();
      rctInner = BoundsImpl.create(are.getTopLeft().getX() + 
        (are.getWidth() - 2.0D * are.getInnerRadius()) / 
        2.0D, 
        are.getTopLeft().getY() + 
        (are.getHeight() - 2.0D * 
        are.getInnerRadius() * 
        radio) / 
        2.0D, 
        2.0D * are.getInnerRadius(), 
        2.0D * are.getInnerRadius() * radio);
    }
    else
    {
      rctInner = BoundsImpl.create(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());
    }
    return rctInner;
  }
  
  public void fillArc(ArcRenderEvent are)
    throws ChartException
  {
    if (iv != null) {
      iv.modifyEvent(are);
    }
    Fill flBackground = validateMultipleFill(are.getBackground());
    if (isFullTransparent(flBackground)) {
      return;
    }
    if ((flBackground instanceof ColorDefinition))
    {
      ColorDefinition cl = (ColorDefinition)flBackground;
      Color clrPrevious = _g2d.getColor();
      Color currentColor = (Color)_ids.getColor(cl);
      _g2d.setColor(currentColor);
      if (((are.getInnerRadius() >= 0.0D) && (are.getOuterRadius() > 0.0D) && (are.getInnerRadius() < are.getOuterRadius())) || (
        (are.getInnerRadius() > 0.0D) && (are.getOuterRadius() <= 0.0D)))
      {
        Bounds rctOuter = getOuterRectangle(are);
        Bounds rctInner = getInnerRectangle(are);
        
        Shape outerArc = new Arc2D.Double(rctOuter.getLeft(), 
          rctOuter.getTop(), 
          rctOuter.getWidth(), 
          rctOuter.getHeight(), 
          are.getStartAngle(), 
          are.getAngleExtent(), 
          2);
        
        Shape innerArc = new Arc2D.Double(rctInner.getLeft(), 
          rctInner.getTop(), 
          rctInner.getWidth(), 
          rctInner.getHeight(), 
          are.getStartAngle(), 
          are.getAngleExtent(), 
          2);
        
        Area fArea = new Area(outerArc);
        fArea.exclusiveOr(new Area(innerArc));
        
        Shape prevClip = _g2d.getClip();
        Area ar2 = new Area(fArea);
        if (prevClip != null)
        {
          Area ar1 = new Area(prevClip);
          ar2.intersect(ar1);
        }
        _g2d.setClip(ar2);
        _g2d.fill(fArea);
        _g2d.setClip(prevClip);
      }
      else
      {
        _g2d.fill(new Arc2D.Double(are.getTopLeft().getX(), 
          are.getTopLeft().getY(), 
          are.getWidth(), 
          are.getHeight(), 
          are.getStartAngle(), 
          are.getAngleExtent(), 
          toG2dArcType(are.getStyle())));
      }
      _g2d.setColor(clrPrevious);
    }
    else if ((flBackground instanceof Gradient))
    {
      Gradient g = (Gradient)flBackground;
      ColorDefinition cdStart = g.getStartColor();
      ColorDefinition cdEnd = g.getEndColor();
      double dAngleInDegrees = g.getDirection();
      double dAngleInRadians = -dAngleInDegrees * 3.141592653589793D / 180.0D;
      Bounds bo = are.getBounds();
      if ((dAngleInDegrees < -90.0D) || (dAngleInDegrees > 90.0D)) {
        throw new ChartException("org.eclipse.birt.chart.device.extension", 
          11, 
          "SwingRendererImpl.exception.gradient.angle", 
          new Object[] {
          new Double(dAngleInDegrees) }, 
          
          Messages.getResourceBundle(getULocale()));
      }
      Point2D.Double p2dEnd;
      Point2D.Double p2dStart;
      Point2D.Double p2dEnd;
      if (dAngleInDegrees == 90.0D)
      {
        Point2D.Double p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop() + 
          bo.getHeight());
        p2dEnd = new Point2D.Double(bo.getLeft(), bo.getTop());
      }
      else
      {
        Point2D.Double p2dStart;
        if (dAngleInDegrees == -90.0D)
        {
          Point2D.Double p2dEnd = new Point2D.Double(bo.getLeft(), bo.getTop() + 
            bo.getHeight());
          p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop());
        }
        else
        {
          Point2D.Double p2dEnd;
          if (dAngleInDegrees > 0.0D)
          {
            Point2D.Double p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop() + 
              bo.getHeight());
            p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), 
              bo.getTop() + 
              bo.getHeight() - 
              bo.getWidth() * 
              Math.abs(Math.tan(dAngleInRadians)));
          }
          else
          {
            Point2D.Double p2dEnd;
            if (dAngleInDegrees < 0.0D)
            {
              Point2D.Double p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop());
              p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), 
                bo.getTop() + 
                bo.getWidth() * 
                Math.abs(Math.tan(dAngleInRadians)));
            }
            else
            {
              p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop());
              p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), 
                bo.getTop());
            }
          }
        }
      }
      Paint pPrevious = _g2d.getPaint();
      _g2d.setPaint(new GradientPaint(p2dStart, 
        (Color)_ids.getColor(cdStart), 
        p2dEnd, 
        (Color)_ids.getColor(cdEnd)));
      if (((are.getInnerRadius() >= 0.0D) && (are.getOuterRadius() > 0.0D) && (are.getInnerRadius() < are.getOuterRadius())) || (
        (are.getInnerRadius() > 0.0D) && (are.getOuterRadius() <= 0.0D)))
      {
        Bounds rctOuter = getOuterRectangle(are);
        Bounds rctInner = getInnerRectangle(are);
        
        Shape outerArc = new Arc2D.Double(rctOuter.getLeft(), 
          rctOuter.getTop(), 
          rctOuter.getWidth(), 
          rctOuter.getHeight(), 
          are.getStartAngle(), 
          are.getAngleExtent(), 
          2);
        
        Shape innerArc = new Arc2D.Double(rctInner.getLeft(), 
          rctInner.getTop(), 
          rctInner.getWidth(), 
          rctInner.getHeight(), 
          are.getStartAngle(), 
          are.getAngleExtent(), 
          2);
        
        Area fArea = new Area(outerArc);
        fArea.exclusiveOr(new Area(innerArc));
        
        Shape prevClip = _g2d.getClip();
        Area ar2 = new Area(fArea);
        if (prevClip != null)
        {
          Area ar1 = new Area(prevClip);
          ar2.intersect(ar1);
        }
        _g2d.setClip(ar2);
        _g2d.fill(fArea);
        _g2d.setClip(prevClip);
      }
      else
      {
        _g2d.fill(new Arc2D.Double(are.getTopLeft().getX(), 
          are.getTopLeft().getY(), 
          are.getWidth(), 
          are.getHeight(), 
          are.getStartAngle(), 
          are.getAngleExtent(), 
          toG2dArcType(are.getStyle())));
      }
      _g2d.setPaint(pPrevious);
    }
    else if ((flBackground instanceof org.eclipse.birt.chart.model.attribute.Image))
    {
      Bounds bo = are.getBounds();
      Rectangle2D.Double r2d = new Rectangle2D.Double(bo.getLeft(), 
        bo.getTop(), 
        bo.getWidth(), 
        bo.getHeight());
      
      Shape shPreviousClip = _g2d.getClip();
      Area ar = null;
      if (((are.get
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

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-2017. Infinite Loop Ltd