Search in sources :

Example 6 with ImageView

use of org.apache.pivot.wtk.ImageView in project pivot by apache.

the class ImageViewSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    ImageView imageView = (ImageView) component;
    imageView.getImageViewListeners().add(this);
    Image image = imageView.getImage();
    if (image != null) {
        image.getImageListeners().add(imageListener);
    }
}
Also used : ImageView(org.apache.pivot.wtk.ImageView) Image(org.apache.pivot.wtk.media.Image)

Example 7 with ImageView

use of org.apache.pivot.wtk.ImageView in project pivot by apache.

the class DragDropTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    frame1.setTitle("Frame 1");
    frame1.setPreferredSize(160, 120);
    frame1.getStyles().put(Style.resizable, false);
    DragSource imageDragSource = new DragSource() {

        private Image image = null;

        private Point offset = null;

        private LocalManifest content = null;

        @Override
        public boolean beginDrag(Component component, int x, int y) {
            ImageView imageView = (ImageView) component;
            image = imageView.getImage();
            if (image != null) {
                imageView.setImage((Image) null);
                content = new LocalManifest();
                content.putImage(image);
                offset = new Point(x - (imageView.getWidth() - image.getWidth()) / 2, y - (imageView.getHeight() - image.getHeight()) / 2);
            }
            return (image != null);
        }

        @Override
        public void endDrag(Component component, DropAction dropAction) {
            if (dropAction == null) {
                ImageView imageView = (ImageView) component;
                imageView.setImage(image);
            }
            image = null;
            offset = null;
            content = null;
        }

        @Override
        public boolean isNative() {
            return false;
        }

        @Override
        public LocalManifest getContent() {
            return content;
        }

        @Override
        public Visual getRepresentation() {
            return image;
        }

        @Override
        public Point getOffset() {
            return offset;
        }

        @Override
        public int getSupportedDropActions() {
            return DropAction.MOVE.getMask();
        }
    };
    DropTarget imageDropTarget = new DropTarget() {

        @Override
        public DropAction dragEnter(Component component, Manifest dragContent, int supportedDropActions, DropAction userDropAction) {
            DropAction dropAction = null;
            ImageView imageView = (ImageView) component;
            if (imageView.getImage() == null && dragContent.containsImage() && DropAction.MOVE.isSelected(supportedDropActions)) {
                dropAction = DropAction.MOVE;
                component.getStyles().put(Style.backgroundColor, IMAGE_VIEW_DROP_HIGHLIGHT_COLOR);
            }
            return dropAction;
        }

        @Override
        public void dragExit(Component component) {
            component.getStyles().put(Style.backgroundColor, IMAGE_VIEW_BACKGROUND_COLOR);
        }

        @Override
        public DropAction dragMove(Component component, Manifest dragContent, int supportedDropActions, int x, int y, DropAction userDropAction) {
            return (dragContent.containsImage() ? DropAction.MOVE : null);
        }

        @Override
        public DropAction userDropActionChange(Component component, Manifest dragContent, int supportedDropActions, int x, int y, DropAction userDropAction) {
            return (dragContent.containsImage() ? DropAction.MOVE : null);
        }

        @Override
        public DropAction drop(Component component, Manifest dragContent, int supportedDropActions, int x, int y, DropAction userDropAction) {
            DropAction dropAction = null;
            if (dragContent.containsImage()) {
                ImageView imageView = (ImageView) component;
                try {
                    imageView.setImage(dragContent.getImage());
                    dropAction = DropAction.MOVE;
                } catch (IOException exception) {
                    System.err.println(exception);
                }
            }
            dragExit(component);
            return dropAction;
        }
    };
    ImageView imageView1 = new ImageView();
    imageView1.setImage(Image.load(getClass().getResource("go-home.png")));
    imageView1.getStyles().put(Style.backgroundColor, IMAGE_VIEW_BACKGROUND_COLOR);
    imageView1.setDragSource(imageDragSource);
    imageView1.setDropTarget(imageDropTarget);
    frame1.setContent(imageView1);
    frame1.open(display);
    frame2.setTitle("Frame 2");
    frame2.setPreferredSize(160, 120);
    frame2.setLocation(180, 0);
    ImageView imageView2 = new ImageView();
    imageView2.getStyles().put(Style.backgroundColor, IMAGE_VIEW_BACKGROUND_COLOR);
    imageView2.setDragSource(imageDragSource);
    imageView2.setDropTarget(imageDropTarget);
    frame2.setContent(imageView2);
    frame2.open(display);
}
Also used : DropAction(org.apache.pivot.wtk.DropAction) DragSource(org.apache.pivot.wtk.DragSource) Point(org.apache.pivot.wtk.Point) ImageView(org.apache.pivot.wtk.ImageView) DropTarget(org.apache.pivot.wtk.DropTarget) IOException(java.io.IOException) Image(org.apache.pivot.wtk.media.Image) Component(org.apache.pivot.wtk.Component) LocalManifest(org.apache.pivot.wtk.LocalManifest) Manifest(org.apache.pivot.wtk.Manifest) LocalManifest(org.apache.pivot.wtk.LocalManifest)

