alignment of members of SmartGWT Canvases

Ian Springer ian.springer at redhat.com
Fri Nov 12 02:20:16 UTC 2010


I have been struggling the past few days to figure out why the members 
within a HLayout (specifically, this.hlayout in AbstractSelector) were 
being right-aligned. Nowhere had I specified to align anything to the 
right. I kept explicitly specifying left alignment everywhere I could 
think of, but still the members remained aligned to the right. This 
afternoon, I finally figured it out. I had the following in my HLayout:

this.hlayout.setAlign(Alignment.LEFT);
this.hlayout.setAlign(Alignment.BOTTOM);

when I axed the this.hlayout.setAlign(Alignment.BOTTOM), the members 
were left aligned and all was well.

So I took a look at the source for the two overloads of setAlign() in 
the Layout class...

     /**
      * Alignment of all members in this Layout on the length axis.  
Defaults to "top" for vertical Layouts, and "left" for horizontal Layouts.
      *
      * @param alignment alignment Default value is null
      */
     public void setAlign(Alignment alignment) {
         setAttribute("align", alignment.getValue(), true);
     }

     /**
      * Alignment of all members in this Layout on the length axis.  
Defaults to "top" for vertical Layouts, and "left"
      * for horizontal Layouts.
      *
      * @param alignment alignment Default value is null
      */
     public void setAlign(VerticalAlignment alignment) {
         setAttribute("align", alignment.getValue(), true);
     }

Notice, they both just set the "align" String attribute, so the second 
call to setAlign() was just overwriting with "bottom" the value "left" 
set by the first call. And for whatever reason (or more likely none at 
all), Smart interprets "bottom" as right-align for an HLayout. My guess 
is that their intention was for the VerticalAlignment method to only be 
used for VLayouts, and the (horizontal)Alignment version to only be used 
for HLayouts. If so, they should have split them up, one in the VLayout 
class and the other in the HLayout class, rather than putting them both 
in the Layout superclass. Or they should have had two underlying 
JavaScript attributes - "align" and "verticalAlign", rather than just 
"align". But as it stands, there's no way to specify both horizontal and 
vertical alignment for a Layout (I think this is wrong - what do others 
think?), and specifying vertical alignment on an HLayout will screw with 
the horizontal alignment. So I think the rules of thumb are:

1) For HLayouts, only call setAlign(Alignment alignment) - do not call 
setAlign(VerticalAlignment alignment)
2) For VLayouts, only call setAlign(VerticalAlignment alignment) - do 
not call setAlign(Alignment alignment)


-- Ian

-- 
Ian Springer
Principal Software Developer
JBoss Operations Network
Red Hat
ian.springer at redhat.com




More information about the rhq-devel mailing list