Advertisement
bladebaka

iNed

Jul 25th, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.78 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package dad.inedgui;
  6.  
  7. import java.awt.Component;
  8. import java.io.*;
  9. import javax.swing.JFileChooser;
  10.  
  11.  
  12.  class MyCustomFilter extends javax.swing.filechooser.FileFilter {
  13.         @Override
  14.         public boolean accept(File file) {
  15.             // Allow only directories, or files with ".txt" extension
  16.             return file.isDirectory() || file.getAbsolutePath().endsWith(".txt");
  17.         }
  18.         @Override
  19.         public String getDescription() {
  20.             // This description will be displayed in the dialog,
  21.             // hard-coded = ugly, should be done via I18N
  22.             return "Text documents (*.txt)";
  23.         }
  24.     }
  25.  
  26. /**
  27.  *
  28.  * @author ccreason
  29.  */
  30.  
  31.     class CSVFilter extends javax.swing.filechooser.FileFilter {
  32.  
  33.         @Override
  34.         public boolean accept(File file) {
  35.             // Allow just directories and files with ".csv" extension...
  36.             return file.isDirectory() || file.getAbsolutePath().endsWith(".csv");
  37.         }
  38.  
  39.         @Override
  40.         public String getDescription() {
  41.             // This description will be displayed in the dialog,
  42.             // hard-coded = ugly, should be done via I18N
  43.             return "CSV Documents (*.csv)";
  44.         }
  45.  
  46.     }
  47.  
  48.  
  49. public class iNedGui extends javax.swing.JFrame {
  50.  
  51.     /**
  52.      * Creates new form iNedGui
  53.      */
  54.     public iNedGui() {
  55.         initComponents();
  56.     }
  57.  
  58.     /**
  59.      * This method is called from within the constructor to initialize the form.
  60.      * WARNING: Do NOT modify this code. The content of this method is always
  61.      * regenerated by the Form Editor.
  62.      */
  63.     @SuppressWarnings("unchecked")
  64.     // <editor-fold defaultstate="collapsed" desc="Generated Code">
  65.     private void initComponents() {
  66.  
  67.         fileChooser = new javax.swing.JFileChooser();
  68.         jScrollBar1 = new javax.swing.JScrollBar();
  69.         jScrollBar2 = new javax.swing.JScrollBar();
  70.         jScrollPane1 = new javax.swing.JScrollPane();
  71.         textarea = new javax.swing.JTextArea();
  72.         jMenuBar1 = new javax.swing.JMenuBar();
  73.         jMenu1 = new javax.swing.JMenu();
  74.         Open = new javax.swing.JMenuItem();
  75.         Save = new javax.swing.JMenuItem();
  76.         jMenuItem3 = new javax.swing.JMenuItem();
  77.         dataMenu = new javax.swing.JMenu();
  78.         fetchNew = new javax.swing.JMenuItem();
  79.         helpMenu = new javax.swing.JMenu();
  80.         Preferences = new javax.swing.JMenuItem();
  81.         Readme = new javax.swing.JMenuItem();
  82.         About = new javax.swing.JMenuItem();
  83.  
  84.         fileChooser.setDialogTitle("Choose a CSV File");
  85.         fileChooser.setFileFilter(new MyCustomFilter());
  86.  
  87.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  88.  
  89.         jScrollBar2.setOrientation(javax.swing.JScrollBar.HORIZONTAL);
  90.  
  91.         textarea.setColumns(20);
  92.         textarea.setRows(5);
  93.         jScrollPane1.setViewportView(textarea);
  94.  
  95.         jMenu1.setText("File");
  96.         jMenu1.addActionListener(new java.awt.event.ActionListener() {
  97.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  98.                 jMenu1ActionPerformed(evt);
  99.             }
  100.         });
  101.  
  102.         Open.setText("Open...");
  103.         Open.addActionListener(new java.awt.event.ActionListener() {
  104.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  105.                 OpenActionPerformed(evt);
  106.             }
  107.         });
  108.         jMenu1.add(Open);
  109.  
  110.         Save.setText("Save...");
  111.         Save.addActionListener(new java.awt.event.ActionListener() {
  112.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  113.                 SaveActionPerformed(evt);
  114.             }
  115.         });
  116.         jMenu1.add(Save);
  117.  
  118.         jMenuItem3.setText("Exit");
  119.         jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
  120.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  121.                 jMenuItem3ActionPerformed(evt);
  122.             }
  123.         });
  124.         jMenu1.add(jMenuItem3);
  125.  
  126.         jMenuBar1.add(jMenu1);
  127.  
  128.         dataMenu.setText("Data");
  129.  
  130.         fetchNew.setText("Fetch New Column");
  131.         dataMenu.add(fetchNew);
  132.  
  133.         jMenuBar1.add(dataMenu);
  134.  
  135.         helpMenu.setText("Help");
  136.  
  137.         Preferences.setText("Preferences");
  138.         helpMenu.add(Preferences);
  139.  
  140.         Readme.setText("Readme...");
  141.         Readme.addActionListener(new java.awt.event.ActionListener() {
  142.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  143.                 ReadmeActionPerformed(evt);
  144.             }
  145.         });
  146.         helpMenu.add(Readme);
  147.  
  148.         About.setText("About iNed");
  149.         helpMenu.add(About);
  150.  
  151.         jMenuBar1.add(helpMenu);
  152.  
  153.         setJMenuBar(jMenuBar1);
  154.  
  155.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  156.         getContentPane().setLayout(layout);
  157.         layout.setHorizontalGroup(
  158.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  159.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  160.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  161.                     .addGroup(layout.createSequentialGroup()
  162.                         .addContainerGap()
  163.                         .addComponent(jScrollBar2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  164.                     .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 571, Short.MAX_VALUE))
  165.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  166.                 .addComponent(jScrollBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  167.         );
  168.         layout.setVerticalGroup(
  169.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  170.             .addComponent(jScrollBar1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  171.             .addGroup(layout.createSequentialGroup()
  172.                 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE)
  173.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  174.                 .addComponent(jScrollBar2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  175.         );
  176.  
  177.         pack();
  178.     }// </editor-fold>
  179.  
  180.     private void ReadmeActionPerformed(java.awt.event.ActionEvent evt) {                                          
  181.         // TODO add your handling code here:
  182.     }                                          
  183.  
  184.     private void OpenActionPerformed(java.awt.event.ActionEvent evt) {                                    
  185.         int returnVal = fileChooser.showOpenDialog(this);
  186.     if (returnVal == JFileChooser.APPROVE_OPTION) {
  187.         File file = fileChooser.getSelectedFile();
  188.         try {
  189.           // What to do with the file, e.g. display it in a TextArea
  190.           textarea.read( new FileReader( file.getAbsolutePath() ), null );
  191.         } catch (IOException ex) {
  192.           System.out.println("problem accessing file"+file.getAbsolutePath());
  193.         }
  194.     } else {
  195.         System.out.println("File access cancelled by user.");
  196.     }
  197.  
  198.     }                                    
  199.  
  200.     private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {                                      
  201.         // int returnVal = fc.showSaveDialog(FileChooserDemo.this);
  202.     }                                      
  203.  
  204.     private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  205.        System.exit(0);
  206.     }                                          
  207.  
  208.     private void SaveActionPerformed(java.awt.event.ActionEvent evt) {                                    
  209.         //TODO
  210.     }                                    
  211.  
  212.     /**
  213.      * @param args the command line arguments
  214.      */
  215.     public static void main(String args[]) {
  216.         /*
  217.          * Set the Nimbus look and feel
  218.          */
  219.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  220.         /*
  221.          * If Nimbus (introduced in Java SE 6) is not available, stay with the
  222.          * default look and feel. For details see
  223.          * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  224.          */
  225.         try {
  226.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  227.                 if ("Nimbus".equals(info.getName())) {
  228.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  229.                     break;
  230.                 }
  231.             }
  232.         } catch (ClassNotFoundException ex) {
  233.             java.util.logging.Logger.getLogger(iNedGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  234.         } catch (InstantiationException ex) {
  235.             java.util.logging.Logger.getLogger(iNedGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  236.         } catch (IllegalAccessException ex) {
  237.             java.util.logging.Logger.getLogger(iNedGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  238.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  239.             java.util.logging.Logger.getLogger(iNedGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  240.         }
  241.         //</editor-fold>
  242.  
  243.         /*
  244.          * Create and display the form
  245.          */
  246.         java.awt.EventQueue.invokeLater(new Runnable() {
  247.  
  248.             public void run() {
  249.                 new iNedGui().setVisible(true);
  250.             }
  251.         });
  252.     }
  253.     // Variables declaration - do not modify
  254.     private javax.swing.JMenuItem About;
  255.     private javax.swing.JMenuItem Open;
  256.     private javax.swing.JMenuItem Preferences;
  257.     private javax.swing.JMenuItem Readme;
  258.     private javax.swing.JMenuItem Save;
  259.     private javax.swing.JMenu dataMenu;
  260.     private javax.swing.JMenuItem fetchNew;
  261.     private javax.swing.JFileChooser fileChooser;
  262.     private javax.swing.JMenu helpMenu;
  263.     private javax.swing.JMenu jMenu1;
  264.     private javax.swing.JMenuBar jMenuBar1;
  265.     private javax.swing.JMenuItem jMenuItem3;
  266.     private javax.swing.JScrollBar jScrollBar1;
  267.     private javax.swing.JScrollBar jScrollBar2;
  268.     private javax.swing.JScrollPane jScrollPane1;
  269.     private javax.swing.JTextArea textarea;
  270.     // End of variables declaration
  271.  
  272.     private Component getFrame() {
  273.         throw new UnsupportedOperationException("Not yet implemented");
  274.     }
  275. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement