Skip to content

Commit 9419d44

Browse files
committed
Update to pom-scijava 40
Supports icons in menus
1 parent a11006e commit 9419d44

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

pom.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.scijava</groupId>
77
<artifactId>pom-scijava</artifactId>
8-
<version>39.0.0</version>
8+
<version>40.0.0</version>
99
<relativePath />
1010
</parent>
1111

@@ -121,9 +121,7 @@
121121

122122
<!-- package version below are not present in the parent pom. A version is needed -->
123123
<bigdataviewer-selector.version>0.2.7</bigdataviewer-selector.version>
124-
<bigvolumeviewer.version>0.3.4</bigvolumeviewer.version>
125124
<reflections.version>0.10.2</reflections.version> <!-- for test only -->
126-
<!--<spim_data.version>2.3.4</spim_data.version>-->
127125

128126
<!-- package version below are determined by the parent pom but need to be upgraded or temporarily fixed for bugs -->
129127

src/main/java/sc/fiji/bdvpg/scijava/BdvScijavaHelper.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@
3838
import org.slf4j.Logger;
3939
import org.slf4j.LoggerFactory;
4040

41+
import javax.swing.Icon;
42+
import javax.swing.ImageIcon;
4143
import javax.swing.JMenu;
4244
import javax.swing.JMenuBar;
4345
import javax.swing.JMenuItem;
4446
import javax.swing.JSeparator;
4547
import java.awt.Component;
48+
import java.net.URL;
4649
import java.util.Arrays;
4750
import java.util.List;
4851
import java.util.stream.Collectors;
@@ -75,8 +78,9 @@ static public void addCommandToBdvHandleMenu(BdvHandle bdvh, Context ctx,
7578
Class<? extends Command> commandClass, int skipTopLevels, Object... args)
7679
{
7780
Plugin plugin = commandClass.getDeclaredAnnotation(Plugin.class);
81+
7882
addActionToBdvHandleMenu(bdvh, plugin.menuPath(), skipTopLevels, () -> ctx
79-
.getService(CommandService.class).run(commandClass, true, args));
83+
.getService(CommandService.class).run(commandClass, true, args), plugin.iconPath(), plugin.description());
8084
}
8185

8286
static public void addSeparator(BdvHandle bdvh, String pathHierarchy) {
@@ -106,12 +110,20 @@ static public void addSeparator(BdvHandle bdvh, String pathHierarchy) {
106110
static public void addCommandToBdvHandleMenu(BdvHandle bdvh, Context ctx, String path,
107111
Class<? extends Command> commandClass, Object... args)
108112
{
113+
114+
Plugin plugin = commandClass.getDeclaredAnnotation(Plugin.class);
115+
109116
addActionToBdvHandleMenu(bdvh, path, 0, () -> ctx
110-
.getService(CommandService.class).run(commandClass, true, args));
117+
.getService(CommandService.class).run(commandClass, true, args), plugin.iconPath(), plugin.description());
118+
}
119+
120+
static public void addActionToBdvHandleMenu(BdvHandle bdvh,
121+
String pathHierarchy, int skipTopLevels, Runnable runnable) {
122+
addActionToBdvHandleMenu(bdvh, pathHierarchy, skipTopLevels, runnable, null, null);
111123
}
112124

113125
static public void addActionToBdvHandleMenu(BdvHandle bdvh,
114-
String pathHierarchy, int skipTopLevels, Runnable runnable)
126+
String pathHierarchy, int skipTopLevels, Runnable runnable, String iconPath, String description)
115127
{
116128
if (bdvh instanceof BdvHandleFrame) {
117129
final JMenuBar bdvMenuBar = ((BdvHandleFrame) bdvh).getBigDataViewer()
@@ -126,6 +138,18 @@ static public void addActionToBdvHandleMenu(BdvHandle bdvh,
126138
JMenuItem jMenuItemRoot = findOrCreateJMenu(bdvMenuBar, path);
127139
if (jMenuItemRoot != null) {
128140
final JMenuItem jMenuItem = new JMenuItem(path.get(path.size() - 1));
141+
142+
if ((iconPath!=null) && (!iconPath.isEmpty())) {
143+
URL iconURL = BdvScijavaHelper.class.getResource(iconPath);
144+
ImageIcon iconRotX = new ImageIcon(iconURL);
145+
Icon icon = new ImageIcon( iconRotX.getImage().getScaledInstance( 32, 32, java.awt.Image.SCALE_SMOOTH ) );
146+
jMenuItem.setIcon(icon);
147+
}
148+
149+
if ((description!=null) && (!description.isEmpty())) {
150+
jMenuItem.setToolTipText(description);
151+
}
152+
129153
jMenuItem.addActionListener(e -> runnable.run());
130154
jMenuItemRoot.add(jMenuItem);
131155
bdvMenuBar.updateUI();

0 commit comments

Comments
 (0)