Package jsynoptic.data

Source Code of jsynoptic.data.DataSourceAnimator$PropertiesPanel

/* ========================
* 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-2004, by :
*     Corporate:
*         Astrium SAS
*         EADS CRC
*     Individual:
*         Nicolas Brodu
*
* $Id: DataSourceAnimator.java,v 1.6 2008/02/25 12:51:19 ogor Exp $
*
* Changes
* -------
* 22-Jan-2004 : Creation date (NB);
*
*/
package jsynoptic.data;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.undo.CompoundEdit;

import jsynoptic.base.ContextualActionProvider;
import jsynoptic.ui.JSynoptic;
import simtools.data.DataException;
import simtools.data.DataSource;
import simtools.ui.MenuResourceBundle;
import simtools.ui.NumberField;
import simtools.ui.ResourceFinder;

/**
* Overloads the collection animator and provides actions for the popup menu in the source tree
*/
public class DataSourceAnimator
    extends
      simtools.data.DataSourceAnimator implements ContextualActionProvider {

    // Reuse messages from the collection
  public static MenuResourceBundle resources = ResourceFinder.getMenu(DataSourceCollectionAnimator.class);

    /**
     * @param ds
     */
    public DataSourceAnimator(DataSource ds) {
        super(ds);
    }

    /**
     * @param ds
     * @param delay
     */
    public DataSourceAnimator(DataSource ds, int delay) {
        super(ds, delay);
    }

    /**
     * @param ds
     * @param delay
     * @param period
     */
    public DataSourceAnimator(DataSource ds, int delay, long period) {
        super(ds, delay, period);
    }
   
  /* (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 (isRunning()) {
      return new String[] {
        resources.getString("sourceProperties"),
        resources.getString("stop"),
        resources.getString("reset"),
      };
    } else {
      if (!isFinished()) {
        return new String[] {
          resources.getString("sourceProperties"),
          resources.getString("start"),
          resources.getString("step"),
          resources.getString("reset"),
        };
      }
      else return new String[] {
        resources.getString("sourceProperties"),
        resources.getString("reset"),
      };
    }
  }

  /* (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("start"))) {
      start();
      return true;
    }

    if (action.equals(resources.getString("stop"))) {
      stop();
      return true;
    }

    if (action.equals(resources.getString("step"))) {
      try {
        step();
        return true;
      } catch (DataException e1) {
        JOptionPane.showMessageDialog(JSynoptic.gui.getOwner(),e1.getMessage(),resources.getString("stepError"),JOptionPane.ERROR_MESSAGE);
        return false;
      }
    }

    if (action.equals(resources.getString("reset"))) {
      reset();
      return true;
    }

    if (action.equals(resources.getString("sourceProperties"))) {
      PropertiesPanel panel = new PropertiesPanel();
      int result = JOptionPane.showConfirmDialog(JSynoptic.gui.getOwner(), panel,
        resources.getString("SourcePropertiesTitle"), JOptionPane.OK_CANCEL_OPTION,
        JOptionPane.PLAIN_MESSAGE);
      if (result == JOptionPane.OK_OPTION) {
        panel.updateProperties();
      }
      return true;
    }

    return false;
  }

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

 
   /* (non-Javadoc)
   * @see simtools.data.DataSource#getDataSourceInformationClass()
   */
  public String getDataSourceInformationClass(){
    return "simtools.ui.DynamicDataSourceInformation";
  }
 
  protected class PropertiesPanel extends JPanel {
 
    protected NumberField nfPeriod;
    protected JCheckBox cbAutoStop;

    public PropertiesPanel() {
      setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
      Box box = Box.createHorizontalBox();
      box.add(new JLabel(resources.getString("Period")));
      box.add(Box.createHorizontalGlue());
      box.add(nfPeriod = new NumberField(getPeriod(), 5));
      add(box);
      box = Box.createHorizontalBox();
      box.add(cbAutoStop = new JCheckBox(resources.getString("AutoStopWhenStepFails"),isAutoStop()));
      box.add(Box.createHorizontalGlue());
      add(box);
    }
   
    public void updateProperties() {
      setPeriod(nfPeriod.getLongValue());
      setAutoStop(cbAutoStop.isSelected());
    }
  }
 
}
TOP

Related Classes of jsynoptic.data.DataSourceAnimator$PropertiesPanel

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.