Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [albireo-dev] A small fix to address layout issues

Hi Gordon,

> When we pass Swing's min/max/preferred sizes back to SWT during 
> validateTree(), we have been querying the JRootPane. It turns out that 
> JRootPane returns an unexpected width value for getMaximumSize(). It is 
> always 0

Indeed. It comes from the inner class 'RootLayout' in JRootPane.java, which
has code like this:

        public Dimension preferredLayoutSize(Container parent) {
          ...
          return new Dimension(Math.max(rd.width, mbd.width) + i.left + i.right, ...);
        }

        public Dimension minimumLayoutSize(Container parent) {
          ...
          return new Dimension(Math.max(rd.width, mbd.width) + i.left + i.right, ...);
        }

        public Dimension maximumLayoutSize(Container target) {
          ...
          return new Dimension(Math.min(rd.width, mbd.width) + i.left + i.right, ...);
        }                           ^^^

The Math.min here is completely senseless.

I have filed a bug at Sun for this. Not sure whether they will acknowledge it,
since the bug has been present already for a very long time.

> I've changed the code to get min/max/preferred values from the parent 
> JApplet which seems to provide more sensible values.

That achieves the goal of getting [MAXINT, MAXINT] instead of [0, MAXINT]
as result. But since layout results are computed bottom-up, I find it a
bit surprising to get the size from the parent. It does work, but probably
only because the parent uses a BorderLayout. I find it safer to follow
the bottom-up direction, by using the maximum size of the content pane.
Like the attached. (Hope you don't mind.) I have checked that this commit
does not change the actual values returned.

Bruno


Index: 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.81
diff -c -3 -r1.81 SwingControl.java
*** org/eclipse/albireo/core/SwingControl.java	21 May 2008 21:58:51 -0000	1.81
--- org/eclipse/albireo/core/SwingControl.java	28 May 2008 14:05:42 -0000
***************
*** 417,426 ****
                              // invalidate()/validateTree() calls.
                              protected void validateTree() {
                                  super.validateTree();
!                                 // JRootPane returns strange values for at least getMaximumSize (max width is 
!                                 // always set to 0), so get all the preferred sizes from the parent (JApplet). 
!                                 updateCachedAWTSizes(getParent().getMinimumSize(), 
!                                         getParent().getPreferredSize(), getParent().getMaximumSize());
                              }
                          };
                      rootPane.setOpaque(true);
--- 417,428 ----
                              // invalidate()/validateTree() calls.
                              protected void validateTree() {
                                  super.validateTree();
!                                 // JRootPane returns a wrong value for getMaximumSize(),
!                                 // namely [0,2147483647] instead of [2147483647,2147483647],
!                                 // so we use the content pane's maximum size instead.
!                                 updateCachedAWTSizes(getMinimumSize(),
!                                                      getPreferredSize(),
!                                                      getContentPane().getMaximumSize());
                              }
                          };
                      rootPane.setOpaque(true);


Back to the top