Changeset 6257 in josm
- Timestamp:
- 2013-09-25T01:19:21+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java
r6248 r6257 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Dimension; 7 import java.awt.GridBagLayout; 6 8 import java.io.BufferedReader; 7 9 import java.io.ByteArrayInputStream; … … 27 29 import java.util.List; 28 30 31 import javax.swing.JLabel; 32 import javax.swing.JOptionPane; 33 import javax.swing.JPanel; 34 import javax.swing.JScrollPane; 35 29 36 import org.openstreetmap.josm.Main; 30 37 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 31 38 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 32 39 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 40 import org.openstreetmap.josm.gui.util.GuiHelper; 41 import org.openstreetmap.josm.gui.widgets.JosmTextArea; 33 42 import org.openstreetmap.josm.io.OsmTransferException; 43 import org.openstreetmap.josm.tools.GBC; 34 44 import org.openstreetmap.josm.tools.ImageProvider; 35 45 import org.openstreetmap.josm.tools.Utils; … … 37 47 38 48 /** 39 * An asynchronous task for downloading plugin lists from the configured plugin download 40 * sites. 41 * 49 * An asynchronous task for downloading plugin lists from the configured plugin download sites. 50 * @since 2817 42 51 */ 43 public class ReadRemotePluginInformationTask extends PleaseWaitRunnable {52 public class ReadRemotePluginInformationTask extends PleaseWaitRunnable { 44 53 45 54 private Collection<String> sites; … … 143 152 * @return the downloaded list 144 153 */ 145 protected String downloadPluginList(String site, ProgressMonitor monitor) {154 protected String downloadPluginList(String site, final ProgressMonitor monitor) { 146 155 BufferedReader in = null; 147 String Builder sb = new StringBuilder();156 String line; 148 157 try { 149 158 /* replace %<x> with empty string or x=plugins (separated with comma) */ … … 166 175 } 167 176 in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); 168 String line;169 while ((line = in.readLine()) != null) {177 StringBuilder sb = new StringBuilder(); 178 while ((line = in.readLine()) != null) { 170 179 sb.append(line).append("\n"); 171 180 } 172 181 return sb.toString(); 173 } catch (MalformedURLException e) {182 } catch (MalformedURLException e) { 174 183 if (canceled) return null; 175 184 e.printStackTrace(); 176 185 return null; 177 } catch (IOException e) {186 } catch (IOException e) { 178 187 if (canceled) return null; 179 e.printStackTrace();188 handleIOException(monitor, e, tr("Plugin list download error"), tr("JOSM failed to download plugin list:")); 180 189 return null; 181 190 } finally { … … 190 199 } 191 200 } 201 202 private void handleIOException(final ProgressMonitor monitor, IOException e, final String title, String firstMessage) { 203 InputStream errStream = connection.getErrorStream(); 204 StringBuilder sb = new StringBuilder(); 205 if (errStream != null) { 206 BufferedReader err = null; 207 try { 208 String line; 209 err = new BufferedReader(new InputStreamReader(errStream, "UTF-8")); 210 while ((line = err.readLine()) != null) { 211 sb.append(line).append("\n"); 212 } 213 } catch (Exception ex) { 214 Main.error(e); 215 Main.error(ex); 216 } finally { 217 Utils.close(err); 218 } 219 } 220 final String msg = e.getMessage(); 221 final String details = sb.toString(); 222 Main.error(details.isEmpty() ? msg : msg + " - Details:\n" + details); 223 224 GuiHelper.runInEDTAndWait(new Runnable() { 225 @Override public void run() { 226 JPanel panel = new JPanel(new GridBagLayout()); 227 panel.add(new JLabel(tr("JOSM failed to download plugin list:")), GBC.eol().insets(0, 0, 0, 10)); 228 StringBuilder b = new StringBuilder(); 229 for (String part : msg.split("(?<=\\G.{200})")) { 230 b.append(part).append("\n"); 231 } 232 panel.add(new JLabel("<html><body width=\"500\"><b>"+b.toString().trim()+"</b></body></html>"), GBC.eol().insets(0, 0, 0, 10)); 233 if (!details.isEmpty()) { 234 panel.add(new JLabel(tr("Details:")), GBC.eol().insets(0, 0, 0, 10)); 235 JosmTextArea area = new JosmTextArea(details); 236 area.setEditable(false); 237 area.setLineWrap(true); 238 area.setWrapStyleWord(true); 239 JScrollPane scrollPane = new JScrollPane(area); 240 scrollPane.setPreferredSize(new Dimension(500, 300)); 241 panel.add(scrollPane, GBC.eol().fill()); 242 } 243 JOptionPane.showMessageDialog(monitor.getWindowParent(), panel, title, JOptionPane.ERROR_MESSAGE); 244 } 245 }); 246 } 192 247 193 248 /** … … 217 272 out.write(buffer, 0, read); 218 273 } 219 } catch (MalformedURLException e) {274 } catch (MalformedURLException e) { 220 275 if (canceled) return; 221 276 e.printStackTrace(); 222 277 return; 223 } catch (IOException e) {278 } catch (IOException e) { 224 279 if (canceled) return; 225 e.printStackTrace();280 handleIOException(monitor, e, tr("Plugin icons download error"), tr("JOSM failed to download plugin icons:")); 226 281 return; 227 282 } finally {
Note:
See TracChangeset
for help on using the changeset viewer.