View difference between Paste ID: nm633L1v and tWnYrwgM
SHOW: | | - or go back to the newest paste.
1-
/*
1+
2-
 * To change this template, choose Tools | Templates
2+
 * iNed  - NED Database Data Retrieval Tool
3-
 * and open the template in the editor.
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-
import java.awt.Component;
7+
8
import au.com.bytecode.opencsv.*;
9
import java.io.*;
10-
  
10+
import java.util.List;
11
import javax.swing.JFileChooser;
12-
 class MyCustomFilter extends javax.swing.filechooser.FileFilter {
12+
13
      class CSVFilter extends javax.swing.filechooser.FileFilter {
14
 
15-
            // Allow only directories, or files with ".txt" extension
15+
16-
            return file.isDirectory() || file.getAbsolutePath().endsWith(".txt");
16+
17
            // Allow just directories and files with ".csv" extension...
18
            return file.isDirectory() || file.getAbsolutePath().endsWith(".csv");
19
        }
20
 
21
        @Override
22-
            return "Text documents (*.txt)";
22+
23
            // This description will be displayed in the dialog,
24-
    } 
24+
25
            return "CSV Documents (*.csv)";
26-
/**
26+
27-
 *
27+
 
28
    }
29
30
public class iNedGui extends javax.swing.JFrame {
31-
    class CSVFilter extends javax.swing.filechooser.FileFilter {
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-
        jScrollBar1 = new javax.swing.JScrollBar();
68+
69-
        jScrollBar2 = new javax.swing.JScrollBar();
69+
        table.setModel(new javax.swing.table.DefaultTableModel(
70-
        jScrollPane1 = new javax.swing.JScrollPane();
70+
            new Object [][] {
71-
        textarea = new javax.swing.JTextArea();
71+
                {null, null, null, null},
72
                {null, null, null, null},
73
                {null, null, null, null},
74-
        Open = new javax.swing.JMenuItem();
74+
                {null, null, null, null}
75-
        Save = new javax.swing.JMenuItem();
75+
            },
76-
        jMenuItem3 = new javax.swing.JMenuItem();
76+
            new String [] {
77-
        dataMenu = new javax.swing.JMenu();
77+
                "Title 1", "Title 2", "Title 3", "Title 4"
78-
        fetchNew = new javax.swing.JMenuItem();
78+
79-
        helpMenu = new javax.swing.JMenu();
79+
        ));
80-
        Preferences = new javax.swing.JMenuItem();
80+
        jScrollPane2.setViewportView(table);
81-
        Readme = new javax.swing.JMenuItem();
81+
82-
        About = new javax.swing.JMenuItem();
82+
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
83
        jPanel1.setLayout(jPanel1Layout);
84-
        fileChooser.setDialogTitle("Choose a CSV File");
84+
        jPanel1Layout.setHorizontalGroup(
85-
        fileChooser.setFileFilter(new MyCustomFilter());
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-
        jScrollBar2.setOrientation(javax.swing.JScrollBar.HORIZONTAL);
89+
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
90
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 648, Short.MAX_VALUE)
91-
        textarea.setColumns(20);
91+
92-
        textarea.setRows(5);
92+
93-
        jScrollPane1.setViewportView(textarea);
93+
94
95
        open.setText("Open File...");
96-
        jMenu1.addActionListener(new java.awt.event.ActionListener() {
96+
        open.addActionListener(new java.awt.event.ActionListener() {
97
            public void actionPerformed(java.awt.event.ActionEvent evt) {
98-
                jMenu1ActionPerformed(evt);
98+
                openActionPerformed(evt);
99
            }
100
        });
101
        jMenu1.add(open);
102-
        Open.setText("Open...");
102+
103-
        Open.addActionListener(new java.awt.event.ActionListener() {
103+
        save.setText("Save File");
104
        save.addActionListener(new java.awt.event.ActionListener() {
105-
                OpenActionPerformed(evt);
105+
106
                saveActionPerformed(evt);
107
            }
108-
        jMenu1.add(Open);
108+
109
        jMenu1.add(save);
110-
        Save.setText("Save...");
110+
111-
        Save.addActionListener(new java.awt.event.ActionListener() {
111+
        exit.setText("Exit Program");
112
        exit.addActionListener(new java.awt.event.ActionListener() {
113-
                SaveActionPerformed(evt);
113+
114
                exitActionPerformed(evt);
115
            }
116-
        jMenu1.add(Save);
116+
117
        jMenu1.add(exit);
118-
        jMenuItem3.setText("Exit");
118+
119-
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
119+
120
121-
                jMenuItem3ActionPerformed(evt);
121+
        jMenu2.setText("Edit");
122
123
        getcolumn.setText("Get New Column...");
124-
        jMenu1.add(jMenuItem3);
124+
        jMenu2.add(getcolumn);
125
126
        jMenuBar1.add(jMenu2);
127
128-
        dataMenu.setText("Data");
128+
        jMenu3.setText("Help");
129
130-
        fetchNew.setText("Fetch New Column");
130+
        prefs.setText("Preferences");
131-
        dataMenu.add(fetchNew);
131+
        jMenu3.add(prefs);
132
133-
        jMenuBar1.add(dataMenu);
133+
        about.setText("About iNed...");
134
        jMenu3.add(about);
135-
        helpMenu.setText("Help");
135+
136
        readme.setText("Readme");
137-
        Preferences.setText("Preferences");
137+
        jMenu3.add(readme);
138-
        helpMenu.add(Preferences);
138+
139
        jMenuBar1.add(jMenu3);
140-
        Readme.setText("Readme...");
140+
141-
        Readme.addActionListener(new java.awt.event.ActionListener() {
141+
142
143-
                ReadmeActionPerformed(evt);
143+
144
        getContentPane().setLayout(layout);
145
        layout.setHorizontalGroup(
146-
        helpMenu.add(Readme);
146+
147
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
148-
        About.setText("About iNed");
148+
149-
        helpMenu.add(About);
149+
150
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
151-
        jMenuBar1.add(helpMenu);
151+
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-
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
159+
    private void exitActionPerformed(java.awt.event.ActionEvent evt) {                                     
160-
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
160+
 System.exit(0);
161-
                    .addGroup(layout.createSequentialGroup()
161+
162-
                        .addContainerGap()
162+
163-
                        .addComponent(jScrollBar2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
163+
    private void openActionPerformed(java.awt.event.ActionEvent evt) {                                     
164-
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 571, Short.MAX_VALUE))
164+
        
165-
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
165+
166-
                .addComponent(jScrollBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
166+
167
        File file = fileChooser.getSelectedFile();
168
        try {
169
          // What to do with the file, e.g. display it in a TextArea
170-
            .addComponent(jScrollBar1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
170+
          CSVReader reader = new CSVReader(new FileReader( file.getAbsolutePath()));
171
          List myEntries = reader.readAll();
172-
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE)
172+
          table (myEntries.toArray());
173-
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
173+
174-
                .addComponent(jScrollBar2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
174+
175
        }
176
    } else {
177
        System.out.println("File access cancelled by user.");
178
    }
179
 
180-
    private void ReadmeActionPerformed(java.awt.event.ActionEvent evt) {                                           
180+
       
181-
        // TODO add your handling code here:
181+
182-
    }                                          
182+
183
    private void saveActionPerformed(java.awt.event.ActionEvent evt) {
184-
    private void OpenActionPerformed(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-
          textarea.read( new FileReader( file.getAbsolutePath() ), null );
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-
    private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {                                       
200+
201-
        // int returnVal = fc.showSaveDialog(FileChooserDemo.this);
201+
202-
    }                                      
202+
203
                if ("Nimbus".equals(info.getName())) {
204-
    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {                                           
204+
205-
       System.exit(0);
205+
206-
    }                                          
206+
207
            }
208-
    private void SaveActionPerformed(java.awt.event.ActionEvent evt) {                                     
208+
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
209-
        //TODO
209+
210
        }
211
        //</editor-fold>
212
213
        /* Create and display the form */
214
        java.awt.EventQueue.invokeLater(new Runnable() {
215
            @Override
216-
        /*
216+
217-
         * Set the Nimbus look and feel
217+
218
            }
219
        });
220-
        /*
220+
221-
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
221+
222-
         * default look and feel. For details see
222+
    private javax.swing.JMenuItem about;
223-
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
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-
        } catch (ClassNotFoundException ex) {
232+
    private javax.swing.JMenuItem open;
233
    private javax.swing.JMenuItem prefs;
234-
        } catch (InstantiationException ex) {
234+
    private javax.swing.JMenuItem readme;
235
    private javax.swing.JMenuItem save;
236-
        } catch (IllegalAccessException ex) {
236+
    private javax.swing.JTable table;
237
    // End of variables declaration
238-
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
238+
239
    private void table(Object[] toArray) {
240
        
241
    }
242
}