resized.setSize(height);
}
return resized;
} else if(graphic instanceof IconStyle2D) {
IconStyle2D iconStyle = (IconStyle2D) graphic;
IconStyle2D resized = (IconStyle2D) iconStyle.clone();
final Icon icon = iconStyle.getIcon();
AffineTransform at;
if(mode == GraphicResize.PROPORTIONAL) {
double factor;
if(width > height) {
factor = width / icon.getIconWidth();
} else {
factor = height / icon.getIconHeight();
}
at = AffineTransform.getScaleInstance(factor, factor);
} else {
at = AffineTransform.getScaleInstance(width / icon.getIconWidth(),
height / icon.getIconHeight());
}
resized.setIcon(new TransformedIcon(icon, at));
return resized;
} else if(graphic instanceof GraphicStyle2D) {
GraphicStyle2D gstyle = (GraphicStyle2D) graphic;
GraphicStyle2D resized = (GraphicStyle2D) graphic.clone();
BufferedImage image = gstyle.getImage();
AffineTransform at;
if(mode == GraphicResize.PROPORTIONAL) {
double factor;
if(width > height) {
factor = width / image.getWidth();
} else {
factor = height / image.getHeight();
}
at = AffineTransform.getScaleInstance(factor, factor);
} else {
at = AffineTransform.getScaleInstance(width / image.getWidth(),
height / image.getHeight());
}
AffineTransformOp ato = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
image = ato.filter(image, null);
resized.setImage(image);
return resized;
} else {
return graphic;
}
}