Changeset 3330 in josm
- Timestamp:
- 2010-06-14T18:57:24+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginListPanel.java
r3113 r3330 13 13 14 14 import javax.swing.JCheckBox; 15 import javax.swing.JLabel; 16 import javax.swing.SwingConstants; 15 17 import javax.swing.event.HyperlinkEvent; 16 18 import javax.swing.event.HyperlinkListener; … … 105 107 String localversion = formatPluginLocalVersion(model.getPluginInformation(pi.getName())); 106 108 107 final JCheckBox cbPlugin = new JCheckBox( 108 tr("{0}: Version {1} (local: {2})", pi.getName(), remoteversion, localversion) 109 ); 109 final JCheckBox cbPlugin = new JCheckBox(); 110 110 cbPlugin.setSelected(selected); 111 111 cbPlugin.setToolTipText(formatCheckboxTooltipText(pi)); … … 115 115 } 116 116 }); 117 JLabel lblPlugin = new JLabel( 118 tr("{0}: Version {1} (local: {2})", pi.getName(), remoteversion, localversion), 119 pi.getScaledIcon(), 120 SwingConstants.LEFT); 121 122 gbc.gridx = 0; 117 123 gbc.gridy = ++row; 118 124 gbc.insets = new Insets(5,5,0,5); 119 125 gbc.weighty = 0.0; 126 gbc.weightx = 0.0; 120 127 add(cbPlugin, gbc); 128 129 gbc.gridx = 1; 130 gbc.weightx = 1.0; 131 add(lblPlugin, gbc); 121 132 122 133 HtmlPanel description = new HtmlPanel(); … … 130 141 }); 131 142 143 gbc.gridx = 1; 132 144 gbc.gridy = ++row; 133 145 gbc.insets = new Insets(3,25,5,5); -
trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java
r3287 r3330 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Image; 6 7 import java.io.File; 7 8 import java.io.FileInputStream; … … 21 22 import java.util.jar.JarInputStream; 22 23 import java.util.jar.Manifest; 24 import javax.swing.ImageIcon; 23 25 24 26 import org.openstreetmap.josm.Main; 25 27 import org.openstreetmap.josm.data.Version; 28 import org.openstreetmap.josm.tools.ImageProvider; 26 29 import org.openstreetmap.josm.tools.LanguageInfo; 27 30 … … 47 50 public String localversion = null; 48 51 public String downloadlink = null; 52 public String iconPath; 53 public ImageIcon icon; 49 54 public List<URL> libraries = new LinkedList<URL>(); 50 55 public final Map<String, String> attr = new TreeMap<String, String>(); … … 135 140 this.version = other.version; 136 141 this.downloadlink = other.downloadlink; 142 this.icon = other.icon; 143 this.iconPath = other.iconPath; 137 144 this.libraries = other.libraries; 138 145 this.attr.clear(); … … 166 173 catch(NumberFormatException e) {} 167 174 author = attr.getValue("Author"); 175 iconPath = attr.getValue("Plugin-Icon"); 176 if (iconPath != null) { 177 // extract icon from the plugin jar file 178 icon = ImageProvider.getIfAvailable(null, null, null, iconPath, file); 179 } 168 180 if(oldcheck && mainversion > Version.getInstance().getVersion()) 169 181 { … … 413 425 } 414 426 427 public ImageIcon getScaledIcon() { 428 if (icon == null) 429 return null; 430 return new ImageIcon(icon.getImage().getScaledInstance(24, 24, Image.SCALE_SMOOTH)); 431 } 415 432 } -
trunk/src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java
r3287 r3330 14 14 import java.util.Map; 15 15 16 import org.openstreetmap.josm.Main;17 16 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 18 17 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 19 18 import org.openstreetmap.josm.io.OsmTransferException; 19 import org.openstreetmap.josm.tools.ImageProvider; 20 20 import org.xml.sax.SAXException; 21 21 … … 66 66 } else { 67 67 availablePlugins.get(info.getName()).localversion = info.version; 68 if (info.icon != null) { 69 availablePlugins.get(info.getName()).icon = info.icon; 70 } 68 71 } 69 72 } … … 89 92 System.err.println(tr("Warning: Failed to scan file ''{0}'' for plugin information. Skipping.", fname)); 90 93 e.printStackTrace(); 94 } 95 monitor.worked(1); 96 } 97 } 98 99 protected void scanIconCacheFiles(ProgressMonitor monitor, File pluginsDirectory) { 100 System.err.println("scanIconCacheFiles"); 101 File[] siteCacheFiles = pluginsDirectory.listFiles( 102 new FilenameFilter() { 103 public boolean accept(File dir, String name) { 104 return name.matches("^([0-9]+-)?site.*plugin-icons\\.zip$"); 105 } 106 } 107 ); 108 if (siteCacheFiles == null || siteCacheFiles.length == 0) 109 return; 110 monitor.subTask(tr("Processing plugin site cache icon files...")); 111 monitor.setTicksCount(siteCacheFiles.length); 112 for (File f: siteCacheFiles) { 113 String fname = f.getName(); 114 monitor.setCustomText(tr("Processing file ''{0}''", fname)); 115 for (PluginInformation pi : availablePlugins.values()) { 116 if (pi.icon == null && pi.iconPath != null) { 117 pi.icon = ImageProvider.getIfAvailable(null, null, null, pi.name+".jar/"+pi.iconPath, f); 118 } 91 119 } 92 120 monitor.worked(1); … … 130 158 monitor.beginTask(""); 131 159 scanSiteCacheFiles(monitor, pluginsDirectory); 160 scanIconCacheFiles(monitor, pluginsDirectory); 132 161 scanPluginFiles(monitor, pluginsDirectory); 133 162 } finally { -
trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java
r3318 r3330 12 12 import java.io.InputStream; 13 13 import java.io.InputStreamReader; 14 import java.io.OutputStream; 14 15 import java.io.OutputStreamWriter; 15 16 import java.io.PrintWriter; … … 32 33 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 33 34 import org.openstreetmap.josm.io.OsmTransferException; 35 import org.openstreetmap.josm.tools.ImageProvider; 34 36 import org.xml.sax.SAXException; 35 37 … … 46 48 private List<PluginInformation> availablePlugins; 47 49 50 protected enum CacheType {PLUGIN_LIST, ICON_LIST}; 51 48 52 protected void init(Collection<String> sites){ 49 53 this.sites = sites; … … 90 94 91 95 /** 92 * Creates the file name for the cached plugin list. 96 * Creates the file name for the cached plugin list and the icon cache 97 * file. 93 98 * 94 99 * @param site the name of the site 100 * @param type icon cache or plugin list cache 95 101 * @return the file name for the cache file 96 102 */ 97 protected File createSiteCacheFile(File pluginDir, String site) { 103 protected File createSiteCacheFile(File pluginDir, String site, CacheType type) { 98 104 String name; 99 105 try { … … 114 120 } 115 121 } 116 sb.append(".txt"); 122 switch (type) { 123 case PLUGIN_LIST: 124 sb.append(".txt"); 125 break; 126 case ICON_LIST: 127 sb.append("-icons.zip"); 128 break; 129 } 117 130 name = sb.toString(); 118 131 } catch(MalformedURLException e) { … … 175 188 176 189 /** 190 * Downloads the icon archive from a remote location 191 * 192 * @param site the site URL 193 * @param monitor a progress monitor 194 */ 195 protected void downloadPluginIcons(String site, File destFile, ProgressMonitor monitor) { 196 InputStream in = null; 197 OutputStream out = null; 198 System.err.println("icons site: "+site); 199 try { 200 monitor.beginTask(""); 201 monitor.indeterminateSubTask(tr("Downloading plugin list from ''{0}''", site)); 202 203 URL url = new URL(site); 204 synchronized(this) { 205 connection = (HttpURLConnection)url.openConnection(); 206 connection.setRequestProperty("Cache-Control", "no-cache"); 207 connection.setRequestProperty("User-Agent",Version.getInstance().getAgentString()); 208 connection.setRequestProperty("Host", url.getHost()); 209 } 210 in = connection.getInputStream(); 211 out = new FileOutputStream(destFile); 212 byte[] buffer = new byte[8192]; 213 for (int read = in.read(buffer); read != -1; read = in.read(buffer)) { 214 out.write(buffer, 0, read); 215 } 216 out.close(); 217 in.close(); 218 } catch(MalformedURLException e) { 219 if (canceled) return; 220 e.printStackTrace(); 221 return; 222 } catch(IOException e) { 223 if (canceled) return; 224 e.printStackTrace(); 225 return; 226 } finally { 227 synchronized(this) { 228 if (connection != null) { 229 connection.disconnect(); 230 } 231 connection = null; 232 } 233 if (in != null) { 234 try { 235 in.close(); 236 } catch(IOException e){/* ignore */} 237 } 238 monitor.finishTask(); 239 } 240 for (PluginInformation pi : availablePlugins) { 241 if (pi.icon == null && pi.iconPath != null) { 242 pi.icon = ImageProvider.getIfAvailable(null, null, null, pi.name+".jar/"+pi.iconPath, destFile); 243 } 244 } 245 } 246 247 /** 177 248 * Writes the list of plugins to a cache file 178 249 * … … 189 260 } 190 261 } 191 File cacheFile = createSiteCacheFile(pluginDir, site); 262 File cacheFile = createSiteCacheFile(pluginDir, site, CacheType.PLUGIN_LIST); 192 263 getProgressMonitor().subTask(tr("Writing plugin list to local cache ''{0}''", cacheFile.toString())); 193 264 writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(cacheFile), "utf-8")); … … 249 320 getProgressMonitor().setTicksCount(sites.size() * 3); 250 321 File pluginDir = Main.pref.getPluginsDirectory(); 322 323 // collect old cache files and remove if no longer in use 251 324 List<File> siteCacheFiles = new LinkedList<File>(); 252 325 for (String location : PluginInformation.getPluginLocations()) { … … 254 327 new FilenameFilter() { 255 328 public boolean accept(File dir, String name) { 256 return name.matches("^([0-9]+-)?site.*\\.txt$"); 329 return name.matches("^([0-9]+-)?site.*\\.txt$") || 330 name.matches("^([0-9]+-)?site.*-icons\\.zip$"); 257 331 } 258 332 } … … 266 340 String list = downloadPluginList(site, getProgressMonitor().createSubTaskMonitor(0, false)); 267 341 if (canceled) return; 268 siteCacheFiles.remove(createSiteCacheFile(pluginDir, site)); 342 siteCacheFiles.remove(createSiteCacheFile(pluginDir, site, CacheType.PLUGIN_LIST)); 343 siteCacheFiles.remove(createSiteCacheFile(pluginDir, site, CacheType.ICON_LIST)); 269 344 if(list != null) 270 345 { … … 278 353 if (canceled) return; 279 354 } 355 downloadPluginIcons(site+"-icons.zip", createSiteCacheFile(pluginDir, site, CacheType.ICON_LIST), getProgressMonitor().createSubTaskMonitor(0, false)); 280 356 } 281 357 for (File file: siteCacheFiles) /* remove old stuff or whole update process is broken */
Note:
See TracChangeset
for help on using the changeset viewer.