Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [albireo-dev] CleanResizeListener

[Followup from a conversation on 2008-02-11.]

Gordon Hirsch wrote:
> Bruno Haible wrote:
> >   - Make it possible to turn on/off the CleanResizeListener, on a per-instance
> >     basis (since it depends on the contents of the window),
> 
> Sounds good.

OK, implemented as below.

> >   - Document that it should be enabled only after a background colour has been
> >     set that approximately matches the window's contents.
> 
> No objection, but wouldn't this be the default case? (i.e. background 
> colors normally match)

For highly graphic views (such as map displays), a developer may not think
that the background color is relevant. Therefore better to mention it.

> >   - Add a boolean method isCleanResizeRecommended() that returns false in
> >     JDK 1.6.
> 
> Should we just keep it off by default under JDK 1.6?

Yes, I agree. I made this change too.

Bruno


Index: src/org/eclipse/albireo/core/SwingControl.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.albireo/org.eclipse.albireo.core/src/org/eclipse/albireo/core/SwingControl.java,v
retrieving revision 1.71
diff -c -3 -r1.71 SwingControl.java
*** src/org/eclipse/albireo/core/SwingControl.java	28 Apr 2008 18:06:32 -0000	1.71
--- src/org/eclipse/albireo/core/SwingControl.java	28 Apr 2008 20:26:40 -0000
***************
*** 197,207 ****
                  handleDispose();
              }
          });
!         // This listener clears garbage during resizing, making it look much cleaner. The garbage
!         // is due to use of the sun.awt.noerasebackground property, so this is done only under Windows.
!         if (Platform.isWin32()) {
!             borderlessChild.addControlListener(new CleanResizeListener());
!         }
      }
  
      // ========================================================================
--- 197,204 ----
                  handleDispose();
              }
          });
! 
!         initCleanResizeListener();
      }
  
      // ========================================================================
***************
*** 909,914 ****
--- 906,966 ----
  
  
      // ========================================================================
+     // Resizing with less flickering
+ 
+     // This listener clears garbage during resizing, making it look much
+     // cleaner. The garbage is due to use of the sun.awt.noerasebackground
+     // property, so this is done only under Windows.
+ 
+     private CleanResizeListener cleanResizeListener /* = null */;
+ 
+     /**
+      * Returns true if a particular mechanism for resizing with less flicker is
+      * enabled.
+      */
+     public boolean isCleanResizeEnabled() {
+         return cleanResizeListener != null;
+     }
+ 
+     /**
+      * Specifies whether the particular mechanism for resizing with less flicker
+      * should be enabled or not.
+      * <p>
+      * For this setting to be useful, a background colour should have been
+      * set that approximately matches the window's contents.
+      * <p>
+      * By default, this setting is enabled on Windows with JDK 1.5 or older, and
+      * disabled otherwise.
+      */
+     public void setCleanResizeEnabled(boolean enabled) {
+         if (enabled != isCleanResizeEnabled()) {
+             if (enabled) {
+                 cleanResizeListener = new CleanResizeListener();
+                 borderlessChild.addControlListener(cleanResizeListener);
+             } else {
+                 borderlessChild.removeControlListener(cleanResizeListener);
+                 cleanResizeListener = null;
+             }
+         }
+     }
+ 
+     private void initCleanResizeListener() {
+         // On Windows:
+         //  - In JDK 1.4 and 1.5: It indeed avoids most of the "garbage". But
+         //    if the background colour is not aligned with the contents of the
+         //    window (like here: background grey, contents dark green), the
+         //    cleaning is visually more disturbing than the garbage. This is
+         //    especially noticeable when you click with the mouse in the above
+         //    test view.
+         //  - In JDK 1.6: There is much less "garbage"; the repaint is quicker.
+         //    The CleanResizeListener's effect is mostly visible as flickering.
+         if (Platform.isWin32()
+             && Platform.JAVA_VERSION < Platform.javaVersion(1, 6, 0)) {
+             setCleanResizeEnabled(true);
+         }
+     }
+ 
+     // ========================================================================
      // Font management
  
      /**


Back to the top