Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 660 → Rev 661

/sun/xmleditor/trunk/src/plugins/regionEditorPlugin/ImagePanel.java
4,10 → 4,10
* Coded by: Group 5, software practice summer 2003
* University of Bielefeld, Germany
*
* @version $Revision: 1.6 $
* @version $Revision: 1.1 $
*
* Last modification: $Date: 2003/07/15 22:23:20 $
* $Id: ImagePanel.java,v 1.6 2003/07/15 22:23:20 ioklasse Exp $
* Last modification: $Date: 2003/07/20 19:47:36 $
* $Id: ImagePanel.java,v 1.1 2003/07/20 19:47:36 ioklasse Exp $
*/
 
package src.plugins.regionEditorPlugin;
22,138 → 22,166
import javax.swing.JPanel;
 
/**
* Image panel shows any images.
* Image panel shows any image.
*
* @author Yulia Klassen, Viktoriya Zudova
* @author Yulia Klassen
* @author Viktoriya Zudova
*
* @version $Revision: 1.45 $ Last modification: $Date: 2003/07/18 13:55:25 $
*/
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;
class ImagePanel extends JPanel {
 
private double coef;
/* The current image. */
private Image image;
 
/** current image */
private Image image;
/* The dx-shift of an image in relation to the left top corner of plugin panel. */
private int dx;
/* The dy-shift of an image in realtion to the left top corner of plugin panel. */
private int dy;
/* The width of the image. */
private int imageWidth;
/* The height of the image. */
private int imageHeight;
 
private List rects;
// TODO comments
private double coef;
private List rects;
private Rectangle selectedRect;
 
private Rectangle selectedRect;
/**
* The class constructor invokes <code>JPanel</code> to create
* all elements for the options dialog.
*
* @see javax.swing.JPanel
*/
public ImagePanel(List rects) {
super(true);
this.rects = rects;
}
 
/** constructor invokes JPanel to create all elements for options dialog */
public ImagePanel(List rects)
{
super(true);
this.rects = rects;
}
/**
* <code>paintComponent</code> draws the image.
*
* @see javax.swing.JComponent#paintComponent
*/
public void paintComponent(Graphics g) {
int w = getWidth();
int h = getHeight();
 
/** draws the image */
public void paintComponent(Graphics g)
{
int w = getWidth();
int h = getHeight();
/* Fill the background. */
g.setColor(getBackground());
g.fillRect(0, 0, w, h);
 
// fill background
g.setColor(getBackground());
g.fillRect(0, 0, w, h);
/* If there is an image ... */
if(image != null) {
/* Calculate the 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;
 
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);
 
coef = Math.max(kx, ky);
if(coef < 1) {
coef = 1;
} else {
iw = (int)(iw/coef);
ih = (int)(ih/coef);
}
 
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;
 
dx = (w-iw)/2;
dy = (h-ih)/2;
imageWidth = iw;
imageHeight = ih;
/* Draw the image. */
g.drawImage(image, dx, dy, iw, ih, null);
 
// 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);
 
// 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));
}
 
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 rectangle. */
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));
}
}
}
 
// 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 currently visible image to the image given as parameter.
*
* @param image: The image to display.
*/
public void setImage(Image image) {
this.image = image;
repaint();
}
}
 
/** sets the image */
public void setImage(Image image)
{
this.image = image;
repaint();
}
// TODO comments
public double getCoef() {
return coef;
}
 
public double getCoef()
{
return coef;
}
/**
* Returns the dx-shift of an image according to the left top
* corner of the plugin panel.
*
* @return The difference on the x-axis.
*/
public int getDx() {
return dx;
}
 
/** returns dx-shift of image according to the left top corner of plugin panel */
public int getDx()
{
return dx;
}
/**
* Returns the dy-shift of an image according to the left top
* corner of the plugin panel.
*
* @return The difference on the y-axis.
*/
public int getDy() {
return dy;
}
 
/** returns dy-shift of image according to the left top corner of plugin panel */
public int getDy()
{
return dy;
}
/**
* Returns the width of the current image.
*
* @return The width of the current image.
*/
public int getImageWidth() {
return imageWidth;
}
 
/** returns width of the image */
public int getImageWidth()
{
return imageWidth;
}
/**
* Returns the height of the current image.
*
* @return The height of the current image.
*/
public int getImageHeight() {
return imageHeight;
}
 
/** returns height of the image */
public int getImageHeight()
{
return imageHeight;
}
 
public void setSelectedRect(Rectangle rect)
{
this.selectedRect = rect;
}
 
// TODO comments
public void setSelectedRect(Rectangle rect) {
this.selectedRect = rect;
}
}