diff U3 plugin.properties plugin.properties --- plugin.properties Wed Jul 26 02:27:32 2006 +++ plugin.properties Fri Feb 08 22:46:19 2008 @@ -1,4 +1,4 @@ plugin.class=org.gudy.azureus2.countrylocator.AZPlugin plugin.langfile=org.gudy.azureus2.countrylocator.internat.Messages -plugin.version=1.7 +plugin.version=1.8 plugin.id=CountryLocator \ No newline at end of file diff U3 org/gudy/azureus2/countrylocator/CountryLocator.java org/gudy/azureus2/countrylocator/CountryLocator.java --- org/gudy/azureus2/countrylocator/CountryLocator.java Tue Jul 25 23:04:26 2006 +++ org/gudy/azureus2/countrylocator/CountryLocator.java Sat Feb 09 15:27:43 2008 @@ -76,6 +76,7 @@ import org.gudy.azureus2.plugins.utils.resourcedownloader.ResourceDownloaderListener; import org.gudy.azureus2.ui.swt.plugins.UISWTInstance; +import com.aelitis.azureus.core.dht.transport.DHTTransportContact; import com.maxmind.geoip.Country; import com.maxmind.geoip.LookupService; import com.maxmind.geoip.csvtodat.CsvToDat; @@ -399,6 +400,43 @@ }); tm.addColumn(countryColumn); + // ISO3166 + TableColumn iso3166VivaldiColumn = tm.createColumn( + TableManager.TABLE_VIVALDI, "CountryCode"); + iso3166VivaldiColumn.initialize(TableColumn.ALIGN_LEAD, TableColumn.POSITION_LAST, + 30, TableColumn.INTERVAL_INVALID_ONLY); + iso3166VivaldiColumn.addCellRefreshListener(new TableCellRefreshListener() { + public void refresh(TableCell cell) { + DHTTransportContact contact = (DHTTransportContact)cell.getDataSource(); + Country loc = (contact == null) ? null : getCountry(contact.getAddress().getAddress().getHostAddress()); + String s = (loc == null) ? "" : loc.getCode(); + + if (!cell.setSortValue(s) && cell.isValid()) + return; + cell.setText(s); + } + }); + tm.addColumn(iso3166VivaldiColumn); + + // Country Name + TableColumn countryVivaldiColumn = tm.createColumn( + TableManager.TABLE_VIVALDI, "Country"); + countryVivaldiColumn.initialize(TableColumn.ALIGN_LEAD, + TableColumn.POSITION_INVISIBLE, 80, TableColumn.INTERVAL_INVALID_ONLY); + countryVivaldiColumn.addCellRefreshListener(new TableCellRefreshListener() { + public void refresh(TableCell cell) { + DHTTransportContact contact = (DHTTransportContact)cell.getDataSource(); + Country loc = (contact == null) ? null : getCountry(contact.getAddress().getAddress().getHostAddress()); + String s = ""; + if (loc != null) + s = getCountryName(loc, Locale.getDefault()); + if (!cell.setSortValue(s) && cell.isValid()) + return; + cell.setText(s); + } + }); + tm.addColumn(countryVivaldiColumn); + // Small Flags TableColumn flagsColumn = tm.createColumn(TableManager.TABLE_TORRENT_PEERS, "CountryFlagSmall"); @@ -420,6 +458,26 @@ flagsColumn.addCellRefreshListener(flagListener); flagsColumn.addCellToolTipListener(flagListener); tm.addColumn(flagsColumn); + + // Small Flags + flagsColumn = tm.createColumn(TableManager.TABLE_VIVALDI, + "CountryFlagSmall"); + flagsColumn.initialize(TableColumn.ALIGN_LEAD, + TableColumn.POSITION_INVISIBLE, 25, TableColumn.INTERVAL_INVALID_ONLY); + flagsColumn.setType(TableColumn.TYPE_GRAPHIC); + VivaldiFlagListener vivaldiFlagListener = new VivaldiFlagListener(FLAGS_SMALL); + flagsColumn.addCellRefreshListener(vivaldiFlagListener); + tm.addColumn(flagsColumn); + + // Normal Flags + flagsColumn = tm.createColumn(TableManager.TABLE_VIVALDI, + "CountryFlag"); + flagsColumn.initialize(TableColumn.ALIGN_LEAD, TableColumn.POSITION_LAST, + 25, TableColumn.INTERVAL_INVALID_ONLY); + flagsColumn.setType(TableColumn.TYPE_GRAPHIC); + vivaldiFlagListener = new VivaldiFlagListener(FLAGS_BIG); + flagsColumn.addCellRefreshListener(vivaldiFlagListener); + tm.addColumn(flagsColumn); } /** @@ -440,33 +498,39 @@ // Copy GeoIP.dat to the plugin directory for faster access try { + // get the file we want to create + String sDir = pluginInterface.getPluginDirectoryName(); + if (!sDir.endsWith(File.separator)) + sDir += File.separator; + fGeoIP = new File(sDir + "GeoIP.dat"); + + long lInternalTime; // get the time of the internal GeoIP // 1) Get the URL URL url = classLoader.getResource("GeoIP.dat"); // 2) Change it to an URI String sInternalPath = url.toExternalForm(); sInternalPath = sInternalPath.replaceAll(" ", "%20"); - if (sInternalPath.startsWith("jar:file:") - && sInternalPath.charAt(9) != '/') - sInternalPath = "jar:file:/" + sInternalPath.substring(9); - int posPling = sInternalPath.lastIndexOf('!'); - sInternalPath = sInternalPath.substring(4, posPling); - URI uri = URI.create(sInternalPath); - // 3) Create File - File fInternalGeoIP = new File(uri); - // 4) Open the JarFile - JarFile jarFile = new JarFile(fInternalGeoIP); - // 5) get the JarEntry - JarEntry entry = jarFile.getJarEntry("GeoIP.dat"); - // 6) get the time - long lInternalTime = entry.getTime(); - // 7) gasp for fresh air and wish you knew of an easier way! - - // get the file we want to create - String sDir = pluginInterface.getPluginDirectoryName(); - if (!sDir.endsWith(File.separator)) - sDir += File.separator; - fGeoIP = new File(sDir + "GeoIP.dat"); + if (sInternalPath.startsWith("jar:file:")) { + if (sInternalPath.charAt(9) != '/') + sInternalPath = "jar:file:/" + sInternalPath.substring(9); + int posPling = sInternalPath.lastIndexOf('!'); + sInternalPath = sInternalPath.substring(4, posPling); + URI uri = URI.create(sInternalPath); + // 3) Create File + File fInternalGeoIP = new File(uri); + // 4) Open the JarFile + JarFile jarFile = new JarFile(fInternalGeoIP); + // 5) get the JarEntry + JarEntry entry = jarFile.getJarEntry("GeoIP.dat"); + // 6) get the time + lInternalTime = entry.getTime(); + // 7) gasp for fresh air and wish you knew of an easier way! + } + else + { + lInternalTime = fGeoIP.lastModified(); + } boolean bCopyFromJar = (!fGeoIP.exists() || lInternalTime > fGeoIP.lastModified()); if (!bCopyFromJar) { @@ -784,6 +848,38 @@ } } + /** + * Vivaldi flag column refresher + * + * @author NormanR 2008/Feb/09 v1.8 + */ + private class VivaldiFlagListener implements TableCellRefreshListener + { + String sFlagSize; + + /** + * Initializer + * + * @param strLoc Location of images + */ + public VivaldiFlagListener(String strLoc) { + sFlagSize = strLoc; + } + + public void refresh(TableCell cell) { + DHTTransportContact contact = (DHTTransportContact)cell.getDataSource(); + Country loc = (contact == null) ? null : getCountry(contact.getAddress().getAddress().getHostAddress()); + String s = (loc == null) ? "" : loc.getCode(); + + if (!cell.setSortValue(s) && cell.isValid()) + return; + + Graphic graphic = (loc == null) ? null : getImage(sFlagSize, + s.toLowerCase()); + cell.setGraphic(graphic); + } + } + /** * Downloads new IP to Country database */ @@ -800,6 +896,13 @@ src = sLocation; this.paramToEnable = paramToEnable; this.status = status; + } + + public void reportAmountComplete(ResourceDownloader downloader, + long amount) + { + if (status != null) + status.setLabelText("" + amount + " bytes"); } public void reportPercentComplete(ResourceDownloader downloader, diff U3 org/gudy/azureus2/countrylocator/internat/Messages.properties org/gudy/azureus2/countrylocator/internat/Messages.properties --- org/gudy/azureus2/countrylocator/internat/Messages.properties Tue Jul 25 23:04:28 2006 +++ org/gudy/azureus2/countrylocator/internat/Messages.properties Sat Feb 09 02:03:54 2008 @@ -26,4 +26,12 @@ CountryLocator.geomap.CountryHighlightColor=Country highlight color CountryLocator.geomap.SelectColor=Select color CountryLocator.geomap.DefaultColor=Reset colors -Views.plugins.org.gudy.azureus2.countrylocator.WorldMapView.title=Geo Map \ No newline at end of file +Views.plugins.org.gudy.azureus2.countrylocator.WorldMapView.title=Geo Map +Vivaldi.column.CountryCode=CC +Vivaldi.column.CountryCode.info=The country code (ISO 3166) where the peer is located +Vivaldi.column.Country=Country +Vivaldi.column.Country.info=The country where the peer is located +Vivaldi.column.CountryFlag=Flag +Vivaldi.column.CountryFlag.info=Country Flag of the peer's country +Vivaldi.column.CountryFlagSmall=Flag +Vivaldi.column.CountryFlagSmall.info=Small Country Flag of the peer's country