[sip-comm-dev] Avatar Image


#1

Hi Yana,

recently I got a problem with one of the contacts on my MSN list. The problem is that when I open the chat window most of it is not pained (only the history that is loaded is ok). In order to use it I must minimize and then restore the window.
Today I saw what is the cause of this problem, see the exceptions at the end of the mail. The exceptions are preventing the window to be repainted. I've tried the following patch and is working ok for me. What you say, should I commit it ?

Index: net/java/sip/communicator/util/ImageUtils.java

···

===================================================================
--- net/java/sip/communicator/util/ImageUtils.java (revision 5109)
+++ net/java/sip/communicator/util/ImageUtils.java (working copy)
@@ -75,6 +75,10 @@
         int scaledImageWidth = scaledImage.getIconWidth();
         int scaledImageHeight = scaledImage.getIconHeight();
+ if(scaledImageHeight <= 0 ||
+ scaledImageWidth <= 0)
+ return null;
+
         BufferedImage destImage =
             new BufferedImage(scaledImageWidth, scaledImageHeight,
                 BufferedImage.TYPE_INT_ARGB);
Index: net/java/sip/communicator/util/swing/FramedImage.java

--- net/java/sip/communicator/util/swing/FramedImage.java (revision 5109)
+++ net/java/sip/communicator/util/swing/FramedImage.java (working copy)
@@ -84,6 +84,9 @@
      */
     public void paintComponent(Graphics g)
     {
+ if(image == null)
+ return;
+
         g.drawImage(image, width / 2 - image.getWidth(null) / 2, height / 2
             - image.getHeight(null) / 2, null);

And here are the exceptions :

18:26:53.228 SEVERE: util.UtilActivator.uncaughtException().81 An uncaught exception occurred in thread=Thread[AWT-EventQueue-0,6,main] and message was: Width (-1) and height (-1) cannot be <= 0
java.lang.IllegalArgumentException: Width (-1) and height (-1) cannot be <= 0
    at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:999)
    at java.awt.image.BufferedImage.<init>(BufferedImage.java:321)
    at net.java.sip.communicator.util.ImageUtils.getScaledRoundedImage(ImageUtils.java:78)
    at net.java.sip.communicator.util.swing.FramedImage.setImageIcon(FramedImage.java:75)
    at net.java.sip.communicator.impl.gui.main.chat.ChatWindow$ContactPhotoPanel.setChatSession(ChatWindow.java:1091)
    at net.java.sip.communicator.impl.gui.main.chat.ChatWindow.setChatContactPhoto(ChatWindow.java:986)
    at net.java.sip.communicator.impl.gui.main.chat.ChatWindow.setCurrentChatPanel(ChatWindow.java:392)
    at net.java.sip.communicator.impl.gui.main.chat.ChatWindowManager.openChat(ChatWindowManager.java:90)
    at net.java.sip.communicator.impl.gui.DefaultContactEventHandler$RunMessageWindow.run(DefaultContactEventHandler.java:99)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
18:26:53.599 SEVERE: util.UtilActivator.uncaughtException().81 An uncaught exception occurred in thread=Thread[AWT-EventQueue-0,6,main] and message was: null
java.lang.NullPointerException
    at net.java.sip.communicator.util.swing.FramedImage.paintComponent(FramedImage.java:87)
    at javax.swing.JComponent.paint(JComponent.java:1027)
    at javax.swing.JComponent.paintChildren(JComponent.java:864)
    at javax.swing.JComponent.paint(JComponent.java:1036)
    at javax.swing.JLayeredPane.paint(JLayeredPane.java:564)
    at javax.swing.JComponent.paintChildren(JComponent.java:864)
    at javax.swing.JComponent.paint(JComponent.java:1036)
    at javax.swing.JComponent.paintChildren(JComponent.java:864)
    at javax.swing.JComponent.paint(JComponent.java:1036)
    at javax.swing.JComponent.paintChildren(JComponent.java:864)
    at javax.swing.JComponent.paint(JComponent.java:1036)
    at javax.swing.JComponent.paintChildren(JComponent.java:864)
    at javax.swing.JComponent.paint(JComponent.java:1036)
    at javax.swing.JLayeredPane.paint(JLayeredPane.java:564)
    at javax.swing.JComponent.paintChildren(JComponent.java:864)
    at javax.swing.JComponent.paintToOffscreen(JComponent.java:5129)
    at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:277)
    at javax.swing.RepaintManager.paint(RepaintManager.java:1217)
    at javax.swing.JComponent.paint(JComponent.java:1013)
    at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
    at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
    at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
    at java.awt.Container.paint(Container.java:1762)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:814)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
    at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:694)
    at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Cheers
damencho

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net


#2

Hi Damian,

seems fine to me. Go ahead with the commit.

And thanks for fixing the issue!

