[sip-comm-dev] Re: svn commit: r4576 - trunk/src/net/java/sip/communicator/impl/gui/lookandfeel


#1

Hi Ben,

thanks for making this optimization! As it looks a little bit tricky and I'm not sure I fully understand could you add some guiding comments in the code and explain us more about it?

Thanks!
Yana

pradelle@dev.java.net wrote:

···

Author: pradelle
Date: 2008-10-08 02:29:16+0000
New Revision: 4576

Modified:
   trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java
   trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java

Log:
UI button rendering optimization

Modified: trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java?view=diff&rev=4576&p1=trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java&p2=trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java&r1=4575&r2=4576

--- trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java (original)
+++ trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java 2008-10-08 02:29:16+0000
@@ -26,6 +26,10 @@
              private final static BufferedImage buttonRolloverBG
         = ImageLoader.getImage(ImageLoader.BUTTON_ROLLOVER);
+ + private boolean bufferIsRollover = false;
+ private BufferedImage paintBuffer = null;
+ private Component bufferedComponent = null;
              // ********************************
     // Create PLAF
@@ -56,46 +60,69 @@
     }
          public void paint(Graphics g, JComponent c) {
- - AntialiasingManager.activateAntialiasing(g);
- +
         AbstractButton button = (AbstractButton)c;
         ButtonModel model = button.getModel();
- - BufferedImage leftImg;
- BufferedImage middleImg;
- BufferedImage rightImg;
- - int imgWidth;
- int imgHeight;
- int indentWidth = 10;
- if(model.isRollover()){
- imgWidth = buttonRolloverBG.getWidth();
- imgHeight = buttonRolloverBG.getHeight();
- - leftImg = buttonRolloverBG.getSubimage(0, 0, indentWidth, imgHeight);
- middleImg = buttonRolloverBG.getSubimage(indentWidth, 0, - imgWidth-2*indentWidth, - imgHeight);
- rightImg = buttonRolloverBG.getSubimage(imgWidth-indentWidth, 0, - indentWidth, imgHeight);
- }
- else{
- imgWidth = buttonBG.getWidth();
- imgHeight = buttonBG.getHeight();
- - leftImg = buttonBG.getSubimage(0, 0, 10, imgHeight);
- middleImg = buttonBG.getSubimage(10, 0, imgWidth-20, imgHeight);
- rightImg = buttonBG.getSubimage(imgWidth-10, 0, 10, imgHeight);
+
+ // check if the context of the buffer is consistent or else recreate it
+ if (paintBuffer == null || c != bufferedComponent
+ || bufferIsRollover != model.isRollover())
+ {
+ // create a buffer in the best available format
+ paintBuffer = ((Graphics2D) g).getDeviceConfiguration().
+ createCompatibleImage(c.getWidth(), c.getHeight(),
+ Transparency.TRANSLUCENT);
+
+ // save the context
+ bufferedComponent = c;
+ bufferIsRollover = model.isRollover();
+
+ // draw in the buffer
+ BufferedImage leftImg;
+ BufferedImage middleImg;
+ BufferedImage rightImg;
+ + int imgWidth;
+ int imgHeight;
+ int indentWidth = 10;
+ if(bufferIsRollover){
+ imgWidth = buttonRolloverBG.getWidth();
+ imgHeight = buttonRolloverBG.getHeight();
+ + leftImg = buttonRolloverBG.getSubimage(0, 0, indentWidth,
+ imgHeight);
+ middleImg = buttonRolloverBG.getSubimage(indentWidth, 0, + imgWidth-2*indentWidth, + imgHeight);
+ rightImg = buttonRolloverBG.getSubimage(imgWidth-indentWidth, 0, + indentWidth, imgHeight);
+ }
+ else{
+ imgWidth = buttonBG.getWidth();
+ imgHeight = buttonBG.getHeight();
+ + leftImg = buttonBG.getSubimage(0, 0, 10, imgHeight);
+ middleImg = buttonBG.getSubimage(10, 0, imgWidth-20, imgHeight);
+ rightImg = buttonBG.getSubimage(imgWidth-10, 0, 10, imgHeight);
+ }
+ + Graphics2D g2 = paintBuffer.createGraphics();
+ + AntialiasingManager.activateAntialiasing(g2);
+ + g2.drawImage(leftImg, 0, 0, indentWidth, c.getHeight(), null);
+ g2.drawImage(middleImg, indentWidth, 0, + c.getWidth() - 2 * indentWidth, c.getHeight(), null);
+ g2.drawImage(rightImg, c.getWidth() - indentWidth, 0, + indentWidth, c.getHeight(), null);
         }
- - - g.drawImage(leftImg, 0, 0, indentWidth, c.getHeight(), null);
- g.drawImage(middleImg, indentWidth, 0, - c.getWidth()-2*indentWidth, c.getHeight(), null);
- g.drawImage(rightImg, c.getWidth()-indentWidth, 0, - indentWidth, c.getHeight(), null);
- +
+ AntialiasingManager.activateAntialiasing(g);
+
+ // draw the buffer in the graphics object
+ g.drawImage(paintBuffer, 0, 0, c.getWidth(), c.getHeight(),
+ 0, 0, c.getWidth(), c.getHeight(), null);
+
         super.paint(g, c); }
        
Modified: trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java?view=diff&rev=4576&p1=trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java&p2=trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java&r1=4575&r2=4576

--- trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java (original)
+++ trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java 2008-10-08 02:29:16+0000
@@ -24,6 +24,10 @@
     private final static BufferedImage buttonPressedBG
         = ImageLoader.getImage(ImageLoader.TOGGLE_BUTTON_PRESSED);
     + private boolean bufferIsPressed = false;
+ private BufferedImage paintBuffer = null;
+ private Component bufferedComponent = null;
+ // ********************************
     // Create PLAF
     // ********************************
@@ -52,43 +56,70 @@
          public void paint(Graphics g, JComponent c)
     { - AntialiasingManager.activateAntialiasing(g);
- AbstractButton button = (AbstractButton)c;
         ButtonModel model = button.getModel();
         - BufferedImage leftImg;
- BufferedImage middleImg;
- BufferedImage rightImg;
- - int imgWidth;
- int imgHeight;
- int indentWidth = 10;
+ boolean isShownPressed = model.isArmed() && model.isPressed()
+ || model.isSelected();
         - if (model.isArmed() && model.isPressed() || model.isSelected())
- {
- imgWidth = buttonPressedBG.getWidth();
- imgHeight = buttonPressedBG.getHeight();
- - leftImg = buttonPressedBG.getSubimage(0, 0, 10, imgHeight);
- middleImg = buttonPressedBG.getSubimage(10, 0, imgWidth-20, imgHeight);
- rightImg = buttonPressedBG.getSubimage(imgWidth-10, 0, 10, imgHeight);
- }
- else
+ // check if the context of the buffer is consistent or else recreate it
+ if (paintBuffer == null || c != bufferedComponent
+ || bufferIsPressed != isShownPressed)
         {
- imgWidth = buttonBG.getWidth();
- imgHeight = buttonBG.getHeight();
- - leftImg = buttonBG.getSubimage(0, 0, 10, imgHeight);
- middleImg = buttonBG.getSubimage(10, 0, imgWidth-20, imgHeight);
- rightImg = buttonBG.getSubimage(imgWidth-10, 0, 10, imgHeight);
- }
+ // create a buffer in the best available format
+ paintBuffer = ((Graphics2D) g).getDeviceConfiguration().
+ createCompatibleImage(c.getWidth(), c.getHeight(),
+ Transparency.TRANSLUCENT);
+
+ // save the context
+ bufferedComponent = c;
+ bufferIsPressed = isShownPressed;
+ + BufferedImage leftImg;
+ BufferedImage middleImg;
+ BufferedImage rightImg;
+ + int imgWidth;
+ int imgHeight;
+ int indentWidth = 10;
+ + if (isShownPressed)
+ {
+ imgWidth = buttonPressedBG.getWidth();
+ imgHeight = buttonPressedBG.getHeight();
+ + leftImg = buttonPressedBG.getSubimage(0, 0, 10, imgHeight);
+ middleImg = buttonPressedBG.getSubimage(10, 0, imgWidth-20,
+ imgHeight);
+ rightImg = buttonPressedBG.getSubimage(imgWidth-10, 0, 10,
+ imgHeight);
+ }
+ else
+ {
+ imgWidth = buttonBG.getWidth();
+ imgHeight = buttonBG.getHeight();
+ + leftImg = buttonBG.getSubimage(0, 0, 10, imgHeight);
+ middleImg = buttonBG.getSubimage(10, 0, imgWidth-20, imgHeight);
+ rightImg = buttonBG.getSubimage(imgWidth-10, 0, 10, imgHeight);
+ }
+ + Graphics2D g2 = paintBuffer.createGraphics();
             - g.drawImage(leftImg, 0, 0, indentWidth, c.getHeight(), null);
- g.drawImage(middleImg, indentWidth, 0, - c.getWidth()-2*indentWidth, c.getHeight(), null);
- g.drawImage(rightImg, c.getWidth()-indentWidth, 0, - indentWidth, c.getHeight(), null);
+ AntialiasingManager.activateAntialiasing(g2);
+ + g2.drawImage(leftImg, 0, 0, indentWidth, c.getHeight(), null);
+ g2.drawImage(middleImg, indentWidth, 0, + c.getWidth()-2*indentWidth, c.getHeight(), null);
+ g2.drawImage(rightImg, c.getWidth()-indentWidth, 0, + indentWidth, c.getHeight(), null);
+ }
+ + AntialiasingManager.activateAntialiasing(g);
+ + // draw the buffer in the graphics object
+ g.drawImage(paintBuffer, 0, 0, c.getWidth(), c.getHeight(),
+ 0, 0, c.getWidth(), c.getHeight(), null);
                  super.paint(g, c); }

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: commits-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


#2

Hi Yana,

I think it's pretty close to what I did for the splash screen
background in order to noticeably boot its repaiting (as it was
extremely slow). The idea is generally that drawing an Image with
characteristics (sufficiently) different than those of the graphics
context (it's said to be incompatible with the device configuration)
is likely to be much slower than drawing an Image compatible with the
device configuration. In this case, one creates a compatible Image
from the incompatible one and always draws the compatible one. For the
splashscreen the speed up was more than 20 times (though it certainly
depends on the number of repaints).

Best regards,
Lubo

···

On Wed, Oct 8, 2008 at 12:25 PM, Yana Stamcheva <yana@sip-communicator.org> wrote:

Hi Ben,

thanks for making this optimization! As it looks a little bit tricky and I'm
not sure I fully understand could you add some guiding comments in the code
and explain us more about it?

Thanks!
Yana

pradelle@dev.java.net wrote:

Author: pradelle
Date: 2008-10-08 02:29:16+0000
New Revision: 4576

Modified:

trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java

trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java

Log:
UI button rendering optimization

Modified:
trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java
Url:
https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java?view=diff&rev=4576&p1=trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java&p2=trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java&r1=4575&r2=4576

==============================================================================
---
trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java
      (original)
+++
trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java
      2008-10-08 02:29:16+0000
@@ -26,6 +26,10 @@
            private final static BufferedImage buttonRolloverBG
        = ImageLoader.getImage(ImageLoader.BUTTON_ROLLOVER);
+ + private boolean bufferIsRollover = false;
+ private BufferedImage paintBuffer = null;
+ private Component bufferedComponent = null;
            // ********************************
    // Create PLAF
@@ -56,46 +60,69 @@
    }
        public void paint(Graphics g, JComponent c) {
- - AntialiasingManager.activateAntialiasing(g);
- +
        AbstractButton button = (AbstractButton)c;
        ButtonModel model = button.getModel();
- - BufferedImage leftImg;
- BufferedImage middleImg;
- BufferedImage rightImg;
- - int imgWidth;
- int imgHeight;
- int indentWidth = 10;
- if(model.isRollover()){
- imgWidth = buttonRolloverBG.getWidth();
- imgHeight = buttonRolloverBG.getHeight();
- - leftImg = buttonRolloverBG.getSubimage(0, 0,
indentWidth, imgHeight);
- middleImg = buttonRolloverBG.getSubimage(indentWidth, 0, -
                                                  imgWidth-2*indentWidth, -
                                                    imgHeight);
- rightImg = buttonRolloverBG.getSubimage(imgWidth-indentWidth,
0, - indentWidth,
imgHeight);
- }
- else{
- imgWidth = buttonBG.getWidth();
- imgHeight = buttonBG.getHeight();
- - leftImg = buttonBG.getSubimage(0, 0, 10,
imgHeight);
- middleImg = buttonBG.getSubimage(10, 0, imgWidth-20,
imgHeight);
- rightImg = buttonBG.getSubimage(imgWidth-10, 0, 10,
imgHeight);
+
+ // check if the context of the buffer is consistent or else
recreate it
+ if (paintBuffer == null || c != bufferedComponent
+ || bufferIsRollover != model.isRollover())
+ {
+ // create a buffer in the best available format
+ paintBuffer = ((Graphics2D) g).getDeviceConfiguration().
+ createCompatibleImage(c.getWidth(), c.getHeight(),
+ Transparency.TRANSLUCENT);
+
+ // save the context
+ bufferedComponent = c;
+ bufferIsRollover = model.isRollover();
+
+ // draw in the buffer
+ BufferedImage leftImg;
+ BufferedImage middleImg;
+ BufferedImage rightImg;
+ + int imgWidth;
+ int imgHeight;
+ int indentWidth = 10;
+ if(bufferIsRollover){
+ imgWidth = buttonRolloverBG.getWidth();
+ imgHeight = buttonRolloverBG.getHeight();
+ + leftImg = buttonRolloverBG.getSubimage(0,
0, indentWidth,
+
                      imgHeight);
+ middleImg = buttonRolloverBG.getSubimage(indentWidth, 0,
+
imgWidth-2*indentWidth, +
     imgHeight);
+ rightImg =
buttonRolloverBG.getSubimage(imgWidth-indentWidth, 0, +
                                   indentWidth, imgHeight);
+ }
+ else{
+ imgWidth = buttonBG.getWidth();
+ imgHeight = buttonBG.getHeight();
+ + leftImg = buttonBG.getSubimage(0, 0, 10,
imgHeight);
+ middleImg = buttonBG.getSubimage(10, 0, imgWidth-20,
imgHeight);
+ rightImg = buttonBG.getSubimage(imgWidth-10, 0, 10,
imgHeight);
+ }
+ + Graphics2D g2 = paintBuffer.createGraphics();
+ + AntialiasingManager.activateAntialiasing(g2);
+ + g2.drawImage(leftImg, 0, 0, indentWidth,
c.getHeight(), null);
+ g2.drawImage(middleImg, indentWidth, 0, +
c.getWidth() - 2 * indentWidth, c.getHeight(), null);
+ g2.drawImage(rightImg, c.getWidth() - indentWidth, 0, +
             indentWidth, c.getHeight(), null);
        }
- - - g.drawImage(leftImg, 0, 0, indentWidth,
c.getHeight(), null);
- g.drawImage(middleImg, indentWidth, 0, -
c.getWidth()-2*indentWidth, c.getHeight(), null);
- g.drawImage(rightImg, c.getWidth()-indentWidth, 0, -
   indentWidth, c.getHeight(), null);
- +
+ AntialiasingManager.activateAntialiasing(g);
+
+ // draw the buffer in the graphics object
+ g.drawImage(paintBuffer, 0, 0, c.getWidth(), c.getHeight(),
+ 0, 0, c.getWidth(), c.getHeight(), null);
+
        super.paint(g, c); }

Modified:
trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java
Url:
https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java?view=diff&rev=4576&p1=trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java&p2=trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java&r1=4575&r2=4576

==============================================================================
---
trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java
(original)
+++
trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java
2008-10-08 02:29:16+0000
@@ -24,6 +24,10 @@
    private final static BufferedImage buttonPressedBG
        = ImageLoader.getImage(ImageLoader.TOGGLE_BUTTON_PRESSED);
    + private boolean bufferIsPressed = false;
+ private BufferedImage paintBuffer = null;
+ private Component bufferedComponent = null;
+ // ********************************
    // Create PLAF
    // ********************************
@@ -52,43 +56,70 @@
        public void paint(Graphics g, JComponent c)
    { - AntialiasingManager.activateAntialiasing(g);
- AbstractButton button = (AbstractButton)c;
        ButtonModel model = button.getModel();
        - BufferedImage leftImg;
- BufferedImage middleImg;
- BufferedImage rightImg;
- - int imgWidth;
- int imgHeight;
- int indentWidth = 10;
+ boolean isShownPressed = model.isArmed() && model.isPressed()
+ || model.isSelected();
        - if (model.isArmed() && model.isPressed() ||
model.isSelected())
- {
- imgWidth = buttonPressedBG.getWidth();
- imgHeight = buttonPressedBG.getHeight();
- - leftImg = buttonPressedBG.getSubimage(0, 0, 10,
imgHeight);
- middleImg = buttonPressedBG.getSubimage(10, 0, imgWidth-20,
imgHeight);
- rightImg = buttonPressedBG.getSubimage(imgWidth-10, 0, 10,
imgHeight);
- }
- else
+ // check if the context of the buffer is consistent or else
recreate it
+ if (paintBuffer == null || c != bufferedComponent
+ || bufferIsPressed != isShownPressed)
        {
- imgWidth = buttonBG.getWidth();
- imgHeight = buttonBG.getHeight();
- - leftImg = buttonBG.getSubimage(0, 0, 10,
imgHeight);
- middleImg = buttonBG.getSubimage(10, 0, imgWidth-20,
imgHeight);
- rightImg = buttonBG.getSubimage(imgWidth-10, 0, 10,
imgHeight);
- }
+ // create a buffer in the best available format
+ paintBuffer = ((Graphics2D) g).getDeviceConfiguration().
+ createCompatibleImage(c.getWidth(), c.getHeight(),
+ Transparency.TRANSLUCENT);
+
+ // save the context
+ bufferedComponent = c;
+ bufferIsPressed = isShownPressed;
+ + BufferedImage leftImg;
+ BufferedImage middleImg;
+ BufferedImage rightImg;
+ + int imgWidth;
+ int imgHeight;
+ int indentWidth = 10;
+ + if (isShownPressed)
+ {
+ imgWidth = buttonPressedBG.getWidth();
+ imgHeight = buttonPressedBG.getHeight();
+ + leftImg =
buttonPressedBG.getSubimage(0, 0, 10, imgHeight);
+ middleImg = buttonPressedBG.getSubimage(10, 0,
imgWidth-20,
+ imgHeight);
+ rightImg = buttonPressedBG.getSubimage(imgWidth-10, 0,
10,
+ imgHeight);
+ }
+ else
+ {
+ imgWidth = buttonBG.getWidth();
+ imgHeight = buttonBG.getHeight();
+ + leftImg = buttonBG.getSubimage(0,
0, 10, imgHeight);
+ middleImg = buttonBG.getSubimage(10, 0, imgWidth-20,
imgHeight);
+ rightImg = buttonBG.getSubimage(imgWidth-10, 0, 10,
imgHeight);
+ }
+ + Graphics2D g2 = paintBuffer.createGraphics();
            - g.drawImage(leftImg, 0, 0, indentWidth,
c.getHeight(), null);
- g.drawImage(middleImg, indentWidth, 0, -
c.getWidth()-2*indentWidth, c.getHeight(), null);
- g.drawImage(rightImg, c.getWidth()-indentWidth, 0, -
   indentWidth, c.getHeight(), null);
+ AntialiasingManager.activateAntialiasing(g2);
+ + g2.drawImage(leftImg, 0, 0,
indentWidth, c.getHeight(), null);
+ g2.drawImage(middleImg, indentWidth, 0, +
      c.getWidth()-2*indentWidth, c.getHeight(), null);
+ g2.drawImage(rightImg, c.getWidth()-indentWidth, 0, +
                  indentWidth, c.getHeight(), null);
+ }
+ + AntialiasingManager.activateAntialiasing(g);
+ + // draw the buffer in the graphics object
+ g.drawImage(paintBuffer, 0, 0, c.getWidth(), c.getHeight(),
+ 0, 0, c.getWidth(), c.getHeight(), null);
                super.paint(g, c); }
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail:
commits-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

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


