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