Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * iNed - NED Database Data Retrieval Tool
- * Accesses the NED Online Database and parses Data into a CSV file specified by the end user.
- * @author ccreason
- */
- package dad.inedgui;
- import au.com.bytecode.opencsv.*;
- import java.io.*;
- import java.util.List;
- import javax.swing.JFileChooser;
- class CSVFilter extends javax.swing.filechooser.FileFilter {
- @Override
- public boolean accept(File file) {
- // Allow just directories and files with ".csv" extension...
- return file.isDirectory() || file.getAbsolutePath().endsWith(".csv");
- }
- @Override
- public String getDescription() {
- // This description will be displayed in the dialog,
- // hard-coded = ugly, should be done via I18N
- return "CSV Documents (*.csv)";
- }
- }
- public class iNedGui extends javax.swing.JFrame {
- private java.util.List<String[]> list;
- /**
- * Creates new form iNedGui
- */
- public iNedGui() {
- initComponents();
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- fileChooser = new javax.swing.JFileChooser();
- jPanel1 = new javax.swing.JPanel();
- jScrollPane2 = new javax.swing.JScrollPane();
- table = new javax.swing.JTable();
- jMenuBar1 = new javax.swing.JMenuBar();
- jMenu1 = new javax.swing.JMenu();
- open = new javax.swing.JMenuItem();
- save = new javax.swing.JMenuItem();
- exit = new javax.swing.JMenuItem();
- jMenu2 = new javax.swing.JMenu();
- getcolumn = new javax.swing.JMenuItem();
- jMenu3 = new javax.swing.JMenu();
- prefs = new javax.swing.JMenuItem();
- about = new javax.swing.JMenuItem();
- readme = new javax.swing.JMenuItem();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- table.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- {null, null, null, null},
- {null, null, null, null},
- {null, null, null, null},
- {null, null, null, null}
- },
- new String [] {
- "Title 1", "Title 2", "Title 3", "Title 4"
- }
- ));
- jScrollPane2.setViewportView(table);
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 800, Short.MAX_VALUE)
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 648, Short.MAX_VALUE)
- );
- jMenu1.setText("File");
- open.setText("Open File...");
- open.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- openActionPerformed(evt);
- }
- });
- jMenu1.add(open);
- save.setText("Save File");
- save.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- saveActionPerformed(evt);
- }
- });
- jMenu1.add(save);
- exit.setText("Exit Program");
- exit.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- exitActionPerformed(evt);
- }
- });
- jMenu1.add(exit);
- jMenuBar1.add(jMenu1);
- jMenu2.setText("Edit");
- getcolumn.setText("Get New Column...");
- jMenu2.add(getcolumn);
- jMenuBar1.add(jMenu2);
- jMenu3.setText("Help");
- prefs.setText("Preferences");
- jMenu3.add(prefs);
- about.setText("About iNed...");
- jMenu3.add(about);
- readme.setText("Readme");
- jMenu3.add(readme);
- jMenuBar1.add(jMenu3);
- setJMenuBar(jMenuBar1);
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(0, 0, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void exitActionPerformed(java.awt.event.ActionEvent evt) {
- System.exit(0);
- }
- private void openActionPerformed(java.awt.event.ActionEvent evt) {
- int returnVal = fileChooser.showOpenDialog(this);
- if (returnVal == JFileChooser.APPROVE_OPTION) {
- File file = fileChooser.getSelectedFile();
- try {
- // What to do with the file, e.g. display it in a TextArea
- CSVReader reader = new CSVReader(new FileReader( file.getAbsolutePath()));
- List myEntries = reader.readAll();
- table (myEntries.toArray());
- } catch (IOException ex) {
- System.out.println("problem accessing file"+file.getAbsolutePath());
- }
- } else {
- System.out.println("File access cancelled by user.");
- }
- }
- private void saveActionPerformed(java.awt.event.ActionEvent evt) {
- try {
- try (BufferedWriter out = new BufferedWriter(new FileWriter("outfilename"))) {
- out.write("toArray");
- }
- } catch (IOException e) {
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(iNedGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- @Override
- public void run() {
- new iNedGui().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JMenuItem about;
- private javax.swing.JMenuItem exit;
- private javax.swing.JFileChooser fileChooser;
- private javax.swing.JMenuItem getcolumn;
- private javax.swing.JMenu jMenu1;
- private javax.swing.JMenu jMenu2;
- private javax.swing.JMenu jMenu3;
- private javax.swing.JMenuBar jMenuBar1;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JScrollPane jScrollPane2;
- private javax.swing.JMenuItem open;
- private javax.swing.JMenuItem prefs;
- private javax.swing.JMenuItem readme;
- private javax.swing.JMenuItem save;
- private javax.swing.JTable table;
- // End of variables declaration
- private void table(Object[] toArray) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement