Package jsynoptic.plugins.merge.ui

Source Code of jsynoptic.plugins.merge.ui.MCWizardPageAddSynchronousDataOption

/* ========================
* 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-2005, by :
*     Corporate:
*         EADS Astrium SAS
*         EADS CRC
*     Individual:
*         Claude Cazenave
*
* $Id: MCWizardPageAddSynchronousDataOption.java,v 1.4 2008/07/22 09:25:17 ogor Exp $
*
* Changes
* -------
* 25 february 2008 : Initial public release (CC);
*
*/
package jsynoptic.plugins.merge.ui;

import java.awt.Font;
import java.awt.event.ActionEvent;

import java.util.HashMap;
import java.util.Map;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.ButtonGroup;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;

import simtools.data.DataSource;
import simtools.data.async.TimeStampedDataSource;
import simtools.ui.FilteredSourceTree;


/**
* Type
* <br><b>Summary:</b><br>
* A wizard page dedicated to set options related to the last added data source or collection
*/
public class MCWizardPageAddSynchronousDataOption  extends MCWizardPageAddAsynchronousDataOption implements TreeSelectionListener{

  protected FilteredSourceTree dstree;

  protected JLabel timeRefFormat;

  protected JRadioButton timeRefIsRelative, timeRefIsAbsolute;  // Kind of time reference

  public MCWizardPageAddSynchronousDataOption(MCWizardManager wizardManager){
    super(wizardManager);
  }
 
  protected void setContents(){

    JLabel selectAdataForTime= new JLabel(resources.getString("selectAdataForTime"));
    selectAdataForTime.setFont(new Font("Dialog", Font.PLAIN,12));
    add( selectAdataForTime, gbc);
    gbc.gridy++;

    // Source panel
    dstree = FilteredSourceTree.getFromPool("MCPageAddSynchronousDataOptionChooser");
    dstree.getSourceTree().addTreeSelectionListener(this);
    add(dstree,gbc);
    gbc.gridy++;

    // Kind of ref time
    timeRefFormat= new JLabel(resources.getString("refTime"));
    timeRefFormat.setFont(new Font("Dialog", Font.PLAIN,12));
    add(timeRefFormat, gbc);
    gbc.gridy++;

    timeRefIsRelative = new JRadioButton(resources.getString("relative"));
    timeRefIsAbsolute = new JRadioButton(resources.getString("absolute"));
    timeRefIsRelative.setSelected(true);//by default.

    timeRefIsRelative.addActionListener(this);
    timeRefIsAbsolute.addActionListener(this);

    timeRefFormat.setEnabled(false);
    timeRefIsRelative.setEnabled(false);
    timeRefIsAbsolute.setEnabled(false);

    ButtonGroup bg2 = new ButtonGroup();
    bg2.add(timeRefIsRelative);
    bg2.add(timeRefIsAbsolute);

    add(timeRefIsRelative, gbc);
    gbc.gridy++;

    add(timeRefIsAbsolute, gbc);
    gbc.gridy++;

    add(Box.createVerticalStrut(25), gbc);
    gbc.gridy++;

    //
    super.setContents();

  }

  public String getProblem(){
    Object o = dstree.getSelectedSourceOrCollection();
    if ((o==null) || !(o instanceof DataSource)){
      return  resources.getString("selectAdataSourceError");
    }
    return super.getProblem();
  }


  public void actionPerformed(ActionEvent e){

    // Enable to disable the choice of time reference format
    boolean enableInitialDateSettings=
      ((timeRefIsRelative.isSelected() &&  (collectionIAsynchronous || !collectionTimeRefIsRelative))
      ||
      (timeRefIsAbsolute.isSelected() &&  collectionTimeRefIsRelative));
   
    initialDate.setEnabled(enableInitialDateSettings);
    initialDateLabel.setEnabled(enableInitialDateSettings);

    super.actionPerformed(e);
  }

  public void valueChanged(TreeSelectionEvent e){
    notifyListenerPageHasChanged();

    // If data is time stamped --> timeRef is absolute
    timeRefIsAbsolute.setSelected((dstree.getSelectedSourceOrCollection() instanceof TimeStampedDataSource));
 
    // If data is not time stamped ask user to choose a format
    boolean enableTimeReferenceFormat = ((dstree.getSelectedSourceOrCollection() instanceof DataSource) && !(dstree.getSelectedSourceOrCollection() instanceof TimeStampedDataSource));
    timeRefFormat.setEnabled(enableTimeReferenceFormat);
    timeRefIsRelative.setEnabled(enableTimeReferenceFormat);
    timeRefIsAbsolute.setEnabled(enableTimeReferenceFormat);
   

    // Enable to disable the choice of time reference format
    boolean enableInitialDateSettings=
      ( (timeRefIsRelative.isSelected() &&  !collectionTimeRefIsRelative) || (timeRefIsAbsolute.isSelected() &&  collectionTimeRefIsRelative) );

    initialDate.setEnabled(enableInitialDateSettings);
    initialDateLabel.setEnabled(enableInitialDateSettings);
  }

  public Map getInformation(){
    HashMap ret = (HashMap)super.getInformation();
    ret.put(MCWizardManager.TIME_REFERENCE + "_" + (wizardManager.numberOfAddedData-1), dstree.getSelectedSourceOrCollection());

    boolean time_reference_is_relative = timeRefIsRelative.isEnabled() && timeRefIsRelative.isSelected();
    ret.put(MCWizardManager.TIME_REFERENCE_IS_RELATIVE + "_" + (wizardManager.numberOfAddedData-1), new Boolean(time_reference_is_relative));

    return ret;
  }

}
TOP

Related Classes of jsynoptic.plugins.merge.ui.MCWizardPageAddSynchronousDataOption

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.