[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [albireo-dev] size/layout management

> This patch fixes the "Relayout Example".

Additionally, with this patch, we can remove the explicit 'composite.layout()'
call from the example. Essentially, we were overriding validateTree() on the
wrong component. When a label somewhere changes, the RepaintManager causes
validate() to be called on the "validation root". This is the JRootPane inside
the JApplet. validate() on the JApplet is not called normally, since the
JRootPane "shields" it from effects that happen inside the JRootPane.

Bruno

Index: src/org/eclipse/albireo/examples/plugin/views/RelayoutExampleView.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.albireo/org.eclipse.albireo.examples.plugin/src/org/eclipse/albireo/examples/plugin/views/RelayoutExampleView.java,v
retrieving revision 1.3
diff -c -3 -r1.3 RelayoutExampleView.java
*** src/org/eclipse/albireo/examples/plugin/views/RelayoutExampleView.java	8 Feb 2008 19:58:00 -0000	1.3
--- src/org/eclipse/albireo/examples/plugin/views/RelayoutExampleView.java	8 Feb 2008 20:44:50 -0000
***************
*** 197,209 ****
          }
          count.setText(PREFIX + String.valueOf(countInt));
          label.setText(text);
- 
-         composite.getDisplay().asyncExec(
-             new Runnable() {
-                 public void run() {
-                     composite.layout();
-                 }
-             });
      }
  
      void relayoutFromOutside() {
--- 197,202 ----
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.20
diff -c -3 -r1.20 SwingControl.java
*** src/org/eclipse/albireo/core/SwingControl.java	8 Feb 2008 20:07:18 -0000	1.20
--- src/org/eclipse/albireo/core/SwingControl.java	8 Feb 2008 20:48:11 -0000
***************
*** 19,24 ****
--- 19,25 ----
  
  import javax.swing.JApplet;
  import javax.swing.JComponent;
+ import javax.swing.JRootPane;
  import javax.swing.RootPaneContainer;
  import javax.swing.SwingUtilities;
  import javax.swing.UIManager;
***************
*** 226,239 ****
          // only single component that satisfies all the above. This does not imply that
          // we have a true applet; in particular, there is no notion of an applet lifecycle in this
          // context.
!         JApplet applet = new JApplet() {
! 
!             // Keep the sizes cache up to date.
!             protected void validateTree() {
!                 super.validateTree();
!                 updateCachedAWTSizes(getMinimumSize(), getPreferredSize(), getMaximumSize());
!             }
!         };
          frame.add(applet);
          return applet;
      }
--- 227,252 ----
          // only single component that satisfies all the above. This does not imply that
          // we have a true applet; in particular, there is no notion of an applet lifecycle in this
          // context.
!         JApplet applet =
!             new JApplet() {
!                 // Overridden from JApplet.
!                 protected JRootPane createRootPane() {
!                     JRootPane rootPane =
!                         new JRootPane() {
!                             // Keep the sizes cache up to date.
!                             // The JRootPane, not the JApplet, is the "validation root",
!                             // as determined by RepaintManager.addInvalidComponent().
!                             // It is here that we can intercept the relevant
!                             // invalidate()/validateTree() calls.
!                             protected void validateTree() {
!                                 super.validateTree();
!                                 updateCachedAWTSizes(getMinimumSize(), getPreferredSize(), getMaximumSize());
!                             }
!                         };
!                     rootPane.setOpaque(true);
!                     return rootPane;
!                 }
!             };
          frame.add(applet);
          return applet;
      }