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("backgroundColor", "#f0e68c");
}
return dropAction;
}
@Override
public void dragExit(Component component) {
component.getStyles().put("backgroundColor", null);
}
@Override
public DropAction dragMove(Component component, Manifest dragContent,
int supportedDropActions, int x, int y, DropAction userDropAction) {
ImageView imageView = (ImageView)component;
return (imageView.getImage() == null
&& dragContent.containsImage() ? DropAction.MOVE : null);
}
@Override
public DropAction userDropActionChange(Component component, Manifest dragContent,
int supportedDropActions, int x, int y, DropAction userDropAction) {
ImageView imageView = (ImageView)component;
return (imageView.getImage() == null
&& dragContent.containsImage() ? DropAction.MOVE : null);
}
@Override
public DropAction drop(Component component, Manifest dragContent,
int supportedDropActions, int x, int y, DropAction userDropAction) {
DropAction dropAction = null;
ImageView imageView = (ImageView)component;
if (imageView.getImage() == null
&& dragContent.containsImage()) {
try {
imageView.setImage(dragContent.getImage());
dropAction = DropAction.MOVE;
} catch(IOException exception) {
System.err.println(exception);
}
}