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.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 | Main.main.menu.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 | Main.getLayerManager().addLayerChangeListener(panel);
|
---|
35 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | private class OpenNanoLogLayerAction extends JosmAction {
|
---|
39 |
|
---|
40 | public OpenNanoLogLayerAction() {
|
---|
41 | super(tr("Open NanoLog file..."), "nanolog.png", tr("Open NanoLog file..."), null, false);
|
---|
42 | }
|
---|
43 |
|
---|
44 | public void actionPerformed( ActionEvent e ) {
|
---|
45 | JFileChooser fc = new JFileChooser();
|
---|
46 | if( fc.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION ) {
|
---|
47 | try {
|
---|
48 | List<NanoLogEntry> entries = NanoLogLayer.readNanoLog(fc.getSelectedFile());
|
---|
49 | if( !entries.isEmpty() ) {
|
---|
50 | NanoLogLayer layer = new NanoLogLayer(entries);
|
---|
51 | Main.getLayerManager().addLayer(layer);
|
---|
52 | layer.setupListeners();
|
---|
53 | }
|
---|
54 | } catch( IOException ex ) {
|
---|
55 | JOptionPane.showMessageDialog(Main.parent, tr("Could not read NanoLog file:") + "\n" + ex.getMessage());
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|
59 | }
|
---|
60 | }
|
---|