1 | package org.openstreetmap.josm.gui;
|
---|
2 |
|
---|
3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
4 |
|
---|
5 | import java.awt.Image;
|
---|
6 | import java.awt.Insets;
|
---|
7 | import java.awt.event.ActionListener;
|
---|
8 |
|
---|
9 | import javax.swing.Action;
|
---|
10 | import javax.swing.ImageIcon;
|
---|
11 | import javax.swing.JButton;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.Main;
|
---|
14 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
15 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
16 |
|
---|
17 | public class SideButton extends JButton {
|
---|
18 | public SideButton(Action action)
|
---|
19 | {
|
---|
20 | super(action);
|
---|
21 | doStyle();
|
---|
22 | }
|
---|
23 |
|
---|
24 | public SideButton(Action action, String imagename)
|
---|
25 | {
|
---|
26 | this(action);
|
---|
27 | setIcon(makeIcon(imagename));
|
---|
28 | }
|
---|
29 |
|
---|
30 | public static ImageIcon makeIcon(String imagename) {
|
---|
31 | Image im = ImageProvider.get("dialogs", imagename).getImage();
|
---|
32 | return new ImageIcon(im.getScaledInstance(20 , 20, Image.SCALE_SMOOTH));
|
---|
33 | }
|
---|
34 |
|
---|
35 | public SideButton(String imagename, String property, String tooltip, ActionListener actionListener)
|
---|
36 | {
|
---|
37 | super(makeIcon(imagename));
|
---|
38 | doStyle();
|
---|
39 | setActionCommand(imagename);
|
---|
40 | addActionListener(actionListener);
|
---|
41 | setToolTipText(tooltip);
|
---|
42 | }
|
---|
43 | public SideButton(String name, String imagename, String property, String tooltip, Shortcut shortcut, ActionListener actionListener)
|
---|
44 | {
|
---|
45 | super(tr(name), makeIcon(imagename));
|
---|
46 | if(shortcut != null)
|
---|
47 | {
|
---|
48 | shortcut.setMnemonic(this);
|
---|
49 | if(tooltip != null) {
|
---|
50 | tooltip = Main.platform.makeTooltip(tooltip, shortcut);
|
---|
51 | }
|
---|
52 | }
|
---|
53 | setup(name, property, tooltip, actionListener);
|
---|
54 | }
|
---|
55 | public SideButton(String name, String imagename, String property, String tooltip, ActionListener actionListener)
|
---|
56 | {
|
---|
57 | super(tr(name), makeIcon(imagename));
|
---|
58 | setup(name, property, tooltip, actionListener);
|
---|
59 | }
|
---|
60 | private void setup(String name, String property, String tooltip, ActionListener actionListener)
|
---|
61 | {
|
---|
62 | doStyle();
|
---|
63 | setActionCommand(name);
|
---|
64 | addActionListener(actionListener);
|
---|
65 | setToolTipText(tooltip);
|
---|
66 | putClientProperty("help", "Dialog/"+property+"/"+name);
|
---|
67 | }
|
---|
68 | private void doStyle()
|
---|
69 | {
|
---|
70 | setMargin(new Insets(1,1,1,1));
|
---|
71 | setIconTextGap(2);
|
---|
72 | }
|
---|
73 | }
|
---|