Changeset 1638 in osm for utils/josm
- Timestamp:
- 2006-11-25T16:42:31+01:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
utils/josm/plugins/osmarender/src/OsmarenderPlugin.java
r1467 r1638 8 8 9 9 import javax.swing.AbstractAction; 10 import javax.swing.JLabel; 10 11 import javax.swing.JMenu; 11 12 import javax.swing.JMenuBar; 12 13 import javax.swing.JMenuItem; 13 14 import javax.swing.JOptionPane; 15 import javax.swing.JTextField; 14 16 15 17 import org.openstreetmap.josm.Main; … … 22 24 import org.openstreetmap.josm.data.osm.visitor.AddVisitor; 23 25 import org.openstreetmap.josm.gui.MapFrame; 26 import org.openstreetmap.josm.gui.preferences.PreferenceDialog; 27 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 24 28 import org.openstreetmap.josm.io.OsmWriter; 25 29 import org.openstreetmap.josm.plugins.Plugin; 30 import org.openstreetmap.josm.tools.GBC; 26 31 27 32 28 33 public class OsmarenderPlugin extends Plugin { 29 34 30 35 private class Action extends AbstractAction { 31 36 32 33 34 37 public Action() { 38 super("Osmarender"); 39 } 35 40 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 41 public void actionPerformed(ActionEvent e) { 42 // get all stuff visible on screen 43 LatLon bottomLeft = Main.map.mapView.getLatLon(0,Main.map.mapView.getHeight()); 44 LatLon topRight = Main.map.mapView.getLatLon(Main.map.mapView.getWidth(), 0); 45 Bounds b = new Bounds(bottomLeft, topRight); 46 Collection<Node> nodes = new HashSet<Node>(); 47 DataSet fromDataSet = new DataSet(); 48 AddVisitor adder = new AddVisitor(fromDataSet); 49 for (Node n : Main.ds.nodes) { 50 if (n.coor.isWithin(b)) { 51 n.visit(adder); 52 nodes.add(n); 53 } 54 } 55 Collection<Segment> segments = new HashSet<Segment>(); 56 for (Segment s : Main.ds.segments) { 57 if (nodes.contains(s.from) || nodes.contains(s.to)) { 58 s.visit(adder); 59 segments.add(s); 60 } 61 } 62 for (Way w : Main.ds.ways) { 63 for (Segment s : w.segments) { 64 if (segments.contains(s)) { 65 w.visit(adder); 66 break; 67 } 68 } 69 } 65 70 66 String firefox = Main.pref.get("osmarender.firefox", "firefox"); 67 boolean retry = false; 68 do { 69 try { 70 retry = false; 71 String firefox = Main.pref.get("osmarender.firefox", "firefox"); 72 try { 73 // write to plugin dir 74 OsmWriter.output(new FileOutputStream(getPluginDir()+"data.osm"), new OsmWriter.All(fromDataSet, true)); 71 75 72 // write to plugin dir 73 OsmWriter.output(new FileOutputStream(getPluginDir()+"data.osm"), new OsmWriter.All(fromDataSet, true)); 76 // get the exec line 77 String exec = firefox; 78 if (System.getProperty("os.name").startsWith("Windows")) 79 exec += " file:///"+getPluginDir().replace('\\','/').replace(" ","%20")+"osm-map-features.xml\""; 80 else 81 exec += " "+getPluginDir()+"osm-map-features.xml"; 74 82 75 // get the exec line 76 String exec = firefox; 77 if (System.getProperty("os.name").startsWith("Windows")) 78 exec += " file:///"+getPluginDir().replace('\\','/').replace(" ","%20")+"osm-map-features.xml\""; 79 else 80 exec += " "+getPluginDir()+"osm-map-features.xml"; 83 // launch up the viewer 84 Runtime.getRuntime().exec(exec); 85 } catch (IOException e1) { 86 JOptionPane.showMessageDialog(Main.parent, tr("FireFox not found. Please set firefox executable in the preferences.")); 87 } 88 } 89 } 81 90 82 // launch up the viewer 83 Runtime.getRuntime().exec(exec); 84 } catch (IOException e1) { 85 firefox = JOptionPane.showInputDialog(Main.parent, "FireFox not found. Please enter location of firefox executable"); 86 if (firefox != null) { 87 Main.pref.put("osmarender.firefox", firefox); 88 retry = true; 89 } 90 } 91 } while (retry); 92 } 93 } 91 private JMenu view; 92 private JMenuItem osmarenderMenu = new JMenuItem(new Action()); 94 93 95 private JMenu view; 96 private JMenuItem osmarenderMenu = new JMenuItem(new Action()); 94 public OsmarenderPlugin() throws IOException { 95 JMenuBar menu = Main.main.menu; 96 view = null; 97 for (int i = 0; i < menu.getMenuCount(); ++i) { 98 if (menu.getMenu(i) != null && tr("View").equals(menu.getMenu(i).getName())) { 99 view = menu.getMenu(i); 100 break; 101 } 102 } 103 if (view == null) { 104 view = new JMenu(tr("View")); 105 menu.add(view, 2); 106 view.setVisible(false); 107 } 108 view.add(osmarenderMenu); 109 osmarenderMenu.setVisible(false); 97 110 98 public OsmarenderPlugin() throws IOException { 99 JMenuBar menu = Main.main.menu; 100 view = null; 101 for (int i = 0; i < menu.getMenuCount(); ++i) { 102 if (menu.getMenu(i) != null && tr("View").equals(menu.getMenu(i).getName())) { 103 view = menu.getMenu(i); 104 break; 105 } 106 } 107 if (view == null) { 108 view = new JMenu(tr("View")); 109 menu.add(view, 2); 110 view.setVisible(false); 111 } 112 view.add(osmarenderMenu); 113 osmarenderMenu.setVisible(false); 111 // install the xsl and xml file 112 copy("/osmarender.xsl", "osmarender.xsl"); 113 copy("/osm-map-features.xml", "osm-map-features.xml"); 114 } 114 115 115 // install the xsl and xml file 116 copy("/osmarender.xsl", "osmarender.xsl"); 117 copy("/osm-map-features.xml", "osm-map-features.xml"); 118 } 116 @Override 117 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 118 if (oldFrame != null && newFrame == null) { 119 // disable 120 osmarenderMenu.setVisible(false); 121 if (view.getMenuComponentCount() == 1) 122 view.setVisible(false); 123 } else if (oldFrame == null && newFrame != null) { 124 // enable 125 osmarenderMenu.setVisible(true); 126 if (view.getMenuComponentCount() == 1) 127 view.setVisible(true); 128 } 129 } 119 130 120 @Override 121 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame){122 if (oldFrame != null && newFrame == null) { 123 // disable 124 osmarenderMenu.setVisible(false);125 if (view.getMenuComponentCount() == 1) 126 view.setVisible(false);127 } else if (oldFrame == null && newFrame != null) { 128 // enable 129 osmarenderMenu.setVisible(true); 130 if (view.getMenuComponentCount() == 1) 131 view.setVisible(true); 132 } 133 131 @Override public PreferenceSetting getPreferenceSetting() { 132 return new PreferenceSetting(){ 133 private JTextField firefox = new JTextField(10); 134 public void addGui(PreferenceDialog gui) { 135 gui.map.add(new JLabel(tr("osmarender options")), GBC.eol().insets(0,5,0,0)); 136 gui.map.add(new JLabel(tr("FireFox executable")), GBC.std().insets(10,5,5,0)); 137 gui.map.add(firefox, GBC.eol().insets(0,5,0,0).fill(GBC.HORIZONTAL)); 138 firefox.setText(Main.pref.get("osmarender.firefox")); 139 } 140 public void ok() { 141 Main.pref.put("osmarender.firefox", firefox.getText()); 142 } 143 }; 144 } 134 145 }
Note:
See TracChangeset
for help on using the changeset viewer.