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.TransferHandlerATransferHandlerforImageSelectionTransferables. 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 classDefaultTransferHandler.FreeColDragGestureRecognizerprivate static classDefaultTransferHandler.FreeColDragHandlerThis 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.DataFlavorflavorprivate FreeColClientfreeColClientThe enclosing client.private static java.util.logging.Loggerloggerprivate FreeColPanelparentPanelThe panel where the transfer begins.private static DefaultTransferHandler.FreeColDragGestureRecognizerrecognizer
-
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 booleancanImport(javax.swing.JComponent comp, java.awt.datatransfer.DataFlavor[] flavor)java.awt.datatransfer.TransferablecreateTransferable(javax.swing.JComponent comp)private booleanequipUnitIfPossible(UnitLabel unitLabel, AbstractGoods goods)voidexportAsDrag(javax.swing.JComponent comp, java.awt.event.InputEvent e, int action)private intgetAmount(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.JComponentgetDropTarget(javax.swing.JComponent component)intgetSourceActions(javax.swing.JComponent comp)booleanimportData(javax.swing.JComponent comp, java.awt.datatransfer.Transferable t)private booleanimportFail(javax.swing.JComponent comp, java.lang.String data)Complain about import failure.private booleanimportGoods(javax.swing.JComponent comp, GoodsLabel label, UnitLabel oldSelectedUnit)Import goods specified by label to a component.private booleanimportGoodsType(javax.swing.JComponent comp, GoodsTypeLabel label)Import goods type specified by label to a component.private booleanimportMarket(javax.swing.JComponent comp, MarketLabel label)Import from a market specified by label to a component.private booleanimportUnit(javax.swing.JComponent comp, UnitLabel label, UnitLabel oldSelectedUnit)Import a unit specified by its label to a component.private voidrestoreSelection(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- TheFreeColClientfor 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- TheGoodsTypeto 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- TheGoodsTypeLabelspecifying 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- TheGoodsLabelspecifying the goods.oldSelectedUnit- A label for the oldUnitto 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- TheMarketLabelspecifying 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- TheUnitLabelspecifying the unit.oldSelectedUnit- A label for the oldUnitto restore selection to.- Returns:
- True if the import succeeds.
-
canImport
public boolean canImport(javax.swing.JComponent comp, java.awt.datatransfer.DataFlavor[] flavor)- Overrides:
canImportin classjavax.swing.TransferHandler
-
createTransferable
public java.awt.datatransfer.Transferable createTransferable(javax.swing.JComponent comp)
- Overrides:
createTransferablein classjavax.swing.TransferHandler
-
exportAsDrag
public void exportAsDrag(javax.swing.JComponent comp, java.awt.event.InputEvent e, int action)- Overrides:
exportAsDragin classjavax.swing.TransferHandler
-
getSourceActions
public int getSourceActions(javax.swing.JComponent comp)
- Overrides:
getSourceActionsin classjavax.swing.TransferHandler
-
importData
public boolean importData(javax.swing.JComponent comp, java.awt.datatransfer.Transferable t)- Overrides:
importDatain classjavax.swing.TransferHandler
-
-