[744] | 1 | package org.openstreetmap.josm.gui;
|
---|
| 2 |
|
---|
| 3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
[2017] | 4 |
|
---|
| 5 | import java.awt.Image;
|
---|
| 6 | import java.awt.Insets;
|
---|
[744] | 7 | import java.awt.event.ActionListener;
|
---|
[2017] | 8 |
|
---|
[744] | 9 | import javax.swing.Action;
|
---|
[2586] | 10 | import javax.swing.Icon;
|
---|
[2017] | 11 | import javax.swing.ImageIcon;
|
---|
[744] | 12 | import javax.swing.JButton;
|
---|
| 13 |
|
---|
[1103] | 14 | import org.openstreetmap.josm.Main;
|
---|
[744] | 15 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
[1102] | 16 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
[744] | 17 |
|
---|
| 18 | public class SideButton extends JButton {
|
---|
[1169] | 19 | public SideButton(Action action)
|
---|
| 20 | {
|
---|
| 21 | super(action);
|
---|
[2586] | 22 | fixIcon();
|
---|
[1169] | 23 | doStyle();
|
---|
| 24 | }
|
---|
[1227] | 25 |
|
---|
[2710] | 26 | public SideButton(Action action, boolean usename)
|
---|
| 27 | {
|
---|
| 28 | super(action);
|
---|
| 29 | if(!usename)
|
---|
| 30 | setText(null);
|
---|
| 31 | fixIcon();
|
---|
| 32 | doStyle();
|
---|
| 33 | }
|
---|
| 34 |
|
---|
[1247] | 35 | public SideButton(Action action, String imagename)
|
---|
| 36 | {
|
---|
[2586] | 37 | super(action);
|
---|
[1247] | 38 | setIcon(makeIcon(imagename));
|
---|
[2586] | 39 | doStyle();
|
---|
[1247] | 40 | }
|
---|
| 41 |
|
---|
[2586] | 42 | void fixIcon() {
|
---|
| 43 | Icon i = getIcon();
|
---|
| 44 | if(i != null && i instanceof ImageIcon)
|
---|
| 45 | {
|
---|
| 46 | Image im = ((ImageIcon) i).getImage();
|
---|
| 47 | setIcon(new ImageIcon(im.getScaledInstance(20 , 20, Image.SCALE_SMOOTH)));
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
| 50 |
|
---|
[1246] | 51 | public static ImageIcon makeIcon(String imagename) {
|
---|
[1227] | 52 | Image im = ImageProvider.get("dialogs", imagename).getImage();
|
---|
| 53 | return new ImageIcon(im.getScaledInstance(20 , 20, Image.SCALE_SMOOTH));
|
---|
| 54 | }
|
---|
| 55 |
|
---|
[1169] | 56 | public SideButton(String imagename, String property, String tooltip, ActionListener actionListener)
|
---|
| 57 | {
|
---|
[1246] | 58 | super(makeIcon(imagename));
|
---|
[1169] | 59 | doStyle();
|
---|
| 60 | setActionCommand(imagename);
|
---|
| 61 | addActionListener(actionListener);
|
---|
| 62 | setToolTipText(tooltip);
|
---|
| 63 | }
|
---|
| 64 | public SideButton(String name, String imagename, String property, String tooltip, Shortcut shortcut, ActionListener actionListener)
|
---|
| 65 | {
|
---|
[1246] | 66 | super(tr(name), makeIcon(imagename));
|
---|
[1169] | 67 | if(shortcut != null)
|
---|
[1246] | 68 | {
|
---|
[1169] | 69 | shortcut.setMnemonic(this);
|
---|
[1790] | 70 | if(tooltip != null) {
|
---|
[1169] | 71 | tooltip = Main.platform.makeTooltip(tooltip, shortcut);
|
---|
[1790] | 72 | }
|
---|
[1246] | 73 | }
|
---|
[1169] | 74 | setup(name, property, tooltip, actionListener);
|
---|
| 75 | }
|
---|
| 76 | public SideButton(String name, String imagename, String property, String tooltip, ActionListener actionListener)
|
---|
| 77 | {
|
---|
[1246] | 78 | super(tr(name), makeIcon(imagename));
|
---|
[1169] | 79 | setup(name, property, tooltip, actionListener);
|
---|
| 80 | }
|
---|
| 81 | private void setup(String name, String property, String tooltip, ActionListener actionListener)
|
---|
| 82 | {
|
---|
| 83 | doStyle();
|
---|
| 84 | setActionCommand(name);
|
---|
| 85 | addActionListener(actionListener);
|
---|
| 86 | setToolTipText(tooltip);
|
---|
| 87 | putClientProperty("help", "Dialog/"+property+"/"+name);
|
---|
| 88 | }
|
---|
| 89 | private void doStyle()
|
---|
| 90 | {
|
---|
| 91 | setMargin(new Insets(1,1,1,1));
|
---|
| 92 | setIconTextGap(2);
|
---|
| 93 | }
|
---|
[744] | 94 | }
|
---|