carl 83 posts since
Oct 17, 2007
4.
Re: I need a DateField looks like a TextField. Jun 12, 2008 10:46 PM

in response to:
Kamal
Actually, for styled controls, you have a number of options. Two reasonably easy ones are demoed below. Depending on your other requirements, you might find one or the other more useful.
1) Collapse the button using style rules
The Graphic in question has the StyleRule "DateField/calendar-button", which you can use to set its width using a StyleManager/StyleSheet, like so:
{value
|| In version 6.0, this line would be {StyleSheet.from-url <foo>}:
def style = {get-default-style-sheet}
{style.rules.append
{StyleRule
"DateField/calendar-button",
width = 0px
}
}
def manager = {BasicStyleManager style}
{DateField
style-manager = manager
}
}
Note that the style manager here would best be set farther up in the graphical hierarchy if you have other changes or are using multiple DateFields like this.
2) Swap in a blank Graphic for the CommandButton
You could override the DateFieldSkin instead of the UI object. Which class you change depends on your planned usages, but the override of the ControlSkin is somewhat more correct. The idea is that skinnable controls do not guarantee what kind of object is delivered for any given content tag, so you can swap in a blank instead of the dropdown button.
(You might use LookAndFeel registrations in an actual application rather than setting the ui-object directly as in the example below. You might also want to platform-switch the control-skin to account for differences on the mac, but here that was omitted for brevity.)
Changing the ControlSkin:
{define-class public open PlainSkinnedDateFieldSkin
{inherits SkinnedDateFieldSkin}
{method protected open {get-tagged-content content-tag:String}:#Graphic
|| Substitute a blank for the calendar button.
{if content-tag == "calendar-button" then
{return {Fill width = 0m, height = 0m}}
}
{return {super.get-tagged-content content-tag}}
}
}
{DateField
ui-object =
{PlainSkinnableDateFieldUI
control-skin = {PlainSkinnedDateFieldSkin},
control-feel = {SkinnedDateFieldFeel}
}
}
(On the UI, you'd override the create-dropdown-button method to return a Fill and not call super.)