edu.northwestern.at.utils.swing
Class ImageTransferable
java.lang.Object
javax.swing.TransferHandler
edu.northwestern.at.utils.swing.ImageTransferable
- All Implemented Interfaces:
- java.io.Serializable
public class ImageTransferable
- extends javax.swing.TransferHandler
Transferable for image files.
Handles the default file types recognized by Java (.gif, .jpeg, .png).
The source and destination fields must be JLabels or subclasses thereof.
- See Also:
- Serialized Form
Nested classes/interfaces inherited from class javax.swing.TransferHandler |
javax.swing.TransferHandler.DropLocation, javax.swing.TransferHandler.TransferSupport |
Fields inherited from class javax.swing.TransferHandler |
COPY, COPY_OR_MOVE, LINK, MOVE, NONE |
Method Summary |
boolean |
canImport(javax.swing.JComponent component,
java.awt.datatransfer.DataFlavor[] flavor)
Check if component can import image. |
java.awt.datatransfer.Transferable |
createTransferable(javax.swing.JComponent component)
Create image transferable. |
int |
getSourceActions(javax.swing.JComponent c)
Return COPY action for a component. |
boolean |
importData(javax.swing.JComponent component,
java.awt.datatransfer.Transferable transferable)
Import image data from a transferable. |
Methods inherited from class javax.swing.TransferHandler |
canImport, exportAsDrag, exportDone, exportToClipboard, getCopyAction, getCutAction, getPasteAction, getVisualRepresentation, importData |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ImageTransferable
public ImageTransferable()
getSourceActions
public int getSourceActions(javax.swing.JComponent c)
- Return COPY action for a component.
- Overrides:
getSourceActions
in class javax.swing.TransferHandler
- Parameters:
c
- The component.
- Returns:
- The COPY action.
canImport
public boolean canImport(javax.swing.JComponent component,
java.awt.datatransfer.DataFlavor[] flavor)
- Check if component can import image.
- Overrides:
canImport
in class javax.swing.TransferHandler
- Parameters:
component
- The component to check.flavor
- Array of transferable flavors the component accepts.
- Returns:
- true if component accepts images, false otherwise.
createTransferable
public java.awt.datatransfer.Transferable createTransferable(javax.swing.JComponent component)
- Create image transferable.
- Overrides:
createTransferable
in class javax.swing.TransferHandler
- Parameters:
component
- The component for which to create the transferable.
- Returns:
- The image transferable, null if the component
cannot accept images.
importData
public boolean importData(javax.swing.JComponent component,
java.awt.datatransfer.Transferable transferable)
- Import image data from a transferable.
- Overrides:
importData
in class javax.swing.TransferHandler
- Parameters:
component
- The component to which to import data.transferable
- The transferable containing the data to import.
- Returns:
- true if the data is successfully imported.