Package jsynoptic.plugins.jfreechart

Source Code of jsynoptic.plugins.jfreechart.AreaPlotShape

/* ========================
* 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 2001-2003, by :
*     Corporate:
*         Astrium SAS
*         EADS CRC
*     Individual:
*         Nicolas Brodu
*
* $Id: AreaPlotShape.java,v 1.6 2008/02/25 13:06:36 ogor Exp $
*
* Changes
* -------
* 18-11-2003 : Creation date (NB);
*
*/

package jsynoptic.plugins.jfreechart;

import java.awt.Container;
import java.util.ResourceBundle;
import java.util.Vector;

import javax.swing.Box;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTabbedPane;
import javax.swing.undo.CompoundEdit;

import jsynoptic.ui.LongAction;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.ui.ChartPropertyEditPanel;

import simtools.data.DataSource;
import simtools.data.DataSourceCollection;
import simtools.ui.NumberField;
import simtools.ui.ResourceFinder;

/**
* A shape specially designed for Area XY plots axis.
* Contains all the parameter configuration options for such axis.
*
*/
public class AreaPlotShape extends StandardPlotShape {

  static final long serialVersionUID = -1528842645686315446L;

  public static ResourceBundle resources = ResourceFinder.get(AreaPlotShape.class, StandardPlotShape.resources);
 
  public AreaPlotShape(JFreeChart chart) {
    this(chart,0,0,400,300);
  }

  public AreaPlotShape(JFreeChart chart, int ox, int oy, int width, int height) {
    super(chart, ox, oy, width, height);
    XYPlot plot = (XYPlot)chart.getXYPlot();
    plot.setRenderer(new JSynopticAreaXYItemRenderer());
    plot.setForegroundAlpha(0.7f);
  }

  /* (non-Javadoc)
   * @see jsynoptic.base.ContextualActionProvider#getActions(double, double, java.lang.Object, int)
   */
  public String[] getActions(double x, double y, Object o, int context) {
    if (context==MOUSE_OVER_CONTEXT) {
      return super.getActions(x,y,o,context);
    }

    if (context==MOUSE_OUT_CONTEXT) {
      return super.getActions(x,y,o,context);
    }

    if (context==MOUSE_PRESSED_CONTEXT) {
      return null;
    }

    if (context==EDITOR_CONTEXT) {
    }

    Vector v = new Vector();
    v.add(resources.getString("Properties..."));

    XYPlot plot = (XYPlot)chart.getXYPlot();
    SourceXYDataset dst = (SourceXYDataset)plot.getDataset();

    if (o instanceof DataSource) {
      v.add(resources.getString("setX"));
      if (dst.getSources().size() != 0) {
        v.add(resources.getString("addY"));
        // No secondary Y here
      }
    }
   
    else if (o instanceof DataSourceCollection) {
      v.add(resources.getString("setXY1Yn"));
      if (dst.getSources().size() != 0) {
        v.add(resources.getString("addY1Yn"));
      }
    }

    return (String[])v.toArray(new String[v.size()]);
  }

  public boolean doAction(double x, double y, Object o, String action, CompoundEdit undoableEdit) {
    if (action.equals(resources.getString("Properties..."))) {
      new LongAction(LongAction.LONG_ACTION_SHAPE, null, this) {
        protected void doAction() {
          ChartPropertyEditPanel panel = new ChartPropertyEditPanel(chart);
          JTabbedPane tab = findTab(panel);
          XYPlot plot = (XYPlot)chart.getXYPlot();
          PlotPanel plotPanel = new PlotPanel();
          Container c = (Container)plotPanel.getComponent(0);
          Box b = Box.createHorizontalBox();
          b.add(new JLabel(resources.getString("TransparencyCoefficient")));
          NumberField nfalpha;
          b.add(Box.createHorizontalGlue());
          b.add(nfalpha = new NumberField(plot.getForegroundAlpha()));
          c.add(b);
          b = Box.createHorizontalBox();
          JCheckBox cbDrawContour;
          b.add(cbDrawContour = new JCheckBox(resources.getString("OutlineEachSegment"), ((JSynopticAreaXYItemRenderer)plot.getRenderer()).isOutline()));
          b.add(Box.createHorizontalGlue());
          c.add(b);
          if (tab!=null) tab.add(plotPanel,0);
          int result = JOptionPane.showConfirmDialog(null, panel,
            resources.getString("ChartProperties"), JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.PLAIN_MESSAGE);
          if (result == JOptionPane.OK_OPTION) {
            panel.updateChartProperties(chart);
            if (plotPanel!=null) {
              plotPanel.updateChartProperties();
              plot.setForegroundAlpha((float)nfalpha.getDoubleValue());
              ((JSynopticAreaXYItemRenderer)plot.getRenderer()).setOutline(cbDrawContour.isSelected());
            }
          }
          notifyChange();
        }
      }.start();
      return true;
    }
    return super.doAction(x,y,o,action, undoableEdit);
  }
 
}

TOP

Related Classes of jsynoptic.plugins.jfreechart.AreaPlotShape

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.