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

16:41:24.848 INFO  jd.cli.Main - Decompiling org.eclipse.birt.chart.device.swt_3.7.2.v20120213.jar
package org.eclipse.birt.chart.device.swt;

import org.eclipse.core.runtime.Plugin;
import org.osgi.framework.BundleContext;

public class ChartDeviceSwtActivator
  extends Plugin
{
  public static final String ID = "org.eclipse.birt.chart.device.swt";
  private static ChartDeviceSwtActivator plugin;
  
  public ChartDeviceSwtActivator()
  {
    plugin = this;
  }
  
  public void start(BundleContext context)
    throws Exception
  {
    super.start(context);
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    super.stop(context);
    plugin = null;
  }
  
  public static ChartDeviceSwtActivator getDefault()
  {
    return plugin;
  }
}

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

import com.ibm.icu.util.ULocale;
import org.eclipse.birt.chart.device.swt.i18n.Messages;
import org.eclipse.birt.chart.log.ILogger;
import org.eclipse.birt.chart.log.Logger;
import org.eclipse.birt.chart.model.attribute.ColorDefinition;
import org.eclipse.birt.chart.model.attribute.Gradient;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Region;
import org.eclipse.swt.graphics.Transform;
import org.eclipse.swt.widgets.Display;

final class R31Enhance
{
  private static final boolean R31_AVAILABLE;
  private static ILogger logger = Logger.getLogger("org.eclipse.birt.chart.device.extension/swt");
  
  static
  {
    GC gc = new GC(Display.getDefault());
    gc.setAdvanced(true);
    R31_AVAILABLE = gc.getAdvanced();
    gc.dispose();
    if (R31_AVAILABLE) {
      logger.log(1, 
        Messages.getString("R31Enhance.info.advanced.enabled", 
        ULocale.getDefault()));
    } else {
      logger.log(1, 
        Messages.getString("R31Enhance.info.advanced.disabled", 
        ULocale.getDefault()));
    }
  }
  
  public static boolean isR31Available()
  {
    return R31_AVAILABLE;
  }
  
  static void setAdvanced(GC gc, boolean value, Region clipping)
  {
    if (R31_AVAILABLE)
    {
      gc.setAdvanced(value);
      
      gc.setClipping(clipping);
    }
  }
  
  static void setAlpha(GC gc, int value)
  {
    if (R31_AVAILABLE) {
      gc.setAlpha(value);
    }
  }
  
  static void setAntialias(GC gc, int value)
  {
    if (R31_AVAILABLE) {
      gc.setAntialias(value);
    }
  }
  
  static void setTextAntialias(GC gc, int value)
  {
    if (R31_AVAILABLE) {
      gc.setTextAntialias(value);
    }
  }
  
  static Object newTransform(Device param)
  {
    if (R31_AVAILABLE) {
      return new Transform(param);
    }
    return null;
  }
  
  static void setTransform(GC gc, Object value)
  {
    if (R31_AVAILABLE) {
      gc.setTransform((Transform)value);
    }
  }
  
  static void translate(GC gc, Object transform, float v1, float v2)
  {
    if (R31_AVAILABLE) {
      ((Transform)transform).translate(v1, v2);
    }
  }
  
  static void rotate(GC gc, Object transform, float value)
  {
    if (R31_AVAILABLE) {
      ((Transform)transform).rotate(value);
    }
  }
  
  static void disposeTransform(Object transform)
  {
    if (R31_AVAILABLE) {
      ((Transform)transform).dispose();
    }
  }
  
  static void setAlpha(GC gc, ColorDefinition cd)
  {
    if (R31_AVAILABLE) {
      if ((cd != null) && (cd.isSetTransparency())) {
        setAlpha(gc, cd.getTransparency());
      } else {
        setAlpha(gc, 255);
      }
    }
  }
  
  static void setAlpha(GC gc, Gradient g)
  {
    if (R31_AVAILABLE) {
      if ((g != null) && (g.isSetTransparency())) {
        setAlpha(gc, g.getTransparency());
      } else {
        setAlpha(gc, 255);
      }
    }
  }
}

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

import java.awt.Shape;
import java.awt.geom.Arc2D.Double;
import java.awt.geom.FlatteningPathIterator;
import java.util.ArrayList;
import org.eclipse.birt.chart.computation.GObjectFactory;
import org.eclipse.birt.chart.computation.IGObjectFactory;
import org.eclipse.birt.chart.event.StructureSource;
import org.eclipse.birt.chart.model.attribute.Bounds;
import org.eclipse.birt.chart.model.attribute.Cursor;
import org.eclipse.birt.chart.model.attribute.Location;
import org.eclipse.birt.chart.model.data.Action;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.Region;

