Back to index

wims  3.65+svn20090927
ImageSelection.java
Go to the documentation of this file.
00001 /*
00002  * Created on 26.10.2005
00003  *
00004  */
00005 package rene.util;
00006 
00007 import java.awt.Image;
00008 import java.awt.datatransfer.DataFlavor;
00009 import java.awt.datatransfer.Transferable;
00010 import java.awt.datatransfer.UnsupportedFlavorException;
00011 import java.io.IOException;
00012 
00018 public class ImageSelection 
00019        implements Transferable 
00020 {
00021 //     the Image object which will be housed by the ImageSelection
00022        private Image image;
00023        
00024        public ImageSelection(Image image) {
00025               this.image = image;
00026        }
00027        
00028 //     Returns the supported flavors of our implementation
00029        public DataFlavor[] getTransferDataFlavors() 
00030        {
00031               return new DataFlavor[] {DataFlavor.imageFlavor};
00032        }
00033        
00034 //     Returns true if flavor is supported
00035        public boolean isDataFlavorSupported(DataFlavor flavor) 
00036        {
00037               return DataFlavor.imageFlavor.equals(flavor);
00038        }
00039        
00040 //     Returns Image object housed by Transferable object
00041        public Object getTransferData(DataFlavor flavor)
00042        throws UnsupportedFlavorException,IOException 
00043        {
00044               if (!DataFlavor.imageFlavor.equals(flavor)) 
00045               {
00046                      throw new UnsupportedFlavorException(flavor);
00047               }
00048               // else return the payload
00049               return image;
00050        }
00051 }
00052 
00053