Subversion Repositories general

Compare Revisions

No changes between revisions

Ignore whitespace Rev 650 → Rev 651

/sun/xmleditor/trunk/src/plugins/regionEditorPlugin/ImagePanel.java
0,0 → 1,159
/*
* This file contains the ImagePanel class.
*
* Coded by: Group 5, software practice summer 2003
* University of Bielefeld, Germany
*
* @version $Revision: 1.6 $
*
* Last modification: $Date: 2003/07/15 22:23:20 $
* $Id: ImagePanel.java,v 1.6 2003/07/15 22:23:20 ioklasse Exp $
*/
 
package src.plugins.regionEditorPlugin;
 
import java.util.List;
 
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.Graphics;
import java.awt.Image;
 
import javax.swing.JPanel;
 
/**
* Image panel shows any images.
*
* @author Yulia Klassen, Viktoriya Zudova
*/
class ImagePanel extends JPanel
{
/** dx-shift of image according to the left top corner of plugin panel */
private int dx;
/** dy-shift of image according to the left top corner of plugin panel */
private int dy;
/** width of the image */
private int imageWidth;
/** height of the image */
private int imageHeight;
 
private double coef;
 
/** current image */
private Image image;
 
private List rects;
 
private Rectangle selectedRect;
 
/** constructor invokes JPanel to create all elements for options dialog */
public ImagePanel(List rects)
{
super(true);
this.rects = rects;
}
 
/** draws the image */
public void paintComponent(Graphics g)
{
int w = getWidth();
int h = getHeight();
 
// fill background
g.setColor(getBackground());
g.fillRect(0, 0, w, h);
 
if(image != null)
{
// calc size and position of the image
int iw = image.getWidth(null);
int ih = image.getHeight(null);
double kx = (double)iw/w;
double ky = (double)ih/h;
 
coef = Math.max(kx, ky);
 
if(coef < 1) {
coef = 1;
}
else {
iw = (int)(iw/coef);
ih = (int)(ih/coef);
}
 
dx = (w-iw)/2;
dy = (h-ih)/2;
imageWidth = iw;
imageHeight = ih;
 
// draw the image
g.drawImage(image, dx, dy, iw, ih, null);
 
// draw rectanges
g.setColor(Color.black);
g.setXORMode(Color.white);
for(int i = 0; i < rects.size(); i++) {
Rectangle rect = (Rectangle)rects.get(i);
 
if(rect != selectedRect) // the selected one will be drawn later
g.drawRect(
(int)(rect.getX() / coef) + dx,
(int)(rect.getY() / coef) + dy,
(int)(rect.getWidth() / coef),
(int)(rect.getHeight() / coef));
}
 
// draw the selected rect
if(selectedRect != null) {
g.setColor(Color.red);
g.drawRect(
(int)(selectedRect.getX() / coef) + dx,
(int)(selectedRect.getY() / coef) + dy,
(int)(selectedRect.getWidth() / coef),
(int)(selectedRect.getHeight() / coef));
}
}
}
 
/** sets the image */
public void setImage(Image image)
{
this.image = image;
repaint();
}
 
public double getCoef()
{
return coef;
}
 
/** returns dx-shift of image according to the left top corner of plugin panel */
public int getDx()
{
return dx;
}
 
/** returns dy-shift of image according to the left top corner of plugin panel */
public int getDy()
{
return dy;
}
 
/** returns width of the image */
public int getImageWidth()
{
return imageWidth;
}
 
/** returns height of the image */
public int getImageHeight()
{
return imageHeight;
}
 
public void setSelectedRect(Rectangle rect)
{
this.selectedRect = rect;
}
 
}
Property changes:
Added: svn:keywords
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
\ No newline at end of property