diff --git a/trunk/siprp/importer/DataChooserWindow.java b/trunk/siprp/importer/DataChooserWindow.java index 0581e170..af5f6708 100644 --- a/trunk/siprp/importer/DataChooserWindow.java +++ b/trunk/siprp/importer/DataChooserWindow.java @@ -46,7 +46,7 @@ public class DataChooserWindow extends CustomJDialog private void setupComponents() { setTitle( "Escolha os campos correspondentes:" ); - setSize(300, 100 + 20 * labels.length ); + setSize(300, 100 + 25 * labels.length ); GridBagLayout gbl = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets( 2, 2, 2, 2 ); diff --git a/trunk/siprp/importer/Importer.java b/trunk/siprp/importer/Importer.java index 1ea977e7..482c2d76 100644 --- a/trunk/siprp/importer/Importer.java +++ b/trunk/siprp/importer/Importer.java @@ -8,10 +8,12 @@ package siprp.importer; import com.evolute.utils.arrays.*; import com.evolute.utils.tables.*; +import com.evolute.utils.ui.*; import java.awt.*; import java.awt.event.*; import java.io.*; +import java.util.*; import javax.swing.*; import javax.swing.table.*; @@ -21,75 +23,189 @@ import jxl.*; * * @author psantos */ -public class Importer extends JFrame +public class Importer extends CustomJDialog { private JPanel panel; + private BaseTable table; + private Excel2DArray e2da; + private boolean canceled = false; + private DataChooserWindow dcw; + private String vals[]; /** Creates a new instance of Importer */ - public Importer( String filename ) + public Importer( JFrame modalFrame, String filename ) throws Exception { -System.out.println( "File: " + filename ); + super( modalFrame, true ); + setupComponents( filename ); - addWindowListener( new WindowAdapter(){ - public void windowClosing( WindowEvent e ) - { - System.exit( 0 ); - } - } ); + if( modalFrame == null ) + { + center(); + } + else + { + centerSuper(); + } + + show(); } private void setupComponents( String filename ) { - setSize( 100, 100 ); + setSize( 600, 500 ); + + GridBagLayout gblGridBag = new GridBagLayout(); + GridBagConstraints gbcConstraints = new GridBagConstraints(); panel = ( JPanel ) getContentPane(); - Excel2DArray e2da = new Excel2DArray( filename ); + panel.setLayout( gblGridBag ); + + e2da = new Excel2DArray( filename ); - Virtual2DTableModel tm = new Virtual2DTableModel( new String[ e2da.rowLength() ], null ); + String colNames[] = new String[ e2da.rowLength() ]; + for( int i = 0; i < colNames.length; i++ ) + { + colNames[ i ] = " "; + } + Virtual2DTableModel tm = new Virtual2DTableModel( colNames, null ); tm.setValues( e2da ); - BaseTable table = new BaseTable( tm ); + table = new BaseTable( tm ); + table.getTableHeader().setResizingAllowed( true ); + table.getTableHeader().setReorderingAllowed( false ); + // table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF ); + for( int i = 0; i < e2da.rowLength(); i++ ) { table.getColumn( i ).setMinWidth( 50 ); - table.getColumn( i ).setResizable( true ); + //table.getColumn( i ).setResizable( true ); } -// TableColumn col = table.getColumnModel().getColumn( 0 ); -// col.setHeaderRenderer( new ComboBoxHeaderRenderer() ); - JScrollPane sp = new JScrollPane( table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + + gbcConstraints.anchor = GridBagConstraints.CENTER; + gbcConstraints.fill = GridBagConstraints.BOTH; + gbcConstraints.insets = new Insets(5, 5, 5, 5); + gbcConstraints.gridwidth = 3; + gbcConstraints.gridheight = 3; + gbcConstraints.weighty = 3; + gbcConstraints.gridx = 0; + gbcConstraints.gridy = 3; + gblGridBag.setConstraints( sp, gbcConstraints ); panel.add( sp ); + + JPanel jpButtons = new JPanel(); + final JButton jbOK = new JButton( "Escolher" ); + jbOK.setEnabled( false ); + jpButtons.add( jbOK ); + JButton jbCancel = new JButton( "Cancelar" ); + jpButtons.add( jbCancel ); + + + gbcConstraints.gridheight = 1; + gbcConstraints.weightx = 1; + gbcConstraints.weighty = 0; + gbcConstraints.anchor = GridBagConstraints.SOUTH; + gbcConstraints.fill = GridBagConstraints.BOTH; + gbcConstraints.insets = new Insets( 2, 2, 2, 2 ); + gbcConstraints.gridwidth = 3; + gbcConstraints.gridx = 0; + gbcConstraints.gridy = 6; + gblGridBag.setConstraints( jpButtons, gbcConstraints ); + panel.add( jpButtons ); + + table.addMouseListener( new MouseAdapter() { + public void mouseClicked( MouseEvent e ) { + jbOK.setEnabled( true ); + if( e.getButton() == MouseEvent.BUTTON1 + && e.getClickCount() == 2 + && table.columnAtPoint( e.getPoint() ) != -1 + && table.rowAtPoint( e.getPoint() ) != -1 ) + { + acceptResult(); + } + } + public void mousePressed( MouseEvent e ) { + jbOK.setEnabled( true ); + } + }); + + jbOK.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent a ) { + acceptResult(); + } + }); + + jbCancel.addActionListener( new ActionListener() { + public void actionPerformed( ActionEvent a ) { + setVisible( false ); + dispose(); + canceled = true; + } + }); + } - + + private void acceptResult() + { + vals = e2da.getRow( table.getSelectedRow() ); +/* + System.out.println( "row: " + table.getSelectedRow() ); + System.out.print( "vals: " ); + for( int i = 0; i < vals.length; i++ ) + { + System.out.print( "[" + vals[ i ] + "]" ); + } + System.out.println(); +*/ + setVisible( false ); + dispose(); + + } + + public Hashtable getData() + { + String names[] = new String[]{ "Nome do Funcion\u00e1rio", + "Data Nascimento", + "Sexo", + "Nacionalidade", + "Data Admiss\u00e3o", + "Categoria", + "Fun\u00e7\u00e3o", + "Local Trabalho" + }; + dcw = new DataChooserWindow( null, names, vals ); + + if( canceled || ( dcw == null ) ) + { + return null; + } + + return dcw.getData(); + } + public static void main( String args[] ) { Importer im = null; try { - im = new Importer( + im = new Importer( null, // "E:\\test.xls" - "C:\\Documents and Settings\\psantos\\My Documents\\Devel\\teste_2.xls" + "C:\\Documents and Settings\\psantos\\My Documents\\Devel\\teste.xls" // "C:\\Documents and Settings\\psantos\\My Documents\\Devel\\Docs\\jexcelapi\\jxlrwtest.xls" ); + +System.out.println( "Escolhido: " + im.getData() ); + } catch( Exception e ) { e.printStackTrace(); } - if( im == null ) - { - System.out.println( "O im e' null" ); - } - else - { - im.show(); - } - // String[][] all = (String[][]) e.getObjects(); // // for( int j = 0; j < e.rowLength(); j++ )