Skip to content

Commit 76fabee

Browse files
committed
added icons to some actions
1 parent 76e94c7 commit 76fabee

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

src/main/java/com/marginallyClever/nodeGraphSwing/Donatello.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,13 @@ private void setupTools() {
203203
private JMenu setupHelpMenu() {
204204
JMenu menu = new JMenu("Help");
205205

206-
menu.add(new BrowseURLAction("Check for updates","https://github.com/MarginallyClever/NodeGraphCore/releases"));
207-
menu.add(new BrowseURLAction("I have a problem...","https://github.com/MarginallyClever/NodeGraphCore/issues"));
206+
BrowseURLAction update = new BrowseURLAction("Check for updates","https://github.com/MarginallyClever/NodeGraphCore/releases");
207+
BrowseURLAction problem = new BrowseURLAction("I have a problem...","https://github.com/MarginallyClever/NodeGraphCore/issues");
208+
update.putValue(Action.SMALL_ICON, new UnicodeIcon("📰"));
209+
problem.putValue(Action.SMALL_ICON, new UnicodeIcon("☏"));
210+
211+
menu.add(update);
212+
menu.add(problem);
208213
menu.add(new BrowseURLAction("I have an idea!","https://github.com/MarginallyClever/NodeGraphCore/issues"));
209214
menu.add(new BrowseURLAction("Join the community","https://discord.gg/TbNHKz6rpy"));
210215
menu.add(new BrowseURLAction("Buy me a drink","https://www.paypal.com/donate/?hosted_button_id=Y3VZ66ZFNUWJE"));
@@ -249,6 +254,10 @@ private JMenu setupGraphMenu() {
249254
PrintGraphAction printGraphAction = new PrintGraphAction("Print",this);
250255
StraightenGraphAction straightenGraphAction = new StraightenGraphAction("Straighten",this);
251256

257+
newGraphAction.putValue(Action.SMALL_ICON,new UnicodeIcon("🌱"));
258+
printGraphAction.putValue(Action.SMALL_ICON,new UnicodeIcon("🖨️"));
259+
updateGraphAction.putValue(Action.SMALL_ICON,new UnicodeIcon("🔃"));
260+
252261
actions.add(newGraphAction);
253262
actions.add(saveGraphAction);
254263
actions.add(loadGraphAction);
@@ -295,6 +304,10 @@ private JMenu setupNodeMenu() {
295304
SelectAllAction selectAllAction = new SelectAllAction("Select all",this);
296305
InvertSelectionAction invertSelectionAction = new InvertSelectionAction("Invert selection",this);
297306

307+
cutGraphAction.putValue(Action.SMALL_ICON, new UnicodeIcon("✂"));
308+
addNodeAction.putValue(Action.SMALL_ICON, new UnicodeIcon("➕"));
309+
deleteGraphAction.putValue(Action.SMALL_ICON, new UnicodeIcon("🚫"));
310+
298311
actions.add(undoAction);
299312
actions.add(redoAction);
300313
actions.add(copyGraphAction);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.marginallyClever.nodeGraphSwing;
2+
3+
import javax.swing.*;
4+
import java.awt.*;
5+
import java.awt.font.FontRenderContext;
6+
import java.awt.geom.Rectangle2D;
7+
import java.awt.image.BufferedImage;
8+
9+
/**
10+
* Creates an Icon based on a Unicode symbol.
11+
* @author Dan Royer
12+
* @since 2022-03-15
13+
*/
14+
public class UnicodeIcon implements Icon {
15+
private final static int HEIGHT = 24;
16+
private final static int WIDTH = 24;
17+
private final String unicode;
18+
19+
public UnicodeIcon(String unicode) {
20+
super();
21+
this.unicode = unicode;
22+
}
23+
24+
@Override
25+
public void paintIcon(Component c, Graphics g, int x, int y) {
26+
//g.drawImage(image,0,0,new Color(1,1,1,1),null);
27+
Graphics g2 = g.create();
28+
Font font = new Font("SansSerif",Font.PLAIN,(int)((double)HEIGHT/1.25));
29+
g2.setFont(font);
30+
FontMetrics fm = g.getFontMetrics();
31+
int x2 = (WIDTH - fm.stringWidth(unicode)) / 2;
32+
int y2 = (fm.getAscent() + (HEIGHT - (fm.getAscent() + fm.getDescent())) / 2);
33+
34+
g2.setColor(Color.GRAY);
35+
g2.drawString(unicode,x2, y+y2);
36+
}
37+
38+
@Override
39+
public int getIconWidth() {
40+
return WIDTH;
41+
}
42+
43+
@Override
44+
public int getIconHeight() {
45+
return HEIGHT;
46+
}
47+
}

src/main/java/com/marginallyClever/nodeGraphSwing/actions/undoable/AddNodeAction.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class AddNodeAction extends AbstractAction {
2424
/**
2525
* Constructor for subclasses to call.
2626
* @param name the name of this action visible on buttons and menu items.
27+
* @param icon the small icon of this action visible on buttons and menu items.
2728
* @param editor the editor affected by this Action.
2829
*/
2930
public AddNodeAction(String name, Donatello editor) {

0 commit comments

Comments
 (0)