source: osm/applications/editors/josm/plugins/NanoLog/src/nanolog/NanoLogPlugin.java@ 30836

Last change on this file since 30836 was 30491, checked in by zverik, 11 years ago

wow, it works

File size: 2.0 KB
Line 
1package nanolog;
2
3import java.awt.event.ActionEvent;
4import java.io.IOException;
5import java.util.List;
6import javax.swing.JFileChooser;
7import javax.swing.JOptionPane;
8import org.openstreetmap.josm.Main;
9import org.openstreetmap.josm.actions.JosmAction;
10import org.openstreetmap.josm.gui.MapFrame;
11import org.openstreetmap.josm.gui.MapView;
12import org.openstreetmap.josm.plugins.Plugin;
13import org.openstreetmap.josm.plugins.PluginInformation;
14import static org.openstreetmap.josm.tools.I18n.tr;
15
16/**
17 * Add NanoLog opening menu item and the panel.
18 *
19 * @author zverik
20 */
21public 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}
Note: See TracBrowser for help on using the repository browser.