public final class RegionAction
{
  private final StructureSource _oSource;
  private Cursor cursor = null;
  private Region region;
  private final Action _ac;
  private static final IGObjectFactory goFactory = ;
  
  private RegionAction(StructureSource source, Region region, Action ac)
  {
    _oSource = source;
    _ac = ac;
    this.region = region;
  }
  
  RegionAction(StructureSource oSource, Location[] loa, Action ac, double dTranslateX, double dTranslateY, double dScale, Region clipping)
  {
    _oSource = oSource;
    int[] i2a = SwtRendererImpl.getCoordinatesAsInts(loa, 
      2, 
      dTranslateX, 
      dTranslateY, 
      dScale);
    Region sh = new Region();
    sh.add(i2a);
    if (clipping != null) {
      sh.intersect(clipping);
    }
    _ac = ac;
    
    region = sh;
  }
  
  RegionAction(StructureSource oSource, Bounds bo, Action ac, double dTranslateX, double dTranslateY, double dScale, Region clipping)
  {
    _oSource = oSource;
    
    bo = goFactory.copyOf(bo);
    bo.translate(dTranslateX, dTranslateY);
    bo.scale(dScale);
    
    Rectangle rect = new Rectangle((int)bo.getLeft(), 
      (int)bo.getTop(), 
      (int)bo.getWidth(), 
      (int)bo.getHeight());
    
    Region sh = new Region();
    sh.add(rect);
    if (clipping != null) {
      sh.intersect(clipping);
    }
    _ac = ac;
    
    region = sh;
  }
  
  private static final int toSwingArcType(int iArcStyle)
  {
    switch (iArcStyle)
    {
    case 1: 
      return 0;
    case 2: 
      return 1;
    case 3: 
      return 2;
    }
    return -1;
  }
  
  private int[] shape2polyCoords(Shape shape)
  {
    if (shape == null) {
      return null;
    }
    ArrayList<Integer> al = new ArrayList();
    
    FlatteningPathIterator pitr = new FlatteningPathIterator(shape.getPathIterator(null), 
      1.0D);
    double[] data = new double[6];
    while (!pitr.isDone())
    {
      int type = pitr.currentSegment(data);
      switch (type)
      {
      case 0: 
        al.add(Integer.valueOf((int)data[0]));
        al.add(Integer.valueOf((int)data[1]));
        break;
      case 1: 
        al.add(Integer.valueOf((int)data[0]));
        al.add(Integer.valueOf((int)data[1]));
        break;
      case 2: 
        al.add(Integer.valueOf((int)data[0]));
        al.add(Integer.valueOf((int)data[1]));
        al.add(Integer.valueOf((int)data[2]));
        al.add(Integer.valueOf((int)data[3]));
        break;
      case 3: 
        al.add(Integer.valueOf((int)data[0]));
        al.add(Integer.valueOf((int)data[1]));
        al.add(Integer.valueOf((int)data[2]));
        al.add(Integer.valueOf((int)data[3]));
        al.add(Integer.valueOf((int)data[4]));
        al.add(Integer.valueOf((int)data[5]));
        break;
      }
      pitr.next();
    }
    if (al.size() == 0) {
      return null;
    }
    int[] coords = new int[al.size()];
    for (int i = 0; i < al.size(); i++) {
      coords[i] = ((Integer)al.get(i)).intValue();
    }
    return coords;
  }
  
  RegionAction(StructureSource oSource, Bounds boEllipse, double dStart, double dExtent, int iArcType, Action ac, double dTranslateX, double dTranslateY, double dScale, Region clipping)
  {
    _oSource = oSource;
    
    boEllipse = goFactory.copyOf(boEllipse);
    boEllipse.translate(dTranslateX, dTranslateY);
    boEllipse.scale(dScale);
    
    Shape shape = new Arc2D.Double(boEllipse.getLeft(), 
      boEllipse.getTop(), 
      boEllipse.getWidth(), 
      boEllipse.getHeight(), 
      dStart, 
      dExtent, 
      toSwingArcType(iArcType));
    
    int[] i2a = shape2polyCoords(shape);
    Region sh = new Region();
    sh.add(i2a);
    if (clipping != null) {
      sh.intersect(clipping);
    }
    _ac = ac;
    region = sh;
  }
  
  public final Action getAction()
  {
    return _ac;
  }
  
  public final StructureSource getSource()
  {
    return _oSource;
  }
  
  public RegionAction copy()
  {
    return new RegionAction(_oSource, region, _ac);
  }
  
  public boolean contains(Point p, GC gc)
  {
    return contains(x, y, gc);
  }
  
  public boolean contains(double x, double y, GC gc)
  {
    if (region != null) {
      return region.contains((int)x, (int)y);
    }
    return false;
  }
  
  public void dispose()
  {
    if (region != null) {
      region.dispose();
    }
  }
  
