| [27939] | 1 | package nanolog;
|
|---|
| 2 |
|
|---|
| [32447] | 3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 4 |
|
|---|
| [27939] | 5 | import java.awt.event.ActionEvent;
|
|---|
| [30491] | 6 | import java.io.IOException;
|
|---|
| 7 | import java.util.List;
|
|---|
| [32447] | 8 |
|
|---|
| [27939] | 9 | import javax.swing.JFileChooser;
|
|---|
| [30491] | 10 | import javax.swing.JOptionPane;
|
|---|
| [32447] | 11 |
|
|---|
| [27939] | 12 | import org.openstreetmap.josm.actions.JosmAction;
|
|---|
| [33788] | 13 | import org.openstreetmap.josm.gui.MainApplication;
|
|---|
| [27939] | 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.
|
|---|
| [32638] | 20 | *
|
|---|
| [27939] | 21 | * @author zverik
|
|---|
| 22 | */
|
|---|
| 23 | public class NanoLogPlugin extends Plugin {
|
|---|
| [32638] | 24 | public NanoLogPlugin(PluginInformation info) {
|
|---|
| [27939] | 25 | super(info);
|
|---|
| [33788] | 26 | MainApplication.getMenu().fileMenu.insert(new OpenNanoLogLayerAction(), 4);
|
|---|
| [27939] | 27 | }
|
|---|
| [32638] | 28 |
|
|---|
| [27939] | 29 | @Override
|
|---|
| [32638] | 30 | public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
|
|---|
| 31 | if (oldFrame == null && newFrame != null) {
|
|---|
| [30491] | 32 | NanoLogPanel panel = new NanoLogPanel();
|
|---|
| 33 | newFrame.addToggleDialog(panel);
|
|---|
| [33788] | 34 | MainApplication.getLayerManager().addLayerChangeListener(panel);
|
|---|
| [27939] | 35 | }
|
|---|
| 36 | }
|
|---|
| [32638] | 37 |
|
|---|
| [33788] | 38 | private static class OpenNanoLogLayerAction extends JosmAction {
|
|---|
| [27939] | 39 |
|
|---|
| [32638] | 40 | OpenNanoLogLayerAction() {
|
|---|
| [27939] | 41 | super(tr("Open NanoLog file..."), "nanolog.png", tr("Open NanoLog file..."), null, false);
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| [32638] | 44 | @Override
|
|---|
| 45 | public void actionPerformed(ActionEvent e) {
|
|---|
| [27939] | 46 | JFileChooser fc = new JFileChooser();
|
|---|
| [34533] | 47 | if (fc.showOpenDialog(MainApplication.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
|
|---|
| [30491] | 48 | try {
|
|---|
| 49 | List<NanoLogEntry> entries = NanoLogLayer.readNanoLog(fc.getSelectedFile());
|
|---|
| [32638] | 50 | if (!entries.isEmpty()) {
|
|---|
| [30491] | 51 | NanoLogLayer layer = new NanoLogLayer(entries);
|
|---|
| [33788] | 52 | MainApplication.getLayerManager().addLayer(layer);
|
|---|
| [31981] | 53 | layer.setupListeners();
|
|---|
| [30491] | 54 | }
|
|---|
| [32638] | 55 | } catch (IOException ex) {
|
|---|
| [34533] | 56 | JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("Could not read NanoLog file:") + "\n" + ex.getMessage());
|
|---|
| [30491] | 57 | }
|
|---|
| [27939] | 58 | }
|
|---|
| [32638] | 59 | }
|
|---|
| [27939] | 60 | }
|
|---|
| 61 | }
|
|---|