Package jsynoptic.plugins.merge.ui

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

/* ========================
* 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: MCWizardPageTerminate.java,v 1.3 2008/04/08 11:53:41 ogor Exp $
*
* Changes
* -------
* 25 february 2008 : Initial public release (CC);
*
*/
package jsynoptic.plugins.merge.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.HashMap;
import java.util.Map;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;

import simtools.ui.MenuResourceBundle;
import simtools.ui.ResourceFinder;
import simtools.ui.WizardPage;

/**
* Type
* <br><b>Summary:</b><br>
* At this step, user can terminate or add another data source or collection
*/
public class MCWizardPageTerminate extends WizardPage implements MouseListener{

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

  protected JTable table;
  protected JLabel referenceForMergedTime;
  protected JLabel selectInTheTable;
  protected int referenceForMergedTimeindex;
  protected boolean chooseADataSourceForMergeTime;
 
  public MCWizardPageTerminate(){
    super(resources.getString("pageTerminateTitle"), resources.getString("addAnotherData"));
   
    referenceForMergedTimeindex = 0;
    chooseADataSourceForMergeTime = false;
   
    JPanel congratulations = new JPanel(new BorderLayout());
    congratulations.add(new JLabel(resources.getIcon("flagIcon")), BorderLayout.WEST);
   
    JPanel congratulationsText = new JPanel();
    congratulationsText.setLayout(new BoxLayout(congratulationsText, BoxLayout.Y_AXIS));
   
    JLabel cong= new JLabel(resources.getString("congratulations"));
    cong.setFont(new Font("Dialog", Font.PLAIN,24));
    congratulationsText.add(cong);
   
    JLabel terminated= new JLabel(resources.getString("terminated"));
    terminated.setFont(new Font("Dialog", Font.PLAIN,12));
    congratulationsText.add(terminated);
   
   
    congratulations.add(congratulationsText, BorderLayout.CENTER);
    add( congratulations,gbc);
    gbc.gridy++;
   

    // Display added data
    JLabel addedData= new JLabel(resources.getString("addedData"));
    addedData.setFont(new Font("Dialog", Font.PLAIN,12));
    add(addedData,gbc);
    gbc.gridy++;

    table  = new JTable(new AddedDataTableModel(null));
    table.setPreferredScrollableViewportSize(new Dimension(100, 100));
    table.addMouseListener(this);
    add(new JScrollPane(table),gbc);
    gbc.gridy++;

    add(Box.createVerticalStrut(20), gbc);
        gbc.gridy++;
       
        selectInTheTable= new JLabel("");
        selectInTheTable.setFont(new Font("Dialog", Font.PLAIN,12));
        add(selectInTheTable,gbc);  
        gbc.gridy++;
       
        referenceForMergedTime= new JLabel("");
        referenceForMergedTime.setFont(new Font("Dialog", Font.PLAIN,12));
        add(referenceForMergedTime,gbc);
        gbc.gridy++;
       
       
  }

  public String getProblem(){
    return null;
  }

  public Map getInformation(){
      HashMap ret = new HashMap();
      ret.put(MCWizardManager.REFERENCE_FOR_MERGED_TIME, new Integer(referenceForMergedTimeindex));
      return ret;
  }

  public void setAddedDataTable(Object[][] addedData){
    table.setModel(new AddedDataTableModel(addedData));
  }
 
  /**
   * Set the
   * @param index - The index of the element whose time is used as merge time
   */
  public void setMergedTimeReference(boolean chooseADataSourceForMergeTime, int index){
      this.referenceForMergedTimeindex = index;
      AddedDataTableModel tableModel = (AddedDataTableModel)table.getModel();

      this.chooseADataSourceForMergeTime = chooseADataSourceForMergeTime;
     
      if (chooseADataSourceForMergeTime){
          selectInTheTable.setText( resources.getString("selectInTheTable"));
          referenceForMergedTime.setText( "<html>"+  resources.getString("mergeTimeRefIs")
                  + "<b>"
                  + (String)tableModel.getValueAt(referenceForMergedTimeindex, 1)
                  + "</b></html>"
                  );
         
      } else {
          referenceForMergedTime.setText("");
          selectInTheTable.setText("");
      }  
  }
 
 
  public class AddedDataTableModel extends AbstractTableModel {
    Object addedData[][];

    public AddedDataTableModel(Object[][] addedData) {
      this.addedData = addedData;
    }

    public int getColumnCount() {
      if (addedData!=null)
        return addedData[0].length;
      return 0;
    }
    public Object getValueAt(int parm1, int parm2) {
      if (addedData!=null)
        return addedData[parm1][parm2];
     
      return null;
    }
    public int getRowCount() {
      if (addedData!=null)
        return addedData.length;
      return 0;
    }

    public String getColumnName(int col){
      switch (col){
      case 0: return resources.getString("addedDataTitle");
      case 1: return resources.getString("timeRefTitle");
      case 2: return resources.getString("offsetTitle");
      case 3: return resources.getString("dateTitle");
      }
      return null;
    }
   
    public boolean isCellEditable(int row, int col) {
      return false;
    }
  }


    public void mouseClicked(MouseEvent e) {
        if ( (e.getSource() == table) && chooseADataSourceForMergeTime){
            setMergedTimeReference(chooseADataSourceForMergeTime, table.getSelectedRow());
        }
    }

    public void mouseEntered(MouseEvent e) {
        // TODO Auto-generated method stub
       
    }

    public void mouseExited(MouseEvent e) {
        // TODO Auto-generated method stub
       
    }

    public void mousePressed(MouseEvent e) {
        // TODO Auto-generated method stub
       
    }

    public void mouseReleased(MouseEvent e) {
        // TODO Auto-generated method stub
       
    }

}
TOP

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

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.