source: subversion/applications/editors/josm/plugins/imagery_offset_db/src/org/openstreetmap/josm/plugins/imagery_offset_db/ImageryOffsetPlugin.java

Last change on this file was 34596, checked in by donvip, 8 months ago

rename package, fix warnings

File size: 2.5 KB
Line 
1// License: WTFPL. For details, see LICENSE file.
2package org.openstreetmap.josm.plugins.imagery_offset_db;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.KeyEvent;
7import java.util.LinkedList;
8import java.util.List;
9
10import javax.swing.JMenu;
11
12import org.openstreetmap.josm.data.Version;
13import org.openstreetmap.josm.gui.MainApplication;
14import org.openstreetmap.josm.gui.preferences.ToolbarPreferences;
15import org.openstreetmap.josm.plugins.Plugin;
16import org.openstreetmap.josm.plugins.PluginInformation;
17import org.openstreetmap.josm.spi.preferences.Config;
18
19/**
20 * A plugin to request and store imagery offsets in the centralized database.
21 *
22 * @author Zverik
23 * @license WTFPL
24 */
25public class ImageryOffsetPlugin extends Plugin {
26    private GetImageryOffsetAction getAction;
27    private StoreImageryOffsetAction storeAction;
28
29    /**
30     * Add both actions to their own menu. This creates
31     * "Offset" menu, because "Imagery" is constantly rebuilt,
32     * losing all changes, and other menus are either too long already,
33     * or completely unsuitable for imagery offset actions.
34     * @param info Plugin information
35     */
36    public ImageryOffsetPlugin(PluginInformation info) {
37        super(info);
38
39        getAction = new GetImageryOffsetAction();
40        storeAction = new StoreImageryOffsetAction();
41
42        // before 5803 imagery menu was constantly regenerated, erasing extra items
43        // before 5729 it was regenerated only when the imagery list was modified (also bad)
44        int version = Version.getInstance().getVersion();
45        JMenu offsetMenu = version < 5803
46                ? MainApplication.getMenu().addMenu("Offset", tr("Offset"), KeyEvent.VK_O, 6, "help")
47                        : MainApplication.getMenu().imageryMenu;
48                offsetMenu.add(getAction);
49                offsetMenu.add(storeAction);
50
51                // an ugly hack to add this plugin to the toolbar
52                if (Config.getPref().getBoolean("iodb.modify.toolbar", true)) {
53                    List<String> toolbar = new LinkedList<>(ToolbarPreferences.getToolString());
54                    if (!toolbar.contains("getoffset")) {
55                        toolbar.add("getoffset");
56                        Config.getPref().putList("toolbar", toolbar);
57                        MainApplication.getToolbar().refreshToolbarControl();
58                    }
59                    Config.getPref().putBoolean("iodb.modify.toolbar", false);
60                }
61    }
62}
Note: See TracBrowser for help on using the repository browser.