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

Last change on this file since 34360 was 33788, checked in by donvip, 8 years ago

update to JOSM 12643

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