// --------------------------------------- // 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_Defaults.java // // Class for specifying the frame size // and the default settings for the text, // buttons and stimulus attributes. // --------------------------------------- import java.awt.*; public class RFV_Defaults { // Default variables // ----------------- private Font text_font; private FontMetrics text_font_metrics; private Font button_font; private FontMetrics button_font_metrics; private Color background_color; private Color text_foreground; private Color button_foreground; private Color button_background; private RFV_Focus_Window focus_window; private double motion_blur_speed_sqrd; private Dimension frame_size; // Flags to make sure each parameter is read in only once // ------------------------------------------------------ private boolean text_f; private boolean button_f; private boolean focus_w; private boolean motion_b; private boolean frame_s; private boolean bg_flag; private boolean text_fg_flag; private boolean button_fg_flag; private boolean button_bg_flag; // Constants // --------- private static final Color DEFAULT_BACKGROUND_COLOUR = Color.white; private static final Color DEFAULT_TEXT_COLOUR = Color.black; private static final Color DEFAULT_BUTTON_COLOUR = Color.lightGray; // Constructor which reads in the default values // --------------------------------------------- public RFV_Defaults(RFV_Input_File input_file, Graphics g) { String token; text_f = false; button_f = false; focus_w = false; motion_b = false; frame_s = false; bg_flag = false; text_fg_flag = false; button_fg_flag = false; button_bg_flag = false; input_file.readOpenBracket(); while (!input_file.isCloseBracket()) { token = input_file.readToken(); if (token.equalsIgnoreCase("frame_size")) readFrameSize(input_file); else if (token.equalsIgnoreCase("focus_window")) readFocusWindow(input_file); else if (token.equalsIgnoreCase("motion_blur_speed")) readMotionBlurSpeed(input_file); else if (token.equalsIgnoreCase("text_font")) readTextFont(input_file, g); else if (token.equalsIgnoreCase("button_font")) readButtonFont(input_file, g); else if (token.equalsIgnoreCase("display_background")) readBackgroundColor(input_file); else if (token.equalsIgnoreCase("text_foreground")) readTextForeground(input_file); else if (token.equalsIgnoreCase("button_foreground")) readButtonForeground(input_file); else if (token.equalsIgnoreCase("button_background")) readButtonBackground(input_file); else RFV_Error.die(41, input_file.getLineNumber(), token); } input_file.readCloseBracket(); // Check everything has been read in // --------------------------------- token = ""; if (!frame_s) token = "FRAME_SIZE "; if (!focus_w) token = token + "FOCUS_WINDOW "; if (!motion_b) token = token + "MOTION_BLUR_SPEED "; if (!(focus_w && motion_b && frame_s)) RFV_Error.die(42, token); // Set values for parameters not explicitly specified // -------------------------------------------------- if (!text_f) { text_font = new Font("Helvetica", Font.PLAIN, 20); text_font_metrics = g.getFontMetrics(text_font); } if (!button_f) { button_font = new Font("Helvetica", Font.PLAIN, 20); button_font_metrics = g.getFontMetrics(button_font); } if (!bg_flag) background_color = DEFAULT_BACKGROUND_COLOUR; if (!text_fg_flag) text_foreground = DEFAULT_TEXT_COLOUR; if (!button_fg_flag) button_foreground = DEFAULT_TEXT_COLOUR; if (!button_bg_flag) button_background = DEFAULT_BUTTON_COLOUR; } // Read in the frame size // Allowed only once in defaults // ----------------------------- private void readFrameSize(RFV_Input_File input_file) { int width; int height; if (frame_s) RFV_Error.die(43, input_file.getLineNumber()); frame_s = true; input_file.readOpenBracket(); width = input_file.readInteger(); height = input_file.readInteger(); input_file.readCloseBracket(); frame_size = new Dimension(width, height); } // Read in the default focus window // Allowed only once in defaults // -------------------------------- private void readFocusWindow(RFV_Input_File input_file) { if (focus_w) RFV_Error.die(44, input_file.getLineNumber()); focus_w = true; focus_window = new RFV_Focus_Window(input_file); } // Read in the default motion blur speed // Allowed only once in defaults // ------------------------------------- private void readMotionBlurSpeed(RFV_Input_File input_file) { int speed; if (motion_b) RFV_Error.die(45, input_file.getLineNumber()); motion_b= true; input_file.readOpenBracket(); speed = input_file.readInteger(); input_file.readCloseBracket(); motion_blur_speed_sqrd = (double) speed * (double) speed; } // Read in the default text font // Allowed only once in defaults // ----------------------------- private void readTextFont(RFV_Input_File input_file, Graphics g) { String font_type; String font_style; int font_size; int font_style_num; if (text_f) RFV_Error.die(46, input_file.getLineNumber()); text_f = true; input_file.readOpenBracket(); font_type = input_file.readLabel().trim(); font_style = input_file.readToken(); font_size = input_file.readInteger(); input_file.readCloseBracket(); // Set the font and font metrics // ----------------------------- font_style_num = Font.PLAIN; if (font_style.equalsIgnoreCase("bold")) font_style_num = Font.BOLD; else if (font_style.equalsIgnoreCase("italic")) font_style_num = Font.ITALIC; else if (font_style.equalsIgnoreCase("bold_italic")) font_style_num = Font.BOLD + Font.ITALIC; text_font = new Font(font_type, font_style_num, font_size); text_font_metrics = g.getFontMetrics(text_font); } // Read in the default button font // Allowed only once in defaults // ------------------------------- private void readButtonFont(RFV_Input_File input_file, Graphics g) { String font_type; String font_style; int font_size; int font_style_num; if (button_f) RFV_Error.die(47, input_file.getLineNumber()); button_f = true; input_file.readOpenBracket(); font_type = input_file.readLabel().trim(); font_style = input_file.readToken(); font_size = input_file.readInteger(); input_file.readCloseBracket(); // Set the font and font metrics // ----------------------------- font_style_num = Font.PLAIN; if (font_style.equalsIgnoreCase("bold")) font_style_num = Font.BOLD; else if (font_style.equalsIgnoreCase("italic")) font_style_num = Font.ITALIC; else if (font_style.equalsIgnoreCase("bold_italic")) font_style_num = Font.BOLD + Font.ITALIC; button_font = new Font(font_type, font_style_num, font_size); button_font_metrics = g.getFontMetrics(button_font); } // Read in the background color // Allowed only once in defaults // ----------------------------- private void readBackgroundColor(RFV_Input_File input_file) { if (bg_flag) RFV_Error.die(48, input_file.getLineNumber()); bg_flag = true; background_color = input_file.readColor(); } // Read in the text foreground // Allowed only once in defaults // ----------------------------- private void readTextForeground(RFV_Input_File input_file) { if (text_fg_flag) RFV_Error.die(86, input_file.getLineNumber()); text_fg_flag = true; text_foreground = input_file.readColor(); } // Read in the button foreground // Allowed only once in defaults // ----------------------------- private void readButtonForeground(RFV_Input_File input_file) { if (button_fg_flag) RFV_Error.die(87, input_file.getLineNumber()); button_fg_flag = true; button_foreground = input_file.readColor(); } // Read in the button background // Allowed only once in defaults // ----------------------------- private void readButtonBackground(RFV_Input_File input_file) { if (button_bg_flag) RFV_Error.die(88, input_file.getLineNumber()); button_bg_flag = true; button_background = input_file.readColor(); } // Returns the text font // --------------------- public Font getTextFont() { return text_font; } // Returns the button font // ----------------------- public Font getButtonFont() { return button_font; } // Returns the text font metrics // ----------------------------- public FontMetrics getTextFontMetrics() { return text_font_metrics; } // Returns the button font metrics // ------------------------------- public FontMetrics getButtonFontMetrics() { return button_font_metrics; } // Returns the background color // ---------------------------- public Color getBackgroundColor() { return background_color; } // Returns the text foreground // --------------------------- public Color getTextForeground() { return text_foreground; } // Returns the button foreground // ----------------------------- public Color getButtonForeground() { return button_foreground; } // Returns the button background // ----------------------------- public Color getButtonBackground() { return button_background; } // Returns the frame size dimensions // --------------------------------- public Dimension getFrameSize() { return frame_size; } // Returns the square of the motion blur speed // ------------------------------------------- public double getMotionBlurSpeedSqrd() { return motion_blur_speed_sqrd; } // Returns the focus window // ------------------------ public RFV_Focus_Window getFocusWindow() { return focus_window; } }