DnDSupportBuilder (@NotNull JComponent component) { final JComponent myComponent = component; final Ref<Boolean> asTarget = Ref.create(true); final Ref<Boolean> asSource = Ref.create(true); final Ref<Boolean> asNativeTarget = Ref.create(false); final Ref<Function<? super DnDActionInfo, ? extends DnDImage>> imageProvider = Ref.create(null); final Ref<Function<? super DnDActionInfo, ? extends DnDDragStartBean>> beanProvider = Ref.create(null); final Ref<Runnable> dropEnded = Ref.create(null); final Ref<Disposable> disposable = Ref.create(null); final Ref<DnDDropHandler.WithResult> dropHandler = Ref.create(null); final Ref<DnDTargetChecker> targetChecker = Ref.create(null); final Ref<DnDDropActionHandler> dropActionHandler = Ref.create(null); final Ref<Runnable> cleanUp = Ref.create(null); return new DnDSupportBuilder() { @Override public DnDSupportBuilder disableAsTarget() { asTarget.set(false); return this; } @Override public DnDSupportBuilder disableAsSource() { asSource.set(false); return this; } @Override public DnDSupportBuilder enableAsNativeTarget() { asNativeTarget.set(true); return this; } @Override public DnDSupportBuilder setImageProvider(Function<? super DnDActionInfo, ? extends DnDImage> fun) { imageProvider.set(fun); return this; } @Override public DnDSupportBuilder setBeanProvider(Function<? super DnDActionInfo, ? extends DnDDragStartBean> fun) { beanProvider.set(fun); return this; } @Override public DnDSupportBuilder setDropHandler(DnDDropHandler handler) { return setDropHandlerWithResult(e -> { handler.drop(e); return true; }); } @Override public DnDSupportBuilder setDropHandlerWithResult(DnDDropHandler.WithResult handler) { dropHandler.set(handler); return this; } @Override public DnDSupportBuilder setTargetChecker(DnDTargetChecker checker) { targetChecker.set(checker); return this; } @Override public DnDSupportBuilder setDropActionHandler(DnDDropActionHandler handler) { dropActionHandler.set(handler); return this; } @Override public DnDSupportBuilder setDisposableParent(Disposable parent) { disposable.set(parent); return this; } @Override public DnDSupportBuilder setCleanUpOnLeaveCallback(Runnable callback) { cleanUp.set(callback); return this; } @Override public DnDSupportBuilder setDropEndedCallback(Runnable callback) { dropEnded.set(callback); return this; } @Override public void install() { //noinspection ResultOfObjectAllocationIgnored new DnDSupport(myComponent, beanProvider.get(), imageProvider.get(), dropHandler.get(), targetChecker.get(), dropEnded.get(), disposable.get(), dropActionHandler.get(), cleanUp.get(), asTarget.get(), asSource.get(), asNativeTarget.get()); } }; }