// --------------------------------------- // 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_Stimulus.java // // Class for drawing and updating an // RFV stimulus, loading the main and // blurred images, and drawing the focus // window in the appropriate location. // --------------------------------------- import java.awt.*; import java.awt.image.*; public class RFV_Stimulus extends RFV_Display_Element implements ImageObserver { // Focus Window Regions // Outermost transition region: 0 // Middle transition region: 1 // Innermost transition region: 2 // Focus region: 3 // ------------------------------- private Image region_image[]; private Image blurred_image; private Image stimulus_image; // Components needed to draw stimulus // ---------------------------------- private RFV_Focus_Window focus_window; private Toolkit toolkit; private MediaTracker media_tracker; // Other variables // --------------- private double motion_blur_speed_sqrd; private boolean guide_box; // Constructor // ----------- public RFV_Stimulus(RFV_Focus_Window fw, Toolkit tk, MediaTracker mt, double mbss, String []filenames) { super(true, false); // Initialize class elements // ------------------------- focus_window = fw; toolkit = tk; media_tracker = mt; motion_blur_speed_sqrd = mbss; guide_box = false; // Check number of filenames // ------------------------- if (filenames.length != focus_window.NUM_REGIONS + 1) RFV_Error.die(70); region_image = new Image[focus_window.NUM_REGIONS]; loadStimulus(filenames); } // Accepts the stimulus image of the correct // dimensions (Class cannot create its own) // ----------------------------------------- public void stimulusImage(Image img) { stimulus_image = img; mouseOff(); } // Returns the square of the motion blur speed // ------------------------------------------- public double getMotionBlurSpeedSqrd() { return motion_blur_speed_sqrd; } // Method to set the guide box status // ---------------------------------- public void setGuideBox(boolean gb) { guide_box = gb; } // Method to ensure the removal of images that are no longer needed // ---------------------------------------------------------------- public void removeImages() { media_tracker.removeImage(blurred_image); for (int i = 0; i < focus_window.NUM_REGIONS; i++) media_tracker.removeImage(region_image[i]); } // Method for loading in the five stimulus images // Accepts filenames for stimulus files as arguments // ------------------------------------------------- private void loadStimulus(String []filenames) { boolean error_flag = false; // Load the images // --------------- blurred_image = toolkit.getImage(filenames[0]); media_tracker.addImage(blurred_image, 0); for (int i = 0; i < focus_window.NUM_REGIONS; i++) { region_image[i] = toolkit.getImage(filenames[i+1]); media_tracker.addImage(region_image[i], i+1); } // Wait for the images to complete loading // --------------------------------------- try { for (int i = 0; i < focus_window.NUM_REGIONS + 1; i++) { media_tracker.waitForID(i); if (media_tracker.isErrorID(i)) RFV_Error.die(55, filenames[i]); } } catch(InterruptedException e) { RFV_Error.die(56); } // Find dimensions of images and verify consistency // ------------------------------------------------ width = blurred_image.getWidth(this); height = blurred_image.getHeight(this); for (int i = 0; i < focus_window.NUM_REGIONS; i++) { if (width != region_image[i].getWidth(this) || height != region_image[i].getHeight(this)) error_flag = true; } if (error_flag) RFV_Error.die(71, filenames[focus_window.NUM_REGIONS]); } // Draws the stimulus image // ------------------------ public void draw(Graphics g) { g.drawImage(stimulus_image, x_offset, y_offset, this); } // Draws the in focus image // ------------------------ public void drawInFocus(Graphics g) { g.drawImage(region_image[3], x_offset, y_offset, this); } // Updates the stimulus image when the mouse is not on it // ------------------------------------------------------ public void mouseOff() { Graphics g = stimulus_image.getGraphics(); g.drawImage(blurred_image, 0, 0, this); } // Updates the stimulus image when the mouse is on it // -------------------------------------------------- public void mouseOn(int mouse_x, int mouse_y, boolean motion_blur) { // Draw the main fully blurred region // ---------------------------------- Graphics g = stimulus_image.getGraphics(); g.drawImage(blurred_image, 0, 0, this); // Adjust mouse position to account for stimulus offset // ---------------------------------------------------- mouse_x -= x_offset; mouse_y -= y_offset; // Draw outermost region // --------------------- drawFocusWindowRegion(0, mouse_x, mouse_y, g); // If no motion blur, draw other regions // ------------------------------------- if (!motion_blur) { drawFocusWindowRegion(1, mouse_x, mouse_y, g); drawFocusWindowRegion(2, mouse_x, mouse_y, g); drawFocusWindowRegion(3, mouse_x, mouse_y, g); } // If guide box needed, draw in red // -------------------------------- if (guide_box) { g.setColor(Color.red); g.drawRect(mouse_x - focus_window.hor_offset[0], mouse_y - focus_window.ver_offset[0], focus_window.width[0], focus_window.height[0]); } } // Draws a specified focus window region // ------------------------------------- private void drawFocusWindowRegion(int region, int mouse_x, int mouse_y, Graphics g) { int left = mouse_x - focus_window.hor_offset[region]; int right = left + focus_window.width[region]; int top = mouse_y - focus_window.ver_offset[region]; int bottom = top + focus_window.height[region]; // Ensure nothing is above or to the left // of the top left corner of the stimulus // -------------------------------------- if (right < 0) return; if (bottom < 0) return; if (left < 0) left = 0; if (top < 0) top = 0; g.drawImage(region_image[region], left, top, right, bottom, left, top, right, bottom, this); } // Required for the ImageObserver interface // ---------------------------------------- public boolean imageUpdate(Image img, int flags, int xc, int yc, int w, int h) { return true; } // Returns the x offset for this stimulus // -------------------------------------- public int getXOffset() { return x_offset; } // Returns the y offset for this stimulus // -------------------------------------- public int getYOffset() { return y_offset; } }