// --------------------------------------- // 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_Image.java // // Class for drawing a static image in the // RFV display window. // --------------------------------------- import java.awt.*; import java.awt.image.*; public class RFV_Image extends RFV_Display_Element implements ImageObserver { // Components needed to draw image // ------------------------------- private Image image; private Toolkit toolkit; private MediaTracker media_tracker; // Constructor which accepts the panel dimensions, an image // and a focus window - defaults to inactive // -------------------------------------------------------- public RFV_Image(Toolkit tk, MediaTracker mt, String filename) { super(true, false); // Initialize class elements // ------------------------- toolkit = tk; media_tracker = mt; loadImage(filename); } // Method to ensure the removal of the image when it is no longer needed // --------------------------------------------------------------------- public void finalize() { media_tracker.removeImage(image); } // Method for loading in the image // ------------------------------- private void loadImage(String filename) { // Load the image // --------------- image = toolkit.getImage(filename); media_tracker.addImage(image, 0); // Wait for the image to complete loading // -------------------------------------- try { media_tracker.waitForID(0); if (media_tracker.isErrorID(0)) RFV_Error.die(55, filename); } catch(InterruptedException e) { RFV_Error.die(56); } // Find dimensions of image // ------------------------ width = image.getWidth(this); height = image.getHeight(this); } // Draws the image // --------------- public void draw(Graphics g) { g.drawImage(image, x_offset, y_offset, this); } // Required for the ImageObserver interface // ---------------------------------------- public boolean imageUpdate(Image img, int flags, int xc, int yc, int w, int h) { return true; } }