org.fife.ui
Class TabbedPaneTransferHandler

java.lang.Object
  extended by javax.swing.TransferHandler
      extended by org.fife.ui.TabbedPaneTransferHandler
All Implemented Interfaces:
java.awt.dnd.DropTargetListener, java.io.Serializable, java.util.EventListener

public class TabbedPaneTransferHandler
extends javax.swing.TransferHandler
implements java.awt.dnd.DropTargetListener

A transfer handler for JTabbedPanes. This handler can move tabs between tabbed panes, as well as move the position of tabs within a tabbed pane.

If the tabbed pane receiving the drop implements the DrawDnDIndicatorTabbedPane interface, it will be sent a rectangle that it can paint to signify where the dropped tab will be placed.

Version:
0.5
Author:
Robert Futrell
See Also:
DrawDnDIndicatorTabbedPane, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.TransferHandler
javax.swing.TransferHandler.DropLocation, javax.swing.TransferHandler.TransferSupport
 
Field Summary
protected  java.awt.Point mouseLocation
          The location of the mouse cursor throughout the drag-and-drop.
 
Fields inherited from class javax.swing.TransferHandler
COPY, COPY_OR_MOVE, LINK, MOVE, NONE
 
Constructor Summary
TabbedPaneTransferHandler()
          Constructor.
 
Method Summary
 boolean canImport(javax.swing.JComponent c, java.awt.datatransfer.DataFlavor[] flavors)
          Overridden to include a check for a TabData flavor.
protected  java.awt.datatransfer.Transferable createTransferable(javax.swing.JComponent c)
           
 void dragEnter(java.awt.dnd.DropTargetDragEvent e)
           
 void dragExit(java.awt.dnd.DropTargetEvent e)
           
 void dragOver(java.awt.dnd.DropTargetDragEvent e)
          Called when a drag-and-drop operation is pending, and the mouse is hovering over the destination component.
 void drop(java.awt.dnd.DropTargetDropEvent e)
           
 void dropActionChanged(java.awt.dnd.DropTargetDragEvent e)
           
protected  int getDroppedTabIndex(javax.swing.JTabbedPane tabbedPane, java.awt.Point p)
          Returns the index at which to add a tab if it is dropped at the mouse location specified by p.
 int getSourceActions(javax.swing.JComponent c)
          We can only move tabs, we cannot copy them.
protected  boolean hasTabFlavor(java.awt.datatransfer.DataFlavor[] flavors)
          Does the flavor list have a Tab flavor?
 boolean importData(javax.swing.JComponent c, java.awt.datatransfer.Transferable t)
          Called when the drag-and-drop operation has just completed.
protected  void selectTab(javax.swing.JTabbedPane tabbedPane, int index)
          Selects the specified tab in the specified tabbed pane.
 
Methods inherited from class javax.swing.TransferHandler
canImport, exportAsDrag, 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

mouseLocation

protected java.awt.Point mouseLocation
The location of the mouse cursor throughout the drag-and-drop. This is here because of a deficiency in TransferHandler's design; you have no way of knowing the exact drop location in the component with a plain TransferHandler unless you implement DropTargetListener and get it that way.

Constructor Detail

TabbedPaneTransferHandler

public TabbedPaneTransferHandler()
Constructor.

Method Detail

canImport

public boolean canImport(javax.swing.JComponent c,
                         java.awt.datatransfer.DataFlavor[] flavors)
Overridden to include a check for a TabData flavor.

Overrides:
canImport in class javax.swing.TransferHandler

createTransferable

protected java.awt.datatransfer.Transferable createTransferable(javax.swing.JComponent c)
Overrides:
createTransferable in class javax.swing.TransferHandler

dragEnter

public void dragEnter(java.awt.dnd.DropTargetDragEvent e)
Specified by:
dragEnter in interface java.awt.dnd.DropTargetListener

dragExit

public void dragExit(java.awt.dnd.DropTargetEvent e)
Specified by:
dragExit in interface java.awt.dnd.DropTargetListener

dragOver

public void dragOver(java.awt.dnd.DropTargetDragEvent e)
Called when a drag-and-drop operation is pending, and the mouse is hovering over the destination component.

Specified by:
dragOver in interface java.awt.dnd.DropTargetListener

drop

public void drop(java.awt.dnd.DropTargetDropEvent e)
Specified by:
drop in interface java.awt.dnd.DropTargetListener

dropActionChanged

public void dropActionChanged(java.awt.dnd.DropTargetDragEvent e)
Specified by:
dropActionChanged in interface java.awt.dnd.DropTargetListener

getDroppedTabIndex

protected int getDroppedTabIndex(javax.swing.JTabbedPane tabbedPane,
                                 java.awt.Point p)
Returns the index at which to add a tab if it is dropped at the mouse location specified by p.

Parameters:
tabbedPane - The tabbed pane who would be receiving the tab.
p - The mouse location.
Returns:
The index at which to add the tab.

getSourceActions

public int getSourceActions(javax.swing.JComponent c)
We can only move tabs, we cannot copy them.

Overrides:
getSourceActions in class javax.swing.TransferHandler
Parameters:
c - This parameter is ignored.
Returns:
TransferHandler.MOVE, as we can only move tabs.

hasTabFlavor

protected boolean hasTabFlavor(java.awt.datatransfer.DataFlavor[] flavors)
Does the flavor list have a Tab flavor?


importData

public boolean importData(javax.swing.JComponent c,
                          java.awt.datatransfer.Transferable t)
Called when the drag-and-drop operation has just completed. This creates a new tab identical to the one "dragged" and places it in the destination JTabbedPane.

Overrides:
importData in class javax.swing.TransferHandler
Parameters:
c - The component receiving the "drop" (the instance of JTabbedPane).
t - The data being transfered (information about the tab and the component contained by the tab).
Returns:
Whether or not the import was successful.

selectTab

protected void selectTab(javax.swing.JTabbedPane tabbedPane,
                         int index)
Selects the specified tab in the specified tabbed pane. This method can be overridden by subclasses to do more stuff than simply select the tab.

Parameters:
tabbedPane - The tabbed pane.
index - The index of the tab to select.