Revision: 6985 Author: [email protected] Date: Wed Nov 18 08:39:41 2009 Log: Fix breakage against JDK 1.5 due to r6973.
Patch by: jat Review by: bobv http://code.google.com/p/google-web-toolkit/source/detail?r=6985 Modified: /trunk/dev/core/src/com/google/gwt/dev/SwingUI.java ======================================= --- /trunk/dev/core/src/com/google/gwt/dev/SwingUI.java Wed Nov 18 08:26:08 2009 +++ /trunk/dev/core/src/com/google/gwt/dev/SwingUI.java Wed Nov 18 08:39:41 2009 @@ -27,11 +27,15 @@ import com.google.gwt.dev.ui.RestartServerEvent; import com.google.gwt.dev.util.collect.HashMap; +import java.awt.Image; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.URL; -import java.util.Arrays; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import javax.swing.Icon; @@ -217,9 +221,8 @@ } } }); - frame.setIconImages(Arrays.asList(gwtIcon48.getImage(), - gwtIcon32.getImage(), gwtIcon64.getImage(), gwtIcon128.getImage(), - gwtIcon16.getImage())); + setIconImages(topLogger, gwtIcon48, gwtIcon32, gwtIcon64, gwtIcon128, + gwtIcon16); frame.setVisible(true); } @@ -313,4 +316,46 @@ } return moduleTabPanel; } -} + + /** + * Set the images for the frame. On JDK 1.5, only the last icon supplied is + * used for all needs. + * + * @param logger logger to use for warnings + * @param icons one or more icons + */ + private void setIconImages(TreeLogger logger, ImageIcon... icons) { + if (icons.length == 0) { + return; + } + Exception caught = null; + try { + // if this fails, we fall back to the JDK 1.5 method + Method method = frame.getClass().getMethod("setIconImages", List.class); + List<Image> imageList = new ArrayList<Image>(); + for (ImageIcon icon : icons) { + Image image = icon.getImage(); + if (image != null) { + imageList.add(image); + } + } + method.invoke(frame, imageList); + return; + } catch (SecurityException e) { + caught = e; + } catch (IllegalArgumentException e) { + caught = e; + } catch (NoSuchMethodException e) { + // ignore, expected on JDK 1.5 + } catch (IllegalAccessException e) { + caught = e; + } catch (InvocationTargetException e) { + caught = e; + } + if (caught != null) { + logger.log(TreeLogger.WARN, "Unexpected exception setting icon images", + caught); + } + frame.setIconImage(icons[icons.length - 1].getImage()); + } +} -- http://groups.google.com/group/Google-Web-Toolkit-Contributors
