// --------------------------------------- // Restricted Focus Viewer (RFV) Program // Version 2.1 // Language: Java 2 // October, 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_Display_Window.java // // Class for setting up the window in // which the displays the RFV elements. // --------------------------------------- import java.awt.*; import java.awt.image.*; import java.util.LinkedList; public class RFV_Display_Window extends Frame implements ImageObserver { // Variables needed for display // ---------------------------- private Image base_image; private RFV_Defaults defaults; private RFV_Block block; private Cursor dot_cursor; private Cursor pointer_cursor; private Toolkit toolkit; private MediaTracker media_tracker; private boolean replayer; // Needed for use with replayer // ---------------------------- private Image blurred_base_image; private Image in_focus_base_image; private int mode; private Replayer_Status_Image status_image; // Constants // --------- private static final String TITLE = "RFV Version 2.1"; private static final int DOT_SIZE = 2; public static final int FOCUS_WINDOW_MODE = 1; public static final int SCAN_PATH_MODE = 2; // Constructor // ----------- public RFV_Display_Window(RFV_Defaults df, boolean rep) { defaults = df; replayer = rep; this.setTitle(TITLE); this.setBackground(defaults.getBackgroundColor()); this.pack(); toolkit = this.getToolkit(); media_tracker = new MediaTracker(this); base_image = this.createImage(defaults.getFrameSize().width, defaults.getFrameSize().height); if (replayer) { blurred_base_image = this.createImage(defaults.getFrameSize().width, defaults.getFrameSize().height); in_focus_base_image = this.createImage(defaults.getFrameSize().width, defaults.getFrameSize().height); } mode = FOCUS_WINDOW_MODE; block = null; status_image = null; blankDisplay(); generateCursors(); this.show(); paint(this.getGraphics()); setPointerCursor(); } // Method to change the replayer mode // ---------------------------------- public void changeMode() { if (mode == FOCUS_WINDOW_MODE) mode = SCAN_PATH_MODE; else mode = FOCUS_WINDOW_MODE; } // Returns the replayer mode // ------------------------- public int getReplayerMode() { return mode; } // Method to generate a cursor which is a small black dot // ------------------------------------------------------ private void generateCursors() { Image cursor_image; Point cursor_hotspot; Dimension cursor_size; String cursor_name; int cursor_grey = 0; int transparent = 1; int pixels[]; IndexColorModel icm; cursor_hotspot = new Point(0, 0); cursor_name = "Dot_Cursor"; // Check the cursor size // --------------------- cursor_size = toolkit.getBestCursorSize(DOT_SIZE, DOT_SIZE); if (cursor_size.width == 0 || cursor_size.height == 0) RFV_Error.die(50); // Draw dot cursor image // --------------------- pixels = new int[cursor_size.width * cursor_size.height]; for (int i = 0; i < cursor_size.width * cursor_size.height; i++) pixels[i] = transparent; pixels[0] = cursor_grey; pixels[1] = cursor_grey; pixels[cursor_size.width] = cursor_grey; pixels[cursor_size.width + 1] = cursor_grey; byte r[] = {0x00, 0x00}; byte g[] = {0x00, 0x00}; byte b[] = {0x00, 0x00}; icm = new IndexColorModel(1, 2, r, g, b, transparent); cursor_image = this.createImage(new MemoryImageSource(cursor_size.width, cursor_size.height, icm, pixels, 0, cursor_size.width)); // Create cursors // -------------- pointer_cursor = new Cursor(Cursor.DEFAULT_CURSOR); try { dot_cursor = toolkit.createCustomCursor(cursor_image, cursor_hotspot, cursor_name); } catch(IndexOutOfBoundsException e) { RFV_Error.die(51); } } // Reads in a new block and draws the relevant base image // ------------------------------------------------------ public void readBlock(RFV_Input_File input_file) { LinkedList stimulus_list; RFV_Stimulus stimulus; if (block != null) { block.removeStimulusImages(); block = null; } block = new RFV_Block(input_file, defaults, this.getGraphics(), media_tracker, toolkit, -1); // Need to allocate images to stimuli // ---------------------------------- stimulus_list = block.getStimulusList(); for (int i = 0; i < stimulus_list.size(); i++) { try { stimulus = (RFV_Stimulus) stimulus_list.get(i); stimulus.stimulusImage(this.createImage(stimulus.getWidth(), stimulus.getHeight())); } catch(IndexOutOfBoundsException e) { RFV_Error.die(7); } } block.drawBlock(base_image.getGraphics()); } // Reset the base images // --------------------- public void resetReplayerImages() { if (replayer) { resetBlurredBaseImage(); resetInFocusBaseImage(); } } // Reads in a feedback block and draws the relevant base image // ----------------------------------------------------------- public void readFeedbackBlock(RFV_Input_File input_file, int time) { if (block != null) { block.removeStimulusImages(); block = null; } block = new RFV_Block(input_file, defaults, this.getGraphics(), media_tracker, toolkit, time); block.drawBlock(base_image.getGraphics()); } // Resets the blurred base image for the replayer // ---------------------------------------------- private void resetBlurredBaseImage() { Graphics g = blurred_base_image.getGraphics(); g.drawImage(base_image, 0, 0, this); } // Resets the base image with in focus stimuli for the replayer // ------------------------------------------------------------- private void resetInFocusBaseImage() { RFV_Stimulus stimulus; LinkedList stimulus_list; Graphics g = in_focus_base_image.getGraphics(); g.drawImage(base_image, 0, 0, this); // Draw each stimuli in focus // -------------------------- stimulus_list = block.getStimulusList(); try { for (int i = 0; i < stimulus_list.size(); i++) { stimulus = (RFV_Stimulus) stimulus_list.get(i); stimulus.drawInFocus(g); } } catch(IndexOutOfBoundsException e) { RFV_Error.die(52); } } // Returns the current block // ------------------------- public RFV_Block getBlock() { return block; } // Draws a blank base image // ------------------------ public void blankDisplay() { Graphics g = base_image.getGraphics(); g.setColor(defaults.getBackgroundColor()); g.fillRect(0, 0, defaults.getFrameSize().width, defaults.getFrameSize().height); } // Returns the graphics of the in focus base image // ----------------------------------------------- public Graphics getFocusGraphics() { return in_focus_base_image.getGraphics(); } // Returns the graphics of the blurred base image // ---------------------------------------------- public Graphics getBlurredGraphics() { return blurred_base_image.getGraphics(); } // Sets the dot cursor // ------------------- public void setDotCursor() { this.setCursor(dot_cursor); } // Sets the pointer cursor // ----------------------- public void setPointerCursor() { this.setCursor(pointer_cursor); } // Returns the minimum frame size // ------------------------------ public Dimension getMinimumSize() { return defaults.getFrameSize(); } // Returns the preferred frame size // -------------------------------- public Dimension getPreferredSize() { return defaults.getFrameSize(); } // Sets the replayer status image // ------------------------------ public void setReplayerStatusImage(Replayer_Status_Image si) { status_image = si; } // Paint method to redraw the display window // ----------------------------------------- public void paint(Graphics g) { if (!replayer) g.drawImage(base_image, 0, 0, this); else if (mode == FOCUS_WINDOW_MODE) g.drawImage(blurred_base_image, 0, 0, this); else g.drawImage(in_focus_base_image, 0, 0, this); if (status_image != null) status_image.draw(g); } // Required for the ImageObserver interface // ---------------------------------------- public boolean imageUpdate(Image img, int flags, int xc, int yc, int w, int h) { return true; } }