#3

Hi Yana, Lubomir, all,

Actually the optimization here is in two parts: the first one has been (very
well) explained by Lubomir but the second one is to bufferize the button
appearance. In the previous implementation the button appearance was
recomputed every time it was painted which was leading us to spend a huge
amount of time in drawing buttons. So now, the concept is very simple: the
first time the button is painted, we save its appearance, every other time
it has to be painted, we simply draw the image saved in the buffer. If any
parameter influencing the button appearance is modified, we refresh the
buffer.

Note that this optimization is really simple and can easily be used by all
of you in any critical parts of your code so don't hesitate to use it!

Hope that helps,
Ben

···

2008/10/8 Lubomir Marinov <lubomir.marinov@gmail.com>

Hi Yana,

I think it's pretty close to what I did for the splash screen
background in order to noticeably boot its repaiting (as it was
extremely slow). The idea is generally that drawing an Image with
characteristics (sufficiently) different than those of the graphics
context (it's said to be incompatible with the device configuration)
is likely to be much slower than drawing an Image compatible with the
device configuration. In this case, one creates a compatible Image
from the incompatible one and always draws the compatible one. For the
splashscreen the speed up was more than 20 times (though it certainly
depends on the number of repaints).

Best regards,
Lubo

On Wed, Oct 8, 2008 at 12:25 PM, Yana Stamcheva > <yana@sip-communicator.org> wrote:
> Hi Ben,
>
> thanks for making this optimization! As it looks a little bit tricky and
I'm
> not sure I fully understand could you add some guiding comments in the
code
> and explain us more about it?
>
> Thanks!
> Yana
>
> pradelle@dev.java.net wrote:
>>
>> Author: pradelle
>> Date: 2008-10-08 02:29:16+0000
>> New Revision: 4576
>>
>> Modified:
>>
>>
trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java
>>
>>
trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java
>>
>> Log:
>> UI button rendering optimization
>>
>> Modified:
>>
trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java
>> Url:
>>
https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java?view=diff&rev=4576&p1=trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java&p2=trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java&r1=4575&r2=4576
>>
>>

>> ---
>>
trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java
>> (original)
>> +++
>>
trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java
>> 2008-10-08 02:29:16+0000
>> @@ -26,6 +26,10 @@
>> private final static BufferedImage buttonRolloverBG
>> = ImageLoader.getImage(ImageLoader.BUTTON_ROLLOVER);
>> + + private boolean bufferIsRollover = false;
>> + private BufferedImage paintBuffer = null;
>> + private Component bufferedComponent = null;
>> // ********************************
>> // Create PLAF
>> @@ -56,46 +60,69 @@
>> }
>> public void paint(Graphics g, JComponent c) {
>> - - AntialiasingManager.activateAntialiasing(g);
>> - +
>> AbstractButton button = (AbstractButton)c;
>> ButtonModel model = button.getModel();
>> - - BufferedImage leftImg;
>> - BufferedImage middleImg;
>> - BufferedImage rightImg;
>> - - int imgWidth;
>> - int imgHeight;
>> - int indentWidth = 10;
>> - if(model.isRollover()){
>> - imgWidth = buttonRolloverBG.getWidth();
>> - imgHeight = buttonRolloverBG.getHeight();
>> - - leftImg = buttonRolloverBG.getSubimage(0, 0,
>> indentWidth, imgHeight);
>> - middleImg = buttonRolloverBG.getSubimage(indentWidth, 0, -
>>
imgWidth-2*indentWidth, -
>> imgHeight);
>> - rightImg =
buttonRolloverBG.getSubimage(imgWidth-indentWidth,
>> 0, - indentWidth,
>> imgHeight);
>> - }
>> - else{
>> - imgWidth = buttonBG.getWidth();
>> - imgHeight = buttonBG.getHeight();
>> - - leftImg = buttonBG.getSubimage(0, 0, 10,
>> imgHeight);
>> - middleImg = buttonBG.getSubimage(10, 0, imgWidth-20,
>> imgHeight);
>> - rightImg = buttonBG.getSubimage(imgWidth-10, 0, 10,
>> imgHeight);
>> +
>> + // check if the context of the buffer is consistent or else
>> recreate it
>> + if (paintBuffer == null || c != bufferedComponent
>> + || bufferIsRollover != model.isRollover())
>> + {
>> + // create a buffer in the best available format
>> + paintBuffer = ((Graphics2D) g).getDeviceConfiguration().
>> + createCompatibleImage(c.getWidth(),
c.getHeight(),
>> + Transparency.TRANSLUCENT);
>> +
>> + // save the context
>> + bufferedComponent = c;
>> + bufferIsRollover = model.isRollover();
>> +
>> + // draw in the buffer
>> + BufferedImage leftImg;
>> + BufferedImage middleImg;
>> + BufferedImage rightImg;
>> + + int imgWidth;
>> + int imgHeight;
>> + int indentWidth = 10;
>> + if(bufferIsRollover){
>> + imgWidth = buttonRolloverBG.getWidth();
>> + imgHeight = buttonRolloverBG.getHeight();
>> + + leftImg =
buttonRolloverBG.getSubimage(0,
>> 0, indentWidth,
>> +
>> imgHeight);
>> + middleImg = buttonRolloverBG.getSubimage(indentWidth,
0,
>> +
>> imgWidth-2*indentWidth, +
>> imgHeight);
>> + rightImg =
>> buttonRolloverBG.getSubimage(imgWidth-indentWidth, 0, +
>> indentWidth, imgHeight);
>> + }
>> + else{
>> + imgWidth = buttonBG.getWidth();
>> + imgHeight = buttonBG.getHeight();
>> + + leftImg = buttonBG.getSubimage(0, 0,
10,
>> imgHeight);
>> + middleImg = buttonBG.getSubimage(10, 0, imgWidth-20,
>> imgHeight);
>> + rightImg = buttonBG.getSubimage(imgWidth-10, 0, 10,
>> imgHeight);
>> + }
>> + + Graphics2D g2 = paintBuffer.createGraphics();
>> + + AntialiasingManager.activateAntialiasing(g2);
>> + + g2.drawImage(leftImg, 0, 0, indentWidth,
>> c.getHeight(), null);
>> + g2.drawImage(middleImg, indentWidth, 0, +
>> c.getWidth() - 2 * indentWidth, c.getHeight(), null);
>> + g2.drawImage(rightImg, c.getWidth() - indentWidth, 0, +
>> indentWidth, c.getHeight(), null);
>> }
>> - - - g.drawImage(leftImg, 0, 0, indentWidth,
>> c.getHeight(), null);
>> - g.drawImage(middleImg, indentWidth, 0, -
>> c.getWidth()-2*indentWidth, c.getHeight(), null);
>> - g.drawImage(rightImg, c.getWidth()-indentWidth, 0, -
>> indentWidth, c.getHeight(), null);
>> - +
>> + AntialiasingManager.activateAntialiasing(g);
>> +
>> + // draw the buffer in the graphics object
>> + g.drawImage(paintBuffer, 0, 0, c.getWidth(), c.getHeight(),
>> + 0, 0, c.getWidth(), c.getHeight(), null);
>> +
>> super.paint(g, c); }
>>
>> Modified:
>>
trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java
>> Url:
>>
https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java?view=diff&rev=4576&p1=trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java&p2=trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java&r1=4575&r2=4576
>>
>>

>> ---
>>
trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java
>> (original)
>> +++
>>
trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java
>> 2008-10-08 02:29:16+0000
>> @@ -24,6 +24,10 @@
>> private final static BufferedImage buttonPressedBG
>> = ImageLoader.getImage(ImageLoader.TOGGLE_BUTTON_PRESSED);
>> + private boolean bufferIsPressed = false;
>> + private BufferedImage paintBuffer = null;
>> + private Component bufferedComponent = null;
>> + // ********************************
>> // Create PLAF
>> // ********************************
>> @@ -52,43 +56,70 @@
>> public void paint(Graphics g, JComponent c)
>> { - AntialiasingManager.activateAntialiasing(g);
>> - AbstractButton button = (AbstractButton)c;
>> ButtonModel model = button.getModel();
>> - BufferedImage leftImg;
>> - BufferedImage middleImg;
>> - BufferedImage rightImg;
>> - - int imgWidth;
>> - int imgHeight;
>> - int indentWidth = 10;
>> + boolean isShownPressed = model.isArmed() && model.isPressed()
>> + || model.isSelected();
>> - if (model.isArmed() && model.isPressed() ||
>> model.isSelected())
>> - {
>> - imgWidth = buttonPressedBG.getWidth();
>> - imgHeight = buttonPressedBG.getHeight();
>> - - leftImg = buttonPressedBG.getSubimage(0, 0, 10,
>> imgHeight);
>> - middleImg = buttonPressedBG.getSubimage(10, 0, imgWidth-20,
>> imgHeight);
>> - rightImg = buttonPressedBG.getSubimage(imgWidth-10, 0, 10,
>> imgHeight);
>> - }
>> - else
>> + // check if the context of the buffer is consistent or else
>> recreate it
>> + if (paintBuffer == null || c != bufferedComponent
>> + || bufferIsPressed != isShownPressed)
>> {
>> - imgWidth = buttonBG.getWidth();
>> - imgHeight = buttonBG.getHeight();
>> - - leftImg = buttonBG.getSubimage(0, 0, 10,
>> imgHeight);
>> - middleImg = buttonBG.getSubimage(10, 0, imgWidth-20,
>> imgHeight);
>> - rightImg = buttonBG.getSubimage(imgWidth-10, 0, 10,
>> imgHeight);
>> - }
>> + // create a buffer in the best available format
>> + paintBuffer = ((Graphics2D) g).getDeviceConfiguration().
>> + createCompatibleImage(c.getWidth(),
c.getHeight(),
>> + Transparency.TRANSLUCENT);
>> +
>> + // save the context
>> + bufferedComponent = c;
>> + bufferIsPressed = isShownPressed;
>> + + BufferedImage leftImg;
>> + BufferedImage middleImg;
>> + BufferedImage rightImg;
>> + + int imgWidth;
>> + int imgHeight;
>> + int indentWidth = 10;
>> + + if (isShownPressed)
>> + {
>> + imgWidth = buttonPressedBG.getWidth();
>> + imgHeight = buttonPressedBG.getHeight();
>> + + leftImg =
>> buttonPressedBG.getSubimage(0, 0, 10, imgHeight);
>> + middleImg = buttonPressedBG.getSubimage(10, 0,
>> imgWidth-20,
>> + imgHeight);
>> + rightImg = buttonPressedBG.getSubimage(imgWidth-10,
0,
>> 10,
>> + imgHeight);
>> + }
>> + else
>> + {
>> + imgWidth = buttonBG.getWidth();
>> + imgHeight = buttonBG.getHeight();
>> + + leftImg = buttonBG.getSubimage(0,
>> 0, 10, imgHeight);
>> + middleImg = buttonBG.getSubimage(10, 0, imgWidth-20,
>> imgHeight);
>> + rightImg = buttonBG.getSubimage(imgWidth-10, 0, 10,
>> imgHeight);
>> + }
>> + + Graphics2D g2 =
paintBuffer.createGraphics();
>> - g.drawImage(leftImg, 0, 0, indentWidth,
>> c.getHeight(), null);
>> - g.drawImage(middleImg, indentWidth, 0, -
>> c.getWidth()-2*indentWidth, c.getHeight(), null);
>> - g.drawImage(rightImg, c.getWidth()-indentWidth, 0, -
>> indentWidth, c.getHeight(), null);
>> + AntialiasingManager.activateAntialiasing(g2);
>> + + g2.drawImage(leftImg, 0, 0,
>> indentWidth, c.getHeight(), null);
>> + g2.drawImage(middleImg, indentWidth, 0, +
>> c.getWidth()-2*indentWidth, c.getHeight(), null);
>> + g2.drawImage(rightImg, c.getWidth()-indentWidth, 0, +
>> indentWidth, c.getHeight(), null);
>> + }
>> + + AntialiasingManager.activateAntialiasing(g);
>> + + // draw the buffer in the graphics object
>> + g.drawImage(paintBuffer, 0, 0, c.getWidth(), c.getHeight(),
>> + 0, 0, c.getWidth(), c.getHeight(), null);
>> super.paint(g, c); }
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
commits-unsubscribe@sip-communicator.dev.java.net
>> For additional commands, e-mail:
>> commits-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
>
>

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