  public boolean isEmpty()
  {
    if (region != null) {
      return region.isEmpty();
    }
    return true;
  }
  
  public Cursor getCursor()
  {
    return cursor;
  }
  
  public void setCursor(Cursor cursor)
  {
    this.cursor = cursor;
  }
}

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

import java.io.InputStream;
import java.net.URL;
import org.eclipse.birt.chart.device.DisplayAdapter;
import org.eclipse.birt.chart.device.ITextMetrics;
import org.eclipse.birt.chart.device.swt.i18n.Messages;
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.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.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;

public final class SwtDisplayServer
  extends DisplayAdapter
{
  private Device _d = null;
  private double dScale = 1.0D;
  private int iDpiResolution = 0;
  private GC gc;
  private static ILogger logger = Logger.getLogger("org.eclipse.birt.chart.device.extension/swt");
  
  public SwtDisplayServer()
  {
    try
    {
      _d = Display.getDefault();
    }
    catch (Exception ex)
    {
      logger.log(ex);
      logger.log(8, 
        Messages.getString("SwtDisplayServer.exception.display.server", getULocale()));
    }
    logger.log(1, 
      Messages.getString("SwtDisplayServer.info.display.server", 
      new Object[] {
      SWT.getPlatform(), 
      Integer.valueOf(SWT.getVersion()) }, 
      
      getULocale()));
  }
  
  public Object createFont(FontDefinition fd)
  {
    int iStyle = 0;
    if (fd.isBold()) {
      iStyle |= 0x1;
    }
    if (fd.isItalic()) {
      iStyle |= 0x2;
    }
    return new Font(_d, fd.getName(), (int)Math.round(fd.getSize() * 
      dScale), iStyle);
  }
  
  public Object getColor(ColorDefinition cd)
  {
    return new Color(_d, cd.getRed(), cd.getGreen(), cd.getBlue());
  }
  
  public final int getDpiResolution()
  {
    if (iDpiResolution == 0) {
      iDpiResolution = _d.getDPI().x;
    }
    return iDpiResolution;
  }
  
  public void setDpiResolution(int dpi)
  {
    throw new UnsupportedOperationException("The dpi resolution depends on the Device you are rendering to (Display or Printer), and can't be set programmatically");
  }
  
  public Object loadImage(URL url)
    throws ChartException
  {
    try
    {
      URL urlFound = findResource(url);
      InputStream is = urlFound.openStream();
      Image img = new Image(_d, is);
      is.close();
      return img;
    }
    catch (Exception ex)
    {
      throw new ChartException("org.eclipse.birt.chart.device.swt", 
        4, 
        ex);
    }
  }
  
  public Size getSize(Object oImage)
  {
    Image img = (Image)oImage;
    Rectangle r = img.getBounds();
    return SizeImpl.create(width, height);
  }
  
  public ITextMetrics getTextMetrics(Label la, boolean autoReuse)
  {
    return new SwtTextMetrics(this, la, gc, autoReuse);
  }
  
  final Device getDevice()
  {
    return _d;
  }
  
  final void setScale(double dScale)
  {
    this.dScale = dScale;
  }
  
  public void setGraphicsContext(Object gc)
  {
    this.gc = ((GC)gc);
    _d = this.gc.getDevice();
  }
  
  public GC getGraphicContext()
  {
    return gc;
  }
}

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

import org.eclipse.birt.chart.model.attribute.URLValue;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;

class SwtEventHandler$1
  extends SelectionAdapter
{
  SwtEventHandler$1(SwtEventHandler paramSwtEventHandler) {}
  
  public void widgetSelected(SelectionEvent e)
  {
    URLValue urlValue = (URLValue)((MenuItem)e.getSource()).getData();
    SwtEventHandler.access$0(this$0, urlValue);
    SwtEventHandler.access$1(this$0).dispose();
  }
}

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

import com.ibm.icu.util.ULocale;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.codec.binary.Base64;
import org.eclipse.birt.chart.device.ICallBackNotifier;
import org.eclipse.birt.chart.device.IUpdateNotifier;
import org.eclipse.birt.chart.device.swt.i18n.Messages;
import org.eclipse.birt.chart.device.swt.util.SwtUtil;
import org.eclipse.birt.chart.event.StructureSource;
import org.eclipse.birt.chart.log.ILogger;
import org.eclipse.birt.chart.log.Logger;
import org.eclipse.birt.chart.model.attribute.ActionType;
import org.eclipse.birt.chart.model.attribute.ActionValue;
import org.eclipse.birt.chart.model.attribute.CallBackValue;
import org.eclipse.birt.chart.model.attribute.CursorType;
import org.eclipse.birt.chart.model.attribute.EmbeddedImage;
import org.eclipse.birt.chart.model.attribute.MultiURLValues;
import org.eclipse.birt.chart.model.attribute.Text;
import org.eclipse.birt.chart.model.attribute.TooltipValue;
import org.eclipse.birt.chart.model.attribute.TriggerCondition;
import org.eclipse.birt.chart.model.attribute.URLValue;
import org.eclipse.birt.chart.model.component.Label;
import org.eclipse.birt.chart.model.data.Action;
import org.eclipse.birt.chart.render.InteractiveRenderer;
import org.eclipse.birt.chart.util.SecurityUtil;
import org.eclipse.emf.common.util.EList;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;

