/************************************************************************** /* This class implements a primitive image-viewer. /* /* Copyright (c) 2006 by Bernhard Bablok (mail@bablokb.de) /* /* 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; see the file COPYING. If not, write to /* the Free Software Foundation Inc., 59 Temple Place - Suite 330, /* Boston, MA 02111-1307 USA /**************************************************************************/ import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; /** This class implements a primitive image-viewer. @version $Revision: 1.10 $ @author $Author: bablokb $ */ public class ImageViewer extends JFrame { public static final int WIDTH = 600, HEIGHT = 400; ////////////////////////////////////////////////////////////////////////////// /** Image-files. */ private RRArray iFiles = null; /** Image-Panel. */ private ImagePanel iImagePanel = null; /** Scroll-pane. */ private JScrollPane iScrollPane = null; ////////////////////////////////////////////////////////////////////////////// /** Constructor. */ public ImageViewer(String title, ImagePanel panel) { super(title); setJMenuBar(getMenu()); iImagePanel = panel; iScrollPane = new JScrollPane((JPanel) iImagePanel); getContentPane().add(iScrollPane); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocation(100, 100); setVisible(false); } ////////////////////////////////////////////////////////////////////////////// /** Create JMenuBar. */ private JMenuBar getMenu() { JMenu menu = new JMenu("Image"); menu.add(new JMenuItem(new AbstractAction("Prev") { public void actionPerformed(ActionEvent e) { setPrevImage(); }; })); menu.add(new JMenuItem(new AbstractAction("Next") { public void actionPerformed(ActionEvent e) { setNextImage(); }; })); menu.addSeparator(); menu.add(new JMenuItem(new AbstractAction("Exit") { public void actionPerformed(ActionEvent e) { System.exit(0); }; })); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); return menuBar; } ////////////////////////////////////////////////////////////////////////////// /** Set images to round-robin array. */ protected void setFiles(Object[] obj) { iFiles = new RRArray(obj); } ////////////////////////////////////////////////////////////////////////////// /** Set image-files. */ protected void setImages(String[] filenames) throws IOException { Image[] imgArray = new Image[filenames.length]; for (int i=0;i