net.sf.freecol.client.gui.panel
Class DefaultTransferHandler

java.lang.Object
  extended by javax.swing.TransferHandler
      extended by net.sf.freecol.client.gui.panel.DefaultTransferHandler
All Implemented Interfaces:
java.io.Serializable

public final class DefaultTransferHandler
extends javax.swing.TransferHandler

The transferhandler that is capable of creating ImageSelection objects. Those ImageSelection objects are Transferable. The DefaultTransferHandler should be attached to JPanels or custom JLabels.

See Also:
Serialized Form

Nested Class Summary
private static class DefaultTransferHandler.FreeColDragGestureRecognizer
           
private static class DefaultTransferHandler.FreeColDragHandler
          This is the default drag handler for drag and drop operations that use the TransferHandler.
 
Nested classes/interfaces inherited from class javax.swing.TransferHandler
javax.swing.TransferHandler.DropLocation, javax.swing.TransferHandler.TransferSupport
 
Field Summary
static java.awt.datatransfer.DataFlavor flavor
           
private  FreeColClient freeColClient
           
private  GUI gui
           
private static java.util.logging.Logger logger
           
private  FreeColPanel parentPanel
           
private static DefaultTransferHandler.FreeColDragGestureRecognizer recognizer
           
 
Fields inherited from class javax.swing.TransferHandler
COPY, COPY_OR_MOVE, LINK, MOVE, NONE
 
Constructor Summary
DefaultTransferHandler(FreeColClient freeColClient, GUI gui, FreeColPanel parentPanel)
          The constructor to use.
 
Method Summary
 boolean canImport(javax.swing.JComponent comp, java.awt.datatransfer.DataFlavor[] flavor)
          Returns 'true' if the given component can import a selection of the flavor that is indicated by the second parameter, 'false' otherwise.
 java.awt.datatransfer.Transferable createTransferable(javax.swing.JComponent comp)
          Creates a Transferable (an ImageSelection to be precise) of the data that is represented by the given component and returns that object.
 void exportAsDrag(javax.swing.JComponent comp, java.awt.event.InputEvent e, int action)
           
private  int getAmount(GoodsType goodsType, int available, int defaultAmount, boolean needToPay)
          Displays an input dialog box where the user should specify a goods transfer amount.
 int getSourceActions(javax.swing.JComponent comp)
          Returns the action that can be done to an ImageSelection on the given component.
 boolean importData(javax.swing.JComponent comp, java.awt.datatransfer.Transferable t)
          Imports the data represented by the given Transferable into the given component.
 
Methods inherited from class javax.swing.TransferHandler
canImport, 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
 

Field Detail

logger

private static java.util.logging.Logger logger

flavor

public static final java.awt.datatransfer.DataFlavor flavor

parentPanel

private final FreeColPanel parentPanel

freeColClient

private FreeColClient freeColClient

gui

private GUI gui

recognizer

private static DefaultTransferHandler.FreeColDragGestureRecognizer recognizer
Constructor Detail

DefaultTransferHandler

public DefaultTransferHandler(FreeColClient freeColClient,
                              GUI gui,
                              FreeColPanel parentPanel)
The constructor to use.

Parameters:
freeColClient -
canvas - The Canvas.
parentPanel - The layered pane that holds all kinds of information.
Method Detail

getSourceActions

public int getSourceActions(javax.swing.JComponent comp)
Returns the action that can be done to an ImageSelection on the given component.

Overrides:
getSourceActions in class javax.swing.TransferHandler
Returns:
The action that can be done to an ImageSelection on the given component.

canImport

public boolean canImport(javax.swing.JComponent comp,
                         java.awt.datatransfer.DataFlavor[] flavor)
Returns 'true' if the given component can import a selection of the flavor that is indicated by the second parameter, 'false' otherwise.

Overrides:
canImport in class javax.swing.TransferHandler
Parameters:
comp - The component that needs to be checked.
flavor - The flavor that needs to be checked for.
Returns:
'true' if the given component can import a selection of the flavor that is indicated by the second parameter, 'false' otherwise.

createTransferable

public java.awt.datatransfer.Transferable createTransferable(javax.swing.JComponent comp)
Creates a Transferable (an ImageSelection to be precise) of the data that is represented by the given component and returns that object.

Overrides:
createTransferable in class javax.swing.TransferHandler
Parameters:
comp - The component to create a Transferable of.
Returns:
The resulting Transferable (an ImageSelection object).

importData

public boolean importData(javax.swing.JComponent comp,
                          java.awt.datatransfer.Transferable t)
Imports the data represented by the given Transferable into the given component. Returns 'true' on success, 'false' otherwise.

Overrides:
importData in class javax.swing.TransferHandler
Parameters:
comp - The component to import the data to.
t - The Transferable that holds the data.
Returns:
'true' on success, 'false' otherwise.

getAmount

private int getAmount(GoodsType goodsType,
                      int available,
                      int defaultAmount,
                      boolean needToPay)
Displays an input dialog box where the user should specify a goods transfer amount.


exportAsDrag

public void exportAsDrag(javax.swing.JComponent comp,
                         java.awt.event.InputEvent e,
                         int action)
Overrides:
exportAsDrag in class javax.swing.TransferHandler