| 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.Main;
|
|---|
| 13 | import org.openstreetmap.josm.actions.JosmAction;
|
|---|
| 14 | import org.openstreetmap.josm.gui.MainApplication;
|
|---|
| 15 | import org.openstreetmap.josm.gui.MapFrame;
|
|---|
| 16 | import org.openstreetmap.josm.plugins.Plugin;
|
|---|
| 17 | import org.openstreetmap.josm.plugins.PluginInformation;
|
|---|
| 18 |
|
|---|
| 19 | /**
|
|---|
| 20 | * Add NanoLog opening menu item and the panel.
|
|---|
| 21 | *
|
|---|
| 22 | * @author zverik
|
|---|
| 23 | */
|
|---|
| 24 | public 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 | }
|
|---|