Index: /applications/editors/josm/plugins/openvisible/build.xml
===================================================================
--- /applications/editors/josm/plugins/openvisible/build.xml	(revision 5137)
+++ /applications/editors/josm/plugins/openvisible/build.xml	(revision 5137)
@@ -0,0 +1,140 @@
+<project name="openvisible" default="dist" basedir=".">
+
+	 <!-- compilation properties -->
+	  <property name="josm.build.dir" value="../../core"/>
+	  <property name="josm.home.dir" value="${user.home}/.josm"/>
+	  <property name="plugin.build.dir" value="bin"/>
+      <property name="plugin.dist.dir" value="dist"/>
+	  <property name="plugin.name" value="${ant.project.name}"/>
+	  <property name="plugin.jar" value="${plugin.name}.jar"/>
+	  
+	  <!-- plugin meta data (enter new version number if anything changed!) -->
+	  <property name="plugin.version" value="0.1"/>
+	  <property name="plugin.description" value="Allows opening gpx/osm files that intersect the currently visible screen area (V${plugin.version})."/>
+	  <property name="plugin.stage" value="50"/>
+    <property name="plugin.class" value="at.dallermassl.josm.plugin.openvisible.OpenVisiblePlugin"/>
+	  
+	  <!-- update site meta data -->
+	  <property name="plugin.site.file" value="josm-site.xml"/>
+	  <property name="plugin.site.description" value="Josm's OpenVisible Update Site"/>
+	  <property name="plugin.site.url" value="http://www.tegmento.org/~cdaller/josm/${ant.project.name}/"/>
+	  <property name="plugin.site.upload.target" value="cdaller@www.tegmento.org:public_html/josm/${ant.project.name}/"/>
+	  
+
+	<target name="dist" depends="compile,site">
+		<!-- images -->
+		<copy todir="${plugin.build.dir}/images">
+			<fileset dir="images" />
+		</copy>
+			<!-- copy configuration xml files 
+		<copy todir="${plugin.build.dir}">
+			<fileset dir="src"> 
+				<include name="*.xml"/>
+  		</fileset>
+		</copy>
+			-->
+		
+		<mkdir dir="dist"/>
+		
+    <!-- create jar file -->
+    <jar destfile="${plugin.dist.dir}/${plugin.jar}" basedir="${plugin.build.dir}">
+      <manifest>
+        <attribute name="Plugin-Class" value="${plugin.class}" />
+        <attribute name="Plugin-Description" value="${plugin.description}" />
+        <attribute name="Plugin-Version" value="${plugin.version}" />
+        <attribute name="Plugin-Dependencies" value="jgrapht-jdk1.5" />
+        <attribute name="Plugin-Stage" value="${plugin.stage}" />
+      </manifest>
+    </jar>
+	</target>
+
+	<target name="compile" depends="init">
+		<mkdir dir="${plugin.build.dir}"/>
+		<javac srcdir="src" destdir="${plugin.build.dir}" debug="true" source="1.5" target="1.5">
+			<classpath>
+				<pathelement path="${josm.build.dir}/build"/>
+	      <fileset dir="${josm.build.dir}/lib">
+	        <include name="**/*.jar"/>
+	      </fileset>
+              <!--
+        <fileset dir="lib">
+          <include name="**/*.jar"/>
+        </fileset>
+        -->
+			</classpath>
+	  </javac>
+	</target>
+
+  <target name="install" depends="dist">
+    <copy file="${plugin.dist.dir}/${plugin.jar}" todir="${josm.home.dir}/plugins" />
+  	<!--
+    <copy todir="${josm.home.dir}/plugins">
+    	<fileset dir="lib">
+        <include name="**/*.jar"/>
+    	</fileset>
+    </copy>
+  	-->
+  </target>
+
+  <target name="init">
+     <echo>java version: ${java.version}</echo>
+   </target>
+
+  <target name="clean">
+    <delete dir="${plugin.build.dir}" />
+    <delete dir="${plugin.site.file}" />
+    <delete dir="${plugin.jar}" />
+  </target>
+
+  <!-- write site description for the given plugin so josm will accept it -->
+  <target name="site">
+    <echo message="creating site description in ${plugin.site.file}"/>
+    <echo file="${plugin.site.file}">&lt;!-- plugins available on this site -->
+  &lt;plugins>
+    &lt;plugin id="${ant.project.name}" version="${plugin.version}">
+      &lt;name>${ant.project.name}&lt;/name>
+      &lt;description>${plugin.description}&lt;/description>
+      &lt;resource>${plugin.site.url}${plugin.jar}&lt;/resource>
+    &lt;/plugin>
+  &lt;/plugins>
+    </echo>
+  </target>
+
+  <!-- write site description for the given plugin (not implemented in JOSM as full version yet!) -->
+  <target name="site-full-donotuse">
+    <echo message="creating site description in ${plugin.site.file}"/>
+    <echo file="${plugin.site.file}">&lt;?xml version="1.0"?>
+&lt;site version="1.0">
+  &lt;!-- meta data of site -->
+  &lt;site-info>
+    &lt;site-name>${plugin.site.description}&lt;/site-name>
+    &lt;site-url>${plugin.site.url}&lt;/site-url>
+  &lt;/site-info>
+
+  &lt;!-- plugins available on this site -->
+  &lt;plugins>
+    &lt;plugin id="${ant.project.name}" version="${plugin.version}">
+      &lt;name>${ant.project.name}&lt;/name>
+      &lt;description>${plugin.description}&lt;/description>
+      &lt;resources>
+        &lt;resource src="${plugin.site.url}${plugin.jar}"
+                  target="${josm.home.dir}/plugins/${plugin.jar}"/>
+      &lt;/resources>
+    &lt;/plugin>
+  &lt;/plugins>
+&lt;/site>
+    </echo>
+  </target>
+
+
+  <!-- upload the site description and the jar file via ssh -->
+  <target name="upload" depends="dist,site">
+    <echo message="uploading jar and site description to ${plugin.site.upload.target}"/>
+    <exec executable="scp">
+      <arg value="${plugin.jar}"/>
+      <arg value="${plugin.site.file}"/>
+      <arg value="${plugin.site.upload.target}"/>
+    </exec>
+  </target>
+
+</project>
Index: /applications/editors/josm/plugins/openvisible/src/at/dallermassl/josm/plugin/openvisible/OpenVisibleAction.java
===================================================================
--- /applications/editors/josm/plugins/openvisible/src/at/dallermassl/josm/plugin/openvisible/OpenVisibleAction.java	(revision 5137)
+++ /applications/editors/josm/plugins/openvisible/src/at/dallermassl/josm/plugin/openvisible/OpenVisibleAction.java	(revision 5137)
@@ -0,0 +1,141 @@
+/**
+ * 
+ */
+package at.dallermassl.josm.plugin.openvisible;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.zip.GZIPInputStream;
+
+import javax.swing.AbstractAction;
+import javax.swing.JFileChooser;
+import javax.swing.JOptionPane;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.actions.ExtensionFileFilter;
+import org.openstreetmap.josm.actions.JosmAction;
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.DataSet;
+import org.openstreetmap.josm.gui.MapView;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer;
+import org.openstreetmap.josm.gui.layer.RawGpsLayer;
+import org.openstreetmap.josm.gui.layer.RawGpsLayer.GpsPoint;
+import org.openstreetmap.josm.gui.layer.markerlayer.Marker;
+import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
+import org.openstreetmap.josm.io.OsmReader;
+import org.openstreetmap.josm.io.RawCsvReader;
+import org.openstreetmap.josm.io.RawGpsReader;
+import org.openstreetmap.josm.tools.ImageProvider;
+import org.xml.sax.SAXException;
+
+/**
+ * @author cdaller
+ *
+ */
+public class OpenVisibleAction extends JosmAction {
+    private File lastDirectory;
+    
+    public OpenVisibleAction() {
+        super(tr("Open Visible"), "openvisible", tr("Open only files that are visible in current view."), KeyEvent.VK_O, 
+            InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK, true);
+    }
+
+    /* (non-Javadoc)
+     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+     */
+    public void actionPerformed(ActionEvent e) {
+        if(Main.map == null || Main.map.mapView == null) {
+            JOptionPane.showMessageDialog(Main.parent, tr("No view open - cannot determine boundaries!"));
+            return;
+        }
+        MapView view = Main.map.mapView;
+        Rectangle bounds = view.getBounds();
+        LatLon bottomLeft = view.getLatLon(bounds.x, bounds.y + bounds.height);
+        LatLon topRight = view.getLatLon(bounds.x + bounds.width, bounds.y);
+        
+        System.err.println("FileFind Bounds: " + bottomLeft + " to " + topRight);
+        
+        JFileChooser fileChooser;
+        if(lastDirectory != null) {
+            fileChooser = new JFileChooser(lastDirectory);
+        } else {
+            fileChooser = new JFileChooser();
+        }
+        fileChooser.setMultiSelectionEnabled(true);
+        fileChooser.showOpenDialog(Main.parent);
+        File[] files = fileChooser.getSelectedFiles();
+        lastDirectory = fileChooser.getCurrentDirectory();
+        
+        for(File file : files) {
+            try {
+                OsmGpxBounds parser = new OsmGpxBounds();
+                parser.parse(new BufferedInputStream(new FileInputStream(file)));
+                if(parser.intersects(bottomLeft.lat(), topRight.lat(), bottomLeft.lon(), topRight.lon())) {
+                    System.out.println(file.getAbsolutePath()); // + "," + parser.minLat + "," + parser.maxLat + "," + parser.minLon + "," + parser.maxLon);
+                    if(file.getName().endsWith("osm")) {
+                        openAsData(file);
+                    } else if(file.getName().endsWith("gpx")) {
+                        openFileAsRawGps(file);
+                    }
+                    
+                }
+            } catch (FileNotFoundException e1) {
+                e1.printStackTrace();
+            } catch (IOException e1) {
+                e1.printStackTrace();
+            } catch (SAXException e1) {
+                e1.printStackTrace();
+            }
+        }
+        
+    }
+    
+    private void openAsData(File file) throws SAXException, IOException, FileNotFoundException {
+        String fn = file.getName();
+        if (ExtensionFileFilter.filters[ExtensionFileFilter.OSM].acceptName(fn)) {
+            DataSet dataSet = OsmReader.parseDataSet(new FileInputStream(file), null, Main.pleaseWaitDlg);
+            OsmDataLayer layer = new OsmDataLayer(dataSet, file.getName(), file);
+            Main.main.addLayer(layer);
+        } else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn))
+            JOptionPane.showMessageDialog(Main.parent, fn+": "+tr("CSV Data import for non-GPS data is not implemented yet."));
+        else
+            JOptionPane.showMessageDialog(Main.parent, fn+": "+tr("Unknown file extension: {0}", fn.substring(file.getName().lastIndexOf('.')+1)));
+    }
+
+    private void openFileAsRawGps(File file) throws SAXException, IOException, FileNotFoundException {
+        String fn = file.getName();
+        Collection<Collection<GpsPoint>> gpsData = null;
+        Collection<Marker> markerData = null;
+        if (ExtensionFileFilter.filters[ExtensionFileFilter.GPX].acceptName(fn)) {
+            RawGpsReader r = null;
+            if (file.getName().endsWith(".gpx.gz"))
+                r = new RawGpsReader(new GZIPInputStream(new FileInputStream(file)), file.getAbsoluteFile().getParentFile());
+            else
+                r = new RawGpsReader(new FileInputStream(file), file.getAbsoluteFile().getParentFile());
+            gpsData = r.trackData;
+            markerData = r.markerData;
+        } else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) {
+            gpsData = new LinkedList<Collection<GpsPoint>>();
+            gpsData.add(new RawCsvReader(new FileReader(file)).parse());
+        } else
+            throw new IllegalStateException();
+        if (gpsData != null && !gpsData.isEmpty())
+            Main.main.addLayer(new RawGpsLayer(false, gpsData, tr("Tracks from {0}", file.getName()), file));
+        if (markerData != null && !markerData.isEmpty())
+            Main.main.addLayer(new MarkerLayer(markerData, tr ("Markers from {0}", file.getName()), file));
+    }
+
+
+}
Index: /applications/editors/josm/plugins/openvisible/src/at/dallermassl/josm/plugin/openvisible/OpenVisiblePlugin.java
===================================================================
--- /applications/editors/josm/plugins/openvisible/src/at/dallermassl/josm/plugin/openvisible/OpenVisiblePlugin.java	(revision 5137)
+++ /applications/editors/josm/plugins/openvisible/src/at/dallermassl/josm/plugin/openvisible/OpenVisiblePlugin.java	(revision 5137)
@@ -0,0 +1,29 @@
+/**
+ * 
+ */
+package at.dallermassl.josm.plugin.openvisible;
+
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.plugins.Plugin;
+
+/**
+ * @author cdaller
+ *
+ */
+public class OpenVisiblePlugin extends Plugin {
+    
+    public OpenVisiblePlugin() {
+        super();
+        JMenu fileMenu = Main.main.menu.fileMenu;
+        //JMenu navigatorMenu = new JMenu("Open Visible");
+        JMenuItem menuItem = new JMenuItem(new OpenVisibleAction());
+        
+        fileMenu.add(menuItem);
+
+    }
+
+}
Index: /applications/editors/josm/plugins/openvisible/src/at/dallermassl/josm/plugin/openvisible/OsmGpxBounds.java
===================================================================
--- /applications/editors/josm/plugins/openvisible/src/at/dallermassl/josm/plugin/openvisible/OsmGpxBounds.java	(revision 5137)
+++ /applications/editors/josm/plugins/openvisible/src/at/dallermassl/josm/plugin/openvisible/OsmGpxBounds.java	(revision 5137)
@@ -0,0 +1,122 @@
+/**
+ * 
+ */
+package at.dallermassl.josm.plugin.openvisible;
+
+import java.awt.geom.Rectangle2D;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * @author cdaller
+ *
+ */
+public class OsmGpxBounds extends DefaultHandler {
+    private double minLat = 180.0;
+    private double maxLat = -180.0;
+    private double minLon = 90.0;
+    private double maxLon = -90.0;
+    
+    public OsmGpxBounds() {
+        
+    }
+    
+    /**
+     * Parses the given input stream (gpx or osm file).
+     * @param in the stream to parse.
+     * @throws IOException if the file cannot be read.
+     * @throws SAXException if the file could not be parsed.
+     */
+    public void parse(InputStream in) throws IOException, SAXException {
+        try {
+            SAXParserFactory.newInstance().newSAXParser().parse(in, this);
+        } catch (ParserConfigurationException e1) {
+            e1.printStackTrace(); // broken SAXException chaining
+            throw new SAXException(e1);
+        }
+    }
+    
+    @Override 
+    public void startElement(String ns, String lname, String qname, Attributes a) {
+        if (qname.equals("node") || qname.equals("trkpt")) {
+            double lat = Double.parseDouble(a.getValue("lat"));
+            double lon = Double.parseDouble(a.getValue("lon"));
+            minLat = Math.min(minLat, lat);
+            minLon = Math.min(minLon, lon);
+            maxLat = Math.max(maxLat, lat);
+            maxLon = Math.max(maxLon, lon);
+        }
+    }
+    
+    /**
+     * Returns <code>true</code>, if the given coordinates intersect with the
+     * parsed min/max latitude longitude.
+     * @param minLat the minimum latitude.
+     * @param maxLat the maximum latitude.
+     * @param minLon the minimum longitude.
+     * @param maxLon the maximum longitude.
+     * @return <code>true</code> if the given rectangle intersects with the parsed min/max.
+     */
+    public boolean intersects(double minLat, double maxLat, double minLon, double maxLon) {
+        double lat1 = Math.max(this.minLat, minLat);
+        double lon1 = Math.max(this.minLon, minLon);
+        double lat2 = Math.min(this.maxLat, maxLat);
+        double lon2 = Math.min(this.maxLon, maxLon);
+        return ((lat2-lat1) > 0) && ((lon2-lon1) > 0);
+    }
+        
+    public static void main(String[] args) {
+        if(args.length < 5) {
+            printHelp();
+            return;
+        }
+        double minLat = Double.parseDouble(args[0]);
+        double maxLat = Double.parseDouble(args[1]);
+        double minLon = Double.parseDouble(args[2]);
+        double maxLon = Double.parseDouble(args[3]);
+        String[] files = new String[args.length - 4];
+        System.arraycopy(args, 4, files, 0, args.length - 4);
+            
+        try {    
+            File file;
+            for(String fileName : files) {
+                file = new File(fileName);
+                if(!file.isDirectory() 
+                  && (file.getName().endsWith("gpx") || file.getName().endsWith("osm"))) {
+                    OsmGpxBounds parser = new OsmGpxBounds();
+                    parser.parse(new BufferedInputStream(new FileInputStream(file)));
+                    if(parser.intersects(minLat, maxLat, minLon, maxLon)) {
+                        System.out.println(file.getAbsolutePath()); // + "," + parser.minLat + "," + parser.maxLat + "," + parser.minLon + "," + parser.maxLon);                        
+                    }
+//                    System.out.println(parser.intersects(47.0555, 47.09, 15.406, 15.4737));
+                }
+            }
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } catch (SAXException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 
+     */
+    private static void printHelp() {
+        System.out.println(OsmGpxBounds.class.getName() + " <minLat> <maxLat> <minLon> <maxLon> <files+>");
+        
+    }
+
+}
