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