Search in sources :

Example 1 with ImageView

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

the class Pivot964Pivot method startup.

@Override
public void startup(Display display, Map<String, String> properties) {
    // force dimensions for host frame
    display.getHostWindow().setSize(1028, 600);
    window = new Window();
    prepareSVG();
    final ImageView image = new ImageView(new Drawing(diagram));
    BoxPane bp = new BoxPane();
    TablePane tp = new TablePane();
    setStyles(tp, "{padding: 4}");
    TablePane.Column c1 = new TablePane.Column(-1);
    TablePane.Column c2 = new TablePane.Column(-1);
    tp.getColumns().add(c1);
    tp.getColumns().add(c2);
    TablePane.Row r1 = new TablePane.Row(-1);
    TablePane.Row r2 = new TablePane.Row(-1);
    TablePane.Row r3 = new TablePane.Row(-1);
    PushButton pb1 = new PushButton("Visible");
    PushButton pb2 = new PushButton("Invisible (bug)");
    r1.add(pb1);
    r1.add(pb2);
    final Spinner sp1 = new Spinner(new ListAdapter<>(spinnerData));
    sp1.setPreferredWidth(80);
    sp1.setSelectedIndex(0);
    final Spinner sp2 = new Spinner(new ListAdapter<>(spinnerData));
    sp2.setPreferredWidth(80);
    sp2.setSelectedIndex(0);
    BoxPane bp1 = new BoxPane();
    setStyles(bp1, "{verticalAlignment:'center', padding: 4, spacing: 2}");
    bp1.add(new Label("X:"));
    bp1.add(sp1);
    r2.add(bp1);
    BoxPane bp2 = new BoxPane();
    setStyles(bp2, "{verticalAlignment:'center', padding: 4, spacing: 2}");
    bp2.add(new Label("Y:"));
    bp2.add(sp2);
    r2.add(bp2);
    tp.getRows().add(r1);
    tp.getRows().add(r2);
    r3.add(new Label("   Max X=507"));
    r3.add(new Label("   Max Y=269"));
    tp.getRows().add(r3);
    bp.add(image);
    bp.add(tp);
    pb1.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button arg0) {
            try {
                root.setAttribute("viewBox", AnimationElement.AT_XML, "0 0 2368 1652");
                root.updateTime(0f);
                image.repaint();
            } catch (SVGElementException e) {
                e.printStackTrace();
            } catch (SVGException e) {
                e.printStackTrace();
            }
        }
    });
    pb2.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button arg0) {
            try {
                String xOffset = (String) sp1.getSelectedItem();
                String yOffset = (String) sp2.getSelectedItem();
                String viewBox = String.format("%1$s %2$s 2368 1652", xOffset, yOffset);
                root.setAttribute("viewBox", AnimationElement.AT_XML, viewBox);
                root.updateTime(0f);
                image.repaint();
            } catch (SVGElementException e) {
                e.printStackTrace();
            } catch (SVGException e) {
                e.printStackTrace();
            }
        }
    });
    window.setContent(bp);
    window.setMaximized(true);
    window.open(display);
}
Also used : Window(org.apache.pivot.wtk.Window) Drawing(org.apache.pivot.wtk.media.Drawing) Spinner(org.apache.pivot.wtk.Spinner) SVGException(com.kitfox.svg.SVGException) Label(org.apache.pivot.wtk.Label) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) BoxPane(org.apache.pivot.wtk.BoxPane) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) ImageView(org.apache.pivot.wtk.ImageView) SVGElementException(com.kitfox.svg.SVGElementException) PushButton(org.apache.pivot.wtk.PushButton) TablePane(org.apache.pivot.wtk.TablePane)

Example 2 with ImageView

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

the class BXMLExplorerDocument method setComponentIconOnTreeNode.

private static void setComponentIconOnTreeNode(TreeNode treeNode, Object comp) {
    String resource = null;
    if (comp instanceof Label) {
        resource = "label.png";
    }
    if (comp instanceof ImageView) {
        resource = "/org/apache/pivot/tutorials/IMG_0725_2.jpg";
    }
    if (comp instanceof PushButton) {
        resource = "pushbutton.png";
    }
    if (comp instanceof RadioButton) {
        resource = "radiobutton.png";
    }
    if (comp instanceof Checkbox) {
        resource = "checkbox.png";
    }
    if (comp instanceof LinkButton) {
        resource = "linkbutton.png";
    }
    if (comp instanceof TablePane) {
        resource = "tablepane.png";
    }
    if (resource != null) {
        URL url = BXMLExplorerDocument.class.getResource(resource);
        if (url == null) {
            throw new IllegalStateException("could not load resource " + resource);
        }
        treeNode.setIcon(url);
    }
}
Also used : Checkbox(org.apache.pivot.wtk.Checkbox) Label(org.apache.pivot.wtk.Label) ImageView(org.apache.pivot.wtk.ImageView) RadioButton(org.apache.pivot.wtk.RadioButton) PushButton(org.apache.pivot.wtk.PushButton) LinkButton(org.apache.pivot.wtk.LinkButton) URL(java.net.URL) TablePane(org.apache.pivot.wtk.TablePane)

Example 3 with ImageView

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

the class ImageViewSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    ImageView imageView = (ImageView) getComponent();
    Image image = imageView.getImage();
    return (image == null) ? 0 : image.getWidth();
}
Also used : ImageView(org.apache.pivot.wtk.ImageView) Image(org.apache.pivot.wtk.media.Image)

Example 4 with ImageView

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

the class ImageViewSkin method paint.

@Override
public void paint(Graphics2D graphics) {
    ImageView imageView = (ImageView) getComponent();
    Image image = imageView.getImage();
    int width = getWidth();
    int height = getHeight();
    if (backgroundColor != null) {
        graphics.setPaint(backgroundColor);
        graphics.fillRect(0, 0, width, height);
    }
    if (image != null) {
        Graphics2D imageGraphics = (Graphics2D) graphics.create();
        imageGraphics.translate(imageX, imageY);
        imageGraphics.scale(scaleX, scaleY);
        // Apply an alpha composite if the opacity value is less than
        // the current alpha
        float alpha = 1.0f;
        Composite composite = imageGraphics.getComposite();
        if (composite instanceof AlphaComposite) {
            AlphaComposite alphaComposite = (AlphaComposite) composite;
            alpha = alphaComposite.getAlpha();
        }
        if (opacity < alpha) {
            imageGraphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));
        }
        image.paint(imageGraphics);
        imageGraphics.dispose();
    }
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) AlphaComposite(java.awt.AlphaComposite) ImageView(org.apache.pivot.wtk.ImageView) Image(org.apache.pivot.wtk.media.Image) Graphics2D(java.awt.Graphics2D)

Example 5 with ImageView

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

the class ImageViewSkin method getPreferredHeight.

@Override
public int getPreferredHeight(int width) {
    ImageView imageView = (ImageView) getComponent();
    Image image = imageView.getImage();
    return (image == null) ? 0 : image.getHeight();
}
Also used : 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