|
@@ -1,103 +1,104 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.forms.client.components.impls.input; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.GWT.client.widgets.*; |
5 |
|
- |
import org.litesoft.GWT.client.widgets.nonpublic.*; |
6 |
|
- |
import org.litesoft.GWT.forms.client.components.nonpublic.*; |
7 |
|
- |
import org.litesoft.commonfoundation.html.*; |
8 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
9 |
|
- |
import org.litesoft.ui.*; |
10 |
|
- |
import org.litesoft.uispecification.*; |
11 |
|
- |
|
12 |
|
- |
import com.google.gwt.event.dom.client.*; |
13 |
|
- |
import com.google.gwt.user.client.ui.*; |
14 |
|
- |
|
15 |
|
- |
public class FormCheckBox extends AbstractFocusWidgetFormElement { |
16 |
|
- |
public FormCheckBox( String pFieldLabel, UiFont pLabelFont, String pTooltip, boolean pAlignWithStandardFormComponents ) { |
17 |
|
- |
super( new MyCheckBox( pFieldLabel, pLabelFont ), "frmChkBox", false ); |
18 |
|
- |
initialize( pAlignWithStandardFormComponents ? " " : null, pLabelFont, pTooltip ); |
19 |
|
- |
mFieldLabel = pFieldLabel; |
20 |
|
- |
} |
21 |
|
- |
|
22 |
|
- |
@Override |
23 |
|
- |
protected void initialize( String pFieldLabel, UiFont pLabelFont, String pTooltip ) { |
24 |
|
- |
super.initialize( pFieldLabel, pLabelFont, pTooltip ); |
25 |
|
- |
|
26 |
|
- |
if ( null == Strings.noEmpty( pTooltip ) ) { |
27 |
|
- |
setVisible( mIndicatorTd.getElement(), false ); |
28 |
|
- |
} |
29 |
|
- |
|
30 |
|
- |
getCheckBox().addClickHandler( new ClickHandler() { |
31 |
|
- |
@Override |
32 |
|
- |
public void onClick( ClickEvent event ) { |
33 |
|
- |
fireChangeListeners(); |
34 |
|
- |
} |
35 |
|
- |
} ); |
36 |
|
- |
} |
37 |
|
- |
|
38 |
|
- |
// SizeManaged |
39 |
|
- |
|
40 |
|
- |
@Override |
41 |
|
- |
public void relayout() { |
42 |
|
- |
Widget parent = getParent(); |
43 |
|
- |
if ( parent instanceof SizeManaged ) { |
44 |
|
- |
((SizeManaged) parent).relayout(); |
45 |
|
- |
} |
46 |
|
- |
} |
47 |
|
- |
|
48 |
|
- |
// IFormComponent |
49 |
|
- |
|
50 |
|
- |
@Override |
51 |
|
- |
public Object getCurrentValue() { |
52 |
|
- |
//noinspection UnnecessaryBoxing |
53 |
|
- |
return Boolean.valueOf( isChecked() ); |
54 |
|
- |
} |
55 |
|
- |
|
56 |
|
- |
@Override |
57 |
|
- |
public void setCurrentValue( Object pNewValue ) { |
58 |
|
- |
if ( pNewValue != null ) { |
59 |
|
- |
if ( !(pNewValue instanceof Boolean) ) { |
60 |
|
- |
throw new IllegalArgumentException( "Not a Boolean: " + pNewValue ); |
61 |
|
- |
} |
62 |
|
- |
setChecked( (Boolean) pNewValue ); |
63 |
|
- |
} |
64 |
|
- |
} |
65 |
|
- |
|
66 |
|
- |
// Support... |
67 |
|
- |
|
68 |
|
- |
@Override |
69 |
|
- |
public void simulateUserTextEntry( String pText ) { |
70 |
|
- |
boolean zCurrentChecked = isChecked(); |
71 |
|
- |
setChecked( !Boolean.FALSE.equals( Booleans.fromString( pText ) ) ); |
72 |
|
- |
if ( zCurrentChecked != isChecked() ) { |
73 |
|
- |
fireChangeListeners(); |
74 |
|
- |
} |
75 |
|
- |
pullFocusTo( getCheckBox() ); |
76 |
|
- |
} |
77 |
|
- |
|
78 |
|
- |
public boolean isChecked() { |
79 |
|
- |
return getCheckBox().getValue(); |
80 |
|
- |
} |
81 |
|
- |
|
82 |
|
- |
public void setChecked( boolean pChecked ) { |
83 |
|
- |
getCheckBox().setValue( pChecked ); |
84 |
|
- |
} |
85 |
|
- |
|
86 |
|
- |
public CheckBox getCheckBox() { |
87 |
|
- |
return (CheckBox) mInputWidget; |
88 |
|
- |
} |
89 |
|
- |
|
90 |
|
- |
private static class MyCheckBox extends CheckBox implements IFocusWidget { |
91 |
|
- |
public MyCheckBox( String pFieldLabel, UiFont pLabelFont ) { |
92 |
|
- |
super( HTMLize( pFieldLabel ), true ); |
93 |
|
- |
if ( !"".equals( getText() ) ) { |
94 |
|
- |
ApplyFont.to( pLabelFont, this ); |
95 |
|
- |
} |
96 |
|
- |
} |
97 |
|
- |
|
98 |
|
- |
private static String HTMLize( String pFieldLabel ) { |
99 |
|
- |
pFieldLabel = Strings.noEmpty( pFieldLabel ); |
100 |
|
- |
return HTMLize.escapeNoWrap( pFieldLabel ); |
101 |
|
- |
} |
102 |
|
- |
} |
103 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.forms.client.components.impls.input; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.GWT.client.widgets.*; |
|
5 |
+ |
import org.litesoft.GWT.client.widgets.nonpublic.*; |
|
6 |
+ |
import org.litesoft.GWT.forms.client.components.nonpublic.*; |
|
7 |
+ |
import org.litesoft.commonfoundation.base.*; |
|
8 |
+ |
import org.litesoft.commonfoundation.html.*; |
|
9 |
+ |
import org.litesoft.commonfoundation.typeutils.*; |
|
10 |
+ |
import org.litesoft.ui.*; |
|
11 |
+ |
import org.litesoft.uispecification.*; |
|
12 |
+ |
|
|
13 |
+ |
import com.google.gwt.event.dom.client.*; |
|
14 |
+ |
import com.google.gwt.user.client.ui.*; |
|
15 |
+ |
|
|
16 |
+ |
public class FormCheckBox extends AbstractFocusWidgetFormElement { |
|
17 |
+ |
public FormCheckBox( String pFieldLabel, UiFont pLabelFont, String pTooltip, boolean pAlignWithStandardFormComponents ) { |
|
18 |
+ |
super( new MyCheckBox( pFieldLabel, pLabelFont ), "frmChkBox", false ); |
|
19 |
+ |
initialize( pAlignWithStandardFormComponents ? " " : null, pLabelFont, pTooltip ); |
|
20 |
+ |
mFieldLabel = pFieldLabel; |
|
21 |
+ |
} |
|
22 |
+ |
|
|
23 |
+ |
@Override |
|
24 |
+ |
protected void initialize( String pFieldLabel, UiFont pLabelFont, String pTooltip ) { |
|
25 |
+ |
super.initialize( pFieldLabel, pLabelFont, pTooltip ); |
|
26 |
+ |
|
|
27 |
+ |
if ( null == ConstrainTo.significantOrNull( pTooltip ) ) { |
|
28 |
+ |
setVisible( mIndicatorTd.getElement(), false ); |
|
29 |
+ |
} |
|
30 |
+ |
|
|
31 |
+ |
getCheckBox().addClickHandler( new ClickHandler() { |
|
32 |
+ |
@Override |
|
33 |
+ |
public void onClick( ClickEvent event ) { |
|
34 |
+ |
fireChangeListeners(); |
|
35 |
+ |
} |
|
36 |
+ |
} ); |
|
37 |
+ |
} |
|
38 |
+ |
|
|
39 |
+ |
// SizeManaged |
|
40 |
+ |
|
|
41 |
+ |
@Override |
|
42 |
+ |
public void relayout() { |
|
43 |
+ |
Widget parent = getParent(); |
|
44 |
+ |
if ( parent instanceof SizeManaged ) { |
|
45 |
+ |
((SizeManaged) parent).relayout(); |
|
46 |
+ |
} |
|
47 |
+ |
} |
|
48 |
+ |
|
|
49 |
+ |
// IFormComponent |
|
50 |
+ |
|
|
51 |
+ |
@Override |
|
52 |
+ |
public Object getCurrentValue() { |
|
53 |
+ |
//noinspection UnnecessaryBoxing |
|
54 |
+ |
return Boolean.valueOf( isChecked() ); |
|
55 |
+ |
} |
|
56 |
+ |
|
|
57 |
+ |
@Override |
|
58 |
+ |
public void setCurrentValue( Object pNewValue ) { |
|
59 |
+ |
if ( pNewValue != null ) { |
|
60 |
+ |
if ( !(pNewValue instanceof Boolean) ) { |
|
61 |
+ |
throw new IllegalArgumentException( "Not a Boolean: " + pNewValue ); |
|
62 |
+ |
} |
|
63 |
+ |
setChecked( (Boolean) pNewValue ); |
|
64 |
+ |
} |
|
65 |
+ |
} |
|
66 |
+ |
|
|
67 |
+ |
// Support... |
|
68 |
+ |
|
|
69 |
+ |
@Override |
|
70 |
+ |
public void simulateUserTextEntry( String pText ) { |
|
71 |
+ |
boolean zCurrentChecked = isChecked(); |
|
72 |
+ |
setChecked( !Boolean.FALSE.equals( Booleans.fromString( pText ) ) ); |
|
73 |
+ |
if ( zCurrentChecked != isChecked() ) { |
|
74 |
+ |
fireChangeListeners(); |
|
75 |
+ |
} |
|
76 |
+ |
pullFocusTo( getCheckBox() ); |
|
77 |
+ |
} |
|
78 |
+ |
|
|
79 |
+ |
public boolean isChecked() { |
|
80 |
+ |
return getCheckBox().getValue(); |
|
81 |
+ |
} |
|
82 |
+ |
|
|
83 |
+ |
public void setChecked( boolean pChecked ) { |
|
84 |
+ |
getCheckBox().setValue( pChecked ); |
|
85 |
+ |
} |
|
86 |
+ |
|
|
87 |
+ |
public CheckBox getCheckBox() { |
|
88 |
+ |
return (CheckBox) mInputWidget; |
|
89 |
+ |
} |
|
90 |
+ |
|
|
91 |
+ |
private static class MyCheckBox extends CheckBox implements IFocusWidget { |
|
92 |
+ |
public MyCheckBox( String pFieldLabel, UiFont pLabelFont ) { |
|
93 |
+ |
super( HTMLize( pFieldLabel ), true ); |
|
94 |
+ |
if ( !"".equals( getText() ) ) { |
|
95 |
+ |
ApplyFont.to( pLabelFont, this ); |
|
96 |
+ |
} |
|
97 |
+ |
} |
|
98 |
+ |
|
|
99 |
+ |
private static String HTMLize( String pFieldLabel ) { |
|
100 |
+ |
pFieldLabel = ConstrainTo.significantOrNull( pFieldLabel ); |
|
101 |
+ |
return HTMLize.escapeNoWrap( pFieldLabel ); |
|
102 |
+ |
} |
|
103 |
+ |
} |
|
104 |
+ |
} |