Skip to content

Commit a6885c3

Browse files
committed
Merge branch 'named'
Add a Named interface for things with names. This was originally part of the imglib2-meta project (and later migrated to imagej-common as a deprecated class). But it really fits best here in the SciJava Common library.
2 parents 33f934a + 69b3feb commit a6885c3

File tree

10 files changed

+125
-64
lines changed

10 files changed

+125
-64
lines changed

src/main/java/org/scijava/AbstractBasicDetails.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ public String toString() {
7171

7272
// -- BasicDetails methods --
7373

74-
@Override
75-
public String getName() {
76-
return name;
77-
}
78-
7974
@Override
8075
public String getLabel() {
8176
return label;
@@ -96,11 +91,6 @@ public String get(final String key) {
9691
return values.get(key);
9792
}
9893

99-
@Override
100-
public void setName(final String name) {
101-
this.name = name;
102-
}
103-
10494
@Override
10595
public void setLabel(final String label) {
10696
this.label = label;
@@ -116,4 +106,16 @@ public void set(String key, String value) {
116106
values.put(key, value);
117107
}
118108

109+
// -- Named methods --
110+
111+
@Override
112+
public String getName() {
113+
return name;
114+
}
115+
116+
@Override
117+
public void setName(final String name) {
118+
this.name = name;
119+
}
120+
119121
}

src/main/java/org/scijava/BasicDetails.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@
3737
*
3838
* @author Curtis Rueden
3939
*/
40-
public interface BasicDetails {
41-
42-
/** Gets the unique name of the object. */
43-
String getName();
40+
public interface BasicDetails extends Named {
4441

4542
/** Gets the name to appear in a UI, if applicable. */
4643
String getLabel();
@@ -54,9 +51,6 @@ public interface BasicDetails {
5451
/** Gets the value of the given key, or null if undefined. */
5552
public String get(String key);
5653

57-
/** Sets the unique name of the object. */
58-
void setName(String name);
59-
6054
/** Sets the name to appear in a UI, if applicable. */
6155
void setLabel(String label);
6256

src/main/java/org/scijava/MenuEntry.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* @author Curtis Rueden
4040
* @author Johannes Schindelin
4141
*/
42-
public class MenuEntry {
42+
public class MenuEntry implements Named {
4343

4444
public static final double DEFAULT_WEIGHT = Double.POSITIVE_INFINITY;
4545

@@ -68,14 +68,6 @@ public MenuEntry(final String name, final double weight,
6868
setIconPath(iconPath);
6969
}
7070

71-
public void setName(final String name) {
72-
this.name = name;
73-
}
74-
75-
public String getName() {
76-
return name;
77-
}
78-
7971
public void setWeight(final double weight) {
8072
this.weight = weight;
8173
}
@@ -120,6 +112,20 @@ public void assignProperties(final MenuEntry entry) {
120112
if (iconPath == null) iconPath = entry.getIconPath();
121113
}
122114

115+
// -- Named methods --
116+
117+
@Override
118+
public String getName() {
119+
return name;
120+
}
121+
122+
@Override
123+
public void setName(final String name) {
124+
this.name = name;
125+
}
126+
127+
// -- Object methods --
128+
123129
@Override
124130
public String toString() {
125131
return name;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* #%L
3+
* SciJava Common shared library for SciJava software.
4+
* %%
5+
* Copyright (C) 2009 - 2014 Board of Regents of the University of
6+
* Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
7+
* Institute of Molecular Cell Biology and Genetics.
8+
* %%
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
* #L%
30+
*/
31+
32+
package org.scijava;
33+
34+
/**
35+
* Interface for things that have names.
36+
*
37+
* @author Lee Kamentsky
38+
*/
39+
public interface Named {
40+
41+
/** Gets the name of the object. */
42+
String getName();
43+
44+
/** Sets the name of the object. */
45+
void setName(String name);
46+
47+
}

src/main/java/org/scijava/command/CommandModuleItem.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,6 @@ public List<T> getChoices() {
167167

168168
// -- BasicDetails methods --
169169

170-
@Override
171-
public String getName() {
172-
return field.getName();
173-
}
174-
175170
@Override
176171
public String getLabel() {
177172
return getParameter().label();
@@ -198,4 +193,11 @@ public String get(final String key) {
198193
return null;
199194
}
200195

196+
// -- Named methods --
197+
198+
@Override
199+
public String getName() {
200+
return field.getName();
201+
}
202+
201203
}

src/main/java/org/scijava/command/DynamicCommandInfo.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,6 @@ public void setSelected(final boolean selected) {
248248

249249
// -- BasicDetails methods --
250250

251-
@Override
252-
public String getName() {
253-
return info.getName();
254-
}
255-
256251
@Override
257252
public String getLabel() {
258253
return info.getLabel();
@@ -263,11 +258,6 @@ public String getDescription() {
263258
return info.getDescription();
264259
}
265260

266-
@Override
267-
public void setName(final String name) {
268-
info.setName(name);
269-
}
270-
271261
@Override
272262
public void setLabel(final String label) {
273263
info.setLabel(label);
@@ -278,6 +268,18 @@ public void setDescription(final String description) {
278268
info.setDescription(description);
279269
}
280270

271+
// -- Named methods --
272+
273+
@Override
274+
public String getName() {
275+
return info.getName();
276+
}
277+
278+
@Override
279+
public void setName(final String name) {
280+
info.setName(name);
281+
}
282+
281283
// -- Validated methods --
282284

283285
@Override

src/main/java/org/scijava/display/AbstractDisplay.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ public void close() {
150150
isClosed = true;
151151
}
152152

153+
// -- Named methods --
154+
153155
@Override
154156
public String getName() {
155157
return name;

src/main/java/org/scijava/display/Display.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import java.util.List;
3535

36+
import org.scijava.Named;
3637
import org.scijava.plugin.Plugin;
3738
import org.scijava.plugin.RichPlugin;
3839

@@ -52,7 +53,7 @@
5253
* @see Plugin
5354
* @see DisplayService
5455
*/
55-
public interface Display<T> extends List<T>, RichPlugin {
56+
public interface Display<T> extends List<T>, RichPlugin, Named {
5657

5758
/**
5859
* Tests whether the display is capable of visualizing objects of the given
@@ -99,10 +100,4 @@ public interface Display<T> extends List<T>, RichPlugin {
99100
/** Closes the display and disposes its resources. */
100101
void close();
101102

102-
/** Gets the name of the display. */
103-
String getName();
104-
105-
/** Sets the name of the display. */
106-
void setName(String name);
107-
108103
}

src/main/java/org/scijava/menu/ShadowMenu.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.scijava.Context;
4646
import org.scijava.MenuEntry;
4747
import org.scijava.MenuPath;
48+
import org.scijava.Named;
4849
import org.scijava.event.EventService;
4950
import org.scijava.log.LogService;
5051
import org.scijava.menu.event.MenusAddedEvent;
@@ -79,7 +80,7 @@
7980
* @see MenuEntry
8081
*/
8182
public class ShadowMenu extends AbstractContextual implements
82-
Comparable<ShadowMenu>, Collection<ModuleInfo>, Runnable
83+
Comparable<ShadowMenu>, Collection<ModuleInfo>, Runnable, Named
8384
{
8485

8586
/** Icon to use for leaf entries by default, if no icon is specified. */
@@ -177,11 +178,6 @@ public int getMenuDepth() {
177178
return menuDepth;
178179
}
179180

180-
/** Gets the name of the menu. */
181-
public String getName() {
182-
return menuEntry == null ? null : menuEntry.getName();
183-
}
184-
185181
/** Gets this node's parent, or null if it is a root node. */
186182
public ShadowMenu getParent() {
187183
return parent;
@@ -279,6 +275,19 @@ public boolean updateAll(final Collection<? extends ModuleInfo> c) {
279275
return true;
280276
}
281277

278+
// -- Named methods --
279+
280+
@Override
281+
public String getName() {
282+
return menuEntry == null ? null : menuEntry.getName();
283+
}
284+
285+
@Override
286+
public void setName(final String name) {
287+
if (menuEntry == null) return;
288+
menuEntry.setName(name);
289+
}
290+
282291
// -- Object methods --
283292

284293
@Override

src/main/java/org/scijava/module/DefaultMutableModuleItem.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,6 @@ public List<T> getChoices() {
296296

297297
// -- BasicDetails methods --
298298

299-
@Override
300-
public String getName() {
301-
return name;
302-
}
303-
304299
@Override
305300
public String getLabel() {
306301
return label;
@@ -311,11 +306,6 @@ public String getDescription() {
311306
return description;
312307
}
313308

314-
@Override
315-
public void setName(final String name) {
316-
this.name = name;
317-
}
318-
319309
@Override
320310
public void setLabel(final String label) {
321311
this.label = label;
@@ -326,4 +316,16 @@ public void setDescription(final String description) {
326316
this.description = description;
327317
}
328318

319+
// -- Named methods --
320+
321+
@Override
322+
public String getName() {
323+
return name;
324+
}
325+
326+
@Override
327+
public void setName(final String name) {
328+
this.name = name;
329+
}
330+
329331
}

0 commit comments

Comments
 (0)