jfreechart-swt-1.0.9

16:37:40.178 INFO  jd.cli.Main - Decompiling jfreechart-swt-1.0.9.jar
package org.jfree.experimental.chart.swt;

import java.awt.Graphics;
import java.awt.RenderingHints;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.File;
import java.io.IOException;
import java.util.ResourceBundle;
import javax.swing.event.EventListenerList;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.HelpListener;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.internal.SWTEventListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.MessageBox;
import org.jfree.chart.ChartMouseEvent;
import org.jfree.chart.ChartMouseListener;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.entity.ChartEntity;
import org.jfree.chart.entity.EntityCollection;
import org.jfree.chart.event.ChartChangeEvent;
import org.jfree.chart.event.ChartChangeListener;
import org.jfree.chart.event.ChartProgressEvent;
import org.jfree.chart.event.ChartProgressListener;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.PlotRenderingInfo;
import org.jfree.chart.plot.ValueAxisPlot;
import org.jfree.chart.plot.Zoomable;
import org.jfree.experimental.chart.swt.editor.SWTChartEditor;
import org.jfree.experimental.swt.SWTGraphics2D;
import org.jfree.experimental.swt.SWTUtils;

public class ChartComposite
  extends Composite
  implements ChartChangeListener, ChartProgressListener, PaintListener, SelectionListener, MouseListener, MouseMoveListener, Printable
{
  public static final boolean DEFAULT_BUFFER_USED = false;
  public static final int DEFAULT_WIDTH = 680;
  public static final int DEFAULT_HEIGHT = 420;
  public static final int DEFAULT_MINIMUM_DRAW_WIDTH = 300;
  public static final int DEFAULT_MINIMUM_DRAW_HEIGHT = 200;
  public static final int DEFAULT_MAXIMUM_DRAW_WIDTH = 800;
  public static final int DEFAULT_MAXIMUM_DRAW_HEIGHT = 600;
  public static final int DEFAULT_ZOOM_TRIGGER_DISTANCE = 10;
  public static final String PROPERTIES_COMMAND = "PROPERTIES";
  public static final String SAVE_COMMAND = "SAVE";
  public static final String PRINT_COMMAND = "PRINT";
  public static final String ZOOM_IN_BOTH_COMMAND = "ZOOM_IN_BOTH";
  public static final String ZOOM_IN_DOMAIN_COMMAND = "ZOOM_IN_DOMAIN";
  public static final String ZOOM_IN_RANGE_COMMAND = "ZOOM_IN_RANGE";
  public static final String ZOOM_OUT_BOTH_COMMAND = "ZOOM_OUT_BOTH";
  public static final String ZOOM_OUT_DOMAIN_COMMAND = "ZOOM_DOMAIN_BOTH";
  public static final String ZOOM_OUT_RANGE_COMMAND = "ZOOM_RANGE_BOTH";
  public static final String ZOOM_RESET_BOTH_COMMAND = "ZOOM_RESET_BOTH";
  public static final String ZOOM_RESET_DOMAIN_COMMAND = "ZOOM_RESET_DOMAIN";
  public static final String ZOOM_RESET_RANGE_COMMAND = "ZOOM_RESET_RANGE";
  private JFreeChart chart;
  private Canvas canvas;
  private EventListenerList chartMouseListeners;
  private boolean useBuffer;
  private boolean refreshBuffer;
  private boolean displayToolTips;
  private Image chartBuffer;
  private int chartBufferHeight;
  private int chartBufferWidth;
  private int minimumDrawWidth;
  private int minimumDrawHeight;
  private int maximumDrawWidth;
  private int maximumDrawHeight;
  private Menu popup;
  private ChartRenderingInfo info;
  private Point2D anchor;
  private double scaleX;
  private double scaleY;
  private PlotOrientation orientation = PlotOrientation.VERTICAL;
  private boolean domainZoomable = false;
  private boolean rangeZoomable = false;
  private org.eclipse.swt.graphics.Point zoomPoint = null;
  private transient Rectangle zoomRectangle = null;
  private int zoomTriggerDistance;
  private boolean horizontalAxisTrace = false;
  private boolean verticalAxisTrace = false;
  private transient int verticalTraceLineX;
  private transient int horizontalTraceLineY;
  private MenuItem zoomInBothMenuItem;
  private MenuItem zoomInDomainMenuItem;
  private MenuItem zoomInRangeMenuItem;
  private MenuItem zoomOutBothMenuItem;
  private MenuItem zoomOutDomainMenuItem;
  private MenuItem zoomOutRangeMenuItem;
  private MenuItem zoomResetBothMenuItem;
  private MenuItem zoomResetDomainMenuItem;
  private MenuItem zoomResetRangeMenuItem;
  private boolean enforceFileExtensions;
  private double zoomInFactor = 0.5D;
  private double zoomOutFactor = 2.0D;
  protected static ResourceBundle localizationResources = ResourceBundle.getBundle("org.jfree.chart.LocalizationBundle");
  
  public ChartComposite(Composite comp, int style)
  {
    this(comp, style, null, 680, 420, 300, 200, 800, 600, false, true, true, true, true, true);
  }
  
  public ChartComposite(Composite comp, int style, JFreeChart chart)
  {
    this(comp, style, chart, 680, 420, 300, 200, 800, 600, false, true, true, true, true, true);
  }
  
  public ChartComposite(Composite comp, int style, JFreeChart chart, boolean useBuffer)
  {
    this(comp, style, chart, 680, 420, 300, 200, 800, 600, useBuffer, true, true, true, true, true);
  }
  
  public ChartComposite(Composite comp, int style, JFreeChart chart, boolean properties, boolean save, boolean print, boolean zoom, boolean tooltips)
  {
    this(comp, style, chart, 680, 420, 300, 200, 800, 600, false, properties, save, print, zoom, tooltips);
  }
  
  public ChartComposite(Composite comp, int style, JFreeChart jfreechart, int width, int height, int minimumDrawW, int minimumDrawH, int maximumDrawW, int maximumDrawH, boolean usingBuffer, boolean properties, boolean save, boolean print, boolean zoom, boolean tooltips)
  {
    super(comp, style);
    setChart(jfreechart);
    chartMouseListeners = new EventListenerList();
    setLayout(new FillLayout());
    info = new ChartRenderingInfo();
    useBuffer = usingBuffer;
    refreshBuffer = false;
    minimumDrawWidth = minimumDrawW;
    minimumDrawHeight = minimumDrawH;
    maximumDrawWidth = maximumDrawW;
    maximumDrawHeight = maximumDrawH;
    zoomTriggerDistance = 10;
    setDisplayToolTips(tooltips);
    
    canvas = new Canvas(this, 537133056);
    canvas.addPaintListener(this);
    canvas.addMouseListener(this);
    canvas.addMouseMoveListener(this);
    if (chart != null)
    {
      chart.addChangeListener(this);
      Plot plot = chart.getPlot();
      domainZoomable = false;
      rangeZoomable = false;
      if ((plot instanceof Zoomable))
      {
        Zoomable z = (Zoomable)plot;
        domainZoomable = z.isDomainZoomable();
        rangeZoomable = z.isRangeZoomable();
        orientation = z.getOrientation();
      }
    }
    popup = null;
    if ((properties) || (save) || (print) || (zoom)) {
      popup = createPopupMenu(properties, save, print, zoom);
    }
    enforceFileExtensions = true;
  }
  
  public double getScaleX()
  {
    return scaleX;
  }
  
  public double getScaleY()
  {
    return scaleY;
  }
  
  public Point2D getAnchor()
  {
    return anchor;
  }
  
  protected void setAnchor(Point2D anchor)
  {
    this.anchor = anchor;
  }
  
  public JFreeChart getChart()
  {
    return chart;
  }
  
  public void setChart(JFreeChart chart)
  {
    if (this.chart != null)
    {
      this.chart.removeChangeListener(this);
      this.chart.removeProgressListener(this);
    }
    this.chart = chart;
    if (chart != null)
    {
      this.chart.addChangeListener(this);
      this.chart.addProgressListener(this);
      Plot plot = chart.getPlot();
      domainZoomable = false;
      rangeZoomable = false;
      if ((plot instanceof Zoomable))
      {
        Zoomable z = (Zoomable)plot;
        domainZoomable = z.isDomainZoomable();
        rangeZoomable = z.isRangeZoomable();
        orientation = z.getOrientation();
      }
    }
    else
    {
      domainZoomable = false;
      rangeZoomable = false;
    }
    if (useBuffer) {
      refreshBuffer = true;
    }
  }
  
  public ChartRenderingInfo getChartRenderingInfo()
  {
    return info;
  }
  
  public boolean isDomainZoomable()
  {
    return domainZoomable;
  }
  
  public void setDomainZoomable(boolean flag)
  {
    if (flag)
    {
      Plot plot = chart.getPlot();
      if ((plot instanceof Zoomable))
      {
        Zoomable z = (Zoomable)plot;
        domainZoomable = ((flag) && (z.isDomainZoomable()));
      }
    }
    else
    {
      domainZoomable = false;
    }
  }
  
  public boolean isRangeZoomable()
  {
    return rangeZoomable;
  }
  
  public void setRangeZoomable(boolean flag)
  {
    if (flag)
    {
      Plot plot = chart.getPlot();
      if ((plot instanceof Zoomable))
      {
        Zoomable z = (Zoomable)plot;
        rangeZoomable = ((flag) && (z.isRangeZoomable()));
      }
    }
    else
    {
      rangeZoomable = false;
    }
  }
  
  public double getZoomInFactor()
  {
    return zoomInFactor;
  }
  
  public void setZoomInFactor(double factor)
  {
    zoomInFactor = factor;
  }
  
  public double getZoomOutFactor()
  {
    return zoomOutFactor;
  }
  
  public void setZoomOutFactor(double factor)
  {
    zoomOutFactor = factor;
  }
  
  private void attemptEditChartProperties()
  {
    SWTChartEditor editor = new SWTChartEditor(canvas.getDisplay(), chart);
    
    editor.open();
  }
  
  public boolean isEnforceFileExtensions()
  {
    return enforceFileExtensions;
  }
  
  public void setEnforceFileExtensions(boolean enforce)
  {
    enforceFileExtensions = enforce;
  }
  
  public void doSaveAs()
    throws IOException
  {
    FileDialog fileDialog = new FileDialog(canvas.getShell(), 8192);
    
    String[] extensions = { "*.png" };
    fileDialog.setFilterExtensions(extensions);
    String filename = fileDialog.open();
    if (filename != null)
    {
      if ((isEnforceFileExtensions()) && 
        (!filename.endsWith(".png"))) {
        filename = filename + ".png";
      }
      ChartUtilities.saveChartAsPNG(new File(filename), chart, canvas.getSize().x, canvas.getSize().y);
    }
  }
  
  private org.eclipse.swt.graphics.Point getPointInRectangle(int x, int y, Rectangle area)
  {
    x = Math.max(x, Math.min(x, x + width));
    y = Math.max(y, Math.min(y, y + height));
    return new org.eclipse.swt.graphics.Point(x, y);
  }
  
  public void zoomInBoth(double x, double y)
  {
    zoomInDomain(x, y);
    zoomInRange(x, y);
  }
  
  public void zoomInDomain(double x, double y)
  {
    Plot p = chart.getPlot();
    if ((p instanceof Zoomable))
    {
      Zoomable plot = (Zoomable)p;
      plot.zoomDomainAxes(zoomInFactor, info.getPlotInfo(), translateScreenToJava2D(new java.awt.Point((int)x, (int)y)));
    }
  }
  
  public void zoomInRange(double x, double y)
  {
    Plot p = chart.getPlot();
    if ((p instanceof Zoomable))
    {
      Zoomable z = (Zoomable)p;
      z.zoomRangeAxes(zoomInFactor, info.getPlotInfo(), translateScreenToJava2D(new java.awt.Point((int)x, (int)y)));
    }
  }
  
  public void zoomOutBoth(double x, double y)
  {
    zoomOutDomain(x, y);
    zoomOutRange(x, y);
  }
  
  public void zoomOutDomain(double x, double y)
  {
    Plot p = chart.getPlot();
    if ((p instanceof Zoomable))
    {
      Zoomable z = (Zoomable)p;
      z.zoomDomainAxes(zoomOutFactor, info.getPlotInfo(), translateScreenToJava2D(new java.awt.Point((int)x, (int)y)));
    }
  }
  
  public void zoomOutRange(double x, double y)
  {
    Plot p = chart.getPlot();
    if ((p instanceof Zoomable))
    {
      Zoomable z = (Zoomable)p;
      z.zoomRangeAxes(zoomOutFactor, info.getPlotInfo(), translateScreenToJava2D(new java.awt.Point((int)x, (int)y)));
    }
  }
  
  public void zoom(Rectangle selection)
  {
    Point2D selectOrigin = translateScreenToJava2D(new java.awt.Point(x, y));
    
    PlotRenderingInfo plotInfo = info.getPlotInfo();
    Rectangle scaledDataArea = getScreenDataArea(x + width / 2, y + height / 2);
    if ((height > 0) && (width > 0))
    {
      double hLower = (x - x) / width;
      
      double hUpper = (x + width - x) / width;
      
      double vLower = (y + height - y - height) / height;
      
      double vUpper = (y + height - y) / height;
      
      Plot p = chart.getPlot();
      if ((p instanceof Zoomable))
      {
        Zoomable z = (Zoomable)p;
        if (z.getOrientation() == PlotOrientation.HORIZONTAL)
        {
          z.zoomDomainAxes(vLower, vUpper, plotInfo, selectOrigin);
          z.zoomRangeAxes(hLower, hUpper, plotInfo, selectOrigin);
        }
        else
        {
          z.zoomDomainAxes(hLower, hUpper, plotInfo, selectOrigin);
          z.zoomRangeAxes(vLower, vUpper, plotInfo, selectOrigin);
        }
      }
    }
  }
  
  public void chartChanged(ChartChangeEvent event)
  {
    refreshBuffer = true;
    Plot plot = chart.getPlot();
    if ((plot instanceof Zoomable))
    {
      Zoomable z = (Zoomable)plot;
      orientation = z.getOrientation();
    }
    canvas.redraw();
  }
  
  public void forceRedraw()
  {
    Event ev = new Event();
    gc = new GC(canvas);
    x = 0;
    y = 0;
    width = canvas.getBounds().width;
    height = canvas.getBounds().height;
    count = 0;
    canvas.notifyListeners(9, ev);
    gc.dispose();
  }
  
  public void addChartMouseListener(ChartMouseListener listener)
  {
    chartMouseListeners.add(ChartMouseListener.class, listener);
  }
  
  public void removeChartMouseListener(ChartMouseListener listener)
  {
    chartMouseListeners.remove(ChartMouseListener.class, listener);
  }
  
  public void chartProgress(ChartProgressEvent event) {}
  
  public void restoreAutoBounds()
  {
    restoreAutoDomainBounds();
    restoreAutoRangeBounds();
  }
  
  public void restoreAutoDomainBounds()
  {
    Plot p = chart.getPlot();
    if ((p instanceof Zoomable))
    {
      Zoomable z = (Zoomable)p;
      
      org.eclipse.swt.graphics.Point zp = zoomPoint != null ? zoomPoint : new org.eclipse.swt.graphics.Point(0, 0);
      
      z.zoomDomainAxes(0.0D, info.getPlotInfo(), SWTUtils.toAwtPoint(zp));
    }
  }
  
  public void restoreAutoRangeBounds()
  {
    Plot p = chart.getPlot();
    if ((p instanceof ValueAxisPlot))
    {
      Zoomable z = (Zoomable)p;
      
      org.eclipse.swt.graphics.Point zp = zoomPoint != null ? zoomPoint : new org.eclipse.swt.graphics.Point(0, 0);
      
      z.zoomRangeAxes(0.0D, info.getPlotInfo(), SWTUtils.toAwtPoint(zp));
    }
  }
  
  public Rectangle scale(Rectangle2D rect)
  {
    Rectangle insets = getClientArea();
    int x = (int)Math.round(rect.getX() * getScaleX()) + x;
    int y = (int)Math.round(rect.getY() * getScaleY()) + y;
    int w = (int)Math.round(rect.getWidth() * getScaleX());
    int h = (int)Math.round(rect.getHeight() * getScaleY());
    return new Rectangle(x, y, w, h);
  }
  
  public Rectangle getScreenDataArea()
  {
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();
    Rectangle clientArea = getClientArea();
    int x = (int)(dataArea.getX() * scaleX + x);
    int y = (int)(dataArea.getY() * scaleY + y);
    int w = (int)(dataArea.getWidth() * scaleX);
    int h = (int)(dataArea.getHeight() * scaleY);
    return new Rectangle(x, y, w, h);
  }
  
  public Rectangle getScreenDataArea(int x, int y)
  {
    PlotRenderingInfo plotInfo = info.getPlotInfo();
    Rectangle result;
    Rectangle result;
    if (plotInfo.getSubplotCount() == 0)
    {
      result = getScreenDataArea();
    }
    else
    {
      Point2D selectOrigin = translateScreenToJava2D(new java.awt.Point(x, y));
      int subplotIndex = plotInfo.getSubplotIndex(selectOrigin);
      if (subplotIndex == -1) {
        return null;
      }
      result = scale(plotInfo.getSubplotInfo(subplotIndex).getDataArea());
    }
    return result;
  }
  
  public java.awt.Point translateJava2DToScreen(Point2D java2DPoint)
  {
    Rectangle insets = getClientArea();
    int x = (int)(java2DPoint.getX() * scaleX + x);
    int y = (int)(java2DPoint.getY() * scaleY + y);
    return new java.awt.Point(x, y);
  }
  
  public java.awt.Point translateScreenToJavaSWT(java.awt.Point screenPoint)
  {
    Rectangle insets = getClientArea();
    int x = (int)((x - x) / scaleX);
    int y = (int)((y - y) / scaleY);
    return new java.awt.Point(x, y);
  }
  
  public Point2D translateScreenToJava2D(java.awt.Point screenPoint)
  {
    Rectangle insets = getClientArea();
    int x = (int)((x - x) / scaleX);
    int y = (int)((y - y) / scaleY);
    return new Point2D.Double(x, y);
  }
  
  public boolean getHorizontalAxisTrace()
  {
    return horizontalAxisTrace;
  }
  
  public void setHorizontalAxisTrace(boolean flag)
  {
    horizontalAxisTrace = flag;
  }
  
  public boolean getVerticalAxisTrace()
  {
    return verticalAxisTrace;
  }
  
  public void setVerticalAxisTrace(boolean flag)
  {
    verticalAxisTrace = flag;
  }
  
  public void setDisplayToolTips(boolean displayToolTips)
  {
    this.displayToolTips = displayToolTips;
  }
  
  public String getToolTipText(org.eclipse.swt.events.MouseEvent e)
  {
    String result = null;
    if (info != null)
    {
      EntityCollection entities = info.getEntityCollection();
      if (entities != null)
      {
        Rectangle insets = getClientArea();
        ChartEntity entity = entities.getEntity((int)((x - x) / scaleX), (int)((y - y) / scaleY));
        if (entity != null) {
          result = entity.getToolTipText();
        }
      }
    }
    return result;
  }
  
  protected void displayPopupMenu(int x, int y)
  {
    if (popup != null)
    {
      Plot plot = chart.getPlot();
      boolean isDomainZoomable = false;
      boolean isRangeZoomable = false;
      if ((plot instanceof Zoomable))
      {
        Zoomable z = (Zoomable)plot;
        isDomainZoomable = z.isDomainZoomable();
        isRangeZoomable = z.isRangeZoomable();
      }
      if (zoomInDomainMenuItem != null) {
        zoomInDomainMenuItem.setEnabled(isDomainZoomable);
      }
      if (zoomOutDomainMenuItem != null) {
        zoomOutDomainMenuItem.setEnabled(isDomainZoomable);
      }
      if (zoomResetDomainMenuItem != null) {
        zoomResetDomainMenuItem.setEnabled(isDomainZoomable);
      }
      if (zoomInRangeMenuItem != null) {
        zoomInRangeMenuItem.setEnabled(isRangeZoomable);
      }
      if (zoomOutRangeMenuItem != null) {
        zoomOutRangeMenuItem.setEnabled(isRangeZoomable);
      }
      if (zoomResetRangeMenuItem != null) {
        zoomResetRangeMenuItem.setEnabled(isRangeZoomable);
      }
      if (zoomInBothMenuItem != null) {
        zoomInBothMenuItem.setEnabled(isDomainZoomable & isRangeZoomable);
      }
      if (zoomOutBothMenuItem != null) {
        zoomOutBothMenuItem.setEnabled(isDomainZoomable & isRangeZoomable);
      }
      if (zoomResetBothMenuItem != null) {
        zoomResetBothMenuItem.setEnabled(isDomainZoomable & isRangeZoomable);
      }
      popup.setLocation(x, y);
      popup.setVisible(true);
    }
  }
  
  public void createChartPrintJob()
  {
    PrinterJob job = PrinterJob.getPrinterJob();
    PageFormat pf = job.defaultPage();
    PageFormat pf2 = job.pageDialog(pf);
    if (pf2 != pf)
    {
      job.setPrintable(this, pf2);
      if (job.printDialog()) {
        try
        {
          job.print();
        }
        catch (PrinterException e)
        {
          MessageBox messageBox = new MessageBox(canvas.getShell(), 33);
          
          messageBox.setMessage(e.getMessage());
          messageBox.open();
        }
      }
    }
  }
  
  protected Menu createPopupMenu(boolean properties, boolean save, boolean print, boolean zoom)
  {
    Menu result = new Menu(this);
    boolean separator = false;
    if (properties)
    {
      MenuItem propertiesItem = new MenuItem(result, 8);
      propertiesItem.setText(localizationResources.getString("Properties..."));
      
      propertiesItem.setData("PROPERTIES");
      propertiesItem.addSelectionListener(this);
      separator = true;
    }
    if (save)
    {
      if (separator)
      {
        new MenuItem(result, 2);
        separator = false;
      }
      MenuItem saveItem = new MenuItem(result, 0);
      saveItem.setText(localizationResources.getString("Save_as..."));
      saveItem.setData("SAVE");
      saveItem.addSelectionListener(this);
      separator = true;
    }
    if (print)
    {
      if (separator)
      {
        new MenuItem(result, 2);
        separator = false;
      }
      MenuItem printItem = new MenuItem(result, 0);
      printItem.setText(localizationResources.getString("Print..."));
      printItem.setData("PRINT");
      printItem.addSelectionListener(this);
      separator = true;
    }
    if (zoom)
    {
      if (separator)
      {
        new MenuItem(result, 2);
        separator = false;
      }
      Menu zoomInMenu = new Menu(result);
      MenuItem zoomInMenuItem = new MenuItem(result, 64);
      zoomInMenuItem.setText(localizationResources.getString("Zoom_In"));
      zoomInMenuItem.setMenu(zoomInMenu);
      
      zoomInBothMenuItem = new MenuItem(zoomInMenu, 8);
      zoomInBothMenuItem.setText(localizationResources.getString("All_Axes"));
      
      zoomInBothMenuItem.setData("ZOOM_IN_BOTH");
      zoomInBothMenuItem.addSelectionListener(this);
      
      new MenuItem(zoomInMenu, 2);
      
      zoomInDomainMenuItem = new MenuItem(zoomInMenu, 8);
      zoomInDomainMenuItem.setText(localizationResources.getString("Domain_Axis"));
      
      zoomInDomainMenuItem.setData("ZOOM_IN_DOMAIN");
      zoomInDomainMenuItem.addSelectionListener(this);
      
      zoomInRangeMenuItem = new MenuItem(zoomInMenu, 8);
      zoomInRangeMenuItem.setText(localizationResources.getString("Range_Axis"));
      
      zoomInRangeMenuItem.setData("ZOOM_IN_RANGE");
      zoomInRangeMenuItem.addSelectionListener(this);
      
      Menu zoomOutMenu = new Menu(result);
      MenuItem zoomOutMenuItem = new MenuItem(result, 64);
      zoomOutMenuItem.setText(localizationResources.getString("Zoom_Out"));
      
      zoomOutMenuItem.setMenu(zoomOutMenu);
      
      zoomOutBothMenuItem = new MenuItem(zoomOutMenu, 8);
      zoomOutBothMenuItem.setText(localizationResources.getString("All_Axes"));
      
      zoomOutBothMenuItem.setData("ZOOM_OUT_BOTH");
      zoomOutBothMenuItem.addSelectionListener(this);
      
      new MenuItem(zoomOutMenu, 2);
      
      zoomOutDomainMenuItem = new MenuItem(zoomOutMenu, 8);
      zoomOutDomainMenuItem.setText(localizationResources.getString("Domain_Axis"));
      
      zoomOutDomainMenuItem.setData("ZOOM_DOMAIN_BOTH");
      zoomOutDomainMenuItem.addSelectionListener(this);
      
      zoomOutRangeMenuItem = new MenuItem(zoomOutMenu, 8);
      zoomOutRangeMenuItem.setText(localizationResources.getString("Range_Axis"));
      
      zoomOutRangeMenuItem.setData("ZOOM_RANGE_BOTH");
      zoomOutRangeMenuItem.addSelectionListener(this);
      
      Menu autoRangeMenu = new Menu(result);
      MenuItem autoRangeMenuItem = new MenuItem(result, 64);
      autoRangeMenuItem.setText(localizationResources.getString("Auto_Range"));
      
      autoRangeMenuItem.setMenu(autoRangeMenu);
      
      zoomResetBothMenuItem = new MenuItem(autoRangeMenu, 8);
      zoomResetBothMenuItem.setText(localizationResources.getString("All_Axes"));
      
      zoomResetBothMenuItem.setData("ZOOM_RESET_BOTH");
      zoomResetBothMenuItem.addSelectionListener(this);
      
      new MenuItem(autoRangeMenu, 2);
      
      zoomResetDomainMenuItem = new MenuItem(autoRangeMenu, 8);
      
      zoomResetDomainMenuItem.setText(localizationResources.getString("Domain_Axis"));
      
      zoomResetDomainMenuItem.setData("ZOOM_RESET_DOMAIN");
      zoomResetDomainMenuItem.addSelectionListener(this);
      
      zoomResetRangeMenuItem = new MenuItem(autoRangeMenu, 8);
      zoomResetRangeMenuItem.setText(localizationResources.getString("Range_Axis"));
      
      zoomResetRangeMenuItem.setData("ZOOM_RESET_RANGE");
      zoomResetRangeMenuItem.addSelectionListener(this);
    }
    return result;
  }
  
  public void widgetDefaultSelected(SelectionEvent e)
  {
    widgetSelected(e);
  }
  
  public void widgetSelected(SelectionEvent e)
  {
    String command = (String)((MenuItem)e.getSource()).getData();
    if (command.equals("PROPERTIES")) {
      attemptEditChartProperties();
    } else if (command.equals("SAVE")) {
      try
      {
        doSaveAs();
      }
      catch (IOException ex)
      {
        ex.printStackTrace();
      }
    } else if (command.equals("PRINT")) {
      createChartPrintJob();
    } else if (command.equals("ZOOM_IN_BOTH")) {
      zoomInBoth(x, y);
    } else if (command.equals("ZOOM_IN_DOMAIN")) {
      zoomInDomain(x, y);
    } else if (command.equals("ZOOM_IN_RANGE")) {
      zoomInRange(x, y);
    } else if (command.equals("ZOOM_OUT_BOTH")) {
      zoomOutBoth(x, y);
    } else if (command.equals("ZOOM_DOMAIN_BOTH")) {
      zoomOutDomain(x, y);
    } else if (command.equals("ZOOM_RANGE_BOTH")) {
      zoomOutRange(x, y);
    } else if (command.equals("ZOOM_RESET_BOTH")) {
      restoreAutoBounds();
    } else if (command.equals("ZOOM_RESET_DOMAIN")) {
      restoreAutoDomainBounds();
    } else if (command.equals("ZOOM_RESET_RANGE")) {
      restoreAutoRangeBounds();
    }
    forceRedraw();
  }
  
  public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
    throws PrinterException
  {
    if (pageIndex != 0) {
      return 1;
    }
    return 0;
  }
  
  public void addSWTListener(SWTEventListener listener)
  {
    if ((listener instanceof ControlListener)) {
      canvas.addControlListener((ControlListener)listener);
    } else if ((listener instanceof DisposeListener)) {
      canvas.addDisposeListener((DisposeListener)listener);
    } else if ((listener instanceof FocusListener)) {
      canvas.addFocusListener((FocusListener)listener);
    } else if ((listener instanceof HelpListener)) {
      canvas.addHelpListener((HelpListener)listener);
    } else if ((listener instanceof KeyListener)) {
      canvas.addKeyListener((KeyListener)listener);
    } else if ((listener instanceof MouseListener)) {
      canvas.addMouseListener((MouseListener)listener);
    } else if ((listener instanceof MouseMoveListener)) {
      canvas.addMouseMoveListener((MouseMoveListener)listener);
    } else if ((listener instanceof MouseTrackListener)) {
      canvas.addMouseTrackListener((MouseTrackListener)listener);
    } else if ((listener instanceof PaintListener)) {
      canvas.addPaintListener((PaintListener)listener);
    } else if ((listener instanceof TraverseListener)) {
      canvas.addTraverseListener((TraverseListener)listener);
    }
  }
  
  public void mouseDoubleClick(org.eclipse.swt.events.MouseEvent event) {}
  
  public void mouseDown(org.eclipse.swt.events.MouseEvent event)
  {
    Rectangle scaledDataArea = getScreenDataArea(x, y);
    if (scaledDataArea == null) {
      return;
    }
    zoomPoint = getPointInRectangle(x, y, scaledDataArea);
    int x = (int)((x - getClientAreax) / scaleX);
    int y = (int)((y - getClientAreay) / scaleY);
    
    anchor = new Point2D.Double(x, y);
    chart.setNotify(true);
    canvas.redraw();
    
    ChartEntity entity = null;
    if (info != null)
    {
      EntityCollection entities = info.getEntityCollection();
      if (entities != null) {
        entity = entities.getEntity(x, y);
      }
    }
    Object[] listeners = chartMouseListeners.getListeners(ChartMouseListener.class);
    if (listeners.length == 0) {
      return;
    }
    java.awt.event.MouseEvent mouseEvent = SWTUtils.toAwtMouseEvent(event);
    ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), mouseEvent, entity);
    for (int i = listeners.length - 1; i >= 0; i--) {
      ((ChartMouseListener)listeners[i]).chartMouseClicked(chartEvent);
    }
  }
  
  public void mouseUp(org.eclipse.swt.events.MouseEvent event)
  {
    if (zoomRectangle == null)
    {
      Rectangle screenDataArea = getScreenDataArea(x, y);
      if (screenDataArea != null) {
        zoomPoint = getPointInRectangle(x, y, screenDataArea);
      }
      if ((popup != null) && (button == 3))
      {
        org.eclipse.swt.graphics.Point pt = canvas.toDisplay(x, y);
        
        displayPopupMenu(x, y);
      }
    }
    else
    {
      boolean hZoom = false;
      boolean vZoom = false;
      if (orientation == PlotOrientation.HORIZONTAL)
      {
        hZoom = rangeZoomable;
        vZoom = domainZoomable;
      }
      else
      {
        hZoom = domainZoomable;
        vZoom = rangeZoomable;
      }
      boolean zoomTrigger1 = (hZoom) && (Math.abs(zoomRectangle.width) >= zoomTriggerDistance);
      
      boolean zoomTrigger2 = (vZoom) && (Math.abs(zoomRectangle.height) >= zoomTriggerDistance);
      if ((zoomTrigger1) || (zoomTrigger2))
      {
        if (((hZoom) && (zoomRectangle.x + zoomRectangle.width < zoomPoint.x)) || ((vZoom) && (zoomRectangle.y + zoomRectangle.height < zoomPoint.y))) {
          restoreAutoBounds();
        } else {
          zoom(zoomRectangle);
        }
        canvas.redraw();
      }
    }
    zoomPoint = null;
    zoomRectangle = null;
  }
  
  public void mouseMove(org.eclipse.swt.events.MouseEvent event)
  {
    if ((horizontalAxisTrace) || (verticalAxisTrace))
    {
      horizontalTraceLineY = y;
      verticalTraceLineX = x;
      canvas.redraw();
    }
    if (displayToolTips)
    {
      String s = getToolTipText(event);
      if (((s == null) && (canvas.getToolTipText() != null)) || ((s != null) && (!s.equals(canvas.getToolTipText())))) {
        canvas.setToolTipText(s);
      }
    }
    if (zoomPoint != null)
    {
      Rectangle scaledDataArea = getScreenDataArea(zoomPoint.x, zoomPoint.y);
      
      org.eclipse.swt.graphics.Point movingPoint = getPointInRectangle(x, y, scaledDataArea);
      boolean vZoom;
      boolean hZoom;
      boolean vZoom;
      if (orientation == PlotOrientation.HORIZONTAL)
      {
        boolean hZoom = rangeZoomable;
        vZoom = domainZoomable;
      }
      else
      {
        hZoom = domainZoomable;
        vZoom = rangeZoomable;
      }
      if ((hZoom) && (vZoom))
      {
        zoomRectangle = new Rectangle(zoomPoint.x, zoomPoint.y, x - zoomPoint.x, y - zoomPoint.y);
      }
      else if (hZoom)
      {
        zoomRectangle = new Rectangle(zoomPoint.x, y, x - zoomPoint.x, height);
      }
      else if (vZoom)
      {
        int ymax = Math.max(y, y);
        zoomRectangle = new Rectangle(x, zoomPoint.y, width, ymax - zoomPoint.y);
      }
      canvas.redraw();
    }
    ChartEntity entity = null;
    int x = (int)((x - getClientAreax) / scaleX);
    int y = (int)((y - getClientAreay) / scaleY);
    if (info != null)
    {
      EntityCollection entities = info.getEntityCollection();
      if (entities != null) {
        entity = entities.getEntity(x, y);
      }
    }
    Object[] listeners = chartMouseListeners.getListeners(ChartMouseListener.class);
    if (listeners.length == 0) {
      return;
    }
    java.awt.event.MouseEvent mouseEvent = SWTUtils.toAwtMouseEvent(event);
    ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), mouseEvent, entity);
    for (int i = listeners.length - 1; i >= 0; i--) {
      ((ChartMouseListener)listeners[i]).chartMouseMoved(chartEvent);
    }
  }
  
  public void paintControl(PaintEvent e)
  {
    Rectangle available = getBounds();
    if (chart == null)
    {
      canvas.drawBackground(gc, x, y, width, height);
      
      return;
    }
    SWTGraphics2D sg2 = new SWTGraphics2D(gc);
    
    boolean scale = false;
    int drawWidth = width;
    int drawHeight = height;
    if ((drawWidth == 0.0D) || (drawHeight == 0.0D)) {
      return;
    }
    scaleX = 1.0D;
    scaleY = 1.0D;
    if (drawWidth < minimumDrawWidth)
    {
      scaleX = (drawWidth / minimumDrawWidth);
      drawWidth = minimumDrawWidth;
      scale = true;
    }
    else if (drawWidth > maximumDrawWidth)
    {
      scaleX = (drawWidth / maximumDrawWidth);
      drawWidth = maximumDrawWidth;
      scale = true;
    }
    if (drawHeight < minimumDrawHeight)
    {
      scaleY = (drawHeight / minimumDrawHeight);
      drawHeight = minimumDrawHeight;
      scale = true;
    }
    else if (drawHeight > maximumDrawHeight)
    {
      scaleY = (drawHeight / maximumDrawHeight);
      drawHeight = maximumDrawHeight;
      scale = true;
    }
    if (useBuffer)
    {
      chartBuffer = ((Image)canvas.getData("double-buffer-image"));
      if ((chartBuffer == null) || (chartBufferWidth != width) || (chartBufferHeight != height))
      {
        chartBufferWidth = width;
        chartBufferHeight = height;
        if (chartBuffer != null) {
          chartBuffer.dispose();
        }
        chartBuffer = new Image(getDisplay(), chartBufferWidth, chartBufferHeight);
        
        refreshBuffer = true;
      }
      if (refreshBuffer)
      {
        GC gci = new GC(chartBuffer);
        if (chart.getAntiAlias()) {
          gci.setAntialias(1);
        }
        if (chart.getTextAntiAlias() == RenderingHints.KEY_TEXT_ANTIALIASING) {
          gci.setTextAntialias(1);
        }
        SWTGraphics2D sg2d = new SWTGraphics2D(gci);
        if (scale)
        {
          sg2d.scale(scaleX, scaleY);
          chart.draw(sg2d, new Rectangle2D.Double(0.0D, 0.0D, drawWidth, drawHeight), getAnchor(), info);
        }
        else
        {
          chart.draw(sg2d, new Rectangle2D.Double(0.0D, 0.0D, drawWidth, drawHeight), getAnchor(), info);
        }
        canvas.setData("double-buffer-image", chartBuffer);
        sg2d.dispose();
        gci.dispose();
        refreshBuffer = false;
      }
      sg2.drawImage(chartBuffer, 0, 0);
    }
    else
    {
      if (chart.getAntiAlias()) {
        gc.setAntialias(1);
      }
      if (chart.getTextAntiAlias() == RenderingHints.KEY_TEXT_ANTIALIASING) {
        gc.setTextAntialias(1);
      }
      chart.draw(sg2, new Rectangle2D.Double(0.0D, 0.0D, getBoundswidth, getBoundsheight), getAnchor(), info);
    }
    Rectangle area = getScreenDataArea();
    if ((verticalAxisTrace) && (x < verticalTraceLineX) && (x + width > verticalTraceLineX)) {
      gc.drawLine(verticalTraceLineX, y, verticalTraceLineX, y + height);
    }
    if ((horizontalAxisTrace) && (y < horizontalTraceLineY) && (y + height > horizontalTraceLineY)) {
      gc.drawLine(x, horizontalTraceLineY, x + width, horizontalTraceLineY);
    }
    verticalTraceLineX = 0;
    horizontalTraceLineY = 0;
    if (zoomRectangle != null) {
      gc.drawRectangle(zoomRectangle);
    }
    sg2.dispose();
  }
}

