- Timestamp:
- 2006-07-12T17:22:23+02:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/io/ProgressReader.java
r103 r109 3 3 import java.io.IOException; 4 4 import java.io.InputStream; 5 import java.io.InputStreamReader;6 import java.io.Reader;7 5 import java.net.URLConnection; 8 6 … … 16 14 public class ProgressReader extends InputStream { 17 15 18 private final Readerin;16 private final InputStream in; 19 17 private final BoundedRangeModel progress; 20 18 private final JLabel currentAction; 21 19 private int readSoFar = 0; 20 private int lastDialogUpdate = 0; 21 private final URLConnection connection; 22 22 23 23 public ProgressReader(URLConnection con, BoundedRangeModel progress, JLabel currentAction) throws IOException { 24 this.in = new InputStreamReader(con.getInputStream()); 24 this.connection = con; 25 this.in = con.getInputStream(); 25 26 this.progress = progress; 26 27 this.currentAction = currentAction; … … 31 32 progress.setMaximum(0); 32 33 progress.setValue(0); 33 34 } 34 35 35 36 @Override public void close() throws IOException { … … 37 38 } 38 39 40 @Override public int read(byte[] b, int off, int len) throws IOException { 41 int read = in.read(b, off, len); 42 if (read != -1) 43 advanceTicker(read); 44 return read; 45 } 46 39 47 @Override public int read() throws IOException { 40 48 int read = in.read(); 41 readSoFar++; 49 if (read != -1) 50 advanceTicker(1); 51 return read; 52 } 42 53 43 String progStr = " ("+readSoFar+"/"; 44 if (progress.getMaximum() == 0) 45 progStr += "???)"; 46 else 47 progStr += progress.getMaximum()+")"; 48 49 String cur = currentAction.getText(); 50 int i = cur.indexOf(' '); 51 if (i != -1) 52 cur = cur.substring(0, i) + progStr; 53 else 54 cur += progStr; 55 currentAction.setText(cur); 56 progress.setValue(readSoFar); 57 return read; 58 } 54 /** 55 * Increase ticker (progress counter and displayed text) by the given amount. 56 * @param amount 57 */ 58 private void advanceTicker(int amount) { 59 if (progress.getMaximum() == 0 && connection.getContentLength() != -1) 60 progress.setMaximum(connection.getContentLength()); 61 62 readSoFar += amount; 63 64 if (readSoFar / 1024 != lastDialogUpdate) { 65 lastDialogUpdate++; 66 String progStr = " "+readSoFar/1024+"/"; 67 progStr += (progress.getMaximum()==0) ? "??? KB" : (progress.getMaximum()/1024)+" KB"; 68 progress.setValue(readSoFar); 69 70 String cur = currentAction.getText(); 71 int i = cur.indexOf(' '); 72 if (i != -1) 73 cur = cur.substring(0, i) + progStr; 74 else 75 cur += progStr; 76 currentAction.setText(cur); 77 } 78 } 59 79 }
Note:
See TracChangeset
for help on using the changeset viewer.