class SwtEventHandler
  implements MouseListener, MouseMoveListener, MouseTrackListener, KeyListener, FocusListener
{
  private static final ILogger logger = Logger.getLogger("org.eclipse.birt.chart.device.extension/swt");
  private final org.eclipse.swt.graphics.Cursor hand_cursor;
  private final LinkedHashMap<TriggerCondition, List<RegionAction>> lhmAllTriggers;
  private final IUpdateNotifier iun;
  private RegionAction raTooltip = null;
  private final ULocale lcl;
  private final GC _gc;
  private InteractiveRenderer iv = null;
  private StructureSource srcHighlight;
  private StructureSource srcToggleDataPoint;
  private StructureSource srcToggleVisibility;
  private Menu popupMenu;
  
  SwtEventHandler(InteractiveRenderer iv, LinkedHashMap<TriggerCondition, List<RegionAction>> _lhmAllTriggers, IUpdateNotifier _jc, ULocale _lcl)
  {
    lhmAllTriggers = _lhmAllTriggers;
    iun = _jc;
    lcl = _lcl;
    hand_cursor = new org.eclipse.swt.graphics.Cursor(Display.getDefault(), 21);
    _gc = new GC(Display.getDefault());
    this.iv = iv;
  }
  
  private final List<RegionAction> getActionsForConditions(TriggerCondition[] tca)
  {
    if ((tca == null) || (tca.length == 0)) {
      return null;
    }
    List<RegionAction> al = new ArrayList();
    for (int i = 0; i < tca.length; i++)
    {
      List<RegionAction> tal = (List)lhmAllTriggers.get(tca[i]);
      if (tal != null) {
        al.addAll(tal);
      }
    }
    if (al.size() > 0) {
      return al;
    }
    return null;
  }
  
  private final boolean isLeftButton(MouseEvent e)
  {
    return button == 1;
  }
  
  private void handleAction(TriggerCondition[] tgArray, Object event)
  {
    handleAction(tgArray, event, true);
  }
  
  private synchronized void handleAction(TriggerCondition[] tgArray, Object event, boolean cleanState)
  {
    List<RegionAction> al = getActionsForConditions(tgArray);
    if ((al == null) || (event == null)) {
      return;
    }
    RegionAction ra = null;
    Action ac = null;
    
    Point p = null;
    if ((event instanceof MouseEvent)) {
      p = new Point(x, y);
    }
    (event instanceof KeyEvent);
    
    boolean bFound = false;
    for (int i = 0; i < al.size(); i++)
    {
      ra = (RegionAction)al.get(i);
      if ((p == null) || (ra.contains(p, _gc)))
      {
        ac = ra.getAction();
        StructureSource src = ra.getSource();
        switch (ac.getType().getValue())
        {
        case 0: 
          ActionValue av = ac.getValue();
          if ((av instanceof URLValue))
          {
            URLValue uv = (URLValue)ac.getValue();
            openURL(uv);
          }
          else if ((av instanceof MultiURLValues))
          {
            MultiURLValues muv = (MultiURLValues)av;
            int size = muv.getURLValues().size();
            if (size != 0) {
              if (size == 1) {
                openURL((URLValue)muv.getURLValues().get(0));
              } else {
                openMultiURLs(muv, p);
              }
            }
          }
          break;
        case 1: 
          if (ra != raTooltip) {
            hideTooltip();
          }
          raTooltip = ra;
          bFound = true;
          showTooltip(raTooltip);
          break;
        case 2: 
          bFound = true;
          srcToggleVisibility = handleGraphicAction(src, 
            srcToggleVisibility, 
            ActionType.TOGGLE_VISIBILITY_LITERAL, 
            cleanState);
          
          break;
        case 6: 
          bFound = true;
          srcToggleDataPoint = handleGraphicAction(src, 
            srcToggleDataPoint, 
            ActionType.TOGGLE_DATA_POINT_VISIBILITY_LITERAL, 
            cleanState);
          
          break;
        case 4: 
          bFound = true;
          srcHighlight = handleGraphicAction(src, 
            srcHighlight, 
            ActionType.HIGHLIGHT_LITERAL, 
            cleanState);
          
          break;
        case 5: 
          if ((iun instanceof ICallBackNotifier))
          {
            CallBackValue cv = (CallBackValue)ac.getValue();
            ((ICallBackNotifier)iun).callback(event, 
              ra.getSource(), 
              cv);
            break label480;
          }
          logger.log(2, 
            Messages.getString("SwtEventHandler.info.improper.callback.notifier", 
            new Object[] {
            iun }, 
            
            lcl));
          break label480;
        }
      }
    }
    label480:
    if (!bFound) {
      disableActions(getActionTypesForConditions(tgArray));
    }
  }
  
  private void openMultiURLs(MultiURLValues muv, Point point)
  {
    Composite comp = (Composite)iun.peerInstance();
    if ((popupMenu != null) && (!popupMenu.isDisposed())) {
      popupMenu.dispose();
    }
    popupMenu = new Menu(comp.getShell(), 8);
    comp.setMenu(popupMenu);
    for (URLValue uv : muv.getURLValues())
    {
      MenuItem menuItem = new MenuItem(popupMenu, 8);
      menuItem.setText(uv.getLabel().getCaption().getValue());
      menuItem.setData(uv);
      menuItem.addSelectionListener(new SelectionAdapter()
      {
        public void widgetSelected(SelectionEvent e)
        {
          URLValue urlValue = (URLValue)((MenuItem)e.getSource()).getData();
          SwtEventHandler.this.openURL(urlValue);
          popupMenu.dispose();
        }
      });
    }
    comp.getMenu().setVisible(true);
  }
  
  private void openURL(URLValue uv)
  {
    logger.log(1, 
      Messages.getString("SwtEventHandler.info.redirect.url", lcl) + 
      uv.getBaseUrl());
    SwtUtil.openURL(uv.getBaseUrl());
  }
  
  protected Set<ActionType> getActionTypesForConditions(TriggerCondition[] tca)
  {
    if ((tca == null) || (tca.length == 0)) {
      return null;
    }
    Set<ActionType> set = new HashSet();
    for (int i = 0; i < tca.length; i++)
    {
      List<RegionAction> tal = (List)lhmAllTriggers.get(tca[i]);
      if (tal != null) {
        for (Iterator<RegionAction> iter = tal.iterator(); iter.hasNext();)
        {
          RegionAction rg = (RegionAction)iter.next();
          ActionType actionType = rg.getAction().getType();
          set.add(actionType);
        }
      }
    }
    return set;
  }
  
  private void disableActions(Set<ActionType> actions)
  {
    if (actions == null) {
      return;
    }
    for (Iterator<ActionType> iter = actions.iterator(); iter.hasNext();)
    {
      ActionType action = (ActionType)iter.next();
      if (action != null) {
        switch (action.getValue())
        {
        case 1: 
          if (raTooltip != null)
          {
            hideTooltip();
            raTooltip = null;
          }
          break;
        case 4: 
          if (srcHighlight != null)
          {
            iv.unregisterAction(srcHighlight, ActionType.HIGHLIGHT_LITERAL);
            srcHighlight = null;
            iun.repaintChart();
          }
          break;
        case 6: 
          if (srcToggleDataPoint != null)
          {
            iv.unregisterAction(srcToggleDataPoint, ActionType.TOGGLE_DATA_POINT_VISIBILITY_LITERAL);
            srcToggleDataPoint = null;
            iun.repaintChart();
          }
          break;
        case 2: 
          if (srcToggleVisibility != null)
          {
            iv.unregisterAction(srcToggleVisibility, ActionType.TOGGLE_VISIBILITY_LITERAL);
            srcToggleVisibility = null;
            iun.repaintChart();
          }
          break;
        }
      }
    }
  }
  
  private StructureSource handleGraphicAction(StructureSource src, StructureSource previousSrc, ActionType actionType, boolean cleanState)
  {
    if (previousSrc == null)
    {
      previousSrc = src;
      iv.registerAction(src, 
        actionType);
      iun.repaintChart();
    }
    else if (!iv.getSource(src).equals(iv.getSource(previousSrc)))
    {
      if (actionType == ActionType.HIGHLIGHT_LITERAL)
      {
        iv.unregisterAction(previousSrc, actionType);
        previousSrc = src;
        iv.registerAction(src, actionType);
      }
      else
      {
        previousSrc = src;
        if (iv.isRegisteredAction(src, actionType)) {
          iv.unregisterAction(src, actionType);
        } else {
          iv.registerAction(src, actionType);
        }
      }
      iun.repaintChart();
    }
    else if (cleanState)
    {
      iv.unregisterAction(previousSrc, 
        actionType);
      previousSrc = null;
      iun.repaintChart();
    }
    return previousSrc;
  }
  
  public void mouseDoubleClick(MouseEvent e)
  {
    if (!isLeftButton(e)) {
      return;
    }
    TriggerCondition[] tgArray = {
      TriggerCondition.ONDBLCLICK_LITERAL };
    
    handleAction(tgArray, e);
  }
  
  public void mouseDown(MouseEvent e)
  {
    if (!isLeftButton(e)) {
      return;
    }
    TriggerCondition[] tgArray = {
      TriggerCondition.ONMOUSEDOWN_LITERAL };
    
    handleAction(tgArray, e);
  }
  
  public void mouseUp(MouseEvent e)
  {
    TriggerCondition[] tgArray = 
    
      {isLeftButton(e) ? new TriggerCondition[] {TriggerCondition.ONMOUSEUP_LITERAL, TriggerCondition.ONCLICK_LITERAL, TriggerCondition.MOUSE_CLICK_LITERAL } : 
      TriggerCondition.ONRIGHTCLICK_LITERAL };
    
    handleAction(tgArray, e);
  }
  
  public void mouseMove(MouseEvent e)
  {
    List<RegionAction> al = getActionsForConditions(new TriggerCondition[] {
      TriggerCondition.ONCLICK_LITERAL, 
      TriggerCondition.ONMOUSEDOWN_LITERAL, 
      TriggerCondition.MOUSE_CLICK_LITERAL, 
      TriggerCondition.ONMOUSEMOVE_LITERAL, 
      TriggerCondition.ONMOUSEOVER_LITERAL });
    if (al != null)
    {
      boolean bFound = false;
      for (int i = 0; i < al.size(); i++)
      {
        RegionAction ra = (RegionAction)al.get(i);
        if (ra.contains(x, y, _gc))
        {
          setCursor((Composite)iun.peerInstance(), ra.getCursor(), hand_cursor);
          bFound = true;
          break;
        }
      }
      if (!bFound) {
        setCursor((Composite)iun.peerInstance(), null, null);
      }
    }
    TriggerCondition[] tgArray = {
      TriggerCondition.ONMOUSEMOVE_LITERAL, 
      TriggerCondition.ONMOUSEOVER_LITERAL };
    if (tgArray != null) {
      handleAction(tgArray, e, false);
    }
  }
  
  public void keyPressed(KeyEvent e)
  {
    TriggerCondition[] tg = {
      TriggerCondition.ONKEYDOWN_LITERAL };
    
    handleAction(tg, e);
  }
  
  public void keyReleased(KeyEvent e)
  {
    TriggerCondition[] tg = {
      TriggerCondition.ONKEYUP_LITERAL, 
      TriggerCondition.ONKEYPRESS_LITERAL };
    
    handleAction(tg, e);
  }
  
  public void mouseEnter(MouseEvent e) {}
  
  public void mouseExit(MouseEvent e)
  {
    TriggerCondition[] tg = {
      TriggerCondition.ONMOUSEOUT_LITERAL };
    
    handleAction(tg, e);
  }
  
  public void mouseHover(MouseEvent e) {}
  
  public void focusGained(FocusEvent e)
  {
    handleAction(new TriggerCondition[] {
      TriggerCondition.ONFOCUS_LITERAL }, 
      e);
  }
  
  public void focusLost(FocusEvent e)
  {
    handleAction(new TriggerCondition[] {
      TriggerCondition.ONBLUR_LITERAL }, 
      e);
  }
  
  private final void hideTooltip()
  {
    ((Composite)iun.peerInstance()).setToolTipText(null);
  }
  
  private final void showTooltip(RegionAction ra)
  {
    Action ac = ra.getAction();
    TooltipValue tv = (TooltipValue)ac.getValue();
    String s = tv.getText();
    
    ((Composite)iun.peerInstance()).setToolTipText(s);
  }
  
  private void setCursor(Composite composite, org.eclipse.birt.chart.model.attribute.Cursor cursor, org.eclipse.swt.graphics.Cursor defaultCursor)
  {
    if ((cursor == null) || (cursor.getType() == CursorType.AUTO))
    {
      composite.setCursor(defaultCursor);
      return;
    }
    if (cursor.getType() == CursorType.CUSTOM)
    {
      EList<org.eclipse.birt.chart.model.attribute.Image> uris = cursor.getImage();
      for (org.eclipse.birt.chart.model.attribute.Image uri : uris) {
        try
        {
          ImageData id = null;
          if ((uri instanceof EmbeddedImage))
          {
            ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decodeBase64(((EmbeddedImage)uri).getData()
              .getBytes()));
            
            id = new org.eclipse.swt.graphics.Image(Display.getDefault(), 
              bis).getImageData();
          }
          else
          {
            File f = SecurityUtil.newFile(new URI(uri.getURL()));
            id = new ImageData(SecurityUtil.newFileInputStream(f));
          }
          composite.setCursor(new org.eclipse.swt.graphics.Cursor(composite.getDisplay(), 
            id, 
            0, 
            0));
          return;
        }
        catch (FileNotFoundException localFileNotFoundException) {}catch (URISyntaxException localURISyntaxException) {}catch (Exception localException) {}
      }
      composite.setCursor(defaultCursor);
      return;
    }
    composite.setCursor(new org.eclipse.swt.graphics.Cursor(Display.getDefault(), ((Integer)SwtUtil.CURSOR_MAP.get(cursor.getType())).intValue()));
  }
  
  public final void dispose()
  {
    hand_cursor.dispose();
    _gc.dispose();
  }
}

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

