diff options
Diffstat (limited to 'javax/swing/text/html/ImageView.java')
-rw-r--r-- | javax/swing/text/html/ImageView.java | 63 |
1 files changed, 53 insertions, 10 deletions
diff --git a/javax/swing/text/html/ImageView.java b/javax/swing/text/html/ImageView.java index 050eb16e2..0ebf1293d 100644 --- a/javax/swing/text/html/ImageView.java +++ b/javax/swing/text/html/ImageView.java @@ -1,6 +1,5 @@ package javax.swing.text.html; -import gnu.javax.swing.text.html.CombinedAttributes; import gnu.javax.swing.text.html.ImageViewIconFactory; import gnu.javax.swing.text.html.css.Length; @@ -15,6 +14,8 @@ import java.net.MalformedURLException; import java.net.URL; import javax.swing.Icon; +import javax.swing.SwingUtilities; +import javax.swing.text.AbstractDocument; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.Document; @@ -40,16 +41,15 @@ public class ImageView extends View public boolean imageUpdate(Image image, int flags, int x, int y, int width, int height) { boolean widthChanged = false; - if ((flags & ImageObserver.WIDTH) != 0 - && ! getElement().getAttributes().isDefined(HTML.Attribute.WIDTH)) + if ((flags & ImageObserver.WIDTH) != 0 && spans[X_AXIS] == null) widthChanged = true; boolean heightChanged = false; - if ((flags & ImageObserver.HEIGHT) != 0 - && ! getElement().getAttributes().isDefined(HTML.Attribute.HEIGHT)) - widthChanged = true; + if ((flags & ImageObserver.HEIGHT) != 0 && spans[Y_AXIS] == null) + heightChanged = true; if (widthChanged || heightChanged) - preferenceChanged(ImageView.this, widthChanged, heightChanged); - return (flags & ALLBITS) != 0; + safePreferenceChanged(ImageView.this, widthChanged, heightChanged); + boolean ret = (flags & ALLBITS) != 0; + return ret; } } @@ -112,8 +112,10 @@ public class ImageView extends View /** * The CSS width and height. + * + * Package private to avoid synthetic accessor methods. */ - private Length[] spans; + Length[] spans; /** * The cached attributes. @@ -131,6 +133,7 @@ public class ImageView extends View observer = new Observer(); reloadProperties = true; reloadImage = true; + loadOnDemand = false; } /** @@ -487,7 +490,9 @@ public class ImageView extends View if (src != null) { // Call getImage(URL) to allow the toolkit caching of that image URL. - newImage = Toolkit.getDefaultToolkit().getImage(src); + Toolkit tk = Toolkit.getDefaultToolkit(); + newImage = tk.getImage(src); + tk.prepareImage(newImage, -1, -1, observer); if (newImage != null && getLoadsSynchronously()) { // Load image synchronously. @@ -548,4 +553,42 @@ public class ImageView extends View tk.prepareImage(newIm, -1, -1, observer); } } + + /** + * Calls preferenceChanged from the event dispatch thread and within + * a read lock to protect us from threading issues. + * + * @param v the view + * @param width true when the width changed + * @param height true when the height changed + */ + void safePreferenceChanged(final View v, final boolean width, + final boolean height) + { + if (SwingUtilities.isEventDispatchThread()) + { + Document doc = getDocument(); + if (doc instanceof AbstractDocument) + ((AbstractDocument) doc).readLock(); + try + { + preferenceChanged(v, width, height); + } + finally + { + if (doc instanceof AbstractDocument) + ((AbstractDocument) doc).readUnlock(); + } + } + else + { + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + safePreferenceChanged(v, width, height); + } + }); + } + } } |