private void Timer(ActionEvent evt) { // TODO Auto-generated method stub try { int minBus = 110; int maxBus = 120; double minAfkLat = 42.302; double maxAfkLat = 42.304; System.out.println("Timer"); timer.stop(); MapMarker init = new MapMarker(theLatitude, theLongitude); String theMapURIAsString = (String) MapLookup.getMap(theLatitude, theLongitude, init).substring(0, 87); int testint2 = 0; for (Listener l : theListeners) { // if(l.Latitude != 9999 && Float.parseFloat(l.BusID.split("#")[1]) < maxBus && // Float.parseFloat(l.BusID.split("#")[1]) > minBus) //Bussar beroende på buss nummer // if(l.Latitude != 9999 && l.Latitude > minAfkLat && l.Latitude < maxAfkLat) // //Possible afk busses // if(l.Latitude != 9999 && ( l.Latitude < minAfkLat || l.Latitude > maxAfkLat)) // //Exclude afk busses if (l.Latitude != 9999.0) // All busses { theMapURIAsString += "|"; theMapURIAsString += Float.toString(l.Latitude) + "," + Float.toString(l.Longitude); } } theMapURIAsString += "&sensor=false&key=AIzaSyBR_wUAQ3iPM2e8WeoQIUw9c3xLJPRGZL8"; // System.out.println("HEIR COWMES F****R\n" + theMapURIAsString + "\nFUCKER IS COMMEN"); String[] GetRidOfinitMarker = theMapURIAsString.split("42.358543,-71.096178\\|"); // String[] GetRidOfinitMarker = theMapURIAsString.split("42.303113,-71.109925\\|"); //afk // bussar String GottenRidOfinitMarker = GetRidOfinitMarker[0] + GetRidOfinitMarker[1]; String test = theMapURIAsString.split("&markers=")[1]; String[] testa = test.split("\\|"); // for(String v : testa)System.out.println(v); //alla inkomna positioner // Retrieve map from Google Maps. // URL theMapURI = new URL(theMapURIAsString); URL theMapURI = new URL(GottenRidOfinitMarker); // URL Utan init marker theMap = ImageIO.read(theMapURI.openStream()); // Create map image scaled to size of the application window size. imagePanel1.setImage( theMap.getScaledInstance( imagePanel1.getWidth(), imagePanel1.getHeight(), Image.SCALE_AREA_AVERAGING)); // Display map image. imagePanel1.repaint(); } catch (Exception ex) { timer.start(); } timer.start(); }
/** * Enumerates the resouces in a give package name. This works even if the resources are loaded * from a jar file! * * <p>Adapted from code by mikewse on the java.sun.com message boards. * http://forum.java.sun.com/thread.jsp?forum=22&thread=30984 * * @param packageName The package to enumerate * @return A Set of Strings for each resouce in the package. */ public static Set getResoucesInPackage(String packageName) throws IOException { String localPackageName; if (packageName.endsWith("/")) { localPackageName = packageName; } else { localPackageName = packageName + '/'; } Enumeration dirEnum = ClassLoader.getSystemResources(localPackageName); Set names = new HashSet(); // Loop CLASSPATH directories while (dirEnum.hasMoreElements()) { URL resUrl = (URL) dirEnum.nextElement(); // Pointing to filesystem directory if (resUrl.getProtocol().equals("file")) { File dir = new File(resUrl.getFile()); File[] files = dir.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { File file = files[i]; if (file.isDirectory()) continue; names.add(localPackageName + file.getName()); } } // Pointing to Jar file } else if (resUrl.getProtocol().equals("jar")) { JarURLConnection jconn = (JarURLConnection) resUrl.openConnection(); JarFile jfile = jconn.getJarFile(); Enumeration entryEnum = jfile.entries(); while (entryEnum.hasMoreElements()) { JarEntry entry = (JarEntry) entryEnum.nextElement(); String entryName = entry.getName(); // Exclude our own directory if (entryName.equals(localPackageName)) continue; String parentDirName = entryName.substring(0, entryName.lastIndexOf('/') + 1); if (!parentDirName.equals(localPackageName)) continue; names.add(entryName); } } else { // Invalid classpath entry } } return names; }
/** * Reads GIF file from specified file/URL source (URL assumed if name contains ":/" or "file:") * * @param name String containing source * @return read status code (0 = no errors) */ public int read(String name) { status = STATUS_OK; try { name = name.trim().toLowerCase(); if ((name.indexOf("file:") >= 0) || (name.indexOf(":/") > 0)) { URL url = new URL(name); in = new BufferedInputStream(url.openStream()); } else { in = new BufferedInputStream(new FileInputStream(name)); } status = read(in); } catch (IOException e) { status = STATUS_OPEN_ERROR; } return status; }
private void downloadImage(final MercatorTextureTile tile, String mimeType) throws Exception { // System.out.println(tile.getPath()); final URL resourceURL = tile.getResourceURL(mimeType); Retriever retriever; String protocol = resourceURL.getProtocol(); if ("http".equalsIgnoreCase(protocol)) { retriever = new HTTPRetriever(resourceURL, new HttpRetrievalPostProcessor(tile)); } else { String message = Logging.getMessage("layers.TextureLayer.UnknownRetrievalProtocol", resourceURL); throw new RuntimeException(message); } retriever.setConnectTimeout(10000); retriever.setReadTimeout(20000); retriever.call(); }
// Goes online to get user authentication from Flickr. public void getAuthentication() { AuthInterface authInterface = flickr.getAuthInterface(); try { frob = authInterface.getFrob(); } catch (Exception e) { e.printStackTrace(); } try { URL authURL = authInterface.buildAuthenticationUrl(Permission.WRITE, frob); // open the authentication URL in a browser open(authURL.toExternalForm()); } catch (Exception e) { e.printStackTrace(); } println("You have 15 seconds to approve the app!"); int startedWaiting = millis(); int waitDuration = 15 * 1000; // wait 10 seconds while ((millis() - startedWaiting) < waitDuration) { // just wait } println("Done waiting"); try { auth = authInterface.getToken(frob); println("Authentication success"); // This token can be used until the user revokes it. token = auth.getToken(); // save it for future use saveToken(token); } catch (Exception e) { e.printStackTrace(); } // complete authentication authenticateWithToken(token); }
private BufferedImage requestImage(MercatorTextureTile tile, String mimeType) throws URISyntaxException { String pathBase = tile.getPath().substring(0, tile.getPath().lastIndexOf(".")); String suffix = WWIO.makeSuffixForMimeType(mimeType); String path = pathBase + suffix; URL url = WorldWind.getDataFileStore().findFile(path, false); if (url == null) // image is not local return null; if (WWIO.isFileOutOfDate(url, tile.getLevel().getExpiryTime())) { // The file has expired. Delete it. WorldWind.getDataFileStore().removeFile(url); String message = Logging.getMessage("generic.DataFileExpired", url); Logging.logger().fine(message); } else { try { File imageFile = new File(url.toURI()); BufferedImage image = ImageIO.read(imageFile); if (image == null) { String message = Logging.getMessage("generic.ImageReadFailed", imageFile); throw new RuntimeException(message); } this.levels.unmarkResourceAbsent(tile); return image; } catch (IOException e) { // Assume that something's wrong with the file and delete it. gov.nasa.worldwind.WorldWind.getDataFileStore().removeFile(url); this.levels.markResourceAbsent(tile); String message = Logging.getMessage("generic.DeletedCorruptDataFile", url); Logging.logger().info(message); } } return null; }
void setIcon() throws Exception { URL url = this.getClass().getResource("/microscope.gif"); if (url == null) return; Image img = createImage((ImageProducer) url.getContent()); if (img != null) setIconImage(img); }