Advertisement
bladebaka

iNed 0.0.12

Aug 20th, 2012
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     /**
  2.  * iNed  - NED Database Data Retrieval Tool
  3.  * Accesses the NED Online Database and parses Data into a CSV file specified by the end user.
  4.  * @author ccreason
  5.  */
  6. package dad.inedgui;
  7.  
  8. import au.com.bytecode.opencsv.*;
  9. import java.io.*;
  10. import java.util.List;
  11. import javax.swing.JFileChooser;
  12.  
  13.       class CSVFilter extends javax.swing.filechooser.FileFilter {
  14.  
  15.         @Override
  16.         public boolean accept(File file) {
  17.             // Allow just directories and files with ".csv" extension...
  18.             return file.isDirectory() || file.getAbsolutePath().endsWith(".csv");
  19.         }
  20.  
  21.         @Override
  22.         public String getDescription() {
  23.             // This description will be displayed in the dialog,
  24.             // hard-coded = ugly, should be done via I18N
  25.             return "CSV Documents (*.csv)";
  26.         }
  27.  
  28.     }
  29.  
  30. public class iNedGui extends javax.swing.JFrame {
  31.    
  32.    
  33.     private java.util.List<String[]> list;
  34.  
  35.     /**
  36.      * Creates new form iNedGui
  37.      */
  38.     public iNedGui() {
  39.         initComponents();
  40.     }
  41.  
  42.     /**
  43.      * This method is called from within the constructor to initialize the form.
  44.      * WARNING: Do NOT modify this code. The content of this method is always
  45.      * regenerated by the Form Editor.
  46.      */
  47.     @SuppressWarnings("unchecked")
  48.     // <editor-fold defaultstate="collapsed" desc="Generated Code">
  49.     private void initComponents() {
  50.  
  51.         fileChooser = new javax.swing.JFileChooser();
  52.         jPanel1 = new javax.swing.JPanel();
  53.         jScrollPane2 = new javax.swing.JScrollPane();
  54.         table = new javax.swing.JTable();
  55.         jMenuBar1 = new javax.swing.JMenuBar();
  56.         jMenu1 = new javax.swing.JMenu();
  57.         open = new javax.swing.JMenuItem();
  58.         save = new javax.swing.JMenuItem();
  59.         exit = new javax.swing.JMenuItem();
  60.         jMenu2 = new javax.swing.JMenu();
  61.         getcolumn = new javax.swing.JMenuItem();
  62.         jMenu3 = new javax.swing.JMenu();
  63.         prefs = new javax.swing.JMenuItem();
  64.         about = new javax.swing.JMenuItem();
  65.         readme = new javax.swing.JMenuItem();
  66.  
  67.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  68.  
  69.         table.setModel(new javax.swing.table.DefaultTableModel(
  70.             new Object [][] {
  71.                 {null, null, null, null},
  72.                 {null, null, null, null},
  73.                 {null, null, null, null},
  74.                 {null, null, null, null}
  75.             },
  76.             new String [] {
  77.                 "Title 1", "Title 2", "Title 3", "Title 4"
  78.             }
  79.         ));
  80.         jScrollPane2.setViewportView(table);
  81.  
  82.         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  83.         jPanel1.setLayout(jPanel1Layout);
  84.         jPanel1Layout.setHorizontalGroup(
  85.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  86.             .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 800, Short.MAX_VALUE)
  87.         );
  88.         jPanel1Layout.setVerticalGroup(
  89.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  90.             .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 648, Short.MAX_VALUE)
  91.         );
  92.  
  93.         jMenu1.setText("File");
  94.  
  95.         open.setText("Open File...");
  96.         open.addActionListener(new java.awt.event.ActionListener() {
  97.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  98.                 openActionPerformed(evt);
  99.             }
  100.         });
  101.         jMenu1.add(open);
  102.  
  103.         save.setText("Save File");
  104.         save.addActionListener(new java.awt.event.ActionListener() {
  105.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  106.                 saveActionPerformed(evt);
  107.             }
  108.         });
  109.         jMenu1.add(save);
  110.  
  111.         exit.setText("Exit Program");
  112.         exit.addActionListener(new java.awt.event.ActionListener() {
  113.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  114.                 exitActionPerformed(evt);
  115.             }
  116.         });
  117.         jMenu1.add(exit);
  118.  
  119.         jMenuBar1.add(jMenu1);
  120.  
  121.         jMenu2.setText("Edit");
  122.  
  123.         getcolumn.setText("Get New Column...");
  124.         jMenu2.add(getcolumn);
  125.  
  126.         jMenuBar1.add(jMenu2);
  127.  
  128.         jMenu3.setText("Help");
  129.  
  130.         prefs.setText("Preferences");
  131.         jMenu3.add(prefs);
  132.  
  133.         about.setText("About iNed...");
  134.         jMenu3.add(about);
  135.  
  136.         readme.setText("Readme");
  137.         jMenu3.add(readme);
  138.  
  139.         jMenuBar1.add(jMenu3);
  140.  
  141.         setJMenuBar(jMenuBar1);
  142.  
  143.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  144.         getContentPane().setLayout(layout);
  145.         layout.setHorizontalGroup(
  146.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  147.             .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  148.         );
  149.         layout.setVerticalGroup(
  150.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  151.             .addGroup(layout.createSequentialGroup()
  152.                 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  153.                 .addGap(0, 0, Short.MAX_VALUE))
  154.         );
  155.  
  156.         pack();
  157.     }// </editor-fold>
  158.  
  159.     private void exitActionPerformed(java.awt.event.ActionEvent evt) {                                    
  160.  System.exit(0);
  161.     }                                    
  162.  
  163.     private void openActionPerformed(java.awt.event.ActionEvent evt) {                                    
  164.        
  165.         int returnVal = fileChooser.showOpenDialog(this);
  166.     if (returnVal == JFileChooser.APPROVE_OPTION) {
  167.         File file = fileChooser.getSelectedFile();
  168.         try {
  169.           // What to do with the file, e.g. display it in a TextArea
  170.           CSVReader reader = new CSVReader(new FileReader( file.getAbsolutePath()));
  171.           List myEntries = reader.readAll();
  172.           table (myEntries.toArray());
  173.         } catch (IOException ex) {
  174.           System.out.println("problem accessing file"+file.getAbsolutePath());
  175.         }
  176.     } else {
  177.         System.out.println("File access cancelled by user.");
  178.     }
  179.  
  180.        
  181.     }                                    
  182.  
  183.     private void saveActionPerformed(java.awt.event.ActionEvent evt) {
  184.        try {
  185.             try (BufferedWriter out = new BufferedWriter(new FileWriter("outfilename"))) {
  186.                 out.write("toArray");
  187.             }
  188. } catch (IOException e) {
  189. }
  190.     }
  191.  
  192.     /**
  193.      * @param args the command line arguments
  194.      */
  195.     public static void main(String args[]) {
  196.         /* Set the Nimbus look and feel */
  197.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  198.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  199.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  200.          */
  201.         try {
  202.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  203.                 if ("Nimbus".equals(info.getName())) {
  204.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  205.                     break;
  206.                 }
  207.             }
  208.         } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
  209.             java.util.logging.Logger.getLogger(iNedGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  210.         }
  211.         //</editor-fold>
  212.  
  213.         /* Create and display the form */
  214.         java.awt.EventQueue.invokeLater(new Runnable() {
  215.             @Override
  216.             public void run() {
  217.                 new iNedGui().setVisible(true);
  218.             }
  219.         });
  220.     }
  221.     // Variables declaration - do not modify
  222.     private javax.swing.JMenuItem about;
  223.     private javax.swing.JMenuItem exit;
  224.     private javax.swing.JFileChooser fileChooser;
  225.     private javax.swing.JMenuItem getcolumn;
  226.     private javax.swing.JMenu jMenu1;
  227.     private javax.swing.JMenu jMenu2;
  228.     private javax.swing.JMenu jMenu3;
  229.     private javax.swing.JMenuBar jMenuBar1;
  230.     private javax.swing.JPanel jPanel1;
  231.     private javax.swing.JScrollPane jScrollPane2;
  232.     private javax.swing.JMenuItem open;
  233.     private javax.swing.JMenuItem prefs;
  234.     private javax.swing.JMenuItem readme;
  235.     private javax.swing.JMenuItem save;
  236.     private javax.swing.JTable table;
  237.     // End of variables declaration
  238.  
  239.     private void table(Object[] toArray) {
  240.        
  241.     }
  242. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement