litesoft
@ 950
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.GWT.forms.client.components.nonpublic; import org.litesoft.GWT.client.*; import org.litesoft.GWT.client.widgets.*; import com.google.gwt.dom.client.*; import com.google.gwt.event.dom.client.*; import com.google.gwt.user.client.ui.*; public class AbstractOneLineTextElement extends AbstractTextElement { protected AbstractOneLineTextElement( IExtendedTextBox pInputWidget, String pTooltip, String pWidgetStyle, boolean pMixedSizeChars, Integer pDisplayCharsWidth, Integer pMaxChar ) { this( pInputWidget, (TextBoxBase) pInputWidget, pTooltip, pWidgetStyle, pMixedSizeChars, pDisplayCharsWidth, pMaxChar ); } protected AbstractOneLineTextElement( IExtendedTextBox pInputWidget, TextBoxBase pTextBoxBase, String pTooltip, String pWidgetStyle, boolean pMixedSizeChars, Integer pDisplayCharsWidth, Integer pMaxChar ) { super( pInputWidget, pTextBoxBase, pTooltip, pWidgetStyle ); mHeightHelper = NullHeightHelper.INSTANCE; if ( pDisplayCharsWidth == null ) { mWidthHelper = new StretchableWidthHelper( this ); } else { mWidthHelper = NullWidthHelper.INSTANCE; EMcalc zEMcalc = pMixedSizeChars ? MixedEMcalc.INSTANCE : NumericEMcalc.INSTANCE; pTextBoxBase.getElement().getStyle().setWidth( zEMcalc.calcEMs( pDisplayCharsWidth ), Style.Unit.EM ); // pInputWidget.setVisibleLength( pDisplayCharsWidth.intValue() ); } if ( pMaxChar != null ) { pInputWidget.setMaxLength( pMaxChar ); } pTextBoxBase.addKeyDownHandler( new KeyDownHandler() { @Override public void onKeyDown( KeyDownEvent event ) { if ( event != null ) { if ( event.getNativeKeyCode() == KeyCodes.KEY_ENTER ) { KeyboardKeyModifier zModifiers = KeyboardKeyModifier.None; if ( event.isAnyModifierKeyDown() ) { if ( event.isAltKeyDown() ) { zModifiers = zModifiers.addAlt(); } if ( event.isMetaKeyDown() ) { zModifiers = zModifiers.addMeta(); } if ( event.isShiftKeyDown() ) { zModifiers = zModifiers.addShift(); } if ( event.isControlKeyDown() ) { zModifiers = zModifiers.addCtrl(); } } fireEnterPressedListeners( zModifiers ); } } } } ); } protected Widget getInput() { return mInputWidget; } private static abstract class EMcalc { abstract public int calcEMs( int pWidth ); abstract protected int calcWithFormulaEMs( int pWidth ); protected int LLcalcEMs( int pWidth, int[] pSmallEMs ) { if ( pWidth < 0 ) { pWidth = 0; } return pWidth < pSmallEMs.length ? pSmallEMs[pWidth] : calcWithFormulaEMs( pWidth ); } } private static class NumericEMcalc extends EMcalc { private static final int[] SMALL_EMS = new int[] // { // 1, // 0 1, // 1 2, // 2 2, // 3 3, // 4 3, // 5 4, // 6 5, // 7 5, // 8 6, // 9 6, // 10 7, // 11 7, // 12 8, // 13 8, // 14 9, // 15 9, // 16 10, // 17 10, // 18 11, // 19 11, // 20 12, // 21 12, // 22 13, // 23 13, // 24 14, // 25 14, // 26 15, // 27 15, // 28 16, // 29 16, // 30 17, // 31 17, // 32 18, // 33 18, // 34 19, // 35 19, // 36 20, // 37 20, // 38 21, // 39 21, // 40 22, // 41 22, // 42 23, // 43 23, // 44 24, // 45 24, // 46 25, // 47 25, // 48 26, // 49 26, // 50 27, // 51 27, // 52 28, // 53 28, // 54 29, // 55 29, // 56 30, // 57 30, // 58 31, // 59 31, // 60 32, // 61 32, // 62 33, // 63 33, // 64 34, // 65 34, // 66 35, // 67 35, // 68 36, // 69 36, // 70 37, // 71 37, // 72 38, // 73 38, // 74 39, // 75 39, // 76 40, // 77 40, // 78 41, // 79 41, // 80 }; @Override public int calcEMs( int pWidth ) { return LLcalcEMs( pWidth, SMALL_EMS ); } @Override protected int calcWithFormulaEMs( int pWidth ) { return ((pWidth + 1) / 2) + 1; } public static final EMcalc INSTANCE = new NumericEMcalc(); } private static class MixedEMcalc extends EMcalc { private static final int[] SMALL_EMS = new int[] // { // 2, // 0 2, // 1 2, // 2 3, // 3 3, // 4 4, // 5 4, // 6 5, // 7 6, // 8 6, // 9 7, // 10 7, // 11 8, // 12 9, // 13 9, // 14 10, // 15 10, // 16 11, // 17 12, // 18 12, // 19 13, // 20 13, // 21 14, // 22 15, // 23 15, // 24 16, // 25 16, // 26 17, // 27 18, // 28 18, // 29 19, // 30 19, // 31 20, // 32 21, // 33 21, // 34 22, // 35 22, // 36 23, // 37 24, // 38 24, // 39 25, // 40 25, // 41 26, // 42 27, // 43 27, // 44 28, // 45 28, // 46 29, // 47 30, // 48 30, // 49 31, // 50 31, // 51 32, // 52 33, // 53 33, // 54 34, // 55 34, // 56 35, // 57 36, // 58 36, // 59 37, // 60 37, // 61 38, // 62 39, // 63 39, // 64 40, // 65 40, // 66 41, // 67 42, // 68 42, // 69 43, // 70 43, // 71 44, // 72 45, // 73 45, // 74 46, // 75 46, // 76 47, // 77 48, // 78 48, // 79 49, // 80 }; @Override public int calcEMs( int pWidth ) { return LLcalcEMs( pWidth, SMALL_EMS ); } @Override protected int calcWithFormulaEMs( int pWidth ) { int base = 0; while ( pWidth >= 15 ) { base += 3; pWidth -= 5; } return base + SMALL_EMS[pWidth]; } public static final EMcalc INSTANCE = new MixedEMcalc(); } } |
Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/forms/client/components/nonpublic/AbstractOneLineTextElement.java
Revision | Author | Commited | Message |
---|---|---|---|
950 Diff | GeorgeS | Thu 19 Jun, 2014 17:57:04 +0000 | New Lines |
948 Diff | GeorgeS | Sat 07 Jun, 2014 23:42:39 +0000 | Jusefuls Formatter Updated to New Code Format |
947 Diff | GeorgeS | Fri 06 Jun, 2014 23:36:56 +0000 | Correct Spelling of package! |
326 Diff | GeorgeS | Wed 27 Jul, 2011 01:00:24 +0000 | |
243 Diff | GeorgeS | Sun 05 Jun, 2011 20:29:12 +0000 | |
151 Diff | GeorgeS | Thu 17 Mar, 2011 04:16:22 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
23 Diff | GeorgeS | Wed 24 Feb, 2010 00:34:32 +0000 | |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |