Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package dad.inedgui;
- import java.awt.Component;
- import java.io.*;
- import javax.swing.JFileChooser;
- class MyCustomFilter extends javax.swing.filechooser.FileFilter {
- @Override
- public boolean accept(File file) {
- // Allow only directories, or files with ".txt" extension
- return file.isDirectory() || file.getAbsolutePath().endsWith(".txt");
- }
- @Override
- public String getDescription() {
- // This description will be displayed in the dialog,
- // hard-coded = ugly, should be done via I18N
- return "Text documents (*.txt)";
- }
- }
- /**
- *
- * @author ccreason
- */
- 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 {
- /**
- * 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();
- jScrollBar1 = new javax.swing.JScrollBar();
- jScrollBar2 = new javax.swing.JScrollBar();
- jScrollPane1 = new javax.swing.JScrollPane();
- textarea = new javax.swing.JTextArea();
- jMenuBar1 = new javax.swing.JMenuBar();
- jMenu1 = new javax.swing.JMenu();
- Open = new javax.swing.JMenuItem();
- Save = new javax.swing.JMenuItem();
- jMenuItem3 = new javax.swing.JMenuItem();
- dataMenu = new javax.swing.JMenu();
- fetchNew = new javax.swing.JMenuItem();
- helpMenu = new javax.swing.JMenu();
- Preferences = new javax.swing.JMenuItem();
- Readme = new javax.swing.JMenuItem();
- About = new javax.swing.JMenuItem();
- fileChooser.setDialogTitle("Choose a CSV File");
- fileChooser.setFileFilter(new MyCustomFilter());
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jScrollBar2.setOrientation(javax.swing.JScrollBar.HORIZONTAL);
- textarea.setColumns(20);
- textarea.setRows(5);
- jScrollPane1.setViewportView(textarea);
- jMenu1.setText("File");
- jMenu1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jMenu1ActionPerformed(evt);
- }
- });
- Open.setText("Open...");
- Open.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- OpenActionPerformed(evt);
- }
- });
- jMenu1.add(Open);
- Save.setText("Save...");
- Save.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- SaveActionPerformed(evt);
- }
- });
- jMenu1.add(Save);
- jMenuItem3.setText("Exit");
- jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jMenuItem3ActionPerformed(evt);
- }
- });
- jMenu1.add(jMenuItem3);
- jMenuBar1.add(jMenu1);
- dataMenu.setText("Data");
- fetchNew.setText("Fetch New Column");
- dataMenu.add(fetchNew);
- jMenuBar1.add(dataMenu);
- helpMenu.setText("Help");
- Preferences.setText("Preferences");
- helpMenu.add(Preferences);
- Readme.setText("Readme...");
- Readme.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- ReadmeActionPerformed(evt);
- }
- });
- helpMenu.add(Readme);
- About.setText("About iNed");
- helpMenu.add(About);
- jMenuBar1.add(helpMenu);
- setJMenuBar(jMenuBar1);
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jScrollBar2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 571, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jScrollBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollBar1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jScrollBar2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- );
- pack();
- }// </editor-fold>
- private void ReadmeActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- 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
- textarea.read( new FileReader( file.getAbsolutePath() ), null );
- } catch (IOException ex) {
- System.out.println("problem accessing file"+file.getAbsolutePath());
- }
- } else {
- System.out.println("File access cancelled by user.");
- }
- }
- private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {
- // int returnVal = fc.showSaveDialog(FileChooserDemo.this);
- }
- private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {
- System.exit(0);
- }
- private void SaveActionPerformed(java.awt.event.ActionEvent evt) {
- //TODO
- }
- /**
- * @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 ex) {
- java.util.logging.Logger.getLogger(iNedGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(iNedGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(iNedGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (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() {
- public void run() {
- new iNedGui().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JMenuItem About;
- private javax.swing.JMenuItem Open;
- private javax.swing.JMenuItem Preferences;
- private javax.swing.JMenuItem Readme;
- private javax.swing.JMenuItem Save;
- private javax.swing.JMenu dataMenu;
- private javax.swing.JMenuItem fetchNew;
- private javax.swing.JFileChooser fileChooser;
- private javax.swing.JMenu helpMenu;
- private javax.swing.JMenu jMenu1;
- private javax.swing.JMenuBar jMenuBar1;
- private javax.swing.JMenuItem jMenuItem3;
- private javax.swing.JScrollBar jScrollBar1;
- private javax.swing.JScrollBar jScrollBar2;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JTextArea textarea;
- // End of variables declaration
- private Component getFrame() {
- throw new UnsupportedOperationException("Not yet implemented");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement