Changeset 109 in josm


Ignore:
Timestamp:
2006-07-12T17:22:23+02:00 (15 years ago)
Author:
imi
Message:
  • fixed performance bug in progress counter (thanks SteveC)
  • added build.xml for ant-freaks. Be sure to have junit.jar in your CLASSPATH (thanks SteveC)
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • CONTRIBUTION

    r104 r109  
    11112.0. The world image is from onearth.pl.
    1212
    13 The gettext-commons-0.9.jar is from Felix Berger and Steffen Pingel (http://xnap-commons.sourceforge.net/gettext-commons/). The jar-file is licensed under LGPL.
     13The gettext-commons-0.9.jar is from Felix Berger and Steffen
     14Pingel (http://xnap-commons.sourceforge.net/gettext-commons/).
     15The jar-file is licensed under LGPL.
    1416
    15 A internationalization-patch was submited 2006 by Sven Anders <sven@anders-hamburg.de>.
     17An internationalization-patch was submited 2006 by Sven
     18Anders <sven@anders-hamburg.de>.
     19
     20Several smaller patches are contributed by community members
     21of OSM.
    1622
    1723All the rest are belong to me.
  • src/org/openstreetmap/josm/io/ProgressReader.java

    r103 r109  
    33import java.io.IOException;
    44import java.io.InputStream;
    5 import java.io.InputStreamReader;
    6 import java.io.Reader;
    75import java.net.URLConnection;
    86
     
    1614public class ProgressReader extends InputStream {
    1715
    18         private final Reader in;
     16        private final InputStream in;
    1917        private final BoundedRangeModel progress;
    2018        private final JLabel currentAction;
    2119        private int readSoFar = 0;
     20        private int lastDialogUpdate = 0;
     21        private final URLConnection connection;
    2222
    2323        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();
    2526                this.progress = progress;
    2627                this.currentAction = currentAction;
     
    3132                        progress.setMaximum(0);
    3233                progress.setValue(0);
    33     }
     34        }
    3435
    3536        @Override public void close() throws IOException {
     
    3738        }
    3839
     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
    3947        @Override public int read() throws IOException {
    4048                int read = in.read();
    41                 readSoFar++;
     49                if (read != -1)
     50                        advanceTicker(1);
     51                return read;
     52        }
    4253
    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        }
    5979}
Note: See TracChangeset for help on using the changeset viewer.