--- FM2SQL/Attic/FM2SQL.java 2003/12/05 11:46:39 1.1 +++ FM2SQL/Attic/FM2SQL.java 2004/01/09 12:43:00 1.8 @@ -2,11 +2,8 @@ import javax.swing.*; import javax.swing.event.*; import javax.swing.table.TableModel; -import Convert.DataBase; - import java.awt.event.*; import java.awt.Dimension; -import java.awt.FlowLayout; import java.awt.*; import java.sql.*; import java.util.*; @@ -20,7 +17,7 @@ import java.io.*; *
* The Database access is made over DBBean class * all other classes are just for the visualization of the data - * @version 0.2( first stable release) + * @version 0.3( first stable release) * @author rogo * */ @@ -67,7 +64,8 @@ public class FM2SQL extends JFrame imple Vector tables = new Vector(); Vector layouts = new Vector(); JPanel listPanel; - JPanel topPanel, contentPanel; + JPanel topPanel,topPanel2, contentPanel; + JScrollPane paneDest; FM2SQL fm = this; boolean noDBUpdate = false; boolean noUserUpdate = false; @@ -102,6 +100,11 @@ public class FM2SQL extends JFrame imple */ public FM2SQL() throws Exception { + + initializeGUI(); + } + public void initializeGUI() throws Exception + { Image local = getToolkit().getImage(getClass().getResource("icons/fm.jpg")); if (local != null); setIconImage(local); @@ -110,7 +113,7 @@ public class FM2SQL extends JFrame imple box2 = new JComboBox(); box3 = new JComboBox(new String[] { "jdbc:fmpro:http://141.14.237.74:8050", "jdbc:fmpro:http://localhost", "jdbc:postgresql://foxridge/test" }); box3.setEditable(true); - box4 = new JComboBox(new String[] {"jdbc:postgresql://foxridge/test","jdbc:postgresql://erebos/test1" }); + box4 = new JComboBox(new String[] { "jdbc:postgresql://foxridge/test", "jdbc:postgresql://erebos/test1" }); box4.setEditable(true); box4.addActionListener(this); table = new TableComponent(); @@ -121,78 +124,94 @@ public class FM2SQL extends JFrame imple contentPanel = new JPanel(); contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS)); - topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 5)); - topPanel.add(Box.createRigidArea(new Dimension(10, 0))); - topPanel.add(new JLabel("FileMaker DB ")); - topPanel.add(new JLabel("PostgresSQL ")); - //tListDest.setMinimumSize(new Dimension(120, 250)); - //tListDest.setMaximumSize(new Dimension(230, 250)); - //tListDest.setPreferredSize(new Dimension(230, 250)); - - box3.setMinimumSize(new Dimension(200, 20)); - box3.setMaximumSize(new Dimension(320, 20)); - box3.setPreferredSize(new Dimension(320, 20)); - box4.setMinimumSize(new Dimension(200, 20)); - box4.setMaximumSize(new Dimension(320, 20)); - box4.setPreferredSize(new Dimension(330, 20)); + box3.setMinimumSize(new Dimension(450, 20)); + box3.setMaximumSize(new Dimension(550, 20)); + box3.setPreferredSize(new Dimension(450, 20)); + box4.setMinimumSize(new Dimension(450, 20)); + box4.setMaximumSize(new Dimension(550, 20)); + box4.setPreferredSize(new Dimension(450, 20)); + paneDest = new JScrollPane(tListDest); + // tListDest.setPreferredSize(paneDest.getPreferredSize()); + // paneDest.setPreferredSize(new Dimension(350, 365)); + Dimension dim = paneDest.getPreferredSize(); + paneDest.setMinimumSize(dim); + //paneDest.setMaximumSize(new Dimension(dim.width + 50, dim.height + 50)); + tC = new TableComponent(); tC.sizeToFit(450, 250); tC.tableModel.addTableModelListener(this); - JPanel dataBasePanel = new JPanel(); - dataBasePanel.setLayout(new FlowLayout(FlowLayout.LEFT, 2, 2)); - dataBasePanel.add(Box.createRigidArea(new Dimension(10, 0))); - dataBasePanel.add(new JLabel("Choose src database: ")); - dataBasePanel.add(box3); - dataBasePanel.add(Box.createRigidArea(new Dimension(10, 0))); - dataBasePanel.add(new JLabel("Choose dest database : ")); - dataBasePanel.add(Box.createRigidArea(new Dimension(5, 0))); + JPanel destPanel = new JPanel(); + destPanel.setLayout(new java.awt.GridBagLayout()); - dataBasePanel.add(box4); - dataBasePanel.add(Box.createRigidArea(new Dimension(10, 0))); listPanel = new JPanel(); listPanel.setLayout(new java.awt.GridBagLayout()); java.awt.GridBagConstraints gbc = new java.awt.GridBagConstraints(); JScrollPane pane = new JScrollPane(tList); - tC.tableScroller.setPreferredSize(new Dimension(450, 265)); - tC.table.revalidate(); - tC.setMinimumSize(tC.tableScroller.getPreferredSize()); - tC.setMaximumSize(tC.tableScroller.getPreferredSize()); + tC.tableScroller.setPreferredSize(new Dimension(450, 365)); + //tC.table.revalidate(); + tC.tableScroller.setMinimumSize(new Dimension(450, 250)); + // tC.tableScroller.setMaximumSize(tC.tableScroller.getPreferredSize()); + topPanel = new JPanel(); + topPanel.setLayout(new GridBagLayout()); + topPanel2 = new JPanel(); + topPanel2.setLayout(new GridBagLayout()); - //gbc.gridx=GridBagConstraints.RELATIVE; gbc.gridx = 0; - gbc.weightx = 1.0; - gbc.weighty = 0.0; - gbc.gridwidth = 2; + gbc.gridy = 0; + gbc.weightx = 0.1; + gbc.weighty = 0.1; + gbc.gridwidth = 1; gbc.gridheight = 1; - gbc.anchor = GridBagConstraints.NORTHWEST; - listPanel.add(new JLabel(" select Tables to Convert ", JLabel.LEFT), gbc); - gbc.gridx = 2; - listPanel.add(new JLabel(" Tables in database ", JLabel.CENTER), gbc); + gbc.insets = new Insets(2, 2, 5, 5); + gbc.ipadx = 1; + gbc.ipady = 1; gbc.anchor = GridBagConstraints.WEST; + listPanel.add(topPanel, gbc); + destPanel.add(topPanel2, gbc); + + topPanel.add(new JLabel("Choose src database: ", JLabel.CENTER), gbc); + topPanel2.add(new JLabel("Choose dest database : ", JLabel.CENTER), gbc); + + gbc.anchor = GridBagConstraints.NORTHWEST; gbc.gridy = 1; + topPanel.add(box3, gbc); + + topPanel2.add(box4, gbc); + + //gbc.gridx=GridBagConstraints.RELATIVE; + //dataBasePanel.add(new JLabel(" select Tables to Convert ", JLabel.LEFT)); + gbc.gridy = 1; + gbc.anchor = GridBagConstraints.SOUTHWEST; + + listPanel.add(new JLabel(" select Tables to Convert ", JLabel.LEFT), gbc); + destPanel.add(new JLabel(" Tables in database ", JLabel.LEFT), gbc); + + // gbc.anchor = GridBagConstraints.WEST; + gbc.gridy = 2; gbc.gridx = 0; - gbc.gridwidth = 1; - gbc.weightx = 0.0; - listPanel.add(tC, gbc); - JScrollPane paneDest = new JScrollPane(tListDest); + // gbc.weightx = 0.0; + //dataBasePanel.add(tC); + gbc.anchor = GridBagConstraints.NORTHWEST; + gbc.gridheight = 1; + gbc.fill = GridBagConstraints.BOTH; + listPanel.add(tC.tableScroller, gbc); + // gbc.fill = GridBagConstraints.VERTICAL; + destPanel.add(paneDest, gbc); showTables1 = new JButton("show Tables"); showTables1.setActionCommand("show Tables source"); - gbc.anchor = GridBagConstraints.NORTH; - gbc.weightx = 0.0; - gbc.gridx = 1; - listPanel.add(showTables1, gbc); - paneDest.setPreferredSize(new Dimension(250, 265)); - paneDest.setMinimumSize(paneDest.getPreferredSize()); - paneDest.setMaximumSize(paneDest.getPreferredSize()); - gbc.anchor = GridBagConstraints.WEST; - gbc.gridy = 1; - gbc.gridx = 2; - gbc.weightx = 0.2; - listPanel.add(paneDest, gbc); + // gbc.anchor = GridBagConstraints.NORTH; + // gbc.weightx = 0.0; + gbc.fill = GridBagConstraints.NONE; + gbc.gridheight = 1; + + gbc.gridx = 0; + gbc.gridy = 2; + // topPanel.add(showTables1, gbc); JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS)); + buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); + buttonPanel.setMinimumSize(new Dimension(380, 30)); convert = new JButton("Convert Tables"); showTables = new JButton("show Tables"); dropTables = new JButton("drop Tables"); @@ -212,18 +231,37 @@ public class FM2SQL extends JFrame imple convert.addActionListener(fm); dropTables.addActionListener(fm); buttonPanel.add(dropTables); - gbc.gridx = 3; - gbc.anchor = GridBagConstraints.NORTHWEST; - gbc.gridy = 1; - gbc.weightx = 1.0; - listPanel.add(buttonPanel, gbc); - contentPanel.add(dataBasePanel); - contentPanel.add(listPanel); - listPanel.setMaximumSize(new Dimension(getPreferredSize().width, 550)); - listPanel.setMinimumSize(new Dimension(getPreferredSize().width, 150)); - listPanel.setPreferredSize(new Dimension(getPreferredSize().width, 350)); - getContentPane().add(contentPanel, "Center"); + JPanel buttonPanelSrc = new JPanel(); + buttonPanelSrc.setLayout(new BoxLayout(buttonPanelSrc, BoxLayout.X_AXIS)); + buttonPanelSrc.setMinimumSize(new Dimension(200, 30)); + buttonPanelSrc.add(showTables1); + + topPanel.add(buttonPanelSrc, gbc); + topPanel2.add(buttonPanel, gbc); + + // gbc.anchor = GridBagConstraints.WEST; + // gbc.gridy = 1; + // gbc.gridx = 2; + // gbc.weightx = 0.2; + + // gbc.gridx = 3; + // gbc.anchor = GridBagConstraints.NORTHWEST; + // gbc.gridy = 1; + // gbc.weightx = 1.0; + //listPanel.add(buttonPanel, gbc); + JSplitPane splitter = new JSplitPane(); + splitter.setTopComponent(listPanel); + splitter.setBottomComponent(destPanel); + + // contentPanel.add(dataBasePanel); + // contentPanel.add(listPanel); + listPanel.setMaximumSize(new Dimension(660, 750)); + listPanel.setMinimumSize(new Dimension(660, 250)); + listPanel.setPreferredSize(new Dimension(480, 500)); + paneDest.setPreferredSize(new Dimension(250, 285)); + + getContentPane().add(splitter, "Center"); this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) @@ -257,13 +295,25 @@ public class FM2SQL extends JFrame imple setSize(getWidth(), table.table.getPreferredSize().height + 2 * size); // System.out.println("size" + size); } - listPanel.setMaximumSize(new Dimension(getPreferredSize().width - 5, 550)); - listPanel.setMinimumSize(new Dimension(getPreferredSize().width - 5, 200)); - listPanel.setPreferredSize(new Dimension(getPreferredSize().width - 5, 370)); - + // listPanel.setMaximumSize(new Dimension(getPreferredSize().width - 5, 550)); + // listPanel.setMinimumSize(new Dimension(getPreferredSize().width - 5, 200)); + // listPanel.setPreferredSize(new Dimension(getPreferredSize().width - 5, 370)); + tC.tableScroller.revalidate(); + Dimension dim = getSize(); + tC.tableScroller.setMinimumSize(new Dimension(dim.width-400, dim.height - topPanel.getPreferredSize().height - 100)); + tC.tableScroller.setMaximumSize(getSize()); + tC.tableScroller.setPreferredSize(tC.tableScroller.getMinimumSize()); + + paneDest.setMinimumSize(new Dimension(400, dim.height - topPanel2.getPreferredSize().height - 100)); + paneDest.setMaximumSize(tC.tableScroller.getMaximumSize()); + paneDest.setPreferredSize(new Dimension(400, dim.height - topPanel2.getPreferredSize().height - 100)); + + paneDest.validate(); + // tC.tableScroller.setPreferredSize(getSize()); + tC.sizeToFit(getWidth(), getHeight()); ((JPanel) getContentPane()).revalidate(); repaint(); - setTitle("Filemaker To Postgres Conversion Tool "); + setTitle("Filemaker 2 SQL Conversion Tool "); } }); @@ -468,7 +518,7 @@ public class FM2SQL extends JFrame imple thread.start(); } - setTitle("Filemaker To Postgres Conversion Tool "); + setTitle("Filemaker 2 SQL Conversion Tool "); // pack(); } catch (Exception e4) @@ -496,7 +546,7 @@ public class FM2SQL extends JFrame imple } } //writing config - if (command.equals("export XML Config")) + if (command.equals("save XML Config")) { if (configExportFileChooser == null) { @@ -530,7 +580,7 @@ public class FM2SQL extends JFrame imple configExportFileChooser.showDialog(fmInstance, " Save "); } - if (command.equals("import XML Config")) + if (command.equals("open XML Config")) { if (configImportFileChooser == null) { @@ -628,6 +678,13 @@ public class FM2SQL extends JFrame imple }; thread.start(); } + if(command.equals("Quit")) + { + fmInstance.dispose(); + System.exit(0); + + } + } /** * Copys the content of source to destination and makes new table if necessary @@ -699,7 +756,7 @@ public class FM2SQL extends JFrame imple fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); fmInstance.setEnabled(false); Vector databases = Convert.getXMLConfig(file); - DataBase destBase = (DataBase) databases.lastElement(); + Convert.DataBase destBase = (Convert.DataBase) databases.lastElement(); //destBase.bean.getConnection(); noUserUpdate = true; destBean=destBase.bean; @@ -707,7 +764,6 @@ public class FM2SQL extends JFrame imple ((DefaultComboBoxModel) box4.getModel()).removeElement(destObj); ((DefaultComboBoxModel) box4.getModel()).insertElementAt(destObj,0); box4.setSelectedItem(destObj); - //@TODO comboBox action Events should do nothing on config file read+combox in table should be updated databases.remove(destBase); for (Iterator iter = databases.iterator(); iter.hasNext();) { @@ -721,6 +777,7 @@ public class FM2SQL extends JFrame imple fillTable(); Vector tables=database.bean.getTableNames(); Collections.sort(tables,String.CASE_INSENSITIVE_ORDER); + int[] indices = new int[database.tables.size()]; for (int i =0;i