Ignore:
Timestamp:
2015-08-05T23:51:30+02:00 (9 years ago)
Author:
wiktorn
Message:

Fix behaviour when exception is thrown during download.

  • fix endless download, when exception is thrown during download
  • draw multiline error text on tile if error string is longer than tile width
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r8636 r8643  
    10371037    private void myDrawString(Graphics g, String text, int x, int y) {
    10381038        Color oldColor = g.getColor();
    1039         g.setColor(Color.black);
    1040         g.drawString(text, x+1, y+1);
    1041         g.setColor(oldColor);
    1042         g.drawString(text, x, y);
     1039        String textToDraw = text;
     1040        if (g.getFontMetrics().stringWidth(text) > tileSource.getTileSize()) {
     1041            // text longer than tile size, split it
     1042            StringBuilder line = new StringBuilder();
     1043            StringBuilder ret = new StringBuilder();
     1044            for(String s: text.split(" ")) {
     1045                if (g.getFontMetrics().stringWidth(line.toString() + s) > tileSource.getTileSize()) {
     1046                    ret.append(line).append("\n");
     1047                    line.setLength(0);
     1048                }
     1049                line.append(s).append(" ");
     1050            }
     1051            ret.append(line);
     1052            textToDraw = ret.toString();
     1053        }
     1054        int offset = 0;
     1055        for (String s: textToDraw.split("\n")) {
     1056            g.setColor(Color.black);
     1057            g.drawString(s, x + 1, y + offset + 1);
     1058            g.setColor(oldColor);
     1059            g.drawString(s, x, y + offset);
     1060            offset += g.getFontMetrics().getHeight() + 3;
     1061        }
    10431062    }
    10441063
Note: See TracChangeset for help on using the changeset viewer.