Search in sources :

Example 6 with Image

use of org.apache.pivot.wtk.media.Image in project pivot by apache.

the class TreeViewNodeRenderer method render.

@Override
public void render(Object node, Path path, int rowIndex, TreeView treeView, boolean expanded, boolean selected, TreeView.NodeCheckState checkState, boolean highlighted, boolean disabled) {
    if (node != null) {
        Image icon = null;
        String text = null;
        if (node instanceof TreeNode) {
            TreeNode treeNode = (TreeNode) node;
            if (expanded && treeNode instanceof TreeBranch) {
                TreeBranch treeBranch = (TreeBranch) treeNode;
                icon = treeBranch.getExpandedIcon();
                if (icon == null) {
                    icon = treeBranch.getIcon();
                }
            } else {
                icon = treeNode.getIcon();
            }
        } else if (node instanceof Image) {
            icon = (Image) node;
        }
        text = toString(node);
        // Update the image view
        imageView.setImage(icon);
        imageView.getStyles().put(Style.opacity, (treeView.isEnabled() && !disabled) ? 1.0f : 0.5f);
        // Update the label
        label.setText(text != null ? text : "");
        if (text == null) {
            label.setVisible(false);
        } else {
            label.setVisible(true);
            Font font = treeView.getStyles().getFont(Style.font);
            label.getStyles().put(Style.font, font);
            Color color;
            if (treeView.isEnabled() && !disabled) {
                if (selected) {
                    if (treeView.isFocused()) {
                        color = treeView.getStyles().getColor(Style.selectionColor);
                    } else {
                        color = treeView.getStyles().getColor(Style.inactiveSelectionColor);
                    }
                } else {
                    color = treeView.getStyles().getColor(Style.color);
                }
            } else {
                color = treeView.getStyles().getColor(Style.disabledColor);
            }
            label.getStyles().put(Style.color, color);
        }
    }
}
Also used : Color(java.awt.Color) Image(org.apache.pivot.wtk.media.Image) Font(java.awt.Font)

Example 7 with Image

use of org.apache.pivot.wtk.media.Image 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 8 with Image

use of org.apache.pivot.wtk.media.Image in project pivot by apache.

the class ImageViewSkin method imageChanged.

// Image view events
@Override
public void imageChanged(ImageView imageView, Image previousImage) {
    if (previousImage != null) {
        previousImage.getImageListeners().remove(imageListener);
    }
    Image image = imageView.getImage();
    if (image != null) {
        image.getImageListeners().add(imageListener);
    }
    invalidateComponent();
}
Also used : Image(org.apache.pivot.wtk.media.Image)

Example 9 with Image

use of org.apache.pivot.wtk.media.Image 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 10 with Image

use of org.apache.pivot.wtk.media.Image 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

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