Skip to content

Commit e518575

Browse files
committed
DragAndDropService: move default method impls to iface
1 parent 068b446 commit e518575

File tree

2 files changed

+48
-70
lines changed

2 files changed

+48
-70
lines changed

src/main/java/org/scijava/ui/dnd/DefaultDragAndDropService.java

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
package org.scijava.ui.dnd;
3333

3434
import org.scijava.app.StatusService;
35-
import org.scijava.display.Display;
3635
import org.scijava.event.EventHandler;
3736
import org.scijava.plugin.AbstractHandlerService;
3837
import org.scijava.plugin.Parameter;
@@ -60,69 +59,6 @@ public class DefaultDragAndDropService extends
6059
@Parameter
6160
private StatusService statusService;
6261

63-
// -- DragAndDropService methods --
64-
65-
@Override
66-
public boolean supports(final DragAndDropData data,
67-
final Display<?> display)
68-
{
69-
return getHandler(data, display) != null;
70-
}
71-
72-
@Override
73-
public boolean supports(final Object object, final Display<?> display) {
74-
return getHandler(object, display) != null;
75-
}
76-
77-
@Override
78-
public boolean drop(final DragAndDropData data, final Display<?> display) {
79-
final DragAndDropHandler<?> handler = getHandler(data, display);
80-
if (handler == null) return false;
81-
return handler.dropData(data, display);
82-
}
83-
84-
@Override
85-
public boolean drop(final Object data, final Display<?> display) {
86-
final DragAndDropHandler<?> handler = getHandler(data, display);
87-
if (handler == null) return false;
88-
return handler.dropObject(data, display);
89-
}
90-
91-
@Override
92-
public DragAndDropHandler<?> getHandler(final DragAndDropData data,
93-
final Display<?> display)
94-
{
95-
for (final DragAndDropHandler<?> handler : getInstances()) {
96-
if (handler.supportsData(data, display)) return handler;
97-
}
98-
return null;
99-
}
100-
101-
@Override
102-
public DragAndDropHandler<?> getHandler(final Object object,
103-
final Display<?> display)
104-
{
105-
for (final DragAndDropHandler<?> handler : getInstances()) {
106-
if (handler.supportsObject(object, display)) return handler;
107-
}
108-
return null;
109-
}
110-
111-
// -- PTService methods --
112-
113-
@Override
114-
@SuppressWarnings({"rawtypes", "unchecked"})
115-
public Class<DragAndDropHandler<Object>> getPluginType() {
116-
return (Class) DragAndDropHandler.class;
117-
}
118-
119-
// -- Typed methods --
120-
121-
@Override
122-
public Class<Object> getType() {
123-
return Object.class;
124-
}
125-
12662
// -- Event handlers --
12763

12864
@EventHandler

src/main/java/org/scijava/ui/dnd/DragAndDropService.java

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ public interface DragAndDropService extends
5353
*
5454
* @see DragAndDropHandler
5555
*/
56-
boolean supports(DragAndDropData data, Display<?> display);
56+
default boolean supports(final DragAndDropData data,
57+
final Display<?> display)
58+
{
59+
return getHandler(data, display) != null;
60+
}
5761

5862
/**
5963
* Checks whether the given object can be dropped onto the specified display.
@@ -62,7 +66,9 @@ public interface DragAndDropService extends
6266
*
6367
* @see DragAndDropHandler
6468
*/
65-
boolean supports(Object object, Display<?> display);
69+
default boolean supports(final Object object, final Display<?> display) {
70+
return getHandler(object, display) != null;
71+
}
6672

6773
/**
6874
* Performs a drag-and-drop operation in the given display with the specified
@@ -73,7 +79,11 @@ public interface DragAndDropService extends
7379
* @throws IllegalArgumentException if the display and/or data object are
7480
* unsupported, or are incompatible with one another.
7581
*/
76-
boolean drop(DragAndDropData data, Display<?> display);
82+
default boolean drop(final DragAndDropData data, final Display<?> display) {
83+
final DragAndDropHandler<?> handler = getHandler(data, display);
84+
if (handler == null) return false;
85+
return handler.dropData(data, display);
86+
}
7787

7888
/**
7989
* Performs a drag-and-drop operation in the given display with the specified
@@ -84,7 +94,11 @@ public interface DragAndDropService extends
8494
* @throws IllegalArgumentException if the display and/or data object are
8595
* unsupported, or are incompatible with one another.
8696
*/
87-
boolean drop(Object data, Display<?> display);
97+
default boolean drop(final Object data, final Display<?> display) {
98+
final DragAndDropHandler<?> handler = getHandler(data, display);
99+
if (handler == null) return false;
100+
return handler.dropObject(data, display);
101+
}
88102

89103
/**
90104
* Gets the drag-and-drop handler which will be used to handle the given
@@ -93,7 +107,14 @@ public interface DragAndDropService extends
93107
* @return The first compatible drag-and-drop handler, or null if none
94108
* available.
95109
*/
96-
DragAndDropHandler<?> getHandler(DragAndDropData data, Display<?> display);
110+
default DragAndDropHandler<?> getHandler(final DragAndDropData data,
111+
final Display<?> display)
112+
{
113+
for (final DragAndDropHandler<?> handler : getInstances()) {
114+
if (handler.supportsData(data, display)) return handler;
115+
}
116+
return null;
117+
}
97118

98119
/**
99120
* Gets the drag-and-drop handler which will be used to handle the given
@@ -102,7 +123,14 @@ public interface DragAndDropService extends
102123
* @return The first compatible drag-and-drop handler, or null if none
103124
* available.
104125
*/
105-
DragAndDropHandler<?> getHandler(Object object, Display<?> display);
126+
default DragAndDropHandler<?> getHandler(final Object object,
127+
final Display<?> display)
128+
{
129+
for (final DragAndDropHandler<?> handler : getInstances()) {
130+
if (handler.supportsObject(object, display)) return handler;
131+
}
132+
return null;
133+
}
106134

107135
// NB: Javadoc overrides.
108136

@@ -115,4 +143,18 @@ public interface DragAndDropService extends
115143
@Override
116144
List<DragAndDropHandler<Object>> getInstances();
117145

146+
// -- PTService methods --
147+
148+
@Override
149+
@SuppressWarnings({"rawtypes", "unchecked"})
150+
default Class<DragAndDropHandler<Object>> getPluginType() {
151+
return (Class) DragAndDropHandler.class;
152+
}
153+
154+
// -- Typed methods --
155+
156+
@Override
157+
default Class<Object> getType() {
158+
return Object.class;
159+
}
118160
}

0 commit comments

Comments
 (0)