Package jsynoptic.plugins.jfreechart

Source Code of jsynoptic.plugins.jfreechart.JFreeChartPlugin

/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info:  http://jsynoptic.sourceforge.net/index.html
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2003, by :
*     Corporate:
*         Astrium SAS
*         EADS CRC
*     Individual:
*         Nicolas Brodu
*
* $Id: JFreeChartPlugin.java,v 1.16 2009/01/19 17:26:35 ogor Exp $
*
* Changes
* -------
* 25-Sep-2003 : Initial public release (NB);
*
*/

package jsynoptic.plugins.jfreechart;

import java.awt.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import javax.swing.Icon;

import jsynoptic.base.Plugin;
import jsynoptic.ui.Run;
import jsynoptic.ui.ShapeCreator;
import jsynoptic.ui.ShapesContainer;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.DialShape;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;

import simtools.diagram.DiagramComponent;
import simtools.shapes.AbstractShape;
import simtools.ui.MenuResourceBundle;
import simtools.ui.ResourceFinder;

/**
* This plugin brings in shapes from the JFreeChart project.
*
*/
public class JFreeChartPlugin extends Plugin {

  public static MenuResourceBundle resources = ResourceFinder.getMenu(JFreeChartPlugin.class);

   
    protected List shapeCreators;
   
    public final static String PLOT_CYCLIC = resources.getString("Plot,Cyclic");
    public final static String PLOT_STANDARD = resources.getString("Plot,Standard");
    public final static String PLOT_SCATTER = resources.getString("Plot,Scatter");
    public final static String PLOT_PARAMETRIC = resources.getString("Plot,Parametric");
   
    public final static String METER = resources.getString("Meter");
    public final static String AREA_CHART = resources.getString("AreaChart");
    public final static String BAR_CHART = resources.getString("BarChart");
    public final static String BAR_CHAR_3D = resources.getString("BarChart,3D");
    public final static String BAR_CHART_STACKED = resources.getString("BarChart,Stacked");
    public final static String BAR_CHART_STACKED_3D = resources.getString("BarChart,Stacked,3D");
    public final static String PIE_CHART = resources.getString("PieChart");
    public final static String PIE_CHART_3D = resources.getString("PieChart,3D");

    public final static String JFREE_CHART =  resources.getString("JFreeChart");
    public final static Icon JFREE_CHART_ICON =  resources.getIcon("JFreeChartIcon");

    public JFreeChartPlugin(){
        shapeCreators = new ArrayList();
       
        shapeCreators.add(new ShapeCreator(this, PLOT_CYCLIC, null, JFREE_CHART, JFREE_CHART_ICON));
        shapeCreators.add(new ShapeCreator(this, PLOT_STANDARD, null, JFREE_CHART, JFREE_CHART_ICON));
        shapeCreators.add(new ShapeCreator(this, PLOT_SCATTER, null, JFREE_CHART, JFREE_CHART_ICON));
        shapeCreators.add(new ShapeCreator(this, PLOT_PARAMETRIC, null, JFREE_CHART, JFREE_CHART_ICON));
       
        shapeCreators.add(new ShapeCreator(this, METER, null, JFREE_CHART, JFREE_CHART_ICON));
        shapeCreators.add(new ShapeCreator(this, AREA_CHART, null, JFREE_CHART, JFREE_CHART_ICON));
       
        shapeCreators.add(new ShapeCreator(this, BAR_CHART, null, JFREE_CHART, JFREE_CHART_ICON));
        shapeCreators.add(new ShapeCreator(this, BAR_CHAR_3D, null, JFREE_CHART, JFREE_CHART_ICON));
        shapeCreators.add(new ShapeCreator(this, BAR_CHART_STACKED, null, JFREE_CHART, JFREE_CHART_ICON));
        shapeCreators.add(new ShapeCreator(this, BAR_CHART_STACKED_3D, null, JFREE_CHART, JFREE_CHART_ICON));
       
        shapeCreators.add(new ShapeCreator(this, PIE_CHART, null, JFREE_CHART, JFREE_CHART_ICON));
        shapeCreators.add(new ShapeCreator(this, PIE_CHART_3D, null, JFREE_CHART, JFREE_CHART_ICON));

    }

    /* (non-Javadoc)
     * @see jsynoptic.base.Plugin#getShapeCreators()
     */
    public List getShapeCreators(){
        return shapeCreators;
    }

