Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2020 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.common.swt.dnd;
import com.diffplug.common.collect.ImmutableList;
import com.diffplug.common.collect.ImmutableMap;
import com.diffplug.common.collect.Immutables;
import com.diffplug.common.swt.SwtMisc;
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import javax.annotation.Nullable;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DropTarget;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.DropTargetListener;
import org.eclipse.swt.dnd.FileTransfer;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.dnd.TransferData;
import org.eclipse.swt.widgets.Control;
/**
* Typed mechanism for implementing drop listeners.
*
* https://eclipse.org/articles/Article-SWT-DND/DND-in-SWT.html
*/
public class StructuredDrop {
public enum DropMethod {
dragEnter, dragLeave, dragOperationChanged, dragOver, drop, dropAccept
}
@FunctionalInterface
public interface TypedDropHandler {
/** If it's the result of a "paste", then DropTargetEvent will be null. */
void onEvent(DropMethod method, @Nullable DropTargetEvent e, T value);
default TypedDropHandler map(Function super R, ? extends T> mapper) {
return new MappedTypedDropHandler(this, mapper);
}
}
private static class MappedTypedDropHandler implements TypedDropHandler {
TypedDropHandler delegate;
Function super R, ? extends T> mapper;
MappedTypedDropHandler(TypedDropHandler delegate, Function super R, ? extends T> mapper) {
this.delegate = Objects.requireNonNull(delegate);
this.mapper = Objects.requireNonNull(mapper);
}
@Override
public void onEvent(DropMethod method, DropTargetEvent e, R value) {
T mapped = mapper.apply(value);
delegate.onEvent(method, e, mapped);
}
}
private static class Handler {
BiFunction