Class DefaultTransferHandler

  • All Implemented Interfaces:
    java.io.Serializable

    public final class DefaultTransferHandler
    extends javax.swing.TransferHandler
    A TransferHandler for ImageSelection Transferables. 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 the TransferHandler.
      • Nested classes/interfaces inherited from class javax.swing.TransferHandler

        javax.swing.TransferHandler.DropLocation, javax.swing.TransferHandler.TransferSupport
    • 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)  
      • Methods inherited from class javax.swing.TransferHandler

        canImport, exportDone, exportToClipboard, getCopyAction, getCutAction, getDragImage, getDragImageOffset, getPasteAction, getVisualRepresentation, importData, setDragImage, setDragImageOffset
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DefaultTransferHandler

        public DefaultTransferHandler​(FreeColClient freeColClient,
                                      FreeColPanel parentPanel)
        Creates the default FreeCol transfer handler.
        Parameters:
        freeColClient - The FreeColClient 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)
      • 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 - The GoodsType 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 - The GoodsTypeLabel 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 - The GoodsLabel specifying the goods.
        oldSelectedUnit - A label for the old Unit 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 - The MarketLabel 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 - The UnitLabel specifying the unit.
        oldSelectedUnit - A label for the old Unit 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 class javax.swing.TransferHandler
      • createTransferable

        public java.awt.datatransfer.Transferable createTransferable​(javax.swing.JComponent comp)
        Overrides:
        createTransferable in class javax.swing.TransferHandler
      • exportAsDrag

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

        public int getSourceActions​(javax.swing.JComponent comp)
        Overrides:
        getSourceActions in class javax.swing.TransferHandler
      • importData

        public boolean importData​(javax.swing.JComponent comp,
                                  java.awt.datatransfer.Transferable t)
        Overrides:
        importData in class javax.swing.TransferHandler