  /* (non-Javadoc)
   * @see jsynoptic.base.Plugin#createShape(java.lang.String)
   */
  public AbstractShape createShape(String name) {
      AbstractShape res = null;
     
    if (name.equals(PLOT_STANDARD)) {
      SourceXYDataset dst = new SourceXYDataset();
      JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "", dst, true, true, false);
      chart.setAntiAlias(AbstractShape.ANTI_ALIASING);
      res = new StandardPlotShape(chart);;
   
    } else if (name.equals(AREA_CHART)) {
      SourceXYDataset dst = new SourceXYDataset();
      JFreeChart chart = ChartFactory.createXYAreaChart("", "", "", dst, PlotOrientation.VERTICAL, true, true, false);
      chart.setAntiAlias(AbstractShape.ANTI_ALIASING);
      res = new AreaPlotShape(chart);;
   
    } else if (name.equals(PLOT_CYCLIC)) {
      SourceXYDataset dst = new SourceXYDataset();
      JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "", dst, true, true, false);
      chart.setAntiAlias(AbstractShape.ANTI_ALIASING);
      res = new CyclicPlotShape(chart);;
   
    } else if (name.equals(PLOT_SCATTER)) {
      SourceXYDataset dst = new SourceXYDataset();
      JFreeChart chart = ChartFactory.createScatterPlot("", "", "", dst, PlotOrientation.VERTICAL, true, true, false);
      chart.setAntiAlias(AbstractShape.ANTI_ALIASING);
      XYPlot plot = chart.getXYPlot();
      NumberAxis axis = new NumberAxis();
      plot.setDomainAxis(axis);
      axis.setAutoRange(true);
      axis.setAutoRangeIncludesZero(false);
      ValueAxis vaxis = plot.getRangeAxis();
      axis.setAutoRange(true);
      if (vaxis instanceof NumberAxis) {((NumberAxis)vaxis).setAutoRangeIncludesZero(false);}
      res = new ScatterPlotShape(chart);;
   
    } else if (name.equals(PLOT_PARAMETRIC)) {
      SourceXYDataset dst = new SourceXYDataset();
      JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "", dst, true, true, false);
      chart.setAntiAlias(AbstractShape.ANTI_ALIASING);
      XYPlot plot = chart.getXYPlot();
      NumberAxis axis = new NumberAxis();
      plot.setDomainAxis(axis);
      axis.setAutoRange(true);
      axis.setAutoRangeIncludesZero(false);
      ValueAxis vaxis = plot.getRangeAxis();
      axis.setAutoRange(true);
      if (vaxis instanceof NumberAxis) {((NumberAxis)vaxis).setAutoRangeIncludesZero(false);}
      res = new ParametricPlotShape(chart);
   
    } else if (name.equals(METER)) {
      SourceMeterDataset dst = new SourceMeterDataset();
      DatasetDelegatedMeterPlot plot = new DatasetDelegatedMeterPlot(dst);
      plot.setDialShape(DialShape.CIRCLE);
      JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
      chart.setAntiAlias(AbstractShape.ANTI_ALIASING);
      res = new MeterShape(chart);
   
    } else if (name.equals(BAR_CHART)) {
      SourceCategoryDataset dst = new SourceCategoryDataset();
      JFreeChart chart = ChartFactory.createBarChart("","","",dst,PlotOrientation.VERTICAL,true,true,false);
      chart.setAntiAlias(AbstractShape.ANTI_ALIASING);
      res = new BarChartShape(chart);
   
    } else if (name.equals(BAR_CHAR_3D)) {
      SourceCategoryDataset dst = new SourceCategoryDataset();
      JFreeChart chart = ChartFactory.createBarChart3D("","","",dst,PlotOrientation.VERTICAL,true,true,false);
      chart.setAntiAlias(AbstractShape.ANTI_ALIASING);
      res = new BarChartShape(chart);
   
    } else if (name.equals(BAR_CHART_STACKED)) {
      SourceCategoryDataset dst = new SourceCategoryDataset();
      JFreeChart chart = ChartFactory.createStackedBarChart("","","",dst,PlotOrientation.VERTICAL,true,true,false);
      chart.setAntiAlias(AbstractShape.ANTI_ALIASING);
      res = new BarChartShape(chart);
   
    } else if (name.equals(BAR_CHART_STACKED_3D)) {
      SourceCategoryDataset dst = new SourceCategoryDataset();
      JFreeChart chart = ChartFactory.createStackedBarChart3D("","","",dst,PlotOrientation.VERTICAL,true,true,false);
      chart.setAntiAlias(AbstractShape.ANTI_ALIASING);
      res = new BarChartShape(chart);
   
    } else if (name.equals(PIE_CHART)) {
      SourcePieDataset dst = new SourcePieDataset();
      JFreeChart chart = ChartFactory.createPieChart("",dst,true,true,false);
      chart.setAntiAlias(AbstractShape.ANTI_ALIASING);
      res = new PieChartShape(chart);
 
    } else if (name.equals(PIE_CHART_3D)) {
      SourcePieDataset dst = new SourcePieDataset();
      JFreeChart chart = ChartFactory.createPieChart3D("",dst,true,true,false);
      chart.setAntiAlias(AbstractShape.ANTI_ALIASING);
      res = new PieChartShape(chart);
    }   
    return res;
  }

  /* (non-Javadoc)
   * @see jsynoptic.base.Plugin#about()
   */
  public String about() {
    return resources.getString("AboutText");
  }
 
}
TOP

Related Classes of jsynoptic.plugins.jfreechart.JFreeChartPlugin

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.