00001
00002
00003
00004
00005
00006
00007 package DisplayGUI;
00008 import java.io.*;
00009
00014 public class BookKeeperPrompt extends javax.swing.JFrame implements displayParams {
00015
00016 File file=null;
00017
00019 public BookKeeperPrompt() {
00020 super("SctRodDaq BookKeeper");
00021 initComponents();
00022 }
00023
00029 private void initComponents() {
00030 java.awt.GridBagConstraints gridBagConstraints;
00031
00032 getContentPane().setBackground(backgroundColor);
00033
00034 jLabel1 = new javax.swing.JLabel();
00035 jTextArea1 = new javax.swing.JTextArea();
00036 jLabel2 = new javax.swing.JLabel();
00037 enterButton = new javax.swing.JButton();
00038 closeButton = new javax.swing.JButton();
00039
00040 getContentPane().setLayout(new java.awt.GridBagLayout());
00041
00042 addWindowListener(new java.awt.event.WindowAdapter() {
00043 public void windowClosing(java.awt.event.WindowEvent evt) {
00044 exitForm(evt);
00045 }
00046 });
00047
00048 jLabel1.setText("jLabel1");
00049 jLabel1.setFont(displayTextFont);
00050 jLabel1.setForeground(darkBlueColor);
00051 gridBagConstraints = new java.awt.GridBagConstraints();
00052 gridBagConstraints.gridwidth = 2;
00053 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00054 getContentPane().add(jLabel1, gridBagConstraints);
00055
00056 gridBagConstraints = new java.awt.GridBagConstraints();
00057 gridBagConstraints.gridx = 0;
00058 gridBagConstraints.gridy = 2;
00059 gridBagConstraints.gridwidth = 2;
00060 gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
00061 jTextArea1.setLineWrap(true);
00062 jTextArea1.setWrapStyleWord(true);
00063 javax.swing.JScrollPane areaScrollPane = new javax.swing.JScrollPane(jTextArea1);
00064 areaScrollPane.setVerticalScrollBarPolicy(
00065 javax.swing.JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
00066 areaScrollPane.setPreferredSize(new java.awt.Dimension(250, 250));
00067 getContentPane().add(areaScrollPane, gridBagConstraints);
00068
00069 jLabel2.setText("Enter comments");
00070 jLabel2.setFont(displayScaleFont);
00071 gridBagConstraints = new java.awt.GridBagConstraints();
00072 gridBagConstraints.gridx = 0;
00073 gridBagConstraints.gridy = 1;
00074 gridBagConstraints.gridwidth = 2;
00075 gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
00076 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
00077 getContentPane().add(jLabel2, gridBagConstraints);
00078
00079 enterButton.setText("Enter");
00080 enterButton.setFont(displayScaleFont);
00081 gridBagConstraints = new java.awt.GridBagConstraints();
00082 gridBagConstraints.gridx = 0;
00083 gridBagConstraints.gridy = 3;
00084 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00085 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
00086 getContentPane().add(enterButton, gridBagConstraints);
00087 enterButton.addActionListener(new java.awt.event.ActionListener() {
00088 public void actionPerformed(java.awt.event.ActionEvent evt) {
00089 if(file==null) {
00090 System.err.println("Null test index file");
00091 return;
00092 }
00093 try {
00094 BufferedWriter out = new BufferedWriter(new FileWriter(file));
00095 String txt = jTextArea1.getText();
00096 if(!txt.equals("")) out.write(jTextArea1.getText());
00097 out.close();
00098 }catch(Exception e) {
00099 System.err.println("SctGUI::BookKeeper - failed to update test index file "+file.getAbsolutePath()+" - "+e.toString());
00100 }
00101 exitForm(null);
00102 }
00103 });
00104
00105 closeButton.setText("Close");
00106 closeButton.setFont(displayScaleFont);
00107 gridBagConstraints = new java.awt.GridBagConstraints();
00108 gridBagConstraints.gridx = 1;
00109 gridBagConstraints.gridy = 3;
00110 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00111 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
00112 getContentPane().add(closeButton, gridBagConstraints);
00113 closeButton.addActionListener(new java.awt.event.ActionListener() {
00114 public void actionPerformed(java.awt.event.ActionEvent evt) {
00115 exitForm(null);
00116 }
00117 });
00118
00119 pack();
00120 java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
00121 java.awt.Dimension WSize = getSize();
00122 setLocation((screenSize.width-(int)WSize.getWidth())/2,(screenSize.height-(int)WSize.getHeight())/2);
00123 }
00124
00126 private void exitForm(java.awt.event.WindowEvent evt) {
00127 setVisible(false);
00128 }
00129
00130 public void showPrompt(File file, String run, String scan, String testName) {
00131 this.file=file;
00132
00133 File parent = file.getParentFile();
00134 if(!parent.exists()) {
00135 javax.swing.JOptionPane.showMessageDialog(null,"Bookkeeping not available for this run or scan");
00136 return;
00137 }
00138
00139 if(testName==null) {
00140 jLabel1.setText("Run "+run);
00141 jLabel2.setText("Please enter a description for this run:");
00142 }
00143 else {
00144 jLabel1.setText(testName+" (Run/Scan "+run+"/"+scan+")");
00145 jLabel2.setText("Please enter a description for this test:");
00146 }
00147 jTextArea1.setText("");
00148 try {
00149 if(file.exists()) {
00150 BufferedReader in = new BufferedReader(new FileReader(file));
00151 String line;
00152 int count=0;
00153 while((line=in.readLine())!=null) {
00154 if(count>0) jTextArea1.append("\n");
00155 jTextArea1.append(line);
00156 count++;
00157 }
00158 in.close();
00159 }
00160 }catch(Exception e) {
00161 System.err.println("SctGUI::BookKeeper - Failed to read test index "+file.getAbsolutePath()+" - "+e.toString());
00162 }
00163 pack();
00164 setVisible(true);
00165 }
00166
00167
00168
00169
00170
00171 private javax.swing.JButton closeButton;
00172 private javax.swing.JButton enterButton;
00173 private javax.swing.JLabel jLabel1;
00174 private javax.swing.JLabel jLabel2;
00175 private javax.swing.JTextArea jTextArea1;
00176
00177
00178 }