8 | | {{{ |
9 | | #!patch |
10 | | Index: src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java |
11 | | =================================================================== |
12 | | --- src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java (revision 13193) |
13 | | +++ src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java (working copy) |
14 | | @@ -90,8 +90,12 @@ |
15 | | private static double bilinUpper; |
16 | | private static double bilinLower; |
17 | | |
18 | | - @Override |
19 | | - public void preferenceChanged(PreferenceChangeEvent e) { |
20 | | + /** |
21 | | + * Avoid find-bugs bad style warnings by write accessing static members from |
22 | | + * a static method only. |
23 | | + * @param e {@code PreferenceChangeEvent} |
24 | | + */ |
25 | | + public static synchronized void preferenceChangedImpl(PreferenceChangeEvent e) { |
26 | | if (e == null || |
27 | | e.getKey().equals(AGPIFO_STYLE.getKey())) { |
28 | | dragButton = AGPIFO_STYLE.get() ? 1 : 3; |
29 | | @@ -106,6 +110,11 @@ |
30 | | } |
31 | | } |
32 | | |
33 | | + @Override |
34 | | + public void preferenceChanged(PreferenceChangeEvent e) { |
35 | | + preferenceChangedImpl(e); |
36 | | + } |
37 | | + |
38 | | /** |
39 | | * Manage the visible rectangle of an image with full bounds stored in init. |
40 | | * @since 13127 |
41 | | @@ -216,8 +225,8 @@ |
42 | | |
43 | | private final File file; |
44 | | private final int orientation; |
45 | | - private int width; |
46 | | - private int height; |
47 | | + private int width = 0; |
48 | | + private int height = 0; |
49 | | |
50 | | LoadImageRunnable(File file, Integer orientation) { |
51 | | this.file = file; |
52 | | @@ -231,7 +240,7 @@ |
53 | | this.width = width; |
54 | | this.height = height; |
55 | | synchronized (this) { |
56 | | - this.notify(); |
57 | | + this.notifyAll(); |
58 | | return false; |
59 | | } |
60 | | } |
61 | | @@ -243,19 +252,27 @@ |
62 | | Image img = Toolkit.getDefaultToolkit().createImage(file.getPath()); |
63 | | |
64 | | synchronized (this) { |
65 | | - width = -1; |
66 | | img.getWidth(this); |
67 | | img.getHeight(this); |
68 | | |
69 | | - while (width < 0) { |
70 | | + long now = System.currentTimeMillis(); |
71 | | + while (!(width > 0 && height > 0)) { |
72 | | try { |
73 | | - this.wait(); |
74 | | - if (width < 0) { |
75 | | - errorLoading = true; |
76 | | + this.wait(1000); |
77 | | + if (this.file != ImageDisplay.this.file) |
78 | | return; |
79 | | - } |
80 | | + if (System.currentTimeMillis() - now > 10000) |
81 | | + // no image dimensions could be read within timeout |
82 | | + synchronized (ImageDisplay.this) { |
83 | | + errorLoading = true; |
84 | | + ImageDisplay.this.repaint(); |
85 | | + return; |
86 | | + } |
87 | | } catch (InterruptedException e) { |
88 | | - e.printStackTrace(); |
89 | | + Logging.trace(e); |
90 | | + Logging.warn("InterruptedException in {0} while getting properties of image {1}", |
91 | | + getClass().getSimpleName(), file.getPath()); |
92 | | + Thread.currentThread().interrupt(); |
93 | | } |
94 | | } |
95 | | } |
96 | | @@ -279,24 +296,19 @@ |
97 | | Thread.sleep(5); |
98 | | } catch (InterruptedException e) { |
99 | | Logging.trace(e); |
100 | | - Logging.warn("InterruptedException in "+getClass().getSimpleName()+ |
101 | | - " while loading image "+file.getPath()); |
102 | | + Logging.warn("InterruptedException in {0} while loading image {1}", |
103 | | + getClass().getSimpleName(), file.getPath()); |
104 | | Thread.currentThread().interrupt(); |
105 | | } |
106 | | } |
107 | | if (tracker.isErrorID(1)) { |
108 | | + // the tracker catches OutOfMemory conditions |
109 | | img = null; |
110 | | - System.gc(); |
111 | | } |
112 | | } else { |
113 | | img = null; |
114 | | } |
115 | | |
116 | | - if (img == null || width <= 0 || height <= 0) { |
117 | | - tracker.removeImage(img); |
118 | | - img = null; |
119 | | - } |
120 | | - |
121 | | synchronized (ImageDisplay.this) { |
122 | | if (this.file != ImageDisplay.this.file) { |
123 | | // The file has changed |
124 | | @@ -566,10 +578,12 @@ |
125 | | public void mouseReleased(MouseEvent e) { |
126 | | File file; |
127 | | Image image; |
128 | | + VisRect visibleRect; |
129 | | |
130 | | synchronized (ImageDisplay.this) { |
131 | | file = ImageDisplay.this.file; |
132 | | image = ImageDisplay.this.image; |
133 | | + visibleRect = ImageDisplay.this.visibleRect; |
134 | | } |
135 | | |
136 | | if (image == null) |
137 | | }}} |
| 8 | |
| 9 | EDIT4: superceded by attachment:josm-store-width-and-height-info-in-ImageEntry.patch |