Package simtools.ui

Source Code of simtools.ui.DataSourceInformationDialog

/* ========================
* 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: DataSourceInformationDialog.java,v 1.3 2007/01/23 17:21:28 ogor Exp $
*
* Changes
* -------
* 14 avr. 2006  : Initial public release (CC);
*
*/
package simtools.ui;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.UIManager;
import javax.swing.border.Border;
import simtools.data.DataException;
import simtools.data.DataSource;


public class DataSourceInformationDialog implements ActionListener{
 
  protected DataSourceInformation dsi;
  protected JDialog dialog=null;
  protected JButton bok;

  protected static MenuResourceBundle resources=ResourceFinder.getMenu(DataSourceInformation.class);
 
  public DataSourceInformationDialog(DataSource ds) throws DataException{
    // Instanciate a DataSourceInformation class from class name
    String dataSourceInformationClass = ds.getDataSourceInformationClass();
    Class c;
    try {
      c = Class.forName(dataSourceInformationClass);
      Object i;
      i = c.newInstance();
      if ((i!=null) && (i instanceof DataSourceInformation)){
        dsi = (DataSourceInformation)i;
        dsi.setPanel(ds);
      }else
        throw new DataException(resources.getString("noInfo"));
    }catch (Exception cnfe) {
      throw new DataException(resources.getString("noInfo"));
    }
  }
 
  protected JPanel createButtonPanel(){
    JPanel p=new JPanel();
    bok = resources.getButton("OKButton", this);
    p.add(bok);
    return p;
  }
 
  public JDialog createDialog(Frame parent) {
   
    if ( (dsi==null) ||(dialog!=null)){
      return null
    }
    dialog = new JDialog( parent, resources.getString("dataSourceInformation"), false);
    Container contentPane = dialog.getContentPane();

    JPanel p  = new JPanel();
    Border paneEdge = BorderFactory.createEmptyBorder(0,10,10,10);
    p.setBorder(paneEdge);
    p.setLayout(new BoxLayout(p,BoxLayout.Y_AXIS));

    p.add(dsi);   
   
    contentPane.add(p,BorderLayout.CENTER);
    contentPane.add(createButtonPanel(), BorderLayout.SOUTH);

    if (JDialog.isDefaultLookAndFeelDecorated()) {
      boolean supportsWindowDecorations =
        UIManager.getLookAndFeel().getSupportsWindowDecorations();
      if (supportsWindowDecorations) {
        dialog.setUndecorated(true);
        dialog.getRootPane().setWindowDecorationStyle(JRootPane.QUESTION_DIALOG);
      }
    }
    dialog.pack();
   
    dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        dispose();
      }
    });
   
    dialog.setLocationRelativeTo(parent);
    dialog.setModal(true);
    return dialog;
  }

 
  /* (non-Javadoc)
   * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
   */
  public void actionPerformed(ActionEvent e) {
    if(e.getSource()==bok){
      dispose()
    }
  }
 
  protected void dispose(){
    dsi.dispose();
    dialog.dispose()
  }
}
TOP

Related Classes of simtools.ui.DataSourceInformationDialog

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.