artoflife pre0.1.0-dev

org.artoflife.gui.population
Class PopulationViewTransferHandler

java.lang.Object
  |
  +--javax.swing.TransferHandler
        |
        +--org.artoflife.gui.population.PopulationViewTransferHandler
All Implemented Interfaces:
java.io.Serializable

public class PopulationViewTransferHandler
extends javax.swing.TransferHandler

Handles transfer of Individuals from a PopulationView for DnD and clipboard operations. Creates PaintableIndividualTransferables only for Individuals with a org.artoflife.gp.paintable.PaintablePhenotype.

Author:
Steve Meyfroidt
See Also:
Serialized Form
To do:
nicer error handling for incompatible genoypes

Field Summary
 
Fields inherited from class javax.swing.TransferHandler
COPY, COPY_OR_MOVE, MOVE, NONE
 
Constructor Summary
PopulationViewTransferHandler()
           
 
Method Summary
 boolean canImport(javax.swing.JComponent comp, java.awt.datatransfer.DataFlavor[] transferFlavors)
          A PopulationView can import two flavors: PaintableIndividualTransferable.SERIALISED_INDIVIDUAL_FLAVOR PaintableIndividualTransferable.INDIVIDUAL_FILE_FLAVOR
protected  java.awt.datatransfer.Transferable createTransferable(javax.swing.JComponent c)
           
protected  void exportDone(javax.swing.JComponent source, java.awt.datatransfer.Transferable data, int action)
          After a drop has been completed (or an export done, which is overkill since this includes clipboard operations), clear the per-VM drag state held in PopulationView.
 int getSourceActions(javax.swing.JComponent c)
           
 javax.swing.Icon getVisualRepresentation(java.awt.datatransfer.Transferable t)
           
 boolean importData(javax.swing.JComponent comp, java.awt.datatransfer.Transferable t)
          Called by the default javax.swing.TransferHandler.DropHandler but we install a custom PopulationViewDropTargetListener that calls importData(JComponent, Transferable, Point) instead, so this method will fail if called (assertion failure).
 boolean importData(javax.swing.JComponent comp, java.awt.datatransfer.Transferable t, java.awt.Point location)
          An alternative to the usual importData(JComponent, Transferable) called by the default DropHandler, but not when a PopulationView uses one of these TransferHandlers to handle DnD.
 
Methods inherited from class javax.swing.TransferHandler
exportAsDrag, exportToClipboard, getCopyAction, getCutAction, getPasteAction
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PopulationViewTransferHandler

public PopulationViewTransferHandler()
Method Detail

canImport

public boolean canImport(javax.swing.JComponent comp,
                         java.awt.datatransfer.DataFlavor[] transferFlavors)
A PopulationView can import two flavors:

Overrides:
canImport in class javax.swing.TransferHandler
Parameters:
comp - must be a PopulationView, else assertion failure
See Also:
TransferHandler.canImport(JComponent, DataFlavor[])

createTransferable

protected java.awt.datatransfer.Transferable createTransferable(javax.swing.JComponent c)
Overrides:
createTransferable in class javax.swing.TransferHandler
Parameters:
c - must be a PopulationView, else assertion failure
Returns:
a org.artoflife.gui.population.PaintableIndividualTransferable for the currently selected Individual which must not be null
See Also:
TransferHandler.createTransferable(JComponent)

exportDone

protected void exportDone(javax.swing.JComponent source,
                          java.awt.datatransfer.Transferable data,
                          int action)
After a drop has been completed (or an export done, which is overkill since this includes clipboard operations), clear the per-VM drag state held in PopulationView. A hack to overcome Sun's DnD impl.

Overrides:
exportDone in class javax.swing.TransferHandler
See Also:
TransferHandler.exportDone(JComponent, Transferable, int)

getSourceActions

public int getSourceActions(javax.swing.JComponent c)
Overrides:
getSourceActions in class javax.swing.TransferHandler
Returns:
DnDConstants.ACTION_COPY_OR_MOVE
See Also:
TransferHandler.getSourceActions(JComponent)

getVisualRepresentation

public javax.swing.Icon getVisualRepresentation(java.awt.datatransfer.Transferable t)
Overrides:
getVisualRepresentation in class javax.swing.TransferHandler
Returns:
an Icon fetched from the PaintableIndividualTransferable (there ought to be a cleaner way of doing this though)
See Also:
TransferHandler.getVisualRepresentation(Transferable)

importData

public boolean importData(javax.swing.JComponent comp,
                          java.awt.datatransfer.Transferable t)
Called by the default javax.swing.TransferHandler.DropHandler but we install a custom PopulationViewDropTargetListener that calls importData(JComponent, Transferable, Point) instead, so this method will fail if called (assertion failure).

Overrides:
importData in class javax.swing.TransferHandler
To do:
this will get called on paste however, which will fail

importData

public boolean importData(javax.swing.JComponent comp,
                          java.awt.datatransfer.Transferable t,
                          java.awt.Point location)
An alternative to the usual importData(JComponent, Transferable) called by the default DropHandler, but not when a PopulationView uses one of these TransferHandlers to handle DnD.

Note that the INDIVIDUAL_FILE_FLAVOR handling accepts multiple files.

See Also:
canImport(JComponent, DataFlavor[]), TransferHandler.importData(JComponent, Transferable)

artoflife pre0.1.0-dev

Copyright © 2002 the Art Of Life team. All Rights Reserved.