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);
}
}
}
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();
}
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();
}
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();
}
}
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();
}
Aggregations