Search in sources :

Example 26 with Image

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());
}
Also used : Dimensions(org.apache.pivot.wtk.Dimensions) ImageView(org.apache.pivot.wtk.ImageView) Image(org.apache.pivot.wtk.media.Image)

Example 27 with Image

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;
        }
    }
}
Also used : Dimensions(org.apache.pivot.wtk.Dimensions) ImageView(org.apache.pivot.wtk.ImageView) Image(org.apache.pivot.wtk.media.Image)

Example 28 with Image

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);
    }
}
Also used : ImageNode(org.apache.pivot.wtk.text.ImageNode) Image(org.apache.pivot.wtk.media.Image)

Example 29 with Image

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;
}
Also used : ImageNode(org.apache.pivot.wtk.text.ImageNode) Image(org.apache.pivot.wtk.media.Image)

Example 30 with Image

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);
    }
}
Also used : ImageNode(org.apache.pivot.wtk.text.ImageNode) Image(org.apache.pivot.wtk.media.Image)

Aggregations

Image (org.apache.pivot.wtk.media.Image)35 Color (java.awt.Color)8 ImageView (org.apache.pivot.wtk.ImageView)8 Font (java.awt.Font)6 Component (org.apache.pivot.wtk.Component)5 ImageNode (org.apache.pivot.wtk.text.ImageNode)5 Dimensions (org.apache.pivot.wtk.Dimensions)3 Point (org.apache.pivot.wtk.Point)3 BasicStroke (java.awt.BasicStroke)2 Graphics2D (java.awt.Graphics2D)2 IOException (java.io.IOException)2 DragSource (org.apache.pivot.wtk.DragSource)2 DropAction (org.apache.pivot.wtk.DropAction)2 DropTarget (org.apache.pivot.wtk.DropTarget)2 Insets (org.apache.pivot.wtk.Insets)2 LocalManifest (org.apache.pivot.wtk.LocalManifest)2 Manifest (org.apache.pivot.wtk.Manifest)2 AlphaComposite (java.awt.AlphaComposite)1 Composite (java.awt.Composite)1 GradientPaint (java.awt.GradientPaint)1