source: osm/applications/editors/josm/plugins/NanoLog/src/nanolog/NanoLogPlugin.java@ 34533

Last change on this file since 34533 was 34533, checked in by donvip, 7 years ago

update to JOSM 14153

File size: 2.1 KB
Line 
1package nanolog;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.awt.event.ActionEvent;
6import java.io.IOException;
7import java.util.List;
8
9import javax.swing.JFileChooser;
10import javax.swing.JOptionPane;
11
12import org.openstreetmap.josm.actions.JosmAction;
13import org.openstreetmap.josm.gui.MainApplication;
14import org.openstreetmap.josm.gui.MapFrame;
15import org.openstreetmap.josm.plugins.Plugin;
16import org.openstreetmap.josm.plugins.PluginInformation;
17
18/**
19 * Add NanoLog opening menu item and the panel.
20 *
21 * @author zverik
22 */
23public class NanoLogPlugin extends Plugin {
24 public NanoLogPlugin(PluginInformation info) {
25 super(info);
26 MainApplication.getMenu().fileMenu.insert(new OpenNanoLogLayerAction(), 4);
27 }
28
29 @Override
30 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
31 if (oldFrame == null && newFrame != null) {
32 NanoLogPanel panel = new NanoLogPanel();
33 newFrame.addToggleDialog(panel);
34 MainApplication.getLayerManager().addLayerChangeListener(panel);
35 }
36 }
37
38 private static class OpenNanoLogLayerAction extends JosmAction {
39
40 OpenNanoLogLayerAction() {
41 super(tr("Open NanoLog file..."), "nanolog.png", tr("Open NanoLog file..."), null, false);
42 }
43
44 @Override
45 public void actionPerformed(ActionEvent e) {
46 JFileChooser fc = new JFileChooser();
47 if (fc.showOpenDialog(MainApplication.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
48 try {
49 List<NanoLogEntry> entries = NanoLogLayer.readNanoLog(fc.getSelectedFile());
50 if (!entries.isEmpty()) {
51 NanoLogLayer layer = new NanoLogLayer(entries);
52 MainApplication.getLayerManager().addLayer(layer);
53 layer.setupListeners();
54 }
55 } catch (IOException ex) {
56 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("Could not read NanoLog file:") + "\n" + ex.getMessage());
57 }
58 }
59 }
60 }
61}
Note: See TracBrowser for help on using the repository browser.