Example 8 with ImageView

use of org.apache.pivot.wtk.ImageView in project pivot by apache.

the class PanoramaTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    frame1 = new Frame();
    frame1.setTitle("Panorama Test 1");
    Panorama panorama = new Panorama();
    frame1.setContent(panorama);
    frame1.setPreferredSize(240, 320);
    ImageView imageView = new ImageView();
    imageView.setImage(getClass().getResource("IMG_0767_2.jpg"));
    panorama.setView(imageView);
    frame1.open(display);
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    frame2 = new Frame((Component) bxmlSerializer.readObject(getClass().getResource("panorama_test.bxml")));
    frame2.setTitle("Panorama Test 2");
    frame2.setPreferredSize(480, 360);
    frame2.open(display);
}
Also used : Frame(org.apache.pivot.wtk.Frame) Panorama(org.apache.pivot.wtk.Panorama) ImageView(org.apache.pivot.wtk.ImageView) Component(org.apache.pivot.wtk.Component) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 9 with ImageView

use of org.apache.pivot.wtk.ImageView in project pivot by apache.

the class ImageViewSkin method getBaseline.

@Override
public int getBaseline(int width, int height) {
    ImageView imageView = (ImageView) getComponent();
    Image image = imageView.getImage();
    int baseline = -1;
    if (image != null) {
        baseline = image.getBaseline();
        if (baseline != -1) {
            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) {
                        baseline *= (float) height / (float) imageSize.height;
                    } else {
                        float scaleYLocal = (float) width / (float) imageSize.width;
                        baseline *= scaleYLocal;
                        baseline += (int) (height - imageSize.height * scaleYLocal) / 2;
                    }
                } else {
                    baseline *= (float) height / (float) imageSize.height;
                }
            } else {
                if (verticalAlignment == VerticalAlignment.CENTER) {
                    baseline += (height - imageSize.height) / 2;
                } else if (verticalAlignment == VerticalAlignment.BOTTOM) {
                    baseline += height - imageSize.height;
                }
            }
        }
    }
    return baseline;
}
Also used : Dimensions(org.apache.pivot.wtk.Dimensions) ImageView(org.apache.pivot.wtk.ImageView) Image(org.apache.pivot.wtk.media.Image)

Example 10 with ImageView

use of org.apache.pivot.wtk.ImageView 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)

Aggregations

ImageView (org.apache.pivot.wtk.ImageView)11 Image (org.apache.pivot.wtk.media.Image)8 Dimensions (org.apache.pivot.wtk.Dimensions)3 Component (org.apache.pivot.wtk.Component)2 Label (org.apache.pivot.wtk.Label)2 PushButton (org.apache.pivot.wtk.PushButton)2 TablePane (org.apache.pivot.wtk.TablePane)2 SVGElementException (com.kitfox.svg.SVGElementException)1 SVGException (com.kitfox.svg.SVGException)1 AlphaComposite (java.awt.AlphaComposite)1 Composite (java.awt.Composite)1 Graphics2D (java.awt.Graphics2D)1 IOException (java.io.IOException)1 URL (java.net.URL)1 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)1 BoxPane (org.apache.pivot.wtk.BoxPane)1 Button (org.apache.pivot.wtk.Button)1 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)1 Checkbox (org.apache.pivot.wtk.Checkbox)1 DragSource (org.apache.pivot.wtk.DragSource)1