/* Location:
 * Qualified Name:     org.jfree.experimental.chart.swt.ChartComposite
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.jfree.experimental.chart.swt.demo;

import java.awt.Color;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.experimental.chart.swt.ChartComposite;

public class SWTBarChartDemo1
{
  private static CategoryDataset createDataset()
  {
    String series1 = "First";
    String series2 = "Second";
    String series3 = "Third";
    
    String category1 = "Category 1";
    String category2 = "Category 2";
    String category3 = "Category 3";
    String category4 = "Category 4";
    String category5 = "Category 5";
    
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    
    dataset.addValue(1.0D, series1, category1);
    dataset.addValue(4.0D, series1, category2);
    dataset.addValue(3.0D, series1, category3);
    dataset.addValue(5.0D, series1, category4);
    dataset.addValue(5.0D, series1, category5);
    
    dataset.addValue(5.0D, series2, category1);
    dataset.addValue(7.0D, series2, category2);
    dataset.addValue(6.0D, series2, category3);
    dataset.addValue(8.0D, series2, category4);
    dataset.addValue(4.0D, series2, category5);
    
    dataset.addValue(4.0D, series3, category1);
    dataset.addValue(3.0D, series3, category2);
    dataset.addValue(2.0D, series3, category3);
    dataset.addValue(3.0D, series3, category4);
    dataset.addValue(6.0D, series3, category5);
    
    return dataset;
  }
  
  private static JFreeChart createChart(CategoryDataset dataset)
  {
    JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo", "Category", "Value", dataset, PlotOrientation.VERTICAL, true, true, false);
    
    chart.setBackgroundPaint(Color.white);
    
    CategoryPlot plot = (CategoryPlot)chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);
    
    NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    
    BarRenderer renderer = (BarRenderer)plot.getRenderer();
    renderer.setDrawBarOutline(false);
    
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(0.5235987755982988D));
    
    return chart;
  }
  
  public static void main(String[] args)
  {
    JFreeChart chart = createChart(createDataset());
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setSize(600, 300);
    shell.setLayout(new FillLayout());
    shell.setText("Test for jfreechart running with SWT");
    ChartComposite frame = new ChartComposite(shell, 0, chart, true);
    
    frame.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.jfree.experimental.chart.swt.demo.SWTBarChartDemo1
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.jfree.experimental.chart.swt.demo;

import java.awt.Color;
import javax.swing.JPanel;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisLocation;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.time.Minute;
import org.jfree.data.time.RegularTimePeriod;
i
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