1 | package org.openstreetmap.josm.plugins.osminspector;
|
---|
2 |
|
---|
3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
4 |
|
---|
5 | import java.awt.event.KeyEvent;
|
---|
6 | import java.awt.event.MouseEvent;
|
---|
7 | import java.awt.event.MouseListener;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.data.Bounds;
|
---|
10 | import org.openstreetmap.josm.data.UserIdentityManager;
|
---|
11 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
12 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
13 | import org.openstreetmap.josm.gui.NavigatableComponent;
|
---|
14 | import org.openstreetmap.josm.gui.NavigatableComponent.ZoomChangeListener;
|
---|
15 | import org.openstreetmap.josm.gui.download.DownloadDialog;
|
---|
16 | import org.openstreetmap.josm.gui.download.DownloadSelection;
|
---|
17 | import org.openstreetmap.josm.plugins.Plugin;
|
---|
18 | import org.openstreetmap.josm.plugins.PluginInformation;
|
---|
19 | import org.openstreetmap.josm.spi.preferences.Config;
|
---|
20 | import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent;
|
---|
21 | import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener;
|
---|
22 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
23 |
|
---|
24 | public class OsmInspectorPlugin extends Plugin
|
---|
25 | implements ZoomChangeListener,
|
---|
26 | MouseListener, PreferenceChangedListener, DownloadSelection{
|
---|
27 |
|
---|
28 | /** The JOSM user identity manager, it is used for obtaining the user name */
|
---|
29 | private final UserIdentityManager userIdentityManager;
|
---|
30 |
|
---|
31 |
|
---|
32 | /** The bounding box from where the MapDust bugs are down-loaded */
|
---|
33 | //private Bounds bBox;
|
---|
34 |
|
---|
35 | private OsmInspectorLayer inspectorLayer;
|
---|
36 |
|
---|
37 | public OsmInspectorPlugin(PluginInformation info) {
|
---|
38 | super(info);
|
---|
39 | userIdentityManager = UserIdentityManager.getInstance();
|
---|
40 | initializePlugin();
|
---|
41 | }
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Initialize the <code>OsmInspectorPlugin</code> object. Creates the
|
---|
45 | * <code>OsmInspectorGUI</code> and initializes the following variables with
|
---|
46 | *.
|
---|
47 | */
|
---|
48 | private void initializePlugin() {
|
---|
49 | Shortcut.registerShortcut("OsmInspector", tr("Toggle: {0}", tr("Open OsmInspector")),
|
---|
50 | KeyEvent.VK_1, Shortcut.ALT_SHIFT);
|
---|
51 | //String name = "Osm Inspector error reports";
|
---|
52 | //String tooltip = "Activates the Osm Inspector reporter plugin";
|
---|
53 |
|
---|
54 | /* add default values for static variables */
|
---|
55 | Config.getPref().put("osmInspector.nickname", "osmi");
|
---|
56 | Config.getPref().putBoolean("osmInspector.showBugs", true);
|
---|
57 | Config.getPref().put("osmInspector.version", getPluginInformation().version);
|
---|
58 | Config.getPref().put("osmInspector.localVersion",getPluginInformation().localversion);
|
---|
59 | inspectorLayer = null;
|
---|
60 | }
|
---|
61 | @Override
|
---|
62 | public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
|
---|
63 | MainApplication.getToolbar().register( new ImportOsmInspectorBugsAction( this ) );
|
---|
64 | if (newFrame == null) {
|
---|
65 | /* if new MapFrame is null, remove listener */
|
---|
66 | NavigatableComponent.removeZoomChangeListener(this);
|
---|
67 | } else {
|
---|
68 | /* add MapDust dialog window */
|
---|
69 | if (MainApplication.getMap() != null && MainApplication.getMap().mapView != null) {
|
---|
70 | /* add MapdustGUI */
|
---|
71 | MainApplication.getMap().setBounds(newFrame.getBounds());
|
---|
72 |
|
---|
73 | /* add Listeners */
|
---|
74 | NavigatableComponent.addZoomChangeListener(this);
|
---|
75 | MainApplication.getMap().mapView.addMouseListener(this);
|
---|
76 | Config.getPref().addPreferenceChangeListener(this);
|
---|
77 | /* put username to preferences */
|
---|
78 | Config.getPref().put("osmInspector.josmUserName",
|
---|
79 | userIdentityManager.getUserName());
|
---|
80 | MainApplication.getToolbar().control.add( new ImportOsmInspectorBugsAction( this ) );
|
---|
81 | }
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | @Override
|
---|
86 | public void zoomChanged() {
|
---|
87 |
|
---|
88 | }
|
---|
89 |
|
---|
90 | @Override
|
---|
91 | //
|
---|
92 | // Delegate feature selection to layer
|
---|
93 | //
|
---|
94 | public void mouseClicked(MouseEvent e) {
|
---|
95 | if (inspectorLayer != null) {
|
---|
96 | inspectorLayer.selectFeatures(e.getX(), e.getY());
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | @Override
|
---|
101 | public void mouseEntered(MouseEvent e) {
|
---|
102 |
|
---|
103 | }
|
---|
104 |
|
---|
105 | @Override
|
---|
106 | public void mouseExited(MouseEvent e) {
|
---|
107 |
|
---|
108 | }
|
---|
109 |
|
---|
110 | @Override
|
---|
111 | public void mousePressed(MouseEvent e) {
|
---|
112 |
|
---|
113 | }
|
---|
114 |
|
---|
115 | @Override
|
---|
116 | public void mouseReleased(MouseEvent e) {
|
---|
117 |
|
---|
118 | }
|
---|
119 |
|
---|
120 | @Override
|
---|
121 | public void preferenceChanged(PreferenceChangeEvent e) {
|
---|
122 |
|
---|
123 | }
|
---|
124 |
|
---|
125 | public OsmInspectorLayer getLayer()
|
---|
126 | {
|
---|
127 | return inspectorLayer;
|
---|
128 | }
|
---|
129 |
|
---|
130 | public void setLayer( OsmInspectorLayer theLayer )
|
---|
131 | {
|
---|
132 | inspectorLayer = theLayer;
|
---|
133 | }
|
---|
134 |
|
---|
135 | @Override
|
---|
136 | public void addGui(DownloadDialog gui) {
|
---|
137 | // TODO Auto-generated method stub
|
---|
138 | }
|
---|
139 |
|
---|
140 | @Override
|
---|
141 | public void setDownloadArea(Bounds bounds) {
|
---|
142 | // TODO Auto-generated method stub
|
---|
143 | }
|
---|
144 | }
|
---|