1 | package nanolog;
|
---|
2 |
|
---|
3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
4 |
|
---|
5 | import java.awt.event.ActionEvent;
|
---|
6 | import java.io.IOException;
|
---|
7 | import java.util.List;
|
---|
8 |
|
---|
9 | import javax.swing.JFileChooser;
|
---|
10 | import javax.swing.JOptionPane;
|
---|
11 |
|
---|
12 | import org.openstreetmap.josm.actions.JosmAction;
|
---|
13 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
14 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
15 | import org.openstreetmap.josm.plugins.Plugin;
|
---|
16 | import org.openstreetmap.josm.plugins.PluginInformation;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Add NanoLog opening menu item and the panel.
|
---|
20 | *
|
---|
21 | * @author zverik
|
---|
22 | */
|
---|
23 | public 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 | }
|
---|