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

Last change on this file since 32447 was 32447, checked in by donvip, 8 years ago

remove calls to deprecated methods

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