Package net.sf.freecol.client.gui.panel
Class DefaultTransferHandler
- java.lang.Object
-
- javax.swing.TransferHandler
-
- net.sf.freecol.client.gui.panel.DefaultTransferHandler
-
- All Implemented Interfaces:
java.io.Serializable
public final class DefaultTransferHandler extends javax.swing.TransferHandler
ATransferHandler
forImageSelection
Transferable
s. The DefaultTransferHandler should be attached to JPanels or custom JLabels.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
DefaultTransferHandler.FreeColDragGestureRecognizer
private static class
DefaultTransferHandler.FreeColDragHandler
This is the default drag handler for drag and drop operations that use theTransferHandler
.
-
Field Summary
Fields Modifier and Type Field Description static java.awt.datatransfer.DataFlavor
flavor
private FreeColClient
freeColClient
The enclosing client.private static java.util.logging.Logger
logger
private FreeColPanel
parentPanel
The panel where the transfer begins.private static DefaultTransferHandler.FreeColDragGestureRecognizer
recognizer
-
Constructor Summary
Constructors Constructor Description DefaultTransferHandler(FreeColClient freeColClient, FreeColPanel parentPanel)
Creates the default FreeCol transfer handler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canImport(javax.swing.JComponent comp, java.awt.datatransfer.DataFlavor[] flavor)
java.awt.datatransfer.Transferable
createTransferable(javax.swing.JComponent comp)
private boolean
equipUnitIfPossible(UnitLabel unitLabel, AbstractGoods goods)
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.private javax.swing.JComponent
getDropTarget(javax.swing.JComponent component)
int
getSourceActions(javax.swing.JComponent comp)
boolean
importData(javax.swing.JComponent comp, java.awt.datatransfer.Transferable t)
private boolean
importFail(javax.swing.JComponent comp, java.lang.String data)
Complain about import failure.private boolean
importGoods(javax.swing.JComponent comp, GoodsLabel label, UnitLabel oldSelectedUnit)
Import goods specified by label to a component.private boolean
importGoodsType(javax.swing.JComponent comp, GoodsTypeLabel label)
Import goods type specified by label to a component.private boolean
importMarket(javax.swing.JComponent comp, MarketLabel label)
Import from a market specified by label to a component.private boolean
importUnit(javax.swing.JComponent comp, UnitLabel label, UnitLabel oldSelectedUnit)
Import a unit specified by its label to a component.private void
restoreSelection(UnitLabel oldSelectedUnit)
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
flavor
public static final java.awt.datatransfer.DataFlavor flavor
-
recognizer
private static final DefaultTransferHandler.FreeColDragGestureRecognizer recognizer
-
freeColClient
private final FreeColClient freeColClient
The enclosing client.
-
parentPanel
private final FreeColPanel parentPanel
The panel where the transfer begins.
-
-
Constructor Detail
-
DefaultTransferHandler
public DefaultTransferHandler(FreeColClient freeColClient, FreeColPanel parentPanel)
Creates the default FreeCol transfer handler.- Parameters:
freeColClient
- TheFreeColClient
for the game.parentPanel
- The layered pane that holds all kinds of information.
-
-
Method Detail
-
getDropTarget
private javax.swing.JComponent getDropTarget(javax.swing.JComponent component)
-
restoreSelection
private void restoreSelection(UnitLabel oldSelectedUnit)
-
equipUnitIfPossible
private boolean equipUnitIfPossible(UnitLabel unitLabel, AbstractGoods goods)
-
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.- Parameters:
goodsType
- TheGoodsType
to transfer.available
- The amount of goods available.defaultAmount
- The default amount of goods to offer.needToPay
- If true limit by available funds.- Returns:
- The selected amount of goods.
-
importFail
private boolean importFail(javax.swing.JComponent comp, java.lang.String data)
Complain about import failure.- Parameters:
comp
- The importing component.data
- A description of the data being imported.- Returns:
- Always false.
-
importGoodsType
private boolean importGoodsType(javax.swing.JComponent comp, GoodsTypeLabel label)
Import goods type specified by label to a component.- Parameters:
comp
- The component to import to.label
- TheGoodsTypeLabel
specifying the goods.- Returns:
- True if the import succeeds.
-
importGoods
private boolean importGoods(javax.swing.JComponent comp, GoodsLabel label, UnitLabel oldSelectedUnit)
Import goods specified by label to a component.- Parameters:
comp
- The component to import to.label
- TheGoodsLabel
specifying the goods.oldSelectedUnit
- A label for the oldUnit
to restore selection to.- Returns:
- True if the import succeeds.
-
importMarket
private boolean importMarket(javax.swing.JComponent comp, MarketLabel label)
Import from a market specified by label to a component.- Parameters:
comp
- The component to import to.label
- TheMarketLabel
specifying the goods.- Returns:
- True if the import succeeds.
-
importUnit
private boolean importUnit(javax.swing.JComponent comp, UnitLabel label, UnitLabel oldSelectedUnit)
Import a unit specified by its label to a component.- Parameters:
comp
- The component to import to.label
- TheUnitLabel
specifying the unit.oldSelectedUnit
- A label for the oldUnit
to restore selection to.- Returns:
- True if the import succeeds.
-
canImport
public boolean canImport(javax.swing.JComponent comp, java.awt.datatransfer.DataFlavor[] flavor)
- Overrides:
canImport
in classjavax.swing.TransferHandler
-
createTransferable
public java.awt.datatransfer.Transferable createTransferable(javax.swing.JComponent comp)
- Overrides:
createTransferable
in classjavax.swing.TransferHandler
-
exportAsDrag
public void exportAsDrag(javax.swing.JComponent comp, java.awt.event.InputEvent e, int action)
- Overrides:
exportAsDrag
in classjavax.swing.TransferHandler
-
getSourceActions
public int getSourceActions(javax.swing.JComponent comp)
- Overrides:
getSourceActions
in classjavax.swing.TransferHandler
-
importData
public boolean importData(javax.swing.JComponent comp, java.awt.datatransfer.Transferable t)
- Overrides:
importData
in classjavax.swing.TransferHandler
-
-