Package jsynoptic.plugins.jfreechart

Source Code of jsynoptic.plugins.jfreechart.MeterShape$BoundsPanel

/* ========================
* 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: MeterShape.java,v 1.7 2008/02/25 13:06:36 ogor Exp $
*
* Changes
* -------
* 25-Sep-2003 : Initial public release (NB);
*
*/

package jsynoptic.plugins.jfreechart;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.util.ResourceBundle;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.undo.CompoundEdit;

import jsynoptic.base.ContextualActionProvider;
import jsynoptic.ui.JSynoptic;
import jsynoptic.ui.LongAction;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.MeterPlot;
import org.jfree.chart.ui.ChartPropertyEditPanel;
import org.jfree.data.Range;

import simtools.data.DataSource;
import simtools.shapes.AbstractShape;
import simtools.ui.ActionCheckBox;
import simtools.ui.NumberField;
import simtools.ui.ResourceFinder;

/**
* @author nbrodu
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class MeterShape extends ChartShape implements ContextualActionProvider {

  static final long serialVersionUID = -8566344700538941237L;

  public static ResourceBundle resources = ResourceFinder.get(MeterShape.class, StandardPlotShape.resources);

  public MeterShape(JFreeChart chart) {
    this(chart,0,0,200,200);
  }

  public MeterShape(JFreeChart chart, int ox, int oy, int width, int height) {
    super(chart, ox, oy, width, height);
  }

  /* (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 null;
    }

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

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

    if (context==EDITOR_CONTEXT) {
    }

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

    if (o instanceof DataSource) {
      v.add(resources.getString("SetSource"));
    }
   
    if (v.size()==0) {
      JSynoptic.setStatus(resources.getString("noSource"));
    }
    return (String[])v.toArray(new String[v.size()]);
  }

  /* (non-Javadoc)
   * @see jsynoptic.base.ContextualActionProvider#doAction(double, double, java.lang.Object, java.lang.String)
   */
  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);
          BoundsPanel plotPanel = null;
          if (tab!=null) tab.add(plotPanel = new BoundsPanel(),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();
          }
          notifyChange();
        }
      }.start();
      return true;
    }
   
    if (action.equals(resources.getString("SetSource"))) {
      try {
        MeterPlot plot = (MeterPlot)chart.getPlot();
        SourceMeterDataset dst = (SourceMeterDataset)plot.getDataset();
        dst.setSource((DataSource)o);
        chart.setTitle(dst.getName());
        notifyChange();
      } catch (ClassCastException cce) {
        JSynoptic.setStatus(resources.getString("ErrorWhileSettingDataSource"));
      }
    }

    return true;
  }

  /* (non-Javadoc)
   * @see jsynoptic.base.ContextualActionProvider#canDoAction(double, double, java.lang.Object, java.lang.String, int)
   */
  public boolean canDoAction(double x, double y, Object o, String action, int context) {
    return true;
  }
 

  public class BoundsPanel extends JPanel {

    ActionCheckBox cbautorange, cbnrange, cbwrange, cbcrange;
    NumberField tfrangemin, tfrangemax, tfnrangemin, tfnrangemax, tfwrangemin, tfwrangemax, tfcrangemin, tfcrangemax;
    JLabel lrangemin, lrangemax, lnrangemin, lnrangemax, lwrangemin, lwrangemax, lcrangemin, lcrangemax;
    JTextField tfTitle;
   
    public BoundsPanel() {
      setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
      Box p1 = new Box(BoxLayout.Y_AXIS);
     
      setName(resources.getString("Properties"));

      JPanel panel;
      Box section;

     
      // Create the title section
      section=Box.createHorizontalBox();
      section.add(new JLabel(resources.getString("PlotTitle:")));
      section.add(tfTitle = new JTextField());
      tfTitle.setText(chart.getTitle().getText());
      p1.add(section);
     
     
      DatasetDelegatedMeterPlot plot = (DatasetDelegatedMeterPlot)chart.getPlot();
      SourceMeterDataset dst = (SourceMeterDataset)plot.getDataset();

      section = new Box(BoxLayout.Y_AXIS);
      section.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),resources.getString("OverallRange")));

      panel = new JPanel();
      panel.setLayout(new FlowLayout(FlowLayout.LEFT));
      panel.add(cbautorange = new ActionCheckBox(resources.getString("Auto-update"), plot.isAutorange()) {
        public void actionPerformed(ActionEvent e) {
          lrangemin.setEnabled(!isSelected());
          lrangemax.setEnabled(!isSelected());
          tfrangemin.setEnabled(!isSelected());
          tfrangemax.setEnabled(!isSelected());
        }
      });
      panel.add(lrangemin = new JLabel(resources.getString("minLabel")));
      panel.add(tfrangemin = new NumberField(10));
      tfrangemin.setValue(plot.getRange().getLowerBound());
      panel.add(lrangemax = new JLabel(resources.getString("maxLabel")));
      panel.add(tfrangemax = new NumberField(10));
      tfrangemax.setValue(plot.getRange().getUpperBound());
      section.add(panel);
      cbautorange.apply();
      p1.add(section);

      section = new Box(BoxLayout.Y_AXIS);
      section.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),resources.getString("'Normal'Range")));
      panel = new JPanel();
      panel.setLayout(new FlowLayout(FlowLayout.LEFT));
      panel.add(cbnrange = new ActionCheckBox(resources.getString("Enable"), plot.getNormalRange()!=null) {
        public void actionPerformed(ActionEvent e) {
          lnrangemin.setEnabled(isSelected());
          lnrangemax.setEnabled(isSelected());
          tfnrangemin.setEnabled(isSelected());
          tfnrangemax.setEnabled(isSelected());
        }
      });
      panel.add(lnrangemin = new JLabel(resources.getString("minLabel")));
      panel.add(tfnrangemin = new NumberField(10));
      if (plot.getNormalRange()!=null) tfnrangemin.setValue(plot.getNormalRange().getLowerBound());
      panel.add(lnrangemax = new JLabel(resources.getString("maxLabel")));
      panel.add(tfnrangemax = new NumberField(10));
      if (plot.getNormalRange()!=null) tfnrangemax.setValue(plot.getNormalRange().getUpperBound());
      section.add(panel);
      cbnrange.apply();
      p1.add(section);

      section = new Box(BoxLayout.Y_AXIS);
      section.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),resources.getString("'Warning'Range")));
      panel = new JPanel();
      panel.setLayout(new FlowLayout(FlowLayout.LEFT));
      panel.add(cbwrange = new ActionCheckBox(resources.getString("Enable"), plot.getWarningRange()!=null) {
        public void actionPerformed(ActionEvent e) {
          lwrangemin.setEnabled(isSelected());
          lwrangemax.setEnabled(isSelected());
          tfwrangemin.setEnabled(isSelected());
          tfwrangemax.setEnabled(isSelected());
        }
      });
      panel.add(lwrangemin = new JLabel(resources.getString("minLabel")));
      panel.add(tfwrangemin = new NumberField(10));
      if (plot.getWarningRange()!=null) tfwrangemin.setValue(plot.getWarningRange().getLowerBound());
      panel.add(lwrangemax = new JLabel(resources.getString("maxLabel")));
      panel.add(tfwrangemax = new NumberField(10));
      if (plot.getWarningRange()!=null) tfwrangemax.setValue(plot.getWarningRange().getUpperBound());
      section.add(panel);
      cbwrange.apply();
      p1.add(section);

      section = new Box(BoxLayout.Y_AXIS);
      section.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),resources.getString("'Critical'Range")));
      panel = new JPanel();
      panel.setLayout(new FlowLayout(FlowLayout.LEFT));
      panel.add(cbcrange = new ActionCheckBox(resources.getString("Enable"), plot.getCriticalRange()!=null) {
        public void actionPerformed(ActionEvent e) {
          lcrangemin.setEnabled(isSelected());
          lcrangemax.setEnabled(isSelected());
          tfcrangemin.setEnabled(isSelected());
          tfcrangemax.setEnabled(isSelected());
        }
      });
      panel.add(lcrangemin = new JLabel(resources.getString("minLabel")));
      panel.add(tfcrangemin = new NumberField(10));
      if (plot.getCriticalRange()!=null) tfcrangemin.setValue(plot.getCriticalRange().getLowerBound());
      panel.add(lcrangemax = new JLabel(resources.getString("maxLabel")));
      panel.add(tfcrangemax = new NumberField(10));
      if (plot.getCriticalRange()!=null) tfcrangemax.setValue(plot.getCriticalRange().getUpperBound());
      section.add(panel);
      cbcrange.apply();
      p1.add(section);

      add(p1);

    }

    protected void updateChartProperties() {
      chart.setTitle(tfTitle.getText());
      DatasetDelegatedMeterPlot plot = (DatasetDelegatedMeterPlot)chart.getPlot();
      SourceMeterDataset dst = (SourceMeterDataset)plot.getDataset();
      plot.setAutorange(cbautorange.isSelected());
      if (tfrangemin.isEnabled() && tfrangemax.isEnabled()) plot.setRange(new Range(tfrangemin.getDoubleValue(), tfrangemax.getDoubleValue()));
      if (tfnrangemin.isEnabled() && tfnrangemax.isEnabled()) plot.setNormalRange(new Range(tfnrangemin.getDoubleValue(), tfnrangemax.getDoubleValue()));
      else plot.setNormalRange(null);
      if (tfwrangemin.isEnabled() && tfwrangemax.isEnabled()) plot.setWarningRange(new Range(tfwrangemin.getDoubleValue(), tfwrangemax.getDoubleValue()));
      else plot.setWarningRange(null);
      if (tfcrangemin.isEnabled() && tfcrangemax.isEnabled()) plot.setCriticalRange(new Range(tfcrangemin.getDoubleValue(), tfcrangemax.getDoubleValue()));
      else plot.setCriticalRange(null);
    }

  }
 

  /* (non-Javadoc)
   * @see simtools.shapes.AbstractShape#cloneShape()
   */
  protected AbstractShape cloneShape() {
      ChartShape cs = (ChartShape)super.cloneShape();
      DatasetDelegatedMeterPlot plot = (DatasetDelegatedMeterPlot)chart.getPlot();
      SourceMeterDataset dst = (SourceMeterDataset)plot.getDataset();
      ((DatasetDelegatedMeterPlot)cs.chart.getPlot()).setDataset(dst.cloneSet());
      return cs;
  }
}

TOP

Related Classes of jsynoptic.plugins.jfreechart.MeterShape$BoundsPanel

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.