>> * How do I make the Label control wrap its text?  I gave it the style 
>> wrapText:true, but it has no effect.
> You need to make sure that the Label is in a container that will respect 
> constrained preferred heights. For example, a TablePane, or a vertical 
> BoxPane with the "fill" style set to true.
> 
> Neither of those quite works right, which I'll elaborate on below.  But it 
> also strikes me as a kind of a broken model if styles only "work" if you pick 
> the right container.

Don't agree. It's no different than specifying a preferred size on a component 
whose parent container doesn't respect it, for example.

Specifically, a Label needs a width constraint in order to know where to break 
the text. Without a parent that can provide that, it wouldn't know where to 
wrap.

>> * How do I make the TextInput fields a reasonable size?  
> 
> Try setting the textSize property.
> 
> That works, thanks.  So what, if anything, does setWidth do on a TextInput 
> component?

It sets the actual width of the component. This is similar to how layout works 
in AWT/Swing - components specify a "preferred size" that indicates how much 
space they would like, but it is ultimately up to the parent container to 
decide how much space they actually get. In general, a caller should specify a 
preferred width and/or height, but leave the setting of the actual width/height 
to the layout container.

FYI, another way you could size your text input is to provide an explicit 
preferred width; e.g. "preferredWidth='120'". But "textSize" will respect the 
current font, whereas "preferredWidth" won't.

>> * Is there a straightforward way to tell the standard dialog accelerators 
>> (Enter, Esc) what to do?  ...
> You don't need to add explicit key listeners. You should open your dialog or 
> sheet with a close listener - that is where you would put any "useful code".
> 
> Well, yes and no. I can certainly restructure the code so that pressing the 
> buttons just closes the sheet, and whoever calls open on the sheet does the 
> processing of the form based on the true/false result.  But it means that I 
> can't keep the sheet open until the login succeeds -- I have to have a close 
> listener that initiates the login code, and if an error comes back, I reopen 
> the sheet, this time with an error message showing.  And to show the user 
> that something is happening during the background authentication call, I 
> can't simply spin an activity indicator on the login sheet, but have to do it 
> somewhere else.  That all seems clumsier than I'd like.

There are a couple of ways to handle this. Generally, you'd override 
close(boolean) and execute your login code if the result is true. In this case, 
you wouldn't call the superclass close() method, since you want to prevent the 
dialog from closing. Once the login succeeds, you'll call close() again, but 
call the superclass method to actually close the dialog. 

Another way to handle it is to veto the close event, perform the login, and 
then re-close.

>> * How do I space the buttons nicely?  . . .
> I don't think you're necessarily missing anything - I think you are just 
> expecting layout in Pivot to work the same way it does in WPF, which is not 
> the case. 
> 
> If you don't want an element to stretch to fill the box pane, simply nest it 
> in another box pane whose fill style is not set to true.
> 
> Yeah, okay, it's not WPF (I'll admit I didn't immediately understand the WPF 
> model when I started with it, either).  Meanwhile, do you have a suggestion 
> for how one lays out two buttons in a horizontal row and achieve a pleasant 
> amount of space between them, perhaps even nicely balanced independent of 
> window width (e.g., equal amounts of whitespace to the left, to the right, 
> and in between)?  In the dread WPF, I might give them center alignment in 2 
> columns of a Grid.  Or I might set the buttons' horizontal margins to be a 
> pleasing width (not quite as good, since that remains static as the parent 
> window's size changes).  What can I do in Pivot?

Not sure exactly what you're envisioning, but maybe you could use a horizontal 
BoxPane with "horizontalAlignment='center'"? You can use the "spacing" style to 
control how much space is allocated between the buttons.

> Also, I'd take advantage of form flags if possible, rather than adding your 
> own custom error message label. 
> 
> I'm not sure I see what's to be gained by that.  Flags are a great feature 
> for a complicated form where you can pinpoint an area that's incorrect, but 
> for a login, these days we don't usually tell the user where the error was.  
> And I need a place to put the error message in any case (the Forms tutorial 
> certainly has one).

Fair enough.

> Anyway, back to the wrapping.  Here's the way my code looks with the BoxPane 
> approach:
> 
> <my:LoginSheet title="Login to server"
>     xmlns:bxml="http://pivot.apache.org/bxml";
>     xmlns:my="com.fxpal.myunity"
>     xmlns="org.apache.pivot.wtk"
>     maximumWidth="300">
>     <BoxPane orientation="vertical" styles="{padding:4, fill:true}">
>         <Form>
>             <Form.Section>
>                 <TextInput bxml:id="textInputName" Form.label="User Name"
>                     textSize="15" />
>                 <TextInput bxml:id="textInputPassword" Form.label="Password"
>                     password="true" textSize="15" />
>             </Form.Section>
>         </Form>
>         
>         <BoxPane orientation="horizontal"
>             styles="{fill:true, horizontalAlignment:'center'}">
>             <PushButton bxml:id="buttonLogin" buttonData="Login" />
>             <PushButton bxml:id="buttonCancel" buttonData="Cancel" />
>         </BoxPane>
>         
>         <Separator />
>         
>         <Label bxml:id="labelProblem" styles="{wrapText:true, color:'red'}" />
>     </BoxPane>
> </my:LoginSheet>
> 
> I can tell it's trying to wrap the text, since some ascenders from the second 
> line are showing thru, but the label's height does not grow as needed.

You have stumbled across a very interesting bug. I'll look into it.

> I also tried a more verbose TablePane:
> 
> <my:LoginSheet title="Login to server"
>     xmlns:bxml="http://pivot.apache.org/bxml";
>     xmlns:my="com.fxpal.myunity"
>     xmlns="org.apache.pivot.wtk"
>     maximumWidth="300">
>     <TablePane styles="{verticalSpacing:4}">
>         <columns>
>             <TablePane.Column width="1*" />
>         </columns>
>         
>         <TablePane.Row height="1*">
>             <Form>
>                 <Form.Section>
>                     <TextInput bxml:id="textInputName" Form.label="User Name"
>                         textSize="15" />
>                     <TextInput bxml:id="textInputPassword" 
> Form.label="Password"
>                         password="true" textSize="15" />
>                 </Form.Section>
>             </Form>
>         </TablePane.Row>
>         
>         <TablePane.Row height="-1">
>             <BoxPane orientation="horizontal" styles="{fill:true, 
> horizontalAlignment:'center'}">
>                 <PushButton bxml:id="buttonLogin" buttonData="Login" />
>                 <PushButton bxml:id="buttonCancel" buttonData="Cancel" />
>             </BoxPane>
>         </TablePane.Row>
>         
>         <TablePane.Row height="-1">
>             <Separator />
>         </TablePane.Row>
>         
>         <TablePane.Row height="-1">
>             <Label bxml:id="labelProblem" styles="{wrapText:true, 
> color:'red'}" />
>         </TablePane.Row>
>     </TablePane>
> </my:LoginSheet>
> 
> This also did not result in a taller label.  The TablePane.Row height value 
> of -1 doesn't seem to be documented anywhere, other than indirectly in the 
> TablePane tutorial, but I'm guessing it means something like "the exact 
> height you need".

It means "use the preferred height of the content". It's the default value, so 
you don't actually need to specify it.

I'll let you know about the other issue. Thanks for finding it.

G


Reply via email to