Cheers,
Yana

Damian Minkov wrote:

···

Hi Yana,

recently I got a problem with one of the contacts on my MSN list. The problem is that when I open the chat window most of it is not pained (only the history that is loaded is ok). In order to use it I must minimize and then restore the window.
Today I saw what is the cause of this problem, see the exceptions at the end of the mail. The exceptions are preventing the window to be repainted. I've tried the following patch and is working ok for me. What you say, should I commit it ?

Index: net/java/sip/communicator/util/ImageUtils.java

--- net/java/sip/communicator/util/ImageUtils.java (revision 5109)
+++ net/java/sip/communicator/util/ImageUtils.java (working copy)
@@ -75,6 +75,10 @@
        int scaledImageWidth = scaledImage.getIconWidth();
        int scaledImageHeight = scaledImage.getIconHeight();

+ if(scaledImageHeight <= 0 ||
+ scaledImageWidth <= 0)
+ return null;
+
        BufferedImage destImage =
            new BufferedImage(scaledImageWidth, scaledImageHeight,
                BufferedImage.TYPE_INT_ARGB);
Index: net/java/sip/communicator/util/swing/FramedImage.java

--- net/java/sip/communicator/util/swing/FramedImage.java (revision 5109)
+++ net/java/sip/communicator/util/swing/FramedImage.java (working copy)
@@ -84,6 +84,9 @@
     */
    public void paintComponent(Graphics g)
    {
+ if(image == null)
+ return;
+
        g.drawImage(image, width / 2 - image.getWidth(null) / 2, height / 2
            - image.getHeight(null) / 2, null);

And here are the exceptions :

18:26:53.228 SEVERE: util.UtilActivator.uncaughtException().81 An uncaught exception occurred in thread=Thread[AWT-EventQueue-0,6,main] and message was: Width (-1) and height (-1) cannot be <= 0
java.lang.IllegalArgumentException: Width (-1) and height (-1) cannot be <= 0
   at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:999)

   at java.awt.image.BufferedImage.<init>(BufferedImage.java:321)
   at net.java.sip.communicator.util.ImageUtils.getScaledRoundedImage(ImageUtils.java:78)

   at net.java.sip.communicator.util.swing.FramedImage.setImageIcon(FramedImage.java:75)

   at net.java.sip.communicator.impl.gui.main.chat.ChatWindow$ContactPhotoPanel.setChatSession(ChatWindow.java:1091)

   at net.java.sip.communicator.impl.gui.main.chat.ChatWindow.setChatContactPhoto(ChatWindow.java:986)

   at net.java.sip.communicator.impl.gui.main.chat.ChatWindow.setCurrentChatPanel(ChatWindow.java:392)

   at net.java.sip.communicator.impl.gui.main.chat.ChatWindowManager.openChat(ChatWindowManager.java:90)

   at net.java.sip.communicator.impl.gui.DefaultContactEventHandler$RunMessageWindow.run(DefaultContactEventHandler.java:99)

   at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)

   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)

   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)

   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
18:26:53.599 SEVERE: util.UtilActivator.uncaughtException().81 An uncaught exception occurred in thread=Thread[AWT-EventQueue-0,6,main] and message was: null
java.lang.NullPointerException
   at net.java.sip.communicator.util.swing.FramedImage.paintComponent(FramedImage.java:87)

   at javax.swing.JComponent.paint(JComponent.java:1027)
   at javax.swing.JComponent.paintChildren(JComponent.java:864)
   at javax.swing.JComponent.paint(JComponent.java:1036)
   at javax.swing.JLayeredPane.paint(JLayeredPane.java:564)
   at javax.swing.JComponent.paintChildren(JComponent.java:864)
   at javax.swing.JComponent.paint(JComponent.java:1036)
   at javax.swing.JComponent.paintChildren(JComponent.java:864)
   at javax.swing.JComponent.paint(JComponent.java:1036)
   at javax.swing.JComponent.paintChildren(JComponent.java:864)
   at javax.swing.JComponent.paint(JComponent.java:1036)
   at javax.swing.JComponent.paintChildren(JComponent.java:864)
   at javax.swing.JComponent.paint(JComponent.java:1036)
   at javax.swing.JLayeredPane.paint(JLayeredPane.java:564)
   at javax.swing.JComponent.paintChildren(JComponent.java:864)
   at javax.swing.JComponent.paintToOffscreen(JComponent.java:5129)
   at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:277)

   at javax.swing.RepaintManager.paint(RepaintManager.java:1217)
   at javax.swing.JComponent.paint(JComponent.java:1013)
   at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
   at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
   at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
   at java.awt.Container.paint(Container.java:1762)
   at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:814)
   at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
   at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:694)
   at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)

   at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)

   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)

   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)

   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Cheers
damencho

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net