From 3bd8ad31b51e6effc02581e58aecc9f2304d06c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Flores?= Date: Thu, 29 Apr 2004 17:17:12 +0000 Subject: [PATCH] no message git-svn-id: https://svn.coded.pt/svn/SIPRP@65 bb69d46d-e84e-40c8-a05a-06db0d633741 --- trunk/siprp/importer/DataChooserWindow.java | 127 ++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 trunk/siprp/importer/DataChooserWindow.java diff --git a/trunk/siprp/importer/DataChooserWindow.java b/trunk/siprp/importer/DataChooserWindow.java new file mode 100644 index 00000000..8f1d8b59 --- /dev/null +++ b/trunk/siprp/importer/DataChooserWindow.java @@ -0,0 +1,127 @@ +/* + * DataChooserWindow.java + * + * Created on 29 de Abril de 2004, 16:53 + */ + +package siprp.importer; + +import java.awt.*; +import java.awt.event.*; +import java.util.*; +import javax.swing.*; + +import com.evolute.utils.ui.*; +/** + * + * @author lflores + */ +public class DataChooserWindow extends CustomJDialog +{ + private final String labels[]; + private final String items[]; + private final JComboBox combos[]; + + private boolean canceled = false; + + /** Creates a new instance of DataChooserWindow */ + public DataChooserWindow( JFrame modalFrame, String names[], String data[] ) + { + super( modalFrame, true ); + labels = names; + items = data; + combos = new JComboBox[ labels.length ]; + setupComponents(); + if( modalFrame == null ) + { + center(); + } + else + { + centerSuper(); + } + show(); + } + + private void setupComponents() + { + setTitle( "Escolha os campos correspondentes" ); + setSize(300, 100 + 20 * labels.length ); + GridBagLayout gbl = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.insets = new Insets( 2, 2, 2, 2 ); + gbc.fill = GridBagConstraints.HORIZONTAL; + Container cont = getContentPane(); + cont.setLayout( gbl ); + for( int i = 0; i < labels.length; ++i ) + { + gbc.weightx = 0; + gbc.gridwidth = 1; + JLabel label = new JLabel( labels[ i ] ); + gbl.setConstraints( label, gbc ); + cont.add( label ); +/* gbc.weightx = 1; + JPanel pad = new JPanel(); + gbl.setConstraints( pad, gbc ); + cont.add( pad ); +*/ gbc.weightx = 1; + gbc.gridwidth = GridBagConstraints.REMAINDER; + JComboBox combo = new JComboBox( items ); + combos[ i ] = combo; + gbl.setConstraints( combo, gbc ); + cont.add( combo ); + } + gbc.insets = new Insets( 10, 2, 2, 2 ); + gbc.weightx = 1; + gbc.gridwidth = 2; + JPanel pad = new JPanel(); + gbl.setConstraints( pad, gbc ); + cont.add( pad ); + gbc.weightx = 0; + gbc.gridwidth = 1; + JButton butOK = new JButton( "OK" ); + gbl.setConstraints( butOK, gbc ); + cont.add( butOK ); + gbc.weightx = 0; + gbc.gridwidth = GridBagConstraints.REMAINDER; + JButton butCancel = new JButton( "Cancelar" ); + gbl.setConstraints( butCancel, gbc ); + cont.add( butCancel ); + butOK.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) + { + setVisible( false ); + dispose(); + } + }); + butCancel.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent e ) + { + setVisible( false ); + dispose(); + canceled = true; + } + }); + } + + public Hashtable getData() + { + if( canceled ) + { + return null; + } + Hashtable hash = new Hashtable(); + for( int i = 0; i < labels.length; ++i ) + { + hash.put( labels[ i ], combos[ i ].getSelectedItem() ); + } + return hash; + } +/* + public static void main( String arg[] ) + { + String names[] = new String[] { "Nome:", "Morada:", "Telefone:" }; + String data[] = new String[] { "Joao Catita", "Damaiasdg sdfg sdf gsdfs hgf h", "nao tem", "so a noite", "" }; + DataChooserWindow dcw = new DataChooserWindow( null, names, data ); + }*/ +}