* This is invoked when a drop has occurred.
* @param event The drop event.
*/
public void drop (DropTargetDropEvent event)
{
DropTargetContext context;
Component component;
SubFilterList list;
String s;
Point point;
Filter[] filters;
boolean accept;
// find the enclosing filter
context = event.getDropTargetContext ();
component = context.getComponent ();
while ( (null != component)
&& !(component instanceof SubFilterList)
&& !(component == mMainPanel))
component = component.getParent ();
if (component instanceof SubFilterList)
list = (SubFilterList)component;
else
list = null;
// so either list is the enclosing list,
// or list is null and the target component is the main panel
try
{
accept = false;
Transferable transferable = event.getTransferable();
// we accept only Strings
if (transferable.isDataFlavorSupported (DataFlavor.stringFlavor))
{
accept = true;
event.acceptDrop (DnDConstants.ACTION_MOVE);
s = (String)transferable.getTransferData (DataFlavor.stringFlavor);
point = event.getLocation ();
try
{
// get the filter and add into the target
filters = Filter.reconstitute (s, new Parser (mURLField.getText ()));
if (0 < filters.length)
insertFilters (filters, point, list);
if (null != list)
list.setSelected (false);
}
catch (Exception e)
{
e.printStackTrace ();
}
// signal the drop was successful
context.dropComplete (accept);
}
else
event.rejectDrop();
}
catch (IOException exception)