Man, it's hard to get started in Pivot! I think I may write more about that
in another message, but here's a concrete example. I wanted to create a
simple popup control to handle a login, so I wrote a class that extends
Sheet. I've included the bxml file below. After several iterations, I
still have a whole bunch of problems to solve:
* How do I make the Label control wrap its text? I gave it the
style wrapText:true, but it has no effect.
* How do I make the TextInput fields a reasonable size? At first, I was
hoping maybe the container hierarchy would propagate size constraints down
from the top-level component (the sheet), but it doesn't -- the TextInput
fields get truncated. I also tried putting a width="100" on the
individual TextInput fields, but that seems to be ignored.
* Is there a straightforward way to tell the standard dialog accelerators
(Enter, Esc) what to do? In WPF, I can add IsDefault and IsCancel
properties to buttons to tell the system to "press" the button when Enter or
Esc is typed. It looks like the default behavior in Pivot is that Enter
sets the dialog result to true, Esc to false, and both close the
dialog *without
invoking any useful code*! That means I *must *do something to handle those
keys or my code is very wrong. It looks like I can add
a ComponentKeyListener to the sheet to capture those keys, but that seems
like a tedious solution to have to apply to every dialog I ever write. It's
also unclear to me how I get the listener to run in the UI thread.
* How do I space the buttons nicely? In WPF, I can put them in a Grid and
set their horizontal alignment to Center. The apparently equivalent Pivot
control is TablePane, but PushButton does not accept a horizontalAlignment
style! I find this maddening. Why doesn't *every *component have
properties/styles that tell its container how to lay it out (alignment and
stretch/fill) within the space the container allots? I noticed, for
example, that BoxPane has style attributes fill & horiz/vert alignment, but
they apply to its children. Usually that's not what I'm looking for -- I'd
want those attributes to apply to the BoxPane itself with respect to its
parent, and I might well want different values for the children. As a
really specific example, if I want to put a Separator into a BoxPane and
have it stretch across the width of the container, I set fill:true on the
BoxPane. But what if I don't want other elements in the pane, say a button,
to be stretched as well? Am I totally missing something here?
* Are there things I could be writing more easily than I show here?
<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
styles="{padding:4, verticalAlignment:'top'}"
orientation="vertical">
<Form>
<Form.Section>
<TextInput bxml:id="textInputName" Form.label="User Name" />
<TextInput bxml:id="textInputPassword" Form.label="Password"
password="true" />
<TablePane>
<columns>
<TablePane.Column width="1*"/>
<TablePane.Column width="1*"/>
</columns>
<rows>
<TablePane.Row>
<PushButton bxml:id="buttonLogin"
buttonData="Login"
styles="{horizontalAlignment:'center'}" />
<PushButton bxml:id="buttonCancel"
buttonData="Cancel"
styles="{horizontalAlignment:'center'}" />
</TablePane.Row>
</rows>
</TablePane>
</Form.Section>
<Form.Section>
<Label bxml:id="labelProblem" styles="{wrapText:true,
color:'red'}" />
</Form.Section>
</Form>
</BoxPane>
</my:LoginSheet>
I'm using Pivot 2.0, since that's what you've been recommending to people
starting new projects (which I am).