Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

RawDataViewer.java

00001 package guiUtilities;
00002 import javax.swing.*;
00003 import java.awt.event.*;
00004 import java.awt.*;
00005 import java.io.*;
00006 import javax.swing.border.Border;
00007 import java.util.Vector;
00008 import Preferences.PreferencesInterface;
00009 
00010 public class RawDataViewer extends JFrame 
00011                             implements ActionListener {
00012 
00013     private static RawDataViewer instance = new RawDataViewer();
00014     JTextArea theTextArea;
00015     JButton saveDataButton;
00016     JLabel title;
00017 
00018     Vector theRawData;
00019     JComboBox fileNameMenu; 
00020     int current = 0;
00021 
00022 
00023     public RawDataViewer() {
00024         super("Data Viewer");
00025         JPanel pane = new JPanel();
00026         Border paneEdge = BorderFactory.createEmptyBorder(0,10,10,10);
00027         pane.setBorder(paneEdge);
00028 
00029 
00030         JScrollPane scrollPane;
00031         this.theRawData=theRawData;
00032 
00033         //A label for the caption.
00034 
00035         title = new JLabel("The title of this Data");
00036         title.setFont(new Font("SansSerif",Font.BOLD,16));
00037         title.setForeground(Color.blue);
00038 
00039         JPanel filenamePane = new JPanel();
00040         filenamePane.setLayout(new BoxLayout(filenamePane,BoxLayout.X_AXIS));
00041         fileNameMenu = new JComboBox();
00042         fileNameMenu.addItem("None yet");
00043         fileNameMenu.setFont(new Font("SansSerif",Font.PLAIN,12));
00044         fileNameMenu.addActionListener(this);
00045         fileNameMenu.setActionCommand("menuChange");
00046         filenamePane.add(Box.createHorizontalGlue());
00047         JLabel fname =new JLabel("Filename:");
00048         fname.setFont(new Font("SansSerif",Font.PLAIN,12));
00049         fname.setForeground(Color.blue);
00050         filenamePane.add(fname);
00051         filenamePane.add(fileNameMenu);
00052         filenamePane.add(Box.createHorizontalGlue());
00053 
00054         //A label for displaying the photographs.
00055 
00056         theTextArea = new JTextArea(60,40);
00057         theTextArea.setEditable(false);
00058         scrollPane = new JScrollPane(theTextArea);
00059         scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
00060 
00061 
00062         scrollPane.setPreferredSize(new Dimension(400,300));
00063 
00064 
00065 
00066         //Create the next and previous buttons.
00067 
00068 
00069          pane.setLayout(new BoxLayout(pane,BoxLayout.Y_AXIS));
00070 
00071         pane.add(Box.createRigidArea(new Dimension(0,20)));
00072         title.setAlignmentX(CENTER_ALIGNMENT);
00073         pane.add(title);
00074         pane.add(filenamePane);
00075         pane.add(scrollPane); 
00076         saveDataButton = new JButton("Save to File");
00077         saveDataButton.setActionCommand("save");
00078         saveDataButton.addActionListener(this);
00079         saveDataButton.setAlignmentX(CENTER_ALIGNMENT);
00080         pane.add(saveDataButton);
00081 
00082         JPanel buttonPane = new JPanel();
00083         buttonPane.setLayout(new BoxLayout(buttonPane,BoxLayout.X_AXIS));
00084         buttonPane.add(Box.createHorizontalGlue());
00085         buttonPane.add(saveDataButton);
00086   //      buttonPane.add(Box.createRigidArea(new Dimension(20,0)));
00087   //      buttonPane.add(nextButton);
00088         buttonPane.add(Box.createHorizontalGlue());
00089         pane.add(buttonPane);
00090  //       pane.setPreferredSize(new Dimension(200,200));
00091           setContentPane(pane);
00092         pack();
00093     }
00094 
00095     public static RawDataViewer getInstance() {
00096         return instance;
00097     }
00098 
00099 
00100     public void actionPerformed(ActionEvent e) {
00101 
00102        if (e.getActionCommand().equals("save")) {
00103 
00104                  String fname = (String)fileNameMenu.getSelectedItem();
00105                  File preferredDir = new File(PreferencesInterface.getInstance().getPreference(PreferencesInterface.SCRATCH_DIR));
00106                  File theFile = new File(preferredDir,fname);
00107                  JFileChooser fc = new JFileChooser(preferredDir);
00108 
00109                    fc.setSelectedFile(theFile);
00110                    int returnVal = fc.showSaveDialog(RawDataViewer.this);
00111 
00112                    if (returnVal == JFileChooser.APPROVE_OPTION) {
00113                       File file = fc.getSelectedFile();     // ******************************************************************************************************************
00114 
00115 
00116 
00117                       try {
00118                           FileWriter fw = new FileWriter(file);
00119                           BufferedWriter out = new BufferedWriter(fw);
00120                           String rawDataList = theTextArea.getText();
00121                           out.write(rawDataList,0,rawDataList.length());
00122                           out.close();
00123                           System.out.println("Raw data file saved ok as "+file.getAbsolutePath());
00124                           } catch(IOException ioe) {System.out.println("Error creating file "+file.getAbsolutePath());}
00125        
00126                       }
00127              }
00128        else { // filename menu has changed... update textpane with string
00129              int nitem = fileNameMenu.getSelectedIndex();
00130              if(nitem>=0) theTextArea.setText((String)theRawData.elementAt(2*nitem + 1));
00131              }
00132        
00133         }
00134   public void showNewData(Vector theRawData, String theTitle) {
00135        this.theRawData=theRawData;
00136        fileNameMenu.removeAllItems();
00137        for(int i=0;i<theRawData.size();i++) {
00138            if(i%2==0) fileNameMenu.addItem((String)theRawData.elementAt(i));
00139            }
00140         theTextArea.setText((String)theRawData.elementAt(1));
00141         title.setText(theTitle);
00142         pack();
00143         setVisible(true);
00144         }
00145 }

Generated on Thu Jul 15 09:55:47 2004 for SCT DAQ/DCS Software - Java by doxygen 1.3.5