1 /* 2 * Copyright (C) 2003-2005 SINTEF 3 * Author: Fredrik Vraalsen (fredrik dot vraalsen at sintef dot no) 4 * Webpage: http://coras.sourceforge.net/ 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public License 8 * as published by the Free Software Foundation; either version 2.1 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this program; if not, write to the Free 18 * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 19 * 02111-1307 USA 20 */ 21 package coras.representations; 22 23 import java.awt.Color; 24 import java.awt.Dimension; 25 import java.awt.Graphics; 26 import java.awt.Image; 27 28 import javax.swing.JPanel; 29 30 /*** 31 * @author fvr 32 * 33 * To change the template for this generated type comment go to 34 * Window - Preferences - Java - Code Generation - Code and Comments 35 */ 36 public class ImagePanel extends JPanel { 37 38 private Image image = null; 39 40 public void setImage(Image image) { 41 this.image = image; 42 if (image != null) 43 setPreferredSize(new Dimension(image.getWidth(null), image.getHeight(null))); 44 else 45 setPreferredSize(new Dimension(0, 0)); 46 revalidate(); 47 } 48 49 50 /* (non-Javadoc) 51 * @see java.awt.Component#paint(java.awt.Graphics) 52 */ 53 public void paint(Graphics g) { 54 super.paint(g); 55 if (image != null) { 56 g.drawImage(image, 0, 0, Color.white, null); 57 } 58 } 59 60 }