blob: e2542c3c693bda0968997a3e0f79a4dfa7c6ec57 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
/**
* <p>�berschrift: </p>
*
* <p>Beschreibung: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Organisation: </p>
*
* @author Andrea Spirka, sven Eisenhauer
* @version 1.0
*/
import java.awt.*;
import java.io.File;
import javax.swing.*;
class ViewComponent extends JComponent
{
transient private Image image;
/* (non-Javadoc)
* @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
*/
protected void paintComponent( Graphics g )
{
if ( image != null )
g.drawImage( image, 10, 10, this );
centerImage(g,this,image);
}
public ViewComponent(){
}
/**
* @param file
*/
public void setImage( File file)
{
image = Toolkit.getDefaultToolkit().getImage( file.getAbsolutePath() );
if ( image != null )
{
repaint();
}
}
/**
* @param g
* @param component
* @param image
*/
public static void centerImage( Graphics g, Component component, Image image )
{
g.setColor( component.getBackground() );
Dimension d = component.getSize();
g.fillRect( 0, 0, d.width, d.height );
g.drawImage( image,
( d.width - image.getWidth( null ) ) / 2,
( d.height - image.getHeight( null ) ) / 2,
null );
}
}
|