#4

Hey Ben,

In fact, I do the same two things as part of my optimization of the
splash background. And, as I said, the difference was really dramatic.
So I'm very happy the same technique is making its way into the rest
of the code. Thank you for doing it!

Best regards,
Lubo

···

On Wed, Oct 8, 2008 at 5:12 PM, Benoit Pradelle <b.pradelle@gmail.com> wrote:

Hi Yana, Lubomir, all,

Actually the optimization here is in two parts: the first one has been (very
well) explained by Lubomir but the second one is to bufferize the button
appearance. In the previous implementation the button appearance was
recomputed every time it was painted which was leading us to spend a huge
amount of time in drawing buttons. So now, the concept is very simple: the
first time the button is painted, we save its appearance, every other time
it has to be painted, we simply draw the image saved in the buffer. If any
parameter influencing the button appearance is modified, we refresh the
buffer.

Note that this optimization is really simple and can easily be used by all
of you in any critical parts of your code so don't hesitate to use it!

Hope that helps,
Ben

2008/10/8 Lubomir Marinov <lubomir.marinov@gmail.com>

Hi Yana,

I think it's pretty close to what I did for the splash screen
background in order to noticeably boot its repaiting (as it was
extremely slow). The idea is generally that drawing an Image with
characteristics (sufficiently) different than those of the graphics
context (it's said to be incompatible with the device configuration)
is likely to be much slower than drawing an Image compatible with the
device configuration. In this case, one creates a compatible Image
from the incompatible one and always draws the compatible one. For the
splashscreen the speed up was more than 20 times (though it certainly
depends on the number of repaints).

Best regards,
Lubo

On Wed, Oct 8, 2008 at 12:25 PM, Yana Stamcheva >> <yana@sip-communicator.org> wrote:
> Hi Ben,
>
> thanks for making this optimization! As it looks a little bit tricky and
> I'm
> not sure I fully understand could you add some guiding comments in the
> code
> and explain us more about it?
>
> Thanks!
> Yana
>
> pradelle@dev.java.net wrote:
>>
>> Author: pradelle
>> Date: 2008-10-08 02:29:16+0000
>> New Revision: 4576
>>
>> Modified:
>>
>>
>> trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java
>>
>>
>> trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java
>>
>> Log:
>> UI button rendering optimization
>>
>> Modified:
>>
>> trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java
>> Url:
>>
>> https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java?view=diff&rev=4576&p1=trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java&p2=trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java&r1=4575&r2=4576
>>
>>
>> ==============================================================================
>> ---
>>
>> trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java
>> (original)
>> +++
>>
>> trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommButtonUI.java
>> 2008-10-08 02:29:16+0000
>> @@ -26,6 +26,10 @@
>> private final static BufferedImage buttonRolloverBG
>> = ImageLoader.getImage(ImageLoader.BUTTON_ROLLOVER);
>> + + private boolean bufferIsRollover = false;
>> + private BufferedImage paintBuffer = null;
>> + private Component bufferedComponent = null;
>> // ********************************
>> // Create PLAF
>> @@ -56,46 +60,69 @@
>> }
>> public void paint(Graphics g, JComponent c) {
>> - - AntialiasingManager.activateAntialiasing(g);
>> - +
>> AbstractButton button = (AbstractButton)c;
>> ButtonModel model = button.getModel();
>> - - BufferedImage leftImg;
>> - BufferedImage middleImg;
>> - BufferedImage rightImg;
>> - - int imgWidth;
>> - int imgHeight;
>> - int indentWidth = 10;
>> - if(model.isRollover()){
>> - imgWidth = buttonRolloverBG.getWidth();
>> - imgHeight = buttonRolloverBG.getHeight();
>> - - leftImg = buttonRolloverBG.getSubimage(0, 0,
>> indentWidth, imgHeight);
>> - middleImg = buttonRolloverBG.getSubimage(indentWidth, 0, -
>>
>> imgWidth-2*indentWidth, -
>> imgHeight);
>> - rightImg =
>> buttonRolloverBG.getSubimage(imgWidth-indentWidth,
>> 0, - indentWidth,
>> imgHeight);
>> - }
>> - else{
>> - imgWidth = buttonBG.getWidth();
>> - imgHeight = buttonBG.getHeight();
>> - - leftImg = buttonBG.getSubimage(0, 0, 10,
>> imgHeight);
>> - middleImg = buttonBG.getSubimage(10, 0, imgWidth-20,
>> imgHeight);
>> - rightImg = buttonBG.getSubimage(imgWidth-10, 0, 10,
>> imgHeight);
>> +
>> + // check if the context of the buffer is consistent or else
>> recreate it
>> + if (paintBuffer == null || c != bufferedComponent
>> + || bufferIsRollover != model.isRollover())
>> + {
>> + // create a buffer in the best available format
>> + paintBuffer = ((Graphics2D)
>> g).getDeviceConfiguration().
>> + createCompatibleImage(c.getWidth(),
>> c.getHeight(),
>> + Transparency.TRANSLUCENT);
>> +
>> + // save the context
>> + bufferedComponent = c;
>> + bufferIsRollover = model.isRollover();
>> +
>> + // draw in the buffer
>> + BufferedImage leftImg;
>> + BufferedImage middleImg;
>> + BufferedImage rightImg;
>> + + int imgWidth;
>> + int imgHeight;
>> + int indentWidth = 10;
>> + if(bufferIsRollover){
>> + imgWidth = buttonRolloverBG.getWidth();
>> + imgHeight = buttonRolloverBG.getHeight();
>> + + leftImg =
>> buttonRolloverBG.getSubimage(0,
>> 0, indentWidth,
>> +
>> imgHeight);
>> + middleImg = buttonRolloverBG.getSubimage(indentWidth,
>> 0,
>> +
>> imgWidth-2*indentWidth, +
>> imgHeight);
>> + rightImg =
>> buttonRolloverBG.getSubimage(imgWidth-indentWidth, 0, +
>> indentWidth, imgHeight);
>> + }
>> + else{
>> + imgWidth = buttonBG.getWidth();
>> + imgHeight = buttonBG.getHeight();
>> + + leftImg = buttonBG.getSubimage(0, 0,
>> 10,
>> imgHeight);
>> + middleImg = buttonBG.getSubimage(10, 0, imgWidth-20,
>> imgHeight);
>> + rightImg = buttonBG.getSubimage(imgWidth-10, 0, 10,
>> imgHeight);
>> + }
>> + + Graphics2D g2 = paintBuffer.createGraphics();
>> + + AntialiasingManager.activateAntialiasing(g2);
>> + + g2.drawImage(leftImg, 0, 0, indentWidth,
>> c.getHeight(), null);
>> + g2.drawImage(middleImg, indentWidth, 0, +
>> c.getWidth() - 2 * indentWidth, c.getHeight(), null);
>> + g2.drawImage(rightImg, c.getWidth() - indentWidth, 0, +
>> indentWidth, c.getHeight(), null);
>> }
>> - - - g.drawImage(leftImg, 0, 0, indentWidth,
>> c.getHeight(), null);
>> - g.drawImage(middleImg, indentWidth, 0, -
>> c.getWidth()-2*indentWidth, c.getHeight(), null);
>> - g.drawImage(rightImg, c.getWidth()-indentWidth, 0, -
>> indentWidth, c.getHeight(), null);
>> - +
>> + AntialiasingManager.activateAntialiasing(g);
>> +
>> + // draw the buffer in the graphics object
>> + g.drawImage(paintBuffer, 0, 0, c.getWidth(), c.getHeight(),
>> + 0, 0, c.getWidth(), c.getHeight(), null);
>> +
>> super.paint(g, c); }
>>
>> Modified:
>>
>> trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java
>> Url:
>>
>> https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java?view=diff&rev=4576&p1=trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java&p2=trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java&r1=4575&r2=4576
>>
>>
>> ==============================================================================
>> ---
>>
>> trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java
>> (original)
>> +++
>>
>> trunk/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java
>> 2008-10-08 02:29:16+0000
>> @@ -24,6 +24,10 @@
>> private final static BufferedImage buttonPressedBG
>> = ImageLoader.getImage(ImageLoader.TOGGLE_BUTTON_PRESSED);
>> + private boolean bufferIsPressed = false;
>> + private BufferedImage paintBuffer = null;
>> + private Component bufferedComponent = null;
>> + // ********************************
>> // Create PLAF
>> // ********************************
>> @@ -52,43 +56,70 @@
>> public void paint(Graphics g, JComponent c)
>> { - AntialiasingManager.activateAntialiasing(g);
>> - AbstractButton button = (AbstractButton)c;
>> ButtonModel model = button.getModel();
>> - BufferedImage leftImg;
>> - BufferedImage middleImg;
>> - BufferedImage rightImg;
>> - - int imgWidth;
>> - int imgHeight;
>> - int indentWidth = 10;
>> + boolean isShownPressed = model.isArmed() && model.isPressed()
>> + || model.isSelected();
>> - if (model.isArmed() && model.isPressed() ||
>> model.isSelected())
>> - {
>> - imgWidth = buttonPressedBG.getWidth();
>> - imgHeight = buttonPressedBG.getHeight();
>> - - leftImg = buttonPressedBG.getSubimage(0, 0,
>> 10,
>> imgHeight);
>> - middleImg = buttonPressedBG.getSubimage(10, 0,
>> imgWidth-20,
>> imgHeight);
>> - rightImg = buttonPressedBG.getSubimage(imgWidth-10, 0, 10,
>> imgHeight);
>> - }
>> - else
>> + // check if the context of the buffer is consistent or else
>> recreate it
>> + if (paintBuffer == null || c != bufferedComponent
>> + || bufferIsPressed != isShownPressed)
>> {
>> - imgWidth = buttonBG.getWidth();
>> - imgHeight = buttonBG.getHeight();
>> - - leftImg = buttonBG.getSubimage(0, 0, 10,
>> imgHeight);
>> - middleImg = buttonBG.getSubimage(10, 0, imgWidth-20,
>> imgHeight);
>> - rightImg = buttonBG.getSubimage(imgWidth-10, 0, 10,
>> imgHeight);
>> - }
>> + // create a buffer in the best available format
>> + paintBuffer = ((Graphics2D)
>> g).getDeviceConfiguration().
>> + createCompatibleImage(c.getWidth(),
>> c.getHeight(),
>> + Transparency.TRANSLUCENT);
>> +
>> + // save the context
>> + bufferedComponent = c;
>> + bufferIsPressed = isShownPressed;
>> + + BufferedImage leftImg;
>> + BufferedImage middleImg;
>> + BufferedImage rightImg;
>> + + int imgWidth;
>> + int imgHeight;
>> + int indentWidth = 10;
>> + + if (isShownPressed)
>> + {
>> + imgWidth = buttonPressedBG.getWidth();
>> + imgHeight = buttonPressedBG.getHeight();
>> + + leftImg =
>> buttonPressedBG.getSubimage(0, 0, 10, imgHeight);
>> + middleImg = buttonPressedBG.getSubimage(10, 0,
>> imgWidth-20,
>> + imgHeight);
>> + rightImg = buttonPressedBG.getSubimage(imgWidth-10,
>> 0,
>> 10,
>> + imgHeight);
>> + }
>> + else
>> + {
>> + imgWidth = buttonBG.getWidth();
>> + imgHeight = buttonBG.getHeight();
>> + + leftImg =
>> buttonBG.getSubimage(0,
>> 0, 10, imgHeight);
>> + middleImg = buttonBG.getSubimage(10, 0,
>> imgWidth-20,
>> imgHeight);
>> + rightImg = buttonBG.getSubimage(imgWidth-10, 0, 10,
>> imgHeight);
>> + }
>> + + Graphics2D g2 =
>> paintBuffer.createGraphics();
>> - g.drawImage(leftImg, 0, 0, indentWidth,
>> c.getHeight(), null);
>> - g.drawImage(middleImg, indentWidth, 0, -
>> c.getWidth()-2*indentWidth, c.getHeight(), null);
>> - g.drawImage(rightImg, c.getWidth()-indentWidth, 0, -
>> indentWidth, c.getHeight(), null);
>> + AntialiasingManager.activateAntialiasing(g2);
>> + + g2.drawImage(leftImg, 0, 0,
>> indentWidth, c.getHeight(), null);
>> + g2.drawImage(middleImg, indentWidth, 0, +
>> c.getWidth()-2*indentWidth, c.getHeight(), null);
>> + g2.drawImage(rightImg, c.getWidth()-indentWidth, 0, +
>> indentWidth, c.getHeight(), null);
>> + }
>> + + AntialiasingManager.activateAntialiasing(g);
>> + + // draw the buffer in the graphics object
>> + g.drawImage(paintBuffer, 0, 0, c.getWidth(), c.getHeight(),
>> + 0, 0, c.getWidth(), c.getHeight(), null);
>> super.paint(g, c); }
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> commits-unsubscribe@sip-communicator.dev.java.net
>> For additional commands, e-mail:
>> commits-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
>
>

---------------------------------------------------------------------
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