// --------------------------------------- // 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. // --------------------------------------- // RFV_Output_File.java // // This file outputs the user's responses // and the mouse movements over blocks // that contain stimuli. // --------------------------------------- import java.io.*; import java.text.*; import java.util.*; public class RFV_Output_File { // Variable to handle file writing // ------------------------------- private PrintWriter output; // Constant file prefix // -------------------- private static final String FILE_SUFFIX = ".rfvd"; private static final String OUTPUT_TITLE = "RFV Version 2.1 Output Data File"; // Constructor which opens a new file (if possible) // and writes header information // ------------------------------------------------ public RFV_Output_File(String subject_id, String input_filename) { String filename; // Open new file // ------------- try { filename = subject_id + FILE_SUFFIX; FileOutputStream out_stream = new FileOutputStream(filename); output = new PrintWriter(out_stream); } catch(IOException e) { RFV_Error.die(68, "" + subject_id + FILE_SUFFIX); } // Get the date // ------------ DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM); // Print file header information // ----------------------------- output.println(OUTPUT_TITLE); output.println("Subject: " + subject_id); output.println("Input Filename: " + input_filename); output.println("Date: " + df.format(new Date())); output.flush(); } // Writes a line to the output // --------------------------- public void writeLine(String line) { output.println(line); output.flush(); } // Writes an empty line to the output // ---------------------------------- public void emptyLine() { output.println(""); output.flush(); } // Method to update the latest mouse position // ------------------------------------------ public void writeMousePosition(int stimulus, long time, int x, int y, boolean motion_blur) { String line; // Record the details in columns // ----------------------------- line = " " + stimulus; while (line.length() < 12) line = line + " "; line = line + time; while (line.length() < 24) line = line + " "; line = line + x; while (line.length() < 30) line = line + " "; line = line + y; while (line.length() < 36) line = line + " "; if (stimulus > 0) { if (motion_blur) line = line + "B"; else line = line + "F"; } // Output the line // --------------- output.println(line); output.flush(); } // Writes out stimulus details // --------------------------- public void writeStimulus(int num, int xc, int yc) { output.println(" Stimulus " + num + ": Top left corner at <" + xc + ", " + yc + ">"); output.flush(); } // Writes out the response details // ------------------------------- public void writeResponse(String response, long time) { output.println(" Response: " + response); output.println(" Time (ms): " + time); output.flush(); } // Close the file before class is destroyed // ---------------------------------------- public void finalize() { if (output != null) output.close(); } }