Interface IFileDropHandler

All Known Implementing Classes:
BaseView, DemoMapView, DrawingView, GeometrySliceDemoView, ImageEvolutionDemoView, JsonView, LogView, MapView2D, NetworkDeclutterDemoView, NetworkLayoutDemoView, PlotView, SimulationView, TspDemoView, VirtualView

public interface IFileDropHandler
Implemented by any component that can receive files via drag-and-drop.

This interface is the application-level contract for file drops. It is deliberately separate from the Swing plumbing (FileDropHandler) so that the view layer never has to reference Swing transfer internals directly.

Intended usage

Concrete views do not implement this interface manually. Instead they extend BaseView, which already implements it, and they activate drop support through a single call:

 // In a BaseView subclass constructor, after super(...):
 enableFileDrop(f -> f.getName().endsWith(".csv"));

 @Override
 public void filesDropped(List<File> files) {
     openCsvFile(files.get(0));
 }
 

Filter semantics

The filter is applied by FileDropHandler before filesDropped(java.util.List<java.io.File>) is called. Only files that pass the predicate are forwarded. Passing null as the filter accepts every dropped file.

Threading

filesDropped(java.util.List<java.io.File>) is called on the Swing Event Dispatch Thread.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Called on the EDT when one or more accepted files have been dropped onto this component.
    Returns the current file filter.
    void
    Set the file filter used to screen dropped files.
  • Method Details

    • setFileFilter

      void setFileFilter(Predicate<File> filter)
      Set the file filter used to screen dropped files.

      The FileDropHandler evaluates this predicate against each candidate file and forwards only those that return true. A null filter accepts every file without screening.

      Parameters:
      filter - the acceptance predicate, or null to accept all files
    • getFileFilter

      Predicate<File> getFileFilter()
      Returns the current file filter.
      Returns:
      the acceptance predicate, or null if no filter is set
    • filesDropped

      void filesDropped(List<File> files)
      Called on the EDT when one or more accepted files have been dropped onto this component.

      The list contains only files that passed the current filter (or all dropped files if no filter is set). The list is never null and is never empty.

      Parameters:
      files - the accepted dropped files; never null, never empty