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