import java.io.ByteArrayInputStream;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import org.apache.commons.codec.binary.Base64;
import org.eclipse.birt.chart.computation.IGObjectFactory;
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.IUpdateNotifier;
import org.eclipse.birt.chart.device.swt.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.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.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.Text;
import org.eclipse.birt.chart.model.attribute.TriggerCondition;
import org.eclipse.birt.chart.model.component.Label;
import org.eclipse.birt.chart.model.data.Trigger;
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.PluginSettings;
import org.eclipse.birt.chart.util.SecurityUtil;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.Path;
import org.eclipse.swt.graphics.Pattern;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.Region;
import org.eclipse.swt.widgets.Composite;

public class SwtRendererImpl
  extends DeviceAdapter
{
  public static final String DOUBLE_BUFFERED = "device.double.buffered";
  private final LinkedHashMap<TriggerCondition, List<RegionAction>> _lhmAllTriggers = new LinkedHashMap();
  private IDisplayServer _ids;
  private SwtTextRenderer _tr;
  private GC _gc = null;
  private IUpdateNotifier _iun = null;
  private SwtEventHandler _eh = null;
  private double dTranslateX = 0.0D;
  private double dTranslateY = 0.0D;
  private double dRotateInDegrees = 0.0D;
  private double dScale = 1.0D;
  private InteractiveRenderer iv;
  static final int CEIL = 1;
  static final int TRUNCATE = 2;
  private static ILogger logger = Logger.getLogger("org.eclipse.birt.chart.device.extension/swt");
  
  public SwtRendererImpl()
  {
    PluginSettings ps = PluginSettings.instance();
    try
    {
      _ids = ps.getDisplayServer("ds.SWT");
      _tr = new SwtTextRenderer(_ids);
      iv = new InteractiveRenderer();
    }
    catch (ChartException pex)
    {
      logger.log(pex);
    }
  }
  
  public Object getGraphicsContext()
  {
    return _gc;
  }
  
  public IDisplayServer getDisplayServer()
  {
    return _ids;
  }
  
  public void setClip(ClipRenderEvent cre)
  {
    Location[] loa = cre.getVertices();
    if (loa == null)
    {
      _gc.setClipping(null);
    }
    else
    {
      Region rgClipping = new Region();
      rgClipping.add(getCoordinatesAsInts(loa, 
        2, 
        dTranslateX, 
        dTranslateY, 
        dScale));
      _gc.setClipping(rgClipping);
      rgClipping.dispose();
    }
  }
  
  public void drawImage(ImageRenderEvent pre)
    throws ChartException
  {
    if ((pre.getImage() == null) || (pre.getLocation() == null)) {
      return;
    }
    org.eclipse.swt.graphics.Image img = null;
    if ((pre.getImage() instanceof EmbeddedImage)) {
      try
      {
        ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decodeBase64(((EmbeddedImage)pre.getImage()).getData()
          .getBytes()));
        
        img = new org.eclipse.swt.graphics.Image(((SwtDisplayServer)_ids).getDevice(), 
          bis);
      }
      catch (Exception ilex)
      {
        throw new ChartException("org.eclipse.birt.chart.device.swt", 
          11, 
          ilex);
      }
    } else {
      try
      {
        String sUrl = pre.getImage().getURL();
        img = (org.eclipse.swt.graphics.Image)_ids.loadImage(SecurityUtil.newURL(sUrl));
      }
      catch (ChartException ilex)
      {
        logger.log(new ChartException("org.eclipse.birt.chart.device.swt", 
          11, 
          ilex));
      }
      catch (MalformedURLException muex)
      {
        throw new ChartException("org.eclipse.birt.chart.device.swt", 
          11, 
          muex);
      }
    }
    if (img == null) {
      return;
    }
    Location loc = pre.getLocation();
    Position pos = pre.getPosition();
    if (pos == null) {
      pos = Position.INSIDE_LITERAL;
    }
    boolean bSizeSet = pre.getWidth() * pre.getHeight() > 0;
    int width = bSizeSet ? pre.getWidth() : getBoundswidth;
    int height = bSizeSet ? pre.getHeight() : getBoundsheight;
    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;
    }
    R31Enhance.setAlpha(_gc, null);
    if (bSizeSet) {
      _gc.drawImage(img, 
        0, 
        0, 
        getBoundswidth, 
        getBoundsheight, 
        x, 
        y, 
        pre.getWidth(), 
        pre.getHeight());
    } else {
      _gc.drawImage(img, x, y);
    }
    img.dispose();
  }
  
  public void drawLine(LineRenderEvent lre)
    throws ChartException
  {
    iv.modifyEvent(lre);
    
    LineAttributes lia = lre.getLineAttributes();
    if ((!validateLineAttributes(lre.getSource(), lia)) || 
      (lia.getColor() == null)) {
      return;
    }
    int iOldLineStyle = _gc.getLineStyle();
    int iOldLineWidth = _gc.getLineWidth();
    Color cFG = (Color)_ids.getColor(lia.getColor());
    int iLineStyle = 1;
    switch (lia.getStyle().getValue())
    {
    case 2: 
      iLineStyle = 3;
      break;
    case 3: 
      iLineStyle = 4;
      break;
    case 1: 
      iLineStyle = 2;
    }
    _gc.setLineStyle(iLineStyle);
    _gc.setLineWidth(lia.getThickness());
    Location lo1 = lre.getStart();
    Location lo2 = lre.getEnd();
    _gc.setForeground(cFG);
    
    R31Enhance.setAlpha(_gc, lia.getColor());
    
    _gc.drawLine((int)((lo1.getX() + dTranslateX) * dScale), 
      (int)((lo1.getY() + dTranslateY) * dScale), 
      (int)((lo2.getX() + dTranslateX) * dScale), 
      (int)((lo2.getY() + dTranslateY) * dScale));
    
    _gc.setLineStyle(iOldLineStyle);
    _gc.setLineWidth(iOldLineWidth);
    cFG.dispose();
  }
  
  public void drawRectangle(RectangleRenderEvent rre)
    throws ChartException
  {
    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) {
      return;
    }
    int iOldLineStyle = _gc.getLineStyle();
    int iOldLineWidth = _gc.getLineWidth();
    int iLineStyle = 1;
    switch (lia.getStyle().getValue())
    {
    case 2: 
      iLineStyle = 3;
      break;
    case 3: 
      iLineStyle = 4;
      break;
    case 1: 
      iLineStyle = 2;
    }
    _gc.setLineStyle(iLineStyle);
    _gc.setLineWidth(lia.getThickness());
    Bounds bo = normalizeBounds(rre.getBounds());
    _gc.setForeground(cFG);
    
    R31Enhance.setAlpha(_gc, lia.getColor());
    
    _gc.drawRectangle((int)((bo.getLeft() + dTranslateX) * dScale), 
      (int)((bo.getTop() + dTranslateY) * dScale), 
      (int)(bo.getWidth() * dScale) - 1, 
      (int)(bo.getHeight() * dScale) - 1);
    
    _gc.setLineStyle(iOldLineStyle);
    _gc.setLineWidth(iOldLineWidth);
    cFG.dispose();
  }
  
  /* Error */
  public void fillRectangle(RectangleRenderEvent rre)
    throws ChartException
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 900	org/eclipse/birt/chart/device/swt/SwtRendererImpl:iv	Lorg/eclipse/birt/chart/render/InteractiveRenderer;
    //   4: aload_1
    //   5: invokevirtual 1036	org/eclipse/birt/chart/render/InteractiveRenderer:modifyEvent	(Lorg/eclipse/birt/chart/event/PrimitiveRenderEvent;)V
    //   8: aload_0
    //   9: aload_1
    //   10: invokevirtual 1014	org/eclipse/birt/chart/event/RectangleRenderEvent:getBackground	()Lorg/eclipse/birt/chart/model/attribute/Fill;
    //   13: invokevirtual 955	org/eclipse/birt/chart/device/swt/SwtRendererImpl:validateMultipleFill	(Lorg/eclipse/birt/chart/model/attribute/Fill;)Lorg/eclipse/birt/chart/model/attribute/Fill;
    //   16: astore_2
    //   17: aload_0
    //   18: aload_2
    //   19: invokevirtual 949	org/eclipse/birt/chart/device/swt/SwtRendererImpl:isFullTransparent	(Lorg/eclipse/birt/chart/model/attribute/Fill;)Z
    //   22: ifeq +4 -> 26
    //   25: return
    //   26: aload_1
    //   27: invokevirtual 1013	org/eclipse/birt/chart/event/RectangleRenderEvent:getBounds	()Lorg/eclipse/birt/chart/model/attribute/Bounds;
    //   30: invokestatic 953	org/eclipse/birt/chart/device/swt/SwtRendererImpl
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-2017. Infinite Loop Ltd