4,10 → 4,10 |
* Coded by: Group 5, software practice summer 2003 |
* University of Bielefeld, Germany |
* |
* @version $Revision: 1.1 $ |
* @version $Revision: 1.2 $ |
* |
* Last modification: $Date: 2003/07/20 19:47:36 $ |
* $Id: ImagePanel.java,v 1.1 2003/07/20 19:47:36 ioklasse Exp $ |
* Last modification: $Date: 2003/07/21 11:18:22 $ |
* $Id: ImagePanel.java,v 1.2 2003/07/21 11:18:22 smcsporr Exp $ |
*/ |
|
package src.plugins.regionEditorPlugin; |
26,8 → 26,8 |
* |
* @author Yulia Klassen |
* @author Viktoriya Zudova |
* |
* @version $Revision: 1.45 $ Last modification: $Date: 2003/07/18 13:55:25 $ |
* |
* @version $Revision: 1.2 $ Last modification: $Date: 2003/07/21 11:18:22 $ |
*/ |
class ImagePanel extends JPanel { |
|
36,35 → 36,35 |
|
/* 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; |
|
// TODO comments |
private double coef; |
private List rects; |
private Rectangle selectedRect; |
private List regions; |
private Region selectedRegion; |
|
/** |
* The class constructor invokes <code>JPanel</code> to create |
* all elements for the options dialog. |
* |
* |
* @see javax.swing.JPanel |
*/ |
public ImagePanel(List rects) { |
public ImagePanel(List regions) { |
super(true); |
this.rects = rects; |
this.regions = regions; |
} |
|
/** |
/** |
* <code>paintComponent</code> draws the image. |
* |
* |
* @see javax.swing.JComponent#paintComponent |
*/ |
public void paintComponent(Graphics g) { |
77,7 → 77,7 |
|
/* 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); |
86,50 → 86,54 |
|
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 regions. */ |
g.setColor(Color.black); |
g.setXORMode(Color.white); |
for(int i = 0; i < regions.size(); i++) { |
Region region = (Region)regions.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(region != selectedRegion){// the selected one will be drawn later |
Rectangle rect = region.getRect(); |
|
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) { |
if(selectedRegion != null) { |
Rectangle rect = selectedRegion.getRect(); |
g.setColor(Color.red); |
g.drawRect( |
(int)(selectedRect.getX() / coef) + dx, |
(int)(selectedRect.getY() / coef) + dy, |
(int)(selectedRect.getWidth() / coef), |
(int)(selectedRect.getHeight() / coef)); |
(int)(rect.getX() / coef) + dx, |
(int)(rect.getY() / coef) + dy, |
(int)(rect.getWidth() / coef), |
(int)(rect.getHeight() / coef)); |
} |
} |
} |
|
/** |
/** |
* Sets the currently visible image to the image given as parameter. |
* |
* |
* @param image: The image to display. |
*/ |
public void setImage(Image image) { |
142,20 → 146,20 |
return coef; |
} |
|
/** |
* Returns the dx-shift of an image according to the left top |
/** |
* Returns the dx-shift of an image according to the left top |
* corner of the plugin panel. |
* |
* @return The difference on the x-axis. |
* |
* @return The difference on the x-axis. |
*/ |
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() { |
164,7 → 168,7 |
|
/** |
* Returns the width of the current image. |
* |
* |
* @return The width of the current image. |
*/ |
public int getImageWidth() { |
171,10 → 175,10 |
return imageWidth; |
} |
|
/** |
/** |
* Returns the height of the current image. |
* |
* @return The height of the current image. |
* @return The height of the current image. |
*/ |
public int getImageHeight() { |
return imageHeight; |
181,7 → 185,7 |
} |
|
// TODO comments |
public void setSelectedRect(Rectangle rect) { |
this.selectedRect = rect; |
public void setSelectedRegion(Region region) { |
this.selectedRegion = region; |
} |
} |