On Tue, 24 Oct 2023 18:54:17 GMT, ScientificWare <d...@openjdk.org> wrote:

>>> You should probably pass `altAtt` as the `description` parameter, yet I'm 
>>> unsure if it's ever used in this context.
>> 
>> As I say, I'm unsure if it's used… The description could be exposed to 
>> Accessibility API. By default, `ImageIcon` uses the URL as the description 
>> if it isn't provided:
>> 
>> https://github.com/openjdk/jdk/blob/99de9bb83ff70fe81c89751516a86a94c8f552be/src/java.desktop/share/classes/javax/swing/ImageIcon.java#L231-L233
>> 
>> Now that you handle the `alt` attribute, you can pass the description if 
>> it's provided.
>
> ![image](https://github.com/openjdk/jdk/assets/19194678/a98c058e-323f-49c5-af63-2f5b837b9b99)
> 
> Did you have this in mind ?
> 
>             <html>
>                 <body>
>                     <input type=image name=point 
> src="file:oracle_logo_50x50.jpg" alt="Logo Oracle JPG">
>                     <p>
>                     <input type=image name=point 
> src="file:oracle_logo_50x50.jpg">
>                     <p>
>                     <input type=image name=point 
> src="file:none_oracle_logo_50x50.jpg" alt="Logo Oracle JPG">
>                     <p>
>                     <input type=image name=point 
> src="file:none_oracle_logo_50x50.jpg">
>                     <p>
>                     <input type=image name=point 
> src="files:none_oracle_logo_50x50.jpg" alt="Logo Oracle JPG">
>                     <p>
>                     <input type=image name=point 
> src="files:none_oracle_logo_50x50.jpg">
>                     <p>
>                 </body>
>             </html>
> 
> 
> 
> 
>             String srcAtt = (String) attr.getAttribute(HTML.Attribute.SRC);
>             String altAtt = (String) attr.getAttribute(HTML.Attribute.ALT);
>             if (altAtt == null) {
>                 altAtt = srcAtt;
>             }
>             JButton button;
>             try {
>                 URL base = 
> ((HTMLDocument)getElement().getDocument()).getBase();
>                 @SuppressWarnings("deprecation")
>                 URL srcURL = new URL(base, srcAtt);
>                 ImageIcon icon = new ImageIcon(srcURL, altAtt);
>                 button = new JButton(icon);
>             } catch (MalformedURLException e) {
>                 button = new JButton(altAtt == null ? srcAtt : altAtt);
>             }

Yes, something similar:


            String srcAtt = (String) attr.getAttribute(HTML.Attribute.SRC);
            String altAtt = (String) attr.getAttribute(HTML.Attribute.ALT);
            JButton button;
            try {
                URL base = ((HTMLDocument)getElement().getDocument()).getBase();
                @SuppressWarnings("deprecation")
                URL srcURL = new URL(base, srcAtt);
                ImageIcon icon = altAtt != null
                                 ? new ImageIcon(srcURL, altAtt)
                                 : new ImageIcon(srcURL);
                button = icon.getImageLoadStatus() == MediaTracker.COMPLETE
                         ? new JButton(icon)
                         : new JButton(altAtt != null ? altAtt : srcAtt);
            } catch (MalformedURLException e) {
                button = new JButton(altAtt != null ? altAtt : srcAtt);
            }

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/15319#discussion_r1370719498

Reply via email to