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

Last change on this file was 36483, checked in by stoecker, 4 months ago

set eol-style, fix checkstyle issues, add ignores

  • Property svn:eol-style set to native
File size: 2.1 KB
RevLine 
[27939]1package nanolog;
2
[32447]3import static org.openstreetmap.josm.tools.I18n.tr;
4
[27939]5import java.awt.event.ActionEvent;
[30491]6import java.io.IOException;
7import java.util.List;
[32447]8
[27939]9import javax.swing.JFileChooser;
[30491]10import javax.swing.JOptionPane;
[32447]11
[27939]12import org.openstreetmap.josm.actions.JosmAction;
[33788]13import org.openstreetmap.josm.gui.MainApplication;
[27939]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.
[32638]20 *
[27939]21 * @author zverik
22 */
23public 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}
Note: See TracBrowser for help on using the repository browser.