// --------------------------------------- // Restricted Focus Viewer (RFV) Program // Version 2.1 // Language: Java 2 // November, 2000 // Copyright (C) 2000 Anthony R. Jansen // --------------------------------------- // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // --------------------------------------- // Replayer_Data_File.java // // The class is for handling data in the // RFV data file that gives the stimulus // mouse movement data. // --------------------------------------- import java.io.*; import java.awt.*; import java.util.LinkedList; public class Replayer_Data_File { // I/O file handling variables // --------------------------- private RandomAccessFile data_file; private int line_number; private String subject_id = ""; private String input_filename = ""; private String date = ""; // Constructor which accepts the input filename as // its argument, and opens up the file if possible // ----------------------------------------------- public Replayer_Data_File(String filename) { try { data_file = new RandomAccessFile(filename, "r"); line_number = 0; } catch(FileNotFoundException e) { RFV_Error.die(57, filename); } readHeaderInfo(); } // Reads in the file header information // ------------------------------------ private void readHeaderInfo() { String string; try { string = readLine().trim(); if (!string.equals("RFV Version 2.1 Output Data File")) RFV_Error.die(79); string = readLine(); subject_id = string.substring(18).trim(); string = readLine(); input_filename = string.substring(18).trim(); string = readLine(); date = string.substring(18).trim(); } catch(IndexOutOfBoundsException e) { RFV_Error.die(80); } } // Method to read in a line and catch the exception // ------------------------------------------------ private String readLine() { String string = " "; try { string = data_file.readLine(); } catch(IOException e) { RFV_Error.die(81); } return string; } // Method to see if a string starts with the specified prefix // ---------------------------------------------------------- private boolean isPrefix(String string, String prefix) { if (string == null || prefix == null) return false; if (string.length() < prefix.length()) return false; try { string = string.substring(0, prefix.length()); } catch(IndexOutOfBoundsException e) { RFV_Error.die(82, "Line " + line_number); } if (string.equals(prefix)) return true; else return false; } // Reads in all the component locations // ------------------------------------ public LinkedList readComponents() { String string; LinkedList list; list = new LinkedList(); try { data_file.seek((long) 0); } catch(IOException e) { RFV_Error.die(83); } string = readLine(); while (string != null) { if (isPrefix(string, "Component:")) list.add(getFileIndex(string.substring(10).trim())); string = readLine(); } return list; } // Reads in the block locations, given a component // Also checks to see if each block contains a stimulus // ---------------------------------------------------- public LinkedList readBlocks(RFV_File_Index index) { RFV_File_Index new_index; String string; LinkedList list; list = new LinkedList(); setFileIndex(index); string = readLine(); while (!isPrefix(string, "Component:") && string != null) { if (isPrefix(string, "Block")) { new_index = getFileIndex(string); string = readLine(); if (isPrefix(string, " Stimulus")) new_index.label = new_index.label + " *"; list.add(new_index); } else string = readLine(); } return list; } // Gets the number of data points for a block // Ignores stimulus location lines, and read until reponse line // ------------------------------------------------------------ public int readNumberDataPoints(RFV_File_Index index) { String string; int total = 0; setFileIndex(index); string = readLine(); while (isPrefix(string, " Stimulus")) string = readLine(); while (!isPrefix(string, " Response")) { total++; string = readLine(); } return total; } // Reads in the data points, ignoring stimulus location lines // ---------------------------------------------------------- public Replayer_Stimulus_Data [] readDataPoints(RFV_File_Index index, int num) { String string; String chunk; int stimulus; int time; int x_pos; int y_pos; boolean motion_blur; Replayer_Stimulus_Data data_array[]; data_array = new Replayer_Stimulus_Data[num]; setFileIndex(index); string = readLine(); while (isPrefix(string, " Stimulus")) string = readLine(); try { for (int i = 0; i < num; i++) { stimulus = Integer.parseInt(string.substring(0,12).trim()); time = Integer.parseInt(string.substring(12,24).trim()); x_pos = Integer.parseInt(string.substring(24,30).trim()); y_pos = Integer.parseInt(string.substring(30,36).trim()); if (stimulus == 0) motion_blur = false; else { if (string.charAt(36) == 'B') motion_blur = true; else motion_blur = false; } data_array[i] = new Replayer_Stimulus_Data(stimulus, time, x_pos, y_pos, motion_blur); string = readLine(); } } catch(IndexOutOfBoundsException e1) { RFV_Error.die(82, "Line " + line_number); } catch(NumberFormatException e2) { RFV_Error.die(84, "Line " + line_number); } return data_array; } // Returns the current file pointer offset, line number and current // file line for a component after its first label has been read in // ---------------------------------------------------------------- private RFV_File_Index getFileIndex(String label) { long offset = 0; try { offset = data_file.getFilePointer(); } catch(IOException e) { RFV_Error.die(58); } return new RFV_File_Index(label, offset, line_number, " "); } // Sets the file pointer offset and line number, based on a component index // ------------------------------------------------------------------------ private void setFileIndex(RFV_File_Index index) { try { line_number = index.line_number; data_file.seek(index.file_offset); } catch(IOException e) { RFV_Error.die(59); } } // Close file before class is destroyed // ------------------------------------ public void finalize() { try { if (data_file != null) data_file.close(); } catch(IOException e) { ; } } // Returns the subject ID // ---------------------- public String getSubjectID() { return subject_id; } // Returns the date // ---------------- public String getDate() { return date; } // Returns the Input filename // -------------------------- public String getInputFilename() { return input_filename; } }