Ignore:
Timestamp:
2020-01-04T20:07:39+01:00 (4 years ago)
Author:
Don-vip
Message:

fix #18510 - Add icons to move up/down/left/right actions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/MoveAction.java

    r14960 r15630  
    88import java.awt.event.KeyEvent;
    99import java.util.Collection;
     10import java.util.Locale;
    1011
    1112import javax.swing.JOptionPane;
     
    3536    public enum Direction {
    3637        /** Move up */
    37         UP,
     38        UP(tr("up"), "up", KeyEvent.VK_UP),
    3839        /** Move left */
    39         LEFT,
     40        LEFT(tr("left"), "previous", KeyEvent.VK_LEFT),
    4041        /** Move right */
    41         RIGHT,
     42        RIGHT(tr("right"), "next", KeyEvent.VK_RIGHT),
    4243        /** Move down */
    43         DOWN
     44        DOWN(tr("down"), "down", KeyEvent.VK_DOWN);
     45
     46        private final String localizedName;
     47        private final String icon;
     48        private final int shortcutKey;
     49
     50        Direction(String localizedName, String icon, int shortcutKey) {
     51            this.localizedName = localizedName;
     52            this.icon = icon;
     53            this.shortcutKey = shortcutKey;
     54        }
     55
     56        String getId() {
     57            return name().toLowerCase(Locale.ENGLISH);
     58        }
     59
     60        String getLocalizedName() {
     61            return localizedName;
     62        }
     63
     64        String getIcon() {
     65            return "dialogs/" + icon;
     66        }
     67
     68        String getToolbarName() {
     69            return "action/move/" + getId();
     70        }
     71
     72        int getShortcutKey() {
     73            return shortcutKey;
     74        }
     75
     76        Shortcut getShortcut() {
     77            return Shortcut.registerShortcut(
     78                    "core:move" + getId(), tr("Move objects {0}", getLocalizedName()), getShortcutKey(), Shortcut.SHIFT);
     79        }
    4480    }
    4581
    4682    private final Direction myDirection;
    47 
    48     // any better idea?
    49     private static String calltosupermustbefirststatementinconstructortext(Direction dir) {
    50         String directiontext;
    51         if (dir == Direction.UP) {
    52             directiontext = tr("up");
    53         } else if (dir == Direction.DOWN) {
    54             directiontext = tr("down");
    55         } else if (dir == Direction.LEFT) {
    56             directiontext = tr("left");
    57         } else {
    58             directiontext = tr("right");
    59         }
    60         return directiontext;
    61     }
    62 
    63     // any better idea?
    64     private static Shortcut calltosupermustbefirststatementinconstructor(Direction dir) {
    65         Shortcut sc;
    66         // CHECKSTYLE.OFF: SingleSpaceSeparator
    67         if (dir == Direction.UP) {
    68             sc = Shortcut.registerShortcut("core:moveup",    tr("Move objects {0}", tr("up")),    KeyEvent.VK_UP,    Shortcut.SHIFT);
    69         } else if (dir == Direction.DOWN) {
    70             sc = Shortcut.registerShortcut("core:movedown",  tr("Move objects {0}", tr("down")),  KeyEvent.VK_DOWN,  Shortcut.SHIFT);
    71         } else if (dir == Direction.LEFT) {
    72             sc = Shortcut.registerShortcut("core:moveleft",  tr("Move objects {0}", tr("left")),  KeyEvent.VK_LEFT,  Shortcut.SHIFT);
    73         } else { //dir == Direction.RIGHT
    74             sc = Shortcut.registerShortcut("core:moveright", tr("Move objects {0}", tr("right")), KeyEvent.VK_RIGHT, Shortcut.SHIFT);
    75         }
    76         // CHECKSTYLE.ON: SingleSpaceSeparator
    77         return sc;
    78     }
    7983
    8084    /**
     
    8387     */
    8488    public MoveAction(Direction dir) {
    85         super(tr("Move {0}", calltosupermustbefirststatementinconstructortext(dir)), null,
    86                 tr("Moves Objects {0}", calltosupermustbefirststatementinconstructortext(dir)),
    87                 calltosupermustbefirststatementinconstructor(dir), false);
     89        super(tr("Move {0}", dir.getLocalizedName()), dir.getIcon(),
     90                tr("Moves Objects {0}", dir.getLocalizedName()),
     91                dir.getShortcut(), true, dir.getToolbarName(), true);
    8892        myDirection = dir;
    8993        setHelpId(ht("/Action/Move"));
    90         if (dir == Direction.UP) {
    91             putValue("toolbar", "action/move/up");
    92         } else if (dir == Direction.DOWN) {
    93             putValue("toolbar", "action/move/down");
    94         } else if (dir == Direction.LEFT) {
    95             putValue("toolbar", "action/move/left");
    96         } else { //dir == Direction.RIGHT
    97             putValue("toolbar", "action/move/right");
    98         }
    99         MainApplication.getToolbar().register(this);
    10094    }
    10195
Note: See TracChangeset for help on using the changeset viewer.