Changeset 8510 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2015-06-20T23:42:21+02:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/tools
- Files:
-
- 35 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/AudioPlayer.java
r8419 r8510 29 29 30 30 private enum State { INITIALIZING, NOTPLAYING, PLAYING, PAUSED, INTERRUPTED } 31 32 private enum Command { PLAY, PAUSE } 33 34 private enum Result { WAITING, OK, FAILED } 35 31 36 private State state; 32 private enum Command { PLAY, PAUSE }33 private enum Result { WAITING, OK, FAILED }34 37 private URL playingUrl; 35 38 private double leadIn; // seconds … … 62 65 send(); 63 66 } 67 64 68 protected void pause() throws Exception { 65 69 command = Command.PAUSE; 66 70 send(); 67 71 } 72 68 73 private void send() throws Exception { 69 74 result = Result.WAITING; … … 75 80 throw exception; 76 81 } 82 77 83 private void possiblyInterrupt() throws InterruptedException { 78 84 if (interrupted() || result == Result.WAITING) 79 85 throw new InterruptedException(); 80 86 } 87 81 88 protected void failed(Exception e) { 82 89 exception = e; … … 84 91 state = State.NOTPLAYING; 85 92 } 93 86 94 protected void ok(State newState) { 87 95 result = Result.OK; 88 96 state = newState; 89 97 } 98 90 99 protected double offset() { 91 100 return offset; 92 101 } 102 93 103 protected double speed() { 94 104 return speed; 95 105 } 106 96 107 protected URL url() { 97 108 return url; 98 109 } 110 99 111 protected Command command() { 100 112 return command; … … 202 214 */ 203 215 public static void reset() { 204 if (audioPlayer != null) {216 if (audioPlayer != null) { 205 217 try { 206 218 pause(); 207 } catch (Exception e) {219 } catch (Exception e) { 208 220 Main.warn(e); 209 221 } … … 235 247 SourceDataLine audioOutputLine = null; 236 248 AudioFormat audioFormat = null; 237 byte[] abData = new byte[(int) chunk];249 byte[] abData = new byte[(int) chunk]; 238 250 239 251 for (;;) { … … 250 262 case PLAYING: 251 263 command.possiblyInterrupt(); 252 for (;;) {264 for (;;) { 253 265 int nBytesRead = 0; 254 266 nBytesRead = audioInputStream.read(abData, 0, abData.length); … … 301 313 } 302 314 if (calibratedOffset > 0.0) { 303 long bytesToSkip = (long)( 304 calibratedOffset /* seconds (double) */ * bytesPerSecond); 305 /* skip doesn't seem to want to skip big chunks, so 306 * reduce it to smaller ones 307 */ 315 long bytesToSkip = (long) (calibratedOffset /* seconds (double) */ * bytesPerSecond); 316 // skip doesn't seem to want to skip big chunks, so reduce it to smaller ones 308 317 // audioInputStream.skip(bytesToSkip); 309 318 while (bytesToSkip > chunk) { … … 361 370 public static void audioMalfunction(Exception ex) { 362 371 String msg = ex.getMessage(); 363 if (msg == null)372 if (msg == null) 364 373 msg = tr("unspecified reason"); 365 374 else -
trunk/src/org/openstreetmap/josm/tools/Base64.java
r7509 r8510 45 45 int l = Math.min(3, s.length()-i*3); 46 46 String buf = s.substring(i*3, i*3+l); 47 out.append(enc.charAt(buf.charAt(0) >>2));47 out.append(enc.charAt(buf.charAt(0) >> 2)); 48 48 out.append(enc.charAt( 49 49 (buf.charAt(0) & 0x03) << 4 | 50 (l==1? 51 0: 52 (buf.charAt(1) & 0xf0) >> 4))); 53 out.append(l>1?enc.charAt((buf.charAt(1) & 0x0f) << 2 | (l==2?0:(buf.charAt(2) & 0xc0) >> 6)):'='); 54 out.append(l>2?enc.charAt(buf.charAt(2) & 0x3f):'='); 50 (l == 1 ? 0 : (buf.charAt(1) & 0xf0) >> 4))); 51 out.append(l > 1 ? enc.charAt((buf.charAt(1) & 0x0f) << 2 | (l == 2 ? 0 : (buf.charAt(2) & 0xc0) >> 6)) : '='); 52 out.append(l > 2 ? enc.charAt(buf.charAt(2) & 0x3f) : '='); 55 53 } 56 54 return out.toString(); … … 82 80 int l = Math.min(3, s.limit()-i*3); 83 81 int byte0 = s.get() & 0xff; 84 int byte1 = l >1? s.get() & 0xff : 0;85 int byte2 = l >2? s.get() & 0xff : 0;82 int byte1 = l > 1 ? s.get() & 0xff : 0; 83 int byte2 = l > 2 ? s.get() & 0xff : 0; 86 84 87 out.append(enc.charAt(byte0 >>2));85 out.append(enc.charAt(byte0 >> 2)); 88 86 out.append(enc.charAt( 89 87 (byte0 & 0x03) << 4 | 90 (l==1? 91 0: 92 (byte1 & 0xf0) >> 4))); 93 out.append(l>1?enc.charAt((byte1 & 0x0f) << 2 | (l==2?0:(byte2 & 0xc0) >> 6)):'='); 94 out.append(l>2?enc.charAt(byte2 & 0x3f):'='); 88 (l == 1 ? 0 : (byte1 & 0xf0) >> 4))); 89 out.append(l > 1 ? enc.charAt((byte1 & 0x0f) << 2 | (l == 2 ? 0 : (byte2 & 0xc0) >> 6)) : '='); 90 out.append(l > 2 ? enc.charAt(byte2 & 0x3f) : '='); 95 91 } 96 92 return out.toString(); -
trunk/src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java
r8509 r8510 199 199 200 200 String text = ShowStatusReportAction.getReportHeader() + stack.getBuffer().toString(); 201 String urltext = text.replaceAll("\r", "");201 String urltext = text.replaceAll("\r", ""); 202 202 if (urltext.length() > maxlen) { 203 urltext = urltext.substring(0, maxlen);203 urltext = urltext.substring(0, maxlen); 204 204 int idx = urltext.lastIndexOf('\n'); 205 205 // cut whole line when not loosing too much 206 206 if (maxlen-idx < 200) { 207 urltext = urltext.substring(0, idx+1);207 urltext = urltext.substring(0, idx+1); 208 208 } 209 209 urltext += "...<snip>...\n"; … … 215 215 "make sure you have updated to the latest version of JOSM here:")), 216 216 GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 217 p.add(new UrlLabel(Main.getJOSMWebsite(), 2), GBC.eop().insets(8,0,0,0));217 p.add(new UrlLabel(Main.getJOSMWebsite(), 2), GBC.eop().insets(8, 0, 0, 0)); 218 218 p.add(new JMultilineLabel( 219 219 tr("You should also update your plugins. If neither of those help please " + 220 220 "file a bug report in our bugtracker using this link:")), 221 221 GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 222 p.add(getBugReportUrlLabel(urltext), GBC.eop().insets(8, 0,0,0));222 p.add(getBugReportUrlLabel(urltext), GBC.eop().insets(8, 0, 0, 0)); 223 223 p.add(new JMultilineLabel( 224 224 tr("There the error information provided below should already be " + … … 229 229 tr("Alternatively, if that does not work you can manually fill in the information " + 230 230 "below at this URL:")), GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 231 p.add(new UrlLabel(Main.getJOSMWebsite()+"/newticket", 2), GBC.eop().insets(8,0,0,0));231 p.add(new UrlLabel(Main.getJOSMWebsite()+"/newticket", 2), GBC.eop().insets(8, 0, 0, 0)); 232 232 233 233 // Wiki formatting for manual copy-paste … … 246 246 for (Component c: p.getComponents()) { 247 247 if (c instanceof JMultilineLabel) { 248 ((JMultilineLabel) c).setMaxWidth(400);248 ((JMultilineLabel) c).setMaxWidth(400); 249 249 } 250 250 } -
trunk/src/org/openstreetmap/josm/tools/ColorHelper.java
r8461 r8510 30 30 try { 31 31 return new Color( 32 Integer.parseInt(html.substring(0, 2),16),33 Integer.parseInt(html.substring(2, 4),16),34 Integer.parseInt(html.substring(4, 6),16),35 html.length() == 8 ? Integer.parseInt(html.substring(6, 8),16) : 255);32 Integer.parseInt(html.substring(0, 2), 16), 33 Integer.parseInt(html.substring(2, 4), 16), 34 Integer.parseInt(html.substring(4, 6), 16), 35 html.length() == 8 ? Integer.parseInt(html.substring(6, 8), 16) : 255); 36 36 } catch (NumberFormatException e) { 37 37 return null; -
trunk/src/org/openstreetmap/josm/tools/ColorScale.java
r8443 r8510 88 88 89 89 public final Color getColor(double value) { 90 if (value <min) return belowMinColor;91 if (value >max) return aboveMaxColor;90 if (value < min) return belowMinColor; 91 if (value > max) return aboveMaxColor; 92 92 if (Double.isNaN(value)) return noDataColor; 93 93 final int n = colors.length; 94 94 int idx = (int) ((value-min)*colors.length / (max-min)); 95 if (idx <colors.length) {95 if (idx < colors.length) { 96 96 return colors[idx]; 97 97 } else { … … 101 101 102 102 public final Color getColor(Number value) { 103 return (value ==null)? noDataColor : getColor(value.doubleValue());103 return (value == null) ? noDataColor : getColor(value.doubleValue()); 104 104 } 105 105 … … 132 132 int n = colors.length; 133 133 Color tmp; 134 for (int i =0; i<n/2; i++) {134 for (int i = 0; i < n/2; i++) { 135 135 tmp = colors[i]; 136 136 colors[i] = colors[n-1-i]; … … 144 144 145 145 public void drawColorBar(Graphics2D g, int x, int y, int w, int h, double valueScale) { 146 int n =colors.length;146 int n = colors.length; 147 147 148 for (int i =0; i<n; i++) {148 for (int i = 0; i < n; i++) { 149 149 g.setColor(colors[i]); 150 if (w <h) {150 if (w < h) { 151 151 g.fillRect(x, y+i*h/n, w, h/n+1); 152 152 } else { … … 158 158 FontMetrics fm = g.getFontMetrics(); 159 159 fh = fm.getHeight()/2; 160 fw = fm.stringWidth(String.valueOf(Math.max((int)Math.abs(max*valueScale), (int)Math.abs(min*valueScale)))) + fm.stringWidth("0.123"); 160 fw = fm.stringWidth(String.valueOf(Math.max((int) Math.abs(max*valueScale), 161 (int) Math.abs(min*valueScale)))) + fm.stringWidth("0.123"); 161 162 g.setColor(noDataColor); 162 163 if (title != null) { 163 164 g.drawString(title, x-fw-3, y-fh*3/2); 164 165 } 165 for (int i =0; i<=intervalCount; i++) {166 g.setColor(colors[(int) (1.0*i*n/intervalCount-1e-10)]);166 for (int i = 0; i <= intervalCount; i++) { 167 g.setColor(colors[(int) (1.0*i*n/intervalCount-1e-10)]); 167 168 final double val = min+i*(max-min)/intervalCount; 168 169 final String txt = String.format("%.3f", val*valueScale); 169 if (w <h) {170 if (w < h) { 170 171 g.drawString(txt, x-fw-3, y+i*h/intervalCount+fh/2); 171 172 } else { -
trunk/src/org/openstreetmap/josm/tools/CompositeList.java
r8470 r8510 13 13 */ 14 14 public class CompositeList<T> extends AbstractList<T> { 15 private List<? extends T> a, b;15 private List<? extends T> a, b; 16 16 17 17 /** -
trunk/src/org/openstreetmap/josm/tools/Diff.java
r8443 r8510 96 96 */ 97 97 public Diff(Object[] a, Object[] b) { 98 Map<Object, Integer> h = new HashMap<>(a.length + b.length);99 filevec = new FileData[] {new FileData(a, h), new FileData(b,h)};98 Map<Object, Integer> h = new HashMap<>(a.length + b.length); 99 filevec = new FileData[] {new FileData(a, h), new FileData(b, h)}; 100 100 } 101 101 … … 396 396 */ 397 397 public Change build_script( 398 boolean[] changed0, int len0,399 boolean[] changed1, int len1398 boolean[] changed0, int len0, 399 boolean[] changed1, int len1 400 400 ); 401 401 } … … 407 407 @Override 408 408 public Change build_script( 409 final boolean[] changed0, int len0,410 final boolean[] changed1, int len1) {409 final boolean[] changed0, int len0, 410 final boolean[] changed1, int len1) { 411 411 Change script = null; 412 412 int i0 = 0, i1 = 0; … … 440 440 @Override 441 441 public Change build_script( 442 final boolean[] changed0, int len0,443 final boolean[] changed1, int len1) {442 final boolean[] changed0, int len0, 443 final boolean[] changed1, int len1) { 444 444 Change script = null; 445 445 int i0 = len0, i1 = len1; … … 570 570 @Override 571 571 public String toString() { 572 String s = String.format("%d -%d +%d %d", line0,deleted,inserted,line1);572 String s = String.format("%d -%d +%d %d", line0, deleted, inserted, line1); 573 573 return (link != null) ? s = s + '\n' + link : s; 574 574 } … … 577 577 /** Data on one input file being compared. 578 578 */ 579 580 579 class FileData { 581 580 … … 801 800 } 802 801 803 FileData(Object[] data, Map<Object, Integer> h) {802 FileData(Object[] data, Map<Object, Integer> h) { 804 803 this(data.length); 805 804 // FIXME: diff 2.7 removes common prefix and common suffix … … 807 806 Integer ir = h.get(data[i]); 808 807 if (ir == null) { 809 h.put(data[i], equivs[i] = equivMax++);808 h.put(data[i], equivs[i] = equivMax++); 810 809 } else { 811 810 equivs[i] = ir.intValue(); -
trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java
r8509 r8510 56 56 } 57 57 58 59 58 public static String explainMissingOAuthAccessTokenException(MissingOAuthAccessTokenException e) { 60 59 Main.error(e); … … 129 128 OsmPrimitive firstRefs = conflict.b.iterator().next(); 130 129 String objId = Long.toString(conflict.a.getId()); 131 Collection<Long> refIds = Utils.transform(conflict.b, new Utils.Function<OsmPrimitive, Long>() {130 Collection<Long> refIds = Utils.transform(conflict.b, new Utils.Function<OsmPrimitive, Long>() { 132 131 133 132 @Override … … 653 652 654 653 if (e instanceof ChangesetClosedException) 655 return explainChangesetClosedException((ChangesetClosedException) e);654 return explainChangesetClosedException((ChangesetClosedException) e); 656 655 657 656 if (e instanceof OsmApiException) { -
trunk/src/org/openstreetmap/josm/tools/GBC.java
r6380 r8510 48 48 */ 49 49 public static GBC eop() { 50 return eol().insets(0, 0,0,10);50 return eol().insets(0, 0, 0, 10); 51 51 } 52 52 … … 119 119 short maxx = x > 0 ? Short.MAX_VALUE : 0; 120 120 short maxy = y > 0 ? Short.MAX_VALUE : 0; 121 return new Box.Filler(new Dimension(x, y), new Dimension(x,y), new Dimension(maxx,maxy));121 return new Box.Filler(new Dimension(x, y), new Dimension(x, y), new Dimension(maxx, maxy)); 122 122 } 123 123 -
trunk/src/org/openstreetmap/josm/tools/GeoPropertyIndex.java
r8470 r8510 73 73 public static int index(LatLon ll, int level) { 74 74 long noParts = 1 << level; 75 long x = ((long) ((ll.lon() + 180.0) * noParts / 360.0)) & 1;76 long y = ((long) ((ll.lat() + 90.0) * noParts / 180.0)) & 1;75 long x = ((long) ((ll.lon() + 180.0) * noParts / 360.0)) & 1; 76 long y = ((long) ((ll.lat() + 90.0) * noParts / 180.0)) & 1; 77 77 return (int) (2 * x + y); 78 78 } … … 149 149 if (DEBUG) System.err.println(" - new with idx "+idx); 150 150 LatLon center = bbox.getCenter(); 151 BBox b = new BBox(lon1, lat1, center.lon(), center.lat());151 BBox b = new BBox(lon1, lat1, center.lon(), center.lat()); 152 152 children[idx] = new GPLevel<>(level + 1, b, this, owner); 153 153 } -
trunk/src/org/openstreetmap/josm/tools/Geometry.java
r8509 r8510 93 93 94 94 //iterate over secondary segment 95 int seg2Start = seg1Way != seg2Way ? 0 : seg1Pos + 2;//skip the adjacent segment96 97 for (int seg2Pos = seg2Start; seg2Pos + 1 < way2Nodes.size(); seg2Pos++) {95 int seg2Start = seg1Way != seg2Way ? 0 : seg1Pos + 2; //skip the adjacent segment 96 97 for (int seg2Pos = seg2Start; seg2Pos + 1 < way2Nodes.size(); seg2Pos++) { 98 98 99 99 //need to get them again every time, because other segments may be changed … … 298 298 if (Math.abs(det) > 1e-12 * mag) { 299 299 double u = uu/det, v = vv/det; 300 if (u >-1e-8 && u < 1+1e-8 && v>-1e-8 && v < 1+1e-8) {301 if (u <0) u=0;302 if (u >1) u=1.0;300 if (u > -1e-8 && u < 1+1e-8 && v > -1e-8 && v < 1+1e-8) { 301 if (u < 0) u = 0; 302 if (u > 1) u = 1.0; 303 303 return new EastNorth(x1+a1*u, y1+a2*u); 304 304 } else { … … 654 654 } 655 655 656 protected static double calcY(Node p1) {656 protected static double calcY(Node p1) { 657 657 double lat1, lon1, lat2, lon2; 658 658 double dlon, dlat; … … 813 813 public static EastNorth getCenter(List<Node> nodes) { 814 814 int nc = nodes.size(); 815 if (nc < 3) return null;815 if (nc < 3) return null; 816 816 /** 817 817 * Equation of each bisector ax + by + c = 0 … … 821 821 double[] c = new double[nc]; 822 822 // Compute equation of bisector 823 for (int i = 0; i < nc; i++) {823 for (int i = 0; i < nc; i++) { 824 824 EastNorth pt1 = nodes.get(i).getEastNorth(); 825 825 EastNorth pt2 = nodes.get((i+1) % nc).getEastNorth(); … … 827 827 b[i] = pt1.north() - pt2.north(); 828 828 double d = Math.sqrt(a[i]*a[i] + b[i]*b[i]); 829 if (d == 0) return null;829 if (d == 0) return null; 830 830 a[i] /= d; 831 831 b[i] /= d; … … 838 838 // At.Y = [bi] 839 839 double b1 = 0, b2 = 0; 840 for (int i = 0; i < nc; i++) {840 for (int i = 0; i < nc; i++) { 841 841 a11 += a[i]*a[i]; 842 842 a12 += a[i]*b[i]; … … 847 847 // (At.A)^-1 = [invij] 848 848 double det = a11*a22 - a12*a12; 849 if (Math.abs(det) < 1e-5) return null;849 if (Math.abs(det) < 1e-5) return null; 850 850 double inv11 = a22/det; 851 851 double inv12 = -a12/det; -
trunk/src/org/openstreetmap/josm/tools/I18n.java
r8414 r8510 219 219 if (text == null) 220 220 return null; 221 return MessageFormat.format(gettext(text, context), (Object) null);221 return MessageFormat.format(gettext(text, context), (Object) null); 222 222 } 223 223 … … 227 227 if (text == null) 228 228 return null; 229 return MessageFormat.format(gettext_lazy(text, context), (Object) null);229 return MessageFormat.format(gettext_lazy(text, context), (Object) null); 230 230 } 231 231 … … 304 304 private static String gettext(String text, String ctx, boolean lazy) { 305 305 int i; 306 if (ctx == null && text.startsWith("_:") && (i = text.indexOf('\n')) >= 0) {307 ctx = text.substring(2, i-1);306 if (ctx == null && text.startsWith("_:") && (i = text.indexOf('\n')) >= 0) { 307 ctx = text.substring(2, i-1); 308 308 text = text.substring(i+1); 309 309 } 310 if (strings != null) {310 if (strings != null) { 311 311 String trans = strings.get(ctx == null ? text : "_:"+ctx+"\n"+text); 312 if (trans != null)312 if (trans != null) 313 313 return trans; 314 314 } 315 if (pstrings != null) {315 if (pstrings != null) { 316 316 i = pluralEval(1); 317 317 String[] trans = pstrings.get(ctx == null ? text : "_:"+ctx+"\n"+text); 318 if (trans != null && trans.length > i)318 if (trans != null && trans.length > i) 319 319 return trans[i]; 320 320 } … … 333 333 private static String gettextn(String text, String plural, String ctx, long num) { 334 334 int i; 335 if (ctx == null && text.startsWith("_:") && (i = text.indexOf('\n')) >= 0) {336 ctx = text.substring(2, i-1);335 if (ctx == null && text.startsWith("_:") && (i = text.indexOf('\n')) >= 0) { 336 ctx = text.substring(2, i-1); 337 337 text = text.substring(i+1); 338 338 } 339 if (pstrings != null) {339 if (pstrings != null) { 340 340 i = pluralEval(num); 341 341 String[] trans = pstrings.get(ctx == null ? text : "_:"+ctx+"\n"+text); 342 if (trans != null && trans.length > i)342 if (trans != null && trans.length > i) 343 343 return trans[i]; 344 344 } … … 353 353 354 354 private static URL getTranslationFile(String lang) { 355 return Main.class.getResource("/data/"+lang.replace("@", "-")+".lang");355 return Main.class.getResource("/data/"+lang.replace("@", "-")+".lang"); 356 356 } 357 357 … … 362 362 public static Locale[] getAvailableTranslations() { 363 363 Collection<Locale> v = new ArrayList<>(languages.size()); 364 if (getTranslationFile("en") != null) {364 if (getTranslationFile("en") != null) { 365 365 for (String loc : languages.keySet()) { 366 if (getTranslationFile(loc) != null) {366 if (getTranslationFile(loc) != null) { 367 367 v.add(LanguageInfo.getLocale(loc)); 368 368 } … … 444 444 445 445 /* try initial language settings, may be changed later again */ 446 if (!load(LanguageInfo.getJOSMLocaleCode())) {446 if (!load(LanguageInfo.getJOSMLocaleCode())) { 447 447 Locale.setDefault(Locale.ENGLISH); 448 448 } … … 471 471 ) { 472 472 found = false; 473 while (!found && (e = jarTrans.getNextEntry()) != null) {473 while (!found && (e = jarTrans.getNextEntry()) != null) { 474 474 String name = e.getName(); 475 475 if (name.equals(langfile)) … … 553 553 boolean multimode = false; 554 554 byte[] str = new byte[4096]; 555 for (;;) {556 if (multimode) {555 for (;;) { 556 if (multimode) { 557 557 int ennum = ens.read(); 558 558 int trnum = trs.read(); 559 if (trnum == 0xFE) /* marks identical string, handle equally to non-translated */559 if (trnum == 0xFE) /* marks identical string, handle equally to non-translated */ 560 560 trnum = 0; 561 if ((ennum == -1 && trnum != -1) || (ennum != -1 && trnum == -1)) /* files do not match */561 if ((ennum == -1 && trnum != -1) || (ennum != -1 && trnum == -1)) /* files do not match */ 562 562 return false; 563 if (ennum == -1) {563 if (ennum == -1) { 564 564 break; 565 565 } 566 566 String[] enstrings = new String[ennum]; 567 567 String[] trstrings = new String[trnum]; 568 for (int i = 0; i < ennum; ++i) {568 for (int i = 0; i < ennum; ++i) { 569 569 int val = ens.read(enlen); 570 if (val != 2) /* file corrupt */570 if (val != 2) /* file corrupt */ 571 571 return false; 572 val = (enlen[0] < 0 ? 256+enlen[0] :enlen[0])*256+(enlen[1] < 0 ? 256+enlen[1]:enlen[1]);573 if (val > str.length) {572 val = (enlen[0] < 0 ? 256+enlen[0] : enlen[0])*256+(enlen[1] < 0 ? 256+enlen[1] : enlen[1]); 573 if (val > str.length) { 574 574 str = new byte[val]; 575 575 } 576 576 int rval = ens.read(str, 0, val); 577 if (rval != val) /* file corrupt */577 if (rval != val) /* file corrupt */ 578 578 return false; 579 579 enstrings[i] = new String(str, 0, val, StandardCharsets.UTF_8); 580 580 } 581 for (int i = 0; i < trnum; ++i) {581 for (int i = 0; i < trnum; ++i) { 582 582 int val = trs.read(trlen); 583 if (val != 2) /* file corrupt */583 if (val != 2) /* file corrupt */ 584 584 return false; 585 val = (trlen[0] < 0 ? 256+trlen[0] :trlen[0])*256+(trlen[1] < 0 ? 256+trlen[1]:trlen[1]);586 if (val > str.length) {585 val = (trlen[0] < 0 ? 256+trlen[0] : trlen[0])*256+(trlen[1] < 0 ? 256+trlen[1] : trlen[1]); 586 if (val > str.length) { 587 587 str = new byte[val]; 588 588 } 589 589 int rval = trs.read(str, 0, val); 590 if (rval != val) /* file corrupt */590 if (rval != val) /* file corrupt */ 591 591 return false; 592 592 trstrings[i] = new String(str, 0, val, StandardCharsets.UTF_8); 593 593 } 594 if (trnum > 0 && !p.containsKey(enstrings[0])) {594 if (trnum > 0 && !p.containsKey(enstrings[0])) { 595 595 p.put(enstrings[0], trstrings); 596 596 } … … 598 598 int enval = ens.read(enlen); 599 599 int trval = trs.read(trlen); 600 if (enval != trval) /* files do not match */600 if (enval != trval) /* files do not match */ 601 601 return false; 602 if (enval == -1) {602 if (enval == -1) { 603 603 break; 604 604 } 605 if (enval != 2) /* files corrupt */605 if (enval != 2) /* files corrupt */ 606 606 return false; 607 enval = (enlen[0] < 0 ? 256+enlen[0] :enlen[0])*256+(enlen[1] < 0 ? 256+enlen[1]:enlen[1]);608 trval = (trlen[0] < 0 ? 256+trlen[0] :trlen[0])*256+(trlen[1] < 0 ? 256+trlen[1]:trlen[1]);609 if (trval == 0xFFFE) /* marks identical string, handle equally to non-translated */607 enval = (enlen[0] < 0 ? 256+enlen[0] : enlen[0])*256+(enlen[1] < 0 ? 256+enlen[1] : enlen[1]); 608 trval = (trlen[0] < 0 ? 256+trlen[0] : trlen[0])*256+(trlen[1] < 0 ? 256+trlen[1] : trlen[1]); 609 if (trval == 0xFFFE) /* marks identical string, handle equally to non-translated */ 610 610 trval = 0; 611 if (enval == 0xFFFF) {611 if (enval == 0xFFFF) { 612 612 multimode = true; 613 if (trval != 0xFFFF) /* files do not match */613 if (trval != 0xFFFF) /* files do not match */ 614 614 return false; 615 615 } else { … … 621 621 } 622 622 int val = ens.read(str, 0, enval); 623 if (val != enval) /* file corrupt */623 if (val != enval) /* file corrupt */ 624 624 return false; 625 625 String enstr = new String(str, 0, enval, StandardCharsets.UTF_8); 626 626 if (trval != 0) { 627 627 val = trs.read(str, 0, trval); 628 if (val != trval) /* file corrupt */628 if (val != trval) /* file corrupt */ 629 629 return false; 630 630 String trstr = new String(str, 0, trval, StandardCharsets.UTF_8); 631 if (!s.containsKey(enstr))631 if (!s.containsKey(enstr)) 632 632 s.put(enstr, trstr); 633 633 } … … 655 655 * @param localeName the locale name. Ignored if null. 656 656 */ 657 public static void set(String localeName) {657 public static void set(String localeName) { 658 658 if (localeName != null) { 659 659 Locale l = LanguageInfo.getLocale(localeName); -
trunk/src/org/openstreetmap/josm/tools/ImageOverlay.java
r8387 r8510 78 78 } 79 79 ImageIcon overlay; 80 if (width != -1 || height != -1) {80 if (width != -1 || height != -1) { 81 81 image = new ImageProvider(image).resetMaxSize(new Dimension(width, height)); 82 82 } … … 84 84 int x, y; 85 85 if (width == -1 && offsetLeft < 0) { 86 x = (int) (w*offsetRight) - overlay.getIconWidth();86 x = (int) (w*offsetRight) - overlay.getIconWidth(); 87 87 } else { 88 x = (int) (w*offsetLeft);88 x = (int) (w*offsetLeft); 89 89 } 90 90 if (height == -1 && offsetTop < 0) { 91 y = (int) (h*offsetBottom) - overlay.getIconHeight();91 y = (int) (h*offsetBottom) - overlay.getIconHeight(); 92 92 } else { 93 y = (int) (h*offsetTop);93 y = (int) (h*offsetTop); 94 94 } 95 95 overlay.paintIcon(null, ground.getGraphics(), x, y); -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r8509 r8510 742 742 if (dirs != null && !dirs.isEmpty()) { 743 743 cacheName = "id:" + id + ":" + fullName; 744 if (archive != null) {744 if (archive != null) { 745 745 cacheName += ":" + archive.getName(); 746 746 } … … 895 895 } else { 896 896 final String fn_md5 = Utils.md5Hex(fn); 897 url = b + fn_md5.substring(0, 1) + "/" + fn_md5.substring(0,2) + "/" + fn;897 url = b + fn_md5.substring(0, 1) + "/" + fn_md5.substring(0, 2) + "/" + fn; 898 898 } 899 899 result = getIfAvailableHttp(url, type); … … 924 924 ZipEntry entry = zipFile.getEntry(entryName); 925 925 if (entry != null) { 926 int size = (int) entry.getSize();926 int size = (int) entry.getSize(); 927 927 int offs = 0; 928 928 byte[] buf = new byte[size]; … … 937 937 return svg == null ? null : new ImageResource(svg); 938 938 case OTHER: 939 while (size > 0) {939 while (size > 0) { 940 940 int l = is.read(buf, offs, size); 941 941 offs += l; … … 1560 1560 Node root = metadata.getAsTree(f); 1561 1561 if (root instanceof Element) { 1562 NodeList list = ((Element) root).getElementsByTagName("TransparentColor");1562 NodeList list = ((Element) root).getElementsByTagName("TransparentColor"); 1563 1563 if (list.getLength() > 0) { 1564 1564 Node item = list.item(0); 1565 1565 if (item instanceof Element) { 1566 1566 // Handle different color spaces (tested with RGB and grayscale) 1567 String value = ((Element) item).getAttribute("value");1567 String value = ((Element) item).getAttribute("value"); 1568 1568 if (!value.isEmpty()) { 1569 1569 String[] s = value.split(" "); … … 1575 1575 int g = model.getGreen(pixel); 1576 1576 int b = model.getBlue(pixel); 1577 return new Color(r, g,b);1577 return new Color(r, g, b); 1578 1578 } else { 1579 1579 Main.warn("Unable to translate TransparentColor '"+value+"' with color model "+model); … … 1598 1598 int[] rgb = new int[3]; 1599 1599 try { 1600 for (int i = 0; i <3; i++) {1600 for (int i = 0; i < 3; i++) { 1601 1601 rgb[i] = Integer.parseInt(s[i]); 1602 1602 } -
trunk/src/org/openstreetmap/josm/tools/InputMapUtils.java
r7937 r8510 34 34 */ 35 35 public static void unassignCtrlShiftUpDown(JComponent cmp, int condition) { 36 InputMap inputMap =SwingUtilities.getUIInputMap(cmp, condition);37 inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.CTRL_MASK|InputEvent.SHIFT_MASK));38 inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.CTRL_MASK|InputEvent.SHIFT_MASK));39 inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.ALT_MASK|InputEvent.SHIFT_MASK));40 inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.ALT_MASK|InputEvent.SHIFT_MASK));41 SwingUtilities.replaceUIInputMap(cmp, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,inputMap);36 InputMap inputMap = SwingUtilities.getUIInputMap(cmp, condition); 37 inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK)); 38 inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK)); 39 inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK)); 40 inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK)); 41 SwingUtilities.replaceUIInputMap(cmp, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap); 42 42 } 43 43 -
trunk/src/org/openstreetmap/josm/tools/LanguageInfo.java
r8440 r8510 38 38 */ 39 39 public static String getWikiLanguagePrefix(LocaleType type) { 40 if (type == LocaleType.ENGLISH)40 if (type == LocaleType.ENGLISH) 41 41 return ""; 42 42 43 43 String code = getJOSMLocaleCode(); 44 if (type == LocaleType.BASELANGUAGE) {45 if (code.matches("[^_]+_[^_]+")) {46 code = code.substring(0, 2);44 if (type == LocaleType.BASELANGUAGE) { 45 if (code.matches("[^_]+_[^_]+")) { 46 code = code.substring(0, 2); 47 47 if ("en".equals(code)) 48 48 return null; … … 50 50 return null; 51 51 } 52 } else if (type == LocaleType.DEFAULTNOTENGLISH && "en".equals(code)) {52 } else if (type == LocaleType.DEFAULTNOTENGLISH && "en".equals(code)) { 53 53 return null; 54 } else if (code.matches(".+@.+")) {55 return code.substring(0, 1).toUpperCase(Locale.ENGLISH) + code.substring(1,2)56 + "-" + code.substring(3, 4).toUpperCase(Locale.ENGLISH) + code.substring(4) + ":";57 } 58 return code.substring(0, 1).toUpperCase(Locale.ENGLISH) + code.substring(1) + ":";54 } else if (code.matches(".+@.+")) { 55 return code.substring(0, 1).toUpperCase(Locale.ENGLISH) + code.substring(1, 2) 56 + "-" + code.substring(3, 4).toUpperCase(Locale.ENGLISH) + code.substring(4) + ":"; 57 } 58 return code.substring(0, 1).toUpperCase(Locale.ENGLISH) + code.substring(1) + ":"; 59 59 } 60 60 … … 95 95 public static String getJOSMLocaleCode(Locale locale) { 96 96 if (locale == null) return "en"; 97 for (String full : getLanguageCodes(locale)) {97 for (String full : getLanguageCodes(locale)) { 98 98 if ("iw_IL".equals(full)) 99 99 return "he"; … … 230 230 public static Collection<String> getLanguageCodes(Locale l) { 231 231 Collection<String> list = new LinkedList<String>(); 232 if (l == null)232 if (l == null) 233 233 l = Locale.getDefault(); 234 234 String lang = l.getLanguage(); 235 235 String c = l.getCountry(); 236 236 String v = l.getVariant(); 237 if (c.isEmpty())237 if (c.isEmpty()) 238 238 c = null; 239 if (v != null && !v.isEmpty()) {240 if (c != null)239 if (v != null && !v.isEmpty()) { 240 if (c != null) 241 241 list.add(lang+"_"+c+"@"+v); 242 242 list.add(lang+"@"+v); 243 243 } 244 if (c != null)244 if (c != null) 245 245 list.add(lang+"_"+c); 246 246 list.add(lang); -
trunk/src/org/openstreetmap/josm/tools/MultiMap.java
r8378 r8510 225 225 if (!(obj instanceof MultiMap)) 226 226 return false; 227 return map.equals(((MultiMap<?, ?>) obj).map);227 return map.equals(((MultiMap<?, ?>) obj).map); 228 228 } 229 229 -
trunk/src/org/openstreetmap/josm/tools/MultikeyActionsHandler.java
r8509 r8510 233 233 public void removeAction(MultikeyShortcutAction action) { 234 234 MyAction a = myActions.get(action); 235 if (a !=null) {235 if (a != null) { 236 236 Main.unregisterActionShortcut(a, a.shortcut); 237 237 myActions.remove(action); -
trunk/src/org/openstreetmap/josm/tools/MultikeyShortcutAction.java
r7937 r8510 23 23 public char getShortcut() { 24 24 if (index < 9) 25 return (char) ('1' + index);25 return (char) ('1' + index); 26 26 else if (index == 9) 27 27 return '0'; 28 28 else 29 return (char) ('A' + index - 10);29 return (char) ('A' + index - 10); 30 30 } 31 31 … … 38 38 39 39 void executeMultikeyAction(int index, boolean repeatLastAction); 40 40 41 List<MultikeyInfo> getMultikeyCombinations(); 42 41 43 MultikeyInfo getLastMultikeyAction(); 42 44 -
trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java
r8364 r8510 146 146 final Map<Character, Integer> array = new HashMap<>(); 147 147 148 for (int i =0; i<SHORTLINK_CHARS.length; ++i) {148 for (int i = 0; i < SHORTLINK_CHARS.length; ++i) { 149 149 array.put(SHORTLINK_CHARS[i], i); 150 150 } … … 159 159 if (array.containsKey(ch)) { 160 160 int val = array.get(ch); 161 for (int i =0; i<3; ++i) {161 for (int i = 0; i < 3; ++i) { 162 162 x <<= 1; 163 163 if ((val & 32) != 0) { -
trunk/src/org/openstreetmap/josm/tools/Pair.java
r8338 r8510 10 10 * @since 429 11 11 */ 12 public final class Pair<A, B> {12 public final class Pair<A, B> { 13 13 14 14 /** … … 40 40 public boolean equals(Object other) { 41 41 if (other instanceof Pair<?, ?>) { 42 Pair<?, ?> o = (Pair<?, ?>) other;42 Pair<?, ?> o = (Pair<?, ?>) other; 43 43 return a.equals(o.a) && b.equals(o.b); 44 44 } else … … 53 53 } 54 54 55 public static <T> Pair<T, T> sort(Pair<T,T> p) {55 public static <T> Pair<T, T> sort(Pair<T, T> p) { 56 56 if (p.b.hashCode() < p.a.hashCode()) { 57 57 T tmp = p.a; … … 73 73 * @return The newly created Pair(u,v) 74 74 */ 75 public static <U, V> Pair<U,V> create(U u, V v) {76 return new Pair<>(u, v);75 public static <U, V> Pair<U, V> create(U u, V v) { 76 return new Pair<>(u, v); 77 77 } 78 78 } -
trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java
r8461 r8510 49 49 Class<?> eawtOpenFilesHandler = Class.forName("com.apple.eawt.OpenFilesHandler"); 50 50 Class<?> eawtPreferencesHandler = Class.forName("com.apple.eawt.PreferencesHandler"); 51 Object appli = eawtApplication.getConstructor((Class[]) null).newInstance((Object[])null);51 Object appli = eawtApplication.getConstructor((Class[]) null).newInstance((Object[]) null); 52 52 Object proxy = Proxy.newProxyInstance(PlatformHookOsx.class.getClassLoader(), new Class<?>[] { 53 53 eawtQuitHandler, eawtAboutHandler, eawtOpenFilesHandler, eawtPreferencesHandler}, ivhandler); … … 98 98 Object oFiles = args[0].getClass().getMethod("getFiles").invoke(args[0]); 99 99 if (oFiles instanceof List) { 100 Main.worker.submit(new OpenFileTask((List<File>) oFiles, null) {100 Main.worker.submit(new OpenFileTask((List<File>) oFiles, null) { 101 101 @Override 102 102 protected void realRun() throws SAXException, IOException, OsmTransferException { … … 143 143 @Override 144 144 public void initSystemShortcuts() { 145 // CHECKSTYLE.OFF: LineLength 145 146 Shortcut.registerSystemShortcut("apple-reserved-01", tr("reserved"), KeyEvent.VK_SPACE, KeyEvent.META_DOWN_MASK).setAutomatic(); // Show or hide the Spotlight search field (when multiple languages are installed, may rotate through enabled script systems). 146 147 Shortcut.registerSystemShortcut("apple-reserved-02", tr("reserved"), KeyEvent.VK_SPACE, KeyEvent.META_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK).setAutomatic(); // Apple reserved. … … 277 278 Shortcut.registerSystemShortcut("view:zoomin", tr("reserved"), KeyEvent.VK_ADD, KeyEvent.META_DOWN_MASK); // Zoom in 278 279 Shortcut.registerSystemShortcut("view:zoomout", tr("reserved"), KeyEvent.VK_SUBTRACT, KeyEvent.META_DOWN_MASK); // Zoom out 280 // CHECKSTYLE.ON: LineLength 279 281 } 280 282 -
trunk/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java
r8509 r8510 131 131 public void initSystemShortcuts() { 132 132 // TODO: Insert system shortcuts here. See Windows and especially OSX to see how to. 133 for (int i = KeyEvent.VK_F1; i <= KeyEvent.VK_F12; ++i)133 for (int i = KeyEvent.VK_F1; i <= KeyEvent.VK_F12; ++i) 134 134 Shortcut.registerSystemShortcut("screen:toogle"+i, tr("reserved"), 135 135 i, KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK).setAutomatic(); … … 265 265 String line = Utils.strip(input.readLine()); 266 266 if (line != null && !line.isEmpty()) { 267 line = line.replaceAll("\"+", "");268 line = line.replaceAll("NAME=", ""); // strange code for some Gentoo's269 if (line.startsWith("Linux ")) // e.g. Linux Mint267 line = line.replaceAll("\"+", ""); 268 line = line.replaceAll("NAME=", ""); // strange code for some Gentoo's 269 if (line.startsWith("Linux ")) // e.g. Linux Mint 270 270 return line; 271 else if (!line.isEmpty())271 else if (!line.isEmpty()) 272 272 return "Linux " + line; 273 273 } … … 381 381 result = prefix + result; 382 382 } 383 if (result != null)384 result = result.replaceAll("\"+", "");383 if (result != null) 384 result = result.replaceAll("\"+", ""); 385 385 return result; 386 386 } -
trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java
r8404 r8510 103 103 @Override 104 104 public void initSystemShortcuts() { 105 // CHECKSTYLE.OFF: LineLength 105 106 //Shortcut.registerSystemCut("system:menuexit", tr("reserved"), VK_Q, CTRL_DOWN_MASK); 106 107 Shortcut.registerSystemShortcut("system:duplicate", tr("reserved"), VK_D, CTRL_DOWN_MASK); // not really system, but to avoid odd results … … 169 170 Shortcut.registerSystemShortcut("microsoft-reserved-52", tr("reserved"), VK_SHIFT, CTRL_DOWN_MASK).setAutomatic(); // Switch the keyboard layout when multiple keyboard layouts are enabled 170 171 //Shortcut.registerSystemCut("microsoft-reserved-53", tr("reserved"), ); // Change the reading direction of text in right-to-left reading languages (TODO: unclear) 172 // CHECKSTYLE.ON: LineLength 171 173 } 172 174 -
trunk/src/org/openstreetmap/josm/tools/Shortcut.java
r8509 r8510 35 35 */ 36 36 public final class Shortcut { 37 private String shortText; // the unique ID of the shortcut 38 private String longText; // a human readable description that will be shown in the preferences 39 private final int requestedKey; // the key, the caller requested 40 private final int requestedGroup;// the group, the caller requested 41 private int assignedKey; // the key that actually is used 42 private int assignedModifier; // the modifiers that are used 43 private boolean assignedDefault; // true if it got assigned what was requested. (Note: modifiers will be ignored in favour of group when loading it from the preferences then.) 44 private boolean assignedUser; // true if the user changed this shortcut 45 private boolean automatic; // true if the user cannot change this shortcut (Note: it also will not be saved into the preferences) 46 private boolean reset; // true if the user requested this shortcut to be set to its default value (will happen on next restart, as this shortcut will not be saved to the preferences) 37 /** the unique ID of the shortcut */ 38 private final String shortText; 39 /** a human readable description that will be shown in the preferences */ 40 private String longText; 41 /** the key, the caller requested */ 42 private final int requestedKey; 43 /** the group, the caller requested */ 44 private final int requestedGroup; 45 /** the key that actually is used */ 46 private int assignedKey; 47 /** the modifiers that are used */ 48 private int assignedModifier; 49 /** true if it got assigned what was requested. 50 * (Note: modifiers will be ignored in favour of group when loading it from the preferences then.) */ 51 private boolean assignedDefault; 52 /** true if the user changed this shortcut */ 53 private boolean assignedUser; 54 /** true if the user cannot change this shortcut (Note: it also will not be saved into the preferences) */ 55 private boolean automatic; 56 /** true if the user requested this shortcut to be set to its default value 57 * (will happen on next restart, as this shortcut will not be saved to the preferences) */ 58 private boolean reset; 47 59 48 60 // simple constructor … … 218 230 if (keyStroke == null) return ""; 219 231 String modifText = KeyEvent.getKeyModifiersText(keyStroke.getModifiers()); 220 if ("".equals 232 if ("".equals(modifText)) return KeyEvent.getKeyText(keyStroke.getKeyCode()); 221 233 return modifText + "+" + KeyEvent.getKeyText(keyStroke.getKeyCode()); 222 234 } … … 235 247 236 248 // and here our modifier groups 237 private static Map<Integer, Integer> groups = new HashMap<>();249 private static Map<Integer, Integer> groups = new HashMap<>(); 238 250 239 251 // check if something collides with an existing shortcut … … 301 313 groups.put(SHIFT, KeyEvent.SHIFT_DOWN_MASK); 302 314 groups.put(CTRL, commandDownMask); 303 groups.put(ALT_SHIFT, KeyEvent.ALT_DOWN_MASK |KeyEvent.SHIFT_DOWN_MASK);304 groups.put(ALT_CTRL, KeyEvent.ALT_DOWN_MASK |commandDownMask);305 groups.put(CTRL_SHIFT, commandDownMask |KeyEvent.SHIFT_DOWN_MASK);306 groups.put(ALT_CTRL_SHIFT, KeyEvent.ALT_DOWN_MASK |commandDownMask|KeyEvent.SHIFT_DOWN_MASK);315 groups.put(ALT_SHIFT, KeyEvent.ALT_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK); 316 groups.put(ALT_CTRL, KeyEvent.ALT_DOWN_MASK | commandDownMask); 317 groups.put(CTRL_SHIFT, commandDownMask | KeyEvent.SHIFT_DOWN_MASK); 318 groups.put(ALT_CTRL_SHIFT, KeyEvent.ALT_DOWN_MASK | commandDownMask | KeyEvent.SHIFT_DOWN_MASK); 307 319 308 320 // (1) System reserved shortcuts … … 310 322 // (2) User defined shortcuts 311 323 List<Shortcut> newshortcuts = new LinkedList<>(); 312 for (String s : Main.pref.getAllPrefixCollectionKeys("shortcut.entry.")) {324 for (String s : Main.pref.getAllPrefixCollectionKeys("shortcut.entry.")) { 313 325 newshortcuts.add(new Shortcut(s)); 314 326 } 315 327 316 for (Shortcut sc : newshortcuts) {328 for (Shortcut sc : newshortcuts) { 317 329 if (sc.isAssignedUser() 318 330 && findShortcut(sc.getAssignedKey(), sc.getAssignedModifier()) == null) { … … 321 333 } 322 334 // Shortcuts at their default values 323 for (Shortcut sc : newshortcuts) {335 for (Shortcut sc : newshortcuts) { 324 336 if (!sc.isAssignedUser() && sc.isAssignedDefault() 325 337 && findShortcut(sc.getAssignedKey(), sc.getAssignedModifier()) == null) { … … 328 340 } 329 341 // Shortcuts that were automatically moved 330 for (Shortcut sc : newshortcuts) {342 for (Shortcut sc : newshortcuts) { 331 343 if (!sc.isAssignedUser() && !sc.isAssignedDefault() 332 344 && findShortcut(sc.getAssignedKey(), sc.getAssignedModifier()) == null) { … … 338 350 private static int getGroupModifier(int group) { 339 351 Integer m = groups.get(group); 340 if (m == null)352 if (m == null) 341 353 m = -1; 342 354 return m; … … 344 356 345 357 private static int findModifier(int group, Integer modifier) { 346 if (modifier == null) {358 if (modifier == null) { 347 359 modifier = getGroupModifier(group); 348 360 if (modifier == null) { // garbage in, no shortcut out … … 440 452 switch (requestedGroup) { 441 453 case CTRL: return KeyEvent.CTRL_DOWN_MASK; 442 case ALT_CTRL: return KeyEvent.ALT_DOWN_MASK |KeyEvent.CTRL_DOWN_MASK;443 case CTRL_SHIFT: return KeyEvent.CTRL_DOWN_MASK |KeyEvent.SHIFT_DOWN_MASK;444 case ALT_CTRL_SHIFT: return KeyEvent.ALT_DOWN_MASK |KeyEvent.CTRL_DOWN_MASK|KeyEvent.SHIFT_DOWN_MASK;454 case ALT_CTRL: return KeyEvent.ALT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK; 455 case CTRL_SHIFT: return KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK; 456 case ALT_CTRL_SHIFT: return KeyEvent.ALT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK; 445 457 default: return 0; 446 458 } -
trunk/src/org/openstreetmap/josm/tools/TextTagParser.java
r8482 r8510 95 95 pos++; 96 96 break; 97 } else if (!quotesStarted && (Arrays.binarySearch(stop, c) >=0)) {97 } else if (!quotesStarted && (Arrays.binarySearch(stop, c) >= 0)) { 98 98 // stop-symbol found 99 99 pos++; … … 101 101 } else { 102 102 // skip non-printable characters 103 if (c>=32) s.append(c);103 if (c >= 32) s.append(c); 104 104 } 105 105 pos++; … … 118 118 if (c == '\t' || c == '\n' || c == ' ') { 119 119 pos++; 120 } else if (c == '=') {120 } else if (c == '=') { 121 121 if (signFound) break; // a = =qwerty means "a"="=qwerty" 122 122 signFound = true; … … 150 150 } 151 151 } 152 String text = k.substring(1, k.length()-1);152 String text = k.substring(1, k.length()-1); 153 153 return (new TextAnalyzer(text)).parseString("\r\t\n"); 154 154 } … … 165 165 Pattern p = Pattern.compile(tagRegex); 166 166 Map<String, String> tags = new HashMap<>(); 167 String k =null, v=null;167 String k = null, v = null; 168 168 for (String line: lines) { 169 169 if (line.trim().isEmpty()) continue; // skip empty lines 170 170 Matcher m = p.matcher(line); 171 171 if (m.matches()) { 172 k=m.group(1).trim(); v=m.group(2).trim(); 172 k = m.group(1).trim(); 173 v = m.group(2).trim(); 173 174 if (unescapeTextInQuotes) { 174 175 k = unescape(k); 175 176 v = unescape(v); 176 if (k ==null || v==null) return null;177 if (k == null || v == null) return null; 177 178 } 178 tags.put(k, v);179 tags.put(k, v); 179 180 } else { 180 181 return null; … … 188 189 } 189 190 190 public static Map<String, String> getValidatedTagsFromText(String buf) {191 Map<String, String> tags = readTagsFromText(buf);191 public static Map<String, String> getValidatedTagsFromText(String buf) { 192 Map<String, String> tags = readTagsFromText(buf); 192 193 return validateTags(tags) ? tags : null; 193 194 } … … 198 199 * @return null if no format is suitable 199 200 */ 200 public static Map<String, String> readTagsFromText(String buf) {201 Map<String, String> tags;201 public static Map<String, String> readTagsFromText(String buf) { 202 Map<String, String> tags; 202 203 203 204 // Format … … 205 206 tags = readTagsByRegexp(buf, "[\\r\\n]+", ".*?([a-zA-Z0-9:_]+).*\\t(.*?)", false); 206 207 // try "tag\tvalue\n" format 207 if (tags !=null) return tags;208 if (tags != null) return tags; 208 209 209 210 // Format … … 214 215 tags = readTagsByRegexp(buf, "[\\n\\t\\r]+", "(.*?)=(.*?)", true); 215 216 // try format t1=v1\n t2=v2\n ... 216 if (tags !=null) return tags;217 if (tags != null) return tags; 217 218 218 219 // JSON-format … … 223 224 tags = readTagsByRegexp(bufJson, "[\\s]*,[\\s]*", 224 225 "[\\s]*(\\\".*?[^\\\\]\\\")"+"[\\s]*:[\\s]*"+"(\\\".*?[^\\\\]\\\")[\\s]*", true); 225 if (tags !=null) return tags;226 if (tags != null) return tags; 226 227 227 228 // Free format … … 240 241 if (s > MAX_KEY_COUNT) { 241 242 // Use trn() even if for english it makes no sense, as s > 30 242 r =warning(trn("There was {0} tag found in the buffer, it is suspicious!",243 r = warning(trn("There was {0} tag found in the buffer, it is suspicious!", 243 244 "There were {0} tags found in the buffer, it is suspicious!", s, 244 245 s), "", "tags.paste.toomanytags"); 245 if (r ==2 || r==3) return false; if (r==4) return true;246 if (r == 2 || r == 3) return false; if (r == 4) return true; 246 247 } 247 248 for (Entry<String, String> entry : tags.entrySet()) { … … 250 251 if (key.length() > MAX_KEY_LENGTH) { 251 252 r = warning(tr("Key is too long (max {0} characters):", MAX_KEY_LENGTH), key+"="+value, "tags.paste.keytoolong"); 252 if (r ==2 || r==3) return false; if (r==4) return true;253 if (r == 2 || r == 3) return false; if (r == 4) return true; 253 254 } 254 255 if (!key.matches(KEY_PATTERN)) { 255 256 r = warning(tr("Suspicious characters in key:"), key, "tags.paste.keydoesnotmatch"); 256 if (r ==2 || r==3) return false; if (r==4) return true;257 if (r == 2 || r == 3) return false; if (r == 4) return true; 257 258 } 258 259 if (value.length() > MAX_VALUE_LENGTH) { 259 260 r = warning(tr("Value is too long (max {0} characters):", MAX_VALUE_LENGTH), value, "tags.paste.valuetoolong"); 260 if (r ==2 || r==3) return false; if (r==4) return true;261 if (r == 2 || r == 3) return false; if (r == 4) return true; 261 262 } 262 263 } … … 270 271 new String[]{tr("Ok"), tr("Cancel"), tr("Clear buffer"), tr("Ignore warnings")}); 271 272 ed.setButtonIcons(new String[]{"ok", "cancel", "dialogs/delete", "pastetags"}); 272 ed.setContent("<html><b>"+text + "</b><br/><br/><div width=\"300px\">"+XmlWriter.encode(data, true)+"</html>");273 ed.setContent("<html><b>"+text + "</b><br/><br/><div width=\"300px\">"+XmlWriter.encode(data, true)+"</html>"); 273 274 ed.setDefaultButton(2); 274 275 ed.setCancelButton(2); … … 277 278 ed.showDialog(); 278 279 int r = ed.getValue(); 279 if (r ==0) r = 2;280 if (r == 0) r = 2; 280 281 // clean clipboard if user asked 281 if (r ==3) Utils.copyToClipboard("");282 if (r == 3) Utils.copyToClipboard(""); 282 283 return r; 283 284 } … … 292 293 + " or suitable text. </p></html>"); 293 294 JPanel p = new JPanel(new GridBagLayout()); 294 p.add(new JLabel(msg), GBC.eop());295 p.add(new JLabel(msg), GBC.eop()); 295 296 String helpUrl = HelpUtil.getHelpTopicUrl(HelpUtil.buildAbsoluteHelpTopic(helpTopic, LocaleType.DEFAULT)); 296 297 if (helpUrl != null) { … … 314 315 int r = ed.getValue(); 315 316 // clean clipboard if user asked 316 if (r ==2) Utils.copyToClipboard("");317 if (r == 2) Utils.copyToClipboard(""); 317 318 } 318 319 } -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r8443 r8510 214 214 if (!condition) 215 215 throw new AssertionError( 216 MessageFormat.format(message, data)216 MessageFormat.format(message, data) 217 217 ); 218 218 } … … 574 574 } 575 575 576 private static final char[] HEX_ARRAY = {'0', '1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};576 private static final char[] HEX_ARRAY = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; 577 577 578 578 /** … … 611 611 * @return the list of sorted objects 612 612 */ 613 public static <T> List<T> topologicalSort(final MultiMap<T, T> dependencies) {614 MultiMap<T, T> deps = new MultiMap<>();613 public static <T> List<T> topologicalSort(final MultiMap<T, T> dependencies) { 614 MultiMap<T, T> deps = new MultiMap<>(); 615 615 for (T key : dependencies.keySet()) { 616 616 deps.putVoid(key); … … 623 623 int size = deps.size(); 624 624 List<T> sorted = new ArrayList<>(); 625 for (int i =0; i<size; ++i) {625 for (int i = 0; i < size; ++i) { 626 626 T parentless = null; 627 627 for (T key : deps.keySet()) { … … 839 839 if (connection != null) { 840 840 connection.setRequestProperty("User-Agent", Version.getInstance().getFullAgentString()); 841 connection.setConnectTimeout(Main.pref.getInteger("socket.timeout.connect", 15)*1000);842 connection.setReadTimeout(Main.pref.getInteger("socket.timeout.read", 30)*1000);841 connection.setConnectTimeout(Main.pref.getInteger("socket.timeout.connect", 15)*1000); 842 connection.setReadTimeout(Main.pref.getInteger("socket.timeout.read", 30)*1000); 843 843 } 844 844 return connection; … … 1158 1158 StringBuilder sb = new StringBuilder(url.substring(0, url.indexOf('?') + 1)); 1159 1159 1160 for (int i =0; i<query.length(); i++) {1160 for (int i = 0; i < query.length(); i++) { 1161 1161 String c = query.substring(i, i+1); 1162 1162 if (URL_CHARS.contains(c)) { -
trunk/src/org/openstreetmap/josm/tools/WikiReader.java
r8390 r8510 72 72 73 73 languageCode = LanguageInfo.getWikiLanguagePrefix(LocaleType.DEFAULTNOTENGLISH); 74 if (languageCode != null) {74 if (languageCode != null) { 75 75 res = readLang(new URL(getBaseUrlWiki() + languageCode + text)); 76 76 } 77 77 78 if (res.isEmpty()) {78 if (res.isEmpty()) { 79 79 languageCode = LanguageInfo.getWikiLanguagePrefix(LocaleType.BASELANGUAGE); 80 if (languageCode != null) {80 if (languageCode != null) { 81 81 res = readLang(new URL(getBaseUrlWiki() + languageCode + text)); 82 82 } 83 83 } 84 84 85 if (res.isEmpty()) {85 if (res.isEmpty()) { 86 86 languageCode = LanguageInfo.getWikiLanguagePrefix(LocaleType.ENGLISH); 87 if (languageCode != null) {87 if (languageCode != null) { 88 88 res = readLang(new URL(getBaseUrlWiki() + languageCode + text)); 89 89 } 90 90 } 91 91 92 if (res.isEmpty()) {92 if (res.isEmpty()) { 93 93 throw new IOException(text + " does not exist"); 94 94 } else { … … 157 157 || b.indexOf(" does not exist. You can create it here.</p>") >= 0) 158 158 return ""; 159 if (b.isEmpty())159 if (b.isEmpty()) 160 160 b = full; 161 161 return "<html><base href=\""+url.toExternalForm() +"\"> " + b + "</html>"; -
trunk/src/org/openstreetmap/josm/tools/WindowGeometry.java
r8443 r8510 72 72 } 73 73 if (reference == null) 74 return new WindowGeometry(new Point(0, 0), extent);75 parentWindow = (Window) reference;74 return new WindowGeometry(new Point(0, 0), extent); 75 parentWindow = (Window) reference; 76 76 Point topLeft = new Point( 77 77 Math.max(0, (parentWindow.getSize().width - extent.width) /2), … … 139 139 Rectangle oldScreen = getScreenInfo(getRectangle()); 140 140 Rectangle newScreen = getScreenInfo(new Rectangle(window.getLocationOnScreen(), window.getSize())); 141 if (oldScreen.x != newScreen.x) {141 if (oldScreen.x != newScreen.x) { 142 142 this.topLeft.x += newScreen.x - oldScreen.x; 143 143 } 144 if (oldScreen.y != newScreen.y) {144 if (oldScreen.y != newScreen.y) { 145 145 this.topLeft.y += newScreen.y - oldScreen.y; 146 146 } … … 150 150 String v = ""; 151 151 try { 152 Pattern p = Pattern.compile(field + "=(-?\\d+)", Pattern.CASE_INSENSITIVE);152 Pattern p = Pattern.compile(field + "=(-?\\d+)", Pattern.CASE_INSENSITIVE); 153 153 Matcher m = p.matcher(preferenceValue); 154 154 if (!m.find()) … … 158 158 v = m.group(1); 159 159 return Integer.parseInt(v); 160 } catch (WindowGeometryException e) {160 } catch (WindowGeometryException e) { 161 161 throw e; 162 } catch (NumberFormatException e) {162 } catch (NumberFormatException e) { 163 163 throw new WindowGeometryException( 164 tr("Preference with key ''{0}'' does not provide an int value for ''{1}''. Got {2}. Cannot restore window geometry from preferences.", 164 tr("Preference with key ''{0}'' does not provide an int value for ''{1}''. Got {2}. " + 165 "Cannot restore window geometry from preferences.", 165 166 preferenceKey, field, v), e); 166 } catch (Exception e) {167 } catch (Exception e) { 167 168 throw new WindowGeometryException( 168 tr("Failed to parse field ''{1}'' in preference with key ''{0}''. Exception was: {2}. Cannot restore window geometry from preferences.", 169 tr("Failed to parse field ''{1}'' in preference with key ''{0}''. Exception was: {2}. " + 170 "Cannot restore window geometry from preferences.", 169 171 preferenceKey, field, e.toString()), e); 170 172 } … … 207 209 } 208 210 } 209 return new WindowGeometry(new Point(x, y), new Dimension(w,h));211 return new WindowGeometry(new Point(x, y), new Dimension(w, h)); 210 212 } else { 211 213 Main.warn(tr("Ignoring malformed geometry: {0}", arg)); … … 213 215 } 214 216 WindowGeometry def; 215 if (maximize) {217 if (maximize) { 216 218 def = new WindowGeometry(screenDimension); 217 219 } else { … … 248 250 try { 249 251 initFromPreferences(preferenceKey); 250 } catch (WindowGeometryException e) {252 } catch (WindowGeometryException e) { 251 253 initFromWindowGeometry(defaultGeometry); 252 254 } … … 413 415 Rectangle g = new WindowGeometry(preferenceKey, 414 416 /* default: something on screen 1 */ 415 new WindowGeometry(new Point(0, 0), new Dimension(10,10))).getRectangle();417 new WindowGeometry(new Point(0, 0), new Dimension(10, 10))).getRectangle(); 416 418 return getScreenInfo(g); 417 419 } … … 467 469 */ 468 470 public static Rectangle getFullScreenInfo() { 469 return new Rectangle(new Point(0, 0), Toolkit.getDefaultToolkit().getScreenSize());471 return new Rectangle(new Point(0, 0), Toolkit.getDefaultToolkit().getScreenSize()); 470 472 } 471 473 -
trunk/src/org/openstreetmap/josm/tools/XmlObjectParser.java
r8509 r8510 300 300 filter.setContentHandler(validator); 301 301 return start(in, filter); 302 } catch (IOException e) {302 } catch (IOException e) { 303 303 throw new SAXException(tr("Failed to load XML schema."), e); 304 304 } … … 306 306 307 307 public void map(String tagName, Class<?> klass) { 308 mapping.put(tagName, new Entry(klass, false,false));308 mapping.put(tagName, new Entry(klass, false, false)); 309 309 } 310 310 311 311 public void mapOnStart(String tagName, Class<?> klass) { 312 mapping.put(tagName, new Entry(klass, true,false));312 mapping.put(tagName, new Entry(klass, true, false)); 313 313 } 314 314 315 315 public void mapBoth(String tagName, Class<?> klass) { 316 mapping.put(tagName, new Entry(klass, false,true));316 mapping.put(tagName, new Entry(klass, false, true)); 317 317 } 318 318 -
trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java
r8374 r8510 54 54 try { 55 55 fact = DatatypeFactory.newInstance(); 56 } catch (DatatypeConfigurationException ce) {56 } catch (DatatypeConfigurationException ce) { 57 57 Main.error(ce); 58 58 } … … 77 77 parsePart(str, 8, 2), 78 78 parsePart(str, 11, 2), 79 parsePart(str, 14, 2),79 parsePart(str, 14, 2), 80 80 parsePart(str, 17, 2)); 81 81 … … 87 87 88 88 return calendar.getTime(); 89 } else if (checkLayout(str, "xxxx-xx-xxTxx:xx:xx.xxxZ") ||89 } else if (checkLayout(str, "xxxx-xx-xxTxx:xx:xx.xxxZ") || 90 90 checkLayout(str, "xxxx-xx-xxTxx:xx:xx.xxx") || 91 91 checkLayout(str, "xxxx-xx-xxTxx:xx:xx.xxx+xx:00") || … … 96 96 parsePart(str, 8, 2), 97 97 parsePart(str, 11, 2), 98 parsePart(str, 14, 2),98 parsePart(str, 14, 2), 99 99 parsePart(str, 17, 2)); 100 100 long millis = parsePart(str, 20, 3); … … 108 108 SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yy HH:mm:ss"); 109 109 Date d = f.parse(str, new ParsePosition(0)); 110 if (d != null)110 if (d != null) 111 111 return d; 112 112 } … … 133 133 private static boolean checkLayout(String text, String pattern) { 134 134 if (text.length() != pattern.length()) return false; 135 for (int i =0; i<pattern.length(); i++) {135 for (int i = 0; i < pattern.length(); i++) { 136 136 char pc = pattern.charAt(i); 137 137 char tc = text.charAt(i); 138 if (pc == 'x' && tc >= '0' && tc <= '9') continue;139 else if (pc == 'x' || pc != tc) return false;138 if (pc == 'x' && tc >= '0' && tc <= '9') continue; 139 else if (pc == 'x' || pc != tc) return false; 140 140 } 141 141 return true; -
trunk/src/org/openstreetmap/josm/tools/template_engine/ContextSwitchTemplate.java
r8509 r8510 42 42 private abstract class ContextProvider extends Match { 43 43 protected Match condition; 44 44 45 abstract List<OsmPrimitive> getPrimitives(OsmPrimitive root); 45 46 } … … 51 52 this.childCondition = child; 52 53 } 53 @Override 54 public boolean match(OsmPrimitive osm) { 55 throw new UnsupportedOperationException(); 56 } 54 55 @Override 56 public boolean match(OsmPrimitive osm) { 57 throw new UnsupportedOperationException(); 58 } 59 57 60 @Override 58 61 List<OsmPrimitive> getPrimitives(OsmPrimitive root) { … … 194 197 195 198 if (lhs instanceof ContextProvider && rhs instanceof ContextProvider) 196 return new AndSet((ContextProvider) lhs, (ContextProvider)rhs);199 return new AndSet((ContextProvider) lhs, (ContextProvider) rhs); 197 200 else if (lhs instanceof ContextProvider) { 198 201 ContextProvider cp = (ContextProvider) lhs; … … 218 221 219 222 if (lhs instanceof ContextProvider && rhs instanceof ContextProvider) 220 return new OrSet((ContextProvider) lhs, (ContextProvider)rhs);223 return new OrSet((ContextProvider) lhs, (ContextProvider) rhs); 221 224 else if (lhs instanceof ContextProvider) 222 225 throw new ParseError( -
trunk/src/org/openstreetmap/josm/tools/template_engine/TemplateEngineDataProvider.java
r7937 r8510 8 8 public interface TemplateEngineDataProvider { 9 9 Collection<String> getTemplateKeys(); 10 10 11 Object getTemplateValue(String name, boolean special); 12 11 13 boolean evaluateCondition(Match condition); 12 14 } -
trunk/src/org/openstreetmap/josm/tools/template_engine/TemplateEntry.java
r7937 r8510 4 4 public interface TemplateEntry { 5 5 void appendText(StringBuilder result, TemplateEngineDataProvider dataProvider); 6 6 7 boolean isValid(TemplateEngineDataProvider dataProvider); 7 8 } -
trunk/src/org/openstreetmap/josm/tools/template_engine/Tokenizer.java
r7937 r8510 36 36 @Override 37 37 public String toString() { 38 return type + (text != null ?" " + text:"");38 return type + (text != null ? " " + text : ""); 39 39 } 40 40 } … … 85 85 return new Token(TokenType.CONDITION_START, position); 86 86 } else 87 throw ParseError.unexpectedChar('{', (char) c, position);87 throw ParseError.unexpectedChar('{', (char) c, position); 88 88 case '!': 89 89 getChar(); … … 92 92 return new Token(TokenType.CONTEXT_SWITCH_START, position); 93 93 } else 94 throw ParseError.unexpectedChar('{', (char) c, position);94 throw ParseError.unexpectedChar('{', (char) c, position); 95 95 case '}': 96 96 getChar(); … … 103 103 return new Token(TokenType.APOSTROPHE, position); 104 104 default: 105 while (c != -1 && !specialCharaters.contains((char) c)) {105 while (c != -1 && !specialCharaters.contains((char) c)) { 106 106 if (c == '\\') { 107 107 getChar(); … … 110 110 } 111 111 } 112 text.append((char) c);112 text.append((char) c); 113 113 getChar(); 114 114 } … … 132 132 getChar(); 133 133 } 134 result.append((char) c);134 result.append((char) c); 135 135 getChar(); 136 136 } 137 137 return new Token(TokenType.TEXT, position, result.toString()); 138 138 } 139 140 139 }
Note:
See TracChangeset
for help on using the changeset viewer.