Skip to content

Commit aa07450

Browse files
committed
Tool: move default method impls to iface
1 parent 894f014 commit aa07450

File tree

2 files changed

+54
-101
lines changed

2 files changed

+54
-101
lines changed

src/main/java/org/scijava/tool/AbstractTool.java

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,6 @@
3131

3232
package org.scijava.tool;
3333

34-
import org.scijava.display.event.input.KyPressedEvent;
35-
import org.scijava.display.event.input.KyReleasedEvent;
36-
import org.scijava.display.event.input.MsClickedEvent;
37-
import org.scijava.display.event.input.MsDraggedEvent;
38-
import org.scijava.display.event.input.MsMovedEvent;
39-
import org.scijava.display.event.input.MsPressedEvent;
40-
import org.scijava.display.event.input.MsReleasedEvent;
41-
import org.scijava.display.event.input.MsWheelEvent;
42-
import org.scijava.input.MouseCursor;
4334
import org.scijava.plugin.AbstractRichPlugin;
4435

4536
/**
@@ -49,80 +40,5 @@
4940
* @author Grant Harris
5041
*/
5142
public abstract class AbstractTool extends AbstractRichPlugin implements Tool {
52-
53-
@Override
54-
public boolean isAlwaysActive() {
55-
return false;
56-
}
57-
58-
@Override
59-
public boolean isActiveInAppFrame() {
60-
return false;
61-
}
62-
63-
@Override
64-
public MouseCursor getCursor() {
65-
return MouseCursor.DEFAULT;
66-
}
67-
68-
@Override
69-
public void activate() {
70-
// do nothing by default
71-
}
72-
73-
@Override
74-
public void deactivate() {
75-
// do nothing by default
76-
}
77-
78-
@Override
79-
public void onKeyDown(final KyPressedEvent evt) {
80-
// do nothing by default
81-
}
82-
83-
@Override
84-
public void onKeyUp(final KyReleasedEvent evt) {
85-
// do nothing by default
86-
}
87-
88-
@Override
89-
public void onMouseDown(final MsPressedEvent evt) {
90-
// do nothing by default
91-
}
92-
93-
@Override
94-
public void onMouseUp(final MsReleasedEvent evt) {
95-
// do nothing by default
96-
}
97-
98-
@Override
99-
public void onMouseClick(final MsClickedEvent evt) {
100-
// do nothing by default
101-
}
102-
103-
@Override
104-
public void onMouseMove(final MsMovedEvent evt) {
105-
// do nothing by default
106-
}
107-
108-
@Override
109-
public void onMouseDrag(final MsDraggedEvent evt) {
110-
// do nothing by default
111-
}
112-
113-
@Override
114-
public void onMouseWheel(final MsWheelEvent evt) {
115-
// do nothing by default
116-
}
117-
118-
@Override
119-
public void configure() {
120-
// do nothing by default
121-
}
122-
123-
@Override
124-
public String getDescription() {
125-
return getInfo().getDescription();
126-
}
127-
43+
// NB: No implementation needed.
12844
}

src/main/java/org/scijava/tool/Tool.java

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,51 +69,88 @@
6969
public interface Tool extends RichPlugin, SingletonPlugin {
7070

7171
/** When true, tool has no button but rather is active all the time. */
72-
boolean isAlwaysActive();
72+
default boolean isAlwaysActive() {
73+
return false;
74+
}
7375

7476
/**
7577
* When true, tool receives events when the main application frame is active.
7678
* When false, tool only receives events when a display window is active.
7779
*/
78-
boolean isActiveInAppFrame();
80+
default boolean isActiveInAppFrame() {
81+
return false;
82+
}
7983

8084
/** The tool's mouse pointer. */
81-
MouseCursor getCursor();
85+
default MouseCursor getCursor() {
86+
return MouseCursor.DEFAULT;
87+
}
8288

8389
/** Informs the tool that it is now active. */
84-
void activate();
90+
default void activate() {
91+
// do nothing by default
92+
}
8593

8694
/** Informs the tool that it is no longer active. */
87-
void deactivate();
95+
default void deactivate() {
96+
// do nothing by default
97+
}
8898

8999
/** Occurs when a key on the keyboard is pressed while the tool is active. */
90-
void onKeyDown(KyPressedEvent event);
100+
@SuppressWarnings("unused")
101+
default void onKeyDown(final KyPressedEvent evt) {
102+
// do nothing by default
103+
}
91104

92105
/** Occurs when a key on the keyboard is released while the tool is active. */
93-
void onKeyUp(KyReleasedEvent event);
106+
@SuppressWarnings("unused")
107+
default void onKeyUp(final KyReleasedEvent evt) {
108+
// do nothing by default
109+
}
94110

95111
/** Occurs when a mouse button is pressed while the tool is active. */
96-
void onMouseDown(MsPressedEvent event);
112+
@SuppressWarnings("unused")
113+
default void onMouseDown(final MsPressedEvent evt) {
114+
// do nothing by default
115+
}
97116

98117
/** Occurs when a mouse button is released while the tool is active. */
99-
void onMouseUp(MsReleasedEvent event);
118+
@SuppressWarnings("unused")
119+
default void onMouseUp(final MsReleasedEvent evt) {
120+
// do nothing by default
121+
}
100122

101123
/** Occurs when a mouse button is double clicked while the tool is active. */
102-
void onMouseClick(MsClickedEvent event);
124+
@SuppressWarnings("unused")
125+
default void onMouseClick(final MsClickedEvent evt) {
126+
// do nothing by default
127+
}
103128

104129
/** Occurs when the mouse is moved while the tool is active. */
105-
void onMouseMove(MsMovedEvent event);
130+
@SuppressWarnings("unused")
131+
default void onMouseMove(final MsMovedEvent evt) {
132+
// do nothing by default
133+
}
106134

107135
/** Occurs when the mouse is dragged while the tool is active. */
108-
void onMouseDrag(MsDraggedEvent event);
136+
@SuppressWarnings("unused")
137+
default void onMouseDrag(final MsDraggedEvent evt) {
138+
// do nothing by default
139+
}
109140

110141
/** Occurs when the mouse wheel is moved while the tool is active. */
111-
void onMouseWheel(MsWheelEvent event);
142+
@SuppressWarnings("unused")
143+
default void onMouseWheel(final MsWheelEvent evt) {
144+
// do nothing by default
145+
}
112146

113147
/** Occurs when the user right clicks this tool's icon. */
114-
void configure();
148+
default void configure() {
149+
// do nothing by default
150+
}
115151

116152
/** Returns the text the tool provides when mouse hovers over tool */
117-
String getDescription();
118-
153+
default String getDescription() {
154+
return getInfo().getDescription();
155+
}
119156
}

0 commit comments

Comments
 (0)