use of org.apache.pivot.wtk.media.Image in project pivot by apache.
the class ImageViewSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
ImageView imageView = (ImageView) getComponent();
Image image = imageView.getImage();
return (image == null) ? Dimensions.ZERO : new Dimensions(image.getWidth(), image.getHeight());
}
use of org.apache.pivot.wtk.media.Image in project pivot by apache.
the class ImageViewSkin method layout.
@Override
public void layout() {
ImageView imageView = (ImageView) getComponent();
Image image = imageView.getImage();
if (image != null) {
int width = getWidth();
int height = getHeight();
Dimensions imageSize = image.getSize();
if (fill) {
// Scale to fit
if (preserveAspectRatio) {
float aspectRatio = (float) width / (float) height;
float imageAspectRatio = (float) imageSize.width / (float) imageSize.height;
if (aspectRatio > imageAspectRatio) {
imageY = 0;
scaleY = (float) height / (float) imageSize.height;
imageX = (int) (width - imageSize.width * scaleY) / 2;
scaleX = scaleY;
} else {
imageX = 0;
scaleX = (float) width / (float) imageSize.width;
imageY = (int) (height - imageSize.height * scaleX) / 2;
scaleY = scaleX;
}
} else {
imageX = 0;
scaleX = (float) width / (float) imageSize.width;
imageY = 0;
scaleY = (float) height / (float) imageSize.height;
}
} else {
if (horizontalAlignment == HorizontalAlignment.CENTER) {
imageX = (width - imageSize.width) / 2;
} else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
imageX = width - imageSize.width;
} else {
imageX = 0;
}
scaleX = 1.0f;
if (verticalAlignment == VerticalAlignment.CENTER) {
imageY = (height - imageSize.height) / 2;
} else if (verticalAlignment == VerticalAlignment.BOTTOM) {
imageY = height - imageSize.height;
} else {
imageY = 0;
}
scaleY = 1.0f;
}
}
}
use of org.apache.pivot.wtk.media.Image in project pivot by apache.
the class TextPaneSkinImageNodeView method attach.
@Override
protected void attach() {
super.attach();
ImageNode imageNode = (ImageNode) getNode();
imageNode.getImageNodeListeners().add(this);
Image image = imageNode.getImage();
if (image != null) {
image.getImageListeners().add(this);
}
}
use of org.apache.pivot.wtk.media.Image in project pivot by apache.
the class TextPaneSkinImageNodeView method getBaseline.
@Override
public int getBaseline() {
ImageNode imageNode = (ImageNode) getNode();
Image image = imageNode.getImage();
int baseline = -1;
if (image != null) {
baseline = image.getBaseline();
}
return baseline;
}
use of org.apache.pivot.wtk.media.Image in project pivot by apache.
the class TextPaneSkinImageNodeView method paint.
@Override
public void paint(Graphics2D graphics) {
ImageNode imageNode = (ImageNode) getNode();
Image image = imageNode.getImage();
if (image != null) {
image.paint(graphics);
}
}
Aggregations